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, *sliding_win;
18 Evas_Object *scroller;
19 int is_sliding_win_visible;
20 #ifdef HAVE_ELEMENTARY_X
21 Ecore_Event_Handler *prop_hdl;
22 Ecore_X_Virtual_Keyboard_State vkb_state;
26 Ecore_Animator *animator; // animaton timer
27 double start; // time started
28 Evas_Coord auto_x, auto_y; // desired delta
29 Evas_Coord x, y; // current delta
31 Ecore_Job *show_region_job;
34 /* Enum to identify conformant swallow parts */
35 typedef enum _Conformant_Part_Type Conformant_Part_Type;
36 enum _Conformant_Part_Type
38 ELM_CONFORM_INDICATOR_PART = 1,
39 ELM_CONFORM_SOFTKEY_PART = 2,
40 ELM_CONFORM_VIRTUAL_KEYPAD_PART = 4,
41 ELM_CONFORM_SLIDING_WIN_PART = 8
44 #define SUB_TYPE_COUNT 2
45 static char *sub_type[SUB_TYPE_COUNT] = { "scroller", "genlist" };
47 /* local function prototypes */
48 static const char *widtype = NULL;
49 static void _del_pre_hook(Evas_Object *obj);
50 static void _del_hook(Evas_Object *obj);
51 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
52 static void _theme_hook(Evas_Object *obj);
53 static void _content_set_hook(Evas_Object *obj,
55 Evas_Object *content);
56 static Evas_Object *_content_get_hook(const Evas_Object *obj,
58 static Evas_Object *_content_unset_hook(Evas_Object *obj, const char *part);
59 static void _swallow_conformant_parts(Evas_Object *obj);
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);
68 static void _conformant_move_resize_event_cb(void *data,
72 static void _sizing_eval(Evas_Object *obj);
73 static void _show_region_job(void *data);
74 static Eina_Bool _prop_change(void *data, int type, void *event);
75 static void _changed_size_hints(void *data, Evas *e,
81 _del_pre_hook(Evas_Object *obj)
83 Widget_Data *wd = elm_widget_data_get(obj);
85 #ifdef HAVE_ELEMENTARY_X
86 if (wd->prop_hdl) ecore_event_handler_del(wd->prop_hdl);
91 _del_hook(Evas_Object *obj)
93 Widget_Data *wd = elm_widget_data_get(obj);
96 if (wd->show_region_job) ecore_job_del(wd->show_region_job);
101 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
103 Widget_Data *wd = elm_widget_data_get(obj);
106 edje_object_mirrored_set(wd->base, rtl);
110 _theme_hook(Evas_Object *obj)
112 Widget_Data *wd = elm_widget_data_get(obj);
115 _elm_widget_mirrored_reload(obj);
116 _mirrored_set(obj, elm_widget_mirrored_get(obj));
117 _elm_theme_object_set(obj, wd->base, "conformant", "base",
118 elm_widget_style_get(obj));
119 _swallow_conformant_parts(obj);
122 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->content);
123 edje_object_scale_set(wd->base, elm_widget_scale_get(obj)
124 * _elm_config->scale);
129 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
131 ELM_CHECK_WIDTYPE(obj, widtype);
134 if (part && strcmp(part, "default")) return;
135 wd = elm_widget_data_get(obj);
137 if (wd->content == content) return;
138 if (wd->content) evas_object_del(wd->content);
139 wd->content = content;
142 elm_widget_sub_object_add(obj, content);
143 evas_object_event_callback_add(content,
144 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
145 _changed_size_hints, obj);
146 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
152 _content_get_hook(const Evas_Object *obj, const char *part)
154 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
157 if (part && strcmp(part, "default")) return NULL;
158 wd = elm_widget_data_get(obj);
159 if (!wd) return NULL;
164 _content_unset_hook(Evas_Object *obj, const char *part)
166 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
168 Evas_Object *content;
169 if (part && strcmp(part, "default")) return NULL;
170 wd = elm_widget_data_get(obj);
171 if ((!wd) || (!wd->content)) return NULL;
172 content = wd->content;
173 elm_widget_sub_object_del(obj, wd->content);
174 evas_object_event_callback_del_full(wd->content,
175 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
176 _changed_size_hints, obj);
177 edje_object_part_unswallow(wd->base, wd->content);
183 _sizing_eval(Evas_Object *obj)
185 Widget_Data *wd = elm_widget_data_get(obj);
186 Evas_Coord mw = -1, mh = -1;
189 edje_object_size_min_calc(wd->base, &mw, &mh);
190 evas_object_size_hint_min_set(obj, mw, mh);
191 evas_object_size_hint_max_set(obj, -1, -1);
194 /* Example of env vars:
195 * ILLUME_KBD="0, 0, 800, 301"
196 * ILLUME_IND=0,0,800,32
197 * ILLUME_STK="0,568,800,32
200 _conformant_part_geometry_env_get(const char *part, int *sx, int *sy, int *sw, int *sh)
202 const char delimiters[] = " ,;";
203 char *env_val, *token;
207 if (!(env_val = getenv(part))) return EINA_FALSE;
209 /* strtok would modify env var if not copied to a buffer */
210 strncpy(buf, env_val, sizeof(buf));
212 token = strtok(buf, delimiters);
213 if (!token) return EINA_FALSE;
216 token = strtok(NULL, delimiters);
217 if (!token) return EINA_FALSE;
220 token = strtok(NULL, delimiters);
221 if (!token) return EINA_FALSE;
224 token = strtok(NULL, delimiters);
225 if (!token) return EINA_FALSE;
236 _conformant_part_size_set(Evas_Object *obj, Evas_Object *sobj, Evas_Coord sx,
237 Evas_Coord sy, Evas_Coord sw, Evas_Coord sh)
239 Evas_Coord cx, cy, cw, ch;
240 Evas_Coord part_height = 0, part_width = 0;
242 evas_object_geometry_get(obj, &cx, &cy, &cw, &ch);
244 /* Part overlapping with conformant */
245 if ((cx < (sx + sw)) && ((cx + cw) > sx)
246 && (cy < (sy + sh)) && ((cy + ch) > sy))
248 part_height = MIN((cy + ch), (sy + sh)) - MAX(cy, sy);
249 part_width = MIN((cx + cw), (sx + sw)) - MAX(cx, sx);
252 evas_object_size_hint_min_set(sobj, part_width, part_height);
253 evas_object_size_hint_max_set(sobj, part_width, part_height);
257 _conformant_part_sizing_eval(Evas_Object *obj, Conformant_Part_Type part_type)
259 Ecore_X_Window zone = 0, xwin;
261 int sx = -1, sy = -1, sw = -1, sh = -1;
262 Widget_Data *wd = elm_widget_data_get(obj);
266 top = elm_widget_top_get(obj);
267 #ifdef HAVE_ELEMENTARY_X
268 xwin = elm_win_xwindow_get(top);
270 zone = ecore_x_e_illume_zone_get(xwin);
273 if (part_type & ELM_CONFORM_INDICATOR_PART)
275 if ((!_conformant_part_geometry_env_get("ILLUME_IND",
276 &sx, &sy, &sw, &sh)) && (xwin))
278 #ifdef HAVE_ELEMENTARY_X
279 //No information of the indicator geometry, reset the geometry.
280 if (!ecore_x_e_illume_indicator_geometry_get(zone, &sx, &sy, &sw, &sh))
281 sx = sy = sw = sh = 0;
286 _conformant_part_size_set(obj, wd->shelf, sx, sy, sw, sh);
288 if (part_type & ELM_CONFORM_VIRTUAL_KEYPAD_PART)
290 if ((!_conformant_part_geometry_env_get("ILLUME_KBD",
291 &sx, &sy, &sw, &sh)) && (xwin))
293 #ifdef HAVE_ELEMENTARY_X
294 //No information of the keyboard geometry, reset the geometry.
295 if (!ecore_x_e_illume_keyboard_geometry_get(zone, &sx, &sy, &sw, &sh))
296 sx = sy = sw = sh = 0;
301 _conformant_part_size_set(obj,wd->virtualkeypad, sx, sy, sw, sh);
303 if (part_type & ELM_CONFORM_SOFTKEY_PART)
305 if ((!_conformant_part_geometry_env_get("ILLUME_STK",
306 &sx, &sy, &sw, &sh)) && (xwin))
308 #ifdef HAVE_ELEMENTARY_X
309 //No information of the softkey geometry, reset the geometry.
310 if (!ecore_x_e_illume_softkey_geometry_get(zone, &sx, &sy, &sw, &sh))
311 sx = sy = sw = sh = 0;
316 _conformant_part_size_set(obj, wd->panel, sx, sy, sw, sh);
321 _swallow_conformant_parts(Evas_Object *obj)
323 Widget_Data *wd = elm_widget_data_get(obj);
328 wd->shelf = evas_object_rectangle_add(evas_object_evas_get(obj));
329 elm_widget_sub_object_add(obj, wd->shelf);
330 evas_object_size_hint_min_set(wd->shelf, -1, 0);
331 evas_object_size_hint_max_set(wd->shelf, -1, 0);
334 _conformant_part_sizing_eval(obj, ELM_CONFORM_INDICATOR_PART);
335 evas_object_color_set(wd->shelf, 0, 0, 0, 0);
336 edje_object_part_swallow(wd->base, "elm.swallow.shelf", wd->shelf);
338 if (!wd->virtualkeypad)
340 wd->virtualkeypad = evas_object_rectangle_add(evas_object_evas_get(obj));
341 elm_widget_sub_object_add(obj, wd->virtualkeypad);
342 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
343 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
346 _conformant_part_sizing_eval(obj, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
347 evas_object_color_set(wd->virtualkeypad, 0, 0, 0, 0);
348 edje_object_part_swallow(wd->base, "elm.swallow.virtualkeypad",
351 if (!wd->sliding_win)
353 wd->sliding_win = evas_object_rectangle_add(evas_object_evas_get(obj));
354 elm_widget_sub_object_add(obj, wd->sliding_win);
355 evas_object_size_hint_min_set(wd->sliding_win, -1, 0);
356 evas_object_size_hint_max_set(wd->sliding_win, -1, 0);
358 #ifdef HAVE_ELEMENTARY_X
360 _conformant_part_sizing_eval(obj, ELM_CONFORM_SLIDING_WIN_PART);
362 evas_object_color_set(wd->sliding_win, 0, 0, 0, 0);
366 wd->panel = evas_object_rectangle_add(evas_object_evas_get(obj));
367 elm_widget_sub_object_add(obj, wd->panel);
368 evas_object_size_hint_min_set(wd->panel, -1, 0);
369 evas_object_size_hint_max_set(wd->panel, -1, 0);
372 _conformant_part_sizing_eval(obj, ELM_CONFORM_SOFTKEY_PART);
373 evas_object_color_set(wd->panel, 0, 0, 0, 0);
374 edje_object_part_swallow(wd->base, "elm.swallow.panel", wd->panel);
378 _changed_size_hints(void *data, Evas *e __UNUSED__,
379 Evas_Object *obj __UNUSED__,
380 void *event_info __UNUSED__)
382 Widget_Data *wd = elm_widget_data_get(data);
389 _sub_del(void *data, Evas_Object *obj __UNUSED__, void *event_info)
391 Widget_Data *wd = elm_widget_data_get(data);
392 Evas_Object *sub = event_info;
394 if (sub == wd->content)
396 evas_object_event_callback_del_full(sub,
397 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
398 _changed_size_hints, data);
404 /* unused now - but meant to be for making sure the focused widget is always
405 * visible when the vkbd comes and goes by moving the conformant obj (and thus
406 * its children) to show the focused widget (and if focus changes follow)
409 _focus_object_get(const Evas_Object *obj)
411 Evas_Object *win, *foc;
413 win = elm_widget_top_get(obj);
414 if (!win) return NULL;
415 foc = elm_widget_top_get(win);
419 _focus_object_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
421 evas_object_geometry_get(obj, x, y, w, h);
425 _focus_change_del(void *data, Evas_Object *obj, void *event_info)
427 // called from toplevel when the focused window shanges
431 _autoscroll_move(Evas_Object *obj)
433 // move conformant edje by delta to show focused widget
437 _autoscroll_mode_enable(Evas_Object *obj)
439 // called when autoscroll mode should be on - content area smaller than
441 // 1. get focused object
442 // 2. if not in visible conformant area calculate delta needed to
444 // 3. store delta and call _autoscroll_move() which either asanimates
445 // or jumps right there
449 _autoscroll_mode_disable(Evas_Object *obj)
451 // called when autoscroll mode should be off - set delta to 0 and
452 // call _autoscroll_move()
457 _conformant_move_resize_event_cb(void *data __UNUSED__, Evas *e __UNUSED__,
458 Evas_Object *obj, void *event_info __UNUSED__)
460 Conformant_Part_Type part_type;
461 Widget_Data *wd = elm_widget_data_get(obj);
464 part_type = (ELM_CONFORM_INDICATOR_PART |
465 ELM_CONFORM_SOFTKEY_PART |
466 ELM_CONFORM_VIRTUAL_KEYPAD_PART |
467 ELM_CONFORM_SLIDING_WIN_PART);
468 _conformant_part_sizing_eval(obj, part_type);
471 // showing the focused/important region.
473 _content_resize_event_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj
474 __UNUSED__, void *event_info __UNUSED__)
476 Evas_Object *conformant = (Evas_Object *)data;
477 Widget_Data *wd = elm_widget_data_get(conformant);
480 #ifdef HAVE_ELEMENTARY_X
481 if ((wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF)
482 && (!wd->is_sliding_win_visible)) return;
485 if (wd->show_region_job) ecore_job_del(wd->show_region_job);
486 wd->show_region_job = ecore_job_add(_show_region_job, conformant);
490 _show_region_job(void *data)
492 Evas_Object *focus_obj;
493 Evas_Object *conformant = (Evas_Object *)data;
494 Widget_Data *wd = elm_widget_data_get(conformant);
498 focus_obj = elm_widget_focused_object_get(conformant);
501 Evas_Coord x, y, w, h;
503 elm_widget_show_region_get(focus_obj, &x, &y, &w, &h);
505 if (h < _elm_config->finger_size)
506 h = _elm_config->finger_size;
508 elm_widget_show_region_set(focus_obj, x, y, w, h, EINA_TRUE);
511 wd->show_region_job = NULL;
514 #ifdef HAVE_ELEMENTARY_X
516 _update_autoscroll_objs(void *data)
520 Evas_Object *sub, *top_scroller = NULL;
521 Evas_Object *conformant = (Evas_Object *)data;
522 Widget_Data *wd = elm_widget_data_get(data);
526 sub = elm_widget_focused_object_get(conformant);
527 //Look up for Top most scroller in the Focus Object hierarchy inside Conformant.
531 type = elm_widget_type_get(sub);
532 if (!strcmp(type, "conformant")) break;
533 for (i = 0; i < SUB_TYPE_COUNT; i++)
534 if (!strcmp(type, sub_type[i]))
539 sub = elm_object_parent_widget_get(sub);
542 //If the scroller got changed by app, replace it.
543 if (top_scroller != wd->scroller)
545 if (wd->scroller) evas_object_event_callback_del(wd->scroller,
546 EVAS_CALLBACK_RESIZE,
547 _content_resize_event_cb);
548 wd->scroller = top_scroller;
549 if (wd->scroller) evas_object_event_callback_add(wd->scroller,
550 EVAS_CALLBACK_RESIZE,
551 _content_resize_event_cb,
557 _prop_change(void *data, int type __UNUSED__, void *event)
559 Ecore_X_Event_Window_Property *ev;
560 Widget_Data *wd = elm_widget_data_get(data);
562 if (!wd) return ECORE_CALLBACK_PASS_ON;
564 if (ev->atom == ECORE_X_ATOM_E_ILLUME_ZONE)
566 Conformant_Part_Type part_type;
568 part_type = (ELM_CONFORM_INDICATOR_PART |
569 ELM_CONFORM_SOFTKEY_PART |
570 ELM_CONFORM_VIRTUAL_KEYPAD_PART |
571 ELM_CONFORM_SLIDING_WIN_PART);
572 _conformant_part_sizing_eval(data, part_type);
574 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_GEOMETRY)
575 _conformant_part_sizing_eval(data, ELM_CONFORM_INDICATOR_PART);
576 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_SOFTKEY_GEOMETRY)
577 _conformant_part_sizing_eval(data, ELM_CONFORM_SOFTKEY_PART);
578 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_KEYBOARD_GEOMETRY)
579 _conformant_part_sizing_eval(data, ELM_CONFORM_VIRTUAL_KEYPAD_PART);
580 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_SLIDING_WIN_GEOMETRY)
581 _conformant_part_sizing_eval(data, ELM_CONFORM_SLIDING_WIN_PART);
582 else if (ev->atom == ECORE_X_ATOM_E_VIRTUAL_KEYBOARD_STATE)
586 printf("Keyboard Geometry Changed\n");
587 zone = ecore_x_e_illume_zone_get(ev->win);
588 wd->vkb_state = ecore_x_e_virtual_keyboard_state_get(zone);
589 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF)
591 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
592 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
595 _update_autoscroll_objs(data);
597 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_SLIDING_WIN_STATE)
601 zone = ecore_x_e_illume_zone_get(ev->win);
602 wd->is_sliding_win_visible = ecore_x_e_illume_sliding_win_state_get(zone);
604 if (!wd->is_sliding_win_visible)
606 evas_object_size_hint_min_set(wd->sliding_win, -1, 0);
607 evas_object_size_hint_max_set(wd->sliding_win, -1, 0);
610 _update_autoscroll_objs(data);
613 return ECORE_CALLBACK_PASS_ON;
618 elm_conformant_add(Evas_Object *parent)
624 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
626 ELM_SET_WIDTYPE(widtype, "conformant");
627 elm_widget_type_set(obj, "conformant");
628 elm_widget_sub_object_add(parent, obj);
629 elm_widget_data_set(obj, wd);
630 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
631 elm_widget_del_hook_set(obj, _del_hook);
632 elm_widget_theme_hook_set(obj, _theme_hook);
633 elm_widget_can_focus_set(obj, EINA_FALSE);
634 elm_widget_content_set_hook_set(obj, _content_set_hook);
635 elm_widget_content_get_hook_set(obj, _content_get_hook);
636 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
638 wd->base = edje_object_add(e);
639 _elm_theme_object_set(obj, wd->base, "conformant", "base", "default");
640 elm_widget_resize_object_set(obj, wd->base);
642 _swallow_conformant_parts(obj);
644 #ifdef HAVE_ELEMENTARY_X
645 Evas_Object *top = elm_widget_top_get(obj);
646 Ecore_X_Window xwin = elm_win_xwindow_get(top);
648 if ((xwin) && (!elm_win_inlined_image_object_get(top)))
650 wd->prop_hdl = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY,
652 wd->vkb_state = ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF;
654 // FIXME: get kbd region prop
657 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
658 _conformant_move_resize_event_cb, obj);
659 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE,
660 _conformant_move_resize_event_cb, obj);
661 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
664 _mirrored_set(obj, elm_widget_mirrored_get(obj));