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;
29 #ifdef HAVE_ELEMENTARY_X
30 Ecore_Event_Handler *prop_hdl;
31 Ecore_X_Virtual_Keyboard_State vkb_state;
35 Ecore_Animator *animator; // animaton timer
36 double start; // time started
37 Evas_Coord auto_x, auto_y; // desired delta
38 Evas_Coord x, y; // current delta
42 /* Enum to identify conformant swallow parts */
43 typedef enum _Conformant_Part_Type Conformant_Part_Type;
44 enum _Conformant_Part_Type
46 ELM_CONFORM_INDICATOR_PART = 1,
47 ELM_CONFORM_SOFTKEY_PART = 2,
48 ELM_CONFORM_VIRTUAL_KEYPAD_PART = 4
51 #define SUB_TYPE_COUNT 2
52 static char *sub_type[SUB_TYPE_COUNT] = { "scroller", "genlist" };
54 /* local function prototypes */
55 static const char *widtype = NULL;
56 static void _del_pre_hook(Evas_Object *obj);
57 static void _del_hook(Evas_Object *obj);
58 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
59 static void _theme_hook(Evas_Object *obj);
60 static void _swallow_conformant_parts(Evas_Object *obj);
61 #ifdef HAVE_ELEMENTARY_X
62 static void _conformant_part_size_set(Evas_Object *obj,
68 static void _conformant_part_sizing_eval(Evas_Object *obj,
69 Conformant_Part_Type part_type);
71 _conformant_move_resize_event_cb(void *data, Evas *e, Evas_Object *obj,
74 static void _sizing_eval(Evas_Object *obj);
75 static Eina_Bool _prop_change(void *data, int type, void *event);
79 _del_pre_hook(Evas_Object *obj)
81 Widget_Data *wd = elm_widget_data_get(obj);
83 #ifdef HAVE_ELEMENTARY_X
84 if (wd->prop_hdl) ecore_event_handler_del(wd->prop_hdl);
89 _del_hook(Evas_Object *obj)
91 Widget_Data *wd = elm_widget_data_get(obj);
98 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
100 Widget_Data *wd = elm_widget_data_get(obj);
103 edje_object_mirrored_set(wd->base, rtl);
107 _theme_hook(Evas_Object *obj)
109 Widget_Data *wd = elm_widget_data_get(obj);
112 _elm_widget_mirrored_reload(obj);
113 _mirrored_set(obj, elm_widget_mirrored_get(obj));
114 _elm_theme_object_set(obj, wd->base, "conformant", "base",
115 elm_widget_style_get(obj));
117 edje_object_scale_set(wd->base, elm_widget_scale_get(obj)
118 * _elm_config->scale);
123 _sizing_eval(Evas_Object *obj)
125 Widget_Data *wd = elm_widget_data_get(obj);
126 Evas_Coord mw = -1, mh = -1;
129 edje_object_size_min_calc(wd->base, &mw, &mh);
130 evas_object_size_hint_min_set(obj, mw, mh);
131 evas_object_size_hint_max_set(obj, -1, -1);
134 #ifdef HAVE_ELEMENTARY_X
136 _conformant_part_size_set(Evas_Object *obj, Evas_Object *sobj, Evas_Coord sx,
137 Evas_Coord sy, Evas_Coord sw, Evas_Coord sh)
139 Evas_Coord cx, cy, cw, ch;
140 Evas_Coord part_height = 0, part_width = 0;
142 evas_object_geometry_get(obj, &cx, &cy, &cw, &ch);
144 /* Part overlapping with conformant */
145 if ((cx < (sx + sw)) && ((cx + cw) > sx)
146 && (cy < (sy + sh)) && ((cy + ch) > sy))
148 part_height = MIN((cy + ch), (sy + sh)) - MAX(cy, sy);
149 part_width = MIN((cx + cw), (sx + sw)) - MAX(cx, sx);
152 evas_object_size_hint_min_set(sobj, part_width, part_height);
153 evas_object_size_hint_max_set(sobj, part_width, part_height);
157 _conformant_part_sizing_eval(Evas_Object *obj, Conformant_Part_Type part_type)
159 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 top = elm_widget_top_get(obj);
167 xwin = elm_win_xwindow_get(top);
169 zone = ecore_x_e_illume_zone_get(xwin);
171 if (part_type & ELM_CONFORM_INDICATOR_PART)
173 ecore_x_e_illume_indicator_geometry_get(zone, &sx, &sy, &sw, &sh);
174 _conformant_part_size_set(obj, wd->shelf, sx, sy, sw, sh);
176 if (part_type & ELM_CONFORM_VIRTUAL_KEYPAD_PART)
178 ecore_x_e_illume_keyboard_geometry_get(zone, &sx, &sy, &sw, &sh);
179 _conformant_part_size_set(obj,wd->virtualkeypad, sx, sy, sw, sh);
181 if (part_type & ELM_CONFORM_SOFTKEY_PART)
183 ecore_x_e_illume_softkey_geometry_get(zone, &sx, &sy, &sw, &sh);
184 _conformant_part_size_set(obj, wd->panel, sx, sy, sw, sh);
190 _swallow_conformant_parts(Evas_Object *obj)
192 Widget_Data *wd = elm_widget_data_get(obj);
197 wd->shelf = evas_object_rectangle_add(evas_object_evas_get(obj));
198 elm_widget_sub_object_add(obj, wd->shelf);
199 evas_object_size_hint_min_set(wd->shelf, -1, 0);
200 evas_object_size_hint_max_set(wd->shelf, -1, 0);
202 #ifdef HAVE_ELEMENTARY_X
204 _conformant_part_sizing_eval(obj, ELM_CONFORM_INDICATOR_PART);
207 evas_object_color_set(wd->shelf, 0, 0, 0, 0);
208 edje_object_part_swallow(wd->base, "elm.swallow.shelf", wd->shelf);
210 if (!wd->virtualkeypad)
212 wd->virtualkeypad = evas_object_rectangle_add(evas_object_evas_get(obj));
213 elm_widget_sub_object_add(obj, wd->virtualkeypad);
214 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
215 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
217 #ifdef HAVE_ELEMENTARY_X
219 _conformant_part_sizing_eval(obj, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
221 evas_object_color_set(wd->virtualkeypad, 0, 0, 0, 0);
222 edje_object_part_swallow(wd->base, "elm.swallow.virtualkeypad",
227 wd->panel = evas_object_rectangle_add(evas_object_evas_get(obj));
228 elm_widget_sub_object_add(obj, wd->panel);
229 evas_object_size_hint_min_set(wd->panel, -1, 0);
230 evas_object_size_hint_max_set(wd->panel, -1, 0);
232 #ifdef HAVE_ELEMENTARY_X
234 _conformant_part_sizing_eval(obj, ELM_CONFORM_SOFTKEY_PART);
237 evas_object_color_set(wd->panel, 0, 0, 0, 0);
238 edje_object_part_swallow(wd->base, "elm.swallow.panel", wd->panel);
242 _changed_size_hints(void *data, Evas *e __UNUSED__,
243 Evas_Object *obj __UNUSED__,
244 void *event_info __UNUSED__)
246 Widget_Data *wd = elm_widget_data_get(data);
253 _sub_del(void *data, Evas_Object *obj __UNUSED__, void *event_info)
255 Widget_Data *wd = elm_widget_data_get(data);
256 Evas_Object *sub = event_info;
259 if (sub == wd->content)
261 evas_object_event_callback_del_full(sub,
262 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
263 _changed_size_hints, data);
270 /* unused now - but meant to be for making sure the focused widget is always
271 * visible when the vkbd comes and goes by moving the conformant obj (and thus
272 * its children) to show the focused widget (and if focus changes follow)
275 _focus_object_get(const Evas_Object *obj)
277 Evas_Object *win, *foc;
279 win = elm_widget_top_get(obj);
280 if (!win) return NULL;
281 foc = elm_widget_top_get(win);
285 _focus_object_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
287 evas_object_geometry_get(obj, x, y, w, h);
291 _focus_change_del(void *data, Evas_Object *obj, void *event_info)
293 // called from toplevel when the focused window shanges
297 _autoscroll_move(Evas_Object *obj)
299 // move conformant edje by delta to show focused widget
303 _autoscroll_mode_enable(Evas_Object *obj)
305 // called when autoscroll mode should be on - content area smaller than
307 // 1. get focused object
308 // 2. if not in visible conformant area calculate delta needed to
310 // 3. store delta and call _autoscroll_move() which either asanimates
311 // or jumps right there
315 _autoscroll_mode_disable(Evas_Object *obj)
317 // called when autoscroll mode should be off - set delta to 0 and
318 // call _autoscroll_move()
322 #ifdef HAVE_ELEMENTARY_X
324 _conformant_move_resize_event_cb(void *data __UNUSED__, Evas *e __UNUSED__,
325 Evas_Object *obj, void *event_info __UNUSED__)
327 Conformant_Part_Type part_type;
328 Widget_Data *wd = elm_widget_data_get(obj);
331 part_type = (ELM_CONFORM_INDICATOR_PART |
332 ELM_CONFORM_SOFTKEY_PART |
333 ELM_CONFORM_VIRTUAL_KEYPAD_PART);
334 _conformant_part_sizing_eval(obj, part_type);
338 // showing the focused/important region.
340 _content_resize_event_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj
341 __UNUSED__, void *event_info __UNUSED__)
343 Evas_Object *focus_obj;
344 Evas_Object *conformant = (Evas_Object *)data;
345 Widget_Data *wd = elm_widget_data_get(conformant);
348 #ifdef HAVE_ELEMENTARY_X
349 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF) return;
352 focus_obj = elm_widget_focused_object_get(conformant);
355 Evas_Coord x, y, w, h;
357 elm_widget_show_region_get(focus_obj, &x, &y, &w, &h);
359 if (h < _elm_config->finger_size)
360 h = _elm_config->finger_size;
362 elm_widget_show_region_set(focus_obj, x, y, w, h, EINA_TRUE);
366 #ifdef HAVE_ELEMENTARY_X
368 _update_autoscroll_objs(void *data)
372 Evas_Object *sub, *top_scroller = NULL;
373 Evas_Object *conformant = (Evas_Object *)data;
374 Widget_Data *wd = elm_widget_data_get(data);
378 sub = elm_widget_focused_object_get(conformant);
379 //Look up for Top most scroller in the Focus Object hierarchy inside Conformant.
383 type = elm_widget_type_get(sub);
384 if (!strcmp(type, "conformant")) break;
385 for (i = 0; i < SUB_TYPE_COUNT; i++)
386 if (!strcmp(type, sub_type[i]))
391 sub = elm_object_parent_widget_get(sub);
394 //If the scroller got changed by app, replace it.
395 if (top_scroller != wd->scroller)
397 if (wd->scroller) evas_object_event_callback_del(wd->scroller,
398 EVAS_CALLBACK_RESIZE,
399 _content_resize_event_cb);
400 wd->scroller = top_scroller;
401 if (wd->scroller) evas_object_event_callback_add(wd->scroller,
402 EVAS_CALLBACK_RESIZE,
403 _content_resize_event_cb,
409 _prop_change(void *data, int type __UNUSED__, void *event)
411 Ecore_X_Event_Window_Property *ev;
412 Widget_Data *wd = elm_widget_data_get(data);
414 if (!wd) return ECORE_CALLBACK_PASS_ON;
416 if (ev->atom == ECORE_X_ATOM_E_ILLUME_ZONE)
418 Conformant_Part_Type part_type;
420 part_type = (ELM_CONFORM_INDICATOR_PART |
421 ELM_CONFORM_SOFTKEY_PART |
422 ELM_CONFORM_VIRTUAL_KEYPAD_PART);
423 _conformant_part_sizing_eval(data, part_type);
425 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_GEOMETRY)
426 _conformant_part_sizing_eval(data, ELM_CONFORM_INDICATOR_PART);
427 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_SOFTKEY_GEOMETRY)
428 _conformant_part_sizing_eval(data, ELM_CONFORM_SOFTKEY_PART);
429 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_KEYBOARD_GEOMETRY)
430 _conformant_part_sizing_eval(data, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
431 else if (ev->atom == ECORE_X_ATOM_E_VIRTUAL_KEYBOARD_STATE)
435 printf("Keyboard Geometry Changed\n");
436 zone = ecore_x_e_illume_zone_get(ev->win);
437 wd->vkb_state = ecore_x_e_virtual_keyboard_state_get(zone);
438 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF)
440 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
441 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
444 _update_autoscroll_objs(data);
447 return ECORE_CALLBACK_PASS_ON;
452 * Add a new Conformant object
454 * @param parent The parent object
455 * @return The new conformant object or NULL if it cannot be created
457 * @ingroup Conformant
460 elm_conformant_add(Evas_Object *parent)
466 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
468 ELM_SET_WIDTYPE(widtype, "conformant");
469 elm_widget_type_set(obj, "conformant");
470 elm_widget_sub_object_add(parent, obj);
471 elm_widget_data_set(obj, wd);
472 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
473 elm_widget_del_hook_set(obj, _del_hook);
474 elm_widget_theme_hook_set(obj, _theme_hook);
475 elm_widget_can_focus_set(obj, EINA_FALSE);
477 wd->base = edje_object_add(e);
478 _elm_theme_object_set(obj, wd->base, "conformant", "base", "default");
479 elm_widget_resize_object_set(obj, wd->base);
481 wd->layout = elm_layout_add(obj);
482 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->layout);
483 elm_layout_theme_set(wd->layout, "conformant", "layout", "content");
485 _swallow_conformant_parts(obj);
487 #ifdef HAVE_ELEMENTARY_X
488 Evas_Object *top = elm_widget_top_get(obj);
489 Ecore_X_Window xwin = elm_win_xwindow_get(top);
491 if ((xwin) && (!elm_win_inlined_image_object_get(top)))
493 _swallow_conformant_parts(obj);
494 wd->prop_hdl = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY,
496 wd->vkb_state = ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF;
498 // FIXME: get kbd region prop
500 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
501 _conformant_move_resize_event_cb, obj);
502 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE,
503 _conformant_move_resize_event_cb, obj);
505 evas_object_smart_callback_add(wd->layout, "sub-object-del", _sub_del, obj);
507 _mirrored_set(obj, elm_widget_mirrored_get(obj));
513 * Set the content of the conformant widget
515 * Once the content object is set, a previously set one will be deleted.
516 * If you want to keep that old content object, use the
517 * elm_conformat_content_unset() function.
519 * @param obj The conformant object
520 * @return The content that was being used
522 * @ingroup Conformant
525 elm_conformant_content_set(Evas_Object *obj, Evas_Object *content)
527 ELM_CHECK_WIDTYPE(obj, widtype);
528 Widget_Data *wd = elm_widget_data_get(obj);
531 if (wd->content == content) return;
532 if (wd->content) evas_object_del(wd->content);
533 wd->content = content;
536 elm_layout_content_set(wd->layout, "elm.swallow.content", wd->content);
537 evas_object_event_callback_add( wd->content,
538 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
539 _changed_size_hints, obj);
545 * Get the content of the conformant widget
547 * Return the content object which is set for this widget;
549 * @param obj The conformant object
550 * @return The content that is being used
552 * @ingroup Conformant
555 elm_conformant_content_get(const Evas_Object *obj)
557 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
558 Widget_Data *wd = elm_widget_data_get(obj);
560 if (!wd) return NULL;
565 * Unset the content of the conformant widget
567 * Unparent and return the content object which was set for this widget;
569 * @param obj The conformant object
570 * @return The content that was being used
572 * @ingroup Conformant
575 elm_conformant_content_unset(Evas_Object *obj)
577 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
578 Widget_Data *wd = elm_widget_data_get(obj);
579 Evas_Object *content;
581 if (!wd) return NULL;
582 if (!wd->content) return NULL;
583 content = wd->content;
584 elm_layout_content_unset(wd->layout, "elm.swallow.content");
590 * Returns the Evas_Object that represents the content area.
592 * @param obj The conformant object.
593 * @return The content area of the widget.
595 * @ingroup Conformant
599 elm_conformant_content_area_get(const Evas_Object *obj)
601 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
602 Widget_Data *wd = elm_widget_data_get(obj);
604 if (!wd) return NULL;
605 /*Finger waggle warning*/
606 _elm_dangerous_call_check(__FUNCTION__);