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
40 /* local function prototypes */
41 static const char *widtype = NULL;
42 static void _del_hook(Evas_Object *obj);
43 static void _theme_hook(Evas_Object *obj);
45 _swallow_conformant_parts(Evas_Object *obj);
47 _conformant_part_size_set(Evas_Object *obj, Evas_Object *sobj, int sy, int sh);
49 _conformant_part_sizing_eval(Evas_Object *obj, Conformant_Part_Type part_type);
50 static void _sizing_eval(Evas_Object *obj);
51 static Eina_Bool _prop_change(void *data, int type, void *event);
55 _del_hook(Evas_Object *obj)
57 Widget_Data *wd = elm_widget_data_get(obj);
59 if (wd->prop_hdl) ecore_event_handler_del(wd->prop_hdl);
64 _theme_hook(Evas_Object *obj)
66 Widget_Data *wd = elm_widget_data_get(obj);
68 _elm_theme_object_set(obj, wd->base, "conformant", "base", elm_widget_style_get(obj));
69 _swallow_conformant_parts(obj);
71 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->content);
72 edje_object_scale_set(wd->base, elm_widget_scale_get(obj) * _elm_config->scale);
77 _sizing_eval(Evas_Object *obj)
79 Widget_Data *wd = elm_widget_data_get(obj);
80 Evas_Coord mw = -1, mh = -1;
82 edje_object_size_min_calc(wd->base, &mw, &mh);
83 evas_object_size_hint_min_set(obj, mw, mh);
84 evas_object_size_hint_max_set(obj, -1, -1);
88 _conformant_part_size_set(Evas_Object *obj, Evas_Object *sobj, int sy, int sh)
90 Evas_Coord cx, cy, cw, ch;
93 evas_object_geometry_get(obj, &cx, &cy, &cw, &ch);
96 if ((ch > 0)&&(sh > 0))
98 /* Part overlapping with conformant */
99 if ((sy > 0) && ((cy + ch) > sy))
100 part_height = cy + ch - sy;
106 evas_object_size_hint_min_set(sobj, -1, part_height);
107 evas_object_size_hint_max_set(sobj, -1, part_height);
111 _conformant_part_sizing_eval(Evas_Object *obj, Conformant_Part_Type part_type)
113 #ifdef HAVE_ELEMENTARY_X
114 Ecore_X_Window zone, xwin;
115 Widget_Data *wd = elm_widget_data_get(obj);
118 xwin = elm_win_xwindow_get(obj);
119 zone = ecore_x_e_illume_zone_get(xwin);
121 if (part_type & ELM_CONFORM_INDICATOR_PART)
123 int sy = -1, sh = -1;
125 ecore_x_e_illume_indicator_geometry_get(zone, NULL, &sy, NULL, &sh);
126 _conformant_part_size_set(obj, wd->shelf, sy, sh);
128 if (part_type & ELM_CONFORM_VIRTUAL_KEYPAD_PART)
130 int sy = -1, sh = -1;
132 ecore_x_e_illume_keyboard_geometry_get(zone, NULL, &sy, NULL, &sh);
133 _conformant_part_size_set(obj,wd->virtualkeypad, sy, sh);
135 if (part_type & ELM_CONFORM_SOFTKEY_PART)
137 int sy = -1, sh = -1;
139 ecore_x_e_illume_softkey_geometry_get(zone, NULL, &sy, NULL, &sh);
140 _conformant_part_size_set(obj, wd->panel, sy, 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);
160 _conformant_part_sizing_eval(obj, ELM_CONFORM_INDICATOR_PART);
162 evas_object_color_set(wd->shelf, 0, 0, 0, 0);
163 edje_object_part_swallow(wd->base, "elm.swallow.shelf", wd->shelf);
165 if (!wd->virtualkeypad)
167 wd->virtualkeypad = evas_object_rectangle_add(evas_object_evas_get(obj));
168 elm_widget_sub_object_add(obj, wd->virtualkeypad);
169 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
170 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
174 _conformant_part_sizing_eval(obj, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
176 evas_object_color_set(wd->virtualkeypad, 0, 0, 0, 0);
177 edje_object_part_swallow(wd->base, "elm.swallow.virtualkeypad",
182 wd->panel = evas_object_rectangle_add(evas_object_evas_get(obj));
183 elm_widget_sub_object_add(obj, wd->panel);
184 evas_object_size_hint_min_set(wd->panel, -1, 0);
185 evas_object_size_hint_max_set(wd->panel, -1, 0);
189 _conformant_part_sizing_eval(obj, ELM_CONFORM_SOFTKEY_PART);
191 evas_object_color_set(wd->panel, 0, 0, 0, 0);
192 edje_object_part_swallow(wd->base, "elm.swallow.panel", wd->panel);
196 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
198 Widget_Data *wd = elm_widget_data_get(data);
204 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
206 Widget_Data *wd = elm_widget_data_get(obj);
207 Evas_Object *sub = event_info;
209 if (sub == wd->content)
211 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
212 _changed_size_hints, obj);
218 /* unused now - but meant to be for making sure the focused widget is always
219 * visible when the vkbd comes and goes by moving the conformant obj (and thus
220 * its children) to show the focused widget (and if focus changes follow)
223 _focus_object_get(const Evas_Object *obj)
225 Evas_Object *win, *foc;
227 win = elm_widget_top_get(obj);
228 if (!win) return NULL;
229 foc = elm_widget_top_get(win);
233 _focus_object_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
235 evas_object_geometry_get(obj, x, y, w, h);
239 _focus_change_del(void *data, Evas_Object *obj, void *event_info)
241 // called from toplevel when the focused window shanges
245 _autoscroll_move(Evas_Object *obj)
247 // move conformant edje by delta to show focused widget
251 _autoscroll_mode_enable(Evas_Object *obj)
253 // called when autoscroll mode should be on - content area smaller than
255 // 1. get focused object
256 // 2. if not in visible conformant area calculate delta needed to
258 // 3. store delta and call _autoscroll_move() which either asanimates
259 // or jumps right there
263 _autoscroll_mode_disable(Evas_Object *obj)
265 // called when autoscroll mode should be off - set delta to 0 and
266 // call _autoscroll_move()
271 _conformant_move_resize_event_cb(void *data, Evas *e, Evas_Object *obj,
274 Conformant_Part_Type part_type;
275 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)
312 Evas_Object *sub, *top_scroller = NULL;
313 Evas_Object *conformant = (Evas_Object *) data;
314 Widget_Data *wd = elm_widget_data_get(data);
317 sub = elm_widget_focused_object_get(conformant);
318 //Look up for Top most scroller in the Focus Object hierarchy inside Conformant.
321 type = elm_widget_type_get(sub);
322 if (!strcmp(type, "conformant")) break;
323 if (!strcmp(type, "scroller") || !strcmp(type, "genlist"))
326 sub = elm_object_parent_widget_get(sub);
329 //If the scroller got changed by app, replace it.
330 if (top_scroller != wd->scroller)
332 if (wd->scroller) evas_object_event_callback_del(wd->scroller,
333 EVAS_CALLBACK_RESIZE,
334 _content_resize_event_cb);
335 wd->scroller = top_scroller;
336 if (wd->scroller) evas_object_event_callback_add(wd->scroller,
337 EVAS_CALLBACK_RESIZE,
338 _content_resize_event_cb,
344 _prop_change(void *data, int type __UNUSED__, void *event)
346 #ifdef HAVE_ELEMENTARY_X
347 Ecore_X_Event_Window_Property *ev;
348 Widget_Data *wd = elm_widget_data_get(data);
349 if (!wd) return ECORE_CALLBACK_PASS_ON;
351 if (ev->atom == ECORE_X_ATOM_E_ILLUME_ZONE)
353 Conformant_Part_Type part_type;
354 part_type = (ELM_CONFORM_INDICATOR_PART |
355 ELM_CONFORM_VIRTUAL_KEYPAD_PART |
356 ELM_CONFORM_SOFTKEY_PART);
357 _conformant_part_sizing_eval(data, part_type);
358 evas_object_event_callback_add(data, EVAS_CALLBACK_RESIZE,
359 _conformant_move_resize_event_cb, data);
360 evas_object_event_callback_add(data, EVAS_CALLBACK_MOVE,
361 _conformant_move_resize_event_cb, data);
363 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_GEOMETRY)
365 _conformant_part_sizing_eval(data, ELM_CONFORM_INDICATOR_PART);
367 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_SOFTKEY_GEOMETRY)
369 _conformant_part_sizing_eval(data, ELM_CONFORM_SOFTKEY_PART);
371 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_KEYBOARD_GEOMETRY)
373 _conformant_part_sizing_eval(data, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
375 else if (ev->atom == ECORE_X_ATOM_E_VIRTUAL_KEYBOARD_STATE)
378 zone = ecore_x_e_illume_zone_get(ev->win);
379 wd->vkb_state = ecore_x_e_virtual_keyboard_state_get(zone);
380 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF)
382 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
383 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
386 _update_autoscroll_objs(data);
390 return ECORE_CALLBACK_PASS_ON;
394 * Add a new Conformant object
396 * @param parent The parent object
397 * @return The new conformant object or NULL if it cannot be created
399 * @ingroup Conformant
402 elm_conformant_add(Evas_Object *parent)
408 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
410 wd = ELM_NEW(Widget_Data);
412 evas = evas_object_evas_get(parent);
413 if (!evas) return NULL;
415 obj = elm_widget_add(evas);
416 ELM_SET_WIDTYPE(widtype, "conformant");
417 elm_widget_type_set(obj, "conformant");
418 elm_widget_sub_object_add(parent, obj);
419 elm_widget_data_set(obj, wd);
420 elm_widget_del_hook_set(obj, _del_hook);
421 elm_widget_theme_hook_set(obj, _theme_hook);
422 elm_widget_can_focus_set(obj, EINA_FALSE);
424 wd->base = edje_object_add(evas);
425 _elm_theme_object_set(obj, wd->base, "conformant", "base", "default");
426 elm_widget_resize_object_set(obj, wd->base);
427 _swallow_conformant_parts(obj);
429 #ifdef HAVE_ELEMENTARY_X
430 wd->prop_hdl = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY,
432 wd->vkb_state = ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF;
435 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
442 * Set the content of the conformant widget
444 * Once the content object is set, a previously set one will be deleted.
445 * If you want to keep that old content object, use the
446 * elm_conformat_content_unset() function.
448 * @param obj The conformant object
449 * @return The content that was being used
451 * @ingroup Conformant
454 elm_conformant_content_set(Evas_Object *obj, Evas_Object *content)
456 ELM_CHECK_WIDTYPE(obj, widtype);
457 Widget_Data *wd = elm_widget_data_get(obj);
459 if (wd->content == content) return;
460 if (wd->content) evas_object_del(wd->content);
461 wd->content = content;
464 elm_widget_sub_object_add(obj, content);
465 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
466 _changed_size_hints, obj);
467 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
473 * Get the content of the conformant widget
475 * Return the content object which is set for this widget;
477 * @param obj The conformant object
478 * @return The content that is being used
480 * @ingroup Conformant
483 elm_conformant_content_get(const Evas_Object *obj)
485 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
486 Widget_Data *wd = elm_widget_data_get(obj);
487 if (!wd) return NULL;
492 * Unset the content of the conformant widget
494 * Unparent and return the content object which was set for this widget;
496 * @param obj The conformant object
497 * @return The content that was being used
499 * @ingroup Conformant
502 elm_conformant_content_unset(Evas_Object *obj)
504 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
505 Widget_Data *wd = elm_widget_data_get(obj);
506 Evas_Object *content;
507 if (!wd) return NULL;
508 if (!wd->content) return NULL;
509 content = wd->content;
510 elm_widget_sub_object_del(obj, wd->content);
511 edje_object_part_unswallow(wd->base, wd->content);
517 * Returns the Evas_Object that represents the content area.
519 * @param obj The conformant object.
520 * @return The content area of the widget.
522 * @ingroup Conformant
525 elm_conformant_content_area_get(Evas_Object *obj)
527 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
528 Widget_Data *wd = elm_widget_data_get(obj);
529 if (!wd) return NULL;
530 /*Finger waggle warning*/
531 _elm_dangerous_call_check(__FUNCTION__);
532 return (Evas_Object*)edje_object_part_object_get(wd->base, "elm.swallow.content");