[elm_popup]Code refactoring for standardization and cleanup.
authorRajeev Ranjan <rajeev.r@samsung.com>
Mon, 2 May 2011 13:28:57 +0000 (18:58 +0530)
committerRajeev Ranjan <rajeev.r@samsung.com>
Wed, 4 May 2011 07:02:54 +0000 (12:32 +0530)
Change-Id: I398f5beb7cac6e60e850fd32dc64e45265c320a9

src/lib/elm_popup.c

index 5257ee9..0d92988 100644 (file)
 
 typedef struct _Widget_Data Widget_Data;
 
-struct _Widget_Data 
+struct _Widget_Data
 {
    Evas_Object *notify;
    Evas_Object *layout;
-   Evas_Object *parent;
    const char *title_area;
    Evas_Object *title_icon;
    Evas_Object *content_area;
    Evas_Object *desc_label;
    Evas_Object *action_area;
    Eina_List *button_list;
-   int rot_angle;
+   Elm_Popup_Mode mode;
    int no_of_buttons;
    Evas_Object *content;
    Elm_Notify_Orient notify_orient;
-   Ecore_Job *del_job;
    Eina_Bool delete_me : 1;
+#ifdef HAVE_ELEMENTARY_X
+   Ecore_Event_Handler* wnd_map_handler;
+#endif
 };
 
 typedef struct _Action_Area_Data Action_Area_Data;
 
-struct _Action_Area_Data 
+struct _Action_Area_Data
 {
-       Evas_Object *obj;
-       Evas_Object *btn;
-       int response_id;
+   Evas_Object *obj;
+   Evas_Object *btn;
+   int response_id;
 };
 
 static const char *widtype = NULL;
@@ -49,44 +50,15 @@ static void _action_area_clicked(void *data, Evas_Object *obj, void *event_info)
 static void _block_clicked_cb(void *data, Evas_Object *obj, void *event_info);
 static void _show(void *data, Evas *e, Evas_Object *obj, void *event_info);
 static void _hide(void *data, Evas *e, Evas_Object *obj, void *event_info);
-
-static void
-_del_parent(void *data, Evas *e, Evas_Object *obj, void *evet_info)
-{
-   Evas_Object *pop = data;
-   Widget_Data *wd = elm_widget_data_get(pop);
-
-   if (!wd) return;
-   if (wd->parent == obj)
-     {
-        evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_DEL, _del_parent, pop);
-        wd->parent = NULL;
-     }
-}
-
-static void
-_del_job(void *data)
-{
-   Evas_Object *obj = data;
-   evas_object_del(obj);
-}
+static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
 
 static void
 _del_hook(Evas_Object *obj)
 {
    Widget_Data *wd = elm_widget_data_get(obj);
 
-   if (!wd) return;  
-   if (!wd->del_job)
-     {
-        if (wd->parent)
-          {
-             evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_DEL, _del_parent, obj);
-             wd->del_job = ecore_job_add(_del_job, wd->parent);
-             wd->parent = NULL;
-          }
-     }
-   free(wd);   
+   if (!wd) return;
+   free(wd);
 }
 
 static void
@@ -99,6 +71,7 @@ _del_pre_hook(Evas_Object *obj)
    if (!wd) return;
    evas_object_event_callback_del_full(obj, EVAS_CALLBACK_SHOW, _show, NULL);
    evas_object_event_callback_del_full(obj, EVAS_CALLBACK_HIDE, _hide, NULL);
