Tizen 2.1 release
[platform/core/uifw/e17.git] / src / bin / e_widget_scrollframe.c
1 #include "e.h"
2
3 typedef struct _E_Widget_Data E_Widget_Data;
4 struct _E_Widget_Data
5 {
6    Evas_Object *o_scrollframe, *o_child, *o_fobj;
7 };
8
9 static void _e_wid_del_hook(Evas_Object *obj);
10 static void _e_wid_focus_hook(Evas_Object *obj);
11 static void _e_wid_focus_steal(void *data, Evas *e, Evas_Object *obj, void *event_info);
12 static void _e_wid_cb_scrollframe_resize(void *data, Evas *e, Evas_Object *obj,
13                                          void *event_info);
14
15 /* externally accessible functions */
16 EAPI Evas_Object *
17 e_widget_scrollframe_simple_add(Evas *evas, Evas_Object *child)
18 {
19    E_Widget_Data *wd;
20    Evas_Object *obj, *o;
21
22    obj = e_widget_add(evas);
23
24    e_widget_del_hook_set(obj, _e_wid_del_hook);
25    e_widget_focus_hook_set(obj, _e_wid_focus_hook);
26    wd = calloc(1, sizeof(E_Widget_Data));
27    e_widget_data_set(obj, wd);
28
29    o = e_scrollframe_add(evas);
30    e_scrollframe_policy_set(o, E_SCROLLFRAME_POLICY_AUTO,
31                             E_SCROLLFRAME_POLICY_AUTO);
32    wd->o_scrollframe = o;
33    evas_object_show(o);
34    e_widget_sub_object_add(obj, o);
35    e_widget_resize_object_set(obj, o);
36    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
37                                   _e_wid_focus_steal, obj);
38
39    e_scrollframe_child_set(wd->o_scrollframe, child);
40    evas_object_show(child);
41    wd->o_child = child;
42    e_widget_sub_object_add(obj, child);
43    evas_object_event_callback_add(wd->o_scrollframe, EVAS_CALLBACK_RESIZE,
44                                   _e_wid_cb_scrollframe_resize, wd->o_child);
45
46    return obj;
47 }
48
49 EAPI Evas_Object *
50 e_widget_scrollframe_pan_add(Evas *evas, Evas_Object *pan, void (*pan_set)(Evas_Object *obj, Evas_Coord x, Evas_Coord y), void (*pan_get)(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y), void (*pan_max_get)(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y), void (*pan_child_size_get)(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y))
51 {
52    Evas_Object *obj, *o;
53    E_Widget_Data *wd;
54
55    obj = e_widget_add(evas);
56
57    e_widget_del_hook_set(obj, _e_wid_del_hook);
58    e_widget_focus_hook_set(obj, _e_wid_focus_hook);
59    wd = calloc(1, sizeof(E_Widget_Data));
60    e_widget_data_set(obj, wd);
61
62    o = e_scrollframe_add(evas);
63    wd->o_scrollframe = o;
64    evas_object_show(o);
65    e_widget_sub_object_add(obj, o);
66    e_widget_resize_object_set(obj, o);
67    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
68                                   _e_wid_focus_steal, obj);
69
70    e_scrollframe_extern_pan_set(o, pan, pan_set, pan_get, pan_max_get,
71                                 pan_child_size_get);
72    evas_object_show(pan);
73    e_widget_sub_object_add(obj, pan);
74
75    return obj;
76 }
77
78 EAPI void
79 e_widget_scrollframe_child_pos_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
80 {
81    E_Widget_Data *wd;
82
83    wd = e_widget_data_get(obj);
84    e_scrollframe_child_pos_set(wd->o_scrollframe, x, y);
85 }
86
87 EAPI void
88 e_widget_scrollframe_child_pos_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
89 {
90    E_Widget_Data *wd;
91
92    wd = e_widget_data_get(obj);
93    e_scrollframe_child_pos_get(wd->o_scrollframe, x, y);
94 }
95
96 EAPI void
97 e_widget_scrollframe_child_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
98 {
99    E_Widget_Data *wd;
100
101    wd = e_widget_data_get(obj);
102    e_scrollframe_child_region_show(wd->o_scrollframe, x, y, w, h);
103 }
104
105 EAPI void
106 e_widget_scrollframe_focus_object_set(Evas_Object *obj, Evas_Object *fobj)
107 {
108    E_Widget_Data *wd;
109
110    wd = e_widget_data_get(obj);
111    wd->o_fobj = fobj;
112 }
113
114 EAPI Evas_Object *
115 e_widget_scrollframe_object_get(Evas_Object *obj)
116 {
117    E_Widget_Data *wd;
118
119    wd = e_widget_data_get(obj);
120    return wd->o_scrollframe;
121 }
122
123 /* Private functions */
124 static void
125 _e_wid_del_hook(Evas_Object *obj)
126 {
127    E_Widget_Data *wd;
128
129    wd = e_widget_data_get(obj);
130    free(wd);
131 }
132
133 static void
134 _e_wid_focus_hook(Evas_Object *obj)
135 {
136    E_Widget_Data *wd;
137
138    wd = e_widget_data_get(obj);
139    if (e_widget_focus_get(obj))
140      {
141         edje_object_signal_emit(e_scrollframe_edje_object_get(wd->o_scrollframe), "e,state,focused", "e");
142         if (wd->o_fobj) evas_object_focus_set(wd->o_fobj, 1);
143         else evas_object_focus_set(wd->o_scrollframe, 1);
144      }
145    else
146      {
147         edje_object_signal_emit(e_scrollframe_edje_object_get(wd->o_scrollframe), "e,state,unfocused", "e");
148         if (wd->o_fobj) evas_object_focus_set(wd->o_fobj, 0);
149         evas_object_focus_set(wd->o_scrollframe, 0);
150      }
151 }
152
153 static void
154 _e_wid_focus_steal(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
155 {
156    e_widget_focus_steal(data);
157 }
158
159 static void
160 _e_wid_cb_scrollframe_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
161 {
162    Evas_Coord mw = 0, mh = 0;
163    Evas_Coord vw = 0, vh = 0;
164    Evas_Coord w = 0, h = 0;
165
166    e_scrollframe_child_viewport_size_get(obj, &vw, &vh);
167    e_widget_size_min_get(data, &mw, &mh);
168    evas_object_geometry_get(data, NULL, NULL, &w, &h);
169    if (vw >= mw)
170      {
171         if (w != vw) evas_object_resize(data, vw, h);
172      }
173 }