Dear all EFL developers,

This is patch for supporting autoperiod feature in entry widget.
Autoperiod is the feature that period (.) will be automatically added 
when space bar is pressed twice in a short time.

As you know, this feature can be seen in the blackberry, iphone, and so on.

You can test this feature according to the below step:
1. run elementary_test
2. Click 'Entry 5'
3. Click 'Autoperiod' button.
4. Type 'I love EFL'
5. Press space twice in a short time (within 0.6sec)

Would you please review this patch and apply in svn if it is ok?

Thanks.
Index: src/lib/edje_private.h
===================================================================
--- src/lib/edje_private.h      (리비전 57076)
+++ src/lib/edje_private.h      (작업 사본)
@@ -368,6 +368,7 @@ typedef struct _Edje_Part_Box_Animation
 #define EDJE_ORIENTATION_AUTO  0
 #define EDJE_ORIENTATION_LTR   1
 #define EDJE_ORIENTATION_RTL   2
+#define EDJE_ENTRY_DOUBLE_SPACE_TIME 0.6
 
 #define EDJE_PART_PATH_SEPARATOR ':'
 #define EDJE_PART_PATH_SEPARATOR_STRING ":"
@@ -1776,7 +1777,8 @@ Eina_Bool _edje_entry_cursor_coord_set(Edje_Real_P
 Eina_Bool _edje_entry_cursor_is_format_get(Edje_Real_Part *rp, Edje_Cursor 
cur);
 Eina_Bool _edje_entry_cursor_is_visible_format_get(Edje_Real_Part *rp, 
Edje_Cursor cur);
 const char *_edje_entry_cursor_content_get(Edje_Real_Part *rp, Edje_Cursor 
cur);
-    
+void _edje_entry_autoperiod_set(Edje_Real_Part *rp, Eina_Bool autoperiod);
+
 void _edje_external_init();
 void _edje_external_shutdown();
 Evas_Object *_edje_external_type_add(const char *type_name, Evas *evas, 
Evas_Object *parent, const Eina_List *params, const char *part_name);
Index: src/lib/edje_util.c
===================================================================
--- src/lib/edje_util.c (리비전 57076)
+++ src/lib/edje_util.c (작업 사본)
@@ -1913,6 +1913,31 @@ edje_object_part_text_select_extend(const Evas_Obj
 }
 
 /**
+ * @brief Enables autoperiod feature
+ * Autoperiod is the feature that period (.) will be automatically added when 
space bar is pressed twice in a short time.
+ *
+ * @param obj A valid Evas_Object handle
+ * @param part The part name
+ * @param autoperiod EINA_TRUE to enable, EINA_FALSE otherwise
+ * @since 1.1.0
+ */
+EAPI void
+edje_object_part_text_autoperiod_set(const Evas_Object *obj, const char *part, 
Eina_Bool autoperiod)
+{
+   Edje *ed;
+   Edje_Real_Part *rp;
+
+   ed = _edje_fetch(obj);
+   if ((!ed) || (!part)) return;
+   rp = _edje_real_part_recursive_get(ed, (char *)part);
+   if (!rp) return;
+   if (rp->part->entry_mode > EDJE_ENTRY_EDIT_MODE_NONE)
+     {
+        _edje_entry_autoperiod_set(rp, autoperiod);
+     }
+}
+
+/**
  * @brief XX
  *
  * @param obj A valid Evas_Object handle
Index: src/lib/Edje.h
===================================================================
--- src/lib/Edje.h      (리비전 57076)
+++ src/lib/Edje.h      (작업 사본)
@@ -608,6 +608,7 @@ typedef Evas_Object *(*Edje_Item_Provider_Cb)   (v
    EAPI Eina_Bool        edje_object_part_text_cursor_is_format_get        
(const Evas_Object *obj, const char *part, Edje_Cursor cur);
    EAPI Eina_Bool        
edje_object_part_text_cursor_is_visible_format_get(const Evas_Object *obj, 
const char *part, Edje_Cursor cur);
    EAPI const char      *edje_object_part_text_cursor_content_get          
(const Evas_Object *obj, const char *part, Edje_Cursor cur);
+   EAPI void             edje_object_part_text_autoperiod_set              
(const Evas_Object *obj, const char *part, Eina_Bool autoperiod);
 
    EAPI void             edje_object_text_insert_filter_callback_add       
(Evas_Object *obj, const char *part, Edje_Text_Filter_Cb func, void *data);
    EAPI void            *edje_object_text_insert_filter_callback_del       
(Evas_Object *obj, const char *part, Edje_Text_Filter_Cb func);
Index: src/lib/edje_entry.c
===================================================================
--- src/lib/edje_entry.c        (리비전 57076)
+++ src/lib/edje_entry.c        (작업 사본)
@@ -1,7 +1,6 @@
 #include "edje_private.h"
 
 #ifdef HAVE_ECORE_IMF
-
 static Eina_Bool _edje_entry_imf_retrieve_surrounding_cb(void *data, 
Ecore_IMF_Context *ctx, char **text, int *cursor_pos);
 static Eina_Bool _edje_entry_imf_event_commit_cb(void *data, int type, void 
*event);
 static Eina_Bool _edje_entry_imf_event_preedit_changed_cb(void *data, int 
type, void *event);
@@ -33,6 +32,8 @@ struct _Entry
    Eina_Bool select_mod_start : 1;
    Eina_Bool select_mod_end : 1;
    Eina_Bool had_sel : 1;
+   Eina_Bool autoperiod : 1;
+   double space_key_time;
 
 #ifdef HAVE_ECORE_IMF
    Eina_Bool have_preedit : 1;
@@ -41,7 +42,7 @@ struct _Entry
    Ecore_Event_Handler *imf_ee_handler_commit;
    Ecore_Event_Handler *imf_ee_handler_delete;
    Ecore_Event_Handler *imf_ee_handler_changed;
-#endif   
+#endif
 };
 
 struct _Sel
@@ -1002,6 +1003,48 @@ _backspace(Evas_Textblock_Cursor *c, Evas_Object *
 }
 
 static void
+_autoperiod_insert(Entry *en, Evas_Textblock_Cursor *cursor)
+{
+   Evas_Textblock_Cursor *tc = NULL;
+   char *str;
+   unsigned int len = 0;
+
+   if (!en || !en->autoperiod) return;
+
+   if ((ecore_time_get() - en->space_key_time) > EDJE_ENTRY_DOUBLE_SPACE_TIME)
+      goto done;
+
+   tc = evas_object_textblock_cursor_new(en->rp->object);
+   evas_textblock_cursor_copy(cursor, tc);
+
+   if (!evas_textblock_cursor_char_prev(tc)) goto done;
+   if (!evas_textblock_cursor_char_prev(tc)) goto done;
+
+   str = evas_textblock_cursor_range_text_get(tc, cursor,
+                                              EVAS_TEXTBLOCK_TEXT_MARKUP);
+
+   if (!str) goto done;
+
+   len = strlen(str);
+
+   if ((len >= 2) &&
+       ((str[len-2] != ':') && (str[len-2] != ';') &&
+        (str[len-2] != '.') && (str[len-2] != ',') &&
+        (str[0] != '?') && (str[len-2] != '!') &&
+        (str[len-2] != ' ')) && (str[len-1] == ' '))
+     {
+        _backspace(cursor, en->rp->object, en);
+        evas_textblock_cursor_text_prepend(cursor, ".");
+     }
+
+   free(str);
+
+done:
+   if (tc) evas_textblock_cursor_free(tc);
+   en->space_key_time = ecore_time_get();
+}
+
+static void
 _delete(Evas_Textblock_Cursor *c, Evas_Object *o __UNUSED__, Entry *en 
__UNUSED__)
 {
    evas_textblock_cursor_char_delete(c);
@@ -1333,6 +1376,8 @@ _edje_key_down_cb(void *data, Evas *e __UNUSED__,
              if (en->have_selection)
                 _range_del(en->cursor, rp->object, en);
              _sel_clear(en->cursor, rp->object, en);
+
+             if (!strcmp(ev->key, "space")) _autoperiod_insert(en, en->cursor);
              //zz
 //             evas_textblock_cursor_text_prepend(en->cursor, ev->string);
              _text_filter_text_prepend(en, en->cursor, ev->string);
@@ -2274,6 +2319,14 @@ _edje_entry_select_abort(Edje_Real_Part *rp)
      }
 }
 
+void
+_edje_entry_autoperiod_set(Edje_Real_Part *rp, Eina_Bool autoperiod)
+{
+   Entry *en = rp->entry_data;
+   if (!en) return;
+   en->autoperiod = autoperiod;
+}
+
 static Evas_Textblock_Cursor *
 _cursor_get(Edje_Real_Part *rp, Edje_Cursor cur)
 {
Index: src/lib/elm_entry.c
===================================================================
--- src/lib/elm_entry.c (리비전 57076)
+++ src/lib/elm_entry.c (작업 사본)
@@ -136,6 +136,7 @@ struct _Widget_Data
    Eina_Bool can_write : 1;
    Eina_Bool autosave : 1;
    Eina_Bool textonly : 1;
+   Eina_Bool autoperiod : 1;
 };
 
 struct _Elm_Entry_Context_Menu_Item
@@ -547,6 +548,7 @@ _theme_hook(Evas_Object *obj)
       edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
    edje_object_message_signal_process(wd->ent);
    edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * 
_elm_config->scale);
+   edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
    _sizing_eval(obj);
 }
 
@@ -1612,6 +1614,7 @@ elm_entry_single_line_set(Evas_Object *obj, Eina_B
    t = eina_stringshare_add(elm_entry_entry_get(obj));
    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), 
elm_widget_style_get(obj));
    elm_entry_entry_set(obj, t);
+   edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
    eina_stringshare_del(t);
    _sizing_eval(obj);
 }
@@ -1659,6 +1662,12 @@ elm_entry_password_set(Evas_Object *obj, Eina_Bool
    t = eina_stringshare_add(elm_entry_entry_get(obj));
    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), 
elm_widget_style_get(obj));
    elm_entry_entry_set(obj, t);
+
+   if (password)
+     {
+        if (wd->autoperiod)
+           elm_entry_autoperiod_set(obj, EINA_FALSE);
+     }
    eina_stringshare_del(t);
    _sizing_eval(obj);
 }
@@ -2878,3 +2887,46 @@ elm_entry_cnp_textonly_get(Evas_Object *obj)
    return wd->textonly;
 }
 
+/**
+ * Set whether entry should support autoperiod.
+ * Autoperiod is the feature that period (.) will be automatically added when 
space bar is pressed twice in a short time.
+ *
+ * @param obj The entry object
+ * @param autoperiod If true, entry suports auto period.
+ *
+ * @ingroup Entry
+ */
+EAPI void
+elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+
+   if (wd->password)
+       wd->autoperiod = EINA_FALSE;
+   else
+       wd->autoperiod = autoperiod;
+
+   edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
+}
+
+/**
+ * Get whether entry should support autoperiod or not.
+ * 
+ * see @ref elm_entry_autoperiod_set for more details.
+ *
+ * @param obj The entry object
+ * @return EINA_TRUE if entry support autoperiod, otherwise EINA_FALSE.
+ *
+ * @ingroup Entry
+ */
+EAPI Eina_Bool
+elm_entry_autoperiod_get(Evas_Object *obj)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return EINA_FALSE;
+
+   return wd->autoperiod;
+}
Index: src/lib/elc_scrolled_entry.c
===================================================================
--- src/lib/elc_scrolled_entry.c        (리비전 57076)
+++ src/lib/elc_scrolled_entry.c        (작업 사본)
@@ -1609,3 +1609,43 @@ elm_scrolled_entry_autosave_get(const Evas_Object
    if (!wd) return EINA_FALSE;
    return elm_entry_autosave_get(wd->entry);
 }
