OSDN Git Service

Merge pull request #247 from mesajflaviu/new_branch
[winmerge-jp/winmerge-jp.git] / Src / MainFrm.h
1 /////////////////////////////////////////////////////////////////////////////
2 //    WinMerge:  an interactive diff/merge utility
3 //    Copyright (C) 1997  Dean P. Grimm
4 //
5 //    This program is free software; you can redistribute it and/or modify
6 //    it under the terms of the GNU General Public License as published by
7 //    the Free Software Foundation; either version 2 of the License, or
8 //    (at your option) any later version.
9 //
10 //    This program is distributed in the hope that it will be useful,
11 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //    GNU General Public License for more details.
14 //
15 //    You should have received a copy of the GNU General Public License
16 //    along with this program; if not, write to the Free Software
17 //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //
19 /////////////////////////////////////////////////////////////////////////////
20 /** 
21  * @file  MainFrm.h
22  *
23  * @brief Declaration file for CMainFrame
24  *
25  */
26 #pragma once
27
28 #include <vector>
29 #include <memory>
30 #include "MDITabBar.h"
31 #include "PathContext.h"
32
33 class BCMenu;
34 class CDirView;
35 class COpenDoc;
36 class CDirDoc;
37 class CMergeDoc;
38 class CHexMergeDoc;
39 class CMergeEditView;
40 class SyntaxColors;
41 class LineFiltersList;
42 class TempFile;
43 struct FileLocation;
44 class DropHandler;
45 class CMainFrame;
46
47 typedef std::shared_ptr<TempFile> TempFilePtr;
48
49 // typed lists (homogenous pointer lists)
50 typedef CTypedPtrList<CPtrList, COpenDoc *> OpenDocList;
51 typedef CTypedPtrList<CPtrList, CMergeDoc *> MergeDocList;
52 typedef CTypedPtrList<CPtrList, CDirDoc *> DirDocList;
53 typedef CTypedPtrList<CPtrList, CHexMergeDoc *> HexMergeDocList;
54
55 class PackingInfo;
56 class CLanguageSelect;
57
58 CMainFrame * GetMainFrame(); // access to the singleton main frame object
59
60 /**
61  * @brief Frame class containing save-routines etc
62  */
63 class CMainFrame : public CMDIFrameWnd
64 {
65         friend CLanguageSelect;
66         DECLARE_DYNAMIC(CMainFrame)
67 public:
68         /**
69          * @brief Frame/View/Document types.
70          */
71         enum FRAMETYPE
72         {
73                 FRAME_FOLDER, /**< Folder compare frame. */
74                 FRAME_FILE, /**< File compare frame. */
75                 FRAME_HEXFILE, /**< Hex file compare frame. */
76                 FRAME_IMGFILE, /**< Image file compare frame. */
77                 FRAME_OTHER, /**< No frame? */
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 GetScriptsSubmenu(HMENU mainMenu);
98         HMENU GetPrediffersSubmenu(HMENU mainMenu);
99         void UpdatePrediffersMenu();
100
101         void FileNew(int nPanes);
102         bool DoFileOpen(const PathContext *pFiles = nullptr,
103                 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);
104         bool ShowAutoMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
105                 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""), const PackingInfo * infoUnpacker = nullptr);
106         bool ShowMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
107                 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""), const PackingInfo * infoUnpacker = nullptr);
108         bool ShowHexMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
109                 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""), const PackingInfo * infoUnpacker = nullptr);
110         bool ShowImgMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
111                 const DWORD dwFlags[], const String strDesc[], const String& sReportFile = _T(""), const PackingInfo * infoUnpacker = nullptr);
112
113         void UpdateResources();
114         void ClearStatusbarItemCount();
115         void ApplyDiffOptions();
116         void SelectFilter();
117         void StartFlashing();
118         bool AskCloseConfirmation();
119         bool DoOpenConflict(const String& conflictFile, const String strDesc[] = nullptr, bool checked = false);
120         FRAMETYPE GetFrameType(const CFrameWnd * pFrame) const;
121         void UpdateDocTitle();
122         void ReloadMenu();
123         DropHandler *GetDropHandler() const { return m_pDropHandler; }
124         const CTypedPtrArray<CPtrArray, CMDIChildWnd*>* GetChildArray() const { return &m_arrChild; }
125
126 // Overrides
127         virtual void GetMessageString(UINT nID, CString& rMessage) const;
128         // ClassWizard generated virtual function overrides
129         //{{AFX_VIRTUAL(CMainFrame)
130 public:
131         virtual void ActivateFrame(int nCmdShow = -1);
132         virtual BOOL PreTranslateMessage(MSG* pMsg);
133         virtual void OnUpdateFrameTitle(BOOL bAddToTitle);
134         virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
135         //}}AFX_VIRTUAL
136
137 // Implementation methods
138 protected:
139         virtual ~CMainFrame();
140
141 // Public implementation data
142 public:
143         bool m_bFirstTime; /**< If first time frame activated, get  pos from reg */
144
145 // Implementation data
146 protected:
147         // control bar embedded members
148         CStatusBar  m_wndStatusBar;
149         CReBar m_wndReBar;
150         CToolBar m_wndToolBar;
151         CMDITabBar m_wndTabBar;
152         CTypedPtrArray<CPtrArray, CMDIChildWnd*> m_arrChild;
153
154         // Tweak MDI client window behavior
155         class CMDIClient : public CWnd
156         {
157                 static UINT_PTR const m_nRedrawTimer = 1612;
158                 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
159                 {
160                         switch (message)
161                         {
162                         case WM_MDICREATE:
163                         case WM_MDIACTIVATE:
164                                 // To reduce flicker in maximized state, disable drawing while messing with MDI child frames
165                                 BOOL bMaximized;
166                                 if ((message == WM_MDICREATE || (SendMessage(WM_MDIGETACTIVE, 0, reinterpret_cast<LPARAM>(&bMaximized))
167                                         && bMaximized)) && SetTimer(m_nRedrawTimer, USER_TIMER_MINIMUM, nullptr))
168                                 {
169                                         SetRedraw(FALSE);
170                                 }
171                                 break;
172                         case WM_TIMER:
173                                 if (wParam == m_nRedrawTimer)
174                                 {
175                                         KillTimer(m_nRedrawTimer);
176                                         SetRedraw(TRUE);
177                                         RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE);
178                                         GetMainFrame()->GetActiveFrame()->OnUpdateFrameTitle(TRUE);
179                                         GetMainFrame()->SendMessageToDescendants(WM_IDLEUPDATECMDUI, (WPARAM)TRUE, 0, TRUE, TRUE);
180                                 }
181                                 break;
182                         }
183                         return CWnd::WindowProc(message, wParam, lParam);
184                 }
185         } m_wndMDIClient;
186
187         /** @brief Toolbar image table indexes. */
188         enum TOOLBAR_IMAGES
189         {
190                 TOOLBAR_IMAGES_ENABLED,
191                 TOOLBAR_IMAGES_DISABLED,
192                 TOOLBAR_IMAGES_COUNT
193         };
194
195         CImageList m_ToolbarImages[TOOLBAR_IMAGES_COUNT]; /**< Images for toolbar */
196
197         enum
198         {
199                 MENU_DEFAULT,
200                 MENU_MERGEVIEW,
201                 MENU_DIRVIEW,
202                 MENU_HEXMERGEVIEW,
203                 MENU_IMGMERGEVIEW,
204                 MENU_OPENVIEW,
205                 MENU_COUNT, // Add new items before this item
206         };
207         /**
208          * Menu frames - for which frame(s) the menu is.
209          */
210         enum
211         {
212                 MENU_MAINFRM = 0x000001,
213                 MENU_FILECMP = 0x000002,
214                 MENU_FOLDERCMP = 0x000004,
215                 MENU_ALL = MENU_MAINFRM | MENU_FILECMP | MENU_FOLDERCMP
216         };
217
218         /**
219          * A structure attaching a menu item, icon and menu types to apply to.
220          */
221         struct MENUITEM_ICON
222         {
223                 int menuitemID;   /**< Menu item's ID. */
224                 int iconResID;    /**< Icon's resource ID. */
225                 int menusToApply; /**< For which menus to apply. */
226         };
227
228         static const MENUITEM_ICON m_MenuIcons[];
229
230         std::unique_ptr<BCMenu> m_pMenus[MENU_COUNT]; /**< Menus for different views */
231         std::vector<TempFilePtr> m_tempFiles; /**< List of possibly needed temp files. */
232         DropHandler *m_pDropHandler;
233
234 // Generated message map functions
235 protected:
236         //{{AFX_MSG(CMainFrame)
237         afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);
238         afx_msg LRESULT OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu) ;
239         afx_msg void OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu);
240         afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
241         afx_msg void OnFileOpen();
242         afx_msg void OnHelpGnulicense();
243         afx_msg void OnOptions();
244         afx_msg void OnViewSelectfont();
245         afx_msg void OnViewUsedefaultfont();
246         afx_msg void OnHelpContents();
247         afx_msg void OnClose();
248         afx_msg void OnToolsGeneratePatch();
249         afx_msg void OnDropFiles(const std::vector<String>& files);
250         afx_msg void OnUpdatePluginUnpackMode(CCmdUI* pCmdUI);
251         afx_msg void OnPluginUnpackMode(UINT nID);
252         afx_msg void OnUpdatePluginPrediffMode(CCmdUI* pCmdUI);
253         afx_msg void OnPluginPrediffMode(UINT nID);
254         afx_msg void OnUpdateReloadPlugins(CCmdUI* pCmdUI);
255         afx_msg void OnReloadPlugins();
256         afx_msg void OnSaveConfigData();
257         afx_msg void OnFileNew();
258         afx_msg void OnFileNew3();
259         afx_msg void OnToolsFilters();
260         afx_msg void OnViewStatusBar();
261         afx_msg void OnUpdateViewTabBar(CCmdUI* pCmdUI);
262         afx_msg void OnViewTabBar();
263         afx_msg void OnUpdateResizePanes(CCmdUI* pCmdUI);
264         afx_msg void OnResizePanes();
265         afx_msg void OnFileOpenProject();
266         afx_msg LRESULT OnCopyData(WPARAM wParam, LPARAM lParam);
267         afx_msg LRESULT OnUser1(WPARAM wParam, LPARAM lParam);
268         afx_msg void OnWindowCloseAll();
269         afx_msg void OnUpdateWindowCloseAll(CCmdUI* pCmdUI);
270         afx_msg void OnSaveProject();
271 #if _MFC_VER > 0x0600
272         afx_msg void OnActivateApp(BOOL bActive, DWORD dwThreadID);
273 #else
274         afx_msg void OnActivateApp(BOOL bActive, HTASK hTask);
275 #endif
276         afx_msg void OnToolbarSize(UINT id);
277         afx_msg void OnUpdateToolbarSize(CCmdUI* pCmdUI);
278         afx_msg BOOL OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult);
279         afx_msg void OnHelpReleasenotes();
280         afx_msg void OnHelpTranslations();
281         afx_msg void OnFileOpenConflict();
282         afx_msg void OnPluginsList();
283         afx_msg void OnUpdatePluginName(CCmdUI* pCmdUI);
284         afx_msg void OnDiffOptionsDropDown(NMHDR* pNMHDR, LRESULT* pResult);
285         afx_msg void OnDiffWhitespace(UINT nID);
286         afx_msg void OnUpdateDiffWhitespace(CCmdUI* pCmdUI);
287         afx_msg void OnDiffCaseSensitive();
288         afx_msg void OnUpdateDiffCaseSensitive(CCmdUI* pCmdUI);
289         afx_msg void OnDiffIgnoreEOL();
290         afx_msg void OnUpdateDiffIgnoreEOL(CCmdUI* pCmdUI);
291         afx_msg void OnDiffIgnoreCP();
292         afx_msg void OnUpdateDiffIgnoreCP(CCmdUI* pCmdUI);
293         afx_msg void OnIncludeSubfolders();
294         afx_msg void OnUpdateIncludeSubfolders(CCmdUI* pCmdUI);
295         afx_msg void OnCompareMethod(UINT nID);
296         afx_msg void OnUpdateCompareMethod(CCmdUI* pCmdUI);
297         afx_msg void OnMRUs(UINT nID);
298         afx_msg void OnUpdateNoMRUs(CCmdUI* pCmdUI);
299         afx_msg void OnDestroy();
300         afx_msg void OnAccelQuit();
301         //}}AFX_MSG
302         afx_msg LRESULT OnChildFrameAdded(WPARAM wParam, LPARAM lParam);
303         afx_msg LRESULT OnChildFrameRemoved(WPARAM wParam, LPARAM lParam);
304         afx_msg LRESULT OnChildFrameActivate(WPARAM wParam, LPARAM lParam);
305         afx_msg LRESULT OnChildFrameActivated(WPARAM wParam, LPARAM lParam);
306         DECLARE_MESSAGE_MAP()
307
308 private:
309         void addToMru(LPCTSTR szItem, LPCTSTR szRegSubKey, UINT nMaxItems = 20);
310         OpenDocList &GetAllOpenDocs();
311         MergeDocList &GetAllMergeDocs();
312         DirDocList &GetAllDirDocs();
313         HexMergeDocList &GetAllHexMergeDocs();
314         void UpdateFont(FRAMETYPE frame);
315         BOOL CreateToolbar();
316         CMergeEditView * GetActiveMergeEditView();
317         void LoadToolbarImages();
318         HMENU NewMenu( int view, int ID );
319 };