Elm entry: Call callbacks for undo/redo,request.
[framework/uifw/elementary.git] / src / lib / elm_entry.c
index 26f5227..b68a6ad 100644 (file)
@@ -19,7 +19,7 @@ typedef struct _Elm_Entry_Text_Filter Elm_Entry_Text_Filter;
 
 struct _Widget_Data
 {
-   Evas_Object *ent, *scroller, *end, *icon;
+   Evas_Object *ent, *scroller;
    Evas_Object *hoversel;
    Ecore_Job *deferred_recalc_job;
    Ecore_Event_Handler *sel_notify_handler;
@@ -47,6 +47,7 @@ struct _Widget_Data
    Elm_Scroller_Policy policy_h, policy_v;
    Elm_Wrap_Type linewrap;
    Elm_Input_Panel_Layout input_panel_layout;
+   Elm_Autocapital_Type autocapital_type;
    Eina_Bool changed : 1;
    Eina_Bool single_line : 1;
    Eina_Bool password : 1;
@@ -64,6 +65,7 @@ struct _Widget_Data
    Eina_Bool textonly : 1;
    Eina_Bool usedown : 1;
    Eina_Bool scroll : 1;
+   Eina_Bool input_panel_enable : 1;
 };
 
 struct _Elm_Entry_Context_Menu_Item
@@ -145,6 +147,8 @@ static const char SIG_ANCHOR_UP[] = "anchor,up";
 static const char SIG_ANCHOR_IN[] = "anchor,in";
 static const char SIG_ANCHOR_OUT[] = "anchor,out";
 static const char SIG_PREEDIT_CHANGED[] = "preedit,changed";
+static const char SIG_UNDO_REQUEST[] = "undo,request";
+static const char SIG_REDO_REQUEST[] = "redo,request";
 static const Evas_Smart_Cb_Description _signals[] = {
        {SIG_CHANGED, ""},
        {SIG_ACTIVATED, ""},
@@ -169,6 +173,8 @@ static const Evas_Smart_Cb_Description _signals[] = {
        {SIG_ANCHOR_OUT, ""},
        {SIG_PREEDIT_CHANGED, ""},
        {SIG_CHANGED_USER, ""},
+       {SIG_UNDO_REQUEST, ""},
+       {SIG_REDO_REQUEST, ""},
        {NULL, NULL}
 };
 
@@ -518,6 +524,8 @@ _theme_hook(Evas_Object *obj)
    if (elm_widget_disabled_get(obj))
      edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
    edje_object_part_text_input_panel_layout_set(wd->ent, "elm.text", wd->input_panel_layout);
+   edje_object_part_text_autocapital_type_set(wd->ent, "elm.text", wd->autocapital_type);
+   edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", wd->input_panel_enable);
    elm_entry_cursor_pos_set(obj, wd->cursor_pos);
    if (elm_widget_focus_get(obj))
      edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
@@ -591,8 +599,9 @@ _elm_deferred_recalc_job(void *data)
 
    evas_object_geometry_get(wd->ent, NULL, NULL, &resw, NULL);
    edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
-   elm_coords_finger_size_adjust(1, &minw, 1, &minh);
-   wd->entmw = minw;
+   edje_object_size_min_restricted_calc(wd->ent, &fw, &fh, 0, 0);
+   elm_coords_finger_size_adjust(1, &fw, 1, &minh);
+   wd->entmw = fw;
    wd->entmh = minh;
    /* This is a hack to workaround the way min size hints are treated.
     * If the minimum width is smaller than the restricted width, it means
@@ -761,14 +770,16 @@ _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
      {
         evas_object_focus_set(wd->ent, EINA_TRUE);
         edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
-        if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
+        if (top && wd->input_panel_enable)
+          elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
         evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
      }
    else
      {
         edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
         evas_object_focus_set(wd->ent, EINA_FALSE);
-        if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
+        if (top && wd->input_panel_enable)
+          elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
         evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
      }
 }
@@ -780,19 +791,24 @@ _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
    Evas_Object *edje;
    if ((!wd) || (!content)) return;
 
-   edje = elm_smart_scroller_edje_object_get(wd->scroller);
+   if (wd->scroll)
+      edje = elm_smart_scroller_edje_object_get(wd->scroller);
+   else
+      edje = wd->ent;
+
+   /* Delete the currently swallowed object */
+     {
+        Evas_Object *cswallow = edje_object_part_swallow_get(edje, part);
+        if (cswallow)
+           evas_object_del(cswallow);
+     }
+
    if (!strcmp(part, "elm.swallow.icon"))
      {
-        if (wd->icon)
-          evas_object_del(wd->icon);
-        wd->icon = content;
         edje_object_signal_emit(edje, "elm,action,show,icon", "elm");
      }
    else if (!strcmp(part, "elm.swallow.end"))
      {
-        if (wd->end)
-          evas_object_del(wd->end);
-        wd->end = content;
         edje_object_signal_emit(edje, "elm,action,show,end", "elm");
      }
    evas_event_freeze(evas_object_evas_get(obj));
@@ -810,15 +826,17 @@ _content_unset_hook(Evas_Object *obj, const char *part)
    Evas_Object *content, *edje;
    if (!wd) return NULL;
 
-   edje = elm_smart_scroller_edje_object_get(wd->scroller);
+   if (wd->scroll)
+      edje = elm_smart_scroller_edje_object_get(wd->scroller);
+   else
+      edje = wd->ent;
+
    if (!strcmp(part, "elm.swallow.icon"))
      {
-        wd->icon = NULL;
         edje_object_signal_emit(edje, "elm,action,hide,icon", "elm");
      }
    else if (!strcmp(part, "elm.swallow.end"))
      {
-        wd->end = NULL;
         edje_object_signal_emit(edje, "elm,action,hide,end", "elm");
      }
 
@@ -842,18 +860,23 @@ _content_get_hook(const Evas_Object *obj, const char *part)
    Evas_Object *content = NULL, *edje;
    if (!wd) return NULL;
 
-   if (!strcmp(part, "elm.swallow.icon"))
-     return wd->icon;
-   if (!strcmp(part, "elm.swallow.end"))
-     return wd->end;
+   if (wd->scroll)
+      edje = elm_smart_scroller_edje_object_get(wd->scroller);
+   else
+      edje = wd->ent;
 
-   edje = elm_smart_scroller_edje_object_get(wd->scroller);
    if (edje)
      content = edje_object_part_swallow_get(edje, part);
    return content;
 }
 
 static void