+
+/**
+ * Set whether scrolled entry should support autoperiod.
+ * Autoperiod is the feature that period (.) will be automatically added when 
space bar is pressed twice in a short time.
+ *
+ * @param obj The entry object
+ * @param autoperiod If true, scrolled entry suports auto period.
+ *
+ * @ingroup Scrolled_Entry
+ */
+EAPI void
+elm_scrolled_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd || !wd->entry) return;
+
+   elm_entry_autoperiod_set(wd->entry, autoperiod);
+}
+
+/**
+ * Get whether scrolled entry should support autoperiod or not.
+ *
+ * see @ref elm_scrolled_entry_autoperiod_set for more details.
+ *
+ * @param obj The entry object
+ * @return EINA_TRUE if entry support autoperiod, otherwise EINA_FALSE.
+ *
+ * @ingroup Scrolled_Entry
+ */
+EAPI Eina_Bool
+elm_scrolled_entry_autoperiod_get(Evas_Object *obj)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd || !wd->entry) return EINA_FALSE;
+
+   return elm_entry_autoperiod_get(wd->entry);
+}
+
Index: src/lib/Elementary.h.in
===================================================================
--- src/lib/Elementary.h.in     (리비전 57076)
+++ src/lib/Elementary.h.in     (작업 사본)
@@ -423,7 +423,6 @@ extern "C" {
    EAPI void             elm_object_tree_dump(const Evas_Object *top);
    EAPI void             elm_object_tree_dot_dump(const Evas_Object *top, 
const char *file);
 
-
    /* theme */
    typedef struct _Elm_Theme Elm_Theme;
 
@@ -1236,6 +1235,8 @@ extern "C" {
    EAPI Eina_Bool    elm_entry_autosave_get(const Evas_Object *obj) 
EINA_ARG_NONNULL(1);
    EAPI void         elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool 
textonly) EINA_ARG_NONNULL(1);
    EAPI Eina_Bool    elm_entry_cnp_textonly_get(Evas_Object *obj) 
EINA_ARG_NONNULL(1);
+   EAPI void         elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool 
autoperiod) EINA_ARG_NONNULL(1);
+   EAPI Eina_Bool    elm_entry_autoperiod_get(Evas_Object *obj) 
EINA_ARG_NONNULL(1);
 
    /* pre-made filters for entries */
    typedef struct _Elm_Entry_Filter_Limit_Size Elm_Entry_Filter_Limit_Size;
