Tizen 2.1 release
[platform/core/uifw/e17.git] / src / modules / physics / e_mod_config.c
1 #include "e.h"
2 #include "e_mod_main.h"
3 #include "e_mod_config.h"
4 #include "e_mod_physics.h"
5
6 struct _E_Config_Dialog_Data
7 {
8    double delay; /* delay before applying physics */
9    double max_mass; /* maximum mass for a window */
10    double gravity; /* maximum mass for a window */
11    Eina_Bool ignore_fullscreen;
12    Eina_Bool ignore_maximized;
13    Eina_Bool ignore_shelves;
14    struct
15    {
16       Eina_Bool disable_rotate;
17       Eina_Bool disable_move;
18    } shelf;
19 };
20
21 /* Protos */
22 static int _basic_check_changed(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata);
23 static void        *_create_data(E_Config_Dialog *cfd);
24 static void         _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
25 static Evas_Object *_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
26 static int          _basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
27
28 E_Config_Dialog *
29 e_int_config_physics_module(E_Container *con,
30                          const char *params __UNUSED__)
31 {
32    E_Config_Dialog *cfd;
33    E_Config_Dialog_View *v;
34    char buf[4096];
35    Mod *mod = _physics_mod;
36
37    if (mod->config_dialog) return NULL;
38    snprintf(buf, sizeof(buf), "%s/e-module-physics.edj", e_module_dir_get(mod->module));
39    v = E_NEW(E_Config_Dialog_View, 1);
40
41    v->create_cfdata = _create_data;
42    v->free_cfdata = _free_data;
43    v->basic.apply_cfdata = _basic_apply_data;
44    v->basic.create_widgets = _basic_create_widgets;
45    v->basic.check_changed = _basic_check_changed;
46
47    cfd = e_config_dialog_new(con, _("Physics Settings"),
48                              "E", "appearance/physics", buf, 32, v, mod);
49    mod->config_dialog = cfd;
50    return cfd;
51 }
52
53 static void *
54 _create_data(E_Config_Dialog *cfd __UNUSED__)
55 {
56    E_Config_Dialog_Data *cfdata;
57
58    cfdata = E_NEW(E_Config_Dialog_Data, 1);
59
60    cfdata->delay = _physics_mod->conf->delay;
61    cfdata->max_mass = _physics_mod->conf->max_mass;
62
63    return cfdata;
64 }
65
66 static void
67 _free_data(E_Config_Dialog *cfd  __UNUSED__,
68            E_Config_Dialog_Data *cfdata)
69 {
70    _physics_mod->config_dialog = NULL;
71    free(cfdata);
72 }
73
74 static int
75 _basic_check_changed(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
76 {
77 #define CHECK(X) \
78    if (cfdata->X != _physics_mod->conf->X) return 1
79
80    CHECK(max_mass);
81    CHECK(gravity);
82    CHECK(ignore_fullscreen);
83    CHECK(ignore_maximized);
84    CHECK(ignore_shelves);
85    CHECK(shelf.disable_move);
86    CHECK(shelf.disable_rotate);
87    if ((unsigned int)cfdata->delay != _physics_mod->conf->delay) return 1;
88
89 #undef CHECK
90    return 0;
91 }
92
93 static Evas_Object *
94 _basic_create_widgets(E_Config_Dialog *cfd,
95                       Evas *evas,
96                       E_Config_Dialog_Data *cfdata)
97 {
98    Evas_Object *ob, *ol, *otb, *tab;
99
100    tab = e_widget_table_add(evas, 0);
101    evas_object_name_set(tab, "dia_table");
102
103    otb = e_widget_toolbook_add(evas, 48 * e_scale, 48 * e_scale);
104
105    ///////////////////////////////////////////
106
107    ol = e_widget_list_add(evas, 0, 0);
108    ob = e_widget_label_add(evas, _("Physics delay after drag"));
109    e_widget_list_object_append(ol, ob, 1, 1, 0.5);
110    ob = e_widget_slider_add(evas, 1, 0, _("%2.0f Frames"), 5, 20, 1, 0, &(cfdata->delay), NULL, 150);
111    e_widget_list_object_append(ol, ob, 1, 1, 0.5);
112    ob = e_widget_label_add(evas, _("Maximum window mass"));
113    e_widget_list_object_append(ol, ob, 1, 1, 0.5);
114    ob = e_widget_slider_add(evas, 1, 0, _("%2.1f Kg"), 1, 6, 1, 0, &(cfdata->max_mass), NULL, 150);
115    e_widget_list_object_append(ol, ob, 1, 1, 0.5);
116    ob = e_widget_label_add(evas, _("Desktop gravity"));
117    e_widget_list_object_append(ol, ob, 1, 1, 0.5);
118    ob = e_widget_slider_add(evas, 1, 0, _("%1.1f m/s^2"), -5, 5, 1, 0, &(cfdata->gravity), NULL, 150);
119    e_widget_list_object_append(ol, ob, 1, 1, 0.5);
120
121    e_widget_toolbook_page_append(otb, NULL, _("General"), ol, 1, 1, 1, 1, 0.5, 0.5);
122
123    ///////////////////////////////////////////
124
125    ol = e_widget_list_add(evas, 0, 0);
126
127    ob = e_widget_check_add(evas, _("Disable Movement"), (int*)&(cfdata->shelf.disable_move));
128    e_widget_list_object_append(ol, ob, 1, 0, 0.5);
129
130    ob = e_widget_check_add(evas, _("Disable Rotation"), (int*)&(cfdata->shelf.disable_rotate));
131    e_widget_list_object_append(ol, ob, 1, 0, 0.5);
132
133    e_widget_toolbook_page_append(otb, NULL, _("Shelves"), ol, 1, 1, 1, 1, 0.5, 0.5);
134
135    ///////////////////////////////////////////
136
137    ol = e_widget_list_add(evas, 0, 0);
138    ob = e_widget_check_add(evas, _("Ignore Fullscreen"), (int*)&(cfdata->ignore_fullscreen));
139    e_widget_list_object_append(ol, ob, 1, 0, 0.5);
140
141    ob = e_widget_check_add(evas, _("Ignore Maximized"), (int*)&(cfdata->ignore_maximized));
142    e_widget_list_object_append(ol, ob, 1, 0, 0.5);
143
144    ob = e_widget_check_add(evas, _("Ignore Shelves"), (int*)&(cfdata->ignore_shelves));
145    e_widget_list_object_append(ol, ob, 1, 0, 0.5);
146
147    e_widget_toolbook_page_append(otb, NULL, _("Ignore"), ol, 1, 1, 1, 1, 0.5, 0.5);
148
149    e_widget_toolbook_page_show(otb, 0);
150
151    e_dialog_resizable_set(cfd->dia, 1);
152
153    e_widget_table_object_append(tab, otb, 0, 0, 1, 1, 1, 1, 1, 1);
154    return tab;
155 }
156
157
158 static int
159 _basic_apply_data(E_Config_Dialog *cfd  __UNUSED__,
160                   E_Config_Dialog_Data *cfdata)
161 {
162    if ((cfdata->delay != _physics_mod->conf->delay) ||
163        (cfdata->max_mass != _physics_mod->conf->max_mass) ||
164        (cfdata->ignore_fullscreen != _physics_mod->conf->ignore_fullscreen) ||
165        (cfdata->ignore_maximized != _physics_mod->conf->ignore_maximized) ||
166        (cfdata->gravity != _physics_mod->conf->gravity)
167       )
168      {
169 #define SET(X) _physics_mod->conf->X = cfdata->X
170         _physics_mod->conf->delay = (unsigned int)cfdata->delay;
171         SET(max_mass);
172         SET(ignore_fullscreen);
173         SET(ignore_maximized);
174         SET(ignore_shelves);
175         SET(gravity);
176         SET(shelf.disable_move);
177         SET(shelf.disable_rotate);
178         e_mod_physics_shutdown();
179         e_mod_physics_init();
180      }
181    e_config_save_queue();
182    return 1;
183 }
184