OSDN Git Service

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