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.

355 lines
10 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: precpage.cpp
  7. //
  8. // Contents: implementation of CPrecedencePage
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include <secedit.h>
  13. #include "wsecmgr.h"
  14. #include "precpage.h"
  15. #include "snapmgr.h"
  16. #include "util.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. #define PRECEDENCE_STATUS_SUCCESS 1
  23. #define PRECEDENCE_STATUS_NO_CONFIG 0
  24. #define PRECEDENCE_STATUS_INVALID 2
  25. #define PRECEDENCE_STATUS_ERROR 3
  26. #define PRECEDENCE_STATUS_CHILD_ERROR 4
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CPrecedencePage property page
  29. IMPLEMENT_DYNCREATE(CPrecedencePage, CSelfDeletingPropertyPage)
  30. CPrecedencePage::CPrecedencePage() : CSelfDeletingPropertyPage(IDD)
  31. {
  32. //{{AFX_DATA_INIT(CPrecedencePage)
  33. m_strSuccess = _T("");
  34. m_strTitle = _T("");
  35. m_strError = _T("");
  36. //}}AFX_DATA_INIT
  37. m_pResult = NULL;
  38. m_pWMI = NULL;
  39. m_pHelpIDs = (DWORD_PTR)a239HelpIDs;
  40. }
  41. CPrecedencePage::~CPrecedencePage()
  42. {
  43. }
  44. void CPrecedencePage::DoDataExchange(CDataExchange* pDX)
  45. {
  46. CSelfDeletingPropertyPage::DoDataExchange(pDX);
  47. //{{AFX_DATA_MAP(CPrecedencePage)
  48. DDX_Control(pDX, IDC_PRECEDENCE_LIST, m_PrecedenceList);
  49. DDX_Control(pDX, IDC_ERROR_ICON, m_iconError);
  50. DDX_Text(pDX, IDC_SUCCESS_TEXT, m_strSuccess);
  51. DDX_Text(pDX, IDC_TITLE, m_strTitle);
  52. DDX_Text(pDX, IDC_ERROR_TEXT, m_strError);
  53. //}}AFX_DATA_MAP
  54. }
  55. BEGIN_MESSAGE_MAP(CPrecedencePage, CSelfDeletingPropertyPage)
  56. //{{AFX_MSG_MAP(CPrecedencePage)
  57. //}}AFX_MSG_MAP
  58. ON_MESSAGE(WM_HELP, OnHelp)
  59. ON_MESSAGE(WM_CONTEXTMENU, OnContextHelp) //Bug 139470, 4/19/2001
  60. END_MESSAGE_MAP()
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CPrecedencePage message handlers
  63. BOOL CPrecedencePage::OnInitDialog()
  64. {
  65. CSelfDeletingPropertyPage::OnInitDialog();
  66. CString strColumn;
  67. #define COL_WIDTH 200
  68. strColumn.LoadString(IDS_PRECEDENCE_GPO_HEADER);
  69. m_PrecedenceList.InsertColumn(0,strColumn,LVCFMT_LEFT,COL_WIDTH,0);
  70. switch(m_pResult->GetType())
  71. {
  72. case ITEM_PROF_GROUP:
  73. //
  74. // Two value columns for groups
  75. //
  76. strColumn.LoadString(IDS_COL_MEMBERSHIP);
  77. m_PrecedenceList.InsertColumn(1,strColumn,LVCFMT_LEFT,COL_WIDTH,1);
  78. strColumn.LoadString(IDS_COL_MEMBEROF);
  79. m_PrecedenceList.InsertColumn(2,strColumn,LVCFMT_LEFT,COL_WIDTH,1);
  80. break;
  81. case ITEM_PROF_REGSD:
  82. case ITEM_PROF_FILESD:
  83. case ITEM_PROF_SERV:
  84. //
  85. // No value columns for files, reg keys, or services
  86. //
  87. break;
  88. default:
  89. //
  90. // One value column for everything else
  91. //
  92. strColumn.LoadString(IDS_PRECEDENCE_VALUE_HEADER);
  93. m_PrecedenceList.InsertColumn(1,strColumn,LVCFMT_LEFT,COL_WIDTH,1);
  94. break;
  95. }
  96. vector<PPRECEDENCEDISPLAY>* pvecDisplay = m_pResult->GetPrecedenceDisplays();
  97. ASSERT(pvecDisplay);
  98. if (!pvecDisplay || pvecDisplay->empty())
  99. {
  100. return TRUE;
  101. }
  102. int nItem = 0;
  103. for(vector<PPRECEDENCEDISPLAY>::iterator i = pvecDisplay->begin();
  104. i != pvecDisplay->end();
  105. ++i )
  106. {
  107. PPRECEDENCEDISPLAY ppd = *i;
  108. if ( ppd->m_szGPO.IsEmpty ())
  109. {
  110. ASSERT(!ppd->m_szGPO.IsEmpty ());
  111. continue;
  112. }
  113. //
  114. // CListCtrl will make a copy of the string passed in so
  115. // there is no point allocating buffer
  116. // (and not free it)
  117. //
  118. nItem = m_PrecedenceList.InsertItem (nItem,
  119. (PCWSTR) ppd->m_szGPO);
  120. if (nItem != -1)
  121. {
  122. if ( !ppd->m_szValue.IsEmpty () )
  123. {
  124. m_PrecedenceList.SetItem(nItem,
  125. 1,
  126. LVIF_TEXT,
  127. (PCWSTR) ppd->m_szValue,
  128. 0,
  129. 0,
  130. 0,
  131. 0);
  132. }
  133. if ( !ppd->m_szValue2.IsEmpty () )
  134. {
  135. m_PrecedenceList.SetItem(nItem,
  136. 2,
  137. LVIF_TEXT,
  138. (PCWSTR) ppd->m_szValue2,
  139. 0,
  140. 0,
  141. 0,
  142. 0);
  143. }
  144. }
  145. nItem++;
  146. }
  147. vector<PPRECEDENCEDISPLAY>::reference ppd = pvecDisplay->front();
  148. if (ppd)
  149. {
  150. if (ppd->m_uStatus == PRECEDENCE_STATUS_SUCCESS)
  151. {
  152. GetDlgItem(IDC_ERROR_TEXT)->SetWindowPos(NULL,0,0,0,0,SWP_HIDEWINDOW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER);
  153. GetDlgItem(IDC_ERROR_ICON)->SetWindowPos(NULL,0,0,0,0,SWP_HIDEWINDOW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER);
  154. }
  155. else
  156. {
  157. GetDlgItem(IDC_SUCCESS_TEXT)->SetWindowPos(NULL,0,0,0,0,SWP_HIDEWINDOW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER);
  158. }
  159. CImageList il;
  160. HICON icon = NULL;
  161. il.Create(IDB_ICON16,16,1,RGB(255,0,255));
  162. if (ppd->m_uStatus != PRECEDENCE_STATUS_SUCCESS)
  163. {
  164. icon = m_iconError.SetIcon(il.ExtractIcon(SCE_CRITICAL_IDX));
  165. if (icon)
  166. {
  167. DestroyIcon(icon);
  168. }
  169. }
  170. }
  171. return TRUE; // return TRUE unless you set the focus to a control
  172. // EXCEPTION: OCX Property Pages should return FALSE
  173. }
  174. void CPrecedencePage::Initialize(CResult *pResult, CWMIRsop *pWMI)
  175. {
  176. m_pResult = pResult;
  177. m_pWMI = pWMI;
  178. vector<PPRECEDENCEDISPLAY>* pvecDisplay = m_pResult->GetPrecedenceDisplays();
  179. ASSERT(pvecDisplay);
  180. if (pvecDisplay && !pvecDisplay->empty())
  181. {
  182. vector<PPRECEDENCEDISPLAY>::reference ppd = pvecDisplay->front();
  183. if (ppd)
  184. {
  185. switch (ppd->m_uStatus)
  186. {
  187. case PRECEDENCE_STATUS_NO_CONFIG:
  188. m_strError.LoadString(IDS_PRECEDENCE_NO_CONFIG);
  189. break;
  190. case PRECEDENCE_STATUS_INVALID:
  191. AfxFormatString1 (m_strError, IDS_PRECEDENCE_INVALID,
  192. (PCWSTR) ppd->m_szGPO);
  193. break;
  194. case PRECEDENCE_STATUS_ERROR:
  195. {
  196. CString strErr;
  197. if (SCESTATUS_SUCCESS != FormatDBErrorMessage (ppd->m_uError,
  198. NULL, strErr))
  199. {
  200. strErr.LoadString(IDS_UNKNOWN_ERROR);
  201. }
  202. AfxFormatString2 (m_strError, IDS_PRECEDENCE_ERROR,
  203. (PCWSTR) ppd->m_szGPO, strErr);
  204. }
  205. break;
  206. case PRECEDENCE_STATUS_SUCCESS:
  207. AfxFormatString1 (m_strSuccess, IDS_PRECEDENCE_SUCCESS,
  208. (PCWSTR) ppd->m_szGPO);
  209. break;
  210. case PRECEDENCE_STATUS_CHILD_ERROR:
  211. m_strError.LoadString(IDS_PRECEDENCE_CHILD_ERROR);
  212. break;
  213. default:
  214. break;
  215. }
  216. }
  217. }
  218. }
  219. BOOL CPrecedencePage::OnHelp(WPARAM wParam, LPARAM lParam) //Bug 316461, Yanggao, 3/14/2001
  220. {
  221. const LPHELPINFO pHelpInfo = (LPHELPINFO)lParam;
  222. if (pHelpInfo && pHelpInfo->iContextType == HELPINFO_WINDOW)
  223. {
  224. if(pHelpInfo->iCtrlId != -1)
  225. this->DoContextHelp ((HWND) pHelpInfo->hItemHandle);
  226. }
  227. return TRUE;
  228. }
  229. void CPrecedencePage::DoContextHelp(HWND hWndControl) //Bug 316461, Yanggao, 3/14/2001
  230. {
  231. // Display context help for a control
  232. if ( !::WinHelp (
  233. hWndControl,
  234. GetGpeditHelpFilename(),
  235. HELP_WM_HELP,
  236. m_pHelpIDs))
  237. {
  238. }
  239. }
  240. BOOL CPrecedencePage::OnContextHelp(WPARAM wParam, LPARAM lParam)
  241. {
  242. HMENU hMenu = CreatePopupMenu();
  243. if( hMenu )
  244. {
  245. CString str;
  246. str.LoadString(IDS_WHAT_ISTHIS);
  247. if( AppendMenu(hMenu, MF_STRING, IDM_WHAT_ISTHIS, str) )
  248. {
  249. int itemID = TrackPopupMenu(hMenu,
  250. TPM_LEFTALIGN|TPM_TOPALIGN|TPM_RETURNCMD|
  251. TPM_LEFTBUTTON|TPM_RIGHTBUTTON,
  252. LOWORD(lParam), HIWORD(lParam), 0, (HWND)wParam, NULL);
  253. if( itemID == IDM_WHAT_ISTHIS ) //Raid #139470, 4/11/2001
  254. {
  255. if( ((HWND)wParam) != this->m_hWnd )
  256. {
  257. ::WinHelp((HWND)wParam,
  258. GetGpeditHelpFilename(),
  259. HELP_WM_HELP,
  260. m_pHelpIDs);
  261. }
  262. else
  263. {
  264. POINT pos;
  265. pos.x = LOWORD(lParam);
  266. pos.y = HIWORD(lParam);
  267. ScreenToClient( &pos );
  268. CWnd* pWnd = ChildWindowFromPoint(pos, CWP_SKIPINVISIBLE);
  269. if( pWnd )
  270. {
  271. ::WinHelp(pWnd->m_hWnd,
  272. GetGpeditHelpFilename(),
  273. HELP_WM_HELP,
  274. m_pHelpIDs);
  275. }
  276. else
  277. {
  278. ::WinHelp((HWND)wParam,
  279. GetGpeditHelpFilename(),
  280. HELP_WM_HELP,
  281. m_pHelpIDs);
  282. }
  283. }
  284. }
  285. }
  286. }
  287. return TRUE;
  288. }
  289. //********************************************************************
  290. //Get the image icon for the result item, based on where the status of
  291. //RSOP result item.
  292. //********************************************************************
  293. int GetRSOPImageIndex(int nImage, CResult* pResult)
  294. {
  295. if ( !pResult )
  296. {
  297. return nImage;
  298. }
  299. vector<PPRECEDENCEDISPLAY>* vppd = pResult->GetPrecedenceDisplays();
  300. if (vppd && !vppd->empty())
  301. {
  302. PPRECEDENCEDISPLAY ppd = vppd->front();
  303. if( ppd && ppd->m_uStatus != PRECEDENCE_STATUS_SUCCESS )
  304. {
  305. return SCE_CRITICAL_IDX;
  306. }
  307. }
  308. return nImage;
  309. }