+   evas_object_smart_callback_del(wd->notify, "block,clicked", _block_clicked_cb);
    EINA_LIST_FOREACH(wd->button_list, list, action_data)
      {
         free(action_data);
@@ -114,23 +87,24 @@ _theme_hook(Evas_Object *obj)
    char buf[4096];
    Eina_List *list = NULL;
    Action_Area_Data *action_data = NULL;
-   int index =0; 
-   
+   int index =0;
+
    if (!wd) return;
    elm_layout_theme_set(wd->layout, "popup", "base", elm_widget_style_get(obj));
    elm_notify_orient_set(wd->notify, wd->notify_orient);
+   _mirrored_set(obj, elm_widget_mirrored_get(obj));
    edje_object_message_signal_process(elm_layout_edje_get(wd->layout));
    if (wd->action_area)
      {
-        snprintf(buf, sizeof(buf), "buttons%d", wd->no_of_buttons);  
-        elm_layout_theme_set(wd->action_area, "popup", buf, elm_widget_style_get(obj));         
+        snprintf(buf, sizeof(buf), "buttons%d", wd->no_of_buttons);
+        elm_layout_theme_set(wd->action_area, "popup", buf, elm_widget_style_get(obj));
         EINA_LIST_FOREACH(wd->button_list, list, action_data)
           {
              snprintf(buf, sizeof(buf), "popup_button/%s", elm_widget_style_get(obj));
              elm_object_style_set(action_data->btn, buf);
              ++index;
-             snprintf(buf, sizeof(buf), "actionbtn%d", index);       
-             elm_layout_content_set(wd->action_area, buf, action_data->btn);                    
+             snprintf(buf, sizeof(buf), "actionbtn%d", index);
+             elm_layout_content_set(wd->action_area, buf, action_data->btn);
           }
         elm_layout_content_set(wd->layout, "elm.swallow.buttonArea", wd->action_area);
      }
@@ -141,15 +115,15 @@ _theme_hook(Evas_Object *obj)
           {
              snprintf(buf, sizeof(buf), "popup_description/%s", elm_widget_style_get(obj));
              elm_object_style_set(wd->desc_label, buf);
-             elm_layout_content_set(wd->content_area, "elm.swallow.content", wd->desc_label);  
+             elm_layout_content_set(wd->content_area, "elm.swallow.content", wd->desc_label);
           }
-        else if(wd->content)
+        else if (wd->content)
           {
              elm_layout_content_set(wd->content_area, "elm.swallow.content", wd->content);
           }
         elm_layout_content_set(wd->layout, "elm.swallow.content", wd->content_area);
-     }     
-   if(wd->title_area)
+     }
+   if (wd->title_area)
      {
         edje_object_part_text_set(elm_layout_edje_get(wd->layout), "elm.swallow.title", wd->title_area);
      }
@@ -174,22 +148,26 @@ _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
    _sizing_eval(data);
 }
 
-static void 
+static void
 _block_clicked_cb(void *data, Evas_Object *obj, void *event_info)
-{  
-   evas_object_hide((Evas_Object*)data);  
-   evas_object_smart_callback_call((Evas_Object *)data, "response", (void *)ELM_POPUP_RESPONSE_NONE);    
-}
+{
+   Widget_Data *wd = elm_widget_data_get((Evas_Object*)data);
 
-static Ecore_Event_Handler* _elm_wnd_map_handler = NULL;
+   if (wd->mode == ELM_POPUP_TYPE_ALERT)
+     {
+        evas_object_hide((Evas_Object*)data);
+        evas_object_smart_callback_call((Evas_Object *)data, "response", (void *)ELM_POPUP_RESPONSE_NONE);
+     }
+}
 
 static Eina_Bool
 _wnd_map_notify(void *data, int type, void *event)
 {
    Evas* e = NULL;
    Evas_Object* obj = (Evas_Object*)data;
+   Widget_Data *wd = elm_widget_data_get((Evas_Object*)data);
 
-   if (obj && _elm_wnd_map_handler)
+   if (obj && wd->wnd_map_handler)
      {
         e = evas_object_evas_get(obj);
 
@@ -197,8 +175,8 @@ _wnd_map_notify(void *data, int type, void *event)
           {
              /* Render given object again, previous frame was discarded. */
              evas_render(e);
-             ecore_event_handler_del(_elm_wnd_map_handler);
-             _elm_wnd_map_handler = NULL;
+             ecore_event_handler_del(wd->wnd_map_handler);
+             wd->wnd_map_handler = NULL;
              return 1;
           }
      }
@@ -208,17 +186,15 @@ _wnd_map_notify(void *data, int type, void *event)
 
 static void
 _show(void *data, Evas *e, Evas_Object *obj, void *event_info)
-{  
-   Widget_Data *wd = elm_widget_data_get(obj);   
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
 
    if (!wd) return;
-   if (wd->parent) evas_object_show(wd->parent);    
    elm_layout_theme_set(wd->layout, "popup", "base", elm_widget_style_get(obj));
    _sizing_eval(obj);
-   edje_object_signal_emit(elm_layout_edje_get(wd->layout), "elm,state,show", "elm");
-   edje_object_message_signal_process(wd->layout);
-   evas_object_show(obj);     
-   if (e && !_elm_wnd_map_handler)
+   evas_object_show(obj);
+#ifdef HAVE_ELEMENTARY_X
+   if (e && !wd->wnd_map_handler)
      {
         int curr_rmethod = 0;
         int gl_rmethod = 0;
@@ -229,41 +205,40 @@ _show(void *data, Evas *e, Evas_Object *obj, void *event_info)
         if (!curr_rmethod) return;
         if (!gl_rmethod) return;
         if (curr_rmethod == gl_rmethod)
-           _elm_wnd_map_handler = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_SHOW, _wnd_map_notify, obj);
+           wd->wnd_map_handler = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_SHOW, _wnd_map_notify, obj);
      }
