summaryrefslogtreecommitdiff
path: root/src/bin/e_widget_toolbar.c
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2008-11-21 03:59:30 +0000
committerCarsten Haitzler <raster@rasterman.com>2008-11-21 03:59:30 +0000
commit5b50a2b89e2d3a2098ff9e514f2bc17f3fc76fb7 (patch)
treebe50a9845baafaf94d167e8013bb57ab7e6fc3e3 /src/bin/e_widget_toolbar.c
parentf8fc0ae092c80501c597efc7b3fd7c5345a45d20 (diff)
* shortening config category titles.
* remove illume custom config dialog - use normal one * add toolbar used in config dialog. will be used for more. makes ui more compact and flexible. * make dialog windows optionally ALWAYS be "normal windows". * config module exports a config gadget now - illume doesnt need it anymore SVN revision: 37721
Diffstat (limited to 'src/bin/e_widget_toolbar.c')
-rw-r--r--src/bin/e_widget_toolbar.c361
1 files changed, 361 insertions, 0 deletions
diff --git a/src/bin/e_widget_toolbar.c b/src/bin/e_widget_toolbar.c
new file mode 100644
index 0000000..7fba140
--- /dev/null
+++ b/src/bin/e_widget_toolbar.c
@@ -0,0 +1,361 @@
1/*
2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3 */
4#include "e.h"
5
6typedef struct _E_Widget_Data E_Widget_Data;
7typedef struct _Item Item;
8struct _E_Widget_Data
9{
10 Evas_Object *o_base, *o_box, *o_scrollframe0;
11 int icon_w, icon_h;
12 Eina_List *items;
13 Evas_Bool scrollable : 1;
14};
15
16struct _Item
17{
18 Evas_Object *o_toolbar, *o_base, *o_icon;
19 void (*func) (void *data1, void *data2);
20 const void *data1, *data2;
21 Evas_Bool selected : 1;
22};
23
24static void _e_wid_del_hook(Evas_Object *obj);
25static void _e_wid_focus_hook(Evas_Object *obj);
26static void _e_wid_focus_steal(void *data, Evas *e, Evas_Object *obj, void *event_info);
27static void _e_wid_disable_hook(Evas_Object *obj);
28static void _e_wid_signal_cb1(void *data, Evas_Object *obj, const char *emission, const char *source);
29static void _e_wid_cb_scrollframe_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
30static void _e_wid_cb_key_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
31static void _item_show(Item *it);
32
33/* local subsystem functions */
34
35/* externally accessible functions */
36EAPI Evas_Object *
37e_widget_toolbar_add(Evas *evas, int icon_w, int icon_h)
38{
39 Evas_Object *obj, *o;
40 E_Widget_Data *wd;
41 Evas_Coord mw = 0, mh = 0;
42
43 obj = e_widget_add(evas);
44
45 e_widget_del_hook_set(obj, _e_wid_del_hook);
46 e_widget_focus_hook_set(obj, _e_wid_focus_hook);
47 e_widget_disable_hook_set(obj, _e_wid_disable_hook);
48 wd = calloc(1, sizeof(E_Widget_Data));
49 e_widget_data_set(obj, wd);
50 wd->icon_w = icon_w;
51 wd->icon_h = icon_h;
52
53 o = e_scrollframe_add(evas);
54 wd->o_base = o;
55 e_scrollframe_custom_theme_set(o, "base/theme/widgets", "e/widgets/toolbar");
56 e_scrollframe_single_dir_set(o, 1);
57 e_scrollframe_policy_set(o, E_SCROLLFRAME_POLICY_AUTO, E_SCROLLFRAME_POLICY_OFF);
58 e_scrollframe_thumbscroll_force(o, 1);
59 evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE,
60 _e_wid_cb_scrollframe_resize, obj);
61 evas_object_event_callback_add(e_scrollframe_edje_object_get(wd->o_base),
62 EVAS_CALLBACK_MOUSE_DOWN,
63 _e_wid_focus_steal, obj);
64 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN,
65 _e_wid_cb_key_down, obj);
66 evas_object_show(o);
67 e_widget_sub_object_add(obj, o);
68 e_widget_resize_object_set(obj, o);
69
70 o = e_box_add(evas);
71 wd->o_box = o;
72 e_box_orientation_set(o, 1);
73 e_box_homogenous_set(o, 1);
74 e_scrollframe_child_set(wd->o_base, o);
75 e_widget_sub_object_add(obj, o);
76 evas_object_show(o);
77
78 edje_object_size_min_calc
79 (e_scrollframe_edje_object_get(wd->o_base), &mw, &mh);
80 e_widget_min_size_set(obj, mw, mh);
81
82 return obj;
83}
84
85EAPI void
86e_widget_toolbar_item_append(Evas_Object *obj, Evas_Object *icon, const char *label, void (*func) (void *data1, void *data2), const void *data1, const void *data2)
87{
88 E_Widget_Data *wd;
89 Evas_Object *o;
90 Item *it;
91 Evas_Coord mw = 0, mh = 0, vw = 0, vh = 0;
92
93 wd = e_widget_data_get(obj);
94 o = edje_object_add(evas_object_evas_get(obj));
95 e_theme_edje_object_set(o, "base/theme/widgets",
96 "e/widgets/toolbar/item");
97 it = E_NEW(Item, 1);
98 it->o_toolbar = obj;
99 it->o_base = o;
100 it->o_icon = icon;
101 it->func = func;
102 it->data1 = data1;
103 it->data2 = data2;
104 wd->items = eina_list_append(wd->items, it);
105
106 edje_object_signal_callback_add(o, "e,action,click", "e",
107 _e_wid_signal_cb1, it);
108 edje_extern_object_min_size_set(icon, wd->icon_w, wd->icon_h);
109 edje_object_part_swallow(o, "e.swallow.icon", icon);
110 evas_object_show(icon);
111 edje_object_part_text_set(o, "e.text.label", label);
112 edje_object_size_min_calc(o, &mw, &mh);
113 e_widget_sub_object_add(obj, o);
114 e_box_pack_end(wd->o_box, o);
115 evas_object_show(o);
116 e_box_pack_options_set(o,
117 1, 1, /* fill */
118 0, 0, /* expand */
119 0.5, 0.5, /* align */
120 mw, mh, /* min */
121 9999, 9999 /* max */
122 );
123 e_box_min_size_get(wd->o_box, &mw, &mh);
124 evas_object_resize(wd->o_box, mw, mh);
125 evas_object_resize(wd->o_base, 500, 500);
126 e_scrollframe_child_viewport_size_get(wd->o_base, &vw, &vh);
127 if (wd->scrollable)
128 e_widget_min_size_set(obj, 500 - vw, mh + (500 - vh));
129 else
130 e_widget_min_size_set(obj, mw + (500 - vw), mh + (500 - vh));
131}
132
133EAPI void
134e_widget_toolbar_item_select(Evas_Object *obj, int num)
135{
136 E_Widget_Data *wd;
137 Eina_List *l;
138 Item *it;
139 int i;
140
141 wd = e_widget_data_get(obj);
142 for (i = 0, l = wd->items; l; l = l->next, i++)
143 {
144 it = l->data;
145 if (i == num)
146 {
147 if (!it->selected)
148 {
149 it->selected = 1;
150 edje_object_signal_emit(it->o_base, "e,state,selected", "e");
151 edje_object_signal_emit(it->o_icon, "e,state,selected", "e");
152 _item_show(it);
153 if (it->func) it->func(it->data1, it->data2);
154 }
155 }
156 else
157 {
158 if (it->selected)
159 {
160 it->selected = 0;
161 edje_object_signal_emit(it->o_base, "e,state,unselected", "e");
162 edje_object_signal_emit(it->o_icon, "e,state,unselected", "e");
163 }
164 }
165 }
166}
167
168EAPI void
169e_widget_toolbar_scrollable_set(Evas_Object *obj, Evas_Bool scrollable)
170{
171 E_Widget_Data *wd;
172 Evas_Coord mw = 0, mh = 0, vw = 0, vh = 0;
173
174 wd = e_widget_data_get(obj);
175 wd->scrollable = scrollable;
176 e_box_min_size_get(wd->o_box, &mw, &mh);
177 evas_object_resize(wd->o_box, mw, mh);
178 evas_object_resize(wd->o_base, 500, 500);
179 e_scrollframe_child_viewport_size_get(wd->o_base, &vw, &vh);
180 if (wd->scrollable)
181 e_widget_min_size_set(obj, 500 - vw, mh + (500 - vh));
182 else
183 e_widget_min_size_set(obj, mw + (500 - vw), mh + (500 - vh));
184}
185
186static void
187_e_wid_del_hook(Evas_Object *obj)
188{
189 E_Widget_Data *wd;
190
191 wd = e_widget_data_get(obj);
192 while (wd->items)
193 {
194 Item *it;
195
196 it = wd->items->data;
197 evas_object_del(it->o_base);
198 evas_object_del(it->o_icon);
199 free(it);
200 wd->items = eina_list_remove_list(wd->items, wd->items);
201 }
202 free(wd);
203}
204
205static void
206_e_wid_disable_hook(Evas_Object *obj)
207{
208 E_Widget_Data *wd;
209
210 wd = e_widget_data_get(obj);
211 if (e_widget_disabled_get(obj))
212 edje_object_signal_emit
213 (e_scrollframe_edje_object_get(wd->o_base), "e,state,disabled", "e");
214 else
215 edje_object_signal_emit
216 (e_scrollframe_edje_object_get(wd->o_base), "e,state,enabled", "e");
217}
218
219static void
220_e_wid_signal_cb1(void *data, Evas_Object *obj, const char *emission, const char *source)
221{
222 Item *it, *it2;
223 E_Widget_Data *wd;
224 Eina_List *l;
225
226 it = data;
227 if (it->selected) return;
228 wd = e_widget_data_get(it->o_toolbar);
229 for (l = wd->items; l; l = l->next)
230 {
231 it2 = l->data;
232 if (it2->selected)
233 {
234 it2->selected = 0;
235 edje_object_signal_emit(it2->o_base, "e,state,unselected", "e");
236 edje_object_signal_emit(it2->o_icon, "e,state,unselected", "e");
237 break;
238 }
239 }
240 it->selected = 1;
241 edje_object_signal_emit(it->o_base, "e,state,selected", "e");
242 edje_object_signal_emit(it->o_icon, "e,state,selected", "e");
243 _item_show(it);
244 if (it->func) it->func(it->data1, it->data2);
245}
246
247static void
248_e_wid_cb_scrollframe_resize(void *data, Evas *e, Evas_Object *obj, void *event_info)
249{
250 E_Widget_Data *wd;
251 Evas_Coord mw, mh, vw, vh, w, h;
252 Eina_List *l;
253 Item *it;
254
255 wd = e_widget_data_get(data);
256 e_scrollframe_child_viewport_size_get(wd->o_base, &vw, &vh);
257 e_box_min_size_get(wd->o_box, &mw, &mh);
258 evas_object_geometry_get(wd->o_box, NULL, NULL, &w, &h);
259 if (vw >= mw)
260 {
261 if (w != vw) evas_object_resize(wd->o_box, vw, h);
262 }
263 for (l = wd->items; l; l = l->next)
264 {
265 it = l->data;
266 if (it->selected)
267 {
268 _item_show(it);
269 break;
270 }
271 }
272}
273
274static void
275_e_wid_cb_key_down(void *data, Evas *evas, Evas_Object *obj, void *event_info)
276{
277 Evas_Event_Key_Down *ev;
278 E_Widget_Data *wd;
279 Eina_List *l;
280 Item *it = NULL, *it2 = NULL;
281
282 ev = event_info;
283 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
284 wd = e_widget_data_get(data);
285 if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")) ||
286 (!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left"))
287 )
288 {
289 for (l = wd->items; l; l = l->next)
290 {
291 it = l->data;
292 if (it->selected)
293 {
294 if (l->prev) it2 = l->prev->data;
295 break;
296 }
297 }
298 }
299 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")) ||
300 (!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right"))
301 )
302 {
303 for (l = wd->items; l; l = l->next)
304 {
305 it = l->data;
306 if (it->selected)
307 {
308 if (l->next) it2 = l->next->data;
309 break;
310 }
311 }
312 }
313 if ((it) && (it2))
314 {
315 it->selected = 0;
316 edje_object_signal_emit(it->o_base, "e,state,unselected", "e");
317 edje_object_signal_emit(it->o_icon, "e,state,unselected", "e");
318 it2->selected = 1;
319 edje_object_signal_emit(it2->o_base, "e,state,selected", "e");
320 edje_object_signal_emit(it2->o_icon, "e,state,selected", "e");
321 _item_show(it2);
322 if (it2->func) it->func(it2->data1, it2->data2);
323 }
324}
325
326static void
327_e_wid_focus_hook(Evas_Object *obj)
328{
329 E_Widget_Data *wd;
330
331 wd = e_widget_data_get(obj);
332 if (e_widget_focus_get(obj))
333 {
334 edje_object_signal_emit(wd->o_base, "e,state,focused", "e");
335 evas_object_focus_set(obj, 1);
336 }
337 else
338 {
339 edje_object_signal_emit(wd->o_base, "e,state,unfocused", "e");
340 evas_object_focus_set(obj, 0);
341 }
342}
343
344static void
345_e_wid_focus_steal(void *data, Evas *e, Evas_Object *obj, void *event_info)
346{
347 e_widget_focus_steal(data);
348}
349
350static void
351_item_show(Item *it)
352{
353 E_Widget_Data *wd;
354 Evas_Coord x, y, w, h, bx, by;
355
356 wd = e_widget_data_get(it->o_toolbar);
357 evas_object_geometry_get(wd->o_box, &bx, &by, NULL, NULL);
358 evas_object_geometry_get(it->o_base, &x, &y, &w, &h);
359 e_scrollframe_child_region_show(wd->o_base, x - bx, y - by, w, h);
360}
361