Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Sep 23, 2024
1 parent e1be4c8 commit e129685
Show file tree
Hide file tree
Showing 7 changed files with 291 additions and 75 deletions.
6 changes: 3 additions & 3 deletions Src/BasicFlatStatusBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ class CBasicFlatStatusBar : public CStatusBar
{
DECLARE_DYNAMIC(CBasicFlatStatusBar)
public:
CBasicFlatStatusBar();
CBasicFlatStatusBar();

protected:
CPoint CBasicFlatStatusBar::GetClientCursorPos() const;
int GetIndexFromPoint(const CPoint& pt) const;
static COLORREF LightenColor(COLORREF color, double amount);

afx_msg void OnPaint();
afx_msg void OnPaint();
afx_msg BOOL OnEraseBkgnd(CDC *pDC);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnMouseLeave();
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
DECLARE_MESSAGE_MAP()
DECLARE_MESSAGE_MAP()

bool m_bMouseTracking;
int m_nTrackingPane;
Expand Down
94 changes: 60 additions & 34 deletions Src/Common/MDITabBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ BEGIN_MESSAGE_MAP(CMDITabBar, CControlBar)
ON_WM_NCHITTEST()
ON_WM_ERASEBKGND()
ON_WM_PAINT()
ON_MESSAGE(WM_NCLBUTTONDBLCLK, OnNcForward<WM_NCLBUTTONDBLCLK>)
ON_MESSAGE(WM_NCLBUTTONDOWN, OnNcForward<WM_NCLBUTTONDOWN>)
ON_MESSAGE(WM_NCLBUTTONUP, OnNcForward<WM_NCLBUTTONUP>)
ON_WM_NCMOUSEMOVE()
ON_WM_NCMOUSELEAVE()
ON_WM_NCLBUTTONDBLCLK()
ON_WM_NCLBUTTONDOWN()
ON_WM_NCLBUTTONUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

Expand Down Expand Up @@ -469,26 +471,6 @@ void CMyTabCtrl::OnLButtonUp(UINT nFlags, CPoint point)
CWnd::OnLButtonUp(nFlags, point);
}

void CMDITabBar::OnSize(UINT nType, int cx, int cy)
{
__super::OnSize(nType, cx, cy);
Invalidate();
m_titleBar.OnSize(this, m_bMaximized, cx, cy);
if (m_tabCtrl.m_hWnd)
{
CClientDC dc(this);
const int lpx = dc.GetDeviceCaps(LOGPIXELSX);
auto pointToPixel = [lpx](float point) { return static_cast<int>(point * lpx / 72); };
const int leftMargin = m_bOnTitleBar ? pointToPixel(m_leftMarginPoint) : 0;
const int rightMargin = m_bOnTitleBar ? pointToPixel(m_rightMarginPoint) : 0;
int topMargin = ((m_bMaximized && m_bOnTitleBar) ? 8 : 0) + (m_bOnTitleBar ? 1 : 0);
int bottomMargin = m_bOnTitleBar ? 1 : 0;
CSize size{ 0, cy - topMargin - bottomMargin };
m_tabCtrl.MoveWindow(leftMargin, topMargin, cx - leftMargin - rightMargin, cy - topMargin - bottomMargin, true);
m_tabCtrl.SetItemSize(size);
}
}

CRect CMyTabCtrl::GetCloseButtonRect(int nItem)
{
CClientDC dc(this);
Expand Down Expand Up @@ -610,12 +592,14 @@ void CMyTabCtrl::UpdateToolTips(int nTabItemIndex)
}
}

BOOL CMDITabBar::Update(bool bOnTitleBar, bool bMaximized, float leftMarginPoint, float rightMarginPoint)
BOOL CMDITabBar::Update(bool bOnTitleBar, bool bMaximized)
{
m_bOnTitleBar = bOnTitleBar;
m_bMaximized = bMaximized;
m_leftMarginPoint = leftMarginPoint;
m_rightMarginPoint = rightMarginPoint;
CRect rc;
if (m_bMaximized)
AfxGetMainWnd()->GetWindowRect(&rc);
m_top = rc.top;
return true;
}

Expand All @@ -627,7 +611,9 @@ BOOL CMDITabBar::Create(CMDIFrameWnd* pMainFrame)
{
m_dwStyle = CBRS_TOP;

CWnd::Create(WC_STATIC, nullptr, WS_CHILD | WS_VISIBLE, CRect(0, 0, 0, 0), pMainFrame, AFX_IDW_CONTROLBAR_FIRST + 30);
m_titleBar.Init(this);

CWnd::Create(nullptr, nullptr, WS_CHILD | WS_VISIBLE, CRect(0, 0, 0, 0), pMainFrame, AFX_IDW_CONTROLBAR_FIRST + 30);

if (!m_tabCtrl.Create(pMainFrame, this))
return FALSE;
Expand Down Expand Up @@ -665,8 +651,7 @@ CSize CMDITabBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
auto pointToPixel = [lpx](int point) { return MulDiv(point, lpx, 72); };
const int r = pointToPixel(RR_RADIUS);
const int sw = pointToPixel(RR_SHADOWWIDTH);

int my = m_bOnTitleBar ? (m_bMaximized ? (8 + 6) : 6) : 0;
int my = m_bOnTitleBar ? (m_bMaximized ? (-m_top + 2) : 2) : 0;
CSize size(SHRT_MAX, my + tm.tmHeight + (sw + r) * 2);
return size;
}
Expand All @@ -676,6 +661,48 @@ LRESULT CMDITabBar::OnNcHitTest(CPoint point)
return m_titleBar.HitTest(point);
}

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

void CMDITabBar::OnNcMouseLeave()
{
m_titleBar.OnNcMouseLeave();
}

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

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

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

