From: <enl...@li...> - 2004-05-27 20:15:29
|
Enlightenment CVS committal Author : rbdpngn Project : e17 Module : libs/ewl Dir : e17/libs/ewl/src Modified Files: Ewl.h Makefile.am ewl_entry.c ewl_entry.h ewl_menu.c ewl_menu.h ewl_text.c ewl_text.h Removed Files: ewl_textarea.c ewl_textarea.h Log Message: Minor theme changes. Moved the textarea code to the text file since that matches the API. A little work on real menus. Ctrl-w word deletion support from Vincent Torri. =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/Ewl.h,v retrieving revision 1.52 retrieving revision 1.53 diff -u -3 -r1.52 -r1.53 --- Ewl.h 13 May 2004 06:03:00 -0000 1.52 +++ Ewl.h 27 May 2004 20:15:16 -0000 1.53 @@ -329,7 +329,7 @@ #include <ewl_embed.h> #include <ewl_window.h> -#include <ewl_textarea.h> +#include <ewl_text.h> #include <ewl_entry.h> #include <ewl_password.h> =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/Makefile.am,v retrieving revision 1.49 retrieving revision 1.50 diff -u -3 -r1.49 -r1.50 --- Makefile.am 21 May 2004 19:12:30 -0000 1.49 +++ Makefile.am 27 May 2004 20:15:16 -0000 1.50 @@ -47,7 +47,7 @@ ewl_spacer.h \ ewl_spectrum.h \ ewl_spinner.h \ - ewl_textarea.h \ + ewl_text.h \ ewl_table.h \ ewl_tree.h \ ewl_tooltip.h \ @@ -95,7 +95,7 @@ ewl_spectrum.c \ ewl_spinner.c \ ewl_table.c \ - ewl_textarea.c \ + ewl_text.c \ ewl_theme.c \ ewl_tree.c \ ewl_tooltip.c \ =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/ewl_entry.c,v retrieving revision 1.90 retrieving revision 1.91 diff -u -3 -r1.90 -r1.91 --- ewl_entry.c 25 May 2004 14:22:10 -0000 1.90 +++ ewl_entry.c 27 May 2004 20:15:16 -0000 1.91 @@ -299,6 +299,11 @@ ewl_entry_delete_to_left(e); else if (!strcmp(ev->keyname, "Delete")) ewl_entry_delete_to_right(e); + else if (((!strcmp(ev->keyname, "w")) && + (ev->modifiers & EWL_KEY_MODIFIER_CTRL)) || + ((!strcmp(ev->keyname, "W")) && + (ev->modifiers & EWL_KEY_MODIFIER_CTRL))) + ewl_entry_delete_to_word_begin(e); else if (!strcmp(ev->keyname, "Return") || !strcmp(ev->keyname, "KP_Return") || !strcmp(ev->keyname, "Enter") || !strcmp(ev->keyname, "KP_Enter")) { @@ -720,7 +725,7 @@ if (!s) DRETURN(DLEVEL_STABLE); - if (!strlen(s) || ep == strlen(s) + 1) + if (!strlen(s) || sp == strlen(s) + 1) DRETURN(DLEVEL_STABLE); strcpy(&(s[sp - 1]), &(s[ep])); @@ -735,6 +740,40 @@ } void +ewl_entry_delete_to_word_begin(Ewl_Entry * e) +{ + char *s; + int bp, index; + + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("e", e); + + s = ewl_entry_get_text(e); + if (!s) + DRETURN(DLEVEL_STABLE); + + bp = ewl_cursor_get_base_position(EWL_CURSOR(e->cursor)); + index = bp-2; + + while ((index-->0) && (s[index] == ' ')){} + if (index < 0) + index = 0; + while ((index-->0) && (s[index] != ' ')){} + index++; + strcpy(&(s[index]), &(s[bp])); + ewl_entry_set_text(e, s); + + FREE(s); + + if (index <= 0) + index = 1; + ewl_cursor_set_base(EWL_CURSOR(e->cursor), index); + ewl_widget_configure(EWL_WIDGET(e)); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +void ewl_entry_child_show_cb(Ewl_Container * c, Ewl_Widget * w) { Ewl_Entry *e; =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/ewl_entry.h,v retrieving revision 1.34 retrieving revision 1.35 diff -u -3 -r1.34 -r1.35 --- ewl_entry.h 24 May 2004 19:25:20 -0000 1.34 +++ ewl_entry.h 27 May 2004 20:15:16 -0000 1.35 @@ -56,6 +56,7 @@ void ewl_entry_insert_text(Ewl_Entry * e, char *s); void ewl_entry_delete_to_left(Ewl_Entry * e); void ewl_entry_delete_to_right(Ewl_Entry * e); +void ewl_entry_delete_to_word_begin(Ewl_Entry * e); /* * Internally used callbacks, override at your own risk. =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/ewl_menu.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -3 -r1.16 -r1.17 --- ewl_menu.c 4 Apr 2004 22:28:14 -0000 1.16 +++ ewl_menu.c 27 May 2004 20:15:16 -0000 1.17 @@ -4,13 +4,12 @@ /** * @param image: the image icon to use for this menu * @param title: the text to place in the menu + * @return Returns a pointer to a new menu on success, NULL on failure. * @brief Create a new internal menu - * - * @return Returns a new menu on success, NULL on failure. */ Ewl_Widget *ewl_menu_new(char *image, char *title) { - Ewl_Menu *menu; + Ewl_Menu *menu; DENTER_FUNCTION(DLEVEL_STABLE); @@ -27,7 +26,7 @@ /** * @param menu: the menu to initialize * @param image: the path to the icon image - * @param title: the text label to be displayed + * @param title: the string displayed in the title * @return Returns no value. * @brief Initialize an internal menu to starting values */ @@ -41,61 +40,77 @@ * Initialize the defaults of the inherited fields. */ ewl_menu_base_init(EWL_MENU_BASE(menu), image, title); - ewl_widget_set_appearance(EWL_WIDGET(menu), "menu"); + + ewl_callback_append(EWL_WIDGET(menu), EWL_CALLBACK_SELECT, + ewl_menu_expand_cb, NULL); + ewl_callback_append(EWL_WIDGET(menu), EWL_CALLBACK_CONFIGURE, + ewl_menu_configure_cb, NULL); /* - * The realize needs to create the pop-up. + * Create the popup menu portion of the widget. */ - ewl_callback_prepend(EWL_WIDGET(menu), EWL_CALLBACK_SELECT, - ewl_menu_expand_cb, NULL); + menu->base.popup = ewl_window_new(); + ewl_widget_set_internal(menu->base.popup, TRUE); + ewl_widget_set_layer(menu->base.popup, 1000); + ewl_widget_set_appearance(EWL_WIDGET(menu->base.popup), "menu"); + ewl_box_set_orientation(EWL_BOX(menu->base.popup), + EWL_ORIENTATION_VERTICAL); + ewl_object_set_fill_policy(EWL_OBJECT(menu->base.popup), + EWL_FLAG_FILL_NONE); + ewl_object_set_alignment(EWL_OBJECT(menu->base.popup), + EWL_FLAG_ALIGN_LEFT | EWL_FLAG_ALIGN_TOP); DLEAVE_FUNCTION(DLEVEL_STABLE); } - -void ewl_menu_expand_cb(Ewl_Widget * w, void *ev_data, void *user_data) +void ewl_menu_configure_cb(Ewl_Widget *w, void *ev_data, void *user_data) { - int x = 0, y = 0, xx = 0, yy = 0; - Ewl_Menu *menu; - Ewl_Embed *emb; + int x, y; + Ewl_Menu *menu = EWL_MENU(w); + Ewl_Embed *emb; DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR("w", w); - menu = EWL_MENU(w); emb = ewl_embed_find_by_widget(w); - /* - * Create the popup menu portion of the menu. Do this prior to - * initializing the rest of the fields to avoid the add callback being - * called. - */ - - menu->base.popup = ewl_window_new(); - ewl_window_set_borderless(EWL_WINDOW(menu->base.popup)); - ewl_object_set_fill_policy(EWL_OBJECT(menu->base.popup), - EWL_FLAG_FILL_NONE); + if (ewl_widget_is_type(EWL_WIDGET(emb), "window")) + ewl_window_get_position(EWL_WINDOW(emb), &x, &y); + else { + x = CURRENT_X(w); + y = CURRENT_Y(w); + } /* * Position the popup menu relative to the menu. */ if (EWL_MENU_ITEM(w)->inmenu) { - xx = CURRENT_X(w) + CURRENT_W(w); - yy = CURRENT_Y(w); - } else { - xx = CURRENT_X(w); - yy = CURRENT_Y(w) + CURRENT_H(w); - - ewl_object_set_minimum_size(EWL_OBJECT(menu->base.popup), - CURRENT_W(menu), - MINIMUM_H(menu->base.popup)); + ewl_window_move(EWL_WINDOW(menu->base.popup), + x + CURRENT_W(w), y); } + else { + ewl_window_move(EWL_WINDOW(menu->base.popup), x, + y + CURRENT_H(w)); + } + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} - ewl_embed_coord_to_screen(emb, xx, yy, &x, &y); - printf("Coords %d, %d, mapped to %d, %d\n", xx, yy, x, y); +void ewl_menu_expand_cb(Ewl_Widget * w, void *ev_data, void *user_data) +{ + Ewl_Menu *menu; + Ewl_Embed *emb; + + DENTER_FUNCTION(DLEVEL_STABLE); + + menu = EWL_MENU(w); + + if (!REALIZED(menu->base.popup)) { + emb = ewl_embed_find_by_widget(w); + ewl_container_append_child(EWL_CONTAINER(emb), + menu->base.popup); + } - ewl_widget_realize(EWL_WIDGET(menu->base.popup)); - ewl_window_move(EWL_WINDOW(menu->base.popup), x, y); + ewl_widget_show(menu->base.popup); DLEAVE_FUNCTION(DLEVEL_STABLE); } =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/ewl_menu.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- ewl_menu.h 19 Nov 2003 20:18:34 -0000 1.6 +++ ewl_menu.h 27 May 2004 20:15:16 -0000 1.7 @@ -2,8 +2,9 @@ #define __EWL_MENU_H__ /** - * @defgroup Ewl_Menu Menu: A Popup Menu - * Provides a popup menu for displaying a list of options. + * @defgroup Ewl_Imenu Imenu: A Simple Internal Menu + * Defines a menu used internally. The contents on the menu are not drawn + * outside of the Evas. * * @{ */ @@ -14,8 +15,7 @@ */ /** - * A simple popup menu widget, with the capability of being nested inside - * another menu. + * A simple internal menu, it is limited to drawing within the current evas. */ typedef struct Ewl_Menu Ewl_Menu; @@ -27,23 +27,24 @@ /** * @struct Ewl_Menu - * Inherits from Ewl_Menu_Base and adds on functionality for displaying a - * pop-up menu that is in a window of it's own. + * Inherits from the Ewl_Menu_Base and does not extend the structure, but + * provides policy for drawing on the current evas. */ struct Ewl_Menu { - Ewl_Menu_Base base; /**< Inherit from Ewl_Menu_Base */ + Ewl_Menu_Base base; }; -Ewl_Widget *ewl_menu_new(char *image, char *title); -void ewl_menu_init(Ewl_Menu * menu, char *image, char *title); +Ewl_Widget *ewl_menu_new(char *image, char *title); +void ewl_menu_init(Ewl_Menu * menu, char *image, char *title); /* * Internally used callbacks, override at your own risk. */ -void ewl_menu_expand_cb(Ewl_Widget * w, void *ev_data, void *user_data); -void ewl_menu_item_clicked_cb(Ewl_Widget * w, void *ev_data, void *user_data); -void ewl_menu_realize_cb(Ewl_Widget * w, void *ev_data, void *user_data); +void ewl_menu_configure_cb(Ewl_Widget *w, void *ev_data, + void *user_data); +void ewl_menu_expand_cb(Ewl_Widget * w, void *ev_data, + void *user_data); /** * @} =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/ewl_text.c,v retrieving revision 1.61 retrieving revision 1.62 diff -u -3 -r1.61 -r1.62 --- ewl_text.c 13 May 2004 06:03:01 -0000 1.61 +++ ewl_text.c 27 May 2004 20:15:16 -0000 1.62 @@ -1,683 +1,752 @@ - #include <Ewl.h> -#include <Etox.h> + +static void ewl_text_ops_apply(Ewl_Text *ta); +static void ewl_text_op_free(void *data); +static Ewl_Text_Op *ewl_text_op_relevant_find(Ewl_Text *ta, + Ewl_Text_Op_Type type); +static void ewl_text_update_size(Ewl_Text * ta); + +/* + * Private functions for applying operations to the text at realize time. + */ +static Ewl_Text_Op *ewl_text_op_color_new(Ewl_Text *ta, int r, int g, int b, + int a); +static void ewl_text_op_color_apply(Ewl_Text *ta, Ewl_Text_Op *op); + +static Ewl_Text_Op *ewl_text_op_font_new(Ewl_Text *ta, char *font, int size); +static void ewl_text_op_font_apply(Ewl_Text *ta, Ewl_Text_Op *op); +static void ewl_text_op_font_free(void *op); + +static Ewl_Text_Op *ewl_text_op_style_new(Ewl_Text *ta, char *style); +static void ewl_text_op_style_apply(Ewl_Text *ta, Ewl_Text_Op *op); +static void ewl_text_op_style_free(void *op); + +static Ewl_Text_Op * ewl_text_op_align_new(Ewl_Text *ta, unsigned int align); +static void ewl_text_op_align_apply(Ewl_Text *ta, Ewl_Text_Op *op); /** - * @param text: the text to display - * @return Returns a pointer a new text widget on success, NULL on failure. - * @brief Allocate a new text widget + * @param text: the initial text of the text + * @return Returns a pointer to a new text on success, NULL on failure. + * @brief Allocate a new text area widget + * + * Sets the text initially to @a text if not NULL. */ -Ewl_Widget * -ewl_text_new(char *text) +Ewl_Widget *ewl_text_new(char *text) { - Ewl_Text *t; + Ewl_Text *ta; DENTER_FUNCTION(DLEVEL_STABLE); - t = NEW(Ewl_Text, 1); - if (!t) + ta = NEW(Ewl_Text, 1); + if (!ta) DRETURN_PTR(NULL, DLEVEL_STABLE); - ewl_text_init(t, text); + ewl_text_init(ta, text); - DRETURN_PTR(EWL_WIDGET(t), DLEVEL_STABLE); + DRETURN_PTR(EWL_WIDGET(ta), DLEVEL_STABLE); } /** - * @param t: the text widget to initialize to default values and callbacks - * @param text: the text to display + * @param ta: the text area to be initialized + * @param text: the text to be displayed initially in the text area * @return Returns no value. - * @brief Initialize a text widget to default values and callbacks + * @brief Initialize the fields and callbacks of a text area * - * Sets the fields and callbacks of the text widget @a t to their defaults. + * Sets the internal fields and callbacks of a text area to their defaults. */ -void -ewl_text_init(Ewl_Text * t, char *text) +void ewl_text_init(Ewl_Text * ta, char *text) { - Ewl_Widget *w; + Ewl_Widget *w; DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR("t", t); + DCHECK_PARAM_PTR("ta", ta); - w = EWL_WIDGET(t); + w = EWL_WIDGET(ta); - ewl_widget_init(w, "text"); + ewl_widget_init(EWL_WIDGET(w), "text"); ewl_object_set_fill_policy(EWL_OBJECT(w), EWL_FLAG_FILL_NONE); - t->text = (text ? strdup(text) : strdup("")); - t->length = strlen(t->text); - t->align = EWL_FLAG_ALIGN_TOP | EWL_FLAG_ALIGN_LEFT; - - /* - * Set up appropriate callbacks for specific events - */ - ewl_callback_append(w, EWL_CALLBACK_REALIZE, ewl_text_realize_cb, NULL); - ewl_callback_prepend(w, EWL_CALLBACK_UNREALIZE, ewl_text_unrealize_cb, - NULL); - ewl_callback_append(w, EWL_CALLBACK_CONFIGURE, ewl_text_configure_cb, + ewl_callback_append(w, EWL_CALLBACK_REALIZE, ewl_text_realize_cb, NULL); + ewl_callback_append(w, EWL_CALLBACK_UNREALIZE, + ewl_text_unrealize_cb, NULL); + ewl_callback_append(w, EWL_CALLBACK_DESTROY, + ewl_text_destroy_cb, NULL); ewl_callback_append(w, EWL_CALLBACK_REPARENT, ewl_text_reparent_cb, NULL); + ewl_callback_append(w, EWL_CALLBACK_CONFIGURE, + ewl_text_configure_cb, NULL); + + ta->ops = ecore_dlist_new(); + ta->applied = ecore_dlist_new(); + + ecore_dlist_set_free_cb(ta->ops, ewl_text_op_free); + ecore_dlist_set_free_cb(ta->applied, ewl_text_op_free); - t->r = 255; - t->g = 255; - t->b = 255; - t->a = 255; + if (text) + ewl_text_text_set(ta, text); DLEAVE_FUNCTION(DLEVEL_STABLE); } /** - * @param t: the text widget to set the text - * @param text: the new text for the text widget @a t + * @param ta: the text area widget to set the text + * @param text: the text to set in the text area widget @a ta * @return Returns no value. - * @brief Set the text of a text widget + * @brief Set the text of a text area widget * - * Sets the text of the text widget @a t to @a text. + * Sets the text of the text area widget @a ta to a copy of the contents of + * @a text. */ -void -ewl_text_set_text(Ewl_Text * t, char *text) +void ewl_text_text_set(Ewl_Text * ta, char *text) { - Ewl_Widget *w; - char *evdata = NULL; - DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR("t", t); + DCHECK_PARAM_PTR("ta", ta); - w = EWL_WIDGET(t); - - if ((text == t->text) || (text && t->text && !strcmp(t->text, text))) - DRETURN(DLEVEL_STABLE); - - IF_FREE(t->text); - - /* - * Set the text to the value that was passed in, or an empty string if - * NULL was passed in. - */ - if (text == NULL) - t->text = strdup(""); - else - t->text = strdup(text); + if (text) { + /* + * Keep a copy of the text for quick access and for creating + * the etox when needed. + */ + ta->text = strdup(text); + ta->length = strlen(text); + } + else { + ta->text = NULL; + ta->length = 0; + } /* - * Update the etox if it's been realized at this point. + * Update the etox and the sizing of the text widget. */ - if (t->etox) { - Evas_Coord x, y, width, height; - - etox_set_text(t->etox, t->text); - t->length = etox_get_length(t->etox); - evas_object_geometry_get(t->etox, &x, &y, &width, &height); - ewl_object_set_preferred_size(EWL_OBJECT(t), - (int)(width), (int)(height)); + if (ta->etox) { + etox_set_text(ta->etox, text); + ewl_text_update_size(ta); } - else - t->length = strlen(t->text); - - evdata = strdup(t->text); - ewl_callback_call_with_event_data(w, EWL_CALLBACK_VALUE_CHANGED, - evdata); - FREE(evdata); DLEAVE_FUNCTION(DLEVEL_STABLE); } /** - * @param t: the text widget to retrieve the text - * @return Returns a copy of text in @a t on success, NULL on failure. + * @param ta: the text widget to retrieve text contents + * @return Returns a copy of the text in @a ta on success, NULL on failure. * @brief Retrieve the text of a text widget */ -char * -ewl_text_get_text(Ewl_Text * t) +char *ewl_text_text_get(Ewl_Text * ta) { - Ewl_Widget *w; + char *txt = NULL; DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR_RET("t", t, NULL); + DCHECK_PARAM_PTR_RET("ta", ta, NULL); - w = EWL_WIDGET(t); + if (ta->etox) + txt = etox_get_text(ta->etox); + else if (ta->text) + txt = strdup(ta->text); - DRETURN_PTR(t->text ? strdup(t->text) : NULL, DLEVEL_STABLE); + DRETURN_PTR(txt, DLEVEL_STABLE); } /** - * @param t: the text widget to set the font - * @param f: the name of the font to use for the text widget - * @return Returns no value. - * @brief Set the font of a text widget - * - * Sets the name of the font for text widget @a t to @a f and - * updates the display to use that font. + * @param ta: the text widget to retrieve length + * @return Returns the length of the text contained in the widget. + * @brief Retrieve the length of the text displayed by the text widget. */ -void -ewl_text_set_font(Ewl_Text * t, char *f) +int ewl_text_length_get(Ewl_Text *ta) { - Ewl_Widget *w; - DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR("t", t); - DCHECK_PARAM_PTR("f", f); - - w = EWL_WIDGET(t); + DCHECK_PARAM_PTR_RET("ta", ta, 0); - IF_FREE(t->font); - - t->font = strdup(f); - t->overrides |= EWL_TEXT_OVERRIDE_FONT; - - /* - * Change the font for the etox. - */ - if (t->etox) { - Evas_Coord x, y, width, height; - - /* - * Change the font and then update the size of the widget - */ - etox_context_set_font(t->context, t->font, t->font_size); - etox_set_text(t->etox, t->text); - evas_object_geometry_get(t->etox, &x, &y, &width, &height); - ewl_object_set_preferred_size(EWL_OBJECT(t), - (int)(width), (int)(height)); - } - - ewl_widget_configure(w); - - DLEAVE_FUNCTION(DLEVEL_STABLE); + DRETURN_INT(ta->length, DLEVEL_STABLE); } /** - * @param t: the text widget to get the font - * @return Returns a copy of the font used by @a t on success, NULL on failure. - * @brief Retrieve the font used by a text widget + * @param ta: the text widget to change color + * @param r: the new red value + * @param g: the new green value + * @param b: the new blue value + * @param a: the new alpha value + * @brief Changes the currently applied color of the text to specified values + * @return Returns no value. */ -char * -ewl_text_get_font(Ewl_Text * t) +void ewl_text_color_set(Ewl_Text *ta, int r, int g, int b, int a) { - Ewl_Widget *w; + Ewl_Text_Op *op; DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR_RET("t", t, NULL); + DCHECK_PARAM_PTR("ta", ta); - w = EWL_WIDGET(t); + op = ewl_text_op_color_new(ta, r, g, b, a); + ecore_dlist_append(ta->ops, op); + if (REALIZED(ta)) + ewl_text_ops_apply(ta); - DRETURN_PTR(t->font ? strdup(t->font) : NULL, DLEVEL_STABLE); + DLEAVE_FUNCTION(DLEVEL_STABLE); } /** - * @param t: the text widget to set the font size - * @param s: the font size to use for the text widget + * @param ta: the text widget to change font + * @param font: the name of the font + * @param size: the size of the font + * @brief Changes the currently applied font of the text to specified values * @return Returns no value. - * @brief Set the font size of a text widget - * - * Sets the font size for text widget @a t to @a s. */ -void -ewl_text_set_font_size(Ewl_Text * t, int s) +void ewl_text_font_set(Ewl_Text *ta, char *font, int size) { - Ewl_Widget *w; + Ewl_Text_Op *op; DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR("t", t); + DCHECK_PARAM_PTR("ta", ta); - w = EWL_WIDGET(t); - - t->font_size = s; - t->overrides |= EWL_TEXT_OVERRIDE_SIZE; - - /* - * Change the font for the etox. - */ - if (t->etox) { - Evas_Coord x, y, width, height; - - /* - * Change the font and then update the size of the widget - */ - etox_context_set_font(t->context, t->font, t->font_size); - evas_object_geometry_get(t->estyle, &x, &y, &width, &height); - ewl_object_set_preferred_size(EWL_OBJECT(t), - (int)(width), (int)(height)); - } - - ewl_widget_configure(w); + op = ewl_text_op_font_new(ta, font, size); + ecore_dlist_append(ta->ops, op); + if (REALIZED(ta)) + ewl_text_ops_apply(ta); DLEAVE_FUNCTION(DLEVEL_STABLE); } /** - * @param t: the text widget to retrieve the font size - * @return Returns the font size of the text widget on success, 0 on failure. - * @brief Retrieve the font size of a text widget + * @param ta: the text widget to change font + * @param font: the name of the font + * @param size: the size of the font + * @brief Changes the currently applied font of the text to specified values + * @return Returns no value. */ -int -ewl_text_get_font_size(Ewl_Text * t) +char *ewl_text_font_get(Ewl_Text *ta) { - Ewl_Widget *w; + Ewl_Text_Op *op; + Ewl_Text_Op_Font *opf; + char *font = NULL; DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR_RET("t", t, 0); + DCHECK_PARAM_PTR_RET("ta", ta, NULL); - w = EWL_WIDGET(t); + op = ewl_text_op_relevant_find(ta, EWL_TEXT_OP_TYPE_FONT_SET); + opf = (Ewl_Text_Op_Font *)op; + if (opf && opf->font) { + font = strdup(opf->font); + } - DRETURN_INT(t->font_size, DLEVEL_STABLE); + DRETURN_PTR(font, DLEVEL_STABLE); } /** - * @param t: the text widget to set the color - * @param r: the red value for the color - * @param g: the green value for the color - * @param b: the blue value for the color - * @param a: the alpha value for the color + * @param ta: the text widget to change style + * @param style: the name of the style + * @brief Changes the currently applied style of the text to specified values * @return Returns no value. - * @brief Set the color of the text for a text widget - * - * Sets the color of the text in the text widget @a t to the new color values - * specified. */ -void -ewl_text_set_color(Ewl_Text * t, int r, int g, int b, int a) +void ewl_text_style_set(Ewl_Text *ta, char *style) { - Ewl_Widget *w; + Ewl_Text_Op *op; DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR("t", t); - - w = EWL_WIDGET(t); + DCHECK_PARAM_PTR("ta", ta); - if (t->estyle) - evas_object_color_set(t->estyle, r, g, b, a); - - t->r = r; - t->g = g; - t->b = b; - t->a = a; - t->overrides |= EWL_TEXT_OVERRIDE_COLOR; - - ewl_widget_configure(w); + op = ewl_text_op_style_new(ta, style); + ecore_dlist_append(ta->ops, op); + if (REALIZED(ta)) + ewl_text_ops_apply(ta); DLEAVE_FUNCTION(DLEVEL_STABLE); } /** - * @param t: the text widget to get the color - * @param r: a pointer to the integer to store the red value - * @param g: a pointer to the integer to store the green value - * @param b: a pointer to the integer to store the blue value - * @param a: a pointer to the integer to store the alpha value - * @return Returns no value. - * @brief Get the color of the text in a text widget - * - * Stores the color values into any non-NULL color pointers. + * @param ta: the text widget to get the current style + * @brief Retrieves the currently used text style from a text widget. + * @return Returns the currently used text style. */ -void -ewl_text_get_color(Ewl_Text * t, int *r, int *g, int *b, int *a) +char *ewl_text_style_get(Ewl_Text *ta) { - Ewl_Widget *w; + Ewl_Text_Op *op; + Ewl_Text_Op_Style *ops; + char *style = NULL; DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR("t", t); + DCHECK_PARAM_PTR_RET("ta", ta, NULL); - w = EWL_WIDGET(t); + op = ewl_text_op_relevant_find(ta, EWL_TEXT_OP_TYPE_FONT_SET); + ops = (Ewl_Text_Op_Style *)op; + if (ops && ops->style) { + style = strdup(ops->style); + } - if (!r) - *r = t->r; + DRETURN_PTR(style, DLEVEL_STABLE); +} - if (!g) - *g = t->g; +/** + * @param ta: the text widget to change alignment + * @param align: the new alignment of the text widget + * @brief Changes the currently applied alignment of the text to specified value + * @return Returns no value. + */ +void ewl_text_align_set(Ewl_Text *ta, unsigned int align) +{ + Ewl_Text_Op *op; - if (!b) - *b = t->b; + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("ta", ta); - if (!a) - *a = t->a; + op = ewl_text_op_align_new(ta, align); + ecore_dlist_append(ta->ops, op); + if (REALIZED(ta)) + ewl_text_ops_apply(ta); DLEAVE_FUNCTION(DLEVEL_STABLE); } /** - * @param t: the text widget to set the text style - * @param s: the name of the style to be set for the text - * @brief Set the text style for a text widget - * - * @return Returns no value. - * Changes the text style of the text widget @a t to the style identified by the - * name @a s. + * @param ta: the text widget to get the current alignment + * @brief Retrieves the currently used text alignment from a text widget. + * @return Returns the currently used text alignment. */ -void -ewl_text_set_style(Ewl_Text * t, char *s) +unsigned int ewl_text_align_get(Ewl_Text *ta) { - Ewl_Widget *w; + unsigned int align = 0; + Ewl_Text_Op *op; + Ewl_Text_Op_Align *opa; DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR("t", t); - - w = EWL_WIDGET(t); - t->style = strdup(s); + DCHECK_PARAM_PTR_RET("ta", ta, NULL); - /* - * Change the font for the estyle. - */ - if (t->estyle) { - Evas_Coord x, y, width, height; - - /* - * Change the font and then update the size of the widget - */ - estyle_set_style(t->estyle, t->style); - evas_object_geometry_get(t->estyle, &x, &y, &width, &height); - ewl_object_set_preferred_size(EWL_OBJECT(t), - (int)(width), (int)(height)); + op = ewl_text_op_relevant_find(ta, EWL_TEXT_OP_TYPE_FONT_SET); + opa = (Ewl_Text_Op_Align *)op; + if (opa) { + align = opa->align; } - t->overrides |= EWL_TEXT_OVERRIDE_STYLE; - - ewl_widget_configure(w); - DLEAVE_FUNCTION(DLEVEL_STABLE); + DRETURN_INT(align, DLEVEL_STABLE); } -/** - * @param t: the text widget to retrieve geometry - * @param xx: a pointer to an integer to store the x coordinate - * @param yy: a pointer to an integer to store the y coordinate - * @param ww: a pointer to an integer to store the width - * @param hh: a pointer to an integer to store the height - * @return Returns no value. - * @brief Retrieve the geometry of a text widget - * - * Stores the position and size of the text in the text - * widget @a t into the integers pointed to by @a xx, @a yy, @a ww, and @a hh - * respectively. - */ -void -ewl_text_get_text_geometry(Ewl_Text * t, int *xx, int *yy, int *ww, int *hh) +static Ewl_Text_Op * +ewl_text_op_relevant_find(Ewl_Text *ta, Ewl_Text_Op_Type type) { - Evas_Coord ex, ey, ew, eh; + Ecore_DList *l; + void *(*traverse)(Ecore_DList *l); + Ewl_Text_Op *op = NULL; + DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR("t", t); - /* - * Need to check if the estyle has been created yet, it may won't be if - * the widget has not yet been realized. - */ - if (t->estyle) { - evas_object_geometry_get(t->estyle, &ex, &ey, &ew, &eh); - *xx = (int)(ex); - *yy = (int)(ey); - *ww = (int)(ew); - *hh = (int)(eh); + if (REALIZED(ta)) { + l = ta->applied; + ecore_dlist_goto_first(l); + traverse = ecore_dlist_next; } else { - *xx = CURRENT_X(t); - *yy = CURRENT_Y(t); - *ww = CURRENT_W(t); - *hh = CURRENT_H(t); + l = ta->ops; + ecore_dlist_goto_last(l); + traverse = ecore_dlist_previous; } - DLEAVE_FUNCTION(DLEVEL_STABLE); + while ((op = traverse(ta->ops))) + if (op->type == type) + break; + + DRETURN_PTR(op, DLEVEL_STABLE); } /** - * @brief Retrieve the length of the text in the widget - * @param t: the text widget to retrieve text length - * - * Returns the length of the text enclosed in the widget @a t. + * @param ta: the text widget to map a coordinate to a character index + * @param x: the x coordinate over the desired character + * @param y: the y coordinate over the desired character + * @brief Finds the index of the character under the specified coordinates + * @return Returns the index of the found character on success, 0 otherwise. */ -inline int ewl_text_get_length(Ewl_Text *t) +int ewl_text_coord_index_map(Ewl_Text *ta, int x, int y) { + int index; DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR_RET("t", t, 0); + DCHECK_PARAM_PTR_RET("ta", ta, 0); - DRETURN_INT(t->length, DLEVEL_STABLE); + if (!ta->etox) + DRETURN_INT(0, DLEVEL_STABLE); + + index = etox_coord_to_index(ta->etox, (Evas_Coord)(x), (Evas_Coord)(y)); + DRETURN_INT(index, DLEVEL_STABLE); } /** - * @param t: the widget that holds the text to retrieve a letters geometry - * @param i: the index of the letter in the text to retrieve geometry - * @param xx: a pointer to an integer to store the x coordinate of the letter - * @param yy: a pointer to an integer to store the y coordinate of the letter - * @param ww: a pointer to an integer to store the width of the letter - * @param hh: a pointer to an integer to store the height of the letter + * @param ta: the text widget to map index to character geometry + * @param index: character index to be mapped + * @param x: pointer to store determined character x coordinate + * @param y: pointer to store determined character y coordinate + * @param w: pointer to store determined character width + * @param h: pointer to store determined character height * @return Returns no value. - * @brief Retrieve the geomtry of a specific letter + * @brief Maps a character index to a set of coordinates and sizes. * - * Stores the geometry of the letter at index @a i of the text - * widget @a t into @a xx, @a yy, @a ww, and @a hh respectively. + * Any of the coordinate parameters may be NULL, they will be ignored. If the + * index fails to map successfully, the values at the locations pointed to by + * the coordinate pointers will not be altered. This function can only succeed + * after the text widget has been realized. */ -void -ewl_text_get_letter_geometry(Ewl_Text * t, int i, int *xx, int *yy, - int *ww, int *hh) +void ewl_text_index_geometry_map(Ewl_Text *ta, int index, int *x, int *y, + int *w, int *h) { - Evas_Coord ex = 0, ey = 0, ew = 0, eh = 0; - Ewl_Widget *w; + Evas_Coord tx, ty, tw, th; DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR("t", t); - - w = EWL_WIDGET(t); - - if (t->estyle) { - estyle_text_at(t->estyle, i, &ex, &ey, &ew, &eh); - } + if (!ta->etox) + DRETURN(DLEVEL_STABLE); - if (xx) - *xx = (int)(ex); - if (yy) - *yy = (int)(ey); - if (ww) - *ww = (int)(ew); - if (hh) - *hh = (int)(eh); + etox_index_to_geometry(ta->etox, index, &tx, &ty, &tw, &th); + if (x) + *x = (int)(tx); + if (y) + *y = (int)(ty); + if (w) + *w = (int)(tw); + if (h) + *h = (int)(th); DLEAVE_FUNCTION(DLEVEL_STABLE); } -/** - * @param t: the text widget to get the letter geometry by coordinates - * @param x: the x coordinate to check for letter geometry - * @param y: the y coordinate to check for letter geometry - * @param tx: the x coordinate of the letter that intersects @a x, @a y - * @param ty: the y coordinate of the letter that intersects @a x, @a y - * @param tw: the width of the letter that intersects @a x, @a y - * @param th: the height of the letter that intersects @a x, @a y - * @brief Get the letter geometry at coordinates - * - * @return Returns no value. - * Stores the geometry of a letter at specified coordinates - * @a x, @a y of text widget @a t into @a tx, @a ty, @a tw, and @a th. - */ -int -ewl_text_get_letter_geometry_at(Ewl_Text * t, int x, int y, - int *tx, int *ty, int *tw, int *th) +void ewl_text_realize_cb(Ewl_Widget * w, void *ev_data, void *user_data) { - Evas_Coord ex = 0, ey = 0, ew = 0, eh = 0; - int i = 0; - Ewl_Widget *w; + char *tmp; + Ewl_Text *ta; + Ewl_Embed *emb; + int r, g, b, a; DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR_RET("t", t, 0); + DCHECK_PARAM_PTR("w", w); - w = EWL_WIDGET(t); + ta = EWL_TEXT(w); + /* + * Find the embed so we know which evas to draw onto. + */ + emb = ewl_embed_find_by_widget(w); - if (t->estyle) { - i = estyle_text_at_position(t->estyle, (Evas_Coord)(x), - (Evas_Coord)(y), &ex, &ey, &ew, &eh); - } + /* + * Create the etox + */ + ta->etox = etox_new(emb->evas); + ta->context = etox_get_context(ta->etox); - if (tx) - *tx = (int)(ex); - if (ty) - *ty = (int)(ey); - if (tw) - *tw = (int)(ew); - if (th) - *th = (int)(eh); + tmp = ewl_theme_data_get_str(w, "font"); + etox_context_set_font(ta->context, tmp, + ewl_theme_data_get_int(w, "font_size")); + IF_FREE(tmp); + + tmp = ewl_theme_data_get_str(w, "style"); + etox_context_set_style(ta->context, tmp); + IF_FREE(tmp); + + r = ewl_theme_data_get_int(w, "color/r"); + g = ewl_theme_data_get_int(w, "color/g"); + b = ewl_theme_data_get_int(w, "color/b"); + a = ewl_theme_data_get_int(w, "color/a"); + etox_context_set_color(ta->context, r, g, b, a); - DRETURN_INT(i, DLEVEL_STABLE); + if (w->fx_clip_box) + evas_object_clip_set(ta->etox, w->fx_clip_box); + + /* + * Now set the text and display it. + */ + etox_set_text(ta->etox, ta->text); + evas_object_show(ta->etox); + + ewl_text_ops_apply(ta); + + /* + * Update the size of the text + */ + ewl_text_update_size(ta); + + DLEAVE_FUNCTION(DLEVEL_STABLE); } -/** - * @param t: the text widget to change text alignment - * @param a: the new alignment for the text in @a t - * @return Returns no value. - * @brief Set the alignment of the text in a text widget - * - * Changes the alignment of the text in @a t to @a a. - */ -void -ewl_text_set_alignment(Ewl_Text * t, unsigned int a) +static void ewl_text_ops_apply(Ewl_Text *ta) { + Ewl_Text_Op *op; + + while ((op = ecore_dlist_remove_first(ta->ops))) { + op->apply(ta, op); + ecore_dlist_append(ta->applied, op); + } +} + +static void ewl_text_op_free(void *data) +{ + Ewl_Text_Op *op = data; + if (op->free) + op->free(op); + else + FREE(op) +} + +void ewl_text_unrealize_cb(Ewl_Widget * w, void *ev_data, void *user_data) +{ + Ewl_Text *ta; + DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR("t", t); + DCHECK_PARAM_PTR("w", w); - ewl_object_set_alignment(EWL_OBJECT(t), a); + ta = EWL_TEXT(w); - ewl_widget_configure(EWL_WIDGET(t)); + evas_object_clip_unset(ta->etox); + evas_object_del(ta->etox); DLEAVE_FUNCTION(DLEVEL_STABLE); } -/** - * @param t: the text widget to find the letter index by coordinates - * @param x: the x coordinate to check for the letter index - * @param y: the y coordinate to check for the letter index - * @return Returns the index of the letter at the coordinates. - * @brief Get the index of the letter at coordinates - */ -int -ewl_text_get_index_at(Ewl_Text * t, int x, int y) +void ewl_text_destroy_cb(Ewl_Widget * w, void *ev_data, void *user_data) { - Ewl_Widget *w; + Ewl_Text *ta; DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR_RET("t", t, 0); + DCHECK_PARAM_PTR("w", w); + + ta = EWL_TEXT(w); + ecore_dlist_destroy(ta->ops); + ta->ops = NULL; - w = EWL_WIDGET(t); + ecore_dlist_destroy(ta->applied); + ta->applied = NULL; - DRETURN_INT(t-> - estyle ? estyle_text_at_position(t->estyle, - (Evas_Coord)(x), - (Evas_Coord)(y), - NULL, NULL, NULL, NULL) : - 0, DLEVEL_STABLE); + DLEAVE_FUNCTION(DLEVEL_STABLE); } -void -ewl_text_realize_cb(Ewl_Widget * w, void *ev_data, void *user_data) +void ewl_text_reparent_cb(Ewl_Widget * w, void *ev_data, void *user_data) { - Ewl_Text *t; - Ewl_Embed *emb; - Evas_Coord x, y, width, height; + Ewl_Text *ta; + + DENTER_FUNCTION(DLEVEL_STABLE); + + ta = EWL_TEXT(w); + if (ta->etox) + evas_object_layer_set(ta->etox, ewl_widget_get_layer_sum(w)); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} +void ewl_text_configure_cb(Ewl_Widget * w, void *ev_data, void *user_data) +{ + Ewl_Text *ta; DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("w", w); - t = EWL_TEXT(w); - emb = ewl_embed_find_by_widget(w); - t->estyle = estyle_new(emb->evas, t->text, t->style); + ta = EWL_TEXT(w); /* - * Set the correct font and size. + * Update the etox position and size. */ - if (!t->font) { - /* - * Setup the default font. - */ - t->font = ewl_theme_data_get_str(w, "font"); - t->font_size = ewl_theme_data_get_int(w, "font_size"); + if (ta->etox) { + evas_object_move(ta->etox, CURRENT_X(w), CURRENT_Y(w)); + evas_object_layer_set(ta->etox, ewl_widget_get_layer_sum(w)); } - estyle_set_font(t->estyle, t->font, t->font_size); - - if (!t->style) - t->style = ewl_theme_data_get_str(w, "style"); - - estyle_set_style(t->estyle, t->style); + DLEAVE_FUNCTION(DLEVEL_STABLE); +} - if (!(t->overrides & EWL_TEXT_OVERRIDE_COLOR)) { - t->r = ewl_theme_data_get_int(w, "color/r"); - t->g = ewl_theme_data_get_int(w, "color/g"); - t->b = ewl_theme_data_get_int(w, "color/b"); - t->a = ewl_theme_data_get_int(w, "color/a"); - } +/* + * Set the size of the text area to the size of the etox. + */ +static void ewl_text_update_size(Ewl_Text * ta) +{ + Evas_Coord x, y, width, height; /* - * Set move it into the correct position. + * Adjust the properties of the widget to indicate the size of the text. */ - evas_object_color_set(t->estyle, t->r, t->g, t->b, t->a); + evas_object_geometry_get(ta->etox, &x, &y, &width, &height); + if (!width) + width = 1; + if (!height) + height = 1; /* - * Adjust the clip box for the estyle and then display it. + * Set the preferred size to the size of the etox and request that + * size for the widget. */ - if (w->fx_clip_box) - evas_object_clip_set(t->estyle, w->fx_clip_box); - evas_object_layer_set(t->estyle, ewl_widget_get_layer_sum(w)); - evas_object_show(t->estyle); - - evas_object_geometry_get(t->estyle, &x, &y, &width, &height); - ewl_object_set_preferred_size(EWL_OBJECT(t), (int)(width), + ewl_object_set_preferred_size(EWL_OBJECT(ta), (int)(width), (int)(height)); +} - DLEAVE_FUNCTION(DLEVEL_STABLE); +static Ewl_Text_Op * +ewl_text_op_color_new(Ewl_Text *ta, int r, int g, int b, int a) +{ + Ewl_Text_Op *op; + Ewl_Text_Op_Color *opc; + + DENTER_FUNCTION(DLEVEL_STABLE); + + op = NEW(Ewl_Text_Op_Color, 1); + if (op) { + opc = (Ewl_Text_Op_Color *)op; + op->type = EWL_TEXT_OP_TYPE_COLOR_SET; + op->apply = ewl_text_op_color_apply; + op->free = free; + opc->r = r; + opc->g = g; + opc->b = b; + opc->a = a; + } + + DRETURN_PTR(op, DLEVEL_STABLE); } -void -ewl_text_unrealize_cb(Ewl_Widget * w, void *ev_data, void *user_data) +static void +ewl_text_op_color_apply(Ewl_Text *ta, Ewl_Text_Op *op) { - Ewl_Text *t; + int or, og, ob, oa; + Ewl_Text_Op_Color *opc = (Ewl_Text_Op_Color *)op; DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR("w", w); - t = EWL_TEXT(w); + etox_context_get_color(ta->context, &or, &og, &ob, &oa); + etox_context_set_color(ta->context, opc->r, opc->g, opc->b, opc->a); + + /* + * Store the previous values for undoing. + */ + opc->r = or; + opc->g = og; + opc->b = ob; + opc->a = oa; + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +static Ewl_Text_Op * +ewl_text_op_font_new(Ewl_Text *ta, char *font, int size) +{ + Ewl_Text_Op *op; + Ewl_Text_Op_Font *opf; + + DENTER_FUNCTION(DLEVEL_STABLE); - if (t->estyle) { - ewl_evas_object_destroy(t->estyle); - t->estyle = NULL; + op = NEW(Ewl_Text_Op_Font, 1); + if (op) { + opf = (Ewl_Text_Op_Font *)op; + op->type = EWL_TEXT_OP_TYPE_FONT_SET; + op->apply = ewl_text_op_font_apply; + op->free = ewl_text_op_font_free; + opf->font = strdup(font); + opf->size = size; } - IF_FREE(t->text); - IF_FREE(t->font); + DRETURN_PTR(op, DLEVEL_STABLE); +} + +static void +ewl_text_op_font_apply(Ewl_Text *ta, Ewl_Text_Op *op) +{ + char *of; + int size; + Ewl_Text_Op_Font *opf = (Ewl_Text_Op_Font *)op; + + DENTER_FUNCTION(DLEVEL_STABLE); + + of = etox_context_get_font(ta->context, &size); + + etox_context_set_font(ta->context, opf->font, opf->size); + + FREE(opf->font); + opf->font = of; + opf->size = size; + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +static void +ewl_text_op_font_free(void *op) +{ + Ewl_Text_Op_Font *opf = (Ewl_Text_Op_Font *)op; + DENTER_FUNCTION(DLEVEL_STABLE); + + FREE(opf->font); + FREE(opf); DLEAVE_FUNCTION(DLEVEL_STABLE); } -void -ewl_text_configure_cb(Ewl_Widget * w, void *ev_data, void *user_data) +static Ewl_Text_Op * +ewl_text_op_style_new(Ewl_Text *ta, char *style) { - Ewl_Text *t; + Ewl_Text_Op *op; + Ewl_Text_Op_Style *ops; DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR("w", w); - t = EWL_TEXT(w); + op = NEW(Ewl_Text_Op_Style, 1); + if (op) { + ops = (Ewl_Text_Op_Style *)op; + op->type = EWL_TEXT_OP_TYPE_STYLE_SET; + op->apply = ewl_text_op_style_apply; + op->free = ewl_text_op_style_free; + ops->style = strdup(style); + } + + DRETURN_PTR(op, DLEVEL_STABLE); +} + +static void +ewl_text_op_style_apply(Ewl_Text *ta, Ewl_Text_Op *op) +{ + char *style; + Ewl_Text_Op_Style *ops = (Ewl_Text_Op_Style *)op; + + DENTER_FUNCTION(DLEVEL_STABLE); + + style = etox_context_get_style(ta->context); + etox_context_set_style(ta->context, ops->style); - if (t->estyle) - evas_object_move(t->estyle, CURRENT_X(t), CURRENT_Y(t)); + FREE(ops->style); + ops->style = style; DLEAVE_FUNCTION(DLEVEL_STABLE); } -void -ewl_text_reparent_cb(Ewl_Widget * w, void *ev_data, void *user_data) +static void +ewl_text_op_style_free(void *op) { - Ewl_Text *t; + Ewl_Text_Op_Style *ops = (Ewl_Text_Op_Style *)op; + DENTER_FUNCTION(DLEVEL_STABLE); + + FREE(ops->style); + FREE(ops); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +static Ewl_Text_Op * +ewl_text_op_align_new(Ewl_Text *ta, unsigned int align) +{ + Ewl_Text_Op *op; + Ewl_Text_Op_Align *opa; DENTER_FUNCTION(DLEVEL_STABLE); - DCHECK_PARAM_PTR("w", w); - t = EWL_TEXT(w); + op = NEW(Ewl_Text_Op_Align, 1); + if (op) { + opa = (Ewl_Text_Op_Align *)op; + op->type = EWL_TEXT_OP_TYPE_ALIGN_SET; + op->apply = ewl_text_op_align_apply; + op->free = free; + opa->align = align; + } - if (!t->estyle) - DRETURN(DLEVEL_STABLE); + DRETURN_PTR(op, DLEVEL_STABLE); +} +static void +ewl_text_op_align_apply(Ewl_Text *ta, Ewl_Text_Op *op) +{ + unsigned int align; + Ewl_Text_Op_Align *opa = (Ewl_Text_Op_Align *)op; - if (w->fx_clip_box) - evas_object_clip_set(t->estyle, w->fx_clip_box); - evas_object_layer_set(t->estyle, ewl_widget_get_layer_sum(w)); + DENTER_FUNCTION(DLEVEL_STABLE); + + align = etox_context_get_align(ta->context); + etox_context_set_align(ta->context, opa->align); + + opa->align = align; DLEAVE_FUNCTION(DLEVEL_STABLE); } =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/ewl_text.h,v retrieving revision 1.29 retrieving revision 1.30 diff -u -3 -r1.29 -r1.30 --- ewl_text.h 13 May 2004 06:03:01 -0000 1.29 +++ ewl_text.h 27 May 2004 20:15:17 -0000 1.30 @@ -1,10 +1,10 @@ -#ifndef __EWL_TEXT_H -#define __EWL_TEXT_H +#ifndef __EWL_TEXT_H__ +#define __EWL_TEXT_H__ /** - * @defgroup Ewl_Text Text: A Single Line Text Display - * @brief Defines the Ewl_Text class to provide text display in a single line. + * @defgroup Ewl_Text Text: A Multi-Line Text Layout Display + * @brief Defines a class for multi-line text layout and formatting. * * @{ */ @@ -15,30 +15,31 @@ */ /** - * Inherits from the Ewl_Widget and provides single line text display. + * Provides for layout of text across multiple lines, as well as formatting + * portions of the text in different ways, and wrapping around obstacles. */ typedef struct Ewl_Text Ewl_Text; /** * @def EWL_TEXT(text) - * Typecast a pointer to an Ewl_Text pointer. + * Typecasts a pointer to an Ewl_Text pointer. */ #define EWL_TEXT(text) ((Ewl_Text *) text) /** * @struct Ewl_Text - * Inherit from the Ewl_Widget and extend to provide single line text display - * capabilities. + * Inherits from the Ewl_Widget class and extends it to provide for multi-line + * text layout, obstacle wrapping, and a variety of formatting. */ struct Ewl_Text { - Ewl_Widget widget; /**< Inherit from Ewl_Widget */ - Evas_Object *etox; /**< Pointer to etox displaying text */ - - char *text; /**< The text contents of the estyle */ - int length; /**< Length of the text in the estyle */ - Etox_Context *context; /**< Context holding text properties */ - int overrides; /**< Bitmask of programmer set properties */ + Ewl_Widget widget; /**< Inherit from Ewl_Widget */ + char *text; /**< The initial text in the text */ + int length; /**< Length of the text displayed */ + Evas_Object *etox; /**< Etox does the actual layout work */ + Etox_Context *context; /**< Contains various format settings */ + Ecore_DList *ops; /**< Series of operations to apply */ + Ecore_DList *applied; /**< Applied set of operations */ }; typedef enum @@ -47,42 +48,124 @@ EWL_TEXT_OVERRIDE_FONT = 0x2, EWL_TEXT_OVERRIDE_SIZE = 0x4, EWL_TEXT_OVERRIDE_STYLE = 0x8, -} EWL_TEXT_OVERRIDES; +} Ewl_Text_Overrides; -Ewl_Widget *ewl_text_new(char *text); -void ewl_text_init(Ewl_Text * t, char *text); +/** + * @enum Ewl_Text_Ops + * Provides a series of operations that can be performed on the text. + */ +typedef enum +{ + EWL_TEXT_OP_TYPE_COLOR_SET, + EWL_TEXT_OP_TYPE_FONT_SET, + EWL_TEXT_OP_TYPE_STYLE_SET, + EWL_TEXT_OP_TYPE_ALIGN_SET, + EWL_TEXT_OP_TYPE_SELECT, + EWL_TEXT_OP_TYPE_TEXT_PREPEND, + EWL_TEXT_OP_TYPE_TEXT_APPEND, + EWL_TEXT_OP_TYPE_TEXT_INSERT, +} Ewl_Text_Op_Type; -void ewl_text_set_text(Ewl_Text * t, char *text); -char *ewl_text_get_text(Ewl_Text * t); -void ewl_text_set_font(Ewl_Text * t, char *font); -char *ewl_text_get_font(Ewl_Text * t); -void ewl_text_set_font_size(Ewl_Text * t, int size); -int ewl_text_get_font_size(Ewl_Text * t); -void ewl_text_set_color(Ewl_Text * t, int r, int g, int b, int a); -void ewl_text_get_color(Ewl_Text * t, int *r, int *g, int *b, - int *a); -void ewl_text_get_text_geometry(Ewl_Text * t, int *xx, int *yy, - int *ww, int *hh); -inline int ewl_text_get_length(Ewl_Text *t); -void ewl_text_set_style(Ewl_Text * t, char *s); -void ewl_text_get_letter_geometry(Ewl_Text * t, int index, int *xx, - int *yy, int *ww, int *hh); -int ewl_text_get_letter_geometry_at(Ewl_Text * t, int x, int y, - int *tx, int *ty, int *tw, - int *th); -void ewl_text_set_alignment(Ewl_Text * t, unsigned int a); -int ewl_text_get_index_at(Ewl_Text * t, int x, int y); +typedef struct Ewl_Text_Op Ewl_Text_Op; +struct Ewl_Text_Op +{ + Ewl_Text_Op_Type type; + void (*apply)(Ewl_Text *ta, Ewl_Text_Op *op); + void (*free)(void *); +}; + +typedef struct Ewl_Text_Op_Color Ewl_Text_Op_Color; +struct Ewl_Text_Op_Color +{ + Ewl_Text_Op op; + int r, g, b, a; +}; + +typedef struct Ewl_Text_Op_Font Ewl_Text_Op_Font; +struct Ewl_Text_Op_Font +{ + Ewl_Text_Op op; + char *font; + int size; +}; + +typedef struct Ewl_Text_Op_Style Ewl_Text_Op_Style; +struct Ewl_Text_Op_Style +{ + Ewl_Text_Op op; + char *style; +}; + +typedef struct Ewl_Text_Op_Align Ewl_Text_Op_Align; +struct Ewl_Text_Op_Align +{ + Ewl_Text_Op op; + unsigned int align; +}; + +typedef struct Ewl_Text_Op_Select Ewl_Text_Op_Select; +struct Ewl_Text_Op_Select +{ + Ewl_Text_Op op; + Evas_Coord sx, sy, ex, ey; + int si, ei; + char *match; + int index; +}; + +typedef struct Ewl_Text_Op_Text Ewl_Text_Op_Text; +struct Ewl_Text_Op_Text +{ + Ewl_Text_Op op; + char *text; + int index; +}; + +Ewl_Widget *ewl_text_new(char *text); +void ewl_text_init(Ewl_Text * ta, char *text); + +void ewl_text_text_set(Ewl_Text * ta, char *text); +void ewl_text_text_prepend(Ewl_Text * ta, char *text); +void ewl_text_text_append(Ewl_Text * ta, char *text); +void ewl_text_text_insert(Ewl_Text * ta, char *text, int index); +char *ewl_text_text_get(Ewl_Text * ta); + +int ewl_text_length_get(Ewl_Text *ta); + +void ewl_text_font_set(Ewl_Text *ta, char *font, int size); +char *ewl_text_font_get(Ewl_Text *ta); +int ewl_text_font_size_get(Ewl_Text *ta); + +void ewl_text_style_set(Ewl_Text *ta, char *style); +char *ewl_text_style_get(Ewl_Text *ta); + +void ewl_text_color_set(Ewl_Text *ta, int r, int g, int b, int a); +void ewl_text_color_get(Ewl_Text *ta, int *r, int *g, int *b, int *a); + +void ewl_text_align_set(Ewl_Text *ta, unsigned int align); +unsigned int ewl_text_align_get(Ewl_Text *ta); + +void ewl_text_index_select(Ewl_Text *ta, int si, int ei); +void ewl_text_coord_select(Ewl_Text *ta, int sx, int sy, int ex, + int ey); + +void ewl_text_index_geometry_map(Ewl_Text *ta, int index, int *xx, + int *yy, int *ww, int *hh); +int ewl_text_coord_index_map(Ewl_Text *ta, int x, int y); +int ewl_text_coord_geometry_map(Ewl_Text *ta, int x, int y, int *xx, + int *yy, int *ww, int *hh); /* * Internally used callbacks, override at your own risk. */ void ewl_text_realize_cb(Ewl_Widget * w, void *ev_data, void *user_data); void ewl_text_unrealize_cb(Ewl_Widget * w, void *ev_data, void *user_data); -void ewl_text_configure_cb(Ewl_Widget * w, void *ev_data, void *user_data); +void ewl_text_destroy_cb(Ewl_Widget * w, void *ev_data, void *user_data); void ewl_text_reparent_cb(Ewl_Widget * w, void *ev_data, void *user_data); +void ewl_text_configure_cb(Ewl_Widget * w, void *ev_data, void *user_data); /** * @} */ -#endif +#endif /* __EWL_TEXT_H__ */ |