Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Sep 24, 2024
1 parent e129685 commit 760bef2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 28 deletions.
12 changes: 12 additions & 0 deletions Src/Common/MDITabBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ BEGIN_MESSAGE_MAP(CMDITabBar, CControlBar)
ON_WM_NCLBUTTONDBLCLK()
ON_WM_NCLBUTTONDOWN()
ON_WM_NCLBUTTONUP()
ON_WM_NCRBUTTONDOWN()
ON_WM_NCRBUTTONUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

Expand Down Expand Up @@ -686,6 +688,16 @@ void CMDITabBar::OnNcLButtonUp(UINT nHitTest, CPoint point)
m_titleBar.OnNcLButtonUp(nHitTest, point);
}

void CMDITabBar::OnNcRButtonDown(UINT nHitTest, CPoint point)
{
m_titleBar.OnNcRButtonDown(nHitTest, point);
}

void CMDITabBar::OnNcRButtonUp(UINT nHitTest, CPoint point)
{
m_titleBar.OnNcRButtonUp(nHitTest, point);
}

void CMDITabBar::OnSize(UINT nType, int cx, int cy)
{
__super::OnSize(nType, cx, cy);
Expand Down
2 changes: 2 additions & 0 deletions Src/Common/MDITabBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class CMDITabBar : public CControlBar
afx_msg void OnNcLButtonDblClk(UINT nHitTest, CPoint point);
afx_msg void OnNcLButtonDown(UINT nHitTest, CPoint point);
afx_msg void OnNcLButtonUp(UINT nHitTest, CPoint point);
afx_msg void OnNcRButtonDown(UINT nHitTest, CPoint point);
afx_msg void OnNcRButtonUp(UINT nHitTest, CPoint point);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnPaint();
Expand Down
65 changes: 39 additions & 26 deletions Src/TitleBarHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
CTitleBarHelper::CTitleBarHelper()
: m_pWnd(nullptr)
, m_maximized(false)
, m_iconSize(0)
, m_dpi(96)
, m_leftMargin(32.f)
, m_rightMargin(35.f * 3)
, m_bMouseTracking(false)
, m_nTrackingButton(-1)
, m_nHitTest(-1)
, m_nHitTest(HTNOWHERE)
{
}

Expand Down Expand Up @@ -81,21 +80,28 @@ void CTitleBarHelper::DrawButtons(CDC& dc)
rcIcons[i].top = static_cast<int>(rcIcons[i].top + (rcButtons[i].Height() - iconSize) / 2);
rcIcons[i].bottom = static_cast<int>(rcIcons[i].top + iconSize);

COLORREF colorref;
Gdiplus::Color color;
color.SetFromCOLORREF((m_nTrackingButton == i) ? GetSysColor(COLOR_WINDOW) : GetSysColor(COLOR_3DFACE));
if (m_nTrackingButton == i)
colorref = (i == 2) ? RGB(0xE9, 0x48, 0x56) : GetSysColor(COLOR_WINDOW);
else
colorref = GetSysColor(COLOR_3DFACE);
color.SetFromCOLORREF(colorref);
Gdiplus::SolidBrush brush(color);
graphics.FillRectangle(&brush, rcButtons[i].left, rcButtons[i].top, rcButtons[i].Width(), rcButtons[i].Height());
}

graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
Gdiplus::Pen pen(Gdiplus::Color(255, 0, 0, 0), PointToPixel(0.75));
Gdiplus::Color penColor;
penColor.SetFromCOLORREF(GetSysColor(COLOR_WINDOWTEXT));
Gdiplus::Pen pen(penColor, PointToPixel(0.75));
graphics.DrawLine(&pen, Gdiplus::Point(rcIcons[2].left, rcIcons[2].top), Gdiplus::Point(rcIcons[2].right, rcIcons[2].bottom));
graphics.DrawLine(&pen, Gdiplus::Point(rcIcons[2].left, rcIcons[2].bottom), Gdiplus::Point(rcIcons[2].right, rcIcons[2].top));

const int r = static_cast<int>(PointToPixel(0.75));
if (m_maximized)
{
DrawTopRightEdgeWithCurve(graphics, pen, Gdiplus::Rect(rcIcons[1].left + r, rcIcons[1].top - r, rcIcons[1].Width() - 2 * r, rcIcons[1].Height() - 2 * r), r);
DrawTopRightEdgeWithCurve(graphics, pen, Gdiplus::Rect(rcIcons[1].left + r, rcIcons[1].top - r, rcIcons[1].Width() - 2 * r, rcIcons[1].Height() - 2 * r), r * 3);
DrawRoundedRectangle(graphics, pen, Gdiplus::Rect(rcIcons[1].left - r, rcIcons[1].top + r, rcIcons[1].Width() - 2 * r, rcIcons[1].Height() - 2 * r), r);
}
else
Expand Down Expand Up @@ -171,15 +177,13 @@ void CTitleBarHelper::OnNcMouseLeave()

