42577453d9aaf274d970d4bbc2e6792d5fd646fb
[framework/uifw/e17.git] / src / modules / conf_theme / e_int_config_borders.c
1 #include "e.h"
2
3 static E_Config_Dialog_View *_config_view_new(void);
4
5 static void *_create_data(E_Config_Dialog *cfd);
6 static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
7 static int _basic_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
8 static Evas_Object *_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
9 static int _basic_check_changed(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
10 static void _fill_data(E_Config_Dialog_Data *cfdata);
11 static void _basic_apply_border(E_Config_Dialog_Data *cfdata);
12
13 struct _E_Config_Dialog_Data 
14 {
15    E_Border *border;
16    E_Container *container;
17    const char *bordername;
18    int remember_border;
19 };
20
21 E_Config_Dialog *
22 e_int_config_borders(E_Container *con, const char *params __UNUSED__) 
23 {
24    E_Config_Dialog *cfd;
25    E_Config_Dialog_View *v;
26
27    if (e_config_dialog_find("E", "appearance/borders")) return NULL;
28    v = _config_view_new();
29    if (!v) return NULL;
30    cfd = e_config_dialog_new(con, _("Default Border Style"), 
31                              "E", "appearance/borders", 
32                              "preferences-system-windows", 0, v, con);
33    return cfd;
34 }
35
36 E_Config_Dialog *
37 e_int_config_borders_border(E_Container *con __UNUSED__, const char *params) 
38 {
39    E_Config_Dialog *cfd;
40    E_Config_Dialog_View *v;
41    E_Border *bd;
42    
43    if (!params) return NULL;
44    bd = NULL;
45    sscanf(params, "%p", &bd);
46    if (!bd) return NULL;
47    v = _config_view_new();
48    if (!v) return NULL;
49    cfd = e_config_dialog_new(bd->zone->container, 
50                              _("Window Border Selection"), 
51                              "E", "_config_border_border_style_dialog", 
52                              "preferences-system-windows", 0, v, bd);
53    bd->border_border_dialog = cfd;
54    return cfd;
55 }
56
57 static E_Config_Dialog_View *
58 _config_view_new(void) 
59 {
60    E_Config_Dialog_View *v;
61    
62    v = E_NEW(E_Config_Dialog_View, 1);
63    if (!v) return NULL;
64    v->create_cfdata = _create_data;
65    v->free_cfdata = _free_data;
66    v->basic.create_widgets = _basic_create;
67    v->basic.apply_cfdata = _basic_apply;
68    v->basic.check_changed = _basic_check_changed;
69    v->override_auto_apply = 1;
70    return v;
71 }
72
73 static void *
74 _create_data(E_Config_Dialog *cfd) 
75 {
76    E_Config_Dialog_Data *cfdata;
77    
78    cfdata = E_NEW(E_Config_Dialog_Data, 1);
79    cfdata->container = NULL;
80    cfdata->border = NULL;
81    if (E_OBJECT(cfd->data)->type == E_CONTAINER_TYPE)
82      cfdata->container = cfd->data;
83    else
84      cfdata->border = cfd->data;
85
86    _fill_data(cfdata);
87    return cfdata;
88 }
89
90 static void 
91 _fill_data(E_Config_Dialog_Data *cfdata) 
92 {
93    if (cfdata->border) 
94      {
95         if ((cfdata->border->remember) && 
96             (cfdata->border->remember->apply & E_REMEMBER_APPLY_BORDER))
97           {
98              cfdata->remember_border = 1;
99           }
100         cfdata->bordername = eina_stringshare_add(cfdata->border->client.border.name);
101      }
102    else
103      cfdata->bordername = eina_stringshare_add(e_config->theme_default_border_style);
104 }
105
106 static void 
107 _free_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata) 
108 {
109    if (cfdata->border) 
110      cfdata->border->border_border_dialog = NULL;
111
112    eina_stringshare_del(cfdata->bordername);
113    E_FREE(cfdata);
114 }
115
116 static int
117 _basic_check_changed(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata) 
118 {
119    if (cfdata->border)
120      return strcmp(cfdata->bordername, cfdata->border->client.border.name);
121    else
122      return strcmp(cfdata->bordername, e_config->theme_default_border_style);
123 }
124
125 static int 
126 _basic_apply(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata) 
127 {
128    if (cfdata->border) 
129      _basic_apply_border(cfdata);
130    else if (cfdata->container)
131      {
132         eina_stringshare_del(e_config->theme_default_border_style);
133         e_config->theme_default_border_style = 
134           eina_stringshare_ref(cfdata->bordername);
135         /* FIXME: Should this trigger an E Restart to reset all borders ? */
136      }
137    e_config_save_queue();
138    return 1;
139 }
140
141 static void 
142 _basic_apply_border(E_Config_Dialog_Data *cfdata) 
143 {
144    if ((!cfdata->border->lock_border) && (!cfdata->border->shaded)) 
145      {
146         eina_stringshare_del(cfdata->border->bordername);
147         cfdata->border->bordername = eina_stringshare_ref(cfdata->bordername);
148         cfdata->border->client.border.changed = 1;
149         cfdata->border->changed = 1;
150      }
151    if (cfdata->remember_border) 
152      {
153         E_Remember *rem = cfdata->border->remember;
154
155         if (!rem) 
156           {
157              rem = e_remember_new();
158              if (rem) e_remember_use(rem);
159           }
160         if (rem) 
161           {
162              rem->apply |= E_REMEMBER_APPLY_BORDER;
163              e_remember_default_match_set(rem, cfdata->border);
164              if (rem->prop.border) eina_stringshare_del(rem->prop.border);
165              rem->prop.border = eina_stringshare_add(cfdata->border->bordername);
166              cfdata->border->remember = rem;
167              e_remember_update(cfdata->border);
168           }
169      }
170    else 
171      {
172         if (cfdata->border->remember) 
173           {
174              cfdata->border->remember->apply &= ~E_REMEMBER_APPLY_BORDER;
175              if (cfdata->border->remember->apply == 0) 
176                {
177                   e_remember_unuse(cfdata->border->remember);
178                   e_remember_del(cfdata->border->remember);
179                   cfdata->border->remember = NULL;
180                }
181           }
182      }
183 }
184
185 static Evas_Object *
186 _basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata) 
187 {
188    Evas_Object *o, *ol, *ob, *oj, *orect, *of;
189    Evas_Coord w, h;
190    Eina_List *borders, *l;
191    int n, sel = 0;
192    char *tmp;
193    
194    if (cfdata->border)
195      tmp = strdup(cfdata->border->client.border.name);
196    else
197      tmp = strdup(e_config->theme_default_border_style);
198
199    o = e_widget_list_add(evas, 0, 0);
200    of = e_widget_framelist_add(evas, _("Default Border Style"), 0);
201    e_widget_framelist_content_align_set(of, 0.0, 0.0);
202    ol = e_widget_ilist_add(evas, 96, 96, &(cfdata->bordername));
203    borders = e_theme_border_list();
204    orect = evas_object_rectangle_add(evas);
205    evas_object_color_set(orect, 0, 0, 0, 128);
206    
207    evas_event_freeze(evas_object_evas_get(ol));
208    edje_freeze();
209    e_widget_ilist_freeze(ol);
210    e_widget_ilist_append(ol, orect, "borderless", NULL, NULL, "borderless");
211    
212    for (n = 1, l = borders; l; l = l->next, n++) 
213      {
214         char buf[PATH_MAX];
215
216         ob = e_livethumb_add(evas);
217         e_livethumb_vsize_set(ob, 96, 96);
218         oj = edje_object_add(e_livethumb_evas_get(ob));
219         snprintf(buf, sizeof(buf), "e/widgets/border/%s/border", 
220                  (char *)l->data);
221         e_theme_edje_object_set(oj, "base/theme/borders", buf);
222         e_livethumb_thumb_set(ob, oj);
223         orect = evas_object_rectangle_add(e_livethumb_evas_get(ob));
224         evas_object_color_set(orect, 0, 0, 0, 128);
225         evas_object_show(orect);
226         edje_object_part_swallow(oj, "e.swallow.client", orect);
227         e_widget_ilist_append(ol, ob, (char *)l->data, NULL, NULL, l->data);
228         if (!strcmp(tmp, (char *)l->data))
229           sel = n;
230      }
231    
232    e_widget_size_min_get(ol, &w, &h);
233    e_widget_size_min_set(ol, w > 200 ? w : 200, 100);
234
235    e_widget_ilist_go(ol);
236    e_widget_ilist_selected_set(ol, sel);
237    e_widget_ilist_thaw(ol);
238    edje_thaw();
239    evas_event_thaw(evas_object_evas_get(ol));
240
241    e_widget_framelist_object_append(of, ol);
242    e_widget_list_object_append(o, of, 1, 1, 0.5);
243
244    if (cfdata->border) 
245      {
246         ob = e_widget_check_add(evas, _("Remember this Border for this window next time it appears"), 
247                                 &(cfdata->remember_border));
248         e_widget_list_object_append(o, ob, 1, 0, 0.0);
249      }
250    
251    E_FREE(tmp);
252    e_dialog_resizable_set(cfd->dia, 1);
253    return o;
254 }