From 3261805fee19e346b4d1f84b23816daa1628764a Mon Sep 17 00:00:00 2001 From: lecoanet Date: Wed, 16 Apr 2003 09:49:22 +0000 Subject: Update from the Windows port and general cleanup/restructure --- generic/Text.c | 474 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 240 insertions(+), 234 deletions(-) (limited to 'generic/Text.c') diff --git a/generic/Text.c b/generic/Text.c index e0dfd00..047354e 100644 --- a/generic/Text.c +++ b/generic/Text.c @@ -36,7 +36,6 @@ #include #include #include -#include #include #include @@ -70,34 +69,34 @@ static const char compile_id[] = "$Compile: " __FILE__ " " __DATE__ " " __TIME__ typedef struct _TextLineInfo { char *start; /* Index of first char in line */ - int num_bytes; /* Number of displayed bytes in line (NOT chars)*/ + unsigned int num_bytes; /* Number of displayed bytes in line (NOT chars)*/ ZnPoint text_origin; /* X pos for drawing the line */ - int width; /* Line width in pixels */ + unsigned int width; /* Line width in pixels */ } TextLineInfoStruct, *TextLineInfo; typedef struct _TextItemStruct { - ItemStruct header; + ZnItemStruct header; /* Public data */ ZnPoint pos; - ZnAnchor anchor; - ZnAnchor connection_anchor; + Tk_Anchor anchor; + Tk_Anchor connection_anchor; ZnGradient *color; char *text; ZnImage fill_pattern; - ZnFont font; - ZnJustify alignment; - ZnDim width; - ZnDim spacing; + Tk_Font font; + Tk_Justify alignment; + unsigned int width; + unsigned int spacing; unsigned short flags; /* Private data */ ZnPoint pos_dev; - int num_chars; - int insert_index; + unsigned int num_chars; + unsigned int insert_index; ZnList text_info; - int max_width; -#ifdef GLX + unsigned int max_width; +#ifdef GL ZnTexFontInfo *tfi; #endif } TextItemStruct, *TextItem; @@ -112,13 +111,13 @@ static ZnAttrConfig text_attrs[] = { { ZN_CONFIG_GRADIENT, "-color", NULL, Tk_Offset(TextItemStruct, color), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composealpha", NULL, - Tk_Offset(TextItemStruct, header.flags), COMPOSE_ALPHA_BIT, + Tk_Offset(TextItemStruct, header.flags), ZN_COMPOSE_ALPHA_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, - Tk_Offset(TextItemStruct, header.flags), COMPOSE_ROTATION_BIT, + Tk_Offset(TextItemStruct, header.flags), ZN_COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-composescale", NULL, - Tk_Offset(TextItemStruct, header.flags), COMPOSE_SCALE_BIT, + Tk_Offset(TextItemStruct, header.flags), ZN_COMPOSE_SCALE_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_ITEM, "-connecteditem", NULL, Tk_Offset(TextItemStruct, header.connected_item), 0, @@ -138,9 +137,9 @@ static ZnAttrConfig text_attrs[] = { Tk_Offset(TextItemStruct, header.priority), 0, ZN_DRAW_FLAG|ZN_REPICK_FLAG, False }, { ZN_CONFIG_BOOL, "-sensitive", NULL, - Tk_Offset(TextItemStruct, header.flags), SENSITIVE_BIT, + Tk_Offset(TextItemStruct, header.flags), ZN_SENSITIVE_BIT, ZN_REPICK_FLAG, False }, - { ZN_CONFIG_DIM, "-spacing", NULL, + { ZN_CONFIG_INT, "-spacing", NULL, Tk_Offset(TextItemStruct, spacing), 0, ZN_COORDS_FLAG|ZN_LAYOUT_FLAG, False }, { ZN_CONFIG_TAG_LIST, "-tags", NULL, @@ -151,13 +150,13 @@ static ZnAttrConfig text_attrs[] = { { ZN_CONFIG_BOOL, "-underlined", NULL, Tk_Offset(TextItemStruct, flags), UNDERLINED, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-visible", NULL, - Tk_Offset(TextItemStruct, header.flags), VISIBLE_BIT, + Tk_Offset(TextItemStruct, header.flags), ZN_VISIBLE_BIT, ZN_DRAW_FLAG|ZN_REPICK_FLAG|ZN_VIS_FLAG, False }, - { ZN_CONFIG_DIM, "-width", NULL, + { ZN_CONFIG_INT, "-width", NULL, Tk_Offset(TextItemStruct, width), 0, ZN_COORDS_FLAG|ZN_LAYOUT_FLAG, False }, - { ZN_CONFIG_END, NULL, NULL, 0, 0, 0 } + { ZN_CONFIG_END, NULL, NULL, 0, 0, 0, False } }; @@ -169,33 +168,33 @@ static ZnAttrConfig text_attrs[] = { ********************************************************************************** */ static int -Init(Item item, - int *argc, - Tcl_Obj *CONST *args[]) +Init(ZnItem item, + int *argc __unused, + Tcl_Obj *CONST *args[] __unused) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; TextItem text = (TextItem) item; text->text_info = NULL; /* Init attributes */ - SET(item->flags, VISIBLE_BIT); - SET(item->flags, SENSITIVE_BIT); - SET(item->flags, COMPOSE_ALPHA_BIT); - SET(item->flags, COMPOSE_ROTATION_BIT); - SET(item->flags, COMPOSE_SCALE_BIT); - item->priority = DEFAULT_TEXT_PRIORITY; + SET(item->flags, ZN_VISIBLE_BIT); + SET(item->flags, ZN_SENSITIVE_BIT); + SET(item->flags, ZN_COMPOSE_ALPHA_BIT); + SET(item->flags, ZN_COMPOSE_ROTATION_BIT); + SET(item->flags, ZN_COMPOSE_SCALE_BIT); + item->priority = 1; text->pos.x = text->pos.y = 0.0; text->text = NULL; text->num_chars = 0; text->fill_pattern = ZnUnspecifiedImage; - text->anchor = ZnAnchorNW; - text->connection_anchor = ZnAnchorSW; + text->anchor = TK_ANCHOR_NW; + text->connection_anchor = TK_ANCHOR_SW; text->color = ZnGetGradientByValue(wi->fore_color); - text->alignment = ZnJustifyLeft; + text->alignment = TK_JUSTIFY_LEFT; text->font = Tk_GetFont(wi->interp, wi->win, Tk_NameOfFont(wi->font)); -#ifdef GLX +#ifdef GL text->tfi = NULL; if (wi->render) { text->tfi = ZnGetTexFont(wi, text->font); @@ -207,7 +206,7 @@ Init(Item item, CLEAR(text->flags, UNDERLINED); CLEAR(text->flags, OVERSTRIKED); - return ZN_OK; + return TCL_OK; } @@ -219,10 +218,10 @@ Init(Item item, ********************************************************************************** */ static void -Clone(Item item) +Clone(ZnItem item) { TextItem text = (TextItem) item; - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; char *str; if (text->text) { @@ -235,7 +234,7 @@ Clone(Item item) } text->color = ZnGetGradientByValue(text->color); text->font = Tk_GetFont(wi->interp, wi->win, Tk_NameOfFont(text->font)); -#ifdef GLX +#ifdef GL if (wi->render) { text->tfi = ZnGetTexFont(wi, text->font); } @@ -248,7 +247,7 @@ Clone(Item item) * text_info. */ text->text_info = NULL; - ITEM.Invalidate(item, ZN_COORDS_FLAG|ZN_LAYOUT_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG|ZN_LAYOUT_FLAG); } @@ -260,7 +259,7 @@ Clone(Item item) ********************************************************************************** */ static void -Destroy(Item item) +Destroy(ZnItem item) { TextItem text = (TextItem) item; @@ -273,7 +272,7 @@ Destroy(Item item) } ZnFreeGradient(text->color); Tk_FreeFont(text->font); -#ifdef GLX +#ifdef GL if (text->tfi) { ZnFreeTexFont(text->tfi); } @@ -293,24 +292,24 @@ Destroy(Item item) ********************************************************************************** */ static int -Configure(Item item, +Configure(ZnItem item, int argc, Tcl_Obj *CONST argv[], int *flags) { TextItem text = (TextItem) item; - Item old_connected = item->connected_item; - int num_chars; -#ifdef GLX - ZnFont old_font = text->font; + ZnItem old_connected = item->connected_item; + unsigned int num_chars; +#ifdef GL + Tk_Font old_font = text->font; #endif if (ZnConfigureAttributes(item->wi, item, text_attrs, - argc, argv, flags) == ZN_ERROR) { - return ZN_ERROR; + argc, argv, flags) == TCL_ERROR) { + return TCL_ERROR; } -#ifdef GLX +#ifdef GL if (old_font != text->font) { if (text->tfi) { ZnFreeTexFont(text->tfi); @@ -318,30 +317,30 @@ Configure(Item item, if (item->wi->render) { text->tfi = ZnGetTexFont(item->wi, text->font); if (!text->tfi) { - return ZN_ERROR; + return TCL_ERROR; } } } #endif num_chars = 0; if (text->text) { - num_chars = Tcl_NumUtfChars(text->text, strlen(text->text)); + num_chars = Tcl_NumUtfChars(text->text, (int) strlen(text->text)); } if (text->num_chars != num_chars) { - TextInfo *ti = &item->wi->text_info; + ZnTextInfo *ti = &item->wi->text_info; /* * The text has changed, update the selection and * insertion pos to keep them valid. */ if (item == ti->sel_item) { - if (ti->sel_last > num_chars) { + if (ti->sel_last > (int) num_chars) { ti->sel_last = num_chars; } if (ti->sel_first >= ti->sel_last) { ti->sel_item = ZN_NO_ITEM; ti->sel_field = ZN_NO_PART; } - if ((ti->anchor_item == item) && (ti->sel_anchor > num_chars)) { + if ((ti->anchor_item == item) && (ti->sel_anchor > (int) num_chars)) { ti->sel_anchor = num_chars; } } @@ -359,14 +358,14 @@ Configure(Item item, if ((item->connected_item == ZN_NO_ITEM) || (item->connected_item->class->has_anchors && (item->parent == item->connected_item->parent))) { - ITEM.UpdateItemDependency(item, old_connected); + ZnITEM.UpdateItemDependency(item, old_connected); } else { item->connected_item = old_connected; } } - return ZN_OK; + return TCL_OK; } @@ -378,15 +377,15 @@ Configure(Item item, ********************************************************************************** */ static int -Query(Item item, - int argc, +Query(ZnItem item, + int argc __unused, Tcl_Obj *CONST argv[]) { - if (ZnQueryAttribute(item->wi, item, text_attrs, argv[0]) == ZN_ERROR) { - return ZN_ERROR; + if (ZnQueryAttribute(item->wi, item, text_attrs, argv[0]) == TCL_ERROR) { + return TCL_ERROR; } - return ZN_OK; + return TCL_OK; } @@ -398,10 +397,10 @@ Query(Item item, ********************************************************************************** */ static void -ComputeCoordinates(Item item, - ZnBool force) +ComputeCoordinates(ZnItem item, + ZnBool force __unused) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; TextItem text = (TextItem) item; TextLineInfo infos; Tk_FontMetrics fm; @@ -409,7 +408,7 @@ ComputeCoordinates(Item item, int cur_dy; int font_height, height; - ResetBBox(&item->item_bounding_box); + ZnResetBBox(&item->item_bounding_box); Tk_GetFontMetrics(text->font, &fm); font_height = fm.ascent+fm.descent; @@ -419,8 +418,8 @@ ComputeCoordinates(Item item, * or rotated. */ if (ISSET(item->inv_flags, ZN_LAYOUT_FLAG)) { - char *scan; - int wrap, prev_num_lines; + char *scan; + int wrap, prev_num_lines; text->max_width = 0; if (text->text_info != NULL) { @@ -493,13 +492,13 @@ ComputeCoordinates(Item item, for (i = 0; i < num_lines; i++) { switch (text->alignment) { - case ZnJustifyLeft: + case TK_JUSTIFY_LEFT: infos[i].text_origin.x = 0; break; - case ZnJustifyCenter: + case TK_JUSTIFY_CENTER: infos[i].text_origin.x = (text->max_width + 1 - infos[i].width)/2; break; - case ZnJustifyRight: + case TK_JUSTIFY_RIGHT: infos[i].text_origin.x = text->max_width + 1 - infos[i].width; break; } @@ -529,19 +528,19 @@ ComputeCoordinates(Item item, } else { ZnTransformPoint(wi->current_transfo, &text->pos, &text->pos_dev); - text->pos_dev.x = REAL_TO_INT(text->pos_dev.x); - text->pos_dev.y = REAL_TO_INT(text->pos_dev.y); + text->pos_dev.x = ZnNearestInt(text->pos_dev.x); + text->pos_dev.y = ZnNearestInt(text->pos_dev.y); } - Anchor2Origin(&text->pos_dev, text->max_width, height, text->anchor, - &text->pos_dev); + ZnAnchor2Origin(&text->pos_dev, (ZnReal) text->max_width, (ZnReal) height, text->anchor, + &text->pos_dev); /* * Compute the bounding box. */ - AddPointToBBox(&item->item_bounding_box, text->pos_dev.x, text->pos_dev.y); - AddPointToBBox(&item->item_bounding_box, text->pos_dev.x+text->max_width+1, - text->pos_dev.y+height); + ZnAddPointToBBox(&item->item_bounding_box, text->pos_dev.x, text->pos_dev.y); + ZnAddPointToBBox(&item->item_bounding_box, text->pos_dev.x+text->max_width+1, + text->pos_dev.y+height); fuzz = 1+(wi->text_info.insert_width/2); item->item_bounding_box.orig.x -= fuzz; item->item_bounding_box.orig.y -= fuzz; @@ -551,7 +550,7 @@ ComputeCoordinates(Item item, /* * Update connected items. */ - SET(item->flags, UPDATE_DEPENDENT_BIT); + SET(item->flags, ZN_UPDATE_DEPENDENT_BIT); } @@ -565,7 +564,7 @@ ComputeCoordinates(Item item, ********************************************************************************** */ static int -ToArea(Item item, +ToArea(ZnItem item, ZnToArea ta) { TextItem text = (TextItem) item; @@ -592,20 +591,20 @@ ToArea(Item item, /*printf("text %d, num lines=%d\n", item->id, num_lines);*/ for (i = 0, lines_ptr = lines; i < num_lines; i++, lines_ptr++) { - ResetBBox(&line_bbox); + ZnResetBBox(&line_bbox); o.x = text->pos_dev.x + lines_ptr->text_origin.x; o.y = text->pos_dev.y + lines_ptr->text_origin.y - fm.ascent; - AddPointToBBox(&line_bbox, o.x, o.y); - AddPointToBBox(&line_bbox, o.x + lines_ptr->width, o.y + font_height); + ZnAddPointToBBox(&line_bbox, o.x, o.y); + ZnAddPointToBBox(&line_bbox, o.x + lines_ptr->width, o.y + font_height); if (!first_done) { first_done = True; - inside = BBoxInBBox(&line_bbox, area); + inside = ZnBBoxInBBox(&line_bbox, area); if (inside == 0) { return 0; } } else { - if (BBoxInBBox(&line_bbox, area) == 0) { + if (ZnBBoxInBBox(&line_bbox, area) == 0) { return 0; } } @@ -618,28 +617,28 @@ ToArea(Item item, * Compute the selection and the cursor geometry. */ static void -ComputeCursorAndSel(Item item, +ComputeCursorAndSel(ZnItem item, TextLineInfo lines, - int num_lines, + unsigned 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) + unsigned int *sel_start_offset, + unsigned int *sel_stop_offset, + unsigned int *cursor_offset) { TextItem text = (TextItem) item; - WidgetInfo *wi = item->wi; - TextInfo *ti = &wi->text_info; + ZnWInfo *wi = item->wi; + ZnTextInfo *ti = &wi->text_info; TextLineInfo lines_ptr; - int i, line_index, byte_index; - int insert_index, sel_first, sel_last; + unsigned int i, line_index, byte_index; + unsigned int insert_index, sel_first, sel_last; if (num_lines == 0) { *cursor_line = 0; } - if ((wi->focus_item == item) && wi->got_focus && ti->cursor_on) { - insert_index = Tcl_UtfAtIndex(text->text, text->insert_index)-text->text; + if ((wi->focus_item == item) && ISSET(wi->flags, ZN_GOT_FOCUS) && ti->cursor_on) { + insert_index = Tcl_UtfAtIndex(text->text, (int) text->insert_index)-text->text; for (i = 0, lines_ptr = lines; i < num_lines; i++, lines_ptr++) { /* * Mark the line with the cursor and compute its @@ -700,20 +699,20 @@ ComputeCursorAndSel(Item item, ********************************************************************************** */ static void -Draw(Item item) +Draw(ZnItem item) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; TextItem text = (TextItem) item; XGCValues values; - int gc_mask = 0; + unsigned int gc_mask = 0; Tk_FontMetrics fm; - int font_height; + unsigned int font_height; int num_lines, i; TextLineInfo lines, lines_ptr; - TextInfo *ti = &wi->text_info; - int underline_thickness, underline_pos=0, overstrike_pos=0; + ZnTextInfo *ti = &wi->text_info; + unsigned 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; + unsigned int sel_start_offset=0, sel_stop_offset=0, cursor_offset=0; if (!text->text_info || !text->text) { return; @@ -739,7 +738,7 @@ Draw(Item item) if ((ti->sel_item == item) && (sel_first_line >= 0)) { int x, y; - values.foreground = ZnPixel(ZnGetGradientColor(ti->sel_color, 0, NULL)); + values.foreground = ZnPixel(ZnGetGradientColor(ti->sel_color, 0.0, NULL)); values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, GCFillStyle | GCForeground, &values); @@ -754,7 +753,7 @@ Draw(Item item) y = (int)(text->pos_dev.y + lines[sel_first_line].text_origin.y - fm.ascent); XFillRectangle(wi->dpy, wi->draw_buffer, wi->gc, x, y, - text->max_width-lines[sel_first_line].text_origin.x-sel_start_offset, + text->max_width-(int)lines[sel_first_line].text_origin.x-sel_start_offset, font_height); for (i = sel_first_line+1, lines_ptr = &lines[sel_first_line+1]; i < sel_last_line; i++, lines_ptr++) { @@ -766,7 +765,7 @@ Draw(Item item) x = (int)text->pos_dev.x; y = (int)(text->pos_dev.y + lines[sel_last_line].text_origin.y - fm.ascent); XFillRectangle(wi->dpy, wi->draw_buffer, wi->gc, - x, y, lines[sel_last_line].text_origin.x+sel_stop_offset, + x, y, (int)lines[sel_last_line].text_origin.x+sel_stop_offset, font_height); } } @@ -781,23 +780,23 @@ Draw(Item item) values.fill_style = FillSolid; values.line_width = ti->insert_width; - values.foreground = ZnPixel(ZnGetGradientColor(ti->insert_color, 0, NULL)); + values.foreground = ZnPixel(ZnGetGradientColor(ti->insert_color, 0.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); ys = (int)(text->pos_dev.y + lines[cursor_line].text_origin.y - fm.ascent + 1); - XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, xs, ys, xs, ys + font_height - 1); + XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, xs, ys, xs, ys + (int) font_height - 1); } /* * Setup the gc to render the text and draw it. */ - values.font = ZnFontId(text->font); - values.foreground = ZnPixel(ZnGetGradientColor(text->color, 0, NULL)); + values.font = Tk_FontId(text->font); + values.foreground = ZnPixel(ZnGetGradientColor(text->color, 0.0, NULL)); gc_mask = GCFont | GCForeground; if (text->fill_pattern != ZnUnspecifiedImage) { values.fill_style = FillStippled; - values.stipple = ZnImagePixmap(text->fill_pattern, NULL); + values.stipple = ZnImagePixmap(text->fill_pattern); gc_mask |= GCFillStyle | GCStipple; } else { @@ -824,19 +823,19 @@ Draw(Item item) tmp_x = (int)(text->pos_dev.x + lines_ptr->text_origin.x); tmp_y = (int)(text->pos_dev.y + lines_ptr->text_origin.y); Tk_DrawChars(wi->dpy, wi->draw_buffer, wi->gc, - text->font, (char *) lines_ptr->start, lines_ptr->num_bytes, - tmp_x, tmp_y); + text->font, (char *) lines_ptr->start, + (int) lines_ptr->num_bytes, tmp_x, tmp_y); if (ISSET(text->flags, UNDERLINED)) { int y_under = tmp_y + underline_pos; XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, - tmp_x, y_under, tmp_x+lines_ptr->width, y_under); + tmp_x, y_under, tmp_x + (int) lines_ptr->width, y_under); } if (ISSET(text->flags, OVERSTRIKED)) { int y_over = tmp_y-overstrike_pos; XDrawLine(wi->dpy, wi->draw_buffer, wi->gc, - tmp_x, y_over, tmp_x+lines_ptr->width, y_over); + tmp_x, y_over, tmp_x + (int) lines_ptr->width, y_over); } } } @@ -849,17 +848,17 @@ Draw(Item item) * ********************************************************************************** */ +#ifdef GL static void -Render(Item item) +Render(ZnItem item) { -#ifdef GLX - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; TextItem text = (TextItem) item; TextLineInfo lines, lines_ptr; - TextInfo *ti = &wi->text_info; + ZnTextInfo *ti = &wi->text_info; int i, num_lines; XColor *color; - int alpha; + unsigned short alpha; Tk_FontMetrics fm; int font_height; int underline_thickness, underline_pos=0, overstrike_pos=0; @@ -905,7 +904,7 @@ Render(Item item) if ((ti->sel_item == item) && (sel_first_line >= 0)) { ZnReal xo, yo, xc, yc; - color = ZnGetGradientColor(ti->sel_color, 0, &alpha); + color = ZnGetGradientColor(ti->sel_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); glBegin(GL_QUADS); @@ -914,39 +913,39 @@ Render(Item item) yo = text->pos_dev.y + lines[sel_first_line].text_origin.y - fm.ascent; xc = xo + sel_stop_offset - sel_start_offset; yc = yo + font_height; - glVertex2f(xo, yo); - glVertex2f(xc, yo); - glVertex2f(xc, yc); - glVertex2f(xo, yc); + glVertex2d(xo, yo); + glVertex2d(xc, yo); + glVertex2d(xc, yc); + glVertex2d(xo, yc); } else { xo = text->pos_dev.x + lines[sel_first_line].text_origin.x + sel_start_offset; yo = text->pos_dev.y + lines[sel_first_line].text_origin.y - fm.ascent; xc = xo + text->max_width-lines[sel_first_line].text_origin.x-sel_start_offset; yc = yo + font_height; - glVertex2f(xo, yo); - glVertex2f(xc, yo); - glVertex2f(xc, yc); - glVertex2f(xo, yc); + glVertex2d(xo, yo); + glVertex2d(xc, yo); + glVertex2d(xc, yc); + glVertex2d(xo, yc); for (i = sel_first_line+1, lines_ptr = &lines[sel_first_line+1]; i < sel_last_line; i++, lines_ptr++) { xo = text->pos_dev.x; yo = text->pos_dev.y + lines_ptr->text_origin.y - fm.ascent; xc = xo + text->max_width; yc = yo + font_height; - glVertex2f(xo, yo); - glVertex2f(xc, yo); - glVertex2f(xc, yc); - glVertex2f(xo, yc); + glVertex2d(xo, yo); + glVertex2d(xc, yo); + glVertex2d(xc, yc); + glVertex2d(xo, yc); } xo = text->pos_dev.x; yo = text->pos_dev.y + lines[sel_last_line].text_origin.y - fm.ascent; xc = xo + lines[sel_last_line].text_origin.x+sel_stop_offset; yc = yo + font_height; - glVertex2f(xo, yo); - glVertex2f(xc, yo); - glVertex2f(xc, yc); - glVertex2f(xo, yc); + glVertex2d(xo, yo); + glVertex2d(xc, yo); + glVertex2d(xc, yc); + glVertex2d(xo, yc); } glEnd(); } @@ -958,15 +957,15 @@ Render(Item item) (wi->focus_item == item) && ti->cursor_on) { int xs, ys; - color = ZnGetGradientColor(ti->insert_color, 0, &alpha); + color = ZnGetGradientColor(ti->insert_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); - glLineWidth(ti->insert_width); - xs = text->pos_dev.x + lines[cursor_line].text_origin.x + cursor_offset; - ys = text->pos_dev.y + lines[cursor_line].text_origin.y - fm.ascent + 1; + glLineWidth((GLfloat) ti->insert_width); + xs = (int) (text->pos_dev.x + lines[cursor_line].text_origin.x) + cursor_offset; + ys = (int) (text->pos_dev.y + lines[cursor_line].text_origin.y) - fm.ascent + 1; glBegin(GL_LINES); - glVertex2f(xs, ys); - glVertex2f(xs, ys + font_height - 1); + glVertex2i(xs, ys); + glVertex2i(xs, ys + font_height - 1); glEnd(); } @@ -976,7 +975,7 @@ Render(Item item) glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBindTexture(GL_TEXTURE_2D, ZnTexFontTex(text->tfi)); - color = ZnGetGradientColor(text->color, 0, &alpha); + color = ZnGetGradientColor(text->color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); @@ -987,23 +986,23 @@ Render(Item item) ys = text->pos_dev.y + lines_ptr->text_origin.y; glPushMatrix(); - glTranslatef(xs, ys, 0.0); + glTranslated(xs, ys, 0.0); ZnRenderString(text->tfi, lines_ptr->start, lines_ptr->num_bytes); glPopMatrix(); if (ISSET(text->flags, UNDERLINED) || ISSET(text->flags, OVERSTRIKED)) { - glLineWidth(underline_thickness); + glLineWidth((GLfloat) underline_thickness); glDisable(GL_TEXTURE_2D); if (ISSET(text->flags, UNDERLINED)) { glBegin(GL_LINES); - glVertex2f(xs, ys+underline_pos); - glVertex2f(xs+lines_ptr->width, ys+underline_pos); + glVertex2d(xs, ys+underline_pos); + glVertex2d(xs+lines_ptr->width, ys+underline_pos); glEnd(); } if (ISSET(text->flags, OVERSTRIKED)) { glBegin(GL_LINES); - glVertex2f(xs, ys-overstrike_pos); - glVertex2f(xs+lines_ptr->width, ys-overstrike_pos); + glVertex2d(xs, ys-overstrike_pos); + glVertex2d(xs+lines_ptr->width, ys-overstrike_pos); glEnd(); } glEnable(GL_TEXTURE_2D); @@ -1016,8 +1015,13 @@ Render(Item item) glCallList(item->gl_list); #endif -#endif } +#else +static void +Render(ZnItem item __unused) +{ +} +#endif /* @@ -1028,10 +1032,10 @@ Render(Item item) ********************************************************************************** */ static ZnBool -IsSensitive(Item item, - int item_part) +IsSensitive(ZnItem item, + int item_part __unused) { - return (ISSET(item->flags, SENSITIVE_BIT) && + return (ISSET(item->flags, ZN_SENSITIVE_BIT) && item->parent->class->IsSensitive(item->parent, ZN_NO_PART)); } @@ -1044,7 +1048,7 @@ IsSensitive(Item item, ********************************************************************************** */ static double -Pick(Item item, +Pick(ZnItem item, ZnPick ps) { TextItem text = (TextItem) item; @@ -1069,12 +1073,12 @@ Pick(Item item, } for (i = 0, lines_ptr = lines; i < num_lines; i++, lines_ptr++) { - ResetBBox(&line_bbox); + ZnResetBBox(&line_bbox); o.x = text->pos_dev.x + lines_ptr->text_origin.x; o.y = text->pos_dev.y + lines_ptr->text_origin.y - fm.ascent; - AddPointToBBox(&line_bbox, o.x, o.y); - AddPointToBBox(&line_bbox, o.x + lines_ptr->width, o.y + font_height); - new_dist = RectangleToPointDist(&line_bbox, p); + ZnAddPointToBBox(&line_bbox, o.x, o.y); + ZnAddPointToBBox(&line_bbox, o.x + lines_ptr->width, o.y + font_height); + new_dist = ZnRectangleToPointDist(&line_bbox, p); dist = MIN(dist, new_dist); if (dist <= 0.0) { dist = 0.0; @@ -1094,8 +1098,8 @@ Pick(Item item, ********************************************************************************** */ static void -PostScript(Item item, - PostScriptInfo ps_info) +PostScript(ZnItem item __unused, + ZnPostScriptInfo ps_info __unused) { } @@ -1108,17 +1112,17 @@ PostScript(Item item, ********************************************************************************** */ static void -GetAnchor(Item item, - ZnAnchor anchor, +GetAnchor(ZnItem item, + Tk_Anchor anchor, ZnPoint *p) { TextItem text = (TextItem) item; if (text->num_chars != 0) { - Origin2Anchor(&text->pos_dev, - item->item_bounding_box.corner.x-item->item_bounding_box.orig.x, - item->item_bounding_box.corner.y-item->item_bounding_box.orig.y, - anchor, p); + ZnOrigin2Anchor(&text->pos_dev, + item->item_bounding_box.corner.x-item->item_bounding_box.orig.x, + item->item_bounding_box.corner.y-item->item_bounding_box.orig.y, + anchor, p); } else { p->x = p->y = 0.0; @@ -1131,19 +1135,19 @@ GetAnchor(Item item, * * GetClipVertices -- * Get the clipping shape. - * Never ever call TRI_FREE on the tristrip returned by GetClipVertices. + * Never ever call ZnTriFree on the tristrip returned by GetClipVertices. * ********************************************************************************** */ static ZnBool -GetClipVertices(Item item, +GetClipVertices(ZnItem item, ZnTriStrip *tristrip) { ZnPoint *points; ZnListAssertSize(item->wi->work_pts, 2); points = (ZnPoint *) ZnListArray(item->wi->work_pts); - TRI_STRIP1(tristrip, points, 2, False); + ZnTriStrip1(tristrip, points, 2, False); points[0] = item->item_bounding_box.orig; points[1] = item->item_bounding_box.corner; @@ -1162,35 +1166,35 @@ GetClipVertices(Item item, ********************************************************************************** */ static int -Coords(Item item, - int contour, - int index, - int cmd, - ZnPoint **pts, - char **controls, - int *num_pts) +Coords(ZnItem item, + int contour __unused, + int index __unused, + int cmd, + ZnPoint **pts, + char **controls __unused, + unsigned int *num_pts) { TextItem text = (TextItem) item; - if ((cmd == COORDS_ADD) || (cmd == COORDS_ADD_LAST) || (cmd == COORDS_REMOVE)) { + if ((cmd == ZN_COORDS_ADD) || (cmd == ZN_COORDS_ADD_LAST) || (cmd == ZN_COORDS_REMOVE)) { Tcl_AppendResult(item->wi->interp, " texts can't add or remove vertices", NULL); - return ZN_ERROR; + return TCL_ERROR; } - else if ((cmd == COORDS_REPLACE) || (cmd == COORDS_REPLACE_ALL)) { + else if ((cmd == ZN_COORDS_REPLACE) || (cmd == ZN_COORDS_REPLACE_ALL)) { if (*num_pts == 0) { Tcl_AppendResult(item->wi->interp, " coords command need 1 point on texts", NULL); - return ZN_ERROR; + return TCL_ERROR; } text->pos = (*pts)[0]; - ITEM.Invalidate(item, ZN_COORDS_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG); } - else if ((cmd == COORDS_READ) || (cmd == COORDS_READ_ALL)) { + else if ((cmd == ZN_COORDS_READ) || (cmd == ZN_COORDS_READ_ALL)) { *num_pts = 1; *pts = &text->pos; } - return ZN_OK; + return TCL_OK; } @@ -1217,8 +1221,8 @@ PointToChar(TextItem text, return 0; } - x -= text->pos_dev.x; - y -= text->pos_dev.y; + x -= (int) text->pos_dev.x; + y -= (int) text->pos_dev.y; /* * Point above text, returns index 0. @@ -1251,8 +1255,8 @@ PointToChar(TextItem text, byte_index = p->start + p->num_bytes - text->text; break; } - n = Tk_MeasureChars(text->font, p->start, p->num_bytes, - x + 2 - p->text_origin.x, TK_PARTIAL_OK, &dummy); + n = Tk_MeasureChars(text->font, p->start, (int) p->num_bytes, + x + 2 - (int) p->text_origin.x, TK_PARTIAL_OK, &dummy); byte_index = (p->start + n - 1) - text->text; break; } @@ -1282,19 +1286,19 @@ PointToChar(TextItem text, * */ static int -MoveFromIndex(TextItem text, - int char_index, - int move) +MoveFromIndex(TextItem text, + unsigned int char_index, + int move) { - int num_lines, byte_index, num_bytes=0; - int line_index, line_start=0; + unsigned int num_lines, byte_index, num_bytes=0; + unsigned int line_index, line_start=0; TextLineInfo lines, p; char *strp; if (!text->text_info || !text->text) { return char_index; } - byte_index = Tcl_UtfAtIndex(text->text, char_index)-text->text; + byte_index = Tcl_UtfAtIndex(text->text, (int) char_index)-text->text; num_lines = ZnListSize(text->text_info); lines = p = ZnListArray(text->text_info); for (line_index = 0; line_index < num_lines; line_index++, p++) { @@ -1354,23 +1358,23 @@ MoveFromIndex(TextItem text, byte_index += line_start; } convert_it: - Tcl_NumUtfChars(text->text, byte_index); + char_index = Tcl_NumUtfChars(text->text, (int) byte_index); default: return char_index; } } static int -Index(Item item, - int field, +Index(ZnItem item, + int field __unused, Tcl_Obj *index_spec, int *index) { TextItem text = (TextItem) item; - WidgetInfo *wi = item->wi; - TextInfo *ti = &wi->text_info; - int c, length; - int x, y; + ZnWInfo *wi = item->wi; + ZnTextInfo *ti = &wi->text_info; + unsigned int length; + int c, x, y; double tmp; char *end, *p; @@ -1430,14 +1434,14 @@ Index(Item item, goto badIndex; } /*x = (int) ((tmp < 0) ? tmp - 0.5 : tmp + 0.5);*/ - x = tmp; + x = (int) tmp; p = end+1; tmp = strtod(p, &end); if ((end == p) || (*end != 0)) { goto badIndex; } /*y = (int) ((tmp < 0) ? tmp - 0.5 : tmp + 0.5);*/ - y = tmp; + y = (int) tmp; *index = PointToChar(text, x, y); } @@ -1445,7 +1449,7 @@ Index(Item item, if (*index < 0){ *index = 0; } - else if (*index > text->num_chars) { + else if ((unsigned int) *index > text->num_chars) { *index = text->num_chars; } } @@ -1467,14 +1471,14 @@ Index(Item item, ********************************************************************************** */ static void -InsertChars(Item item, - int field, +InsertChars(ZnItem item, + int field __unused, int *index, char *chars) { TextItem text = (TextItem) item; - TextInfo *ti = &item->wi->text_info; - int num_chars, byte_index, num_bytes = strlen(chars); + ZnTextInfo *ti = &item->wi->text_info; + unsigned int num_chars, byte_index, num_bytes = strlen(chars); char *new; if (num_bytes == 0) { @@ -1483,26 +1487,28 @@ InsertChars(Item item, if (*index < 0) { *index = 0; } - if (*index > text->num_chars) { + if ((unsigned int) *index > text->num_chars) { *index = text->num_chars; } - byte_index = Tcl_UtfAtIndex(text->text, *index)-text->text; - num_chars = Tcl_NumUtfChars(chars, num_bytes); + num_chars = Tcl_NumUtfChars(chars, (int) num_bytes); if (text->text) { + byte_index = Tcl_UtfAtIndex(text->text, *index)-text->text; new = ZnMalloc(strlen(text->text) + num_bytes + 1); memcpy(new, text->text, (size_t) byte_index); strcpy(new + byte_index + num_bytes, text->text + byte_index); ZnFree(text->text); } else { + byte_index = 0; new = ZnMalloc(num_bytes + 1); + new[num_bytes] = 0; } - strcpy(new + byte_index, chars); + memcpy(new + byte_index, chars, num_bytes); text->text = new; text->num_chars += num_chars; - if (text->insert_index >= *index) { + if (text->insert_index >= (unsigned int) *index) { text->insert_index += num_chars; } if (ti->sel_item == item) { @@ -1517,7 +1523,7 @@ InsertChars(Item item, } } - ITEM.Invalidate(item, ZN_COORDS_FLAG|ZN_LAYOUT_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG|ZN_LAYOUT_FLAG); } @@ -1529,15 +1535,15 @@ InsertChars(Item item, ********************************************************************************** */ static void -DeleteChars(Item item, - int field, +DeleteChars(ZnItem item, + int field __unused, int *first, int *last) { TextItem text = (TextItem) item; int byte_count, first_offset; int char_count, num_bytes; - TextInfo *ti = &item->wi->text_info; + ZnTextInfo *ti = &item->wi->text_info; char *new; if (!text->text) { @@ -1546,7 +1552,7 @@ DeleteChars(Item item, if (*first < 0) { *first = 0; } - if (*last >= text->num_chars) { + if (*last >= (int) text->num_chars) { *last = text->num_chars-1; } if (*first > *last) { @@ -1572,9 +1578,9 @@ DeleteChars(Item item, text->num_chars = 0; } - if (text->insert_index > *first) { + if (text->insert_index > (unsigned int) *first) { text->insert_index -= char_count; - if (text->insert_index < *first) { + if (text->insert_index < (unsigned int) *first) { text->insert_index = *first; } } @@ -1602,7 +1608,7 @@ DeleteChars(Item item, } } - ITEM.Invalidate(item, ZN_COORDS_FLAG|ZN_LAYOUT_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG|ZN_LAYOUT_FLAG); } @@ -1614,16 +1620,16 @@ DeleteChars(Item item, ********************************************************************************** */ static void -TextCursor(Item item, - int field, - int index) +TextCursor(ZnItem item, + int field __unused, + int index) { TextItem text = (TextItem) item; if (index < 0) { text->insert_index = 0; } - else if (index > text->num_chars) { + else if ((unsigned int) index > text->num_chars) { text->insert_index = text->num_chars; } else { @@ -1640,15 +1646,15 @@ TextCursor(Item item, ********************************************************************************** */ static int -Selection(Item item, - int field, - int offset, - char *chars, - int max_bytes) +Selection(ZnItem item, + int field __unused, + int offset, + char *chars, + int max_bytes) { TextItem text = (TextItem) item; - WidgetInfo *wi = item->wi; - TextInfo *ti = &wi->text_info; + ZnWInfo *wi = item->wi; + ZnTextInfo *ti = &wi->text_info; int count; char const *sel_first, *sel_last; @@ -1682,7 +1688,7 @@ Selection(Item item, * ********************************************************************************** */ -static ItemClassStruct TEXT_ITEM_CLASS = { +static ZnItemClassStruct TEXT_ITEM_CLASS = { sizeof(TextItemStruct), 0, /* num_parts */ True, /* has_anchors */ -- cgit v1.1