Enlightenment CVS committal Author : rbdpngn Project : e17 Module : libs/etox
Dir : e17/libs/etox/src Modified Files: etox.c etox_line.c etox_line.h Log Message: Wrap text when it takes up the entire line. This needs further testing, but works for the trivial case. =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/etox/src/etox.c,v retrieving revision 1.48 retrieving revision 1.49 diff -u -3 -r1.48 -r1.49 --- etox.c 29 Jul 2003 04:41:04 -0000 1.48 +++ etox.c 31 Jul 2003 04:57:09 -0000 1.49 @@ -2,8 +2,6 @@ #include "Etox_private.h" static Evas_List *_etox_break_text(Etox * et, char *text); -static void _etox_wrap_lines(Etox * et); -static void _etox_unwrap_lines(Etox * et); /** * etox_new - create a new etox with default settings @@ -1016,145 +1014,6 @@ } /* - * _etox_wrap_lines - break lines that are too long if soft wrap flag is set - * @et: the etox to wrap - * - * Returns nothing, modifies the lines of the etox - */ -void _etox_wrap_lines(Etox *et) -{ - Etox_Line *line; - Etox_Line *newline; - Evas_List *l, *ll; - - CHECK_PARAM_POINTER("et", et); - - /* if the soft wrap flag is not set, don't do anything */ - if (!(et->context->flags & ETOX_SOFT_WRAP)) - return; - - /* iterate through the lines */ - for (l = et->lines; l; l = l->next) { - line = l->data; - - /* if the line is wider than the etox */ - if (line->w > et->w) { - Estyle *bit = NULL, *split = NULL, *marker; - int index = -1; - - /* iterate through the bits to find the one on the - * border */ - for (ll = line->bits; ll; ll = ll->next) { - bit = ll->data; - - /* get the index of the character on the edge */ - index = estyle_text_at_position(bit, - et->x + et->w, line->y, - NULL, NULL, NULL, NULL); - /* if this bit contained the character on the - * edge, break */ - if (index >= 0) - break; - } - - /* if we have an index */ - if (index != -1) { - char *tmp; - - /* don't start a new line with a space */ - tmp = estyle_get_text(bit); - while (tmp[index] == ' ') - index ++; - FREE(tmp); - - /* split the edge bit */ - split = estyle_split(bit, index); - } - - /* if split successful, set up the new bit */ - if (split) { - /* create a marker bit. */ - marker = estyle_new(et->evas, - et->context->marker.text, - et->context->marker.style); - estyle_set_color(marker, et->context->marker.r, - et->context->marker.g, - et->context->marker.b, - et->context->marker.a); - estyle_set_clip(marker, et->clip); - estyle_set_font(bit, et->context->font, - et->context->font_size); - estyle_show(marker); - - /* create a new line, with the marker and the - * split bits */ - newline = etox_line_new(line->flags | - ETOX_LINE_WRAPPED); - newline->et = et; - etox_line_append(newline, marker); - etox_line_append(newline, split); - - /* move the remaining bits to the new line */ - for (ll = ll->next; ll; ll = ll->next) { - bit = ll->data; - etox_line_remove(line, bit); - etox_line_append(newline, split); - } - - /* add the newline after the current one */ - et->lines = evas_list_append_relative(et->lines, - newline, line); - } - } - } -} - - -/* - * _etox_unwrap_lines - recombine lines that have been split by soft wrapping - * @et: the etox to wrap - * - * Returns nothing, modifies the lines of the etox - */ -void _etox_unwrap_lines(Etox *et) -{ - Etox_Line *line, *prevline; - Evas_List *l; - int i = 0; - - CHECK_PARAM_POINTER("et", et); - - if (!et->lines) - return; - - prevline = et->lines->data; - - for (l = et->lines->next; l; l = l->next) { - i++; - line = l->data; - if (line->flags & ETOX_LINE_WRAPPED) { - printf("unwrap line: %i\n", i); - - /* remove the wrap marker bit */ - line->bits = evas_list_remove(line->bits, - line->bits->data); - - /* remove the line from the list */ - et->lines = evas_list_remove(et->lines, line); - - /* merge the two lines */ - etox_line_merge_append(prevline, line); - etox_line_free(line); - - /* skip the line we just merged */ - l = l->next; - } - else - prevline = line; - } -} - -/* * etox_layout - deals with the actual laying out of lines within the etox * @et: the etox to be laid out * @@ -1178,24 +1037,38 @@ if (!et->lines) return; - /* - * Begin by rewrapping the necessary lines. - */ - _etox_unwrap_lines(et); - _etox_wrap_lines(et); - y = et->y; /* * Traverse the list displaying each line, moving down the screen after * each line. */ - for (l = et->lines; l; l = l->next) { + l = et->lines; + while (l) { line = l->data; line->x = et->x; line->y = y; + /* + * Unwrap lines if they were wrapped + */ + if (l->next) { + Etox_Line *temp = l->next->data; + + if (temp->flags & ETOX_LINE_WRAPPED) + etox_line_unwrap(et, line); + } + etox_line_layout(line); + + /* + * If we need to wrap the line, we don't need to re-layout since + * the maximal width was used for splitting. + */ + if ((et->context->flags & ETOX_SOFT_WRAP) && (line->w > et->w)) + etox_line_wrap(et, line); + + l = l->next; y += line->h; } =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/etox/src/etox_line.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -3 -r1.14 -r1.15 --- etox_line.c 28 Jul 2003 22:04:31 -0000 1.14 +++ etox_line.c 31 Jul 2003 04:57:09 -0000 1.15 @@ -1,5 +1,6 @@ #include "Etox_private.h" +#include <ctype.h> #include <string.h> /* @@ -154,12 +155,21 @@ */ void etox_line_remove(Etox_Line * line, Estyle * bit) { + int w; + CHECK_PARAM_POINTER("line", line); CHECK_PARAM_POINTER("bit", bit); line->bits = evas_list_remove(line->bits, bit); line->length -= estyle_length(bit); - etox_line_minimize(line); + estyle_geometry(bit, NULL, NULL, &w, NULL); + line->w -= w; + + /* + * FIXME: Need to fix-up line minimizing to ensure it doesn't stomp on + * selections. + * etox_line_minimize(line); + */ } /* @@ -186,13 +196,17 @@ * x coordinate appropriately. */ if (line->flags & ETOX_ALIGN_LEFT) { - x = line->x; + x = line->et->x; } else if (line->flags & ETOX_ALIGN_RIGHT) { x = line->et->x + line->et->w - line->w; } else { x = line->et->x + (line->et->w / 2) - (line->w / 2); } + if ((line->et->context->flags & ETOX_SOFT_WRAP) && + (line->x < line->et->x)) + x = line->et->x; + /* * Determine the veritcal alignment and perform the layout of the * bits. @@ -239,14 +253,23 @@ CHECK_PARAM_POINTER("line", line); l = line->bits; - while ((bit = l->data)) { + if (!l) + return; + + last_bit = l->data; + l = l->next; + while (l) { + bit = l->data; /* * Attempt to merge the bits if possible, remove the second * one if successful. */ - if (estyle_merge(last_bit, bit)) - l = evas_list_remove(l, bit); + if (estyle_merge(last_bit, bit)) { + line->bits = evas_list_remove(line->bits, bit); + l = evas_list_find_list(line->bits, last_bit); + l = l->next; + } else { last_bit = bit; l = l->next; @@ -347,39 +370,47 @@ strcat(buf, "\n"); } -void +int etox_line_wrap(Etox *et, Etox_Line *line) { Evas_List *ll; Etox_Line *newline; Estyle *bit = NULL, *split = NULL, *marker; + int x, w, y, h; int index = -1; /* iterate through the bits to find the one on the border */ - for (ll = line->bits; ll; ll = ll->next) { + ll = line->bits; + while (ll) { bit = ll->data; - /* get the index of the character on the edge */ - index = estyle_text_at_position(bit, et->x + et->w, line->y, - NULL, NULL, NULL, NULL); - - /* if this bit contained the character on the edge, break */ - if (index >= 0) + estyle_geometry(bit, &x, &y, &w, &h); + if (x + w > et->x + et->w) break; + + ll = ll->next; } + /* get the index of the character on the edge */ + if (bit) + index = estyle_text_at_position(bit, et->x + et->w, y + (h / 2), + NULL, NULL, NULL, NULL); + /* if we have an index */ if (index != -1) { char *tmp; /* don't start a new line with a space */ tmp = estyle_get_text(bit); - while (tmp[index] == ' ') + while (isspace(tmp[index])) index++; FREE(tmp); + etox_line_remove(line, bit); + /* split the edge bit */ split = estyle_split(bit, index); + etox_line_append(line, bit); } /* if split successful, set up the new bit */ @@ -400,15 +431,51 @@ etox_line_append(newline, marker); etox_line_append(newline, split); + ll = evas_list_find_list(line->bits, bit); + /* move the remaining bits to the new line */ for (ll = ll->next; ll; ll = ll->next) { bit = ll->data; etox_line_remove(line, bit); - etox_line_append(newline, split); + etox_line_append(newline, bit); } /* add the newline after the current one */ et->lines = evas_list_append_relative(et->lines, newline, line); + } + else + index = 0; + + return index; +} + +void +etox_line_unwrap(Etox *et, Etox_Line *line) +{ + Evas_List *l, *prevline; + + if (!et->lines) + return; + + prevline = evas_list_find_list(et->lines, line); + + l = prevline->next; + while (l) { + line = l->data; + if (!(line->flags & ETOX_LINE_WRAPPED)) + break; + + /* remove the wrap marker bit */ + line->bits = evas_list_remove(line->bits, line->bits->data); + + /* remove the line from the list */ + et->lines = evas_list_remove(et->lines, line); + + /* merge the two lines */ + etox_line_merge_append(prevline->data, line); + etox_line_free(line); + + l = prevline->next; } } =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/etox/src/etox_line.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- etox_line.h 28 Jul 2003 22:04:31 -0000 1.6 +++ etox_line.h 31 Jul 2003 04:57:09 -0000 1.7 @@ -14,6 +14,8 @@ void etox_line_minimize(Etox_Line * line); void etox_line_get_text(Etox_Line * line, char *buf); +int etox_line_wrap(Etox *et, Etox_Line *line); +void etox_line_unwrap(Etox *et, Etox_Line *line); Estyle *etox_line_coord_to_bit(Etox_Line *line, int x); Estyle *etox_line_index_to_bit(Etox_Line *line, int *i); ------------------------------------------------------- This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET. http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01 _______________________________________________ enlightenment-cvs mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs