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 Ecore_Event_Handler *prop_hdl;
20 #ifdef HAVE_ELEMENTARY_X
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_hook(Evas_Object *obj);
45 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
46 static void _theme_hook(Evas_Object *obj);
48 _swallow_conformant_parts(Evas_Object *obj);
50 _conformant_part_size_set(Evas_Object *obj, Evas_Object *sobj, Evas_Coord sx,
51 Evas_Coord sy, Evas_Coord sw, Evas_Coord sh);
53 _conformant_part_sizing_eval(Evas_Object *obj, Conformant_Part_Type part_type);
54 static void _sizing_eval(Evas_Object *obj);
55 static Eina_Bool _prop_change(void *data, int type, void *event);
59 _del_hook(Evas_Object *obj)
61 Widget_Data *wd = elm_widget_data_get(obj);
63 if (wd->prop_hdl) ecore_event_handler_del(wd->prop_hdl);
68 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
70 Widget_Data *wd = elm_widget_data_get(obj);
72 edje_object_mirrored_set(wd->base, rtl);
76 _theme_hook(Evas_Object *obj)
78 Widget_Data *wd = elm_widget_data_get(obj);
81 _elm_widget_mirrored_reload(obj);
82 _mirrored_set(obj, elm_widget_mirrored_get(obj));
83 _elm_theme_object_set(obj, wd->base, "conformant", "base", elm_widget_style_get(obj));
84 _swallow_conformant_parts(obj);
87 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->content);
88 edje_object_scale_set(wd->base, elm_widget_scale_get(obj) * _elm_config->scale);
93 _sizing_eval(Evas_Object *obj)
95 Widget_Data *wd = elm_widget_data_get(obj);
96 Evas_Coord mw = -1, mh = -1;
98 edje_object_size_min_calc(wd->base, &mw, &mh);
99 evas_object_size_hint_min_set(obj, mw, mh);
100 evas_object_size_hint_max_set(obj, -1, -1);
104 _conformant_part_size_set(Evas_Object *obj, Evas_Object *sobj, Evas_Coord sx,
105 Evas_Coord sy, Evas_Coord sw, Evas_Coord sh)
107 Evas_Coord cx, cy, cw, ch;
108 Evas_Coord part_height = 0, part_width = 0;
110 evas_object_geometry_get(obj, &cx, &cy, &cw, &ch);
112 /* Part overlapping with conformant */
113 if ((cx < (sx+sw)) && ((cx+cw) > sx) && (cy < (sy+sh)) && ((cy+ch) > sy))
115 part_height = MIN((cy+ch), (sy+sh)) - MAX(cy, sy);
116 part_width = MIN((cx+cw), (sx+sw)) - MAX(cx, sx);
119 evas_object_size_hint_min_set(sobj, part_width, part_height);
120 evas_object_size_hint_max_set(sobj, part_width, part_height);
124 _conformant_part_sizing_eval(Evas_Object *obj, Conformant_Part_Type part_type)
126 #ifdef HAVE_ELEMENTARY_X
127 Ecore_X_Window zone, xwin;
128 int sx = -1, sy = -1, sw = -1, sh = -1;
129 Widget_Data *wd = elm_widget_data_get(obj);
133 xwin = elm_win_xwindow_get(obj);
134 zone = ecore_x_e_illume_zone_get(xwin);
136 if (part_type & ELM_CONFORM_INDICATOR_PART)
138 ecore_x_e_illume_indicator_geometry_get(zone, &sx, &sy, &sw, &sh);
139 _conformant_part_size_set(obj, wd->shelf, sx, sy, sw, sh);
141 if (part_type & ELM_CONFORM_VIRTUAL_KEYPAD_PART)
143 ecore_x_e_illume_keyboard_geometry_get(zone, &sx, &sy, &sw, &sh);
144 _conformant_part_size_set(obj,wd->virtualkeypad, sx, sy, sw, sh);
146 if (part_type & ELM_CONFORM_SOFTKEY_PART)
148 ecore_x_e_illume_softkey_geometry_get(zone, &sx, &sy, &sw, &sh);
149 _conformant_part_size_set(obj, wd->panel, sx, sy, sw, sh);
155 _swallow_conformant_parts(Evas_Object *obj)
157 Widget_Data *wd = elm_widget_data_get(obj);
162 wd->shelf = evas_object_rectangle_add(evas_object_evas_get(obj));
163 elm_widget_sub_object_add(obj, wd->shelf);
164 evas_object_size_hint_min_set(wd->shelf, -1, 0);
165 evas_object_size_hint_max_set(wd->shelf, -1, 0);
168 _conformant_part_sizing_eval(obj, ELM_CONFORM_INDICATOR_PART);
170 evas_object_color_set(wd->shelf, 0, 0, 0, 0);
171 edje_object_part_swallow(wd->base, "elm.swallow.shelf", wd->shelf);
173 if (!wd->virtualkeypad)
175 wd->virtualkeypad = evas_object_rectangle_add(evas_object_evas_get(obj));
176 elm_widget_sub_object_add(obj, wd->virtualkeypad);
177 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
178 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
181 _conformant_part_sizing_eval(obj, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
183 evas_object_color_set(wd->virtualkeypad, 0, 0, 0, 0);
184 edje_object_part_swallow(wd->base, "elm.swallow.virtualkeypad",
189 wd->panel = evas_object_rectangle_add(evas_object_evas_get(obj));
190 elm_widget_sub_object_add(obj, wd->panel);
191 evas_object_size_hint_min_set(wd->panel, -1, 0);
192 evas_object_size_hint_max_set(wd->panel, -1, 0);
195 _conformant_part_sizing_eval(obj, ELM_CONFORM_SOFTKEY_PART);
197 evas_object_color_set(wd->panel, 0, 0, 0, 0);
198 edje_object_part_swallow(wd->base, "elm.swallow.panel", wd->panel);
202 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
204 Widget_Data *wd = elm_widget_data_get(data);
210 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
212 Widget_Data *wd = elm_widget_data_get(obj);
213 Evas_Object *sub = event_info;
215 if (sub == wd->content)
217 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
218 _changed_size_hints, obj);
224 /* unused now - but meant to be for making sure the focused widget is always
225 * visible when the vkbd comes and goes by moving the conformant obj (and thus
226 * its children) to show the focused widget (and if focus changes follow)
229 _focus_object_get(const Evas_Object *obj)
231 Evas_Object *win, *foc;
233 win = elm_widget_top_get(obj);
234 if (!win) return NULL;
235 foc = elm_widget_top_get(win);
239 _focus_object_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
241 evas_object_geometry_get(obj, x, y, w, h);
245 _focus_change_del(void *data, Evas_Object *obj, void *event_info)
247 // called from toplevel when the focused window shanges
251 _autoscroll_move(Evas_Object *obj)
253 // move conformant edje by delta to show focused widget
257 _autoscroll_mode_enable(Evas_Object *obj)
259 // called when autoscroll mode should be on - content area smaller than
261 // 1. get focused object
262 // 2. if not in visible conformant area calculate delta needed to
264 // 3. store delta and call _autoscroll_move() which either asanimates
265 // or jumps right there
269 _autoscroll_mode_disable(Evas_Object *obj)
271 // called when autoscroll mode should be off - set delta to 0 and
272 // call _autoscroll_move()
277 _conformant_move_resize_event_cb(void *data, Evas *e, Evas_Object *obj,
280 Conformant_Part_Type part_type;
281 Widget_Data *wd = elm_widget_data_get(obj);
284 part_type = (ELM_CONFORM_INDICATOR_PART |
285 ELM_CONFORM_VIRTUAL_KEYPAD_PART |
286 ELM_CONFORM_SOFTKEY_PART);
287 _conformant_part_sizing_eval(obj, part_type);
291 _content_resize_event_cb(void *data, Evas *e, Evas_Object *obj,
294 Evas_Object *focus_obj;
295 Evas_Object *conformant = (Evas_Object *) data;
296 Widget_Data *wd = elm_widget_data_get(conformant);
299 #ifdef HAVE_ELEMENTARY_X
300 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF) return;
303 focus_obj = elm_widget_focused_object_get(conformant);
306 Evas_Coord x, y, w, h;
308 elm_widget_show_region_get(focus_obj, &x, &y, &w, &h);
310 if (h < _elm_config->finger_size)
311 h = _elm_config->finger_size;
313 elm_widget_show_region_set(focus_obj, x, y, w, h, EINA_TRUE);
318 _update_autoscroll_objs(void *data)
322 Evas_Object *sub, *top_scroller = NULL;
323 Evas_Object *conformant = (Evas_Object *) data;
324 Widget_Data *wd = elm_widget_data_get(data);
328 sub = elm_widget_focused_object_get(conformant);
329 //Look up for Top most scroller in the Focus Object hierarchy inside Conformant.
333 type = elm_widget_type_get(sub);
334 if (!strcmp(type, "conformant")) break;
335 for (i = 0; i < SUB_TYPE_COUNT; i++)
336 if (!strcmp(type, sub_type[i]))
341 sub = elm_object_parent_widget_get(sub);
344 //If the scroller got changed by app, replace it.
345 if (top_scroller != wd->scroller)
347 if (wd->scroller) evas_object_event_callback_del(wd->scroller,
348 EVAS_CALLBACK_RESIZE,
349 _content_resize_event_cb);
350 wd->scroller = top_scroller;
351 if (wd->scroller) evas_object_event_callback_add(wd->scroller,
352 EVAS_CALLBACK_RESIZE,
353 _content_resize_event_cb,
359 _prop_change(void *data, int type __UNUSED__, void *event)
361 #ifdef HAVE_ELEMENTARY_X
362 Ecore_X_Event_Window_Property *ev;
363 Widget_Data *wd = elm_widget_data_get(data);
364 if (!wd) return ECORE_CALLBACK_PASS_ON;
366 if (ev->atom == ECORE_X_ATOM_E_ILLUME_ZONE)
368 Conformant_Part_Type part_type;
370 part_type = (ELM_CONFORM_INDICATOR_PART |
371 ELM_CONFORM_VIRTUAL_KEYPAD_PART |
372 ELM_CONFORM_SOFTKEY_PART);
373 _conformant_part_sizing_eval(data, part_type);
374 evas_object_event_callback_add(data, EVAS_CALLBACK_RESIZE,
375 _conformant_move_resize_event_cb, data);
376 evas_object_event_callback_add(data, EVAS_CALLBACK_MOVE,
377 _conformant_move_resize_event_cb, data);
379 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_GEOMETRY)
380 _conformant_part_sizing_eval(data, ELM_CONFORM_INDICATOR_PART);
381 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_SOFTKEY_GEOMETRY)
382 _conformant_part_sizing_eval(data, ELM_CONFORM_SOFTKEY_PART);
383 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_KEYBOARD_GEOMETRY)
384 _conformant_part_sizing_eval(data, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
385 else if (ev->atom == ECORE_X_ATOM_E_VIRTUAL_KEYBOARD_STATE)
389 zone = ecore_x_e_illume_zone_get(ev->win);
390 wd->vkb_state = ecore_x_e_virtual_keyboard_state_get(zone);
391 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF)
393 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
394 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
397 _update_autoscroll_objs(data);
401 return ECORE_CALLBACK_PASS_ON;
405 * Add a new Conformant object
407 * @param parent The parent object
408 * @return The new conformant object or NULL if it cannot be created
410 * @ingroup Conformant
413 elm_conformant_add(Evas_Object *parent)
419 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
421 ELM_SET_WIDTYPE(widtype, "conformant");
422 elm_widget_type_set(obj, "conformant");
423 elm_widget_sub_object_add(parent, obj);
424 elm_widget_data_set(obj, wd);
425 elm_widget_del_hook_set(obj, _del_hook);
426 elm_widget_theme_hook_set(obj, _theme_hook);
427 elm_widget_can_focus_set(obj, EINA_FALSE);
429 wd->base = edje_object_add(e);
430 _elm_theme_object_set(obj, wd->base, "conformant", "base", "default");
431 elm_widget_resize_object_set(obj, wd->base);
432 _swallow_conformant_parts(obj);
434 #ifdef HAVE_ELEMENTARY_X
435 wd->prop_hdl = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY,
437 wd->vkb_state = ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF;
440 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
442 _mirrored_set(obj, elm_widget_mirrored_get(obj));
448 * Set the content of the conformant widget
450 * Once the content object is set, a previously set one will be deleted.
451 * If you want to keep that old content object, use the
452 * elm_conformat_content_unset() function.
454 * @param obj The conformant object
455 * @return The content that was being used
457 * @ingroup Conformant
460 elm_conformant_content_set(Evas_Object *obj, Evas_Object *content)
462 ELM_CHECK_WIDTYPE(obj, widtype);
463 Widget_Data *wd = elm_widget_data_get(obj);
465 if (wd->content == content) return;
466 if (wd->content) evas_object_del(wd->content);
467 wd->content = content;
470 elm_widget_sub_object_add(obj, content);
471 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
472 _changed_size_hints, obj);
473 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
479 * Get the content of the conformant widget
481 * Return the content object which is set for this widget;
483 * @param obj The conformant object
484 * @return The content that is being used
486 * @ingroup Conformant
489 elm_conformant_content_get(const Evas_Object *obj)
491 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
492 Widget_Data *wd = elm_widget_data_get(obj);
493 if (!wd) return NULL;
498 * Unset the content of the conformant widget
500 * Unparent and return the content object which was set for this widget;
502 * @param obj The conformant object
503 * @return The content that was being used
505 * @ingroup Conformant
508 elm_conformant_content_unset(Evas_Object *obj)
510 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
511 Widget_Data *wd = elm_widget_data_get(obj);
512 Evas_Object *content;
513 if (!wd) return NULL;
514 if (!wd->content) return NULL;
515 content = wd->content;
516 elm_widget_sub_object_del(obj, wd->content);
517 edje_object_part_unswallow(wd->base, wd->content);
523 * Returns the Evas_Object that represents the content area.
525 * @param obj The conformant object.
526 * @return The content area of the widget.
528 * @ingroup Conformant
531 elm_conformant_content_area_get(Evas_Object *obj)
533 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
534 Widget_Data *wd = elm_widget_data_get(obj);
536 if (!wd) return NULL;
537 /*Finger waggle warning*/
538 _elm_dangerous_call_check(__FUNCTION__);
539 return (Evas_Object*)edje_object_part_object_get(wd->base, "elm.swallow.content");