Skip to content

Commit

Permalink
Fix issue #2510: Second monitor - BIG title bar v 2.16.44
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Oct 31, 2024
1 parent 2c8ade8 commit e0f7a47
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
12 changes: 4 additions & 8 deletions Src/Common/MDITabBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions Src/Common/MDITabBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,13 @@ class CMDITabBar : public CControlBar
private:

bool m_bOnTitleBar;
bool m_bMaximized;
int m_top;
CMyTabCtrl m_tabCtrl;
CFont m_font;
CTitleBarHelper m_titleBar;

public:
CMDITabBar()
: m_bOnTitleBar(true)
, m_bMaximized(false)
, m_top(0)
{}
virtual ~CMDITabBar() {}
BOOL Update(bool bOnTitleBar, bool bMaxmized);
Expand Down
14 changes: 9 additions & 5 deletions Src/TitleBarHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,20 @@ 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);
if (hIcon == nullptr)
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);
Expand Down Expand Up @@ -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<int>(m_size.cx - (3 - button) * buttonWidth);
rcPart.right = static_cast<int>(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);
Expand Down
5 changes: 4 additions & 1 deletion Src/TitleBarHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit e0f7a47

Please sign in to comment.