OSDN Git Service

Merge remote-tracking branch 'upstream/master' into jp
[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 #include "FileOpenFlags.h"
22
23 class BCMenu;
24 class CDirView;
25 class COpenDoc;
26 class CDirDoc;
27 class CMergeDoc;
28 class CHexMergeDoc;
29 class CMergeEditView;
30 class SyntaxColors;
31 class LineFiltersList;
32 class TempFile;
33 struct FileLocation;
34 class DropHandler;
35 class CMainFrame;
36 class CImgMergeFrame;
37 class CWebPageDiffFrame;
38 class DirWatcher;
39
40 typedef std::shared_ptr<TempFile> TempFilePtr;
41
42 // typed lists (homogenous pointer lists)
43 typedef CTypedPtrList<CPtrList, COpenDoc *> OpenDocList;
44 typedef CTypedPtrList<CPtrList, CMergeDoc *> MergeDocList;
45 typedef CTypedPtrList<CPtrList, CDirDoc *> DirDocList;
46 typedef CTypedPtrList<CPtrList, CHexMergeDoc *> HexMergeDocList;
47
48 class PackingInfo;
49 class PrediffingInfo;
50 class CLanguageSelect;
51 struct IMergeDoc;
52
53 CMainFrame * GetMainFrame(); // access to the singleton main frame object
54
55 /**
56  * @brief Frame class containing save-routines etc
57  */
58 class CMainFrame : public CMDIFrameWnd
59 {
60         friend CLanguageSelect;
61         DECLARE_DYNAMIC(CMainFrame)
62 public:
63         /**
64          * @brief Frame/View/Document types.
65          */
66         enum FRAMETYPE
67         {
68                 FRAME_FOLDER, /**< Folder compare frame. */
69                 FRAME_FILE, /**< File compare frame. */
70                 FRAME_HEXFILE, /**< Hex file compare frame. */
71                 FRAME_IMGFILE, /**< Image file compare frame. */
72                 FRAME_WEBPAGE, /**< Web page compare frame. */
73                 FRAME_OTHER, /**< No frame? */
74         };
75
76         struct OpenFileParams
77         {
78                 virtual ~OpenFileParams() {}
79         };
80
81         struct OpenTextFileParams : public OpenFileParams
82         {
83                 virtual ~OpenTextFileParams() {}
84                 int m_line = -1;
85                 int m_char = -1;
86                 String m_fileExt;
87         };
88
89         struct OpenTableFileParams : public OpenTextFileParams
90         {
91                 virtual ~OpenTableFileParams() {}
92                 std::optional<tchar_t> m_tableDelimiter;
93                 std::optional<tchar_t> m_tableQuote;
94                 std::optional<bool> m_tableAllowNewlinesInQuotes;
95         };
96
97         struct OpenBinaryFileParams : public OpenFileParams
98         {
99                 virtual ~OpenBinaryFileParams() {}
100                 int m_address = -1;
101         };
102
103         struct OpenImageFileParams : public OpenFileParams
104         {
105                 virtual ~OpenImageFileParams() {}
106                 int m_x = -1;
107                 int m_y = -1;
108         };
109
110         struct OpenWebPageParams : public OpenFileParams
111         {
112                 virtual ~OpenWebPageParams() {}
113         };
114
115         struct OpenAutoFileParams : public OpenTableFileParams, public OpenBinaryFileParams, public OpenImageFileParams
116         {
117                 virtual ~OpenAutoFileParams() {}
118         };
119
120         struct OpenFolderParams : public OpenFileParams
121         {
122                 virtual ~OpenFolderParams() {}
123                 std::vector<String> m_hiddenItems;
124         };
125
126         CMainFrame();
127
128 // Attributes
129 public: 
130         bool m_bShowErrors; /**< Show folder compare error items? */
131         LOGFONT m_lfDiff; /**< MergeView user-selected font */
132         LOGFONT m_lfDir; /**< DirView user-selected font */
133         static const tchar_t szClassName[];
134
135 // Operations
136 public:
137         HMENU NewDirViewMenu();
138         HMENU NewMergeViewMenu();
139         HMENU NewHexMergeViewMenu();
140         HMENU NewImgMergeViewMenu();
141         HMENU NewWebPageDiffViewMenu();
142         HMENU NewOpenViewMenu();
143         HMENU NewDefaultMenu(int ID = 0);
144         HMENU GetPrediffersSubmenu(HMENU mainMenu);
145         void UpdatePrediffersMenu();
146
147         bool DoFileOrFolderOpen(const PathContext *pFiles = nullptr,
148                 const fileopenflags_t dwFlags[] = nullptr, const String strDesc[] = nullptr,
149                 const String& sReportFile = _T(""), std::optional<bool> bRecurse = false, CDirDoc *pDirDoc = nullptr,
150                 const PackingInfo * infoUnpacker = nullptr, const PrediffingInfo * infoPrediffer = nullptr,
151                 UINT nID = 0, const OpenFileParams *pOpenParams = nullptr);
152         bool DoFileOpen(UINT nID, const PathContext* pFiles,
153                 const fileopenflags_t dwFlags[] = nullptr, const String strDesc[] = nullptr,
154                 const String& sReportFile = _T(""),
155                 const PackingInfo* infoUnpacker = nullptr, const PrediffingInfo * infoPrediffer = nullptr,
156                 const OpenFileParams *pOpenParams = nullptr);
157         bool DoFileNew(UINT nID, int nPanes,
158                 const fileopenflags_t dwFlags[] = nullptr, const String strDesc[] = nullptr,
159                 const PrediffingInfo * infoPrediffer = nullptr,
160                 const OpenFileParams *pOpenParams = nullptr);
161         bool DoOpenConflict(const String& conflictFile, const String strDesc[] = nullptr, bool checked = false);
162         bool DoOpenClipboard(UINT nID = 0, int nBuffers = 2, const fileopenflags_t dwFlags[] = nullptr, const String strDesc[] = nullptr,
163                 const PackingInfo* infoUnpacker = nullptr, const PrediffingInfo * infoPrediffer = nullptr,
164                 const OpenFileParams* pOpenParams = nullptr);
165         bool DoSelfCompare(UINT nID, const String& file, const String strDesc[] = nullptr,
166                 const PackingInfo* infoUnpacker = nullptr, const PrediffingInfo * infoPrediffer = nullptr,
167                 const OpenFileParams* pOpenParams = nullptr);
168         bool ShowAutoMergeDoc(UINT nID, CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
169                 const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
170                 const PackingInfo * infoUnpacker = nullptr, const OpenFileParams *pOpenParams = nullptr);
171         bool ShowMergeDoc(UINT nID, CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
172                 const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
173                 const PackingInfo * infoUnpacker = nullptr, const OpenFileParams *pOpenParams = nullptr);
174         bool ShowTextOrTableMergeDoc(std::optional<bool> table, CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
175                 const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
176                 const PackingInfo * infoUnpacker = nullptr, const OpenTextFileParams *pOpenParams = nullptr);
177         bool ShowTextMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
178                 const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
179                 const PackingInfo * infoUnpacker = nullptr, const OpenTextFileParams *pOpenParams = nullptr);
180         bool ShowTextMergeDoc(CDirDoc* pDirDoc, int nBuffers, const String text[],
181                 const String strDesc[], const String& strFileExt, const OpenTextFileParams *pOpenParams = nullptr);
182         bool ShowTableMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
183                 const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
184                 const PackingInfo * infoUnpacker = nullptr, const OpenTextFileParams *pOpenParams = nullptr);
185         bool ShowHexMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
186                 const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
187                 const PackingInfo * infoUnpacker = nullptr, const OpenBinaryFileParams *pOpenParams = nullptr);
188         bool ShowImgMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
189                 const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
190                 const PackingInfo * infoUnpacker = nullptr, const OpenImageFileParams *pOpenParams = nullptr);
191         bool ShowWebDiffDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
192                 const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile = _T(""),
193                 const PackingInfo * infoUnpacker = nullptr, const OpenWebPageParams *pOpenParams = nullptr);
194
195         void UpdateResources();
196         void ApplyDiffOptions();
197         void SelectFilter();
198         void StartFlashing();
199         bool AskCloseConfirmation();
200         static FRAMETYPE GetFrameType(const CFrameWnd * pFrame);
201         static void UpdateDocTitle();
202         static void ReloadMenu();
203         static void AppendPluginMenus(CMenu* pMenu, const String& filteredFilenames,
204                 const std::vector<std::wstring>& events, bool addAllMenu, unsigned baseId);
205         static String GetPluginPipelineByMenuId(unsigned idSearch, const std::vector<std::wstring>& events, unsigned baseId);
206         DropHandler *GetDropHandler() const { return m_pDropHandler; }
207         const CTypedPtrArray<CPtrArray, CMDIChildWnd*>* GetChildArray() const { return &m_arrChild; }
208         IMergeDoc* GetActiveIMergeDoc();
209         DirWatcher* GetDirWatcher() { return m_pDirWatcher.get(); }
210         void WatchDocuments(IMergeDoc* pMergeDoc);
211         void UnwatchDocuments(IMergeDoc* pMergeDoc);
212         CToolBar* GetToolbar() { return &m_wndToolBar; }
213
214 // Overrides
215         virtual void GetMessageString(UINT nID, CString& rMessage) const;
216         // ClassWizard generated virtual function overrides
217         //{{AFX_VIRTUAL(CMainFrame)
218 public:
219         virtual void ActivateFrame(int nCmdShow = -1);
220         virtual BOOL PreTranslateMessage(MSG* pMsg);
221         virtual void OnUpdateFrameTitle(BOOL bAddToTitle);
222         virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
223         //}}AFX_VIRTUAL
224
225 // Implementation methods
226 protected:
227         virtual ~CMainFrame();
228
229 // Public implementation data
230 public:
231         bool m_bFirstTime; /**< If first time frame activated, get  pos from reg */
232
233 // Implementation data
234 protected:
235         // control bar embedded members
236         CStatusBar  m_wndStatusBar;
237         CReBar m_wndReBar;
238         CToolBar m_wndToolBar;
239         CMDITabBar m_wndTabBar;
240         CTypedPtrArray<CPtrArray, CMDIChildWnd*> m_arrChild;
241
242         // Tweak MDI client window behavior
243         class CMDIClient : public CWnd
244         {
245                 static UINT_PTR const m_nRedrawTimer = 1612;
246                 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
247                 {
248                         switch (message)
249                         {
250                         case WM_MDICREATE:
251                         case WM_MDIACTIVATE:
252                         {
253                                 // To reduce flicker in maximized state, disable drawing while messing with MDI child frames
254                                 BOOL bMaximized;
255                                 HWND hwndActive = reinterpret_cast<HWND>(SendMessage(WM_MDIGETACTIVE, 0, reinterpret_cast<LPARAM>(&bMaximized)));
256                                 if ((bMaximized || (message == WM_MDICREATE && !hwndActive)) &&
257                                         SetTimer(m_nRedrawTimer, USER_TIMER_MINIMUM, nullptr))
258                                 {
259                                         SetRedraw(FALSE);
260                                 }
261                                 break;
262                         }
263                         case WM_TIMER:
264                                 if (wParam == m_nRedrawTimer)
265                                 {
266                                         KillTimer(m_nRedrawTimer);
267                                         SetRedraw(TRUE);
268                                         RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE);
269                                 }
270                                 break;
271                         }
272                         return CWnd::WindowProc(message, wParam, lParam);
273                 }
274         } m_wndMDIClient;
275
276         enum
277         {
278                 MENU_DEFAULT,
279                 MENU_MERGEVIEW,
280                 MENU_DIRVIEW,
281                 MENU_HEXMERGEVIEW,
282                 MENU_IMGMERGEVIEW,
283                 MENU_WEBPAGEDIFFVIEW,
284                 MENU_OPENVIEW,
285                 MENU_COUNT, // Add new items before this item
286         };
287         /**
288          * Menu frames - for which frame(s) the menu is.
289          */
290         enum
291         {
292                 MENU_MAINFRM = 0x000001,
293                 MENU_FILECMP = 0x000002,
294                 MENU_FOLDERCMP = 0x000004,
295                 MENU_ALL = MENU_MAINFRM | MENU_FILECMP | MENU_FOLDERCMP
296         };
297         enum
298         {
299                 AUTO_RELOAD_MODIFIED_FILES_DISABLED,
300                 AUTO_RELOAD_MODIFIED_FILES_ONWINDOWACTIVATED,
301                 AUTO_RELOAD_MODIFIED_FILES_IMMEDIATELY
302         };
303
304         /**
305          * A structure attaching a menu item, icon and menu types to apply to.
306          */
307         struct MENUITEM_ICON
308         {
309                 int menuitemID;   /**< Menu item's ID. */
310                 int iconResID;    /**< Icon's resource ID. */
311                 int menusToApply; /**< For which menus to apply. */
312         };
313
314         static const MENUITEM_ICON m_MenuIcons[];
315
316         std::unique_ptr<BCMenu> m_pMenus[MENU_COUNT]; /**< Menus for different views */
317         std::unique_ptr<BCMenu> m_pImageMenu;
318         std::unique_ptr<BCMenu> m_pWebPageMenu;
319         std::vector<TempFilePtr> m_tempFiles; /**< List of possibly needed temp files. */
320         DropHandler *m_pDropHandler;
321         std::unique_ptr<DirWatcher> m_pDirWatcher;
322
323 // Generated message map functions
324 protected:
325         //{{AFX_MSG(CMainFrame)
326         afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);
327         afx_msg LRESULT OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu) ;
328         afx_msg void OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu);
329         afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
330         afx_msg void OnFileOpen();
331         afx_msg void OnHelpGnulicense();
332         afx_msg void OnOptions();
333         afx_msg void OnViewSelectfont();
334         afx_msg void OnViewUsedefaultfont();
335         afx_msg void OnHelpContents();
336         afx_msg void OnClose();
337         afx_msg void OnToolsGeneratePatch();
338         afx_msg void OnDropFiles(const std::vector<String>& files);
339         afx_msg void OnUpdatePluginUnpackMode(CCmdUI* pCmdUI);
340         afx_msg void OnPluginUnpackMode(UINT nID);
341         afx_msg void OnUpdatePluginPrediffMode(CCmdUI* pCmdUI);
342         afx_msg void OnPluginPrediffMode(UINT nID);
343         afx_msg void OnUpdatePluginRelatedMenu(CCmdUI* pCmdUI);
344         afx_msg void OnReloadPlugins();
345         afx_msg void OnSaveConfigData();
346         template <int nFiles, unsigned nID>
347         afx_msg void OnFileNew() { DoFileNew(nID, nFiles); }
348         afx_msg void OnToolsFilters();
349         afx_msg void OnViewStatusBar();
350         afx_msg void OnUpdateViewTabBar(CCmdUI* pCmdUI);
351         afx_msg void OnViewTabBar();
352         afx_msg void OnUpdateResizePanes(CCmdUI* pCmdUI);
353         afx_msg void OnResizePanes();
354         afx_msg void OnFileOpenProject();
355         afx_msg LRESULT OnCopyData(WPARAM wParam, LPARAM lParam);
356         afx_msg LRESULT OnUser1(WPARAM wParam, LPARAM lParam);
357         afx_msg void OnWindowCloseAll();
358         afx_msg void OnUpdateWindowCloseAll(CCmdUI* pCmdUI);
359         afx_msg void OnSaveProject();
360 #if _MFC_VER > 0x0600
361         afx_msg void OnActivateApp(BOOL bActive, DWORD dwThreadID);
362 #else
363         afx_msg void OnActivateApp(BOOL bActive, HTASK hTask);
364 #endif
365         afx_msg void OnToolbarSize(UINT id);
366         afx_msg void OnUpdateToolbarSize(CCmdUI* pCmdUI);
367         afx_msg BOOL OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult);
368         afx_msg void OnHelpReleasenotes();
369         afx_msg void OnHelpTranslations();
370         afx_msg void OnHelpCheckForUpdates();
371         afx_msg void OnUpdateHelpCheckForUpdates(CCmdUI* pCmdUI);
372         afx_msg void OnFileOpenConflict();
373         afx_msg void OnFileOpenClipboard();
374         afx_msg void OnPluginsList();
375         afx_msg void OnUpdatePluginName(CCmdUI* pCmdUI);
376         afx_msg void OnUpdateStatusNum(CCmdUI* pCmdUI);
377         afx_msg void OnToolbarButtonDropDown(NMHDR* pNMHDR, LRESULT* pResult);
378         afx_msg void OnDiffWhitespace(UINT nID);
379         afx_msg void OnUpdateDiffWhitespace(CCmdUI* pCmdUI);
380         afx_msg void OnDiffIgnoreBlankLines();
381         afx_msg void OnUpdateDiffIgnoreBlankLines(CCmdUI* pCmdUI);
382         afx_msg void OnDiffIgnoreCase();
383         afx_msg void OnUpdateDiffIgnoreCase(CCmdUI* pCmdUI);
384         afx_msg void OnDiffIgnoreNumbers();
385         afx_msg void OnUpdateDiffIgnoreNumbers(CCmdUI* pCmdUI);
386         afx_msg void OnDiffIgnoreEOL();
387         afx_msg void OnUpdateDiffIgnoreEOL(CCmdUI* pCmdUI);
388         afx_msg void OnDiffIgnoreCP();
389         afx_msg void OnUpdateDiffIgnoreCP(CCmdUI* pCmdUI);
390         afx_msg void OnDiffIgnoreComments();
391         afx_msg void OnUpdateDiffIgnoreComments(CCmdUI* pCmdUI);
392         afx_msg void OnIncludeSubfolders();
393         afx_msg void OnUpdateIncludeSubfolders(CCmdUI* pCmdUI);
394         afx_msg void OnCompareMethod(UINT nID);
395         afx_msg void OnUpdateCompareMethod(CCmdUI* pCmdUI);
396         afx_msg void OnMRUs(UINT nID);
397         afx_msg void OnUpdateNoMRUs(CCmdUI* pCmdUI);
398         afx_msg void OnFirstFile();
399         afx_msg void OnUpdateFirstFile(CCmdUI* pCmdUI);
400         afx_msg void OnPrevFile();
401         afx_msg void OnUpdatePrevFile(CCmdUI* pCmdUI);
402         afx_msg void OnNextFile();
403         afx_msg void OnUpdateNextFile(CCmdUI* pCmdUI);
404         afx_msg void OnLastFile();
405         afx_msg void OnUpdateLastFile(CCmdUI* pCmdUI);
406         afx_msg void OnTimer(UINT_PTR nIDEvent);
407         afx_msg void OnDestroy();
408         afx_msg void OnAccelQuit();
409         afx_msg LRESULT OnChildFrameAdded(WPARAM wParam, LPARAM lParam);
410         afx_msg LRESULT OnChildFrameRemoved(WPARAM wParam, LPARAM lParam);
411         afx_msg LRESULT OnChildFrameActivate(WPARAM wParam, LPARAM lParam);
412         afx_msg LRESULT OnChildFrameActivated(WPARAM wParam, LPARAM lParam);
413         //}}AFX_MSG
414         DECLARE_MESSAGE_MAP()
415
416 private:
417         void addToMru(const tchar_t* szItem, const tchar_t* szRegSubKey, UINT nMaxItems = 20);
418         OpenDocList &GetAllOpenDocs();
419         MergeDocList &GetAllMergeDocs();
420         DirDocList &GetAllDirDocs();
421         HexMergeDocList &GetAllHexMergeDocs();
422         std::vector<CImgMergeFrame *> GetAllImgMergeFrames();
423         std::vector<CWebPageDiffFrame *> GetAllWebPageDiffFrames();
424         void UpdateFont(FRAMETYPE frame);
425         BOOL CreateToolbar();
426         CMergeEditView * GetActiveMergeEditView();
427         void LoadToolbarImages();
428         HMENU NewMenu( int view, int ID );
429 };