Skip to content

Commit

Permalink
patch from Wallby (https://github.com/Wallby):
Browse files Browse the repository at this point in the history
correctly track the visibility of the updown control called "spin"

closes #351
  • Loading branch information
stefankueng committed Jan 31, 2024
1 parent 37f59ea commit adc19be
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
35 changes: 26 additions & 9 deletions src/TabBar.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<LPPOINT>(&rcSpin), 2);
rPage.right = rcSpin.left;
rPage.right = rcSpin.left;
}
if (m_currentHoverTabRect.left < rPage.right && m_currentHoverTabRect.right > 0)
{
Expand Down Expand Up @@ -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)));
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -1533,6 +1549,7 @@ void CTabBar::SubclassSpinBox()

pThis->m_tabBarSpinDefaultProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(hChild, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(TabBarSpin_Proc)));
pThis->m_spin = hChild;
pThis->m_bIsSpinVisible = true;
return FALSE;
}
return TRUE;
Expand Down
8 changes: 4 additions & 4 deletions src/TabBar.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit adc19be

Please sign in to comment.