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.

228 lines
5.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: cname.cpp
  7. //
  8. // Contents: implementation of CConfigName
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "wsecmgr.h"
  13. #include "CName.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. PCWSTR g_pcszNEWLINE = L"\x00d\x00a";
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CConfigName dialog
  23. CConfigName::CConfigName(UINT nTemplateID)
  24. : CAttribute(nTemplateID ? nTemplateID : IDD),
  25. m_bNoBlanks(FALSE)
  26. {
  27. //{{AFX_DATA_INIT(CConfigName)
  28. m_strName = _T("");
  29. m_bConfigure = TRUE;
  30. //}}AFX_DATA_INIT
  31. m_pHelpIDs = (DWORD_PTR)a183HelpIDs;
  32. m_uTemplateResID = IDD;
  33. }
  34. CConfigName::~CConfigName ()
  35. {
  36. }
  37. void CConfigName::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CAttribute::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CConfigName)
  41. // DDX_Radio(pDX, IDC_ACCEPT, m_nAcceptCurrentRadio);
  42. DDX_Text(pDX, IDC_NAME, m_strName);
  43. //}}AFX_DATA_MAP
  44. }
  45. BEGIN_MESSAGE_MAP(CConfigName, CAttribute)
  46. //{{AFX_MSG_MAP(CConfigName)
  47. ON_BN_CLICKED(IDC_CONFIGURE, OnConfigure)
  48. ON_EN_CHANGE(IDC_NAME, OnChangeName)
  49. //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CConfigName message handlers
  53. void CConfigName::Initialize(CResult * pResult)
  54. {
  55. CAttribute::Initialize(pResult);
  56. if ((LONG_PTR)ULongToPtr(SCE_NO_VALUE) == pResult->GetBase() ||
  57. 0 == pResult->GetBase() )
  58. {
  59. m_strName = _T("");
  60. m_bConfigure = FALSE;
  61. }
  62. else
  63. {
  64. m_bConfigure = TRUE;
  65. m_strName = (LPTSTR) pResult->GetBase();
  66. }
  67. if (m_pData->GetID() == IDS_NEW_ADMIN ||
  68. m_pData->GetID() == IDS_NEW_GUEST)
  69. {
  70. m_bNoBlanks = TRUE;
  71. }
  72. else
  73. m_bNoBlanks = FALSE;
  74. }
  75. BOOL CConfigName::OnApply()
  76. {
  77. if ( !m_bReadOnly )
  78. {
  79. LONG_PTR dw = 0;
  80. CString szDoubleNewLine (g_pcszNEWLINE);
  81. szDoubleNewLine += g_pcszNEWLINE;
  82. UpdateData(TRUE);
  83. m_strName.TrimLeft();
  84. m_strName.TrimRight();
  85. // 249188 SCE UI: allows adding empty lines to REG_MULTI_SZ fields
  86. // Replace all double newlines with single newlines. This has the effect
  87. // of deleting empty lines.
  88. while (m_strName.Replace (szDoubleNewLine, g_pcszNEWLINE) != 0);
  89. UpdateData (FALSE);
  90. if (!m_bConfigure)
  91. dw = (LONG_PTR)ULongToPtr(SCE_NO_VALUE);
  92. else
  93. dw = (LONG_PTR)(LPCTSTR)m_strName;
  94. if ( SetProfileInfo(m_pData->GetID(),dw,m_pData->GetBaseProfile()) )
  95. {
  96. switch ( m_pData->GetID() )
  97. {
  98. case IDS_NEW_ADMIN:
  99. dw = (LONG_PTR)(m_pData->GetBaseProfile()->pTemplate->NewAdministratorName);
  100. break;
  101. case IDS_NEW_GUEST:
  102. dw = (LONG_PTR)(m_pData->GetBaseProfile()->pTemplate->NewGuestName);
  103. break;
  104. default:
  105. dw = 0;
  106. break;
  107. }
  108. m_pData->SetBase(dw);
  109. m_pData->Update(m_pSnapin);
  110. }
  111. }
  112. return CAttribute::OnApply();
  113. }
  114. void CConfigName::OnConfigure()
  115. {
  116. CAttribute::OnConfigure();
  117. if(m_bConfigure && m_pData) //Raid #367756, 4/13/2001
  118. {
  119. UpdateData(TRUE);
  120. if( m_strName.IsEmpty() )
  121. {
  122. switch(m_pData->GetType())
  123. {
  124. case ITEM_PROF_REGVALUE:
  125. {
  126. DWORD_PTR dw = (DWORD_PTR)m_pData->GetRegDefault();
  127. LPTSTR sz = SZToMultiSZ((PCWSTR)dw);
  128. m_strName = sz;
  129. if(sz)
  130. {
  131. LocalFree(sz);
  132. }
  133. ((CWnd*)(GetDlgItem(IDC_NAME)))->SetWindowText(m_strName);
  134. break;
  135. }
  136. default:
  137. break;
  138. }
  139. }
  140. }
  141. CWnd *cwnd = 0;
  142. if (m_bNoBlanks)
  143. {
  144. cwnd = GetDlgItem(IDOK);
  145. if (cwnd)
  146. {
  147. if (m_bConfigure)
  148. cwnd->EnableWindow(!m_strName.IsEmpty());
  149. else
  150. cwnd->EnableWindow(TRUE);
  151. }
  152. }
  153. }
  154. BOOL CConfigName::OnInitDialog()
  155. {
  156. CAttribute::OnInitDialog();
  157. AddUserControl(IDC_NAME);
  158. OnConfigure();
  159. return TRUE; // return TRUE unless you set the focus to a control
  160. // EXCEPTION: OCX Property Pages should return FALSE
  161. }
  162. void CConfigName::OnChangeName()
  163. {
  164. CWnd *cwnd = 0;
  165. SetModified(TRUE);
  166. if (m_bNoBlanks)
  167. {
  168. UpdateData(TRUE);
  169. cwnd = GetDlgItem(IDOK);
  170. if (cwnd)
  171. cwnd->EnableWindow(!m_strName.IsEmpty());
  172. }
  173. }
  174. BOOL CConfigName::OnKillActive()
  175. {
  176. if (m_bNoBlanks && !m_bReadOnly && m_bConfigure ) //Raid #406748
  177. {
  178. UpdateData(TRUE);
  179. m_strName.TrimLeft(); //Raid #406738
  180. m_strName.TrimRight();
  181. UpdateData(FALSE);
  182. if (m_strName.IsEmpty())
  183. {
  184. //Raid #313721, Yang Gao, 3/29/2001
  185. CString str;
  186. str.LoadString(IDS_EMPTY_NAME_STRING);
  187. AfxMessageBox(str);
  188. return FALSE;
  189. }
  190. }
  191. return TRUE;
  192. }