OSDN Git Service

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