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.

247 lines
8.1 KiB

  1. /*++
  2. Module Name:
  3. MmcAdmin.cpp
  4. Abstract:
  5. This module contains the part of the declaration for CDfsSnapinResultManager.
  6. --*/
  7. #include "stdafx.h"
  8. #include "DfsGUI.h"
  9. #include "DfsReslt.h"
  10. #include "DfsScope.h" // The CDfsSnapinScopeManager class
  11. STDMETHODIMP CDfsSnapinResultManager :: AddMenuItems
  12. (
  13. IN LPDATAOBJECT i_lpDataObject,
  14. IN LPCONTEXTMENUCALLBACK i_lpContextMenuCallback,
  15. IN LPLONG i_lpInsertionAllowed
  16. )
  17. /*++
  18. Routine Description:
  19. This routine adds the appropriate context menu using the ContextMenuCallback provided.
  20. Arguments:
  21. i_lpDataObject - The dataobject used to identify the node.
  22. i_lpContextMenuCallback - A callback(function pointer) that is used to add the menu items
  23. i_lpInsertionAllowed - Specifies what menus can be added and where they can be added.
  24. --*/
  25. {
  26. RETURN_INVALIDARG_IF_NULL(i_lpDataObject);
  27. RETURN_INVALIDARG_IF_NULL(i_lpContextMenuCallback);
  28. RETURN_INVALIDARG_IF_NULL(i_lpInsertionAllowed);
  29. if (DOBJ_CUSTOMOCX == i_lpDataObject)
  30. return S_OK;
  31. return m_pScopeManager->AddMenuItems(i_lpDataObject, i_lpContextMenuCallback, i_lpInsertionAllowed);
  32. }
  33. STDMETHODIMP
  34. CDfsSnapinResultManager::Command(
  35. IN LONG i_lCommandID,
  36. IN LPDATAOBJECT i_lpDataObject
  37. )
  38. /*++
  39. Routine Description:
  40. Action to be taken on a context menu selection or click is takes place.
  41. Arguments:
  42. i_lpDataObject - The dataobject used to identify the node.
  43. i_lCommandID - The Command ID of the menu for which action has to be taken
  44. --*/
  45. {
  46. RETURN_INVALIDARG_IF_NULL(i_lpDataObject);
  47. return m_pScopeManager->Command(i_lCommandID, i_lpDataObject);
  48. }
  49. STDMETHODIMP
  50. CDfsSnapinResultManager::SetControlbar(
  51. IN LPCONTROLBAR i_pControlbar
  52. )
  53. /*++
  54. Routine Description:
  55. Called by MMC to allow us to set the IControlbar interface pointer
  56. As items are selected and deselected, snap-ins are activated and deactivated.
  57. When a snap-in is activated, the console calls SetControlbar with a non-NULL
  58. pControlbar value. The snap-in should call AddRef on this IControlBar. The
  59. snap-in should also use this opportunity to attach controls. Similarly, when
  60. the snap-in is deactivated, the console calls SetControlbar with a NULL
  61. pControlbar. The snap-in should then detach its controls and call Release
  62. on the saved IControlBar.
  63. Arguments:
  64. i_pControlbar - The IControlbar interface pointer. Note, can be 0.
  65. --*/
  66. {
  67. if (!i_pControlbar) // We are shutting down
  68. m_pControlbar.Release();
  69. else
  70. m_pControlbar = i_pControlbar;
  71. return S_OK;
  72. }
  73. void
  74. CDfsSnapinResultManager::DetachAllToolbars()
  75. {
  76. if (m_pMMCAdminToolBar)
  77. m_pControlbar->Detach(m_pMMCAdminToolBar);
  78. if (m_pMMCRootToolBar)
  79. m_pControlbar->Detach(m_pMMCRootToolBar);
  80. if (m_pMMCJPToolBar)
  81. m_pControlbar->Detach(m_pMMCJPToolBar);
  82. if (m_pMMCReplicaToolBar)
  83. m_pControlbar->Detach(m_pMMCReplicaToolBar);
  84. }
  85. STDMETHODIMP
  86. CDfsSnapinResultManager::ControlbarNotify(
  87. IN MMC_NOTIFY_TYPE i_Event,
  88. IN LPARAM i_lArg,
  89. IN LPARAM i_lParam
  90. )
  91. /*++
  92. Routine Description:
  93. Called by MMC to notify the toolbar about an event.
  94. This can be selection\disselection of node, click on a toolbar, etc.
  95. Arguments:
  96. i_Event - The event that occurred.
  97. i_lArg - The argument for the event. Depends on the event
  98. i_lParam - The parameter for the event. Depends on the event
  99. --*/
  100. {
  101. // The snap-in should return S_FALSE for any notification it does not handle.
  102. // MMC then performs a default operation for the notification.
  103. HRESULT hr = S_FALSE;
  104. LPDATAOBJECT p_DataObject = NULL;
  105. CMmcDisplay* pCMmcDisplayObj = NULL;
  106. switch (i_Event) // Decide which method to call of the display object
  107. {
  108. case MMCN_BTN_CLICK: // Click on a toolbar
  109. {
  110. // The MMCN_BTN_CLICK notification is sent to the snap-in's IComponent,
  111. // IComponentData, or IExtendControlbar implementation when a user clicks
  112. // one of the toolbar buttons.
  113. //
  114. // For IExtendControlBar::ControlbarNotify:
  115. // arg: Data object of the currently selected scope or result item.
  116. // param: [in] The snap-in-defined command ID of the selected toolbar button.
  117. p_DataObject = (LPDATAOBJECT)i_lArg;
  118. // Get the display object from IDataObject
  119. hr = m_pScopeManager->GetDisplayObject(p_DataObject, &pCMmcDisplayObj);
  120. if (SUCCEEDED(hr))
  121. hr = pCMmcDisplayObj->ToolbarClick(m_pControlbar, i_lParam);
  122. break;
  123. }
  124. case MMCN_SELECT: // A node is being selected\deselected
  125. {
  126. // The MMCN_SELECT notification is sent to the snap-in's IComponent::Notify
  127. // or IExtendControlbar::ControlbarNotify method when an item is selected
  128. // in either the scope pane or result pane.
  129. //
  130. // For IExtendControlbar::ControlbarNotify:
  131. // arg: BOOL bScope = (BOOL) LOWORD(arg); BOOL bSelect = (BOOL) HIWORD(arg);
  132. // bScope is TRUE if an item in the scope pane is selected, or FALSE
  133. // if an item in the result pane is selected.
  134. // bSelect is TRUE if the item is selected, or FALSE if the item is deselected.
  135. // param: LPDATAOBJECT pDataobject = (LPDATAOBJECT)param;
  136. // pDataobject is the data object of the item being selected or deselected.
  137. p_DataObject = (LPDATAOBJECT)i_lParam;
  138. if (DOBJ_CUSTOMOCX == p_DataObject)
  139. break;
  140. // Get the display object from IDataObject
  141. hr = m_pScopeManager->GetDisplayObject(p_DataObject, &pCMmcDisplayObj);
  142. RETURN_IF_FAILED(hr);
  143. //
  144. // Update the custom toolbars.
  145. // On select, it should detach unused toolbars and attach new ones as needed.
  146. // On deselect, to minimize flashing, it should not detach toolbars; it is
  147. // best to disable them, but doing nothing on deselect is also acceptable.
  148. //
  149. BOOL bSelect = (BOOL) HIWORD(i_lArg);
  150. IToolbar *pToolbar = NULL;
  151. DISPLAY_OBJECT_TYPE DisplayObType = pCMmcDisplayObj->GetDisplayObjectType();
  152. switch (DisplayObType)
  153. {
  154. case DISPLAY_OBJECT_TYPE_ADMIN:
  155. if (!m_pMMCAdminToolBar)
  156. hr = pCMmcDisplayObj->CreateToolbar(m_pControlbar, (LPEXTENDCONTROLBAR)this, &m_pMMCAdminToolBar);
  157. pToolbar = (IToolbar *)m_pMMCAdminToolBar;
  158. break;
  159. case DISPLAY_OBJECT_TYPE_ROOT:
  160. if (!m_pMMCRootToolBar)
  161. hr = pCMmcDisplayObj->CreateToolbar(m_pControlbar, (LPEXTENDCONTROLBAR)this, &m_pMMCRootToolBar);
  162. pToolbar = (IToolbar *)m_pMMCRootToolBar;
  163. break;
  164. case DISPLAY_OBJECT_TYPE_JUNCTION:
  165. if (!m_pMMCJPToolBar)
  166. hr = pCMmcDisplayObj->CreateToolbar(m_pControlbar, (LPEXTENDCONTROLBAR)this, &m_pMMCJPToolBar);
  167. pToolbar = (IToolbar *)m_pMMCJPToolBar;
  168. break;
  169. case DISPLAY_OBJECT_TYPE_REPLICA:
  170. if (!m_pMMCReplicaToolBar)
  171. hr = pCMmcDisplayObj->CreateToolbar(m_pControlbar, (LPEXTENDCONTROLBAR)this, &m_pMMCReplicaToolBar);
  172. pToolbar = (IToolbar *)m_pMMCReplicaToolBar;
  173. break;
  174. }
  175. if (SUCCEEDED(hr))
  176. {
  177. if (bSelect)
  178. {
  179. DetachAllToolbars();
  180. m_pControlbar->Attach(TOOLBAR, (LPUNKNOWN)pToolbar);
  181. }
  182. hr = pCMmcDisplayObj->ToolbarSelect(i_lArg, pToolbar);
  183. }
  184. break;
  185. }
  186. default:
  187. break;
  188. } // switch()
  189. return hr;
  190. }