Enlightenment CVS committal
Author : raster
Project : e17
Module : libs/etox
Dir : e17/libs/etox/src
Modified Files:
Etox.h etox.c etox_line.c etox_selection.c
Log Message:
bart's etox patches - seem to work with ewl. fixed an infinite loop issue
with re-layout
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/Etox.h,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -3 -r1.54 -r1.55
--- Etox.h 30 Dec 2004 20:58:45 -0000 1.54
+++ Etox.h 29 Jan 2005 03:46:07 -0000 1.55
@@ -251,6 +251,9 @@
Etox_Context *context);
Etox_Rect *etox_selection_get_geometry(Etox_Selection *selected, int *num);
+/** Printout the text buffer to support debugging */
+void etox_print_text(Evas_Object *obj);
+
#ifdef __cplusplus
}
#endif
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/etox.c,v
retrieving revision 1.111
retrieving revision 1.112
diff -u -3 -r1.111 -r1.112
--- etox.c 30 Dec 2004 23:44:52 -0000 1.111
+++ etox.c 29 Jan 2005 03:46:08 -0000 1.112
@@ -1,6 +1,9 @@
+#include <ctype.h>
#include "config.h"
#include "Etox_private.h"
+//#define DEBUG ON
+
static void etox_free(Evas_Object * et);
static void etox_show(Evas_Object * et);
static void etox_hide(Evas_Object * et);
@@ -382,6 +385,9 @@
et->tw = line->w;
}
+#ifdef DEBUG
+ printf("etox_set_text() - calling etox_layout()\n");
+#endif
etox_layout(et);
if (et->lines && evas_object_visible_get(obj))
evas_object_show(et->clip);
@@ -412,7 +418,9 @@
*/
if (!et->lines)
return NULL;
-
+#ifdef DEBUG
+ printf("etox_get_text() - etox length = %d\n", et->length);
+#endif
ret = (char *) calloc(et->length + 1, sizeof(char));
temp = ret;
@@ -422,7 +430,13 @@
len = et->length;
for (l = et->lines; l; l = l->next) {
line = l->data;
+#ifdef DEBUG
+ printf("etox_get_text() - getting up to %d characters\n", len);
+#endif
etox_line_get_text(line, temp, len);
+#ifdef DEBUG
+ printf("etox_get_text() - line text is : (%s)\n", temp);
+#endif
/*
* FIXME: Currently, in etox_line_get_text(), line->length
@@ -436,6 +450,9 @@
Etox_Line * nline = l->next->data;
if (!(nline->flags & ETOX_LINE_WRAPPED)) {
strcat(temp, "\n");
+#ifdef DEBUG
+ printf("etox_get_text() - appended newline\n");
+#endif
temp++;
len--;
}
@@ -478,6 +495,9 @@
et->lines = NULL;
evas_object_hide(et->clip);
+
+ // Reset the active selections
+ etox_selection_free_by_etox(obj);
}
/**
@@ -500,6 +520,9 @@
else
et->flags &= ~ETOX_SOFT_WRAP;
+#ifdef DEBUG
+ printf("\netox_set_soft_wrap() - calling etox_layout()\n");
+#endif
etox_layout(et);
}
@@ -557,6 +580,9 @@
else
et->flags &= ~ETOX_BREAK_WORDS;
+#ifdef DEBUG
+ printf("\netox_set_word_wrap() - calling etox_layout()\n");
+#endif
etox_layout(et);
}
@@ -631,7 +657,12 @@
* Layout lines if appropriate.
*/
if (et->lines)
+ {
+#ifdef DEBUG
+ printf("\netox_move() - calling etox_layout()\n");
+#endif
etox_layout(et);
+ }
/*
* Adjust the clip box to display the contents correctly. We need to
@@ -653,6 +684,9 @@
*/
static void etox_resize(Evas_Object * obj, Evas_Coord w, Evas_Coord h)
{
+#ifdef DEBUG
+ printf("\netox_resize() - called. w=%d h=%d\n", w, h);
+#endif
Etox *et;
CHECK_PARAM_POINTER("obj", obj);
@@ -668,6 +702,9 @@
/*
* Layout lines if appropriate.
*/
+#ifdef DEBUG
+ printf("etox_resize() - calling etox_layout()\n");
+#endif
etox_layout(et);
/*
@@ -948,6 +985,9 @@
if (obst)
et->obstacles = evas_list_append(et->obstacles, obst);
+#ifdef DEBUG
+ printf("\netox_obstacle_add() - calling etox_layout()\n");
+#endif
etox_layout(et);
return obst;
@@ -1081,6 +1121,9 @@
etox_line_append(line, bit);
evas_object_show(bit);
+ // We just converted 1 character into 8, so adjust the
line length
+ line->length += 7;
+
break;
/*
@@ -1115,6 +1158,9 @@
if (*walk == '\r' && *text == '\n') {
walk++;
text++;
+ // This skips a character that was counted in
the
+ // original length, so decrement length by 1.
+//?? et->length--;
}
if (line->w > et->tw)
@@ -1165,6 +1211,10 @@
*/
void etox_layout(Etox * et)
{
+#ifdef DEBUG
+ printf("\netox_layout() - called\n");
+ printf("etox_layout() - etox size is w=%d, h=%d\n", et->w, et->h);
+#endif
int y;
Etox_Line *line;
Evas_List *l;
@@ -1208,6 +1258,13 @@
line->x = et->x;
line->y = y;
+#ifdef DEBUG
+ char *tmpLine = calloc(256, sizeof(char));
+ etox_line_get_text(line, tmpLine, 256);
+ printf("\n\netox_layout() - current line is : %s\n", tmpLine);
+ free(tmpLine);
+#endif
+
/*
* Unwrap lines if they were wrapped
*/
@@ -1234,6 +1291,9 @@
ll = ll->next;
}
+#ifdef DEBUG
+ printf("etox_layout() - performing initial line layout\n");
+#endif
etox_line_layout(line);
/*
@@ -1241,14 +1301,31 @@
* the width affects alignment.
*/
if ((et->flags & ETOX_SOFT_WRAP) && (line->w > et->w)) {
- etox_line_wrap(et, line);
+#ifdef DEBUG
+ printf("etox_layout() - line needs wrapping. calling
etox_line_wrap()\n");
+#endif
+ int index = etox_line_wrap(et, line);
+ if (index >= 0)
+ {
+#ifdef DEBUG
+ printf("etox_layout() - re-laying out wrapped line.\n");
+#endif
etox_line_layout(line);
+ }
}
+#ifdef DEBUG
+ printf("etox_layout() - line complete. current etox size is
w=%d, h=%d\n", et->w, et->h);
+#endif
l = l->next;
y += line->h;
}
et->th = y - et->y;
+#ifdef DEBUG
+ printf("etox_layout() - Unwrapped text size is w=%d, h=%d\n", et->tw,
et->th);
+ printf("etox_layout() - etox size is w=%d, h=%d\n", et->w, et->h);
+ printf("etox_layout() - done.\n\n");
+#endif
}
Etox_Line *
@@ -1274,22 +1351,52 @@
Etox_Line *
etox_index_to_line(Etox *et, int *i)
{
- int len = 0;
+#ifdef DEBUG
+ printf("etox_index_to_line() - called. index = %d\n", *i);
+#endif
+ int begin_line_index = 0;
+ int line_length;
Evas_List *l;
Etox_Line *line = NULL;;
l = et->lines;
while (l) {
line = l->data;
- len += line->length;
- if (*i < len)
- break;
+#ifdef DEBUG
+ printf("etox_index_to_line() - checking line :\n");
+ etox_line_print_bits(line);
+ printf("etox_index_to_line() - line length is %d\n",
line->length);
+#endif
+ line_length = line->length;
+ if (!(line->flags & ETOX_LINE_WRAPPED))
+ {
+#ifdef DEBUG
+ printf("etox_index_to_line() - not a wrapped line.
length++\n");
+#endif
+ line_length++;
+ }
+#ifdef DEBUG
+ else
+ {
+ printf("etox_index_to_line() - wrapped line\n");
+ }
+#endif
+ if (*i < (begin_line_index + line_length)) break;
+
+ begin_line_index += line_length;
+#ifdef DEBUG
+ printf("etox_index_to_line() - begin_line_index is %d\n",
begin_line_index);
+#endif
l = l->next;
}
if (line)
- *i -= len - line->length;
-
+ {
+#ifdef DEBUG
+ printf("etox_index_to_line() - found line!\n");
+#endif
+ *i -= begin_line_index;
+ }
return line;
}
@@ -1306,6 +1413,42 @@
}
}
+/** Printout the text buffer to support debugging */
+void
+etox_print_text(Evas_Object *obj)
+{
+ char *charptr_orig = etox_get_text(obj);
+ char *charptr = charptr_orig;
+ int char_num = 0;
+ while (*charptr)
+ {
+ // Print line prefix with index
+ if (char_num == 0)
+ {
+ printf("\netox_print_lines() - %5.5d : ", (charptr-charptr_orig));
+ }
+
+ // Print characters for printables, decimal otherwise
+ if (isprint(*charptr))
+ {
+ printf(" %c ", *charptr);
+ }
+ else
+ {
+ printf("%2.2d ", *charptr);
+ }
+ fflush(stdout);
+
+ // 16 characters per line
+ if (++char_num == 16)
+ {
+ char_num = 0;
+ }
+ charptr++;
+ }
+ free(charptr_orig);
+}
+
/**
* etox_text_geometry_get - get the desired text geometry
* @obj: the etox to get the geometry from
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/etox_line.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -3 -r1.48 -r1.49
--- etox_line.c 30 Dec 2004 20:58:45 -0000 1.48
+++ etox_line.c 29 Jan 2005 03:46:09 -0000 1.49
@@ -3,6 +3,9 @@
#include <ctype.h>
#include <string.h>
+//#define DEBUG ON
+
+
/*
* etox_line_new - create a new line with the specified alignment
* @align: the alignment of the current line
@@ -237,16 +240,25 @@
/*
* Move the evas object into place.
*/
+#ifdef DEBUG
+ printf("etox_line_layout() - moving bit to %d,%d. Bit
text is (%s)\n",
+ x, ty, etox_style_get_text(bit));
+#endif
evas_object_move(bit, x, ty);
}
+#ifdef DEBUG
else
printf("Encountered an obstacle!!\n");
+#endif
/*
* Move horizontally to place the next bit.
*/
x += tw;
}
+#ifdef DEBUG
+ printf("etox_line_layout() - done\n");
+#endif
}
/*
@@ -358,6 +370,9 @@
*/
void etox_line_get_text(Etox_Line * line, char *buf, int len)
{
+#ifdef DEBUG
+ printf("etox_line_get_text() - called. len = %d\n", len);
+#endif
char *temp;
Evas_Object *es;
Evas_List *l;
@@ -379,26 +394,44 @@
es = l->data;
sum += etox_style_length(es);
+#ifdef DEBUG
+ printf("etox_line_get_text() - etox_style_length() returned
%d\n", etox_style_length(es));
+#endif
t = etox_style_get_type(es);
if (t == ETOX_BIT_TYPE_WRAP_MARKER)
continue;
else if (t == ETOX_BIT_TYPE_TAB)
+ {
temp = strdup("\t");
+ sum -= 7; // etox_style_length returns 8 but we're only
inserting 1
+ }
else
temp = etox_style_get_text(es);
tlen = strlen(temp);
+#ifdef DEBUG
+ printf("etox_line_get_text() - actual length of returned text
is %d\n", tlen);
+#endif
if (pos + tlen < len) {
+#ifdef DEBUG
+ printf("etox_line_get_text() - appending %d characters
at pos = %d\n", tlen, pos);
+#endif
pos += tlen;
strcat(buf, temp);
}
else {
+#ifdef DEBUG
+ printf("etox_line_get_text() - appending %d characters
(limited) at pos = %d\n", (len-pos), pos);
+#endif
strncat(buf, temp, (len - pos));
- pos = len - 1;
+ pos = len;
}
free(temp);
}
line->length = sum;
+#ifdef DEBUG
+ printf("etox_line_get_text() - done\n");
+#endif
}
int
@@ -407,8 +440,35 @@
Evas_List *ll;
Evas_Object *bit = NULL, *marker;
Evas_Coord x, w, y, h;
- int index = -1;
+ int index = -1, ok = 0;
+#ifdef DEBUG
+ printf("etox_line_wrap() - trying to wrap line:\n");
+ etox_line_print_bits(line);
+#endif
+
+ ok= 1;
+ for (ll = line->bits; ll; ll = ll->next)
+ {
+ bit = ll->data;
+ char *tmp;
+
+ tmp = etox_style_get_text(bit);
+ evas_object_geometry_get(bit, &x, &y, &w, &h);
+ /* if we are down to 1 character... or 1 char +space - abort */
+ if (
+ (strlen(tmp) <= 1) ||
+ ((strlen(tmp) == 2) && (tmp[1] == ' '))
+ ) {
+ if (w > et->w) {
+ ok = 0;
+ }
+ }
+ FREE(tmp);
+ }
+ if (!ok) {
+ return -1;
+ }
/* iterate through the bits to find the one on the border */
ll = line->bits;
while (ll) {
@@ -441,13 +501,17 @@
/* don't start a new line with a space */
while (index < strlen(tmp) && isspace(tmp[index]))
index++;
+
FREE(tmp);
}
/* Wrap if we've found a reasonable position */
if (index > 0 || (index == 0 && bit != line->bits->data)) {
+#ifdef DEBUG
+ printf("etox_line_wrap() - going to split line at index %d of
bit:"
+ "(%s)\n", index, etox_style_get_text(bit));
+#endif
etox_line_split(line, bit, index);
-
ll = evas_list_find_list(et->lines, line);
ll = ll->next;
@@ -470,7 +534,7 @@
etox_line_append(line, marker);
}
else
- index = 0;
+ index = -1;
return index;
}
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/etox_selection.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -3 -r1.17 -r1.18
--- etox_selection.c 30 Dec 2004 20:58:45 -0000 1.17
+++ etox_selection.c 29 Jan 2005 03:46:17 -0000 1.18
@@ -1,4 +1,7 @@
#include "Etox_private.h"
+#include <ctype.h>
+
+//#define DEBUG ON
Evas_List *active_selections = NULL;
@@ -66,6 +69,7 @@
Evas_Object *s1, Evas_Object *s2, int i1, int i2)
{
Evas_Object *temp;
+ Evas_Object *temp2;
Etox_Selection *selected;
/*
@@ -83,7 +87,7 @@
* Split on the ending index, we use the original s2 for the end,
* since it's the bit portion before the split.
*/
- etox_split_bit(l2, s2, i2);
+ temp2 = etox_split_bit(l2, s2, i2+1); // split after the end character
selected = calloc(1, sizeof(Etox_Selection));
memset(selected, 0, sizeof(Etox_Selection));
@@ -98,7 +102,17 @@
active_selections = evas_list_prepend(active_selections, selected);
+ // If any bits were split, re-layout the etox.
+ /** @TODO : If there are multiple selections created in an etox, the
layout
+ * will be repeated for each. It would be optimal to hold off the
layouts
+ * until the selections were all created */
+ if (temp != s1 || temp2 != s2)
+ {
+#ifdef DEBUG
+ printf("etox_selection_new() - bit(s) were split. calling
etox_layout()\n");
+#endif
etox_layout(etox);
+ }
return selected;
}
@@ -260,6 +274,9 @@
i = *index;
pos = strstr(text + i, match);
+#ifdef DEBUG
+ printf("\etox_select_str() - found string at index %d\n",
(pos-(text+i)));
+#endif
if (pos == NULL)
{
@@ -269,9 +286,8 @@
}
si = pos - text;
- ei = si + strlen(match);
-
- printf("si: %d, ei: %d\n", si, ei);
+ // The end index should point to the last character in the match text
+ ei = si + strlen(match) - 1;
if (index)
*index = ei;
@@ -346,6 +362,9 @@
}
}
+#ifdef DEBUG
+ printf("etox_selection_apply_context() - calling etox_layout()\n");
+#endif
etox_layout(selected->etox);
}
@@ -380,6 +399,9 @@
l = evas_list_find_list(selected->etox->lines, selected->start.line);
+ // Start with the second line (if any)
+ l = l->next;
+ count++; /* count the first line */
while (l)
{
Etox_Line *line = l->data;
@@ -392,8 +414,6 @@
l = l->next;
}
- printf("count: %d\n", count);
-
rects = calloc(count, sizeof(Etox_Rect)); /* start and end line also */
/* first line */
@@ -405,6 +425,10 @@
etox_line_get_geometry(selected->start.line, &x, &y, &w, &h);
rects->w = x + w - rects->x;
rects->h = y + h - rects->y;
+#ifdef DEBUG
+ printf("etox_selection_get_geometry() - first line rect is %dx%d @ %d,%d\n",
+ rects->w, rects->h, rects->x, rects->y);
+#endif
cur = rects;
/* printf("cur1: %d\n", cur); */
@@ -436,6 +460,10 @@
cur->w = x + w - cur->x;
cur->h = y + h - cur->y;
+#ifdef DEBUG
+ printf("etox_selection_get_geometry() - last line rect is %dx%d @ %d,%d\n",
+ cur->w, cur->h, cur->x, cur->y);
+#endif
if (num) *num = count;
return rects;
-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs