Enlightenment CVS committal

Author  : rbdpngn
Project : e17
Module  : libs/ewl

Dir     : e17/libs/ewl/src


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


Log Message:
Re-added selection of text in the entry widget. This works for most cases,
except where strange coords are getting reported back from estyle/evas. There
is also a corner case of selections starting after the text, but this should
be a simple fix which I'll take care of after lunch.

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/ewl_cursor.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -3 -r1.11 -r1.12
--- ewl_cursor.c        26 Feb 2003 01:15:23 -0000      1.11
+++ ewl_cursor.c        3 Mar 2003 18:14:21 -0000       1.12
@@ -74,8 +74,8 @@
 }
 
 /**
- * ewl_cursor_get_position - retrieve the position of the cursor
- * @w: the entry cursor to retrieve the current position
+ * ewl_cursor_get_start_position - retrieve the start position of the cursor
+ * @w: the entry cursor to retrieve the current start position
  *
  * Returns the current start position of the cursor widget @w.
  */
@@ -88,8 +88,8 @@
 }
 
 /**
- * ewl_cursor_get_position - retrieve the position of the cursor
- * @w: the entry cursor to retrieve the current position
+ * ewl_cursor_get_end_position - retrieve the end position of the cursor
+ * @w: the entry cursor to retrieve the current end position
  *
  * Returns the current end position of the cursor widget @w.
  */
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/ewl_entry.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -3 -r1.47 -r1.48
--- ewl_entry.c 27 Feb 2003 04:18:49 -0000      1.47
+++ ewl_entry.c 3 Mar 2003 18:14:22 -0000       1.48
@@ -194,7 +194,7 @@
                ewl_text_get_letter_geometry(EWL_TEXT(e->text), --c_spos, &sx,
                                             &sy, NULL, NULL);
 
-               c_epos = ewl_cursor_get_start_position(EWL_CURSOR(e->cursor));
+               c_epos = ewl_cursor_get_end_position(EWL_CURSOR(e->cursor));
                ewl_text_get_letter_geometry(EWL_TEXT(e->text), --c_epos, &ex,
                                             &ey, &ew, &eh);
 
@@ -266,7 +266,9 @@
                                              CURRENT_Y(e->text) +
                                              (CURRENT_H(e->text) / 2));
 
-       ewl_cursor_set_position(EWL_CURSOR(e->cursor), index + 1, index + 1);
+       index++;
+       ewl_cursor_set_position(EWL_CURSOR(e->cursor), index, index);
+       e->base_click = index;
 
        ewl_widget_configure(w);
 
