From e96587e7c59b720f8c59aa42cef888dbaf03da3f Mon Sep 17 00:00:00 2001 From: lecoanet Date: Wed, 25 May 2005 08:26:27 +0000 Subject: Need to reinstate the GL rendering context after using Tk_MeasureChars or Tk_TextWidth under windows. --- generic/Field.c | 14 +++++++++++--- generic/Text.c | 2 ++ 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'generic') diff --git a/generic/Field.c b/generic/Field.c index 9f36e88..e0a428f 100644 --- a/generic/Field.c +++ b/generic/Field.c @@ -586,7 +586,9 @@ ComputeFieldTextLocation(Field fptr, Tk_GetFontMetrics(fptr->font, &fm); w = 0; if (fptr->text) { - w = Tk_TextWidth(fptr->font, fptr->text, (int) strlen(fptr->text)); + int width; + Tk_MeasureChars(fptr->font, fptr->text, strlen(fptr->text), -1, 0, &width); + w = width; } h = fm.ascent + fm.descent; text_bbox->orig.y = (bbox->orig.y + bbox->corner.y - h) / 2.0; @@ -1352,11 +1354,11 @@ FieldInsertChars(ZnFieldSet fs, if (*index > num_chars) { *index = num_chars; } - byte_index = Tcl_UtfAtIndex(fptr->text, *index) - fptr->text; chars_added = Tcl_NumUtfChars(chars, (int) bytes_added); - new = ZnMalloc(num_bytes + bytes_added + 1); if (fptr->text) { + byte_index = Tcl_UtfAtIndex(fptr->text, *index) - fptr->text; + new = ZnMalloc(num_bytes + bytes_added + 1); /* * Copy the part before and the part after the new * text (if any). @@ -1365,6 +1367,11 @@ FieldInsertChars(ZnFieldSet fs, strcpy(new + byte_index + bytes_added, fptr->text + byte_index); ZnFree(fptr->text); } + else { + byte_index = 0; + new = ZnMalloc(num_bytes + 1); + new[num_bytes] = 0; + } /* * Insert the new text. */ @@ -1986,6 +1993,7 @@ RenderField(ZnWInfo *wi, ZnReal xs; ZnTextInfo *ti = &wi->text_info; + ZnGLMakeCurrent(wi->dpy, wi); /* * Draw the background. */ diff --git a/generic/Text.c b/generic/Text.c index bc7c843..b2e83f8 100644 --- a/generic/Text.c +++ b/generic/Text.c @@ -1135,6 +1135,8 @@ Render(ZnItem item) ComputeCursor(item, &cursor_line, &cursor_offset); ComputeSelection(item, &sel_first_line, &sel_last_line, &sel_start_offset, &sel_stop_offset); + + ZnGLMakeCurrent(wi->dpy, wi); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPushMatrix(); -- cgit v1.1