create rotation job and EAPI e_border_rotation_set
[platform/core/uifw/e17.git] / src / bin / e_int_shelf_config.c
1 #include "e.h"
2
3 struct _E_Config_Dialog_Data
4 {
5    E_Shelf *es;
6    E_Config_Shelf *escfg;
7
8    Evas_Object *o_autohide, *o_desk_list;
9    Eina_List *autohide_list, *desk_list;
10
11    int layer, overlap;
12    int orient, fit_along;
13    int size;
14    const char *style;
15    int autohide, autohide_action;
16    double hide_timeout, hide_duration;
17    int desk_show_mode;
18    Eina_List *handlers;
19 #ifdef _F_SHELF_INPUT_CONTROL_
20    int disable_menu;
21 #endif
22 };
23
24 /* local function prototypes */
25 static void *_create_data(E_Config_Dialog *cfd);
26 static void _fill_data(E_Config_Dialog_Data *cfdata);
27 static void _free_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata);
28 static Evas_Object *_basic_create(E_Config_Dialog *cfd __UNUSED__, Evas *evas, E_Config_Dialog_Data *cfdata);
29 static int _basic_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
30 static void _fill_styles(E_Config_Dialog_Data *cfdata, Evas_Object *obj);
31 static void _cb_autohide_change(void *data, Evas_Object *obj __UNUSED__);
32 static void _fill_desks(E_Config_Dialog_Data *cfdata);
33
34 EAPI void
35 e_int_shelf_config(E_Shelf *es)
36 {
37    E_Config_Dialog_View *v;
38
39    if (!(v = E_NEW(E_Config_Dialog_View, 1))) return;
40
41    v->create_cfdata = _create_data;
42    v->free_cfdata = _free_data;
43    v->basic.create_widgets = _basic_create;
44    v->basic.apply_cfdata = _basic_apply;
45
46    es->config_dialog =
47      e_config_dialog_new(es->zone->container, _("Shelf Settings"),
48                          "E", "_shelf_config_dialog",
49                          "preferences-desktop-shelf", 0, v, es);
50    e_win_centered_set(es->config_dialog->dia->win, EINA_TRUE);
51 }
52
53 /* local functions */
54 static Eina_Bool
55 _shelf_event_add(E_Config_Dialog_Data *cfdata, int type __UNUSED__, E_Event_Shelf *ev)
56 {
57    if (ev->shelf->cfg == cfdata->escfg)
58      cfdata->es = ev->shelf;
59    return ECORE_CALLBACK_RENEW;
60 }
61
62 static Eina_Bool
63 _shelf_event_del(E_Config_Dialog_Data *cfdata, int type __UNUSED__, E_Event_Shelf *ev)
64 {
65    if (ev->shelf == cfdata->es)
66      cfdata->es = NULL;
67    return ECORE_CALLBACK_RENEW;
68 }
69
70 static void *
71 _create_data(E_Config_Dialog *cfd)
72 {
73    E_Config_Dialog_Data *cfdata;
74
75    cfdata = E_NEW(E_Config_Dialog_Data, 1);
76    cfdata->es = cfd->data;
77    cfdata->escfg = cfdata->es->cfg;
78    E_LIST_HANDLERS_APPEND(cfdata->handlers, E_EVENT_SHELF_ADD, _shelf_event_add, cfdata);
79    E_LIST_HANDLERS_APPEND(cfdata->handlers, E_EVENT_SHELF_DEL, _shelf_event_del, cfdata);
80    _fill_data(cfdata);
81    return cfdata;
82 }
83
84 static void
85 _fill_data(E_Config_Dialog_Data *cfdata)
86 {
87    /* stacking */
88    if ((!cfdata->escfg->popup) && (cfdata->escfg->layer == 1))
89      cfdata->layer = 0;
90    else if ((cfdata->escfg->popup) && (cfdata->escfg->layer == 0))
91      cfdata->layer = 1;
92    else if ((cfdata->escfg->popup) && (cfdata->escfg->layer == 200))
93      cfdata->layer = 2;
94    else
95      cfdata->layer = 2;
96    cfdata->overlap = cfdata->escfg->overlap;
97
98    /* position */
99    cfdata->orient = cfdata->escfg->orient;
100    cfdata->fit_along = cfdata->escfg->fit_along;
101
102    /* size */
103    cfdata->size = cfdata->escfg->size;
104
105    /* style */
106    if (cfdata->escfg->style)
107      cfdata->style = eina_stringshare_ref(cfdata->escfg->style);
108    else
109      cfdata->style = eina_stringshare_add("");
110
111    /* autohide */
112    cfdata->autohide = cfdata->escfg->autohide;
113    cfdata->autohide_action = cfdata->escfg->autohide_show_action;
114    cfdata->hide_timeout = cfdata->escfg->hide_timeout;
115    cfdata->hide_duration = cfdata->escfg->hide_duration;
116
117    /* desktop */
118    cfdata->desk_show_mode = cfdata->escfg->desk_show_mode;
119    cfdata->desk_list = cfdata->escfg->desk_list;
120
121 #ifdef _F_SHELF_INPUT_CONTROL_
122    /* controls */
123    cfdata->disable_menu = cfdata->escfg->disable_menu;
124 #endif
125 }
126
127 static void
128 _free_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
129 {
130    eina_list_free(cfdata->autohide_list);
131
132    eina_stringshare_del(cfdata->style);
133    cfdata->style = NULL;
134
135    E_FREE_LIST(cfdata->handlers, ecore_event_handler_del);
136    cfdata->es->config_dialog = NULL;
137    E_FREE(cfdata);
138 }
139
140 static Evas_Object *
141 _basic_create(E_Config_Dialog *cfd __UNUSED__, Evas *evas, E_Config_Dialog_Data *cfdata)
142 {
143    Evas_Object *otb, *ol, *ow;
144    E_Radio_Group *rg;
145
146    otb = e_widget_toolbook_add(evas, 24, 24);
147
148    /* Stacking */
149    ol = e_widget_list_add(evas, 0, 0);
150    rg = e_widget_radio_group_new(&(cfdata->layer));
151    ow = e_widget_radio_add(evas, _("Above Everything"), 2, rg);
152    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
153    ow = e_widget_radio_add(evas, _("Below Windows"), 1, rg);
154    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
155    ow = e_widget_radio_add(evas, _("Below Everything"), 0, rg);
156    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
157    ow = e_widget_check_add(evas, _("Allow windows to overlap the shelf"),
158                            &(cfdata->overlap));
159    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
160    e_widget_toolbook_page_append(otb, NULL, _("Stacking"), ol,
161                                  1, 0, 1, 0, 0.5, 0.0);
162
163    /* position */
164    ol = e_widget_table_add(evas, 1);
165    rg = e_widget_radio_group_new(&(cfdata->orient));
166    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-left",
167                                 24, 24, E_GADCON_ORIENT_LEFT, rg);
168    e_widget_table_object_append(ol, ow, 0, 2, 1, 1, 1, 1, 1, 1);
169    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-right",
170                                 24, 24, E_GADCON_ORIENT_RIGHT, rg);
171    e_widget_table_object_append(ol, ow, 2, 2, 1, 1, 1, 1, 1, 1);
172    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-top",
173                                 24, 24, E_GADCON_ORIENT_TOP, rg);
174    e_widget_table_object_append(ol, ow, 1, 0, 1, 1, 1, 1, 1, 1);
175    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-bottom",
176                                 24, 24, E_GADCON_ORIENT_BOTTOM, rg);
177    e_widget_table_object_append(ol, ow, 1, 4, 1, 1, 1, 1, 1, 1);
178    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-top-left",
179                                 24, 24, E_GADCON_ORIENT_CORNER_TL, rg);
180    e_widget_table_object_append(ol, ow, 0, 0, 1, 1, 1, 1, 1, 1);
181    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-top-right",
182                                 24, 24, E_GADCON_ORIENT_CORNER_TR, rg);
183    e_widget_table_object_append(ol, ow, 2, 0, 1, 1, 1, 1, 1, 1);
184    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-bottom-left",
185                                 24, 24, E_GADCON_ORIENT_CORNER_BL, rg);
186    e_widget_table_object_append(ol, ow, 0, 4, 1, 1, 1, 1, 1, 1);
187    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-bottom-right",
188                                 24, 24, E_GADCON_ORIENT_CORNER_BR, rg);
189    e_widget_table_object_append(ol, ow, 2, 4, 1, 1, 1, 1, 1, 1);
190    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-left-top",
191                                 24, 24, E_GADCON_ORIENT_CORNER_LT, rg);
192    e_widget_table_object_append(ol, ow, 0, 1, 1, 1, 1, 1, 1, 1);
193    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-right-top",
194                                 24, 24, E_GADCON_ORIENT_CORNER_RT, rg);
195    e_widget_table_object_append(ol, ow, 2, 1, 1, 1, 1, 1, 1, 1);
196    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-left-bottom",
197                                 24, 24, E_GADCON_ORIENT_CORNER_LB, rg);
198    e_widget_table_object_append(ol, ow, 0, 3, 1, 1, 1, 1, 1, 1);
199    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-right-bottom",
200                                 24, 24, E_GADCON_ORIENT_CORNER_RB, rg);
201    e_widget_table_object_append(ol, ow, 2, 3, 1, 1, 1, 1, 1, 1);
202    e_widget_toolbook_page_append(otb, NULL, _("Position"), ol,
203                                  1, 0, 1, 0, 0.5, 0.0);
204
205    /* size */
206    ol = e_widget_list_add(evas, 0, 0);
207    ow = e_widget_slider_add(evas, 1, 0, _("Height (%3.0f pixels)"), 4, 256, 4, 0,
208                             NULL, &(cfdata->size), 100);
209    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
210    ow = e_widget_check_add(evas, _("Shrink to Content Width"),
211                            &(cfdata->fit_along));
212    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
213    e_widget_toolbook_page_append(otb, NULL, _("Size"), ol,
214                                  1, 0, 1, 0, 0.5, 0.0);
215
216    /* style */
217    ol = e_widget_list_add(evas, 0, 0);
218    ow = e_widget_ilist_add(evas, 60, 20, &(cfdata->style));
219    _fill_styles(cfdata, ow);
220    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
221    e_widget_toolbook_page_append(otb, NULL, _("Style"), ol,
222                                  1, 0, 1, 0, 0.5, 0.0);
223
224    /* autohide */
225    ol = e_widget_list_add(evas, 0, 0);
226    cfdata->o_autohide =
227      e_widget_check_add(evas, _("Auto-hide the shelf"), &(cfdata->autohide));
228    e_widget_on_change_hook_set(cfdata->o_autohide, _cb_autohide_change, cfdata);
229    e_widget_list_object_append(ol, cfdata->o_autohide, 1, 1, 0.5);
230
231    rg = e_widget_radio_group_new(&(cfdata->autohide_action));
232    ow = e_widget_radio_add(evas, _("Show on mouse in"), 0, rg);
233    e_widget_disabled_set(ow, !cfdata->autohide);
234    cfdata->autohide_list = eina_list_append(cfdata->autohide_list, ow);
235    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
236    ow = e_widget_radio_add(evas, _("Show on mouse click"), 1, rg);
237    cfdata->autohide_list = eina_list_append(cfdata->autohide_list, ow);
238    e_widget_disabled_set(ow, !cfdata->autohide);
239    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
240
241    ow = e_widget_label_add(evas, _("Hide timeout"));
242    cfdata->autohide_list = eina_list_append(cfdata->autohide_list, ow);
243    e_widget_disabled_set(ow, !cfdata->autohide);
244    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
245    ow = e_widget_slider_add(evas, 1, 0, _("%.1f seconds"), 0.2, 6.0, 0.2, 0,
246                             &(cfdata->hide_timeout), NULL, 100);
247    cfdata->autohide_list = eina_list_append(cfdata->autohide_list, ow);
248    e_widget_disabled_set(ow, !cfdata->autohide);
249    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
250
251    ow = e_widget_label_add(evas, _("Hide duration"));
252    cfdata->autohide_list = eina_list_append(cfdata->autohide_list, ow);
253    e_widget_disabled_set(ow, !cfdata->autohide);
254    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
255    ow = e_widget_slider_add(evas, 1, 0, _("%.2f seconds"), 0.05, 6.0, 0.05, 0,
256                             &(cfdata->hide_duration), NULL, 100);
257    cfdata->autohide_list = eina_list_append(cfdata->autohide_list, ow);
258    e_widget_disabled_set(ow, !cfdata->autohide);
259    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
260    e_widget_toolbook_page_append(otb, NULL, _("Auto Hide"), ol,
261                                  1, 0, 1, 0, 0.5, 0.0);
262
263    /* Desktop */
264    ol = e_widget_list_add(evas, 0, 0);
265    rg = e_widget_radio_group_new(&(cfdata->desk_show_mode));
266    ow = e_widget_radio_add(evas, _("Show on all Desktops"), 0, rg);
267    e_widget_list_object_append(ol, ow, 1, 0, 0.5);
268    ow = e_widget_radio_add(evas, _("Show on specified Desktops"), 1, rg);
269    e_widget_list_object_append(ol, ow, 1, 0, 0.5);
270
271    cfdata->o_desk_list = e_widget_ilist_add(evas, 24, 24, NULL);
272    e_widget_ilist_multi_select_set(cfdata->o_desk_list, EINA_TRUE);
273    _fill_desks(cfdata);
274    e_widget_list_object_append(ol, cfdata->o_desk_list, 1, 1, 0.5);
275    e_widget_toolbook_page_append(otb, NULL, _("Desktop"), ol,
276                                  1, 0, 1, 0, 0.5, 0.0);
277
278 #ifdef _F_SHELF_INPUT_CONTROL_
279    /* Controls */
280    ol = e_widget_list_add(evas, 0, 0);
281    ow = e_widget_check_add(evas, _("Disable menu on the shelf"),
282                            &(cfdata->disable_menu));
283    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
284    e_widget_toolbook_page_append(otb, NULL, _("Control"), ol,
285                                  1, 0, 1, 0, 0.5, 0.0);
286 #endif
287
288    e_widget_toolbook_page_show(otb, 0);
289    return otb;
290 }
291
292 static int
293 _basic_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
294 {
295    E_Config_Shelf_Desk *sd;
296    int recreate = 0;
297
298    if (!cfdata->escfg->style)
299      {
300         cfdata->escfg->style = eina_stringshare_ref(cfdata->style);
301         e_shelf_style_set(cfdata->es, cfdata->style);
302      }
303    else if ((cfdata->escfg->style) &&
304             (cfdata->escfg->style != cfdata->style))
305      {
306         eina_stringshare_replace(&cfdata->escfg->style, cfdata->style);
307         e_shelf_style_set(cfdata->es, cfdata->style);
308      }
309
310    if (cfdata->escfg->orient != cfdata->orient)
311      {
312         cfdata->escfg->orient = cfdata->orient;
313         recreate = 1;
314      }
315
316    if (cfdata->escfg->fit_along != cfdata->fit_along)
317      {
318         cfdata->escfg->fit_along = cfdata->fit_along;
319         cfdata->es->fit_along = cfdata->fit_along;
320         recreate = 1;
321      }
322
323    if (cfdata->escfg->size != cfdata->size)
324      {
325         cfdata->escfg->size = cfdata->size;
326         cfdata->es->size = cfdata->size;
327         recreate = 1;
328      }
329
330    if (cfdata->layer == 0)
331      {
332         if ((cfdata->escfg->popup != 0) || (cfdata->escfg->layer != 1))
333           {
334              cfdata->escfg->popup = 0;
335              cfdata->escfg->layer = 1;
336              recreate = 1;
337           }
338      }
339    else if (cfdata->layer == 1)
340      {
341         if ((cfdata->escfg->popup != 1) || (cfdata->escfg->layer != 0))
342           {
343              cfdata->escfg->popup = 1;
344              cfdata->escfg->layer = 0;
345              recreate = 1;
346           }
347      }
348    else if (cfdata->layer == 2)
349      {
350         if ((cfdata->escfg->popup != 1) || (cfdata->escfg->layer != 200))
351           {
352              cfdata->escfg->popup = 1;
353              cfdata->escfg->layer = 200;
354              recreate = 1;
355           }
356      }
357
358    cfdata->escfg->overlap = cfdata->overlap;
359    e_shelf_autohide_set(cfdata->es, cfdata->autohide);
360    cfdata->escfg->autohide_show_action = cfdata->autohide_action;
361    cfdata->escfg->hide_timeout = cfdata->hide_timeout;
362    cfdata->escfg->hide_duration = cfdata->hide_duration;
363    cfdata->escfg->desk_show_mode = cfdata->desk_show_mode;
364
365    EINA_LIST_FREE(cfdata->escfg->desk_list, sd)
366      E_FREE(sd);
367    cfdata->escfg->desk_list = NULL;
368
369    if (cfdata->desk_show_mode)
370      {
371         const Eina_List *l;
372         const E_Ilist_Item *it;
373         int idx = -1;
374
375         EINA_LIST_FOREACH(e_widget_ilist_items_get(cfdata->o_desk_list), l, it)
376           {
377              E_Desk *desk;
378
379              idx++;
380              if ((!it) || (!it->selected)) continue;
381              if (!(desk = e_desk_at_pos_get(cfdata->es->zone, idx))) continue;
382              sd = E_NEW(E_Config_Shelf_Desk, 1);
383              sd->x = desk->x;
384              sd->y = desk->y;
385              cfdata->escfg->desk_list =
386                eina_list_append(cfdata->escfg->desk_list, sd);
387           }
388      }
389
390    if (recreate)
391      {
392         E_Zone *zone;
393         E_Config_Shelf *cf_es;
394
395         zone = cfdata->es->zone;
396         cf_es = cfdata->es->cfg;
397         cfdata->es->config_dialog = NULL;
398         e_object_del(E_OBJECT(cfdata->es));
399
400         cfdata->es = e_shelf_config_new(zone, cf_es);
401         cfdata->es->config_dialog = cfd;
402      }
403
404    if (cfdata->escfg->desk_show_mode)
405      {
406         E_Desk *desk;
407         Eina_List *l;
408         int show = 0;
409
410         desk = e_desk_current_get(cfdata->es->zone);
411         EINA_LIST_FOREACH(cfdata->escfg->desk_list, l, sd)
412           {
413              if ((desk->x == sd->x) && (desk->y == sd->y))
414                {
415                   show = 1;
416                   break;
417                }
418           }
419         if (show) e_shelf_show(cfdata->es);
420         else e_shelf_hide(cfdata->es);
421      }
422    else
423      e_shelf_show(cfdata->es);
424
425    if ((cfdata->escfg->autohide) && (!cfdata->es->hidden))
426      e_shelf_toggle(cfdata->es, 0);
427    else if ((!cfdata->escfg->autohide) && (cfdata->es->hidden))
428      e_shelf_toggle(cfdata->es, 1);
429
430 #ifdef _F_SHELF_INPUT_CONTROL_
431    cfdata->escfg->disable_menu = cfdata->disable_menu;
432    cfdata->es->disable_menu = cfdata->disable_menu;
433 #endif
434
435    e_zone_useful_geometry_dirty(cfdata->es->zone);
436    e_config_save_queue();
437    cfdata->es->config_dialog = cfd;
438    return 1;
439 }
440
441 static void
442 _fill_styles(E_Config_Dialog_Data *cfdata, Evas_Object *obj)
443 {
444    Evas *evas;
445    Eina_List *l, *styles;
446    char *style;
447    const char *str;
448    int mw, n = 0;
449
450    evas = evas_object_evas_get(obj);
451    evas_event_freeze(evas);
452    edje_freeze();
453    e_widget_ilist_freeze(obj);
454    e_widget_ilist_clear(obj);
455
456    styles = e_theme_shelf_list();
457    EINA_LIST_FOREACH(styles, l, style)
458      {
459         Evas_Object *thumb, *ow;
460         char buff[4096];
461
462         thumb = e_livethumb_add(evas);
463         e_livethumb_vsize_set(thumb, 120, 40);
464         ow = edje_object_add(e_livethumb_evas_get(thumb));
465         snprintf(buff, sizeof(buff), "e/shelf/%s/base", style);
466         e_theme_edje_object_set(ow, "base/theme/shelf", buff);
467         e_livethumb_thumb_set(thumb, ow);
468         e_widget_ilist_append(obj, thumb, style, NULL, NULL, style);
469         if (!strcmp(cfdata->style, style))
470           e_widget_ilist_selected_set(obj, n);
471         n++;
472      }
473
474    e_widget_size_min_get(obj, &mw, NULL);
475    e_widget_size_min_set(obj, mw, 180);
476
477    e_widget_ilist_go(obj);
478    e_widget_ilist_thaw(obj);
479    edje_thaw();
480    evas_event_thaw(evas);
481
482    EINA_LIST_FREE(styles, str)
483      eina_stringshare_del(str);
484 }
485
486 static void
487 _cb_autohide_change(void *data, Evas_Object *obj __UNUSED__)
488 {
489    E_Config_Dialog_Data *cfdata;
490    Eina_List *l;
491    Evas_Object *ow;
492
493    if (!(cfdata = data)) return;
494    EINA_LIST_FOREACH(cfdata->autohide_list, l, ow)
495      e_widget_disabled_set(ow, !cfdata->autohide);
496 }
497
498 static void
499 _fill_desks(E_Config_Dialog_Data *cfdata)
500 {
501    Evas *evas;
502    int mw, x, y;
503    int i = 0;
504
505    evas = evas_object_evas_get(cfdata->o_desk_list);
506    evas_event_freeze(evas);
507    edje_freeze();
508    e_widget_ilist_freeze(cfdata->o_desk_list);
509    e_widget_ilist_clear(cfdata->o_desk_list);
510
511    for (y = 0; y < e_config->zone_desks_y_count; y++)
512      for (x = 0; x < e_config->zone_desks_x_count; x++)
513        {
514           E_Desk *desk;
515           Eina_List *l;
516           E_Config_Shelf_Desk *sd;
517
518           desk = e_desk_at_xy_get(cfdata->es->zone, x, y);
519           e_widget_ilist_append(cfdata->o_desk_list, NULL, desk->name,
520                                 NULL, NULL, NULL);
521           i++;
522
523           EINA_LIST_FOREACH(cfdata->desk_list, l, sd)
524             {
525                if ((sd->x != x) || (sd->y != y)) continue;
526                e_widget_ilist_multi_select(cfdata->o_desk_list, i);
527                break;
528             }
529        }
530
531    e_widget_size_min_get(cfdata->o_desk_list, &mw, NULL);
532    e_widget_size_min_set(cfdata->o_desk_list, mw, 180);
533
534    e_widget_ilist_go(cfdata->o_desk_list);
535    e_widget_ilist_thaw(cfdata->o_desk_list);
536    edje_thaw();
537    evas_event_thaw(evas);
538 }