1 #include <Elementary.h>
5 # define MIN(a,b) ((a) < (b)) ? (a) : (b)
9 # define MAX(a,b) ((a) < (b)) ? (b) : (a)
12 typedef struct _Widget_Data Widget_Data;
16 Evas_Object *shelf, *panel, *virtualkeypad;
18 Evas_Object *scroller;
19 #ifdef HAVE_ELEMENTARY_X
20 Ecore_Event_Handler *prop_hdl;
21 Ecore_X_Virtual_Keyboard_State vkb_state;
25 Ecore_Animator *animator; // animaton timer
26 double start; // time started
27 Evas_Coord auto_x, auto_y; // desired delta
28 Evas_Coord x, y; // current delta
30 Ecore_Job *show_region_job;
33 /* Enum to identify conformant swallow parts */
34 typedef enum _Conformant_Part_Type Conformant_Part_Type;
35 enum _Conformant_Part_Type
37 ELM_CONFORM_INDICATOR_PART = 1,
38 ELM_CONFORM_SOFTKEY_PART = 2,
39 ELM_CONFORM_VIRTUAL_KEYPAD_PART = 4
42 #define SUB_TYPE_COUNT 2
43 static char *sub_type[SUB_TYPE_COUNT] = { "scroller", "genlist" };
45 /* local function prototypes */
46 static const char *widtype = NULL;
47 static void _del_pre_hook(Evas_Object *obj);
48 static void _del_hook(Evas_Object *obj);
49 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
50 static void _theme_hook(Evas_Object *obj);
51 static void _content_set_hook(Evas_Object *obj,
53 Evas_Object *content);
54 static Evas_Object *_content_get_hook(const Evas_Object *obj,
56 static Evas_Object *_content_unset_hook(Evas_Object *obj, const char *part);
57 static void _swallow_conformant_parts(Evas_Object *obj);
58 static void _conformant_part_size_set(Evas_Object *obj,
64 static void _conformant_part_sizing_eval(Evas_Object *obj,
65 Conformant_Part_Type part_type);
66 static void _conformant_move_resize_event_cb(void *data,
70 static void _sizing_eval(Evas_Object *obj);
71 static void _show_region_job(void *data);
72 static Eina_Bool _prop_change(void *data, int type, void *event);
73 static void _changed_size_hints(void *data, Evas *e,
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);
94 if (wd->show_region_job) ecore_job_del(wd->show_region_job);
99 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
101 Widget_Data *wd = elm_widget_data_get(obj);
104 edje_object_mirrored_set(wd->base, rtl);
108 _theme_hook(Evas_Object *obj)
110 Widget_Data *wd = elm_widget_data_get(obj);
113 _elm_widget_mirrored_reload(obj);
114 _mirrored_set(obj, elm_widget_mirrored_get(obj));
115 _elm_theme_object_set(obj, wd->base, "conformant", "base",
116 elm_widget_style_get(obj));
117 _swallow_conformant_parts(obj);
120 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->content);
121 edje_object_scale_set(wd->base, elm_widget_scale_get(obj)
122 * _elm_config->scale);
127 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
129 ELM_CHECK_WIDTYPE(obj, widtype);
132 if (part && strcmp(part, "default")) return;
133 wd = elm_widget_data_get(obj);
135 if (wd->content == content) return;
136 if (wd->content) evas_object_del(wd->content);
137 wd->content = content;
140 elm_widget_sub_object_add(obj, content);
141 evas_object_event_callback_add(content,
142 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
143 _changed_size_hints, obj);
144 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
150 _content_get_hook(const Evas_Object *obj, const char *part)
152 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
155 if (part && strcmp(part, "default")) return NULL;
156 wd = elm_widget_data_get(obj);
157 if (!wd) return NULL;
162 _content_unset_hook(Evas_Object *obj, const char *part)
164 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
166 Evas_Object *content;
167 if (part && strcmp(part, "default")) return NULL;
168 wd = elm_widget_data_get(obj);
169 if ((!wd) || (!wd->content)) return NULL;
170 content = wd->content;
171 elm_widget_sub_object_del(obj, wd->content);
172 evas_object_event_callback_del_full(wd->content,
173 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
174 _changed_size_hints, obj);
175 edje_object_part_unswallow(wd->base, wd->content);
181 _sizing_eval(Evas_Object *obj)
183 Widget_Data *wd = elm_widget_data_get(obj);
184 Evas_Coord mw = -1, mh = -1;
187 edje_object_size_min_calc(wd->base, &mw, &mh);
188 evas_object_size_hint_min_set(obj, mw, mh);
189 evas_object_size_hint_max_set(obj, -1, -1);
192 /* Example of env vars:
193 * ILLUME_KBD="0, 0, 800, 301"
194 * ILLUME_IND=0,0,800,32
195 * ILLUME_STK="0,568,800,32
198 _conformant_part_geometry_env_get(const char *part, int *sx, int *sy, int *sw, int *sh)
200 const char delimiters[] = " ,;";
201 char *env_val, *token;
205 if (!(env_val = getenv(part))) return EINA_FALSE;
207 /* strtok would modify env var if not copied to a buffer */
208 strncpy(buf, env_val, sizeof(buf));
210 token = strtok(buf, delimiters);
211 if (!token) return EINA_FALSE;
214 token = strtok(NULL, delimiters);
215 if (!token) return EINA_FALSE;
218 token = strtok(NULL, delimiters);
219 if (!token) return EINA_FALSE;
222 token = strtok(NULL, delimiters);
223 if (!token) return EINA_FALSE;
234 _conformant_part_size_set(Evas_Object *obj, Evas_Object *sobj, Evas_Coord sx,
235 Evas_Coord sy, Evas_Coord sw, Evas_Coord sh)
237 Evas_Coord cx, cy, cw, ch;
238 Evas_Coord part_height = 0, part_width = 0;
240 evas_object_geometry_get(obj, &cx, &cy, &cw, &ch);
242 /* Part overlapping with conformant */
243 if ((cx < (sx + sw)) && ((cx + cw) > sx)
244 && (cy < (sy + sh)) && ((cy + ch) > sy))
246 part_height = MIN((cy + ch), (sy + sh)) - MAX(cy, sy);
247 part_width = MIN((cx + cw), (sx + sw)) - MAX(cx, sx);
250 evas_object_size_hint_min_set(sobj, part_width, part_height);
251 evas_object_size_hint_max_set(sobj, part_width, part_height);
255 _conformant_part_sizing_eval(Evas_Object *obj, Conformant_Part_Type part_type)
257 Ecore_X_Window zone = 0, xwin;
259 int sx = -1, sy = -1, sw = -1, sh = -1;
260 Widget_Data *wd = elm_widget_data_get(obj);
264 top = elm_widget_top_get(obj);
265 #ifdef HAVE_ELEMENTARY_X
266 xwin = elm_win_xwindow_get(top);
268 zone = ecore_x_e_illume_zone_get(xwin);
271 if (part_type & ELM_CONFORM_INDICATOR_PART)
273 if ((!_conformant_part_geometry_env_get("ILLUME_IND",
274 &sx, &sy, &sw, &sh)) && (xwin))
276 #ifdef HAVE_ELEMENTARY_X
277 //No information of the indicator geometry, reset the geometry.
278 if (!ecore_x_e_illume_indicator_geometry_get(zone, &sx, &sy, &sw, &sh))
279 sx = sy = sw = sh = 0;
284 _conformant_part_size_set(obj, wd->shelf, sx, sy, sw, sh);
286 if (part_type & ELM_CONFORM_VIRTUAL_KEYPAD_PART)
288 if ((!_conformant_part_geometry_env_get("ILLUME_KBD",
289 &sx, &sy, &sw, &sh)) && (xwin))
291 #ifdef HAVE_ELEMENTARY_X
292 //No information of the keyboard geometry, reset the geometry.
293 if (!ecore_x_e_illume_keyboard_geometry_get(zone, &sx, &sy, &sw, &sh))
294 sx = sy = sw = sh = 0;
299 _conformant_part_size_set(obj,wd->virtualkeypad, sx, sy, sw, sh);
301 if (part_type & ELM_CONFORM_SOFTKEY_PART)
303 if ((!_conformant_part_geometry_env_get("ILLUME_STK",
304 &sx, &sy, &sw, &sh)) && (xwin))
306 #ifdef HAVE_ELEMENTARY_X
307 //No information of the softkey geometry, reset the geometry.
308 if (!ecore_x_e_illume_softkey_geometry_get(zone, &sx, &sy, &sw, &sh))
309 sx = sy = sw = sh = 0;
314 _conformant_part_size_set(obj, wd->panel, sx, sy, sw, sh);
319 _swallow_conformant_parts(Evas_Object *obj)
321 Widget_Data *wd = elm_widget_data_get(obj);
326 wd->shelf = evas_object_rectangle_add(evas_object_evas_get(obj));
327 elm_widget_sub_object_add(obj, wd->shelf);
328 evas_object_size_hint_min_set(wd->shelf, -1, 0);
329 evas_object_size_hint_max_set(wd->shelf, -1, 0);
332 _conformant_part_sizing_eval(obj, ELM_CONFORM_INDICATOR_PART);
333 evas_object_color_set(wd->shelf, 0, 0, 0, 0);
334 edje_object_part_swallow(wd->base, "elm.swallow.shelf", wd->shelf);
336 if (!wd->virtualkeypad)
338 wd->virtualkeypad = evas_object_rectangle_add(evas_object_evas_get(obj));
339 elm_widget_sub_object_add(obj, wd->virtualkeypad);
340 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
341 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
344 _conformant_part_sizing_eval(obj, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
345 evas_object_color_set(wd->virtualkeypad, 0, 0, 0, 0);
346 edje_object_part_swallow(wd->base, "elm.swallow.virtualkeypad",
351 wd->panel = evas_object_rectangle_add(evas_object_evas_get(obj));
352 elm_widget_sub_object_add(obj, wd->panel);
353 evas_object_size_hint_min_set(wd->panel, -1, 0);
354 evas_object_size_hint_max_set(wd->panel, -1, 0);
357 _conformant_part_sizing_eval(obj, ELM_CONFORM_SOFTKEY_PART);
358 evas_object_color_set(wd->panel, 0, 0, 0, 0);
359 edje_object_part_swallow(wd->base, "elm.swallow.panel", wd->panel);
363 _changed_size_hints(void *data, Evas *e __UNUSED__,
364 Evas_Object *obj __UNUSED__,
365 void *event_info __UNUSED__)
367 Widget_Data *wd = elm_widget_data_get(data);
374 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
376 Widget_Data *wd = elm_widget_data_get(obj);
377 Evas_Object *sub = event_info;
379 if (sub == wd->content)
381 evas_object_event_callback_del_full(sub,
382 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
383 _changed_size_hints, obj);
389 /* unused now - but meant to be for making sure the focused widget is always
390 * visible when the vkbd comes and goes by moving the conformant obj (and thus
391 * its children) to show the focused widget (and if focus changes follow)
394 _focus_object_get(const Evas_Object *obj)
396 Evas_Object *win, *foc;
398 win = elm_widget_top_get(obj);
399 if (!win) return NULL;
400 foc = elm_widget_top_get(win);
404 _focus_object_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
406 evas_object_geometry_get(obj, x, y, w, h);
410 _focus_change_del(void *data, Evas_Object *obj, void *event_info)
412 // called from toplevel when the focused window shanges
416 _autoscroll_move(Evas_Object *obj)
418 // move conformant edje by delta to show focused widget
422 _autoscroll_mode_enable(Evas_Object *obj)
424 // called when autoscroll mode should be on - content area smaller than
426 // 1. get focused object
427 // 2. if not in visible conformant area calculate delta needed to
429 // 3. store delta and call _autoscroll_move() which either asanimates
430 // or jumps right there
434 _autoscroll_mode_disable(Evas_Object *obj)
436 // called when autoscroll mode should be off - set delta to 0 and
437 // call _autoscroll_move()
442 _conformant_move_resize_event_cb(void *data __UNUSED__, Evas *e __UNUSED__,
443 Evas_Object *obj, void *event_info __UNUSED__)
445 Conformant_Part_Type part_type;
446 Widget_Data *wd = elm_widget_data_get(obj);
449 part_type = (ELM_CONFORM_INDICATOR_PART |
450 ELM_CONFORM_SOFTKEY_PART |
451 ELM_CONFORM_VIRTUAL_KEYPAD_PART);
452 _conformant_part_sizing_eval(obj, part_type);
455 // showing the focused/important region.
457 _content_resize_event_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj
458 __UNUSED__, void *event_info __UNUSED__)
460 Evas_Object *conformant = (Evas_Object *)data;
461 Widget_Data *wd = elm_widget_data_get(conformant);
464 #ifdef HAVE_ELEMENTARY_X
465 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF) return;
468 if (wd->show_region_job) ecore_job_del(wd->show_region_job);
469 wd->show_region_job = ecore_job_add(_show_region_job, conformant);
473 _show_region_job(void *data)
475 Evas_Object *focus_obj;
476 Evas_Object *conformant = (Evas_Object *)data;
477 Widget_Data *wd = elm_widget_data_get(conformant);
481 focus_obj = elm_widget_focused_object_get(conformant);
484 Evas_Coord x, y, w, h;
486 elm_widget_show_region_get(focus_obj, &x, &y, &w, &h);
488 if (h < _elm_config->finger_size)
489 h = _elm_config->finger_size;
491 elm_widget_show_region_set(focus_obj, x, y, w, h, EINA_TRUE);
494 wd->show_region_job = NULL;
497 #ifdef HAVE_ELEMENTARY_X
499 _update_autoscroll_objs(void *data)
503 Evas_Object *sub, *top_scroller = NULL;
504 Evas_Object *conformant = (Evas_Object *)data;
505 Widget_Data *wd = elm_widget_data_get(data);
509 sub = elm_widget_focused_object_get(conformant);
510 //Look up for Top most scroller in the Focus Object hierarchy inside Conformant.
514 type = elm_widget_type_get(sub);
515 if (!strcmp(type, "conformant")) break;
516 for (i = 0; i < SUB_TYPE_COUNT; i++)
517 if (!strcmp(type, sub_type[i]))
522 sub = elm_object_parent_widget_get(sub);
525 //If the scroller got changed by app, replace it.
526 if (top_scroller != wd->scroller)
528 if (wd->scroller) evas_object_event_callback_del(wd->scroller,
529 EVAS_CALLBACK_RESIZE,
530 _content_resize_event_cb);
531 wd->scroller = top_scroller;
532 if (wd->scroller) evas_object_event_callback_add(wd->scroller,
533 EVAS_CALLBACK_RESIZE,
534 _content_resize_event_cb,
540 _prop_change(void *data, int type __UNUSED__, void *event)
542 Ecore_X_Event_Window_Property *ev;
543 Widget_Data *wd = elm_widget_data_get(data);
545 if (!wd) return ECORE_CALLBACK_PASS_ON;
547 if (ev->atom == ECORE_X_ATOM_E_ILLUME_ZONE)
549 Conformant_Part_Type part_type;
551 part_type = (ELM_CONFORM_INDICATOR_PART |
552 ELM_CONFORM_SOFTKEY_PART |
553 ELM_CONFORM_VIRTUAL_KEYPAD_PART);
554 _conformant_part_sizing_eval(data, part_type);
556 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_GEOMETRY)
557 _conformant_part_sizing_eval(data, ELM_CONFORM_INDICATOR_PART);
558 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_SOFTKEY_GEOMETRY)
559 _conformant_part_sizing_eval(data, ELM_CONFORM_SOFTKEY_PART);
560 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_KEYBOARD_GEOMETRY)
561 _conformant_part_sizing_eval(data, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
562 else if (ev->atom == ECORE_X_ATOM_E_VIRTUAL_KEYBOARD_STATE)
566 printf("Keyboard Geometry Changed\n");
567 zone = ecore_x_e_illume_zone_get(ev->win);
568 wd->vkb_state = ecore_x_e_virtual_keyboard_state_get(zone);
569 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF)
571 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
572 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
575 _update_autoscroll_objs(data);
578 return ECORE_CALLBACK_PASS_ON;
583 elm_conformant_add(Evas_Object *parent)
589 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
591 ELM_SET_WIDTYPE(widtype, "conformant");
592 elm_widget_type_set(obj, "conformant");
593 elm_widget_sub_object_add(parent, obj);
594 elm_widget_data_set(obj, wd);
595 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
596 elm_widget_del_hook_set(obj, _del_hook);
597 elm_widget_theme_hook_set(obj, _theme_hook);
598 elm_widget_can_focus_set(obj, EINA_FALSE);
599 elm_widget_content_set_hook_set(obj, _content_set_hook);
600 elm_widget_content_get_hook_set(obj, _content_get_hook);
601 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
603 wd->base = edje_object_add(e);
604 _elm_theme_object_set(obj, wd->base, "conformant", "base", "default");
605 elm_widget_resize_object_set(obj, wd->base);
607 _swallow_conformant_parts(obj);
609 #ifdef HAVE_ELEMENTARY_X
610 Evas_Object *top = elm_widget_top_get(obj);
611 Ecore_X_Window xwin = elm_win_xwindow_get(top);
613 if ((xwin) && (!elm_win_inlined_image_object_get(top)))
615 wd->prop_hdl = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY,
617 wd->vkb_state = ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF;
619 // FIXME: get kbd region prop
622 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
623 _conformant_move_resize_event_cb, obj);
624 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE,
625 _conformant_move_resize_event_cb, obj);
627 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
629 _mirrored_set(obj, elm_widget_mirrored_get(obj));
634 EINA_DEPRECATED EAPI void
635 elm_conformant_content_set(Evas_Object *obj, Evas_Object *content)
637 _content_set_hook(obj, NULL, content);
640 EINA_DEPRECATED EAPI Evas_Object *
641 elm_conformant_content_get(const Evas_Object *obj)
643 return _content_get_hook(obj, NULL);
646 EINA_DEPRECATED EAPI Evas_Object *
647 elm_conformant_content_unset(Evas_Object *obj)
649 return _content_unset_hook(obj, NULL);
652 EINA_DEPRECATED EAPI Evas_Object *
653 elm_conformant_content_area_get(const Evas_Object *obj)
655 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
656 Widget_Data *wd = elm_widget_data_get(obj);
658 if (!wd) return NULL;
659 /*Finger waggle warning*/
660 _elm_dangerous_call_check(__FUNCTION__);
661 return (Evas_Object *)edje_object_part_object_get(wd->base, "elm.swallow.content");