1 #include <Elementary.h>
5 * @defgroup Conformant Conformant
8 * The aim is to provide a widget that can be used in elementary apps to
9 * account for space taken up by the indicator & softkey windows when running
10 * the illume2 module of E17.
13 typedef struct _Widget_Data Widget_Data;
17 Evas_Object *shelf, *panel, *virtualkeypad;
19 Evas_Object *scroller;
20 Ecore_Event_Handler *prop_hdl;
21 #ifdef HAVE_ELEMENTARY_X
22 Ecore_X_Virtual_Keyboard_State vkb_state;
26 /* local function prototypes */
27 static const char *widtype = NULL;
29 _del_hook(Evas_Object *obj);
31 _theme_hook(Evas_Object *obj);
33 _swallow_conformant_parts(Evas_Object *obj);
35 _sizing_eval(Evas_Object *obj);
37 _prop_change(void *data, int type, void *event);
41 _del_hook(Evas_Object *obj)
43 Widget_Data *wd = elm_widget_data_get(obj);
45 if (wd->prop_hdl) ecore_event_handler_del(wd->prop_hdl);
46 if (wd->shelf) evas_object_del(wd->shelf);
47 if (wd->virtualkeypad) evas_object_del(wd->virtualkeypad);
48 if (wd->panel) evas_object_del(wd->panel);
53 _theme_hook(Evas_Object *obj)
55 Widget_Data *wd = elm_widget_data_get(obj);
57 _elm_theme_object_set(obj, wd->base, "conformant", "base",
58 elm_widget_style_get(obj));
59 _swallow_conformant_parts(obj);
61 if (wd->content) edje_object_part_swallow(wd->base, "elm.swallow.content",
63 edje_object_scale_set(wd->base, elm_widget_scale_get(obj)
64 * _elm_config->scale);
69 _sizing_eval(Evas_Object *obj)
71 Widget_Data *wd = elm_widget_data_get(obj);
72 Evas_Coord mw = -1, mh = -1;
74 edje_object_size_min_calc(wd->base, &mw, &mh);
75 evas_object_size_hint_min_set(obj, mw, mh);
76 evas_object_size_hint_max_set(obj, -1, -1);
80 _swallow_conformant_parts(Evas_Object *obj)
82 Widget_Data *wd = elm_widget_data_get(obj);
85 #ifdef HAVE_ELEMENTARY_X
86 Ecore_X_Window zone, xwin;
88 xwin = elm_win_xwindow_get(obj);
89 zone = ecore_x_e_illume_zone_get(xwin);
91 ecore_x_e_illume_indicator_geometry_get(zone, NULL, NULL, NULL, &sh);
95 wd->shelf = evas_object_rectangle_add(evas_object_evas_get(obj));
96 evas_object_color_set(wd->shelf, 0, 0, 0, 0);
97 evas_object_size_hint_min_set(wd->shelf, -1, sh);
98 evas_object_size_hint_max_set(wd->shelf, -1, sh);
99 edje_object_part_swallow(wd->base, "elm.swallow.shelf", wd->shelf);
103 #ifdef HAVE_ELEMENTARY_X
104 ecore_x_e_illume_keyboard_geometry_get(zone, NULL, NULL, NULL, &sh);
107 if (!wd->virtualkeypad)
108 wd->virtualkeypad = evas_object_rectangle_add(evas_object_evas_get(obj));
109 evas_object_color_set(wd->virtualkeypad, 0, 0, 0, 0);
110 evas_object_size_hint_min_set(wd->virtualkeypad, -1, sh);
111 evas_object_size_hint_max_set(wd->virtualkeypad, -1, sh);
112 edje_object_part_swallow(wd->base, "elm.swallow.virtualkeypad",
116 #ifdef HAVE_ELEMENTARY_X
117 ecore_x_e_illume_softkey_geometry_get(zone, NULL, NULL, NULL, &sh);
121 wd->panel = evas_object_rectangle_add(evas_object_evas_get(obj));
122 evas_object_color_set(wd->panel, 0, 0, 0, 0);
123 evas_object_size_hint_min_set(wd->panel, -1, sh);
124 evas_object_size_hint_max_set(wd->panel, -1, sh);
125 edje_object_part_swallow(wd->base, "elm.swallow.panel", wd->panel);
129 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
131 Widget_Data *wd = elm_widget_data_get(data);
137 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
139 Widget_Data *wd = elm_widget_data_get(obj);
140 Evas_Object *sub = event_info;
142 if (sub == wd->content)
144 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
145 _changed_size_hints, obj);
152 _content_resize_event_cb(void *data, Evas *e, Evas_Object *obj,
155 Evas_Object *focus_obj;
156 Widget_Data *wd = elm_widget_data_get(obj);
157 if (wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF) return;
158 focus_obj = elm_widget_focused_object_get(obj);
161 Evas_Coord x, y, w, h;
163 elm_widget_show_region_get(focus_obj, &x, &y, &w, &h);
165 if (h < _elm_config->finger_size)
166 h = _elm_config->finger_size;
168 h = 1 + h; //elm_widget_show_region_set expects some change, to redo the job.
169 elm_widget_show_region_set(focus_obj, x, y, w, h);
174 _update_autoscroll_objs(void *data)
177 Evas_Object *sub, *top_scroller = NULL;
178 Evas_Object *conformant = (Evas_Object *) data;
179 Widget_Data *wd = elm_widget_data_get(data);
181 sub = elm_widget_focused_object_get(conformant);
183 //Look up for Top most scroller in the Focus Object hierarchy inside Conformant.
186 type = elm_widget_type_get(sub);
187 if (!strcmp(type, "conformant")) break;
188 if (!strcmp(type, "scroller") || !strcmp(type, "genlist"))
191 sub = elm_object_parent_widget_get(sub);
194 //If the scroller got changed by app, replace it.
195 if (top_scroller != wd->scroller)
197 if (wd->scroller) evas_object_event_callback_del(wd->scroller,
198 EVAS_CALLBACK_RESIZE,
199 _content_resize_event_cb);
200 wd->scroller = top_scroller;
201 if (wd->scroller) evas_object_event_callback_add(wd->scroller,
202 EVAS_CALLBACK_RESIZE,
203 _content_resize_event_cb,
209 _prop_change(void *data, int type __UNUSED__, void *event)
211 #ifdef HAVE_ELEMENTARY_X
212 int indicator_height=0;
213 Ecore_X_Virtual_Keyboard_State virt_keypad_state = ECORE_X_VIRTUAL_KEYBOARD_STATE_UNKNOWN;
214 Ecore_X_Event_Window_Property *ev;
215 Widget_Data *wd = elm_widget_data_get(data);
216 if (!wd) return ECORE_CALLBACK_PASS_ON;
218 if (ev->atom == ECORE_X_ATOM_E_ILLUME_ZONE)
223 zone = ecore_x_e_illume_zone_get(ev->win);
224 ecore_x_e_illume_indicator_geometry_get(zone, NULL, NULL, NULL, &sh);
225 if (sh < 0) sh = indicator_height;
227 evas_object_size_hint_min_set(wd->shelf, -1, sh);
228 evas_object_size_hint_max_set(wd->shelf, -1, sh);
230 zone = ecore_x_e_illume_zone_get(ev->win);
231 ecore_x_e_illume_keyboard_geometry_get(zone, NULL, NULL, NULL, &sh);
233 evas_object_size_hint_min_set(wd->virtualkeypad, -1, sh);
234 evas_object_size_hint_max_set(wd->virtualkeypad, -1, sh);
236 ecore_x_e_illume_softkey_geometry_get(zone, NULL, NULL, NULL, &sh);
238 evas_object_size_hint_min_set(wd->panel, -1, sh);
239 evas_object_size_hint_max_set(wd->panel, -1, sh);
241 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_GEOMETRY)
246 zone = ecore_x_e_illume_zone_get(ev->win);
247 ecore_x_e_illume_indicator_geometry_get(zone, NULL, NULL, NULL, &sh);
249 evas_object_size_hint_min_set(wd->shelf, -1, sh);
250 evas_object_size_hint_max_set(wd->shelf, -1, sh);
252 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_SOFTKEY_GEOMETRY)
257 zone = ecore_x_e_illume_zone_get(ev->win);
258 ecore_x_e_illume_softkey_geometry_get(zone, NULL, NULL, NULL, &sh);
260 evas_object_size_hint_min_set(wd->panel, -1, sh);
261 evas_object_size_hint_max_set(wd->panel, -1, sh);
263 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_KEYBOARD_GEOMETRY)
266 int ky = -1, kh = -1;
268 zone = ecore_x_e_illume_zone_get(ev->win);
269 ecore_x_e_illume_keyboard_geometry_get(zone, NULL, &ky, NULL, &kh);
271 evas_object_size_hint_min_set(wd->virtualkeypad, -1, kh);
272 evas_object_size_hint_max_set(wd->virtualkeypad, -1, kh);
274 else if (ev->atom == ECORE_X_ATOM_E_VIRTUAL_KEYBOARD_STATE)
277 zone = ecore_x_e_illume_zone_get(ev->win);
278 wd->vkb_state = ecore_x_e_virtual_keyboard_state_get(zone);
280 if(wd->vkb_state == ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF)
282 evas_object_size_hint_min_set(wd->virtualkeypad, -1, 0);
283 evas_object_size_hint_max_set(wd->virtualkeypad, -1, 0);
286 _update_autoscroll_objs(data);
290 return ECORE_CALLBACK_PASS_ON;
294 * Add a new Conformant object
296 * @param parent The parent object
297 * @return The new conformant object or NULL if it cannot be created
299 * @ingroup Conformant
302 elm_conformant_add(Evas_Object *parent)
308 wd = ELM_NEW(Widget_Data);
310 evas = evas_object_evas_get(parent);
312 obj = elm_widget_add(evas);
313 ELM_SET_WIDTYPE(widtype, "conformant");
314 elm_widget_type_set(obj, "conformant");
315 elm_widget_sub_object_add(parent, obj);
316 elm_widget_data_set(obj, wd);
317 elm_widget_del_hook_set(obj, _del_hook);
318 elm_widget_theme_hook_set(obj, _theme_hook);
320 wd->base = edje_object_add(evas);
321 _elm_theme_object_set(obj, wd->base, "conformant", "base", "default");
322 elm_widget_resize_object_set(obj, wd->base);
323 _swallow_conformant_parts(obj);
325 #ifdef HAVE_ELEMENTARY_X
326 wd->prop_hdl = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY,
328 wd->vkb_state = ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF;
331 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
338 * Set the content of the conformant widget
340 * Once the content object is set, a previously set one will be deleted.
341 * If you want to keep that old content object, use the
342 * elm_conformat_content_unset() function.
344 * @param obj The conformant object
345 * @return The content that was being used
347 * @ingroup Conformant
350 elm_conformant_content_set(Evas_Object *obj, Evas_Object *content)
352 ELM_CHECK_WIDTYPE(obj, widtype);
353 Widget_Data *wd = elm_widget_data_get(obj);
355 if (wd->content == content) return;
356 if (wd->content) evas_object_del(wd->content);
357 wd->content = content;
360 elm_widget_sub_object_add(obj, content);
361 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
362 _changed_size_hints, obj);
363 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
369 * Unset the content of the conformant widget
371 * Unparent and return the content object which was set for this widget;
373 * @param obj The conformant object
374 * @return The content that was being used
376 * @ingroup Conformant
379 elm_conformant_content_unset(Evas_Object *obj)
381 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
382 Widget_Data *wd = elm_widget_data_get(obj);
383 Evas_Object *content;
384 if (!wd) return NULL;
385 if (!wd->content) return NULL;
386 content = wd->content;
387 elm_widget_sub_object_del(obj, wd->content);
388 edje_object_part_unswallow(wd->base, wd->content);