Skip to content

Commit

Permalink
Implement Menu Bar as a Toolbar (WinMerge#2400)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka authored Aug 15, 2024
1 parent 711a3b8 commit d78d4a7
Show file tree
Hide file tree
Showing 11 changed files with 638 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Src/BasicFlatStatusBar.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright (c) 2024 Takashi Sawanaka
// SPDX-License-Identifier: BSL-1.0
/**
* @file BasicFlatStatusBar.cpp
*
Expand Down
37 changes: 31 additions & 6 deletions Src/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
ON_MESSAGE(WM_COPYDATA, OnCopyData)
ON_MESSAGE(WM_USER+1, OnUser1)
ON_WM_ACTIVATEAPP()
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>))
ON_COMMAND(ID_FILE_NEW_TABLE, (OnFileNew<2, ID_MERGE_COMPARE_TABLE>))
Expand Down Expand Up @@ -288,6 +289,7 @@ BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
ON_COMMAND(ID_LASTFILE, OnLastFile)
ON_UPDATE_COMMAND_UI(ID_LASTFILE, OnUpdateLastFile)
// Tool bar drop-down menu
ON_NOTIFY(TBN_DROPDOWN, AFX_IDW_MENUBAR, OnMenubarButtonDropDown)
ON_NOTIFY(TBN_DROPDOWN, AFX_IDW_TOOLBAR, OnToolbarButtonDropDown)
ON_COMMAND_RANGE(ID_DIFF_OPTIONS_WHITESPACE_COMPARE, ID_DIFF_OPTIONS_WHITESPACE_IGNOREALL, OnDiffWhitespace)
ON_UPDATE_COMMAND_UI_RANGE(ID_DIFF_OPTIONS_WHITESPACE_COMPARE, ID_DIFF_OPTIONS_WHITESPACE_IGNOREALL, OnUpdateDiffWhitespace)
Expand Down Expand Up @@ -446,6 +448,11 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
return 0;
}

void CMainFrame::OnUpdateMenuBarMenuItem(CCmdUI* pCmdUI)
{
m_wndMenuBar.OnUpdateMenuBarMenuItem(pCmdUI);
}

void CMainFrame::OnTimer(UINT_PTR nIDEvent)
{
__super::OnTimer(nIDEvent);
Expand Down Expand Up @@ -1682,6 +1689,8 @@ void CMainFrame::OnClose()
theApp.WriteProfileInt(_T("Settings"), _T("MainBottom"),wp.rcNormalPosition.bottom);
theApp.WriteProfileInt(_T("Settings"), _T("MainMax"), (wp.showCmd == SW_MAXIMIZE));

GetOptionsMgr()->SaveOption(OPT_REBAR_STATE, m_wndReBar.GenerateStateString());

for (auto pFrame: GetAllImgMergeFrames())
{
if (!pFrame->CloseNow())
Expand Down Expand Up @@ -2167,6 +2176,8 @@ void CMainFrame::SelectFilter()
*/
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
if (m_wndMenuBar.PreTranslateMessage(pMsg))
return TRUE;
// Check if we got 'ESC pressed' -message
if ((pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_ESCAPE))
{
Expand Down Expand Up @@ -2470,26 +2481,30 @@ void CMainFrame::OnActivateApp(BOOL bActive, DWORD dwThreadID)

BOOL CMainFrame::CreateToolbar()
{
if (!m_wndToolBar.CreateEx(this) ||
if (!m_wndMenuBar.Create(this))
{
return FALSE;
}

if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
return FALSE;
}

if (!m_wndReBar.Create(this, RBS_BANDBORDERS,
if (!m_wndReBar.Create(this, 0,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_ALIGN_TOP))
{
return FALSE;
}

VERIFY(m_wndToolBar.ModifyStyle(0, TBSTYLE_FLAT|TBSTYLE_TRANSPARENT));

// Remove this if you don't want tool tips or a resizable toolbar
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
m_wndToolBar.GetToolBarCtrl().SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS);

m_wndReBar.AddBar(&m_wndToolBar);
m_wndReBar.AddBar(&m_wndMenuBar);
m_wndReBar.AddBar(&m_wndToolBar, nullptr, nullptr, RBBS_GRIPPERALWAYS | RBBS_FIXEDBMP | RBBS_BREAK);

LoadToolbarImages();

Expand All @@ -2508,6 +2523,10 @@ BOOL CMainFrame::CreateToolbar()
__super::ShowControlBar(&m_wndToolBar, false, 0);
}

__super::ShowControlBar(&m_wndMenuBar, true, 0);

m_wndReBar.LoadStateFromString(GetOptionsMgr()->GetString(OPT_REBAR_STATE).c_str());

return TRUE;
}

Expand Down Expand Up @@ -2542,7 +2561,7 @@ void CMainFrame::LoadToolbarImages()
REBARBANDINFO rbbi = { sizeof REBARBANDINFO };
rbbi.fMask = RBBIM_CHILDSIZE;
rbbi.cyMinChild = sizeButton.cy;
m_wndReBar.GetReBarCtrl().SetBandInfo(0, &rbbi);
m_wndReBar.GetReBarCtrl().SetBandInfo(1, &rbbi);
}


Expand Down Expand Up @@ -2916,6 +2935,12 @@ void CMainFrame::OnPluginsList()
dlg.DoModal();
}

