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
16 #include "MDITabBar.h"
17 #include "PathContext.h"
18 #include "OptionsDef.h"
19 #include "OptionsMgr.h"
29 class LineFiltersList;
36 typedef std::shared_ptr<TempFile> TempFilePtr;
38 // typed lists (homogenous pointer lists)
39 typedef CTypedPtrList<CPtrList, COpenDoc *> OpenDocList;
40 typedef CTypedPtrList<CPtrList, CMergeDoc *> MergeDocList;
41 typedef CTypedPtrList<CPtrList, CDirDoc *> DirDocList;
42 typedef CTypedPtrList<CPtrList, CHexMergeDoc *> HexMergeDocList;
45 class CLanguageSelect;
47 CMainFrame * GetMainFrame(); // access to the singleton main frame object
50 * @brief Frame class containing save-routines etc
52 class CMainFrame : public CMDIFrameWnd
54 friend CLanguageSelect;
55 DECLARE_DYNAMIC(CMainFrame)
58 * @brief Frame/View/Document types.
62 FRAME_FOLDER, /**< Folder compare frame. */
63 FRAME_FILE, /**< File compare frame. */
64 FRAME_HEXFILE, /**< Hex file compare frame. */
65 FRAME_IMGFILE, /**< Image file compare frame. */
66 FRAME_OTHER, /**< No frame? */
73 bool m_bShowErrors; /**< Show folder compare error items? */
74 LOGFONT m_lfDiff; /**< MergeView user-selected font */
75 LOGFONT m_lfDir; /**< DirView user-selected font */
76 static const TCHAR szClassName[];
80 HMENU NewDirViewMenu();
81 HMENU NewMergeViewMenu();
82 HMENU NewHexMergeViewMenu();
83 HMENU NewImgMergeViewMenu();
84 HMENU NewOpenViewMenu();
85 HMENU NewDefaultMenu(int ID = 0);
86 HMENU GetScriptsSubmenu(HMENU mainMenu);
87 HMENU GetPrediffersSubmenu(HMENU mainMenu);
88 void UpdatePrediffersMenu();
90 void FileNew(int nPanes, FRAMETYPE frameType, bool table);
91 bool DoFileOpen(const PathContext *pFiles = nullptr,
92 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);
93 bool ShowAutoMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
94 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""), const PackingInfo * infoUnpacker = nullptr);
95 bool ShowMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
96 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""), const PackingInfo * infoUnpacker = nullptr);
97 bool ShowMergeDoc(CDirDoc* pDirDoc, int nBuffers, const String text[],
98 const String strDesc[], const String& strFileExt);
99 bool ShowHexMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
100 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""), const PackingInfo * infoUnpacker = nullptr);
101 bool ShowImgMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
102 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""), const PackingInfo * infoUnpacker = nullptr);
104 void UpdateResources();
105 void ClearStatusbarItemCount();
106 void ApplyDiffOptions();
108 void StartFlashing();
109 bool AskCloseConfirmation();
110 bool DoOpenConflict(const String& conflictFile, const String strDesc[] = nullptr, bool checked = false);
111 bool DoSelfCompare(const String& file, const String strDesc[] = nullptr);
112 FRAMETYPE GetFrameType(const CFrameWnd * pFrame) const;
113 void UpdateDocTitle();
115 DropHandler *GetDropHandler() const { return m_pDropHandler; }
116 const CTypedPtrArray<CPtrArray, CMDIChildWnd*>* GetChildArray() const { return &m_arrChild; }
119 virtual void GetMessageString(UINT nID, CString& rMessage) const;
120 // ClassWizard generated virtual function overrides
121 //{{AFX_VIRTUAL(CMainFrame)
123 virtual void ActivateFrame(int nCmdShow = -1);
124 virtual BOOL PreTranslateMessage(MSG* pMsg);
125 virtual void OnUpdateFrameTitle(BOOL bAddToTitle);
126 virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
129 // Implementation methods
131 virtual ~CMainFrame();
133 // Public implementation data
135 bool m_bFirstTime; /**< If first time frame activated, get pos from reg */
137 // Implementation data
139 // control bar embedded members
140 CStatusBar m_wndStatusBar;
142 CToolBar m_wndToolBar;
143 CMDITabBar m_wndTabBar;
144 CTypedPtrArray<CPtrArray, CMDIChildWnd*> m_arrChild;
146 // Tweak MDI client window behavior
147 class CMDIClient : public CWnd
149 static UINT_PTR const m_nRedrawTimer = 1612;
150 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
157 // To reduce flicker in maximized state, disable drawing while messing with MDI child frames
159 HWND hwndActive = reinterpret_cast<HWND>(SendMessage(WM_MDIGETACTIVE, 0, reinterpret_cast<LPARAM>(&bMaximized)));
160 if ((bMaximized || (message == WM_MDICREATE && !hwndActive)) &&
161 SetTimer(m_nRedrawTimer, USER_TIMER_MINIMUM, nullptr))
168 if (wParam == m_nRedrawTimer)
170 KillTimer(m_nRedrawTimer);
172 RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE);
176 return CWnd::WindowProc(message, wParam, lParam);
180 /** @brief Toolbar image table indexes. */
183 TOOLBAR_IMAGES_ENABLED,
184 TOOLBAR_IMAGES_DISABLED,
188 CImageList m_ToolbarImages[TOOLBAR_IMAGES_COUNT]; /**< Images for toolbar */
198 MENU_COUNT, // Add new items before this item
201 * Menu frames - for which frame(s) the menu is.
205 MENU_MAINFRM = 0x000001,
206 MENU_FILECMP = 0x000002,
207 MENU_FOLDERCMP = 0x000004,
208 MENU_ALL = MENU_MAINFRM | MENU_FILECMP | MENU_FOLDERCMP
212 * A structure attaching a menu item, icon and menu types to apply to.
216 int menuitemID; /**< Menu item's ID. */
217 int iconResID; /**< Icon's resource ID. */
218 int menusToApply; /**< For which menus to apply. */
221 static const MENUITEM_ICON m_MenuIcons[];
223 std::unique_ptr<BCMenu> m_pMenus[MENU_COUNT]; /**< Menus for different views */
224 std::unique_ptr<BCMenu> m_pImageMenu;
225 std::vector<TempFilePtr> m_tempFiles; /**< List of possibly needed temp files. */
226 DropHandler *m_pDropHandler;
228 // Generated message map functions
230 //{{AFX_MSG(CMainFrame)
231 afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);
232 afx_msg LRESULT OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu) ;
233 afx_msg void OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu);
234 afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
235 afx_msg void OnFileOpen();
236 afx_msg void OnHelpGnulicense();
237 afx_msg void OnOptions();
238 afx_msg void OnViewSelectfont();
239 afx_msg void OnViewUsedefaultfont();
240 afx_msg void OnHelpContents();
241 afx_msg void OnClose();
242 afx_msg void OnToolsGeneratePatch();
243 afx_msg void OnDropFiles(const std::vector<String>& files);
244 afx_msg void OnUpdatePluginUnpackMode(CCmdUI* pCmdUI);
245 afx_msg void OnPluginUnpackMode(UINT nID);
246 afx_msg void OnUpdatePluginPrediffMode(CCmdUI* pCmdUI);
247 afx_msg void OnPluginPrediffMode(UINT nID);
248 afx_msg void OnUpdateReloadPlugins(CCmdUI* pCmdUI);
249 afx_msg void OnReloadPlugins();
250 afx_msg void OnSaveConfigData();
251 template <int nFiles, FRAMETYPE frameType, bool table = false>
252 afx_msg void OnFileNew();
253 afx_msg void OnToolsFilters();
254 afx_msg void OnViewStatusBar();
255 afx_msg void OnUpdateViewTabBar(CCmdUI* pCmdUI);
256 afx_msg void OnViewTabBar();
257 afx_msg void OnUpdateResizePanes(CCmdUI* pCmdUI);
258 afx_msg void OnResizePanes();
259 afx_msg void OnFileOpenProject();
260 afx_msg LRESULT OnCopyData(WPARAM wParam, LPARAM lParam);
261 afx_msg LRESULT OnUser1(WPARAM wParam, LPARAM lParam);
262 afx_msg void OnWindowCloseAll();
263 afx_msg void OnUpdateWindowCloseAll(CCmdUI* pCmdUI);
264 afx_msg void OnSaveProject();
265 #if _MFC_VER > 0x0600
266 afx_msg void OnActivateApp(BOOL bActive, DWORD dwThreadID);
268 afx_msg void OnActivateApp(BOOL bActive, HTASK hTask);
270 afx_msg void OnToolbarSize(UINT id);
271 afx_msg void OnUpdateToolbarSize(CCmdUI* pCmdUI);
272 afx_msg BOOL OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult);
273 afx_msg void OnHelpReleasenotes();
274 afx_msg void OnHelpTranslations();
275 afx_msg void OnHelpCheckForUpdates();
276 afx_msg void OnUpdateHelpCheckForUpdates(CCmdUI* pCmdUI);
277 afx_msg void OnFileOpenConflict();
278 afx_msg void OnPluginsList();
279 afx_msg void OnUpdatePluginName(CCmdUI* pCmdUI);
280 afx_msg void OnToolbarButtonDropDown(NMHDR* pNMHDR, LRESULT* pResult);
281 afx_msg void OnDiffWhitespace(UINT nID);
282 afx_msg void OnUpdateDiffWhitespace(CCmdUI* pCmdUI);
283 afx_msg void OnDiffIgnoreCase();
284 afx_msg void OnUpdateDiffIgnoreCase(CCmdUI* pCmdUI);
285 afx_msg void OnDiffIgnoreEOL();
286 afx_msg void OnUpdateDiffIgnoreEOL(CCmdUI* pCmdUI);
287 afx_msg void OnDiffIgnoreCP();
288 afx_msg void OnUpdateDiffIgnoreCP(CCmdUI* pCmdUI);
289 afx_msg void OnIncludeSubfolders();
290 afx_msg void OnUpdateIncludeSubfolders(CCmdUI* pCmdUI);
291 afx_msg void OnCompareMethod(UINT nID);
292 afx_msg void OnUpdateCompareMethod(CCmdUI* pCmdUI);
293 afx_msg void OnMRUs(UINT nID);
294 afx_msg void OnUpdateNoMRUs(CCmdUI* pCmdUI);
295 afx_msg void OnTimer(UINT_PTR nIDEvent);
296 afx_msg void OnDestroy();
297 afx_msg void OnAccelQuit();
299 afx_msg LRESULT OnChildFrameAdded(WPARAM wParam, LPARAM lParam);
300 afx_msg LRESULT OnChildFrameRemoved(WPARAM wParam, LPARAM lParam);
301 afx_msg LRESULT OnChildFrameActivate(WPARAM wParam, LPARAM lParam);
302 afx_msg LRESULT OnChildFrameActivated(WPARAM wParam, LPARAM lParam);
303 DECLARE_MESSAGE_MAP()
306 void addToMru(LPCTSTR szItem, LPCTSTR szRegSubKey, UINT nMaxItems = 20);
307 OpenDocList &GetAllOpenDocs();
308 MergeDocList &GetAllMergeDocs();
309 DirDocList &GetAllDirDocs();
310 HexMergeDocList &GetAllHexMergeDocs();
311 std::list<CImgMergeFrame *> GetAllImgMergeFrames();
312 void UpdateFont(FRAMETYPE frame);
313 BOOL CreateToolbar();
314 CMergeEditView * GetActiveMergeEditView();
315 void LoadToolbarImages();
316 HMENU NewMenu( int view, int ID );