OSDN Git Service

Allow NUL and \\.\NUL in paths specified as command line arguments (#2056)
[winmerge-jp/winmerge-jp.git] / Src / HexMergeDoc.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  HexMergeDoc.h
8  *
9  * @brief Declaration of CHexMergeDoc class
10  */
11 #pragma once
12
13 #include "PathContext.h"
14 #include "FileLocation.h"
15 #include "IMergeDoc.h"
16 #include "FileTransform.h"
17
18 struct IDirDoc;
19 class CHexMergeFrame;
20 class CHexMergeView;
21
22 /**
23  * @brief Document class for bytewise merging two files presented as hexdumps
24  */
25 class CHexMergeDoc : public CDocument, public IMergeDoc
26 {
27 public:
28         enum class BUFFERTYPE
29         {
30                 NORMAL = 0, /**< Normal, file loaded from disk */
31                 NORMAL_NAMED, /**< Normal, description given */
32                 UNNAMED, /**< Empty, created buffer */
33                 UNNAMED_SAVED, /**< Empty buffer saved with filename */
34         };
35
36 // Attributes
37 public:
38         static int m_nBuffersTemp;
39         int m_nBuffers;
40         PathContext m_filePaths; /**< Filepaths for this document */
41
42 // Begin declaration of CHexMergeDoc
43
44 protected: // create from serialization only
45         CHexMergeDoc();
46         DECLARE_DYNCREATE(CHexMergeDoc)
47
48         
49         // Operations
50 public: 
51         void SetMergeViews(CHexMergeView * pView[]);
52         CHexMergeView *GetActiveMergeView() const;
53
54         // Overrides
55         // ClassWizard generated virtual function overrides
56         //{{AFX_VIRTUAL(CMergeDoc)
57         public:
58         virtual BOOL SaveModified();
59         virtual void SetTitle(LPCTSTR lpszTitle);
60         //}}AFX_VIRTUAL
61
62 // Implementation
63 public:
64         ~CHexMergeDoc();
65         int UpdateLastCompareResult();
66         bool PromptAndSaveIfNeeded(bool bAllowCancel);
67         IDirDoc* GetDirDoc() const override { return m_pDirDoc; };
68         void SetDirDoc(IDirDoc * pDirDoc) override;
69         void DirDocClosing(IDirDoc * pDirDoc) override;
70         bool CloseNow() override;
71         bool GenerateReport(const String& sFileName) const override { return true; }
72         const PackingInfo* GetUnpacker() const override { return &m_infoUnpacker; };
73         PackingInfo* GetUnpacker() { return &m_infoUnpacker; };
74         void SetUnpacker(const PackingInfo* infoUnpacker) override { if (infoUnpacker) m_infoUnpacker = *infoUnpacker;  };
75         const PrediffingInfo* GetPrediffer() const override { return nullptr; };
76         int GetFileCount() const override { return m_filePaths.GetSize(); }
77         String GetPath(int pane) const override { return m_filePaths[pane]; }
78         bool GetReadOnly(int pane) const override;
79         CString GetTooltipString() const override;
80         CHexMergeFrame * GetParentFrame() const;
81         void UpdateHeaderPath(int pane);
82         void RefreshOptions();
83         bool OpenDocs(int nFiles, const FileLocation fileloc[], const bool bRO[], const String strDesc[]);
84         void MoveOnLoad(int nPane = -1, int nLineIndex = -1);
85         void ChangeFile(int nBuffer, const String& path, int nLineIndex = -1);
86         void CheckFileChanged(void) override;
87         String GetDescription(int pane) const override { return m_strDesc[pane]; };
88         void SetDescription(int pane, const String& strDesc) {  m_strDesc[pane] = strDesc; };
89         void SaveAs(int nBuffer, bool packing = true) { DoFileSaveAs(nBuffer, packing); }
90         String GetSaveAsPath() const { return m_strSaveAsPath; }
91         void SetSaveAsPath(const String& strSaveAsPath) { m_strSaveAsPath = strSaveAsPath; }
92         bool IsModified() const;
93
94 private:
95         bool DoFileSave(int nBuffer);
96         bool DoFileSaveAs(int nBuffer, bool packing = true);
97         HRESULT LoadOneFile(int index, const tchar_t* filename, bool readOnly, const String& strDesc);
98         void RecompareAs(UINT id);
99 // Implementation data
100 protected:
101         CHexMergeView * m_pView[3]; /**< Pointer to left/right view */
102         IDirDoc * m_pDirDoc;
103         String m_strDesc[3]; /**< Left/right side description text */
104         BUFFERTYPE m_nBufferType[3];
105         PackingInfo m_infoUnpacker;
106         String m_strSaveAsPath; /**< "3rd path" where output saved if given */
107
108 // Generated message map functions
109 protected:
110         //{{AFX_MSG(CMergeDoc)
111         afx_msg void OnFileSave();
112         afx_msg void OnFileSaveLeft();
113         afx_msg void OnFileSaveMiddle();
114         afx_msg void OnFileSaveRight();
115         afx_msg void OnFileSaveAsLeft();
116         afx_msg void OnFileSaveAsMiddle();
117         afx_msg void OnFileSaveAsRight();
118         afx_msg void OnFileReload();
119         afx_msg void OnUpdateStatusNum(CCmdUI* pCmdUI);
120         afx_msg void OnUpdateFileSaveLeft(CCmdUI* pCmdUI);
121         afx_msg void OnUpdateFileSaveMiddle(CCmdUI* pCmdUI);
122         afx_msg void OnUpdateFileSaveRight(CCmdUI* pCmdUI);
123         afx_msg void OnUpdateFileSave(CCmdUI* pCmdUI);
124         afx_msg void OnCopyX2Y(UINT nID);
125         afx_msg void OnUpdateX2Y(CCmdUI* pCmdUI);
126         afx_msg void OnL2r();
127         afx_msg void OnUpdateL2r(CCmdUI* pCmdUI);
128         afx_msg void OnR2l();
129         afx_msg void OnUpdateR2l(CCmdUI* pCmdUI);
130         afx_msg void OnUpdateL2RNext(CCmdUI* pCmdUI);
131         afx_msg void OnUpdateR2LNext(CCmdUI* pCmdUI);
132         afx_msg void OnCopyFromLeft();
133         afx_msg void OnUpdateCopyFromLeft(CCmdUI* pCmdUI);
134         afx_msg void OnCopyFromRight();
135         afx_msg void OnUpdateCopyFromRight(CCmdUI* pCmdUI);
136         afx_msg void OnAllRight();
137         afx_msg void OnUpdateAllRight(CCmdUI* pCmdUI);
138         afx_msg void OnAllLeft();
139         afx_msg void OnUpdateAllLeft(CCmdUI* pCmdUI);
140         afx_msg void OnViewZoomIn();
141         afx_msg void OnViewZoomOut();
142         afx_msg void OnViewZoomNormal();
143         afx_msg void OnRefresh();
144         afx_msg void OnFileRecompareAs(UINT nID);
145         afx_msg void OnUpdateFileRecompareAs(CCmdUI* pCmdUI);
146         afx_msg void OnOpenWithUnpacker();
147         //}}AFX_MSG
148         DECLARE_MESSAGE_MAP()
149 };
150