-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathpopup_entry.c
159 lines (140 loc) · 5.27 KB
/
popup_entry.c
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
/*
Compile with:
arm-linux-gnueabihf-gcc -o example example.c `pkg-config --cflags --libs elementary` -lecore_input --sysroot=/path_to_arm_usr_and_lib/ -Wl,-dynamic-linker,/lib/ld-2.13.so
We need to specify the correct ld or it will not work on device.
*/
#include <Elementary.h>
#include <strings.h>
#include <Ecore.h>
#include <Ecore_Input.h>
char *message="No message given",message_out[255], label_ok[255], label_cancel[255], label_entry[255], sample_text[255];
Evas_Object *win, *bg, *bg2, *bgl, *box, *box2, *lab, *button_ok, *button_cancel, *entry_field, *entry_frame;
int debug=0, entry_number_only=0, button_height=80, button_width=360;
static void
ok_button_1_clicked(void *data, Evas_Object *obj, void *event_info)
{
printf("%s",elm_object_text_get(entry_field));
elm_exit();
exit(0);
}
static void
ok_button_2_clicked(void *data, Evas_Object *obj, void *event_info)
{
/* quit the mainloop (elm_run) */
elm_exit();
exit(255);
}
static Eina_Bool key_down_callback(void *data, int type, void *ev)
{
Ecore_Event_Key *event = ev;
if (!strcmp("KP_Enter", event->key))
{
ok_button_1_clicked(NULL, NULL, NULL);
}
if (!strcmp("Menu", event->key))
{
ok_button_2_clicked(NULL, NULL, NULL);
}
debug && printf("Key: %s\n",event->key);
return ECORE_CALLBACK_PASS_ON;
}
EAPI int
elm_main(int argc, char **argv)
{
if (argc > 1) {
message=argv[1];
}
strncpy(label_ok,"OK",10);
strncpy(label_cancel,"CANCEL",10);
strncpy(sample_text,"",100);
if (argc > 2) {
strncpy(label_ok,argv[2],255);
}
if (argc > 3) {
strncpy(label_cancel,argv[3],255);
}
if (argc > 4) {
strncpy(sample_text,argv[4],255);
}
if (argc > 5 && 0 == strcmp("number", argv[5]))
{
entry_number_only=1;
}
strncpy(message_out,"<align=center>",20);
strncat(message_out,message,210);
strncat(message_out,"</align>",20);
win = elm_win_add(NULL, "Info", ELM_WIN_BASIC);
evas_object_move(win, 0,0);
elm_win_title_set(win, "Info");
evas_object_smart_callback_add(win, "delete,request", ok_button_1_clicked, NULL);
bg = elm_bg_add(win);
elm_bg_color_set(bg, 0,20,30);
elm_win_resize_object_add(win, bg);
evas_object_show(bg);
box = elm_box_add(win);
elm_win_resize_object_add(win, box);
evas_object_size_hint_padding_set(box, 1,1,1,1);
evas_object_show(box);
Evas_Object* etable = elm_table_add(win);
elm_box_pack_end(box, etable);
bg2 = evas_object_rectangle_add(evas_object_evas_get(etable));
evas_object_size_hint_min_set(bg2, button_width, button_height);
lab = elm_label_add(win);
elm_label_line_wrap_set(lab,ELM_WRAP_WORD);
elm_object_style_set(lab, "transparent");
elm_object_text_set(lab, message_out);
evas_object_size_hint_min_set(lab, button_width, button_height);
evas_object_size_hint_weight_set(lab, 1.0, 1.0);
bg2 = evas_object_rectangle_add(evas_object_evas_get(lab));
evas_object_color_set(bg2, 60, 60, 60, 255);
elm_table_pack(etable,bg2,1,1,1,1);
evas_object_show(bg2);
elm_table_pack(etable,lab,1,1,1,1);
evas_object_show(lab);
entry_field = elm_entry_add(win);
elm_entry_single_line_set(entry_field, EINA_TRUE);
elm_object_text_set(entry_field, sample_text);
elm_entry_cursor_pos_set(entry_field, strlen(sample_text));
if (entry_number_only==1)
elm_entry_input_panel_layout_set(entry_field,ELM_INPUT_PANEL_LAYOUT_NUMBERONLY);
evas_object_resize(entry_field,button_width,button_height);
elm_object_style_set(entry_field, "transparent");
bg2 = evas_object_rectangle_add(evas_object_evas_get(entry_field));
evas_object_size_hint_min_set(bg2, button_width-2, button_height);
evas_object_color_set(bg2, 20, 30, 40, 255);
elm_table_pack(etable,bg2,2,1,1,1);
evas_object_show(bg2);
elm_table_pack(etable,entry_field,2,1,1,1);
evas_object_show(entry_field);
button_ok = elm_button_add(win);
elm_object_style_set(button_ok, "transparent");
elm_object_text_set(button_ok, label_ok);
evas_object_size_hint_min_set(button_ok, button_width, button_height);
bg2 = evas_object_rectangle_add(evas_object_evas_get(button_ok));
evas_object_size_hint_min_set(bg2, button_width-2, button_height-4);
evas_object_color_set(bg2, 60, 120, 60, 255);
evas_object_show(bg2);
elm_table_pack(etable,bg2,2,2,1,1);
elm_table_pack(etable,button_ok,2,2,1,1);
evas_object_show(button_ok);
evas_object_smart_callback_add(button_ok, "clicked", ok_button_1_clicked, NULL);
button_cancel = elm_button_add(win);
elm_object_style_set(button_cancel, "transparent");
elm_object_text_set(button_cancel, label_cancel);
evas_object_size_hint_min_set(button_cancel, button_width, button_height);
bg2 = evas_object_rectangle_add(evas_object_evas_get(button_cancel));
evas_object_size_hint_min_set(bg2, button_width-2, button_height-4);
evas_object_color_set(bg2, 120, 0, 0, 255);
evas_object_show(bg2);
elm_table_pack(etable,bg2,1,2,1,1);
elm_table_pack(etable,button_cancel,1,2,1,1);
evas_object_show(button_cancel);
evas_object_smart_callback_add(button_cancel, "clicked", ok_button_2_clicked, NULL);
elm_object_focus_set(entry_field, EINA_TRUE);
evas_object_show(etable);
evas_object_show(win);
ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, key_down_callback, NULL);
elm_run();
return 0;
}
ELM_MAIN()