package upload
[framework/uifw/elementary.git] / src / bin / test_win_plug.c
1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4 #include <Elementary.h>
5 #ifndef ELM_LIB_QUICKLAUNCH
6
7 #define MAX_TRY 40
8
9 static int try_num = 0;
10
11 static void
12 _timer_del(void *data       __UNUSED__,
13               Evas *e          __UNUSED__,
14               Evas_Object     *obj,
15               void *event_info __UNUSED__)
16 {
17    Ecore_Timer *timer = evas_object_data_del(obj, "test-timer");
18    if (!timer) return;
19    ecore_timer_del(timer);
20 }
21
22 static Eina_Bool
23 cb_plug_connect(void *data)
24 {
25    Evas_Object *obj = data;
26    Ecore_Timer *timer;
27
28    if (!obj) return ECORE_CALLBACK_CANCEL;
29
30    try_num++;
31    if (try_num > MAX_TRY) return ECORE_CALLBACK_CANCEL;
32
33    timer= evas_object_data_get(obj, "test-timer");
34    if (!timer) return ECORE_CALLBACK_CANCEL;
35
36    if (elm_plug_connect(obj, "ello", 0, EINA_FALSE))
37      {
38         printf("plug connect to server[ello]\n");
39         return ECORE_CALLBACK_CANCEL;
40      }
41
42    ecore_timer_interval_set(timer, 1);
43    return ECORE_CALLBACK_RENEW;
44 }
45
46 static void
47 cb_plug_disconnected(void *data __UNUSED__,
48                     Evas_Object *obj,
49                     void *event_info __UNUSED__)
50 {
51    Ecore_Timer *timer = evas_object_data_get(obj, "test-timer");
52    if (timer)
53      {
54         ecore_timer_del(timer);
55         evas_object_data_del(obj, "test-timer");
56      }
57
58    timer = ecore_timer_add(1, cb_plug_connect, obj);
59    evas_object_data_set(obj, "test-timer", timer);
60 }
61
62 static void
63 cb_mouse_down(void *data __UNUSED__, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
64 {
65    Evas_Event_Mouse_Down *ev = event_info;
66    
67    if (ev->button == 1) elm_object_focus_set(obj, EINA_TRUE);
68 }
69
70 static void
71 cb_mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
72 {
73    Evas_Event_Mouse_Move *ev = event_info;
74    Evas_Object *orig = data;
75    Evas_Coord x, y;
76    Evas_Map *p;
77    int i, w, h;
78
79    if (!ev->buttons) return;
80    evas_object_geometry_get(obj, &x, &y, NULL, NULL);
81    evas_object_move(obj,
82                     x + (ev->cur.canvas.x - ev->prev.output.x),
83                     y + (ev->cur.canvas.y - ev->prev.output.y));
84    evas_object_image_size_get(orig, &w, &h);
85    p = evas_map_new(4);
86    evas_object_map_enable_set(orig, EINA_TRUE);
87    evas_object_raise(orig);
88    for (i = 0; i < 4; i++)
89      {
90         Evas_Object *hand;
91         char key[32];
92
93         snprintf(key, sizeof(key), "h-%i\n", i);
94         hand = evas_object_data_get(orig, key);
95         evas_object_raise(hand);
96         evas_object_geometry_get(hand, &x, &y, NULL, NULL);
97         x += 15;
98         y += 15;
99         evas_map_point_coord_set(p, i, x, y, 0);
100         if (i == 0) evas_map_point_image_uv_set(p, i, 0, 0);
101         else if (i == 1) evas_map_point_image_uv_set(p, i, w, 0);
102         else if (i == 2) evas_map_point_image_uv_set(p, i, w, h);
103         else if (i == 3) evas_map_point_image_uv_set(p, i, 0, h);
104      }
105    evas_object_map_set(orig, p);
106    evas_map_free(p);
107 }
108
109 static void
110 create_handles(Evas_Object *obj)
111 {
112    int i;
113    Evas_Coord x, y, w, h;
114
115    evas_object_geometry_get(obj, &x, &y, &w, &h);
116    for (i = 0; i < 4; i++)
117      {
118         Evas_Object *hand;
119         char buf[PATH_MAX];
120         char key[32];
121
122         hand = evas_object_image_filled_add(evas_object_evas_get(obj));
123         evas_object_resize(hand, 31, 31);
124         snprintf(buf, sizeof(buf), "%s/images/pt.png", elm_app_data_dir_get());
125         evas_object_image_file_set(hand, buf, NULL);
126         if (i == 0)      evas_object_move(hand, x     - 15, y     - 15);
127         else if (i == 1) evas_object_move(hand, x + w - 15, y     - 15);
128         else if (i == 2) evas_object_move(hand, x + w - 15, y + h - 15);
129         else if (i == 3) evas_object_move(hand, x     - 15, y + h - 15);
130         evas_object_event_callback_add(hand, EVAS_CALLBACK_MOUSE_MOVE, cb_mouse_move, obj);
131         evas_object_show(hand);
132         snprintf(key, sizeof(key), "h-%i\n", i);
133         evas_object_data_set(obj, key, hand);
134      }
135 }
136
137 void
138 test_win_plug(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
139 {
140    Evas_Object *win, *bg, *plug;
141    char buf[PATH_MAX];
142
143    win = elm_win_add(NULL, "window-plug", ELM_WIN_BASIC);
144    elm_win_title_set(win, "Window Plug");
145    elm_win_autodel_set(win, EINA_TRUE);
146
147    bg = elm_bg_add(win);
148    snprintf(buf, sizeof(buf), "%s/images/plant_01.jpg", elm_app_data_dir_get());
149    elm_bg_file_set(bg, buf, NULL);
150    elm_win_resize_object_add(win, bg);
151    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
152    evas_object_show(bg);
153
154    plug = elm_plug_add(win);
155    evas_object_event_callback_add(elm_plug_image_object_get(plug), EVAS_CALLBACK_MOUSE_DOWN, cb_mouse_down, NULL);
156    evas_object_event_callback_add(plug, EVAS_CALLBACK_DEL, _timer_del, NULL);
157    if (!elm_plug_connect(plug, "ello", 0, EINA_FALSE))
158      {
159         printf("Cannot connect plug\n");
160         return;
161      }
162
163    evas_object_smart_callback_add(plug, "image.deleted", cb_plug_disconnected, NULL);
164
165    evas_object_resize(plug, 380, 500);
166    evas_object_move(plug, 10, 10);
167    evas_object_show(plug);
168
169    create_handles(elm_plug_image_object_get(plug));
170
171    evas_object_resize(win, 400, 600);
172    evas_object_show(win);
173 }
174 #endif