@@ -2259,6 +2260,8 @@ extern "C" {
    EAPI void         elm_scrolled_entry_file_save(Evas_Object *obj) 
EINA_ARG_NONNULL(1);
    EAPI void         elm_scrolled_entry_autosave_set(Evas_Object *obj, 
Eina_Bool autosave) EINA_ARG_NONNULL(1);
    EAPI Eina_Bool    elm_scrolled_entry_autosave_get(const Evas_Object *obj) 
EINA_ARG_NONNULL(1);
+   EAPI void         elm_scrolled_entry_autoperiod_set(Evas_Object *obj, 
Eina_Bool autoperiod) EINA_ARG_NONNULL(1);
+   EAPI Eina_Bool    elm_scrolled_entry_autoperiod_get(Evas_Object *obj) 
EINA_ARG_NONNULL(1);
 
    /* conformant */
    EAPI Evas_Object *elm_conformant_add(Evas_Object *parent) 
EINA_ARG_NONNULL(1);
Index: src/bin/test_entry.c
===================================================================
--- src/bin/test_entry.c        (리비전 57076)
+++ src/bin/test_entry.c        (작업 사본)
@@ -664,6 +664,21 @@ my_ent_bt_pas(void *data, Evas_Object *obj __UNUSE
    elm_scrolled_entry_selection_paste(en);
 }
 
+static void
+my_ent_bt_autoperiod(void *data, Evas_Object *obj __UNUSED__, void *event_info 
__UNUSED__)
+{
+   Evas_Object *en = data;
+   Eina_Bool autoperiod = elm_scrolled_entry_autoperiod_get(en);
+   autoperiod = !autoperiod;
+
+   if (autoperiod)
+       printf("Turn on autoperiod\n");
+   else
+       printf("Turn off autoperiod\n");
+
+   elm_scrolled_entry_autoperiod_set(en, autoperiod);
+}
+
 void
 test_entry3(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void 
*event_info __UNUSED__)
 {
@@ -1577,6 +1592,16 @@ test_entry5(void *data __UNUSED__, Evas_Object *ob
    elm_object_focus_allow_set(bt, 0);
    evas_object_show(bt);
 
+   bt = elm_button_add(win);
+   elm_button_label_set(bt, "Autoperiod");
+   evas_object_smart_callback_add(bt, "clicked", my_ent_bt_autoperiod, en);
+   evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
+   evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
+   elm_box_pack_end(bx2, bt);
+   evas_object_propagate_events_set(bt, EINA_FALSE);
+   elm_object_focus_allow_set(bt, EINA_FALSE);
+   evas_object_show(bt);
+
    elm_box_pack_end(bx, bx2);
    evas_object_show(bx2);
 
------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to