+_translate_hook(Evas_Object *obj)
+{
+   evas_object_smart_callback_call(obj, "language,changed", NULL);
+}
+
+static void
 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
 {
    Widget_Data *wd = elm_widget_data_get(obj);
@@ -919,16 +942,20 @@ _sub_del(void *data, Evas_Object *obj, void *event_info)
    Evas_Object *sub = event_info;
    Evas_Object *edje;
 
-   edje = elm_smart_scroller_edje_object_get(wd->scroller);
-   if (sub == wd->icon)
+   if (wd->scroll)
+      edje = elm_smart_scroller_edje_object_get(wd->scroller);
+   else
+      edje = wd->ent;
+
+   if (sub == edje_object_part_swallow_get(edje, "elm.swallow.icon"))
      {
-        wd->icon = NULL;
+        edje_object_part_unswallow(edje, sub);
         if (edje)
           edje_object_signal_emit(edje, "elm,action,hide,icon", "elm");
      }
-   else if (sub == wd->end)
+   else if (sub == edje_object_part_swallow_get(edje, "elm.swallow.end"))
      {
-        wd->end = NULL;
+        edje_object_part_unswallow(edje, sub);
         if (edje)
           edje_object_signal_emit(edje, "elm,action,hide,end", "elm");
      }
@@ -1401,7 +1428,6 @@ _entry_changed_common_handling(void *data, const char *event)
    _sizing_eval(data);
    if (wd->text) eina_stringshare_del(wd->text);
    wd->text = NULL;
-   evas_object_smart_callback_call(data, event, NULL);
    if (wd->delay_write)
      {
         ecore_timer_del(wd->delay_write);
@@ -1409,8 +1435,11 @@ _entry_changed_common_handling(void *data, const char *event)
      }
    evas_event_thaw(evas_object_evas_get(data));
    evas_event_thaw_eval(evas_object_evas_get(data));
-   if ((!wd->autosave) || (!wd->file)) return;
-   wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
+   if ((wd->autosave) && (wd->file))
+     wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
+   /* callback - this could call callbacks that delete the entry... thus...
+    * any access to wd after this could be invalid */
+   evas_object_smart_callback_call(data, event, NULL);
 }
 
 static void
@@ -1432,6 +1461,18 @@ _signal_preedit_changed(void *data, Evas_Object *obj __UNUSED__, const char *emi
 }
 
 static void