+#endif
 }
 
 static void
 _hide(void *data, Evas *e, Evas_Object *obj, void *event_info)
 {
    Widget_Data *wd = elm_widget_data_get(obj);
+
    if (!wd) return;
-   edje_object_signal_emit(elm_layout_edje_get(wd->layout), "elm,state,hide", "elm");
-   edje_object_message_signal_process(wd->layout);
-   if (wd->parent) evas_object_hide(wd->parent);  
-   evas_object_hide(obj); 
+   evas_object_hide(obj);
 }
 
-static void 
+static void
 _action_area_clicked(void *data, Evas_Object *obj, void *event_info)
 {
-   Action_Area_Data *adata = NULL;
-   adata = (Action_Area_Data *)data;
+   Action_Area_Data *adata = data;
 
-   if (!adata) return;  
+   if (!adata) return;
    evas_object_hide(adata->obj);
-   evas_object_smart_callback_call(adata->obj, "response", (void *)adata->response_id);   
+   evas_object_smart_callback_call(adata->obj, "response", (void *)adata->response_id);
 }
 
-static Evas_Object* 
+static Evas_Object*
 _elm_popup_add_button(Evas_Object *obj, const char *text, int response_id)
 {
    char buf[4096];
    Widget_Data *wd = elm_widget_data_get(obj);
    Evas_Object *btn;
+   Action_Area_Data *adata;
 
    if (!wd) return NULL;
-   Action_Area_Data *adata = ELM_NEW(Action_Area_Data); 
+   adata = ELM_NEW(Action_Area_Data);
    btn = elm_button_add(obj);
    snprintf(buf, sizeof(buf), "popup_button/%s", elm_widget_style_get(obj));
    elm_object_style_set(btn, buf);
@@ -272,64 +247,74 @@ _elm_popup_add_button(Evas_Object *obj, const char *text, int response_id)
    adata->obj = obj;
    adata->btn = btn;
    wd->button_list = eina_list_append(wd->button_list, adata);
-   evas_object_smart_callback_add(btn, "clicked", _action_area_clicked, adata);  
+   evas_object_smart_callback_add(btn, "clicked", _action_area_clicked, adata);
    return btn;
 }
 
-static void 
+static void
 _elm_popup_buttons_add_valist(Evas_Object *obj, const char *first_button_text, va_list args)
 {
-   const char *text = NULL; 
+   const char *text = NULL;
    char buf[4096];
    int response = 0;
    int index = 0;
    Evas_Object *btn;
-
-   if (first_button_text == NULL) return;
    Widget_Data *wd = elm_widget_data_get(obj);
+
    if (!wd) return;
-   text = first_button_text;  
+   if (first_button_text == NULL) return;
+   text = first_button_text;
    response = va_arg(args, int);
    while (text != NULL)
      {
         btn = _elm_popup_add_button(obj, text, response);
         ++index;
-        snprintf(buf, sizeof(buf), "actionbtn%d", index);           
+        snprintf(buf, sizeof(buf), "actionbtn%d", index);
         elm_layout_content_set(wd->action_area, buf, btn);
         evas_object_event_callback_add(wd->action_area, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
                                        _changed_size_hints, obj);
         text = va_arg(args, char*);
         if (text == NULL) break;
         response = va_arg(args, int);
-     }      
+     }
 }
 
