Enlightenment CVS committal

Author  : rbdpngn
Project : e17
Module  : libs/etox

Dir     : e17/libs/etox/src


Modified Files:
        Etox.h Etox_private.h Makefile.am etox.c etox_context.c 
        etox_line.c etox_line.h etox_obstacle.c 
Added Files:
        etox_selection.c 
Removed Files:
        etox_selection.h 


Log Message:
Basic framework in place for using selections to update an etox. So far the
actual selecting based on index gets the correct bits. Need to investigate an
estyle issue for searching by coordinates.

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/Etox.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -3 -r1.31 -r1.32
--- Etox.h      14 Jan 2003 18:42:45 -0000      1.31
+++ Etox.h      23 Jul 2003 06:46:16 -0000      1.32
@@ -9,7 +9,8 @@
  * Simple alignment bitfield
  */
 typedef enum _etox_alignment Etox_Alignment;
-enum _etox_alignment {
+enum _etox_alignment
+{
        ETOX_ALIGN_CENTER = 0,
        ETOX_ALIGN_LEFT = 1,
        ETOX_ALIGN_RIGHT = 2,
@@ -21,7 +22,8 @@
  * The color struct simply keeps track of the various colors available
  */
 typedef struct _etox_color Etox_Color;
-struct _etox_color {
+struct _etox_color
+{
        int a, r, g, b;
 };
 
@@ -29,7 +31,8 @@
  * Text layout requires knowing the font layout, size, ascent and descent.
  */
 typedef struct _etox_font Etox_Font;
-struct _etox_font {
+struct _etox_font
+{
        char *name;
        int size, ascent, descent;
 };
@@ -39,7 +42,8 @@
  * represents it.
  */
 typedef struct _etox_obstacle Etox_Obstacle;
-struct _etox_obstacle {
+struct _etox_obstacle
+{
        Estyle *bit;
        int start_line;
        int end_line;
@@ -50,7 +54,8 @@
  * the bits used to display the text.
  */
 typedef struct _etox_style_info Etox_Style_Info;
-struct _etox_style_info {
+struct _etox_style_info
+{
        char *name;
        E_DB_File *style_db;
        int references;
@@ -61,7 +66,8 @@
  * that is added to the etox.
  */
 typedef struct _etox_context Etox_Context;
-struct _etox_context {
+struct _etox_context
+{
        /*
         * Color for displaying the text
         */
@@ -100,9 +106,9 @@
         */
        struct
        {
-         char *text;
-         char *style;
-         int r, g, b, a;
+               char *text;
+               char *style;
+               int r, g, b, a;
        } marker;
 };
 
@@ -111,7 +117,8 @@
  * text enclosed.
  */
 typedef struct _etox Etox;
-struct _etox {
+struct _etox
+{
        /*
         * Evas for drawing the text
         */
@@ -165,6 +172,62 @@
 };
 
 /*
+ * Line information helps process the bits layout
+ */
+typedef struct _etox_line Etox_Line;
+struct _etox_line
+{
+
+       /*
+        * The etox containing this line, used for getting back to necessary
+        * etox info when drawing bits.
+        */
+       Etox *et;
+
+       /*
+        * This is a pointer to a list of bits
+        */
+       Evas_List *bits;
+
+       /*
+        * The dimensions of this line.
+        */
+       int x, y, w, h;
+
+       /*
+        * Flags indicating alignment, or if this is a "softline", ie. etox
+        * wrapped the line because it was too long to fit within the etox's
+        * bounds.
+        */
+       char flags;
+
+       /*
+        * Keep track of the length of text stored in this bit to avoid
+        * needing to recalculate this often.
+        */
+       int length;
+};
+
+/*
+ * Selection are used to manipulate previously composed etox, it is
+ * recommended to keep the number of active selections to a minimum, and if
+ * possible, compose using contexts and setup time.
+ */
+typedef struct _etox_selection Etox_Selection;
+struct _etox_selection
+{
+       Etox *etox;
+
+       struct
+       {
+               Etox_Line *line;
+               Estyle *bit;
+       } start, end;
+
+       Etox_Context *context;
+};
+
+/*
  * Etox creation and deletion functions
  */
 Etox *etox_new(Evas *evas);
@@ -281,5 +344,43 @@
 void etox_obstacle_move(Etox * et, Etox_Obstacle * obstacle, int x, int y);
 void etox_obstacle_resize(Etox * et, Etox_Obstacle * obstacle, int w,
                          int h);
+
+/*
+ * These functions select regions of the etox.
+ */
+Etox_Selection *etox_select_coords(Etox * et, int sx, int sy, int ex,
+                                  int ey);
+Etox_Selection *etox_select_index(Etox * et, int si, int ei);
+Etox_Selection *etox_select_str(Etox * et, char *match, char **last);
+
+/*
+ * Release a selection that is no longer needed.
+ */
+void etox_selection_free(Etox_Selection * selected);
+void etox_selection_free_by_etox(Etox *etox);
+
+/*
+ * This function gets a rectangular bound on the selection.
+ */
+void etox_selection_bounds(Etox_Selection * selected, int *x, int *y,
+                          int *w, int *h);
+
+/*
+ * These methods alter the appearance of the selected region.
+ */
+void etox_selection_set_font(Etox_Selection * selected, char *font,
+                            int size);
+void etox_selection_set_style(Etox_Selection * selected, char *style);
+
+/*
+ * These functions manipulate callbacks on the selected region.
+ */
+void etox_selection_add_callback(Etox_Selection * selected,
+                                Evas_Callback_Type callback,
+                                void (*func) (void *data, Evas *e,
+                                              Evas_Object *o, int b, int x,
+                                              int y), void *data);
+void etox_selection_del_callback(Etox_Selection * selected,
+                                Evas_Callback_Type callback);
 
 #endif
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/Etox_private.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -3 -r1.14 -r1.15
--- Etox_private.h      14 Jan 2003 18:42:53 -0000      1.14
+++ Etox_private.h      23 Jul 2003 06:46:16 -0000      1.15
@@ -9,52 +9,18 @@
  * untouched so that a single char can hold all of the necessary information.
  */
 typedef enum _etox_line_flags Etox_Line_Flags;
-enum _etox_line_flags {
+enum _etox_line_flags
+{
        ETOX_SOFT_WRAP = 0x10,
        ETOX_LINE_WRAPPED = 0x20,
 };
 
 /*
- * Line information helps process the bits layout
- */
-typedef struct _etox_line Etox_Line;
-struct _etox_line {
-
-       /*
-        * The etox containing this line, used for getting back to necessary
-        * etox info when drawing bits.
-        */
-       Etox *et;
-
-       /*
-        * This is a pointer to a list of bits
-        */
-       Evas_List *bits;
-
-       /*
-        * The dimensions of this line.
-        */
-       int x, y, w, h;
-
-       /*
-        * Flags indicating alignment, or if this is a "softline", ie. etox
-        * wrapped the line because it was too long to fit within the etox's
-        * bounds.
-        */
-       char flags;
-
-       /*
-        * Keep track of the length of text stored in this bit to avoid
-        * needing to recalculate this often.
-        */
-       int length;
-};
-
-/*
  * The bit holds all information necessary for display and layout of the text
  */
 typedef struct _etox_bit Etox_Bit;
-struct _etox_bit {
+struct _etox_bit
+{
        /*
         * This is the estyle that displays the bit.
         */
@@ -65,6 +31,9 @@
         */
        Evas_List *regions;
 };
+
+Etox_Line * _etox_coord_to_line(Etox *et, int y);
+Etox_Line * _etox_index_to_line(Etox *et, int *i);
 
 #include "etox_line.h"
 #include "etox_obstacle.h"
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/Makefile.am,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -3 -r1.13 -r1.14
--- Makefile.am 2 Apr 2002 02:50:09 -0000       1.13
+++ Makefile.am 23 Jul 2003 06:46:16 -0000      1.14
@@ -14,7 +14,8 @@
 etox.c \
 etox_line.c \
 etox_context.c \
-etox_obstacle.c
+etox_obstacle.c \
+etox_selection.c
 
 
 libetox_la_LIBADD       = @evas_libs@ @ewd_libs@
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/etox.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -3 -r1.38 -r1.39
--- etox.c      24 Jan 2003 17:06:14 -0000      1.38
+++ etox.c      23 Jul 2003 06:46:17 -0000      1.39
@@ -21,16 +21,14 @@
        /*
         * Create the etox and assign it's evas to draw on.
         */
-       et = (Etox *) malloc(sizeof(Etox));
-       memset(et, 0, sizeof(Etox));
+       et = (Etox *) calloc(1, sizeof(Etox));
 
        et->evas = evas;
 
        /*
         * Allocate space for the default context
         */
-       et->context = (Etox_Context *) malloc(sizeof(Etox_Context));
-       memset(et->context, 0, sizeof(Etox_Context));
+       et->context = (Etox_Context *) calloc(1, sizeof(Etox_Context));
 
        /*
         * Setup the default color
@@ -130,8 +128,9 @@
 
        etox_clear(et);
        FREE(et->context->style);
+       etox_selection_free_by_etox(et);
 
-       //FIXME could this be replaced by evas_list_free ?
+       /* FIXME could this be replaced by evas_list_free ? */
        for (l = et->obstacles; l; l = l->next) {
                obst = l->data;
 
@@ -416,8 +415,7 @@
        if (!et->lines)
                return NULL;
 
-       ret = (char *) malloc((et->length + 1) * sizeof(char));
-       memset(ret, 0, (et->length + 1) * sizeof(char));
+       ret = (char *) calloc((et->length + 1), sizeof(char));
 
        temp = ret;
 
@@ -620,7 +618,7 @@
 }
 
 /**
- * etox_get_letter_geometry - retrieve information about a letters geometry
+ * etox_index_to_geometry - retrieve information about a letters geometry
  * @et: the etox to inquire the geometry
  * @x: a pointer to an int to store the x coordinate of the etox
  * @y: a pointer to an int to store the y coordinate of the etox
@@ -1182,4 +1180,48 @@
        et->h = y - et->y;
 
        evas_object_resize(et->clip, et->w, et->h);
+}
+
+Etox_Line *
+_etox_coord_to_line(Etox *et, int y)
+{
+       Evas_List *l;
+       Etox_Line *line = NULL;;
+
+       l = et->lines;
+       while (l) {
+               line = l->data;
+               if (y < line->y + line->h)
+                       break;
+               l = l->next;
+       }
+
+       if (!l)
+               line = NULL;
+
+       return line;
+}
+
+Etox_Line *
+_etox_index_to_line(Etox *et, int *i)
+{
+       int len = 0;
+       Evas_List *l;
+       Etox_Line *line = NULL;;
+
+       l = et->lines;
+       while (l) {
+               line = l->data;
+               len += line->length;
+               if (*i < len)
+                       break;
+               l = l->next;
+       }
+
+       if (!l)
+               line = NULL;
+       else
+               *i -= len - line->length;
+
+       return line;
 }
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/etox_context.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- etox_context.c      14 Jan 2003 18:43:12 -0000      1.6
+++ etox_context.c      23 Jul 2003 06:46:17 -0000      1.7
@@ -11,11 +11,7 @@
 {
        Etox_Context *ret;
 
-       ret = (Etox_Context *) malloc(sizeof(Etox_Context));
-       if (!ret)
-               return NULL;
-
-       memset(ret, 0, sizeof(Etox_Context));
+       ret = (Etox_Context *) calloc(1, sizeof(Etox_Context));
 
        return ret;
 }
@@ -39,11 +35,16 @@
         * Copy the contents of the old context
         */
        memcpy(ret, et->context, sizeof(Etox_Context));
+       if (et->context->style)
+               ret->style = strdup(et->context->style);
+       if (et->context->font)
+               ret->font = strdup(et->context->font);
 
-       /*
-        * Need to increment references the style counter
-        */
-       ret->style = strdup(et->context->style);
+       if (et->context->marker.text)
+               ret->marker.text = strdup(et->context->marker.text);
+
+       if (et->context->marker.style)
+               ret->marker.style = strdup(et->context->marker.style);
 
        return ret;
 }
@@ -64,13 +65,23 @@
        /*
         * Dereference the style before overwriting
         */
-       FREE(et->context->style);
-       FREE(et->context->font);
+       IF_FREE(et->context->style);
+       IF_FREE(et->context->font);
+       IF_FREE(et->context->marker.text);
+       IF_FREE(et->context->marker.style);
 
        memcpy(et->context, context, sizeof(Etox_Context));
 
-       et->context->style = strdup(context->style);
-       et->context->font = strdup(context->font);
+       if (context->style)
+               et->context->style = strdup(context->style);
+       if (context->font)
+               et->context->font = strdup(context->font);
+
+       if (et->context->marker.text)
+               et->context->marker.text = strdup(context->marker.text);
+
+       if (et->context->marker.style)
+               et->context->marker.style = strdup(context->marker.style);
 }
 
 /**
@@ -86,6 +97,10 @@
 
        IF_FREE(context->font);
        IF_FREE(context->style);
+       IF_FREE(context->marker.text);
+       IF_FREE(context->marker.style);
+
+       FREE(context);
 }
 
 /**
@@ -184,7 +199,7 @@
 
        CHECK_PARAM_POINTER("et", et);
 
-       cb = malloc(sizeof(Etox_Callback));
+       cb = calloc(1, sizeof(Etox_Callback));
        cb->type = type;
        cb->func = func;
        cb->data = data;
@@ -304,7 +319,7 @@
        et->context->flags = align;
 }
 
-/*
+/**
  * etox_context_set_soft_wrap - turns on soft wrapping of lines that are
  * longer than the etox is wide
  * @et: the etox to set for
@@ -314,15 +329,15 @@
  */
 void etox_context_set_soft_wrap(Etox *et, int boolean)
 {
-  CHECK_PARAM_POINTER("et", et);
+       CHECK_PARAM_POINTER("et", et);
 
-  if (boolean)
-    et->context->flags = et->context->flags | ETOX_SOFT_WRAP;
-  else
-    et->context->flags = et->context->flags & ~ETOX_SOFT_WRAP;
+       if (boolean)
+               et->context->flags = et->context->flags | ETOX_SOFT_WRAP;
+       else
+               et->context->flags = et->context->flags & ~ETOX_SOFT_WRAP;
 }
 
-/*
+/**
  * etox_set_wrap_marker - sets string to mark wrapped lines
  * @et: the etox to set for
  * @marker: the string to mark wrapped lines
@@ -332,11 +347,11 @@
  */
 void etox_context_set_wrap_marker(Etox *et, char *marker, char *style)
 {
-  CHECK_PARAM_POINTER("et", et);
-  IF_FREE(et->context->marker.text);
-  IF_FREE(et->context->marker.style);
-  et->context->marker.text = strdup(marker);
-  et->context->marker.style = strdup(style);
+       CHECK_PARAM_POINTER("et", et);
+       IF_FREE(et->context->marker.text);
+       IF_FREE(et->context->marker.style);
+       et->context->marker.text = strdup(marker);
+       et->context->marker.style = strdup(style);
 }
 
 /*
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/etox_line.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -3 -r1.9 -r1.10
--- etox_line.c 14 Jan 2003 18:43:13 -0000      1.9
+++ etox_line.c 23 Jul 2003 06:46:17 -0000      1.10
@@ -12,9 +12,8 @@
 {
        Etox_Line *ret;
 
-       ret = (Etox_Line *) malloc(sizeof(Etox_Line));
+       ret = (Etox_Line *) calloc(1, sizeof(Etox_Line));
        if (ret) {
-               memset(ret, 0, sizeof(Etox_Line));
                ret->flags |= align;
                ret->length = 1;
        }
@@ -398,11 +397,11 @@
        }
 }
 
-Evas_List *
+Estyle *
 etox_line_coord_to_bit(Etox_Line *line, int x)
 {
-       int bx, by, bw, bh;
-       Evas_List *l = NULL, *ll = NULL;
+       int bx;
+       Evas_List *l = NULL;
        Estyle *bit = NULL;
 
        /*
@@ -411,24 +410,33 @@
        l = line->bits;
        while (l) {
                bit = l->data;
-               estyle_geometry(bit, &bx, &by, &bw, &bh);
+               estyle_geometry(bit, &bx, NULL, NULL, NULL);
                if (bx < x)
                        break;
                l = l->next;
        }
 
-       /*
-        * The found line did not contain an intersecting bit.
-        */
-       while (l && !bit) {
-               line = l->data;
-               ll = line->bits;
-               if (ll)
-                       bit = ll->data;
+       return bit;
+}
+
+Estyle *
+etox_line_index_to_bit(Etox_Line *line, int *i)
+{
+       int len = 0;
+       Evas_List *l = NULL;
+       Estyle *bit = NULL;
+
+       l = line->bits;
+       while (l) {
+               bit = l->data;
+               len += estyle_length(bit);
+               if (*i < len)
+                       break;
+               l = l->next;
        }
 
-       if (!bit)
-               ll = NULL;
+       if (l)
+               *i -= (len - estyle_length(bit));
 
-       return ll;
+       return bit;
 }
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/etox_line.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- etox_line.h 14 Jan 2003 18:43:15 -0000      1.4
+++ etox_line.h 23 Jul 2003 06:46:17 -0000      1.5
@@ -13,4 +13,7 @@
 void etox_line_minimize(Etox_Line * line);
 void etox_line_get_text(Etox_Line * line, char *buf);
 
+Estyle *etox_line_coord_to_bit(Etox_Line *line, int x);
+Estyle *etox_line_index_to_bit(Etox_Line *line, int *i);
+
 #endif
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/etox_obstacle.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- etox_obstacle.c     14 Jan 2003 18:43:18 -0000      1.10
+++ etox_obstacle.c     23 Jul 2003 06:46:17 -0000      1.11
@@ -24,9 +24,11 @@
         * Allocate the obstacle and bit. Also, give the obstacle's bit correct
         * position and fixed geometry.
         */
-       obst = (Etox_Obstacle *) malloc(sizeof(Etox_Obstacle));
-       obst->bit = estyle_new(et->evas, "", NULL);
-       estyle_fix_geometry(obst->bit, x, y, w, h);
+       obst = (Etox_Obstacle *) calloc(1, sizeof(Etox_Obstacle));
+       if (obst) {
+               obst->bit = estyle_new(et->evas, "", NULL);
+               estyle_fix_geometry(obst->bit, x, y, w, h);
+       }
 
        return obst;
 }
@@ -183,11 +185,10 @@
                        if (!bit)
                                return;
                        /*
-                          * FIXME: We need to do some bit-splitting here, just need 
to get
-                          * around to it.
+                        * FIXME: We need to do some bit-splitting here, just need to 
get
+                        * around to it.
                         */
-                       l = evas_list_prepend_relative(l, obst->bit,
-                                                      l->next);
+                       l = evas_list_prepend_relative(l, obst->bit, l->next);
                        break;
                }
        }




-------------------------------------------------------
This SF.net email is sponsored by: VM Ware
With VMware you can run multiple operating systems on a single machine.
WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the
same time. Free trial click here: http://www.vmware.com/wl/offer/345/0
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to