the repository of RSA merge with private repository.
[platform/core/uifw/e17.git] / src / bin / e_entry_dialog.c
1 #include "e.h"
2
3 /* Private function definitions */
4 static void _e_entry_dia_del(void *data);
5 static void _e_entry_dialog_free(E_Entry_Dialog *dia);
6 static void _e_entry_dialog_ok(void *data, E_Dialog *dia);
7 static void _e_entry_dialog_cancel(void *data, E_Dialog *dia);
8 static void _e_entry_dialog_delete(E_Win *win);
9 static void _e_entry_cb_key_down(void *data, Evas_Object *obj, void *event_info);
10
11 /* Externally accesible functions */
12 EAPI E_Entry_Dialog *
13 e_entry_dialog_show(const char *title, const char *icon, const char *text,
14                     const char *initial_text,
15                     const char *button_text, const char *button2_text,
16                     void (*ok_func)(void *data, char *text),
17                     void (*cancel_func)(void *data), void *data)
18 {
19    E_Entry_Dialog *ed;
20    E_Dialog *dia;
21    Evas_Object *o, *ob;
22    Evas_Modifier_Mask mask;
23    int w, h;
24
25    ed = E_OBJECT_ALLOC(E_Entry_Dialog, E_ENTRY_DIALOG_TYPE, _e_entry_dialog_free);
26    ed->ok.func = ok_func;
27    ed->ok.data = data;
28    ed->cancel.func = cancel_func;
29    ed->cancel.data = data;
30    if (initial_text)
31      ed->text = strdup(initial_text);
32
33    dia = e_dialog_new(e_container_current_get(e_manager_current_get()), "E", "_entry_dialog");
34    if (!dia)
35      {
36         e_object_del(E_OBJECT(ed));
37         return NULL;
38      }
39    dia->data = ed;
40    ed->dia = dia;
41
42    mask = 0;
43    evas_object_key_ungrab(dia->event_object, "space", mask, ~mask);
44    e_object_del_attach_func_set(E_OBJECT(dia), _e_entry_dia_del);
45    e_win_delete_callback_set(dia->win, _e_entry_dialog_delete);
46
47    if (title) e_dialog_title_set(dia, title);
48    if (icon) e_dialog_icon_set(dia, icon, 64);
49
50    o = e_widget_list_add(dia->win->evas, 0, 0);
51    if (text)
52      {
53         ob = e_widget_label_add(dia->win->evas, text);
54         e_widget_list_object_append(o, ob, 1, 0, 0.5);
55      }
56
57    ed->entry = e_widget_entry_add(dia->win->evas, &(ed->text), NULL, NULL, NULL);
58    evas_object_smart_callback_add(ed->entry, "key_down", _e_entry_cb_key_down, ed);
59    e_widget_list_object_append(o, ed->entry, 1, 1, 0.5);
60    e_widget_size_min_get(o, &w, &h);
61    e_dialog_content_set(dia, o, 2 * w, h);
62
63    e_dialog_button_add(dia, !button_text ? _("OK") : button_text, NULL, _e_entry_dialog_ok, ed);
64    e_dialog_button_add(dia, !button2_text ? _("Cancel") : button2_text, NULL, _e_entry_dialog_cancel, ed);
65
66    e_win_centered_set(dia->win, 1);
67    e_dialog_show(dia);
68    e_widget_focus_set(ed->entry, 1);
69    e_editable_select_all(e_widget_entry_editable_object_get(ed->entry));
70    return ed;
71 }
72
73 /* Private Function Bodies */
74 static void
75 _e_entry_dia_del(void *data)
76 {
77    E_Dialog *dia = data;
78
79    e_object_del(dia->data);
80 }
81
82 static void
83 _e_entry_dialog_free(E_Entry_Dialog *ed)
84 {
85    e_object_del(E_OBJECT(ed->dia));
86    E_FREE(ed->text);
87    free(ed);
88 }
89
90 static void
91 _e_entry_dialog_ok(void *data, E_Dialog *dia __UNUSED__)
92 {
93    E_Entry_Dialog *ed;
94
95    ed = data;
96    e_object_ref(E_OBJECT(ed));
97    if (ed->ok.func) ed->ok.func(ed->ok.data, ed->text);
98    e_object_del(E_OBJECT(ed));
99    e_object_unref(E_OBJECT(ed));
100 }
101
102 static void
103 _e_entry_dialog_cancel(void *data, E_Dialog *dia __UNUSED__)
104 {
105    E_Entry_Dialog *ed;
106
107    ed = data;
108    e_object_ref(E_OBJECT(ed));
109    if (ed->cancel.func) ed->cancel.func(ed->cancel.data);
110    e_object_del(E_OBJECT(ed));
111    e_object_unref(E_OBJECT(ed));
112 }
113
114 static void
115 _e_entry_dialog_delete(E_Win *win)
116 {
117    E_Dialog *dia;
118    E_Entry_Dialog *ed;
119
120    dia = win->data;
121    ed = dia->data;
122    e_object_del(E_OBJECT(ed));
123 }
124
125 static void
126 _e_entry_cb_key_down(void *data, Evas_Object *obj __UNUSED__, void *event_info)
127 {
128    Evas_Event_Key_Down *ev;
129    E_Entry_Dialog *ed;
130
131    ev = event_info;
132    if (!(ed = data)) return;
133    if (!strcmp(ev->keyname, "Return"))
134      _e_entry_dialog_ok(data, ed->dia);
135    else
136    if (!strcmp(ev->keyname, "Escape"))
137      _e_entry_dialog_cancel(data, ed->dia);
138 }
139