void CTitleBarHelper::OnNcLButtonDblClk(UINT nHitTest, CPoint point)
{
if (nHitTest == HTCAPTION || nHitTest == HTSYSMENU)
{
if (nHitTest != HTMINBUTTON && nHitTest != HTMAXBUTTON && nHitTest != HTCLOSE)
AfxGetMainWnd()->SendMessage(WM_NCLBUTTONDBLCLK, nHitTest, MAKELPARAM(point.x, point.y));
}
}

void CTitleBarHelper::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
if (nHitTest == HTCAPTION || nHitTest == HTSYSMENU)
if (nHitTest != HTMINBUTTON && nHitTest != HTMAXBUTTON && nHitTest != HTCLOSE)
{
AfxGetMainWnd()->SendMessage(WM_NCLBUTTONDOWN, nHitTest, MAKELPARAM(point.x, point.y));
}
Expand All @@ -191,11 +195,11 @@ void CTitleBarHelper::OnNcLButtonDown(UINT nHitTest, CPoint point)

void CTitleBarHelper::OnNcLButtonUp(UINT nHitTest, CPoint point)
{
if (nHitTest == HTCAPTION || nHitTest == HTSYSMENU)
if (nHitTest != HTMINBUTTON && nHitTest != HTMAXBUTTON && nHitTest != HTCLOSE)
{
AfxGetMainWnd()->SendMessage(WM_NCLBUTTONUP, nHitTest, MAKELPARAM(point.x, point.y));
}
else if (m_nHitTest != -1 && m_nHitTest == nHitTest)
else if (m_nHitTest != HTNOWHERE && m_nHitTest == nHitTest)
{
if (nHitTest == HTMINBUTTON)
AfxGetMainWnd()->ShowWindow(SW_MINIMIZE);
Expand All @@ -204,22 +208,31 @@ void CTitleBarHelper::OnNcLButtonUp(UINT nHitTest, CPoint point)
else if (nHitTest == HTCLOSE)
AfxGetMainWnd()->PostMessage(WM_CLOSE);
}
m_nHitTest = -1;
m_nHitTest = HTNOWHERE;
}

void CTitleBarHelper::OnNcRButtonDown(UINT nHitTest, CPoint point)
{
AfxGetMainWnd()->SendMessage(WM_NCRBUTTONDOWN, nHitTest, MAKELPARAM(point.x, point.y));
}

void CTitleBarHelper::OnNcRButtonUp(UINT nHitTest, CPoint point)
{
CMenu *pSysMenu = AfxGetMainWnd()->GetSystemMenu(FALSE);
pSysMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, point.x, point.y, m_pWnd, nullptr);
}

int CTitleBarHelper::HitTest(CPoint pt)
{
if (!m_pWnd)
return HTNOWHERE;
CClientDC dc(m_pWnd);
const int height = m_size.cy;
const int leftMargin = static_cast<int>(PointToPixel(m_leftMargin));
const int rightMargin = static_cast<int>(PointToPixel(m_rightMargin));
CRect rc;
const int bw = rightMargin / 3;
const int m = 8;
CRect rc;
m_pWnd->GetWindowRect(&rc);
if (pt.y < rc.top + 4)
if (pt.y < rc.top + m)
{
if (pt.x < rc.left + m)
return HTTOPLEFT;
Expand All @@ -233,22 +246,22 @@ int CTitleBarHelper::HitTest(CPoint pt)
return HTRIGHT;
if (pt.x < rc.left + leftMargin)
return HTSYSMENU;
if (rc.right - bw * 3 <= pt.x && pt.x < rc.right - bw * 2)
{
CRect rcButton = GetButtonRect(0);
m_pWnd->ClientToScreen(&rcButton);
if (PtInRect(&rcButton, pt))
return HTMINBUTTON;
}
else if (rc.right - bw * 2 <= pt.x && pt.x < rc.right - bw)
{
rcButton = GetButtonRect(1);
m_pWnd->ClientToScreen(&rcButton);
if (PtInRect(&rcButton, pt))
return HTMAXBUTTON;
}
else if (rc.right - bw <= pt.x && pt.x < rc.right)
{
rcButton = GetButtonRect(2);
m_pWnd->ClientToScreen(&rcButton);
if (PtInRect(&rcButton, pt))
return HTCLOSE;
}
return HTCAPTION;
}

float CTitleBarHelper::PointToPixel(float point) const
{
return point * m_dpi / 72.f;
};
}
5 changes: 3 additions & 2 deletions Src/TitleBarHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class CTitleBarHelper {
void OnNcLButtonDblClk(UINT nHitTest, CPoint point);
void OnNcLButtonDown(UINT nHitTest, CPoint point);
void OnNcLButtonUp(UINT nHitTest, CPoint point);
void OnNcRButtonDown(UINT nHitTest, CPoint point);
void OnNcRButtonUp(UINT nHitTest, CPoint point);
int HitTest(CPoint pt);

private:
Expand All @@ -36,9 +38,8 @@ class CTitleBarHelper {
bool m_maximized;
bool m_bMouseTracking;
int m_nTrackingButton;
int m_nHitTest;
int m_iconSize;
int m_dpi;
unsigned m_nHitTest;
float m_leftMargin;
float m_rightMargin;
};

0 comments on commit 760bef2

Please sign in to comment.