[entry] fixed bugs in text selection handlers
[framework/uifw/elementary.git] / src / modules / ctxpopup_copypasteUI / copypaste.c
index 340af36..0ad6794 100644 (file)
@@ -20,6 +20,8 @@ struct _Elm_Entry_Context_Menu_Item
 static void
 _ctxpopup_position(Evas_Object *obj)
 {
+   if(!ext_mod) return;
+
    Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
    evas_object_geometry_get(ext_mod->ent, &x, &y, NULL, NULL);
    edje_object_part_text_cursor_geometry_get(ext_mod->ent, "elm.text",
@@ -42,6 +44,8 @@ _ctxpopup_position(Evas_Object *obj)
 static void
 _select_all(void *data, Evas_Object *obj, void *event_info)
 {
+   if(!ext_mod) return;
+
    ext_mod->selectall(data,obj,event_info);
    evas_object_hide(obj);
 }
@@ -49,6 +53,8 @@ _select_all(void *data, Evas_Object *obj, void *event_info)
 static void
 _select(void *data, Evas_Object *obj, void *event_info)
 {
+   if(!ext_mod) return;
+
    ext_mod->select(data,obj,event_info);
    evas_object_hide(obj);
 }
@@ -56,6 +62,8 @@ _select(void *data, Evas_Object *obj, void *event_info)
 static void
 _paste(void *data, Evas_Object *obj, void *event_info)
 {
+   if(!ext_mod) return;
+
    ext_mod->paste(data,obj,event_info);
    evas_object_hide(obj);
 }
@@ -63,6 +71,8 @@ _paste(void *data, Evas_Object *obj, void *event_info)
 static void
 _cut(void *data, Evas_Object *obj, void *event_info)
 {
+   if(!ext_mod) return;
+
    ext_mod->cut(data,obj,event_info);
    evas_object_hide(obj);
    elm_object_scroll_freeze_pop(ext_mod->popup);
@@ -71,6 +81,8 @@ _cut(void *data, Evas_Object *obj, void *event_info)
 static void
 _copy(void *data, Evas_Object *obj, void *event_info)
 {
+   if(!ext_mod) return;
+
    ext_mod->copy(data,obj,event_info);
    evas_object_hide(obj);
    elm_object_scroll_freeze_pop(ext_mod->popup);
@@ -79,6 +91,8 @@ _copy(void *data, Evas_Object *obj, void *event_info)
 static void
 _cancel(void *data, Evas_Object *obj, void *event_info)
 {
+   if(!ext_mod) return;
+
    ext_mod->cancel(data,obj,event_info);
    evas_object_hide(obj);
    elm_object_scroll_freeze_pop(ext_mod->popup);
@@ -87,14 +101,18 @@ _cancel(void *data, Evas_Object *obj, void *event_info)
 static void
 _clipboard_menu(void *data, Evas_Object *obj, void *event_info)
 {
+   if(!ext_mod) return;
+
    // start for cbhm
+#ifdef HAVE_ELEMENTARY_X
    ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
+#endif
    ext_mod->cnpinit(data,obj,event_info);
    elm_cbhm_helper_init(obj);
    if (ext_mod->textonly)
-      elm_cbhm_send_raw_data("show0");
+     elm_cbhm_send_raw_data("show0");
    else
-      elm_cbhm_send_raw_data("show1");
+     elm_cbhm_send_raw_data("show1");
    evas_object_hide(obj);
    // end for cbhm
 }
@@ -109,6 +127,14 @@ _item_clicked(void *data, Evas_Object *obj, void *event_info)
    evas_object_hide(obj);
 }
 
+static void
+_ctxpopup_dismissed_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
+{
+   if (!ext_mod) return;
+
+   elm_object_scroll_freeze_pop(ext_mod->popup);
+}
+
 // module api funcs needed
 EAPI int
 elm_modapi_init(void *m)
@@ -122,11 +148,12 @@ elm_modapi_shutdown(void *m)
    return 1; // succeed always
 }
 
-// module fucns for the specific module type
+// module funcs for the specific module type
 EAPI void
 obj_hook(Evas_Object *obj)
 {
    _mod_hook_count++;
+   //if(_mod_hook_count > 1) return;
 
    if(!ext_mod)
      {
@@ -139,7 +166,6 @@ EAPI void
 obj_unhook(Evas_Object *obj)
 {
    _mod_hook_count--;
-
    if(_mod_hook_count > 0) return;
 
    if(ext_mod)
@@ -151,8 +177,9 @@ obj_unhook(Evas_Object *obj)
 
 EAPI void
 obj_longpress(Evas_Object *obj)
-{      
+{
    if(!ext_mod) return;
+
    Evas_Object *top;
    const Eina_List *l;
    const Elm_Entry_Context_Menu_Item *it;
@@ -168,14 +195,18 @@ obj_longpress(Evas_Object *obj)
         //else elm_widget_scroll_freeze_push(obj);
         top = elm_widget_top_get(obj);
         if(top)
-           ext_mod->popup = elm_ctxpopup_add(top);
+          {
+             ext_mod->popup = elm_ctxpopup_add(top);
+             elm_object_tree_unfocusable_set(ext_mod->popup, EINA_TRUE);
+             evas_object_smart_callback_add(ext_mod->popup, "dismissed", _ctxpopup_dismissed_cb, NULL);
+          }
         /*currently below theme not used,when guideline comes a new theme can be created if required*/
         elm_object_style_set(ext_mod->popup,"extended/entry");
         context_menu_orientation = edje_object_data_get
            (ext_mod->ent, "context_menu_orientation");
         if ((context_menu_orientation) &&
             (!strcmp(context_menu_orientation, "horizontal")))
-           elm_ctxpopup_horizontal_set(ext_mod->popup, EINA_TRUE);
+          elm_ctxpopup_horizontal_set(ext_mod->popup, EINA_TRUE);
 
         elm_widget_sub_object_add(obj, ext_mod->popup);
         if (!ext_mod->selmode)
@@ -191,7 +222,7 @@ obj_longpress(Evas_Object *obj)
              if (1) // need way to detect if someone has a selection
                {
                   if (ext_mod->editable)
-                     elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
+                    elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
                }
              //elm_ctxpopup_item_append(wd->ctxpopup, NULL, "Selectall",_select_all, obj );
              // start for cbhm
@@ -213,9 +244,9 @@ obj_longpress(Evas_Object *obj)
                     {
                        elm_ctxpopup_item_append(ext_mod->popup, "Copy", NULL, _copy, obj );
                        if (ext_mod->editable)
-                          elm_ctxpopup_item_append(ext_mod->popup, "Cut", NULL, _cut, obj );
+                         elm_ctxpopup_item_append(ext_mod->popup, "Cut", NULL, _cut, obj );
                        if (ext_mod->editable)
-                          elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
+                         elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
                     }
                   else
                     {
@@ -228,7 +259,7 @@ obj_longpress(Evas_Object *obj)
                        if (1) // need way to detect if someone has a selection
                          {
                             if (ext_mod->editable)
-                               elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
+                              elm_ctxpopup_item_append(ext_mod->popup, "Paste", NULL, _paste, obj );
                          }
                     }
                   // start for cbhm
@@ -260,28 +291,16 @@ obj_longpress(Evas_Object *obj)
 EAPI void
 obj_mouseup(Evas_Object *obj)
 {
-   if (!obj || !ext_mod) {
-        return;
-   }
-
-   /*update*/
-   elm_entry_extension_module_data_get(obj,ext_mod);
-   if (ext_mod->longpress_timer)
-     {    
-        if (ext_mod->have_selection )
-          {
-             _cancel(obj,ext_mod->popup,NULL);
-          }
-     }     
+   if (!obj || !ext_mod)
+     return;
 }
 
 
 EAPI void
 obj_hidemenu(Evas_Object *obj)
 {
-   if (!obj || !ext_mod) {
-        return;
-   }
+   if (!obj || !ext_mod)
+     return;
 
    evas_object_hide(ext_mod->popup);
    // if (ext_mod->popup) evas_object_del(ext_mod->popup);