1 /////////////////////////////////////////////////////////////////////////////
2 // WinMerge: an interactive diff/merge utility
3 // Copyright (C) 1997 Dean P. Grimm
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.
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.
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.
19 /////////////////////////////////////////////////////////////////////////////
23 * @brief Declaration of class CDirView
26 // ID line follows -- this is updated by SVN
27 // $Id: DirView.h 7062 2009-12-27 14:43:51Z kimmov $
29 #if !defined(AFX_DirView_H__16E7C721_351C_11D1_95CD_444553540000__INCLUDED_)
30 #define AFX_DirView_H__16E7C721_351C_11D1_95CD_444553540000__INCLUDED_
32 /////////////////////////////////////////////////////////////////////////////
37 #include "OptionsDiffColors.h"
38 #include "SortHeaderCtrl.h"
39 #include "UnicodeString.h"
40 #include "DirItemIterator.h"
41 #include "DirActions.h"
43 class FileActionScript;
47 typedef enum { eMain, eContext } eMenuType;
54 class DirCompProgressBar;
57 class CLoadSaveCodepageDlg;
58 class CShellContextMenu;
60 class DirViewColItems;
61 class DirItemEnumerator;
65 * @brief Position value for special items (..) in directory compare view.
67 const uintptr_t SPECIAL_ITEM_POS = (uintptr_t) - 1L;
69 /** Default column width in directory compare */
70 const UINT DefColumnWidth = 150;
73 * @brief Directory compare results view.
75 * Directory compare view is list-view based, so it shows one result (for
76 * folder or file, commonly called as 'item') in one line. User can select
77 * visible columns, re-order columns, sort by column etc.
79 * Actual data is stored in CDiffContext in CDirDoc. Dircompare items and
80 * CDiffContext items are linked by storing POSITION of CDiffContext item
81 * as CDirView listitem key.
83 class CDirView : public CListView
85 friend struct FileCmpReport;
86 friend DirItemEnumerator;
88 CDirView(); // protected constructor used by dynamic creation
89 DECLARE_DYNCREATE(CDirView)
93 CDirDoc* GetDocument(); // non-debug version is inline
94 // const version, for const methods to be able to call
95 const CDirDoc * GetDocument() const { return const_cast<CDirView *>(this)->GetDocument(); }
96 const CDiffContext& GetDiffContext() const;
97 CDiffContext& GetDiffContext();
101 CDirFrame * GetParentFrame();
103 void StartCompare(CompareStats *pCompareStats);
105 void RedisplayChildren(uintptr_t diffpos, int level, UINT &index, int &alldiffs, const DirViewFilterSettings& dirfilter);
106 void UpdateResources();
107 void LoadColumnHeaderItems();
108 uintptr_t GetItemKey(int idx) const;
109 int GetItemIndex(uintptr_t key);
110 // for populating list
111 void DeleteItem(int sel);
112 void DeleteAllDisplayItems();
113 void SetFont(const LOGFONT & lf);
115 void SortColumnsAppropriately();
117 UINT GetSelectedCount() const;
118 int GetFirstSelectedInd();
119 void AddParentFolderItem(bool bEnable);
120 void RefreshOptions();
122 LRESULT HandleMenuMessage(UINT message, WPARAM wParam, LPARAM lParam);
124 // Implementation types
127 // Implementation in DirActions.cpp
129 void GetItemFileNames(int sel, String& strLeft, String& strRight) const;
130 void GetItemFileNames(int sel, PathContext * paths) const;
131 void FormatEncodingDialogDisplays(CLoadSaveCodepageDlg * dlg);
132 bool IsItemLeftOnly(int code);
133 bool IsItemRightOnly(int code);
134 DirActions MakeDirActions(DirActions::method_type func) const;
135 DirActions MakeDirActions(DirActions::method_type2 func) const;
136 Counts Count(DirActions::method_type2 func) const;
137 void DoDirAction(DirActions::method_type func, const String& status_message);
138 void DoDirActionTo(SIDE_TYPE stype, DirActions::method_type func, const String& status_message);
139 void DoOpen(SIDE_TYPE stype);
140 void DoOpenWith(SIDE_TYPE stype);
141 void DoOpenWithEditor(SIDE_TYPE stype);
142 void DoUpdateOpen(SELECTIONTYPE selectionType, CCmdUI* pCmdUI);
143 void ConfirmAndPerformActions(FileActionScript & actions);
144 void PerformActionList(FileActionScript & actions);
145 void UpdateAfterFileScript(FileActionScript & actionList);
146 void DoFileEncodingDialog();
148 // End DirActions.cpp
149 void ReflectGetdispinfo(NMLVDISPINFO *);
151 // Implementation in DirViewColHandler.cpp
153 void UpdateColumnNames();
154 void SetColAlignments();
155 // class CompareState is used to pass parameters to the PFNLVCOMPARE callback function.
159 const DirViewColItems *const pColItems;
160 const CDiffContext *const pCtxt;
162 const bool bSortAscending;
163 const bool bTreeMode;
165 CompareState(const CDiffContext *pCtxt, const DirViewColItems *pColItems, int sortCol, bool bSortAscending, bool bTreeMode);
166 static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
168 void UpdateDiffItemStatus(UINT nIdx);
171 void NameColumn(const char* idname, int subitem);
172 int AddNewItem(int i, uintptr_t diffpos, int iImage, int iIndent);
173 // End DirViewCols.cpp
178 // ClassWizard generated virtual function overrides
179 //{{AFX_VIRTUAL(CDirView)
181 virtual void OnInitialUpdate();
183 virtual BOOL PreTranslateMessage(MSG* pMsg);
184 virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult);
185 virtual BOOL OnChildNotify(UINT, WPARAM, LPARAM, LRESULT*);
191 int GetFocusedItem();
192 int GetFirstDifferentItem();
193 int GetLastDifferentItem();
194 int AddSpecialItems();
195 void GetCurrentColRegKeys(std::vector<String>& colKeys);
196 void OpenSpecialItems(uintptr_t pos1, uintptr_t pos2, uintptr_t pos3);
198 // Implementation data
200 CString GenerateReport();
201 CSortHeaderCtrl m_ctlSortHeader;
202 CImageList m_imageList;
203 CImageList m_imageState;
205 std::unique_ptr<IListCtrl> m_pIList;
206 bool m_bEscCloses; /**< Cached value for option for ESC closing window */
207 bool m_bExpandSubdirs;
208 CFont m_font; /**< User-selected font */
209 UINT m_nHiddenItems; /**< Count of items we have hidden */
210 bool m_bTreeMode; /**< TRUE if tree mode is on*/
211 std::unique_ptr<DirCompProgressBar> m_pCmpProgressBar;
212 clock_t m_compareStart; /**< Starting process time of the compare */
213 bool m_bUserCancelEdit; /**< TRUE if the user cancels rename */
214 String m_lastCopyFolder; /**< Last Copy To -target folder. */
218 bool m_bNeedSearchFirstDiffItem;
219 bool m_bNeedSearchLastDiffItem;
220 COLORSETTINGS m_cachedColors; /**< Cached color settings */
222 std::unique_ptr<CShellContextMenu> m_pShellContextMenuLeft; /**< Shell context menu for group of left files */
223 std::unique_ptr<CShellContextMenu> m_pShellContextMenuMiddle; /**< Shell context menu for group of middle files */
224 std::unique_ptr<CShellContextMenu> m_pShellContextMenuRight; /**< Shell context menu for group of right files */
225 HMENU m_hCurrentMenu; /**< Current shell context menu (either left or right) */
226 std::unique_ptr<DirViewTreeState> m_pSavedTreeState;
227 std::unique_ptr<DirViewColItems> m_pColItems;
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 template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
235 afx_msg void OnDirCopy();
236 template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
237 afx_msg void OnCtxtDirCopy();
238 template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
239 afx_msg void OnUpdateDirCopy(CCmdUI* pCmdUI);
240 template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
241 afx_msg void OnUpdateCtxtDirCopy(CCmdUI* pCmdUI);
242 template<SIDE_TYPE stype>
243 afx_msg void OnCtxtDirDel();
244 template<SIDE_TYPE stype>
245 afx_msg void OnUpdateCtxtDirDel(CCmdUI* pCmdUI);
246 afx_msg void OnCtxtDirDelBoth();
247 afx_msg void OnUpdateCtxtDirDelBoth(CCmdUI* pCmdUI);
248 template<SIDE_TYPE stype>
249 afx_msg void OnCtxtDirOpen();
250 template<SIDE_TYPE stype>
251 afx_msg void OnUpdateCtxtDirOpen(CCmdUI* pCmdUI);
252 template<SIDE_TYPE stype>
253 afx_msg void OnCtxtDirOpenWith();
254 template<SIDE_TYPE stype>
255 afx_msg void OnUpdateCtxtDirOpenWith(CCmdUI* pCmdUI);
256 template<SIDE_TYPE stype>
257 afx_msg void OnCtxtDirOpenWithEditor();
258 template<SIDE_TYPE stype>
259 afx_msg void OnUpdateCtxtDirOpenWithEditor(CCmdUI* pCmdUI);
260 template<SIDE_TYPE stype>
261 afx_msg void OnCtxtDirCopyTo();
262 template<SIDE_TYPE stype>
263 afx_msg void OnUpdateCtxtDirCopyTo(CCmdUI* pCmdUI);
264 afx_msg void OnDestroy();
265 afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
266 afx_msg void OnClick(NMHDR* pNMHDR, LRESULT* pResult);
267 afx_msg void OnFirstdiff();
268 afx_msg void OnUpdateFirstdiff(CCmdUI* pCmdUI);
269 afx_msg void OnLastdiff();
270 afx_msg void OnUpdateLastdiff(CCmdUI* pCmdUI);
271 afx_msg void OnNextdiff();
272 afx_msg void OnUpdateNextdiff(CCmdUI* pCmdUI);
273 afx_msg void OnPrevdiff();
274 afx_msg void OnUpdatePrevdiff(CCmdUI* pCmdUI);
275 afx_msg void OnCurdiff();
276 afx_msg void OnUpdateCurdiff(CCmdUI* pCmdUI);
277 afx_msg void OnUpdateSave(CCmdUI* pCmdUI);
278 afx_msg LRESULT OnUpdateUIMessage(WPARAM wParam, LPARAM lParam);
279 afx_msg void OnRefresh();
280 afx_msg void OnUpdateRefresh(CCmdUI* pCmdUI);
281 afx_msg void OnTimer(UINT_PTR nIDEvent);
282 afx_msg void OnEditColumns();
283 template<SIDE_TYPE stype>
284 afx_msg void OnReadOnly();
285 template<SIDE_TYPE stype>
286 afx_msg void OnUpdateReadOnly(CCmdUI* pCmdUI);
287 afx_msg void OnUpdateStatusLeftRO(CCmdUI* pCmdUI);
288 afx_msg void OnUpdateStatusMiddleRO(CCmdUI* pCmdUI);
289 afx_msg void OnUpdateStatusRightRO(CCmdUI* pCmdUI);
290 afx_msg void OnCustomizeColumns();
291 afx_msg void OnCtxtOpenWithUnpacker();
292 afx_msg void OnUpdateCtxtOpenWithUnpacker(CCmdUI* pCmdUI);
293 afx_msg void OnToolsGenerateReport();
294 afx_msg void OnCtxtDirZipLeft();
295 afx_msg void OnCtxtDirZipRight();
296 afx_msg void OnCtxtDirZipBoth();
297 afx_msg void OnCtxtDirZipBothDiffsOnly();
298 afx_msg void OnUpdateCtxtDir(CCmdUI* pCmdUI);
299 afx_msg void OnSelectAll();
300 afx_msg void OnUpdateSelectAll(CCmdUI* pCmdUI);
301 afx_msg void OnPluginPredifferMode(UINT nID);
302 afx_msg void OnUpdatePluginPredifferMode(CCmdUI* pCmdUI);
303 template<SIDE_TYPE side>
304 afx_msg void OnCopyPathnames();
305 afx_msg void OnCopyBothPathnames();
306 afx_msg void OnCopyFilenames();
307 afx_msg void OnUpdateCopyFilenames(CCmdUI* pCmdUI);
308 template<SIDE_TYPE side>
309 afx_msg void OnCopyToClipboard();
310 afx_msg void OnCopyBothToClipboard();
311 afx_msg void OnItemRename();
312 afx_msg void OnUpdateItemRename(CCmdUI* pCmdUI);
313 afx_msg void OnHideFilenames();
314 afx_msg void OnSize(UINT nType, int cx, int cy);
315 template<SIDE_TYPE stype>
316 afx_msg void OnCtxtDirMoveTo();
317 template<SIDE_TYPE stype>
318 afx_msg void OnUpdateCtxtDirMoveTo(CCmdUI* pCmdUI);
319 afx_msg void OnUpdateHideFilenames(CCmdUI* pCmdUI);
320 afx_msg void OnDelete();
321 afx_msg void OnUpdateDelete(CCmdUI* pCmdUI);
322 afx_msg void OnMarkedRescan();
323 afx_msg void OnUpdateStatusNum(CCmdUI* pCmdUI);
324 afx_msg void OnViewShowHiddenItems();
325 afx_msg void OnUpdateViewShowHiddenItems(CCmdUI* pCmdUI);
326 afx_msg void OnViewTreeMode();
327 afx_msg void OnUpdateViewTreeMode(CCmdUI* pCmdUI);
328 afx_msg void OnViewExpandAllSubdirs();
329 afx_msg void OnUpdateViewExpandAllSubdirs(CCmdUI* pCmdUI);
330 afx_msg void OnViewCollapseAllSubdirs();
331 afx_msg void OnUpdateViewCollapseAllSubdirs(CCmdUI* pCmdUI);
332 afx_msg void OnMergeCompare();
333 template<SELECTIONTYPE seltype>
334 afx_msg void OnMergeCompare2();
335 afx_msg void OnMergeCompareXML();
336 afx_msg void OnMergeCompareHex();
337 afx_msg void OnUpdateMergeCompare(CCmdUI *pCmdUI);
338 template<SELECTIONTYPE seltype>
339 afx_msg void OnUpdateMergeCompare2(CCmdUI *pCmdUI);
340 afx_msg void OnViewCompareStatistics();
341 afx_msg void OnFileEncoding();
342 afx_msg void OnUpdateFileEncoding(CCmdUI* pCmdUI);
343 afx_msg void OnHelp();
344 afx_msg void OnEditCopy();
345 afx_msg void OnEditCut();
346 afx_msg void OnEditPaste();
347 afx_msg void OnEditUndo();
348 afx_msg void OnUpdateEditUndo(CCmdUI* pCmdUI);
349 afx_msg void OnItemChanged(NMHDR* pNMHDR, LRESULT* pResult);
350 afx_msg void OnBeginLabelEdit(NMHDR* pNMHDR, LRESULT* pResult);
351 afx_msg void OnEndLabelEdit(NMHDR* pNMHDR, LRESULT* pResult);
352 afx_msg void OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult);
353 afx_msg void OnSearch();
354 afx_msg void OnExpandFolder();
355 afx_msg void OnCollapseFolder();
356 afx_msg void OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult);
357 afx_msg void OnBnClickedComparisonStop();
359 DECLARE_MESSAGE_MAP()
360 BOOL OnHeaderBeginDrag(LPNMHEADER hdr, LRESULT* pResult);
361 BOOL OnHeaderEndDrag(LPNMHEADER hdr, LRESULT* pResult);
364 void OpenSelection(SELECTIONTYPE selectionType = SELECTIONTYPE_NORMAL, PackingInfo * infoUnpacker = NULL);
365 void OpenSelectionHex();
366 bool GetSelectedItems(int * sel1, int * sel2, int * sel3);
367 void OpenParentDirectory();
368 template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
369 void DoUpdateDirCopy(CCmdUI* pCmdUI, eMenuType menuType);
370 const DIFFITEM & GetDiffItem(int sel) const;
371 DIFFITEM & GetDiffItem(int sel);
372 int GetSingleSelectedItem() const;
373 void MoveFocus(int currentInd, int i, int selCount);
375 void FixReordering();
376 void HeaderContextMenu(CPoint point, int i);
377 void ListContextMenu(CPoint point, int i);
378 bool ListShellContextMenu(SIDE_TYPE side);
379 CShellContextMenu* GetCorrespondingShellContextMenu(HMENU hMenu) const;
380 void ReloadColumns();
381 bool IsLabelEdit() const;
382 void CollapseSubdir(int sel);
383 void ExpandSubdir(int sel, bool bRecursive = false);
384 void GetColors(int nRow, int nCol, COLORREF& clrBk, COLORREF& clrText) const;
386 DirItemIterator Begin() const { return DirItemIterator(m_pIList.get()); }
387 DirItemIterator End() const { return DirItemIterator(); }
388 DirItemIterator RevBegin() const { return DirItemIterator(m_pIList.get(), -1, false, true); }
389 DirItemIterator RevEnd() const { return DirItemIterator(); }
390 DirItemIterator SelBegin() const { return DirItemIterator(m_pIList.get(), -1, true); }
391 DirItemIterator SelEnd() const { return DirItemIterator(); }
392 DirItemIterator SelRevBegin() const { return DirItemIterator(m_pIList.get(), -1, true, true); }
393 DirItemIterator SelRevEnd() const { return DirItemIterator(); }
396 #ifndef _DEBUG // debug version in DirView.cpp
397 inline CDirDoc* CDirView::GetDocument()
398 { return (CDirDoc*)m_pDocument; }
402 /////////////////////////////////////////////////////////////////////////////
404 //{{AFX_INSERT_LOCATION}}
405 // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
407 #endif // !defined(AFX_DirView_H__16E7C721_351C_11D1_95CD_444553540000__INCLUDED_)