Enlightenment CVS committal

Author  : rephorm
Project : e17
Module  : libs/etox

Dir     : e17/libs/etox/src


Modified Files:
        etox.c etox_context.c etox_line.c etox_obstacle.c Etox.h 


Log Message:

Added etox_get_length(), which returns what should be the strlen of etox_get_text().

Fixed a bug in etox_get_text(), where it was allocating a buffer of et->length + 1, 
which was too small, since et->length did not include the ending \n's from each line. 
etox_get_length() was implemented to temporarily fix this.

I think a better solution would be to effectively "unwrap" on get_get(). (We don't 
actually have to unwrap the lines, just return text without the \n's before soft 
wrapped lines. Although we need to be careful to increment the buffer pointer by the 
correct amount.)

Added some strdup()'s to the default marker text / style. Otherwise we'd get malloc 
errors on free (segv's with efence compiled in).

Use new estyle type field to determine whether bits are obstacles or wrap markers or 
just normal text. It is no longer assumed that the first non-obstacle bit of a 
soft-wrapped line is a wrap marker. (Now we can eventually add other wrap marker 
positions, such as putting a "-" at the end of the line). Also, we should probably add 
something where wrap markers are positioned in the margins of the text (so the first 
non wrap marker characters all line up on the left side).


===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/etox.c,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -3 -r1.63 -r1.64
--- etox.c      4 Sep 2003 03:05:23 -0000       1.63
+++ etox.c      8 Sep 2003 02:22:58 -0000       1.64
@@ -493,7 +493,12 @@
         */
        if (!et->lines)
                return NULL;
-       ret = (char *) calloc((et->length + 1), sizeof(char));
+
+       /*
+        * etox_get_length() includes the \n's at the end of each line
+        * whereas et->length does not.
+        */
+       ret = (char *) calloc(etox_get_length(obj), sizeof(char));
 
        temp = ret;
 
@@ -503,6 +508,15 @@
        for (l = et->lines; l; l = l->next) {
                line = l->data;
                etox_line_get_text(line, temp);
+
+               /*
+                * FIXME: Currently, in etox_line_get_text(), line->length
+                * is set to the actual length of what gets filled into the
+                * buffer. If this isn't done, then line->length will often
+                * be too long, resulting in an early \0 terminating our 
+                * string.
+                * Is there a better way to do this?
+                */
                temp += line->length;
        }
 
@@ -597,6 +611,25 @@
 }
 
 /**
+ * etox_get_length - get the length of the etox's text
+ * @obj: the etox object
+ *
+ * Returns the length of the text contained in the etox, including the \n's
+ * at the end of each line. (This will match the strlen of etox_get_text()).
+ */
+int
+etox_get_length(Evas_Object *obj)
+{
+       Etox *et;
+
+       CHECK_PARAM_POINTER_RETURN("obj", obj, 0);
+
+       et = evas_object_smart_data_get(obj);
+       return et->length + evas_list_count(et->lines);
+}
+
+
+/**
  * etox_move - move the etox into a new desired position
  * @et: the etox to change position
  * @x: the new x coordinate of the etox
@@ -1261,3 +1294,4 @@
                i++;
        }
 }
+
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/etox_context.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -3 -r1.14 -r1.15
--- etox_context.c      20 Aug 2003 17:37:10 -0000      1.14
+++ etox_context.c      8 Sep 2003 02:22:58 -0000       1.15
@@ -40,8 +40,8 @@
        /*
         * Set up a default blank wrap marker
         */
-       context->marker.text = "+";
-       context->marker.style = "plain";
+       context->marker.text = (char *)strdup("+");
+       context->marker.style = (char *)strdup("plain");
        context->marker.r = 255;
        context->marker.g = 0;
        context->marker.b = 0;
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/etox_line.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -3 -r1.28 -r1.29
--- etox_line.c 4 Sep 2003 03:05:23 -0000       1.28
+++ etox_line.c 8 Sep 2003 02:22:58 -0000       1.29
@@ -360,6 +360,7 @@
        char *temp;
        Evas_Object *es;
        Evas_List *l;
