From e0f7a47c9364f3a5daad3a52c80b8940fa925895 Mon Sep 17 00:00:00 2001 From: sdottaka Date: Thu, 31 Oct 2024 22:04:46 +0900 Subject: [PATCH] Fix issue #2510: Second monitor - BIG title bar v 2.16.44 --- Src/Common/MDITabBar.cpp | 12 ++++-------- Src/Common/MDITabBar.h | 4 ---- Src/TitleBarHelper.cpp | 14 +++++++++----- Src/TitleBarHelper.h | 5 ++++- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Src/Common/MDITabBar.cpp b/Src/Common/MDITabBar.cpp index 07ab550b4e0..e7bfd3ceda7 100644 --- a/Src/Common/MDITabBar.cpp +++ b/Src/Common/MDITabBar.cpp @@ -623,11 +623,7 @@ void CMyTabCtrl::UpdateToolTips(int nTabItemIndex) BOOL CMDITabBar::Update(bool bOnTitleBar, bool bMaximized) { m_bOnTitleBar = bOnTitleBar; - m_bMaximized = bMaximized; - CRect rc; - if (m_bMaximized) - AfxGetMainWnd()->GetWindowRect(&rc); - m_top = rc.top; + m_titleBar.SetMaximized(bMaximized); m_tabCtrl.SetOnTitleBar(bOnTitleBar); return true; } @@ -689,7 +685,7 @@ CSize CMDITabBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz) auto pointToPixel = [lpx](int point) { return MulDiv(point, lpx, 72); }; const int pd = pointToPixel(RR_PADDING); const int sw = pointToPixel(RR_SHADOWWIDTH); - int my = m_bOnTitleBar ? (m_bMaximized ? (-m_top + 2) : 2) : 0; + int my = m_bOnTitleBar ? (m_titleBar.GetTopMargin() + 2) : 0; CSize size(SHRT_MAX, my + tm.tmHeight + (sw + pd) * 2); return size; } @@ -739,12 +735,12 @@ void CMDITabBar::OnNcRButtonUp(UINT nHitTest, CPoint point) void CMDITabBar::OnSize(UINT nType, int cx, int cy) { __super::OnSize(nType, cx, cy); - m_titleBar.OnSize(m_bMaximized, cx, cy); + m_titleBar.SetSize(cx, cy); if (m_tabCtrl.m_hWnd) { const int leftMargin = m_bOnTitleBar ? m_titleBar.GetLeftMargin() : 0; const int rightMargin = m_bOnTitleBar ? m_titleBar.GetRightMargin() : 0; - const int topMargin = ((m_bMaximized && m_bOnTitleBar) ? -m_top : 0) + (m_bOnTitleBar ? 1 : 0); + const int topMargin = ((m_titleBar.GetMaximized() && m_bOnTitleBar) ? m_titleBar.GetTopMargin() : 0) + (m_bOnTitleBar ? 1 : 0); const int bottomMargin = m_bOnTitleBar ? 1 : 0; CSize size{ 0, cy - topMargin - bottomMargin }; m_tabCtrl.MoveWindow(leftMargin, topMargin, cx - leftMargin - rightMargin, cy - topMargin - bottomMargin, true); diff --git a/Src/Common/MDITabBar.h b/Src/Common/MDITabBar.h index da443034d3e..15456e8acfc 100644 --- a/Src/Common/MDITabBar.h +++ b/Src/Common/MDITabBar.h @@ -93,8 +93,6 @@ class CMDITabBar : public CControlBar private: bool m_bOnTitleBar; - bool m_bMaximized; - int m_top; CMyTabCtrl m_tabCtrl; CFont m_font; CTitleBarHelper m_titleBar; @@ -102,8 +100,6 @@ class CMDITabBar : public CControlBar public: CMDITabBar() : m_bOnTitleBar(true) - , m_bMaximized(false) - , m_top(0) {} virtual ~CMDITabBar() {} BOOL Update(bool bOnTitleBar, bool bMaxmized); diff --git a/Src/TitleBarHelper.cpp b/Src/TitleBarHelper.cpp index 01bd2a1be2f..6386e85979d 100644 --- a/Src/TitleBarHelper.cpp +++ b/Src/TitleBarHelper.cpp @@ -26,6 +26,12 @@ void CTitleBarHelper::Init(CWnd *pWnd) m_pWnd = pWnd; } +int CTitleBarHelper::GetTopMargin() const +{ + return m_maximized ? + GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER) : 0; +} + void CTitleBarHelper::DrawIcon(CWnd* pWnd, CDC& dc) { HICON hIcon = (HICON)pWnd->SendMessage(WM_GETICON, ICON_SMALL2, 0); @@ -33,7 +39,7 @@ void CTitleBarHelper::DrawIcon(CWnd* pWnd, CDC& dc) hIcon = (HICON)GetClassLongPtr(pWnd->m_hWnd, GCLP_HICONSM); if (hIcon == nullptr) return; - const int topMargin = (m_maximized ? -m_rc.top : 0); + const int topMargin = GetTopMargin(); const int height = m_size.cy - topMargin; const int cx = PointToPixel(12.f); const int cy = PointToPixel(12.f); @@ -123,18 +129,16 @@ CRect CTitleBarHelper::GetButtonRect(int button) const { CRect rcPart; const float buttonWidth = PointToPixelF(m_rightMargin) / 3.f; - const int topMargin = (m_maximized ? -m_rc.top : 0); - rcPart.top = topMargin; + rcPart.top = GetTopMargin(); rcPart.bottom = m_size.cy; rcPart.left = static_cast(m_size.cx - (3 - button) * buttonWidth); rcPart.right = static_cast(rcPart.left + buttonWidth + 0.5); return rcPart; } -void CTitleBarHelper::OnSize(bool maximized, int cx, int cy) +void CTitleBarHelper::SetSize(int cx, int cy) { m_size = CSize(cx, cy); - m_maximized = maximized; CClientDC dc(m_pWnd); m_dpi = dc.GetDeviceCaps(LOGPIXELSX); m_pWnd->GetWindowRect(&m_rc); diff --git a/Src/TitleBarHelper.h b/Src/TitleBarHelper.h index 6d6720cad7a..eb091e1fdef 100644 --- a/Src/TitleBarHelper.h +++ b/Src/TitleBarHelper.h @@ -16,10 +16,13 @@ class CTitleBarHelper { void Init(CWnd* pWnd); void DrawIcon(CWnd* pWnd, CDC& dc); void DrawButtons(CDC& dc, COLORREF textColor, COLORREF backColor); + int GetTopMargin() const; int GetLeftMargin() const { return PointToPixel(m_leftMargin); } int GetRightMargin() const { return PointToPixel(m_rightMargin); } CRect GetButtonRect(int button) const; - void OnSize(bool maximized, int cx, int cy); + void SetMaximized(bool maximized) { m_maximized = maximized; } + bool GetMaximized() const { return m_maximized; } + void SetSize(int cx, int cy); LRESULT OnNcHitTest(CPoint pt); void OnNcMouseMove(UINT nHitTest, CPoint point); void OnNcMouseLeave();