Enlightenment CVS committal

Author  : pfritz
Project : e17
Module  : libs/ewl

Dir     : e17/libs/ewl/src/lib


Modified Files:
        ewl_text.c ewl_entry.c ewl_text.h 


Log Message:
improve the utf-8 support of the entry

===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_text.c,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -3 -r1.104 -r1.105
--- ewl_text.c  26 May 2006 19:58:00 -0000      1.104
+++ ewl_text.c  10 Jun 2006 16:52:06 -0000      1.105
@@ -2974,6 +2974,43 @@
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
 
+unsigned int
+ewl_text_utf_char_position_next(const char *text, unsigned int pos)
+{
+       const unsigned char *t;
+
+       t = text;
+
+       if (!text) {
+               DRETURN_INT(0, DLEVEL_STABLE);
+       }
+       
+       do {
+               pos++;
+       }
+       while (t[pos] >= 0x80 && t[pos] <= 0xbf);
+
+       DRETURN_INT(pos, DLEVEL_STABLE);
+}
+
+unsigned int
+ewl_text_utf_char_position_prev(const char *text, unsigned int pos)
+{
+       const unsigned char *t;
+
+       t = text;
+
+       if (!text)
+               DRETURN_INT(0, DLEVEL_STABLE);
+       
+       do {
+               pos--;
+       }
+       while (t[pos] >= 0x80 && t[pos] <= 0xbf && pos > 0);
+
+       DRETURN_INT(pos, DLEVEL_STABLE);
+}
+
 /*
  * Trigger stuff 
  */
===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_entry.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -3 -r1.59 -r1.60
--- ewl_entry.c 10 Jun 2006 04:06:53 -0000      1.59
+++ ewl_entry.c 10 Jun 2006 16:52:06 -0000      1.60
@@ -539,7 +539,9 @@
        if (pos == 0)
                DRETURN(DLEVEL_STABLE);
 
-       ewl_entry_cursor_position_set(EWL_ENTRY_CURSOR(e->cursor), pos - 1);
+       pos = ewl_text_utf_char_position_prev(EWL_TEXT(e)->text, pos);
+       
+       ewl_entry_cursor_position_set(EWL_ENTRY_CURSOR(e->cursor), pos);
        ewl_widget_configure(EWL_WIDGET(e));
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
@@ -565,7 +567,8 @@
        if (pos == ewl_text_length_get(EWL_TEXT(e)))
                DRETURN(DLEVEL_STABLE);
 
-       ewl_entry_cursor_position_set(EWL_ENTRY_CURSOR(e->cursor), pos + 1);
+       pos = ewl_text_utf_char_position_next(EWL_TEXT(e)->text, pos);
+       ewl_entry_cursor_position_set(EWL_ENTRY_CURSOR(e->cursor), pos);
        ewl_widget_configure(EWL_WIDGET(e));
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
@@ -621,13 +624,16 @@
 void
 ewl_entry_delete_left(Ewl_Entry *e)
 {
+       int pos1, pos2;
+       
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR("e", e);
        DCHECK_TYPE("e", e, EWL_ENTRY_TYPE);
 
-       ewl_entry_cursor_position_set(EWL_ENTRY_CURSOR(e->cursor),
-               ewl_entry_cursor_position_get(EWL_ENTRY_CURSOR(e->cursor)) - 1);
-       ewl_text_text_delete(EWL_TEXT(e), 1);
+       pos1 = ewl_entry_cursor_position_get(EWL_ENTRY_CURSOR(e->cursor));
+       pos2 = ewl_text_utf_char_position_prev(EWL_TEXT(e)->text, pos1);
+       ewl_entry_cursor_position_set(EWL_ENTRY_CURSOR(e->cursor), pos2);
+       ewl_text_text_delete(EWL_TEXT(e), pos1 - pos2);
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
@@ -640,11 +646,15 @@
 void
 ewl_entry_delete_right(Ewl_Entry *e)
 {
+       int pos1, pos2;
+       
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR("e", e);
        DCHECK_TYPE("e", e, EWL_ENTRY_TYPE);
 
-       ewl_text_text_delete(EWL_TEXT(e), 1);
+       pos1 = ewl_entry_cursor_position_get(EWL_ENTRY_CURSOR(e->cursor));
+       pos2 = ewl_text_utf_char_position_next(EWL_TEXT(e)->text, pos1);
+       ewl_text_text_delete(EWL_TEXT(e), pos2 - pos1);
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_text.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -3 -r1.37 -r1.38
--- ewl_text.h  8 May 2006 18:31:51 -0000       1.37
+++ ewl_text.h  10 Jun 2006 16:52:06 -0000      1.38
@@ -241,6 +241,9 @@
                                                        unsigned int *b, 
unsigned int *a,
                                                        unsigned int idx);
 
+unsigned int    ewl_text_utf_char_position_next(const char *text, unsigned int 
pos);
+unsigned int    ewl_text_utf_char_position_prev(const char *text, unsigned int 
pos);
+
 /**
  * Inherits from Ewl_Widget and extends to provide a trigger for the text
  * widget




_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to