OSDN Git Service

Fix build errors
[winmerge-jp/winmerge-jp.git] / Src / Merge.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  Merge.h
8  *
9  * @brief main header file for the MERGE application
10  *
11  */
12 #pragma once
13
14 #define WMU_CHILDFRAMEADDED                                             (WM_APP + 10)
15 #define WMU_CHILDFRAMEREMOVED                                   (WM_APP + 11)
16 #define WMU_CHILDFRAMEACTIVATE                                  (WM_APP + 12)
17 #define WMU_CHILDFRAMEACTIVATED                                 (WM_APP + 13)
18 #define IDT_UPDATEMAINMENU 1
19
20 #ifndef __AFXWIN_H__
21         #error include 'stdafx.h' before including this file for PCH
22 #endif
23
24 #include <memory>
25 #include "MergeCmdLineInfo.h"
26 #include "resource.h"       // main symbols
27
28 struct FileFilter;
29 class FileFilterHelper;
30 class CAssureScriptsForThread;
31 class CMainFrame;
32 class CLanguageSelect;
33 class MergeCmdLineInfo;
34 class ProjectFile;
35 class COptionsMgr;
36 class LineFiltersList;
37 class SubstitutionFiltersList;
38 class SyntaxColors;
39 class CCrystalTextMarkers;
40
41 /////////////////////////////////////////////////////////////////////////////
42 // CMergeApp:
43 // See Merge.cpp for the implementation of this class
44 //
45
46 enum { IDLE_TIMER = 9754 };
47
48 /**
49  * @brief WinMerge application class
50  */
51 class CMergeApp : public CWinApp
52 {
53 public:
54         bool m_bNeedIdleTimer;
55         CMultiDocTemplate* m_pOpenTemplate;
56         CMultiDocTemplate* m_pDiffTemplate;
57         CMultiDocTemplate* m_pHexMergeTemplate;
58         CMultiDocTemplate* m_pDirTemplate;
59         std::unique_ptr<CLanguageSelect> m_pLangDlg;
60         std::unique_ptr<FileFilterHelper> m_pGlobalFileFilter;
61         std::unique_ptr<SyntaxColors> m_pSyntaxColors; /**< Syntax color container */
62         std::unique_ptr<CCrystalTextMarkers> m_pMarkers; /**< Marker container */
63         String m_strSaveAsPath; /**< "3rd path" where output saved if given */
64         bool m_bEscShutdown; /**< If commandline switch -e given ESC closes appliction */
65         SyntaxColors * GetMainSyntaxColors() { return m_pSyntaxColors.get(); }
66         CCrystalTextMarkers * GetMainMarkers() const { return m_pMarkers.get(); }
67         MergeCmdLineInfo::ExitNoDiff m_bExitIfNoDiff; /**< Exit if files are identical? */
68         std::unique_ptr<LineFiltersList> m_pLineFilters; /**< List of linefilters */
69         std::unique_ptr<SubstitutionFiltersList> m_pSubstitutionFiltersList;
70
71         WORD GetLangId() const;
72         void SetIndicators(CStatusBar &, const UINT *, int) const;
73         void TranslateMenu(HMENU) const;
74         void TranslateDialog(HWND) const;
75         String LoadString(UINT) const;
76         bool TranslateString(const std::string&, String&) const;
77         std::wstring LoadDialogCaption(LPCTSTR) const;
78
79         CMergeApp();
80         ~CMergeApp();
81
82 public:
83         void AddToRecentProjectsMRU(LPCTSTR sPathName);
84         void SetNeedIdleTimer();
85         void SetLastCompareResult(int nResult) { m_nLastCompareResult = nResult; }
86
87         COptionsMgr * GetMergeOptionsMgr() { return static_cast<COptionsMgr *> (m_pOptions.get()); }
88         FileFilterHelper * GetGlobalFileFilter() { return m_pGlobalFileFilter.get(); }
89         void ShowHelp(LPCTSTR helpLocation = nullptr);
90         static void OpenFileToExternalEditor(const String& file, int nLineNumber = 1);
91         static bool CreateBackup(bool bFolder, const String& pszPath);
92         static int HandleReadonlySave(String& strSavePath, bool bMultiFile, bool &bApplyToAll);
93         static String GetPackingErrorMessage(int pane, int paneCount, const String& path, const String& pluginName);
94         bool GetMergingMode() const;
95         void SetMergingMode(bool bMergingMode);
96         static void SetupTempPath();
97         bool IsReallyIdle() const;
98
99         virtual UINT GetProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nDefault) override;
100         virtual BOOL WriteProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nValue) override;
101         virtual CString GetProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszDefault = NULL) override;
102         virtual BOOL WriteProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszValue) override;
103         virtual HINSTANCE LoadAppLangResourceDLL() override { return nullptr; }; // Disable loading lang resource dll
104
105 // Implementation
106 protected:
107
108 // Overrides
109         // ClassWizard generated virtual function overrides
110         //{{AFX_VIRTUAL(CMergeApp)
111         public:
112         virtual BOOL InitInstance();
113         virtual int ExitInstance();
114         virtual int DoMessageBox(LPCTSTR lpszPrompt, UINT nType, UINT nIDPrompt);
115         virtual BOOL OnIdle(LONG lCount);
116         //}}AFX_VIRTUAL
117
118         void InitializeFileFilters();
119         bool ParseArgsAndDoOpen(MergeCmdLineInfo& cmdInfo, CMainFrame* pMainFrame);
120         void UpdateDefaultCodepage(int cpDefaultMode, int cpCustomCodepage);
121         void UpdateCodepageModule();
122         void ApplyCommandLineConfigOptions(MergeCmdLineInfo & cmdInfo);
123
124         // End MergeArgs.cpp
125
126         bool LoadProjectFile(const String& sProject, ProjectFile &project);
127         bool SaveProjectFile(const String& sProject, const ProjectFile &project);
128         bool LoadAndOpenProjectFile(const String& sFilepath, const String& sReportFile = _T(""));
129         bool IsProjectFile(const String& filepath) const;
130
131         //@{
132         /**
133          * @name Active operations counter.
134          * These functions implement counter for active operations. We need to
135          * track active operations during whose user cannot exit the application.
136          * E.g. copying files in folder compare is such an operation.
137          */
138         /**
139          * Increment the active operation counter.
140          */
141         void AddOperation() { InterlockedIncrement(&m_nActiveOperations); }
142         /**
143          * Decrement the active operation counter.
144          */
145         void RemoveOperation()
146         {
147                 ASSERT(m_nActiveOperations > 0);
148                 InterlockedDecrement( &m_nActiveOperations);
149         }
150         /**
151          * Get the active operations count.
152          */
153         LONG GetActiveOperations() const { return m_nActiveOperations; }
154         //@}
155
156         //{{AFX_MSG(CMergeApp)
157         afx_msg BOOL OnOpenRecentFile(UINT nID);
158         afx_msg void OnAppAbout();
159         afx_msg void OnHelp();
160         afx_msg void OnMergingMode();
161         afx_msg void OnUpdateMergingMode(CCmdUI* pCmdUI);
162         afx_msg void OnUpdateMergingStatus(CCmdUI* pCmdUI);
163         //}}AFX_MSG
164         DECLARE_MESSAGE_MAP()
165 private:
166         std::unique_ptr<COptionsMgr> m_pOptions;
167         CAssureScriptsForThread * m_mainThreadScripts;
168         int m_nLastCompareResult;
169         bool m_bNonInteractive;
170         LONG m_nActiveOperations; /**< Active operations count. */
171         bool m_bMergingMode; /**< Merging or Edit mode */
172         CFont m_fontGUI;
173         ATL::CImage m_imageForInitializingGdiplus;
174 };
175
176 extern CMergeApp theApp;
177
178 /**
179  * @brief Set flag so that application will broadcast notification at next
180  * idle time (via WM_TIMER id=IDLE_TIMER)
181  */
182 inline void CMergeApp::SetNeedIdleTimer()
183 {
184         m_bNeedIdleTimer = true;
185 }
186
187 COptionsMgr* CreateOptionManager();