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.
17 #include <ui-gadget.h>
18 #include "view_uigadget.h"
19 #include <AppCommon.h>
20 #include "common_defs.h"
21 #include "settingviewmgr.h"
25 * This callback function is invoked with base layout for layout arrangement
26 * after UI Gadget create create operation is completed.
28 * @param ug [in] The handler data representing a UI gadget.
29 * @param mode [in] The UI gadget mode.
30 * @param priv [in] The function specific data passed by UG caller.
33 void CUiGadget::sm_CbLayout(ui_gadget_h ug, enum ug_mode mode, void *priv)
35 CUiGadget *root = (CUiGadget*)priv;
37 root->t_OnLayout(ug, mode);
42 * After UG module invoke ug_send_message to send result,
43 * UG library call this callback function registered by calling ug_create.
45 * @param ug [in] The handler data representing a UI gadget.
46 * @param result [in] The Service handler.
47 * @param priv [in] The function specific data passed by UG caller.
50 void CUiGadget::sm_CbResult(ui_gadget_h ug, service_h result, void *priv)
52 CUiGadget *root = (CUiGadget*)priv;
54 root->t_OnResult(ug, result);
60 * Send the destroy request, use ug_destroy_me,
61 * then UG library calls this callback function registered by UG caller.
63 * @param ug [in] The handler data representing a UI gadget.
64 * @param priv [in] The function specific data passed by UG caller.
67 void CUiGadget::sm_CbDestroy(ui_gadget_h ug, void *priv)
69 CUiGadget *root = (CUiGadget*)priv;
71 root->t_OnDestroy(ug);
75 void CUiGadget::sm_CbEnd(ui_gadget_h ug, void *priv)
77 CUiGadget *root = (CUiGadget*)priv;
83 bool CUiGadget::Create(ui_gadget_h parent, const char *name, ug_mode mode, service_h service)
95 m_handler = ug_create(NULL, name, UG_MODE_FRAMEVIEW, NULL, &cbs);
97 return m_handler ? true : false;
101 void CUiGadget::Destroy(void)
106 ug_destroy(m_handler);
111 struct SUiGadgetView {
115 Evas_Object *main_item_box;
116 Evas_Object *subitem_box;
118 const char *display_name;
120 struct settingview_data *view;
124 * This function is invoked to hide view layout.
126 * @param base [in] The view layout evas object.
129 void CUiGadgetView::Hide(void)
133 evas_object_hide(m->base);
137 * Hide current ug launcher view, then pop this view from view list and return to main view.
139 * @param data [in] The function specific data which hold _data pointer.
142 void CUiGadgetView::m_BackToMainview(void)
151 * This function is invoked to show sub item buttons evas object.
153 * @param box [in] The box evas object contained sub item buttons.
156 static void _show_item_btns(Evas_Object *box)
165 list = elm_box_children_get(box);
167 _ERR("button list is null.");
171 EINA_LIST_FOREACH(list, l, obj)
173 btn = (Evas_Object *) obj;
174 evas_object_show(btn);
177 eina_list_free(list);
181 void CUiGadgetView::t_OnDestroy(ui_gadget_h ug)
184 _ERR("Invalid parameters in ug destroy callback.");
188 _show_item_btns(m->subitem_box);
190 elm_object_focus_set(m->subbtn, EINA_TRUE);
191 elm_object_part_text_set(m->base, UG_TITLE_TEXT, "");
193 CUiGadget::Destroy();
199 * This function is invoked to create UI Gadget with specific UG name.
201 * @param data [in] The function specific data which hold _data pointer.
202 * @return 0 if success, -1 if fail.
204 bool CUiGadgetView::m_Load(void)
207 struct settingitem *parent;
209 parent = viewdata_get_parentitem(m->view);
210 name = settingitem_get_settingui_name(parent);
211 elm_object_part_text_set(m->base, UG_TITLE_TEXT, m->display_name);
213 if (!CUiGadget::Create(NULL, name, UG_MODE_FRAMEVIEW, NULL)) {
217 m->mgr->FreezeTimeout();
224 * This function is invoked to hide sub item buttons evas object.
226 * @param box [in] The box evas object contained sub item buttons.
229 static void _hide_item_btns(Evas_Object *box)
236 _ERR("item box is null.");
240 list = elm_box_children_get(box);
242 _ERR("button list is null.");
246 EINA_LIST_FOREACH(list, l, obj)
248 btn = (Evas_Object *) obj;
249 evas_object_hide(btn);
252 eina_list_free(list);
256 Evas_Object *CUiGadgetView::Base(void)
265 * This function is invoked to create UG launcher view layout.
267 * @param mgr [in] The setting_mgr data pointer passed by @settingmgr_view_push.
268 * @param view [in] The settingview_data data pointer passed by @settingmgr_view_push.
269 * @param prev [in] The parameter data which passed by prev view or NULL.
270 * @return View layout evas object, NULL on error.
272 bool CUiGadgetView::Create(struct settingview_data *view, void *prev)
278 Evas_Object *win, *base;
279 struct evas_obj_data *param;
281 CSettingMgr *mgr = CSettingMgr::GetInstance();
283 param = (struct evas_obj_data *) prev;
284 _hide_item_btns(param->subitem_box);
289 m = new SUiGadgetView;
291 _ERR("calloc SUiGadgetView failed.");
295 base = elm_layout_add(win);
297 _ERR("add base layout failed.");
303 elm_layout_file_set(base, EDJ_FILE, UG_GROUP);
309 m->subitem_box = param->subitem_box;
310 m->display_name = param->display_name;
311 m->subbtn = param->cur_btn;
314 _ERR("load ui gadget failed.");
315 evas_object_del(base);
326 void CUiGadgetView::Show(void)
330 evas_object_show(m->base);
334 void CUiGadgetView::Destroy(void)
338 CUiGadget::Destroy();
341 viewdata_release(m->view);
343 evas_object_del(m->base);