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.

169 lines
4.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: cchoice.cpp
  7. //
  8. // Contents: implementation of CConfigChoice
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "wsecmgr.h"
  13. #include "attr.h"
  14. #include "CChoice.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. // CConfigChoice dialog
  23. CConfigChoice::CConfigChoice(UINT nTemplateID)
  24. : CAttribute(nTemplateID ? nTemplateID : IDD)
  25. {
  26. //{{AFX_DATA_INIT(CConfigChoice)
  27. //}}AFX_DATA_INIT
  28. m_pHelpIDs = (DWORD_PTR)a236HelpIDs;
  29. m_uTemplateResID = IDD;
  30. }
  31. void CConfigChoice::DoDataExchange(CDataExchange* pDX)
  32. {
  33. CAttribute::DoDataExchange(pDX);
  34. //{{AFX_DATA_MAP(CConfigChoice)
  35. DDX_Control(pDX, IDC_CHOICES, m_cbChoices);
  36. //}}AFX_DATA_MAP
  37. }
  38. BEGIN_MESSAGE_MAP(CConfigChoice, CAttribute)
  39. //{{AFX_MSG_MAP(CConfigChoice)
  40. ON_CBN_SELCHANGE(IDC_CHOICES, OnSelchangeChoices)
  41. //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CConfigChoice message handlers
  45. void CConfigChoice::Initialize(CResult * pResult)
  46. {
  47. CAttribute::Initialize(pResult);
  48. m_pChoices = pResult->GetRegChoices();
  49. PSCE_REGISTRY_VALUE_INFO prv = (PSCE_REGISTRY_VALUE_INFO)(pResult->GetBase());
  50. if ( prv && prv->Value) //Raid #372939, 4/20/2001; #395353, #396098, 5/16/2001
  51. {
  52. m_bConfigure = TRUE;
  53. } else {
  54. m_bConfigure = FALSE;
  55. }
  56. }
  57. BOOL CConfigChoice::OnInitDialog()
  58. {
  59. CAttribute::OnInitDialog();
  60. PREGCHOICE pChoice = m_pChoices;
  61. PSCE_REGISTRY_VALUE_INFO prv = (PSCE_REGISTRY_VALUE_INFO)(m_pData->GetBase());
  62. int nIndex = 0;
  63. ASSERT(prv);
  64. ASSERT(pChoice);
  65. if (!prv || !pChoice) {
  66. return TRUE;
  67. }
  68. CString strOut;
  69. DWORD dwValue = pChoice->dwValue; //Raid #404000
  70. if (prv->Value)
  71. {
  72. dwValue = (DWORD)_ttoi(prv->Value);
  73. }
  74. while(pChoice) {
  75. m_cbChoices.InsertString(nIndex,pChoice->szName);
  76. if (dwValue == pChoice->dwValue) {
  77. m_cbChoices.SetCurSel(nIndex);
  78. }
  79. m_cbChoices.SetItemData(nIndex++,pChoice->dwValue);
  80. pChoice = pChoice->pNext;
  81. }
  82. AddUserControl(IDC_CHOICES);
  83. EnableUserControls(m_bConfigure);
  84. return TRUE; // return TRUE unless you set the focus to a control
  85. // EXCEPTION: OCX Property Pages should return FALSE
  86. }
  87. BOOL CConfigChoice::OnApply()
  88. {
  89. if ( !m_bReadOnly )
  90. {
  91. DWORD dw = 0;
  92. int nIndex = 0;
  93. UpdateData(TRUE);
  94. if (!m_bConfigure)
  95. dw = SCE_NO_VALUE;
  96. else
  97. {
  98. nIndex = m_cbChoices.GetCurSel();
  99. if (CB_ERR != nIndex)
  100. dw = (DWORD)m_cbChoices.GetItemData(nIndex);
  101. }
  102. PSCE_REGISTRY_VALUE_INFO prv=(PSCE_REGISTRY_VALUE_INFO)(m_pData->GetBase());
  103. //
  104. // this address should never be NULL
  105. //
  106. ASSERT(prv != NULL);
  107. if ( prv )
  108. {
  109. PWSTR pTmp=NULL;
  110. if ( dw != SCE_NO_VALUE )
  111. {
  112. CString strTmp;
  113. // allocate buffer
  114. strTmp.Format(TEXT("%d"), dw);
  115. pTmp = (PWSTR)LocalAlloc(0, (strTmp.GetLength()+1)*sizeof(TCHAR));
  116. if ( pTmp )
  117. //This may not be a safe usage, using sizeof(WCHAR) instead of sizeof(TCHAR). Consider fix.
  118. wcscpy(pTmp,(LPCTSTR)strTmp);
  119. else
  120. {
  121. // can't allocate buffer, error!!
  122. return FALSE;
  123. }
  124. }
  125. if ( prv->Value )
  126. LocalFree(prv->Value);
  127. prv->Value = pTmp;
  128. m_pData->SetBase((LONG_PTR)prv);
  129. m_pData->Update(m_pSnapin);
  130. }
  131. }
  132. return CAttribute::OnApply();
  133. }
  134. void CConfigChoice::OnSelchangeChoices()
  135. {
  136. SetModified(TRUE);
  137. }