OSDN Git Service

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