summaryrefslogtreecommitdiff
path: root/src/modules/prefs/prefs_iface.c
blob: 5d1b12bcc121ee648949f4a6a1fc6abbb75a841b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#include "Elementary.h"
#include "private.h"

/* including declaration of each prefs item implementation iface struct */
#define PREFS_ADD(w_name) \
  extern const Elm_Prefs_Item_Iface prefs_##w_name##_impl;

#include "item_widgets.inc"

#undef PREFS_ADD

int _elm_prefs_log_dom = -1;

/* now building on array of those, to be put on a hash for lookup */
static Elm_Prefs_Item_Iface_Info _elm_prefs_item_widgets[] =
{
#define PREFS_ADD(w_name) \
  {"elm/" #w_name, &prefs_##w_name##_impl},

#include "item_widgets.inc"

#undef PREFS_ADD
   {NULL, NULL}
};

/* including declaration of each prefs page implementation iface struct */
#define PREFS_ADD(w_name) \
  extern const Elm_Prefs_Page_Iface prefs_##w_name##_impl;

#include "page_widgets.inc"

#undef PREFS_ADD

/* now building on array of those, to be put on a hash for lookup */
static Elm_Prefs_Page_Iface_Info _elm_prefs_page_widgets[] =
{
#define PREFS_ADD(w_name) \
  {"elm/" #w_name, &prefs_##w_name##_impl},

#include "page_widgets.inc"

#undef PREFS_ADD
   {NULL, NULL}
};

Eina_Bool
elm_prefs_page_item_value_set(Evas_Object *it,
                              const Elm_Prefs_Item_Iface *iface,
                              Eina_Bool val)
{
   Eina_Value value;

   if (!iface->value_set) return EINA_FALSE;

   if ((!eina_value_setup(&value, EINA_VALUE_TYPE_UCHAR)) ||
       (!eina_value_set(&value, val)))
     return EINA_FALSE;

   return iface->value_set(it, &value);
}

static Evas_Object *
_elm_prefs_page_box_add(Evas_Object *obj,
                        Evas_Object *it)
{
   Evas_Object *sbx;
   double align_x, align_y;

   evas_object_size_hint_align_get(it, &align_x, &align_y);

   sbx = elm_box_add(obj);
   elm_box_horizontal_set(sbx, EINA_TRUE);
   evas_object_size_hint_weight_set(sbx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(sbx, align_x, align_y);
   evas_object_data_set(obj, "sub_box", sbx);
   evas_object_show(sbx);

   return sbx;
}

static void
_elm_prefs_page_item_hints_set(Evas_Object *it,
                          const Elm_Prefs_Item_Iface *iface)
{
   if (iface && iface->expand_want && iface->expand_want(it))
     evas_object_size_hint_align_set(it, EVAS_HINT_FILL, EVAS_HINT_FILL);

   evas_object_size_hint_weight_set(it, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
}

static void
_elm_prefs_page_pack_setup(Evas_Object *it,
                               Evas_Object *obj,
                               const Elm_Prefs_Item_Iface *iface)
{
   Evas_Object *l, *i, *sbx;

   _elm_prefs_page_item_hints_set(it, iface);

   l = evas_object_data_get(it, "label_widget");
   i = evas_object_data_get(it, "icon_widget");
   if (i)
     {
        sbx = _elm_prefs_page_box_add(obj, it);
        elm_box_pack_end(obj, sbx);

        evas_object_size_hint_align_set(it, EVAS_HINT_FILL, EVAS_HINT_FILL);
        evas_object_size_hint_align_set(i, 0.0, EVAS_HINT_FILL);
        elm_box_pack_end(sbx, i);
        elm_box_pack_end(sbx, it);

        if (l) elm_box_pack_before(obj, l, sbx);
     }
   else
     {
        elm_box_pack_end(obj, it);
        if (l) elm_box_pack_before(obj, l, it);
     }
}

static void
_elm_prefs_page_pack_before_setup(Evas_Object *it,
                                      Evas_Object *it_before,
                                      Evas_Object *obj,
                                      const Elm_Prefs_Item_Iface *iface)
{
   Evas_Object *l, *i, *sbx;

   _elm_prefs_page_item_hints_set(it, iface);

   l = evas_object_data_get(it, "label_widget");
   i = evas_object_data_get(it, "icon_widget");
   if (i)
     {
        sbx = _elm_prefs_page_box_add(obj, it);
        elm_box_pack_before(obj, sbx, it_before);

        evas_object_size_hint_align_set(i, EVAS_HINT_FILL, 0.5);
        elm_box_pack_end(sbx, i);
        elm_box_pack_end(sbx, it);

        if (l) elm_box_pack_before(obj, l, sbx);
     }
   else
     {
        elm_box_pack_before(obj, it, it_before);
        if (l) elm_box_pack_before(obj, l, it);
     }
}

static void
_elm_prefs_page_pack_after_setup(Evas_Object *it,
                                     Evas_Object *it_after,
                                     Evas_Object *obj,
                                     const Elm_Prefs_Item_Iface *iface)
{
   Evas_Object *l, *i, *sbx;

   _elm_prefs_page_item_hints_set(it, iface);

   l = evas_object_data_get(it, "label_widget");
   i = evas_object_data_get(it, "icon_widget");
   if (i)
     {
        sbx = _elm_prefs_page_box_add(obj, it);
        elm_box_pack_after(obj, sbx, it_after);

        evas_object_size_hint_align_set(i, EVAS_HINT_FILL, 0.5);
        elm_box_pack_end(sbx, i);
        elm_box_pack_end(sbx, it);

        if (l) elm_box_pack_before(obj, l, sbx);
     }
   else
     {
        elm_box_pack_after(obj, it, it_after);
        if (l) elm_box_pack_before(obj, l, it);
     }
}

void
elm_prefs_horizontal_page_common_pack(Evas_Object *it,
                                      Evas_Object *obj,
                                      const Elm_Prefs_Item_Iface *iface)
{
   evas_object_size_hint_align_set(it, 0.5, EVAS_HINT_FILL);
   _elm_prefs_page_pack_setup(it, obj, iface);
}

void
elm_prefs_horizontal_page_common_pack_before(Evas_Object *it,
                                             Evas_Object *it_before,
                                             Evas_Object *obj,
                                             const Elm_Prefs_Item_Iface *iface)
{
   evas_object_size_hint_align_set(it, 0.5, EVAS_HINT_FILL);
   _elm_prefs_page_pack_before_setup(it, it_before, obj, iface);
}

void
elm_prefs_horizontal_page_common_pack_after(Evas_Object *it,
                                            Evas_Object *it_after,
                                            Evas_Object *obj,
                                            const Elm_Prefs_Item_Iface *iface)
{
   evas_object_size_hint_align_set(it, 0.5, EVAS_HINT_FILL);
   _elm_prefs_page_pack_after_setup(it, it_after, obj, iface);
}

void
elm_prefs_vertical_page_common_pack(Evas_Object *it,
                                    Evas_Object *obj,
                                    const Elm_Prefs_Item_Iface *iface)
{
   evas_object_size_hint_align_set(it, EVAS_HINT_FILL, 0.5);
   _elm_prefs_page_pack_setup(it, obj, iface);
}

void
elm_prefs_vertical_page_common_pack_before(Evas_Object *it,
                                           Evas_Object *it_before,
                                           Evas_Object *obj,
                                           const Elm_Prefs_Item_Iface *iface)
{
   evas_object_size_hint_align_set(it, EVAS_HINT_FILL, 0.5);
   _elm_prefs_page_pack_before_setup(it, it_before, obj, iface);
}

void
elm_prefs_vertical_page_common_pack_after(Evas_Object *it,
                                          Evas_Object *it_after,
                                          Evas_Object *obj,
                                          const Elm_Prefs_Item_Iface *iface)
{
   evas_object_size_hint_align_set(it, EVAS_HINT_FILL, 0.5);
   _elm_prefs_page_pack_after_setup(it, it_after, obj, iface);
}

void
elm_prefs_page_common_unpack(Evas_Object *it,
                             Evas_Object *obj)
{
   Evas_Object *l, *i, *sbx;

   l = evas_object_data_get(it, "label_widget");
   if (l) elm_box_unpack(obj, l);

   sbx = evas_object_data_get(it, "sub_box");
   i = evas_object_data_get(it, "icon_widget");

   if (i && sbx)
     {
        elm_box_unpack_all(sbx);
        elm_box_unpack(obj, sbx);
        evas_object_del(sbx);
     }
   else
     elm_box_unpack(obj, it);
}

EAPI int
elm_modapi_init(void *m __UNUSED__)
{
   _elm_prefs_log_dom = eina_log_domain_register
       ("elm-prefs", EINA_COLOR_YELLOW);

   elm_prefs_item_iface_register(_elm_prefs_item_widgets);
   elm_prefs_page_iface_register(_elm_prefs_page_widgets);

   return 1; // succeed always
}

EAPI int
elm_modapi_shutdown(void *m __UNUSED__)
{
   elm_prefs_item_iface_unregister(_elm_prefs_item_widgets);
   elm_prefs_page_iface_unregister(_elm_prefs_page_widgets);

   if (_elm_prefs_log_dom >= 0) eina_log_domain_unregister(_elm_prefs_log_dom);
   _elm_prefs_log_dom = -1;

   return 1; // succeed always
}