1 #include <Elementary.h>
5 * @defgroup Conformant Conformant
7 * The aim is to provide a widget that can be used in elementary apps to
8 * account for space taken up by the indicator, virtual keypad & softkey windows when running
9 * the illume2 module of E17.
12 typedef struct _Widget_Data Widget_Data;
16 Evas_Object *shelf, *panel, *virtualkeypad;
18 Evas_Object *scroller;
19 #ifdef HAVE_ELEMENTARY_X
20 Ecore_Event_Handler *prop_hdl;
21 Ecore_X_Virtual_Keyboard_State vkb_state;
24 Ecore_Animator *animator; // animaton timer
25 double start; // time started
26 Evas_Coord auto_x, auto_y; // desired delta
27 Evas_Coord x, y; // current delta
31 /* Enum to identify conformant swallow parts */
32 typedef enum _Conformant_Part_Type Conformant_Part_Type;
33 enum _Conformant_Part_Type
35 ELM_CONFORM_INDICATOR_PART = 1,
36 ELM_CONFORM_VIRTUAL_KEYPAD_PART = 2,
37 ELM_CONFORM_SOFTKEY_PART = 4
39 #define SUB_TYPE_COUNT 2
40 static char *sub_type[SUB_TYPE_COUNT] = { "scroller", "genlist" };
42 /* local function prototypes */
43 static const char *widtype = NULL;
44 static void _del_pre_hook(Evas_Object *obj);
45 static void _del_hook(Evas_Object *obj);
46 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
47 static void _theme_hook(Evas_Object *obj);
49 _swallow_conformant_parts(Evas_Object *obj);
51 _conformant_part_size_set(Evas_Object *obj, Evas_Object *sobj, Evas_Coord sx,
52 Evas_Coord sy, Evas_Coord sw, Evas_Coord sh);
54 _conformant_part_sizing_eval(Evas_Object *obj, Conformant_Part_Type part_type);
56 _conformant_move_resize_event_cb(void *data, Evas *e, Evas_Object *obj,
58 static void _sizing_eval(Evas_Object *obj);
59 static Eina_Bool _prop_change(void *data, int type, void *event);
63 _del_pre_hook(Evas_Object *obj)
65 Widget_Data *wd = elm_widget_data_get(obj);
67 #ifdef HAVE_ELEMENTARY_X
68 if (wd->prop_hdl) ecore_event_handler_del(wd->prop_hdl);
73 _del_hook(Evas_Object *obj)
75 Widget_Data *wd = elm_widget_data_get(obj);
81 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
83 Widget_Data *wd = elm_widget_data_get(obj);
85 edje_object_mirrored_set(wd->base, rtl);
89 _theme_hook(Evas_Object *obj)
91 Widget_Data *wd = elm_widget_data_get(obj);
94 _elm_widget_mirrored_reload(obj);
95 _mirrored_set(obj, elm_widget_mirrored_get(obj));
96 _elm_theme_object_set(obj, wd->base, "conformant", "base", elm_widget_style_get(obj));
97 _swallow_conformant_parts(obj);
100 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->content);
101 edje_object_scale_set(wd->base, elm_widget_scale_get(obj) * _elm_config->scale);
106 _sizing_eval(Evas_Object *obj)
108 Widget_Data *wd = elm_widget_data_get(obj);
109 Evas_Coord mw = -1, mh = -1;
111 edje_object_size_min_calc(wd->base, &mw, &mh);
112 evas_object_size_hint_min_set(obj, mw, mh);
113 evas_object_size_hint_max_set(obj, -1, -1);
117 _conformant_part_size_set(Evas_Object *obj, Evas_Object *sobj, Evas_Coord sx,
118 Evas_Coord sy, Evas_Coord sw, Evas_Coord sh)
120 Evas_Coord cx, cy, cw, ch;
121 Evas_Coord part_height = 0, part_width = 0;
123 evas_object_geometry_get(obj, &cx, &cy, &cw, &ch);
125 /* Part overlapping with conformant */
126 if ((cx < (sx+sw)) && ((cx+cw) > sx) && (cy < (sy+sh)) && ((cy+ch) > sy))
128 part_height = MIN((cy+ch), (sy+sh)) - MAX(cy, sy);
129 part_width = MIN((cx+cw), (sx+sw)) - MAX(cx, sx);
132 evas_object_size_hint_min_set(sobj, part_width, part_height);
133 evas_object_size_hint_max_set(sobj, part_width, part_height);
137 _conformant_part_sizing_eval(Evas_Object *obj, Conformant_Part_Type part_type)
139 #ifdef HAVE_ELEMENTARY_X
140 Ecore_X_Window zone, xwin;
141 int sx = -1, sy = -1, sw = -1, sh = -1;
142 Widget_Data *wd = elm_widget_data_get(obj);
146 xwin = elm_win_xwindow_get(obj);
147 zone = ecore_x_e_illume_zone_get(xwin);
149 if (part_type & ELM_CONFORM_INDICATOR_PART)
151 ecore_x_e_illume_indicator_geometry_get(zone, &sx, &sy, &sw, &sh);
152 _conformant_part_size_set(obj, wd->shelf, sx, sy, sw, sh);
154 if (part_type & ELM_CONFORM_VIRTUAL_KEYPAD_PART)
156 ecore_x_e_illume_keyboard_geometry_get(zone, &sx, &sy, &sw, &sh);
157 _conformant_part_size_set(obj,wd->virtualkeypad, sx, sy, sw, sh);
159 if (part_type & ELM_CONFORM_SOFTKEY_PART)
161 ecore_x_e_illume_softkey_geometry_get(zone, &sx, &sy, &sw, &sh);
162 _conformant_part_size_set(obj, wd->panel, sx, sy, sw, sh);
168 _swallow_conformant_parts(Evas_Object *obj)
170 Widget_Data *wd = elm_widget_data_get(obj);
175 wd->shelf = evas_object_rectangle_add(evas_object_evas_get(obj));
176 elm_widget_sub_object_add(obj, wd->shelf);
177 evas_object_size_hint_min_set(wd->shelf, -1, 0);
178 evas_object_size_hint_max_set(wd->shelf, -1, 0);
181 _conformant_part_sizing_eval(obj, ELM_CONFORM_INDICATOR_PART);
183 evas_object_color_set(wd->shelf, 0, 0, 0, 0);
184 edje_object_part_swallow(wd->base, "elm.swallow.shelf", wd->shelf);
186 if (!wd->virtualkeypad)
188 wd->virtualkeypad = evas_object_rectangle_add(evas_object_evas_get(obj));
189 elm_widget_sub_object_add(obj, wd->virtualkeypad);
190 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
191 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
194 _conformant_part_sizing_eval(obj, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
196 evas_object_color_set(wd->virtualkeypad, 0, 0, 0, 0);
197 edje_object_part_swallow(wd->base, "elm.swallow.virtualkeypad",
202 wd->panel = evas_object_rectangle_add(evas_object_evas_get(obj));
203 elm_widget_sub_object_add(obj, wd->panel);
204 evas_object_size_hint_min_set(wd->panel, -1, 0);
205 evas_object_size_hint_max_set(wd->panel, -1, 0);
208 _conformant_part_sizing_eval(obj, ELM_CONFORM_SOFTKEY_PART);
210 evas_object_color_set(wd->panel, 0, 0, 0, 0);
211 edje_object_part_swallow(wd->base, "elm.swallow.panel", wd->panel);
215 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
217 Widget_Data *wd = elm_widget_data_get(data);
223 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
225 Widget_Data *wd = elm_widget_data_get(obj);
226 Evas_Object *sub = event_info;
228 if (sub == wd->content)
230 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
231 _changed_size_hints, obj);
237 /* unused now - but meant to be for making sure the focused widget is always
238 * visible when the vkbd comes and goes by moving the conformant obj (and thus
239 * its children) to show the focused widget (and if focus changes follow)
242 _focus_object_get(const Evas_Object *obj)
244 Evas_Object *win, *foc;
246 win = elm_widget_top_get(obj);
247 if (!win) return NULL;
248 foc = elm_widget_top_get(win);
252 _focus_object_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
254 evas_object_geometry_get(obj, x, y, w, h);
258 _focus_change_del(void *data, Evas_Object *obj, void *event_info)
260 // called from toplevel when the focused window shanges
264 _autoscroll_move(Evas_Object *obj)
266 // move conformant edje by delta to show focused widget
270 _autoscroll_mode_enable(Evas_Object *obj)
272 // called when autoscroll mode should be on - content area smaller than
274 // 1. get focused object
275 // 2. if not in visible conformant area calculate delta needed to
277 // 3. store delta and call _autoscroll_move() which either asanimates
278 // or jumps right there
282 _autoscroll_mode_disable(Evas_Object *obj)
284 // called when autoscroll mode should be off - set delta to 0 and
285 // call _autoscroll_move()
290 _conformant_move_resize_event_cb(void *data __UNUSED__, Evas *e __UNUSED__,
292 void *event_info __UNUSED__)
294 Conformant_Part_Type part_type;
295 Widget_Data *wd = elm_widget_data_get(obj);
298 part_type = (ELM_CONFORM_INDICATOR_PART |
299 ELM_CONFORM_VIRTUAL_KEYPAD_PART |
300 ELM_CONFORM_SOFTKEY_PART);
301 _conformant_part_sizing_eval(obj, part_type);
305 _content_resize_event_cb(void *data, Evas *e __UNUSED__,
306 Evas_Object *obj __UNUSED__,
307 void *event_info __UNUSED__)
309 Evas_Object *focus_obj;
310 Evas_Object *conformant = (Evas_Object *) data;
311 Widget_Data *wd = elm_widget_data_get(conformant);
314 #ifdef HAVE_ELEMENTARY_X
315 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF) return;
318 focus_obj = elm_widget_focused_object_get(conformant);
321 Evas_Coord x, y, w, h;
323 elm_widget_show_region_get(focus_obj, &x, &y, &w, &h);
325 if (h < _elm_config->finger_size)
326 h = _elm_config->finger_size;
328 elm_widget_show_region_set(focus_obj, x, y, w, h, EINA_TRUE);
333 _update_autoscroll_objs(void *data)
337 Evas_Object *sub, *top_scroller = NULL;
338 Evas_Object *conformant = (Evas_Object *) data;
339 Widget_Data *wd = elm_widget_data_get(data);
343 sub = elm_widget_focused_object_get(conformant);
344 //Look up for Top most scroller in the Focus Object hierarchy inside Conformant.
348 type = elm_widget_type_get(sub);
349 if (!strcmp(type, "conformant")) break;
350 for (i = 0; i < SUB_TYPE_COUNT; i++)
351 if (!strcmp(type, sub_type[i]))
356 sub = elm_object_parent_widget_get(sub);
359 //If the scroller got changed by app, replace it.
360 if (top_scroller != wd->scroller)
362 if (wd->scroller) evas_object_event_callback_del(wd->scroller,
363 EVAS_CALLBACK_RESIZE,
364 _content_resize_event_cb);
365 wd->scroller = top_scroller;
366 if (wd->scroller) evas_object_event_callback_add(wd->scroller,
367 EVAS_CALLBACK_RESIZE,
368 _content_resize_event_cb,
374 _prop_change(void *data, int type __UNUSED__, void *event)
376 #ifdef HAVE_ELEMENTARY_X
377 Ecore_X_Event_Window_Property *ev;
378 Widget_Data *wd = elm_widget_data_get(data);
379 if (!wd) return ECORE_CALLBACK_PASS_ON;
381 if (ev->atom == ECORE_X_ATOM_E_ILLUME_ZONE)
383 Conformant_Part_Type part_type;
385 part_type = (ELM_CONFORM_INDICATOR_PART |
386 ELM_CONFORM_VIRTUAL_KEYPAD_PART |
387 ELM_CONFORM_SOFTKEY_PART);
388 _conformant_part_sizing_eval(data, part_type);
390 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_GEOMETRY)
391 _conformant_part_sizing_eval(data, ELM_CONFORM_INDICATOR_PART);
392 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_SOFTKEY_GEOMETRY)
393 _conformant_part_sizing_eval(data, ELM_CONFORM_SOFTKEY_PART);
394 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_KEYBOARD_GEOMETRY)
395 _conformant_part_sizing_eval(data, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
396 else if (ev->atom == ECORE_X_ATOM_E_VIRTUAL_KEYBOARD_STATE)
400 zone = ecore_x_e_illume_zone_get(ev->win);
401 wd->vkb_state = ecore_x_e_virtual_keyboard_state_get(zone);
402 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF)
404 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
405 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
408 _update_autoscroll_objs(data);
412 return ECORE_CALLBACK_PASS_ON;
416 * Add a new Conformant object
418 * @param parent The parent object
419 * @return The new conformant object or NULL if it cannot be created
421 * @ingroup Conformant
424 elm_conformant_add(Evas_Object *parent)
430 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
432 ELM_SET_WIDTYPE(widtype, "conformant");
433 elm_widget_type_set(obj, "conformant");
434 elm_widget_sub_object_add(parent, obj);
435 elm_widget_data_set(obj, wd);
436 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
437 elm_widget_del_hook_set(obj, _del_hook);
438 elm_widget_theme_hook_set(obj, _theme_hook);
439 elm_widget_can_focus_set(obj, EINA_FALSE);
441 wd->base = edje_object_add(e);
442 _elm_theme_object_set(obj, wd->base, "conformant", "base", "default");
443 elm_widget_resize_object_set(obj, wd->base);
444 _swallow_conformant_parts(obj);
446 #ifdef HAVE_ELEMENTARY_X
447 wd->prop_hdl = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY,
449 wd->vkb_state = ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF;
452 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
453 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
454 _conformant_move_resize_event_cb, obj);
455 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE,
456 _conformant_move_resize_event_cb, obj);
458 _mirrored_set(obj, elm_widget_mirrored_get(obj));
464 * Set the content of the conformant widget
466 * Once the content object is set, a previously set one will be deleted.
467 * If you want to keep that old content object, use the
468 * elm_conformat_content_unset() function.
470 * @param obj The conformant object
471 * @return The content that was being used
473 * @ingroup Conformant
476 elm_conformant_content_set(Evas_Object *obj, Evas_Object *content)
478 ELM_CHECK_WIDTYPE(obj, widtype);
479 Widget_Data *wd = elm_widget_data_get(obj);
481 if (wd->content == content) return;
482 if (wd->content) evas_object_del(wd->content);
483 wd->content = content;
486 elm_widget_sub_object_add(obj, content);
487 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
488 _changed_size_hints, obj);
489 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
495 * Get the content of the conformant widget
497 * Return the content object which is set for this widget;
499 * @param obj The conformant object
500 * @return The content that is being used
502 * @ingroup Conformant
505 elm_conformant_content_get(const Evas_Object *obj)
507 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
508 Widget_Data *wd = elm_widget_data_get(obj);
509 if (!wd) return NULL;
514 * Unset the content of the conformant widget
516 * Unparent and return the content object which was set for this widget;
518 * @param obj The conformant object
519 * @return The content that was being used
521 * @ingroup Conformant
524 elm_conformant_content_unset(Evas_Object *obj)
526 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
527 Widget_Data *wd = elm_widget_data_get(obj);
528 Evas_Object *content;
529 if (!wd) return NULL;
530 if (!wd->content) return NULL;
531 content = wd->content;
532 elm_widget_sub_object_del(obj, wd->content);
533 edje_object_part_unswallow(wd->base, wd->content);
539 * Returns the Evas_Object that represents the content area.
541 * @param obj The conformant object.
542 * @return The content area of the widget.
544 * @ingroup Conformant
547 elm_conformant_content_area_get(Evas_Object *obj)
549 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
550 Widget_Data *wd = elm_widget_data_get(obj);
552 if (!wd) return NULL;
553 /*Finger waggle warning*/
554 _elm_dangerous_call_check(__FUNCTION__);
555 return (Evas_Object*)edje_object_part_object_get(wd->base, "elm.swallow.content");