+_signal_undo_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
+{
+   evas_object_smart_callback_call(data, SIG_UNDO_REQUEST, NULL);
+}
+
+static void
+_signal_redo_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
+{
+   evas_object_smart_callback_call(data, SIG_REDO_REQUEST, NULL);
+}
+
+static void
 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
 {
    Widget_Data *wd = elm_widget_data_get(data);
@@ -2045,11 +2086,16 @@ _elm_entry_text_set(Evas_Object *obj, const char *item, const char *entry)
 {
    int len = 0;
    ELM_CHECK_WIDTYPE(obj, widtype);
-   if (item && strcmp(item, "default")) return;
    Widget_Data *wd = elm_widget_data_get(obj);
    if (!wd) return;
    evas_event_freeze(evas_object_evas_get(obj));
    if (!entry) entry = "";
+   if (item && strcmp(item, "default"))
+     {
+        edje_object_part_text_set(wd->ent, item, entry);
+        return;
+     }
+
    if (wd->text) eina_stringshare_del(wd->text);
    wd->text = NULL;
    wd->changed = EINA_TRUE;
@@ -2159,6 +2205,7 @@ elm_entry_add(Evas_Object *parent)
    elm_widget_content_set_hook_set(obj, _content_set_hook);
    elm_widget_content_unset_hook_set(obj, _content_unset_hook);
    elm_widget_content_get_hook_set(obj, _content_get_hook);
+   elm_widget_translate_hook_set(obj, _translate_hook);
 
    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, wd);
 
@@ -2242,6 +2289,10 @@ elm_entry_add(Evas_Object *parent)
                                    _signal_mouse_double, obj);
    edje_object_signal_callback_add(wd->ent, "mouse,down,1,triple", "elm.text",
                                    _signal_mouse_triple, obj);
+   edje_object_signal_callback_add(wd->ent, "entry,undo,request", "elm.text",
+                                   _signal_undo_request, obj);
+   edje_object_signal_callback_add(wd->ent, "entry,redo,request", "elm.text",
+                                   _signal_redo_request, obj);
    edje_object_part_text_set(wd->ent, "elm.text", "");
    if (_elm_config->desktop_entry)
      edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
@@ -2250,6 +2301,9 @@ elm_entry_add(Evas_Object *parent)
 
    elm_entry_input_panel_layout_set(obj, ELM_INPUT_PANEL_LAYOUT_NORMAL);
 
+   wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
+   wd->autocapital_type = edje_object_part_text_autocapital_type_get(wd->ent, "elm.text");
+
 #ifdef HAVE_ELEMENTARY_X
    top = elm_widget_top_get(obj);
    if ((top) && (elm_win_xwindow_get(top)))
@@ -3140,9 +3194,13 @@ elm_entry_icon_visible_set(Evas_Object *obj, Eina_Bool setting)
    ELM_CHECK_WIDTYPE(obj, widtype);
    Widget_Data *wd = elm_widget_data_get(obj);
    Evas_Object *edje;
-   if ((!wd) || (!wd->icon)) return;
-   edje = elm_smart_scroller_edje_object_get(wd->scroller);
-   if (!edje) return;
+   if (!wd) return;
+   if (wd->scroll)
+      edje = elm_smart_scroller_edje_object_get(wd->scroller);
+   else
+      edje = wd->ent;
+
+   if ((!edje) || (!edje_object_part_swallow_get(edje, "elm.swallow.icon"))) return;
    if (setting)
      edje_object_signal_emit(edje, "elm,action,show,icon", "elm");
    else
@@ -3178,9 +3236,13 @@ elm_entry_end_visible_set(Evas_Object *obj, Eina_Bool setting)
    ELM_CHECK_WIDTYPE(obj, widtype);
    Widget_Data *wd = elm_widget_data_get(obj);
    Evas_Object *edje;
-   if ((!wd) || (!wd->end)) return;
-   edje = elm_smart_scroller_edje_object_get(wd->scroller);
-   if (!edje) return;
+   if (!wd) return;
+   if (wd->scroll)
+      edje = elm_smart_scroller_edje_object_get(wd->scroller);
+   else
+      edje = wd->ent;
+
+   if ((!edje) || (!edje_object_part_swallow_get(edje, "elm.swallow.icon"))) return;
    if (setting)
      edje_object_signal_emit(edje, "elm,action,show,end", "elm");
    else
@@ -3246,3 +3308,36 @@ elm_entry_input_panel_layout_get(Evas_Object *obj)
 
    return wd->input_panel_layout;
 }
+
+EAPI void
+elm_entry_autocapital_type_set(Evas_Object *obj, Elm_Autocapital_Type autocapital_type)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+
+   wd->autocapital_type = autocapital_type;
+   edje_object_part_text_autocapital_type_set(wd->ent, "elm.text", autocapital_type);
+}
+
+EAPI Elm_Autocapital_Type
+elm_entry_autocapital_type_get(Evas_Object *obj)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype) ELM_AUTOCAPITAL_TYPE_NONE;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return ELM_AUTOCAPITAL_TYPE_NONE;
+
+   return wd->autocapital_type;
+}
+
+EAPI void
+elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+
+   wd->input_panel_enable = enabled;
+   edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
+}
+