2 * Copyright 2012 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 "ivug-popup.h"
19 #define NOTIFY_TIMEOUT 3.0
21 #define IVUG_POPUP_EDJ_NAME EDJ_PATH"/ivug-popup.edj"
23 typedef struct _Ivug_Popup
33 Popup_Response response;
35 Evas_Smart_Cb callback;
44 Evas_Object *radio_main;
45 Ivug_Popup *p_iv_popup;
46 Elm_Object_Item *item;
47 } ivug_radio_popup_item;
49 static Ivug_Popup * ivug_popup_create()
51 Ivug_Popup *iv_popup = calloc(1, sizeof(Ivug_Popup));
56 static void ivug_popup_delete(Ivug_Popup *iv_popup)
61 evas_object_del(iv_popup->popup);
62 iv_popup->popup = NULL;
67 evas_object_del(iv_popup->layout);
68 iv_popup->layout = NULL;
74 static void _on_popup_response(void *data, Evas_Object *obj, void *event_info )
76 IV_ASSERT(data != NULL);
78 Ivug_Popup *iv_popup = (Ivug_Popup *)data;
79 Popup_Response response = (Popup_Response)evas_object_data_get(obj, "response");
80 MSG_IMAGEVIEW_HIGH("response callback=%d", response);
82 if(iv_popup->callback)
84 iv_popup->callback(iv_popup->data, iv_popup->popup, (void *)response);
87 ivug_popup_delete(iv_popup);
91 static void _on_ctxpopup_dismissed( void *data, Evas_Object *obj, void *event_info )
93 // Triggered when clicked outside ctxpopup
94 MSG_IMAGEVIEW_HIGH("Dismissed response");
96 Ivug_Popup *iv_popup = (Ivug_Popup *)data;
98 ivug_popup_delete(iv_popup);
102 ivug_deletepopup_show(Evas_Object* parent, const char* title,
103 const char* contents, Evas_Smart_Cb response, void* user_data)
106 Evas_Object *btn_delete;
107 Evas_Object *btn_cancel;
110 IV_ASSERT(response != NULL);
112 Ivug_Popup *iv_popup = ivug_popup_create();
114 popup = elm_popup_add(parent);
115 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
116 elm_object_text_set(popup, contents);
117 elm_object_part_text_set(popup, "title,text", title);
119 btn_delete = ivug_button_add(popup, "popup_button/default", IDS_DELETE, NULL, _on_popup_response, iv_popup);
120 elm_object_part_content_set(popup, "button1", btn_delete);
121 evas_object_data_set(btn_delete, "response", (void *)POPUP_RESPONSE_OK);
123 btn_cancel = ivug_button_add(popup, "popup_button/default", IDS_CANCEL, NULL, _on_popup_response, iv_popup);
124 elm_object_part_content_set(popup, "button2", btn_cancel);
125 evas_object_data_set(btn_cancel, "response", (void *)POPUP_RESPONSE_CANCEL);
127 iv_popup->popup = popup;
128 iv_popup->callback = response;
129 iv_popup->data = user_data;
131 evas_object_show(popup);
138 ivug_2btn_popup_show(Evas_Object* parent, const char* title,
139 const char* contents, Evas_Smart_Cb response, void* user_data)
141 IV_ASSERT(response != NULL);
143 Ivug_Popup *iv_popup = ivug_popup_create();
146 Evas_Object *btn_yes;
150 popup = elm_popup_add(parent);
151 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
152 elm_object_text_set(popup, contents);
155 elm_object_part_text_set(popup, "title,text", title);
158 btn_yes = ivug_button_add(popup, "popup_button/default", IDS_YES, NULL, _on_popup_response, iv_popup);
159 elm_object_part_content_set(popup, "button1", btn_yes);
160 evas_object_data_set(btn_yes, "response", (void *)POPUP_RESPONSE_OK);
162 btn_no = ivug_button_add(popup, "popup_button/default", IDS_NO, NULL, _on_popup_response, iv_popup);
163 elm_object_part_content_set(popup, "button2", btn_no);
164 evas_object_data_set(btn_no, "response", (void *)POPUP_RESPONSE_CANCEL);
166 iv_popup->popup = popup;
167 iv_popup->callback = response;
168 iv_popup->data = user_data;
170 evas_object_show(popup);
171 evas_object_layer_set(popup, EVAS_LAYER_MAX);
176 Evas_Object *ivug_timeout_popup_show(Evas_Object *parent,
177 Evas_Smart_Cb response, void *data, const char *sztitle, const char *content)
180 Ivug_Popup *iv_popup = ivug_popup_create();
184 popup = elm_popup_add(parent);
185 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
187 elm_object_text_set(popup, content);
191 iv_popup->callback = response;
196 iv_popup->data = data;
200 elm_object_part_text_set(popup, "title,text", sztitle);
202 elm_popup_timeout_set(popup, 3.0);
203 evas_object_smart_callback_add(popup, "timeout", _on_popup_response, iv_popup);
205 iv_popup->popup = popup;
207 evas_object_show(popup);
213 static void _on_longpress_popup_selected(void *data, Evas_Object *obj, void *event_info)
215 IV_ASSERT(data != NULL);
217 Ivug_Popup *iv_popup = (Ivug_Popup *)data;
219 const char *label = elm_object_item_text_get((Elm_Object_Item *)event_info);
222 MSG_MAIN_ERROR("label is NULL");
223 ivug_popup_delete(iv_popup);
226 MSG_MAIN_HIGH("text(%s) is clicked", label);
228 Longpress_Popup_Response response = LPPOPUP_RESPONSE_NONE;
229 if(strncmp(label, IDS_COPY, strlen(label)) == 0)
231 response = LPPOPUP_RESPONSE_COPY;
233 else if(strncmp(label, IDS_MANUALLY_DETECT, strlen(label)) == 0)
235 response = LPPOPUP_RESPONSE_MANUALLY_DETECT;
239 MSG_MAIN_WARN("Unknown Share type : %s", label);
241 MSG_MAIN_HIGH("response=%d", response);
243 if(iv_popup->callback)
245 iv_popup->callback(iv_popup->data, iv_popup->popup, (void *)response);
248 ivug_popup_delete(iv_popup);
252 ivug_longpress_popup_show(Evas_Object *parent, int x, int y, Evas_Smart_Cb response, void *data)
254 Ivug_Popup *iv_popup = ivug_popup_create();
256 Evas_Object* ctx_popup = NULL;
258 ctx_popup = elm_ctxpopup_add(parent);
260 elm_ctxpopup_item_append(ctx_popup, IDS_COPY, NULL, _on_longpress_popup_selected, iv_popup);
263 evas_object_smart_callback_add(ctx_popup, "dismissed", _on_ctxpopup_dismissed, iv_popup);
265 evas_object_move(ctx_popup, x, y);
267 iv_popup->popup = ctx_popup;
268 iv_popup->callback = response;
269 iv_popup->data = data;
271 evas_object_show(ctx_popup);
278 _ivug_rename_enter_click_cb(void *data, Evas_Object *obj, void *event_info)
280 Ivug_Popup *iv_popup = (Ivug_Popup *)data;
281 IV_ASSERT(iv_popup != NULL);
283 Evas_Object *entry = iv_popup->obj;
285 char *name = elm_entry_markup_to_utf8 ( elm_entry_entry_get(entry) );
287 MSG_IMAGEVIEW_HIGH("name = %s", name);
291 char *new_name = NULL;
292 new_name = ivug_strip_string(name);
295 MSG_IMAGEVIEW_ERROR( "rename failed");
297 ecore_imf_context_input_panel_hide(elm_entry_imf_context_get(entry));
300 elm_object_text_set(entry, new_name);
301 if(iv_popup->callback)
303 iv_popup->callback(iv_popup->data, iv_popup->popup, (void *)POPUP_RESPONSE_OK);
305 ivug_popup_delete(iv_popup);
309 //ecore_imf_context_input_panel_hide(elm_entry_imf_context_get(entry));
314 _ivug_rename_entry_changed(void *data, Evas_Object *obj, void *event_info)
316 Ivug_Popup *iv_popup = (Ivug_Popup *)data;
317 IV_ASSERT(iv_popup != NULL);
319 Evas_Object *entry = iv_popup->obj;
320 Evas_Object *btn_ok = elm_object_part_content_get(iv_popup->popup, "button1");
322 char *content = elm_entry_markup_to_utf8 ( elm_entry_entry_get(entry) );
324 if (strlen(content) == 0)
326 MSG_IMAGEVIEW_HIGH("ISF1 : %s", content);
327 elm_object_disabled_set(btn_ok, EINA_TRUE);
331 MSG_IMAGEVIEW_HIGH("ISF : %s", content);
332 elm_object_disabled_set(btn_ok, EINA_FALSE);
338 _ivug_rename_maxlength_reached(void *data, Evas_Object *obj, void *event_info)
340 Ivug_Popup *iv_popup = (Ivug_Popup *)data;
341 IV_ASSERT(iv_popup != NULL);
346 Evas_Object *ivug_rename_popup_show(Evas_Object *parent, const char *filename, Evas_Smart_Cb response, void *data)
348 Evas_Object *popup = NULL;
349 Evas_Object *entry = NULL;
350 Evas_Object *layout = NULL;
352 Ivug_Popup *iv_popup = ivug_popup_create();
355 MSG_IMAGEVIEW_ERROR("ivug_popup_create ERROR");
359 popup = elm_popup_add(parent);
362 MSG_IMAGEVIEW_ERROR("popup is NULL");
363 goto ENTRY_POPUP_FREE;
365 //evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
366 //elm_object_style_set(popup, "menustyle");
367 elm_object_part_text_set(popup, "title,text", "Rename");
369 layout = ivug_layout_add2(popup, IVUG_POPUP_EDJ_NAME, "popup_entryview");
372 MSG_IMAGEVIEW_ERROR("layout is NULL");
373 goto ENTRY_POPUP_FREE;
376 entry = elm_entry_add(popup);
377 elm_entry_scrollable_set(entry, EINA_TRUE);
378 elm_entry_single_line_set(entry, EINA_TRUE);
379 elm_object_text_set(entry, filename);
380 elm_entry_cursor_end_set(entry);
381 elm_object_part_content_set(layout, "elm.swallow.content", entry);
382 elm_object_content_set(popup, layout);
384 evas_object_smart_callback_add(entry, "activated", _ivug_rename_enter_click_cb, iv_popup);
385 evas_object_smart_callback_add(entry, "changed", _ivug_rename_entry_changed, iv_popup);
387 static Elm_Entry_Filter_Limit_Size limit_filter_data;
388 limit_filter_data.max_char_count = 64;
389 limit_filter_data.max_byte_count = 0;
390 elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_filter_data);
391 evas_object_smart_callback_add(entry, "maxlength,reached", _ivug_rename_maxlength_reached, (void *)iv_popup);
393 evas_object_show(layout);
395 Evas_Object *btn_ok = ivug_button_add(popup, "popup_button/default", IDS_OK, NULL, _ivug_rename_enter_click_cb, iv_popup);
396 elm_object_part_content_set(popup, "button1", btn_ok);
397 evas_object_data_set(btn_ok, "response", (void *)POPUP_RESPONSE_OK);
399 Evas_Object *btn_cancel = ivug_button_add(popup, "popup_button/default", IDS_CANCEL, NULL, _on_popup_response, iv_popup);
400 elm_object_part_content_set(popup, "button2", btn_cancel);
401 evas_object_data_set(btn_cancel, "response", (void *)POPUP_RESPONSE_CANCEL);
403 iv_popup->popup = popup;
404 iv_popup->callback = response;
405 iv_popup->data = data;
406 iv_popup->obj = entry;
408 evas_object_show(popup);
415 evas_object_del(popup);
417 ivug_popup_delete(iv_popup);
421 static void _block_clicked_cb(void *data, Evas_Object *obj, void *event_info)
423 IV_ASSERT(data != NULL);
425 Ivug_Popup *iv_popup = (Ivug_Popup *)data;
426 Popup_Response response = (Popup_Response)evas_object_data_get(obj, "response");
427 MSG_IMAGEVIEW_HIGH("response callback=%d", response);
429 if(iv_popup->callback)
431 iv_popup->callback(iv_popup->data, iv_popup->popup, (void *)response);
434 ivug_popup_delete(iv_popup);
438 _gl_text_get(void *data, Evas_Object *obj, const char *part)
440 ivug_radio_popup_item *popup_item = (ivug_radio_popup_item *)data;
441 //int index = popup_item->index;
443 if (strcmp(part, "elm.text") == 0)
445 return strdup(popup_item->name);
451 _gl_content_get(void *data, Evas_Object *obj, const char *part)
453 ivug_radio_popup_item *popup_item = (ivug_radio_popup_item *)data;
456 Evas_Object *radio_main = popup_item->radio_main;
457 int index = popup_item->index;
458 int selected_index = popup_item->p_iv_popup->selected_index;
460 if (strcmp(part, "elm.icon") == 0 || strcmp(part, "elm.swallow.icon") == 0)
462 radio = elm_radio_add(obj);
463 elm_radio_state_value_set(radio, index);
464 elm_radio_group_add(radio, radio_main);
465 if (index == selected_index)
466 elm_radio_value_set(radio, selected_index);
467 evas_object_size_hint_weight_set(radio, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
468 evas_object_size_hint_align_set(radio, EVAS_HINT_FILL, EVAS_HINT_FILL);
477 _gl_del(void *data, Evas_Object *obj)
479 ivug_radio_popup_item *popup_item = (ivug_radio_popup_item *)data;
483 free(popup_item->name);
484 popup_item->name = NULL;
493 _gl_sel(void *data, Evas_Object *obj, void *event_info)
495 IV_ASSERT(data != NULL);
497 Ivug_Popup *iv_popup = (Ivug_Popup *)data;
499 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
500 ivug_radio_popup_item *popup_item = NULL;
502 MSG_IMAGEVIEW_HIGH("_gl_sel");
506 popup_item = (ivug_radio_popup_item *)elm_object_item_data_get(item);
507 iv_popup->selected_index = popup_item->index;
508 elm_genlist_item_update(item);
510 if(iv_popup->callback)
512 iv_popup->callback(iv_popup->data, iv_popup->popup, (void *)iv_popup->selected_index);
515 ivug_popup_delete(iv_popup);
519 Evas_Object *ivug_radio_popoup_show(Evas_Object *parent, char *title,
520 int selected_index, Eina_List *name_list, Evas_Smart_Cb response, void *data)
522 #define GET_POPUP_HEIGHT(icnt) (((113*icnt-1) > 408) ? (408) : (113*icnt-1))
523 #define GET_POPUP_WIDTH(icnt) (614)
527 Elm_Object_Item *item;
528 Evas_Object *genlist;
529 Evas_Object *btn_close;
530 Evas_Object *radio_main;
532 static Elm_Genlist_Item_Class itc = {0,};
534 ivug_radio_popup_item *popup_item;
536 Ivug_Popup *iv_popup = ivug_popup_create();
538 popup = elm_popup_add(parent);
539 elm_object_style_set(popup, "menustyle");//elm_object_style_set(popup, "min_menustyle");
540 elm_object_part_text_set(popup, "title,text", title);
541 evas_object_smart_callback_add(popup, "block,clicked", _block_clicked_cb, iv_popup);
542 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
544 btn_close = ivug_button_add(popup, "popup_button/default", IDS_CLOSE, NULL, _on_popup_response, iv_popup);
545 elm_object_part_content_set(popup, "button1", btn_close);
546 evas_object_data_set(btn_close, "response", (void *)POPUP_RESPONSE_OK);
548 itc.item_style = "1text.1icon.2";
549 itc.func.text_get = _gl_text_get;
550 itc.func.content_get = _gl_content_get;
551 itc.func.state_get = NULL;
552 itc.func.del = _gl_del;
554 genlist = elm_genlist_add(popup);
555 evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
556 evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
557 evas_object_propagate_events_set(genlist, EINA_FALSE);
559 radio_main = elm_radio_add(genlist);
560 elm_radio_state_value_set(radio_main, -1);
561 elm_radio_value_set(radio_main, -1);
562 evas_object_propagate_events_set(radio_main, EINA_FALSE);
567 EINA_LIST_FOREACH(name_list, l, name)
569 popup_item = calloc(1, sizeof(ivug_radio_popup_item));
570 popup_item->index = index++;
571 popup_item->name = strdup(name);
572 popup_item->radio_main = radio_main;
573 popup_item->p_iv_popup = iv_popup;
575 item = elm_genlist_item_append(genlist, &itc, (void *)popup_item, NULL,
576 ELM_GENLIST_ITEM_NONE, _gl_sel, iv_popup);
578 popup_item->item = item;
582 box = elm_box_add(popup);
583 evas_object_size_hint_min_set(box, GET_POPUP_WIDTH(index-1) * elm_config_scale_get(), GET_POPUP_HEIGHT(index-1) * elm_config_scale_get());
584 evas_object_show(genlist);
585 elm_box_pack_end(box, genlist);
586 elm_object_content_set(popup, box);
587 //elm_object_content_set(popup, genlist);
589 iv_popup->popup = popup;
590 iv_popup->callback = response;
591 iv_popup->data = data;
592 iv_popup->obj = radio_main;
593 iv_popup->selected_index = selected_index;
595 evas_object_show(popup);