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;
28 #ifdef HAVE_ELEMENTARY_X
29 Ecore_Event_Handler *prop_hdl;
30 Ecore_X_Virtual_Keyboard_State vkb_state;
34 Ecore_Animator *animator; // animaton timer
35 double start; // time started
36 Evas_Coord auto_x, auto_y; // desired delta
37 Evas_Coord x, y; // current delta
41 /* Enum to identify conformant swallow parts */
42 typedef enum _Conformant_Part_Type Conformant_Part_Type;
43 enum _Conformant_Part_Type
45 ELM_CONFORM_INDICATOR_PART = 1,
46 ELM_CONFORM_SOFTKEY_PART = 2,
47 ELM_CONFORM_VIRTUAL_KEYPAD_PART = 4
50 #define SUB_TYPE_COUNT 2
51 static char *sub_type[SUB_TYPE_COUNT] = { "scroller", "genlist" };
53 /* local function prototypes */
54 static const char *widtype = NULL;
55 static void _del_pre_hook(Evas_Object *obj);
56 static void _del_hook(Evas_Object *obj);
57 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
58 static void _theme_hook(Evas_Object *obj);
59 static void _swallow_conformant_parts(Evas_Object *obj);
60 #ifdef HAVE_ELEMENTARY_X
61 static void _conformant_part_size_set(Evas_Object *obj,
67 static void _conformant_part_sizing_eval(Evas_Object *obj,
68 Conformant_Part_Type part_type);
70 _conformant_move_resize_event_cb(void *data, Evas *e, Evas_Object *obj,
73 static void _sizing_eval(Evas_Object *obj);
74 static Eina_Bool _prop_change(void *data, int type, void *event);
78 _del_pre_hook(Evas_Object *obj)
80 Widget_Data *wd = elm_widget_data_get(obj);
82 #ifdef HAVE_ELEMENTARY_X
83 if (wd->prop_hdl) ecore_event_handler_del(wd->prop_hdl);
88 _del_hook(Evas_Object *obj)
90 Widget_Data *wd = elm_widget_data_get(obj);
97 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
99 Widget_Data *wd = elm_widget_data_get(obj);
102 edje_object_mirrored_set(wd->base, rtl);
106 _theme_hook(Evas_Object *obj)
108 Widget_Data *wd = elm_widget_data_get(obj);
111 _elm_widget_mirrored_reload(obj);
112 _mirrored_set(obj, elm_widget_mirrored_get(obj));
113 _elm_theme_object_set(obj, wd->base, "conformant", "base",
114 elm_widget_style_get(obj));
115 _swallow_conformant_parts(obj);
118 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->content);
119 edje_object_scale_set(wd->base, elm_widget_scale_get(obj)
120 * _elm_config->scale);
125 _sizing_eval(Evas_Object *obj)
127 Widget_Data *wd = elm_widget_data_get(obj);
128 Evas_Coord mw = -1, mh = -1;
131 edje_object_size_min_calc(wd->base, &mw, &mh);
132 evas_object_size_hint_min_set(obj, mw, mh);
133 evas_object_size_hint_max_set(obj, -1, -1);
136 #ifdef HAVE_ELEMENTARY_X
138 _conformant_part_size_set(Evas_Object *obj, Evas_Object *sobj, Evas_Coord sx,
139 Evas_Coord sy, Evas_Coord sw, Evas_Coord sh)
141 Evas_Coord cx, cy, cw, ch;
142 Evas_Coord part_height = 0, part_width = 0;
144 evas_object_geometry_get(obj, &cx, &cy, &cw, &ch);
146 /* Part overlapping with conformant */
147 if ((cx < (sx + sw)) && ((cx + cw) > sx)
148 && (cy < (sy + sh)) && ((cy + ch) > sy))
150 part_height = MIN((cy + ch), (sy + sh)) - MAX(cy, sy);
151 part_width = MIN((cx + cw), (sx + sw)) - MAX(cx, sx);
154 evas_object_size_hint_min_set(sobj, part_width, part_height);
155 evas_object_size_hint_max_set(sobj, part_width, part_height);
159 _conformant_part_sizing_eval(Evas_Object *obj, Conformant_Part_Type part_type)
161 Ecore_X_Window zone, xwin;
163 int sx = -1, sy = -1, sw = -1, sh = -1;
164 Widget_Data *wd = elm_widget_data_get(obj);
168 top = elm_widget_top_get(obj);
169 xwin = elm_win_xwindow_get(top);
171 zone = ecore_x_e_illume_zone_get(xwin);
173 if (part_type & ELM_CONFORM_INDICATOR_PART)
175 ecore_x_e_illume_indicator_geometry_get(zone, &sx, &sy, &sw, &sh);
176 _conformant_part_size_set(obj, wd->shelf, sx, sy, sw, sh);
178 if (part_type & ELM_CONFORM_VIRTUAL_KEYPAD_PART)
180 ecore_x_e_illume_keyboard_geometry_get(zone, &sx, &sy, &sw, &sh);
181 _conformant_part_size_set(obj,wd->virtualkeypad, sx, sy, sw, sh);
183 if (part_type & ELM_CONFORM_SOFTKEY_PART)
185 ecore_x_e_illume_softkey_geometry_get(zone, &sx, &sy, &sw, &sh);
186 _conformant_part_size_set(obj, wd->panel, sx, sy, sw, sh);
192 _swallow_conformant_parts(Evas_Object *obj)
194 Widget_Data *wd = elm_widget_data_get(obj);
199 wd->shelf = evas_object_rectangle_add(evas_object_evas_get(obj));
200 elm_widget_sub_object_add(obj, wd->shelf);
201 evas_object_size_hint_min_set(wd->shelf, -1, 0);
202 evas_object_size_hint_max_set(wd->shelf, -1, 0);
204 #ifdef HAVE_ELEMENTARY_X
206 _conformant_part_sizing_eval(obj, ELM_CONFORM_INDICATOR_PART);
209 evas_object_color_set(wd->shelf, 0, 0, 0, 0);
210 edje_object_part_swallow(wd->base, "elm.swallow.shelf", wd->shelf);
212 if (!wd->virtualkeypad)
214 wd->virtualkeypad = evas_object_rectangle_add(evas_object_evas_get(obj));
215 elm_widget_sub_object_add(obj, wd->virtualkeypad);
216 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
217 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
219 #ifdef HAVE_ELEMENTARY_X
221 _conformant_part_sizing_eval(obj, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
223 evas_object_color_set(wd->virtualkeypad, 0, 0, 0, 0);
224 edje_object_part_swallow(wd->base, "elm.swallow.virtualkeypad",
229 wd->panel = evas_object_rectangle_add(evas_object_evas_get(obj));
230 elm_widget_sub_object_add(obj, wd->panel);
231 evas_object_size_hint_min_set(wd->panel, -1, 0);
232 evas_object_size_hint_max_set(wd->panel, -1, 0);
234 #ifdef HAVE_ELEMENTARY_X
236 _conformant_part_sizing_eval(obj, ELM_CONFORM_SOFTKEY_PART);
239 evas_object_color_set(wd->panel, 0, 0, 0, 0);
240 edje_object_part_swallow(wd->base, "elm.swallow.panel", wd->panel);
244 _changed_size_hints(void *data, Evas *e __UNUSED__,
245 Evas_Object *obj __UNUSED__,
246 void *event_info __UNUSED__)
248 Widget_Data *wd = elm_widget_data_get(data);
255 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
257 Widget_Data *wd = elm_widget_data_get(obj);
258 Evas_Object *sub = event_info;
261 if (sub == wd->content)
263 evas_object_event_callback_del_full(sub,
264 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
265 _changed_size_hints, obj);
271 /* unused now - but meant to be for making sure the focused widget is always
272 * visible when the vkbd comes and goes by moving the conformant obj (and thus
273 * its children) to show the focused widget (and if focus changes follow)
276 _focus_object_get(const Evas_Object *obj)
278 Evas_Object *win, *foc;
280 win = elm_widget_top_get(obj);
281 if (!win) return NULL;
282 foc = elm_widget_top_get(win);
286 _focus_object_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
288 evas_object_geometry_get(obj, x, y, w, h);
292 _focus_change_del(void *data, Evas_Object *obj, void *event_info)
294 // called from toplevel when the focused window shanges
298 _autoscroll_move(Evas_Object *obj)
300 // move conformant edje by delta to show focused widget
304 _autoscroll_mode_enable(Evas_Object *obj)
306 // called when autoscroll mode should be on - content area smaller than
308 // 1. get focused object
309 // 2. if not in visible conformant area calculate delta needed to
311 // 3. store delta and call _autoscroll_move() which either asanimates
312 // or jumps right there
316 _autoscroll_mode_disable(Evas_Object *obj)
318 // called when autoscroll mode should be off - set delta to 0 and
319 // call _autoscroll_move()
323 #ifdef HAVE_ELEMENTARY_X
325 _conformant_move_resize_event_cb(void *data __UNUSED__, Evas *e __UNUSED__,
326 Evas_Object *obj, void *event_info __UNUSED__)
328 Conformant_Part_Type part_type;
329 Widget_Data *wd = elm_widget_data_get(obj);
332 part_type = (ELM_CONFORM_INDICATOR_PART |
333 ELM_CONFORM_SOFTKEY_PART |
334 ELM_CONFORM_VIRTUAL_KEYPAD_PART);
335 _conformant_part_sizing_eval(obj, part_type);
339 // showing the focused/important region.
341 _content_resize_event_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj
342 __UNUSED__, void *event_info __UNUSED__)
344 Evas_Object *focus_obj;
345 Evas_Object *conformant = (Evas_Object *)data;
346 Widget_Data *wd = elm_widget_data_get(conformant);
349 #ifdef HAVE_ELEMENTARY_X
350 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF) return;
353 focus_obj = elm_widget_focused_object_get(conformant);
356 Evas_Coord x, y, w, h;
358 elm_widget_show_region_get(focus_obj, &x, &y, &w, &h);
360 if (h < _elm_config->finger_size)
361 h = _elm_config->finger_size;
363 elm_widget_show_region_set(focus_obj, x, y, w, h, EINA_TRUE);
367 #ifdef HAVE_ELEMENTARY_X
369 _update_autoscroll_objs(void *data)
373 Evas_Object *sub, *top_scroller = NULL;
374 Evas_Object *conformant = (Evas_Object *)data;
375 Widget_Data *wd = elm_widget_data_get(data);
379 sub = elm_widget_focused_object_get(conformant);
380 //Look up for Top most scroller in the Focus Object hierarchy inside Conformant.
384 type = elm_widget_type_get(sub);
385 if (!strcmp(type, "conformant")) break;
386 for (i = 0; i < SUB_TYPE_COUNT; i++)
387 if (!strcmp(type, sub_type[i]))
392 sub = elm_object_parent_widget_get(sub);
395 //If the scroller got changed by app, replace it.
396 if (top_scroller != wd->scroller)
398 if (wd->scroller) evas_object_event_callback_del(wd->scroller,
399 EVAS_CALLBACK_RESIZE,
400 _content_resize_event_cb);
401 wd->scroller = top_scroller;
402 if (wd->scroller) evas_object_event_callback_add(wd->scroller,
403 EVAS_CALLBACK_RESIZE,
404 _content_resize_event_cb,
410 _prop_change(void *data, int type __UNUSED__, void *event)
412 Ecore_X_Event_Window_Property *ev;
413 Widget_Data *wd = elm_widget_data_get(data);
415 if (!wd) return ECORE_CALLBACK_PASS_ON;
417 if (ev->atom == ECORE_X_ATOM_E_ILLUME_ZONE)
419 Conformant_Part_Type part_type;
421 part_type = (ELM_CONFORM_INDICATOR_PART |
422 ELM_CONFORM_SOFTKEY_PART |
423 ELM_CONFORM_VIRTUAL_KEYPAD_PART);
424 _conformant_part_sizing_eval(data, part_type);
426 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_GEOMETRY)
427 _conformant_part_sizing_eval(data, ELM_CONFORM_INDICATOR_PART);
428 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_SOFTKEY_GEOMETRY)
429 _conformant_part_sizing_eval(data, ELM_CONFORM_SOFTKEY_PART);
430 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_KEYBOARD_GEOMETRY)
431 _conformant_part_sizing_eval(data, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
432 else if (ev->atom == ECORE_X_ATOM_E_VIRTUAL_KEYBOARD_STATE)
436 printf("Keyboard Geometry Changed\n");
437 zone = ecore_x_e_illume_zone_get(ev->win);
438 wd->vkb_state = ecore_x_e_virtual_keyboard_state_get(zone);
439 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF)
441 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
442 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
445 _update_autoscroll_objs(data);
448 return ECORE_CALLBACK_PASS_ON;
453 * Add a new Conformant object
455 * @param parent The parent object
456 * @return The new conformant object or NULL if it cannot be created
458 * @ingroup Conformant
461 elm_conformant_add(Evas_Object *parent)
467 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
469 ELM_SET_WIDTYPE(widtype, "conformant");
470 elm_widget_type_set(obj, "conformant");
471 elm_widget_sub_object_add(parent, obj);
472 elm_widget_data_set(obj, wd);
473 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
474 elm_widget_del_hook_set(obj, _del_hook);
475 elm_widget_theme_hook_set(obj, _theme_hook);
476 elm_widget_can_focus_set(obj, EINA_FALSE);
478 wd->base = edje_object_add(e);
479 _elm_theme_object_set(obj, wd->base, "conformant", "base", "default");
480 elm_widget_resize_object_set(obj, wd->base);
482 #ifdef HAVE_ELEMENTARY_X
483 Evas_Object *top = elm_widget_top_get(obj);
484 Ecore_X_Window xwin = elm_win_xwindow_get(top);
486 if ((xwin) && (!elm_win_inlined_image_object_get(top)))
488 _swallow_conformant_parts(obj);
489 wd->prop_hdl = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY,
491 wd->vkb_state = ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF;
493 // FIXME: get kbd region prop
495 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
496 _conformant_move_resize_event_cb, obj);
497 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE,
498 _conformant_move_resize_event_cb, obj);
500 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
502 _mirrored_set(obj, elm_widget_mirrored_get(obj));
508 * Set the content of the conformant widget
510 * Once the content object is set, a previously set one will be deleted.
511 * If you want to keep that old content object, use the
512 * elm_conformat_content_unset() function.
514 * @param obj The conformant object
515 * @return The content that was being used
517 * @ingroup Conformant
520 elm_conformant_content_set(Evas_Object *obj, Evas_Object *content)
522 ELM_CHECK_WIDTYPE(obj, widtype);
523 Widget_Data *wd = elm_widget_data_get(obj);
526 if (wd->content == content) return;
527 if (wd->content) evas_object_del(wd->content);
528 wd->content = content;
531 elm_widget_sub_object_add(obj, content);
532 evas_object_event_callback_add(content,
533 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
534 _changed_size_hints, obj);
535 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
541 * Get the content of the conformant widget
543 * Return the content object which is set for this widget;
545 * @param obj The conformant object
546 * @return The content that is being used
548 * @ingroup Conformant
551 elm_conformant_content_get(const Evas_Object *obj)
553 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
554 Widget_Data *wd = elm_widget_data_get(obj);
556 if (!wd) return NULL;
561 * Unset the content of the conformant widget
563 * Unparent and return the content object which was set for this widget;
565 * @param obj The conformant object
566 * @return The content that was being used
568 * @ingroup Conformant
571 elm_conformant_content_unset(Evas_Object *obj)
573 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
574 Widget_Data *wd = elm_widget_data_get(obj);
575 Evas_Object *content;
577 if (!wd) return NULL;
578 if (!wd->content) return NULL;
579 content = wd->content;
580 elm_widget_sub_object_del(obj, wd->content);
581 edje_object_part_unswallow(wd->base, wd->content);
587 * Returns the Evas_Object that represents the content area.
589 * @param obj The conformant object.
590 * @return The content area of the widget.
592 * @ingroup Conformant
596 elm_conformant_content_area_get(const Evas_Object *obj)
598 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
599 Widget_Data *wd = elm_widget_data_get(obj);
601 if (!wd) return NULL;
602 /*Finger waggle warning*/
603 _elm_dangerous_call_check(__FUNCTION__);
605 return (Evas_Object *)edje_object_part_object_get(wd->base, "elm.swallow.content");