From f85b666de3d6de93f6c60d612e1c4abf5c671a90 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 30 Sep 2016 09:29:39 +0000 Subject: Add a few "const" keywords, just for 'correctness' --- unix/tkUnixFont.c | 6 +++--- unix/tkUnixRFont.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/unix/tkUnixFont.c b/unix/tkUnixFont.c index 1b0f175..e694573 100644 --- a/unix/tkUnixFont.c +++ b/unix/tkUnixFont.c @@ -171,7 +171,7 @@ static Tcl_ThreadDataKey dataKey; * encodings into the names expected by the Tcl encoding package. */ -static EncodingAlias encodingAliases[] = { +static const EncodingAlias encodingAliases[] = { {"gb2312-raw", "gb2312*"}, {"big5", "big5*"}, {"cns11643-1", "cns11643*-1"}, @@ -408,8 +408,8 @@ ControlUtfProc( char *dstStart, *dstEnd; int ch; int result; - static char hexChars[] = "0123456789abcdef"; - static char mapChars[] = { + static const char hexChars[] = "0123456789abcdef"; + static const char mapChars[] = { 0, 0, 0, 0, 0, 0, 0, 'a', 'b', 't', 'n', 'v', 'f', 'r' }; diff --git a/unix/tkUnixRFont.c b/unix/tkUnixRFont.c index cf4127d..36c4540 100644 --- a/unix/tkUnixRFont.c +++ b/unix/tkUnixRFont.c @@ -69,7 +69,7 @@ void TkpFontPkgInit( TkMainInfo *mainPtr) /* The application being created. */ { - static Tcl_Config cfg[] = { + static const Tcl_Config cfg[] = { { "fontsystem", "xft" }, { 0,0 } }; -- cgit v0.12 From dbd5092cb00d45365d9260c2c767757fa4219ede Mon Sep 17 00:00:00 2001 From: fvogel Date: Wed, 2 Nov 2016 20:07:14 +0000 Subject: Removed proc ::tk_getFileType since it is used nowhere in Tk, is undocumented, is superseded by the -typevariable option of file dialogs, and was anyway only available if tk_strictMotif is true. --- library/tclIndex | 1 - library/xmfbox.tcl | 7 ------- 2 files changed, 8 deletions(-) diff --git a/library/tclIndex b/library/tclIndex index b3f37fa..919fa8a 100644 --- a/library/tclIndex +++ b/library/tclIndex @@ -247,7 +247,6 @@ set auto_index(::tk::ListBoxKeyAccel_Unset) [list source [file join $dir xmfbox. set auto_index(::tk::ListBoxKeyAccel_Key) [list source [file join $dir xmfbox.tcl]] set auto_index(::tk::ListBoxKeyAccel_Goto) [list source [file join $dir xmfbox.tcl]] set auto_index(::tk::ListBoxKeyAccel_Reset) [list source [file join $dir xmfbox.tcl]] -set auto_index(tk_getFileType) [list source [file join $dir xmfbox.tcl]] set auto_index(::tk::unsupported::ExposePrivateCommand) [list source [file join $dir unsupported.tcl]] set auto_index(::tk::unsupported::ExposePrivateVariable) [list source [file join $dir unsupported.tcl]] set auto_index(::tk::fontchooser) [list source [file join $dir fontchooser.tcl]] diff --git a/library/xmfbox.tcl b/library/xmfbox.tcl index 14d2be5..f1daea0 100644 --- a/library/xmfbox.tcl +++ b/library/xmfbox.tcl @@ -210,7 +210,6 @@ proc ::tk::MotifFDialog_SetFilter {w type} { variable ::tk::Priv set data(filter) [lindex $type 1] - set Priv(selectFileType) [lindex [lindex $type 0] 0] MotifFDialog_Update $w } @@ -981,9 +980,3 @@ proc ::tk::ListBoxKeyAccel_Reset {w} { unset -nocomplain Priv(lbAccel,$w) } -proc ::tk_getFileType {} { - variable ::tk::Priv - - return $Priv(selectFileType) -} - -- cgit v0.12 From 2da9e225ec7604a5ad4e4dc46e76d090d733b87c Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 4 Nov 2016 15:38:45 +0000 Subject: More internal use of size_t, so refcounts can be bigger than before (2^31 -> 2^32 on 32-bit platforms, even more on 64-bit) --- generic/tkConfig.c | 21 ++++++++++----------- generic/tkConsole.c | 12 ++++++------ generic/tkFont.c | 5 ++--- unix/tkUnixFont.c | 15 +++++++-------- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/generic/tkConfig.c b/generic/tkConfig.c index 9c159e6..093bd35 100644 --- a/generic/tkConfig.c +++ b/generic/tkConfig.c @@ -91,7 +91,7 @@ typedef struct TkOption { */ typedef struct OptionTable { - int refCount; /* Counts the number of uses of this table + size_t refCount; /* Counts the number of uses of this table * (the number of times Tk_CreateOptionTable * has returned it). This can be greater than * 1 if it is shared along several option @@ -103,7 +103,7 @@ typedef struct OptionTable { * templates, this points to the table * corresponding to the next template in the * chain. */ - int numOptions; /* The number of items in the options array + size_t numOptions; /* The number of items in the options array * below. */ Option options[1]; /* Information about the individual options in * the table. This must be the last field in @@ -177,7 +177,7 @@ Tk_CreateOptionTable( OptionTable *tablePtr; const Tk_OptionSpec *specPtr, *specPtr2; Option *optionPtr; - int numOptions, i; + size_t numOptions, i; ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); @@ -330,10 +330,9 @@ Tk_DeleteOptionTable( { OptionTable *tablePtr = (OptionTable *) optionTable; Option *optionPtr; - int count; + size_t count; - tablePtr->refCount--; - if (tablePtr->refCount > 0) { + if (tablePtr->refCount-- > 1) { return; } @@ -978,7 +977,7 @@ GetOption( Option *bestPtr, *optionPtr; OptionTable *tablePtr2; const char *p1, *p2; - int count; + size_t count; /* * Search through all of the option tables in the chain to find the best @@ -1539,7 +1538,7 @@ Tk_FreeConfigOptions( { OptionTable *tablePtr; Option *optionPtr; - int count; + size_t count; Tcl_Obj **oldPtrPtr, *oldPtr; char *oldInternalPtr; const Tk_OptionSpec *specPtr; @@ -1733,7 +1732,7 @@ Tk_GetOptionInfo( Tcl_Obj *resultPtr; OptionTable *tablePtr = (OptionTable *) optionTable; Option *optionPtr; - int count; + size_t count; /* * If information is only wanted for a single configuration spec, then @@ -2096,9 +2095,9 @@ TkDebugConfig( if (tablePtr == (OptionTable *) Tcl_GetHashValue(hashEntryPtr)) { for ( ; tablePtr != NULL; tablePtr = tablePtr->nextPtr) { Tcl_ListObjAppendElement(NULL, objPtr, - Tcl_NewIntObj(tablePtr->refCount)); + Tcl_NewWideIntObj(tablePtr->refCount)); Tcl_ListObjAppendElement(NULL, objPtr, - Tcl_NewIntObj(tablePtr->numOptions)); + Tcl_NewWideIntObj(tablePtr->numOptions)); Tcl_ListObjAppendElement(NULL, objPtr, Tcl_NewStringObj( tablePtr->options[0].specPtr->optionName, -1)); } diff --git a/generic/tkConsole.c b/generic/tkConsole.c index 8bfbe9b..fc60d5f 100644 --- a/generic/tkConsole.c +++ b/generic/tkConsole.c @@ -24,7 +24,7 @@ typedef struct ConsoleInfo { Tcl_Interp *consoleInterp; /* Interpreter displaying the console. */ Tcl_Interp *interp; /* Interpreter controlled by console. */ - int refCount; + size_t refCount; } ConsoleInfo; /* @@ -452,7 +452,7 @@ Tk_CreateConsoleWindow( if (mainWindow) { Tk_DeleteEventHandler(mainWindow, StructureNotifyMask, ConsoleEventProc, info); - if (--info->refCount <= 0) { + if (info->refCount-- <= 1) { ckfree(info); } } @@ -592,7 +592,7 @@ ConsoleClose( ConsoleInfo *info = data->info; if (info) { - if (--info->refCount <= 0) { + if (info->refCount-- <= 1) { /* * Assuming the Tcl_Interp * fields must already be NULL. */ @@ -881,7 +881,7 @@ InterpDeleteProc( Tcl_DeleteThreadExitHandler(DeleteConsoleInterp, info->consoleInterp); info->consoleInterp = NULL; } - if (--info->refCount <= 0) { + if (info->refCount-- <= 1) { ckfree(info); } } @@ -912,7 +912,7 @@ ConsoleDeleteProc( if (info->consoleInterp) { Tcl_DeleteInterp(info->consoleInterp); } - if (--info->refCount <= 0) { + if (info->refCount-- <= 1) { ckfree(info); } } @@ -949,7 +949,7 @@ ConsoleEventProc( Tcl_EvalEx(consoleInterp, "tk::ConsoleExit", -1, TCL_EVAL_GLOBAL); } - if (--info->refCount <= 0) { + if (info->refCount-- <= 1) { ckfree(info); } } diff --git a/generic/tkFont.c b/generic/tkFont.c index 7f2715b..a00c627 100644 --- a/generic/tkFont.c +++ b/generic/tkFont.c @@ -41,7 +41,7 @@ typedef struct TkFontInfo { */ typedef struct NamedFont { - int refCount; /* Number of users of named font. */ + size_t refCount; /* Number of users of named font. */ int deletePending; /* Non-zero if font should be deleted when * last reference goes away. */ TkFontAttributes fa; /* Desired attributes for named font. */ @@ -1434,8 +1434,7 @@ Tk_FreeFont( */ nfPtr = Tcl_GetHashValue(fontPtr->namedHashPtr); - nfPtr->refCount--; - if ((nfPtr->refCount == 0) && nfPtr->deletePending) { + if ((nfPtr->refCount-- <= 1) && nfPtr->deletePending) { Tcl_DeleteHashEntry(fontPtr->namedHashPtr); ckfree(nfPtr); } diff --git a/unix/tkUnixFont.c b/unix/tkUnixFont.c index e694573..c96e562 100644 --- a/unix/tkUnixFont.c +++ b/unix/tkUnixFont.c @@ -19,8 +19,8 @@ * The preferred font encodings. */ -static const char *const encodingList[] = { - "iso8859-1", "jis0208", "jis0212", NULL +static const char encodingList[][10] = { + "iso8859-1", "jis0208", "jis0212" }; /* @@ -42,7 +42,7 @@ static const char *const encodingList[] = { typedef struct FontFamily { struct FontFamily *nextPtr; /* Next in list of all known font families. */ - int refCount; /* How many SubFonts are referring to this + size_t refCount; /* How many SubFonts are referring to this * FontFamily. When the refCount drops to * zero, this FontFamily may be freed. */ /* @@ -1916,8 +1916,7 @@ FreeFontFamily( if (familyPtr == NULL) { return; } - familyPtr->refCount--; - if (familyPtr->refCount > 0) { + if (familyPtr->refCount-- > 1) { return; } Tcl_FreeEncoding(familyPtr->encoding); @@ -2686,7 +2685,7 @@ RankAttributes( penalty += 150 * diff; } if (gotPtr->xa.charset != wantPtr->xa.charset) { - int i; + size_t i; const char *gotAlias, *wantAlias; penalty += 65000; @@ -2694,7 +2693,7 @@ RankAttributes( wantAlias = GetEncodingAlias(wantPtr->xa.charset); if (strcmp(gotAlias, wantAlias) != 0) { penalty += 30000; - for (i = 0; encodingList[i] != NULL; i++) { + for (i = 0; i < sizeof(encodingList)/sizeof(encodingList[0]); i++) { if (strcmp(gotAlias, encodingList[i]) == 0) { penalty -= 30000; break; @@ -3012,7 +3011,7 @@ static const char * GetEncodingAlias( const char *name) /* The name to look up. */ { - EncodingAlias *aliasPtr; + const EncodingAlias *aliasPtr; for (aliasPtr = encodingAliases; aliasPtr->aliasPattern != NULL; ) { if (Tcl_StringMatch(name, aliasPtr->aliasPattern)) { -- cgit v0.12 From 3b8a1a19064c05bb314d93d5ce9e2d51efbb5e44 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 9 Nov 2016 13:41:27 +0000 Subject: Bring all win32 version stuff to one place. Should work the same (should still work on XP, although I don't know if we really want that). --- win/tkWin.h | 12 +++++++++--- win/tkWinMenu.c | 17 ++++++----------- win/tkWinX.c | 10 ---------- win/ttkWinXPTheme.c | 6 +----- 4 files changed, 16 insertions(+), 29 deletions(-) diff --git a/win/tkWin.h b/win/tkWin.h index 4d278d7..86be2e9 100644 --- a/win/tkWin.h +++ b/win/tkWin.h @@ -18,14 +18,20 @@ * the SystemParametersInfo API doesn't like to receive structures that * are larger than it expects which affects the font assignments. * - * WINVER = 0x0500 means Windows 2000 and above + * NTDDI_VERSION = 0x0600 means Windows Vista and above */ +#ifndef NTDDI_VERSION +#define NTDDI_VERSION 0x06000000 +#endif #ifndef WINVER -#define WINVER 0x0500 +#define WINVER 0x0600 #endif #ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0500 +#define _WIN32_WINNT 0x0600 +#endif +#ifndef _WIN32_IE +#define _WIN32_IE 0x0600 #endif #ifndef _TK diff --git a/win/tkWinMenu.c b/win/tkWinMenu.c index 8e14669..0975633 100644 --- a/win/tkWinMenu.c +++ b/win/tkWinMenu.c @@ -3203,12 +3203,7 @@ SetDefaults( int pointSize; HFONT menuFont; /* See: [Bug #3239768] tk8.4.19 (and later) WIN32 menu font support */ - struct { - NONCLIENTMETRICS metrics; -#if (WINVER < 0x0600) - int padding; -#endif - } nc; + NONCLIENTMETRICS metrics; OSVERSIONINFOW os; /* @@ -3227,17 +3222,17 @@ SetDefaults( } Tcl_DStringInit(&menuFontDString); - nc.metrics.cbSize = sizeof(nc); + metrics.cbSize = sizeof(metrics); os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW); GetVersionExW(&os); if (os.dwMajorVersion < 6) { - nc.metrics.cbSize -= sizeof(int); + metrics.cbSize -= sizeof(int); } - SystemParametersInfo(SPI_GETNONCLIENTMETRICS, nc.metrics.cbSize, - &nc.metrics, 0); - menuFont = CreateFontIndirect(&nc.metrics.lfMenuFont); + SystemParametersInfo(SPI_GETNONCLIENTMETRICS, metrics.cbSize, + &metrics, 0); + menuFont = CreateFontIndirect(&metrics.lfMenuFont); SelectObject(scratchDC, menuFont); GetTextMetricsA(scratchDC, &tm); GetTextFaceA(scratchDC, LF_FACESIZE, faceName); diff --git a/win/tkWinX.c b/win/tkWinX.c index cfd64af..d41b6c1 100644 --- a/win/tkWinX.c +++ b/win/tkWinX.c @@ -13,16 +13,6 @@ #include "tkWinInt.h" -/* - * The w32api 1.1 package (included in Mingw 1.1) does not define _WIN32_IE by - * default. Define it here to gain access to the InitCommonControlsEx API in - * commctrl.h. - */ - -#ifndef _WIN32_IE -#define _WIN32_IE 0x0550 /* IE 5.5 */ -#endif - #include #ifdef _MSC_VER # pragma comment (lib, "comctl32.lib") diff --git a/win/ttkWinXPTheme.c b/win/ttkWinXPTheme.c index 3de1504..909660a 100644 --- a/win/ttkWinXPTheme.c +++ b/win/ttkWinXPTheme.c @@ -15,14 +15,12 @@ * shellcc/platform/commctls/userex/refentry.asp > */ +#include #ifndef HAVE_UXTHEME_H /* Stub for platforms that lack the XP theme API headers: */ -#include int TtkXPTheme_Init(Tcl_Interp *interp, HWND hwnd) { return TCL_OK; } #else -#define WINVER 0x0501 /* Requires Windows XP APIs */ - #include #include #if defined(HAVE_VSSYM32_H) || _MSC_VER > 1500 @@ -31,8 +29,6 @@ int TtkXPTheme_Init(Tcl_Interp *interp, HWND hwnd) { return TCL_OK; } # include #endif -#include - #include "ttk/ttkTheme.h" typedef HTHEME (STDAPICALLTYPE OpenThemeDataProc)(HWND hwnd, -- cgit v0.12 From 39cfdaa0524f329527d9ee22d9229ce476560f05 Mon Sep 17 00:00:00 2001 From: fvogel Date: Wed, 30 Nov 2016 21:51:25 +0000 Subject: Fixed [3ee76e41c2] - New textTag test failures --- tests/textTag.test | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/tests/textTag.test b/tests/textTag.test index 2df8c5a..a2b2d73 100644 --- a/tests/textTag.test +++ b/tests/textTag.test @@ -11,6 +11,19 @@ namespace import ::tcltest::* eval tcltest::configure $argv tcltest::loadTestedCommands +set textWidgetFont {Courier 12} +set bigFont {Helvetica 24} + +# what is needed is a specific font *size* because in some tests (that +# will be constrained by haveFontSizes), a tag applying the $bigFont +# will be set to some characters, which action has the effect of +# changing what character is under the mouse pointer, which is the +# purpose of the tests +testConstraint haveFontSizes [expr { + [font actual $textWidgetFont -size] == 12 && + [font actual $bigFont -size] == 24 } +] + destroy .t text .t -width 20 -height 10 @@ -19,7 +32,6 @@ update .t debug on wm geometry . {} -set bigFont {Helvetica 24} # The statements below reset the main window; it's needed if the window # manager is mwm, to make mwm forget about a previous minimum size setting. @@ -1313,9 +1325,13 @@ test textTag-16.1 {TkTextPickCurrent procedure} -setup { lappend x [.t index current] } -result {2.1 3.2 3.2 3.2 3.2 3.2 4.3} -test textTag-16.2 {TkTextPickCurrent procedure} -setup { +test textTag-16.2 {TkTextPickCurrent procedure} -constraints { + haveFontSizes +} -setup { .t tag delete {*}[.t tag names] event generate {} -warp 1 -x -1 -y -1; update + set curFont [.t cget -font] + .t configure -font $textWidgetFont } -body { .t tag configure big -font $bigFont event gen .t -state 0x100 -x $x1 -y $y1 @@ -1326,6 +1342,7 @@ test textTag-16.2 {TkTextPickCurrent procedure} -setup { lappend x [.t index current] } -cleanup { .t tag delete big + .t configure -font $curFont } -result {3.2 3.1} test textTag-16.3 {TkTextPickCurrent procedure} -setup { @@ -1381,11 +1398,15 @@ test textTag-16.4 {TkTextPickCurrent procedure} -setup { .t tag delete {*}[.t tag names] } -result {enter-a enter-b enter-c | leave-c leave-b} -test textTag-16.5 {TkTextPickCurrent procedure} -setup { +test textTag-16.5 {TkTextPickCurrent procedure} -constraints { + haveFontSizes +} -setup { foreach i {big a b c d} { .t tag remove $i 1.0 end } event generate {} -warp 1 -x -1 -y -1; update + set curFont [.t cget -font] + .t configure -font $textWidgetFont } -body { .t tag configure big -font $bigFont event gen .t -x $x1 -y $y1 @@ -1395,13 +1416,18 @@ test textTag-16.5 {TkTextPickCurrent procedure} -setup { .t index current } -cleanup { .t tag delete a big + .t configure -font $curFont } -result {3.2} -test textTag-16.6 {TkTextPickCurrent procedure} -setup { +test textTag-16.6 {TkTextPickCurrent procedure} -constraints { + haveFontSizes +} -setup { foreach i {big a b c d} { .t tag remove $i 1.0 end } event generate {} -warp 1 -x -1 -y -1; update + set curFont [.t cget -font] + .t configure -font $textWidgetFont } -body { .t tag configure big -font $bigFont event gen .t -x $x1 -y $y1 @@ -1412,13 +1438,18 @@ test textTag-16.6 {TkTextPickCurrent procedure} -setup { .t index current } -cleanup { .t tag delete a big + .t configure -font $curFont } -result {3.1} -test textTag-16.7 {TkTextPickCurrent procedure} -setup { +test textTag-16.7 {TkTextPickCurrent procedure} -constraints { + haveFontSizes +} -setup { foreach i {big a b c d} { .t tag remove $i 1.0 end } event generate {} -warp 1 -x -1 -y -1; update + set curFont [.t cget -font] + .t configure -font $textWidgetFont } -body { .t tag configure big -font $bigFont .t tag bind a {.t tag add big 3.0 3.2} @@ -1432,6 +1463,7 @@ test textTag-16.7 {TkTextPickCurrent procedure} -setup { .t index current } -cleanup { .t tag delete a big + .t configure -font $curFont } -result {3.1} -- cgit v0.12 From 9d9cee0288f4ef2d88ddaa3a3f41c34751d851fd Mon Sep 17 00:00:00 2001 From: fvogel Date: Thu, 1 Dec 2016 19:27:08 +0000 Subject: Also the fact that the actually used fonts must be fixed-width needs to be checked when assessing the value of the haveFontSizes constraint --- tests/textTag.test | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/textTag.test b/tests/textTag.test index a2b2d73..6489c3a 100644 --- a/tests/textTag.test +++ b/tests/textTag.test @@ -12,16 +12,18 @@ eval tcltest::configure $argv tcltest::loadTestedCommands set textWidgetFont {Courier 12} -set bigFont {Helvetica 24} +set bigFont {Courier 24} -# what is needed is a specific font *size* because in some tests (that -# will be constrained by haveFontSizes), a tag applying the $bigFont -# will be set to some characters, which action has the effect of -# changing what character is under the mouse pointer, which is the -# purpose of the tests +# what is needed is a font that is both fixed-width and featuring a +# specific size because in some tests (that will be constrained by +# haveFontSizes), a tag applying the $bigFont will be set to some +# characters, which action has the effect of changing what character +# is under the mouse pointer, which is the purpose of the tests testConstraint haveFontSizes [expr { - [font actual $textWidgetFont -size] == 12 && - [font actual $bigFont -size] == 24 } + [font metrics $textWidgetFont -fixed] && + [font actual $textWidgetFont -size] == 12 && + [font metrics $bigFont -fixed] && + [font actual $bigFont -size] == 24 } ] destroy .t -- cgit v0.12 From cabe11c363724790cf77f9a1c39b27703d0093b9 Mon Sep 17 00:00:00 2001 From: fvogel Date: Thu, 1 Dec 2016 21:45:34 +0000 Subject: When changing the text font, (x,y) coordinates previously saved in the (xi,yi) doublets are no longer relevant. Save coordinates for each of the two font possibilities, and use the right ones in each test. --- tests/textTag.test | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/tests/textTag.test b/tests/textTag.test index 6489c3a..ca34bc7 100644 --- a/tests/textTag.test +++ b/tests/textTag.test @@ -1210,7 +1210,8 @@ test textTag-14.4 {SortTags} -setup { } -result {x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29} - +set curFont [.t cget -font] +set curWrap [.t cget -wrap] set c [.t bbox 2.1] set x1 [expr [lindex $c 0] + [lindex $c 2]/2] set y1 [expr [lindex $c 1] + [lindex $c 3]/2] @@ -1220,6 +1221,15 @@ set y2 [expr [lindex $c 1] + [lindex $c 3]/2] set c [.t bbox 4.3] set x3 [expr [lindex $c 0] + [lindex $c 2]/2] set y3 [expr [lindex $c 1] + [lindex $c 3]/2] +.t configure -font $textWidgetFont -wrap none +update +set c [.t bbox 2.1] +set x4 [expr [lindex $c 0] + [lindex $c 2]/2] +set y4 [expr [lindex $c 1] + [lindex $c 3]/2] +set c [.t bbox 3.2] +set x5 [expr [lindex $c 0] + [lindex $c 2]/2] +set y5 [expr [lindex $c 1] + [lindex $c 3]/2] +.t configure -font $curFont -wrap $curWrap test textTag-15.1 {TkTextBindProc} -setup { .t tag delete x y @@ -1333,18 +1343,18 @@ test textTag-16.2 {TkTextPickCurrent procedure} -constraints { .t tag delete {*}[.t tag names] event generate {} -warp 1 -x -1 -y -1; update set curFont [.t cget -font] - .t configure -font $textWidgetFont + .t configure -font $textWidgetFont -wrap none } -body { .t tag configure big -font $bigFont - event gen .t -state 0x100 -x $x1 -y $y1 - event gen .t -x $x2 -y $y2 + event gen .t -state 0x100 -x $x4 -y $y4 + event gen .t -x $x5 -y $y5 set x [.t index current] .t tag add big 3.0 update lappend x [.t index current] } -cleanup { .t tag delete big - .t configure -font $curFont + .t configure -font $curFont -wrap $curWrap } -result {3.2 3.1} test textTag-16.3 {TkTextPickCurrent procedure} -setup { @@ -1408,17 +1418,17 @@ test textTag-16.5 {TkTextPickCurrent procedure} -constraints { } event generate {} -warp 1 -x -1 -y -1; update set curFont [.t cget -font] - .t configure -font $textWidgetFont + .t configure -font $textWidgetFont -wrap none } -body { .t tag configure big -font $bigFont - event gen .t -x $x1 -y $y1 + event gen .t -x $x4 -y $y4 .t tag bind a {.t tag add big 3.0 3.2} .t tag add a 3.2 - event gen .t -x $x2 -y $y2 + event gen .t -x $x5 -y $y5 .t index current } -cleanup { .t tag delete a big - .t configure -font $curFont + .t configure -font $curFont -wrap $curWrap } -result {3.2} test textTag-16.6 {TkTextPickCurrent procedure} -constraints { @@ -1429,18 +1439,18 @@ test textTag-16.6 {TkTextPickCurrent procedure} -constraints { } event generate {} -warp 1 -x -1 -y -1; update set curFont [.t cget -font] - .t configure -font $textWidgetFont + .t configure -font $textWidgetFont -wrap none } -body { .t tag configure big -font $bigFont - event gen .t -x $x1 -y $y1 + event gen .t -x $x4 -y $y4 .t tag bind a {.t tag add big 3.0 3.2} .t tag add a 3.2 - event gen .t -x $x2 -y $y2 + event gen .t -x $x5 -y $y5 update .t index current } -cleanup { .t tag delete a big - .t configure -font $curFont + .t configure -font $curFont -wrap $curWrap } -result {3.1} test textTag-16.7 {TkTextPickCurrent procedure} -constraints { @@ -1451,21 +1461,21 @@ test textTag-16.7 {TkTextPickCurrent procedure} -constraints { } event generate {} -warp 1 -x -1 -y -1; update set curFont [.t cget -font] - .t configure -font $textWidgetFont + .t configure -font $textWidgetFont -wrap none } -body { .t tag configure big -font $bigFont .t tag bind a {.t tag add big 3.0 3.2} .t tag add a 3.2 - event gen .t -x $x1 -y $y1 + event gen .t -x $x4 -y $y4 .t tag bind a {.t tag add big 3.0 3.2} .t tag add a 2.1 - event gen .t -x $x2 -y $y2 + event gen .t -x $x5 -y $y5 update .t index current } -cleanup { .t tag delete a big - .t configure -font $curFont + .t configure -font $curFont -wrap $curWrap } -result {3.1} -- cgit v0.12 From 954d42e47de744904aac4b8d78c7f7b4048e8a17 Mon Sep 17 00:00:00 2001 From: fvogel Date: Fri, 2 Dec 2016 06:35:22 +0000 Subject: Remove superfluous lines (the default font of the text widget is already saved in $curFont before the tests start). --- tests/textTag.test | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/textTag.test b/tests/textTag.test index ca34bc7..93feb27 100644 --- a/tests/textTag.test +++ b/tests/textTag.test @@ -1342,7 +1342,6 @@ test textTag-16.2 {TkTextPickCurrent procedure} -constraints { } -setup { .t tag delete {*}[.t tag names] event generate {} -warp 1 -x -1 -y -1; update - set curFont [.t cget -font] .t configure -font $textWidgetFont -wrap none } -body { .t tag configure big -font $bigFont @@ -1417,7 +1416,6 @@ test textTag-16.5 {TkTextPickCurrent procedure} -constraints { .t tag remove $i 1.0 end } event generate {} -warp 1 -x -1 -y -1; update - set curFont [.t cget -font] .t configure -font $textWidgetFont -wrap none } -body { .t tag configure big -font $bigFont @@ -1438,7 +1436,6 @@ test textTag-16.6 {TkTextPickCurrent procedure} -constraints { .t tag remove $i 1.0 end } event generate {} -warp 1 -x -1 -y -1; update - set curFont [.t cget -font] .t configure -font $textWidgetFont -wrap none } -body { .t tag configure big -font $bigFont @@ -1460,7 +1457,6 @@ test textTag-16.7 {TkTextPickCurrent procedure} -constraints { .t tag remove $i 1.0 end } event generate {} -warp 1 -x -1 -y -1; update - set curFont [.t cget -font] .t configure -font $textWidgetFont -wrap none } -body { .t tag configure big -font $bigFont -- cgit v0.12 From fd7ab722c98be2bee1064d8721bbcae710a74f14 Mon Sep 17 00:00:00 2001 From: dgp Date: Fri, 2 Dec 2016 12:57:58 +0000 Subject: [76e2d9c095] Repair broken test border-3.1 --- tests/border.test | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/border.test b/tests/border.test index 2ca64c1..d6ff5c7 100644 --- a/tests/border.test +++ b/tests/border.test @@ -127,16 +127,18 @@ test border-2.2 {Tk_Free3DBorder - unlinking from list} -constraints { destroy .b .t2 .t3 .t } -result {{{4 1} {3 0} {2 0} {1 0}} {{4 1} {2 0} {1 0}} {{4 1} {2 0}} {{2 0}} {}} + test border-3.1 {FreeBorderObjProc} -constraints { testborder } -setup { set result {} + proc copy {s} {return [string index $s 0][string range $s 1 end]} } -body { - set x [join purple] + set x [copy purple] button .b -bg $x -text .b1 - set y [join purple] + set y [copy purple] .b configure -bg $y - set z [join purple] + set z [copy purple] .b configure -bg $z lappend result [testborder purple] set x red @@ -148,6 +150,7 @@ test border-3.1 {FreeBorderObjProc} -constraints { set y bogus return $result } -cleanup { + rename copy {} destroy .b } -result {{{1 3}} {{1 2}} {{1 1}} {}} -- cgit v0.12 From c9609fa27feeb754fbbaa92539825a04d2c4d7f6 Mon Sep 17 00:00:00 2001 From: fvogel Date: Fri, 2 Dec 2016 20:58:36 +0000 Subject: Fix [ad98f10b3a] and [bd0017bf79] - bitmap-4.1 and cursor-4.1 tests failures. Also, apply again the same pattern to fix color-4.1 that was also failing (when the colorsFree constraint was met) despite there was no such report (yet). Thanks to dgp. --- tests/bitmap.test | 9 ++++++--- tests/color.test | 16 +++++++++++----- tests/cursor.test | 9 ++++++--- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/tests/bitmap.test b/tests/bitmap.test index bd9c47f..6996f88 100644 --- a/tests/bitmap.test +++ b/tests/bitmap.test @@ -84,12 +84,14 @@ test bitmap-3.1 {Tk_FreeBitmapFromObj - reference counts} -constraints { test bitmap-4.1 {FreeBitmapObjProc} -constraints { testbitmap +} -setup { + proc copy {s} {return [string index $s 0][string range $s 1 end]} } -body { - set x [join questhead] + set x [copy questhead] button .b -bitmap $x - set y [join questhead] + set y [copy questhead] .b configure -bitmap $y - set z [join questhead] + set z [copy questhead] .b configure -bitmap $z set result {} lappend result [testbitmap questhead] @@ -102,6 +104,7 @@ test bitmap-4.1 {FreeBitmapObjProc} -constraints { set y bogus return $result } -cleanup { + rename copy {} destroy .b } -result {{{1 3}} {{1 2}} {{1 1}} {}} diff --git a/tests/color.test b/tests/color.test index 237ec01..0b328cf 100644 --- a/tests/color.test +++ b/tests/color.test @@ -255,13 +255,17 @@ test color-3.4 {Tk_FreeColorFromObj - unlinking from list} colorsFree { lappend result [testcolor purple] } {{{4 1} {3 0} {2 0} {1 0}} {{4 1} {2 0} {1 0}} {{4 1} {2 0}} {{2 0}} {}} -test color-4.1 {FreeColorObjProc} colorsFree { +test color-4.1 {FreeColorObjProc} -constraints { + colorsFree +} -setup { + proc copy {s} {return [string index $s 0][string range $s 1 end]} +} -body { destroy .b - set x [format purple] + set x [copy purple] button .b -foreground $x -text .b1 - set y [format purple] + set y [copy purple] .b configure -foreground $y - set z [format purple] + set z [copy purple] .b configure -foreground $z set result {} lappend result [testcolor purple] @@ -273,7 +277,9 @@ test color-4.1 {FreeColorObjProc} colorsFree { lappend result [testcolor purple] set y bogus set result -} {{{1 3}} {{1 2}} {{1 1}} {}} +} -cleanup { + rename copy {} +} -result {{{1 3}} {{1 2}} {{1 1}} {}} destroy .t diff --git a/tests/cursor.test b/tests/cursor.test index 95c7b99..8d7ebb0 100644 --- a/tests/cursor.test +++ b/tests/cursor.test @@ -144,12 +144,14 @@ test cursor-3.1 {Tk_FreeCursorFromObj - reference counts} -constraints { test cursor-4.1 {FreeCursorObjProc} -constraints { testcursor +} -setup { + proc copy {s} {return [string index $s 0][string range $s 1 end]} } -body { - set x [join heart] + set x [copy heart] button .b -cursor $x - set y [join heart] + set y [copy heart] .b configure -cursor $y - set z [join heart] + set z [copy heart] .b configure -cursor $z set result {} lappend result [testcursor heart] @@ -162,6 +164,7 @@ test cursor-4.1 {FreeCursorObjProc} -constraints { set y bogus set result } -cleanup { + rename copy {} destroy .b } -result {{{1 3}} {{1 2}} {{1 1}} {}} -- cgit v0.12 From e63cc287cacc144a9a0a5c405d49cca44b37e574 Mon Sep 17 00:00:00 2001 From: fvogel Date: Thu, 8 Dec 2016 20:46:48 +0000 Subject: Micro-optimization in tkTextDisp.c --- generic/tkTextDisp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c index a6e665a..1c4925d 100644 --- a/generic/tkTextDisp.c +++ b/generic/tkTextDisp.c @@ -8981,13 +8981,13 @@ RemoveFromBaseChunk( bciPtr = baseCharChunkPtr->clientData; +#ifdef DEBUG_LAYOUT_WITH_BASE_CHUNKS if ((ciPtr->baseOffset + ciPtr->numBytes) != Tcl_DStringLength(&bciPtr->baseChars)) { -#ifdef DEBUG_LAYOUT_WITH_BASE_CHUNKS fprintf(stderr,"RemoveFromBaseChunk called with wrong chunk " "(not last)\n"); -#endif } +#endif Tcl_DStringSetLength(&bciPtr->baseChars, ciPtr->baseOffset); -- cgit v0.12 From 6130ca3ef131a8459a378ee9e3fa67484d6fe178 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 15 Dec 2016 16:07:06 +0000 Subject: Proposed fix for [7d967c68a09e07e355358af40f36dd5dd84c7022|7d967c68]: Tk applications segmentation fault when ibus-daemon IME is restarted --- generic/tkEvent.c | 13 ++++++++++++- generic/tkInt.h | 6 ++++++ generic/tkWindow.c | 11 +++++++++-- unix/tkUnixEvent.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 3 deletions(-) diff --git a/generic/tkEvent.c b/generic/tkEvent.c index 95aeda1..d058e7c 100644 --- a/generic/tkEvent.c +++ b/generic/tkEvent.c @@ -356,6 +356,7 @@ CreateXIC( /* XCreateIC failed. */ return; } + winPtr->ximGeneration = dispPtr->ximGeneration; /* * Adjust the window's event mask if the IM requires it. @@ -1288,6 +1289,14 @@ Tk_HandleEvent( */ #ifdef TK_USE_INPUT_METHODS + /* + * If the XIC has been invalidated, it must be recreated. + */ + if (winPtr->dispPtr->ximGeneration != winPtr->ximGeneration) { + winPtr->flags &= ~TK_CHECKED_IC; + winPtr->inputContext = NULL; + } + if ((winPtr->dispPtr->flags & TK_DISPLAY_USE_IM)) { if (!(winPtr->flags & (TK_CHECKED_IC|TK_ALREADY_DEAD))) { winPtr->flags |= TK_CHECKED_IC; @@ -1295,7 +1304,9 @@ Tk_HandleEvent( CreateXIC(winPtr); } } - if (eventPtr->type == FocusIn && winPtr->inputContext != NULL) { + if ((eventPtr->type == FocusIn) && + (winPtr->dispPtr->inputMethod != NULL) && + (winPtr->inputContext != NULL)) { XSetICFocus(winPtr->inputContext); } } diff --git a/generic/tkInt.h b/generic/tkInt.h index 1615a81..f00d833 100644 --- a/generic/tkInt.h +++ b/generic/tkInt.h @@ -508,6 +508,9 @@ typedef struct TkDisplay { int iconDataSize; /* Size of default iconphoto image data. */ unsigned char *iconDataPtr; /* Default iconphoto image data, if set. */ +#ifdef TK_USE_INPUT_METHODS + int ximGeneration; /* Used to invalidate XIC */ +#endif /* TK_USE_INPUT_METHODS */ } TkDisplay; /* @@ -809,6 +812,9 @@ typedef struct TkWindow { int minReqWidth; /* Minimum requested width. */ int minReqHeight; /* Minimum requested height. */ char *geometryMaster; +#ifdef TK_USE_INPUT_METHODS + int ximGeneration; /* Used to invalidate XIC */ +#endif /* TK_USE_INPUT_METHODS */ } TkWindow; /* diff --git a/generic/tkWindow.c b/generic/tkWindow.c index 5855b7c..85c5590 100644 --- a/generic/tkWindow.c +++ b/generic/tkWindow.c @@ -355,6 +355,9 @@ CreateTopLevelWindow( * Set the flags specified in the call. */ +#ifdef TK_USE_INPUT_METHODS + winPtr->ximGeneration = 0; +#endif /*TK_USE_INPUT_METHODS*/ winPtr->flags |= flags; /* @@ -472,6 +475,9 @@ GetScreen( dispPtr->cursorFont = None; dispPtr->warpWindow = NULL; dispPtr->multipleAtom = None; +#ifdef TK_USE_INPUT_METHODS + dispPtr->ximGeneration = 0; +#endif /*TK_USE_INPUT_METHODS*/ /* * By default we do want to collapse motion events in @@ -1442,10 +1448,11 @@ Tk_DestroyWindow( UnlinkWindow(winPtr); TkEventDeadWindow(winPtr); #ifdef TK_USE_INPUT_METHODS - if (winPtr->inputContext != NULL) { + if (winPtr->inputContext != NULL && + winPtr->ximGeneration == winPtr->dispPtr->ximGeneration) { XDestroyIC(winPtr->inputContext); - winPtr->inputContext = NULL; } + winPtr->inputContext = NULL; #endif /* TK_USE_INPUT_METHODS */ if (winPtr->tagPtr != NULL) { TkFreeBindingTags(winPtr); diff --git a/unix/tkUnixEvent.c b/unix/tkUnixEvent.c index f3beb16..111d430 100644 --- a/unix/tkUnixEvent.c +++ b/unix/tkUnixEvent.c @@ -38,6 +38,8 @@ static void DisplayFileProc(ClientData clientData, int flags); static void DisplaySetupProc(ClientData clientData, int flags); static void TransferXEventsToTcl(Display *display); #ifdef TK_USE_INPUT_METHODS +static void InstantiateIMCallback(Display *, XPointer client_data, XPointer call_data); +static void DestroyIMCallback(XIM im, XPointer client_data, XPointer call_data); static void OpenIM(TkDisplay *dispPtr); #endif @@ -179,6 +181,8 @@ TkpOpenDisplay( dispPtr->flags |= use_xkb; #ifdef TK_USE_INPUT_METHODS OpenIM(dispPtr); + XRegisterIMInstantiateCallback(dispPtr->display, NULL, NULL, NULL, + InstantiateIMCallback, (XPointer) dispPtr); #endif Tcl_CreateFileHandler(ConnectionNumber(display), TCL_READABLE, DisplayFileProc, dispPtr); @@ -664,6 +668,35 @@ TkpSync( } #ifdef TK_USE_INPUT_METHODS +static void +InstantiateIMCallback( + Display *display, + XPointer client_data, + XPointer call_data) +{ + TkDisplay *dispPtr; + + dispPtr = (TkDisplay *) client_data; + OpenIM(dispPtr); + XUnregisterIMInstantiateCallback(dispPtr->display, NULL, NULL, NULL, + InstantiateIMCallback, (XPointer) dispPtr); +} + +static void +DestroyIMCallback( + XIM im, + XPointer client_data, + XPointer call_data) +{ + TkDisplay *dispPtr; + + dispPtr = (TkDisplay *) client_data; + dispPtr->inputMethod = NULL; + ++dispPtr->ximGeneration; + XRegisterIMInstantiateCallback(dispPtr->display, NULL, NULL, NULL, + InstantiateIMCallback, (XPointer) dispPtr); +} + /* *-------------------------------------------------------------- * @@ -693,11 +726,23 @@ OpenIM( return; } + ++dispPtr->ximGeneration; dispPtr->inputMethod = XOpenIM(dispPtr->display, NULL, NULL, NULL); if (dispPtr->inputMethod == NULL) { return; } + /* Require X11R6 */ + { + XIMCallback destroy_cb; + + destroy_cb.callback = DestroyIMCallback; + destroy_cb.client_data = (XPointer) dispPtr; + if (XSetIMValues(dispPtr->inputMethod, XNDestroyCallback, + &destroy_cb, NULL)) + goto error; + } + if ((XGetIMValues(dispPtr->inputMethod, XNQueryInputStyle, &stylePtr, NULL) != NULL) || (stylePtr == NULL)) { goto error; @@ -744,6 +789,7 @@ error: if (dispPtr->inputMethod) { XCloseIM(dispPtr->inputMethod); dispPtr->inputMethod = NULL; + ++dispPtr->ximGeneration; } } #endif /* TK_USE_INPUT_METHODS */ -- cgit v0.12