void CMDITabBar::OnSize(UINT nType, int cx, int cy)
{
__super::OnSize(nType, cx, cy);
Invalidate();
m_titleBar.OnSize(m_bMaximized, 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 bottomMargin = m_bOnTitleBar ? 1 : 0;
CSize size{ 0, cy - topMargin - bottomMargin };
m_tabCtrl.MoveWindow(leftMargin, topMargin, cx - leftMargin - rightMargin, cy - topMargin - bottomMargin, true);
m_tabCtrl.SetItemSize(size);
}
}

BOOL CMDITabBar::OnEraseBkgnd(CDC* pDC)
{
CRect rClient;
Expand All @@ -686,12 +713,11 @@ BOOL CMDITabBar::OnEraseBkgnd(CDC* pDC)

void CMDITabBar::OnPaint()
{
CPaintDC dc(this);
if (!m_bOnTitleBar)
return;
return __super::OnPaint();
CPaintDC dc(this);
CRect rcClient;
GetClientRect(&rcClient);
const int lpx = dc.GetDeviceCaps(LOGPIXELSX);
auto pointToPixel = [lpx](float point) -> int { return static_cast<int>(point * lpx / 72); };
m_titleBar.DrawIcon(AfxGetMainWnd(), dc, pointToPixel(m_leftMarginPoint));
m_titleBar.DrawIcon(AfxGetMainWnd(), dc);
m_titleBar.DrawButtons(dc);
}
19 changes: 10 additions & 9 deletions Src/Common/MDITabBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ class CMDITabBar : public CControlBar

bool m_bOnTitleBar;
bool m_bMaximized;
float m_leftMarginPoint;
float m_rightMarginPoint;
int m_top;
CMyTabCtrl m_tabCtrl;
CFont m_font;
CTitleBarHelper m_titleBar;
Expand All @@ -96,11 +95,10 @@ class CMDITabBar : public CControlBar
CMDITabBar()
: m_bOnTitleBar(true)
, m_bMaximized(false)
, m_leftMarginPoint(0)
, m_rightMarginPoint(0)
, m_top(0)
{}
virtual ~CMDITabBar() {}
BOOL Update(bool bOnTitleBar, bool bMaxmized, float iconWidthPoint, float buttonsWidthPoint);
BOOL Update(bool bOnTitleBar, bool bMaxmized);
BOOL Create(CMDIFrameWnd* pParentWnd);
void UpdateTabs() { m_tabCtrl.UpdateTabs(); }
bool GetAutoMaxWidth() const { return m_tabCtrl.GetAutoMaxWidth(); }
Expand All @@ -113,12 +111,15 @@ class CMDITabBar : public CControlBar
protected:

//{{AFX_MSG(CMDITabBar)
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnPaint();
afx_msg LRESULT OnNcHitTest(CPoint point);
template <UINT message>
afx_msg LRESULT OnNcForward(WPARAM wParam, LPARAM lParam) { return AfxGetMainWnd()->SendMessage(message, wParam, lParam); }
afx_msg void OnNcMouseMove(UINT nHitTest, CPoint point);
afx_msg void OnNcMouseLeave();
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 OnSize(UINT nType, int cx, int cy);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnPaint();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()

Expand Down
20 changes: 18 additions & 2 deletions Src/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
ON_WM_ACTIVATEAPP()
ON_WM_NCCALCSIZE()
ON_WM_SIZE()
ON_WM_MOUSEMOVE()
ON_WM_MOUSELEAVE()
ON_WM_NCMOUSEMOVE()
ON_WM_NCMOUSELEAVE()
ON_UPDATE_COMMAND_UI_RANGE(CMenuBar::FIRST_MENUID, CMenuBar::FIRST_MENUID + 10, OnUpdateMenuBarMenuItem)
// [File] menu
ON_COMMAND(ID_FILE_NEW, (OnFileNew<2, ID_MERGE_COMPARE_TEXT>))
Expand Down Expand Up @@ -413,7 +417,7 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
if (IsWin10_OrGreater())
m_bTabsOnTitleBar = GetOptionsMgr()->GetBool(OPT_TABBAR_ON_TITLEBAR);

m_wndTabBar.Update(m_bTabsOnTitleBar.value_or(false), false, 32.f, 18.f * 3);
m_wndTabBar.Update(m_bTabsOnTitleBar.value_or(false), false);

if (m_bTabsOnTitleBar.value_or(false) && !m_wndTabBar.Create(this))
{
Expand Down Expand Up @@ -2543,10 +2547,22 @@ void CMainFrame::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncs

void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
m_wndTabBar.Update(m_bTabsOnTitleBar.value_or(false), (nType == SIZE_MAXIMIZED), 32.f, 18.f * 3);
m_wndTabBar.Update(m_bTabsOnTitleBar.value_or(false), (nType == SIZE_MAXIMIZED));
__super::OnSize(nType, cx, cy);
}

void CMainFrame::OnMouseMove(UINT nFlags, CPoint point)
{
}

void CMainFrame::OnMouseLeave()
{
}

void CMainFrame::OnNcMouseMove(UINT nHitTest, CPoint point)
{
}

BOOL CMainFrame::CreateToolbar()
{
if (!m_wndMenuBar.Create(this))
Expand Down
3 changes: 3 additions & 0 deletions Src/MainFrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ class CMainFrame : public CMDIFrameWnd
afx_msg void OnActivateApp(BOOL bActive, DWORD dwThreadID);
afx_msg void OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnMouseLeave();
afx_msg void OnNcMouseMove(UINT nHitTest, CPoint point);
afx_msg void OnToolbarSize(UINT id);
afx_msg void OnUpdateToolbarSize(CCmdUI* pCmdUI);
afx_msg BOOL OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult);
Expand Down
Loading

0 comments on commit e129685

Please sign in to comment.