Merge branch 'master' of juyung.seo@165.213.180.234:/git/slp2.0/slp2.0-pkgs/EFL-pkgs...
[framework/uifw/elementary.git] / src / lib / elm_conform.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 /**
5  * @defgroup Conformant Conformant
6  * @ingroup Elementary
7  * 
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.
11  */
12
13 typedef struct _Widget_Data Widget_Data;
14 struct _Widget_Data 
15 {
16    Evas_Object *base;
17    Evas_Object *shelf, *panel;
18    Evas_Object *content;
19    Ecore_Event_Handler *prop_hdl;
20    struct {
21       Ecore_Animator *animator; // animaton timer
22       double start; // time started
23       Evas_Coord auto_x, auto_y; // desired delta
24       Evas_Coord x, y; // current delta
25    } delta;
26 };
27
28 /* local function prototypes */
29 static const char *widtype = NULL;
30 static void _del_hook(Evas_Object *obj);
31 static void _theme_hook(Evas_Object *obj);
32 static void _sizing_eval(Evas_Object *obj);
33 static int _prop_change(void *data, int type, void *event);
34
35 /* local functions */
36 static void 
37 _del_hook(Evas_Object *obj) 
38 {
39    Widget_Data *wd = elm_widget_data_get(obj);
40    if (!wd) return;
41    if (wd->prop_hdl) ecore_event_handler_del(wd->prop_hdl);
42    free(wd);
43 }
44
45 static void 
46 _theme_hook(Evas_Object *obj) 
47 {
48    Widget_Data *wd = elm_widget_data_get(obj);
49    if (!wd) return;
50    _elm_theme_object_set(obj, wd->base, "conformant", "base", elm_widget_style_get(obj));
51    if (wd->content)
52      edje_object_part_swallow(wd->base, "elm.swallow.content", wd->content);
53    edje_object_scale_set(wd->base, elm_widget_scale_get(obj) * _elm_config->scale);
54    _sizing_eval(obj);
55 }
56
57 static void 
58 _sizing_eval(Evas_Object *obj) 
59 {
60    Widget_Data *wd = elm_widget_data_get(obj);
61    Evas_Coord mw = -1, mh = -1;
62    if (!wd) return;
63    edje_object_size_min_calc(wd->base, &mw, &mh);
64    evas_object_size_hint_min_set(obj, mw, mh);
65    evas_object_size_hint_max_set(obj, -1, -1);
66 }
67
68 static void
69 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
70 {
71    Widget_Data *wd = elm_widget_data_get(data);
72    if (!wd) return;
73    _sizing_eval(data);
74 }
75
76 static void
77 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
78 {
79    Widget_Data *wd = elm_widget_data_get(obj);
80    Evas_Object *sub = event_info;
81    if (!wd) return;
82    if (sub == wd->content)
83      {
84         evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
85                                             _changed_size_hints, obj);
86         wd->content = NULL;
87         _sizing_eval(obj);
88      }
89 }
90
91 /* unused now - but meant to be for making sure the focused widget is always
92  * visible when the vkbd comes and goes by moving the conformant obj (and thus
93  * its children) to  show the focused widget (and if focus changes follow)
94
95 static Evas_Object *
96 _focus_object_get(const Evas_Object *obj)
97 {
98    Evas_Object *win, *foc;
99    
100    win = elm_widget_top_get(obj);
101    if (!win) return NULL;
102    foc = elm_widget_top_get(win);
103 }
104
105 static void
106 _focus_object_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
107 {
108    evas_object_geometry_get(obj, x, y, w, h);
109 }
110
111 static void
112 _focus_change_del(void *data, Evas_Object *obj, void *event_info)
113 {
114    // called from toplevel when the focused window shanges
115 }
116
117 static void
118 _autoscroll_move(Evas_Object *obj)
119 {
120    // move conformant edje by delta to show focused widget
121 }
122
123 static void
124 _autoscroll_mode_enable(Evas_Object *obj)
125 {
126    // called when autoscroll mode should be on - content area smaller than
127    // its min size
128    // 1. get focused object
129    // 2. if not in visible conformant area calculate delta needed to
130    //    get it in
131    // 3. store delta and call _autoscroll_move() which either asanimates
132    //    or jumps right there
133 }
134
135 static void
136 _autoscroll_mode_disable(Evas_Object *obj)
137 {
138    // called when autoscroll mode should be off - set delta to 0 and
139    // call _autoscroll_move()
140 }
141 */
142
143 static int 
144 _prop_change(void *data, int type __UNUSED__, void *event) 
145 {
146 #ifdef HAVE_ELEMENTARY_X
147    Ecore_X_Event_Window_Property *ev;
148    Widget_Data *wd = elm_widget_data_get(data);
149    if (!wd) return 1;
150    ev = event;
151    if (ev->atom == ECORE_X_ATOM_E_ILLUME_ZONE) 
152      {
153         Ecore_X_Window zone;
154         int sh = -1;
155
156         zone = ecore_x_e_illume_zone_get(ev->win);
157         ecore_x_e_illume_indicator_geometry_get(zone, NULL, NULL, NULL, &sh);
158         if (sh < 0) sh = 0;
159         evas_object_size_hint_min_set(wd->shelf, -1, sh);
160         evas_object_size_hint_max_set(wd->shelf, -1, sh);
161         sh = -1;
162         ecore_x_e_illume_softkey_geometry_get(zone, NULL, NULL, NULL, &sh);
163         if (sh < 0) sh = 0;
164         evas_object_size_hint_min_set(wd->panel, -1, sh);
165         evas_object_size_hint_max_set(wd->panel, -1, sh);
166      }
167    else if (ev->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_GEOMETRY) 
168      {
169         Ecore_X_Window zone;
170         int sh = -1;
171
172         zone = ecore_x_e_illume_zone_get(ev->win);
173         ecore_x_e_illume_indicator_geometry_get(zone, NULL, NULL, NULL, &sh);
174         if (sh < 0) sh = 0;
175         evas_object_size_hint_min_set(wd->shelf, -1, sh);
176         evas_object_size_hint_max_set(wd->shelf, -1, sh);
177      }
178    else if (ev->atom == ECORE_X_ATOM_E_ILLUME_SOFTKEY_GEOMETRY) 
179      {
180         Ecore_X_Window zone;
181         int sh = -1;
182
183         zone = ecore_x_e_illume_zone_get(ev->win);
184         ecore_x_e_illume_softkey_geometry_get(zone, NULL, NULL, NULL, &sh);
185         if (sh < 0) sh = 0;
186         evas_object_size_hint_min_set(wd->panel, -1, sh);
187         evas_object_size_hint_max_set(wd->panel, -1, sh);
188      }
189    else if (ev->atom == ECORE_X_ATOM_E_ILLUME_KEYBOARD_GEOMETRY) 
190      {
191         Ecore_X_Window zone;
192         int ky = -1;
193
194         printf("Keyboard Geometry Changed\n");
195         zone = ecore_x_e_illume_zone_get(ev->win);
196         ecore_x_e_illume_keyboard_geometry_get(zone, NULL, &ky, NULL, NULL);
197         printf("\tGeom: %d\n", ky);
198      }
199 #endif
200
201    return 1;
202 }
203
204 /**
205  * Add a new Conformant object
206  * 
207  * @param parent The parent object
208  * @return The new conformant object or NULL if it cannot be created
209  * 
210  * @ingroup Conformant
211  */
212 EAPI Evas_Object *
213 elm_conformant_add(Evas_Object *parent) 
214 {
215    Evas_Object *obj;
216    Evas *evas;
217    Widget_Data *wd;
218
219    wd = ELM_NEW(Widget_Data);
220
221    evas = evas_object_evas_get(parent);
222
223    obj = elm_widget_add(evas);
224    ELM_SET_WIDTYPE(widtype, "conformant");
225    elm_widget_type_set(obj, "conformant");
226    elm_widget_sub_object_add(parent, obj);
227    elm_widget_data_set(obj, wd);
228    elm_widget_del_hook_set(obj, _del_hook);
229    elm_widget_theme_hook_set(obj, _theme_hook);
230
231    wd->base = edje_object_add(evas);
232    _elm_theme_object_set(obj, wd->base, "conformant", "base", "default");
233    elm_widget_resize_object_set(obj, wd->base);
234
235 #ifdef HAVE_ELEMENTARY_X
236    Ecore_X_Window zone, xwin;
237    int sh = -1;
238
239    xwin = elm_win_xwindow_get(parent);
240    zone = ecore_x_e_illume_zone_get(xwin);
241
242    ecore_x_e_illume_indicator_geometry_get(zone, NULL, NULL, NULL, &sh);
243    if (sh < 0) sh = 0;
244    wd->shelf = evas_object_rectangle_add(evas);
245    evas_object_color_set(wd->shelf, 0, 0, 0, 0);
246    evas_object_size_hint_min_set(wd->shelf, -1, sh);
247    evas_object_size_hint_max_set(wd->shelf, -1, sh);
248    edje_object_part_swallow(wd->base, "elm.swallow.shelf", wd->shelf);
249
250    sh = -1;
251    ecore_x_e_illume_softkey_geometry_get(zone, NULL, NULL, NULL, &sh);
252    if (sh < 0) sh = 0;
253    wd->panel = evas_object_rectangle_add(evas);
254    evas_object_color_set(wd->panel, 0, 0, 0, 0);
255    evas_object_size_hint_min_set(wd->panel, -1, sh);
256    evas_object_size_hint_max_set(wd->panel, -1, sh);
257    edje_object_part_swallow(wd->base, "elm.swallow.panel", wd->panel);
258
259    wd->prop_hdl = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY, 
260                                           _prop_change, obj);
261    // FIXME: get kbd region prop
262 #endif
263
264    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
265
266    _sizing_eval(obj);
267    return obj;
268 }
269
270 /**
271  * Set the content of the conformant widget
272  * 
273  * @param obj The conformant object
274  * @param content The content that will be used inside this conformant object
275  * 
276  * @ingroup Conformant
277  */
278 EAPI void 
279 elm_conformant_content_set(Evas_Object *obj, Evas_Object *content) 
280 {
281    ELM_CHECK_WIDTYPE(obj, widtype);
282    Widget_Data *wd = elm_widget_data_get(obj);
283    if (!wd) return;
284    if ((wd->content != content) && (wd->content))
285      elm_widget_sub_object_del(obj, wd->content);
286    wd->content = content;
287    if (content) 
288      {
289         elm_widget_sub_object_add(obj, content);
290         evas_object_event_callback_add(content,
291                                        EVAS_CALLBACK_CHANGED_SIZE_HINTS,
292                                        _changed_size_hints, obj);
293         edje_object_part_swallow(wd->base, "elm.swallow.content", content);
294         _sizing_eval(obj);
295      }
296 }