OSDN Git Service

Fix the issue where the Apache Tika plugin becomes enabled again when reopening the...
[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         static void WaitAndDoMessageLoop(bool& completed, int ms);
214
215 // Overrides
216         virtual void GetMessageString(UINT nID, CString& rMessage) const;
217         // ClassWizard generated virtual function overrides
218         //{{AFX_VIRTUAL(CMainFrame)
219 public:
220         virtual void ActivateFrame(int nCmdShow = -1);
221         virtual BOOL PreTranslateMessage(MSG* pMsg);
222         virtual void OnUpdateFrameTitle(BOOL bAddToTitle);
223         virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
224         //}}AFX_VIRTUAL
225
226 // Implementation methods
227 protected:
228         virtual ~CMainFrame();
229
230 // Public implementation data
231 public:
232         bool m_bFirstTime; /**< If first time frame activated, get  pos from reg */
233
234 // Implementation data
235 protected:
236         // control bar embedded members
237         CStatusBar  m_wndStatusBar;
238         CReBar m_wndReBar;
239         CToolBar m_wndToolBar;
240         CMDITabBar m_wndTabBar;
241         CTypedPtrArray<CPtrArray, CMDIChildWnd*> m_arrChild;
242
243         // Tweak MDI client window behavior
244         class CMDIClient : public CWnd
245         {
246                 static UINT_PTR const m_nRedrawTimer = 1612;
247                 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
248                 {
249                         switch (message)
250                         {
251                         case WM_MDICREATE:
252                         case WM_MDIACTIVATE:
253                         {
254                                 // To reduce flicker in maximized state, disable drawing while messing with MDI child frames
255                                 BOOL bMaximized;
256                                 HWND hwndActive = reinterpret_cast<HWND>(SendMessage(WM_MDIGETACTIVE, 0, reinterpret_cast<LPARAM>(&bMaximized)));
257                                 if ((bMaximized || (message == WM_MDICREATE && !hwndActive)) &&
258                                         SetTimer(m_nRedrawTimer, USER_TIMER_MINIMUM, nullptr))
259                                 {
260                                         SetRedraw(FALSE);
261                                 }
262                                 break;
263                         }
264                         case WM_TIMER:
265                                 if (wParam == m_nRedrawTimer)
266                                 {
267                                         KillTimer(m_nRedrawTimer);
268                                         SetRedraw(TRUE);
269                                         RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE);
270                                 }
271                                 break;
272                         }
273                         return CWnd::WindowProc(message, wParam, lParam);
274                 }
275         } m_wndMDIClient;
276
277         enum
278         {
279                 MENU_DEFAULT,
280                 MENU_MERGEVIEW,
281                 MENU_DIRVIEW,
282                 MENU_HEXMERGEVIEW,
283                 MENU_IMGMERGEVIEW,
284                 MENU_WEBPAGEDIFFVIEW,
285                 MENU_OPENVIEW,
286                 MENU_COUNT, // Add new items before this item
287         };
288         /**
289          * Menu frames - for which frame(s) the menu is.
290          */
291         enum
292         {
293                 MENU_MAINFRM = 0x000001,
294                 MENU_FILECMP = 0x000002,
295                 MENU_FOLDERCMP = 0x000004,
296                 MENU_ALL = MENU_MAINFRM | MENU_FILECMP | MENU_FOLDERCMP
297         };
298         enum
299         {
300                 AUTO_RELOAD_MODIFIED_FILES_DISABLED,
301                 AUTO_RELOAD_MODIFIED_FILES_ONWINDOWACTIVATED,
302                 AUTO_RELOAD_MODIFIED_FILES_IMMEDIATELY
303         };
304
305         /**
306          * A structure attaching a menu item, icon and menu types to apply to.
307          */
308         struct MENUITEM_ICON
309         {
310                 int menuitemID;   /**< Menu item's ID. */
311                 int iconResID;    /**< Icon's resource ID. */
312                 int menusToApply; /**< For which menus to apply. */
313         };
314
315         static const MENUITEM_ICON m_MenuIcons[];
316
317         std::unique_ptr<BCMenu> m_pMenus[MENU_COUNT]; /**< Menus for different views */
318         std::unique_ptr<BCMenu> m_pImageMenu;
319         std::unique_ptr<BCMenu> m_pWebPageMenu;
320         std::vector<TempFilePtr> m_tempFiles; /**< List of possibly needed temp files. */
321         DropHandler *m_pDropHandler;
322         std::unique_ptr<DirWatcher> m_pDirWatcher;
323
324 // Generated message map functions
325 protected:
326         //{{AFX_MSG(CMainFrame)
327         afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);
328         afx_msg LRESULT OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu) ;
329         afx_msg void OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu);
330         afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
331         afx_msg void OnFileOpen();
332         afx_msg void OnHelpGnulicense();
333         afx_msg void OnOptions();
334         afx_msg void OnViewSelectfont();
335         afx_msg void OnViewUsedefaultfont();
336         afx_msg void OnHelpContents();
337         afx_msg void OnClose();
338         afx_msg void OnToolsGeneratePatch();
339         afx_msg void OnDropFiles(const std::vector<String>& files);
340         afx_msg void OnUpdatePluginUnpackMode(CCmdUI* pCmdUI);
341         afx_msg void OnPluginUnpackMode(UINT nID);
342         afx_msg void OnUpdatePluginPrediffMode(CCmdUI* pCmdUI);
343         afx_msg void OnPluginPrediffMode(UINT nID);
344         afx_msg void OnUpdatePluginRelatedMenu(CCmdUI* pCmdUI);
345         afx_msg void OnReloadPlugins();
346         afx_msg void OnSaveConfigData();
347         template <int nFiles, unsigned nID>
348         afx_msg void OnFileNew() { DoFileNew(nID, nFiles); }
349         afx_msg void OnToolsFilters();
350         afx_msg void OnViewStatusBar();
351         afx_msg void OnUpdateViewTabBar(CCmdUI* pCmdUI);
352         afx_msg void OnViewTabBar();
353         afx_msg void OnUpdateResizePanes(CCmdUI* pCmdUI);
354         afx_msg void OnResizePanes();
355         afx_msg void OnFileOpenProject();
356         afx_msg LRESULT OnCopyData(WPARAM wParam, LPARAM lParam);
357         afx_msg LRESULT OnUser1(WPARAM wParam, LPARAM lParam);
358         afx_msg void OnWindowCloseAll();
359         afx_msg void OnUpdateWindowCloseAll(CCmdUI* pCmdUI);
360         afx_msg void OnSaveProject();
361 #if _MFC_VER > 0x0600
362         afx_msg void OnActivateApp(BOOL bActive, DWORD dwThreadID);
363 #else
364         afx_msg void OnActivateApp(BOOL bActive, HTASK hTask);
365 #endif
366         afx_msg void OnToolbarSize(UINT id);
367         afx_msg void OnUpdateToolbarSize(CCmdUI* pCmdUI);
368         afx_msg BOOL OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult);
369         afx_msg void OnHelpReleasenotes();
370         afx_msg void OnHelpTranslations();
371         afx_msg void OnFileOpenConflict();
372         afx_msg void OnFileOpenClipboard();
373         afx_msg void OnPluginsList();
374         afx_msg void OnUpdatePluginName(CCmdUI* pCmdUI);
375         afx_msg void OnUpdateStatusNum(CCmdUI* pCmdUI);
376         afx_msg void OnToolbarButtonDropDown(NMHDR* pNMHDR, LRESULT* pResult);
377         afx_msg void OnDiffWhitespace(UINT nID);
378         afx_msg void OnUpdateDiffWhitespace(CCmdUI* pCmdUI);
379         afx_msg void OnDiffIgnoreBlankLines();
380         afx_msg void OnUpdateDiffIgnoreBlankLines(CCmdUI* pCmdUI);
381         afx_msg void OnDiffIgnoreCase();
382         afx_msg void OnUpdateDiffIgnoreCase(CCmdUI* pCmdUI);
383         afx_msg void OnDiffIgnoreNumbers();
384         afx_msg void OnUpdateDiffIgnoreNumbers(CCmdUI* pCmdUI);
385         afx_msg void OnDiffIgnoreEOL();
386         afx_msg void OnUpdateDiffIgnoreEOL(CCmdUI* pCmdUI);
387         afx_msg void OnDiffIgnoreCP();
388         afx_msg void OnUpdateDiffIgnoreCP(CCmdUI* pCmdUI);
389         afx_msg void OnDiffIgnoreComments();
390         afx_msg void OnUpdateDiffIgnoreComments(CCmdUI* pCmdUI);
391         afx_msg void OnIncludeSubfolders();
392         afx_msg void OnUpdateIncludeSubfolders(CCmdUI* pCmdUI);
393         afx_msg void OnCompareMethod(UINT nID);
394         afx_msg void OnUpdateCompareMethod(CCmdUI* pCmdUI);
395         afx_msg void OnMRUs(UINT nID);
396         afx_msg void OnUpdateNoMRUs(CCmdUI* pCmdUI);
397         afx_msg void OnFirstFile();
398         afx_msg void OnUpdateFirstFile(CCmdUI* pCmdUI);
399         afx_msg void OnPrevFile();
400         afx_msg void OnUpdatePrevFile(CCmdUI* pCmdUI);
401         afx_msg void OnNextFile();
402         afx_msg void OnUpdateNextFile(CCmdUI* pCmdUI);
403         afx_msg void OnLastFile();
404         afx_msg void OnUpdateLastFile(CCmdUI* pCmdUI);
405         afx_msg void OnTimer(UINT_PTR nIDEvent);
406         afx_msg void OnDestroy();
407         afx_msg void OnAccelQuit();
408         afx_msg LRESULT OnChildFrameAdded(WPARAM wParam, LPARAM lParam);
409         afx_msg LRESULT OnChildFrameRemoved(WPARAM wParam, LPARAM lParam);
410         afx_msg LRESULT OnChildFrameActivate(WPARAM wParam, LPARAM lParam);
411         afx_msg LRESULT OnChildFrameActivated(WPARAM wParam, LPARAM lParam);
412         //}}AFX_MSG
413         DECLARE_MESSAGE_MAP()
414
415 private:
416         void addToMru(const tchar_t* szItem, const tchar_t* szRegSubKey, UINT nMaxItems = 20);
417         OpenDocList &GetAllOpenDocs();
418         MergeDocList &GetAllMergeDocs();
419         DirDocList &GetAllDirDocs();
420         HexMergeDocList &GetAllHexMergeDocs();
421         std::vector<CImgMergeFrame *> GetAllImgMergeFrames();
422         std::vector<CWebPageDiffFrame *> GetAllWebPageDiffFrames();
423         void UpdateFont(FRAMETYPE frame);
424         BOOL CreateToolbar();
425         CMergeEditView * GetActiveMergeEditView();
426         void LoadToolbarImages();
427         HMENU NewMenu( int view, int ID );
428 };