-- 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