summaryrefslogtreecommitdiff
path: root/src/bin/e_dialog.c
blob: e3c8a1a61230340dfdaa1775e4193aa3028a132c (plain)
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
/*
 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
 */
#include "e.h"

typedef struct _E_Dialog_Button E_Dialog_Button;

struct _E_Dialog_Button
{
   E_Dialog *dialog;
   Evas_Object *obj;
   char *label;
   char *icon;
   void (*func) (void *data, E_Dialog *dia);
   void *data;
};

/* local subsystem functions */
static void _e_dialog_free(E_Dialog *dia);
static void _e_dialog_cb_button_clicked(void *data, Evas_Object *obj, const char *emission, const char *source);
static void _e_dialog_cb_delete(E_Win *win);
    
/* local subsystem globals */

/* externally accessible functions */

E_Dialog *
e_dialog_new(E_Container *con)
{
   E_Dialog *dia;
   E_Manager *man;
   Evas_Object *o;
   
   if (!con)
     {
	man = e_manager_current_get();
	if (!man) return NULL;
	con = e_container_current_get(man);
	if (!con) con = e_manager_container_number_get(man, 0);
	if (!con) return NULL;
     }
   dia = E_OBJECT_ALLOC(E_Dialog, E_DIALOG_TYPE, _e_dialog_free);
   if (!dia) return NULL;
   dia->win = e_win_new(con);
   if (!dia->win)
     {
	free(dia);
	return NULL;
     }
   dia->win->data = dia;
   e_win_name_class_set(dia->win, "E", "_dialog");
   o = edje_object_add(e_win_evas_get(dia->win));
   dia->bg_object = o;
   e_theme_edje_object_set(o, "base/theme/dialog",
			   "widgets/dialog/main");
   evas_object_move(o, 0, 0);
   evas_object_show(o);
   
   o = evas_object_textblock_add(e_win_evas_get(dia->win));
   dia->text_object = o;
   edje_object_part_swallow(dia->bg_object, "content_swallow", o);
   evas_object_show(o);
     {
        char format[1024];
	char *fname;
	int fsize;
	
	fname = (char *)e_font_default_string_get("default", &fsize);
	snprintf(format, sizeof(format),
		 "font='%s' size=%i wrap=word",
		 fname, fsize);
	evas_object_textblock_format_insert(o, format);
	evas_object_textblock_format_insert(o, "color=#000");
	evas_object_textblock_format_insert(o, "\n");
	evas_object_textblock_text_insert(o, "Here is some text");
	evas_object_textblock_format_insert(o, "\n");
	evas_object_textblock_text_insert(o, "Here is some more text");
	evas_object_textblock_format_insert(o, "\n");
	evas_object_textblock_text_insert(o, "And even more text on this line to make it really long for testing");
	evas_object_textblock_format_insert(o, "\n");
	evas_object_textblock_text_insert(o, "Short");
	evas_object_textblock_format_insert(o, "\n");
	evas_object_textblock_text_insert(o, "Aaardvaaarks On!");
	evas_object_textblock_format_insert(o, "\n");
	evas_object_textblock_format_insert(o, "\n");
     }
   
   o = e_box_add(e_win_evas_get(dia->win));
   dia->box_object = o;
   e_box_orientation_set(o, 1);
   e_box_homogenous_set(o, 1);
   e_box_align_set(o, 0.5, 0.5);
   edje_object_part_swallow(dia->bg_object, "buttons_swallow", o);
   evas_object_show(o);
   
   return dia;
}

void
e_dialog_button_add(E_Dialog *dia, char *label, char *icon, void (*func) (void *data, E_Dialog *dia), void *data)
{
   E_Dialog_Button *db;
   Evas_Coord mw, mh;
   
   db = E_NEW(E_Dialog_Button, 1);
   db->dialog = dia;
   if (label) db->label = strdup(label);
   if (icon) db->icon = strdup(icon);
   db->func = func;
   db->data = data;
   db->obj = edje_object_add(e_win_evas_get(dia->win));
   e_theme_edje_object_set(db->obj, "base/theme/dialog",
			   "widgets/dialog/button");
   edje_object_signal_callback_add(db->obj, "click", "",
				   _e_dialog_cb_button_clicked, db);
   edje_object_part_text_set(db->obj, "button_text", db->label);
   edje_object_size_min_calc(db->obj, &mw, &mh);
   e_box_pack_end(dia->box_object, db->obj);
   e_box_pack_options_set(db->obj,
			  1, 1, /* fill */
			  0, 1, /* expand */
			  0.5, 0.5, /* align */
			  mw, mh, /* min */
			  9999, mh /* max */
			  );
   evas_object_show(db->obj);
   
   dia->buttons = evas_list_append(dia->buttons, db);
}

void
e_dialog_title_set(E_Dialog *dia, char *title)
{
   e_win_title_set(dia->win, title);
}

void
e_dialog_text_set(E_Dialog *dia, char *text)
{
}

void
e_dialog_icon_set(E_Dialog *dia, char *icon)
{
}

void
e_dialog_show(E_Dialog *dia)
{
   Evas_Coord mw, mh;
   Evas_Object *o;
   
   o = dia->text_object;
//   evas_object_textblock_format_size_get(o, &mw, &mh);
   evas_object_textblock_native_size_get(o, &mw, &mh);
   edje_extern_object_min_size_set(o, mw + 2, mh + 2);
   edje_object_part_swallow(dia->bg_object, "content_swallow", o);

   o = dia->box_object;
   e_box_min_size_get(o, &mw, &mh);
   edje_extern_object_min_size_set(o, mw, mh);
   edje_object_part_swallow(dia->bg_object, "buttons_swallow", o);
   
   edje_object_size_min_calc(dia->bg_object, &mw, &mh);
   evas_object_resize(dia->bg_object, mw, mh);
   e_win_resize(dia->win, mw, mh);
   e_win_size_min_set(dia->win, mw, mh);
   e_win_size_max_set(dia->win, mw, mh);
   e_win_show(dia->win);
}

/* local subsystem functions */
static void
_e_dialog_free(E_Dialog *dia)
{
   while (dia->buttons)
     {
	E_Dialog_Button *db;
	
	db = dia->buttons->data;
	dia->buttons = evas_list_remove_list(dia->buttons, dia->buttons);
	IF_FREE(db->label);
	IF_FREE(db->icon);
	evas_object_del(db->obj);
	free(db);
     }
   if (dia->text_object) evas_object_del(dia->text_object);
   if (dia->icon_object) evas_object_del(dia->icon_object);
   if (dia->box_object) evas_object_del(dia->box_object);
   if (dia->bg_object) evas_object_del(dia->bg_object);
   e_object_del(E_OBJECT(dia->win));
   free(dia);
}

static void
_e_dialog_cb_button_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
{
   E_Dialog_Button *db;
   
   db = data;
   if (db->func)
     db->func(db->data, db->dialog);
   else
     e_object_del(E_OBJECT(db->dialog));
}

static void
_e_dialog_cb_delete(E_Win *win)
{
   E_Dialog *dia;
   
   dia = win->data;
   e_object_del(E_OBJECT(dia));
}