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.

312 lines
7.6 KiB

  1. //-------------------------------------------------------------------------
  2. // File: DlgFilterProperties.cpp
  3. //
  4. // Author : Kishnan Nedungadi
  5. //
  6. // created : 3/27/2000
  7. //-------------------------------------------------------------------------
  8. #include "stdafx.h"
  9. #include <wbemidl.h>
  10. #include <commctrl.h>
  11. #include "resource.h"
  12. #include "defines.h"
  13. #include "ntdmutils.h"
  14. #include "DlgFilterProperties.h"
  15. CFilterPropertiesDlg * g_pFilterProperties = NULL;
  16. //-------------------------------------------------------------------------
  17. INT_PTR CALLBACK FilterPropertiesDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
  18. {
  19. if(g_pFilterProperties)
  20. {
  21. return g_pFilterProperties->FilterPropertiesDlgProc(hDlg, iMessage, wParam, lParam);
  22. }
  23. return FALSE;
  24. }
  25. //-------------------------------------------------------------------------
  26. CFilterPropertiesDlg::CFilterPropertiesDlg(IWbemServices * pIWbemServices, IWbemClassObject * pIWbemClassObject)
  27. {
  28. _ASSERT(pIWbemServices);
  29. _ASSERT(pIWbemClassObject);
  30. m_hWnd = NULL;
  31. m_hwndRulesListView = NULL;
  32. m_pIWbemServices = pIWbemServices;
  33. m_pIWbemServices->AddRef();
  34. m_pIWbemClassObject = pIWbemClassObject;
  35. m_pIWbemClassObject->AddRef();
  36. }
  37. //-------------------------------------------------------------------------
  38. CFilterPropertiesDlg::~CFilterPropertiesDlg()
  39. {
  40. NTDM_RELEASE_IF_NOT_NULL(m_pIWbemClassObject);
  41. NTDM_RELEASE_IF_NOT_NULL(m_pIWbemServices);
  42. }
  43. //-------------------------------------------------------------------------
  44. INT_PTR CALLBACK CFilterPropertiesDlg::FilterPropertiesDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
  45. {
  46. LPPSHNOTIFY lppsn = NULL;
  47. switch(iMessage)
  48. {
  49. case WM_INITDIALOG:
  50. {
  51. m_hWnd = hDlg;
  52. InitializeDialog();
  53. break;
  54. }
  55. case WM_DESTROY:
  56. {
  57. DestroyDialog();
  58. break;
  59. }
  60. case WM_COMMAND:
  61. {
  62. switch(LOWORD(wParam))
  63. {
  64. case IDOK:
  65. case IDCANCEL:
  66. EndDialog(m_hWnd, 0);
  67. return TRUE;
  68. }
  69. break;
  70. }
  71. }
  72. return FALSE;
  73. }
  74. //---------------------------------------------------------------------------
  75. STDMETHODIMP CFilterPropertiesDlg::InitializeDialog()
  76. {
  77. HRESULT hr;
  78. LVCOLUMN lvColumn;
  79. CComBSTR bstrTemp;
  80. NTDM_BEGIN_METHOD()
  81. // Set all the properties
  82. ShowProperty(m_pIWbemClassObject, _T("Name"), IDC_NAME);
  83. ShowProperty(m_pIWbemClassObject, _T("Author"), IDC_AUTHOR);
  84. ShowProperty(m_pIWbemClassObject, _T("SourceOrganization"), IDC_SOURCE_ORGANIZATION);
  85. ShowProperty(m_pIWbemClassObject, _T("CreationDate"), IDC_CREATION_DATE);
  86. ShowProperty(m_pIWbemClassObject, _T("ChangeDate"), IDC_CHANGE_DATE);
  87. ShowProperty(m_pIWbemClassObject, _T("DsPath"), IDC_DSPATH);
  88. ShowProperty(m_pIWbemClassObject, _T("ID"), IDC_ID);
  89. //Initialize the ListView Control
  90. m_hwndRulesListView = GetDlgItem(m_hWnd, IDC_RULES);
  91. NTDM_ERR_IF_NULL(m_hwndRulesListView);
  92. lvColumn.mask = LVCF_TEXT|LVCF_FMT;
  93. lvColumn.fmt = LVCFMT_LEFT;
  94. bstrTemp.LoadString(_Module.GetResourceInstance(), IDS_QUERY);
  95. lvColumn.pszText = bstrTemp;
  96. NTDM_ERR_IF_MINUSONE(ListView_InsertColumn(m_hwndRulesListView, 0, &lvColumn));
  97. bstrTemp.LoadString(_Module.GetResourceInstance(), IDS_QUERY_LANGUAGE);
  98. lvColumn.pszText = bstrTemp;
  99. NTDM_ERR_IF_MINUSONE(ListView_InsertColumn(m_hwndRulesListView, 1, &lvColumn));
  100. bstrTemp.LoadString(_Module.GetResourceInstance(), IDS_TARGET_NAMESPACE);
  101. lvColumn.pszText = bstrTemp;
  102. NTDM_ERR_IF_MINUSONE(ListView_InsertColumn(m_hwndRulesListView, 2, &lvColumn));
  103. PopulateRulesList();
  104. NTDM_ERR_IF_FALSE(ListView_SetColumnWidth(m_hwndRulesListView, 0, LVSCW_AUTOSIZE_USEHEADER));
  105. NTDM_ERR_IF_FALSE(ListView_SetColumnWidth(m_hwndRulesListView, 1, LVSCW_AUTOSIZE_USEHEADER));
  106. NTDM_ERR_IF_FALSE(ListView_SetColumnWidth(m_hwndRulesListView, 2, LVSCW_AUTOSIZE_USEHEADER));
  107. NTDM_END_METHOD()
  108. // cleanup
  109. return hr;
  110. }
  111. //---------------------------------------------------------------------------
  112. STDMETHODIMP CFilterPropertiesDlg::DestroyDialog()
  113. {
  114. HRESULT hr;
  115. NTDM_BEGIN_METHOD()
  116. ClearRulesList();
  117. NTDM_END_METHOD()
  118. // cleanup
  119. return hr;
  120. }
  121. //---------------------------------------------------------------------------
  122. STDMETHODIMP CFilterPropertiesDlg::ClearRulesList()
  123. {
  124. HRESULT hr;
  125. LVITEM lvItem;
  126. long lCount;
  127. NTDM_BEGIN_METHOD()
  128. //Release each item in the ListView Control
  129. lvItem.mask = LVIF_PARAM;
  130. lvItem.iSubItem = 0;
  131. lCount = ListView_GetItemCount(m_hwndRulesListView);
  132. while(lCount > 0)
  133. {
  134. lCount--;
  135. lvItem.iItem = lCount;
  136. NTDM_ERR_IF_FALSE(ListView_GetItem(m_hwndRulesListView, &lvItem));
  137. if(lvItem.lParam)
  138. {
  139. ((IWbemClassObject *)lvItem.lParam)->Release();
  140. }
  141. }
  142. ListView_DeleteAllItems(m_hwndRulesListView);
  143. NTDM_END_METHOD()
  144. // cleanup
  145. return hr;
  146. }
  147. //---------------------------------------------------------------------------
  148. STDMETHODIMP CFilterPropertiesDlg::PopulateRulesList()
  149. {
  150. HRESULT hr;
  151. CComVariant vValue;
  152. CIMTYPE vType;
  153. SAFEARRAY *psaRules = NULL;
  154. long lLower, lUpper, i;
  155. NTDM_BEGIN_METHOD()
  156. NTDM_ERR_IF_FAIL(m_pIWbemClassObject->Get(_T("Rules"), 0, &vValue, &vType, NULL));
  157. // Value should be an array
  158. if(V_VT(&vValue) != (VT_UNKNOWN | VT_ARRAY))
  159. {
  160. NTDM_EXIT(E_FAIL);
  161. }
  162. psaRules = V_ARRAY(&vValue);
  163. NTDM_ERR_IF_FAIL(SafeArrayGetUBound(psaRules, 1, &lUpper));
  164. NTDM_ERR_IF_FAIL(SafeArrayGetLBound(psaRules, 1, &lLower));
  165. for(i=lLower; i<=lUpper; i++)
  166. {
  167. IUnknown * pUnk = NULL;
  168. CComPtr<IWbemClassObject> pIRulesClassObject;
  169. NTDM_ERR_IF_FAIL(SafeArrayGetElement(psaRules, &i, (void *)&pUnk));
  170. NTDM_ERR_IF_FAIL(pUnk->QueryInterface(IID_IWbemClassObject, (void **)&pIRulesClassObject));
  171. // Show Properties of this rule.
  172. NTDM_ERR_IF_FAIL(AddItemToList(pIRulesClassObject));
  173. }
  174. NTDM_END_METHOD()
  175. // cleanup
  176. return hr;
  177. }
  178. //---------------------------------------------------------------------------
  179. STDMETHODIMP CFilterPropertiesDlg::AddItemToList(IWbemClassObject * pIWbemClassObject)
  180. {
  181. HRESULT hr;
  182. CComVariant vValue;
  183. CIMTYPE vType;
  184. LVITEM lvItem;
  185. NTDM_BEGIN_METHOD()
  186. NTDM_ERR_IF_FAIL(pIWbemClassObject->Get(_T("Query"), 0, &vValue, &vType, NULL));
  187. lvItem.mask = LVIF_TEXT|LVIF_PARAM;
  188. lvItem.iSubItem = 0;
  189. lvItem.pszText = vValue.bstrVal;
  190. lvItem.lParam = (LPARAM)pIWbemClassObject;
  191. lvItem.iItem = ListView_InsertItem(m_hwndRulesListView, &lvItem);
  192. NTDM_ERR_IF_MINUSONE(lvItem.iItem);
  193. NTDM_ERR_IF_FAIL(pIWbemClassObject->Get(_T("QueryLanguage"), 0, &vValue, &vType, NULL));
  194. lvItem.mask = LVIF_TEXT;
  195. lvItem.iSubItem = 1;
  196. lvItem.pszText = vValue.bstrVal;
  197. NTDM_ERR_IF_MINUSONE(ListView_SetItem(m_hwndRulesListView, &lvItem));
  198. NTDM_ERR_IF_FAIL(pIWbemClassObject->Get(_T("TargetNamespace"), 0, &vValue, &vType, NULL));
  199. lvItem.mask = LVIF_TEXT;
  200. lvItem.iSubItem = 2;
  201. lvItem.pszText = vValue.bstrVal;
  202. NTDM_ERR_IF_MINUSONE(ListView_SetItem(m_hwndRulesListView, &lvItem));
  203. pIWbemClassObject->AddRef();
  204. NTDM_END_METHOD()
  205. // cleanup
  206. return hr;
  207. }
  208. //---------------------------------------------------------------------------
  209. STDMETHODIMP CFilterPropertiesDlg::ShowProperty(IWbemClassObject * pIWbemClassObject, LPCTSTR pszPropertyName, long lResID)
  210. {
  211. HRESULT hr;
  212. CComVariant vValue;
  213. CIMTYPE vType;
  214. NTDM_BEGIN_METHOD()
  215. NTDM_ERR_IF_FAIL(pIWbemClassObject->Get(pszPropertyName, 0, &vValue, &vType, NULL));
  216. NTDM_ERR_IF_FAIL(VariantChangeType(&vValue, &vValue, VARIANT_ALPHABOOL|VARIANT_LOCALBOOL, VT_BSTR));
  217. SetDlgItemText(m_hWnd, lResID, (LPCTSTR)V_BSTR(&vValue));
  218. NTDM_END_METHOD()
  219. // cleanup
  220. return hr;
  221. }