1 #include "e.h"
2 
3 /* actual module specifics */
4 typedef struct _Instance Instance;
5 
6 struct _Instance
7 {
8    Evas_Object     *site;
9    Evas_Object     *o_button;
10    E_Menu          *main_menu;
11 };
12 
13 static void
do_orient(Instance * inst,E_Gadget_Site_Orient orient,E_Gadget_Site_Anchor anchor)14 do_orient(Instance *inst, E_Gadget_Site_Orient orient, E_Gadget_Site_Anchor anchor)
15 {
16    char buf[4096];
17    const char *s = "float";
18 
19    if (anchor & E_GADGET_SITE_ANCHOR_LEFT)
20      {
21         if (anchor & E_GADGET_SITE_ANCHOR_TOP)
22           {
23              switch (orient)
24                {
25                 case E_GADGET_SITE_ORIENT_HORIZONTAL:
26                   s = "top_left";
27                   break;
28                 case E_GADGET_SITE_ORIENT_VERTICAL:
29                   s = "left_top";
30                   break;
31                 case E_GADGET_SITE_ORIENT_NONE:
32                   s = "left_top";
33                   break;
34                }
35           }
36         else if (anchor & E_GADGET_SITE_ANCHOR_BOTTOM)
37           {
38              switch (orient)
39                {
40                 case E_GADGET_SITE_ORIENT_HORIZONTAL:
41                   s = "bottom_left";
42                   break;
43                 case E_GADGET_SITE_ORIENT_VERTICAL:
44                   s = "left_bottom";
45                   break;
46                 case E_GADGET_SITE_ORIENT_NONE:
47                   s = "left_bottom";
48                   break;
49                }
50           }
51         else
52           s = "left";
53      }
54    else if (anchor & E_GADGET_SITE_ANCHOR_RIGHT)
55      {
56         if (anchor & E_GADGET_SITE_ANCHOR_TOP)
57           {
58              switch (orient)
59                {
60                 case E_GADGET_SITE_ORIENT_HORIZONTAL:
61                   s = "top_right";
62                   break;
63                 case E_GADGET_SITE_ORIENT_VERTICAL:
64                   s = "right_top";
65                   break;
66                 case E_GADGET_SITE_ORIENT_NONE:
67                   s = "right_top";
68                   break;
69                }
70           }
71         else if (anchor & E_GADGET_SITE_ANCHOR_BOTTOM)
72           {
73              switch (orient)
74                {
75                 case E_GADGET_SITE_ORIENT_HORIZONTAL:
76                   s = "bottom_right";
77                   break;
78                 case E_GADGET_SITE_ORIENT_VERTICAL:
79                   s = "right_bottom";
80                   break;
81                 case E_GADGET_SITE_ORIENT_NONE:
82                   s = "right_bottom";
83                   break;
84                }
85           }
86         else
87           s = "right";
88      }
89    else if (anchor & E_GADGET_SITE_ANCHOR_TOP)
90      s = "top";
91    else if (anchor & E_GADGET_SITE_ANCHOR_BOTTOM)
92      s = "bottom";
93    else
94      {
95         switch (orient)
96           {
97            case E_GADGET_SITE_ORIENT_HORIZONTAL:
98              s = "horizontal";
99              break;
100            case E_GADGET_SITE_ORIENT_VERTICAL:
101              s = "vertical";
102              break;
103            default: break;
104           }
105      }
106    snprintf(buf, sizeof(buf), "e,state,orientation,%s", s);
107    elm_layout_signal_emit(inst->o_button, buf, "e");
108 }
109 
110 static void
_menu_cb_post(void * data,E_Menu * m)111 _menu_cb_post(void *data, E_Menu *m)
112 {
113    Instance *inst = data;
114    Eina_Bool fin;
115 
116    if (stopping || (!inst->main_menu)) return;
117    fin = m == inst->main_menu;
118    e_object_del(E_OBJECT(m));
119    if (!fin) return;
120    elm_layout_signal_emit(inst->o_button, "e,state,unfocused", "e");
121    inst->main_menu = NULL;
122 }
123 
124 static void
_button_cb_mouse_up(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info)125 _button_cb_mouse_up(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
126 {
127    Instance *inst = data;
128    Evas_Event_Mouse_Up *ev = event_info;
129    Evas_Coord x, y, w, h;
130    E_Gadget_Site_Anchor an;
131    int dir = E_MENU_POP_DIRECTION_AUTO;
132 
133    if (ev->button != 1) return;
134    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
135 
136    evas_object_geometry_get(inst->o_button, &x, &y, &w, &h);
137    if (!inst->main_menu)
138      inst->main_menu = e_int_menus_main_new();
139    if (!inst->main_menu) return;
140    e_menu_post_deactivate_callback_set(inst->main_menu,
141                                        _menu_cb_post, inst);
142    an = e_gadget_site_anchor_get(e_gadget_site_get(inst->o_button));
143    switch (e_gadget_site_orient_get(e_gadget_site_get(inst->o_button)))
144      {
145       case E_GADGET_SITE_ORIENT_HORIZONTAL:
146         if (an & E_GADGET_SITE_ANCHOR_TOP)
147           dir = E_MENU_POP_DIRECTION_DOWN;
148         else if (an & E_GADGET_SITE_ANCHOR_BOTTOM)
149           dir = E_MENU_POP_DIRECTION_UP;
150         break;
151       case E_GADGET_SITE_ORIENT_VERTICAL:
152         if (an & E_GADGET_SITE_ANCHOR_LEFT)
153           dir = E_MENU_POP_DIRECTION_RIGHT;
154         else if (an & E_GADGET_SITE_ANCHOR_RIGHT)
155           dir = E_MENU_POP_DIRECTION_LEFT;
156         break;
157       default: break;
158      }
159    e_menu_activate_mouse(inst->main_menu,
160                          e_zone_current_get(),
161                          x, y, w, h, dir, ev->timestamp);
162    evas_object_smart_callback_call(inst->o_button, "gadget_popup",
163      inst->main_menu->container_object);
164    elm_layout_signal_emit(inst->o_button, "e,state,focused", "e");
165    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
166 }
167 
168 static void
_anchor_change(void * data,Evas_Object * obj,void * event_info EINA_UNUSED)169 _anchor_change(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
170 {
171    Instance *inst = data;
172 
173    do_orient(inst, e_gadget_site_orient_get(obj), e_gadget_site_anchor_get(obj));
174 }
175 
176 static void
start_del(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)177 start_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
178 {
179    Instance *inst = data;
180 
181    if (inst->main_menu)
182      {
183         e_menu_post_deactivate_callback_set(inst->main_menu, NULL, NULL);
184         e_object_del(E_OBJECT(inst->main_menu));
185      }
186    evas_object_smart_callback_del_full(inst->site, "gadget_site_anchor", _anchor_change, inst);
187    free(inst);
188 }
189 
190 static void
_gadget_created(void * data,Evas_Object * obj,void * event_info)191 _gadget_created(void *data, Evas_Object *obj, void *event_info)
192 {
193    Instance *inst = data;
194 
195    if (event_info != inst->o_button) return;
196    do_orient(inst, e_gadget_site_orient_get(obj), e_gadget_site_anchor_get(obj));
197    evas_object_smart_callback_del_full(obj, "gadget_created", _gadget_created, inst);
198 }
199 
200 EINTERN Evas_Object *
start_create(Evas_Object * parent,int * id,E_Gadget_Site_Orient orient)201 start_create(Evas_Object *parent, int *id, E_Gadget_Site_Orient orient)
202 {
203    Evas_Object *o;
204    Instance *inst;
205 
206    if (e_gadget_site_is_desklock(parent)) return NULL;
207    if (*id == 0) *id = 1;
208    inst = E_NEW(Instance, 1);
209    inst->site = parent;
210 
211    o = elm_layout_add(parent);
212 
213    e_theme_edje_object_set(o, NULL, "e/gadget/start/main");
214    elm_layout_signal_emit(o, "e,state,unfocused", "e");
215 
216    inst->o_button = o;
217    evas_object_size_hint_aspect_set(o, EVAS_ASPECT_CONTROL_BOTH, 1, 1);
218 
219    evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP,
220                                   _button_cb_mouse_up, inst);
221    evas_object_event_callback_add(o, EVAS_CALLBACK_DEL, start_del, inst);
222    evas_object_smart_callback_add(parent, "gadget_site_anchor", _anchor_change, inst);
223    evas_object_smart_callback_add(parent, "gadget_created", _gadget_created, inst);
224    do_orient(inst, orient, e_gadget_site_anchor_get(parent));
225 
226    return o;
227 }
228