2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "SourceInfo.h"
22 #include "source_mgr.h"
24 Evas_Object *util_add_btn(Evas_Object *parent, const char *group)
28 if (!parent || !group)
31 btn = elm_button_add(parent);
35 elm_object_style_set(btn, group);
37 evas_object_size_hint_weight_set(btn,
38 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
39 evas_object_show(btn);
43 Evas_Object *util_add_layout(Evas_Object *parent, const char *group)
47 if (!parent || !group)
50 layout = elm_layout_add(parent);
54 elm_layout_file_set(layout, EDJ_FILE, group);
56 evas_object_size_hint_weight_set(layout,
57 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
62 Evas_Object *util_add_grid(Evas_Object *parent, int w, int h)
69 grid = elm_gengrid_add(parent);
73 elm_scroller_bounce_set(grid, EINA_FALSE, EINA_FALSE);
74 elm_gengrid_horizontal_set(grid, EINA_FALSE);
75 elm_gengrid_align_set(grid, 0.0, 0.0);
76 elm_gengrid_select_mode_set(grid, ELM_OBJECT_SELECT_MODE_ALWAYS);
77 elm_gengrid_multi_select_set(grid, EINA_FALSE);
79 elm_gengrid_item_size_set(grid, elm_config_scale_get() * h,
80 elm_config_scale_get() * w);
82 evas_object_size_hint_weight_set(grid,
83 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
84 evas_object_size_hint_align_set(grid,
85 EVAS_HINT_FILL, EVAS_HINT_FILL);
90 void util_dim_item(Elm_Object_Item *it)
97 elm_object_item_disabled_set(it, EINA_TRUE);
99 img = elm_object_item_part_content_get(it, PART_ITEM_ICO);
103 evas_object_color_set(img, ITEM_ICO_DIM_R,
104 ITEM_ICO_DIM_G, ITEM_ICO_DIM_B, ITEM_ICO_DIM_A);
107 static Evas_Object *_util_grid_content_get(void *data,
108 Evas_Object *obj, const char *part)
114 if (!part || !data || !obj)
117 si = (CSourceInfo *)data;
119 if (!strcmp(part, PART_ITEM_ICO)) {
120 path = si->IconPath();
124 img = elm_image_add(obj);
128 elm_image_file_set(img, path, NULL);
129 evas_object_show(img);
136 static char *_util_grid_text_get(void *data, Evas_Object *obj, const char *part)
146 si = (CSourceInfo *)data;
148 if (!strcmp(part, PART_ITEM_NAME)) {
150 ret = strdup(cret ? cret : NO_NAME);
151 } else if (!strcmp(part, PART_ITEM_TYPE)) {
152 cret = si->TypeName();
153 ret = strdup(cret ? cret : NO_TYPE);
159 static void _util_grid_item_del(void *data, Evas_Object *obj)
168 si = (CSourceInfo *)data;
169 it = (Elm_Object_Item *)si->Data();
171 timer = (Ecore_Timer*)elm_object_item_data_get(it);
175 ecore_timer_del(timer);
178 static void _util_grid_sel(void *data, Evas_Object *obj, void *event_info)
185 si = (CSourceInfo *)data;
187 if (!si->SwitchTo()) {
188 _ERR("Switch to source failed.");
191 elm_gengrid_item_selected_set((Elm_Object_Item*)event_info, EINA_FALSE);
195 void util_add_item(Evas_Object *grid, CSourceInfo *si)
198 Elm_Gengrid_Item_Class *ic;
201 _ERR("Parameter is NULL.");
205 ic = elm_gengrid_item_class_new();
207 _ERR("Create item class failed.");
211 ic->item_style = "source";
212 ic->func.text_get = _util_grid_text_get;
213 ic->func.content_get = _util_grid_content_get;
214 ic->func.state_get = NULL;
215 ic->func.del = _util_grid_item_del;
217 it = elm_gengrid_item_append(grid, ic, si, _util_grid_sel, si);
221 elm_gengrid_item_class_free(ic);