OSDN Git Service

Update CWindowsManagerDialog - check some pointers for null and made … (#824) (2)
[winmerge-jp/winmerge-jp.git] / Src / MainFrm.h
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 /////////////////////////////////////////////////////////////////////////////
6 /** 
7  * @file  MainFrm.h
8  *
9  * @brief Declaration file for CMainFrame
10  *
11  */
12 #pragma once
13
14 #include <vector>
15 #include <memory>
16 #include <optional>
17 #include "MDITabBar.h"
18 #include "PathContext.h"
19 #include "OptionsDef.h"
20 #include "OptionsMgr.h"
21
22 class BCMenu;
23 class CDirView;
24 class COpenDoc;
25 class CDirDoc;
26 class CMergeDoc;
27 class CHexMergeDoc;
28 class CMergeEditView;
29 class SyntaxColors;
30 class LineFiltersList;
31 class TempFile;
32 struct FileLocation;
33 class DropHandler;
34 class CMainFrame;
35 class CImgMergeFrame;
36
37 typedef std::shared_ptr<TempFile> TempFilePtr;
38
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;
44
45 class PackingInfo;
46 class CLanguageSelect;
47 struct IMergeDoc;
48
49 CMainFrame * GetMainFrame(); // access to the singleton main frame object
50
51 /**
52  * @brief Frame class containing save-routines etc
53  */
54 class CMainFrame : public CMDIFrameWnd
55 {
56         friend CLanguageSelect;
57         DECLARE_DYNAMIC(CMainFrame)
58 public:
59         /**
60          * @brief Frame/View/Document types.
61          */
62         enum FRAMETYPE
63         {
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? */
69         };
70
71         CMainFrame();
72
73 // Attributes
74 public: 
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[];
79
80 // Operations
81 public:
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();
91
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);
113
114         void UpdateResources();
115         void ClearStatusbarItemCount();
116         void ApplyDiffOptions();
117         void SelectFilter();
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();
128
129 // Overrides
130         virtual void GetMessageString(UINT nID, CString& rMessage) const;
131         // ClassWizard generated virtual function overrides
132         //{{AFX_VIRTUAL(CMainFrame)
133 public:
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);
138         //}}AFX_VIRTUAL
139
140 // Implementation methods
141 protected:
142         virtual ~CMainFrame();
143
144 // Public implementation data
145 public:
146         bool m_bFirstTime; /**< If first time frame activated, get  pos from reg */
147
148 // Implementation data
149 protected:
150         // control bar embedded members
151         CStatusBar  m_wndStatusBar;
152         CReBar m_wndReBar;
153         CToolBar m_wndToolBar;
154         CMDITabBar m_wndTabBar;
155         CTypedPtrArray<CPtrArray, CMDIChildWnd*> m_arrChild;
156
157         // Tweak MDI client window behavior
158         class CMDIClient : public CWnd
159         {
160                 static UINT_PTR const m_nRedrawTimer = 1612;
161                 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
162                 {
163                         switch (message)
164                         {
165                         case WM_MDICREATE:
166                         case WM_MDIACTIVATE:
167                         {
168                                 // To reduce flicker in maximized state, disable drawing while messing with MDI child frames
169                                 BOOL bMaximized;
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))
173                                 {
174                                         SetRedraw(FALSE);
175                                 }
176                                 break;
177                         }
178                         case WM_TIMER:
179                                 if (wParam == m_nRedrawTimer)
180                                 {
181                                         KillTimer(m_nRedrawTimer);
182                                         SetRedraw(TRUE);
183                                         RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE);
184                                 }
185                                 break;
186                         }
187                         return CWnd::WindowProc(message, wParam, lParam);
188                 }
189         } m_wndMDIClient;
190
191         /** @brief Toolbar image table indexes. */
192         enum TOOLBAR_IMAGES
193         {
194                 TOOLBAR_IMAGES_ENABLED,
195                 TOOLBAR_IMAGES_DISABLED,
196                 TOOLBAR_IMAGES_COUNT
197         };
198
199         CImageList m_ToolbarImages[TOOLBAR_IMAGES_COUNT]; /**< Images for toolbar */
200
201         enum
202         {
203                 MENU_DEFAULT,
204                 MENU_MERGEVIEW,
205                 MENU_DIRVIEW,
206                 MENU_HEXMERGEVIEW,
207                 MENU_IMGMERGEVIEW,
208                 MENU_OPENVIEW,
209                 MENU_COUNT, // Add new items before this item
210         };
211         /**
212          * Menu frames - for which frame(s) the menu is.
213          */
214         enum
215         {
216                 MENU_MAINFRM = 0x000001,
217                 MENU_FILECMP = 0x000002,
218                 MENU_FOLDERCMP = 0x000004,
219                 MENU_ALL = MENU_MAINFRM | MENU_FILECMP | MENU_FOLDERCMP
220         };
221
222         /**
223          * A structure attaching a menu item, icon and menu types to apply to.
224          */
225         struct MENUITEM_ICON
226         {
227                 int menuitemID;   /**< Menu item's ID. */
228                 int iconResID;    /**< Icon's resource ID. */
229                 int menusToApply; /**< For which menus to apply. */
230         };
231
232         static const MENUITEM_ICON m_MenuIcons[];
233
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;
238
239 // Generated message map functions
240 protected:
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);
278 #else
279         afx_msg void OnActivateApp(BOOL bActive, HTASK hTask);
280 #endif
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);
323         //}}AFX_MSG
324         DECLARE_MESSAGE_MAP()
325
326 private:
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 );
338 };