diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2012-06-11 09:33:15 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2012-06-11 09:33:15 (GMT) |
commit | 691a4bcee2166be892a17b23f7ea5c6cbf6208ea (patch) | |
tree | 1ebf4bee831b41f37a439e0f5aad965d112ba259 | |
parent | 3a05c79d88c75ffdff4f576da2565f63101723ab (diff) | |
parent | bf900a025e09fca253dd396abc9c29f1de5ae36a (diff) | |
download | tk-691a4bcee2166be892a17b23f7ea5c6cbf6208ea.zip tk-691a4bcee2166be892a17b23f7ea5c6cbf6208ea.tar.gz tk-691a4bcee2166be892a17b23f7ea5c6cbf6208ea.tar.bz2 |
fix the clipping in entries too
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | generic/ttk/ttkEntry.c | 32 |
2 files changed, 32 insertions, 13 deletions
@@ -1,12 +1,13 @@ 2012-06-11 Donal K. Fellows <dkf@users.sf.net> * generic/ttk/ttkLabel.c (TextDraw): [Bug 3294450]: Get the clipping - of text in Ttk text elements (e.g., buttons, entries, etc.) correct. - Stops a whole range of visual problems, including loss of the second - and subsequent lines of a label when the first line doesn't entirely - fit, and failing to draw the last character of an entry at all if it - doesn't all exactly fit in the space available (a problem I've noticed - in tkchat, and been very frustrated with). + * generic/ttk/ttkEntry.c (EntryDisplay): of text in Ttk various text + elements (e.g., buttons, entries, etc.) correct. Stops a whole range + of visual problems, including loss of the second and subsequent lines + of a label when the first line doesn't entirely fit, and failing to + draw the last character of an entry at all if it doesn't all exactly + fit in the space available (a problem I've noticed in tkchat, and been + very frustrated with). 2012-06-10 Jan Nijtmans <nijtmans@users.sf.net> diff --git a/generic/ttk/ttkEntry.c b/generic/ttk/ttkEntry.c index c4b1b6a..410c60c 100644 --- a/generic/ttk/ttkEntry.c +++ b/generic/ttk/ttkEntry.c @@ -10,7 +10,7 @@ #include <string.h> #include <stdio.h> -#include <tk.h> +#include <tkInt.h> #include <X11/Xatom.h> #include "ttkTheme.h" @@ -1123,7 +1123,7 @@ EntryDoLayout(void *recordPtr) * rightIndex is set to one past the last fully-visible character. */ Tk_CharBbox(textLayout, leftIndex, &leftX, NULL, NULL, NULL); - rightIndex = Tk_PointToChar(textLayout, leftX + textarea.width, 0); + rightIndex = Tk_PointToChar(textLayout, leftX + textarea.width, 0)+1; entryPtr->entry.layoutX = textarea.x - leftX; } @@ -1135,13 +1135,14 @@ EntryDoLayout(void *recordPtr) * Get a GC using the specified foreground color and the entry's font. * Result must be freed with Tk_FreeGC(). */ -static GC EntryGetGC(Entry *entryPtr, Tcl_Obj *colorObj) +static GC EntryGetGC(Entry *entryPtr, Tcl_Obj *colorObj, TkRegion clip) { Tk_Window tkwin = entryPtr->core.tkwin; Tk_Font font = Tk_GetFontFromObj(tkwin, entryPtr->entry.fontObj); XColor *colorPtr; unsigned long mask = 0ul; XGCValues gcValues; + GC gc; gcValues.line_width = 1; mask |= GCLineWidth; gcValues.font = Tk_FontId(font); mask |= GCFont; @@ -1149,7 +1150,9 @@ static GC EntryGetGC(Entry *entryPtr, Tcl_Obj *colorObj) gcValues.foreground = colorPtr->pixel; mask |= GCForeground; } - return Tk_GetGC(entryPtr->core.tkwin, mask, &gcValues); + gc = Tk_GetGC(entryPtr->core.tkwin, mask, &gcValues); + TkSetRegion(Tk_Display(entryPtr->core.tkwin), gc, clip); + return gc; } /* EntryDisplay -- @@ -1166,9 +1169,13 @@ static void EntryDisplay(void *clientData, Drawable d) EntryStyleData es; GC gc; int showSelection, showCursor; + Ttk_Box textarea; + TkRegion clipRegion; + XRectangle rect; EntryInitStyleData(entryPtr, &es); + textarea = Ttk_ClientRegion(corePtr->layout, "textarea"); showCursor = (entryPtr->core.flags & CURSOR_ON) != 0 && EntryEditable(entryPtr) @@ -1214,6 +1221,16 @@ static void EntryDisplay(void *clientData, Drawable d) } } + /* Initialize the clip region: + */ + + rect.x = textarea.x; + rect.y = textarea.y; + rect.width = textarea.width; + rect.height = textarea.height; + clipRegion = TkCreateRegion(); + TkUnionRectWithRegion(&rect, clipRegion, clipRegion); + /* Draw cursor: */ if (showCursor) { @@ -1230,7 +1247,7 @@ static void EntryDisplay(void *clientData, Drawable d) /* @@@ should: maybe: SetCaretPos even when blinked off */ Tk_SetCaretPos(tkwin, cursorX, cursorY, cursorHeight); - gc = EntryGetGC(entryPtr, es.insertColorObj); + gc = EntryGetGC(entryPtr, es.insertColorObj, clipRegion); XFillRectangle(Tk_Display(tkwin), d, gc, cursorX-cursorWidth/2, cursorY, cursorWidth, cursorHeight); Tk_FreeGC(Tk_Display(tkwin), gc); @@ -1238,7 +1255,7 @@ static void EntryDisplay(void *clientData, Drawable d) /* Draw the text: */ - gc = EntryGetGC(entryPtr, es.foregroundObj); + gc = EntryGetGC(entryPtr, es.foregroundObj, clipRegion); Tk_DrawTextLayout( Tk_Display(tkwin), d, gc, entryPtr->entry.textLayout, entryPtr->entry.layoutX, entryPtr->entry.layoutY, @@ -1248,13 +1265,14 @@ static void EntryDisplay(void *clientData, Drawable d) /* Overwrite the selected portion (if any) in the -selectforeground color: */ if (showSelection) { - gc = EntryGetGC(entryPtr, es.selForegroundObj); + gc = EntryGetGC(entryPtr, es.selForegroundObj, clipRegion); Tk_DrawTextLayout( Tk_Display(tkwin), d, gc, entryPtr->entry.textLayout, entryPtr->entry.layoutX, entryPtr->entry.layoutY, selFirst, selLast); Tk_FreeGC(Tk_Display(tkwin), gc); } + TkDestroyRegion(clipRegion); } /*------------------------------------------------------------------------ |