Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for placing the tab bar on the title bar #2428

Merged
merged 34 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7e2f5ff
WIP
sdottaka Aug 22, 2024
00d9c2b
WIP
sdottaka Aug 23, 2024
d0bf09a
WIP
sdottaka Aug 25, 2024
5ed5f4c
Merge branch 'master' into custom-titlebar
sdottaka Aug 28, 2024
10daec4
Merge branch 'master' into custom-titlebar
sdottaka Aug 31, 2024
4bee9e2
WIP
sdottaka Sep 1, 2024
8b3cd59
WIP
sdottaka Sep 1, 2024
6110e8f
WIP
sdottaka Sep 7, 2024
8875d62
Merge branch 'master' into custom-titlebar
sdottaka Sep 8, 2024
e867c0d
crystaledit/editlib/parses/*: refactor
sdottaka Sep 8, 2024
c82b15f
Merge branch 'master' into custom-titlebar
sdottaka Sep 8, 2024
a4b4150
WIP
sdottaka Sep 10, 2024
7496b33
WIP
sdottaka Sep 16, 2024
573af39
WIP
sdottaka Sep 17, 2024
a371119
Merge branch 'master' into custom-titlebar
sdottaka Sep 17, 2024
d4eb296
WIP
sdottaka Sep 18, 2024
0a4f3dc
Merge branch 'master' into custom-titlebar
sdottaka Sep 18, 2024
1f0c334
Merge branch 'master' into custom-titlebar
sdottaka Sep 18, 2024
3387acb
WIP
sdottaka Sep 19, 2024
862541a
Merge branch 'master' into custom-titlebar
sdottaka Sep 19, 2024
6617b92
WIP
sdottaka Sep 21, 2024
2b9a605
WIP
sdottaka Sep 21, 2024
e1be4c8
WIP
sdottaka Sep 22, 2024
e129685
WIP
sdottaka Sep 23, 2024
760bef2
WIP
sdottaka Sep 24, 2024
e485afd
WIP
sdottaka Sep 24, 2024
a1b27d1
Merge remote-tracking branch 'origin/master' into custom-titlebar
sdottaka Sep 25, 2024
18aa09a
WIP
sdottaka Sep 25, 2024
1633bb6
Merge branch 'master' into custom-titlebar
sdottaka Sep 28, 2024
a4ba334
WIP
sdottaka Sep 28, 2024
45a42ef
Merge branch 'master' into custom-titlebar
sdottaka Sep 28, 2024
cd1259a
Update Japanese.po
sdottaka Sep 28, 2024
d50e145
WIP
sdottaka Sep 28, 2024
0d800f3
Merge remote-tracking branch 'origin/master' into custom-titlebar
sdottaka Sep 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 54 additions & 6 deletions Src/Common/MDITabBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
ON_WM_MOUSELEAVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_MESSAGE(WM_SIZEPARENT, OnSizeParent)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

Expand All @@ -42,6 +43,15 @@
return GetSystemMetrics(SM_CXSMICON);
}

BOOL CMDITabBar::Update(bool bOnTitleBar, bool bMaximized, float leftMarginPoint, float rightMarginPoint)
{
m_bOnTitleBar = bOnTitleBar;
m_bMaximized = bMaximized;
m_leftMarginPoint = leftMarginPoint;
m_rightMarginPoint = rightMarginPoint;
return true;
}

/**
* @brief Create tab bar.
* @param pParentWnd [in] main frame window pointer
Expand Down Expand Up @@ -92,7 +102,7 @@
*/
CSize CMDITabBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
{
if (GetItemCount() == 0)
if (!m_bOnTitleBar && GetItemCount() == 0)
return CSize(SHRT_MAX, 0);

TEXTMETRIC tm;
Expand All @@ -106,7 +116,10 @@
const int r = pointToPixel(RR_RADIUS);
const int sw = pointToPixel(RR_SHADOWWIDTH);

return CSize(SHRT_MAX, tm.tmHeight + (sw + r) * 2);
int my = m_bOnTitleBar ? (m_bMaximized ? (8 + 6) : 6) : 0;
CSize size(SHRT_MAX, my + tm.tmHeight + (sw + r) * 2);
SetItemSize(0, size.cy);
return size;
}

void CMDITabBar::OnPaint()
Expand Down Expand Up @@ -359,18 +372,23 @@
const int sw = pointToPixel(RR_SHADOWWIDTH);