void CMainFrame::OnMenubarButtonDropDown(NMHDR* pNMHDR, LRESULT* pResult)
{
m_wndMenuBar.OnMenuBarMenuItem(reinterpret_cast<LPNMTOOLBAR>(pNMHDR)->iItem);
*pResult = 0;
}

void CMainFrame::OnToolbarButtonDropDown(NMHDR* pNMHDR, LRESULT* pResult)
{
LPNMTOOLBAR pToolBar = reinterpret_cast<LPNMTOOLBAR>(pNMHDR);
Expand Down
13 changes: 12 additions & 1 deletion Src/MainFrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <vector>
#include <memory>
#include <optional>
#include "MyReBar.h"
#include "MenuBar.h"
#include "MDITabBar.h"
#include "BasicFlatStatusBar.h"
#include "PathContext.h"
Expand Down Expand Up @@ -222,6 +224,7 @@ class CMainFrame : public CMDIFrameWnd
DirWatcher* GetDirWatcher() { return m_pDirWatcher.get(); }
void WatchDocuments(IMergeDoc* pMergeDoc);
void UnwatchDocuments(IMergeDoc* pMergeDoc);
CMenuBar* GetMenuBar() { return &m_wndMenuBar; }
CToolBar* GetToolbar() { return &m_wndToolBar; }
static void WaitAndDoMessageLoop(bool& completed, int ms);

Expand All @@ -248,7 +251,8 @@ class CMainFrame : public CMDIFrameWnd
protected:
// control bar embedded members
CBasicFlatStatusBar m_wndStatusBar;
CReBar m_wndReBar;
CMyReBar m_wndReBar;
CMenuBar m_wndMenuBar;
CToolBar m_wndToolBar;
CMDITabBar m_wndTabBar;
CTypedPtrArray<CPtrArray, CMDIChildWnd*> m_arrChild;
Expand All @@ -274,6 +278,11 @@ class CMainFrame : public CMDIFrameWnd
}
break;
}
case WM_MDISETMENU:
GetMainFrame()->SetMenuBarState(AFX_MBS_HIDDEN);
GetMainFrame()->GetMenuBar()->AttachMenu(CMenu::FromHandle(reinterpret_cast<HMENU>(wParam)));
return TRUE;
break;
case WM_TIMER:
if (wParam == m_nRedrawTimer)
{
Expand Down Expand Up @@ -383,6 +392,7 @@ class CMainFrame : public CMDIFrameWnd
afx_msg void OnUpdatePluginName(CCmdUI* pCmdUI);
afx_msg void OnUpdateStatusNum(CCmdUI* pCmdUI);
afx_msg void OnToolbarButtonDropDown(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnMenubarButtonDropDown(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnDiffWhitespace(UINT nID);
afx_msg void OnUpdateDiffWhitespace(CCmdUI* pCmdUI);
afx_msg void OnDiffIgnoreBlankLines();
Expand Down Expand Up @@ -418,6 +428,7 @@ class CMainFrame : public CMDIFrameWnd
afx_msg LRESULT OnChildFrameRemoved(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnChildFrameActivate(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnChildFrameActivated(WPARAM wParam, LPARAM lParam);
afx_msg void OnUpdateMenuBarMenuItem(CCmdUI* pCmdUI);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()

Expand Down
Loading

0 comments on commit d78d4a7

Please sign in to comment.