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.

203 lines
5.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: aflags.cpp
  7. //
  8. // Contents: definition of CAttrRegFlags
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "wsecmgr.h"
  13. #include "attr.h"
  14. #include "chklist.h"
  15. #include "util.h"
  16. #include "aFlags.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CAttrRegFlags dialog
  24. CAttrRegFlags::CAttrRegFlags()
  25. : CAttribute(IDD), m_pFlags(NULL)
  26. {
  27. //{{AFX_DATA_INIT(CAttrRegFlags)
  28. // NOTE: the ClassWizard will add member initialization here
  29. //}}AFX_DATA_INIT
  30. m_pHelpIDs = (DWORD_PTR)a236HelpIDs;
  31. m_uTemplateResID = IDD;
  32. }
  33. void CAttrRegFlags::DoDataExchange(CDataExchange* pDX)
  34. {
  35. CAttribute::DoDataExchange(pDX);
  36. //{{AFX_DATA_MAP(CAttrRegFlags)
  37. // NOTE: the ClassWizard will add DDX and DDV calls here
  38. DDX_Text(pDX, IDC_CURRENT, m_Current);
  39. //}}AFX_DATA_MAP
  40. }
  41. BEGIN_MESSAGE_MAP(CAttrRegFlags, CAttribute)
  42. //{{AFX_MSG_MAP(CAttrRegFlags)
  43. //}}AFX_MSG_MAP
  44. ON_NOTIFY(CLN_CLICK, IDC_CHECKBOX, OnClickCheckBox)
  45. END_MESSAGE_MAP()
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CAttrRegFlags message handlers
  48. void CAttrRegFlags::Initialize(CResult * pResult)
  49. {
  50. CAttribute::Initialize(pResult);
  51. m_pFlags = pResult->GetRegFlags();
  52. PSCE_REGISTRY_VALUE_INFO prv = (PSCE_REGISTRY_VALUE_INFO)(pResult->GetBase());
  53. if ( prv && prv->Value ) {
  54. m_bConfigure = TRUE;
  55. } else {
  56. m_bConfigure = FALSE;
  57. }
  58. pResult->GetDisplayName(NULL,m_Current,2);
  59. }
  60. BOOL CAttrRegFlags::OnInitDialog()
  61. {
  62. CAttribute::OnInitDialog();
  63. CWnd *wndCL = NULL;
  64. DWORD fFlags = 0;
  65. DWORD fFlagsComp = 0;
  66. PREGFLAGS pFlags = m_pFlags;
  67. PSCE_REGISTRY_VALUE_INFO prv = (PSCE_REGISTRY_VALUE_INFO)(m_pData->GetBase());
  68. PSCE_REGISTRY_VALUE_INFO prvComp = (PSCE_REGISTRY_VALUE_INFO)(m_pData->GetSetting());
  69. if (prv && prv->Value) {
  70. fFlags = (DWORD)_ttoi(prv->Value);
  71. }
  72. if (prvComp && prvComp->Value) {
  73. fFlagsComp = (DWORD)_ttoi(prvComp->Value);
  74. }
  75. int nIndex = 0;
  76. CString strOut;
  77. wndCL = GetDlgItem(IDC_CHECKBOX);
  78. if (!wndCL) {
  79. //
  80. // This should never happen
  81. //
  82. ASSERT(wndCL);
  83. return FALSE;
  84. }
  85. wndCL->SendMessage(CLM_RESETCONTENT,0,0);
  86. while(pFlags) {
  87. nIndex = (int) wndCL->SendMessage(CLM_ADDITEM,
  88. (WPARAM)pFlags->szName,
  89. (LPARAM)pFlags->dwValue);
  90. if (nIndex != -1) {
  91. BOOL bSet;
  92. //
  93. // Template setting: editable
  94. //
  95. bSet = ((fFlags & pFlags->dwValue) == pFlags->dwValue);
  96. wndCL->SendMessage(CLM_SETSTATE,
  97. MAKELONG(nIndex,1),
  98. bSet ? CLST_CHECKED : CLST_UNCHECKED);
  99. //
  100. // Analyzed setting: always disabled
  101. //
  102. bSet = ((fFlagsComp & pFlags->dwValue) == pFlags->dwValue);
  103. wndCL->SendMessage(CLM_SETSTATE,
  104. MAKELONG(nIndex,2),
  105. CLST_DISABLED | (bSet ? CLST_CHECKED : CLST_UNCHECKED));
  106. }
  107. pFlags = pFlags->pNext;
  108. }
  109. AddUserControl(IDC_CHECKBOX);
  110. EnableUserControls(m_bConfigure);
  111. return TRUE; // return TRUE unless you set the focus to a control
  112. // EXCEPTION: OCX Property Pages should return FALSE
  113. }
  114. BOOL CAttrRegFlags::OnApply()
  115. {
  116. if ( !m_bReadOnly )
  117. {
  118. DWORD dw = 0;
  119. CWnd *wndCL = NULL;
  120. DWORD fFlags = 0;
  121. UpdateData(TRUE);
  122. wndCL = GetDlgItem(IDC_CHECKBOX);
  123. ASSERT(wndCL != NULL);
  124. if (!m_bConfigure || !wndCL)
  125. dw = SCE_NO_VALUE;
  126. else
  127. {
  128. int nItems = (int) wndCL->SendMessage(CLM_GETITEMCOUNT,0,0);
  129. for (int i=0;i<nItems;i++)
  130. {
  131. dw = (DWORD)wndCL->SendMessage(CLM_GETSTATE,MAKELONG(i,1));
  132. if (CLST_CHECKED == dw)
  133. fFlags |= wndCL->SendMessage(CLM_GETITEMDATA,i);
  134. }
  135. }
  136. PSCE_REGISTRY_VALUE_INFO prv=(PSCE_REGISTRY_VALUE_INFO)(m_pData->GetBase());
  137. //
  138. // this address should never be NULL
  139. //
  140. ASSERT(prv != NULL);
  141. if ( prv )
  142. {
  143. PWSTR pTmp=NULL;
  144. if ( dw != SCE_NO_VALUE )
  145. {
  146. CString strTmp;
  147. // allocate buffer
  148. strTmp.Format(TEXT("%d"), fFlags);
  149. pTmp = (PWSTR)LocalAlloc(0, (strTmp.GetLength()+1)*sizeof(TCHAR));
  150. if ( pTmp )
  151. lstrcpy(pTmp,(LPCTSTR)strTmp);
  152. else
  153. {
  154. // can't allocate buffer, error!!
  155. return FALSE;
  156. }
  157. }
  158. if ( prv->Value )
  159. LocalFree(prv->Value);
  160. prv->Value = pTmp;
  161. m_pData->SetBase((LONG_PTR)prv);
  162. m_pData->Update(m_pSnapin);
  163. }
  164. }
  165. return CAttribute::OnApply();
  166. }
  167. void CAttrRegFlags::OnClickCheckBox(NMHDR *pNM, LRESULT *pResult) //Raid #389890, 5/11/2001
  168. {
  169. SetModified(TRUE);
  170. }