CRect rc = lpDraw->rcItem;
if (m_bOnTitleBar)
{
rc.top += 2 + (m_bMaximized ? 8 : 0);
rc.bottom -= 1;
}
if (lpDraw->itemState & ODS_SELECTED)
{
const COLORREF clrShadow = CEColor::GetIntermediateColor(GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DFACE), 0.5f);
if (GetSysColor(COLOR_3DFACE) == GetSysColor(COLOR_WINDOW))
{
DrawRoundedRectWithShadow(lpDraw->hDC, rc.left + sw, sw - 1, rc.Width() - sw * 2, rc.top - sw * 2 + 2, r, sw,
DrawRoundedRectWithShadow(lpDraw->hDC, rc.left + sw, rc.top + sw - 1, rc.Width() - sw * 2, rc.top - sw * 2 + 2, r, sw,
GetSysColor(COLOR_HIGHLIGHT), clrShadow, GetSysColor(COLOR_3DFACE));
SetTextColor(lpDraw->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
}
else
{
DrawRoundedRectWithShadow(lpDraw->hDC, rc.left + sw, sw - 1, rc.Width() - sw * 2, rc.Height() - sw * 2 + 2, r, sw,
DrawRoundedRectWithShadow(lpDraw->hDC, rc.left + sw, rc.top + sw - 1, rc.Width() - sw * 2, rc.Height() - sw * 2 + 2, r, sw,
GetSysColor(COLOR_WINDOW), clrShadow, GetSysColor(COLOR_3DFACE));
SetTextColor(lpDraw->hDC, GetSysColor(COLOR_WINDOWTEXT));
}
Expand Down Expand Up @@ -462,7 +480,7 @@
InvalidateRect(m_rcCurrentCloseButtom);
if (!m_bCloseButtonDown)
{
if (DragDetect(point))
if (DragDetect(point))
{
m_nDraggingTabItemIndex = GetItemIndexFromPoint(point);
SetCapture();
Expand All @@ -488,6 +506,34 @@
CWnd::OnLButtonUp(nFlags, point);
}

LRESULT CMDITabBar::OnSizeParent(WPARAM wParam, LPARAM lParam)
{
if (!m_bOnTitleBar)
return __super::OnSizeParent(wParam, lParam);
CClientDC dc(this);
const int lpx = dc.GetDeviceCaps(LOGPIXELSX);
auto pointToPixel = [lpx](float point) { return static_cast<int>(point * lpx / 72); };
AFX_SIZEPARENTPARAMS* lpLayout = (AFX_SIZEPARENTPARAMS*)lParam;
const int leftMargin = pointToPixel(m_leftMarginPoint);
const int rightMargin = pointToPixel(m_rightMarginPoint);
if (m_bMaximized)
{
// lpLayout->rect.top += 8;
// lpLayout->rect.bottom -= 8;
Fixed Show fixed Hide fixed
}
Fixed Show fixed Hide fixed
lpLayout->rect.left += leftMargin;
lpLayout->rect.right -= rightMargin;
LRESULT result = __super::OnSizeParent(wParam, reinterpret_cast<LPARAM>(lpLayout));
if (m_bMaximized)
{
// lpLayout->rect.top -= 8;
// lpLayout->rect.bottom += 8;
Fixed Show fixed Hide fixed
}
Fixed Show fixed Hide fixed
lpLayout->rect.left -= leftMargin;
lpLayout->rect.right += rightMargin;
return result;
}

CRect CMDITabBar::GetCloseButtonRect(int nItem)
{
CClientDC dc(this);
Expand All @@ -502,7 +548,7 @@
rc.left = rc.right - size.cx - sw - r;
rc.right = rc.left + size.cx;
int y = (rcClient.top + rcClient.bottom) / 2;
rc.top = y - size.cy / 2 + 1;
rc.top = y - size.cy / 2 + 1 + ((m_bOnTitleBar && m_bMaximized) ? 8 / 2 : 0);
rc.bottom = rc.top + size.cy;
return rc;
}
Expand Down Expand Up @@ -572,6 +618,7 @@
return;

for (CWnd* pFrame = pParentWnd->GetTopWindow(); pFrame; pFrame = pFrame->GetNextWindow())
{
if (reinterpret_cast<HWND>(tci.lParam) == pFrame->m_hWnd)
{
HWND hFrameWnd = pFrame->m_hWnd;
Expand Down Expand Up @@ -605,4 +652,5 @@
m_nTooltipTabItemIndex = nTabItemIndex;
return;
}
}
}
21 changes: 20 additions & 1 deletion Src/Common/MDITabBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class CMDITabBar : public CControlBar
private:
enum {MDITABBAR_MINTITLELENGTH = 8, MDITABBAR_MAXTITLELENGTH = 64};

bool m_bOnTitleBar;
bool m_bMaximized;
float m_leftMarginPoint;
float m_rightMarginPoint;
bool m_bInSelchange;
CMDIFrameWnd *m_pMainFrame;
bool m_bMouseTracking;
Expand All @@ -28,8 +32,20 @@ class CMDITabBar : public CControlBar
int m_nTooltipTabItemIndex; /**< Index of the tab displaying tooltip */

public:
CMDITabBar() : m_bInSelchange(false), m_pMainFrame(nullptr), m_bMouseTracking(false), m_bCloseButtonDown(false), m_bAutoMaxWidth(true), m_nDraggingTabItemIndex(-1), m_nTooltipTabItemIndex(-1){}
CMDITabBar()
: m_bOnTitleBar(true)
, m_bMaximized(false)
, m_leftMarginPoint(0)
, m_rightMarginPoint(0)
, m_bInSelchange(false)
, m_pMainFrame(nullptr)
, m_bMouseTracking(false)
, m_bCloseButtonDown(false)
, m_bAutoMaxWidth(true)
, m_nDraggingTabItemIndex(-1)
, m_nTooltipTabItemIndex(-1) {}
virtual ~CMDITabBar() {}
BOOL Update(bool bOnTitleBar, bool bMaxmized, float iconWidthPoint, float buttonsWidthPoint);
BOOL Create(CMDIFrameWnd* pParentWnd);
void UpdateTabs();
bool GetAutoMaxWidth() const { return m_bAutoMaxWidth; }
Expand All @@ -56,6 +72,8 @@ class CMDITabBar : public CControlBar
{ ASSERT(::IsWindow(m_hWnd)); return (int)::SendMessage(m_hWnd, TCM_HITTEST, 0, (LPARAM) pHitTestInfo); }
BOOL GetItemRect(int nItem, LPRECT lpRect) const
{ ASSERT(::IsWindow(m_hWnd)); return (BOOL)::SendMessage(m_hWnd, TCM_GETITEMRECT, (WPARAM)nItem, (LPARAM)lpRect); }
BOOL SetItemSize(int x, int y) const
{ ASSERT(::IsWindow(m_hWnd)); return (BOOL)::SendMessage(m_hWnd, TCM_SETITEMSIZE, (WPARAM)0, (LPARAM)MAKELONG(x, y)); }

protected:
virtual BOOL PreTranslateMessage(MSG* pMsg);
Expand All @@ -71,6 +89,7 @@ class CMDITabBar : public CControlBar
afx_msg void OnMouseLeave();
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg LRESULT OnSizeParent(WPARAM wParam, LPARAM lParam);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()

Expand Down
66 changes: 60 additions & 6 deletions Src/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#include "ClipboardHistory.h"
#include "locality.h"
#include "DirWatcher.h"
#include <afxwinverapi.h>

using std::vector;
using boost::begin;
Expand Down Expand Up @@ -220,6 +221,12 @@ BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
ON_MESSAGE(WM_COPYDATA, OnCopyData)
ON_MESSAGE(WM_USER+1, OnUser1)
ON_WM_ACTIVATEAPP()
ON_WM_NCCALCSIZE()
ON_WM_NCHITTEST()
ON_WM_NCLBUTTONDOWN()
ON_WM_NCLBUTTONUP()
ON_WM_SIZE()
ON_WM_PAINT()
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 @@ -404,12 +411,8 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)

m_wndMDIClient.SubclassWindow(m_hWndMDIClient);

if (!CreateToolbar())
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}

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

if (!m_wndTabBar.Create(this))
{
TRACE0("Failed to create tab bar\n");
Expand All @@ -420,6 +423,12 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
if (!GetOptionsMgr()->GetBool(OPT_SHOW_TABBAR))
__super::ShowControlBar(&m_wndTabBar, false, 0);

if (!CreateToolbar())
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}

if (!m_wndStatusBar.Create(this))
{
TRACE0("Failed to create status bar\n");
Expand Down Expand Up @@ -2481,6 +2490,51 @@ void CMainFrame::OnActivateApp(BOOL bActive, DWORD dwThreadID)
}
}

