Source code of Windows XP (NT5)
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.

308 lines
11 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1999
  5. //
  6. // File: dragdroptest.hxx
  7. //
  8. // Contents: Classes that implement Drag&Drop test snapin using the framework.
  9. //
  10. //--------------------------------------------------------------------
  11. #ifndef _DRAGDROPTEST_H_
  12. #define _DRAGDROPTEST_H_
  13. // Forward declarations.
  14. class CDragDropSnapinLVContainer;
  15. class CDragDropSnapinLVLeafItem;
  16. class CDragDropSnapin;
  17. typedef vector<tstring> StringVector;
  18. //+-------------------------------------------------------------------
  19. //
  20. // Class: CDragDropSnapinRootItem
  21. //
  22. // Purpose: Implements the root item for a standalone snapin.
  23. //
  24. //--------------------------------------------------------------------
  25. class CDragDropSnapinRootItem : public CBaseSnapinItem
  26. {
  27. typedef CBaseSnapinItem super;
  28. // Used by CBaseSnapinItem::ScCreateItem, connect this item with its children.
  29. typedef CComObject<CSnapinItem<CDragDropSnapinRootItem> > t_item;
  30. typedef CComObject<CSnapinItem<CDragDropSnapinLVContainer> > t_itemChild; // Who is my child?
  31. public:
  32. CDragDropSnapinRootItem( void ) {} // Raw constructor - use only for static item.
  33. virtual ~CDragDropSnapinRootItem( void ) {}
  34. BEGIN_COM_MAP(CDragDropSnapinRootItem)
  35. COM_INTERFACE_ENTRY(IDataObject) // Cant have empty map so add IDataObject
  36. END_COM_MAP()
  37. protected:
  38. // Item tree related information
  39. // node type related information
  40. virtual const CNodeType* Pnodetype( void ) { return &nodetypeDragDropRoot;}
  41. // the display name of the item
  42. virtual const tstring* PstrDisplayName( void ) { return &m_strDisplayName;}
  43. // Get ListView data (GetDisplayInfo calls this).
  44. virtual SC ScGetField(DAT dat, tstring& strField);
  45. // Image list information
  46. virtual LONG Iconid() { return m_uIconIndex; }
  47. virtual LONG OpenIconid() { return m_uIconIndex; }
  48. virtual BOOL FIsContainer( void ) { return TRUE; }
  49. // Context menu support
  50. virtual SnapinMenuItem *Pmenuitem(void);
  51. virtual INT CMenuItem(void);
  52. virtual SC ScCommand(long nCommandID, CComponent *pComponent = NULL);
  53. virtual DWORD DwFlagsMenuChecked(void) { return TRUE;}
  54. public:
  55. virtual SC ScInit(CBaseSnapin *pSnapin, CColumnInfoEx *pcolinfoex = NULL, INT ccolinfoex = 0, BOOL fIsRoot = FALSE);
  56. virtual SC ScInitializeChild(CBaseSnapinItem* pitem);
  57. public:
  58. // Creates children for the node
  59. virtual SC ScCreateChildren( void );
  60. void SetDisplayName(tstring & strItemName) { m_strDisplayName = strItemName; }
  61. SC _ScDeleteCutItem(tstring& strItemName)
  62. {
  63. StringVector::iterator itItem = std::find(m_vecContainerItems.begin(),
  64. m_vecContainerItems.end(),
  65. strItemName);
  66. if (itItem == m_vecContainerItems.end())
  67. return S_FALSE;
  68. m_vecContainerItems.erase(itItem);
  69. return S_OK;
  70. }
  71. protected:
  72. virtual SC ScGetVerbs(DWORD * pdwVerbs) { *pdwVerbs = 0; return S_OK;}
  73. protected:
  74. tstring m_strDisplayName;
  75. UINT m_uIconIndex;
  76. StringVector m_vecContainerItems;
  77. static int s_iNextChildID;
  78. // For context menus
  79. static SnapinMenuItem s_rgmenuitemRoot[];
  80. static INT s_cmenuitemRoot;
  81. };
  82. //+-------------------------------------------------------------------
  83. //
  84. // Class: CDragDropSnapinLVContainer
  85. //
  86. // Purpose: Implements a scope pane item.
  87. //
  88. //--------------------------------------------------------------------
  89. class CDragDropSnapinLVContainer : public CBaseSnapinItem
  90. {
  91. typedef CBaseSnapinItem super;
  92. // Used by CBaseSnapinItem::ScCreateItem, connect this item with its children.
  93. typedef CComObject<CSnapinItem<CDragDropSnapinLVContainer> > t_item;
  94. typedef CComObject<CSnapinItem<CDragDropSnapinLVLeafItem> > t_itemChild;
  95. public:
  96. CDragDropSnapinLVContainer( void ) {}
  97. virtual ~CDragDropSnapinLVContainer( void ) {}
  98. BEGIN_COM_MAP(CDragDropSnapinLVContainer)
  99. COM_INTERFACE_ENTRY(IDataObject) // Cant have empty map so add IDataObject
  100. END_COM_MAP()
  101. protected:
  102. // Item tree related information
  103. // node type related information
  104. const CNodeType *Pnodetype( void ) { return &nodetypeDragDropLVContainer;}
  105. // the display name of the item
  106. virtual const tstring* PstrDisplayName( void ) { return &m_strDisplayName;}
  107. // Get ListView data (GetDisplayInfo calls this).
  108. virtual SC ScGetField(DAT dat, tstring& strField);
  109. // Image list information
  110. virtual LONG Iconid() { return m_uIconIndex; }
  111. virtual LONG OpenIconid() { return m_uIconIndex; }
  112. // This item attributes.
  113. virtual BOOL FIsContainer( void ) { return TRUE; }
  114. virtual BOOL FAllowMultiSelectionForChildren() { return TRUE;}
  115. virtual BOOL FAllowPasteForResultItems();
  116. public:
  117. virtual SC ScInit(CBaseSnapin *pSnapin, CColumnInfoEx *pcolinfoex = NULL, INT ccolinfoex = 0, BOOL fIsRoot = FALSE);
  118. public:
  119. // Creates children for the node
  120. virtual SC ScCreateChildren( void );
  121. static SC ScCreateLVContainer(CBaseSnapinItem *pitemParent, CBaseSnapinItem *pitemPrevious, CDragDropSnapinLVContainer ** ppitem, BOOL fNew);
  122. void SetDisplayName(tstring & strItemName) { m_strDisplayName = strItemName;}
  123. void SetDisplayIndex(int index) { m_index = index;}
  124. SC _ScDeleteCutItem(tstring& strItemName, bool bContainerItem)
  125. {
  126. StringVector::iterator itItem;
  127. StringVector& vecStrings = bContainerItem ? m_vecContainerItems : m_vecLeafItems;
  128. itItem = std::find(vecStrings.begin(), vecStrings.end(), strItemName);
  129. if (itItem == vecStrings.end())
  130. return S_FALSE;
  131. vecStrings.erase(itItem);
  132. return S_OK;
  133. }
  134. public: // Notification handlers
  135. virtual SC ScOnQueryPaste(LPDATAOBJECT pDataObject, BOOL *pfCanPaste);
  136. virtual SC ScOnDelete(BOOL *pfDeleted) { *pfDeleted = TRUE; return S_OK;}
  137. virtual SC ScOnSelect(CComponent * pComponent, LPDATAOBJECT lpDataObject, BOOL fScope, BOOL fSelect);
  138. virtual SC ScOnPaste(LPDATAOBJECT pDataObject, BOOL fMove, BOOL *pfPasted);
  139. virtual SC ScOnCutOrMove();
  140. protected:
  141. virtual SC ScGetVerbs(DWORD * pdwVerbs) { *pdwVerbs = vmCopy | vmDelete | vmPaste; return S_OK;}
  142. protected:
  143. tstring m_strDisplayName;
  144. int m_index; // ID given by container of this item.
  145. UINT m_uIconIndex;
  146. StringVector m_vecContainerItems;
  147. StringVector m_vecLeafItems;
  148. };
  149. //+-------------------------------------------------------------------
  150. //
  151. // Class: CDragDropSnapinLVLeafItem
  152. //
  153. // Purpose: Implements a result pane item.
  154. //
  155. //--------------------------------------------------------------------
  156. class CDragDropSnapinLVLeafItem : public CBaseSnapinItem
  157. {
  158. typedef CBaseSnapinItem super;
  159. // Used by CBaseSnapinItem::ScCreateItem, connect this item with its children.
  160. // This is a leaf item so this item acts as its child.
  161. typedef CComObject<CSnapinItem<CDragDropSnapinLVLeafItem> > t_item;
  162. typedef CComObject<CSnapinItem<CDragDropSnapinLVLeafItem> > t_itemChild;
  163. public:
  164. CDragDropSnapinLVLeafItem( void ) {}
  165. virtual ~CDragDropSnapinLVLeafItem( void ) {}
  166. BEGIN_COM_MAP(CDragDropSnapinLVLeafItem)
  167. COM_INTERFACE_ENTRY(IDataObject) // Cant have empty map so add IDataObject
  168. END_COM_MAP()
  169. protected:
  170. // Item tree related information
  171. // node type related information
  172. virtual const CNodeType *Pnodetype( void ) {return &nodetypeDragDropLVLeafItem;}
  173. // the display name of the item
  174. virtual const tstring* PstrDisplayName( void ) { return &m_strDisplayName; }
  175. // Get ListView data (GetDisplayInfo calls this).
  176. virtual SC ScGetField(DAT dat, tstring& strField);
  177. // Image list information
  178. virtual LONG Iconid() { return m_uIconIndex; }
  179. virtual BOOL FIsContainer( void ) { return FALSE; }
  180. public:
  181. virtual SC ScInit(CBaseSnapin *pSnapin, CColumnInfoEx *pcolinfoex = NULL, INT ccolinfoex = 0, BOOL fIsRoot = FALSE);
  182. public:
  183. static SC ScCreateLVLeafItem(CBaseSnapinItem *pitemParent, CBaseSnapinItem * pitemPrevious, CDragDropSnapinLVLeafItem ** ppitem, BOOL fNew);
  184. void SetDisplayName(tstring & strItemName) { m_strDisplayName = strItemName; }
  185. public: // Notification handlers
  186. virtual SC ScOnQueryPaste(LPDATAOBJECT pDataObject, BOOL *pfCanPaste);
  187. virtual SC ScOnDelete(BOOL *pfDeleted) { *pfDeleted = TRUE; return S_OK;}
  188. virtual SC ScOnSelect(CComponent * pComponent, LPDATAOBJECT lpDataObject, BOOL fScope, BOOL fSelect);
  189. virtual SC ScOnPaste(LPDATAOBJECT pDataObject, BOOL fMove, BOOL *pfPasted);
  190. virtual SC ScOnCutOrMove();
  191. virtual SC ScOnRename(const tstring& strNewName) { m_strDisplayName = strNewName; return S_OK;}
  192. protected:
  193. virtual SC ScGetVerbs(DWORD * pdwVerbs);
  194. private:
  195. tstring m_strDisplayName;
  196. UINT m_uIconIndex;
  197. tstring m_strItemPasted;
  198. };
  199. //+-------------------------------------------------------------------
  200. //
  201. // Class: CDragDropSnapin
  202. //
  203. // Purpose: Implements a snapin.
  204. //
  205. //--------------------------------------------------------------------
  206. class CDragDropSnapin : public CBaseSnapin
  207. {
  208. // Specify the root node of the snapin.
  209. typedef CComObject<CSnapinItem<CDragDropSnapinRootItem> > t_itemRoot;
  210. SNAPIN_DECLARE(CDragDropSnapin);
  211. public:
  212. CDragDropSnapin();
  213. virtual ~CDragDropSnapin();
  214. // information about the snapin and root (ie initial) node
  215. virtual BOOL FStandalone() { return TRUE; }
  216. virtual BOOL FIsExtension() { return FALSE; }
  217. virtual BOOL FSupportsIComponent2() {return TRUE;}
  218. virtual LONG IdsDescription(void) {return IDS_DragDropSnapinDesc;}
  219. virtual LONG IdsName(void) {return IDS_DragDropSnapinName;}
  220. const CSnapinInfo* Psnapininfo() { return &snapininfoDragDrop; }
  221. BOOL FCutDisabled() {return m_bDisableCut;}
  222. BOOL FPasteIntoResultPane() {return m_bPasteIntoResultPane;}
  223. void SetCutDisabled(BOOL b) {m_bDisableCut = b;}
  224. void SetPasteIntoResultPane(BOOL b) {m_bPasteIntoResultPane = b;}
  225. protected:
  226. // The column header info structures.
  227. static CColumnInfoEx s_colinfo[];
  228. static INT s_colwidths[];
  229. static INT s_ccolinfo;
  230. protected:
  231. virtual CColumnInfoEx* Pcolinfoex(INT icolinfo=0) { return s_colinfo + icolinfo; }
  232. virtual INT &ColumnWidth(INT icolwidth=0) { return s_colwidths[icolwidth]; }
  233. virtual INT Ccolinfoex() { return s_ccolinfo; }
  234. private:
  235. BOOL m_bDisableCut;
  236. BOOL m_bPasteIntoResultPane;
  237. };
  238. #endif //_DRAGDROPTEST_H_