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.

338 lines
9.2 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1998.
  5. //
  6. // File: Category.cpp
  7. //
  8. // Contents: Categories property page (for an application)
  9. //
  10. // Classes: CCategory
  11. //
  12. // History: 03-14-1998 stevebl Commented
  13. //
  14. //---------------------------------------------------------------------------
  15. #include "precomp.hxx"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CCategory property page
  23. IMPLEMENT_DYNCREATE(CCategory, CPropertyPage)
  24. CCategory::CCategory() : CPropertyPage(CCategory::IDD)
  25. {
  26. //{{AFX_DATA_INIT(CCategory)
  27. //}}AFX_DATA_INIT
  28. m_pIClassAdmin = NULL;
  29. m_ppThis = NULL;
  30. m_fPreDeploy = FALSE;
  31. }
  32. CCategory::~CCategory()
  33. {
  34. if (m_ppThis)
  35. {
  36. *m_ppThis = NULL;
  37. }
  38. if (m_pIClassAdmin)
  39. {
  40. m_pIClassAdmin->Release();
  41. }
  42. }
  43. void CCategory::DoDataExchange(CDataExchange* pDX)
  44. {
  45. CPropertyPage::DoDataExchange(pDX);
  46. //{{AFX_DATA_MAP(CCategory)
  47. DDX_Control(pDX, IDC_LIST1, m_Available);
  48. DDX_Control(pDX, IDC_LIST2, m_Assigned);
  49. //}}AFX_DATA_MAP
  50. }
  51. BEGIN_MESSAGE_MAP(CCategory, CPropertyPage)
  52. //{{AFX_MSG_MAP(CCategory)
  53. ON_BN_CLICKED(IDC_BUTTON1, OnAssign)
  54. ON_BN_CLICKED(IDC_BUTTON2, OnRemove)
  55. ON_LBN_DBLCLK(IDC_LIST1, OnAssign)
  56. ON_LBN_DBLCLK(IDC_LIST2, OnRemove)
  57. ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
  58. ON_LBN_SELCHANGE(IDC_LIST2, OnSelchangeList2)
  59. ON_WM_CONTEXTMENU()
  60. //}}AFX_MSG_MAP
  61. END_MESSAGE_MAP()
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CCategory message handlers
  64. void CCategory::OnSelchangeList1()
  65. {
  66. BOOL fOK = FALSE;
  67. int iSel = m_Available.GetCurSel();
  68. if (iSel != LB_ERR)
  69. {
  70. fOK = TRUE;
  71. }
  72. GetDlgItem(IDC_BUTTON1)->EnableWindow(fOK && (!m_fRSOP));
  73. if (NULL == GetFocus())
  74. {
  75. GetParent()->GetDlgItem(IDOK)->SetFocus();
  76. }
  77. }
  78. void CCategory::OnSelchangeList2()
  79. {
  80. BOOL fOK = FALSE;
  81. int iSel = m_Assigned.GetCurSel();
  82. if (iSel != LB_ERR)
  83. {
  84. fOK = TRUE;
  85. }
  86. GetDlgItem(IDC_BUTTON2)->EnableWindow(fOK && (!m_fRSOP));
  87. if (NULL == GetFocus())
  88. {
  89. GetParent()->GetDlgItem(IDOK)->SetFocus();
  90. }
  91. }
  92. void CCategory::OnAssign()
  93. {
  94. if ( m_fRSOP )
  95. {
  96. return;
  97. }
  98. int i = m_Available.GetCurSel();
  99. if (i != LB_ERR)
  100. {
  101. CString sz;
  102. m_Available.GetText(i, sz);
  103. m_Available.DeleteString(i);
  104. if (i > 0 && i >= m_Available.GetCount())
  105. {
  106. i = m_Available.GetCount() - 1;
  107. }
  108. GetDlgItem(IDC_BUTTON1)->EnableWindow(
  109. LB_ERR != m_Available.SetCurSel(i));
  110. if (NULL == GetFocus())
  111. {
  112. GetParent()->GetDlgItem(IDOK)->SetFocus();
  113. }
  114. m_Assigned.AddString(sz);
  115. CDC * pDC = m_Assigned.GetDC();
  116. CSize size = pDC->GetTextExtent(sz);
  117. pDC->LPtoDP(&size);
  118. m_Assigned.ReleaseDC(pDC);
  119. if (m_Assigned.GetHorizontalExtent() < size.cx)
  120. {
  121. m_Assigned.SetHorizontalExtent(size.cx);
  122. }
  123. m_Assigned.SelectString(-1, sz);
  124. GetDlgItem(IDC_BUTTON2)->EnableWindow(TRUE);
  125. m_fModified = TRUE;
  126. if (!m_fPreDeploy)
  127. SetModified();
  128. }
  129. }
  130. void CCategory::OnRemove()
  131. {
  132. if ( m_fRSOP )
  133. {
  134. return;
  135. }
  136. int i = m_Assigned.GetCurSel();
  137. if (i != LB_ERR)
  138. {
  139. CString sz;
  140. m_Assigned.GetText(i, sz);
  141. m_Assigned.DeleteString(i);
  142. if (i > 0 && i >= m_Assigned.GetCount())
  143. {
  144. i = m_Assigned.GetCount() - 1;
  145. }
  146. GetDlgItem(IDC_BUTTON2)->EnableWindow(
  147. LB_ERR != m_Assigned.SetCurSel(i));
  148. if (NULL == GetFocus())
  149. {
  150. GetParent()->GetDlgItem(IDOK)->SetFocus();
  151. }
  152. m_Available.AddString(sz);
  153. m_Available.SelectString(-1, sz);
  154. GetDlgItem(IDC_BUTTON1)->EnableWindow(TRUE);
  155. m_fModified = TRUE;
  156. if (!m_fPreDeploy)
  157. SetModified();
  158. }
  159. }
  160. BOOL CCategory::OnApply()
  161. {
  162. if (m_fModified)
  163. {
  164. if (this->m_fRSOP)
  165. {
  166. return CPropertyPage::OnApply();
  167. }
  168. multimap<CString, GUID> Categories;
  169. // build a mapping from category names to guids
  170. DWORD n = m_pCatList->cCategory;
  171. while (n--)
  172. {
  173. Categories.insert(pair<const CString, GUID>(m_pCatList->pCategoryInfo[n].pszDescription, m_pCatList->pCategoryInfo[n].AppCategoryId));
  174. }
  175. // build the list of categories assigned to this app
  176. UINT cCategories = m_Assigned.GetCount();
  177. HRESULT hr = E_FAIL;
  178. GUID * rpCategory = (GUID *)OLEALLOC(sizeof(GUID) * cCategories);
  179. CString sz;
  180. if (rpCategory)
  181. {
  182. UINT index = cCategories;
  183. while (index--)
  184. {
  185. m_Assigned.GetText(index, sz);
  186. rpCategory[index] = Categories.find(sz)->second;
  187. }
  188. if (m_pIClassAdmin)
  189. {
  190. hr = m_pIClassAdmin->ChangePackageCategories(m_pData->m_pDetails->pszPackageName,
  191. cCategories,
  192. rpCategory);
  193. }
  194. }
  195. else
  196. {
  197. hr = E_OUTOFMEMORY;
  198. }
  199. if (SUCCEEDED(hr))
  200. {
  201. OLESAFE_DELETE(m_pData->m_pDetails->rpCategory);
  202. m_pData->m_pDetails->cCategories = cCategories;
  203. m_pData->m_pDetails->rpCategory = rpCategory;
  204. m_fModified = FALSE;
  205. }
  206. else
  207. {
  208. DebugMsg((DM_WARNING, TEXT("ChangePackageCategories failed with 0x%x"), hr));
  209. // apply failed
  210. OLESAFE_DELETE(rpCategory);
  211. CString sz;
  212. sz.LoadString(IDS_CATEGORYFAILED);
  213. ReportGeneralPropertySheetError(m_hWnd, sz, hr);
  214. return FALSE;
  215. }
  216. }
  217. return CPropertyPage::OnApply();
  218. }
  219. BOOL CCategory::OnInitDialog()
  220. {
  221. CPropertyPage::OnInitDialog();
  222. RefreshData();
  223. return TRUE; // return TRUE unless you set the focus to a control
  224. // EXCEPTION: OCX Property Pages should return FALSE
  225. }
  226. LRESULT CCategory::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  227. {
  228. switch (message)
  229. {
  230. case WM_HELP:
  231. StandardHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, IDD);
  232. return 0;
  233. case WM_USER_REFRESH:
  234. RefreshData();
  235. return 0;
  236. case WM_USER_CLOSE:
  237. return GetOwner()->SendMessage(WM_CLOSE);
  238. default:
  239. return CPropertyPage::WindowProc(message, wParam, lParam);
  240. }
  241. }
  242. BOOL CCategory::IsAssigned(GUID & guid)
  243. {
  244. UINT n = m_pData->m_pDetails->cCategories;
  245. while (n--)
  246. {
  247. if (IsEqualGUID(guid, m_pData->m_pDetails->rpCategory[n]))
  248. {
  249. return TRUE;
  250. }
  251. }
  252. return FALSE;
  253. }
  254. void CCategory::RefreshData()
  255. {
  256. GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);
  257. GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);
  258. m_Assigned.ResetContent();
  259. m_Available.ResetContent();
  260. m_Assigned.SetHorizontalExtent(0);
  261. m_Available.SetHorizontalExtent(0);
  262. // for each category available, determine if it has been assigned or not
  263. DWORD n = m_pCatList->cCategory;
  264. while (n--)
  265. {
  266. if (IsAssigned(m_pCatList->pCategoryInfo[n].AppCategoryId))
  267. {
  268. // it's assigned
  269. m_Assigned.AddString(m_pCatList->pCategoryInfo[n].pszDescription);
  270. CDC * pDC = m_Assigned.GetDC();
  271. CSize size = pDC->GetTextExtent(m_pCatList->pCategoryInfo[n].pszDescription);
  272. pDC->LPtoDP(&size);
  273. m_Assigned.ReleaseDC(pDC);
  274. if (m_Assigned.GetHorizontalExtent() < size.cx)
  275. {
  276. m_Assigned.SetHorizontalExtent(size.cx);
  277. }
  278. GetDlgItem(IDC_BUTTON2)->EnableWindow(TRUE && (!m_fRSOP));
  279. }
  280. else
  281. {
  282. // it's not assigned
  283. m_Available.AddString(m_pCatList->pCategoryInfo[n].pszDescription);
  284. CDC * pDC = m_Available.GetDC();
  285. CSize size = pDC->GetTextExtent(m_pCatList->pCategoryInfo[n].pszDescription);
  286. pDC->LPtoDP(&size);
  287. m_Available.ReleaseDC(pDC);
  288. if (m_Available.GetHorizontalExtent() < size.cx)
  289. {
  290. m_Available.SetHorizontalExtent(size.cx);
  291. }
  292. GetDlgItem(IDC_BUTTON1)->EnableWindow(TRUE && (!m_fRSOP));
  293. }
  294. }
  295. m_Assigned.SetCurSel(0);
  296. m_Available.SetCurSel(0);
  297. m_fModified = FALSE;
  298. SetModified(FALSE);
  299. if (NULL == GetFocus())
  300. {
  301. GetParent()->GetDlgItem(IDOK)->SetFocus();
  302. }
  303. }
  304. void CCategory::OnContextMenu(CWnd* pWnd, CPoint point)
  305. {
  306. StandardContextMenu(pWnd->m_hWnd, IDD_CATEGORY);
  307. }