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.

291 lines
6.8 KiB

  1. /*++
  2. Copyright (C) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. History:
  6. --*/
  7. // PropsPg.cpp : implementation file
  8. //
  9. #include "stdafx.h"
  10. #include "wmitest.h"
  11. #include "OpWrap.h"
  12. #include "PropsPg.h"
  13. #include "WMITestDoc.h"
  14. #include "ObjVw.h"
  15. #include "OpView.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CPropsPg property page
  23. IMPLEMENT_DYNCREATE(CPropsPg, CPropertyPage)
  24. CPropsPg::CPropsPg() :
  25. CPropertyPage(CPropsPg::IDD),
  26. m_pObj(NULL),
  27. //m_bShowSystemProperties(theApp.m_bShowSystemProperties),
  28. //m_bShowInheritedProperties(theApp.m_bShowInheritedProperties),
  29. m_bTranslateValues(theApp.m_bTranslateValues)
  30. {
  31. //{{AFX_DATA_INIT(CPropsPg)
  32. // NOTE: the ClassWizard will add member initialization here
  33. //}}AFX_DATA_INIT
  34. m_bShowSystemProperties =
  35. theApp.GetProfileInt(_T("Settings"), _T("ShowSysOnDlg"), TRUE);
  36. m_bShowInheritedProperties =
  37. theApp.GetProfileInt(_T("Settings"), _T("ShowInheritedOnDlg"), TRUE);
  38. }
  39. CPropsPg::~CPropsPg()
  40. {
  41. theApp.WriteProfileInt(_T("Settings"), _T("ShowSysOnDlg"),
  42. m_bShowSystemProperties);
  43. theApp.WriteProfileInt(_T("Settings"), _T("ShowInheritedOnDlg"),
  44. m_bShowInheritedProperties);
  45. }
  46. void CPropsPg::DoDataExchange(CDataExchange* pDX)
  47. {
  48. CPropertyPage::DoDataExchange(pDX);
  49. //{{AFX_DATA_MAP(CPropsPg)
  50. DDX_Control(pDX, IDC_PROPS, m_ctlProps);
  51. //}}AFX_DATA_MAP
  52. }
  53. void CPropsPg::InitListCtrl()
  54. {
  55. RECT rect;
  56. CString strTemp;
  57. m_ctlProps.SetExtendedStyle(LVS_EX_FULLROWSELECT);
  58. m_ctlProps.SetImageList(&((CMainFrame *) AfxGetMainWnd())->m_imageList,
  59. LVSIL_SMALL);
  60. m_ctlProps.GetClientRect(&rect);
  61. strTemp.LoadString(IDS_NAME);
  62. m_ctlProps.InsertColumn(0, strTemp, LVCFMT_LEFT, rect.right * 25 / 100);
  63. strTemp.LoadString(IDS_TYPE);
  64. m_ctlProps.InsertColumn(1, strTemp, LVCFMT_LEFT, rect.right * 25 / 100);
  65. strTemp.LoadString(IDS_VALUE);
  66. m_ctlProps.InsertColumn(2, strTemp, LVCFMT_LEFT, rect.right * 50 / 100);
  67. }
  68. void CPropsPg::LoadProps()
  69. {
  70. int nItems = m_pObj->GetProps()->GetSize(),
  71. iItem = 0;
  72. CPropInfo *pProps = m_pObj->GetProps()->GetData();
  73. m_ctlProps.DeleteAllItems();
  74. for (int i = 0; i < nItems; i++)
  75. {
  76. CString strType,
  77. strValue;
  78. int iImage,
  79. iFlavor;
  80. m_pObj->GetPropInfo(i, strValue, strType, &iImage, &iFlavor,
  81. m_bTranslateValues);
  82. if ((m_bShowSystemProperties || iFlavor != WBEM_FLAVOR_ORIGIN_SYSTEM) &&
  83. (m_bShowInheritedProperties ||
  84. iFlavor != WBEM_FLAVOR_ORIGIN_PROPAGATED))
  85. {
  86. m_ctlProps.InsertItem(iItem, pProps[i].m_strName, iImage);
  87. m_ctlProps.SetItemData(iItem, i);
  88. m_ctlProps.SetItemText(iItem, 1, strType);
  89. m_ctlProps.SetItemText(iItem, 2, strValue);
  90. iItem++;
  91. }
  92. }
  93. UpdateButtons();
  94. //if (FAILED(hr))
  95. // CWMITestDoc::DisplayWMIErrorBox(hr, NULL);
  96. }
  97. int CPropsPg::GetSelectedItem()
  98. {
  99. POSITION pos = m_ctlProps.GetFirstSelectedItemPosition();
  100. if (pos)
  101. return m_ctlProps.GetNextSelectedItem(pos);
  102. else
  103. return -1;
  104. }
  105. void CPropsPg::UpdateButtons()
  106. {
  107. int iIndex = GetSelectedItem();
  108. GetDlgItem(IDC_DELETE)->EnableWindow(iIndex != -1);
  109. GetDlgItem(IDC_EDIT)->EnableWindow(iIndex != -1);
  110. }
  111. BEGIN_MESSAGE_MAP(CPropsPg, CPropertyPage)
  112. //{{AFX_MSG_MAP(CPropsPg)
  113. ON_BN_CLICKED(IDC_ADD, OnAdd)
  114. ON_BN_CLICKED(IDC_EDIT, OnEdit)
  115. ON_BN_CLICKED(IDC_DELETE, OnDelete)
  116. ON_NOTIFY(NM_DBLCLK, IDC_PROPS, OnDblclkProps)
  117. ON_NOTIFY(LVN_ITEMCHANGED, IDC_PROPS, OnItemchangedProps)
  118. ON_BN_CLICKED(IDC_SYSTEM, OnSystem)
  119. ON_BN_CLICKED(IDC_INHERITED, OnInherited)
  120. //}}AFX_MSG_MAP
  121. END_MESSAGE_MAP()
  122. /////////////////////////////////////////////////////////////////////////////
  123. // CPropsPg message handlers
  124. void CPropsPg::OnAdd()
  125. {
  126. CString strName;
  127. if (CObjView::AddProperty(m_pObj, strName))
  128. {
  129. m_pObj->LoadProps(g_pOpView->GetDocument()->m_pNamespace);
  130. LoadProps();
  131. // Now try to find the item we just added.
  132. LVFINDINFO find;
  133. int iItem;
  134. find.flags = LVFI_STRING;
  135. find.psz = strName;
  136. iItem = m_ctlProps.FindItem(&find);
  137. if (iItem != -1)
  138. {
  139. m_ctlProps.EnsureVisible(iItem, FALSE);
  140. m_ctlProps.SetItemState(iItem, LVIS_SELECTED, LVIS_SELECTED);
  141. }
  142. }
  143. }
  144. void CPropsPg::OnEdit()
  145. {
  146. int iItem = GetSelectedItem();
  147. if (iItem != -1)
  148. {
  149. CPropInfo *pProp;
  150. _variant_t var;
  151. iItem = m_ctlProps.GetItemData(iItem);
  152. pProp = &m_pObj->GetProps()->GetData()[iItem];
  153. m_pObj->ValueToVariant(iItem, &var);
  154. if (CObjView::EditProperty(m_pObj, pProp, &var))
  155. {
  156. LoadProps();
  157. m_ctlProps.EnsureVisible(iItem, FALSE);
  158. m_ctlProps.SetItemState(iItem, LVIS_SELECTED, LVIS_SELECTED);
  159. }
  160. // Otherwise the destructor freaks out because it doesn't know what to
  161. // do with VT_I8.
  162. if (var.vt == VT_I8)
  163. var.vt = VT_I4;
  164. }
  165. }
  166. void CPropsPg::OnDelete()
  167. {
  168. int iItem = GetSelectedItem();
  169. if (iItem != -1)
  170. {
  171. CString strProperty = m_ctlProps.GetItemText(iItem, 0);
  172. HRESULT hr;
  173. hr = m_pObj->m_pObj->Delete(_bstr_t(strProperty));
  174. if (SUCCEEDED(hr))
  175. {
  176. m_pObj->LoadProps(g_pOpView->GetDocument()->m_pNamespace);
  177. LoadProps();
  178. if (iItem >= m_ctlProps.GetItemCount())
  179. iItem--;
  180. if (iItem >= 0)
  181. {
  182. m_ctlProps.EnsureVisible(iItem, FALSE);
  183. m_ctlProps.SetItemState(iItem, LVIS_SELECTED, LVIS_SELECTED);
  184. }
  185. }
  186. else
  187. CWMITestDoc::DisplayWMIErrorBox(hr);
  188. }
  189. }
  190. void CPropsPg::OnDblclkProps(NMHDR* pNMHDR, LRESULT* pResult)
  191. {
  192. OnEdit();
  193. *pResult = 0;
  194. }
  195. void CPropsPg::OnItemchangedProps(NMHDR* pNMHDR, LRESULT* pResult)
  196. {
  197. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  198. UpdateButtons();
  199. *pResult = 0;
  200. }
  201. BOOL CPropsPg::OnInitDialog()
  202. {
  203. CPropertyPage::OnInitDialog();
  204. CheckDlgButton(IDC_SYSTEM, m_bShowSystemProperties);
  205. CheckDlgButton(IDC_INHERITED, m_bShowInheritedProperties);
  206. InitListCtrl();
  207. LoadProps();
  208. return TRUE; // return TRUE unless you set the focus to a control
  209. // EXCEPTION: OCX Property Pages should return FALSE
  210. }
  211. void CPropsPg::OnSystem()
  212. {
  213. m_bShowSystemProperties ^= 1;
  214. LoadProps();
  215. }
  216. void CPropsPg::OnInherited()
  217. {
  218. m_bShowInheritedProperties ^= 1;
  219. LoadProps();
  220. }