summaryrefslogtreecommitdiff
path: root/main/src/util/ivug-widget.c
blob: fd43992903845c3c00d53676a8ecaa18a1874be7 (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
/*
 * 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 "ivug-common.h"
#include "ivug-widget.h"
#include <ui-gadget-module.h>

#include <Elementary.h>

static void _on_obj_deleted(void * data, Evas * e, Evas_Object * obj, void * event_info)
{
	char *szMsg = (char *)data;
	IV_ASSERT(szMsg != NULL);

	MSG_MAIN_HIGH("On Object deleted. %s", szMsg);

	free(szMsg);
}

void ivug_on_obj_deleted(Evas_Object* obj, char *msg, const char *func, int line)
{
	static char buf[1024];

	sprintf(buf, "%s(L%d):%s", func, line, msg);

	evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, _on_obj_deleted, strdup(buf));
}

Evas_Object* ivug_bg_add(Evas_Object* parent, int r, int g, int b)
{
    IV_ASSERT(parent != NULL);

	Evas_Object *bg = elm_bg_add(parent);
	evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL);

//	elm_win_resize_object_add(parent, bg);

	elm_bg_color_set(bg, r,  g, b);

	evas_object_show(bg);

	return bg;
}

Evas_Object *
ivug_layout_add(Evas_Object *win, const char *edj, const char *group)
{
	IV_ASSERT(win != NULL);

	Evas_Object *layout;

	layout = elm_layout_add(win);

	if ( layout == NULL )
	{
		MSG_SETAS_ERROR("Cannot create layout");
		return NULL;
	}

	if (elm_layout_file_set(layout, edj, group) == EINA_FALSE)
	{
		MSG_SETAS_ERROR("edj loading fail, filepath=%s Group=%s", edj, group);
		evas_object_del(layout);
		return NULL;
	}

	evas_object_size_hint_expand_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	evas_object_size_hint_fill_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);

#ifdef USE_WIN_AS_PARENT
	elm_win_resize_object_add( ug_get_window(), layout);
#else
	Evas_Coord x, y, w, h;
	evas_object_geometry_get(win, &x, &y, &w, &h);

	evas_object_move(layout, x, y);
	evas_object_resize(layout, w, h);
#endif

	evas_object_show(layout);
	return layout;
}

Evas_Object*
ivug_default_layout_add( Evas_Object *win)
{
	IV_ASSERT(win != NULL);

	Evas_Object *layout;
	layout = elm_layout_add(win);

	if ( layout == NULL )
	{
		MSG_SETAS_ERROR("Cannot create layout");
		return NULL;
	}

	if ( elm_layout_theme_set( layout, "layout", "application", "default") == EINA_FALSE)
	{
		MSG_SETAS_ERROR("theme set fail, layout/application/defaulty");
		evas_object_del(layout);
		return NULL;
	}

	evas_object_size_hint_expand_set( layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	evas_object_size_hint_fill_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL );

#ifdef USE_WIN_AS_PARENT
	elm_win_resize_object_add( ug_get_window(), layout);
#else
	Evas_Coord x, y, w, h;
	evas_object_geometry_get(parent, &x, &y, &w, &h);

	evas_object_move(layout, x, y);
	evas_object_resize(layout, w, h);
#endif

	evas_object_show(layout);
	return layout;
}


Evas_Object *ivug_button_add(Evas_Object *parent, char *style, char *caption, Evas_Object *icon, OnClickCB pFunc, const void *  data )
{
	IV_ASSERT(parent != NULL);

	Evas_Object *btn;

	btn = elm_button_add(parent);
	if ( btn == NULL )
	{
		return NULL;
	}

	if ( style )
		elm_object_style_set(btn, style);

	if ( caption )
		elm_object_text_set(btn, caption);

	if ( icon )
		elm_object_part_content_set(btn, "icon", icon);

	elm_object_focus_allow_set(btn, EINA_FALSE);
	evas_object_propagate_events_set(btn, EINA_FALSE);

	evas_object_smart_callback_add(btn, "clicked", pFunc, (void*)data);

	return btn;
}

Evas_Object *ivug_icon_add(Evas_Object *parent, char *edjname, char *groupname)
{
	Evas_Object *icon;

	icon = elm_icon_add(parent);

	if ( elm_icon_file_set(icon, edjname, groupname) == EINA_FALSE)
	{
		MSG_IVUG_ERROR("Cannot file set. EDJ=%s Group=%s", edjname, groupname);
		evas_object_del(icon);
		return NULL;
	}

	evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
	elm_icon_resizable_set(icon, EINA_TRUE, EINA_TRUE);
	evas_object_size_hint_expand_set(icon, 1, 1);

	return icon;
}

Evas_Object *ivug_controlbar_add(Evas_Object *parent, const char *style)
{
	Evas_Object *toolbar = elm_toolbar_add(parent);
	if (!toolbar)
	{
		MSG_MAIN_ERROR("create tool bar failed");
		return NULL;
	}
	elm_toolbar_shrink_mode_set(toolbar, ELM_TOOLBAR_SHRINK_EXPAND);
	elm_object_style_set(toolbar, style);

	return toolbar;
}



void
ivug_object_del(Evas_Object *obj)
{
	evas_object_del(obj);
}