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 _theme_hook(Evas_Object *obj);
47 _swallow_conformant_parts(Evas_Object *obj);
49 _conformant_part_size_set(Evas_Object *obj, Evas_Object *sobj, Evas_Coord sx,
50 Evas_Coord sy, Evas_Coord sw, Evas_Coord sh);
52 _conformant_part_sizing_eval(Evas_Object *obj, Conformant_Part_Type part_type);
53 static void _sizing_eval(Evas_Object *obj);
54 static Eina_Bool _prop_change(void *data, int type, void *event);
58 _del_hook(Evas_Object *obj)
60 Widget_Data *wd = elm_widget_data_get(obj);
63 if (wd->prop_hdl) ecore_event_handler_del(wd->prop_hdl);
68 _theme_hook(Evas_Object *obj)
70 Widget_Data *wd = elm_widget_data_get(obj);
73 _elm_theme_object_set(obj, wd->base, "conformant", "base", elm_widget_style_get(obj));
74 _swallow_conformant_parts(obj);
77 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->content);
78 edje_object_scale_set(wd->base, elm_widget_scale_get(obj) * _elm_config->scale);
83 _sizing_eval(Evas_Object *obj)
85 Widget_Data *wd = elm_widget_data_get(obj);
86 Evas_Coord mw = -1, mh = -1;
89 edje_object_size_min_calc(wd->base, &mw, &mh);
90 evas_object_size_hint_min_set(obj, mw, mh);
91 evas_object_size_hint_max_set(obj, -1, -1);
95 _conformant_part_size_set(Evas_Object *obj, Evas_Object *sobj, Evas_Coord sx,
96 Evas_Coord sy, Evas_Coord sw, Evas_Coord sh)
98 Evas_Coord cx, cy, cw, ch;
99 Evas_Coord part_height = 0, part_width = 0;
101 evas_object_geometry_get(obj, &cx, &cy, &cw, &ch);
103 /* Part overlapping with conformant */
104 if ((cx < (sx+sw)) && ((cx+cw) > sx) && (cy < (sy+sh)) && ((cy+ch) > sy))
106 part_height = MIN((cy+ch), (sy+sh)) - MAX(cy, sy);
107 part_width = MIN((cx+cw), (sx+sw)) - MAX(cx, sx);
110 evas_object_size_hint_min_set(sobj, part_width, part_height);
111 evas_object_size_hint_max_set(sobj, part_width, part_height);
115 _conformant_part_sizing_eval(Evas_Object *obj, Conformant_Part_Type part_type)
117 #ifdef HAVE_ELEMENTARY_X
118 Ecore_X_Window zone, xwin;
119 int sx = -1, sy = -1, sw = -1, sh = -1;
120 Widget_Data *wd = elm_widget_data_get(obj);
124 xwin = elm_win_xwindow_get(obj);
125 zone = ecore_x_e_illume_zone_get(xwin);
127 if (part_type & ELM_CONFORM_INDICATOR_PART)
129 ecore_x_e_illume_indicator_geometry_get(zone, &sx, &sy, &sw, &sh);
130 _conformant_part_size_set(obj, wd->shelf, sx, sy, sw, sh);
132 if (part_type & ELM_CONFORM_VIRTUAL_KEYPAD_PART)
134 ecore_x_e_illume_keyboard_geometry_get(zone, &sx, &sy, &sw, &sh);
135 _conformant_part_size_set(obj,wd->virtualkeypad, sx, sy, sw, sh);
137 if (part_type & ELM_CONFORM_SOFTKEY_PART)
139 ecore_x_e_illume_softkey_geometry_get(zone, &sx, &sy, &sw, &sh);
140 _conformant_part_size_set(obj, wd->panel, sx, sy, sw, sh);
146 _swallow_conformant_parts(Evas_Object *obj)
148 Widget_Data *wd = elm_widget_data_get(obj);
153 wd->shelf = evas_object_rectangle_add(evas_object_evas_get(obj));
154 elm_widget_sub_object_add(obj, wd->shelf);
155 evas_object_size_hint_min_set(wd->shelf, -1, 0);
156 evas_object_size_hint_max_set(wd->shelf, -1, 0);
159 _conformant_part_sizing_eval(obj, ELM_CONFORM_INDICATOR_PART);
161 evas_object_color_set(wd->shelf, 0, 0, 0, 0);
162 edje_object_part_swallow(wd->base, "elm.swallow.shelf", wd->shelf);
164 if (!wd->virtualkeypad)
166 wd->virtualkeypad = evas_object_rectangle_add(evas_object_evas_get(obj));
167 elm_widget_sub_object_add(obj, wd->virtualkeypad);
168 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
169 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
172 _conformant_part_sizing_eval(obj, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
174 evas_object_color_set(wd->virtualkeypad, 0, 0, 0, 0);
175 edje_object_part_swallow(wd->base, "elm.swallow.virtualkeypad",
180 wd->panel = evas_object_rectangle_add(evas_object_evas_get(obj));
181 elm_widget_sub_object_add(obj, wd->panel);
182 evas_object_size_hint_min_set(wd->panel, -1, 0);
183 evas_object_size_hint_max_set(wd->panel, -1, 0);
186 _conformant_part_sizing_eval(obj, ELM_CONFORM_SOFTKEY_PART);
188 evas_object_color_set(wd->panel, 0, 0, 0, 0);
189 edje_object_part_swallow(wd->base, "elm.swallow.panel", wd->panel);
193 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
195 Widget_Data *wd = elm_widget_data_get(data);
202 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
204 Widget_Data *wd = elm_widget_data_get(obj);
205 Evas_Object *sub = event_info;
208 if (sub == wd->content)
210 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
211 _changed_size_hints, obj);
217 /* unused now - but meant to be for making sure the focused widget is always
218 * visible when the vkbd comes and goes by moving the conformant obj (and thus
219 * its children) to show the focused widget (and if focus changes follow)
222 _focus_object_get(const Evas_Object *obj)
224 Evas_Object *win, *foc;
226 win = elm_widget_top_get(obj);
227 if (!win) return NULL;
228 foc = elm_widget_top_get(win);
232 _focus_object_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
234 evas_object_geometry_get(obj, x, y, w, h);
238 _focus_change_del(void *data, Evas_Object *obj, void *event_info)
240 // called from toplevel when the focused window shanges
244 _autoscroll_move(Evas_Object *obj)
246 // move conformant edje by delta to show focused widget
250 _autoscroll_mode_enable(Evas_Object *obj)
252 // called when autoscroll mode should be on - content area smaller than
254 // 1. get focused object
255 // 2. if not in visible conformant area calculate delta needed to
257 // 3. store delta and call _autoscroll_move() which either asanimates
258 // or jumps right there
262 _autoscroll_mode_disable(Evas_Object *obj)
264 // called when autoscroll mode should be off - set delta to 0 and
265 // call _autoscroll_move()
270 _conformant_move_resize_event_cb(void *data, Evas *e, Evas_Object *obj,
273 Conformant_Part_Type part_type;
274 Widget_Data *wd = elm_widget_data_get(obj);
277 part_type = (ELM_CONFORM_INDICATOR_PART |
278 ELM_CONFORM_VIRTUAL_KEYPAD_PART |
279 ELM_CONFORM_SOFTKEY_PART);
280 _conformant_part_sizing_eval(obj, part_type);
284 _content_resize_event_cb(void *data, Evas *e, Evas_Object *obj,
287 Evas_Object *focus_obj;
288 Evas_Object *conformant = (Evas_Object *) data;
289 Widget_Data *wd = elm_widget_data_get(conformant);
291 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF) return;
293 focus_obj = elm_widget_focused_object_get(conformant);
296 Evas_Coord x, y, w, h;
298 elm_widget_show_region_get(focus_obj, &x, &y, &w, &h);
300 if (h < _elm_config->finger_size)
301 h = _elm_config->finger_size;
303 h = 1 + h; //elm_widget_show_region_set expects some change, to redo the job.
304 elm_widget_show_region_set(focus_obj, x, y, w, h);
309 _update_autoscroll_objs(void *data)
313 Evas_Object *sub, *top_scroller = NULL;
314 Evas_Object *conformant = (Evas_Object *) data;
315 Widget_Data *wd = elm_widget_data_get(data);
319 sub = elm_widget_focused_object_get(conformant);
320 //Look up for Top most scroller in the Focus Object hierarchy inside Conformant.
324 type = elm_widget_type_get(sub);
325 if (!strcmp(type, "conformant")) break;
326 for (i = 0; i < SUB_TYPE_COUNT; i++)
327 if (!strcmp(type, sub_type[i]))
332 sub = elm_object_parent_widget_get(sub);
335 //If the scroller got changed by app, replace it.
336 if (top_scroller != wd->scroller)
338 if (wd->scroller) evas_object_event_callback_del(wd->scroller,
339 EVAS_CALLBACK_RESIZE,
340 _content_resize_event_cb);
341 wd->scroller = top_scroller;
342 if (wd->scroller) evas_object_event_callback_add(wd->scroller,
343 EVAS_CALLBACK_RESIZE,
344 _content_resize_event_cb,
350 _prop_change(void *data, int type __UNUSED__, void *event)
352 #ifdef HAVE_ELEMENTARY_X
353 Ecore_X_Event_Window_Property *ev;
354 Widget_Data *wd = elm_widget_data_get(data);
356 if (!wd) return ECORE_CALLBACK_PASS_ON;
358 if (ev->atom == ECORE_X_ATOM_E_ILLUME_ZONE)
360 Conformant_Part_Type part_type;
362 part_type = (ELM_CONFORM_INDICATOR_PART |
363 ELM_CONFORM_VIRTUAL_KEYPAD_PART |
364 ELM_CONFORM_SOFTKEY_PART);
365 _conformant_part_sizing_eval(data, part_type);
366 evas_object_event_callback_add(data, EVAS_CALLBACK_RESIZE,
367 _conformant_move_resize_event_cb, data);
368 evas_object_event_callback_add(data, EVAS_CALLBACK_MOVE,
369 _conformant_move_resize_event_cb, data);
371 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_GEOMETRY)
372 _conformant_part_sizing_eval(data, ELM_CONFORM_INDICATOR_PART);
373 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_SOFTKEY_GEOMETRY)
374 _conformant_part_sizing_eval(data, ELM_CONFORM_SOFTKEY_PART);
375 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_KEYBOARD_GEOMETRY)
376 _conformant_part_sizing_eval(data, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
377 else if (ev->atom == ECORE_X_ATOM_E_VIRTUAL_KEYBOARD_STATE)
381 zone = ecore_x_e_illume_zone_get(ev->win);
382 wd->vkb_state = ecore_x_e_virtual_keyboard_state_get(zone);
383 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF)
385 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
386 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
389 _update_autoscroll_objs(data);
393 return ECORE_CALLBACK_PASS_ON;
397 * Add a new Conformant object
399 * @param parent The parent object
400 * @return The new conformant object or NULL if it cannot be created
402 * @ingroup Conformant
405 elm_conformant_add(Evas_Object *parent)
411 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
413 wd = ELM_NEW(Widget_Data);
415 evas = evas_object_evas_get(parent);
416 if (!evas) return NULL;
418 obj = elm_widget_add(evas);
419 ELM_SET_WIDTYPE(widtype, "conformant");
420 elm_widget_type_set(obj, "conformant");
421 elm_widget_sub_object_add(parent, obj);
422 elm_widget_data_set(obj, wd);
423 elm_widget_del_hook_set(obj, _del_hook);
424 elm_widget_theme_hook_set(obj, _theme_hook);
425 elm_widget_can_focus_set(obj, EINA_FALSE);
427 wd->base = edje_object_add(evas);
428 _elm_theme_object_set(obj, wd->base, "conformant", "base", "default");
429 elm_widget_resize_object_set(obj, wd->base);
430 _swallow_conformant_parts(obj);
432 #ifdef HAVE_ELEMENTARY_X
433 wd->prop_hdl = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY,
435 wd->vkb_state = ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF;
438 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, 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);
463 if (wd->content == content) return;
464 if (wd->content) evas_object_del(wd->content);
465 wd->content = content;
468 elm_widget_sub_object_add(obj, content);
469 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
470 _changed_size_hints, obj);
471 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
477 * Get the content of the conformant widget
479 * Return the content object which is set for this widget;
481 * @param obj The conformant object
482 * @return The content that is being used
484 * @ingroup Conformant
487 elm_conformant_content_get(const Evas_Object *obj)
489 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
490 Widget_Data *wd = elm_widget_data_get(obj);
492 if (!wd) return NULL;
497 * Unset the content of the conformant widget
499 * Unparent and return the content object which was set for this widget;
501 * @param obj The conformant object
502 * @return The content that was being used
504 * @ingroup Conformant
507 elm_conformant_content_unset(Evas_Object *obj)
509 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
510 Widget_Data *wd = elm_widget_data_get(obj);
511 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");