From fedc5b84e2d4d27df360e8ccacb73ec10b86026d Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Thu, 6 Jun 2019 00:46:56 +0900 Subject: [PATCH] Add MergeFrameCommon.* --- Src/DirFrame.cpp | 81 ++++--------------------------- Src/DirFrame.h | 8 +--- Src/HexMergeFrm.cpp | 70 ++------------------------- Src/HexMergeFrm.h | 9 +--- Src/ImgMergeFrm.cpp | 62 ++---------------------- Src/ImgMergeFrm.h | 9 +--- Src/Merge.vs2017.vcxproj | 2 + Src/Merge.vs2017.vcxproj.filters | 6 +++ Src/Merge.vs2019.vcxproj | 2 + Src/Merge.vs2019.vcxproj.filters | 6 +++ Src/MergeEditFrm.cpp | 81 ++----------------------------- Src/MergeEditFrm.h | 11 +---- Src/MergeFrameCommon.cpp | 101 +++++++++++++++++++++++++++++++++++++++ Src/MergeFrameCommon.h | 30 ++++++++++++ Src/OpenFrm.cpp | 34 ++----------- Src/OpenFrm.h | 7 +-- 16 files changed, 185 insertions(+), 334 deletions(-) create mode 100644 Src/MergeFrameCommon.cpp create mode 100644 Src/MergeFrameCommon.h diff --git a/Src/DirFrame.cpp b/Src/DirFrame.cpp index 005d56d71..747b58967 100644 --- a/Src/DirFrame.cpp +++ b/Src/DirFrame.cpp @@ -77,11 +77,10 @@ static UINT RO_PANEL_WIDTH = 30; ///////////////////////////////////////////////////////////////////////////// // CDirFrame -IMPLEMENT_DYNCREATE(CDirFrame, CMDIChildWnd) +IMPLEMENT_DYNCREATE(CDirFrame, CMergeFrameCommon) CDirFrame::CDirFrame() -: m_hIdentical(nullptr) -, m_hDifferent(nullptr) +: CMergeFrameCommon(IDI_EQUALFOLDER, IDI_NOTEQUALFOLDER) { } @@ -90,13 +89,12 @@ CDirFrame::~CDirFrame() } -BEGIN_MESSAGE_MAP(CDirFrame, CMDIChildWnd) +BEGIN_MESSAGE_MAP(CDirFrame, CMergeFrameCommon) //{{AFX_MSG_MAP(CDirFrame) ON_WM_CREATE() ON_WM_CLOSE() ON_WM_SIZE() ON_WM_MDIACTIVATE() - ON_WM_GETMINMAXINFO() //}}AFX_MSG_MAP END_MESSAGE_MAP() @@ -142,9 +140,6 @@ int CDirFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) m_wndStatusBar.SetPaneText(PANE_MIDDLE_RO, sText.c_str(), TRUE); m_wndStatusBar.SetPaneText(PANE_RIGHT_RO, sText.c_str(), TRUE); - m_hIdentical = AfxGetApp()->LoadIcon(IDI_EQUALFOLDER); - m_hDifferent = AfxGetApp()->LoadIcon(IDI_NOTEQUALFOLDER); - return 0; } @@ -190,18 +185,7 @@ void CDirFrame::ActivateFrame(int nCmdShow) CDockState dockState; dockState.LoadState(_T("Settings-DirFrame")); SetDockState(dockState); - // get the active child frame, and a flag whether it is maximized - BOOL bMaximized = FALSE; - CMDIChildWnd * oldActiveFrame = GetMDIFrame()->MDIGetActive(&bMaximized); - if (oldActiveFrame == nullptr) - // for the first frame, get the restored/maximized state from the registry - bMaximized = GetOptionsMgr()->GetBool(OPT_ACTIVE_FRAME_MAX); - if (bMaximized) - nCmdShow = SW_SHOWMAXIMIZED; - else - nCmdShow = SW_SHOWNORMAL; - - CMDIChildWnd::ActivateFrame(nCmdShow); + CMergeFrameCommon::ActivateFrame(nCmdShow); } /** @@ -211,34 +195,6 @@ void CDirFrame::UpdateResources() { } -/** -* @brief Reflect comparison result in window's icon. -* @param nResult [in] Last comparison result which the application returns. -*/ -void CDirFrame::SetLastCompareResult(int nResult) -{ - HICON hCurrent = GetIcon(FALSE); - HICON hReplace = (nResult == 0) ? m_hIdentical : m_hDifferent; - - if (hCurrent != hReplace) - { - SetIcon(hReplace, TRUE); - - BOOL bMaximized; - GetMDIFrame()->MDIGetActive(&bMaximized); - - // When MDI maximized the window icon is drawn on the menu bar, so we - // need to notify it that our icon has changed. - if (bMaximized) - { - GetMDIFrame()->DrawMenuBar(); - } - GetMDIFrame()->OnUpdateFrameTitle(FALSE); - } - - theApp.SetLastCompareResult(nResult); -} - void CDirFrame::OnClose() { CMDIChildWnd::OnClose(); @@ -249,20 +205,11 @@ void CDirFrame::OnClose() */ BOOL CDirFrame::DestroyWindow() { - // If we are active, save the restored/maximized state - // If we are not, do nothing and let the active frame do the job. - if (this->GetParentFrame()->GetActiveFrame() == (CFrameWnd*)this) - { - WINDOWPLACEMENT wp; - wp.length = sizeof(WINDOWPLACEMENT); - GetWindowPlacement(&wp); - GetOptionsMgr()->SaveOption(OPT_ACTIVE_FRAME_MAX, (wp.showCmd == SW_MAXIMIZE)); - // save docking positions and sizes - CDockState dockState; - GetDockState(dockState); - dockState.SaveState(_T("Settings-DirFrame")); - } - + // save docking positions and sizes + CDockState dockState; + GetDockState(dockState); + dockState.SaveState(_T("Settings-DirFrame")); + SaveWindowState(); return CMDIChildWnd::DestroyWindow(); } @@ -273,13 +220,3 @@ void CDirFrame::OnSize(UINT nType, int cx, int cy) m_wndFilePathBar.Resize(); } -void CDirFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI) -{ - CMDIChildWnd::OnGetMinMaxInfo(lpMMI); - // [Fix for MFC 8.0 MDI Maximizing Child Window bug on Vista] - // https://groups.google.com/forum/#!topic/microsoft.public.vc.mfc/iajCdW5DzTM -#if _MFC_VER >= 0x0800 - lpMMI->ptMaxTrackSize.x = max(lpMMI->ptMaxTrackSize.x, lpMMI->ptMaxSize.x); - lpMMI->ptMaxTrackSize.y = max(lpMMI->ptMaxTrackSize.y, lpMMI->ptMaxSize.y); -#endif -} diff --git a/Src/DirFrame.h b/Src/DirFrame.h index 3e43fd8d0..4168e9971 100644 --- a/Src/DirFrame.h +++ b/Src/DirFrame.h @@ -26,6 +26,7 @@ #pragma once #include "EditorFilepathBar.h" +#include "MergeFrameCommon.h" ///////////////////////////////////////////////////////////////////////////// // CDirFrame frame @@ -33,7 +34,7 @@ /** * @brief Frame window for Directory Compare window */ -class CDirFrame : public CMDIChildWnd +class CDirFrame : public CMergeFrameCommon { DECLARE_DYNCREATE(CDirFrame) protected: @@ -43,8 +44,6 @@ protected: public: private: - HICON m_hIdentical; - HICON m_hDifferent; // Operations public: @@ -54,8 +53,6 @@ public: CStatusBar m_wndStatusBar; IHeaderBar * GetHeaderInterface(); void UpdateResources(); - void SetSharedMenu(HMENU hMenu) { m_hMenuShared = hMenu; }; - void SetLastCompareResult(int nResult); // Overrides // ClassWizard generated virtual function overrides @@ -74,7 +71,6 @@ protected: afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnClose(); afx_msg void OnSize(UINT nType, int cx, int cy); - afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; diff --git a/Src/HexMergeFrm.cpp b/Src/HexMergeFrm.cpp index 69502bfa3..851496d6a 100644 --- a/Src/HexMergeFrm.cpp +++ b/Src/HexMergeFrm.cpp @@ -40,14 +40,13 @@ ///////////////////////////////////////////////////////////////////////////// // CHexMergeFrame -IMPLEMENT_DYNCREATE(CHexMergeFrame, CMDIChildWnd) +IMPLEMENT_DYNCREATE(CHexMergeFrame, CMergeFrameCommon) -BEGIN_MESSAGE_MAP(CHexMergeFrame, CMDIChildWnd) +BEGIN_MESSAGE_MAP(CHexMergeFrame, CMergeFrameCommon) //{{AFX_MSG_MAP(CHexMergeFrame) ON_WM_CREATE() ON_WM_CLOSE() ON_WM_SIZE() - ON_WM_GETMINMAXINFO() ON_MESSAGE_VOID(WM_IDLEUPDATECMDUI, OnIdleUpdateCmdUI) ON_UPDATE_COMMAND_UI(ID_VIEW_DETAIL_BAR, OnUpdateControlBarMenu) ON_COMMAND_EX(ID_VIEW_DETAIL_BAR, OnBarCheck) @@ -74,10 +73,8 @@ enum // CHexMergeFrame construction/destruction CHexMergeFrame::CHexMergeFrame() -: m_hIdentical(nullptr) -, m_hDifferent(nullptr) + : CMergeFrameCommon(IDI_EQUALBINARY, IDI_BINARYDIFF) { - std::fill_n(m_nLastSplitPos, 2, 0); m_pMergeDoc = 0; } @@ -155,9 +152,6 @@ BOOL CHexMergeFrame::OnCreateClient( LPCREATESTRUCT /*lpcs*/, CSize size = m_wndStatusBar[0].CalcFixedLayout(TRUE, TRUE); m_rectBorder.bottom = size.cy; - m_hIdentical = AfxGetApp()->LoadIcon(IDI_EQUALBINARY); - m_hDifferent = AfxGetApp()->LoadIcon(IDI_BINARYDIFF); - // get the IHexEditorWindow interfaces IHexEditorWindow *pif[3]; for (nPane = 0; nPane < m_pMergeDoc->m_nBuffers; nPane++) @@ -196,11 +190,7 @@ BOOL CHexMergeFrame::OnCreateClient( LPCREATESTRUCT /*lpcs*/, void CHexMergeFrame::ActivateFrame(int nCmdShow) { - if (!GetMDIFrame()->MDIGetActive() && GetOptionsMgr()->GetBool(OPT_ACTIVE_FRAME_MAX)) - { - nCmdShow = SW_SHOWMAXIMIZED; - } - CMDIChildWnd::ActivateFrame(nCmdShow); + CMergeFrameCommon::ActivateFrame(nCmdShow); } /** @@ -209,16 +199,7 @@ void CHexMergeFrame::ActivateFrame(int nCmdShow) BOOL CHexMergeFrame::DestroyWindow() { SavePosition(); - // If we are active, save the restored/maximized state - // If we are not, do nothing and let the active frame do the job. - if (GetParentFrame()->GetActiveFrame() == this) - { - WINDOWPLACEMENT wp; - wp.length = sizeof(WINDOWPLACEMENT); - GetWindowPlacement(&wp); - GetOptionsMgr()->SaveOption(OPT_ACTIVE_FRAME_MAX, (wp.showCmd == SW_MAXIMIZE)); - } - + SaveWindowState(); return CMDIChildWnd::DestroyWindow(); } @@ -232,9 +213,6 @@ void CHexMergeFrame::SavePosition() { if (CWnd *pLeft = m_wndSplitter.GetPane(0,0)) { - CRect rc; - pLeft->GetWindowRect(&rc); - theApp.WriteProfileInt(_T("Settings"), _T("WLeft"), rc.Width()); GetOptionsMgr()->SaveOption(OPT_ACTIVE_PANE, GetActivePane()); } } @@ -255,17 +233,6 @@ void CHexMergeFrame::OnSize(UINT nType, int cx, int cy) UpdateHeaderSizes(); } -void CHexMergeFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI) -{ - CMDIChildWnd::OnGetMinMaxInfo(lpMMI); - // [Fix for MFC 8.0 MDI Maximizing Child Window bug on Vista] - // https://groups.google.com/forum/#!topic/microsoft.public.vc.mfc/iajCdW5DzTM -#if _MFC_VER >= 0x0800 - lpMMI->ptMaxTrackSize.x = max(lpMMI->ptMaxTrackSize.x, lpMMI->ptMaxSize.x); - lpMMI->ptMaxTrackSize.y = max(lpMMI->ptMaxTrackSize.y, lpMMI->ptMaxSize.y); -#endif -} - /// update splitting position for panels 1/2 and headerbar and statusbar void CHexMergeFrame::UpdateHeaderSizes() { @@ -308,33 +275,6 @@ IHeaderBar *CHexMergeFrame::GetHeaderInterface() return &m_wndFilePathBar; } -/** - * @brief Reflect comparison result in window's icon. - * @param nResult [in] Last comparison result which the application returns. - */ -void CHexMergeFrame::SetLastCompareResult(int nResult) -{ - HICON hCurrent = GetIcon(FALSE); - HICON hReplace = (nResult == 0) ? m_hIdentical : m_hDifferent; - - if (hCurrent != hReplace) - { - SetIcon(hReplace, TRUE); - - BOOL bMaximized; - GetMDIFrame()->MDIGetActive(&bMaximized); - - // When MDI maximized the window icon is drawn on the menu bar, so we - // need to notify it that our icon has changed. - if (bMaximized) - { - GetMDIFrame()->DrawMenuBar(); - } - GetMDIFrame()->OnUpdateFrameTitle(FALSE); - } - - theApp.SetLastCompareResult(nResult); -} void CHexMergeFrame::UpdateAutoPaneResize() { diff --git a/Src/HexMergeFrm.h b/Src/HexMergeFrm.h index d59460a93..7b02e760f 100644 --- a/Src/HexMergeFrm.h +++ b/Src/HexMergeFrm.h @@ -27,6 +27,7 @@ #include "SplitterWndEx.h" #include "EditorFilepathBar.h" +#include "MergeFrameCommon.h" #define HEKSEDIT_INTERFACE_VERSION 2 #include "heksedit.h" @@ -36,7 +37,7 @@ class CHexMergeDoc; /** * @brief Frame class for file compare, handles panes, statusbar etc. */ -class CHexMergeFrame : public CMDIChildWnd +class CHexMergeFrame : public CMergeFrameCommon { DECLARE_DYNCREATE(CHexMergeFrame) public: @@ -47,9 +48,7 @@ public: void UpdateResources(); void CloseNow(); IHeaderBar * GetHeaderInterface(); - void SetSharedMenu(HMENU hMenu) { m_hMenuShared = hMenu; }; CHexMergeDoc * GetMergeDoc() { return m_pMergeDoc; } - void SetLastCompareResult(int nResult); void UpdateAutoPaneResize(); void UpdateSplitter(); @@ -79,18 +78,14 @@ private: void CreateHexWndStatusBar(CStatusBar &, CWnd *); // Generated message map functions private: - int m_nLastSplitPos[2]; void UpdateHeaderSizes(); CHexMergeDoc * m_pMergeDoc; - HICON m_hIdentical; - HICON m_hDifferent; //{{AFX_MSG(CHexMergeFrame) afx_msg void OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd); afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg void OnIdleUpdateCmdUI(); afx_msg LRESULT OnStorePaneSizes(WPARAM wParam, LPARAM lParam); - afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; diff --git a/Src/ImgMergeFrm.cpp b/Src/ImgMergeFrm.cpp index c2c310ccf..770399af8 100644 --- a/Src/ImgMergeFrm.cpp +++ b/Src/ImgMergeFrm.cpp @@ -53,15 +53,14 @@ ///////////////////////////////////////////////////////////////////////////// // CImgMergeFrame -IMPLEMENT_DYNCREATE(CImgMergeFrame, CMDIChildWnd) +IMPLEMENT_DYNCREATE(CImgMergeFrame, CMergeFrameCommon) -BEGIN_MESSAGE_MAP(CImgMergeFrame, CMDIChildWnd) +BEGIN_MESSAGE_MAP(CImgMergeFrame, CMergeFrameCommon) //{{AFX_MSG_MAP(CImgMergeFrame) ON_WM_CREATE() ON_WM_CLOSE() ON_WM_MDIACTIVATE() ON_WM_SIZE() - ON_WM_GETMINMAXINFO() ON_COMMAND(ID_FILE_SAVE, OnFileSave) ON_UPDATE_COMMAND_UI(ID_VIEW_LOCATION_BAR, OnUpdateControlBarMenu) ON_COMMAND_EX(ID_VIEW_LOCATION_BAR, OnBarCheck) @@ -158,14 +157,12 @@ CMenu CImgMergeFrame::menu; // CImgMergeFrame construction/destruction CImgMergeFrame::CImgMergeFrame() -: m_hIdentical(nullptr) -, m_hDifferent(nullptr) +: CMergeFrameCommon(IDI_EQUALIMAGE, IDI_NOTEQUALIMAGE) , m_pDirDoc(nullptr) , m_bAutoMerged(false) , m_pImgMergeWindow(nullptr) , m_pImgToolWindow(nullptr) { - std::fill_n(m_nLastSplitPos, 2, 0); std::fill_n(m_nBufferType, 3, BUFFER_NORMAL); std::fill_n(m_bRO, 3, false); } @@ -516,9 +513,6 @@ int CImgMergeFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) CSize size = m_wndStatusBar[0].CalcFixedLayout(TRUE, TRUE); m_rectBorder.bottom = size.cy; - m_hIdentical = AfxGetApp()->LoadIcon(IDI_EQUALIMAGE); - m_hDifferent = AfxGetApp()->LoadIcon(IDI_NOTEQUALIMAGE); - return 0; } @@ -561,16 +555,7 @@ BOOL CImgMergeFrame::DestroyWindow() { SavePosition(); SaveOptions(); - // If we are active, save the restored/maximized state - // If we are not, do nothing and let the active frame do the job. - if (GetParentFrame()->GetActiveFrame() == this) - { - WINDOWPLACEMENT wp; - wp.length = sizeof(WINDOWPLACEMENT); - GetWindowPlacement(&wp); - GetOptionsMgr()->SaveOption(OPT_ACTIVE_FRAME_MAX, (wp.showCmd == SW_MAXIMIZE)); - } - + SaveWindowState(); return CMDIChildWnd::DestroyWindow(); } @@ -1032,34 +1017,6 @@ void CImgMergeFrame::SetTitle(LPCTSTR lpszTitle) SetWindowText(sTitle.c_str()); } -/** - * @brief Reflect comparison result in window's icon. - * @param nResult [in] Last comparison result which the application returns. - */ -void CImgMergeFrame::SetLastCompareResult(int nResult) -{ - HICON hCurrent = GetIcon(FALSE); - HICON hReplace = (nResult == 0) ? m_hIdentical : m_hDifferent; - - if (hCurrent != hReplace) - { - SetIcon(hReplace, TRUE); - - BOOL bMaximized; - GetMDIFrame()->MDIGetActive(&bMaximized); - - // When MDI maximized the window icon is drawn on the menu bar, so we - // need to notify it that our icon has changed. - if (bMaximized) - { - GetMDIFrame()->DrawMenuBar(); - } - GetMDIFrame()->OnUpdateFrameTitle(FALSE); - } - - theApp.SetLastCompareResult(nResult); -} - void CImgMergeFrame::UpdateLastCompareResult() { SetLastCompareResult(m_pImgMergeWindow->GetDiffCount() > 0 ? 1 : 0); @@ -1305,17 +1262,6 @@ void CImgMergeFrame::OnSize(UINT nType, int cx, int cy) UpdateHeaderSizes(); } -void CImgMergeFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI) -{ - CMDIChildWnd::OnGetMinMaxInfo(lpMMI); - // [Fix for MFC 8.0 MDI Maximizing Child Window bug on Vista] - // https://groups.google.com/forum/#!topic/microsoft.public.vc.mfc/iajCdW5DzTM -#if _MFC_VER >= 0x0800 - lpMMI->ptMaxTrackSize.x = max(lpMMI->ptMaxTrackSize.x, lpMMI->ptMaxSize.x); - lpMMI->ptMaxTrackSize.y = max(lpMMI->ptMaxTrackSize.y, lpMMI->ptMaxSize.y); -#endif -} - /** * @brief Synchronize control and status bar placements with splitter position, * update mod indicators, synchronize scrollbars diff --git a/Src/ImgMergeFrm.h b/Src/ImgMergeFrm.h index 71d028e86..98c2c3e3e 100644 --- a/Src/ImgMergeFrm.h +++ b/Src/ImgMergeFrm.h @@ -32,13 +32,14 @@ #include "WinIMergeLib.h" #include "LocationBar.h" #include "FileLocation.h" +#include "MergeFrameCommon.h" class CDirDoc; /** * @brief Frame class for file compare, handles panes, statusbar etc. */ -class CImgMergeFrame : public CMDIChildWnd, public IMergeDoc +class CImgMergeFrame : public IMergeDoc, public CMergeFrameCommon { private: enum BUFFERTYPE @@ -65,8 +66,6 @@ public: void UpdateResources(); bool CloseNow(); void DirDocClosing(CDirDoc * pDirDoc) { m_pDirDoc = nullptr; } - void SetSharedMenu(HMENU hMenu) { m_hMenuShared = hMenu; }; - void SetLastCompareResult(int nResult); void UpdateLastCompareResult(); void UpdateAutoPaneResize(); void UpdateSplitter(); @@ -116,9 +115,6 @@ private: bool MergeModeKeyDown(MSG* pMsg); static void OnChildPaneEvent(const IImgMergeWindow::Event& evt); void OnDropFiles(int pane, const std::vector& files); - int m_nLastSplitPos[2]; - HICON m_hIdentical; - HICON m_hDifferent; CLocationBar m_wndLocationBar; IImgMergeWindow *m_pImgMergeWindow; IImgToolWindow *m_pImgToolWindow; @@ -133,7 +129,6 @@ private: //{{AFX_MSG(CImgMergeFrame) afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd); - afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI); afx_msg void OnClose(); afx_msg void OnFileSave(); afx_msg void OnUpdateFileSave(CCmdUI* pCmdUI); diff --git a/Src/Merge.vs2017.vcxproj b/Src/Merge.vs2017.vcxproj index 7e96ec1a2..0d9d8b951 100644 --- a/Src/Merge.vs2017.vcxproj +++ b/Src/Merge.vs2017.vcxproj @@ -611,6 +611,7 @@ NotUsing + Use @@ -1194,6 +1195,7 @@ + diff --git a/Src/Merge.vs2017.vcxproj.filters b/Src/Merge.vs2017.vcxproj.filters index 7e3f7da53..9b1018421 100644 --- a/Src/Merge.vs2017.vcxproj.filters +++ b/Src/Merge.vs2017.vcxproj.filters @@ -865,6 +865,9 @@ Source Files + + MFCGui\Source Files + @@ -1557,6 +1560,9 @@ Header Files + + MFCGui\Header Files + diff --git a/Src/Merge.vs2019.vcxproj b/Src/Merge.vs2019.vcxproj index c7e81b559..2280a699b 100644 --- a/Src/Merge.vs2019.vcxproj +++ b/Src/Merge.vs2019.vcxproj @@ -610,6 +610,7 @@ NotUsing + Use @@ -1193,6 +1194,7 @@ + diff --git a/Src/Merge.vs2019.vcxproj.filters b/Src/Merge.vs2019.vcxproj.filters index 7e3f7da53..9b1018421 100644 --- a/Src/Merge.vs2019.vcxproj.filters +++ b/Src/Merge.vs2019.vcxproj.filters @@ -865,6 +865,9 @@ Source Files + + MFCGui\Source Files + @@ -1557,6 +1560,9 @@ Header Files + + MFCGui\Header Files + diff --git a/Src/MergeEditFrm.cpp b/Src/MergeEditFrm.cpp index 2280bd65a..7c6c6961a 100644 --- a/Src/MergeEditFrm.cpp +++ b/Src/MergeEditFrm.cpp @@ -45,15 +45,14 @@ ///////////////////////////////////////////////////////////////////////////// // CMergeEditFrame -IMPLEMENT_DYNCREATE(CMergeEditFrame, CMDIChildWnd) +IMPLEMENT_DYNCREATE(CMergeEditFrame, CMergeFrameCommon) -BEGIN_MESSAGE_MAP(CMergeEditFrame, CMDIChildWnd) +BEGIN_MESSAGE_MAP(CMergeEditFrame, CMergeFrameCommon) //{{AFX_MSG_MAP(CMergeEditFrame) ON_WM_CREATE() ON_WM_CLOSE() ON_WM_MDIACTIVATE() ON_WM_TIMER() - ON_WM_GETMINMAXINFO() ON_UPDATE_COMMAND_UI(ID_VIEW_DETAIL_BAR, OnUpdateControlBarMenu) ON_COMMAND_EX(ID_VIEW_DETAIL_BAR, OnBarCheck) ON_UPDATE_COMMAND_UI(ID_VIEW_LOCATION_BAR, OnUpdateControlBarMenu) @@ -75,11 +74,8 @@ END_MESSAGE_MAP() * @brief Constructor. */ CMergeEditFrame::CMergeEditFrame() -: m_hIdentical(nullptr) -, m_hDifferent(nullptr) +: CMergeFrameCommon(IDI_EQUALTEXTFILE, IDI_NOTEQUALTEXTFILE) { - m_bActivated = false; - std::fill_n(m_nLastSplitPos, 2, 0); m_pMergeDoc = 0; } @@ -218,9 +214,6 @@ int CMergeEditFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) return -1; // fail to create } - m_hIdentical = AfxGetApp()->LoadIcon(IDI_EQUALTEXTFILE); - m_hDifferent = AfxGetApp()->LoadIcon(IDI_NOTEQUALTEXTFILE); - return 0; } @@ -267,38 +260,13 @@ void CMergeEditFrame::ActivateFrame(int nCmdShow) m_wndLocationBar.LoadState(_T("Settings")); m_wndDetailBar.LoadState(_T("Settings")); - if (!m_bActivated) - { - m_bActivated = true; - - // get the active child frame, and a flag whether it is maximized - BOOL bMaximized = FALSE; - CMDIChildWnd * oldActiveFrame = GetMDIFrame()->MDIGetActive(&bMaximized); - if (oldActiveFrame == nullptr) - // for the first frame, get the restored/maximized state from the registry - bMaximized = GetOptionsMgr()->GetBool(OPT_ACTIVE_FRAME_MAX); - if (bMaximized) - nCmdShow = SW_SHOWMAXIMIZED; - else - nCmdShow = SW_SHOWNORMAL; - } - - CMDIChildWnd::ActivateFrame(nCmdShow); + CMergeFrameCommon::ActivateFrame(nCmdShow); } BOOL CMergeEditFrame::DestroyWindow() { SavePosition(); - // If we are active, save the restored/maximized state - // If we are not, do nothing and let the active frame do the job. - if (this->GetParentFrame()->GetActiveFrame() == (CFrameWnd*)this) - { - WINDOWPLACEMENT wp; - wp.length = sizeof(WINDOWPLACEMENT); - GetWindowPlacement(&wp); - GetOptionsMgr()->SaveOption(OPT_ACTIVE_FRAME_MAX, (wp.showCmd == SW_MAXIMIZE)); - } - + SaveWindowState(); return CMDIChildWnd::DestroyWindow(); } @@ -386,34 +354,6 @@ IHeaderBar * CMergeEditFrame::GetHeaderInterface() return &m_wndFilePathBar; } -/** -* @brief Reflect comparison result in window's icon. -* @param nResult [in] Last comparison result which the application returns. -*/ -void CMergeEditFrame::SetLastCompareResult(int nResult) -{ - HICON hCurrent = GetIcon(FALSE); - HICON hReplace = (nResult == 0) ? m_hIdentical : m_hDifferent; - - if (hCurrent != hReplace) - { - SetIcon(hReplace, TRUE); - - BOOL bMaximized; - GetMDIFrame()->MDIGetActive(&bMaximized); - - // When MDI maximized the window icon is drawn on the menu bar, so we - // need to notify it that our icon has changed. - if (bMaximized) - { - GetMDIFrame()->DrawMenuBar(); - } - GetMDIFrame()->OnUpdateFrameTitle(FALSE); - } - - theApp.SetLastCompareResult(nResult); -} - void CMergeEditFrame::UpdateAutoPaneResize() { auto& wndSplitter = GetMergeEditSplitterWnd(0); @@ -451,17 +391,6 @@ void CMergeEditFrame::OnTimer(UINT_PTR nIDEvent) CMDIChildWnd::OnTimer(nIDEvent); } -void CMergeEditFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI) -{ - CMDIChildWnd::OnGetMinMaxInfo(lpMMI); - // [Fix for MFC 8.0 MDI Maximizing Child Window bug on Vista] - // https://groups.google.com/forum/#!topic/microsoft.public.vc.mfc/iajCdW5DzTM -#if _MFC_VER >= 0x0800 - lpMMI->ptMaxTrackSize.x = max(lpMMI->ptMaxTrackSize.x, lpMMI->ptMaxSize.x); - lpMMI->ptMaxTrackSize.y = max(lpMMI->ptMaxTrackSize.y, lpMMI->ptMaxSize.y); -#endif -} - void CMergeEditFrame::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd) { CMDIChildWnd::OnMDIActivate(bActivate, pActivateWnd, pDeactivateWnd); diff --git a/Src/MergeEditFrm.h b/Src/MergeEditFrm.h index 314f6cc37..4b1d155a1 100644 --- a/Src/MergeEditFrm.h +++ b/Src/MergeEditFrm.h @@ -31,13 +31,14 @@ #include "EditorFilepathBar.h" #include "DiffViewBar.h" #include "LocationBar.h" +#include "MergeFrameCommon.h" class CMergeDoc; /** * @brief Frame class for file compare, handles panes, statusbar etc. */ -class CMergeEditFrame : public CMDIChildWnd +class CMergeEditFrame : public CMergeFrameCommon { DECLARE_DYNCREATE(CMergeEditFrame) public: @@ -48,14 +49,11 @@ public: void UpdateResources(); void CloseNow(); IHeaderBar * GetHeaderInterface(); - void SetSharedMenu(HMENU hMenu) { m_hMenuShared = hMenu; }; CMergeDoc * GetMergeDoc() { return m_pMergeDoc; } - void SetLastCompareResult(int nResult); void UpdateAutoPaneResize(); void UpdateSplitter(); CSplitterWndEx& GetSplitter() { return m_wndSplitter; }; - bool IsActivated() const { return m_bActivated; } // Attributes protected: @@ -87,12 +85,8 @@ private: // Generated message map functions private: - int m_nLastSplitPos[2]; void UpdateHeaderSizes(); - bool m_bActivated; CMergeDoc * m_pMergeDoc; - HICON m_hIdentical; - HICON m_hDifferent; //{{AFX_MSG(CMergeEditFrame) afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); @@ -104,7 +98,6 @@ private: afx_msg LRESULT OnStorePaneSizes(WPARAM wParam, LPARAM lParam); afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg void OnIdleUpdateCmdUI(); - afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; diff --git a/Src/MergeFrameCommon.cpp b/Src/MergeFrameCommon.cpp new file mode 100644 index 000000000..1aa3a4cfc --- /dev/null +++ b/Src/MergeFrameCommon.cpp @@ -0,0 +1,101 @@ +/** + * @file MergeFrameCommon.cpp + * + * @brief Implementation file for CMergeFrameCommon + * + */ +#include "StdAfx.h" +#include "MergeFrameCommon.h" +#include "OptionsDef.h" +#include "OptionsMgr.h" +#include "Merge.h" + +IMPLEMENT_DYNCREATE(CMergeFrameCommon, CMDIChildWnd) + +BEGIN_MESSAGE_MAP(CMergeFrameCommon, CMDIChildWnd) + //{{AFX_MSG_MAP(CMergeFrameCommon) + ON_WM_GETMINMAXINFO() + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +CMergeFrameCommon::CMergeFrameCommon(int nIdenticalIcon, int nDifferentIcon) + : m_hIdentical(nIdenticalIcon < 0 ? nullptr : AfxGetApp()->LoadIcon(nIdenticalIcon)) + , m_hDifferent(nDifferentIcon < 0 ? nullptr : AfxGetApp()->LoadIcon(nDifferentIcon)) + , m_bActivated(false) + , m_nLastSplitPos{0} +{ +} + +void CMergeFrameCommon::ActivateFrame(int nCmdShow) +{ + if (!m_bActivated) + { + m_bActivated = true; + + // get the active child frame, and a flag whether it is maximized + BOOL bMaximized = FALSE; + CMDIChildWnd * oldActiveFrame = GetMDIFrame()->MDIGetActive(&bMaximized); + if (oldActiveFrame == nullptr) + // for the first frame, get the restored/maximized state from the registry + bMaximized = GetOptionsMgr()->GetBool(OPT_ACTIVE_FRAME_MAX); + if (bMaximized) + nCmdShow = SW_SHOWMAXIMIZED; + else + nCmdShow = SW_SHOWNORMAL; + } + + CMDIChildWnd::ActivateFrame(nCmdShow); +} + +void CMergeFrameCommon::SaveWindowState() +{ + // If we are active, save the restored/maximized state + // If we are not, do nothing and let the active frame do the job. + if (GetParentFrame()->GetActiveFrame() == this) + { + WINDOWPLACEMENT wp; + wp.length = sizeof(WINDOWPLACEMENT); + GetWindowPlacement(&wp); + GetOptionsMgr()->SaveOption(OPT_ACTIVE_FRAME_MAX, (wp.showCmd == SW_MAXIMIZE)); + } +} + +/** + * @brief Reflect comparison result in window's icon. + * @param nResult [in] Last comparison result which the application returns. + */ +void CMergeFrameCommon::SetLastCompareResult(int nResult) +{ + HICON hCurrent = GetIcon(FALSE); + HICON hReplace = (nResult == 0) ? m_hIdentical : m_hDifferent; + + if (hCurrent != hReplace) + { + SetIcon(hReplace, TRUE); + + BOOL bMaximized; + GetMDIFrame()->MDIGetActive(&bMaximized); + + // When MDI maximized the window icon is drawn on the menu bar, so we + // need to notify it that our icon has changed. + if (bMaximized) + { + GetMDIFrame()->DrawMenuBar(); + } + GetMDIFrame()->OnUpdateFrameTitle(FALSE); + } + + theApp.SetLastCompareResult(nResult); +} + +void CMergeFrameCommon::OnGetMinMaxInfo(MINMAXINFO* lpMMI) +{ + CMDIChildWnd::OnGetMinMaxInfo(lpMMI); + // [Fix for MFC 8.0 MDI Maximizing Child Window bug on Vista] + // https://groups.google.com/forum/#!topic/microsoft.public.vc.mfc/iajCdW5DzTM +#if _MFC_VER >= 0x0800 + lpMMI->ptMaxTrackSize.x = max(lpMMI->ptMaxTrackSize.x, lpMMI->ptMaxSize.x); + lpMMI->ptMaxTrackSize.y = max(lpMMI->ptMaxTrackSize.y, lpMMI->ptMaxSize.y); +#endif +} + diff --git a/Src/MergeFrameCommon.h b/Src/MergeFrameCommon.h new file mode 100644 index 000000000..b29562f2e --- /dev/null +++ b/Src/MergeFrameCommon.h @@ -0,0 +1,30 @@ +/** + * @file MergeFrameCommon.h + * + * @brief interface of the CMergeFrameCommon class + * + */ +#pragma once + +class CMergeFrameCommon: public CMDIChildWnd +{ + DECLARE_DYNCREATE(CMergeFrameCommon) +public: + CMergeFrameCommon::CMergeFrameCommon(int nIdenticalIcon = -1, int nDifferentIcon = -1); + bool IsActivated() const { return m_bActivated; } + void ActivateFrame(int nCmdShow); + void SetLastCompareResult(int nResult); + void SaveWindowState(); + void SetSharedMenu(HMENU hMenu) { m_hMenuShared = hMenu; }; +protected: + int m_nLastSplitPos[2]; +private: + bool m_bActivated; + HICON m_hIdentical; + HICON m_hDifferent; + + //{{AFX_MSG(CMergeFrameCommon) + afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; diff --git a/Src/OpenFrm.cpp b/Src/OpenFrm.cpp index 5dab89460..7ef34cb6c 100644 --- a/Src/OpenFrm.cpp +++ b/Src/OpenFrm.cpp @@ -4,6 +4,7 @@ #include "OpenFrm.h" #include "OptionsDef.h" #include "OptionsMgr.h" +#include "MergeFrameCommon.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -12,14 +13,13 @@ // COpenFrame -IMPLEMENT_DYNCREATE(COpenFrame, CMDIChildWnd) +IMPLEMENT_DYNCREATE(COpenFrame, CMergeFrameCommon) -BEGIN_MESSAGE_MAP(COpenFrame, CMDIChildWnd) +BEGIN_MESSAGE_MAP(COpenFrame, CMergeFrameCommon) //{{AFX_MSG_MAP(COpenFrame) ON_WM_ERASEBKGND() ON_WM_NCHITTEST() ON_WM_WINDOWPOSCHANGING() - ON_WM_GETMINMAXINFO() //}}AFX_MSG_MAP END_MESSAGE_MAP() @@ -87,24 +87,9 @@ void COpenFrame::OnWindowPosChanging(WINDOWPOS* lpwndpos) } } -void COpenFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI) -{ - CMDIChildWnd::OnGetMinMaxInfo(lpMMI); - // [Fix for MFC 8.0 MDI Maximizing Child Window bug on Vista] - // https://groups.google.com/forum/#!topic/microsoft.public.vc.mfc/iajCdW5DzTM -#if _MFC_VER >= 0x0800 - lpMMI->ptMaxTrackSize.x = max(lpMMI->ptMaxTrackSize.x, lpMMI->ptMaxSize.x); - lpMMI->ptMaxTrackSize.y = max(lpMMI->ptMaxTrackSize.y, lpMMI->ptMaxSize.y); -#endif -} - void COpenFrame::ActivateFrame(int nCmdShow) { - if (!GetMDIFrame()->MDIGetActive() && GetOptionsMgr()->GetBool(OPT_ACTIVE_FRAME_MAX)) - { - nCmdShow = SW_SHOWMAXIMIZED; - } - CMDIChildWnd::ActivateFrame(nCmdShow); + CMergeFrameCommon::ActivateFrame(nCmdShow); if (CView *const pView = GetActiveView()) { WINDOWPLACEMENT wp; @@ -132,16 +117,7 @@ void COpenFrame::UpdateResources() */ BOOL COpenFrame::DestroyWindow() { - // If we are active, save the restored/maximized state - // If we are not, do nothing and let the active frame do the job. - if (GetParentFrame()->GetActiveFrame() == this) - { - WINDOWPLACEMENT wp; - wp.length = sizeof(WINDOWPLACEMENT); - GetWindowPlacement(&wp); - GetOptionsMgr()->SaveOption(OPT_ACTIVE_FRAME_MAX, (wp.showCmd == SW_MAXIMIZE)); - } - + SaveWindowState(); return CMDIChildWnd::DestroyWindow(); } diff --git a/Src/OpenFrm.h b/Src/OpenFrm.h index 909df8fe6..dd2027cc4 100644 --- a/Src/OpenFrm.h +++ b/Src/OpenFrm.h @@ -1,11 +1,10 @@ // OpenFrm.h : interface of the COpenFrame class // - - #pragma once +#include "MergeFrameCommon.h" -class COpenFrame : public CMDIChildWnd +class COpenFrame : public CMergeFrameCommon { DECLARE_DYNCREATE(COpenFrame) public: @@ -17,7 +16,6 @@ public: // Operations public: void UpdateResources(); - void SetSharedMenu(HMENU hMenu) { m_hMenuShared = hMenu; }; // Overrides // ClassWizard generated virtual function overrides @@ -39,7 +37,6 @@ protected: afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg LRESULT OnNcHitTest(CPoint point); afx_msg void OnWindowPosChanging(WINDOWPOS* lpwndpos); - afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; -- 2.11.0