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);
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 ShowHexMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
98 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""), const PackingInfo * infoUnpacker = nullptr);
99 bool ShowImgMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
100 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""), const PackingInfo * infoUnpacker = nullptr);
102 void UpdateResources();
103 void ClearStatusbarItemCount();
104 void ApplyDiffOptions();
106 void StartFlashing();
107 bool AskCloseConfirmation();
108 bool DoOpenConflict(const String& conflictFile, const String strDesc[] = nullptr, bool checked = false);
109 FRAMETYPE GetFrameType(const CFrameWnd * pFrame) const;
110 void UpdateDocTitle();
112 DropHandler *GetDropHandler() const { return m_pDropHandler; }
113 const CTypedPtrArray<CPtrArray, CMDIChildWnd*>* GetChildArray() const { return &m_arrChild; }
116 virtual void GetMessageString(UINT nID, CString& rMessage) const;
117 // ClassWizard generated virtual function overrides
118 //{{AFX_VIRTUAL(CMainFrame)
120 virtual void ActivateFrame(int nCmdShow = -1);
121 virtual BOOL PreTranslateMessage(MSG* pMsg);
122 virtual void OnUpdateFrameTitle(BOOL bAddToTitle);
123 virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
126 // Implementation methods
128 virtual ~CMainFrame();
130 // Public implementation data
132 bool m_bFirstTime; /**< If first time frame activated, get pos from reg */
134 // Implementation data
136 // control bar embedded members
137 CStatusBar m_wndStatusBar;
139 CToolBar m_wndToolBar;
140 CMDITabBar m_wndTabBar;
141 CTypedPtrArray<CPtrArray, CMDIChildWnd*> m_arrChild;
143 // Tweak MDI client window behavior
144 class CMDIClient : public CWnd
146 static UINT_PTR const m_nRedrawTimer = 1612;
147 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
154 // To reduce flicker in maximized state, disable drawing while messing with MDI child frames
156 HWND hwndActive = reinterpret_cast<HWND>(SendMessage(WM_MDIGETACTIVE, 0, reinterpret_cast<LPARAM>(&bMaximized)));
157 if ((bMaximized || (message == WM_MDICREATE &&
158 (!hwndActive || !GetOptionsMgr()->GetBool(OPT_CLOSE_WITH_OK)))) &&
159 SetTimer(m_nRedrawTimer, USER_TIMER_MINIMUM, nullptr))
166 if (wParam == m_nRedrawTimer)
168 KillTimer(m_nRedrawTimer);
170 RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE);
171 GetMainFrame()->GetActiveFrame()->OnUpdateFrameTitle(TRUE);
172 GetMainFrame()->SendMessageToDescendants(WM_IDLEUPDATECMDUI, (WPARAM)TRUE, 0, TRUE, TRUE);
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 afx_msg void OnFileNew();
252 afx_msg void OnFileNew3();
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 OnFileOpenConflict();
276 afx_msg void OnPluginsList();
277 afx_msg void OnUpdatePluginName(CCmdUI* pCmdUI);
278 afx_msg void OnDiffOptionsDropDown(NMHDR* pNMHDR, LRESULT* pResult);
279 afx_msg void OnDiffWhitespace(UINT nID);
280 afx_msg void OnUpdateDiffWhitespace(CCmdUI* pCmdUI);
281 afx_msg void OnDiffCaseSensitive();
282 afx_msg void OnUpdateDiffCaseSensitive(CCmdUI* pCmdUI);
283 afx_msg void OnDiffIgnoreEOL();
284 afx_msg void OnUpdateDiffIgnoreEOL(CCmdUI* pCmdUI);
285 afx_msg void OnDiffIgnoreCP();
286 afx_msg void OnUpdateDiffIgnoreCP(CCmdUI* pCmdUI);
287 afx_msg void OnIncludeSubfolders();
288 afx_msg void OnUpdateIncludeSubfolders(CCmdUI* pCmdUI);
289 afx_msg void OnCompareMethod(UINT nID);
290 afx_msg void OnUpdateCompareMethod(CCmdUI* pCmdUI);
291 afx_msg void OnMRUs(UINT nID);
292 afx_msg void OnUpdateNoMRUs(CCmdUI* pCmdUI);
293 afx_msg void OnDestroy();
294 afx_msg void OnAccelQuit();
296 afx_msg LRESULT OnChildFrameAdded(WPARAM wParam, LPARAM lParam);
297 afx_msg LRESULT OnChildFrameRemoved(WPARAM wParam, LPARAM lParam);
298 afx_msg LRESULT OnChildFrameActivate(WPARAM wParam, LPARAM lParam);
299 afx_msg LRESULT OnChildFrameActivated(WPARAM wParam, LPARAM lParam);
300 DECLARE_MESSAGE_MAP()
303 void addToMru(LPCTSTR szItem, LPCTSTR szRegSubKey, UINT nMaxItems = 20);
304 OpenDocList &GetAllOpenDocs();
305 MergeDocList &GetAllMergeDocs();
306 DirDocList &GetAllDirDocs();
307 HexMergeDocList &GetAllHexMergeDocs();
308 std::list<CImgMergeFrame *> GetAllImgMergeFrames();
309 void UpdateFont(FRAMETYPE frame);
310 BOOL CreateToolbar();
311 CMergeEditView * GetActiveMergeEditView();
312 void LoadToolbarImages();
313 HMENU NewMenu( int view, int ID );