2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 "ug-nfc-setting-popup.h"
21 #define NFC_POPUP_AUTO_TIMEOUT_SEC 3.0
22 #define MOUSE_RIGHT_BTN_UP 3
24 static Evas_Object *_popup = NULL;
25 static UG_NFC_POPUP_USER_RESP_CB _user_response_cb;
26 static void *_user_data = NULL;
28 static void _remove_key_event_handler(void);
29 static void _add_key_event_handler(void);
31 static void _ug_nfc_setting_popup_response_cb(void *data, Evas_Object *obj, void *event_info)
33 int btn_type = (int)data;
35 if (_user_response_cb)
36 _user_response_cb(_user_data, obj, (void*)btn_type);
38 LOGD("btn_type: %d", (int)btn_type);
39 LOGD("Popup is removed: [%p]", obj);
40 evas_object_del(_popup);
43 _user_response_cb = NULL;
47 static Eina_Bool _ug_nfc_setting_popup_show_cb(void *data)
50 evas_object_show(_popup);
52 return ECORE_CALLBACK_CANCEL;
55 static void _popup_back_click_cb(void)
60 _remove_key_event_handler();
62 _ug_nfc_setting_popup_response_cb((void*)UG_NFC_POPUP_RESP_CANCEL, _popup, NULL);
65 static void _mouseup_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
67 Evas_Event_Mouse_Up *ev = event_info;
72 if (ev->button == MOUSE_RIGHT_BTN_UP)
73 _popup_back_click_cb();
76 static void _keydown_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
78 Evas_Event_Key_Down *ev = event_info;
83 if (!strcmp(ev->keyname, KEY_BACK))
84 _popup_back_click_cb();
87 static void _remove_key_event_handler(void)
92 evas_object_event_callback_del(_popup, EVAS_CALLBACK_MOUSE_UP, _mouseup_cb);
93 evas_object_event_callback_del(_popup, EVAS_CALLBACK_KEY_DOWN, _keydown_cb);
96 static void _add_key_event_handler(void)
101 evas_object_event_callback_add(_popup, EVAS_CALLBACK_MOUSE_UP, _mouseup_cb, NULL);
102 evas_object_event_callback_add(_popup, EVAS_CALLBACK_KEY_DOWN, _keydown_cb, NULL);
105 static void _ug_nfc_setting_popup_block_clicked_cb(void *data, Evas_Object *obj, void *event_info)
107 _ug_nfc_setting_popup_response_cb((void*)UG_NFC_POPUP_RESP_CANCEL, _popup, NULL);
110 Evas_Object *ug_nfc_setting_create_popup(void *data,
111 Evas_Object *parent_layout,
113 const char *description,
114 const char *btn1_text,
116 const char *btn2_text,
118 const char *btn3_text,
122 UG_NFC_POPUP_USER_RESP_CB response_cb)
124 Evas_Object *btn = NULL;
130 ug_nfc_setting_close_popup(_popup);
134 _popup = elm_popup_add(parent_layout);
135 LOGD("Popup is created: [%p]", _popup);
136 evas_object_size_hint_weight_set(_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
139 elm_object_part_text_set(_popup, "title,text", title);
141 elm_object_text_set(_popup, description);
144 btn = elm_button_add(_popup);
145 elm_object_style_set (btn, "popup");
146 elm_object_text_set(btn, btn1_text);
147 elm_object_part_content_set(_popup, "button1", btn);
148 evas_object_smart_callback_add(btn, "clicked",
149 _ug_nfc_setting_popup_response_cb, (void*)btn1_type);
152 btn = elm_button_add(_popup);
153 elm_object_style_set (btn, "popup");
154 elm_object_text_set(btn, btn2_text);
155 elm_object_part_content_set(_popup, "button2", btn);
156 evas_object_smart_callback_add(btn, "clicked",
157 _ug_nfc_setting_popup_response_cb, (void*)btn2_type);
160 btn = elm_button_add(_popup);
161 elm_object_style_set (btn, "popup");
162 elm_object_text_set(btn, btn3_text);
163 elm_object_part_content_set(_popup, "button3", btn);
164 evas_object_smart_callback_add(btn, "clicked",
165 _ug_nfc_setting_popup_response_cb, (void*)btn3_type);
168 _user_response_cb = response_cb;
172 evas_object_smart_callback_add(_popup, "block,clicked",
173 _ug_nfc_setting_popup_block_clicked_cb, NULL);
176 if (enable_timeout) {
177 elm_popup_timeout_set(_popup, NFC_POPUP_AUTO_TIMEOUT_SEC);
178 evas_object_smart_callback_add(_popup, "timeout",
179 _ug_nfc_setting_popup_response_cb, NULL);
182 _add_key_event_handler();
184 _ug_nfc_setting_popup_show_cb(NULL);
190 void ug_nfc_setting_close_popup(Evas_Object* popup)
192 if (NULL == popup || NULL == _popup || _popup != popup) {
193 LOGD("NULL == popup || NULL == _popup || _popup != popup");
196 _ug_nfc_setting_popup_response_cb((void*)UG_NFC_POPUP_RESP_CANCEL, _popup, NULL);