2 * @file MergeFrameCommon.cpp
\r
4 * @brief Implementation file for CMergeFrameCommon
\r
8 #include "MergeFrameCommon.h"
\r
9 #include "OptionsDef.h"
\r
10 #include "OptionsMgr.h"
\r
13 #include <../src/mfc/afximpl.h>
\r
15 IMPLEMENT_DYNCREATE(CMergeFrameCommon, CMDIChildWnd)
\r
17 BEGIN_MESSAGE_MAP(CMergeFrameCommon, CMDIChildWnd)
\r
18 //{{AFX_MSG_MAP(CMergeFrameCommon)
\r
19 ON_WM_GETMINMAXINFO()
\r
25 CMergeFrameCommon::CMergeFrameCommon(int nIdenticalIcon, int nDifferentIcon)
\r
26 : m_hIdentical(nIdenticalIcon < 0 ? nullptr : AfxGetApp()->LoadIcon(nIdenticalIcon))
\r
27 , m_hDifferent(nDifferentIcon < 0 ? nullptr : AfxGetApp()->LoadIcon(nDifferentIcon))
\r
28 , m_hCurrent((HICON)-1)
\r
29 , m_bActivated(false)
\r
30 , m_nLastSplitPos{0}
\r
32 ::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), WMU_CHILDFRAMEADDED, 0, reinterpret_cast<LPARAM>(this));
\r
35 CMergeFrameCommon::~CMergeFrameCommon()
\r
37 ::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), WMU_CHILDFRAMEREMOVED, 0, reinterpret_cast<LPARAM>(this));
\r
40 void CMergeFrameCommon::ActivateFrame(int nCmdShow)
\r
44 m_bActivated = true;
\r
46 // get the active child frame, and a flag whether it is maximized
\r
47 BOOL bMaximized = FALSE;
\r
48 CMDIChildWnd * oldActiveFrame = GetMDIFrame()->MDIGetActive(&bMaximized);
\r
49 if (oldActiveFrame == nullptr)
\r
50 // for the first frame, get the restored/maximized state from the registry
\r
51 bMaximized = GetOptionsMgr()->GetBool(OPT_ACTIVE_FRAME_MAX);
\r
53 nCmdShow = SW_SHOWMAXIMIZED;
\r
55 nCmdShow = SW_SHOWNORMAL;
\r
58 CMDIChildWnd::ActivateFrame(nCmdShow);
\r
61 void CMergeFrameCommon::SaveWindowState()
\r
63 // If we are active, save the restored/maximized state
\r
64 // If we are not, do nothing and let the active frame do the job.
\r
65 if (GetParentFrame()->GetActiveFrame() == this)
\r
67 WINDOWPLACEMENT wp = {};
\r
68 wp.length = sizeof(WINDOWPLACEMENT);
\r
69 GetWindowPlacement(&wp);
\r
70 GetOptionsMgr()->SaveOption(OPT_ACTIVE_FRAME_MAX, (wp.showCmd == SW_MAXIMIZE));
\r
74 void CMergeFrameCommon::RemoveBarBorder()
\r
76 afxData.cxBorder2 = 0;
\r
77 afxData.cyBorder2 = 0;
\r
78 for (int i = 0; i < 4; ++i)
\r
80 CControlBar* pBar = GetControlBar(i + AFX_IDW_DOCKBAR_TOP);
\r
81 pBar->SetBarStyle(pBar->GetBarStyle() & ~(CBRS_BORDER_ANY | CBRS_BORDER_3D));
\r
86 * @brief Reflect comparison result in window's icon.
\r
87 * @param nResult [in] Last comparison result which the application returns.
\r
89 void CMergeFrameCommon::SetLastCompareResult(int nResult)
\r
91 HICON hReplace = (nResult == 0) ? m_hIdentical : m_hDifferent;
\r
93 if (m_hCurrent != hReplace)
\r
95 SetIcon(hReplace, TRUE);
\r
97 AfxGetMainWnd()->SetTimer(IDT_UPDATEMAINMENU, 500, nullptr);
\r
99 m_hCurrent = hReplace;
\r
102 theApp.SetLastCompareResult(nResult);
\r
105 void CMergeFrameCommon::ShowIdenticalMessage(const PathContext& paths, bool bIdenticalAll, std::function<int(LPCTSTR, unsigned, unsigned)> fnMessageBox)
\r
108 if (theApp.m_bExitIfNoDiff != MergeCmdLineInfo::ExitQuiet)
\r
110 UINT nFlags = MB_ICONINFORMATION | MB_DONT_DISPLAY_AGAIN;
\r
112 if (theApp.m_bExitIfNoDiff == MergeCmdLineInfo::Exit)
\r
114 // Show the "files are identical" for basic "exit no diff" flag
\r
115 // If user don't want to see the message one uses the quiet version
\r
116 // of the "exit no diff".
\r
117 nFlags &= ~MB_DONT_DISPLAY_AGAIN;
\r
119 if ((paths.GetSize() == 2 && !paths.GetLeft().empty() && !paths.GetRight().empty() &&
\r
120 strutils::compare_nocase(paths.GetLeft(), paths.GetRight()) == 0) ||
\r
121 (paths.GetSize() == 3 && !paths.GetLeft().empty() && !paths.GetMiddle().empty() && !paths.GetRight().empty() &&
\r
122 (strutils::compare_nocase(paths.GetLeft(), paths.GetRight()) == 0 ||
\r
123 strutils::compare_nocase(paths.GetMiddle(), paths.GetRight()) == 0 ||
\r
124 strutils::compare_nocase(paths.GetLeft(), paths.GetMiddle()) == 0)))
\r
126 // compare file to itself, a custom message so user may hide the message in this case only
\r
127 s = _("The same file is opened in both panels.");
\r
128 fnMessageBox(s.c_str(), nFlags, IDS_FILE_TO_ITSELF);
\r
130 else if (bIdenticalAll)
\r
132 s = _("The selected files are identical.");
\r
133 fnMessageBox(s.c_str(), nFlags, IDS_FILESSAME);
\r
139 // Exit application if files are identical.
\r
140 if (theApp.m_bExitIfNoDiff == MergeCmdLineInfo::Exit ||
\r
141 theApp.m_bExitIfNoDiff == MergeCmdLineInfo::ExitQuiet)
\r
143 AfxGetMainWnd()->PostMessage(WM_COMMAND, ID_APP_EXIT);
\r
148 String CMergeFrameCommon::GetTitleString(const PathContext& paths, const String desc[])
\r
150 const int nBuffers = paths.GetSize();
\r
151 String sFileName[3];
\r
153 for (int nBuffer = 0; nBuffer < paths.GetSize(); nBuffer++)
\r
154 sFileName[nBuffer] = !desc[nBuffer].empty() ? desc[nBuffer] : paths::FindFileName(paths[nBuffer]);
\r
155 if (std::count(&sFileName[0], &sFileName[0] + nBuffers, sFileName[0]) == nBuffers)
\r
156 sTitle = sFileName[0] + strutils::format(_T(" x %d"), nBuffers);
\r
158 sTitle = strutils::join(&sFileName[0], &sFileName[0] + nBuffers, _T(" - "));
\r
162 void CMergeFrameCommon::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
\r
164 CMDIChildWnd::OnGetMinMaxInfo(lpMMI);
\r
165 // [Fix for MFC 8.0 MDI Maximizing Child Window bug on Vista]
\r
166 // https://groups.google.com/forum/#!topic/microsoft.public.vc.mfc/iajCdW5DzTM
\r
167 #if _MFC_VER >= 0x0800
\r
168 lpMMI->ptMaxTrackSize.x = max(lpMMI->ptMaxTrackSize.x, lpMMI->ptMaxSize.x);
\r
169 lpMMI->ptMaxTrackSize.y = max(lpMMI->ptMaxTrackSize.y, lpMMI->ptMaxSize.y);
\r
173 void CMergeFrameCommon::OnDestroy()
\r
175 // https://stackoverflow.com/questions/35553955/getting-rid-of-3d-look-of-mdi-frame-window
\r
176 CFrameWnd::OnDestroy();
\r
179 void CMergeFrameCommon::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd)
\r
181 // call the base class to let standard processing switch to
\r
182 // the top-level menu associated with this window
\r
183 CMDIChildWnd::OnMDIActivate(bActivate, pActivateWnd, pDeactivateWnd);
\r
186 ::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), WMU_CHILDFRAMEACTIVATED, 0, reinterpret_cast<LPARAM>(this));
\r