void CMainFrame::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
{
RECT rcWindow = lpncsp->rgrc[0];
__super::OnNcCalcSize(bCalcValidRects, lpncsp);
lpncsp->rgrc[0].top = rcWindow.top + 0;
}

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

LRESULT CMainFrame::OnNcHitTest(CPoint point)
{
LRESULT res = m_titleBar.HitTest(point);
if (res > HTNOWHERE)
return res;
return __super::OnNcHitTest(point);
}

void CMainFrame::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
__super::OnNcLButtonDown(nHitTest, point);
}

void CMainFrame::OnNcLButtonUp(UINT nFlags, CPoint point)
{
__super::OnNcLButtonUp(nFlags, point);
}

void CMainFrame::OnPaint()
{
__super::OnPaint();
CRect rcClient;
GetClientRect(&rcClient);
CClientDC dc(this);
m_titleBar.DrawIcon(this, dc);
const int bw = 64;
CRect rc1{ rcClient.right - bw, 0, rcClient.right, bw };
CRect rc2{ rcClient.right - bw * 2, 0, rcClient.right - bw * 1, bw };
CRect rc3{ rcClient.right - bw * 3, 0, rcClient.right - bw * 2, bw };
}

BOOL CMainFrame::CreateToolbar()
{
if (!m_wndMenuBar.Create(this))
Expand Down
8 changes: 8 additions & 0 deletions Src/MainFrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "OptionsDef.h"
#include "OptionsMgr.h"
#include "FileOpenFlags.h"
#include "TitleBarHelper.h"

class BCMenu;
class CDirView;
Expand Down Expand Up @@ -342,6 +343,7 @@ class CMainFrame : public CMDIFrameWnd
std::vector<TempFilePtr> m_tempFiles; /**< List of possibly needed temp files. */
DropHandler *m_pDropHandler;
std::unique_ptr<DirWatcher> m_pDirWatcher;
CTitleBarHelper m_titleBar;

// Generated message map functions
protected:
Expand Down Expand Up @@ -381,6 +383,12 @@ class CMainFrame : public CMDIFrameWnd
afx_msg void OnUpdateWindowCloseAll(CCmdUI* pCmdUI);
afx_msg void OnSaveProject();
afx_msg void OnActivateApp(BOOL bActive, DWORD dwThreadID);
afx_msg LRESULT OnNcHitTest(CPoint point);
afx_msg void OnNcLButtonDown(UINT nHitTest, CPoint point);
afx_msg void OnNcLButtonUp(UINT nHitTest, CPoint point);
afx_msg void OnPaint();
afx_msg void OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnToolbarSize(UINT id);
afx_msg void OnUpdateToolbarSize(CCmdUI* pCmdUI);
afx_msg BOOL OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult);
Expand Down
5 changes: 5 additions & 0 deletions Src/MenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ BOOL CMenuBar::Create(CWnd* pParentWnd, DWORD dwStyle, UINT nID)

