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
27 /////////////////////////////////////////////////////////////////////////////
31 #include "OptionsDiffColors.h"
32 #include "SortHeaderCtrl.h"
33 #include "UnicodeString.h"
34 #include "DirItemIterator.h"
35 #include "DirActions.h"
37 class FileActionScript;
41 typedef enum { eMain, eContext } eMenuType;
48 class DirCompProgressBar;
51 class CLoadSaveCodepageDlg;
52 class CShellContextMenu;
54 class DirViewColItems;
55 class DirItemEnumerator;
59 * @brief Position value for special items (..) in directory compare view.
61 const uintptr_t SPECIAL_ITEM_POS = (uintptr_t) - 1L;
63 /** Default column width in directory compare */
64 const UINT DefColumnWidth = 150;
67 * @brief Directory compare results view.
69 * Directory compare view is list-view based, so it shows one result (for
70 * folder or file, commonly called as 'item') in one line. User can select
71 * visible columns, re-order columns, sort by column etc.
73 * Actual data is stored in CDiffContext in CDirDoc. Dircompare items and
74 * CDiffContext items are linked by storing POSITION of CDiffContext item
75 * as CDirView listitem key.
77 class CDirView : public CListView
79 friend struct FileCmpReport;
80 friend DirItemEnumerator;
82 CDirView(); // protected constructor used by dynamic creation
83 DECLARE_DYNCREATE(CDirView)
87 CDirDoc* GetDocument(); // non-debug version is inline
88 // const version, for const methods to be able to call
89 const CDirDoc * GetDocument() const { return const_cast<CDirView *>(this)->GetDocument(); }
90 const CDiffContext& GetDiffContext() const;
91 CDiffContext& GetDiffContext();
95 CDirFrame * GetParentFrame();
97 void StartCompare(CompareStats *pCompareStats);
99 void RedisplayChildren(uintptr_t diffpos, int level, UINT &index, int &alldiffs);
100 void UpdateResources();
101 void LoadColumnHeaderItems();
102 uintptr_t GetItemKey(int idx) const;
103 int GetItemIndex(uintptr_t key);
104 // for populating list
105 void DeleteItem(int sel);
106 void DeleteAllDisplayItems();
107 void SetFont(const LOGFONT & lf);
109 void SortColumnsAppropriately();
111 UINT GetSelectedCount() const;
112 int GetFirstSelectedInd();
113 void AddParentFolderItem(bool bEnable);
114 void RefreshOptions();
116 LRESULT HandleMenuMessage(UINT message, WPARAM wParam, LPARAM lParam);
120 void MoveToNextDiff();
121 void MoveToPrevDiff();
125 // Implementation types
128 // Implementation in DirActions.cpp
130 void GetItemFileNames(int sel, String& strLeft, String& strRight) const;
131 void GetItemFileNames(int sel, PathContext * paths) const;
132 void FormatEncodingDialogDisplays(CLoadSaveCodepageDlg * dlg);
133 bool IsItemLeftOnly(int code);
134 bool IsItemRightOnly(int code);
135 DirActions MakeDirActions(DirActions::method_type func) const;
136 DirActions MakeDirActions(DirActions::method_type2 func) const;
137 Counts Count(DirActions::method_type2 func) const;
138 void DoDirAction(DirActions::method_type func, const String& status_message);
139 void DoDirActionTo(SIDE_TYPE stype, DirActions::method_type func, const String& status_message);
140 void DoOpen(SIDE_TYPE stype);
141 void DoOpenWith(SIDE_TYPE stype);
142 void DoOpenWithEditor(SIDE_TYPE stype);
143 void DoUpdateOpen(SELECTIONTYPE selectionType, CCmdUI* pCmdUI);
144 void ConfirmAndPerformActions(FileActionScript & actions);
145 void PerformActionList(FileActionScript & actions);
146 void UpdateAfterFileScript(FileActionScript & actionList);
147 void DoFileEncodingDialog();
149 // End DirActions.cpp
150 void ReflectGetdispinfo(NMLVDISPINFO *);
152 // Implementation in DirViewColHandler.cpp
154 void UpdateColumnNames();
155 void SetColAlignments();
156 // class CompareState is used to pass parameters to the PFNLVCOMPARE callback function.
160 const DirViewColItems *const pColItems;
161 const CDiffContext *const pCtxt;
163 const bool bSortAscending;
164 const bool bTreeMode;
166 CompareState(const CDiffContext *pCtxt, const DirViewColItems *pColItems, int sortCol, bool bSortAscending, bool bTreeMode);
167 static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
169 void UpdateDiffItemStatus(UINT nIdx);
172 void NameColumn(const char* idname, int subitem);
173 int AddNewItem(int i, uintptr_t diffpos, int iImage, int iIndent);
174 // End DirViewCols.cpp
179 // ClassWizard generated virtual function overrides
180 //{{AFX_VIRTUAL(CDirView)
182 virtual void OnInitialUpdate();
184 virtual BOOL PreTranslateMessage(MSG* pMsg);
185 virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult);
186 virtual BOOL OnChildNotify(UINT, WPARAM, LPARAM, LRESULT*);
187 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
193 int GetFocusedItem();
194 int GetFirstDifferentItem();
195 int GetLastDifferentItem();
196 int AddSpecialItems();
197 void GetCurrentColRegKeys(std::vector<String>& colKeys);
198 void OpenSpecialItems(uintptr_t pos1, uintptr_t pos2, uintptr_t pos3);
200 // Implementation data
202 CSortHeaderCtrl m_ctlSortHeader;
203 CImageList m_imageList;
204 CImageList m_imageState;
206 std::unique_ptr<IListCtrl> m_pIList;
207 bool m_bEscCloses; /**< Cached value for option for ESC closing window */
208 bool m_bExpandSubdirs;
209 CFont m_font; /**< User-selected font */
210 UINT m_nHiddenItems; /**< Count of items we have hidden */
211 bool m_bTreeMode; /**< TRUE if tree mode is on*/
212 DirViewFilterSettings m_dirfilter;
213 std::unique_ptr<DirCompProgressBar> m_pCmpProgressBar;
214 clock_t m_compareStart; /**< Starting process time of the compare */
215 bool m_bUserCancelEdit; /**< TRUE if the user cancels rename */
216 String m_lastCopyFolder; /**< Last Copy To -target folder. */
220 bool m_bNeedSearchFirstDiffItem;
221 bool m_bNeedSearchLastDiffItem;
222 COLORSETTINGS m_cachedColors; /**< Cached color settings */
224 std::unique_ptr<CShellContextMenu> m_pShellContextMenuLeft; /**< Shell context menu for group of left files */
225 std::unique_ptr<CShellContextMenu> m_pShellContextMenuMiddle; /**< Shell context menu for group of middle files */
226 std::unique_ptr<CShellContextMenu> m_pShellContextMenuRight; /**< Shell context menu for group of right files */
227 HMENU m_hCurrentMenu; /**< Current shell context menu (either left or right) */
228 std::unique_ptr<DirViewTreeState> m_pSavedTreeState;
229 std::unique_ptr<DirViewColItems> m_pColItems;
231 // Generated message map functions
232 afx_msg void OnColumnClick(NMHDR* pNMHDR, LRESULT* pResult);
233 afx_msg void OnContextMenu(CWnd*, CPoint point);
234 //{{AFX_MSG(CDirView)
235 afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
236 template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
237 afx_msg void OnDirCopy();
238 template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
239 afx_msg void OnCtxtDirCopy();
240 template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
241 afx_msg void OnUpdateDirCopy(CCmdUI* pCmdUI);
242 template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
243 afx_msg void OnUpdateCtxtDirCopy(CCmdUI* pCmdUI);
244 template<SIDE_TYPE stype>
245 afx_msg void OnCtxtDirDel();
246 template<SIDE_TYPE stype>
247 afx_msg void OnUpdateCtxtDirDel(CCmdUI* pCmdUI);
248 afx_msg void OnCtxtDirDelBoth();
249 afx_msg void OnUpdateCtxtDirDelBoth(CCmdUI* pCmdUI);
250 template<SIDE_TYPE stype>
251 afx_msg void OnCtxtDirOpen();
252 template<SIDE_TYPE stype>
253 afx_msg void OnUpdateCtxtDirOpen(CCmdUI* pCmdUI);
254 template<SIDE_TYPE stype>
255 afx_msg void OnCtxtDirOpenWith();
256 template<SIDE_TYPE stype>
257 afx_msg void OnUpdateCtxtDirOpenWith(CCmdUI* pCmdUI);
258 template<SIDE_TYPE stype>
259 afx_msg void OnCtxtDirOpenWithEditor();
260 template<SIDE_TYPE stype>
261 afx_msg void OnUpdateCtxtDirOpenWithEditor(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 void OnToolsGeneratePatch();
300 afx_msg void OnCtxtDirZip();
301 template<SIDE_TYPE stype>
302 afx_msg void OnCtxtDirShellContextMenu();
303 afx_msg void OnUpdateCtxtDir(CCmdUI* pCmdUI);
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 OnUpdateOptionsShowdifferent(CCmdUI* pCmdUI);
346 afx_msg void OnUpdateOptionsShowidentical(CCmdUI* pCmdUI);
347 afx_msg void OnUpdateOptionsShowuniqueleft(CCmdUI* pCmdUI);
348 afx_msg void OnUpdateOptionsShowuniquemiddle(CCmdUI* pCmdUI);
349 afx_msg void OnUpdateOptionsShowuniqueright(CCmdUI* pCmdUI);
350 afx_msg void OnUpdateOptionsShowBinaries(CCmdUI* pCmdUI);
351 afx_msg void OnUpdateOptionsShowSkipped(CCmdUI* pCmdUI);
352 afx_msg void OnMergeCompare();
353 template<SELECTIONTYPE seltype>
354 afx_msg void OnMergeCompare2();
355 afx_msg void OnMergeCompareXML();
356 afx_msg void OnMergeCompareHex();
357 afx_msg void OnUpdateMergeCompare(CCmdUI *pCmdUI);
358 template<SELECTIONTYPE seltype>
359 afx_msg void OnUpdateMergeCompare2(CCmdUI *pCmdUI);
360 afx_msg void OnViewCompareStatistics();
361 afx_msg void OnFileEncoding();
362 afx_msg void OnUpdateFileEncoding(CCmdUI* pCmdUI);
363 afx_msg void OnHelp();
364 afx_msg void OnEditCopy();
365 afx_msg void OnEditCut();
366 afx_msg void OnEditPaste();
367 afx_msg void OnEditUndo();
368 afx_msg void OnUpdateEditUndo(CCmdUI* pCmdUI);
369 afx_msg void OnItemChanged(NMHDR* pNMHDR, LRESULT* pResult);
370 afx_msg void OnBeginLabelEdit(NMHDR* pNMHDR, LRESULT* pResult);
371 afx_msg void OnEndLabelEdit(NMHDR* pNMHDR, LRESULT* pResult);
372 afx_msg void OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult);
373 afx_msg void OnSearch();
374 afx_msg void OnExpandFolder();
375 afx_msg void OnCollapseFolder();
376 afx_msg void OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult);
377 afx_msg void OnBnClickedComparisonStop();
379 DECLARE_MESSAGE_MAP()
380 BOOL OnHeaderBeginDrag(LPNMHEADER hdr, LRESULT* pResult);
381 BOOL OnHeaderEndDrag(LPNMHEADER hdr, LRESULT* pResult);
384 void OpenSelection(SELECTIONTYPE selectionType = SELECTIONTYPE_NORMAL, PackingInfo * infoUnpacker = NULL);
385 void OpenSelectionHex();
386 bool GetSelectedItems(int * sel1, int * sel2, int * sel3);
387 void OpenParentDirectory();
388 template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
389 void DoUpdateDirCopy(CCmdUI* pCmdUI, eMenuType menuType);
390 const DIFFITEM & GetDiffItem(int sel) const;
391 DIFFITEM & GetDiffItem(int sel);
392 int GetSingleSelectedItem() const;
393 void MoveFocus(int currentInd, int i, int selCount);
395 void FixReordering();
396 void HeaderContextMenu(CPoint point, int i);
397 void ListContextMenu(CPoint point, int i);
398 bool ListShellContextMenu(SIDE_TYPE side);
399 void ShowShellContextMenu(SIDE_TYPE side);
400 CShellContextMenu* GetCorrespondingShellContextMenu(HMENU hMenu) const;
401 void ReloadColumns();
402 bool IsLabelEdit() const;
403 void CollapseSubdir(int sel);
404 void ExpandSubdir(int sel, bool bRecursive = false);
405 void GetColors(int nRow, int nCol, COLORREF& clrBk, COLORREF& clrText) const;
407 DirItemIterator Begin() const { return DirItemIterator(m_pIList.get()); }
408 DirItemIterator End() const { return DirItemIterator(); }
409 DirItemIterator RevBegin() const { return DirItemIterator(m_pIList.get(), -1, false, true); }
410 DirItemIterator RevEnd() const { return DirItemIterator(); }
411 DirItemIterator SelBegin() const { return DirItemIterator(m_pIList.get(), -1, true); }
412 DirItemIterator SelEnd() const { return DirItemIterator(); }
413 DirItemIterator SelRevBegin() const { return DirItemIterator(m_pIList.get(), -1, true, true); }
414 DirItemIterator SelRevEnd() const { return DirItemIterator(); }
417 #ifndef _DEBUG // debug version in DirView.cpp
418 inline CDirDoc* CDirView::GetDocument()
419 { return reinterpret_cast<CDirDoc*>(m_pDocument); }
423 /////////////////////////////////////////////////////////////////////////////
425 //{{AFX_INSERT_LOCATION}}
426 // Microsoft Developer Studio will insert additional declarations immediately before the previous line.