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.

430 lines
13 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2001.
  5. //
  6. // File: Wiz97pg.cpp
  7. //
  8. // Contents: WiF Policy Snapin
  9. //
  10. //
  11. // History: TaroonM
  12. // 10/30/01
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "stdafx.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. //
  23. // Base classes for Wiz97 dialogs
  24. //
  25. /////////////////////////////////////////////////////////////////////////////
  26. /////////////////////////////////////////////////////////////////////////////
  27. //
  28. // CWiz97BasePage base class
  29. //
  30. /////////////////////////////////////////////////////////////////////////////
  31. IMPLEMENT_DYNCREATE(CWiz97BasePage, CSnapPage)
  32. BOOL CWiz97BasePage::m_static_bFinish = FALSE;
  33. BOOL CWiz97BasePage::m_static_bOnCancelCalled = FALSE;
  34. CWiz97BasePage::CWiz97BasePage( UINT nIDD, BOOL bWiz97 /*= TRUE*/, BOOL bFinishPage /*= FALSE*/ ) :
  35. CSnapPage( nIDD, bWiz97 ),
  36. m_bSetActive( FALSE ),
  37. m_bFinishPage( bFinishPage ),
  38. m_pbDoAfterWizardHook( NULL ),
  39. m_bReset( FALSE )
  40. {
  41. CWiz97BasePage::m_static_bFinish = FALSE;
  42. CWiz97BasePage::m_static_bOnCancelCalled = FALSE;
  43. }
  44. CWiz97BasePage::~CWiz97BasePage()
  45. {
  46. // Clean up
  47. m_psp.dwFlags = 0;
  48. m_psp.pfnCallback = NULL;
  49. m_psp.lParam = (LPARAM)NULL;
  50. }
  51. BOOL CWiz97BasePage::OnInitDialog()
  52. {
  53. CSnapPage::OnInitDialog();
  54. if ( IDD_PROPPAGE_P_WELCOME == m_nIDD )
  55. {
  56. SetLargeFont(m_hWnd, IDC_POLICY_WIZARD_TITLE );
  57. }
  58. if ( IDD_PROPPAGE_N_DONE == m_nIDD )
  59. {
  60. SetLargeFont(m_hWnd, IDC_POLICY_WIZARD_DONE );
  61. }
  62. OnFinishInitDialog();
  63. return TRUE; // return TRUE unless you set the focus to a control
  64. // EXCEPTION: OCX Property Pages should return FALSE
  65. }
  66. BOOL CWiz97BasePage::InitWiz97
  67. (
  68. DWORD dwFlags,
  69. DWORD dwWizButtonFlags /*= 0*/,
  70. UINT nHeaderTitle /*= 0*/,
  71. UINT nSubTitle /*= 0*/,
  72. STACK_INT *pstackPages /*= NULL*/
  73. )
  74. {
  75. // NOTE: we wouldn't ever get here except when win97 wizards are running
  76. // but we have to compile this in because its a base class, EVEN WHEN
  77. // NOT DOING WIZ97 WIZARDS. To maintain the compile we have to ifdef
  78. // out this call to the base class
  79. #ifdef WIZ97WIZARDS
  80. // Hook up our callback function
  81. return CSnapPage::InitWiz97( &CWiz97BasePage::PropSheetPageCallback,
  82. NULL, dwFlags, dwWizButtonFlags, nHeaderTitle, nSubTitle, pstackPages );
  83. #else
  84. return FALSE;
  85. #endif
  86. }
  87. BOOL CWiz97BasePage::InitWiz97
  88. (
  89. CComObject<CSecPolItem> *pSecPolItem,
  90. DWORD dwFlags,
  91. DWORD dwWizButtonFlags /*= 0*/,
  92. UINT nHeaderTitle /*= 0*/,
  93. UINT nSubTitle /*= 0*/
  94. )
  95. {
  96. // Hook up our callback function
  97. return CSnapPage::InitWiz97( &CWiz97BasePage::PropSheetPageCallback,
  98. pSecPolItem, dwFlags, dwWizButtonFlags, nHeaderTitle, nSubTitle );
  99. }
  100. // static member
  101. UINT CALLBACK CWiz97BasePage::PropSheetPageCallback( HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp )
  102. {
  103. if (PSPCB_RELEASE == uMsg)
  104. {
  105. ASSERT( NULL != ppsp && NULL != ppsp->lParam );
  106. CWiz97BasePage *pThis = reinterpret_cast<CWiz97BasePage*>(ppsp->lParam);
  107. // Wiz97BasePage callback handling is for wizards only.
  108. if (pThis->m_bWiz97)
  109. {
  110. if (m_static_bFinish) // Sheet is finishing
  111. {
  112. // Call OnWizardRelease for each page in the sheet giving each page
  113. // the opportunity to clean up anything left over after the finish
  114. // page's OnWizardFinish.
  115. pThis->OnWizardRelease();
  116. // If an access violation occurs here its because OnWizardRelease()
  117. // is not a member of the base class. See the implementation note
  118. // in wiz97run.cpp.
  119. }
  120. else // Sheet is cancelling
  121. {
  122. // Call OnCancel when it hasn't been called yet. OnCancel was already
  123. // called by OnReset for pages which were activated, don't call it again.
  124. if (!pThis->m_bReset)
  125. pThis->OnCancel();
  126. if (!CWiz97BasePage::m_static_bOnCancelCalled)
  127. {
  128. // Make sure base class OnCancel is called exactly once because
  129. // there is only one object for the propsheet, and OnCancel
  130. // refreshes it, throwing away changes. All proppages have
  131. // a ptr to the same object.
  132. CWiz97BasePage::m_static_bOnCancelCalled = TRUE;
  133. pThis->CSnapPage::OnCancel();
  134. }
  135. }
  136. }
  137. }
  138. return CSnapPage::PropertyPageCallback( hwnd, uMsg, ppsp );
  139. }
  140. void CWiz97BasePage::ConnectAfterWizardHook( BOOL *pbDoHook )
  141. {
  142. ASSERT( NULL != pbDoHook );
  143. m_pbDoAfterWizardHook = pbDoHook;
  144. *m_pbDoAfterWizardHook = FALSE; // initialize
  145. }
  146. void CWiz97BasePage::SetAfterWizardHook( BOOL bDoHook )
  147. {
  148. ASSERT( NULL != m_pbDoAfterWizardHook );
  149. *m_pbDoAfterWizardHook = bDoHook;
  150. }
  151. /////////////////////////////////////////////////////////////////////////////
  152. // CWiz97BasePage message handlers
  153. BOOL CWiz97BasePage::OnSetActive()
  154. {
  155. m_bSetActive = TRUE;
  156. return CSnapPage::OnSetActive();
  157. }
  158. BOOL CWiz97BasePage::OnWizardFinish()
  159. {
  160. // Let other wizard pages know they should finish, instead of cancel.
  161. SetFinished();
  162. // If m_pbDoAfterWizardHook is valid, caller expects it to be set.
  163. // Derive this function in your class.
  164. return CSnapPage::OnWizardFinish();
  165. }
  166. void CWiz97BasePage::OnCancel()
  167. {
  168. // Make sure we don't call OnCancel again for this page
  169. m_bReset = TRUE;
  170. // Note: OnCancel is ALWAYS called, even when the page has not been
  171. // activated. Override this class to clean up anything that was done
  172. // in InitWiz97. CSnapPage::OnCancel will be called exactly once for
  173. // the Sheet by the Page callback function.
  174. }
  175. //////////////////////////////////////////////////////////////////////
  176. // CWiz97PSBasePage Class
  177. //////////////////////////////////////////////////////////////////////
  178. /////////////////////////////////////////////////////////////////////////////
  179. //
  180. // General Name/Properties Wiz97 dialog(s)
  181. //
  182. /////////////////////////////////////////////////////////////////////////////
  183. CWiz97WirelessPolGenPage::CWiz97WirelessPolGenPage(UINT nIDD, UINT nInformativeText, BOOL bWiz97) :
  184. CWiz97BasePage(nIDD, bWiz97)
  185. {
  186. m_nInformativeText = nInformativeText;
  187. m_pPolicy = NULL;
  188. }
  189. CWiz97WirelessPolGenPage::~CWiz97WirelessPolGenPage()
  190. {
  191. }
  192. void CWiz97WirelessPolGenPage::DoDataExchange(CDataExchange* pDX)
  193. {
  194. CWiz97BasePage::DoDataExchange(pDX);
  195. //{{AFX_DATA_MAP(CWiz97WirelessPolGenPage)
  196. // NOTE: the ClassWizard will add DDX and DDV calls here
  197. //}}AFX_DATA_MAP
  198. if (IDD_WIFIGEN_WIZBASE == m_nIDD)
  199. {
  200. DDX_Control(pDX, IDC_EDNAME, m_edName);
  201. DDX_Control(pDX, IDC_EDDESCRIPTION, m_edDescription);
  202. }
  203. }
  204. BEGIN_MESSAGE_MAP(CWiz97WirelessPolGenPage, CWiz97BasePage)
  205. //{{AFX_MSG_MAP(CWiz97WirelessPolGenPage)
  206. ON_EN_CHANGE(IDC_EDNAME, OnChangedName)
  207. ON_EN_CHANGE(IDC_EDDESCRIPTION, OnChangedDescription)
  208. //}}AFX_MSG_MAP
  209. END_MESSAGE_MAP()
  210. BOOL CWiz97WirelessPolGenPage::OnInitDialog()
  211. {
  212. // call base class init
  213. CWiz97BasePage::OnInitDialog();
  214. m_pPolicy = m_pspiResultItem->GetWirelessPolicy();
  215. if (IDD_WIFIGEN_WIZBASE == m_nIDD)
  216. {
  217. // show the wait cursor in case there is a huge description being accessed
  218. CWaitCursor waitCursor;
  219. m_edName.SetLimitText(c_nMaxName);
  220. m_edDescription.SetLimitText(c_nMaxName);
  221. // initialize our edit controls
  222. m_edName.SetWindowText (m_pPolicy->pszWirelessName);
  223. m_edDescription.SetWindowText (m_pPolicy->pszDescription);
  224. // add context help to the style bits
  225. if (GetParent())
  226. {
  227. GetParent()->ModifyStyleEx (0, WS_EX_CONTEXTHELP, 0);
  228. }
  229. UpdateData (FALSE);
  230. }
  231. else if (IDD_PROPPAGE_G_NAMEDESCRIPTION == m_nIDD)
  232. {
  233. SendDlgItemMessage(IDC_NEW_POLICY_NAME, EM_LIMITTEXT, c_nMaxName, 0);
  234. SendDlgItemMessage(IDC_NEW_POLICY_DESCRIPTION, EM_LIMITTEXT, c_nMaxName, 0);
  235. }
  236. // OK, we can start paying attention to modifications made via dlg controls now.
  237. // This should be the last call before returning from OnInitDialog.
  238. OnFinishInitDialog();
  239. return TRUE; // return TRUE unless you set the focus to a control
  240. // EXCEPTION: OCX Property Pages should return FALSE
  241. }
  242. BOOL CWiz97WirelessPolGenPage::OnHelpInfo(HELPINFO* pHelpInfo)
  243. {
  244. if (pHelpInfo->iContextType == HELPINFO_WINDOW)
  245. {
  246. DWORD* pdwHelp = (DWORD*) &g_aHelpIDs_IDD_PROPPAGE_G_NAMEDESCRIPTION[0];
  247. ::WinHelp ((HWND)pHelpInfo->hItemHandle,
  248. c_szWlsnpHelpFile,
  249. HELP_WM_HELP,
  250. (DWORD_PTR)(LPVOID)pdwHelp);
  251. }
  252. return CWiz97BasePage::OnHelpInfo(pHelpInfo);
  253. }
  254. void CWiz97WirelessPolGenPage::OnChangedName()
  255. {
  256. ASSERT( IDD_WIFIGEN_WIZBASE == m_nIDD );
  257. SetModified();
  258. }
  259. void CWiz97WirelessPolGenPage::OnChangedDescription()
  260. {
  261. ASSERT( IDD_WIFIGEN_WIZBASE == m_nIDD );
  262. SetModified();
  263. }
  264. BOOL CWiz97WirelessPolGenPage::OnSetActive()
  265. {
  266. if (IDD_WIFIGEN_WIZBASE != m_nIDD)
  267. {
  268. // show the wait cursor in case there is a huge description being accessed
  269. CWaitCursor waitCursor;
  270. // initialize our name/description controls with the correct name/description
  271. GetDlgItem(IDC_NEW_POLICY_NAME)->SetWindowText (m_pPolicy->pszWirelessName);
  272. GetDlgItem(IDC_NEW_POLICY_DESCRIPTION)->SetWindowText (m_pPolicy->pszDescription);
  273. // set the informative text correctly
  274. if (m_nInformativeText != 0)
  275. {
  276. // NOTE: currently the IDC_INFORMATIVETEXT control is disabled and
  277. // readonly. Need to change the resource if this functionality is to
  278. // be used.
  279. ASSERT (0);
  280. CString strInformativeText;
  281. strInformativeText.LoadString (m_nInformativeText);
  282. GetDlgItem(IDC_INFORMATIVETEXT)->SetWindowText (strInformativeText);
  283. }
  284. }
  285. return CWiz97BasePage::OnSetActive();
  286. }
  287. LRESULT CWiz97WirelessPolGenPage::OnWizardBack()
  288. {
  289. ASSERT( IDD_WIFIGEN_WIZBASE != m_nIDD );
  290. // skip going to the prev page if they selected 'cancel' on a data error dialog
  291. return CWiz97BasePage::OnWizardBack();
  292. }
  293. LRESULT CWiz97WirelessPolGenPage::OnWizardNext()
  294. {
  295. ASSERT( IDD_WIFIGEN_WIZBASE != m_nIDD );
  296. // TODO: enable this when we are sure update stuff is working
  297. // refresh the display
  298. // GetResultObject()->m_pComponentDataImpl->GetConsole()->UpdateAllViews (0, 0,0);
  299. // skip going to the next page if they selected 'cancel' on a data error dialog
  300. return SaveControlData() ? CWiz97BasePage::OnWizardNext() : -1;
  301. }
  302. BOOL CWiz97WirelessPolGenPage::OnApply()
  303. {
  304. ASSERT( IDD_WIFIGEN_WIZBASE == m_nIDD );
  305. // pull our data out of the controls and into the object
  306. CString strName;
  307. CString strDescription;
  308. if (!UpdateData (TRUE))
  309. // Data was not valid, return for user to correct it.
  310. return CancelApply();
  311. m_edName.GetWindowText (strName);
  312. m_edDescription.GetWindowText (strDescription);
  313. // verify that the name is not empty
  314. CString strNameNoBlank = strName;
  315. strNameNoBlank.TrimLeft();
  316. if (strNameNoBlank.GetLength() == 0)
  317. {
  318. AfxMessageBox (IDS_WARNNONAME, MB_ICONSTOP);
  319. return CancelApply();
  320. }
  321. SaveControlData();
  322. return CWiz97BasePage::OnApply();
  323. }
  324. BOOL CWiz97WirelessPolGenPage::SaveControlData()
  325. {
  326. ASSERT( IDD_WIFIGEN_WIZBASE != m_nIDD );
  327. BOOL bSaved = TRUE;
  328. // set the wait cursor
  329. CWaitCursor waitCursor;
  330. // set the new name and description
  331. CString strName, strDesc;
  332. GetDlgItem(IDC_NEW_POLICY_NAME)->GetWindowText (strName);
  333. GetDlgItem(IDC_NEW_POLICY_DESCRIPTION)->GetWindowText (strDesc);
  334. // verify that the name is not empty
  335. CString strNameNoBlank = strName;
  336. strNameNoBlank.TrimLeft();
  337. if (strNameNoBlank.GetLength() == 0)
  338. {
  339. AfxMessageBox (IDS_WARNNONAME, MB_ICONSTOP);
  340. return FALSE;
  341. }
  342. if (m_pPolicy->pszWirelessName)
  343. FreePolStr(m_pPolicy->pszWirelessName);
  344. m_pPolicy->pszWirelessName = AllocPolStr(strName);
  345. if (m_pPolicy->pszDescription)
  346. FreePolStr(m_pPolicy->pszDescription);
  347. m_pPolicy->pszDescription = AllocPolStr(strDesc);
  348. return bSaved;
  349. }