1 /////////////////////////////////////////////////////////////////////////////
2 // WinMerge: an interactive diff/merge utility
3 // Copyright (C) 1997 Dean P. Grimm
4 // SPDX-License-Identifier: GPL-2.0-or-later
5 /////////////////////////////////////////////////////////////////////////////
9 * @brief Declaration file for CMainFrame
17 #include "MDITabBar.h"
18 #include "PathContext.h"
19 #include "OptionsDef.h"
20 #include "OptionsMgr.h"
21 #include "FileOpenFlags.h"
31 class LineFiltersList;
37 class CWebPageDiffFrame;
40 typedef std::shared_ptr<TempFile> TempFilePtr;
42 // typed lists (homogenous pointer lists)
43 typedef CTypedPtrList<CPtrList, COpenDoc *> OpenDocList;
44 typedef CTypedPtrList<CPtrList, CMergeDoc *> MergeDocList;
45 typedef CTypedPtrList<CPtrList, CDirDoc *> DirDocList;
46 typedef CTypedPtrList<CPtrList, CHexMergeDoc *> HexMergeDocList;
50 class CLanguageSelect;
53 CMainFrame * GetMainFrame(); // access to the singleton main frame object
56 * @brief Frame class containing save-routines etc
58 class CMainFrame : public CMDIFrameWnd
60 friend CLanguageSelect;
61 DECLARE_DYNAMIC(CMainFrame)
64 * @brief Frame/View/Document types.
68 FRAME_FOLDER, /**< Folder compare frame. */
69 FRAME_FILE, /**< File compare frame. */
70 FRAME_HEXFILE, /**< Hex file compare frame. */
71 FRAME_IMGFILE, /**< Image file compare frame. */
72 FRAME_WEBPAGE, /**< Web page compare frame. */
73 FRAME_OTHER, /**< No frame? */
78 virtual ~OpenFileParams() {}
81 struct OpenTextFileParams : public OpenFileParams
83 virtual ~OpenTextFileParams() {}
89 struct OpenTableFileParams : public OpenTextFileParams
91 virtual ~OpenTableFileParams() {}
92 std::optional<tchar_t> m_tableDelimiter;
93 std::optional<tchar_t> m_tableQuote;
94 std::optional<bool> m_tableAllowNewlinesInQuotes;
97 struct OpenBinaryFileParams : public OpenFileParams
99 virtual ~OpenBinaryFileParams() {}
103 struct OpenImageFileParams : public OpenFileParams
105 virtual ~OpenImageFileParams() {}
110 struct OpenWebPageParams : public OpenFileParams
112 virtual ~OpenWebPageParams() {}
115 struct OpenAutoFileParams : public OpenTableFileParams, public OpenBinaryFileParams, public OpenImageFileParams
117 virtual ~OpenAutoFileParams() {}
120 struct OpenFolderParams : public OpenFileParams
122 virtual ~OpenFolderParams() {}
123 std::vector<String> m_hiddenItems;
130 bool m_bShowErrors; /**< Show folder compare error items? */
131 LOGFONT m_lfDiff; /**< MergeView user-selected font */
132 LOGFONT m_lfDir; /**< DirView user-selected font */
133 static const tchar_t szClassName[];
137 HMENU NewDirViewMenu();
138 HMENU NewMergeViewMenu();
139 HMENU NewHexMergeViewMenu();
140 HMENU NewImgMergeViewMenu();
141 HMENU NewWebPageDiffViewMenu();
142 HMENU NewOpenViewMenu();
143 HMENU NewDefaultMenu(int ID = 0);
144 HMENU GetPrediffersSubmenu(HMENU mainMenu);
145 void UpdatePrediffersMenu();
147 bool DoFileOrFolderOpen(const PathContext *pFiles = nullptr,
148 const fileopenflags_t dwFlags[] = nullptr, const String strDesc[] = nullptr,
149 const String& sReportFile = _T(""), std::optional<bool> bRecurse = false, CDirDoc *pDirDoc = nullptr,
150 const PackingInfo * infoUnpacker = nullptr, const PrediffingInfo * infoPrediffer = nullptr,
151 UINT nID = 0, const OpenFileParams *pOpenParams = nullptr);
152 bool DoFileOpen(UINT nID, const PathContext* pFiles,
153 const fileopenflags_t dwFlags[] = nullptr, const String strDesc[] = nullptr,
154 const String& sReportFile = _T(""),
155 const PackingInfo* infoUnpacker = nullptr, const PrediffingInfo * infoPrediffer = nullptr,
156 const OpenFileParams *pOpenParams = nullptr);
157 bool DoFileNew(UINT nID, int nPanes,
158 const fileopenflags_t dwFlags[] = nullptr, const String strDesc[] = nullptr,
159 const PrediffingInfo * infoPrediffer = nullptr,
160 const OpenFileParams *pOpenParams = nullptr);
161 bool DoOpenConflict(const String& conflictFile, const String strDesc[] = nullptr, bool checked = false);
162 bool DoOpenClipboard(UINT nID = 0, int nBuffers = 2, const fileopenflags_t dwFlags[] = nullptr, const String strDesc[] = nullptr,
163 const PackingInfo* infoUnpacker = nullptr, const PrediffingInfo * infoPrediffer = nullptr,
164 const OpenFileParams* pOpenParams = nullptr);
165 bool DoSelfCompare(UINT nID, const String& file, const String strDesc[] = nullptr,
166 const PackingInfo* infoUnpacker = nullptr, const PrediffingInfo * infoPrediffer = nullptr,
167 const OpenFileParams* pOpenParams = nullptr);
168 bool ShowAutoMergeDoc(UINT nID, CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
169 const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
170 const PackingInfo * infoUnpacker = nullptr, const OpenFileParams *pOpenParams = nullptr);
171 bool ShowMergeDoc(UINT nID, CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
172 const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
173 const PackingInfo * infoUnpacker = nullptr, const OpenFileParams *pOpenParams = nullptr);
174 bool ShowTextOrTableMergeDoc(std::optional<bool> table, CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
175 const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
176 const PackingInfo * infoUnpacker = nullptr, const OpenTextFileParams *pOpenParams = nullptr);
177 bool ShowTextMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
178 const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
179 const PackingInfo * infoUnpacker = nullptr, const OpenTextFileParams *pOpenParams = nullptr);
180 bool ShowTextMergeDoc(CDirDoc* pDirDoc, int nBuffers, const String text[],
181 const String strDesc[], const String& strFileExt, const OpenTextFileParams *pOpenParams = nullptr);
182 bool ShowTableMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
183 const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
184 const PackingInfo * infoUnpacker = nullptr, const OpenTextFileParams *pOpenParams = nullptr);
185 bool ShowHexMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
186 const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
187 const PackingInfo * infoUnpacker = nullptr, const OpenBinaryFileParams *pOpenParams = nullptr);
188 bool ShowImgMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
189 const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
190 const PackingInfo * infoUnpacker = nullptr, const OpenImageFileParams *pOpenParams = nullptr);
191 bool ShowWebDiffDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
192 const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
193 const PackingInfo * infoUnpacker = nullptr, const OpenWebPageParams *pOpenParams = nullptr);
195 void UpdateResources();
196 void ApplyDiffOptions();
198 void StartFlashing();
199 bool AskCloseConfirmation();
200 static FRAMETYPE GetFrameType(const CFrameWnd * pFrame);
201 static void UpdateDocTitle();
202 static void ReloadMenu();
203 static void AppendPluginMenus(CMenu* pMenu, const String& filteredFilenames,
204 const std::vector<std::wstring>& events, bool addAllMenu, unsigned baseId);
205 static String GetPluginPipelineByMenuId(unsigned idSearch, const std::vector<std::wstring>& events, unsigned baseId);
206 DropHandler *GetDropHandler() const { return m_pDropHandler; }
207 const CTypedPtrArray<CPtrArray, CMDIChildWnd*>* GetChildArray() const { return &m_arrChild; }
208 IMergeDoc* GetActiveIMergeDoc();
209 DirWatcher* GetDirWatcher() { return m_pDirWatcher.get(); }
210 void WatchDocuments(IMergeDoc* pMergeDoc);
211 void UnwatchDocuments(IMergeDoc* pMergeDoc);
212 CToolBar* GetToolbar() { return &m_wndToolBar; }
215 virtual void GetMessageString(UINT nID, CString& rMessage) const;
216 // ClassWizard generated virtual function overrides
217 //{{AFX_VIRTUAL(CMainFrame)
219 virtual void ActivateFrame(int nCmdShow = -1);
220 virtual BOOL PreTranslateMessage(MSG* pMsg);
221 virtual void OnUpdateFrameTitle(BOOL bAddToTitle);
222 virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
225 // Implementation methods
227 virtual ~CMainFrame();
229 // Public implementation data
231 bool m_bFirstTime; /**< If first time frame activated, get pos from reg */
233 // Implementation data
235 // control bar embedded members
236 CStatusBar m_wndStatusBar;
238 CToolBar m_wndToolBar;
239 CMDITabBar m_wndTabBar;
240 CTypedPtrArray<CPtrArray, CMDIChildWnd*> m_arrChild;
242 // Tweak MDI client window behavior
243 class CMDIClient : public CWnd
245 static UINT_PTR const m_nRedrawTimer = 1612;
246 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
253 // To reduce flicker in maximized state, disable drawing while messing with MDI child frames
255 HWND hwndActive = reinterpret_cast<HWND>(SendMessage(WM_MDIGETACTIVE, 0, reinterpret_cast<LPARAM>(&bMaximized)));
256 if ((bMaximized || (message == WM_MDICREATE && !hwndActive)) &&
257 SetTimer(m_nRedrawTimer, USER_TIMER_MINIMUM, nullptr))
264 if (wParam == m_nRedrawTimer)
266 KillTimer(m_nRedrawTimer);
268 RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE);
272 return CWnd::WindowProc(message, wParam, lParam);
283 MENU_WEBPAGEDIFFVIEW,
285 MENU_COUNT, // Add new items before this item
288 * Menu frames - for which frame(s) the menu is.
292 MENU_MAINFRM = 0x000001,
293 MENU_FILECMP = 0x000002,
294 MENU_FOLDERCMP = 0x000004,
295 MENU_ALL = MENU_MAINFRM | MENU_FILECMP | MENU_FOLDERCMP
299 AUTO_RELOAD_MODIFIED_FILES_DISABLED,
300 AUTO_RELOAD_MODIFIED_FILES_ONWINDOWACTIVATED,
301 AUTO_RELOAD_MODIFIED_FILES_IMMEDIATELY
305 * A structure attaching a menu item, icon and menu types to apply to.
309 int menuitemID; /**< Menu item's ID. */
310 int iconResID; /**< Icon's resource ID. */
311 int menusToApply; /**< For which menus to apply. */
314 static const MENUITEM_ICON m_MenuIcons[];
316 std::unique_ptr<BCMenu> m_pMenus[MENU_COUNT]; /**< Menus for different views */
317 std::unique_ptr<BCMenu> m_pImageMenu;
318 std::unique_ptr<BCMenu> m_pWebPageMenu;
319 std::vector<TempFilePtr> m_tempFiles; /**< List of possibly needed temp files. */
320 DropHandler *m_pDropHandler;
321 std::unique_ptr<DirWatcher> m_pDirWatcher;
323 // Generated message map functions
325 //{{AFX_MSG(CMainFrame)
326 afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);
327 afx_msg LRESULT OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu) ;
328 afx_msg void OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu);
329 afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
330 afx_msg void OnFileOpen();
331 afx_msg void OnHelpGnulicense();
332 afx_msg void OnOptions();
333 afx_msg void OnViewSelectfont();
334 afx_msg void OnViewUsedefaultfont();
335 afx_msg void OnHelpContents();
336 afx_msg void OnClose();
337 afx_msg void OnToolsGeneratePatch();
338 afx_msg void OnDropFiles(const std::vector<String>& files);
339 afx_msg void OnUpdatePluginUnpackMode(CCmdUI* pCmdUI);
340 afx_msg void OnPluginUnpackMode(UINT nID);
341 afx_msg void OnUpdatePluginPrediffMode(CCmdUI* pCmdUI);
342 afx_msg void OnPluginPrediffMode(UINT nID);
343 afx_msg void OnUpdatePluginRelatedMenu(CCmdUI* pCmdUI);
344 afx_msg void OnReloadPlugins();
345 afx_msg void OnSaveConfigData();
346 template <int nFiles, unsigned nID>
347 afx_msg void OnFileNew() { DoFileNew(nID, nFiles); }
348 afx_msg void OnToolsFilters();
349 afx_msg void OnViewStatusBar();
350 afx_msg void OnUpdateViewTabBar(CCmdUI* pCmdUI);
351 afx_msg void OnViewTabBar();
352 afx_msg void OnUpdateResizePanes(CCmdUI* pCmdUI);
353 afx_msg void OnResizePanes();
354 afx_msg void OnFileOpenProject();
355 afx_msg LRESULT OnCopyData(WPARAM wParam, LPARAM lParam);
356 afx_msg LRESULT OnUser1(WPARAM wParam, LPARAM lParam);
357 afx_msg void OnWindowCloseAll();
358 afx_msg void OnUpdateWindowCloseAll(CCmdUI* pCmdUI);
359 afx_msg void OnSaveProject();
360 #if _MFC_VER > 0x0600
361 afx_msg void OnActivateApp(BOOL bActive, DWORD dwThreadID);
363 afx_msg void OnActivateApp(BOOL bActive, HTASK hTask);
365 afx_msg void OnToolbarSize(UINT id);
366 afx_msg void OnUpdateToolbarSize(CCmdUI* pCmdUI);
367 afx_msg BOOL OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult);
368 afx_msg void OnHelpReleasenotes();
369 afx_msg void OnHelpTranslations();
370 afx_msg void OnHelpCheckForUpdates();
371 afx_msg void OnUpdateHelpCheckForUpdates(CCmdUI* pCmdUI);
372 afx_msg void OnFileOpenConflict();
373 afx_msg void OnFileOpenClipboard();
374 afx_msg void OnPluginsList();
375 afx_msg void OnUpdatePluginName(CCmdUI* pCmdUI);
376 afx_msg void OnUpdateStatusNum(CCmdUI* pCmdUI);
377 afx_msg void OnToolbarButtonDropDown(NMHDR* pNMHDR, LRESULT* pResult);
378 afx_msg void OnDiffWhitespace(UINT nID);
379 afx_msg void OnUpdateDiffWhitespace(CCmdUI* pCmdUI);
380 afx_msg void OnDiffIgnoreBlankLines();
381 afx_msg void OnUpdateDiffIgnoreBlankLines(CCmdUI* pCmdUI);
382 afx_msg void OnDiffIgnoreCase();
383 afx_msg void OnUpdateDiffIgnoreCase(CCmdUI* pCmdUI);
384 afx_msg void OnDiffIgnoreNumbers();
385 afx_msg void OnUpdateDiffIgnoreNumbers(CCmdUI* pCmdUI);
386 afx_msg void OnDiffIgnoreEOL();
387 afx_msg void OnUpdateDiffIgnoreEOL(CCmdUI* pCmdUI);
388 afx_msg void OnDiffIgnoreCP();
389 afx_msg void OnUpdateDiffIgnoreCP(CCmdUI* pCmdUI);
390 afx_msg void OnDiffIgnoreComments();
391 afx_msg void OnUpdateDiffIgnoreComments(CCmdUI* pCmdUI);
392 afx_msg void OnIncludeSubfolders();
393 afx_msg void OnUpdateIncludeSubfolders(CCmdUI* pCmdUI);
394 afx_msg void OnCompareMethod(UINT nID);
395 afx_msg void OnUpdateCompareMethod(CCmdUI* pCmdUI);
396 afx_msg void OnMRUs(UINT nID);
397 afx_msg void OnUpdateNoMRUs(CCmdUI* pCmdUI);
398 afx_msg void OnFirstFile();
399 afx_msg void OnUpdateFirstFile(CCmdUI* pCmdUI);
400 afx_msg void OnPrevFile();
401 afx_msg void OnUpdatePrevFile(CCmdUI* pCmdUI);
402 afx_msg void OnNextFile();
403 afx_msg void OnUpdateNextFile(CCmdUI* pCmdUI);
404 afx_msg void OnLastFile();
405 afx_msg void OnUpdateLastFile(CCmdUI* pCmdUI);
406 afx_msg void OnTimer(UINT_PTR nIDEvent);
407 afx_msg void OnDestroy();
408 afx_msg void OnAccelQuit();
409 afx_msg LRESULT OnChildFrameAdded(WPARAM wParam, LPARAM lParam);
410 afx_msg LRESULT OnChildFrameRemoved(WPARAM wParam, LPARAM lParam);
411 afx_msg LRESULT OnChildFrameActivate(WPARAM wParam, LPARAM lParam);
412 afx_msg LRESULT OnChildFrameActivated(WPARAM wParam, LPARAM lParam);
414 DECLARE_MESSAGE_MAP()
417 void addToMru(const tchar_t* szItem, const tchar_t* szRegSubKey, UINT nMaxItems = 20);
418 OpenDocList &GetAllOpenDocs();
419 MergeDocList &GetAllMergeDocs();
420 DirDocList &GetAllDirDocs();
421 HexMergeDocList &GetAllHexMergeDocs();
422 std::vector<CImgMergeFrame *> GetAllImgMergeFrames();
423 std::vector<CWebPageDiffFrame *> GetAllWebPageDiffFrames();
424 void UpdateFont(FRAMETYPE frame);
425 BOOL CreateToolbar();
426 CMergeEditView * GetActiveMergeEditView();
427 void LoadToolbarImages();
428 HMENU NewMenu( int view, int ID );