summaryrefslogtreecommitdiff
path: root/src/_util_efl.c
blob: def79ceb5ebb3455cd8213c914e99ac686f3db84 (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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
 /*
  * Copyright 2012  Samsung Electronics Co., Ltd
  *
  * Licensed under the Flora License, Version 1.0 (the License);
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.tizenopensource.org/license
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an AS IS BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */


#include <appcore-efl.h>

#include "taskmanager.h"
#include "_util_log.h"
#include "_util_efl.h"
#include "_logic.h"

Evas_Object *_add_window(const char *name)
{
	Evas_Object *eo;
	int w, h;

	eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
	if (eo) {
		elm_win_title_set(eo, name);
		elm_win_borderless_set(eo, EINA_TRUE);
		ecore_x_window_size_get(ecore_x_window_root_first_get(),
					&w, &h);
		evas_object_resize(eo, w, h);
	}

	return eo;
}

Evas_Object *_add_bg(Evas_Object *parent, char *style)
{
	Evas_Object *bg;

	bg = elm_bg_add(parent);
	retvm_if(bg == NULL, NULL, "Failed to add bg\n");
	if (style)	elm_object_style_set(bg, style);
	evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND,
					 EVAS_HINT_EXPAND);
	evas_object_show(bg);
	return bg;
}

Evas_Object *_add_genlist(Evas_Object *parent)
{
	Evas_Object *eo;

	eo = elm_genlist_add(parent);
	if (eo == NULL) {
		printf("[Error] Cannot add genlist\n");
		return NULL;
	}

	evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND,
					 EVAS_HINT_EXPAND);
	evas_object_size_hint_align_set(eo, EVAS_HINT_FILL, EVAS_HINT_FILL);

	return eo;
}

Evas_Object *_add_icon(Evas_Object *parent, const char *png)
{
	Evas_Object *eo;
	char buf[128] = { 0, };

	eo = elm_icon_add(parent);
	if (eo == NULL) {
		printf("[Error] Cannot add button\n");
		return NULL;
	}

	snprintf(buf, sizeof(buf), "%s/%s", IMAGEDIR, png);
	elm_icon_file_set(eo, buf, NULL);
	elm_icon_resizable_set(eo, 1, 1);
	evas_object_size_hint_aspect_set(eo, EVAS_ASPECT_CONTROL_VERTICAL, 1,
					 1);

	return eo;
}

Evas_Object *_add_layout(Evas_Object *parent, const char *file,
			      const char *group)
{
	Evas_Object *eo = NULL;
	int r;

	eo = elm_layout_add(parent);
	if (eo == NULL) {
		printf("[Error] Cannot add layout\n");
		return NULL;
	}

	r = elm_layout_file_set(eo, file, group);
	if (!r) {
		printf("[Error] Cannot set file layout\n");
		evas_object_del(eo);
		return NULL;
	}

	evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND,
					 EVAS_HINT_EXPAND);

	return eo;
}

Evas_Object *_add_ctxpopup(Evas_Object *parent)
{
	Evas_Object *eo = NULL;

	eo = elm_ctxpopup_add(parent);
	if (eo == NULL) {
		printf("[Error] Cannot add ctxpopup\n");
		return NULL;
	}

	elm_ctxpopup_horizontal_set(eo, EINA_TRUE);
	elm_ctxpopup_direction_priority_set(eo,
					    ELM_CTXPOPUP_DIRECTION_DOWN,
					    ELM_CTXPOPUP_DIRECTION_UP,
					    ELM_CTXPOPUP_DIRECTION_LEFT,
					    ELM_CTXPOPUP_DIRECTION_RIGHT);

	return eo;
}

Evas_Object *_add_label(Evas_Object *parent, const char *msg)
{
	Evas_Object *eo = NULL;

	eo = elm_label_add(parent);
	if (eo == NULL) {
		printf("[Error] Cannot add label\n");
		return NULL;
	}

	elm_label_line_wrap_set(eo, ELM_WRAP_WORD);
	elm_object_text_set(eo, msg);

	return eo;
}

