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
15 * The aim is to provide a widget that can be used in elementary apps to
16 * account for space taken up by the indicator, virtual keypad & softkey windows when running
17 * the illume2 module of E17.
20 typedef struct _Widget_Data Widget_Data;
24 Evas_Object *shelf, *panel, *virtualkeypad;
26 Evas_Object *scroller;
27 #ifdef HAVE_ELEMENTARY_X
28 Ecore_Event_Handler *prop_hdl;
29 Ecore_X_Virtual_Keyboard_State vkb_state;
33 Ecore_Animator *animator; // animaton timer
34 double start; // time started
35 Evas_Coord auto_x, auto_y; // desired delta
36 Evas_Coord x, y; // current delta
40 /* Enum to identify conformant swallow parts */
41 typedef enum _Conformant_Part_Type Conformant_Part_Type;
42 enum _Conformant_Part_Type
44 ELM_CONFORM_INDICATOR_PART = 1,
45 ELM_CONFORM_SOFTKEY_PART = 2,
46 ELM_CONFORM_VIRTUAL_KEYPAD_PART = 4
49 #define SUB_TYPE_COUNT 2
50 static char *sub_type[SUB_TYPE_COUNT] = { "scroller", "genlist" };
52 /* local function prototypes */
53 static const char *widtype = NULL;
54 static void _del_pre_hook(Evas_Object *obj);
55 static void _del_hook(Evas_Object *obj);
56 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
57 static void _theme_hook(Evas_Object *obj);
58 static void _swallow_conformant_parts(Evas_Object *obj);
59 #ifdef HAVE_ELEMENTARY_X
60 static void _conformant_part_size_set(Evas_Object *obj,
66 static void _conformant_part_sizing_eval(Evas_Object *obj,
67 Conformant_Part_Type part_type);
69 _conformant_move_resize_event_cb(void *data, Evas *e, Evas_Object *obj,
72 static void _sizing_eval(Evas_Object *obj);
73 static Eina_Bool _prop_change(void *data, int type, void *event);
77 _del_pre_hook(Evas_Object *obj)
79 Widget_Data *wd = elm_widget_data_get(obj);
81 #ifdef HAVE_ELEMENTARY_X
82 if (wd->prop_hdl) ecore_event_handler_del(wd->prop_hdl);
87 _del_hook(Evas_Object *obj)
89 Widget_Data *wd = elm_widget_data_get(obj);
96 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
98 Widget_Data *wd = elm_widget_data_get(obj);
101 edje_object_mirrored_set(wd->base, rtl);
105 _theme_hook(Evas_Object *obj)
107 Widget_Data *wd = elm_widget_data_get(obj);
110 _elm_widget_mirrored_reload(obj);
111 _mirrored_set(obj, elm_widget_mirrored_get(obj));
112 _elm_theme_object_set(obj, wd->base, "conformant", "base",
113 elm_widget_style_get(obj));
114 _swallow_conformant_parts(obj);
117 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->content);
118 edje_object_scale_set(wd->base, elm_widget_scale_get(obj)
119 * _elm_config->scale);
124 _sizing_eval(Evas_Object *obj)
126 Widget_Data *wd = elm_widget_data_get(obj);
127 Evas_Coord mw = -1, mh = -1;
130 edje_object_size_min_calc(wd->base, &mw, &mh);
131 evas_object_size_hint_min_set(obj, mw, mh);
132 evas_object_size_hint_max_set(obj, -1, -1);
135 #ifdef HAVE_ELEMENTARY_X
137 _conformant_part_size_set(Evas_Object *obj, Evas_Object *sobj, Evas_Coord sx,
138 Evas_Coord sy, Evas_Coord sw, Evas_Coord sh)
140 Evas_Coord cx, cy, cw, ch;
141 Evas_Coord part_height = 0, part_width = 0;
143 evas_object_geometry_get(obj, &cx, &cy, &cw, &ch);
145 /* Part overlapping with conformant */
146 if ((cx < (sx + sw)) && ((cx + cw) > sx)
147 && (cy < (sy + sh)) && ((cy + ch) > sy))
149 part_height = MIN((cy + ch), (sy + sh)) - MAX(cy, sy);
150 part_width = MIN((cx + cw), (sx + sw)) - MAX(cx, sx);
153 evas_object_size_hint_min_set(sobj, part_width, part_height);
154 evas_object_size_hint_max_set(sobj, part_width, part_height);
158 _conformant_part_sizing_eval(Evas_Object *obj, Conformant_Part_Type part_type)
160 Ecore_X_Window zone, xwin;
161 int sx = -1, sy = -1, sw = -1, sh = -1;
162 Widget_Data *wd = elm_widget_data_get(obj);
166 Evas_Object *top = elm_widget_top_get(obj);
167 xwin = elm_win_xwindow_get(top);
168 zone = ecore_x_e_illume_zone_get(xwin);
170 if (part_type & ELM_CONFORM_INDICATOR_PART)
172 ecore_x_e_illume_indicator_geometry_get(zone, &sx, &sy, &sw, &sh);
173 _conformant_part_size_set(obj, wd->shelf, sx, sy, sw, sh);
175 if (part_type & ELM_CONFORM_VIRTUAL_KEYPAD_PART)
177 ecore_x_e_illume_keyboard_geometry_get(zone, &sx, &sy, &sw, &sh);
178 _conformant_part_size_set(obj,wd->virtualkeypad, sx, sy, sw, sh);
180 if (part_type & ELM_CONFORM_SOFTKEY_PART)
182 ecore_x_e_illume_softkey_geometry_get(zone, &sx, &sy, &sw, &sh);
183 _conformant_part_size_set(obj, wd->panel, sx, sy, sw, sh);
189 _swallow_conformant_parts(Evas_Object *obj)
191 Widget_Data *wd = elm_widget_data_get(obj);
196 wd->shelf = evas_object_rectangle_add(evas_object_evas_get(obj));
197 elm_widget_sub_object_add(obj, wd->shelf);
198 evas_object_size_hint_min_set(wd->shelf, -1, 0);
199 evas_object_size_hint_max_set(wd->shelf, -1, 0);
201 #ifdef HAVE_ELEMENTARY_X
203 _conformant_part_sizing_eval(obj, ELM_CONFORM_INDICATOR_PART);
205 evas_object_color_set(wd->shelf, 0, 0, 0, 0);
206 edje_object_part_swallow(wd->base, "elm.swallow.shelf", wd->shelf);
208 if (!wd->virtualkeypad)
210 wd->virtualkeypad = evas_object_rectangle_add(evas_object_evas_get(obj));
211 elm_widget_sub_object_add(obj, wd->virtualkeypad);
212 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
213 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
215 #ifdef HAVE_ELEMENTARY_X
217 _conformant_part_sizing_eval(obj, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
219 evas_object_color_set(wd->virtualkeypad, 0, 0, 0, 0);
220 edje_object_part_swallow(wd->base, "elm.swallow.virtualkeypad",
225 wd->panel = evas_object_rectangle_add(evas_object_evas_get(obj));
226 elm_widget_sub_object_add(obj, wd->panel);
227 evas_object_size_hint_min_set(wd->panel, -1, 0);
228 evas_object_size_hint_max_set(wd->panel, -1, 0);
230 #ifdef HAVE_ELEMENTARY_X
232 _conformant_part_sizing_eval(obj, ELM_CONFORM_SOFTKEY_PART);
234 evas_object_color_set(wd->panel, 0, 0, 0, 0);
235 edje_object_part_swallow(wd->base, "elm.swallow.panel", wd->panel);
239 _changed_size_hints(void *data, Evas *e __UNUSED__,
240 Evas_Object *obj __UNUSED__,
241 void *event_info __UNUSED__)
243 Widget_Data *wd = elm_widget_data_get(data);
250 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
252 Widget_Data *wd = elm_widget_data_get(obj);
253 Evas_Object *sub = event_info;
256 if (sub == wd->content)
258 evas_object_event_callback_del_full(sub,
259 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
260 _changed_size_hints, obj);
266 /* unused now - but meant to be for making sure the focused widget is always
267 * visible when the vkbd comes and goes by moving the conformant obj (and thus
268 * its children) to show the focused widget (and if focus changes follow)
271 _focus_object_get(const Evas_Object *obj)
273 Evas_Object *win, *foc;
275 win = elm_widget_top_get(obj);
276 if (!win) return NULL;
277 foc = elm_widget_top_get(win);
281 _focus_object_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
283 evas_object_geometry_get(obj, x, y, w, h);
287 _focus_change_del(void *data, Evas_Object *obj, void *event_info)
289 // called from toplevel when the focused window shanges
293 _autoscroll_move(Evas_Object *obj)
295 // move conformant edje by delta to show focused widget
299 _autoscroll_mode_enable(Evas_Object *obj)
301 // called when autoscroll mode should be on - content area smaller than
303 // 1. get focused object
304 // 2. if not in visible conformant area calculate delta needed to
306 // 3. store delta and call _autoscroll_move() which either asanimates
307 // or jumps right there
311 _autoscroll_mode_disable(Evas_Object *obj)
313 // called when autoscroll mode should be off - set delta to 0 and
314 // call _autoscroll_move()
318 #ifdef HAVE_ELEMENTARY_X
320 _conformant_move_resize_event_cb(void *data __UNUSED__, Evas *e __UNUSED__,
321 Evas_Object *obj, void *event_info __UNUSED__)
323 Conformant_Part_Type part_type;
324 Widget_Data *wd = elm_widget_data_get(obj);
327 part_type = (ELM_CONFORM_INDICATOR_PART |
328 ELM_CONFORM_SOFTKEY_PART |
329 ELM_CONFORM_VIRTUAL_KEYPAD_PART);
330 _conformant_part_sizing_eval(obj, part_type);
334 // showing the focused/important region.
336 _content_resize_event_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj
337 __UNUSED__, void *event_info __UNUSED__)
339 Evas_Object *focus_obj;
340 Evas_Object *conformant = (Evas_Object *)data;
341 Widget_Data *wd = elm_widget_data_get(conformant);
344 #ifdef HAVE_ELEMENTARY_X
345 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF) return;
348 focus_obj = elm_widget_focused_object_get(conformant);
351 Evas_Coord x, y, w, h;
353 elm_widget_show_region_get(focus_obj, &x, &y, &w, &h);
355 if (h < _elm_config->finger_size)
356 h = _elm_config->finger_size;
358 elm_widget_show_region_set(focus_obj, x, y, w, h);
362 #ifdef HAVE_ELEMENTARY_X
364 _update_autoscroll_objs(void *data)
368 Evas_Object *sub, *top_scroller = NULL;
369 Evas_Object *conformant = (Evas_Object *)data;
370 Widget_Data *wd = elm_widget_data_get(data);
374 sub = elm_widget_focused_object_get(conformant);
375 //Look up for Top most scroller in the Focus Object hierarchy inside Conformant.
379 type = elm_widget_type_get(sub);
380 if (!strcmp(type, "conformant")) break;
381 for (i = 0; i < SUB_TYPE_COUNT; i++)
382 if (!strcmp(type, sub_type[i]))
387 sub = elm_object_parent_widget_get(sub);
390 //If the scroller got changed by app, replace it.
391 if (top_scroller != wd->scroller)
393 if (wd->scroller) evas_object_event_callback_del(wd->scroller,
394 EVAS_CALLBACK_RESIZE,
395 _content_resize_event_cb);
396 wd->scroller = top_scroller;
397 if (wd->scroller) evas_object_event_callback_add(wd->scroller,
398 EVAS_CALLBACK_RESIZE,
399 _content_resize_event_cb,
405 _prop_change(void *data, int type __UNUSED__, void *event)
407 Ecore_X_Event_Window_Property *ev;
408 Widget_Data *wd = elm_widget_data_get(data);
410 if (!wd) return ECORE_CALLBACK_PASS_ON;
412 if (ev->atom == ECORE_X_ATOM_E_ILLUME_ZONE)
414 Conformant_Part_Type part_type;
416 part_type = (ELM_CONFORM_INDICATOR_PART |
417 ELM_CONFORM_SOFTKEY_PART |
418 ELM_CONFORM_VIRTUAL_KEYPAD_PART);
419 _conformant_part_sizing_eval(data, part_type);
421 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_GEOMETRY)
422 _conformant_part_sizing_eval(data, ELM_CONFORM_INDICATOR_PART);
423 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_SOFTKEY_GEOMETRY)
424 _conformant_part_sizing_eval(data, ELM_CONFORM_SOFTKEY_PART);
425 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_KEYBOARD_GEOMETRY)
426 _conformant_part_sizing_eval(data, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
427 else if (ev->atom == ECORE_X_ATOM_E_VIRTUAL_KEYBOARD_STATE)
431 printf("Keyboard Geometry Changed\n");
432 zone = ecore_x_e_illume_zone_get(ev->win);
433 wd->vkb_state = ecore_x_e_virtual_keyboard_state_get(zone);
434 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF)
436 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
437 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
440 _update_autoscroll_objs(data);
443 return ECORE_CALLBACK_PASS_ON;
448 * Add a new Conformant object
450 * @param parent The parent object
451 * @return The new conformant object or NULL if it cannot be created
453 * @ingroup Conformant
456 elm_conformant_add(Evas_Object *parent)
462 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
464 ELM_SET_WIDTYPE(widtype, "conformant");
465 elm_widget_type_set(obj, "conformant");
466 elm_widget_sub_object_add(parent, obj);
467 elm_widget_data_set(obj, wd);
468 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
469 elm_widget_del_hook_set(obj, _del_hook);
470 elm_widget_theme_hook_set(obj, _theme_hook);
471 elm_widget_can_focus_set(obj, EINA_FALSE);
473 wd->base = edje_object_add(e);
474 _elm_theme_object_set(obj, wd->base, "conformant", "base", "default");
475 elm_widget_resize_object_set(obj, wd->base);
477 #ifdef HAVE_ELEMENTARY_X
478 Evas_Object *top = elm_widget_top_get(obj);
479 Ecore_X_Window xwin = elm_win_xwindow_get(top);
481 if ((xwin) && (!elm_win_inlined_image_object_get(top)))
483 _swallow_conformant_parts(obj);
484 wd->prop_hdl = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY,
486 wd->vkb_state = ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF;
488 // FIXME: get kbd region prop
490 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
491 _conformant_move_resize_event_cb, obj);
492 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE,
493 _conformant_move_resize_event_cb, obj);
495 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
497 _mirrored_set(obj, elm_widget_mirrored_get(obj));
503 * Set the content of the conformant widget
505 * Once the content object is set, a previously set one will be deleted.
506 * If you want to keep that old content object, use the
507 * elm_conformat_content_unset() function.
509 * @param obj The conformant object
510 * @return The content that was being used
512 * @ingroup Conformant
515 elm_conformant_content_set(Evas_Object *obj, Evas_Object *content)
517 ELM_CHECK_WIDTYPE(obj, widtype);
518 Widget_Data *wd = elm_widget_data_get(obj);
521 if (wd->content == content) return;
522 if (wd->content) evas_object_del(wd->content);
523 wd->content = content;
526 elm_widget_sub_object_add(obj, content);
527 evas_object_event_callback_add(content,
528 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
529 _changed_size_hints, obj);
530 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
536 * Get the content of the conformant widget
538 * Return the content object which is set for this widget;
540 * @param obj The conformant object
541 * @return The content that is being used
543 * @ingroup Conformant
546 elm_conformant_content_get(const Evas_Object *obj)
548 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
549 Widget_Data *wd = elm_widget_data_get(obj);
551 if (!wd) return NULL;
556 * Unset the content of the conformant widget
558 * Unparent and return the content object which was set for this widget;
560 * @param obj The conformant object
561 * @return The content that was being used
563 * @ingroup Conformant
566 elm_conformant_content_unset(Evas_Object *obj)
568 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
569 Widget_Data *wd = elm_widget_data_get(obj);
570 Evas_Object *content;
572 if (!wd) return NULL;
573 if (!wd->content) return NULL;
574 content = wd->content;
575 elm_widget_sub_object_del(obj, wd->content);
576 edje_object_part_unswallow(wd->base, wd->content);
581 * Returns the Evas_Object that represents the content area.
583 * @param obj The conformant object.
584 * @return The content area of the widget.
586 * @ingroup Conformant
589 elm_conformant_content_area_get(const Evas_Object *obj)
591 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
592 Widget_Data *wd = elm_widget_data_get(obj);
594 if (!wd) return NULL;
595 /*Finger waggle warning*/
596 _elm_dangerous_call_check(__FUNCTION__);
597 return (Evas_Object *)edje_object_part_object_get(wd->base, "elm.swallow.content");