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"
30 class LineFiltersList;
37 typedef std::shared_ptr<TempFile> TempFilePtr;
39 // typed lists (homogenous pointer lists)
40 typedef CTypedPtrList<CPtrList, COpenDoc *> OpenDocList;
41 typedef CTypedPtrList<CPtrList, CMergeDoc *> MergeDocList;
42 typedef CTypedPtrList<CPtrList, CDirDoc *> DirDocList;
43 typedef CTypedPtrList<CPtrList, CHexMergeDoc *> HexMergeDocList;
47 class CLanguageSelect;
50 CMainFrame * GetMainFrame(); // access to the singleton main frame object
53 * @brief Frame class containing save-routines etc
55 class CMainFrame : public CMDIFrameWnd
57 friend CLanguageSelect;
58 DECLARE_DYNAMIC(CMainFrame)
61 * @brief Frame/View/Document types.
65 FRAME_FOLDER, /**< Folder compare frame. */
66 FRAME_FILE, /**< File compare frame. */
67 FRAME_HEXFILE, /**< Hex file compare frame. */
68 FRAME_IMGFILE, /**< Image file compare frame. */
69 FRAME_OTHER, /**< No frame? */
74 virtual ~OpenFileParams() {}
77 struct OpenTextFileParams : public OpenFileParams
79 virtual ~OpenTextFileParams() {}
85 struct OpenTableFileParams : public OpenTextFileParams
87 virtual ~OpenTableFileParams() {}
88 std::optional<TCHAR> m_tableDelimiter;
89 std::optional<TCHAR> m_tableQuote;
90 std::optional<bool> m_tableAllowNewlinesInQuotes;
93 struct OpenBinaryFileParams : public OpenFileParams
95 virtual ~OpenBinaryFileParams() {}
99 struct OpenImageFileParams : public OpenFileParams
101 virtual ~OpenImageFileParams() {}
106 struct OpenAutoFileParams : public OpenTableFileParams, public OpenBinaryFileParams, public OpenImageFileParams
108 virtual ~OpenAutoFileParams() {}
115 bool m_bShowErrors; /**< Show folder compare error items? */
116 LOGFONT m_lfDiff; /**< MergeView user-selected font */
117 LOGFONT m_lfDir; /**< DirView user-selected font */
118 static const TCHAR szClassName[];
122 HMENU NewDirViewMenu();
123 HMENU NewMergeViewMenu();
124 HMENU NewHexMergeViewMenu();
125 HMENU NewImgMergeViewMenu();
126 HMENU NewOpenViewMenu();
127 HMENU NewDefaultMenu(int ID = 0);
128 HMENU GetPrediffersSubmenu(HMENU mainMenu);
129 void UpdatePrediffersMenu();
131 bool DoFileOrFolderOpen(const PathContext *pFiles = nullptr,
132 const DWORD dwFlags[] = nullptr, const String strDesc[] = nullptr,
133 const String& sReportFile = _T(""), bool bRecurse = false, CDirDoc *pDirDoc = nullptr,
134 const PackingInfo * infoUnpacker = nullptr, const PrediffingInfo * infoPrediffer = nullptr,
135 UINT nID = 0, const OpenFileParams *pOpenParams = nullptr);
136 bool DoFileOpen(UINT nID, const PathContext* pFiles,
137 const DWORD dwFlags[] = nullptr, const String strDesc[] = nullptr,
138 const String& sReportFile = _T(""),
139 const PackingInfo* infoUnpacker = nullptr, const PrediffingInfo * infoPrediffer = nullptr,
140 const OpenFileParams *pOpenParams = nullptr);
141 bool DoFileNew(UINT nID, int nPanes, const String strDesc[] = nullptr,
142 const PrediffingInfo * infoPrediffer = nullptr,
143 const OpenFileParams *pOpenParams = nullptr);
144 bool DoOpenConflict(const String& conflictFile, const String strDesc[] = nullptr, bool checked = false);
145 bool DoOpenClipboard(UINT nID = 0, int nBuffers = 2, const DWORD dwFlags[] = nullptr, const String strDesc[] = nullptr,
146 const PackingInfo* infoUnpacker = nullptr, const PrediffingInfo * infoPrediffer = nullptr,
147 const OpenFileParams* pOpenParams = nullptr);
148 bool DoSelfCompare(UINT nID, const String& file, const String strDesc[] = nullptr,
149 const PackingInfo* infoUnpacker = nullptr, const PrediffingInfo * infoPrediffer = nullptr,
150 const OpenFileParams* pOpenParams = nullptr);
151 bool ShowAutoMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
152 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
153 const PackingInfo * infoUnpacker = nullptr, const OpenFileParams *pOpenParams = nullptr);
154 bool ShowMergeDoc(UINT nID, CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
155 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
156 const PackingInfo * infoUnpacker = nullptr, const OpenFileParams *pOpenParams = nullptr);
157 bool ShowTextOrTableMergeDoc(std::optional<bool> table, CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
158 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
159 const PackingInfo * infoUnpacker = nullptr, const OpenTextFileParams *pOpenParams = nullptr);
160 bool ShowTextMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
161 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
162 const PackingInfo * infoUnpacker = nullptr, const OpenTextFileParams *pOpenParams = nullptr);
163 bool ShowTextMergeDoc(CDirDoc* pDirDoc, int nBuffers, const String text[],
164 const String strDesc[], const String& strFileExt, const OpenTextFileParams *pOpenParams = nullptr);
165 bool ShowTableMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
166 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
167 const PackingInfo * infoUnpacker = nullptr, const OpenTextFileParams *pOpenParams = nullptr);
168 bool ShowHexMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
169 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
170 const PackingInfo * infoUnpacker = nullptr, const OpenBinaryFileParams *pOpenParams = nullptr);
171 bool ShowImgMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
172 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
173 const PackingInfo * infoUnpacker = nullptr, const OpenImageFileParams *pOpenParams = nullptr);
175 void UpdateResources();
176 void ApplyDiffOptions();
178 void StartFlashing();
179 bool AskCloseConfirmation();
180 static FRAMETYPE GetFrameType(const CFrameWnd * pFrame);
181 static void UpdateDocTitle();
182 static void ReloadMenu();
183 static void AppendPluginMenus(CMenu* pMenu, const String& filteredFilenames,
184 const std::vector<std::wstring>& events, bool addAllMenu, unsigned baseId);
185 static String GetPluginPipelineByMenuId(unsigned idSearch, const std::vector<std::wstring>& events, unsigned baseId);
186 DropHandler *GetDropHandler() const { return m_pDropHandler; }
187 const CTypedPtrArray<CPtrArray, CMDIChildWnd*>* GetChildArray() const { return &m_arrChild; }
188 IMergeDoc* GetActiveIMergeDoc();
191 virtual void GetMessageString(UINT nID, CString& rMessage) const;
192 // ClassWizard generated virtual function overrides
193 //{{AFX_VIRTUAL(CMainFrame)
195 virtual void ActivateFrame(int nCmdShow = -1);
196 virtual BOOL PreTranslateMessage(MSG* pMsg);
197 virtual void OnUpdateFrameTitle(BOOL bAddToTitle);
198 virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
201 // Implementation methods
203 virtual ~CMainFrame();
205 // Public implementation data
207 bool m_bFirstTime; /**< If first time frame activated, get pos from reg */
209 // Implementation data
211 // control bar embedded members
212 CStatusBar m_wndStatusBar;
214 CToolBar m_wndToolBar;
215 CMDITabBar m_wndTabBar;
216 CTypedPtrArray<CPtrArray, CMDIChildWnd*> m_arrChild;
218 // Tweak MDI client window behavior
219 class CMDIClient : public CWnd
221 static UINT_PTR const m_nRedrawTimer = 1612;
222 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
229 // To reduce flicker in maximized state, disable drawing while messing with MDI child frames
231 HWND hwndActive = reinterpret_cast<HWND>(SendMessage(WM_MDIGETACTIVE, 0, reinterpret_cast<LPARAM>(&bMaximized)));
232 if ((bMaximized || (message == WM_MDICREATE && !hwndActive)) &&
233 SetTimer(m_nRedrawTimer, USER_TIMER_MINIMUM, nullptr))
240 if (wParam == m_nRedrawTimer)
242 KillTimer(m_nRedrawTimer);
244 RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE);
248 return CWnd::WindowProc(message, wParam, lParam);
260 MENU_COUNT, // Add new items before this item
263 * Menu frames - for which frame(s) the menu is.
267 MENU_MAINFRM = 0x000001,
268 MENU_FILECMP = 0x000002,
269 MENU_FOLDERCMP = 0x000004,
270 MENU_ALL = MENU_MAINFRM | MENU_FILECMP | MENU_FOLDERCMP
274 * A structure attaching a menu item, icon and menu types to apply to.
278 int menuitemID; /**< Menu item's ID. */
279 int iconResID; /**< Icon's resource ID. */
280 int menusToApply; /**< For which menus to apply. */
283 static const MENUITEM_ICON m_MenuIcons[];
285 std::unique_ptr<BCMenu> m_pMenus[MENU_COUNT]; /**< Menus for different views */
286 std::unique_ptr<BCMenu> m_pImageMenu;
287 std::vector<TempFilePtr> m_tempFiles; /**< List of possibly needed temp files. */
288 DropHandler *m_pDropHandler;
290 // Generated message map functions
292 //{{AFX_MSG(CMainFrame)
293 afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);
294 afx_msg LRESULT OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu) ;
295 afx_msg void OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu);
296 afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
297 afx_msg void OnFileOpen();
298 afx_msg void OnHelpGnulicense();
299 afx_msg void OnOptions();
300 afx_msg void OnViewSelectfont();
301 afx_msg void OnViewUsedefaultfont();
302 afx_msg void OnHelpContents();
303 afx_msg void OnClose();
304 afx_msg void OnToolsGeneratePatch();
305 afx_msg void OnDropFiles(const std::vector<String>& files);
306 afx_msg void OnUpdatePluginUnpackMode(CCmdUI* pCmdUI);
307 afx_msg void OnPluginUnpackMode(UINT nID);
308 afx_msg void OnUpdatePluginPrediffMode(CCmdUI* pCmdUI);
309 afx_msg void OnPluginPrediffMode(UINT nID);
310 afx_msg void OnUpdatePluginRelatedMenu(CCmdUI* pCmdUI);
311 afx_msg void OnReloadPlugins();
312 afx_msg void OnSaveConfigData();
313 template <int nFiles, unsigned nID>
314 afx_msg void OnFileNew();
315 afx_msg void OnToolsFilters();
316 afx_msg void OnViewStatusBar();
317 afx_msg void OnUpdateViewTabBar(CCmdUI* pCmdUI);
318 afx_msg void OnViewTabBar();
319 afx_msg void OnUpdateResizePanes(CCmdUI* pCmdUI);
320 afx_msg void OnResizePanes();
321 afx_msg void OnFileOpenProject();
322 afx_msg LRESULT OnCopyData(WPARAM wParam, LPARAM lParam);
323 afx_msg LRESULT OnUser1(WPARAM wParam, LPARAM lParam);
324 afx_msg void OnWindowCloseAll();
325 afx_msg void OnUpdateWindowCloseAll(CCmdUI* pCmdUI);
326 afx_msg void OnSaveProject();
327 #if _MFC_VER > 0x0600
328 afx_msg void OnActivateApp(BOOL bActive, DWORD dwThreadID);
330 afx_msg void OnActivateApp(BOOL bActive, HTASK hTask);
332 afx_msg void OnToolbarSize(UINT id);
333 afx_msg void OnUpdateToolbarSize(CCmdUI* pCmdUI);
334 afx_msg BOOL OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult);
335 afx_msg void OnHelpReleasenotes();
336 afx_msg void OnHelpTranslations();
337 afx_msg void OnFileOpenConflict();
338 afx_msg void OnFileOpenClipboard();
339 afx_msg void OnPluginsList();
340 afx_msg void OnUpdatePluginName(CCmdUI* pCmdUI);
341 afx_msg void OnUpdateStatusNum(CCmdUI* pCmdUI);
342 afx_msg void OnToolbarButtonDropDown(NMHDR* pNMHDR, LRESULT* pResult);
343 afx_msg void OnDiffWhitespace(UINT nID);
344 afx_msg void OnUpdateDiffWhitespace(CCmdUI* pCmdUI);
345 afx_msg void OnDiffIgnoreBlankLines();
346 afx_msg void OnUpdateDiffIgnoreBlankLines(CCmdUI* pCmdUI);
347 afx_msg void OnDiffIgnoreCase();
348 afx_msg void OnUpdateDiffIgnoreCase(CCmdUI* pCmdUI);
349 afx_msg void OnDiffIgnoreNumbers();
350 afx_msg void OnUpdateDiffIgnoreNumbers(CCmdUI* pCmdUI);
351 afx_msg void OnDiffIgnoreEOL();
352 afx_msg void OnUpdateDiffIgnoreEOL(CCmdUI* pCmdUI);
353 afx_msg void OnDiffIgnoreCP();
354 afx_msg void OnUpdateDiffIgnoreCP(CCmdUI* pCmdUI);
355 afx_msg void OnDiffIgnoreComments();
356 afx_msg void OnUpdateDiffIgnoreComments(CCmdUI* pCmdUI);
357 afx_msg void OnIncludeSubfolders();
358 afx_msg void OnUpdateIncludeSubfolders(CCmdUI* pCmdUI);
359 afx_msg void OnCompareMethod(UINT nID);
360 afx_msg void OnUpdateCompareMethod(CCmdUI* pCmdUI);
361 afx_msg void OnMRUs(UINT nID);
362 afx_msg void OnUpdateNoMRUs(CCmdUI* pCmdUI);
363 afx_msg void OnFirstFile();
364 afx_msg void OnUpdateFirstFile(CCmdUI* pCmdUI);
365 afx_msg void OnPrevFile();
366 afx_msg void OnUpdatePrevFile(CCmdUI* pCmdUI);
367 afx_msg void OnNextFile();
368 afx_msg void OnUpdateNextFile(CCmdUI* pCmdUI);
369 afx_msg void OnLastFile();
370 afx_msg void OnUpdateLastFile(CCmdUI* pCmdUI);
371 afx_msg void OnTimer(UINT_PTR nIDEvent);
372 afx_msg void OnDestroy();
373 afx_msg void OnAccelQuit();
374 afx_msg LRESULT OnChildFrameAdded(WPARAM wParam, LPARAM lParam);
375 afx_msg LRESULT OnChildFrameRemoved(WPARAM wParam, LPARAM lParam);
376 afx_msg LRESULT OnChildFrameActivate(WPARAM wParam, LPARAM lParam);
377 afx_msg LRESULT OnChildFrameActivated(WPARAM wParam, LPARAM lParam);
379 DECLARE_MESSAGE_MAP()
382 void addToMru(LPCTSTR szItem, LPCTSTR szRegSubKey, UINT nMaxItems = 20);
383 OpenDocList &GetAllOpenDocs();
384 MergeDocList &GetAllMergeDocs();
385 DirDocList &GetAllDirDocs();
386 HexMergeDocList &GetAllHexMergeDocs();
387 std::vector<CImgMergeFrame *> GetAllImgMergeFrames();
388 void UpdateFont(FRAMETYPE frame);
389 BOOL CreateToolbar();
390 CMergeEditView * GetActiveMergeEditView();
391 void LoadToolbarImages();
392 HMENU NewMenu( int view, int ID );