static Eina_Bool _disappear_popup(void *data)
{
	Evas_Object *eo = (Evas_Object *)data;
	if (eo == NULL) {
		printf("[Error] Invalid argument: popup is NULL\n");
		return ECORE_CALLBACK_CANCEL;
	}
	evas_object_del(eo);
	return ECORE_CALLBACK_CANCEL;
}

Evas_Object *_add_popup_ask(Evas_Object *parent, char *text, void *data)
{
	Evas_Object *pu, *bt1, *bt2;
	retvm_if(parent == NULL, NULL, "Invalid argument: parent is NULL\n");

	pu = elm_popup_add(parent);
	retvm_if(pu == NULL, NULL, "Falied to add popup\n");
	evas_object_size_hint_weight_set(pu, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	elm_object_part_text_set(pu, "title,text", D_("IDS_COM_POP_WARNING"));
	elm_object_text_set(pu, text);
	evas_object_show(pu);

	bt1 = elm_button_add(pu);
	elm_object_text_set(bt1, D_("IDS_COM_SK_OK"));
	elm_object_part_content_set(pu, "button1", bt1);
	evas_object_smart_callback_add(bt1, "clicked", _ok_response_cb, data);

	bt2 = elm_button_add(pu);
	elm_object_text_set(bt2, _("IDS_COM_POP_CANCEL"));
	elm_object_part_content_set(pu, "button2", bt2);
	evas_object_smart_callback_add(bt2, "clicked", _cancel_response_cb, data);


	return pu;
}

void util_show_popup_with_message(Evas_Object *parent, double in,
				  const char *msg)
{
	Evas_Object *eo = NULL;

	eo = elm_popup_add(parent);
	if (eo == NULL) {
		printf("[Error] Cannot add popup\n");
		return;
	}

	evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND,
					 EVAS_HINT_EXPAND);
	elm_object_text_set(eo, msg);

	ecore_timer_add(in, _disappear_popup, eo);
}

Evas_Object *_add_naviframe(Evas_Object *parent)
{
	Evas_Object *nv;

	retv_if(parent == NULL, NULL);

	nv = elm_naviframe_add(parent);
	retvm_if(nv == NULL, NULL, "Failed to add naviframe\n");
	elm_object_part_content_set(parent, "elm.swallow.content", nv);

	evas_object_show(nv);

	return nv;
}

Evas_Object *_add_layout_main(Evas_Object *parent,
		Eina_Bool content, Eina_Bool transparent)
{
	Evas_Object *ly;

	retv_if(parent == NULL, NULL);

	ly = elm_layout_add(parent);
	retvm_if(ly == NULL, NULL, "Failed elm_layout_add.\n");

	elm_layout_theme_set(ly, "layout", "application", "default");
	evas_object_size_hint_weight_set(ly,
		EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	elm_win_resize_object_add(parent, ly);
	if (content)
		elm_object_signal_emit(ly, "elm,state,show,content", "elm");
	if (transparent)
		elm_object_signal_emit(ly, "elm,bg,show,transparent", "elm");
	evas_object_show(ly);
	return ly;
}

Evas_Object *_add_progressbar(Evas_Object *parent, const char *style,
		Evas_Coord w, Evas_Coord h)
{
	Evas_Object *pb;
	double scale;

	retvm_if(parent == NULL, NULL, "Invalid argument: parent is NULL\n");

	scale = elm_config_scale_get();

	pb = elm_progressbar_add(parent);
	retvm_if(pb == NULL, NULL, "Failed to add progressbar\n");

	elm_object_style_set(pb, style);
	evas_object_resize(pb, w, (int)(60 * scale));
	evas_object_move(pb, 0, h / 2);
	elm_progressbar_pulse(pb, EINA_TRUE);
	evas_object_show(pb);

	return pb;
}