[Entry] Fix scrolling issue with cnp, magnifier
[framework/uifw/elementary.git] / src / bin / test_win_wm_rotation.c
1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4 #include <Elementary.h>
5 #ifndef ELM_LIB_QUICKLAUNCH
6
7 typedef struct _App_Data App_Data;
8
9 struct _App_Data
10 {
11    Eina_Bool    wm_rot_supported;
12    Eina_List   *chs;
13    int          available_rots[4];
14    unsigned int count;
15    Evas_Object *lb;
16    Evas_Object *rdg;
17 };
18
19 static void
20 _bt_available_rots_set(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
21 {
22    Evas_Object *win = (Evas_Object *)(data);
23    App_Data *ad = evas_object_data_get(win, "ad");
24    Evas_Object *o;
25    Eina_List *l;
26    const char *str;
27    unsigned int i = 0;
28
29    if (!ad->wm_rot_supported) return;
30
31    EINA_LIST_FOREACH(ad->chs, l, o)
32      {
33         if (!elm_check_state_get(o)) continue;
34         str = elm_object_text_get(o);
35         if (!str) continue;
36         ad->available_rots[i] = atoi(str);
37         i++;
38      }
39
40    ad->count = i;
41
42    elm_win_wm_rotation_available_rotations_set
43      (win, ad->available_rots, ad->count);
44 }
45
46 static void
47 _bt_preferred_rot_set(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
48 {
49    Evas_Object *win = (Evas_Object *)(data);
50    App_Data *ad = evas_object_data_get(win, "ad");
51
52    if (!ad->wm_rot_supported) return;
53
54    Evas_Object *rd = elm_radio_selected_object_get(ad->rdg);
55    if (rd)
56      {
57         const char *str = elm_object_text_get(rd);
58         int rot = 0;
59
60         if (!strcmp(str, "Unset"))
61           rot = -1;
62         else
63           rot = atoi(str);
64
65         elm_win_wm_rotation_preferred_rotation_set(win, rot);
66      }
67 }
68
69 static void
70 _win_wm_rotation_changed_cb(void *data, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
71 {
72    Evas_Object *win = (Evas_Object *)(data);
73    App_Data *ad = evas_object_data_get(win, "ad");
74    int rot = elm_win_rotation_get(win);
75    char buf[32];
76
77    if (!ad->wm_rot_supported) return;
78
79    eina_convert_itoa(rot, buf);
80    elm_object_text_set(ad->lb, eina_stringshare_add(buf));
81 }
82
83 static void
84 _win_del_cb(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
85 {
86    App_Data *ad = evas_object_data_get(obj, "ad");
87    Evas_Object *o;
88
89    if (ad->wm_rot_supported)
90      {
91         EINA_LIST_FREE(ad->chs, o)
92           evas_object_data_del(o, "rotation");
93      }
94
95    free(ad);
96 }
97
98 void
99 test_win_wm_rotation(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
100 {
101    App_Data *ad;
102    Evas_Object *win, *bx, *bx2, *lb, *ch, *bt, *en, *rd, *rdg = NULL;
103    int i;
104    char buf[32];
105
106    if (!(ad = calloc(1, sizeof(App_Data)))) return;
107
108    win = elm_win_util_standard_add("wmrotation", "WMRotation");
109    elm_win_autodel_set(win, EINA_TRUE);
110    evas_object_data_set(win, "ad", ad);
111
112    bx = elm_box_add(win);
113    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
114    elm_win_resize_object_add(win, bx);
115
116    lb = elm_label_add(win);
117    elm_object_text_set(lb, "<b>Window manager rotation test</b>");
118    evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
119    elm_box_pack_end(bx, lb);
120    evas_object_show(lb);
121
122    ad->wm_rot_supported = elm_win_wm_rotation_supported_get(win);
123    if (ad->wm_rot_supported)
124      {
125         int rots[] = { 0, 90, 270 };
126         elm_win_wm_rotation_available_rotations_set(win, rots, (sizeof(rots) / sizeof(int)));
127         elm_win_wm_rotation_preferred_rotation_set(win, 90);
128
129         bx2 = elm_box_add(win);
130         evas_object_size_hint_weight_set(bx2, EVAS_HINT_EXPAND, 0.0);
131         evas_object_size_hint_align_set(bx2, EVAS_HINT_FILL, 0.0);
132         elm_box_align_set(bx2, 0.0, 0.5);
133         elm_box_horizontal_set(bx2, EINA_TRUE);
134         elm_box_pack_end(bx, bx2);
135         evas_object_show(bx2);
136
137         for (i = 0; i < 4; i++)
138           {
139              ch = elm_check_add(win);
140              eina_convert_itoa((i * 90), buf);
141              elm_object_text_set(ch, eina_stringshare_add(buf));
142              evas_object_size_hint_weight_set(ch, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
143              elm_box_pack_end(bx2, ch);
144              evas_object_show(ch);
145
146              if (i != 2) elm_check_state_set(ch, 1);
147
148              ad->chs = eina_list_append(ad->chs, ch);
149           }
150
151         bt = elm_button_add(win);
152         elm_object_text_set(bt, "Available rotations");
153         evas_object_smart_callback_add(bt, "clicked", _bt_available_rots_set, win);
154         elm_box_pack_end(bx, bt);
155         evas_object_show(bt);
156
157         bx2 = elm_box_add(win);
158         evas_object_size_hint_weight_set(bx2, EVAS_HINT_EXPAND, 0.0);
159         evas_object_size_hint_align_set(bx2, EVAS_HINT_FILL, 0.0);
160         elm_box_align_set(bx2, 0.0, 0.5);
161         elm_box_horizontal_set(bx2, EINA_TRUE);
162         elm_box_pack_end(bx, bx2);
163         evas_object_show(bx2);
164
165         for (i = 0; i < 5; i++)
166           {
167              rd = elm_radio_add(win);
168              if (!rdg) rdg = rd;
169              elm_radio_state_value_set(rd, i);
170              elm_radio_group_add(rd, rdg);
171
172              if (i == 0)
173                elm_object_text_set(rd, "Unset");
174              else
175                {
176                   eina_convert_itoa(((i - 1) * 90), buf);
177                   elm_object_text_set(rd, eina_stringshare_add(buf));
178                }
179
180              evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
181              elm_box_pack_end(bx2, rd);
182              evas_object_show(rd);
183           }
184
185         elm_radio_value_set(rdg, 2);
186         ad->rdg = rdg;
187
188         bt = elm_button_add(win);
189         elm_object_text_set(bt, "Preferred rotation");
190         evas_object_smart_callback_add(bt, "clicked", _bt_preferred_rot_set, win);
191         elm_box_pack_end(bx, bt);
192         evas_object_show(bt);
193
194         evas_object_smart_callback_add(win, "wm,rotation,changed", _win_wm_rotation_changed_cb, win);
195      }
196
197    en = elm_entry_add(win);
198    elm_entry_single_line_set(en, EINA_TRUE);
199    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
200    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
201    elm_box_pack_end(bx, en);
202    evas_object_show(en);
203
204    lb = elm_label_add(win);
205    elm_object_text_set(lb, "N/A");
206    evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
207    elm_box_pack_end(bx, lb);
208    evas_object_show(lb);
209    ad->lb = lb;
210
211    evas_object_smart_callback_add(win, "delete,request", _win_del_cb, NULL);
212
213    evas_object_resize(win, 480, 400);
214    evas_object_show(bx);
215    evas_object_show(win);
216 }
217 #endif