1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4 
5 #include "Elementary.h"
6 
7 #ifndef EFL_BUILD
8 # define EFL_BUILD
9 #endif
10 #undef ELM_MODULE_HELPER_H
11 #include "private.h"
12 
13 /* including declaration of each prefs item implementation iface struct */
14 #define PREFS_ADD(w_name) \
15   extern const Elm_Prefs_Item_Iface prefs_##w_name##_impl;
16 
17 #include "item_widgets.inc"
18 
19 #undef PREFS_ADD
20 
21 int _elm_prefs_log_dom = -1;
22 
23 /* now building on array of those, to be put on a hash for lookup */
24 static Elm_Prefs_Item_Iface_Info _elm_prefs_item_widgets[] =
25 {
26 #define PREFS_ADD(w_name) \
27   {"elm/" #w_name, &prefs_##w_name##_impl},
28 
29 #include "item_widgets.inc"
30 
31 #undef PREFS_ADD
32    {NULL, NULL}
33 };
34 
35 /* including declaration of each prefs page implementation iface struct */
36 #define PREFS_ADD(w_name) \
37   extern const Elm_Prefs_Page_Iface prefs_##w_name##_impl;
38 
39 #include "page_widgets.inc"
40 
41 #undef PREFS_ADD
42 
43 /* now building on array of those, to be put on a hash for lookup */
44 static Elm_Prefs_Page_Iface_Info _elm_prefs_page_widgets[] =
45 {
46 #define PREFS_ADD(w_name) \
47   {"elm/" #w_name, &prefs_##w_name##_impl},
48 
49 #include "page_widgets.inc"
50 
51 #undef PREFS_ADD
52    {NULL, NULL}
53 };
54 
55 Eina_Bool
elm_prefs_page_item_value_set(Evas_Object * it,const Elm_Prefs_Item_Iface * iface,Eina_Bool val)56 elm_prefs_page_item_value_set(Evas_Object *it,
57                               const Elm_Prefs_Item_Iface *iface,
58                               Eina_Bool val)
59 {
60    Eina_Value value;
61 
62    if (!iface->value_set) return EINA_FALSE;
63 
64    if ((!eina_value_setup(&value, EINA_VALUE_TYPE_UCHAR)) ||
65        (!eina_value_set(&value, val)))
66      return EINA_FALSE;
67 
68    return iface->value_set(it, &value);
69 }
70 
71 static Evas_Object *
_elm_prefs_page_box_add(Evas_Object * obj,Evas_Object * it)72 _elm_prefs_page_box_add(Evas_Object *obj,
73                         Evas_Object *it)
74 {
75    Evas_Object *sbx;
76    double align_x, align_y;
77 
78    evas_object_size_hint_align_get(it, &align_x, &align_y);
79 
80    sbx = elm_box_add(obj);
81    elm_box_horizontal_set(sbx, EINA_TRUE);
82    evas_object_size_hint_weight_set(sbx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
83    evas_object_size_hint_align_set(sbx, align_x, align_y);
84    evas_object_data_set(obj, "sub_box", sbx);
85    evas_object_show(sbx);
86 
87    return sbx;
88 }
89 
90 static void
_elm_prefs_page_item_hints_set(Evas_Object * it,const Elm_Prefs_Item_Iface * iface)91 _elm_prefs_page_item_hints_set(Evas_Object *it,
92                           const Elm_Prefs_Item_Iface *iface)
93 {
94    if (iface && iface->expand_want && iface->expand_want(it))
95      evas_object_size_hint_align_set(it, EVAS_HINT_FILL, EVAS_HINT_FILL);
96 
97    evas_object_size_hint_weight_set(it, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
98 }
99 
100 static void
_elm_prefs_page_pack_setup(Evas_Object * it,Evas_Object * obj,const Elm_Prefs_Item_Iface * iface)101 _elm_prefs_page_pack_setup(Evas_Object *it,
102                                Evas_Object *obj,
103                                const Elm_Prefs_Item_Iface *iface)
104 {
105    Evas_Object *l, *i, *sbx;
106 
107    _elm_prefs_page_item_hints_set(it, iface);
108 
109    l = evas_object_data_get(it, "label_widget");
110    i = evas_object_data_get(it, "icon_widget");
111    if (i)
112      {
113         sbx = _elm_prefs_page_box_add(obj, it);
114         elm_box_pack_end(obj, sbx);
115 
116         evas_object_size_hint_align_set(it, EVAS_HINT_FILL, EVAS_HINT_FILL);
117         evas_object_size_hint_align_set(i, 0.0, EVAS_HINT_FILL);
118         elm_box_pack_end(sbx, i);
119         elm_box_pack_end(sbx, it);
120 
121         if (l) elm_box_pack_before(obj, l, sbx);
122      }
123    else
124      {
125         elm_box_pack_end(obj, it);
126         if (l) elm_box_pack_before(obj, l, it);
127      }
128 }
129 
130 static void
_elm_prefs_page_pack_before_setup(Evas_Object * it,Evas_Object * it_before,Evas_Object * obj,const Elm_Prefs_Item_Iface * iface)131 _elm_prefs_page_pack_before_setup(Evas_Object *it,
132                                       Evas_Object *it_before,
133                                       Evas_Object *obj,
134                                       const Elm_Prefs_Item_Iface *iface)
135 {
136    Evas_Object *l, *i, *sbx;
137 
138    _elm_prefs_page_item_hints_set(it, iface);
139 
140    l = evas_object_data_get(it, "label_widget");
141    i = evas_object_data_get(it, "icon_widget");
142    if (i)
143      {
144         sbx = _elm_prefs_page_box_add(obj, it);
145         elm_box_pack_before(obj, sbx, it_before);
146 
147         evas_object_size_hint_align_set(i, EVAS_HINT_FILL, 0.5);
148         elm_box_pack_end(sbx, i);
149         elm_box_pack_end(sbx, it);
150 
151         if (l) elm_box_pack_before(obj, l, sbx);
152      }
153    else
154      {
155         elm_box_pack_before(obj, it, it_before);
156         if (l) elm_box_pack_before(obj, l, it);
157      }
158 }
159 
160 static void
_elm_prefs_page_pack_after_setup(Evas_Object * it,Evas_Object * it_after,Evas_Object * obj,const Elm_Prefs_Item_Iface * iface)161 _elm_prefs_page_pack_after_setup(Evas_Object *it,
162                                      Evas_Object *it_after,
163                                      Evas_Object *obj,
164                                      const Elm_Prefs_Item_Iface *iface)
165 {
166    Evas_Object *l, *i, *sbx;
167 
168    _elm_prefs_page_item_hints_set(it, iface);
169 
170    l = evas_object_data_get(it, "label_widget");
171    i = evas_object_data_get(it, "icon_widget");
172    if (i)
173      {
174         sbx = _elm_prefs_page_box_add(obj, it);
175         elm_box_pack_after(obj, sbx, it_after);
176 
177         evas_object_size_hint_align_set(i, EVAS_HINT_FILL, 0.5);
178         elm_box_pack_end(sbx, i);
179         elm_box_pack_end(sbx, it);
180 
181         if (l) elm_box_pack_before(obj, l, sbx);
182      }
183    else
184      {
185         elm_box_pack_after(obj, it, it_after);
186         if (l) elm_box_pack_before(obj, l, it);
187      }
188 }
189 
190 void
elm_prefs_horizontal_page_common_pack(Evas_Object * it,Evas_Object * obj,const Elm_Prefs_Item_Iface * iface)191 elm_prefs_horizontal_page_common_pack(Evas_Object *it,
192                                       Evas_Object *obj,
193                                       const Elm_Prefs_Item_Iface *iface)
194 {
195    evas_object_size_hint_align_set(it, 0.5, EVAS_HINT_FILL);
196    _elm_prefs_page_pack_setup(it, obj, iface);
197 }
198 
199 void
elm_prefs_horizontal_page_common_pack_before(Evas_Object * it,Evas_Object * it_before,Evas_Object * obj,const Elm_Prefs_Item_Iface * iface)200 elm_prefs_horizontal_page_common_pack_before(Evas_Object *it,
201                                              Evas_Object *it_before,
202                                              Evas_Object *obj,
203                                              const Elm_Prefs_Item_Iface *iface)
204 {
205    evas_object_size_hint_align_set(it, 0.5, EVAS_HINT_FILL);
206    _elm_prefs_page_pack_before_setup(it, it_before, obj, iface);
207 }
208 
209 void
elm_prefs_horizontal_page_common_pack_after(Evas_Object * it,Evas_Object * it_after,Evas_Object * obj,const Elm_Prefs_Item_Iface * iface)210 elm_prefs_horizontal_page_common_pack_after(Evas_Object *it,
211                                             Evas_Object *it_after,
212                                             Evas_Object *obj,
213                                             const Elm_Prefs_Item_Iface *iface)
214 {
215    evas_object_size_hint_align_set(it, 0.5, EVAS_HINT_FILL);
216    _elm_prefs_page_pack_after_setup(it, it_after, obj, iface);
217 }
218 
219 void
elm_prefs_vertical_page_common_pack(Evas_Object * it,Evas_Object * obj,const Elm_Prefs_Item_Iface * iface)220 elm_prefs_vertical_page_common_pack(Evas_Object *it,
221                                     Evas_Object *obj,
222                                     const Elm_Prefs_Item_Iface *iface)
223 {
224    evas_object_size_hint_align_set(it, EVAS_HINT_FILL, 0.5);
225    _elm_prefs_page_pack_setup(it, obj, iface);
226 }
227 
228 void
elm_prefs_vertical_page_common_pack_before(Evas_Object * it,Evas_Object * it_before,Evas_Object * obj,const Elm_Prefs_Item_Iface * iface)229 elm_prefs_vertical_page_common_pack_before(Evas_Object *it,
230                                            Evas_Object *it_before,
231                                            Evas_Object *obj,
232                                            const Elm_Prefs_Item_Iface *iface)
233 {
234    evas_object_size_hint_align_set(it, EVAS_HINT_FILL, 0.5);
235    _elm_prefs_page_pack_before_setup(it, it_before, obj, iface);
236 }
237 
238 void
elm_prefs_vertical_page_common_pack_after(Evas_Object * it,Evas_Object * it_after,Evas_Object * obj,const Elm_Prefs_Item_Iface * iface)239 elm_prefs_vertical_page_common_pack_after(Evas_Object *it,
240                                           Evas_Object *it_after,
241                                           Evas_Object *obj,
242                                           const Elm_Prefs_Item_Iface *iface)
243 {
244    evas_object_size_hint_align_set(it, EVAS_HINT_FILL, 0.5);
245    _elm_prefs_page_pack_after_setup(it, it_after, obj, iface);
246 }
247 
248 void
elm_prefs_page_common_unpack(Evas_Object * it,Evas_Object * obj)249 elm_prefs_page_common_unpack(Evas_Object *it,
250                              Evas_Object *obj)
251 {
252    Evas_Object *l, *i, *sbx;
253 
254    l = evas_object_data_get(it, "label_widget");
255    if (l) elm_box_unpack(obj, l);
256 
257    sbx = evas_object_data_get(it, "sub_box");
258    i = evas_object_data_get(it, "icon_widget");
259 
260    if (i && sbx)
261      {
262         elm_box_unpack_all(sbx);
263         elm_box_unpack(obj, sbx);
264         evas_object_del(sbx);
265      }
266    else
267      elm_box_unpack(obj, it);
268 }
269 
270 EAPI int
elm_modapi_init(void * m EINA_UNUSED)271 elm_modapi_init(void *m EINA_UNUSED)
272 {
273    _elm_prefs_log_dom = eina_log_domain_register
274        ("elm-prefs", EINA_COLOR_YELLOW);
275 
276    elm_prefs_item_iface_register(_elm_prefs_item_widgets);
277    elm_prefs_page_iface_register(_elm_prefs_page_widgets);
278 
279    return 1; // succeed always
280 }
281 
282 EAPI int
elm_modapi_shutdown(void * m EINA_UNUSED)283 elm_modapi_shutdown(void *m EINA_UNUSED)
284 {
285    elm_prefs_item_iface_unregister(_elm_prefs_item_widgets);
286    elm_prefs_page_iface_unregister(_elm_prefs_page_widgets);
287 
288    if (_elm_prefs_log_dom >= 0) eina_log_domain_unregister(_elm_prefs_log_dom);
289    _elm_prefs_log_dom = -1;
290 
291    return 1; // succeed always
292 }
293