-static void 
+static void
 _elm_popup_timeout(void *data, Evas_Object *obj, void *event_info)
-{  
-       evas_object_hide((Evas_Object*)data);  
-       evas_object_smart_callback_call((Evas_Object *)data, "response", (void *)ELM_POPUP_RESPONSE_TIMEOUT);    
+{
+   evas_object_hide((Evas_Object*)data);
+   evas_object_smart_callback_call((Evas_Object *)data, "response", (void *)ELM_POPUP_RESPONSE_TIMEOUT);
 }
 
 static Eina_Bool
 _elm_signal_exit(void *data __UNUSED__, int ev_type __UNUSED__, void *ev __UNUSED__)
 {
    int res_id  =  ELM_POPUP_RESPONSE_NONE;
-   int *id = (int *)data;
+   int *id = data;
    *id = res_id;
    ecore_main_loop_quit();
    return EINA_TRUE;
 }
 
-static void 
+static void
 response_cb(void *data, Evas_Object *obj, void *event_info)
 {
-   int res_id = (int) event_info;
-   int *id = (int *)data;
+   int res_id = event_info;
+   int *id = data;
+
    *id = res_id;
    ecore_main_loop_quit();
 }
 
+static void
+_mirrored_set(Evas_Object *obj, Eina_Bool rtl)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+
+   if (!wd) return;
+   elm_object_mirrored_set(wd->notify, rtl);
+}
+
 /**
  * Add a new Popup object.
  *
@@ -339,52 +324,26 @@ response_cb(void *data, Evas_Object *obj, void *event_info)
  * @ingroup Popup
  */
 EAPI Evas_Object *
-elm_popup_add(Evas_Object *parent_app)
+elm_popup_add(Evas_Object *parent)
 {
    Evas_Object *obj;
    Evas *e;
    Widget_Data *wd;
-   Evas_Object *parent;
-   Evas_Coord x,y,w,h;
-   int rotation = -1;
-   int count;
-   unsigned char *prop_data = NULL;
-   int ret;
+#ifdef HAVE_ELEMENTARY_X
    Ecore_X_Window_Type type;
-   if (!parent_app)
-     {
-        //FIXME: Keep this window always on top
-        parent = elm_win_add(parent_app, "popup", ELM_WIN_DIALOG_BASIC);
-        elm_win_borderless_set(parent, EINA_TRUE);
-        elm_win_alpha_set(parent, EINA_TRUE);
-        elm_win_raise(parent);  
-        ecore_x_window_geometry_get(ecore_x_window_root_get(ecore_x_window_focus_get()), &x, &y, &w, &h);
-        ret  = ecore_x_window_prop_property_get(ecore_x_window_root_get(ecore_x_window_focus_get()), ECORE_X_ATOM_E_ILLUME_ROTATE_ROOT_ANGLE, 
-                                                ECORE_X_ATOM_CARDINAL, 32, &prop_data, &count);
-        if (ret && prop_data) memcpy(&rotation, prop_data, sizeof(int));
-        if (prop_data) free(prop_data);
-        evas_object_resize(parent, w, h);
-        evas_object_move(parent, x, y);
-        if (rotation != -1) 
-           elm_win_rotation_with_resize_set(parent, rotation);    
+#endif
 
-     }
-   else
-      parent = parent_app;
-
-   wd = ELM_NEW(Widget_Data);
-   e = evas_object_evas_get(parent);
-   obj = elm_widget_add(e);
+   ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
    ELM_SET_WIDTYPE(widtype, "popup");
-   elm_widget_type_set(obj, "popup");
+   elm_widget_type_set(obj, widtype);
+   elm_widget_can_focus_set(obj, EINA_FALSE);
    elm_widget_sub_object_add(parent, obj);
    elm_widget_data_set(obj, wd);
    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
    elm_widget_del_hook_set(obj, _del_hook);
    elm_widget_theme_hook_set(obj, _theme_hook);
-   elm_widget_can_focus_set(obj, EINA_FALSE);
 
-   wd->notify = elm_notify_add(parent);    
+   wd->notify = elm_notify_add(parent);
    elm_widget_sub_object_add(obj, wd->notify);
    elm_widget_resize_object_set(obj, wd->notify);
    elm_notify_orient_set(wd->notify, ELM_NOTIFY_ORIENT_CENTER);
@@ -402,19 +361,15 @@ elm_popup_add(Evas_Object *parent_app)
 
    evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _show, NULL);
    evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _hide, NULL);
