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);
70 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESIZE, _conformant_move_resize_event_cb, obj);
71 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_MOVE, _conformant_move_resize_event_cb, obj);
75 _del_hook(Evas_Object *obj)
77 Widget_Data *wd = elm_widget_data_get(obj);
83 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
85 Widget_Data *wd = elm_widget_data_get(obj);
87 edje_object_mirrored_set(wd->base, rtl);
91 _theme_hook(Evas_Object *obj)
93 Widget_Data *wd = elm_widget_data_get(obj);
96 _elm_widget_mirrored_reload(obj);
97 _mirrored_set(obj, elm_widget_mirrored_get(obj));
98 _elm_theme_object_set(obj, wd->base, "conformant", "base", elm_widget_style_get(obj));
99 _swallow_conformant_parts(obj);
102 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->content);
103 edje_object_scale_set(wd->base, elm_widget_scale_get(obj) * _elm_config->scale);
108 _sizing_eval(Evas_Object *obj)
110 Widget_Data *wd = elm_widget_data_get(obj);
111 Evas_Coord mw = -1, mh = -1;
113 edje_object_size_min_calc(wd->base, &mw, &mh);
114 evas_object_size_hint_min_set(obj, mw, mh);
115 evas_object_size_hint_max_set(obj, -1, -1);
119 _conformant_part_size_set(Evas_Object *obj, Evas_Object *sobj, Evas_Coord sx,
120 Evas_Coord sy, Evas_Coord sw, Evas_Coord sh)
122 Evas_Coord cx, cy, cw, ch;
123 Evas_Coord part_height = 0, part_width = 0;
125 evas_object_geometry_get(obj, &cx, &cy, &cw, &ch);
127 /* Part overlapping with conformant */
128 if ((cx < (sx+sw)) && ((cx+cw) > sx) && (cy < (sy+sh)) && ((cy+ch) > sy))
130 part_height = MIN((cy+ch), (sy+sh)) - MAX(cy, sy);
131 part_width = MIN((cx+cw), (sx+sw)) - MAX(cx, sx);
134 evas_object_size_hint_min_set(sobj, part_width, part_height);
135 evas_object_size_hint_max_set(sobj, part_width, part_height);
139 _conformant_part_sizing_eval(Evas_Object *obj, Conformant_Part_Type part_type)
141 #ifdef HAVE_ELEMENTARY_X
142 Ecore_X_Window zone, xwin;
143 int sx = -1, sy = -1, sw = -1, sh = -1;
144 Widget_Data *wd = elm_widget_data_get(obj);
148 xwin = elm_win_xwindow_get(obj);
149 zone = ecore_x_e_illume_zone_get(xwin);
151 if (part_type & ELM_CONFORM_INDICATOR_PART)
153 ecore_x_e_illume_indicator_geometry_get(zone, &sx, &sy, &sw, &sh);
154 _conformant_part_size_set(obj, wd->shelf, sx, sy, sw, sh);
156 if (part_type & ELM_CONFORM_VIRTUAL_KEYPAD_PART)
158 ecore_x_e_illume_keyboard_geometry_get(zone, &sx, &sy, &sw, &sh);
159 _conformant_part_size_set(obj,wd->virtualkeypad, sx, sy, sw, sh);
161 if (part_type & ELM_CONFORM_SOFTKEY_PART)
163 ecore_x_e_illume_softkey_geometry_get(zone, &sx, &sy, &sw, &sh);
164 _conformant_part_size_set(obj, wd->panel, sx, sy, sw, sh);
170 _swallow_conformant_parts(Evas_Object *obj)
172 Widget_Data *wd = elm_widget_data_get(obj);
177 wd->shelf = evas_object_rectangle_add(evas_object_evas_get(obj));
178 elm_widget_sub_object_add(obj, wd->shelf);
179 evas_object_size_hint_min_set(wd->shelf, -1, 0);
180 evas_object_size_hint_max_set(wd->shelf, -1, 0);
183 _conformant_part_sizing_eval(obj, ELM_CONFORM_INDICATOR_PART);
185 evas_object_color_set(wd->shelf, 0, 0, 0, 0);
186 edje_object_part_swallow(wd->base, "elm.swallow.shelf", wd->shelf);
188 if (!wd->virtualkeypad)
190 wd->virtualkeypad = evas_object_rectangle_add(evas_object_evas_get(obj));
191 elm_widget_sub_object_add(obj, wd->virtualkeypad);
192 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
193 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
196 _conformant_part_sizing_eval(obj, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
198 evas_object_color_set(wd->virtualkeypad, 0, 0, 0, 0);
199 edje_object_part_swallow(wd->base, "elm.swallow.virtualkeypad",
204 wd->panel = evas_object_rectangle_add(evas_object_evas_get(obj));
205 elm_widget_sub_object_add(obj, wd->panel);
206 evas_object_size_hint_min_set(wd->panel, -1, 0);
207 evas_object_size_hint_max_set(wd->panel, -1, 0);
210 _conformant_part_sizing_eval(obj, ELM_CONFORM_SOFTKEY_PART);
212 evas_object_color_set(wd->panel, 0, 0, 0, 0);
213 edje_object_part_swallow(wd->base, "elm.swallow.panel", wd->panel);
217 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
219 Widget_Data *wd = elm_widget_data_get(data);
225 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
227 Widget_Data *wd = elm_widget_data_get(obj);
228 Evas_Object *sub = event_info;
230 if (sub == wd->content)
232 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
233 _changed_size_hints, obj);
239 /* unused now - but meant to be for making sure the focused widget is always
240 * visible when the vkbd comes and goes by moving the conformant obj (and thus
241 * its children) to show the focused widget (and if focus changes follow)
244 _focus_object_get(const Evas_Object *obj)
246 Evas_Object *win, *foc;
248 win = elm_widget_top_get(obj);
249 if (!win) return NULL;
250 foc = elm_widget_top_get(win);
254 _focus_object_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
256 evas_object_geometry_get(obj, x, y, w, h);
260 _focus_change_del(void *data, Evas_Object *obj, void *event_info)
262 // called from toplevel when the focused window shanges
266 _autoscroll_move(Evas_Object *obj)
268 // move conformant edje by delta to show focused widget
272 _autoscroll_mode_enable(Evas_Object *obj)
274 // called when autoscroll mode should be on - content area smaller than
276 // 1. get focused object
277 // 2. if not in visible conformant area calculate delta needed to
279 // 3. store delta and call _autoscroll_move() which either asanimates
280 // or jumps right there
284 _autoscroll_mode_disable(Evas_Object *obj)
286 // called when autoscroll mode should be off - set delta to 0 and
287 // call _autoscroll_move()
292 _conformant_move_resize_event_cb(void *data __UNUSED__, Evas *e __UNUSED__,
294 void *event_info __UNUSED__)
296 Conformant_Part_Type part_type;
297 Widget_Data *wd = elm_widget_data_get(obj);
300 part_type = (ELM_CONFORM_INDICATOR_PART |
301 ELM_CONFORM_VIRTUAL_KEYPAD_PART |
302 ELM_CONFORM_SOFTKEY_PART);
303 _conformant_part_sizing_eval(obj, part_type);
307 _content_resize_event_cb(void *data, Evas *e __UNUSED__,
308 Evas_Object *obj __UNUSED__,
309 void *event_info __UNUSED__)
311 Evas_Object *focus_obj;
312 Evas_Object *conformant = (Evas_Object *) data;
313 Widget_Data *wd = elm_widget_data_get(conformant);
316 #ifdef HAVE_ELEMENTARY_X
317 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF) return;
320 focus_obj = elm_widget_focused_object_get(conformant);
323 Evas_Coord x, y, w, h;
325 elm_widget_show_region_get(focus_obj, &x, &y, &w, &h);
327 if (h < _elm_config->finger_size)
328 h = _elm_config->finger_size;
330 elm_widget_show_region_set(focus_obj, x, y, w, h, EINA_TRUE);
335 _update_autoscroll_objs(void *data)
339 Evas_Object *sub, *top_scroller = NULL;
340 Evas_Object *conformant = (Evas_Object *) data;
341 Widget_Data *wd = elm_widget_data_get(data);
345 sub = elm_widget_focused_object_get(conformant);
346 //Look up for Top most scroller in the Focus Object hierarchy inside Conformant.
350 type = elm_widget_type_get(sub);
351 if (!strcmp(type, "conformant")) break;
352 for (i = 0; i < SUB_TYPE_COUNT; i++)
353 if (!strcmp(type, sub_type[i]))
358 sub = elm_object_parent_widget_get(sub);
361 //If the scroller got changed by app, replace it.
362 if (top_scroller != wd->scroller)
364 if (wd->scroller) evas_object_event_callback_del(wd->scroller,
365 EVAS_CALLBACK_RESIZE,
366 _content_resize_event_cb);
367 wd->scroller = top_scroller;
368 if (wd->scroller) evas_object_event_callback_add(wd->scroller,
369 EVAS_CALLBACK_RESIZE,
370 _content_resize_event_cb,
376 _prop_change(void *data, int type __UNUSED__, void *event)
378 #ifdef HAVE_ELEMENTARY_X
379 Ecore_X_Event_Window_Property *ev;
380 Widget_Data *wd = elm_widget_data_get(data);
381 if (!wd) return ECORE_CALLBACK_PASS_ON;
383 if (ev->atom == ECORE_X_ATOM_E_ILLUME_ZONE)
385 Conformant_Part_Type part_type;
387 part_type = (ELM_CONFORM_INDICATOR_PART |
388 ELM_CONFORM_VIRTUAL_KEYPAD_PART |
389 ELM_CONFORM_SOFTKEY_PART);
390 _conformant_part_sizing_eval(data, part_type);
392 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_GEOMETRY)
393 _conformant_part_sizing_eval(data, ELM_CONFORM_INDICATOR_PART);
394 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_SOFTKEY_GEOMETRY)
395 _conformant_part_sizing_eval(data, ELM_CONFORM_SOFTKEY_PART);
396 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_KEYBOARD_GEOMETRY)
397 _conformant_part_sizing_eval(data, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
398 else if (ev->atom == ECORE_X_ATOM_E_VIRTUAL_KEYBOARD_STATE)
402 zone = ecore_x_e_illume_zone_get(ev->win);
403 wd->vkb_state = ecore_x_e_virtual_keyboard_state_get(zone);
404 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF)
406 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
407 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
410 _update_autoscroll_objs(data);
414 return ECORE_CALLBACK_PASS_ON;
418 * Add a new Conformant object
420 * @param parent The parent object
421 * @return The new conformant object or NULL if it cannot be created
423 * @ingroup Conformant
426 elm_conformant_add(Evas_Object *parent)
432 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
434 ELM_SET_WIDTYPE(widtype, "conformant");
435 elm_widget_type_set(obj, "conformant");
436 elm_widget_sub_object_add(parent, obj);
437 elm_widget_data_set(obj, wd);
438 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
439 elm_widget_del_hook_set(obj, _del_hook);
440 elm_widget_theme_hook_set(obj, _theme_hook);
441 elm_widget_can_focus_set(obj, EINA_FALSE);
443 wd->base = edje_object_add(e);
444 _elm_theme_object_set(obj, wd->base, "conformant", "base", "default");
445 elm_widget_resize_object_set(obj, wd->base);
446 _swallow_conformant_parts(obj);
448 #ifdef HAVE_ELEMENTARY_X
449 wd->prop_hdl = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY,
451 wd->vkb_state = ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF;
454 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
455 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
456 _conformant_move_resize_event_cb, obj);
457 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE,
458 _conformant_move_resize_event_cb, obj);
460 _mirrored_set(obj, elm_widget_mirrored_get(obj));
466 * Set the content of the conformant widget
468 * Once the content object is set, a previously set one will be deleted.
469 * If you want to keep that old content object, use the
470 * elm_conformat_content_unset() function.
472 * @param obj The conformant object
473 * @return The content that was being used
475 * @ingroup Conformant
478 elm_conformant_content_set(Evas_Object *obj, Evas_Object *content)
480 ELM_CHECK_WIDTYPE(obj, widtype);
481 Widget_Data *wd = elm_widget_data_get(obj);
483 if (wd->content == content) return;
484 if (wd->content) evas_object_del(wd->content);
485 wd->content = content;
488 elm_widget_sub_object_add(obj, content);
489 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
490 _changed_size_hints, obj);
491 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
497 * Get the content of the conformant widget
499 * Return the content object which is set for this widget;
501 * @param obj The conformant object
502 * @return The content that is being used
504 * @ingroup Conformant
507 elm_conformant_content_get(const Evas_Object *obj)
509 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
510 Widget_Data *wd = elm_widget_data_get(obj);
511 if (!wd) return NULL;
516 * Unset the content of the conformant widget
518 * Unparent and return the content object which was set for this widget;
520 * @param obj The conformant object
521 * @return The content that was being used
523 * @ingroup Conformant
526 elm_conformant_content_unset(Evas_Object *obj)
528 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
529 Widget_Data *wd = elm_widget_data_get(obj);
530 Evas_Object *content;
531 if (!wd) return NULL;
532 if (!wd->content) return NULL;
533 content = wd->content;
534 elm_widget_sub_object_del(obj, wd->content);
535 edje_object_part_unswallow(wd->base, wd->content);
541 * Returns the Evas_Object that represents the content area.
543 * @param obj The conformant object.
544 * @return The content area of the widget.
546 * @ingroup Conformant
549 elm_conformant_content_area_get(Evas_Object *obj)
551 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
552 Widget_Data *wd = elm_widget_data_get(obj);
554 if (!wd) return NULL;
555 /*Finger waggle warning*/
556 _elm_dangerous_call_check(__FUNCTION__);
557 return (Evas_Object*)edje_object_part_object_get(wd->base, "elm.swallow.content");