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 _mirrored_set(obj, elm_widget_mirrored_get(obj));
59 _elm_theme_object_set(obj, wd->base, "conformant", "base", elm_widget_style_get(obj));
61 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->content);
62 edje_object_scale_set(wd->base, elm_widget_scale_get(obj) * _elm_config->scale);
67 _sizing_eval(Evas_Object *obj)
69 Widget_Data *wd = elm_widget_data_get(obj);
70 Evas_Coord mw = -1, mh = -1;
72 edje_object_size_min_calc(wd->base, &mw, &mh);
73 evas_object_size_hint_min_set(obj, mw, mh);
74 evas_object_size_hint_max_set(obj, -1, -1);
78 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
80 Widget_Data *wd = elm_widget_data_get(data);
86 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
88 Widget_Data *wd = elm_widget_data_get(obj);
89 Evas_Object *sub = event_info;
91 if (sub == wd->content)
93 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
94 _changed_size_hints, obj);
100 /* unused now - but meant to be for making sure the focused widget is always
101 * visible when the vkbd comes and goes by moving the conformant obj (and thus
102 * its children) to show the focused widget (and if focus changes follow)
105 _focus_object_get(const Evas_Object *obj)
107 Evas_Object *win, *foc;
109 win = elm_widget_top_get(obj);
110 if (!win) return NULL;
111 foc = elm_widget_top_get(win);
115 _focus_object_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
117 evas_object_geometry_get(obj, x, y, w, h);
121 _focus_change_del(void *data, Evas_Object *obj, void *event_info)
123 // called from toplevel when the focused window shanges
127 _autoscroll_move(Evas_Object *obj)
129 // move conformant edje by delta to show focused widget
133 _autoscroll_mode_enable(Evas_Object *obj)
135 // called when autoscroll mode should be on - content area smaller than
137 // 1. get focused object
138 // 2. if not in visible conformant area calculate delta needed to
140 // 3. store delta and call _autoscroll_move() which either asanimates
141 // or jumps right there
145 _autoscroll_mode_disable(Evas_Object *obj)
147 // called when autoscroll mode should be off - set delta to 0 and
148 // call _autoscroll_move()
153 _prop_change(void *data, int type __UNUSED__, void *event)
155 #ifdef HAVE_ELEMENTARY_X
156 Ecore_X_Event_Window_Property *ev;
157 Widget_Data *wd = elm_widget_data_get(data);
158 if (!wd) return ECORE_CALLBACK_PASS_ON;
160 if (ev->atom == ECORE_X_ATOM_E_ILLUME_ZONE)
165 zone = ecore_x_e_illume_zone_get(ev->win);
166 ecore_x_e_illume_indicator_geometry_get(zone, NULL, NULL, NULL, &sh);
168 evas_object_size_hint_min_set(wd->shelf, -1, sh);
169 evas_object_size_hint_max_set(wd->shelf, -1, sh);
171 ecore_x_e_illume_softkey_geometry_get(zone, NULL, NULL, NULL, &sh);
173 evas_object_size_hint_min_set(wd->panel, -1, sh);
174 evas_object_size_hint_max_set(wd->panel, -1, sh);
176 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_GEOMETRY)
181 zone = ecore_x_e_illume_zone_get(ev->win);
182 ecore_x_e_illume_indicator_geometry_get(zone, NULL, NULL, NULL, &sh);
184 evas_object_size_hint_min_set(wd->shelf, -1, sh);
185 evas_object_size_hint_max_set(wd->shelf, -1, sh);
187 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_SOFTKEY_GEOMETRY)
192 zone = ecore_x_e_illume_zone_get(ev->win);
193 ecore_x_e_illume_softkey_geometry_get(zone, NULL, NULL, NULL, &sh);
195 evas_object_size_hint_min_set(wd->panel, -1, sh);
196 evas_object_size_hint_max_set(wd->panel, -1, sh);
198 else if (ev->atom == ECORE_X_ATOM_E_ILLUME_KEYBOARD_GEOMETRY)
203 printf("Keyboard Geometry Changed\n");
204 zone = ecore_x_e_illume_zone_get(ev->win);
205 ecore_x_e_illume_keyboard_geometry_get(zone, NULL, &ky, NULL, NULL);
206 printf("\tGeom: %d\n", ky);
210 return ECORE_CALLBACK_PASS_ON;
214 * Add a new Conformant object
216 * @param parent The parent object
217 * @return The new conformant object or NULL if it cannot be created
219 * @ingroup Conformant
222 elm_conformant_add(Evas_Object *parent)
228 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
230 wd = ELM_NEW(Widget_Data);
232 evas = evas_object_evas_get(parent);
233 if (!evas) return NULL;
235 obj = elm_widget_add(evas);
236 ELM_SET_WIDTYPE(widtype, "conformant");
237 elm_widget_type_set(obj, "conformant");
238 elm_widget_sub_object_add(parent, obj);
239 elm_widget_data_set(obj, wd);
240 elm_widget_del_hook_set(obj, _del_hook);
241 elm_widget_theme_hook_set(obj, _theme_hook);
242 elm_widget_can_focus_set(obj, EINA_FALSE);
244 wd->base = edje_object_add(evas);
245 _elm_theme_object_set(obj, wd->base, "conformant", "base", "default");
246 elm_widget_resize_object_set(obj, wd->base);
248 #ifdef HAVE_ELEMENTARY_X
249 Ecore_X_Window zone, xwin;
252 xwin = elm_win_xwindow_get(parent);
253 zone = ecore_x_e_illume_zone_get(xwin);
255 ecore_x_e_illume_indicator_geometry_get(zone, NULL, NULL, NULL, &sh);
257 wd->shelf = evas_object_rectangle_add(evas);
258 evas_object_color_set(wd->shelf, 0, 0, 0, 0);
259 evas_object_size_hint_min_set(wd->shelf, -1, sh);
260 evas_object_size_hint_max_set(wd->shelf, -1, sh);
261 edje_object_part_swallow(wd->base, "elm.swallow.shelf", wd->shelf);
264 ecore_x_e_illume_softkey_geometry_get(zone, NULL, NULL, NULL, &sh);
266 wd->panel = evas_object_rectangle_add(evas);
267 evas_object_color_set(wd->panel, 0, 0, 0, 0);
268 evas_object_size_hint_min_set(wd->panel, -1, sh);
269 evas_object_size_hint_max_set(wd->panel, -1, sh);
270 edje_object_part_swallow(wd->base, "elm.swallow.panel", wd->panel);
272 wd->prop_hdl = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY,
274 // FIXME: get kbd region prop
277 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
279 _mirrored_set(obj, elm_widget_mirrored_get(obj));
285 * Set the content of the conformant widget
287 * Once the content object is set, a previously set one will be deleted.
288 * If you want to keep that old content object, use the
289 * elm_conformat_content_unset() function.
291 * @param obj The conformant object
292 * @return The content that was being used
294 * @ingroup Conformant
297 elm_conformant_content_set(Evas_Object *obj, Evas_Object *content)
299 ELM_CHECK_WIDTYPE(obj, widtype);
300 Widget_Data *wd = elm_widget_data_get(obj);
302 if (wd->content == content) return;
303 if (wd->content) evas_object_del(wd->content);
304 wd->content = content;
307 elm_widget_sub_object_add(obj, content);
308 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
309 _changed_size_hints, obj);
310 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
316 * Get the content of the conformant widget
318 * Return the content object which is set for this widget;
320 * @param obj The conformant object
321 * @return The content that is being used
323 * @ingroup Conformant
326 elm_conformant_content_get(const Evas_Object *obj)
328 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
329 Widget_Data *wd = elm_widget_data_get(obj);
330 if (!wd) return NULL;
335 * Unset the content of the conformant widget
337 * Unparent and return the content object which was set for this widget;
339 * @param obj The conformant object
340 * @return The content that was being used
342 * @ingroup Conformant
345 elm_conformant_content_unset(Evas_Object *obj)
347 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
348 Widget_Data *wd = elm_widget_data_get(obj);
349 Evas_Object *content;
350 if (!wd) return NULL;
351 if (!wd->content) return NULL;
352 content = wd->content;
353 elm_widget_sub_object_del(obj, wd->content);
354 edje_object_part_unswallow(wd->base, wd->content);