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.

214 lines
5.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: achoice.cpp
  7. //
  8. // Contents: implementation of CAttrChoice
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "wsecmgr.h"
  13. #include "attr.h"
  14. #include "AChoice.h"
  15. #include "util.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CAttrChoice dialog
  23. CAttrChoice::CAttrChoice()
  24. : CAttribute(IDD), m_pChoices(NULL)
  25. {
  26. //{{AFX_DATA_INIT(CAttrChoice)
  27. m_Current = _T("");
  28. //}}AFX_DATA_INIT
  29. m_pHelpIDs = (DWORD_PTR)a237HelpIDs;
  30. m_uTemplateResID = IDD;
  31. }
  32. void CAttrChoice::DoDataExchange(CDataExchange* pDX)
  33. {
  34. CAttribute::DoDataExchange(pDX);
  35. //{{AFX_DATA_MAP(CAttrChoice)
  36. DDX_Control(pDX, IDC_CHOICES, m_cbChoices);
  37. DDX_Text(pDX, IDC_CURRENT, m_Current);
  38. //}}AFX_DATA_MAP
  39. }
  40. BEGIN_MESSAGE_MAP(CAttrChoice, CAttribute)
  41. //{{AFX_MSG_MAP(CAttrChoice)
  42. ON_CBN_SELCHANGE(IDC_CHOICES, OnSelchangeChoices)
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CAttrChoice message handlers
  47. void CAttrChoice::OnSelchangeChoices()
  48. {
  49. CWnd *cwndOK;
  50. SetModified(TRUE);
  51. /*
  52. cwndOK = GetDlgItem(IDOK);
  53. if (cwndOK) {
  54. cwndOK->EnableWindow( CB_ERR != m_cbChoices.GetCurSel() );
  55. }
  56. */
  57. }
  58. void CAttrChoice::Initialize(CResult * pResult)
  59. {
  60. CAttribute::Initialize(pResult);
  61. m_pChoices = pResult->GetRegChoices();
  62. PSCE_REGISTRY_VALUE_INFO prv = (PSCE_REGISTRY_VALUE_INFO)(pResult->GetBase());
  63. if ( prv && prv->Value ) {
  64. m_bConfigure = TRUE;
  65. } else {
  66. m_bConfigure = FALSE;
  67. }
  68. prv = (PSCE_REGISTRY_VALUE_INFO)(pResult->GetSetting());
  69. PREGCHOICE pChoice;
  70. DWORD dwSetting = 0; //Raid #395353, 5/16/2001
  71. if( m_pChoices ) //Raid #404000
  72. dwSetting = m_pChoices->dwValue;
  73. if( prv->Value )
  74. dwSetting = (DWORD)_ttoi(prv->Value);
  75. pChoice = m_pChoices;
  76. while(pChoice) {
  77. if (dwSetting == pChoice->dwValue) {
  78. m_Current = pChoice->szName;
  79. break;
  80. }
  81. pChoice = pChoice->pNext;
  82. }
  83. pResult->GetDisplayName( NULL, m_Current, 2 );
  84. }
  85. BOOL CAttrChoice::OnInitDialog()
  86. {
  87. CAttribute::OnInitDialog();
  88. PREGCHOICE pChoice = m_pChoices;
  89. int nIndex = 0;
  90. PSCE_REGISTRY_VALUE_INFO prv = (PSCE_REGISTRY_VALUE_INFO)(m_pData->GetBase());
  91. ASSERT(prv);
  92. ASSERT(pChoice);
  93. if (!prv || !pChoice) {
  94. return TRUE;
  95. }
  96. AddUserControl(IDC_CHOICES);
  97. DWORD dwBase = pChoice->dwValue; //Raid #404000
  98. if (prv->Value) {
  99. dwBase = (DWORD)_ttoi(prv->Value);
  100. }
  101. while(pChoice) {
  102. m_cbChoices.InsertString(nIndex,pChoice->szName);
  103. if (dwBase == pChoice->dwValue) {
  104. m_cbChoices.SetCurSel(nIndex);
  105. }
  106. m_cbChoices.SetItemData(nIndex++,pChoice->dwValue);
  107. pChoice = pChoice->pNext;
  108. }
  109. EnableUserControls(m_bConfigure);
  110. OnSelchangeChoices();
  111. return TRUE; // return TRUE unless you set the focus to a control
  112. // EXCEPTION: OCX Property Pages should return FALSE
  113. }
  114. BOOL CAttrChoice::OnApply()
  115. {
  116. if ( !m_bReadOnly )
  117. {
  118. int nIndex = 0;
  119. int status = 0;
  120. DWORD rc=0;
  121. UpdateData(TRUE);
  122. DWORD dw = 0;
  123. if (!m_bConfigure)
  124. dw = SCE_NO_VALUE;
  125. else
  126. {
  127. nIndex = m_cbChoices.GetCurSel();
  128. if (CB_ERR != nIndex)
  129. dw = (DWORD) m_cbChoices.GetItemData(nIndex);
  130. }
  131. PSCE_REGISTRY_VALUE_INFO prv=(PSCE_REGISTRY_VALUE_INFO)(m_pData->GetBase());
  132. //
  133. // this address should never be NULL
  134. //
  135. if ( prv )
  136. {
  137. PWSTR pTmp=NULL;
  138. if ( dw != SCE_NO_VALUE )
  139. {
  140. CString strTmp;
  141. // allocate buffer
  142. strTmp.Format(TEXT("%d"), dw);
  143. pTmp = (PWSTR)LocalAlloc(0, (strTmp.GetLength()+1)*sizeof(TCHAR));
  144. if ( pTmp )
  145. wcscpy(pTmp,(LPCTSTR)strTmp);
  146. else
  147. {
  148. // can't allocate buffer, error!!
  149. // if this happens, nothing else is probably running so just fail
  150. rc = ERROR_NOT_ENOUGH_MEMORY;
  151. }
  152. }
  153. if ( rc == ERROR_SUCCESS )
  154. {
  155. if ( prv->Value )
  156. LocalFree(prv->Value);
  157. prv->Value = pTmp;
  158. status = CEditTemplate::ComputeStatus(
  159. (PSCE_REGISTRY_VALUE_INFO)m_pData->GetBase(),
  160. (PSCE_REGISTRY_VALUE_INFO)m_pData->GetSetting());
  161. if ( m_pData->GetBaseProfile() )
  162. m_pData->GetBaseProfile()->SetDirty(AREA_SECURITY_POLICY);
  163. m_pData->SetStatus(status);
  164. m_pData->Update(m_pSnapin);
  165. }
  166. else
  167. return FALSE;
  168. }
  169. }
  170. return CAttribute::OnApply();
  171. }