@@ -278,6 +280,8 @@
  */
 void __ewl_entry_mouse_move(Ewl_Widget * w, void *ev_data, void *user_data)
 {
+       int             ss, ee;
+       int             index = 0;
        Ecore_Event_Mouse_Move *ev;
        Ewl_Entry      *e;
 
@@ -290,33 +294,41 @@
        /*
         * Check for the button pressed state, otherwise, do nothing.
         */
-       if (w->state & EWL_STATE_PRESSED) {
-               int             ss, ee;
-               int             index = 0;
-
-               ss = ewl_cursor_get_start_position(EWL_CURSOR(e->cursor));
-               ee = ewl_cursor_get_end_position(EWL_CURSOR(e->cursor));
-
-               /*
-                * FIXME: the correct behavior here is to scroll to the left
-                * or right when selecting text.
-                */
-               if (ev->x < CURRENT_X(e->text))
-                       ss = 1;
-               else if (ev->x > CURRENT_X(e->text) + CURRENT_W(e->text))
-                       ee = ewl_text_get_length(EWL_TEXT(e->text)) + 1;
-               else {
-                       index = ewl_text_get_index_at(EWL_TEXT(e->text), ev->x,
-                                             (CURRENT_Y(e->text) +
-                                              (CURRENT_H(e->text) / 2)));
+       if (!(w->state & EWL_STATE_PRESSED))
+               DRETURN(DLEVEL_STABLE);
 
-                       ee = index - ss;
-               }
+       ss = ewl_cursor_get_start_position(EWL_CURSOR(e->cursor));
+       ee = ewl_cursor_get_end_position(EWL_CURSOR(e->cursor));
 
-               ewl_cursor_set_position(EWL_CURSOR(e->cursor), ss, ee);
+       /*
+        * FIXME: the correct behavior here is to scroll to the left
+        * or right when selecting text.
+        */
+       if (ev->x < CURRENT_X(e->text))
+               index = 0;
+       else if (ev->x > CURRENT_X(e->text) + CURRENT_W(e->text))
+               index = ewl_text_get_length(EWL_TEXT(e->text));
+       else {
+               index = ewl_text_get_index_at(EWL_TEXT(e->text), ev->x,
+                                     (CURRENT_Y(e->text) +
+                                      (CURRENT_H(e->text) / 2)));
+       }
 
-               ewl_widget_configure(w);
+       index++;
+       if (index < e->base_click) {
+               ss = index;
+               ee = e->base_click;
        }
+       else if (index > e->base_click) {
+               ss = e->base_click;
+               ee = index;
+       }
+       else
+               ss = ee = index;
+
+       ewl_cursor_set_position(EWL_CURSOR(e->cursor), ss, ee);
+
+       ewl_widget_configure(w);
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
@@ -444,7 +456,7 @@
 {
        Ewl_Entry      *e;
        char           *s2, *s3;
-       int             l = 0, l2 = 0, p = 0;
+       int             l = 0, l2 = 0, sp = 0, ep = 0;
 
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR("w", w);
@@ -455,24 +467,26 @@
        l = strlen(s);
        l2 = strlen(s2);
 
-       p = ewl_cursor_get_start_position(EWL_CURSOR(e->cursor));
+       sp = ewl_cursor_get_start_position(EWL_CURSOR(e->cursor));
 
        s3 = NEW(char, l + 1 + l2);
 
        s3[0] = 0;
-       strncat(s3, s2, p - 1);
+       strncat(s3, s2, sp - 1);
        strcat(s3, s);
 
-       p = ewl_cursor_get_end_position(EWL_CURSOR(e->cursor));
-       strcat(s3, &(s2[p - 1]));
+       ep = ewl_cursor_get_end_position(EWL_CURSOR(e->cursor));
+       if (sp != ep)
+               ep++;
+       strcat(s3, &(s2[ep - 1]));
 
        ewl_entry_set_text(EWL_ENTRY(w), s3);
 
        FREE(s2);
        FREE(s3);
 
-       p += l;
-       ewl_cursor_set_position(EWL_CURSOR(e->cursor), p, p);
+       sp++;
+       ewl_cursor_set_position(EWL_CURSOR(e->cursor), sp, sp);
        ewl_widget_configure(w);
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
@@ -481,32 +495,34 @@
 void __ewl_entry_delete_to_left(Ewl_Widget * w)
 {
        Ewl_Entry      *e;
-       char           *s, *s2;
-       int             p;
+       char           *s;
+       unsigned int    sp, ep;
 
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR("w", w);
 
        e = EWL_ENTRY(w);
-       p = ewl_cursor_get_start_position(EWL_CURSOR(e->cursor));
-
-       if (p <= 1)
-               DRETURN(DLEVEL_STABLE);
+       sp = ewl_cursor_get_start_position(EWL_CURSOR(e->cursor));
+       ep = ewl_cursor_get_end_position(EWL_CURSOR(e->cursor));
 
-       s2 = ewl_entry_get_text(EWL_ENTRY(w));
-       if (!strlen(s2))
+       s = ewl_entry_get_text(EWL_ENTRY(w));
+       if (!strlen(s) || sp < 2) {
+               FREE(s);
                DRETURN(DLEVEL_STABLE);
+       }
 
-       s = ewl_entry_get_text(EWL_ENTRY(w));
+       if (sp != ep) {
+               sp++;
+               ep++;
+       }
 
-       strcpy(&(s[p - 2]), &(s2[p - 1]));
+       strcpy(&(s[sp - 2]), &(s[ep - 1]));
        ewl_entry_set_text(EWL_ENTRY(w), s);
-       p--;
+       sp--;
 
        FREE(s);
-       FREE(s2);
 
-       ewl_cursor_set_position(EWL_CURSOR(e->cursor), p, p);
+       ewl_cursor_set_position(EWL_CURSOR(e->cursor), sp, sp);
        ewl_widget_configure(w);
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
@@ -515,28 +531,27 @@
 void __ewl_entry_delete_to_right(Ewl_Widget * w)
 {
        Ewl_Entry      *e;
-       char           *s, *s2;
-       int             p;
+       char           *s;
+       int             sp, ep;
 
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR("w", w);
 
        e = EWL_ENTRY(w);
-       p = ewl_cursor_get_end_position(EWL_CURSOR(e->cursor));
+       sp = ewl_cursor_get_start_position(EWL_CURSOR(e->cursor));
+       ep = ewl_cursor_get_end_position(EWL_CURSOR(e->cursor));
 
-       s2 = ewl_entry_get_text(EWL_ENTRY(w));
+       s = ewl_entry_get_text(EWL_ENTRY(w));
 
-       if (!strlen(s2) || p == strlen(s2) + 1)
+       if (!strlen(s) || ep == strlen(s) + 1)
                DRETURN(DLEVEL_STABLE);
 
-       s = ewl_entry_get_text(EWL_ENTRY(w));
-
-       strcpy(&(s[p - 1]), &(s2[p]));
+       strcpy(&(s[sp - 1]), &(s[ep]));
        ewl_entry_set_text(EWL_ENTRY(w), s);
 
        FREE(s);
 
-       ewl_cursor_set_position(EWL_CURSOR(e->cursor), p, p);
+       ewl_cursor_set_position(EWL_CURSOR(e->cursor), sp, sp);
        ewl_widget_configure(w);
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/ewl_entry.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -3 -r1.17 -r1.18
--- ewl_entry.h 26 Feb 2003 01:15:23 -0000      1.17
+++ ewl_entry.h 3 Mar 2003 18:14:22 -0000       1.18
@@ -11,6 +11,8 @@
 
        Ewl_Widget     *text;
        Ewl_Widget     *cursor;
+
+       int             base_click;
 };
 
 Ewl_Widget     *ewl_entry_new(char *text);
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/ewl_object.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -3 -r1.29 -r1.30
--- ewl_object.c        1 Mar 2003 18:34:46 -0000       1.29
+++ ewl_object.c        3 Mar 2003 18:14:22 -0000       1.30
@@ -539,6 +539,12 @@
        if (MAXIMUM_W(o) < w)
                MAXIMUM_W(o) = w;
 
+       /*
+        * Notify the parent widgets of the change in size.
+        */
+       ewl_container_resize_child(EWL_WIDGET(o), 0,
+                                  EWL_ORIENTATION_HORIZONTAL);
+
        if (CURRENT_W(o) < w)
                ewl_object_request_w(o, w);
 
@@ -564,6 +570,12 @@
 
        if (MAXIMUM_H(o) < h)
                MAXIMUM_H(o) = h;
+
+       /*
+        * Notify the parent widgets of the change in size.
+        */
+       ewl_container_resize_child(EWL_WIDGET(o), 0,
+                                  EWL_ORIENTATION_VERTICAL);
 
        if (CURRENT_H(o) < h)
                ewl_object_request_h(o, h);
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/ewl_text.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -3 -r1.45 -r1.46
--- ewl_text.c  26 Feb 2003 01:15:24 -0000      1.45
+++ ewl_text.c  3 Mar 2003 18:14:23 -0000       1.46
@@ -59,8 +59,8 @@
        ewl_object_set_fill_policy(EWL_OBJECT(w), EWL_FILL_POLICY_NONE);
 
        t->text = (text ? strdup(text) : strdup(""));
+       t->length = strlen(t->text);
        t->align = EWL_ALIGNMENT_TOP | EWL_ALIGNMENT_LEFT;
-       t->length = strlen(text);
 
        /*
         * Set up appropriate callbacks for specific events




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to