1 #include <Elementary.h>
5 # define MIN(a,b) ((a) < (b)) ? (a) : (b)
9 # define MAX(a,b) ((a) < (b)) ? (b) : (a)
13 * @defgroup Conformant Conformant
16 * The aim is to provide a widget that can be used in elementary apps to
17 * account for space taken up by the indicator, virtual keypad & softkey windows when running
18 * the illume2 module of E17.
21 typedef struct _Widget_Data Widget_Data;
25 Evas_Object *shelf, *panel, *virtualkeypad;
27 Evas_Object *scroller;
29 #ifdef HAVE_ELEMENTARY_X
30 Ecore_Event_Handler *prop_hdl;
31 Ecore_X_Virtual_Keyboard_State vkb_state;
35 Ecore_Animator *animator; // animaton timer
36 double start; // time started
37 Evas_Coord auto_x, auto_y; // desired delta
38 Evas_Coord x, y; // current delta
42 /* Enum to identify conformant swallow parts */
43 typedef enum _Conformant_Part_Type Conformant_Part_Type;
44 enum _Conformant_Part_Type
46 ELM_CONFORM_INDICATOR_PART = 1,
47 ELM_CONFORM_SOFTKEY_PART = 2,
48 ELM_CONFORM_VIRTUAL_KEYPAD_PART = 4
51 #define SUB_TYPE_COUNT 2
52 static char *sub_type[SUB_TYPE_COUNT] = { "scroller", "genlist" };
54 /* local function prototypes */
55 static const char *widtype = NULL;
56 static void _del_pre_hook(Evas_Object *obj);
57 static void _del_hook(Evas_Object *obj);
58 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
59 static void _theme_hook(Evas_Object *obj);
60 static void _swallow_conformant_parts(Evas_Object *obj);
61 #ifdef HAVE_ELEMENTARY_X
62 static void _conformant_part_size_set(Evas_Object *obj,
68 static void _conformant_part_sizing_eval(Evas_Object *obj,
69 Conformant_Part_Type part_type);
71 _conformant_move_resize_event_cb(void *data, Evas *e, Evas_Object *obj,
74 static void _sizing_eval(Evas_Object *obj);
75 static Eina_Bool _prop_change(void *data, int type, void *event);
79 _del_pre_hook(Evas_Object *obj)
81 Widget_Data *wd = elm_widget_data_get(obj);
83 #ifdef HAVE_ELEMENTARY_X
84 if (wd->prop_hdl) ecore_event_handler_del(wd->prop_hdl);
89 _del_hook(Evas_Object *obj)
91 Widget_Data *wd = elm_widget_data_get(obj);
98 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
100 Widget_Data *wd = elm_widget_data_get(obj);
103 edje_object_mirrored_set(wd->base, rtl);
107 _theme_hook(Evas_Object *obj)
109 Widget_Data *wd = elm_widget_data_get(obj);
112 _elm_widget_mirrored_reload(obj);
113 _mirrored_set(obj, elm_widget_mirrored_get(obj));
114 _elm_theme_object_set(obj, wd->base, "conformant", "base",
115 elm_widget_style_get(obj));
117 edje_object_scale_set(wd->base, elm_widget_scale_get(obj)
118 * _elm_config->scale);
123 _sizing_eval(Evas_Object *obj)
125 Widget_Data *wd = elm_widget_data_get(obj);
126 Evas_Coord mw = -1, mh = -1;
129 edje_object_size_min_calc(wd->base, &mw, &mh);
130 evas_object_size_hint_min_set(obj, mw, mh);
131 evas_object_size_hint_max_set(obj, -1, -1);
134 #ifdef HAVE_ELEMENTARY_X
136 _conformant_part_size_set(Evas_Object *obj, Evas_Object *sobj, Evas_Coord sx,
137 Evas_Coord sy, Evas_Coord sw, Evas_Coord sh)
139 Evas_Coord cx, cy, cw, ch;
140 Evas_Coord part_height = 0, part_width = 0;
142 evas_object_geometry_get(obj, &cx, &cy, &cw, &ch);
144 /* Part overlapping with conformant */
145 if ((cx < (sx + sw)) && ((cx + cw) > sx)
146 && (cy < (sy + sh)) && ((cy + ch) > sy))
148 part_height = MIN((cy + ch), (sy + sh)) - MAX(cy, sy);
149 part_width = MIN((cx + cw), (sx + sw)) - MAX(cx, sx);
152 evas_object_size_hint_min_set(sobj, part_width, part_height);
153 evas_object_size_hint_max_set(sobj, part_width, part_height);
157 _conformant_part_sizing_eval(Evas_Object *obj, Conformant_Part_Type part_type)
159 Ecore_X_Window zone, xwin;
162 int sx = -1, sy = -1, sw = -1, sh = -1;
163 Widget_Data *wd = elm_widget_data_get(obj);
167 top = elm_widget_top_get(obj);
168 xwin = elm_win_xwindow_get(top);
170 zone = ecore_x_e_illume_zone_get(xwin);
172 if (part_type & ELM_CONFORM_INDICATOR_PART)
174 ret = ecore_x_e_illume_indicator_geometry_get(zone, &sx, &sy, &sw, &sh);
175 if (!ret) //There is NO information of the indicator geometry, reset the geometry.
176 _conformant_part_size_set(obj, wd->shelf, 0, 0, 0, 0);
178 _conformant_part_size_set(obj, wd->shelf, sx, sy, sw, sh);
180 if (part_type & ELM_CONFORM_VIRTUAL_KEYPAD_PART)
182 ret = ecore_x_e_illume_keyboard_geometry_get(zone, &sx, &sy, &sw, &sh);
183 if (!ret) //There is NO information of the keyboard geometry, reset the geometry.
184 _conformant_part_size_set(obj, wd->virtualkeypad, 0, 0, 0, 0);
186 _conformant_part_size_set(obj,wd->virtualkeypad, sx, sy, sw, sh);
188 if (part_type & ELM_CONFORM_SOFTKEY_PART)
190 ret = ecore_x_e_illume_softkey_geometry_get(zone, &sx, &sy, &sw, &sh);
191 if (!ret) //There is NO information of the softkey geometry, reset the geometry.
192 _conformant_part_size_set(obj,wd->panel, 0, 0, 0, 0);
194 _conformant_part_size_set(obj, wd->panel, sx, sy, sw, sh);
200 _swallow_conformant_parts(Evas_Object *obj)
202 Widget_Data *wd = elm_widget_data_get(obj);
207 wd->shelf = evas_object_rectangle_add(evas_object_evas_get(obj));
208 elm_widget_sub_object_add(obj, wd->shelf);
209 evas_object_size_hint_min_set(wd->shelf, -1, 0);
210 evas_object_size_hint_max_set(wd->shelf, -1, 0);
212 #ifdef HAVE_ELEMENTARY_X
214 _conformant_part_sizing_eval(obj, ELM_CONFORM_INDICATOR_PART);
217 evas_object_color_set(wd->shelf, 0, 0, 0, 0);
218 edje_object_part_swallow(wd->base, "elm.swallow.shelf", wd->shelf);
220 if (!wd->virtualkeypad)
222 wd->virtualkeypad = evas_object_rectangle_add(evas_object_evas_get(obj));
223 elm_widget_sub_object_add(obj, wd->virtualkeypad);
224 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
225 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
227 #ifdef HAVE_ELEMENTARY_X
229 _conformant_part_sizing_eval(obj, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
231 evas_object_color_set(wd->virtualkeypad, 0, 0, 0, 0);
232 edje_object_part_swallow(wd->base, "elm.swallow.virtualkeypad",
237 wd->panel = evas_object_rectangle_add(evas_object_evas_get(obj));
238 elm_widget_sub_object_add(obj, wd->panel);
239 evas_object_size_hint_min_set(wd->panel, -1, 0);
240 evas_object_size_hint_max_set(wd->panel, -1, 0);
242 #ifdef HAVE_ELEMENTARY_X
244 _conformant_part_sizing_eval(obj, ELM_CONFORM_SOFTKEY_PART);
247 evas_object_color_set(wd->panel, 0, 0, 0, 0);
248 edje_object_part_swallow(wd->base, "elm.swallow.panel", wd->panel);
252 _changed_size_hints(void *data, Evas *e __UNUSED__,
253 Evas_Object *obj __UNUSED__,
254 void *event_info __UNUSED__)
256 Widget_Data *wd = elm_widget_data_get(data);
263 _sub_del(void *data, Evas_Object *obj __UNUSED__, void *event_info)
265 Widget_Data *wd = elm_widget_data_get(data);
266 Evas_Object *sub = event_info;
269 if (sub == wd->content)
271 evas_object_event_callback_del_full(sub,
272 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
273 _changed_size_hints, data);
280 /* unused now - but meant to be for making sure the focused widget is always
281 * visible when the vkbd comes and goes by moving the conformant obj (and thus
282 * its children) to show the focused widget (and if focus changes follow)
285 _focus_object_get(const Evas_Object *obj)
287 Evas_Object *win, *foc;
289 win = elm_widget_top_get(obj);
290 if (!win) return NULL;
291 foc = elm_widget_top_get(win);
295 _focus_object_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
297 evas_object_geometry_get(obj, x, y, w, h);
301 _focus_change_del(void *data, Evas_Object *obj, void *event_info)
303 // called from toplevel when the focused window shanges
307 _autoscroll_move(Evas_Object *obj)
309 // move conformant edje by delta to show focused widget
313 _autoscroll_mode_enable(Evas_Object *obj)
315 // called when autoscroll mode should be on - content area smaller than
317 // 1. get focused object
318 // 2. if not in visible conformant area calculate delta needed to
320 // 3. store delta and call _autoscroll_move() which either asanimates
321 // or jumps right there
325 _autoscroll_mode_disable(Evas_Object *obj)
327 // called when autoscroll mode should be off - set delta to 0 and
328 // call _autoscroll_move()
332 #ifdef HAVE_ELEMENTARY_X
334 _conformant_move_resize_event_cb(void *data __UNUSED__, Evas *e __UNUSED__,
335 Evas_Object *obj, void *event_info __UNUSED__)
337 Conformant_Part_Type part_type;
338 Widget_Data *wd = elm_widget_data_get(obj);
341 part_type = (ELM_CONFORM_INDICATOR_PART |
342 ELM_CONFORM_SOFTKEY_PART |
343 ELM_CONFORM_VIRTUAL_KEYPAD_PART);
344 _conformant_part_sizing_eval(obj, part_type);
348 // showing the focused/important region.
350 _content_resize_event_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj
351 __UNUSED__, void *event_info __UNUSED__)
353 Evas_Object *focus_obj;
354 Evas_Object *conformant = (Evas_Object *)data;
355 Widget_Data *wd = elm_widget_data_get(conformant);
358 #ifdef HAVE_ELEMENTARY_X
359 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF) return;
362 focus_obj = elm_widget_focused_object_get(conformant);
365 Evas_Coord x, y, w, h;
367 elm_widget_show_region_get(focus_obj, &x, &y, &w, &h);
369 if (h < _elm_config->finger_size)
370 h = _elm_config->finger_size;
372 elm_widget_show_region_set(focus_obj, x, y, w, h, EINA_TRUE);
376 #ifdef HAVE_ELEMENTARY_X
378 _update_autoscroll_objs(void *data)
382 Evas_Object *sub, *top_scroller = NULL;
383 Evas_Object *conformant = (Evas_Object *)data;
384 Widget_Data *wd = elm_widget_data_get(data);
388 sub = elm_widget_focused_object_get(conformant);
389 //Look up for Top most scroller in the Focus Object hierarchy inside Conformant.
393 type = elm_widget_type_get(sub);
394 if (!strcmp(type, "conformant")) break;
395 for (i = 0; i < SUB_TYPE_COUNT; i++)
396 if (!strcmp(type, sub_type[i]))
401 sub = elm_object_parent_widget_get(sub);
404 //If the scroller got changed by app, replace it.
405 if (top_scroller != wd->scroller)
407 if (wd->scroller) evas_object_event_callback_del(wd->scroller,
408 EVAS_CALLBACK_RESIZE,
409 _content_resize_event_cb);
410 wd->scroller = top_scroller;
411 if (wd->scroller) evas_object_event_callback_add(wd->scroller,
412 EVAS_CALLBACK_RESIZE,
413 _content_resize_event_cb,
419 _prop_change(void *data, int type __UNUSED__, void *event)
421 Ecore_X_Event_Window_Property *ev;
422 Widget_Data *wd = elm_widget_data_get(data);
424 if (!wd) return ECORE_CALLBACK_PASS_ON;
426 if (ev->atom == ECORE_X_ATOM_E_ILLUME_ZONE)
428 Conformant_Part_Type part_type;
430 part_type = (ELM_CONFORM_INDICATOR_PART |
431 ELM_CONFORM_SOFTKEY_PART |
432 ELM_CONFORM_VIRTUAL_KEYPAD_PART);
433 _conformant_part_sizing_eval(data, part_type);
435 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_GEOMETRY)
436 _conformant_part_sizing_eval(data, ELM_CONFORM_INDICATOR_PART);
437 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_SOFTKEY_GEOMETRY)
438 _conformant_part_sizing_eval(data, ELM_CONFORM_SOFTKEY_PART);
439 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_KEYBOARD_GEOMETRY)
440 _conformant_part_sizing_eval(data, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
441 else if (ev->atom == ECORE_X_ATOM_E_VIRTUAL_KEYBOARD_STATE)
445 printf("Keyboard Geometry Changed\n");
446 zone = ecore_x_e_illume_zone_get(ev->win);
447 wd->vkb_state = ecore_x_e_virtual_keyboard_state_get(zone);
448 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF)
450 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
451 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
454 _update_autoscroll_objs(data);
457 return ECORE_CALLBACK_PASS_ON;
462 * Add a new Conformant object
464 * @param parent The parent object
465 * @return The new conformant object or NULL if it cannot be created
467 * @ingroup Conformant
470 elm_conformant_add(Evas_Object *parent)
476 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
478 ELM_SET_WIDTYPE(widtype, "conformant");
479 elm_widget_type_set(obj, "conformant");
480 elm_widget_sub_object_add(parent, obj);
481 elm_widget_data_set(obj, wd);
482 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
483 elm_widget_del_hook_set(obj, _del_hook);
484 elm_widget_theme_hook_set(obj, _theme_hook);
485 elm_widget_can_focus_set(obj, EINA_FALSE);
487 wd->base = edje_object_add(e);
488 _elm_theme_object_set(obj, wd->base, "conformant", "base", "default");
489 elm_widget_resize_object_set(obj, wd->base);
491 wd->layout = elm_layout_add(obj);
492 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->layout);
493 elm_layout_theme_set(wd->layout, "conformant", "layout", "content");
495 _swallow_conformant_parts(obj);
497 #ifdef HAVE_ELEMENTARY_X
498 Evas_Object *top = elm_widget_top_get(obj);
499 Ecore_X_Window xwin = elm_win_xwindow_get(top);
501 if ((xwin) && (!elm_win_inlined_image_object_get(top)))
503 _swallow_conformant_parts(obj);
504 wd->prop_hdl = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY,
506 wd->vkb_state = ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF;
508 // FIXME: get kbd region prop
510 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
511 _conformant_move_resize_event_cb, obj);
512 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE,
513 _conformant_move_resize_event_cb, obj);
515 evas_object_smart_callback_add(wd->layout, "sub-object-del", _sub_del, obj);
517 _mirrored_set(obj, elm_widget_mirrored_get(obj));
523 * Set the content of the conformant widget
525 * Once the content object is set, a previously set one will be deleted.
526 * If you want to keep that old content object, use the
527 * elm_conformat_content_unset() function.
529 * @param obj The conformant object
530 * @return The content that was being used
532 * @ingroup Conformant
535 elm_conformant_content_set(Evas_Object *obj, Evas_Object *content)
537 ELM_CHECK_WIDTYPE(obj, widtype);
538 Widget_Data *wd = elm_widget_data_get(obj);
541 if (wd->content == content) return;
542 if (wd->content) evas_object_del(wd->content);
543 wd->content = content;
546 elm_layout_content_set(wd->layout, "elm.swallow.content", wd->content);
547 evas_object_event_callback_add( wd->content,
548 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
549 _changed_size_hints, obj);
555 * Get the content of the conformant widget
557 * Return the content object which is set for this widget;
559 * @param obj The conformant object
560 * @return The content that is being used
562 * @ingroup Conformant
565 elm_conformant_content_get(const Evas_Object *obj)
567 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
568 Widget_Data *wd = elm_widget_data_get(obj);
570 if (!wd) return NULL;
575 * Unset the content of the conformant widget
577 * Unparent and return the content object which was set for this widget;
579 * @param obj The conformant object
580 * @return The content that was being used
582 * @ingroup Conformant
585 elm_conformant_content_unset(Evas_Object *obj)
587 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
588 Widget_Data *wd = elm_widget_data_get(obj);
589 Evas_Object *content;
591 if (!wd) return NULL;
592 if (!wd->content) return NULL;
593 content = wd->content;
594 elm_layout_content_unset(wd->layout, "elm.swallow.content");
600 * Returns the Evas_Object that represents the content area.
602 * @param obj The conformant object.
603 * @return The content area of the widget.
605 * @ingroup Conformant
609 elm_conformant_content_area_get(const Evas_Object *obj)
611 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
612 Widget_Data *wd = elm_widget_data_get(obj);
614 if (!wd) return NULL;
615 /*Finger waggle warning*/
616 _elm_dangerous_call_check(__FUNCTION__);