-- cgit v0.12 From d6e49238a94a313ec7fa612387ad1c72211ea479 Mon Sep 17 00:00:00 2001 From: bll Date: Wed, 20 May 2020 15:43:52 +0000 Subject: Work around a windows vsapi issue where the size returned for a vsapi element changes upon fetching the size a second time. --- win/ttkWinXPTheme.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/win/ttkWinXPTheme.c b/win/ttkWinXPTheme.c index 4391fdd..c32d3cd 100644 --- a/win/ttkWinXPTheme.c +++ b/win/ttkWinXPTheme.c @@ -373,6 +373,10 @@ static Ttk_StateTable tabitem_statemap[] = * <>: * This gives bogus metrics for some parts (in particular, * BP_PUSHBUTTONS). Set the IGNORE_THEMESIZE flag to skip this call. + * + * <>: + * It seems that fetching the part size more than once on checkbuttons + * and radiobuttons does not work properly. */ typedef struct /* XP element specifications */ @@ -390,6 +394,7 @@ typedef struct /* XP element specifications */ # define HEAP_ELEMENT 0x20000000U /* ElementInfo is on heap */ # define HALF_HEIGHT 0x10000000U /* Used by GenericSizedElements */ # define HALF_WIDTH 0x08000000U /* Used by GenericSizedElements */ +# define FETCH_ONCE 0x04000000U /* Used by GenericElementSize See NOTE-GetThemePartSize-2 */ } ElementInfo; typedef struct @@ -407,6 +412,12 @@ typedef struct HDC hDC; HWND hwnd; + /* + * To work around fetch of size returning wrong data + */ + SIZE origSize; + int fetched; + /* For TkWinDrawableReleaseDC: */ Drawable drawable; TkWinDCState dcState; @@ -420,6 +431,7 @@ NewElementData(XPThemeProcs *procs, ElementInfo *info) elementData->procs = procs; elementData->info = info; elementData->hTheme = elementData->hDC = 0; + elementData->fetched = 0; return elementData; } @@ -508,19 +520,28 @@ static void GenericElementSize( return; if (!(elementData->info->flags & IGNORE_THEMESIZE)) { - result = elementData->procs->GetThemePartSize( - elementData->hTheme, - elementData->hDC, - elementData->info->partId, - Ttk_StateTableLookup(elementData->info->statemap, 0), - NULL /*RECT *prc*/, - TS_TRUE, - &size); + if ((elementData->info->flags & FETCH_ONCE) && elementData->fetched) { + size = elementData->origSize; + result = 0; /* non-negative is success */ + } else { + result = elementData->procs->GetThemePartSize( + elementData->hTheme, + elementData->hDC, + elementData->info->partId, + Ttk_StateTableLookup(elementData->info->statemap, 0), + NULL /*RECT *prc*/, + TS_TRUE, + &size); + } if (SUCCEEDED(result)) { *widthPtr = size.cx; *heightPtr = size.cy; } + if ((elementData->info->flags & FETCH_ONCE) && ! elementData->fetched) { + elementData->origSize = size; + elementData->fetched = 1; + } } /* See NOTE-GetThemeMargins @@ -966,9 +987,9 @@ TTK_END_LAYOUT_TABLE static ElementInfo ElementInfoTable[] = { { "Checkbutton.indicator", &GenericElementSpec, L"BUTTON", - BP_CHECKBOX, checkbox_statemap, PAD(0, 0, 4, 0), PAD_MARGINS }, + BP_CHECKBOX, checkbox_statemap, PAD(0, 0, 4, 0), PAD_MARGINS | FETCH_ONCE }, { "Radiobutton.indicator", &GenericElementSpec, L"BUTTON", - BP_RADIOBUTTON, radiobutton_statemap, PAD(0, 0, 4, 0), PAD_MARGINS }, + BP_RADIOBUTTON, radiobutton_statemap, PAD(0, 0, 4, 0), PAD_MARGINS | FETCH_ONCE }, { "Button.button", &GenericElementSpec, L"BUTTON", BP_PUSHBUTTON, pushbutton_statemap, PAD(3, 3, 3, 3), IGNORE_THEMESIZE }, { "Labelframe.border", &GenericElementSpec, L"BUTTON", -- cgit v0.12 From 36975c88f715a973f160b5f6627d89965ebbb06e Mon Sep 17 00:00:00 2001 From: fvogel Date: Sun, 24 May 2020 10:51:11 +0000 Subject: Use S_OK for result instead of directly 0. --- win/ttkWinXPTheme.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/win/ttkWinXPTheme.c b/win/ttkWinXPTheme.c index c32d3cd..f91be9b 100644 --- a/win/ttkWinXPTheme.c +++ b/win/ttkWinXPTheme.c @@ -522,7 +522,7 @@ static void GenericElementSize( if (!(elementData->info->flags & IGNORE_THEMESIZE)) { if ((elementData->info->flags & FETCH_ONCE) && elementData->fetched) { size = elementData->origSize; - result = 0; /* non-negative is success */ + result = S_OK; } else { result = elementData->procs->GetThemePartSize( elementData->hTheme, @@ -538,7 +538,7 @@ static void GenericElementSize( *widthPtr = size.cx; *heightPtr = size.cy; } - if ((elementData->info->flags & FETCH_ONCE) && ! elementData->fetched) { + if ((elementData->info->flags & FETCH_ONCE) && !elementData->fetched) { elementData->origSize = size; elementData->fetched = 1; } -- cgit v0.12 From 5da5fa8645eacfb6a876212e959f93a6603e1c5b Mon Sep 17 00:00:00 2001 From: bll Date: Sun, 24 May 2020 15:00:22 +0000 Subject: Add FETCH_ONCE to the treeview indicator also. --- win/ttkWinXPTheme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/win/ttkWinXPTheme.c b/win/ttkWinXPTheme.c index f91be9b..3252a18 100644 --- a/win/ttkWinXPTheme.c +++ b/win/ttkWinXPTheme.c @@ -1058,7 +1058,7 @@ static ElementInfo ElementInfoTable[] = { { "Treeview.field", &GenericElementSpec, L"TREEVIEW", TVP_TREEITEM, treeview_statemap, PAD(1, 1, 1, 1), IGNORE_THEMESIZE }, { "Treeitem.indicator", &TreeIndicatorElementSpec, L"TREEVIEW", - TVP_GLYPH, tvpglyph_statemap, PAD(1,1,6,0), PAD_MARGINS }, + TVP_GLYPH, tvpglyph_statemap, PAD(1,1,6,0), PAD_MARGINS | FETCH_ONCE }, { "Treeheading.border", &GenericElementSpec, L"HEADER", HP_HEADERITEM, header_statemap, PAD(4,0,4,0),0 }, { "sizegrip", &GenericElementSpec, L"STATUS", -- cgit v0.12 From 343083448bf1002eaefaedcee770d7641a653bda Mon Sep 17 00:00:00 2001 From: bll Date: Sun, 24 May 2020 20:58:18 +0000 Subject: Implement a much simpler method to get the proper sizing (nemethi). --- win/ttkWinXPTheme.c | 43 +++++++++++-------------------------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/win/ttkWinXPTheme.c b/win/ttkWinXPTheme.c index 3252a18..436fe00 100644 --- a/win/ttkWinXPTheme.c +++ b/win/ttkWinXPTheme.c @@ -373,10 +373,6 @@ static Ttk_StateTable tabitem_statemap[] = * <>: * This gives bogus metrics for some parts (in particular, * BP_PUSHBUTTONS). Set the IGNORE_THEMESIZE flag to skip this call. - * - * <>: - * It seems that fetching the part size more than once on checkbuttons - * and radiobuttons does not work properly. */ typedef struct /* XP element specifications */ @@ -394,7 +390,6 @@ typedef struct /* XP element specifications */ # define HEAP_ELEMENT 0x20000000U /* ElementInfo is on heap */ # define HALF_HEIGHT 0x10000000U /* Used by GenericSizedElements */ # define HALF_WIDTH 0x08000000U /* Used by GenericSizedElements */ -# define FETCH_ONCE 0x04000000U /* Used by GenericElementSize See NOTE-GetThemePartSize-2 */ } ElementInfo; typedef struct @@ -412,12 +407,6 @@ typedef struct HDC hDC; HWND hwnd; - /* - * To work around fetch of size returning wrong data - */ - SIZE origSize; - int fetched; - /* For TkWinDrawableReleaseDC: */ Drawable drawable; TkWinDCState dcState; @@ -431,7 +420,6 @@ NewElementData(XPThemeProcs *procs, ElementInfo *info) elementData->procs = procs; elementData->info = info; elementData->hTheme = elementData->hDC = 0; - elementData->fetched = 0; return elementData; } @@ -520,28 +508,19 @@ static void GenericElementSize( return; if (!(elementData->info->flags & IGNORE_THEMESIZE)) { - if ((elementData->info->flags & FETCH_ONCE) && elementData->fetched) { - size = elementData->origSize; - result = S_OK; - } else { - result = elementData->procs->GetThemePartSize( - elementData->hTheme, - elementData->hDC, - elementData->info->partId, - Ttk_StateTableLookup(elementData->info->statemap, 0), - NULL /*RECT *prc*/, - TS_TRUE, - &size); - } + result = elementData->procs->GetThemePartSize( + elementData->hTheme, + NULL, + elementData->info->partId, + Ttk_StateTableLookup(elementData->info->statemap, 0), + NULL /*RECT *prc*/, + TS_TRUE, + &size); if (SUCCEEDED(result)) { *widthPtr = size.cx; *heightPtr = size.cy; } - if ((elementData->info->flags & FETCH_ONCE) && !elementData->fetched) { - elementData->origSize = size; - elementData->fetched = 1; - } } /* See NOTE-GetThemeMargins @@ -987,9 +966,9 @@ TTK_END_LAYOUT_TABLE static ElementInfo ElementInfoTable[] = { { "Checkbutton.indicator", &GenericElementSpec, L"BUTTON", - BP_CHECKBOX, checkbox_statemap, PAD(0, 0, 4, 0), PAD_MARGINS | FETCH_ONCE }, + BP_CHECKBOX, checkbox_statemap, PAD(0, 0, 4, 0), PAD_MARGINS }, { "Radiobutton.indicator", &GenericElementSpec, L"BUTTON", - BP_RADIOBUTTON, radiobutton_statemap, PAD(0, 0, 4, 0), PAD_MARGINS | FETCH_ONCE }, + BP_RADIOBUTTON, radiobutton_statemap, PAD(0, 0, 4, 0), PAD_MARGINS }, { "Button.button", &GenericElementSpec, L"BUTTON", BP_PUSHBUTTON, pushbutton_statemap, PAD(3, 3, 3, 3), IGNORE_THEMESIZE }, { "Labelframe.border", &GenericElementSpec, L"BUTTON", @@ -1058,7 +1037,7 @@ static ElementInfo ElementInfoTable[] = { { "Treeview.field", &GenericElementSpec, L"TREEVIEW", TVP_TREEITEM, treeview_statemap, PAD(1, 1, 1, 1), IGNORE_THEMESIZE }, { "Treeitem.indicator", &TreeIndicatorElementSpec, L"TREEVIEW", - TVP_GLYPH, tvpglyph_statemap, PAD(1,1,6,0), PAD_MARGINS | FETCH_ONCE }, + TVP_GLYPH, tvpglyph_statemap, PAD(1,1,6,0), PAD_MARGINS }, { "Treeheading.border", &GenericElementSpec, L"HEADER", HP_HEADERITEM, header_statemap, PAD(4,0,4,0),0 }, { "sizegrip", &GenericElementSpec, L"STATUS", -- cgit v0.12 From 9d65143eb6ec4d77828501177d7275b0c84b5958 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 27 May 2020 10:47:08 +0000 Subject: A few more tweaks, using size_t in Tcl 9 builds. --- generic/tkText.c | 7 +++---- generic/ttk/ttkEntry.c | 22 +++++++++++----------- generic/ttk/ttkNotebook.c | 48 +++++++++++++++++++++++------------------------ 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/generic/tkText.c b/generic/tkText.c index 0c4d74c..2f5991b 100644 --- a/generic/tkText.c +++ b/generic/tkText.c @@ -3425,7 +3425,8 @@ TextFetchSelection( { TkText *textPtr = (TkText *)clientData; TkTextIndex eof; - int count, chunkSize, offsetInSeg; + int count, chunkSize; + TkSizeT offsetInSeg; TkTextSearch search; TkTextSegment *segPtr; @@ -3484,12 +3485,10 @@ TextFetchSelection( */ while (1) { - TkSizeT offsetInSeg1; if (maxBytes == 0) { goto fetchDone; } - segPtr = TkTextIndexToSeg(&textPtr->selIndex, &offsetInSeg1); - offsetInSeg = offsetInSeg1; + segPtr = TkTextIndexToSeg(&textPtr->selIndex, &offsetInSeg); chunkSize = segPtr->size - offsetInSeg; if (chunkSize > (int)maxBytes) { chunkSize = (int)maxBytes; diff --git a/generic/ttk/ttkEntry.c b/generic/ttk/ttkEntry.c index aedc384..e07617c 100644 --- a/generic/ttk/ttkEntry.c +++ b/generic/ttk/ttkEntry.c @@ -1756,7 +1756,7 @@ typedef struct { Tcl_Obj *postCommandObj; Tcl_Obj *valuesObj; Tcl_Obj *heightObj; - int currentIndex; + TkSizeT currentIndex; } ComboboxPart; typedef struct { @@ -1786,7 +1786,7 @@ ComboboxInitialize(Tcl_Interp *interp, void *recordPtr) { Combobox *cb = (Combobox *)recordPtr; - cb->combobox.currentIndex = -1; + cb->combobox.currentIndex = TCL_INDEX_NONE; TtkTrackElementState(&cb->core); EntryInitialize(interp, recordPtr); } @@ -1818,35 +1818,35 @@ static int ComboboxCurrentCommand( void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { Combobox *cbPtr = (Combobox *)recordPtr; - int currentIndex = cbPtr->combobox.currentIndex; + TkSizeT currentIndex = cbPtr->combobox.currentIndex; const char *currentValue = cbPtr->entry.string; int nValues; Tcl_Obj **values; - Tcl_ListObjGetElements(interp,cbPtr->combobox.valuesObj,&nValues,&values); + Tcl_ListObjGetElements(interp, cbPtr->combobox.valuesObj, &nValues, &values); if (objc == 2) { /* Check if currentIndex still valid: */ - if ( currentIndex < 0 - || currentIndex >= nValues + if ( currentIndex == TCL_INDEX_NONE + || currentIndex >= (TkSizeT)nValues || strcmp(currentValue,Tcl_GetString(values[currentIndex])) ) { /* Not valid. Check current value against each element in -values: */ - for (currentIndex = 0; currentIndex < nValues; ++currentIndex) { + for (currentIndex = 0; currentIndex < (TkSizeT)nValues; ++currentIndex) { if (!strcmp(currentValue,Tcl_GetString(values[currentIndex]))) { break; } } - if (currentIndex >= nValues) { + if (currentIndex >= (TkSizeT)nValues) { /* Not found */ - currentIndex = -1; + currentIndex = TCL_INDEX_NONE; } } cbPtr->combobox.currentIndex = currentIndex; - Tcl_SetObjResult(interp, Tcl_NewWideIntObj(currentIndex)); + Tcl_SetObjResult(interp, Tcl_NewWideIntObj((int)currentIndex)); return TCL_OK; } else if (objc == 3) { TkSizeT idx; @@ -1858,7 +1858,7 @@ static int ComboboxCurrentCommand( Tcl_SetErrorCode(interp, "TTK", "COMBOBOX", "IDX_RANGE", NULL); return TCL_ERROR; } - currentIndex = (int)idx; + currentIndex = idx; } else { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "Incorrect index %s", Tcl_GetString(objv[2]))); diff --git a/generic/ttk/ttkNotebook.c b/generic/ttk/ttkNotebook.c index c17f255..7ad46a4 100644 --- a/generic/ttk/ttkNotebook.c +++ b/generic/ttk/ttkNotebook.c @@ -94,8 +94,8 @@ typedef struct Ttk_Manager *mgr; /* Geometry manager */ Tk_OptionTable tabOptionTable; /* Tab options */ Tk_OptionTable paneOptionTable; /* Tab+pane options */ - int currentIndex; /* index of currently selected tab */ - int activeIndex; /* index of currently active tab */ + TkSizeT currentIndex; /* index of currently selected tab */ + TkSizeT activeIndex; /* index of currently active tab */ Ttk_Layout tabLayout; /* Sublayout for tabs */ Ttk_Box clientArea; /* Where to pack slave widgets */ @@ -272,7 +272,7 @@ static TkSizeT IdentifyTab(Notebook *nb, int x, int y) * ActivateTab -- * Set the active tab index, redisplay if necessary. */ -static void ActivateTab(Notebook *nb, int index) +static void ActivateTab(Notebook *nb, TkSizeT index) { if (index != nb->notebook.activeIndex) { nb->notebook.activeIndex = index; @@ -293,13 +293,13 @@ static Ttk_State TabState(Notebook *nb, TkSizeT index) Tab *tab = (Tab *)Ttk_SlaveData(nb->notebook.mgr, index); TkSizeT i = 0; - if ((int)index == nb->notebook.currentIndex) { + if (index == nb->notebook.currentIndex) { state |= TTK_STATE_SELECTED; } else { state &= ~TTK_STATE_FOCUS; } - if ((int)index == nb->notebook.activeIndex) { + if (index == nb->notebook.activeIndex) { state |= TTK_STATE_ACTIVE; } for (i = 0; i < Ttk_NumberSlaves(nb->notebook.mgr); ++i) { @@ -589,8 +589,8 @@ static void NotebookPlaceSlave(Notebook *nb, TkSizeT slaveIndex) static void NotebookPlaceSlaves(void *recordPtr) { Notebook *nb = (Notebook *)recordPtr; - int currentIndex = nb->notebook.currentIndex; - if (currentIndex >= 0) { + TkSizeT currentIndex = nb->notebook.currentIndex; + if (currentIndex != TCL_INDEX_NONE) { NotebookDoLayout(nb); NotebookPlaceSlave(nb, currentIndex); } @@ -700,11 +700,11 @@ static void TabRemoved(void *managerData, TkSizeT index) Notebook *nb = (Notebook *)managerData; Tab *tab = (Tab *)Ttk_SlaveData(nb->notebook.mgr, index); - if ((int)index == nb->notebook.currentIndex) { + if (index == nb->notebook.currentIndex) { SelectNearestTab(nb); } - if ((int)index < nb->notebook.currentIndex) { + if (index + 1 < nb->notebook.currentIndex + 1) { --nb->notebook.currentIndex; } @@ -728,7 +728,7 @@ static int TabRequest(void *managerData, TkSizeT index, int width, int height) */ static int AddTab( Tcl_Interp *interp, Notebook *nb, - int destIndex, Tk_Window slaveWindow, + TkSizeT destIndex, Tk_Window slaveWindow, int objc, Tcl_Obj *const objv[]) { Tab *tab; @@ -759,9 +759,9 @@ static int AddTab( /* Adjust indices and/or autoselect first tab: */ - if (nb->notebook.currentIndex < 0) { + if (nb->notebook.currentIndex == TCL_INDEX_NONE) { SelectTab(nb, destIndex); - } else if (nb->notebook.currentIndex >= destIndex) { + } else if (nb->notebook.currentIndex + 1 >= destIndex + 1) { ++nb->notebook.currentIndex; } @@ -940,7 +940,7 @@ static int NotebookInsertCommand( { Notebook *nb = (Notebook *)recordPtr; TkSizeT current = nb->notebook.currentIndex; - TkSizeT nSlaves1 = Ttk_NumberSlaves(nb->notebook.mgr); + TkSizeT nSlaves = Ttk_NumberSlaves(nb->notebook.mgr); TkSizeT srcIndex, destIndex; if (objc < 4) { @@ -985,14 +985,14 @@ static int NotebookInsertCommand( return TCL_ERROR; } - if (destIndex + 1 >= nSlaves1 + 1) { - destIndex = nSlaves1 - 1; + if (destIndex + 1 >= nSlaves + 1) { + destIndex = nSlaves - 1; } Ttk_ReorderSlave(nb->notebook.mgr, srcIndex, destIndex); /* Adjust internal indexes: */ - nb->notebook.activeIndex = -1; + nb->notebook.activeIndex = TCL_INDEX_NONE; if (current == srcIndex) { nb->notebook.currentIndex = destIndex; } else if (destIndex + 1 <= current + 1 && current + 1 < srcIndex + 1) { @@ -1051,7 +1051,7 @@ static int NotebookHideCommand( tab = (Tab *)Ttk_SlaveData(nb->notebook.mgr, index); tab->state = TAB_STATE_HIDDEN; - if (index == (TkSizeT)nb->notebook.currentIndex) { + if (index == nb->notebook.currentIndex) { SelectNearestTab(nb); } @@ -1151,7 +1151,7 @@ static int NotebookSelectCommand( Notebook *nb = (Notebook *)recordPtr; if (objc == 2) { - if (nb->notebook.currentIndex >= 0) { + if (nb->notebook.currentIndex != TCL_INDEX_NONE) { Tk_Window pane = Ttk_SlaveWindow( nb->notebook.mgr, nb->notebook.currentIndex); Tcl_SetObjResult(interp, Tcl_NewStringObj(Tk_PathName(pane), -1)); @@ -1233,7 +1233,7 @@ static int NotebookTabCommand( /* If the current tab has become disabled or hidden, * select the next nondisabled, unhidden one: */ - if (index == (TkSizeT)nb->notebook.currentIndex && tab->state != TAB_STATE_NORMAL) { + if (index == nb->notebook.currentIndex && tab->state != TAB_STATE_NORMAL) { SelectNearestTab(nb); } @@ -1273,8 +1273,8 @@ static void NotebookInitialize(Tcl_Interp *interp, void *recordPtr) nb->notebook.tabOptionTable = Tk_CreateOptionTable(interp,TabOptionSpecs); nb->notebook.paneOptionTable = Tk_CreateOptionTable(interp,PaneOptionSpecs); - nb->notebook.currentIndex = -1; - nb->notebook.activeIndex = -1; + nb->notebook.currentIndex = TCL_INDEX_NONE; + nb->notebook.activeIndex = TCL_INDEX_NONE; nb->notebook.tabLayout = 0; nb->notebook.clientArea = Ttk_MakeBox(0,0,1,1); @@ -1359,8 +1359,8 @@ static void DisplayTab(Notebook *nb, int index, Drawable d) static void NotebookDisplay(void *clientData, Drawable d) { Notebook *nb = (Notebook *)clientData; - int nSlaves = Ttk_NumberSlaves(nb->notebook.mgr); - int index; + TkSizeT nSlaves = Ttk_NumberSlaves(nb->notebook.mgr); + TkSizeT index; /* Draw notebook background (base layout): */ @@ -1374,7 +1374,7 @@ static void NotebookDisplay(void *clientData, Drawable d) DisplayTab(nb, index, d); } } - if (nb->notebook.currentIndex >= 0) { + if (nb->notebook.currentIndex != TCL_INDEX_NONE) { DisplayTab(nb, nb->notebook.currentIndex, d); } } -- cgit v0.12 From 9ba4c746ec344f1455e03c2f97ca0ae7c95d139f Mon Sep 17 00:00:00 2001 From: culler Date: Fri, 29 May 2020 18:21:55 +0000 Subject: Remove some unnecessary macOS conditional code by using internal stubs. --- generic/tkFont.c | 10 ++++------ generic/tkInt.decls | 9 +++++++++ generic/tkIntDecls.h | 36 ++++++++++++++++++++++++++++++++++++ generic/tkStubInit.c | 20 ++++++++++++++++++++ generic/tkTextDisp.c | 36 +++++++++++++++++++----------------- macosx/tkMacOSXInt.h | 2 -- macosx/tkMacOSXSubwindows.c | 8 +------- macosx/tkMacOSXWindowEvent.c | 35 +++++++++++++++++++++++++---------- macosx/tkMacOSXWm.c | 34 +++++++++++++++++++++++----------- unix/tkUnixPort.h | 2 ++ win/tkWinPort.h | 7 +++++++ 11 files changed, 146 insertions(+), 53 deletions(-) diff --git a/generic/tkFont.c b/generic/tkFont.c index 53855ac..448f918 100644 --- a/generic/tkFont.c +++ b/generic/tkFont.c @@ -13,9 +13,7 @@ #include "tkInt.h" #include "tkFont.h" -#if defined(MAC_OSX_TK) -#include "tkMacOSXInt.h" -#endif + /* * The following structure is used to keep track of all the fonts that exist * in the current application. It must be stored in the TkMainInfo for the @@ -874,18 +872,18 @@ TheWorldHasChanged( ClientData clientData) /* Info about application's fonts. */ { TkFontInfo *fiPtr = clientData; -#if defined(MAC_OSX_TK) /* * On macOS it is catastrophic to recompute all widgets while the * [NSView drawRect] method is drawing. The best that we can do in * that situation is to abort the recomputation and hope for the best. + * This is ignored on other platforms. */ - if (TkpAppIsDrawing()) { + if (TkpAppCanDraw(NULL)) { return; } -#endif + fiPtr->updatePending = 0; RecomputeWidgets(fiPtr->mainPtr->winPtr); } diff --git a/generic/tkInt.decls b/generic/tkInt.decls index bb2057b..da591cb 100644 --- a/generic/tkInt.decls +++ b/generic/tkInt.decls @@ -634,6 +634,15 @@ declare 184 { Tk_Font tkfont, const char *source, int numBytes, double x, double y, double angle) } + +# Support for aqua's inability to draw outside [NSView drawRect:] +declare 185 aqua { + void TkpRedrawWidget(Tk_Window tkwin) +} +declare 186 aqua { + int TkpAppCanDraw(Tk_Window tkwin) +} + ############################################################################## diff --git a/generic/tkIntDecls.h b/generic/tkIntDecls.h index fa1833e..7bf9bd7 100644 --- a/generic/tkIntDecls.h +++ b/generic/tkIntDecls.h @@ -550,6 +550,14 @@ EXTERN void TkDrawAngledChars(Display *display, Drawable drawable, GC gc, Tk_Font tkfont, const char *source, int numBytes, double x, double y, double angle); +#ifdef MAC_OSX_TK /* AQUA */ +/* 185 */ +EXTERN void TkpRedrawWidget(Tk_Window tkwin); +#endif /* AQUA */ +#ifdef MAC_OSX_TK /* AQUA */ +/* 186 */ +EXTERN int TkpAppCanDraw(Tk_Window tkwin); +#endif /* AQUA */ typedef struct TkIntStubs { int magic; @@ -767,6 +775,26 @@ typedef struct TkIntStubs { void (*tkUnderlineAngledTextLayout) (Display *display, Drawable drawable, GC gc, Tk_TextLayout layout, int x, int y, double angle, int underline); /* 182 */ int (*tkIntersectAngledTextLayout) (Tk_TextLayout layout, int x, int y, int width, int height, double angle); /* 183 */ void (*tkDrawAngledChars) (Display *display, Drawable drawable, GC gc, Tk_Font tkfont, const char *source, int numBytes, double x, double y, double angle); /* 184 */ +#if !(defined(_WIN32) || defined(MAC_OSX_TK)) /* X11 */ + void (*reserved185)(void); +#endif /* X11 */ +#if defined(_WIN32) /* WIN */ + void (*reserved185)(void); +#endif /* WIN */ +#ifdef MAC_OSX_TK /* AQUA */ + void (*reserved185)(void); /* Dummy entry for stubs table backwards compatibility */ + void (*tkpRedrawWidget) (Tk_Window tkwin); /* 185 */ +#endif /* AQUA */ +#if !(defined(_WIN32) || defined(MAC_OSX_TK)) /* X11 */ + void (*reserved186)(void); +#endif /* X11 */ +#if defined(_WIN32) /* WIN */ + void (*reserved186)(void); +#endif /* WIN */ +#ifdef MAC_OSX_TK /* AQUA */ + void (*reserved186)(void); /* Dummy entry for stubs table backwards compatibility */ + int (*tkpAppCanDraw) (Tk_Window tkwin); /* 186 */ +#endif /* AQUA */ } TkIntStubs; extern const TkIntStubs *tkIntStubsPtr; @@ -1139,6 +1167,14 @@ extern const TkIntStubs *tkIntStubsPtr; (tkIntStubsPtr->tkIntersectAngledTextLayout) /* 183 */ #define TkDrawAngledChars \ (tkIntStubsPtr->tkDrawAngledChars) /* 184 */ +#ifdef MAC_OSX_TK /* AQUA */ +#define TkpRedrawWidget \ + (tkIntStubsPtr->tkpRedrawWidget) /* 185 */ +#endif /* AQUA */ +#ifdef MAC_OSX_TK /* AQUA */ +#define TkpAppCanDraw \ + (tkIntStubsPtr->tkpAppCanDraw) /* 186 */ +#endif /* AQUA */ #endif /* defined(USE_TK_STUBS) */ diff --git a/generic/tkStubInit.c b/generic/tkStubInit.c index 61c698a..045c86e 100644 --- a/generic/tkStubInit.c +++ b/generic/tkStubInit.c @@ -485,6 +485,26 @@ static const TkIntStubs tkIntStubs = { TkUnderlineAngledTextLayout, /* 182 */ TkIntersectAngledTextLayout, /* 183 */ TkDrawAngledChars, /* 184 */ +#if !(defined(_WIN32) || defined(MAC_OSX_TK)) /* X11 */ + 0, /* 185 */ +#endif /* X11 */ +#if defined(_WIN32) /* WIN */ + 0, /* 185 */ +#endif /* WIN */ +#ifdef MAC_OSX_TK /* AQUA */ + 0, /* 185 */ /* Dummy entry for stubs table backwards compatibility */ + TkpRedrawWidget, /* 185 */ +#endif /* AQUA */ +#if !(defined(_WIN32) || defined(MAC_OSX_TK)) /* X11 */ + 0, /* 186 */ +#endif /* X11 */ +#if defined(_WIN32) /* WIN */ + 0, /* 186 */ +#endif /* WIN */ +#ifdef MAC_OSX_TK /* AQUA */ + 0, /* 186 */ /* Dummy entry for stubs table backwards compatibility */ + TkpAppCanDraw, /* 186 */ +#endif /* AQUA */ }; static const TkIntPlatStubs tkIntPlatStubs = { diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c index c848fd2..084fd64 100644 --- a/generic/tkTextDisp.c +++ b/generic/tkTextDisp.c @@ -20,15 +20,13 @@ #include "tkWinInt.h" #elif defined(__CYGWIN__) #include "tkUnixInt.h" +#elif defined(MAC_OSX_TK) +#include "tkMacOSXInt.h" +#define OK_TO_LOG (!TkpAppCanDraw(textPtr->tkwin)) #endif -#ifdef MAC_OSX_TK -#include "tkMacOSXInt.h" -#define OK_TO_LOG (!TkpAppIsDrawing()) -#define FORCE_DISPLAY(winPtr) TkpDisplayWindow(winPtr) -#else +#if !defined(MAC_OSX_TK) #define OK_TO_LOG 1 -#define FORCE_DISPLAY(winPtr) #endif /* @@ -3157,7 +3155,7 @@ GenerateWidgetViewSyncEvent( */ if (!tkTextDebug) { - FORCE_DISPLAY(textPtr->tkwin); + TkpRedrawWidget(textPtr->tkwin); } if (NewSyncState != OldSyncState) { @@ -4176,11 +4174,23 @@ DisplayText( * warnings. */ Tcl_Interp *interp; + + if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)) { + /* + * The widget has been deleted. Don't do anything. + */ + + return; + } + #ifdef MAC_OSX_TK /* - * If drawing is disabled, all we need to do is - * clear the REDRAW_PENDING flag. + * If the toplevel is being resized it would be dangerous to try redrawing + * the widget. But we can just clear the REDRAW_PENDING flag and return. + * This display proc will be called again after the widget has been + * reconfigured. */ + TkWindow *winPtr = (TkWindow *)(textPtr->tkwin); MacDrawable *macWin = winPtr->privatePtr; if (macWin && (macWin->flags & TK_DO_NOT_DRAW)){ @@ -4189,14 +4199,6 @@ DisplayText( } #endif - if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)) { - /* - * The widget has been deleted. Don't do anything. - */ - - return; - } - interp = textPtr->interp; Tcl_Preserve(interp); diff --git a/macosx/tkMacOSXInt.h b/macosx/tkMacOSXInt.h index 9cb75d2..58761d5 100644 --- a/macosx/tkMacOSXInt.h +++ b/macosx/tkMacOSXInt.h @@ -200,8 +200,6 @@ MODULE_SCOPE void TkpClipDrawableToRect(Display *display, Drawable d, int x, MODULE_SCOPE void TkpRetainRegion(TkRegion r); MODULE_SCOPE void TkpReleaseRegion(TkRegion r); MODULE_SCOPE void TkpShiftButton(NSButton *button, NSPoint delta); -MODULE_SCOPE Bool TkpAppIsDrawing(void); -MODULE_SCOPE void TkpDisplayWindow(Tk_Window tkwin); MODULE_SCOPE Bool TkTestLogDisplay(void); MODULE_SCOPE Bool TkMacOSXInDarkMode(Tk_Window tkwin); diff --git a/macosx/tkMacOSXSubwindows.c b/macosx/tkMacOSXSubwindows.c index 5063fa3..6602564 100644 --- a/macosx/tkMacOSXSubwindows.c +++ b/macosx/tkMacOSXSubwindows.c @@ -698,16 +698,10 @@ XConfigureWindow( if (value_mask & CWStackMode) { NSView *view = TkMacOSXDrawableView(macWin); - Rect bounds; - NSRect r; if (view) { TkMacOSXInvalClipRgns((Tk_Window) winPtr->parentPtr); - TkMacOSXWinBounds(winPtr, &bounds); - r = NSMakeRect(bounds.left, - [view bounds].size.height - bounds.bottom, - bounds.right - bounds.left, bounds.bottom - bounds.top); - [view setNeedsDisplayInRect:r]; + TkpRedrawWidget((Tk_Window) winPtr); } } diff --git a/macosx/tkMacOSXWindowEvent.c b/macosx/tkMacOSXWindowEvent.c index cb4ffd1..76b2b04 100644 --- a/macosx/tkMacOSXWindowEvent.c +++ b/macosx/tkMacOSXWindowEvent.c @@ -382,26 +382,41 @@ extern NSString *NSWindowDidOrderOffScreenNotification; /* *---------------------------------------------------------------------- * - * TkpAppIsDrawing -- + * TkpAppCanDraw -- * * A widget display procedure can call this to determine whether it is - * being run inside of the drawRect method. This is needed for some tests, - * especially of the Text widget, which record data in a global Tcl - * variable and assume that display procedures will be run in a - * predictable sequence as Tcl idle tasks. + * being run inside of the drawRect method. If not, it may be desirable + * for the display procedure to simply clear the REDRAW_PENDING flag + * and return. The widget can be recorded in order to schedule a + * redraw, via and Expose event, from within drawRect. + * + * This is also needed for some tests, especially of the Text widget, + * which record data in a global Tcl variable and assume that display + * procedures will be run in a predictable sequence as Tcl idle tasks. * * Results: - * True only while running the drawRect method of a TKContentView; + * True if called from the drawRect method of a TKContentView with + * tkwin NULL or pointing to a widget in the current focusView. * * Side effects: - * None + * The tkwin parameter may be recorded to handle redrawing the widget + * later. * *---------------------------------------------------------------------- */ -MODULE_SCOPE Bool -TkpAppIsDrawing(void) { - return [NSApp isDrawing]; +int +TkpAppCanDraw(Tk_Window tkwin) { + if (![NSApp isDrawing]) { + return 0; + } + if (tkwin) { + TkWindow *winPtr = (TkWindow *)tkwin; + NSView *view = TkMacOSXDrawableView(winPtr->privatePtr); + return (view == [NSView focusView]); + } else { + return 1; + } } /* diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index 9117159..cab2b9a 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -6174,28 +6174,40 @@ TkMacOSXMakeRealWindowExist( /* *---------------------------------------------------------------------- * - * TkpDisplayWindow -- + * TkpRedrawWidget -- * - * Mark the contentView of this window as needing display so the window - * will be drawn by the window manager. If this is called within the - * drawRect method, do nothing. + * Mark the bounding rectangle of this widget as needing display so the + * widget will be drawn by [NSView drawRect:]. If this is called within + * the drawRect method, do nothing. * * Results: * None. * * Side effects: - * The window's contentView is marked as needing display. + * The widget's bounding rectangle is marked as dirty. * *---------------------------------------------------------------------- */ -MODULE_SCOPE void -TkpDisplayWindow(Tk_Window tkwin) { - if (![NSApp isDrawing]) { - TkWindow *winPtr = (TkWindow *) tkwin; - NSWindow *w = TkMacOSXDrawableWindow(winPtr->window); +void +TkpRedrawWidget(Tk_Window tkwin) { + TkWindow *winPtr = (TkWindow *) tkwin; + NSWindow *w; + Rect tkBounds; + NSRect bounds; - [[w contentView] setNeedsDisplay: YES]; + if ([NSApp isDrawing]) { + return; + } + w = TkMacOSXDrawableWindow(winPtr->window); + if (w) { + NSView *view = [w contentView]; + TkMacOSXWinBounds(winPtr, &tkBounds); + bounds = NSMakeRect(tkBounds.left, + [view bounds].size.height - tkBounds.bottom, + tkBounds.right - tkBounds.left, + tkBounds.bottom - tkBounds.top); + [view setNeedsDisplayInRect:bounds]; } } diff --git a/unix/tkUnixPort.h b/unix/tkUnixPort.h index 09ff558..8fd56fe 100644 --- a/unix/tkUnixPort.h +++ b/unix/tkUnixPort.h @@ -167,6 +167,8 @@ #define TkpButtonSetDefaults() {} #define TkpDestroyButton(butPtr) {} +#define TkpAppCanDraw(tkwin) 1 +#define TkpRedrawWidget(tkwin) #define TkSelUpdateClipboard(a,b) {} #ifndef __CYGWIN__ #define TkSetPixmapColormap(p,c) {} diff --git a/win/tkWinPort.h b/win/tkWinPort.h index 8cc5677..4ef8680 100644 --- a/win/tkWinPort.h +++ b/win/tkWinPort.h @@ -125,4 +125,11 @@ #define TkpCreateNativeBitmap(display, source) None #define TkpGetNativeAppBitmap(display, name, w, h) None +/* + * Other functions not used under Windows + */ + +#define TkpAppCanDraw(tkwin) 1 +#define TkpRedrawWidget(tkwin) + #endif /* _WINPORT */ -- cgit v0.12 From 4d6ace7f224a40a423390fa6c0bb3c39d4162313 Mon Sep 17 00:00:00 2001 From: culler Date: Sun, 31 May 2020 17:21:57 +0000 Subject: Rename Aqua stub TkpAppCanDraw as TkpWillDrawWidget --- generic/tkFont.c | 2 +- generic/tkInt.decls | 2 +- generic/tkIntDecls.h | 8 ++++---- generic/tkStubInit.c | 2 +- generic/tkTextDisp.c | 4 ++-- macosx/tkMacOSXWindowEvent.c | 4 ++-- unix/tkUnixPort.h | 2 +- win/tkWinPort.h | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/generic/tkFont.c b/generic/tkFont.c index 448f918..e53e3f9 100644 --- a/generic/tkFont.c +++ b/generic/tkFont.c @@ -880,7 +880,7 @@ TheWorldHasChanged( * This is ignored on other platforms. */ - if (TkpAppCanDraw(NULL)) { + if (!TkpWillDrawWidget(NULL)) { return; } diff --git a/generic/tkInt.decls b/generic/tkInt.decls index da591cb..f6e7ea9 100644 --- a/generic/tkInt.decls +++ b/generic/tkInt.decls @@ -640,7 +640,7 @@ declare 185 aqua { void TkpRedrawWidget(Tk_Window tkwin) } declare 186 aqua { - int TkpAppCanDraw(Tk_Window tkwin) + int TkpWillDrawWidget(Tk_Window tkwin) } diff --git a/generic/tkIntDecls.h b/generic/tkIntDecls.h index 7bf9bd7..1344cc6 100644 --- a/generic/tkIntDecls.h +++ b/generic/tkIntDecls.h @@ -556,7 +556,7 @@ EXTERN void TkpRedrawWidget(Tk_Window tkwin); #endif /* AQUA */ #ifdef MAC_OSX_TK /* AQUA */ /* 186 */ -EXTERN int TkpAppCanDraw(Tk_Window tkwin); +EXTERN int TkpWillDrawWidget(Tk_Window tkwin); #endif /* AQUA */ typedef struct TkIntStubs { @@ -793,7 +793,7 @@ typedef struct TkIntStubs { #endif /* WIN */ #ifdef MAC_OSX_TK /* AQUA */ void (*reserved186)(void); /* Dummy entry for stubs table backwards compatibility */ - int (*tkpAppCanDraw) (Tk_Window tkwin); /* 186 */ + int (*tkpWillDrawWidget) (Tk_Window tkwin); /* 186 */ #endif /* AQUA */ } TkIntStubs; @@ -1172,8 +1172,8 @@ extern const TkIntStubs *tkIntStubsPtr; (tkIntStubsPtr->tkpRedrawWidget) /* 185 */ #endif /* AQUA */ #ifdef MAC_OSX_TK /* AQUA */ -#define TkpAppCanDraw \ - (tkIntStubsPtr->tkpAppCanDraw) /* 186 */ +#define TkpWillDrawWidget \ + (tkIntStubsPtr->tkpWillDrawWidget) /* 186 */ #endif /* AQUA */ #endif /* defined(USE_TK_STUBS) */ diff --git a/generic/tkStubInit.c b/generic/tkStubInit.c index 045c86e..4abc637 100644 --- a/generic/tkStubInit.c +++ b/generic/tkStubInit.c @@ -503,7 +503,7 @@ static const TkIntStubs tkIntStubs = { #endif /* WIN */ #ifdef MAC_OSX_TK /* AQUA */ 0, /* 186 */ /* Dummy entry for stubs table backwards compatibility */ - TkpAppCanDraw, /* 186 */ + TkpWillDrawWidget, /* 186 */ #endif /* AQUA */ }; diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c index 084fd64..2deeaf2 100644 --- a/generic/tkTextDisp.c +++ b/generic/tkTextDisp.c @@ -22,7 +22,7 @@ #include "tkUnixInt.h" #elif defined(MAC_OSX_TK) #include "tkMacOSXInt.h" -#define OK_TO_LOG (!TkpAppCanDraw(textPtr->tkwin)) +#define OK_TO_LOG (!TkpWillDrawWidget(textPtr->tkwin)) #endif #if !defined(MAC_OSX_TK) @@ -4174,7 +4174,7 @@ DisplayText( * warnings. */ Tcl_Interp *interp; - + if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)) { /* * The widget has been deleted. Don't do anything. diff --git a/macosx/tkMacOSXWindowEvent.c b/macosx/tkMacOSXWindowEvent.c index 76b2b04..ee49541 100644 --- a/macosx/tkMacOSXWindowEvent.c +++ b/macosx/tkMacOSXWindowEvent.c @@ -382,7 +382,7 @@ extern NSString *NSWindowDidOrderOffScreenNotification; /* *---------------------------------------------------------------------- * - * TkpAppCanDraw -- + * TkpWillDrawWidget -- * * A widget display procedure can call this to determine whether it is * being run inside of the drawRect method. If not, it may be desirable @@ -406,7 +406,7 @@ extern NSString *NSWindowDidOrderOffScreenNotification; */ int -TkpAppCanDraw(Tk_Window tkwin) { +TkpWillDrawWidget(Tk_Window tkwin) { if (![NSApp isDrawing]) { return 0; } diff --git a/unix/tkUnixPort.h b/unix/tkUnixPort.h index 8fd56fe..491a339 100644 --- a/unix/tkUnixPort.h +++ b/unix/tkUnixPort.h @@ -167,7 +167,7 @@ #define TkpButtonSetDefaults() {} #define TkpDestroyButton(butPtr) {} -#define TkpAppCanDraw(tkwin) 1 +#define TkpWillDrawWidget(tkwin) 1 #define TkpRedrawWidget(tkwin) #define TkSelUpdateClipboard(a,b) {} #ifndef __CYGWIN__ diff --git a/win/tkWinPort.h b/win/tkWinPort.h index 4ef8680..dbde9e1 100644 --- a/win/tkWinPort.h +++ b/win/tkWinPort.h @@ -129,7 +129,7 @@ * Other functions not used under Windows */ -#define TkpAppCanDraw(tkwin) 1 +#define TkpWillDrawWidget(tkwin) 1 #define TkpRedrawWidget(tkwin) #endif /* _WINPORT */ -- cgit v0.12 From 7f9a1328482227ad2462a296bb956c68df2cb2e1 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 2 Jun 2020 09:50:22 +0000 Subject: Fix two (minor) warnings, discovered with gcc-10, using Tcl 9 headers) . --- generic/tkCanvText.c | 2 +- generic/ttk/ttkEntry.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/generic/tkCanvText.c b/generic/tkCanvText.c index 1c8bc04..a1b2358 100644 --- a/generic/tkCanvText.c +++ b/generic/tkCanvText.c @@ -960,7 +960,7 @@ DisplayCanvText( * anti-aliasing colors would blend together. */ - if ((selFirstChar >= 0) && (textPtr->selTextGC != textPtr->gc)) { + if ((selFirstChar != TCL_INDEX_NONE) && (textPtr->selTextGC != textPtr->gc)) { if (0 < selFirstChar) { TkDrawAngledTextLayout(display, drawable, textPtr->gc, textPtr->textLayout, drawableX, drawableY, textPtr->angle, diff --git a/generic/ttk/ttkEntry.c b/generic/ttk/ttkEntry.c index e07617c..cbc3b3f 100644 --- a/generic/ttk/ttkEntry.c +++ b/generic/ttk/ttkEntry.c @@ -1312,7 +1312,7 @@ static void EntryDisplay(void *clientData, Drawable d) } /* Use placeholder text width */ leftIndex = 0; - TkGetStringFromObj(entryPtr->entry.placeholderObj, &rightIndex); + (void)TkGetStringFromObj(entryPtr->entry.placeholderObj, &rightIndex); } else { foregroundObj = es.foregroundObj; } -- cgit v0.12 From c0f2471d203026409e33969ccdb40cf06ff0f99c Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 2 Jun 2020 21:51:23 +0000 Subject: size_t for Tk_ItemDCharsProc(), with Tcl 9 headers --- generic/tk.h | 41 +++++++++++++++++++---------------------- generic/tkCanvLine.c | 12 ++++++------ generic/tkCanvPoly.c | 16 ++++++++-------- generic/tkCanvText.c | 24 ++++++++++++------------ generic/tkText.c | 49 +++++++++++++++++++++++++------------------------ 5 files changed, 70 insertions(+), 72 deletions(-) diff --git a/generic/tk.h b/generic/tk.h index 5efd2cb..90d4115 100644 --- a/generic/tk.h +++ b/generic/tk.h @@ -1047,13 +1047,17 @@ typedef struct Tk_Item { * lines, circles, etc.) that can form part of a canvas widget. */ -#ifdef USE_OLD_CANVAS +#if defined(USE_OLD_CANVAS) && TCL_MAJOR_VERSION < 9 typedef int (Tk_ItemCreateProc)(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int argc, char **argv); typedef int (Tk_ItemConfigureProc)(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int argc, char **argv, int flags); typedef int (Tk_ItemCoordProc)(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int argc, char **argv); +typedef void (Tk_ItemInsertProc)(Tk_Canvas canvas, Tk_Item *itemPtr, + int beforeThis, char *string); +typedef int (Tk_ItemIndexProc)(Tcl_Interp *interp, Tk_Canvas canvas, + Tk_Item *itemPtr, char *indexString, int *indexPtr); #else typedef int (Tk_ItemCreateProc)(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int argc, Tcl_Obj *const objv[]); @@ -1062,6 +1066,17 @@ typedef int (Tk_ItemConfigureProc)(Tcl_Interp *interp, Tk_Canvas canvas, int flags); typedef int (Tk_ItemCoordProc)(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int argc, Tcl_Obj *const argv[]); +#if TCL_MAJOR_VERSION > 8 +typedef void (Tk_ItemInsertProc)(Tk_Canvas canvas, Tk_Item *itemPtr, + size_t beforeThis, Tcl_Obj *string); +typedef int (Tk_ItemIndexProc)(Tcl_Interp *interp, Tk_Canvas canvas, + Tk_Item *itemPtr, Tcl_Obj *indexString, size_t *indexPtr); +#else +typedef void (Tk_ItemInsertProc)(Tk_Canvas canvas, Tk_Item *itemPtr, + int beforeThis, Tcl_Obj *string); +typedef int (Tk_ItemIndexProc)(Tcl_Interp *interp, Tk_Canvas canvas, + Tk_Item *itemPtr, Tcl_Obj *indexString, int *indexPtr); +#endif #endif /* USE_OLD_CANVAS */ typedef void (Tk_ItemDeleteProc)(Tk_Canvas canvas, Tk_Item *itemPtr, Display *display); @@ -1081,39 +1096,21 @@ typedef void (Tk_ItemScaleProc)(Tk_Canvas canvas, Tk_Item *itemPtr, double scaleY); typedef void (Tk_ItemTranslateProc)(Tk_Canvas canvas, Tk_Item *itemPtr, double deltaX, double deltaY); -#ifdef USE_OLD_CANVAS -typedef int (Tk_ItemIndexProc)(Tcl_Interp *interp, Tk_Canvas canvas, - Tk_Item *itemPtr, char *indexString, int *indexPtr); -#elif TCL_MAJOR_VERSION > 8 -typedef int (Tk_ItemIndexProc)(Tcl_Interp *interp, Tk_Canvas canvas, - Tk_Item *itemPtr, Tcl_Obj *indexString, size_t *indexPtr); -#else -typedef int (Tk_ItemIndexProc)(Tcl_Interp *interp, Tk_Canvas canvas, - Tk_Item *itemPtr, Tcl_Obj *indexString, int *indexPtr); -#endif /* USE_OLD_CANVAS */ #if TCL_MAJOR_VERSION > 8 typedef void (Tk_ItemCursorProc)(Tk_Canvas canvas, Tk_Item *itemPtr, size_t index); typedef size_t (Tk_ItemSelectionProc)(Tk_Canvas canvas, Tk_Item *itemPtr, size_t offset, char *buffer, size_t maxBytes); +typedef void (Tk_ItemDCharsProc)(Tk_Canvas canvas, Tk_Item *itemPtr, + size_t first, size_t last); #else typedef void (Tk_ItemCursorProc)(Tk_Canvas canvas, Tk_Item *itemPtr, int index); typedef int (Tk_ItemSelectionProc)(Tk_Canvas canvas, Tk_Item *itemPtr, int offset, char *buffer, int maxBytes); -#endif -#ifdef USE_OLD_CANVAS -typedef void (Tk_ItemInsertProc)(Tk_Canvas canvas, Tk_Item *itemPtr, - int beforeThis, char *string); -#elif TCL_MAJOR_VERSION > 8 -typedef void (Tk_ItemInsertProc)(Tk_Canvas canvas, Tk_Item *itemPtr, - size_t beforeThis, Tcl_Obj *string); -#else -typedef void (Tk_ItemInsertProc)(Tk_Canvas canvas, Tk_Item *itemPtr, - int beforeThis, Tcl_Obj *string); -#endif /* USE_OLD_CANVAS */ typedef void (Tk_ItemDCharsProc)(Tk_Canvas canvas, Tk_Item *itemPtr, int first, int last); +#endif #ifndef __NO_OLD_CONFIG diff --git a/generic/tkCanvLine.c b/generic/tkCanvLine.c index 484f41c..88ddc97 100644 --- a/generic/tkCanvLine.c +++ b/generic/tkCanvLine.c @@ -97,7 +97,7 @@ static int LineCoords(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int objc, Tcl_Obj *const objv[]); static void LineDeleteCoords(Tk_Canvas canvas, - Tk_Item *itemPtr, int first, int last); + Tk_Item *itemPtr, TkSizeT first, TkSizeT last); static void LineInsert(Tk_Canvas canvas, Tk_Item *itemPtr, TkSizeT beforeThis, Tcl_Obj *obj); static int LineToArea(Tk_Canvas canvas, @@ -1153,8 +1153,8 @@ static void LineDeleteCoords( Tk_Canvas canvas, /* Canvas containing itemPtr. */ Tk_Item *itemPtr, /* Item in which to delete characters. */ - int first, /* Index of first character to delete. */ - int last) /* Index of last character to delete. */ + TkSizeT first, /* Index of first character to delete. */ + TkSizeT last) /* Index of last character to delete. */ { LineItem *linePtr = (LineItem *) itemPtr; int count, i, first1, last1; @@ -1169,13 +1169,13 @@ LineDeleteCoords( first &= -2; last &= -2; - if (first < 0) { + if ((int)first < 0) { first = 0; } - if (last >= length) { + if ((int)last >= length) { last = length-2; } - if (first > last) { + if ((int)first > (int)last) { return; } if (linePtr->firstArrowPtr != NULL) { diff --git a/generic/tkCanvPoly.c b/generic/tkCanvPoly.c index f4f0163..88f63e8 100644 --- a/generic/tkCanvPoly.c +++ b/generic/tkCanvPoly.c @@ -168,7 +168,7 @@ static int PolygonCoords(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int objc, Tcl_Obj *const objv[]); static void PolygonDeleteCoords(Tk_Canvas canvas, - Tk_Item *itemPtr, int first, int last); + Tk_Item *itemPtr, TkSizeT first, TkSizeT last); static void PolygonInsert(Tk_Canvas canvas, Tk_Item *itemPtr, TkSizeT beforeThis, Tcl_Obj *obj); static int PolygonToArea(Tk_Canvas canvas, @@ -1172,23 +1172,23 @@ static void PolygonDeleteCoords( Tk_Canvas canvas, /* Canvas containing itemPtr. */ Tk_Item *itemPtr, /* Item in which to delete characters. */ - int first, /* Index of first character to delete. */ - int last) /* Index of last character to delete. */ + TkSizeT first, /* Index of first character to delete. */ + TkSizeT last) /* Index of last character to delete. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; int count, i; int length = 2*(polyPtr->numPoints - polyPtr->autoClosed); - while (first >= length) { + while ((int)first >= length) { first -= length; } - while (first < 0) { + while ((int)first < 0) { first += length; } - while (last >= length) { + while ((int)last >= length) { last -= length; } - while (last < 0) { + while ((int)last < 0) { last += length; } @@ -1215,7 +1215,7 @@ PolygonDeleteCoords( polyPtr->coordPtr[i-count] = polyPtr->coordPtr[i]; } } else { - for (i=last; i<=first; i++) { + for (i=last; i<=(int)first; i++) { polyPtr->coordPtr[i-last] = polyPtr->coordPtr[i]; } } diff --git a/generic/tkCanvText.c b/generic/tkCanvText.c index a1b2358..304e009 100644 --- a/generic/tkCanvText.c +++ b/generic/tkCanvText.c @@ -161,7 +161,7 @@ static int TextCoords(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int argc, Tcl_Obj *const objv[]); static void TextDeleteChars(Tk_Canvas canvas, - Tk_Item *itemPtr, int first, int last); + Tk_Item *itemPtr, TkSizeT first, TkSizeT last); static void TextInsert(Tk_Canvas canvas, Tk_Item *itemPtr, TkSizeT beforeThis, Tcl_Obj *obj); static int TextToArea(Tk_Canvas canvas, @@ -1091,9 +1091,9 @@ static void TextDeleteChars( Tk_Canvas canvas, /* Canvas containing itemPtr. */ Tk_Item *itemPtr, /* Item in which to delete characters. */ - int first, /* Character index of first character to + TkSizeT first, /* Character index of first character to * delete. */ - int last) /* Character index of last character to delete + TkSizeT last) /* Character index of last character to delete * (inclusive). */ { TextItem *textPtr = (TextItem *) itemPtr; @@ -1102,13 +1102,13 @@ TextDeleteChars( Tk_CanvasTextInfo *textInfoPtr = textPtr->textInfoPtr; text = textPtr->text; - if (first < 0) { + if ((int)first < 0) { first = 0; } - if (last >= (int)textPtr->numChars) { + if (last + 1 >= textPtr->numChars + 1) { last = textPtr->numChars - 1; } - if (first > last) { + if (first + 1 > last + 1) { return; } charsRemoved = last + 1 - first; @@ -1132,15 +1132,15 @@ TextDeleteChars( */ if (textInfoPtr->selItemPtr == itemPtr) { - if (textInfoPtr->selectFirst + 1 > (TkSizeT)first + 1) { + if (textInfoPtr->selectFirst + 1 > first + 1) { textInfoPtr->selectFirst -= charsRemoved; if ((int)textInfoPtr->selectFirst + 1 < (int)first + 1) { textInfoPtr->selectFirst = first; } } - if (textInfoPtr->selectLast + 1 >= (TkSizeT)first + 1) { + if (textInfoPtr->selectLast + 1 >= first + 1) { textInfoPtr->selectLast -= charsRemoved; - if (textInfoPtr->selectLast + 1 < (TkSizeT)first) { + if (textInfoPtr->selectLast + 1 < first) { textInfoPtr->selectLast = first - 1; } } @@ -1148,14 +1148,14 @@ TextDeleteChars( textInfoPtr->selItemPtr = NULL; } if ((textInfoPtr->anchorItemPtr == itemPtr) - && (textInfoPtr->selectAnchor + 1 > (TkSizeT)first + 1)) { + && (textInfoPtr->selectAnchor + 1 > first + 1)) { textInfoPtr->selectAnchor -= charsRemoved; - if (textInfoPtr->selectAnchor + 1 < (TkSizeT)first + 1) { + if (textInfoPtr->selectAnchor + 1 < first + 1) { textInfoPtr->selectAnchor = first; } } } - if (textPtr->insertPos + 1 > (TkSizeT)first + 1) { + if (textPtr->insertPos + 1 > first + 1) { textPtr->insertPos -= charsRemoved; if ((int)textPtr->insertPos + 1 < (int)first + 1) { textPtr->insertPos = first; diff --git a/generic/tkText.c b/generic/tkText.c index 2f5991b..39be0b7 100644 --- a/generic/tkText.c +++ b/generic/tkText.c @@ -279,10 +279,10 @@ typedef ClientData SearchAddLineProc(int lineNum, typedef int SearchMatchProc(int lineNum, struct SearchSpec *searchSpecPtr, ClientData clientData, Tcl_Obj *theLine, - int matchOffset, int matchLength); + TkSizeT matchOffset, TkSizeT matchLength); typedef int SearchLineIndexProc(Tcl_Interp *interp, Tcl_Obj *objPtr, struct SearchSpec *searchSpecPtr, - int *linePosPtr, int *offsetPosPtr); + int *linePosPtr, TkSizeT *offsetPosPtr); typedef struct SearchSpec { int exact; /* Whether search is exact or regexp. */ @@ -298,10 +298,10 @@ typedef struct SearchSpec { int all; /* Whether all or the first match should be * reported. */ int startLine; /* First line to examine. */ - int startOffset; /* Index in first line to start at. */ + TkSizeT startOffset1; /* Index in first line to start at. */ int stopLine; /* Last line to examine, or -1 when we search * all available text. */ - int stopOffset; /* Index to stop at, provided stopLine is not + TkSizeT stopOffset1; /* Index to stop at, provided stopLine is not * -1. */ int numLines; /* Total lines which are available. */ int backwards; /* Searching forwards or backwards. */ @@ -410,8 +410,8 @@ static void TextPushUndoAction(TkText *textPtr, Tcl_Obj *undoString, int insert, const TkTextIndex *index1Ptr, const TkTextIndex *index2Ptr); -static int TextSearchIndexInLine(const SearchSpec *searchSpecPtr, - TkTextLine *linePtr, int byteIndex); +static TkSizeT TextSearchIndexInLine(const SearchSpec *searchSpecPtr, + TkTextLine *linePtr, TkSizeT byteIndex); static int TextPeerCmd(TkText *textPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); static TkUndoProc TextUndoRedoCallback; @@ -4015,7 +4015,7 @@ TextSearchGetLineIndex( Tcl_Obj *objPtr, /* Contains a textual index like "1.2" */ SearchSpec *searchSpecPtr, /* Contains other search parameters. */ int *linePosPtr, /* For returning the line number. */ - int *offsetPosPtr) /* For returning the text offset in the + TkSizeT *offsetPosPtr) /* For returning the text offset in the * line. */ { const TkTextIndex *indexPtr; @@ -4075,35 +4075,36 @@ TextSearchGetLineIndex( *---------------------------------------------------------------------- */ -static int +static TkSizeT TextSearchIndexInLine( const SearchSpec *searchSpecPtr, /* Search parameters. */ TkTextLine *linePtr, /* The line we're looking at. */ - int byteIndex) /* Index into the line. */ + TkSizeT byteIndex) /* Index into the line. */ { TkTextSegment *segPtr; TkTextIndex curIndex; - int index, leftToScan; + TkSizeT index; + int leftToScan; TkText *textPtr = (TkText *)searchSpecPtr->clientData; index = 0; curIndex.tree = textPtr->sharedTextPtr->tree; curIndex.linePtr = linePtr; curIndex.byteIndex = 0; for (segPtr = linePtr->segPtr, leftToScan = byteIndex; - leftToScan > 0; + leftToScan + 1 > 1; curIndex.byteIndex += segPtr->size, segPtr = segPtr->nextPtr) { if ((segPtr->typePtr == &tkTextCharType) && (searchSpecPtr->searchElide || !TkTextIsElided(textPtr, &curIndex, NULL))) { - if (leftToScan < (int)segPtr->size) { + if (leftToScan + 1 < (int)segPtr->size + 1) { if (searchSpecPtr->exact) { index += leftToScan; } else { index += Tcl_NumUtfChars(segPtr->body.chars, leftToScan); } } else if (searchSpecPtr->exact) { - index += (int)segPtr->size; + index += segPtr->size; } else { index += Tcl_NumUtfChars(segPtr->body.chars, -1); } @@ -4267,9 +4268,9 @@ TextSearchFoundMatch( Tcl_Obj *theLine, /* Text from current line, only accessed for * exact searches, and is allowed to be NULL * for regexp searches. */ - int matchOffset, /* Offset of found item in utf-8 bytes for + TkSizeT matchOffset, /* Offset of found item in utf-8 bytes for * exact search, Unicode chars for regexp. */ - int matchLength) /* Length also in bytes/chars as per search + TkSizeT matchLength) /* Length also in bytes/chars as per search * type. */ { TkSizeT numChars; @@ -4287,7 +4288,7 @@ TextSearchFoundMatch( */ if (searchSpecPtr->backwards ^ - (matchOffset >= searchSpecPtr->stopOffset)) { + (matchOffset + 1 >= searchSpecPtr->stopOffset1 + 1)) { return 0; } } @@ -4312,7 +4313,7 @@ TextSearchFoundMatch( if (searchSpecPtr->strictLimits && lineNum == searchSpecPtr->stopLine) { if (searchSpecPtr->backwards ^ - ((matchOffset + numChars + 1) > (TkSizeT) searchSpecPtr->stopOffset + 1)) { + ((matchOffset + numChars + 1) > searchSpecPtr->stopOffset1 + 1)) { return 0; } } @@ -5663,7 +5664,7 @@ SearchPerform( if (searchSpecPtr->lineIndexProc(interp, fromPtr, searchSpecPtr, &searchSpecPtr->startLine, - &searchSpecPtr->startOffset) != TCL_OK) { + &searchSpecPtr->startOffset1) != TCL_OK) { return TCL_ERROR; } @@ -5694,7 +5695,7 @@ SearchPerform( if (searchSpecPtr->lineIndexProc(interp, toPtr, searchSpecPtr, &searchSpecPtr->stopLine, - &searchSpecPtr->stopOffset) != TCL_OK) { + &searchSpecPtr->stopOffset1) != TCL_OK) { return TCL_ERROR; } } else { @@ -5893,7 +5894,7 @@ SearchCore( } if (lineNum == searchSpecPtr->stopLine && searchSpecPtr->backwards) { - firstOffset = searchSpecPtr->stopOffset; + firstOffset = searchSpecPtr->stopOffset1; } else { firstOffset = 0; } @@ -5927,8 +5928,8 @@ SearchCore( * Only use the last part of the line. */ - if (searchSpecPtr->startOffset > firstOffset) { - firstOffset = searchSpecPtr->startOffset; + if (searchSpecPtr->startOffset1 + 1 > (TkSizeT)firstOffset + 1) { + firstOffset = searchSpecPtr->startOffset1; } if ((firstOffset >= lastOffset) && ((lastOffset != 0) || searchSpecPtr->exact)) { @@ -5939,8 +5940,8 @@ SearchCore( * Use only the first part of the line. */ - if (searchSpecPtr->startOffset < lastOffset) { - lastOffset = searchSpecPtr->startOffset; + if (searchSpecPtr->startOffset1 + 1 < (TkSizeT)lastOffset + 1) { + lastOffset = searchSpecPtr->startOffset1; } } } -- cgit v0.12 From ebbce5dd4848c8dd3bf2ea49d23f83fc2343e425 Mon Sep 17 00:00:00 2001 From: oehhar Date: Thu, 4 Jun 2020 19:12:50 +0000 Subject: photo read command: memory error on shrink option did not close the channel --- generic/tkImgPhoto.c | 1 + 1 file changed, 1 insertion(+) diff --git a/generic/tkImgPhoto.c b/generic/tkImgPhoto.c index 96c3743..ab962c1 100644 --- a/generic/tkImgPhoto.c +++ b/generic/tkImgPhoto.c @@ -1106,6 +1106,7 @@ ImgPhotoCmd( Tcl_SetObjResult(interp, Tcl_NewStringObj( TK_PHOTO_ALLOC_FAILURE_MESSAGE, -1)); Tcl_SetErrorCode(interp, "TK", "MALLOC", NULL); + Tcl_Close(NULL, chan); return TCL_ERROR; } } -- cgit v0.12 From e159a0d79d67dd98e17595c467599e0a54837677 Mon Sep 17 00:00:00 2001 From: fvogel Date: Sat, 6 Jun 2020 07:45:20 +0000 Subject: Update leftover comments that didn't follow the changes made in [0deef053f6] --- generic/tkCanvas.c | 4 ++-- generic/tkListbox.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/generic/tkCanvas.c b/generic/tkCanvas.c index 4d68ade..8230122 100644 --- a/generic/tkCanvas.c +++ b/generic/tkCanvas.c @@ -5556,8 +5556,8 @@ CanvasUpdateScrollbars( Tcl_DString buf; /* - * Save all the relevant values from the canvasPtr, because it might be - * deleted as part of either of the two calls to Tcl_VarEval below. + * Preserve the relevant values from the canvasPtr, because it might be + * deleted as part of either of the two calls to Tcl_EvalEx below. */ interp = canvasPtr->interp; diff --git a/generic/tkListbox.c b/generic/tkListbox.c index d92325f..b00a895 100644 --- a/generic/tkListbox.c +++ b/generic/tkListbox.c @@ -3318,7 +3318,7 @@ ListboxUpdateVScrollbar( /* * We must hold onto the interpreter from the listPtr because the data at - * listPtr might be freed as a result of the Tcl_VarEval. + * listPtr might be freed as a result of the Tcl_EvalEx. */ interp = listPtr->interp; @@ -3390,7 +3390,7 @@ ListboxUpdateHScrollbar( /* * We must hold onto the interpreter because the data referred to at - * listPtr might be freed as a result of the call to Tcl_VarEval. + * listPtr might be freed as a result of the call to Tcl_EvalEx. */ interp = listPtr->interp; -- cgit v0.12