OSDN Git Service

Fix issue #172: 'Compare Non-horizontally' doesn't support 3-way merge
[winmerge-jp/winmerge-jp.git] / Src / DirView.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 DirView.h
22  *
23  *  @brief Declaration of class CDirView
24  */
25 #pragma once
26
27 /////////////////////////////////////////////////////////////////////////////
28 // CDirView view
29 #include <afxcview.h>
30 #include <memory>
31 #include "OptionsDirColors.h"
32 #include "SortHeaderCtrl.h"
33 #include "UnicodeString.h"
34 #include "DirItemIterator.h"
35 #include "DirActions.h"
36
37 class FileActionScript;
38
39 typedef enum { eMain, eContext } eMenuType;
40
41 class CDirDoc;
42 class CDirFrame;
43
44 class PackingInfo;
45 class PathContext;
46 class DirCompProgressBar;
47 class CompareStats;
48 struct DirColInfo;
49 class CLoadSaveCodepageDlg;
50 class CShellContextMenu;
51 class CDiffContext;
52 class DirViewColItems;
53 class DirItemEnumerator;
54 struct IListCtrl;
55
56 /**
57  * @brief Position value for special items (..) in directory compare view.
58  */
59 const uintptr_t SPECIAL_ITEM_POS = (uintptr_t)(reinterpret_cast<DIFFITEM *>( - 1L));
60
61 /** Default column width in directory compare */
62 const UINT DefColumnWidth = 150;
63
64 /**
65  * @brief Directory compare results view.
66  *
67  * Directory compare view is list-view based, so it shows one result (for
68  * folder or file, commonly called as 'item') in one line. User can select
69  * visible columns, re-order columns, sort by column etc.
70  *
71  * Actual data is stored in CDiffContext in CDirDoc. Dircompare items and
72  * CDiffContext items are linked by storing POSITION of CDiffContext item
73  * as CDirView listitem key.
74  */
75 class CDirView : public CListView
76 {
77         friend struct FileCmpReport;
78         friend DirItemEnumerator;
79 protected:
80         CDirView();           // protected constructor used by dynamic creation
81         DECLARE_DYNCREATE(CDirView)
82
83 // Attributes
84 public:
85         CDirDoc* GetDocument(); // non-debug version is inline
86         // const version, for const methods to be able to call
87         const CDirDoc * GetDocument() const { return const_cast<CDirView *>(this)->GetDocument(); }
88         const CDiffContext& GetDiffContext() const;
89         CDiffContext& GetDiffContext();
90
91 // Operations
92 public:
93         CDirFrame * GetParentFrame();
94
95         void StartCompare(CompareStats *pCompareStats);
96         void Redisplay();
97         void RedisplayChildren(DIFFITEM *diffpos, int level, UINT &index, int &alldiffs);
98         void UpdateResources();
99         void LoadColumnHeaderItems();
100         DIFFITEM *GetItemKey(int idx) const;
101         int GetItemIndex(DIFFITEM *key);
102         // for populating list
103         void DeleteItem(int sel, bool removeDIFFITEM = false);
104         void DeleteAllDisplayItems();
105         void SetFont(const LOGFONT & lf);
106
107         void SortColumnsAppropriately();
108
109         UINT GetSelectedCount() const;
110         int GetFirstSelectedInd();
111         void AddParentFolderItem(bool bEnable);
112         void RefreshOptions();
113
114         bool HasNextDiff();
115         bool HasPrevDiff();
116         void MoveToNextDiff();
117         void MoveToPrevDiff();
118         void OpenNextDiff();
119         void OpenPrevDiff();
120         void SetActivePane(int pane);
121
122 // Implementation types
123 private:
124
125 // Implementation in DirActions.cpp
126 private:
127         void GetItemFileNames(int sel, String& strLeft, String& strRight) const;
128         void GetItemFileNames(int sel, PathContext * paths) const;
129         void FormatEncodingDialogDisplays(CLoadSaveCodepageDlg * dlg);
130         DirActions MakeDirActions(DirActions::method_type func) const;
131         DirActions MakeDirActions(DirActions::method_type2 func) const;
132         Counts Count(DirActions::method_type2 func) const;
133         void DoDirAction(DirActions::method_type func, const String& status_message);
134         void DoDirActionTo(SIDE_TYPE stype, DirActions::method_type func, const String& status_message);
135         void DoOpen(SIDE_TYPE stype);
136         void DoOpenWith(SIDE_TYPE stype);
137         void DoOpenWithEditor(SIDE_TYPE stype);
138         void DoOpenParentFolder(SIDE_TYPE stype);
139         void DoUpdateOpen(SELECTIONTYPE selectionType, CCmdUI* pCmdUI);
140         void ConfirmAndPerformActions(FileActionScript & actions);
141         void PerformActionList(FileActionScript & actions);
142         void UpdateAfterFileScript(FileActionScript & actionList);
143         void DoFileEncodingDialog();
144
145 // End DirActions.cpp
146         void ReflectGetdispinfo(NMLVDISPINFO *);
147
148 // Implementation in DirViewColHandler.cpp
149 public:
150         void UpdateColumnNames();
151         void SetColAlignments();
152         // class CompareState is used to pass parameters to the PFNLVCOMPARE callback function.
153         class CompareState
154         {
155         private:
156                 const DirViewColItems *const pColItems;
157                 const CDiffContext *const pCtxt;
158                 const int sortCol;
159                 const bool bSortAscending;
160                 const bool bTreeMode;
161         public:
162                 CompareState(const CDiffContext *pCtxt, const DirViewColItems *pColItems, int sortCol, bool bSortAscending, bool bTreeMode);
163                 static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
164         } friend;
165         void UpdateDiffItemStatus(UINT nIdx);
166 private:
167         void InitiateSort();
168         void NameColumn(const DirColInfo *col, int subitem);
169         int AddNewItem(int i, DIFFITEM *diffpos, int iImage, int iIndent);
170 // End DirViewCols.cpp
171
172 private:
173
174 // Overrides
175         // ClassWizard generated virtual function overrides
176         //{{AFX_VIRTUAL(CDirView)
177 public:
178         virtual void OnInitialUpdate();
179 protected:
180         virtual BOOL PreTranslateMessage(MSG* pMsg);
181         virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult);
182         virtual BOOL OnChildNotify(UINT, WPARAM, LPARAM, LRESULT*);
183         virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
184         //}}AFX_VIRTUAL
185
186 // Implementation
187 protected:
188         virtual ~CDirView();
189         int GetFocusedItem();
190         int GetFirstDifferentItem();
191         int GetLastDifferentItem();
192         int AddSpecialItems();
193         std::vector<String>     GetCurrentColRegKeys();
194         void OpenSpecialItems(DIFFITEM *pos1, DIFFITEM *pos2, DIFFITEM *pos3);
195
196 // Implementation data
197 protected:
198         CSortHeaderCtrl m_ctlSortHeader;
199         CImageList m_imageList;
200         CImageList m_imageState;
201         CListCtrl *m_pList;
202         std::unique_ptr<IListCtrl> m_pIList;
203         bool m_bEscCloses; /**< Cached value for option for ESC closing window */
204         bool m_bExpandSubdirs;
205         CFont m_font; /**< User-selected font */
206         UINT m_nHiddenItems; /**< Count of items we have hidden */
207         bool m_bTreeMode; /**< `true` if tree mode is on*/
208         DirViewFilterSettings m_dirfilter;
209         std::unique_ptr<DirCompProgressBar> m_pCmpProgressBar;
210         clock_t m_compareStart; /**< Starting process time of the compare */
211         bool m_bUserCancelEdit; /**< `true` if the user cancels rename */
212         String m_lastCopyFolder; /**< Last Copy To -target folder. */
213
214         int m_firstDiffItem;
215         int m_lastDiffItem;
216         bool m_bNeedSearchFirstDiffItem;
217         bool m_bNeedSearchLastDiffItem;
218         DIRCOLORSETTINGS m_cachedColors; /**< Cached color settings */
219         bool m_bUseColors;
220
221         std::unique_ptr<CShellContextMenu> m_pShellContextMenuLeft; /**< Shell context menu for group of left files */
222         std::unique_ptr<CShellContextMenu> m_pShellContextMenuMiddle; /**< Shell context menu for group of middle files */
223         std::unique_ptr<CShellContextMenu> m_pShellContextMenuRight; /**< Shell context menu for group of right files */
224         HMENU m_hCurrentMenu; /**< Current shell context menu (either left or right) */
225         std::unique_ptr<DirViewTreeState> m_pSavedTreeState;
226         std::unique_ptr<DirViewColItems> m_pColItems;
227         int m_nActivePane;
228
229         // Generated message map functions
230         afx_msg void OnColumnClick(NMHDR* pNMHDR, LRESULT* pResult);
231         afx_msg void OnContextMenu(CWnd*, CPoint point);
232         //{{AFX_MSG(CDirView)
233         afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
234         afx_msg void OnDirCopy(UINT id);
235         template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
236         afx_msg void OnCtxtDirCopy();
237         afx_msg void OnUpdateDirCopy(CCmdUI* pCmdUI);
238         template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
239         afx_msg void OnUpdateCtxtDirCopy(CCmdUI* pCmdUI);
240         template<SIDE_TYPE stype>
241         afx_msg void OnCtxtDirDel();
242         template<SIDE_TYPE stype>
243         afx_msg void OnUpdateCtxtDirDel(CCmdUI* pCmdUI);
244         afx_msg void OnCtxtDirDelBoth();
245         afx_msg void OnUpdateCtxtDirDelBoth(CCmdUI* pCmdUI);
246         template<SIDE_TYPE stype>
247         afx_msg void OnCtxtDirOpen();
248         template<SIDE_TYPE stype>
249         afx_msg void OnUpdateCtxtDirOpen(CCmdUI* pCmdUI);
250         template<SIDE_TYPE stype>
251         afx_msg void OnCtxtDirOpenWith();
252         template<SIDE_TYPE stype>
253         afx_msg void OnUpdateCtxtDirOpenWith(CCmdUI* pCmdUI);
254         template<SIDE_TYPE stype>
255         afx_msg void OnCtxtDirOpenWithEditor();
256         template<SIDE_TYPE stype>
257         afx_msg void OnUpdateCtxtDirOpenWithEditor(CCmdUI* pCmdUI);
258         template<SIDE_TYPE stype>
259         afx_msg void OnCtxtDirOpenParentFolder();
260         template<SIDE_TYPE stype>
261         afx_msg void OnUpdateCtxtDirOpenParentFolder(CCmdUI* pCmdUI);
262         template<SIDE_TYPE stype>
263         afx_msg void OnCtxtDirCopyTo();
264         template<SIDE_TYPE stype>
265         afx_msg void OnUpdateCtxtDirCopyTo(CCmdUI* pCmdUI);
266         afx_msg void OnUpdateCtxtDirCopyBothTo(CCmdUI* pCmdUI);
267         afx_msg void OnUpdateCtxtDirCopyBothDiffsOnlyTo(CCmdUI* pCmdUI);
268         afx_msg void OnDestroy();
269         afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
270         afx_msg void OnClick(NMHDR* pNMHDR, LRESULT* pResult);
271         afx_msg void OnFirstdiff();
272         afx_msg void OnUpdateFirstdiff(CCmdUI* pCmdUI);
273         afx_msg void OnLastdiff();
274         afx_msg void OnUpdateLastdiff(CCmdUI* pCmdUI);
275         afx_msg void OnNextdiff();
276         afx_msg void OnUpdateNextdiff(CCmdUI* pCmdUI);
277         afx_msg void OnPrevdiff();
278         afx_msg void OnUpdatePrevdiff(CCmdUI* pCmdUI);
279         afx_msg void OnCurdiff();
280         afx_msg void OnUpdateCurdiff(CCmdUI* pCmdUI);
281         afx_msg void OnUpdateSave(CCmdUI* pCmdUI);
282         afx_msg LRESULT OnUpdateUIMessage(WPARAM wParam, LPARAM lParam);
283         afx_msg void OnRefresh();
284         afx_msg void OnUpdateRefresh(CCmdUI* pCmdUI);
285         afx_msg void OnTimer(UINT_PTR nIDEvent);
286         afx_msg void OnEditColumns();
287         template<SIDE_TYPE stype>
288         afx_msg void OnReadOnly();
289         template<SIDE_TYPE stype>
290         afx_msg void OnUpdateReadOnly(CCmdUI* pCmdUI);
291         afx_msg void OnUpdateStatusLeftRO(CCmdUI* pCmdUI);
292         afx_msg void OnUpdateStatusMiddleRO(CCmdUI* pCmdUI);
293         afx_msg void OnUpdateStatusRightRO(CCmdUI* pCmdUI);
294         afx_msg void OnCustomizeColumns();
295         afx_msg void OnCtxtOpenWithUnpacker();
296         afx_msg void OnUpdateCtxtOpenWithUnpacker(CCmdUI* pCmdUI);
297         afx_msg void OnToolsGenerateReport();
298         afx_msg LRESULT OnGenerateFileCmpReport(WPARAM wParam, LPARAM lParam);
299         afx_msg void OnToolsGeneratePatch();
300         template<int flag>
301         afx_msg void OnCtxtDirZip();
302         template<SIDE_TYPE stype>
303         afx_msg void OnCtxtDirShellContextMenu();
304         afx_msg void OnSelectAll();
305         afx_msg void OnUpdateSelectAll(CCmdUI* pCmdUI);
306         afx_msg void OnPluginPredifferMode(UINT nID);
307         afx_msg void OnUpdatePluginPredifferMode(CCmdUI* pCmdUI);
308         template<SIDE_TYPE side>
309         afx_msg void OnCopyPathnames();
310         afx_msg void OnCopyBothPathnames();
311         afx_msg void OnCopyFilenames();
312         afx_msg void OnUpdateCopyFilenames(CCmdUI* pCmdUI);
313         template<SIDE_TYPE side>
314         afx_msg void OnCopyToClipboard();
315         afx_msg void OnCopyBothToClipboard();
316         afx_msg void OnItemRename();
317         afx_msg void OnUpdateItemRename(CCmdUI* pCmdUI);
318         afx_msg void OnHideFilenames();
319         afx_msg void OnSize(UINT nType, int cx, int cy);
320         template<SIDE_TYPE stype>
321         afx_msg void OnCtxtDirMoveTo();
322         template<SIDE_TYPE stype>
323         afx_msg void OnUpdateCtxtDirMoveTo(CCmdUI* pCmdUI);
324         afx_msg void OnUpdateHideFilenames(CCmdUI* pCmdUI);
325         afx_msg void OnDelete();
326         afx_msg void OnUpdateDelete(CCmdUI* pCmdUI);
327         afx_msg void OnMarkedRescan();
328         afx_msg void OnUpdateStatusNum(CCmdUI* pCmdUI);
329         afx_msg void OnViewShowHiddenItems();
330         afx_msg void OnUpdateViewShowHiddenItems(CCmdUI* pCmdUI);
331         afx_msg void OnViewTreeMode();
332         afx_msg void OnUpdateViewTreeMode(CCmdUI* pCmdUI);
333         afx_msg void OnViewExpandAllSubdirs();
334         afx_msg void OnUpdateViewExpandAllSubdirs(CCmdUI* pCmdUI);
335         afx_msg void OnViewCollapseAllSubdirs();
336         afx_msg void OnUpdateViewCollapseAllSubdirs(CCmdUI* pCmdUI);
337         afx_msg void OnViewSwapPanes();
338         afx_msg void OnOptionsShowDifferent();
339         afx_msg void OnOptionsShowIdentical();
340         afx_msg void OnOptionsShowUniqueLeft();
341         afx_msg void OnOptionsShowUniqueMiddle();
342         afx_msg void OnOptionsShowUniqueRight();
343         afx_msg void OnOptionsShowBinaries();
344         afx_msg void OnOptionsShowSkipped();
345         afx_msg void OnOptionsShowDifferentLeftOnly();
346         afx_msg void OnOptionsShowDifferentMiddleOnly();
347         afx_msg void OnOptionsShowDifferentRightOnly();
348         afx_msg void OnOptionsShowMissingLeftOnly();
349         afx_msg void OnOptionsShowMissingMiddleOnly();
350         afx_msg void OnOptionsShowMissingRightOnly();
351         afx_msg void OnUpdateOptionsShowdifferent(CCmdUI* pCmdUI);
352         afx_msg void OnUpdateOptionsShowidentical(CCmdUI* pCmdUI);
353         afx_msg void OnUpdateOptionsShowuniqueleft(CCmdUI* pCmdUI);
354         afx_msg void OnUpdateOptionsShowuniquemiddle(CCmdUI* pCmdUI);
355         afx_msg void OnUpdateOptionsShowuniqueright(CCmdUI* pCmdUI);
356         afx_msg void OnUpdateOptionsShowBinaries(CCmdUI* pCmdUI);
357         afx_msg void OnUpdateOptionsShowSkipped(CCmdUI* pCmdUI);
358         afx_msg void OnUpdateOptionsShowDifferentLeftOnly(CCmdUI* pCmdUI);
359         afx_msg void OnUpdateOptionsShowDifferentMiddleOnly(CCmdUI* pCmdUI);
360         afx_msg void OnUpdateOptionsShowDifferentRightOnly(CCmdUI* pCmdUI);
361         afx_msg void OnUpdateOptionsShowMissingLeftOnly(CCmdUI* pCmdUI);
362         afx_msg void OnUpdateOptionsShowMissingMiddleOnly(CCmdUI* pCmdUI);
363         afx_msg void OnUpdateOptionsShowMissingRightOnly(CCmdUI* pCmdUI);
364         afx_msg void OnMergeCompare();
365         template<SELECTIONTYPE seltype>
366         afx_msg void OnMergeCompare2();
367         afx_msg void OnMergeCompareNonHorizontally();
368         afx_msg void OnMergeCompareXML();
369         afx_msg void OnMergeCompareAs(UINT nID);
370         afx_msg void OnUpdateMergeCompare(CCmdUI *pCmdUI);
371         template<SELECTIONTYPE seltype>
372         afx_msg void OnUpdateMergeCompare2(CCmdUI *pCmdUI);
373         afx_msg void OnViewCompareStatistics();
374         afx_msg void OnFileEncoding();
375         afx_msg void OnHelp();
376         afx_msg void OnEditCopy();
377         afx_msg void OnEditCut();
378         afx_msg void OnEditPaste();
379         afx_msg void OnEditUndo();
380         afx_msg void OnUpdateEditUndo(CCmdUI* pCmdUI);
381         afx_msg void OnItemChanged(NMHDR* pNMHDR, LRESULT* pResult);
382         afx_msg void OnBeginLabelEdit(NMHDR* pNMHDR, LRESULT* pResult);
383         afx_msg void OnEndLabelEdit(NMHDR* pNMHDR, LRESULT* pResult);
384         afx_msg void OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult);
385         afx_msg void OnSearch();
386         afx_msg void OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult);
387         afx_msg void OnBnClickedComparisonStop();
388         afx_msg void OnBnClickedComparisonPause();
389         afx_msg void OnBnClickedComparisonContinue();
390         //}}AFX_MSG
391         DECLARE_MESSAGE_MAP()
392         bool OnHeaderBeginDrag(LPNMHEADER hdr, LRESULT* pResult);
393         bool OnHeaderEndDrag(LPNMHEADER hdr, LRESULT* pResult);
394
395 private:
396         void Open(const PathContext& paths, DWORD dwFlags[3], PackingInfo * infoUnpacker = nullptr);
397         void OpenSelection(SELECTIONTYPE selectionType = SELECTIONTYPE_NORMAL, PackingInfo * infoUnpacker = nullptr);
398         void OpenSelectionAs(UINT id);
399         bool GetSelectedItems(int * sel1, int * sel2, int * sel3);
400         void OpenParentDirectory();
401         template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
402         void DoUpdateDirCopy(CCmdUI* pCmdUI, eMenuType menuType);
403         const DIFFITEM &GetDiffItem(int sel) const;
404         DIFFITEM &GetDiffItem(int sel);
405         int GetSingleSelectedItem() const;
406         void MoveFocus(int currentInd, int i, int selCount);
407
408         void FixReordering();
409         void HeaderContextMenu(CPoint point, int i);
410         void ListContextMenu(CPoint point, int i);
411         bool ListShellContextMenu(SIDE_TYPE side);
412         void ShowShellContextMenu(SIDE_TYPE side);
413         CShellContextMenu* GetCorrespondingShellContextMenu(HMENU hMenu) const;
414         void ReloadColumns();
415         bool IsLabelEdit() const;
416         void CollapseSubdir(int sel);
417         void ExpandSubdir(int sel, bool bRecursive = false);
418         void GetColors(int nRow, int nCol, COLORREF& clrBk, COLORREF& clrText) const;
419 public:
420         DirItemIterator Begin() const { return DirItemIterator(m_pIList.get()); }
421         DirItemIterator End() const { return DirItemIterator(); }
422         DirItemIterator RevBegin() const { return DirItemIterator(m_pIList.get(), -1, false, true); }
423         DirItemIterator RevEnd() const { return DirItemIterator(); }
424         DirItemIterator SelBegin() const { return DirItemIterator(m_pIList.get(), -1, true); }
425         DirItemIterator SelEnd() const { return DirItemIterator(); }
426         DirItemIterator SelRevBegin() const { return DirItemIterator(m_pIList.get(), -1, true, true); }
427         DirItemIterator SelRevEnd() const { return DirItemIterator(); }
428 };
429
430 #ifndef _DEBUG  // debug version in DirView.cpp
431 inline CDirDoc* CDirView::GetDocument()
432 { return reinterpret_cast<CDirDoc*>(m_pDocument); }
433 #endif