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.

197 lines
4.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: attrstring.cpp
  7. //
  8. // Contents: implementation of CAttrString
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "wsecmgr.h"
  13. #include "AString.h"
  14. #include "util.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CAttrString dialog
  22. CAttrString::CAttrString(UINT nTemplateID)
  23. : CAttribute(nTemplateID ? nTemplateID : IDD),
  24. m_bNoBlanks(FALSE)
  25. {
  26. //{{AFX_DATA_INIT(CAttrString)
  27. m_strSetting = _T("");
  28. m_strBase = _T("");
  29. //}}AFX_DATA_INIT
  30. m_pHelpIDs = (DWORD_PTR)a167HelpIDs;
  31. m_uTemplateResID = IDD;
  32. }
  33. void CAttrString::DoDataExchange(CDataExchange* pDX)
  34. {
  35. CAttribute::DoDataExchange(pDX);
  36. //{{AFX_DATA_MAP(CAttrString)
  37. DDX_Text(pDX, IDC_CURRENT, m_strSetting);
  38. DDX_Text(pDX, IDC_NEW, m_strBase);
  39. //}}AFX_DATA_MAP
  40. }
  41. BEGIN_MESSAGE_MAP(CAttrString, CAttribute)
  42. //{{AFX_MSG_MAP(CAttrString)
  43. ON_BN_CLICKED(IDC_CONFIGURE, OnConfigure)
  44. ON_EN_CHANGE(IDC_NEW, OnChangeNew)
  45. //}}AFX_MSG_MAP
  46. END_MESSAGE_MAP()
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CAttrString message handlers
  49. BOOL CAttrString::OnInitDialog()
  50. {
  51. CAttribute::OnInitDialog();
  52. AddUserControl(IDC_NEW);
  53. OnConfigure();
  54. return TRUE; // return TRUE unless you set the focus to a control
  55. // EXCEPTION: OCX Property Pages should return FALSE
  56. }
  57. void CAttrString::OnConfigure()
  58. {
  59. CAttribute::OnConfigure();
  60. CWnd *item = 0;
  61. if (m_bNoBlanks) {
  62. item = GetDlgItem(IDOK);
  63. if (item) {
  64. if (m_bConfigure) {
  65. item->EnableWindow(!m_strBase.IsEmpty());
  66. } else {
  67. item->EnableWindow(TRUE);
  68. }
  69. }
  70. }
  71. }
  72. void CAttrString::Initialize(CResult * pResult)
  73. {
  74. CAttribute::Initialize(pResult);
  75. pResult->GetDisplayName( NULL, m_strSetting, 2 );
  76. if ((LONG_PTR)ULongToPtr(SCE_NO_VALUE) == pResult->GetBase() ||
  77. NULL == pResult->GetBase() ){
  78. m_bConfigure = FALSE;
  79. } else {
  80. m_bConfigure = TRUE;
  81. pResult->GetDisplayName( NULL, m_strBase, 1 );
  82. }
  83. if (m_pData->GetID() == IDS_NEW_ADMIN ||
  84. m_pData->GetID() == IDS_NEW_GUEST) {
  85. m_bNoBlanks = TRUE;
  86. } else {
  87. m_bNoBlanks = FALSE;
  88. }
  89. }
  90. BOOL CAttrString::OnApply()
  91. {
  92. if ( !m_bReadOnly )
  93. {
  94. LONG_PTR dw = 0;
  95. UpdateData(TRUE);
  96. BOOL bChanged=TRUE;
  97. m_strBase.TrimLeft();
  98. m_strBase.TrimRight();
  99. if (!m_bConfigure)
  100. {
  101. dw = 0;
  102. if ( (LONG_PTR)ULongToPtr(SCE_NO_VALUE) == m_pData->GetBase() ||
  103. 0 == m_pData->GetBase() )
  104. {
  105. bChanged = FALSE;
  106. }
  107. }
  108. else
  109. {
  110. dw = (LONG_PTR)(LPCTSTR)m_strBase;
  111. if ( m_pData->GetBase() && dw &&
  112. (LONG_PTR)ULongToPtr(SCE_NO_VALUE) != m_pData->GetBase() &&
  113. _wcsicmp((LPTSTR)(m_pData->GetBase()), (LPTSTR)dw) == 0 )
  114. {
  115. bChanged = FALSE;
  116. }
  117. }
  118. if ( bChanged )
  119. {
  120. if ( m_pData->GetSetting() == m_pData->GetBase() &&
  121. m_pData->GetSetting() )
  122. {
  123. // a good item, need take the base into setting
  124. m_pSnapin->TransferAnalysisName(m_pData->GetID());
  125. }
  126. m_pData->SetBase(dw);
  127. DWORD dwStatus = m_pSnapin->SetAnalysisInfo(m_pData->GetID(),dw, m_pData);
  128. m_pData->SetStatus(dwStatus);
  129. m_pData->Update(m_pSnapin);
  130. }
  131. }
  132. return CAttribute::OnApply();
  133. }
  134. void CAttrString::OnChangeNew()
  135. {
  136. CWnd *cwnd = 0;
  137. if (m_bNoBlanks) {
  138. UpdateData(TRUE);
  139. cwnd = GetDlgItem(IDOK);
  140. if (cwnd) {
  141. cwnd->EnableWindow(!m_strBase.IsEmpty());
  142. }
  143. }
  144. SetModified(TRUE);
  145. }
  146. BOOL CAttrString::OnKillActive() {
  147. if ( m_bNoBlanks && m_bConfigure ) //Raid #407190
  148. {
  149. UpdateData(TRUE);
  150. m_strBase.TrimLeft();
  151. m_strBase.TrimRight();
  152. UpdateData(FALSE);
  153. if (m_strBase.IsEmpty())
  154. {
  155. CString str;
  156. str.LoadString(IDS_EMPTY_NAME_STRING);
  157. AfxMessageBox(str);
  158. return FALSE;
  159. }
  160. }
  161. return TRUE;
  162. }