From 9898a8253d5236a949b125eeabf590d93d4adfe6 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Fri, 15 Mar 2002 14:18:35 +0000 Subject: Ajustement des ressources couleurs pour tenir compte de la g�n�ralisation des gradients. Mise en facteur du code calculant le curseur et la selection. Premiere �tape vers le support GL. Suppression du inset. --- generic/Text.c | 118 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 71 insertions(+), 47 deletions(-) (limited to 'generic/Text.c') diff --git a/generic/Text.c b/generic/Text.c index e506794..e9bae13 100644 --- a/generic/Text.c +++ b/generic/Text.c @@ -188,7 +188,7 @@ Init(Item item, text->fill_pattern = ZnUnspecifiedPattern; text->anchor = ZnAnchorNW; text->connection_anchor = ZnAnchorSW; - text->color = ZnGetGradientByValue(wi->fore_gradient); + text->color = ZnGetGradientByValue(wi->fore_color); text->alignment = ZnJustifyLeft; text->font = Tk_GetFont(wi->interp, wi->win, Tk_NameOfFont(wi->font)); text->width = 0; @@ -564,41 +564,26 @@ ToArea(Item item, return inside; } - /* -********************************************************************************** - * - * Draw -- - * - ********************************************************************************** + * Compute the selection and the cursor geometry. */ static void -Draw(Item item) -{ - WidgetInfo *wi = item->wi; +ComputeCursorAndSel(Item item, + TextLineInfo lines, + int num_lines, + int *sel_first_line, + int *sel_last_line, + int *cursor_line, + int *sel_start_offset, + int *sel_stop_offset, + int *cursor_offset) +{ TextItem text = (TextItem) item; - XGCValues values; - int gc_mask = 0; - Tk_FontMetrics fm; - int font_height; - int num_lines, i, line_index, char_index; - TextLineInfo lines, lines_ptr; - int underline_thickness, underline_pos=0, overstrike_pos=0; - int sel_first_line=-1, sel_last_line=-1, cursor_line=-1; - int sel_start_offset=0, sel_stop_offset=0, cursor_offset=0; + WidgetInfo *wi = item->wi; + TextLineInfo lines_ptr; + int i, line_index, char_index; - if (!text->text_info) { - return; - } - lines = (TextLineInfo) ZnListArray(text->text_info); - num_lines = ZnListSize(text->text_info); - Tk_GetFontMetrics(text->font, &fm); - font_height = fm.ascent+fm.descent; - - /* - * Compute the selection and the cursor geometry. - */ for (i = 0, lines_ptr = lines; i < num_lines; i++, lines_ptr++) { /* * Mark the line with the cursor and compute its @@ -608,11 +593,11 @@ Draw(Item item) if ((wi->text_info.focus_item == item) && wi->text_info.got_focus && text->insert_index >= line_index && text->insert_index <= line_index + lines_ptr->num_chars) { - cursor_line = i; - cursor_offset = Tk_TextWidth(text->font, (char *) lines_ptr->start, - text->insert_index - line_index); + *cursor_line = i; + *cursor_offset = Tk_TextWidth(text->font, (char *) lines_ptr->start, + text->insert_index - line_index); } - + /* * Compute the selection first and last line as well as * the positions along the X axis. @@ -620,27 +605,66 @@ Draw(Item item) if ((wi->text_info.sel_item == item) && (wi->text_info.sel_last >= line_index) && (wi->text_info.sel_first <= (line_index + lines_ptr->num_chars))) { - if (sel_first_line < 0) { + if (*sel_first_line < 0) { char_index = wi->text_info.sel_first - line_index; if (char_index <= 0) { - sel_first_line = i; - sel_start_offset = 0; - /*printf("sel_start_offset 1 : %d\n", sel_start_offset);*/ + *sel_first_line = i; + *sel_start_offset = 0; + /*printf("sel_start_offset 1 : %d\n", *sel_start_offset);*/ } else if (char_index <= lines_ptr->num_chars) { - sel_first_line = i; - sel_start_offset = Tk_TextWidth(text->font, (char *) lines_ptr->start, char_index); - /*printf("sel_start_offset 2 : %d\n", sel_start_offset);*/ + *sel_first_line = i; + *sel_start_offset = Tk_TextWidth(text->font, (char *) lines_ptr->start, char_index); + /*printf("sel_start_offset 2 : %d\n", *sel_start_offset);*/ } } char_index = wi->text_info.sel_last - line_index; - sel_last_line = i; + *sel_last_line = i; if (char_index == lines_ptr->num_chars+1) - sel_stop_offset = lines_ptr->width; + *sel_stop_offset = lines_ptr->width; else if (char_index <= lines_ptr->num_chars) - sel_stop_offset = Tk_TextWidth(text->font, (char *) lines_ptr->start, char_index); + *sel_stop_offset = Tk_TextWidth(text->font, (char *) lines_ptr->start, char_index); } } +} + +/* + ********************************************************************************** + * + * Draw -- + * + ********************************************************************************** + */ +static void +Draw(Item item) +{ + WidgetInfo *wi = item->wi; + TextItem text = (TextItem) item; + XGCValues values; + int gc_mask = 0; + Tk_FontMetrics fm; + int font_height; + int num_lines, i; + TextLineInfo lines, lines_ptr; + int underline_thickness, underline_pos=0, overstrike_pos=0; + int sel_first_line=-1, sel_last_line=-1, cursor_line=-1; + int sel_start_offset=0, sel_stop_offset=0, cursor_offset=0; + + if (!text->text_info) { + return; + } + lines = (TextLineInfo) ZnListArray(text->text_info); + num_lines = ZnListSize(text->text_info); + Tk_GetFontMetrics(text->font, &fm); + font_height = fm.ascent+fm.descent; + + /* + * Compute the selection and the cursor geometry. + */ + ComputeCursorAndSel(item, lines, num_lines, + &sel_first_line, &sel_last_line, + &cursor_line, &sel_start_offset, + &sel_stop_offset, &cursor_offset); /*printf("sel 1st : %d offset : %d, sel last : %d offset : %d\n", sel_first_line, sel_start_offset, sel_last_line, sel_stop_offset);*/ @@ -650,7 +674,7 @@ Draw(Item item) if ((wi->text_info.sel_item == item) && (sel_first_line >= 0)) { int x, y; - values.foreground = ZnPixel(wi->text_info.sel_color); + values.foreground = ZnPixel(ZnGetGradientColor(wi->text_info.sel_color, 0, NULL)); values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCForeground, &values); @@ -692,7 +716,7 @@ Draw(Item item) values.fill_style = FillSolid; values.line_width = wi->text_info.insert_width; - values.foreground = ZnPixel(wi->text_info.insert_color); + values.foreground = ZnPixel(ZnGetGradientColor(wi->text_info.insert_color, 0, NULL)); XChangeGC(wi->dpy, wi->gc, GCForeground|GCFillStyle|GCLineWidth, &values); xs = (int)(text->pos_dev.x + lines[cursor_line].text_origin.x + cursor_offset); @@ -1106,7 +1130,7 @@ Index(Item item, /*y = (int) ((tmp < 0) ? tmp - 0.5 : tmp + 0.5);*/ y = tmp; - *index = PointToChar(item, x-wi->inset, y-wi->inset); + *index = PointToChar(item, x, y); } else if (Tcl_GetIntFromObj(wi->interp, index_spec, index) == TCL_OK) { if (*index < 0){ -- cgit v1.1