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;
46 class CLanguageSelect;
49 CMainFrame * GetMainFrame(); // access to the singleton main frame object
52 * @brief Frame class containing save-routines etc
54 class CMainFrame : public CMDIFrameWnd
56 friend CLanguageSelect;
57 DECLARE_DYNAMIC(CMainFrame)
60 * @brief Frame/View/Document types.
64 FRAME_FOLDER, /**< Folder compare frame. */
65 FRAME_FILE, /**< File compare frame. */
66 FRAME_HEXFILE, /**< Hex file compare frame. */
67 FRAME_IMGFILE, /**< Image file compare frame. */
68 FRAME_OTHER, /**< No frame? */
75 bool m_bShowErrors; /**< Show folder compare error items? */
76 LOGFONT m_lfDiff; /**< MergeView user-selected font */
77 LOGFONT m_lfDir; /**< DirView user-selected font */
78 static const TCHAR szClassName[];
82 HMENU NewDirViewMenu();
83 HMENU NewMergeViewMenu();
84 HMENU NewHexMergeViewMenu();
85 HMENU NewImgMergeViewMenu();
86 HMENU NewOpenViewMenu();
87 HMENU NewDefaultMenu(int ID = 0);
88 HMENU GetScriptsSubmenu(HMENU mainMenu);
89 HMENU GetPrediffersSubmenu(HMENU mainMenu);
90 void UpdatePrediffersMenu();
92 void FileNew(int nPanes, FRAMETYPE frameType, bool table);
93 bool DoFileOpen(const PathContext *pFiles = nullptr,
94 const DWORD dwFlags[] = nullptr, const String strDesc[] = nullptr, const String& sReportFile = _T(""), bool bRecurse = false, CDirDoc *pDirDoc = nullptr, String prediffer = _T(""), const PackingInfo * infoUnpacker = nullptr);
95 bool DoFileOpen(UINT nID, const PathContext *pFiles = nullptr,
96 const DWORD dwFlags[] = nullptr, const String strDesc[] = nullptr);
97 bool ShowAutoMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
98 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""), const PackingInfo * infoUnpacker = nullptr);
99 bool ShowMergeDoc(UINT nID, CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
100 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""), const PackingInfo * infoUnpacker = nullptr);
101 bool ShowTextOrTableMergeDoc(std::optional<bool> table, CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
102 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""), const PackingInfo * infoUnpacker = nullptr);
103 bool ShowTextMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
104 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""), const PackingInfo * infoUnpacker = nullptr);
105 bool ShowTextMergeDoc(CDirDoc* pDirDoc, int nBuffers, const String text[],
106 const String strDesc[], const String& strFileExt);
107 bool ShowTableMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
108 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""), const PackingInfo * infoUnpacker = nullptr);
109 bool ShowHexMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
110 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""), const PackingInfo * infoUnpacker = nullptr);
111 bool ShowImgMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
112 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""), const PackingInfo * infoUnpacker = nullptr);
114 void UpdateResources();
115 void ClearStatusbarItemCount();
116 void ApplyDiffOptions();
118 void StartFlashing();
119 bool AskCloseConfirmation();
120 bool DoOpenConflict(const String& conflictFile, const String strDesc[] = nullptr, bool checked = false);
121 bool DoSelfCompare(UINT nID, const String& file, const String strDesc[] = nullptr);
122 static FRAMETYPE GetFrameType(const CFrameWnd * pFrame);
123 static void UpdateDocTitle();
124 static void ReloadMenu();
125 DropHandler *GetDropHandler() const { return m_pDropHandler; }
126 const CTypedPtrArray<CPtrArray, CMDIChildWnd*>* GetChildArray() const { return &m_arrChild; }
127 IMergeDoc* GetActiveIMergeDoc();
130 virtual void GetMessageString(UINT nID, CString& rMessage) const;
131 // ClassWizard generated virtual function overrides
132 //{{AFX_VIRTUAL(CMainFrame)
134 virtual void ActivateFrame(int nCmdShow = -1);
135 virtual BOOL PreTranslateMessage(MSG* pMsg);
136 virtual void OnUpdateFrameTitle(BOOL bAddToTitle);
137 virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
140 // Implementation methods
142 virtual ~CMainFrame();
144 // Public implementation data
146 bool m_bFirstTime; /**< If first time frame activated, get pos from reg */
148 // Implementation data
150 // control bar embedded members
151 CStatusBar m_wndStatusBar;
153 CToolBar m_wndToolBar;
154 CMDITabBar m_wndTabBar;
155 CTypedPtrArray<CPtrArray, CMDIChildWnd*> m_arrChild;
157 // Tweak MDI client window behavior
158 class CMDIClient : public CWnd
160 static UINT_PTR const m_nRedrawTimer = 1612;
161 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
168 // To reduce flicker in maximized state, disable drawing while messing with MDI child frames
170 HWND hwndActive = reinterpret_cast<HWND>(SendMessage(WM_MDIGETACTIVE, 0, reinterpret_cast<LPARAM>(&bMaximized)));
171 if ((bMaximized || (message == WM_MDICREATE && !hwndActive)) &&
172 SetTimer(m_nRedrawTimer, USER_TIMER_MINIMUM, nullptr))
179 if (wParam == m_nRedrawTimer)
181 KillTimer(m_nRedrawTimer);
183 RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE);
187 return CWnd::WindowProc(message, wParam, lParam);
191 /** @brief Toolbar image table indexes. */
194 TOOLBAR_IMAGES_ENABLED,
195 TOOLBAR_IMAGES_DISABLED,
199 CImageList m_ToolbarImages[TOOLBAR_IMAGES_COUNT]; /**< Images for toolbar */
209 MENU_COUNT, // Add new items before this item
212 * Menu frames - for which frame(s) the menu is.
216 MENU_MAINFRM = 0x000001,
217 MENU_FILECMP = 0x000002,
218 MENU_FOLDERCMP = 0x000004,
219 MENU_ALL = MENU_MAINFRM | MENU_FILECMP | MENU_FOLDERCMP
223 * A structure attaching a menu item, icon and menu types to apply to.
227 int menuitemID; /**< Menu item's ID. */
228 int iconResID; /**< Icon's resource ID. */
229 int menusToApply; /**< For which menus to apply. */
232 static const MENUITEM_ICON m_MenuIcons[];
234 std::unique_ptr<BCMenu> m_pMenus[MENU_COUNT]; /**< Menus for different views */
235 std::unique_ptr<BCMenu> m_pImageMenu;
236 std::vector<TempFilePtr> m_tempFiles; /**< List of possibly needed temp files. */
237 DropHandler *m_pDropHandler;
239 // Generated message map functions
241 //{{AFX_MSG(CMainFrame)
242 afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);
243 afx_msg LRESULT OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu) ;
244 afx_msg void OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu);
245 afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
246 afx_msg void OnFileOpen();
247 afx_msg void OnHelpGnulicense();
248 afx_msg void OnOptions();
249 afx_msg void OnViewSelectfont();
250 afx_msg void OnViewUsedefaultfont();
251 afx_msg void OnHelpContents();
252 afx_msg void OnClose();
253 afx_msg void OnToolsGeneratePatch();
254 afx_msg void OnDropFiles(const std::vector<String>& files);
255 afx_msg void OnUpdatePluginUnpackMode(CCmdUI* pCmdUI);
256 afx_msg void OnPluginUnpackMode(UINT nID);
257 afx_msg void OnUpdatePluginPrediffMode(CCmdUI* pCmdUI);
258 afx_msg void OnPluginPrediffMode(UINT nID);
259 afx_msg void OnUpdateReloadPlugins(CCmdUI* pCmdUI);
260 afx_msg void OnReloadPlugins();
261 afx_msg void OnSaveConfigData();
262 template <int nFiles, FRAMETYPE frameType, bool table = false>
263 afx_msg void OnFileNew();
264 afx_msg void OnToolsFilters();
265 afx_msg void OnViewStatusBar();
266 afx_msg void OnUpdateViewTabBar(CCmdUI* pCmdUI);
267 afx_msg void OnViewTabBar();
268 afx_msg void OnUpdateResizePanes(CCmdUI* pCmdUI);
269 afx_msg void OnResizePanes();
270 afx_msg void OnFileOpenProject();
271 afx_msg LRESULT OnCopyData(WPARAM wParam, LPARAM lParam);
272 afx_msg LRESULT OnUser1(WPARAM wParam, LPARAM lParam);
273 afx_msg void OnWindowCloseAll();
274 afx_msg void OnUpdateWindowCloseAll(CCmdUI* pCmdUI);
275 afx_msg void OnSaveProject();
276 #if _MFC_VER > 0x0600
277 afx_msg void OnActivateApp(BOOL bActive, DWORD dwThreadID);
279 afx_msg void OnActivateApp(BOOL bActive, HTASK hTask);
281 afx_msg void OnToolbarSize(UINT id);
282 afx_msg void OnUpdateToolbarSize(CCmdUI* pCmdUI);
283 afx_msg BOOL OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult);
284 afx_msg void OnHelpReleasenotes();
285 afx_msg void OnHelpTranslations();
286 afx_msg void OnFileOpenConflict();
287 afx_msg void OnPluginsList();
288 afx_msg void OnUpdatePluginName(CCmdUI* pCmdUI);
289 afx_msg void OnToolbarButtonDropDown(NMHDR* pNMHDR, LRESULT* pResult);
290 afx_msg void OnDiffWhitespace(UINT nID);
291 afx_msg void OnUpdateDiffWhitespace(CCmdUI* pCmdUI);
292 afx_msg void OnDiffIgnoreBlankLines();
293 afx_msg void OnUpdateDiffIgnoreBlankLines(CCmdUI* pCmdUI);
294 afx_msg void OnDiffIgnoreCase();
295 afx_msg void OnUpdateDiffIgnoreCase(CCmdUI* pCmdUI);
296 afx_msg void OnDiffIgnoreEOL();
297 afx_msg void OnUpdateDiffIgnoreEOL(CCmdUI* pCmdUI);
298 afx_msg void OnDiffIgnoreCP();
299 afx_msg void OnUpdateDiffIgnoreCP(CCmdUI* pCmdUI);
300 afx_msg void OnDiffIgnoreComments();
301 afx_msg void OnUpdateDiffIgnoreComments(CCmdUI* pCmdUI);
302 afx_msg void OnIncludeSubfolders();
303 afx_msg void OnUpdateIncludeSubfolders(CCmdUI* pCmdUI);
304 afx_msg void OnCompareMethod(UINT nID);
305 afx_msg void OnUpdateCompareMethod(CCmdUI* pCmdUI);
306 afx_msg void OnMRUs(UINT nID);
307 afx_msg void OnUpdateNoMRUs(CCmdUI* pCmdUI);
308 afx_msg void OnFirstFile();
309 afx_msg void OnUpdateFirstFile(CCmdUI* pCmdUI);
310 afx_msg void OnPrevFile();
311 afx_msg void OnUpdatePrevFile(CCmdUI* pCmdUI);
312 afx_msg void OnNextFile();
313 afx_msg void OnUpdateNextFile(CCmdUI* pCmdUI);
314 afx_msg void OnLastFile();
315 afx_msg void OnUpdateLastFile(CCmdUI* pCmdUI);
316 afx_msg void OnTimer(UINT_PTR nIDEvent);
317 afx_msg void OnDestroy();
318 afx_msg void OnAccelQuit();
319 afx_msg LRESULT OnChildFrameAdded(WPARAM wParam, LPARAM lParam);
320 afx_msg LRESULT OnChildFrameRemoved(WPARAM wParam, LPARAM lParam);
321 afx_msg LRESULT OnChildFrameActivate(WPARAM wParam, LPARAM lParam);
322 afx_msg LRESULT OnChildFrameActivated(WPARAM wParam, LPARAM lParam);
324 DECLARE_MESSAGE_MAP()
327 void addToMru(LPCTSTR szItem, LPCTSTR szRegSubKey, UINT nMaxItems = 20);
328 OpenDocList &GetAllOpenDocs();
329 MergeDocList &GetAllMergeDocs();
330 DirDocList &GetAllDirDocs();
331 HexMergeDocList &GetAllHexMergeDocs();
332 std::list<CImgMergeFrame *> GetAllImgMergeFrames();
333 void UpdateFont(FRAMETYPE frame);
334 BOOL CreateToolbar();
335 CMergeEditView * GetActiveMergeEditView();
336 void LoadToolbarImages();
337 HMENU NewMenu( int view, int ID );