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.

182 lines
4.6 KiB

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