bool CMenuBar::AttachMenu(CMenu* pMenu)
{
if (!m_hWnd)
return false;

CToolBarCtrl& toolbar = GetToolBarCtrl();

toolbar.SetRedraw(false);
Expand Down Expand Up @@ -334,6 +337,8 @@ LRESULT CMenuBar::OnShowPopupMenu(WPARAM wParam, LPARAM lParam)

BOOL CMenuBar::PreTranslateMessage(MSG* pMsg)
{
if (!m_hWnd)
return FALSE;
if (pMsg->message == WM_SYSKEYDOWN || pMsg->message == WM_SYSKEYUP)
{
if (pMsg->wParam == VK_F10 || pMsg->wParam == VK_MENU)
Expand Down
2 changes: 2 additions & 0 deletions Src/Merge.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,7 @@
<PrecompiledHeaderOutputFile>$(IntDir)$(TargetName)2.pch</PrecompiledHeaderOutputFile>
</ClCompile>
<ClCompile Include="TestMain.cpp" />
<ClCompile Include="TitleBarHelper.cpp" />
<ClCompile Include="TrDialogs.cpp" />
<ClCompile Include="Common\varprop.cpp">
<PrecompiledHeader>Use</PrecompiledHeader>
Expand Down Expand Up @@ -1647,6 +1648,7 @@
<ClInclude Include="Common\unicoder.h" />
<ClInclude Include="Common\UnicodeString.h" />
<ClInclude Include="Common\UniFile.h" />
<ClInclude Include="TitleBarHelper.h" />
<ClInclude Include="TrDialogs.h" />
<ClInclude Include="Common\varprop.h" />
<ClInclude Include="Common\VersionInfo.h" />
Expand Down
6 changes: 6 additions & 0 deletions Src/Merge.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,9 @@
<ClCompile Include="MyReBar.cpp">
<Filter>MFCGui\Common\Source Files</Filter>
</ClCompile>
<ClCompile Include="TitleBarHelper.cpp">
<Filter>MFCGui\Common\Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="charsets.h">
Expand Down Expand Up @@ -1406,6 +1409,9 @@
<ClInclude Include="MyReBar.h">
<Filter>MFCGui\Common\Header Files</Filter>
</ClInclude>
<ClInclude Include="TitleBarHelper.h">
<Filter>MFCGui\Common\Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="res\binarydiff.ico">
Expand Down
Loading
Loading