aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/start/start.c
blob: 3708b65e497c5ec6615a7e133a675593816c0523 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#include "e.h"

/* actual module specifics */
typedef struct _Instance Instance;

struct _Instance
{
   Evas_Object     *o_button;
   E_Menu          *main_menu;
};

static void
do_orient(Instance *inst, E_Gadget_Site_Orient orient, E_Gadget_Site_Anchor anchor)
{
   char buf[4096];
   const char *s = "float";

   if (anchor & E_GADGET_SITE_ANCHOR_LEFT)
     {
        if (anchor & E_GADGET_SITE_ANCHOR_TOP)
          {
             switch (orient)
               {
                case E_GADGET_SITE_ORIENT_HORIZONTAL:
                  s = "top_left";
                  break;
                case E_GADGET_SITE_ORIENT_VERTICAL:
                  s = "left_top";
                  break;
                case E_GADGET_SITE_ORIENT_NONE:
                  s = "left_top";
                  break;
               }
          }
        else if (anchor & E_GADGET_SITE_ANCHOR_BOTTOM)
          {
             switch (orient)
               {
                case E_GADGET_SITE_ORIENT_HORIZONTAL:
                  s = "bottom_left";
                  break;
                case E_GADGET_SITE_ORIENT_VERTICAL:
                  s = "left_bottom";
                  break;
                case E_GADGET_SITE_ORIENT_NONE:
                  s = "left_bottom";
                  break;
               }
          }
        else
          s = "left";
     }
   else if (anchor & E_GADGET_SITE_ANCHOR_RIGHT)
     {
        if (anchor & E_GADGET_SITE_ANCHOR_TOP)
          {
             switch (orient)
               {
                case E_GADGET_SITE_ORIENT_HORIZONTAL:
                  s = "top_right";
                  break;
                case E_GADGET_SITE_ORIENT_VERTICAL:
                  s = "right_top";
                  break;
                case E_GADGET_SITE_ORIENT_NONE:
                  s = "right_top";
                  break;
               }
          }
        else if (anchor & E_GADGET_SITE_ANCHOR_BOTTOM)
          {
             switch (orient)
               {
                case E_GADGET_SITE_ORIENT_HORIZONTAL:
                  s = "bottom_right";
                  break;
                case E_GADGET_SITE_ORIENT_VERTICAL:
                  s = "right_bottom";
                  break;
                case E_GADGET_SITE_ORIENT_NONE:
                  s = "right_bottom";
                  break;
               }
          }
        else
          s = "right";
     }
   else if (anchor & E_GADGET_SITE_ANCHOR_TOP)
     s = "top";
   else if (anchor & E_GADGET_SITE_ANCHOR_BOTTOM)
     s = "bottom";
   else
     {
        switch (orient)
          {
           case E_GADGET_SITE_ORIENT_HORIZONTAL:
             s = "horizontal";
             break;
           case E_GADGET_SITE_ORIENT_VERTICAL:
             s = "vertical";
             break;
           default: break;
          }
     }
   snprintf(buf, sizeof(buf), "e,state,orientation,%s", s);
   elm_layout_signal_emit(inst->o_button, buf, "e");
}

static void
_menu_cb_post(void *data, E_Menu *m)
{
   Instance *inst = data;
   Eina_Bool fin;

   if (stopping || (!inst->main_menu)) return;
   fin = m == inst->main_menu;
   e_object_del(E_OBJECT(m));
   if (!fin) return;
   elm_layout_signal_emit(inst->o_button, "e,state,unfocused", "e");
   inst->main_menu = NULL;
}

static void
_button_cb_mouse_down(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
{
   Instance *inst = data;
   Evas_Event_Mouse_Down *ev = event_info;
   Evas_Coord x, y, w, h;
   E_Gadget_Site_Anchor an;
   int dir = E_MENU_POP_DIRECTION_AUTO;

   if (ev->button != 1) return;
   if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;

   evas_object_geometry_get(inst->o_button, &x, &y, &w, &h);
   if (!inst->main_menu)
     inst->main_menu = e_int_menus_main_new();
   if (!inst->main_menu) return;
   e_menu_post_deactivate_callback_set(inst->main_menu,
                                       _menu_cb_post, inst);
   an = e_gadget_site_anchor_get(e_gadget_site_get(inst->o_button));
   switch (e_gadget_site_orient_get(e_gadget_site_get(inst->o_button)))
     {
      case E_GADGET_SITE_ORIENT_HORIZONTAL:
        if (an & E_GADGET_SITE_ANCHOR_TOP)
          dir = E_MENU_POP_DIRECTION_DOWN;
        else if (an & E_GADGET_SITE_ANCHOR_BOTTOM)
          dir = E_MENU_POP_DIRECTION_UP;
        break;
      case E_GADGET_SITE_ORIENT_VERTICAL:
        if (an & E_GADGET_SITE_ANCHOR_LEFT)
          dir = E_MENU_POP_DIRECTION_RIGHT;
        else if (an & E_GADGET_SITE_ANCHOR_RIGHT)
          dir = E_MENU_POP_DIRECTION_LEFT;
        break;
      default: break;
     }
   e_menu_activate_mouse(inst->main_menu,
                         e_zone_current_get(),
                         x, y, w, h, dir, ev->timestamp);
   evas_object_smart_callback_call(inst->o_button, "gadget_popup",
     inst->main_menu->container_object);
   elm_layout_signal_emit(inst->o_button, "e,state,focused", "e");
   ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
}

static void
start_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Instance *inst = data;

   if (inst->main_menu)
     {
        e_menu_post_deactivate_callback_set(inst->main_menu, NULL, NULL);
        e_object_del(E_OBJECT(inst->main_menu));
     }
   free(inst);
}

static void
_anchor_change(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
   Instance *inst = data;

   do_orient(inst, e_gadget_site_orient_get(obj), e_gadget_site_anchor_get(obj));
}

static void
_gadget_created(void *data, Evas_Object *obj, void *event_info)
{
   Instance *inst = data;

   if (event_info == inst->o_button)
     do_orient(inst, e_gadget_site_orient_get(obj), e_gadget_site_anchor_get(obj));
}

EINTERN Evas_Object *
start_create(Evas_Object *parent, int *id EINA_UNUSED, E_Gadget_Site_Orient orient)
{
   Evas_Object *o;
   Instance *inst;

   inst = E_NEW(Instance, 1);

   o = elm_layout_add(parent);

   e_theme_edje_object_set(o, NULL, "e/gadget/start/main");
   elm_layout_signal_emit(o, "e,state,unfocused", "e");

   inst->o_button = o;
   evas_object_size_hint_aspect_set(o, EVAS_ASPECT_CONTROL_BOTH, 1, 1);

   evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
                                  _button_cb_mouse_down, inst);
   evas_object_event_callback_add(o, EVAS_CALLBACK_DEL, start_del, inst);
   evas_object_smart_callback_add(parent, "gadget_site_anchor", _anchor_change, inst);
   evas_object_smart_callback_add(parent, "gadget_created", _gadget_created, inst);
   do_orient(inst, orient, e_gadget_site_anchor_get(parent));

   return o;
}