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.

396 lines
11 KiB

  1. /****************************************************************************
  2. *
  3. * ICWESTSN.cpp
  4. *
  5. * Microsoft Confidential
  6. * Copyright (c) Microsoft Corporation 1992-1997
  7. * All rights reserved
  8. *
  9. * This module provides the implementation of the methods for
  10. * the CICWExtension class.
  11. *
  12. * 4/24/97 jmazner Created
  13. *
  14. ***************************************************************************/
  15. #include "wizard.h"
  16. #include "icwextsn.h"
  17. #include "icwaprtc.h"
  18. #include "imnext.h"
  19. // in propmgr.cpp
  20. extern BOOL DialogIDAlreadyInUse( UINT uDlgID );
  21. extern BOOL SetDialogIDInUse( UINT uDlgID, BOOL fInUse );
  22. /*** Class definition, for reference only ***
  23. (actual definition is in icwextsn.h)
  24. class CICWExtension : public IICWExtension
  25. {
  26. public:
  27. virtual BOOL STDMETHODCALLTYPE AddExternalPage(HPROPSHEETPAGE hPage, UINT uDlgID);
  28. virtual BOOL STDMETHODCALLTYPE RemoveExternalPage(HPROPSHEETPAGE hPage, UINT uDlgID);
  29. virtual BOOL STDMETHODCALLTYPE ExternalCancel(CANCELTYPE type);
  30. virtual BOOL STDMETHODCALLTYPE SetFirstLastPage(UINT uFirstPageDlgID, UINT uLastPageDlgID);
  31. virtual HRESULT STDMETHODCALLTYPE QueryInterface( REFIID theGUID, void** retPtr );
  32. virtual ULONG STDMETHODCALLTYPE AddRef( void );
  33. virtual ULONG STDMETHODCALLTYPE Release( void );
  34. HWND m_hWizardHWND;
  35. private:
  36. LONG m_lRefCount;
  37. };
  38. ****/
  39. //+----------------------------------------------------------------------------
  40. //
  41. // Function CICWExtension::AddExternalPage
  42. //
  43. // Synopsis Adds a page created via CreatePropertySheetPage to the main
  44. // property sheet/wizard.
  45. //
  46. //
  47. // Arguments hPage -- page handle returned from CreatePropertySheetPage
  48. // uDlgID -- the dialog ID of the page to be added, as defined
  49. // the resource file of the page's owner.
  50. //
  51. //
  52. // Returns FALSE is the dlgID is already in use in the Wizard
  53. // TRUE otherwise
  54. //
  55. // Notes: PropSheet_AddPage does not return a usefull error code. Thus
  56. // the assumption here is that every AddPage will succeed. But, even
  57. // though it is not enforced by PropSheet_AddPage, every page in the
  58. // PropSheet must have a unique dialog ID. Thus, if the uDlgID passed
  59. // in has previously been added to the PropSheet, we'll return FALSE.
  60. //
  61. // History 4/23/97 jmazner created
  62. //
  63. //-----------------------------------------------------------------------------
  64. BOOL CICWExtension::AddExternalPage( HPROPSHEETPAGE hPage, UINT uDlgID )
  65. {
  66. LRESULT lResult= 0;
  67. if ( (uDlgID < EXTERNAL_DIALOGID_MINIMUM) || (EXTERNAL_DIALOGID_MAXIMUM < uDlgID) )
  68. {
  69. DEBUGMSG("SetFirstLastPage: uDlgID %d is out of range!", uDlgID);
  70. return( FALSE );
  71. }
  72. if( !DialogIDAlreadyInUse(uDlgID) )
  73. {
  74. SetDialogIDInUse( uDlgID, TRUE );
  75. lResult = PropSheet_AddPage(m_hWizardHWND, hPage);
  76. DEBUGMSG("propmgr: PS_AddPage DlgID %d", uDlgID);
  77. return(TRUE);
  78. }
  79. else
  80. {
  81. DEBUGMSG("AddExternalPage DlgID %d is already in use, rejecting this page!", uDlgID);
  82. return(FALSE);
  83. }
  84. }
  85. //+----------------------------------------------------------------------------
  86. //
  87. // Function CICWExtension::RemoveExternalPage
  88. //
  89. // Synopsis Removes a page added via ::AddExternalPage to the main
  90. // property sheet/wizard.
  91. //
  92. //
  93. // Arguments hPage -- page handle returned from CreatePropertySheetPage
  94. // uDlgID -- the dialog ID of the page to be removed, as defined
  95. // the resource file of the page's owner.
  96. //
  97. //
  98. // Returns FALSE is the dlgID is not already in use in the Wizard
  99. // TRUE otherwise
  100. //
  101. // Notes: PropSheet_RemovePage does not return a usefull error code. Thus
  102. // the assumption here is that every RemovePage will succeed if that
  103. // dialog id is currently in the property sheet
  104. //
  105. // History 4/23/97 jmazner created
  106. //
  107. //-----------------------------------------------------------------------------
  108. BOOL CICWExtension::RemoveExternalPage( HPROPSHEETPAGE hPage, UINT uDlgID )
  109. {
  110. if ( (uDlgID < EXTERNAL_DIALOGID_MINIMUM) || (EXTERNAL_DIALOGID_MAXIMUM < uDlgID) )
  111. {
  112. DEBUGMSG("SetFirstLastPage: uDlgID %d is out of range!", uDlgID);
  113. return( FALSE );
  114. }
  115. if( DialogIDAlreadyInUse(uDlgID) )
  116. {
  117. SetDialogIDInUse( uDlgID, FALSE );
  118. PropSheet_RemovePage(m_hWizardHWND, NULL, hPage);
  119. DEBUGMSG("propmgr: PS_RemovePage DlgID %d", uDlgID);
  120. return(TRUE);
  121. }
  122. else
  123. {
  124. DEBUGMSG("RemoveExternalPage: DlgID %d was not marked as in use!", uDlgID);
  125. return(FALSE);
  126. }
  127. }
  128. //+----------------------------------------------------------------------------
  129. //
  130. // Function CICWExtension::ExternalCancel
  131. //
  132. // Synopsis Notifies the wizard that the user has cancelled while in the
  133. // apprentice pages
  134. //
  135. //
  136. // Arguments uCancelType -- tells the wizard whether it should immediately
  137. // quit out, or whether it should show the confirmation
  138. // dialog (as though the user had hit Cancel within the
  139. // wizard itself.)
  140. //
  141. //
  142. // Returns TRUE if we're about to exit the wizard
  143. // FALSE if not.
  144. //
  145. //
  146. // History 4/23/97 jmazner created
  147. //
  148. //-----------------------------------------------------------------------------
  149. BOOL CICWExtension::ExternalCancel( CANCELTYPE uCancelType )
  150. {
  151. DEBUGMSG("propmgr.cpp: received ExternalCancel callback");
  152. switch( uCancelType )
  153. {
  154. case CANCEL_PROMPT:
  155. gfUserCancelled = (MsgBox(m_hWizardHWND,IDS_QUERYCANCEL,
  156. MB_ICONQUESTION,MB_YESNO |
  157. MB_DEFBUTTON2) == IDYES);
  158. if( gfUserCancelled )
  159. {
  160. PropSheet_PressButton( m_hWizardHWND, PSBTN_CANCEL );
  161. gfQuitWizard = TRUE;
  162. return( TRUE );
  163. }
  164. else
  165. {
  166. return( FALSE );
  167. }
  168. break;
  169. case CANCEL_SILENT:
  170. PropSheet_PressButton( m_hWizardHWND, PSBTN_CANCEL );
  171. gfQuitWizard = TRUE;
  172. return( TRUE );
  173. break;
  174. case CANCEL_REBOOT:
  175. PropSheet_PressButton( m_hWizardHWND, PSBTN_CANCEL );
  176. gfQuitWizard = TRUE;
  177. gpWizardState->fNeedReboot = TRUE;
  178. return( TRUE );
  179. break;
  180. default:
  181. DEBUGMSG("ExternalCancel got an unkown CancelType!");
  182. return( FALSE );
  183. }
  184. }
  185. //+----------------------------------------------------------------------------
  186. //
  187. // Function CICWExtension::SetFirstLastPage
  188. //
  189. // Synopsis Lets the apprentice notify the wizard of the dialog IDs of the
  190. // first and last pages in the apprentice
  191. //
  192. //
  193. // Arguments uFirstPageDlgID -- DlgID of first page in apprentice.
  194. // uLastPageDlgID -- DlgID of last page in apprentice
  195. //
  196. //
  197. // Returns FALSE if the parameters passed in are out of range
  198. // TRUE if the update succeeded.
  199. //
  200. // Notes: If either variable is set to 0, the function will not update
  201. // that information, i.e. a value of 0 means "ignore me". If both
  202. // variables are 0, the function immediately returns FALSE.
  203. //
  204. // History 4/23/97 jmazner created
  205. //
  206. //-----------------------------------------------------------------------------
  207. BOOL CICWExtension::SetFirstLastPage(UINT uFirstPageDlgID, UINT uLastPageDlgID)
  208. {
  209. // validation code galore!
  210. if( (0 == uFirstPageDlgID) && (0 == uLastPageDlgID) )
  211. {
  212. DEBUGMSG("SetFirstLastPage: both IDs are 0!");
  213. return( FALSE );
  214. }
  215. if( (0 != uFirstPageDlgID) )
  216. {
  217. if ( (uFirstPageDlgID < EXTERNAL_DIALOGID_MINIMUM) || (EXTERNAL_DIALOGID_MAXIMUM < uFirstPageDlgID) )
  218. {
  219. DEBUGMSG("SetFirstLastPage: uFirstPageDlgID %d is out of range!", uFirstPageDlgID);
  220. return( FALSE );
  221. }
  222. if( !DialogIDAlreadyInUse(uFirstPageDlgID) )
  223. {
  224. DEBUGMSG("SetFirstLastPage: uFirstPageDlgID %d not marked as in use!", uFirstPageDlgID);
  225. return( FALSE );
  226. }
  227. }
  228. if( (0 != uLastPageDlgID) )
  229. {
  230. if ( (uLastPageDlgID < EXTERNAL_DIALOGID_MINIMUM) || (EXTERNAL_DIALOGID_MAXIMUM < uLastPageDlgID) )
  231. {
  232. DEBUGMSG("SetFirstLastPage: uLastPageDlgID %d is out of range!", uFirstPageDlgID);
  233. return( FALSE );
  234. }
  235. if( !DialogIDAlreadyInUse(uLastPageDlgID) )
  236. {
  237. DEBUGMSG("SetFirstLastPage: uLastPageDlgID %d not marked as in use!", uFirstPageDlgID);
  238. return( FALSE );
  239. }
  240. }
  241. if( 0 != uFirstPageDlgID )
  242. g_uAcctMgrUIFirst = uFirstPageDlgID;
  243. if( 0 != uLastPageDlgID )
  244. g_uAcctMgrUILast = uLastPageDlgID;
  245. DEBUGMSG("SetFirstLastPage: updating mail, first = %d, last = %d",
  246. uFirstPageDlgID, uLastPageDlgID);
  247. return TRUE;
  248. }
  249. //+----------------------------------------------------------------------------
  250. //
  251. // Function CICWExtension::QueryInterface
  252. //
  253. // Synopsis This is the standard QI, with support for
  254. // IID_Unknown, IICW_Extension and IID_ICWApprentice
  255. // (Taken from Inside COM, chapter 7)
  256. //
  257. // History 4/23/97 jmazner created
  258. //
  259. //-----------------------------------------------------------------------------
  260. HRESULT CICWExtension::QueryInterface( REFIID riid, void** ppv )
  261. {
  262. if (ppv == NULL)
  263. return(E_INVALIDARG);
  264. *ppv = NULL;
  265. // IID_IICWApprentice
  266. if (IID_IICWApprentice == riid)
  267. *ppv = (void *)(IICWApprentice *)this;
  268. // IID_IICWApprenticeEx
  269. else if (IID_IICWApprenticeEx == riid)
  270. *ppv = (void *)(IICWApprenticeEx *)this;
  271. // IID_IICWExtension
  272. else if (IID_IICWExtension == riid)
  273. *ppv = (void *)(IICWExtension *)this;
  274. // IID_IUnknown
  275. else if (IID_IUnknown == riid)
  276. *ppv = (void *)this;
  277. else
  278. return(E_NOINTERFACE);
  279. ((LPUNKNOWN)*ppv)->AddRef();
  280. return(S_OK);
  281. }
  282. //+----------------------------------------------------------------------------
  283. //
  284. // Function CICWExtension::AddRef
  285. //
  286. // Synopsis This is the standard AddRef
  287. //
  288. // History 4/23/97 jmazner created
  289. //
  290. //-----------------------------------------------------------------------------
  291. ULONG CICWExtension::AddRef( void )
  292. {
  293. DEBUGMSG("CICWExtension::AddRef called %d", m_lRefCount + 1);
  294. return InterlockedIncrement(&m_lRefCount) ;
  295. }
  296. //+----------------------------------------------------------------------------
  297. //
  298. // Function CICWExtension::Release
  299. //
  300. // Synopsis This is the standard Release
  301. //
  302. // History 4/23/97 jmazner created
  303. //
  304. //-----------------------------------------------------------------------------
  305. ULONG CICWExtension::Release( void )
  306. {
  307. ASSERT( m_lRefCount > 0 );
  308. InterlockedDecrement(&m_lRefCount);
  309. DEBUGMSG("CICWExtension::Release called %d", m_lRefCount);
  310. if( 0 == m_lRefCount )
  311. {
  312. delete( this );
  313. return( 0 );
  314. }
  315. else
  316. {
  317. return( m_lRefCount );
  318. }
  319. }
  320. //+----------------------------------------------------------------------------
  321. //
  322. // Function CICWExtension::CICWExtension
  323. //
  324. // Synopsis The constructor. Initializes member variables to NULL.
  325. //
  326. // History 4/23/97 jmazner created
  327. //
  328. //-----------------------------------------------------------------------------
  329. CICWExtension::CICWExtension( void )
  330. {
  331. DEBUGMSG("CICWExtension constructor called");
  332. m_lRefCount = 0;
  333. m_hWizardHWND = NULL;
  334. }
  335. //+----------------------------------------------------------------------------
  336. //
  337. // Function CICWExtension::CICWExtension
  338. //
  339. // Synopsis The constructor. Since there was no fancy initialization,
  340. // there's nothing to do here.
  341. //
  342. // History 4/23/97 jmazner created
  343. //
  344. //-----------------------------------------------------------------------------
  345. CICWExtension::~CICWExtension( void )
  346. {
  347. DEBUGMSG("CICWExtension destructor called with ref count of %d", m_lRefCount);
  348. }