-   wd->rot_angle = rotation;
-   if (!parent_app)
-     {
-        wd->parent = parent;
-        elm_object_style_set(wd->notify, "popup");
-        evas_object_event_callback_add(parent, EVAS_CALLBACK_DEL, _del_parent, obj);
-     }
-
-   ecore_x_netwm_window_type_get(elm_win_xwindow_get(parent), &type);    
+   wd->mode = ELM_POPUP_TYPE_NONE;
+   evas_object_smart_callback_add(wd->notify, "block,clicked", _block_clicked_cb, obj);
+#ifdef HAVE_ELEMENTARY_X
+   ecore_x_netwm_window_type_get(elm_win_xwindow_get(parent), &type);
    if (type == ECORE_X_WINDOW_TYPE_DIALOG)
      {
         elm_object_style_set(wd->notify, "popup");
      }
+#endif
    _sizing_eval(obj);
 
    return obj;
@@ -437,10 +392,12 @@ EAPI Evas_Object *
 elm_popup_with_buttons_add(Evas_Object *parent, const char *title, const char *desc_text,int no_of_buttons, const char *first_button_text, ...)
 {
    Evas_Object *popup;
-   popup = elm_popup_add(parent);
-   Widget_Data *wd = elm_widget_data_get(popup);
    char buf[4096];
+   Widget_Data *wd;
 
+   EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
+   popup = elm_popup_add(parent);
+   wd = elm_widget_data_get(popup);
    if (desc_text)
      {
         elm_popup_desc_set(popup, desc_text);
@@ -451,8 +408,8 @@ elm_popup_with_buttons_add(Evas_Object *parent, const char *title, const char *d
      }
    if (first_button_text)
      {
-        va_list args;  
-        va_start(args, first_button_text); 
+        va_list args;
+        va_start(args, first_button_text);
         wd->action_area = elm_layout_add(popup);
         elm_layout_content_set(wd->layout, "elm.swallow.buttonArea", wd->action_area);
         snprintf(buf,sizeof(buf), "buttons%d", no_of_buttons);
@@ -469,7 +426,7 @@ elm_popup_with_buttons_add(Evas_Object *parent, const char *title, const char *d
    edje_object_message_signal_process(wd->layout);
    _sizing_eval(popup);
 
-   return popup;   
+   return popup;
 }
 
 
@@ -481,11 +438,11 @@ elm_popup_with_buttons_add(Evas_Object *parent, const char *title, const char *d
  *
  * @ingroup Popup
  */
-EAPI void 
+EAPI void
 elm_popup_desc_set(Evas_Object *obj, const char *text)
 {
    ELM_CHECK_WIDTYPE(obj, widtype);
-   Widget_Data *wd = elm_widget_data_get(obj);     
+   Widget_Data *wd = elm_widget_data_get(obj);
    char buf[4096];
 
    if (!wd) return;
@@ -493,7 +450,7 @@ elm_popup_desc_set(Evas_Object *obj, const char *text)
      {
         evas_object_del(wd->content_area);
         wd->content_area = NULL;
-     }  
+     }
    wd->content_area = elm_layout_add(obj);
    elm_layout_theme_set(wd->content_area, "popup", "content", elm_widget_style_get(obj));
    wd->desc_label = elm_label_add(obj);
@@ -503,9 +460,9 @@ elm_popup_desc_set(Evas_Object *obj, const char *text)
    elm_label_label_set(wd->desc_label, text);
    evas_object_size_hint_weight_set(wd->desc_label, EVAS_HINT_EXPAND, 0.0);
    evas_object_size_hint_align_set(wd->desc_label, EVAS_HINT_FILL, EVAS_HINT_FILL);
-   evas_object_show(wd->desc_label);      
-   elm_layout_content_set(wd->content_area, "elm.swallow.content", wd->desc_label);    
-   elm_layout_content_set(wd->layout, "elm.swallow.content", wd->content_area);        
+   evas_object_show(wd->desc_label);
+   elm_layout_content_set(wd->content_area, "elm.swallow.content", wd->desc_label);
+   elm_layout_content_set(wd->layout, "elm.swallow.content", wd->content_area);
    evas_object_event_callback_add(wd->content_area, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
                                   _changed_size_hints, obj);
    _sizing_eval(obj);
@@ -519,7 +476,7 @@ elm_popup_desc_set(Evas_Object *obj, const char *text)
  *
  * @ingroup Popup
  */
-EAPI const char* 
+EAPI const char*
 elm_popup_desc_get(Evas_Object *obj)
 {
    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
@@ -537,7 +494,7 @@ elm_popup_desc_get(Evas_Object *obj)
  *
  * @ingroup Popup
  */
-EAPI void 
+EAPI void
 elm_popup_title_label_set(Evas_Object *obj, const char *text)
 {
    ELM_CHECK_WIDTYPE(obj, widtype);
@@ -563,7 +520,7 @@ elm_popup_title_label_set(Evas_Object *obj, const char *text)
  *
  * @ingroup Popup
  */
-EAPI const char* 
+EAPI const char*
 elm_popup_title_label_get(Evas_Object *obj)
 {
    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
@@ -581,7 +538,7 @@ elm_popup_title_label_get(Evas_Object *obj)
  *
  * @ingroup Popup
  */
-EAPI void 
+EAPI void
 elm_popup_title_icon_set(Evas_Object *obj, Evas_Object *icon)
 {
    ELM_CHECK_WIDTYPE(obj, widtype);
@@ -593,9 +550,9 @@ elm_popup_title_icon_set(Evas_Object *obj, Evas_Object *icon)
         evas_object_del(wd->title_icon);
         wd->title_icon = NULL;
      }
-   wd->title_icon = icon;   
-   elm_layout_content_set(wd->layout, "elm.swallow.title.icon", wd->title_icon);    
-   edje_object_signal_emit(elm_layout_edje_get(wd->layout), "elm,state,title,icon,visible", "elm");   
+   wd->title_icon = icon;
+   elm_layout_content_set(wd->layout, "elm.swallow.title.icon", wd->title_icon);
+   edje_object_signal_emit(elm_layout_edje_get(wd->layout), "elm,state,title,icon,visible", "elm");
    edje_object_message_signal_process(wd->layout);
    _sizing_eval(obj);
 }
@@ -608,7 +565,7 @@ elm_popup_title_icon_set(Evas_Object *obj, Evas_Object *icon)
  *
  * @ingroup Popup
  */
-EAPI Evas_Object* 
+EAPI Evas_Object*
 elm_popup_title_icon_get(Evas_Object *obj)
 {
    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
@@ -626,26 +583,26 @@ elm_popup_title_icon_get(Evas_Object *obj)
  *
  * @ingroup Popup
  */
-EAPI void 
+EAPI void
 elm_popup_content_set(Evas_Object *obj, Evas_Object *content)
 {
    ELM_CHECK_WIDTYPE(obj, widtype);
-   Widget_Data *wd = elm_widget_data_get(obj);  
-   
+   Widget_Data *wd = elm_widget_data_get(obj);
+
    if (!wd) return;
    if (wd->content == content) return;
    if (wd->content_area)
      {
         evas_object_del(wd->content_area);
         wd->content_area = NULL;
-     }        
+     }
    wd->content = content;
-   if(content)
+   if (content)
      {
         wd->content_area = elm_layout_add(obj);
         elm_layout_theme_set(wd->content_area, "popup","content", elm_widget_style_get(obj));
-        elm_layout_content_set(wd->content_area, "elm.swallow.content", content);     
-        elm_layout_content_set(wd->layout, "elm.swallow.content", wd->content_area);     
+        elm_layout_content_set(wd->content_area, "elm.swallow.content", content);
+        elm_layout_content_set(wd->layout, "elm.swallow.content", wd->content_area);
         evas_object_event_callback_add(wd->content_area, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
                                        _changed_size_hints, obj);
      }
@@ -665,7 +622,7 @@ elm_popup_content_get(Evas_Object *obj)
 {
    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
    Widget_Data *wd = elm_widget_data_get(obj);
-   
+
    if (!wd) return NULL;
    return wd->content;
 }
@@ -679,16 +636,16 @@ elm_popup_content_get(Evas_Object *obj)
  * @param[in] Varargs  Response ID(Elm_Popup_Response/ any integer value) for first button, then additional buttons along with their response id ending with NULL.
  * @ingroup Popup
  */
-EAPI void 
+EAPI void
 elm_popup_buttons_add(Evas_Object *obj,int no_of_buttons, const char *first_button_text,  ...)
 {
    ELM_CHECK_WIDTYPE(obj, widtype);
-   Widget_Data *wd = elm_widget_data_get(obj);  
-   char buf[4096];  
-   va_list args;  
-   
+   Widget_Data *wd = elm_widget_data_get(obj);
+   char buf[4096];
+   va_list args;
+
    if (!wd) return;
-   va_start(args, first_button_text); 
+   va_start(args, first_button_text);
    if (wd->action_area)
      {
         evas_object_del(wd->action_area);
@@ -698,8 +655,8 @@ elm_popup_buttons_add(Evas_Object *obj,int no_of_buttons, const char *first_butt
    elm_layout_content_set(wd->layout, "elm.swallow.buttonArea", wd->action_area);
    evas_object_size_hint_weight_set(wd->action_area, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
    evas_object_size_hint_align_set(wd->action_area, EVAS_HINT_FILL, EVAS_HINT_FILL);
-   snprintf(buf, sizeof(buf), "buttons%d", no_of_buttons);  
-   elm_layout_theme_set(wd->action_area, "popup", buf, elm_widget_style_get(obj));     
+   snprintf(buf, sizeof(buf), "buttons%d", no_of_buttons);
+   elm_layout_theme_set(wd->action_area, "popup", buf, elm_widget_style_get(obj));
    wd->no_of_buttons = no_of_buttons;
    edje_object_signal_emit(elm_layout_edje_get(wd->layout), "elm,state,button,visible", "elm");
    if (wd->title_area)
@@ -711,7 +668,7 @@ elm_popup_buttons_add(Evas_Object *obj,int no_of_buttons, const char *first_butt
 }
 
 /**
- * This Set's the time before the popup window is hidden, 
+ * This Set's the time before the popup window is hidden,
  * and ELM_POPUP_RESPONSE_TIMEOUT is sent along with response signal.
  *
  * @param[in] obj The popup object
@@ -719,19 +676,19 @@ elm_popup_buttons_add(Evas_Object *obj,int no_of_buttons, const char *first_butt
  *
  * @ingroup Popup
  */
-EAPI void 
+EAPI void
 elm_popup_timeout_set(Evas_Object *obj, double timeout)
-{  
+{
    ELM_CHECK_WIDTYPE(obj, widtype);
    Widget_Data *wd = elm_widget_data_get(obj);
-   
-   if (!wd) return;  
+
+   if (!wd) return;
    elm_notify_timeout_set(wd->notify, timeout);
    evas_object_smart_callback_add(wd->notify, "timeout", _elm_popup_timeout, obj);
 }
 
 /**
- * This Set's the mode of popup, by default ELM_POPUP_TYPE_NONE is set i.e, popup  
+ * This Set's the mode of popup, by default ELM_POPUP_TYPE_NONE is set i.e, popup
  * will not close when clicked outside. if ELM_POPUP_TYPE_ALERT is set, popup will close
  * when clicked outside, and ELM_POPUP_RESPONSE_NONE is sent along with response signal.
  *
@@ -740,17 +697,15 @@ elm_popup_timeout_set(Evas_Object *obj, double timeout)
  *
  * @ingroup Popup
  */
-EAPI void 
+EAPI void
 elm_popup_mode_set(Evas_Object *obj, Elm_Popup_Mode mode)
 {
    ELM_CHECK_WIDTYPE(obj, widtype);
    Widget_Data *wd = elm_widget_data_get(obj);
 
-   if (!wd) return; 
-   if (mode == ELM_POPUP_TYPE_ALERT)
-      evas_object_smart_callback_add(wd->notify, "block,clicked", _block_clicked_cb, obj);
-   else
-      evas_object_smart_callback_del(wd->notify, "block,clicked", _block_clicked_cb);
+   if (!wd) return;
+   if (mode == wd->mode) return;
+   wd->mode = mode;
 }
 
 /**
@@ -760,16 +715,16 @@ elm_popup_mode_set(Evas_Object *obj, Elm_Popup_Mode mode)
  * @param[in] response_id  response ID of the signal to be emitted along with response signal
  *
  * @ingroup Popup
- */ 
-EAPI void 
+ */
+EAPI void
 elm_popup_response(Evas_Object *obj, int  response_id)
 {
    ELM_CHECK_WIDTYPE(obj, widtype);
    Widget_Data *wd = elm_widget_data_get(obj);
 
-   if (!wd) return;  
-   evas_object_hide(obj);  
-   evas_object_smart_callback_call((Evas_Object *)obj, "response", (void *)response_id);  
+   if (!wd) return;
+   evas_object_hide(obj);
+   evas_object_smart_callback_call((Evas_Object *)obj, "response", (void *)response_id);
 }
 
 /**
@@ -779,7 +734,7 @@ elm_popup_response(Evas_Object *obj, int  response_id)
  *
  * @ingroup Popup
  */
-EAPI void 
+EAPI void
 elm_popup_orient_set(Evas_Object *obj, Elm_Popup_Orient orient)
 {
    ELM_CHECK_WIDTYPE(obj, widtype);
@@ -826,7 +781,7 @@ elm_popup_orient_set(Evas_Object *obj, Elm_Popup_Orient orient)
  * to exit signal, when exit signal is received dialog responds with ELM_POPUP_RESPONSE_NONE
  * response ID else returns the response ID from response signal emission.
  * before entering the main loop popup calls evas_object_show on the popup for you.
- * you can force popup to return at any time by calling elm_popup_responsec to emit the 
+ * you can force popup to return at any time by calling elm_popup_responsec to emit the
  * response signal. destroying the popup during elm_popup_run is a very bad idea.
  * typical usage of this function may be
  * int result = elm_popup_run(popup);
@@ -848,25 +803,26 @@ elm_popup_orient_set(Evas_Object *obj, Elm_Popup_Orient orient)
  * do not run elm_popup_run in a timer/idler callback.
  * when popup returns with signal ELM_POPUP_RESPONSE_NONE, then exit the application using elm_exit
  * by calling any post exit application code.
- * 
+ *
  * @param[in] obj The popup object
  * @ingroup Popup
  */
-EAPI int 
+EAPI int
 elm_popup_run(Evas_Object *obj)
 {
    int response_id=0;
    Ecore_Event_Handler *_elm_exit_handler = NULL;
+
    /*Finger waggle warning*/
    _elm_dangerous_call_check(__FUNCTION__);
    evas_object_show(obj);
-   evas_object_smart_callback_add(obj, "response", response_cb, &response_id);  
+   evas_object_smart_callback_add(obj, "response", response_cb, &response_id);
    _elm_exit_handler = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, _elm_signal_exit, &response_id);
    ecore_main_loop_begin();
    if (_elm_exit_handler)
      {
         ecore_event_handler_del(_elm_exit_handler);
-        _elm_exit_handler = NULL; 
+        _elm_exit_handler = NULL;
      }
    return response_id;
 }