Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

580 lines
19 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: cclvctl.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _CCLVCTL_H_
  11. #define _CCLVCTL_H_
  12. // cclvctl.h : header file
  13. //
  14. #include <objbase.h>
  15. #include <atlbase.h>
  16. #include <atlcom.h>
  17. #include "imagemap.h"
  18. #include "ndmgr.h"
  19. #include "fontlink.h"
  20. #include "amcnav.h"
  21. #include "dd.h"
  22. #include "columninfo.h"
  23. // Don't let macro override CWnd method
  24. #undef SubclassWindow
  25. class CAMCView;
  26. class CCCListViewCtrl;
  27. class CResultItem;
  28. class CListFontLinker : public CFontLinker
  29. {
  30. public:
  31. CListFontLinker (CCCListViewCtrl* pListCtrl) : m_pListCtrl (pListCtrl)
  32. { ASSERT (m_pListCtrl != NULL); }
  33. protected:
  34. virtual bool IsAnyItemLocalizable () const;
  35. virtual std::wstring GetItemText (NMCUSTOMDRAW* pnmcd) const;
  36. private:
  37. CCCListViewCtrl* const m_pListCtrl;
  38. };
  39. class CSysColorImageList : public CImageList
  40. {
  41. public:
  42. CSysColorImageList (HINSTANCE hInst, UINT nID)
  43. : m_hInst (hInst),
  44. m_hRsrc (::FindResource (m_hInst, MAKEINTRESOURCE (nID), RT_BITMAP))
  45. {
  46. CreateSysColorImageList();
  47. }
  48. void OnSysColorChange ()
  49. {
  50. DeleteImageList();
  51. CreateSysColorImageList();
  52. }
  53. operator HIMAGELIST() const
  54. {
  55. return (CImageList::operator HIMAGELIST());
  56. }
  57. private:
  58. void CreateSysColorImageList ()
  59. {
  60. CBitmap bmp;
  61. bmp.Attach (AfxLoadSysColorBitmap (m_hInst, m_hRsrc));
  62. /*
  63. * get the dimensions of the bitmap
  64. */
  65. BITMAP bm;
  66. bmp.GetBitmap (&bm);
  67. /*
  68. * assume square images (cx == cy)
  69. */
  70. Create (bm.bmHeight, bm.bmHeight, ILC_COLORDDB, bm.bmWidth / bm.bmHeight, 2);
  71. Add (&bmp, CLR_NONE);
  72. }
  73. HINSTANCE m_hInst;
  74. HRSRC m_hRsrc;
  75. };
  76. class CAMCHeaderCtrl : public CHeaderCtrl
  77. {
  78. public:
  79. bool IsColumnHidden(int iCol);
  80. protected:
  81. afx_msg void OnSetFocus(CWnd *pOldWnd);
  82. afx_msg BOOL OnSetCursor( CWnd* pWnd, UINT nHitTest, UINT message );
  83. DECLARE_MESSAGE_MAP()
  84. };
  85. class CFocusHandler
  86. {
  87. public:
  88. virtual void OnKeyboardFocus(UINT nState, UINT nStateMask) = 0;
  89. };
  90. /////////////////////////////////////////////////////////////////////////////
  91. // CAMCListView
  92. class CAMCListView :
  93. public CListView,
  94. public CAMCNavigator,
  95. public CFocusHandler,
  96. public CMMCViewDropTarget,
  97. public CEventSource<CListViewActivationObserver>
  98. {
  99. // Construction
  100. public:
  101. CAMCListView() :
  102. m_bVirtual(false),
  103. m_iDropTarget(-1),
  104. m_pAMCView(NULL),
  105. m_bColumnsNeedToBeRestored(true),
  106. m_bColumnsBeingRestored(false)
  107. {
  108. DEBUG_INCREMENT_INSTANCE_COUNTER(CAMCListView);
  109. }
  110. ~CAMCListView()
  111. {
  112. if (m_header.m_hWnd)
  113. m_header.UnsubclassWindow();
  114. DEBUG_DECREMENT_INSTANCE_COUNTER(CAMCListView);
  115. }
  116. // CFocusHandler implementation
  117. virtual void OnKeyboardFocus(UINT nState, UINT nStateMask);
  118. // CAMCNavigator implementation
  119. virtual BOOL ChangePane(AMCNavDir eDir);
  120. virtual BOOL TakeFocus(AMCNavDir eDir);
  121. SC ScOnColumnsAttributeChanged(NMHEADER *pNMHeader, UINT code);
  122. // Setup header width/order/hiddenness from columninfolist data.
  123. SC ScRestoreColumnsFromPersistedData();
  124. SC ScGetColumnInfoList(CColumnInfoList *pColumnsList);
  125. SC ScModifyColumns(const CColumnInfoList& colInfoList);
  126. SC ScSaveColumnInfoList();
  127. SC ScGetDefaultColumnInfoList(CColumnInfoList& columnsList);
  128. SC ScResetColumnStatusData();
  129. // Overrides
  130. // ClassWizard generated virtual function overrides
  131. //{{AFX_VIRTUAL(CAMCListView)
  132. public:
  133. virtual BOOL OnCmdMsg( UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo );
  134. protected:
  135. virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
  136. virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  137. //}}AFX_VIRTUAL
  138. public:
  139. virtual SC ScDropOnTarget(bool bHitTestOnly, IDataObject * pDataObject, CPoint pt, bool& bCopyOperation);
  140. virtual void RemoveDropTargetHiliting();
  141. void SetVirtual()
  142. {
  143. m_bVirtual = true;
  144. }
  145. bool IsInLargeIconMode() const
  146. {
  147. return (GetMode() == LVS_ICON);
  148. }
  149. bool IsInSmallIconMode() const
  150. {
  151. return (GetMode() == LVS_SMALLICON);
  152. }
  153. bool IsInListMode() const
  154. {
  155. return (GetMode() == LVS_LIST);
  156. }
  157. bool IsInReportMode() const
  158. {
  159. return (GetMode() == LVS_REPORT);
  160. }
  161. bool IsInFilteredReportMode() const
  162. {
  163. if (!IsInReportMode())
  164. return (false);
  165. CWnd* pwndHeader = GetHeaderCtrl();
  166. if (pwndHeader == NULL)
  167. return (false);
  168. return (pwndHeader->GetStyle() & HDS_FILTERBAR);
  169. }
  170. DWORD SetExtendedListViewStyle (DWORD dwExStyle, DWORD dwExMask = 0)
  171. {
  172. return (SendMessage (LVM_SETEXTENDEDLISTVIEWSTYLE, dwExMask, dwExStyle));
  173. }
  174. CAMCView* GetAMCView() const
  175. {
  176. return (m_pAMCView);
  177. }
  178. CAMCHeaderCtrl* GetHeaderCtrl() const;
  179. bool AreColumnsNeedToBeRestored() const { return m_bColumnsNeedToBeRestored;}
  180. void SetColumnsNeedToBeRestored(bool b = false) {m_bColumnsNeedToBeRestored = b;}
  181. bool IsColumnHidden(int iCol) const;
  182. protected:
  183. //{{AFX_MSG(CAMCListView)
  184. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  185. afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
  186. afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  187. afx_msg void OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  188. afx_msg void OnSysChar(UINT nChar, UINT nRepCnt, UINT nFlags);
  189. afx_msg void OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult);
  190. afx_msg void OnBeginRDrag(NMHDR* pNMHDR, LRESULT* pResult);
  191. afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
  192. afx_msg void OnSetFocus(CWnd* pOldWnd);
  193. afx_msg void OnPaint();
  194. afx_msg void OnSize(UINT nType, int cx, int cy);
  195. afx_msg void OnBeginTrack(NMHDR * pNotifyStruct, LRESULT * result);
  196. //}}AFX_MSG
  197. afx_msg LRESULT OnColumnPersistedDataChanged (WPARAM, LPARAM);
  198. DECLARE_MESSAGE_MAP()
  199. private:
  200. bool m_bVirtual;
  201. CAMCView* m_pAMCView;
  202. mutable CAMCHeaderCtrl m_header; // mutable so GetHeaderCtrl can call CWnd::SubclassWindow
  203. int m_iDropTarget;
  204. CColumnInfoList m_defaultColumnInfoList;
  205. INodeCallback* GetNodeCallback();
  206. HNODE GetScopePaneSelNode();
  207. void SelectDropTarget(int iDropTarget);
  208. bool ActivateSelf (bool fNotify = true);
  209. bool NeedsCustomPaint ();
  210. SC ScGetDropTarget(const CPoint& point, HNODE& hNode, bool& bScope, LPARAM& lvData, int& iDrop);
  211. DWORD GetMode () const
  212. {
  213. return (GetStyle() & LVS_TYPEMASK);
  214. }
  215. private:
  216. // For columns
  217. static const UINT m_nColumnPersistedDataChangedMsg;
  218. // To allow hidden column width changes.
  219. bool m_bColumnsBeingRestored;
  220. // We dont care if restore is success or failure.
  221. bool m_bColumnsNeedToBeRestored;
  222. };
  223. /////////////////////////////////////////////////////////////////////////////
  224. // CCCListViewCtrl window
  225. class CCCListViewCtrl :
  226. public IMMCListView,
  227. public CComObjectRoot,
  228. public CEventSource<CListViewObserver>,
  229. public CTiedObject
  230. {
  231. // Construction
  232. public:
  233. CCCListViewCtrl();
  234. virtual ~CCCListViewCtrl();
  235. // initialization
  236. SC ScInitialize();
  237. BEGIN_COM_MAP(CCCListViewCtrl)
  238. COM_INTERFACE_ENTRY(IMMCListView)
  239. END_COM_MAP()
  240. typedef struct _SortParams
  241. {
  242. BOOL bAscending; // sort direction
  243. BOOL bLexicalSort; // apply default sort to all items
  244. int nCol; // Which column to sort on.
  245. COMPONENTID OwnerID;
  246. void * lpListView; // CCCListViewCtrl *
  247. IResultDataComparePtr spResultCompare; // Snap-in component interface
  248. IResultDataCompareExPtr spResultCompareEx; // "
  249. LPNODECALLBACK lpNodeCallback;
  250. LPARAM lpUserParam; // parameter user passes in
  251. HNODE hSelectedNode; // Currently selected node in scope pane.
  252. } SortParams;
  253. //DECLARE_AGGREGATABLE(CCCListViewCtrl)
  254. //DECLARE_REGISTRY(CNodeInitObject, _T("NODEMGR.NodeInitObject.1"), _T("NODEMGR.NodeInitObject.1"), IDS_NODEINIT_DESC, THREADFLAGS_BOTH)
  255. // Operations
  256. public:
  257. #ifdef IMPLEMENT_LIST_SAVE // See nodemgr.idl (t-dmarm)
  258. long GetColCount() const { return m_colCount; }
  259. long GetItemCount() const { return m_itemCount; }
  260. #endif
  261. CAMCListView* GetListViewPtr() const { return m_pListView; }
  262. CListCtrl& GetListCtrl() const { return m_pListView->GetListCtrl(); }
  263. CAMCHeaderCtrl* GetHeaderCtrl() const { return m_pListView->GetHeaderCtrl(); }
  264. bool AreColumnsNeedToBeRestored() const { return m_pListView->AreColumnsNeedToBeRestored();}
  265. void SetColumnsNeedToBeRestored(bool b = true) {m_pListView->SetColumnsNeedToBeRestored(b);}
  266. bool IsColumnHidden(int iCol) const {return m_pListView->IsColumnHidden(iCol);}
  267. SC ScGetAMCView(CAMCView **ppAMCView);
  268. HWND GetListViewHWND() const { if (m_pListView) return m_pListView->GetSafeHwnd(); else return NULL;}
  269. BOOL IsVirtual() const { return m_bVirtual; }
  270. BOOL Create( DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext=NULL);
  271. SC ScAttachToListPad (HWND hwnd, HWND* phwnd); // NULL hwnd == detach
  272. BOOL IsListPad () const { return m_SavedHWND != NULL; }
  273. LRESULT OnCustomDraw (NMLVCUSTOMDRAW* plvcd);
  274. void OnSysColorChange();
  275. // IMMCListView Methods
  276. STDMETHOD(GetListStyle) ();
  277. STDMETHOD(SetListStyle) (long nNewValue);
  278. STDMETHOD(GetViewMode) ();
  279. STDMETHOD(SetViewMode) (long nViewMode);
  280. STDMETHOD(InsertItem) (LPOLESTR str, long iconNdx, LPARAM lParam, long state, COMPONENTID ownerID, long itemIndex, CResultItem*& pri);
  281. STDMETHOD(DeleteItem) (HRESULTITEM itemID, long nCol);
  282. STDMETHOD(FindItemByLParam) (COMPONENTID ownerID, LPARAM lParam, CResultItem*& pri);
  283. STDMETHOD(InsertColumn) (int nCol, LPCOLESTR str, long nFormat, long width);
  284. STDMETHOD(DeleteColumn) (int nCol);
  285. STDMETHOD(DeleteAllItems) (COMPONENTID ownerID);
  286. STDMETHOD(SetColumn) (long nCol, LPCOLESTR str, long nFormat, long width);
  287. STDMETHOD(GetColumn) (long nCol, LPOLESTR* str, LPLONG nFormat, int FAR* width);
  288. STDMETHOD(GetColumnCount) (int* pnColCnt);
  289. STDMETHOD(SetItem) (int nIndex, CResultItem* pri, long nCol, LPOLESTR str, long nImage, LPARAM lParam, long nState, COMPONENTID ownerID);
  290. STDMETHOD(GetItem) (int nIndex, CResultItem*& pri, long nCol, LPOLESTR* str, int FAR *nImage, LPARAM* lParam, unsigned int FAR *nState, BOOL* pbScopeItem);
  291. STDMETHOD(GetNextItem) (COMPONENTID ownerID, long nIndex, UINT nState, CResultItem*& pri, long& nIndexNextItem);
  292. STDMETHOD(GetLParam) (long nItem, CResultItem*& pri);
  293. STDMETHOD(ModifyItemState) (long nItem, CResultItem* pri, UINT add, UINT remove);
  294. STDMETHOD(SetIcon) (long nID, HICON hIcon, long nLoc);
  295. STDMETHOD(SetImageStrip) (long nID, HBITMAP hbmSmall, HBITMAP hbmLarge, long nStartLoc, long cMask);
  296. STDMETHOD(MapImage) (COMPONENTID nID, long nLoc, int far *pResult);
  297. STDMETHOD(Reset) ();
  298. STDMETHOD(Arrange) (long style);
  299. STDMETHOD(UpdateItem) (HRESULTITEM itemID);
  300. STDMETHOD(Sort) (LPARAM lUserParam, long* lpParams);
  301. STDMETHOD(SetItemCount) (int nItemCount, DWORD dwOptions);
  302. STDMETHOD(SetVirtualMode) (BOOL bVirtual);
  303. STDMETHOD(Repaint) (BOOL bErase);
  304. STDMETHOD(SetChangeTimeOut) (ULONG lTimeout);
  305. STDMETHOD(SetColumnFilter) (int nCol, DWORD dwType, MMC_FILTERDATA* pFilterData);
  306. STDMETHOD(GetColumnFilter) (int nCol, DWORD* dwType, MMC_FILTERDATA* pFilterData);
  307. STDMETHOD(SetColumnSortIcon) (int nNewCol, int nOldCol, BOOL bAscending, BOOL bSetSortIcon);
  308. STDMETHOD(SetLoadMode) (BOOL bState);
  309. STDMETHOD(GetColumnInfoList) (CColumnInfoList *pColumnsList);
  310. STDMETHOD(ModifyColumns) (const CColumnInfoList& columnsList);
  311. STDMETHOD(RenameItem) (HRESULTITEM itemID);
  312. STDMETHOD(GetDefaultColumnInfoList)( CColumnInfoList& columnsList);
  313. STDMETHOD(OnModifyItem)(CResultItem* pri);
  314. void CutSelectedItems(BOOL b);
  315. bool UseFontLinking() const;
  316. UINT GetSelectedCount()
  317. { return (GetListCtrl().GetSelectedCount()); }
  318. // these methods implement access to enumerations for AMCView
  319. SC Scget_ListItems( PPNODES ppNodes );
  320. SC Scget_SelectedItems( PPNODES ppNodes);
  321. SC ScSelect( PNODE pNode);
  322. SC ScDeselect( PNODE pNode);
  323. SC ScIsSelected( PNODE pNode, PBOOL pIsSelected);
  324. SC ScSelectAll();
  325. // method used from Nodes collections
  326. SC ScValidateItem( int iItem, bool &bScopeNode );
  327. // method transfering requests from Nodes to AMCView (for scope nodes only)
  328. SC ScGetScopeNodeForItem ( int iItem, PPNODE ppNode );
  329. // Columns access methods
  330. SC Scget_Columns( PPCOLUMNS Columns );
  331. SC ScItem( long Index, PPCOLUMN ppColumn );
  332. SC Scget_Count( PLONG pCount );
  333. SC ScEnumNext(int &pos, PDISPATCH & pDispatch); // should return the next element.
  334. SC ScEnumSkip(unsigned long celt, unsigned long& celtSkipped, int &pos);
  335. SC ScEnumReset(int &pos);
  336. // methods called from Column instances
  337. SC ScName( /*[out, retval]*/ BSTR *Name, int iColIndex );
  338. SC Scget_Width( /*[out, retval]*/ PLONG Width, int iColIndex );
  339. SC Scput_Width( /*[in]*/ long Width, int iColIndex );
  340. SC Scget_DisplayPosition( /*[out, retval]*/ PLONG DisplayPosition, int iColIndex );
  341. SC Scput_DisplayPosition( /*[in]*/ long Index, int iColIndex );
  342. SC Scget_Hidden( /*[out, retval]*/ PBOOL Hidden, int iColIndex );
  343. SC Scput_Hidden( /*[in]*/ BOOL Hidden , int iColIndex );
  344. SC ScSetAsSortColumn( /*[in]*/ ColumnSortOrder SortOrder, int iColIndex );
  345. SC ScIsSortColumn( PBOOL IsSortColumn, int iColIndex );
  346. // Column/Columns implementation helpers
  347. struct ColumnData
  348. {
  349. int iColumnWidth;
  350. int iColumnOrder;
  351. bool bIsHidden;
  352. // initialization
  353. void Init() { iColumnWidth = 0; iColumnOrder = -1; bIsHidden = false; }
  354. ColumnData() { Init(); }
  355. // comparison
  356. bool operator == (const ColumnData& other) const
  357. { return ( 0 == memcmp(this, &other, sizeof(ColumnData)) ); }
  358. };
  359. SC ScGetColumnData( int iZeroBasedColIndex, ColumnData *pColData );
  360. SC ScSetColumnData( int iZeroBasedColIndex, const ColumnData& ColData );
  361. SC ScFindResultItem ( PNODE pNode, int &iItem );
  362. private:
  363. // helper methods
  364. SC ScGetNodesEnum ( bool bSelectedItemsOnly, PPNODES ppNodes );
  365. SC ScAllocResultItem ( CResultItem*& pResultItem, COMPONENTID id, LPARAM lSnapinData, int nImage);
  366. SC ScFreeResultItem ( CResultItem* pResultItem);
  367. SC ScRedrawItem (int nIndex);
  368. SC ScGetItemIndexFromHRESULTITEM(const HRESULTITEM& itemID, int& nIndex);
  369. SC ScRedrawHeader(bool bRedraw);
  370. protected:
  371. CAMCListView* m_pListView; // current list (points to m_StandardList or m_VirtualList)
  372. CAMCListView* m_pStandardList;
  373. CAMCListView* m_pVirtualList;
  374. HWND m_SavedHWND;
  375. WINDOWPLACEMENT m_wp;
  376. CWnd* m_pParentWnd;
  377. //void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  378. //void OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  379. long m_itemCount; // internal item counter
  380. long m_nScopeItems; // scope item count
  381. long m_colCount; // internal column counter
  382. // ImageList members
  383. CImageList m_smallIL;
  384. CImageList m_largeIL;
  385. CImageIndexMap m_resultIM;
  386. // Header Sorting (Up/Down arrow) Icons.
  387. CSysColorImageList m_headerIL;
  388. // Sorting members
  389. SortParams m_sortParams;
  390. static int CALLBACK SortCompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM pSortParams);
  391. static int SnapinCompare(SortParams* pSortParams, CResultItem* pri1, CResultItem* pri2);
  392. static int SnapinCompareEx(SortParams* pSortParams, CResultItem* pri1, CResultItem* pri2);
  393. static int CALLBACK DefaultCompare(LPARAM lParam1, LPARAM lParam2, LPARAM pSortParams);
  394. private:
  395. CListFontLinker m_FontLinker;
  396. NodesPtr m_spAllNodes;
  397. NodesPtr m_spSelNodes;
  398. ColumnsPtr m_spColumns;
  399. BOOL m_bVirtual;
  400. BOOL m_bFiltered; // filtering on now
  401. BOOL m_bEnsureFocusVisible; // force focused item to be visible
  402. BOOL m_bLoading;
  403. BOOL m_bDeferredSort;
  404. void SetFilterHeader(void);
  405. SC ScSetImageLists ();
  406. int ResultItemToIndex (CResultItem* pri) const;
  407. CResultItem* IndexToResultItem (int nItem);
  408. };
  409. ////////////////////////////////////////////////////////////////////////////
  410. // CQFilterDll
  411. //
  412. // This class dynamically loads and initializes the quickfilter DLL.
  413. // A single instance of the class should be declared at the global level.
  414. //
  415. class CQFilterDll
  416. {
  417. public:
  418. CQFilterDll()
  419. {
  420. m_hModule = LoadLibrary(_T("qfctrl.dll"));
  421. if (m_hModule != NULL)
  422. {
  423. void (*pfnInitQuickFilter)();
  424. pfnInitQuickFilter = (void (*)())GetProcAddress(m_hModule, "InitQuickFilter");
  425. if (pfnInitQuickFilter != NULL)
  426. (*pfnInitQuickFilter)();
  427. }
  428. }
  429. CQFilterDll::~CQFilterDll()
  430. {
  431. if (m_hModule != NULL)
  432. FreeLibrary(m_hModule);
  433. }
  434. private:
  435. HMODULE m_hModule;
  436. };
  437. /*+-------------------------------------------------------------------------*
  438. * CHiddenColumnInfo
  439. *
  440. * Contains information about a hidden column in report view: a flag
  441. * indicating it's hidden and its width when it's not hidden.
  442. *
  443. * This class is stored in HDITEM.lParam for hidden columns, so it *must*
  444. * be the same size as an LPARAM.
  445. *--------------------------------------------------------------------------*/
  446. class CHiddenColumnInfo
  447. {
  448. public:
  449. CHiddenColumnInfo (LPARAM lParam_) : lParam (lParam_)
  450. {
  451. COMPILETIME_ASSERT (sizeof(CHiddenColumnInfo) == sizeof(LPARAM));
  452. }
  453. CHiddenColumnInfo (int cx_, bool fHidden_) : cx (cx_), fHidden (fHidden_)
  454. {
  455. COMPILETIME_ASSERT (sizeof(CHiddenColumnInfo) == sizeof(LPARAM));
  456. }
  457. union
  458. {
  459. LPARAM lParam;
  460. struct
  461. {
  462. int cx : 16;
  463. int fHidden : 1;
  464. };
  465. };
  466. };
  467. #endif _CCLVCTL_H_