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);
298 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF) return;
300 focus_obj = elm_widget_focused_object_get(conformant);
303 Evas_Coord x, y, w, h;
305 elm_widget_show_region_get(focus_obj, &x, &y, &w, &h);
307 if (h < _elm_config->finger_size)
308 h = _elm_config->finger_size;
310 elm_widget_show_region_set(focus_obj, x, y, w, h, EINA_TRUE);
315 _update_autoscroll_objs(void *data)
319 Evas_Object *sub, *top_scroller = NULL;
320 Evas_Object *conformant = (Evas_Object *) data;
321 Widget_Data *wd = elm_widget_data_get(data);
325 sub = elm_widget_focused_object_get(conformant);
326 //Look up for Top most scroller in the Focus Object hierarchy inside Conformant.
330 type = elm_widget_type_get(sub);
331 if (!strcmp(type, "conformant")) break;
332 for (i = 0; i < SUB_TYPE_COUNT; i++)
333 if (!strcmp(type, sub_type[i]))
338 sub = elm_object_parent_widget_get(sub);
341 //If the scroller got changed by app, replace it.
342 if (top_scroller != wd->scroller)
344 if (wd->scroller) evas_object_event_callback_del(wd->scroller,
345 EVAS_CALLBACK_RESIZE,
346 _content_resize_event_cb);
347 wd->scroller = top_scroller;
348 if (wd->scroller) evas_object_event_callback_add(wd->scroller,
349 EVAS_CALLBACK_RESIZE,
350 _content_resize_event_cb,
356 _prop_change(void *data, int type __UNUSED__, void *event)
358 #ifdef HAVE_ELEMENTARY_X
359 Ecore_X_Event_Window_Property *ev;
360 Widget_Data *wd = elm_widget_data_get(data);
361 if (!wd) return ECORE_CALLBACK_PASS_ON;
363 if (ev->atom == ECORE_X_ATOM_E_ILLUME_ZONE)
365 Conformant_Part_Type part_type;
367 part_type = (ELM_CONFORM_INDICATOR_PART |
368 ELM_CONFORM_VIRTUAL_KEYPAD_PART |
369 ELM_CONFORM_SOFTKEY_PART);
370 _conformant_part_sizing_eval(data, part_type);
371 evas_object_event_callback_add(data, EVAS_CALLBACK_RESIZE,
372 _conformant_move_resize_event_cb, data);
373 evas_object_event_callback_add(data, EVAS_CALLBACK_MOVE,
374 _conformant_move_resize_event_cb, data);
376 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_GEOMETRY)
377 _conformant_part_sizing_eval(data, ELM_CONFORM_INDICATOR_PART);
378 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_SOFTKEY_GEOMETRY)
379 _conformant_part_sizing_eval(data, ELM_CONFORM_SOFTKEY_PART);
380 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_KEYBOARD_GEOMETRY)
381 _conformant_part_sizing_eval(data, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
382 else if (ev->atom == ECORE_X_ATOM_E_VIRTUAL_KEYBOARD_STATE)
386 zone = ecore_x_e_illume_zone_get(ev->win);
387 wd->vkb_state = ecore_x_e_virtual_keyboard_state_get(zone);
388 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF)
390 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
391 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
394 _update_autoscroll_objs(data);
398 return ECORE_CALLBACK_PASS_ON;
402 * Add a new Conformant object
404 * @param parent The parent object
405 * @return The new conformant object or NULL if it cannot be created
407 * @ingroup Conformant
410 elm_conformant_add(Evas_Object *parent)
416 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
418 ELM_SET_WIDTYPE(widtype, "conformant");
419 elm_widget_type_set(obj, "conformant");
420 elm_widget_sub_object_add(parent, obj);
421 elm_widget_data_set(obj, wd);
422 elm_widget_del_hook_set(obj, _del_hook);
423 elm_widget_theme_hook_set(obj, _theme_hook);
424 elm_widget_can_focus_set(obj, EINA_FALSE);
426 wd->base = edje_object_add(e);
427 _elm_theme_object_set(obj, wd->base, "conformant", "base", "default");
428 elm_widget_resize_object_set(obj, wd->base);
429 _swallow_conformant_parts(obj);
431 #ifdef HAVE_ELEMENTARY_X
432 wd->prop_hdl = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY,
434 wd->vkb_state = ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF;
437 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
439 _mirrored_set(obj, elm_widget_mirrored_get(obj));
445 * Set the content of the conformant widget
447 * Once the content object is set, a previously set one will be deleted.
448 * If you want to keep that old content object, use the
449 * elm_conformat_content_unset() function.
451 * @param obj The conformant object
452 * @return The content that was being used
454 * @ingroup Conformant
457 elm_conformant_content_set(Evas_Object *obj, Evas_Object *content)
459 ELM_CHECK_WIDTYPE(obj, widtype);
460 Widget_Data *wd = elm_widget_data_get(obj);
462 if (wd->content == content) return;
463 if (wd->content) evas_object_del(wd->content);
464 wd->content = content;
467 elm_widget_sub_object_add(obj, content);
468 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
469 _changed_size_hints, obj);
470 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
476 * Get the content of the conformant widget
478 * Return the content object which is set for this widget;
480 * @param obj The conformant object
481 * @return The content that is being used
483 * @ingroup Conformant
486 elm_conformant_content_get(const Evas_Object *obj)
488 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
489 Widget_Data *wd = elm_widget_data_get(obj);
490 if (!wd) return NULL;
495 * Unset the content of the conformant widget
497 * Unparent and return the content object which was set for this widget;
499 * @param obj The conformant object
500 * @return The content that was being used
502 * @ingroup Conformant
505 elm_conformant_content_unset(Evas_Object *obj)
507 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
508 Widget_Data *wd = elm_widget_data_get(obj);
509 Evas_Object *content;
510 if (!wd) return NULL;
511 if (!wd->content) return NULL;
512 content = wd->content;
513 elm_widget_sub_object_del(obj, wd->content);
514 edje_object_part_unswallow(wd->base, wd->content);
520 * Returns the Evas_Object that represents the content area.
522 * @param obj The conformant object.
523 * @return The content area of the widget.
525 * @ingroup Conformant
528 elm_conformant_content_area_get(Evas_Object *obj)
530 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
531 Widget_Data *wd = elm_widget_data_get(obj);
533 if (!wd) return NULL;
534 /*Finger waggle warning*/
535 _elm_dangerous_call_check(__FUNCTION__);
536 return (Evas_Object*)edje_object_part_object_get(wd->base, "elm.swallow.content");