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 & softkey windows when running
9 * the illume2 module of E17.
12 typedef struct _Widget_Data Widget_Data;
16 Evas_Object *shelf, *panel;
18 Ecore_Event_Handler *prop_hdl;
20 Ecore_Animator *animator; // animaton timer
21 double start; // time started
22 Evas_Coord auto_x, auto_y; // desired delta
23 Evas_Coord x, y; // current delta
27 /* local function prototypes */
28 static const char *widtype = NULL;
29 static void _del_hook(Evas_Object *obj);
30 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
31 static void _theme_hook(Evas_Object *obj);
32 static void _sizing_eval(Evas_Object *obj);
33 static Eina_Bool _prop_change(void *data, int type, void *event);
37 _del_hook(Evas_Object *obj)
39 Widget_Data *wd = elm_widget_data_get(obj);
41 if (wd->prop_hdl) ecore_event_handler_del(wd->prop_hdl);
46 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
48 Widget_Data *wd = elm_widget_data_get(obj);
50 edje_object_mirrored_set(wd->base, rtl);
54 _theme_hook(Evas_Object *obj)
56 Widget_Data *wd = elm_widget_data_get(obj);
58 _elm_widget_mirrored_reload(obj);
59 _mirrored_set(obj, elm_widget_mirrored_get(obj));
60 _elm_theme_object_set(obj, wd->base, "conformant", "base", elm_widget_style_get(obj));
62 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->content);
63 edje_object_scale_set(wd->base, elm_widget_scale_get(obj) * _elm_config->scale);
68 _sizing_eval(Evas_Object *obj)
70 Widget_Data *wd = elm_widget_data_get(obj);
71 Evas_Coord mw = -1, mh = -1;
73 edje_object_size_min_calc(wd->base, &mw, &mh);
74 evas_object_size_hint_min_set(obj, mw, mh);
75 evas_object_size_hint_max_set(obj, -1, -1);
79 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
81 Widget_Data *wd = elm_widget_data_get(data);
87 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
89 Widget_Data *wd = elm_widget_data_get(obj);
90 Evas_Object *sub = event_info;
92 if (sub == wd->content)
94 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
95 _changed_size_hints, obj);
101 /* unused now - but meant to be for making sure the focused widget is always
102 * visible when the vkbd comes and goes by moving the conformant obj (and thus
103 * its children) to show the focused widget (and if focus changes follow)
106 _focus_object_get(const Evas_Object *obj)
108 Evas_Object *win, *foc;
110 win = elm_widget_top_get(obj);
111 if (!win) return NULL;
112 foc = elm_widget_top_get(win);
116 _focus_object_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
118 evas_object_geometry_get(obj, x, y, w, h);
122 _focus_change_del(void *data, Evas_Object *obj, void *event_info)
124 // called from toplevel when the focused window shanges
128 _autoscroll_move(Evas_Object *obj)
130 // move conformant edje by delta to show focused widget
134 _autoscroll_mode_enable(Evas_Object *obj)
136 // called when autoscroll mode should be on - content area smaller than
138 // 1. get focused object
139 // 2. if not in visible conformant area calculate delta needed to
141 // 3. store delta and call _autoscroll_move() which either asanimates
142 // or jumps right there
146 _autoscroll_mode_disable(Evas_Object *obj)
148 // called when autoscroll mode should be off - set delta to 0 and
149 // call _autoscroll_move()
154 _prop_change(void *data, int type __UNUSED__, void *event)
156 #ifdef HAVE_ELEMENTARY_X
157 Ecore_X_Event_Window_Property *ev;
158 Widget_Data *wd = elm_widget_data_get(data);
159 if (!wd) return ECORE_CALLBACK_PASS_ON;
161 if (ev->atom == ECORE_X_ATOM_E_ILLUME_ZONE)
166 zone = ecore_x_e_illume_zone_get(ev->win);
167 ecore_x_e_illume_indicator_geometry_get(zone, NULL, NULL, NULL, &sh);
169 evas_object_size_hint_min_set(wd->shelf, -1, sh);
170 evas_object_size_hint_max_set(wd->shelf, -1, sh);
172 ecore_x_e_illume_softkey_geometry_get(zone, NULL, NULL, NULL, &sh);
174 evas_object_size_hint_min_set(wd->panel, -1, sh);
175 evas_object_size_hint_max_set(wd->panel, -1, sh);
177 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_GEOMETRY)
182 zone = ecore_x_e_illume_zone_get(ev->win);
183 ecore_x_e_illume_indicator_geometry_get(zone, NULL, NULL, NULL, &sh);
185 evas_object_size_hint_min_set(wd->shelf, -1, sh);
186 evas_object_size_hint_max_set(wd->shelf, -1, sh);
188 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_SOFTKEY_GEOMETRY)
193 zone = ecore_x_e_illume_zone_get(ev->win);
194 ecore_x_e_illume_softkey_geometry_get(zone, NULL, NULL, NULL, &sh);
196 evas_object_size_hint_min_set(wd->panel, -1, sh);
197 evas_object_size_hint_max_set(wd->panel, -1, sh);
199 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_KEYBOARD_GEOMETRY)
204 printf("Keyboard Geometry Changed\n");
205 zone = ecore_x_e_illume_zone_get(ev->win);
206 ecore_x_e_illume_keyboard_geometry_get(zone, NULL, &ky, NULL, NULL);
207 printf("\tGeom: %d\n", ky);
211 return ECORE_CALLBACK_PASS_ON;
215 * Add a new Conformant object
217 * @param parent The parent object
218 * @return The new conformant object or NULL if it cannot be created
220 * @ingroup Conformant
223 elm_conformant_add(Evas_Object *parent)
229 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
231 ELM_SET_WIDTYPE(widtype, "conformant");
232 elm_widget_type_set(obj, "conformant");
233 elm_widget_sub_object_add(parent, obj);
234 elm_widget_data_set(obj, wd);
235 elm_widget_del_hook_set(obj, _del_hook);
236 elm_widget_theme_hook_set(obj, _theme_hook);
237 elm_widget_can_focus_set(obj, EINA_FALSE);
239 wd->base = edje_object_add(e);
240 _elm_theme_object_set(obj, wd->base, "conformant", "base", "default");
241 elm_widget_resize_object_set(obj, wd->base);
243 #ifdef HAVE_ELEMENTARY_X
244 Ecore_X_Window zone, xwin;
247 xwin = elm_win_xwindow_get(parent);
248 zone = ecore_x_e_illume_zone_get(xwin);
250 ecore_x_e_illume_indicator_geometry_get(zone, NULL, NULL, NULL, &sh);
252 wd->shelf = evas_object_rectangle_add(e);
253 evas_object_color_set(wd->shelf, 0, 0, 0, 0);
254 evas_object_size_hint_min_set(wd->shelf, -1, sh);
255 evas_object_size_hint_max_set(wd->shelf, -1, sh);
256 edje_object_part_swallow(wd->base, "elm.swallow.shelf", wd->shelf);
259 ecore_x_e_illume_softkey_geometry_get(zone, NULL, NULL, NULL, &sh);
261 wd->panel = evas_object_rectangle_add(e);
262 evas_object_color_set(wd->panel, 0, 0, 0, 0);
263 evas_object_size_hint_min_set(wd->panel, -1, sh);
264 evas_object_size_hint_max_set(wd->panel, -1, sh);
265 edje_object_part_swallow(wd->base, "elm.swallow.panel", wd->panel);
267 wd->prop_hdl = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY,
269 // FIXME: get kbd region prop
272 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
274 _mirrored_set(obj, elm_widget_mirrored_get(obj));
280 * Set the content of the conformant widget
282 * Once the content object is set, a previously set one will be deleted.
283 * If you want to keep that old content object, use the
284 * elm_conformat_content_unset() function.
286 * @param obj The conformant object
287 * @return The content that was being used
289 * @ingroup Conformant
292 elm_conformant_content_set(Evas_Object *obj, Evas_Object *content)
294 ELM_CHECK_WIDTYPE(obj, widtype);
295 Widget_Data *wd = elm_widget_data_get(obj);
297 if (wd->content == content) return;
298 if (wd->content) evas_object_del(wd->content);
299 wd->content = content;
302 elm_widget_sub_object_add(obj, content);
303 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
304 _changed_size_hints, obj);
305 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
311 * Get the content of the conformant widget
313 * Return the content object which is set for this widget;
315 * @param obj The conformant object
316 * @return The content that is being used
318 * @ingroup Conformant
321 elm_conformant_content_get(const Evas_Object *obj)
323 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
324 Widget_Data *wd = elm_widget_data_get(obj);
325 if (!wd) return NULL;
330 * Unset the content of the conformant widget
332 * Unparent and return the content object which was set for this widget;
334 * @param obj The conformant object
335 * @return The content that was being used
337 * @ingroup Conformant
340 elm_conformant_content_unset(Evas_Object *obj)
342 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
343 Widget_Data *wd = elm_widget_data_get(obj);
344 Evas_Object *content;
345 if (!wd) return NULL;
346 if (!wd->content) return NULL;
347 content = wd->content;
348 elm_widget_sub_object_del(obj, wd->content);
349 edje_object_part_unswallow(wd->base, wd->content);