+       int sum = 0;
 
        CHECK_PARAM_POINTER("line", line);
        CHECK_PARAM_POINTER("buf", buf);
@@ -371,13 +372,23 @@
         */
        for (l = line->bits; l; l = l->next) {
                es = l->data;
+
+               sum += estyle_length(es);
+
+               if (estyle_get_type(es) == ETOX_BIT_TYPE_WRAP_MARKER)
+                 continue;
+
                temp = estyle_get_text(es);
-               printf("*** temp:\n%s\n", temp);
                strcat(buf, temp);
-               printf("*** buf:\n%s\n", buf);
                free(temp);
        }
+       line->length = sum;
 
+       /*
+        * FIXME: this shouldn't happen if the next line is a wrapped line
+        * Maybe we should just let whoever calls this func add \n's where
+        * necessary. However, we need to be careful about the line length.
+        */
        strcat(buf, "\n");
 }
 
@@ -412,7 +423,7 @@
 
                /* don't start a new line with a space */
                tmp = estyle_get_text(bit);
-               while (isspace(tmp[index]))
+               while (index < strlen(tmp) && isspace(tmp[index]))
                        index++;
                FREE(tmp);
 
@@ -424,6 +435,7 @@
                /* create a marker bit. */
                marker = estyle_new(et->evas, et->context->marker.text,
                                et->context->marker.style);
+               estyle_set_type(marker, ETOX_BIT_TYPE_WRAP_MARKER);
                evas_object_smart_member_add(marker, et->smart_obj);
                evas_object_color_set(marker, et->context->marker.r,
                                et->context->marker.g,
@@ -512,17 +524,17 @@
                if (!(line->flags & ETOX_LINE_WRAPPED))
                        break;
 
-               /* remove the wrap marker bit */
+               /* remove any wrap marker bits */
                ll = line->bits;
                while (ll) {
                        marker = ll->data;
-                       if (!estyle_fixed(marker)) {
-                               line->bits = evas_list_remove(line->bits,
-                                               marker);
-                               evas_object_del(marker);
-                               break;
-                       }
+
                        ll = ll->next;
+
+                       if (estyle_get_type(marker) == 
+                         ETOX_BIT_TYPE_WRAP_MARKER) {
+                               line->bits = evas_list_remove(line->bits, marker);
+                       }
                }
 
                /* remove the line from the list */
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/etox_obstacle.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -3 -r1.17 -r1.18
--- etox_obstacle.c     19 Aug 2003 04:00:23 -0000      1.17
+++ etox_obstacle.c     8 Sep 2003 02:22:58 -0000       1.18
@@ -25,6 +25,7 @@
        if (obst) {
                obst->et = et;
                obst->bit = estyle_new(et->evas, "", NULL);
+               estyle_set_type(obst->bit, ETOX_BIT_TYPE_OBSTACLE);
                evas_object_smart_member_add(obst->bit, et->smart_obj);
                estyle_fix_geometry(obst->bit, x, y, w, h);
        }
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/Etox.h,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -3 -r1.41 -r1.42
--- Etox.h      4 Sep 2003 03:05:23 -0000       1.41
+++ Etox.h      8 Sep 2003 02:22:58 -0000       1.42
@@ -20,6 +20,13 @@
 
 #define ETOX_ALIGN_MASK 0xF
 
+typedef enum _etox_bit_type Etox_Bit_Type;
+enum _etox_bit_type
+{
+       ETOX_BIT_TYPE_TEXT = 0,
+       ETOX_BIT_TYPE_OBSTACLE = 1,
+       ETOX_BIT_TYPE_WRAP_MARKER = 2
+};
 /*
  * The context structure holds information relative to the appearance of text
  * that is added to the etox.
@@ -149,6 +156,7 @@
 char *etox_get_text(Evas_Object * et);
 void etox_clear(Evas_Object * et);
 
+int etox_get_length(Evas_Object *obj);
 /*
  * Geometry retrieval functions
  */




-------------------------------------------------------
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