From adc19be48ae0c105fa08b2ff513c22456fb55957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=BCng?= Date: Wed, 31 Jan 2024 19:54:23 +0100 Subject: [PATCH] patch from Wallby (https://github.com/Wallby): correctly track the visibility of the updown control called "spin" closes #351 --- src/TabBar.cpp | 35 ++++++++++++++++++++++++++--------- src/TabBar.h | 8 ++++---- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/TabBar.cpp b/src/TabBar.cpp index ddcb1010..d5e4d0b1 100644 --- a/src/TabBar.cpp +++ b/src/TabBar.cpp @@ -1,6 +1,6 @@ // This file is part of BowPad. // -// Copyright (C) 2013-2023 - Stefan Kueng +// Copyright (C) 2013-2024 - Stefan Kueng // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -55,6 +55,7 @@ CTabBar::CTabBar(HINSTANCE hInst) , m_tabBarDefaultProc(nullptr) , m_tabBarSpinDefaultProc(nullptr) , m_spin(nullptr) + , m_bIsSpinVisible(false) , m_currentHoverTabItem(-1) , m_bIsCloseHover(false) , m_whichCloseClickDown(-1) @@ -483,7 +484,7 @@ LRESULT CTabBar::RunProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) DrawMainBorder(&dis); - if (m_spin) + if (m_bIsSpinVisible) { RECT rcSpin{}; GetWindowRect(m_spin, &rcSpin); @@ -492,7 +493,7 @@ LRESULT CTabBar::RunProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) dis.rcItem.right = rcSpin.left; } // paint the tabs first and then the borders - auto count = GetItemCount(); + auto count = GetItemCount(); if (!count) // no pages added { SelectObject(hDC, hOldFont); @@ -677,7 +678,7 @@ LRESULT CTabBar::RunProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) auto index = GetTabIndexAt(xPos, yPos); RECT rcItem{}; TabCtrl_GetItemRect(*this, index, &rcItem); - if (m_spin) + if (m_bIsSpinVisible) { RECT rcSpin{}; GetWindowRect(m_spin, &rcSpin); @@ -754,12 +755,12 @@ LRESULT CTabBar::RunProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) RECT rPage{}; GetClientRect(*this, &rPage); TabCtrl_AdjustRect(*this, FALSE, &rPage); - if (m_spin) + if (m_bIsSpinVisible) { RECT rcSpin{}; GetWindowRect(m_spin, &rcSpin); MapWindowPoints(nullptr, *this, reinterpret_cast(&rcSpin), 2); - rPage.right = rcSpin.left; + rPage.right = rcSpin.left; } if (m_currentHoverTabRect.left < rPage.right && m_currentHoverTabRect.right > 0) { @@ -996,7 +997,7 @@ COLORREF CTabBar::GetTabColor(UINT item) const return clr; } -void CTabBar::DrawMainBorder(const LPDRAWITEMSTRUCT lpdis) const +void CTabBar::DrawMainBorder(const LPDRAWITEMSTRUCT lpdis) { GDIHelpers::FillSolidRect(lpdis->hDC, &lpdis->rcItem, CTheme::Instance().GetThemeColor(::GetSysColor(COLOR_3DFACE))); } @@ -1272,10 +1273,16 @@ LRESULT CTabBar::TabBarSpin_Proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM { case WM_PAINT: { + // as WM_SHOWWINDOW is only ever sent with wParam == FALSE, use WM_PAINT instead + // of WM_SHOWWINDOW with wParam == TRUE + // alternatives might be WM_NCPAINT or 1125, which also both seem to be only + // sent when updown control is unhidden + if (!pTab->m_bIsSpinVisible) + pTab->m_bIsSpinVisible = true; + PAINTSTRUCT ps; BeginPaint(hwnd, &ps); HDC hdc = ps.hdc; - RECT rcPaint{}; GetClientRect(hwnd, &rcPaint); auto rcLeft = rcPaint; @@ -1472,9 +1479,18 @@ LRESULT CTabBar::TabBarSpin_Proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM InvalidateRect(hwnd, nullptr, false); } break; + case WM_SHOWWINDOW: + { + if (wParam == FALSE) //< checked and is only ever sent with wParam == FALSE + pTab->m_bIsSpinVisible = false; + else + pTab->m_bIsSpinVisible = true; + break; + } case WM_DESTROY: { - pTab->m_spin = nullptr; + pTab->m_bIsSpinVisible = false; + pTab->m_spin = nullptr; break; } default: @@ -1533,6 +1549,7 @@ void CTabBar::SubclassSpinBox() pThis->m_tabBarSpinDefaultProc = reinterpret_cast(::SetWindowLongPtr(hChild, GWLP_WNDPROC, reinterpret_cast(TabBarSpin_Proc))); pThis->m_spin = hChild; + pThis->m_bIsSpinVisible = true; return FALSE; } return TRUE; diff --git a/src/TabBar.h b/src/TabBar.h index 322e0971..3fc9683a 100644 --- a/src/TabBar.h +++ b/src/TabBar.h @@ -1,6 +1,6 @@ // This file is part of BowPad. // -// Copyright (C) 2013-2018, 2020-2022 - Stefan Kueng +// Copyright (C) 2013-2018, 2020-2022, 2024 - Stefan Kueng // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -117,10 +117,10 @@ class CTabBar : public CWindow void ExchangeItemData(POINT point); LRESULT RunProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); COLORREF GetTabColor(UINT item) const; - void DrawMainBorder(LPDRAWITEMSTRUCT lpDrawItemStruct) const; + static void DrawMainBorder(LPDRAWITEMSTRUCT lpDrawItemStruct); void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct, float fraction) const; void DraggingCursor(POINT screenPoint, UINT item); - int GetTabIndexAt(const POINT &p) const { return GetTabIndexAt(p.x, p.y); } + int GetTabIndexAt(const POINT & p) const { return GetTabIndexAt(p.x, p.y); } int GetTabIndexAt(int x, int y) const; bool IsPointInParentZone(POINT screenPoint) const; void NotifyTabDelete(int tab); @@ -145,10 +145,10 @@ class CTabBar : public CWindow WNDPROC m_tabBarDefaultProc; WNDPROC m_tabBarSpinDefaultProc; HWND m_spin; + bool m_bIsSpinVisible; RECT m_currentHoverTabRect; int m_currentHoverTabItem; - CloseButtonZone m_closeButtonZone; bool m_bIsCloseHover; int m_whichCloseClickDown;