Enlightenment CVS committal
Author : rbdpngn
Project : e17
Module : libs/etox
Dir : e17/libs/etox/src
Modified Files:
Etox.h Etox_private.h etox.c etox_selection.c
Log Message:
More work on selections, changing the font of a selection now results in a
reasonable change and layout for that selected area.
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/Etox.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -3 -r1.32 -r1.33
--- Etox.h 23 Jul 2003 06:46:16 -0000 1.32
+++ Etox.h 23 Jul 2003 16:37:39 -0000 1.33
@@ -371,6 +371,12 @@
void etox_selection_set_font(Etox_Selection * selected, char *font,
int size);
void etox_selection_set_style(Etox_Selection * selected, char *style);
+void etox_selection_set_color(Etox_Selection *selected, int r, int g, int b,
+ int a);
+void etox_selection_set_wrap_marker(Etox_Selection *selected, char *marker,
+ char *style);
+void etox_selection_set_wrap_marker_color(Etox_Selection *selected, int r,
+ int g, int b, int a);
/*
* These functions manipulate callbacks on the selected region.
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/Etox_private.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -3 -r1.15 -r1.16
--- Etox_private.h 23 Jul 2003 06:46:16 -0000 1.15
+++ Etox_private.h 23 Jul 2003 16:37:39 -0000 1.16
@@ -32,8 +32,10 @@
Evas_List *regions;
};
-Etox_Line * _etox_coord_to_line(Etox *et, int y);
-Etox_Line * _etox_index_to_line(Etox *et, int *i);
+void etox_layout(Etox * et);
+
+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/etox.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -3 -r1.39 -r1.40
--- etox.c 23 Jul 2003 06:46:17 -0000 1.39
+++ etox.c 23 Jul 2003 16:37:39 -0000 1.40
@@ -4,7 +4,6 @@
static Evas_List *_etox_break_text(Etox * et, char *text);
static void _etox_wrap_lines(Etox * et);
static void _etox_unwrap_lines(Etox * et);
-static void _etox_layout(Etox * et, int y);
/**
* etox_new - create a new etox with default settings
@@ -54,7 +53,7 @@
/*
* Setup the default alignment
*/
- et->context->flags = ETOX_ALIGN_LEFT | ETOX_ALIGN_TOP;
+ et->context->flags = ETOX_ALIGN_LEFT | ETOX_ALIGN_BOTTOM;
/*
* Set the clip rectangle for the etox
@@ -130,10 +129,8 @@
FREE(et->context->style);
etox_selection_free_by_etox(et);
- /* FIXME could this be replaced by evas_list_free ? */
- for (l = et->obstacles; l; l = l->next) {
+ for (l = et->obstacles; l; l = evas_list_remove(l, obst)) {
obst = l->data;
-
FREE(obst);
}
@@ -240,14 +237,9 @@
}
/*
- * wrap the lines
- */
- _etox_wrap_lines(et);
-
- /*
* Layout the lines on the etox starting at the newly added text.
*/
- _etox_layout(et, end->y);
+ etox_layout(et);
/*
* Destroy the temporary list of lines now that it is empty.
@@ -322,8 +314,7 @@
/*
* Layout the lines on the etox.
*/
- _etox_wrap_lines(et);
- _etox_layout(et, et->y);
+ etox_layout(et);
/*
* Destroy the temporary list of lines now that it is empty.
@@ -372,8 +363,7 @@
*/
et->lines = _etox_break_text(et, text);
- _etox_wrap_lines(et);
- _etox_layout(et, et->y);
+ etox_layout(et);
/*
* Sum up the length and height of the text in the etox.
@@ -541,9 +531,8 @@
/*
* Layout lines if appropriate.
*/
- if (et->lines) {
- _etox_layout(et, et->y);
- }
+ if (et->lines)
+ etox_layout(et);
/*
* Adjust the clip box to display the contents correctly. We need to
@@ -573,12 +562,8 @@
/*
* Layout lines if appropriate.
*/
- if (et->lines) {
- /* rewrap the lines */
- _etox_unwrap_lines(et);
- _etox_wrap_lines(et);
- _etox_layout(et, et->y);
- }
+ if (et->lines)
+ etox_layout(et);
/*
* Adjust the clip box to display the contents correctly. We need to
@@ -1022,131 +1007,135 @@
*/
void _etox_wrap_lines(Etox *et)
{
- Etox_Line *line;
- Etox_Line *newline;
- Evas_List *l, *ll;
+ Etox_Line *line;
+ Etox_Line *newline;
+ Evas_List *l, *ll;
- CHECK_PARAM_POINTER("et", et);
+ 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;
+ /* 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);
- }
+ /* 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);
+ }
- /* add the newline after the current one */
- et->lines = evas_list_append_relative(et->lines, newline, line);
- }
- }
- }
+ /* 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 - break lines that are too long if soft wrap flag is set
+ * _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);
-
- 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(prevline, line);
-
- /* skip the line we just merged */
- l = l->next;
- }
- else
- prevline = line;
- }
+ Etox_Line *line, *prevline;
+ Evas_List *l;
+ int i = 0;
+
+ CHECK_PARAM_POINTER("et", et);
+
+ 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(prevline, 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
+ * etox_layout - deals with the actual laying out of lines within the etox
* @et: the etox to be laid out
*
* Returns no value. Updates the positions of liens within the etox in order
@@ -1154,14 +1143,23 @@
* current position in the line list, so that should be set appropriately
* before performing this operation.
*/
-static void _etox_layout(Etox * et, int y)
+void etox_layout(Etox * et)
{
+ int y;
Etox_Line *line;
Evas_List *l;
CHECK_PARAM_POINTER("et", et);
/*
+ * 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.
*/
@@ -1183,7 +1181,7 @@
}
Etox_Line *
-_etox_coord_to_line(Etox *et, int y)
+etox_coord_to_line(Etox *et, int y)
{
Evas_List *l;
Etox_Line *line = NULL;;
@@ -1203,7 +1201,7 @@
}
Etox_Line *
-_etox_index_to_line(Etox *et, int *i)
+etox_index_to_line(Etox *et, int *i)
{
int len = 0;
Evas_List *l;
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/etox/src/etox_selection.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- etox_selection.c 23 Jul 2003 06:46:17 -0000 1.1
+++ etox_selection.c 23 Jul 2003 16:37:39 -0000 1.2
@@ -2,8 +2,31 @@
Evas_List *active_selections = NULL;
+#define SELECTION_LOOP_START(selected) \
+do { \
+ Estyle *bit = NULL; \
+ Etox_Line *line; \
+ Evas_List *l, *bl; \
+ line = selected->start.line; \
+ l = evas_list_find_list(selected->etox->lines, selected->start.line); \
+ bl = evas_list_find_list(line->bits, selected->start.bit); \
+ while (bl && bit != selected->end.bit) { \
+ bit = bl->data
+
+#define SELECTION_LOOP_END \
+ if (!bl) { \
+ l = l->next; \
+ line = l->data; \
+ bl = line->bits; \
+ } \
+ else \
+ bl = bl->next; \
+ } \
+} while (0)
+
+
Estyle *
-etox_selection_split_bit(Etox_Line *line, Estyle *bit, int index)
+etox_split_bit(Etox_Line *line, Estyle *bit, int index)
{
Evas_List *l;
Estyle *point = bit;
@@ -40,7 +63,7 @@
* Split bits on their index boundaries, this updates selections that
* contain the bits.
*/
- temp = etox_selection_split_bit(l1, s1, i1);
+ temp = etox_split_bit(l1, s1, i1);
if (s1 == s2) {
i2 -= i1;
s2 = temp;
@@ -51,7 +74,7 @@
* Split on the ending index, we use the original s2 for the end,
* since it's the bit portion before the split.
*/
- etox_selection_split_bit(l2, s2, i2);
+ etox_split_bit(l2, s2, i2);
selected = calloc(1, sizeof(Etox_Selection));
memset(selected, 0, sizeof(Etox_Selection));
@@ -68,6 +91,8 @@
active_selections = evas_list_prepend(active_selections, selected);
+ etox_layout(etox);
+
return selected;
}
@@ -110,11 +135,11 @@
Estyle *sb, *eb = NULL;
Etox_Selection *selected = NULL;
- sl = _etox_coord_to_line(et, sy);
+ sl = etox_coord_to_line(et, sy);
if (!sl)
goto out;
- el = _etox_coord_to_line(et, ey);
+ el = etox_coord_to_line(et, ey);
if (!el)
goto out;
@@ -153,11 +178,11 @@
/*
* First determine the lines containing the indices.
*/
- sl = _etox_index_to_line(et, &si);
+ sl = etox_index_to_line(et, &si);
if (!sl)
goto out;
- el = _etox_index_to_line(et, &ei);
+ el = etox_index_to_line(et, &ei);
if (!el)
goto out;
@@ -199,10 +224,6 @@
void
etox_selection_set_font(Etox_Selection *selected, char *font, int font_size)
{
- Evas_List *l, *bl;
- Etox_Line *line;
- Estyle *bit;
-
/*
* Make the necessary context changes.
*/
@@ -210,30 +231,12 @@
selected->context->font = strdup(font);
selected->context->font_size = font_size;
- /*
- * Apply the settings to all bits between the selections start and end
- * points.
- */
- line = selected->start.line;
- l = evas_list_find_list(selected->etox->lines, selected->start.line);
- bl = evas_list_find_list(line->bits, selected->start.bit);
- while (bl) {
- bit = bl->data;
+ SELECTION_LOOP_START(selected);
estyle_set_font(bit, font, font_size);
+ SELECTION_LOOP_END;
- if (bit == selected->end.bit)
- goto out;
+ etox_layout(selected->etox);
- if (!bl) {
- l = l->next;
- line = l->data;
- bl = line->bits;
- }
- else
- bl = bl->next;
- }
-
-out:
return;
}
@@ -242,40 +245,89 @@
void
etox_selection_set_style(Etox_Selection *selected, char *style)
{
- Evas_List *l, *bl;
- Etox_Line *line;
- Estyle *bit;
-
/*
* Make the necessary context changes.
*/
IF_FREE(selected->context->style);
selected->context->style = strdup(style);
+ SELECTION_LOOP_START(selected);
+ estyle_set_style(bit, style);
+ SELECTION_LOOP_END;
+
+ etox_layout(selected->etox);
+
+ return;
+}
+
+/**
+ */
+void
+etox_selection_set_color(Etox_Selection *selected, int r, int g, int b, int a)
+{
/*
- * Apply the settings to all bits between the selections start and end
- * points.
+ * Make the necessary context changes.
*/
- line = selected->start.line;
- l = evas_list_find_list(selected->etox->lines, selected->start.line);
- bl = evas_list_find_list(line->bits, selected->start.bit);
- while (bl) {
- bit = bl->data;
- estyle_set_style(bit, style);
+ selected->context->a = a;
+ selected->context->r = r;
+ selected->context->g = g;
+ selected->context->b = b;
+
+ SELECTION_LOOP_START(selected);
+ estyle_set_color(bit, r, g, b, a);
+ SELECTION_LOOP_END;
- if (bit == selected->end.bit)
- goto out;
+ etox_layout(selected->etox);
- if (!bl) {
- l = l->next;
- line = l->data;
- bl = line->bits;
+ return;
+}
+
+/**
+ */
+void
+etox_selection_set_wrap_marker_color(Etox_Selection *selected, int r, int g,
+ int b, int a)
+{
+ /*
+ * Make the necessary context changes.
+ */
+ selected->context->marker.a = a;
+ selected->context->marker.r = r;
+ selected->context->marker.g = g;
+ selected->context->marker.b = b;
+
+ SELECTION_LOOP_START(selected);
+ if (!bl->prev && line->flags & ETOX_LINE_WRAPPED) {
+ estyle_set_color(bit, r, g, b, a);
}
- else
- bl = bl->next;
- }
+ SELECTION_LOOP_END;
+
+ etox_layout(selected->etox);
+
+ return;
+}
+
+/**
+ */
+void
+etox_selection_set_wrap_marker(Etox_Selection *selected, char *marker,
+ char *style)
+{
+ /*
+ * Make the necessary context changes.
+ */
+ IF_FREE(selected->context->marker.text);
+ IF_FREE(selected->context->marker.style);
+
+ SELECTION_LOOP_START(selected);
+ if (!bl->prev && line->flags & ETOX_LINE_WRAPPED) {
+ estyle_set_text(bit, marker);
+ estyle_set_style(bit, style);
+ }
+ SELECTION_LOOP_END;
+
+ etox_layout(selected->etox);
-out:
return;
}
-------------------------------------------------------
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/psa00100006ave/direct;at.asp_061203_01/01
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs