OSDN Git Service

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