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.

570 lines
20 KiB

  1. /****************************************************************************
  2. *
  3. * ICWAPRTC.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 CICWApprentice class.
  11. *
  12. * 5/13/98 donaldm adapted from INETCFG
  13. *
  14. ***************************************************************************/
  15. #include "pre.h"
  16. #include <vfw.h>
  17. #include "initguid.h"
  18. #include "icwaprtc.h"
  19. #include "icwconn.h"
  20. #include "webvwids.h"
  21. #define PROGRESSANIME_XPOS 10 // Default offset from the left side
  22. #define PROGRESSANIME_YPOS 40 // Default height plus border at bottom
  23. #define PROGRESSANIME_YBORDER 10 // default border at bottom
  24. UINT g_uExternUIPrev, g_uExternUINext;
  25. //defined/allocated in icwconn.cpp
  26. extern PAGEINFO PageInfo[NUM_WIZARD_PAGES];
  27. // In GENDLG.CPP
  28. extern INT_PTR CALLBACK GenDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  29. extern BOOL InitWizardState(WIZARDSTATE * pWizardState);
  30. extern BOOL CleanupWizardState(WIZARDSTATE * pWizardState);
  31. extern DWORD WINAPI GetICWCONNVersion(void);
  32. //+----------------------------------------------------------------------------
  33. //
  34. // Function CICWApprentice::Initialize
  35. //
  36. // Synopsis Called by the main Wizard to initialize class members and
  37. // globals
  38. //
  39. // Arguments [in] pExt -- pointer the Wizard's IICW50Extension interface, which
  40. // encapsulates the functionality needed to add wizard
  41. // pages.
  42. //
  43. // Returns E_OUTOFMEMORY -- unable to allocate global vars.
  44. // S_OK indicates success
  45. //
  46. // History 4/23/97 jmazner created
  47. //
  48. //-----------------------------------------------------------------------------
  49. HRESULT CICWApprentice::Initialize(IICW50Extension *pExt)
  50. {
  51. TraceMsg(TF_APPRENTICE, "CICWApprentice::Initialize");
  52. ASSERT( pExt );
  53. m_pIICW50Ext = pExt;
  54. m_pIICW50Ext->AddRef();
  55. if( !gpWizardState)
  56. {
  57. gpWizardState = new WIZARDSTATE;
  58. }
  59. if( !gpWizardState )
  60. {
  61. TraceMsg(TF_APPRENTICE, "CICWApprentice::Initialize couldn't initialize the globals!");
  62. return E_OUTOFMEMORY;
  63. }
  64. // initialize the app state structure
  65. if (!InitWizardState(gpWizardState))
  66. return E_FAIL;
  67. // Since we now have the ISPData object (created during InitWizardState), this is a good time to
  68. // initialize the ISPData object, since we cannot be sure when it will be
  69. // used for data validation
  70. gpWizardState->hWndWizardApp = pExt->GetWizardHwnd();
  71. gpWizardState->pISPData->Init(gpWizardState->hWndWizardApp);
  72. return S_OK;
  73. }
  74. //+----------------------------------------------------------------------------
  75. //
  76. // Function CICWApprentice::AddWizardPages
  77. //
  78. // Synopsis Creates a series of Property Sheet pages, and adds them to the
  79. // main wizard via the m_pIICW50Ext interface pointer. Note that
  80. // we add every page in the global PageInfo struct, even though the
  81. // Apprentice may not use some pages (eg, CONNECTEDOK)
  82. //
  83. // Arguments [] dwFlags -- currently unused
  84. //
  85. // Returns S_OK indicates success
  86. // E_FAIL indicates failure. If for any reason all pages can not be
  87. // added, we will attempt to remove any pages that had been
  88. // added prior to the failure.
  89. //
  90. // History 4/23/97 jmazner created
  91. //
  92. //-----------------------------------------------------------------------------
  93. HRESULT CICWApprentice::AddWizardPages(DWORD dwFlags)
  94. {
  95. HPROPSHEETPAGE hWizPage[NUM_WIZARD_PAGES]; // array to hold handles to pages
  96. PROPSHEETPAGE psPage; // struct used to create prop sheet pages
  97. UINT nPageIndex;
  98. HRESULT hr = S_OK;
  99. unsigned long ulNumItems = 0;
  100. TraceMsg(TF_APPRENTICE, "CICWApprentice::AddWizardPages");
  101. ZeroMemory(&hWizPage,sizeof(hWizPage)); // hWizPage is an array
  102. ZeroMemory(&psPage,sizeof(PROPSHEETPAGE));
  103. // fill out common data property sheet page struct
  104. psPage.dwSize = sizeof(psPage);
  105. psPage.hInstance = ghInstanceResDll;
  106. psPage.pfnDlgProc = GenDlgProc;
  107. // create a property sheet page for each page in the wizard
  108. for (nPageIndex = 0; nPageIndex < NUM_WIZARD_PAGES; nPageIndex++)
  109. {
  110. UINT uDlgID;
  111. psPage.dwFlags = PSP_DEFAULT | PSP_USETITLE;
  112. psPage.pszTitle = gpWizardState->cmnStateData.szWizTitle;
  113. uDlgID = PageInfo[nPageIndex].uDlgID;
  114. psPage.pszTemplate = MAKEINTRESOURCE(uDlgID);
  115. // set a pointer to the PAGEINFO struct as the private data for this
  116. // page
  117. psPage.lParam = (LPARAM) &PageInfo[nPageIndex];
  118. if (PageInfo[nPageIndex].nIdTitle)
  119. {
  120. psPage.dwFlags |= PSP_USEHEADERTITLE | (PageInfo[nPageIndex].nIdSubTitle ? PSP_USEHEADERSUBTITLE : 0);
  121. psPage.pszHeaderTitle = MAKEINTRESOURCE(PageInfo[nPageIndex].nIdTitle);
  122. psPage.pszHeaderSubTitle = MAKEINTRESOURCE(PageInfo[nPageIndex].nIdSubTitle);
  123. }
  124. else
  125. {
  126. psPage.dwFlags |= PSP_HIDEHEADER;
  127. }
  128. hWizPage[nPageIndex] = CreatePropertySheetPage(&psPage);
  129. if (!hWizPage[nPageIndex])
  130. {
  131. ASSERT(0);
  132. MsgBox(NULL,IDS_ERR_OUTOFMEMORY,MB_ICONEXCLAMATION,MB_OK);
  133. hr = E_FAIL;
  134. // creating page failed, free any pages already created and bail
  135. goto AddWizardPagesErrorExit;
  136. }
  137. hr = m_pIICW50Ext->AddExternalPage( hWizPage[nPageIndex], uDlgID);
  138. if( FAILED(hr) )
  139. {
  140. // free any pages already created and bail
  141. goto AddWizardPagesErrorExit;
  142. }
  143. // Load the accelerator table for this page if necessary
  144. if (PageInfo[nPageIndex].idAccel)
  145. PageInfo[nPageIndex].hAccel = LoadAccelerators(ghInstanceResDll,
  146. MAKEINTRESOURCE(PageInfo[nPageIndex].idAccel));
  147. }
  148. // of course, we have no idea what the last page will really be.
  149. // so make a guess here, and update it later when we know for sure.
  150. ProcessCustomFlags(dwFlags);
  151. return S_OK;
  152. AddWizardPagesErrorExit:
  153. UINT nFreeIndex;
  154. for (nFreeIndex=0;nFreeIndex<nPageIndex;nFreeIndex++)
  155. {
  156. UINT uDlgID;
  157. uDlgID = PageInfo[nPageIndex].uDlgID;
  158. DestroyPropertySheetPage(hWizPage[nFreeIndex]);
  159. m_pIICW50Ext->RemoveExternalPage( hWizPage[nFreeIndex], uDlgID );
  160. }
  161. return hr;
  162. }
  163. //+----------------------------------------------------------------------------
  164. //
  165. // Function CICWApprentice::Save
  166. //
  167. // Synopsis Called by the Wizard to commit changes
  168. //
  169. // Arguments [in] hwnd -- hwnd of Wizard window, used to display modal msgs
  170. // [out] pdwError -- implementation specfic error code. Not used.
  171. //
  172. // Returns S_OK indicates success
  173. // Otherwise, returns E_FAIL.
  174. //
  175. //
  176. // History 4/23/97 jmazner created
  177. //
  178. //-----------------------------------------------------------------------------
  179. HRESULT CICWApprentice::Save(HWND hwnd, DWORD *pdwError)
  180. {
  181. TraceMsg(TF_APPRENTICE, "CICWApprentice::Save");
  182. return S_OK;
  183. }
  184. //+----------------------------------------------------------------------------
  185. //
  186. // Function CICWApprentice::SetPrevNextPage
  187. //
  188. // Synopsis Lets the apprentice notify the wizard of the dialog IDs of the
  189. // first and last pages in the apprentice
  190. //
  191. //
  192. // Arguments uPrevPageDlgID -- DlgID of wizard page to back up to
  193. // uNextPageDlgID -- DlgID of wizard page to go forwards into
  194. //
  195. //
  196. // Returns FALSE if both parameters are 0
  197. // TRUE if the update succeeded.
  198. //
  199. // Notes: If either variable is set to 0, the function will not update
  200. // that information, i.e. a value of 0 means "ignore me". If both
  201. // variables are 0, the function immediately returns FALSE.
  202. //
  203. // History 4/23/97 jmazner created
  204. //
  205. //-----------------------------------------------------------------------------
  206. HRESULT CICWApprentice::SetPrevNextPage(UINT uPrevPageDlgID, UINT uNextPageDlgID)
  207. {
  208. TraceMsg(TF_APPRENTICE, "CICWApprentice::SetPrevNextPage: updating prev = %d, next = %d",
  209. uPrevPageDlgID, uNextPageDlgID);
  210. if( (0 == uPrevPageDlgID) && (0 == uNextPageDlgID) )
  211. {
  212. TraceMsg(TF_APPRENTICE, "SetFirstLastPage: both IDs are 0!");
  213. return( E_INVALIDARG );
  214. }
  215. if( 0 != uPrevPageDlgID )
  216. g_uExternUIPrev = uPrevPageDlgID;
  217. if( 0 != uNextPageDlgID )
  218. g_uExternUINext = uNextPageDlgID;
  219. return S_OK;
  220. }
  221. //+----------------------------------------------------------------------------
  222. //
  223. // Function CICWApprentice::ProcessCustomFlags
  224. //
  225. // Synopsis Lets the apprentice know that there is a special modification
  226. // to this set of apprentice pages after it is loaded
  227. //
  228. // Arguments dwFlags -- info needed to pass to the external pages
  229. //
  230. //
  231. // Returns FALSE if both parameters are 0
  232. // TRUE if the update succeeded.
  233. //
  234. // History 5/23/97 vyung created
  235. //
  236. //-----------------------------------------------------------------------------
  237. HRESULT CICWApprentice::ProcessCustomFlags(DWORD dwFlags)
  238. {
  239. if( m_pIICW50Ext )
  240. {
  241. if(dwFlags & ICW_CFGFLAG_IEAKMODE)
  242. {
  243. CISPCSV *pcISPCSV = new CISPCSV;
  244. if (pcISPCSV == NULL)
  245. {
  246. return E_FAIL;
  247. }
  248. // Set the Current selected ISP to this one.
  249. gpWizardState->lpSelectedISPInfo = pcISPCSV;
  250. // Initialize the new Selected ISP info object
  251. gpWizardState->lpSelectedISPInfo->set_szISPName(gpWizardState->cmnStateData.ispInfo.szISPName);
  252. gpWizardState->lpSelectedISPInfo->set_szISPFilePath(gpWizardState->cmnStateData.ispInfo.szISPFile);
  253. gpWizardState->lpSelectedISPInfo->set_szBillingFormPath(gpWizardState->cmnStateData.ispInfo.szBillHtm);
  254. gpWizardState->lpSelectedISPInfo->set_szPayCSVPath(gpWizardState->cmnStateData.ispInfo.szPayCsv);
  255. gpWizardState->lpSelectedISPInfo->set_bCNS(FALSE);
  256. gpWizardState->lpSelectedISPInfo->set_bIsSpecial(FALSE);
  257. gpWizardState->lpSelectedISPInfo->set_dwCFGFlag(dwFlags);
  258. gpWizardState->lpSelectedISPInfo->set_dwRequiredUserInputFlags(gpWizardState->cmnStateData.ispInfo.dwValidationFlags);
  259. // What page do we display first?
  260. if (dwFlags & ICW_CFGFLAG_USERINFO)
  261. m_pIICW50Ext->SetFirstLastPage( IDD_PAGE_USERINFO, IDD_PAGE_USERINFO );
  262. else if (dwFlags & ICW_CFGFLAG_BILL)
  263. m_pIICW50Ext->SetFirstLastPage( IDD_PAGE_BILLINGOPT, IDD_PAGE_BILLINGOPT );
  264. else if (dwFlags & ICW_CFGFLAG_PAYMENT)
  265. m_pIICW50Ext->SetFirstLastPage( IDD_PAGE_PAYMENT, IDD_PAGE_PAYMENT );
  266. else
  267. m_pIICW50Ext->SetFirstLastPage( IDD_PAGE_ISPDIAL, IDD_PAGE_ISPDIAL );
  268. }
  269. else
  270. {
  271. if (dwFlags & ICW_CFGFLAG_AUTOCONFIG)
  272. {
  273. m_pIICW50Ext->SetFirstLastPage( IDD_PAGE_ACFG_ISP, IDD_PAGE_ACFG_ISP );
  274. }
  275. else
  276. {
  277. m_pIICW50Ext->SetFirstLastPage( IDD_PAGE_ISPSELECT, IDD_PAGE_ISPSELECT );
  278. }
  279. }
  280. }
  281. return S_OK;
  282. }
  283. //+----------------------------------------------------------------------------
  284. //
  285. // Function CICWApprentice::SetStateData
  286. //
  287. // Synopsis Lets the apprentice set wizard state data
  288. //
  289. // Arguments LPCMNSTATEDATA Pointer to state data to be set
  290. //
  291. // Returns
  292. // History 5/22/98 donaldm created
  293. //
  294. //-----------------------------------------------------------------------------
  295. HRESULT CICWApprentice::SetStateDataFromExeToDll(LPCMNSTATEDATA lpData)
  296. {
  297. TCHAR szTemp[MAX_RES_LEN];
  298. HWND hWndAnimeParent = gpWizardState->hWndWizardApp;
  299. int xPosProgress = PROGRESSANIME_XPOS;
  300. int yPosProgress = -1;
  301. RECT rect;
  302. LPTSTR lpszAnimateFile = MAKEINTRESOURCE(IDA_PROGRESSANIME);
  303. ASSERT(gpWizardState);
  304. memcpy(&gpWizardState->cmnStateData, lpData, sizeof(CMNSTATEDATA));
  305. // Set values in the ISP Data object that are part of the cmnstatedata, or are not
  306. // specific to user data entry
  307. wsprintf (szTemp, TEXT("%ld"), gpWizardState->cmnStateData.dwCountryCode);
  308. gpWizardState->pISPData->PutDataElement(ISPDATA_COUNTRYCODE, szTemp, ISPDATA_Validate_None);
  309. gpWizardState->pISPData->PutDataElement(ISPDATA_AREACODE, gpWizardState->cmnStateData.szAreaCode, ISPDATA_Validate_None);
  310. wsprintf (szTemp, TEXT("%ld"), GetICWCONNVersion());
  311. gpWizardState->pISPData->PutDataElement(ISPDATA_ICW_VERSION, szTemp, ISPDATA_Validate_None);
  312. // If we are in modeless operation, (aka OEM custom) then we need
  313. // to set the HTML background color for some pages
  314. if(gpWizardState->cmnStateData.bOEMCustom)
  315. {
  316. gpWizardState->pICWWebView->SetHTMLColors(gpWizardState->cmnStateData.szclrHTMLText,
  317. gpWizardState->cmnStateData.szHTMLBackgroundColor);
  318. if (!gpWizardState->cmnStateData.bHideProgressAnime)
  319. {
  320. // Set the progress animation parent to the App window
  321. hWndAnimeParent = gpWizardState->cmnStateData.hWndApp;
  322. // see if the oem has specified an x Position for the animation
  323. if (-1 != gpWizardState->cmnStateData.xPosBusy)
  324. xPosProgress = gpWizardState->cmnStateData.xPosBusy;
  325. // see if the oem has specified an differen animation file
  326. if ('\0' != gpWizardState->cmnStateData.szBusyAnimationFile[0])
  327. {
  328. PAVIFILE pFile;
  329. AVIFILEINFO fi;
  330. lpszAnimateFile = gpWizardState->cmnStateData.szBusyAnimationFile;
  331. // Compute the y-Position based on the height of the AVI file
  332. // and the size of the parent window
  333. AVIFileInit();
  334. AVIFileOpen(&pFile,
  335. gpWizardState->cmnStateData.szBusyAnimationFile,
  336. OF_READ,
  337. NULL);
  338. AVIFileInfo(pFile, &fi, sizeof(fi));
  339. AVIFileRelease(pFile);
  340. AVIFileExit();
  341. GetClientRect(hWndAnimeParent, &rect);
  342. yPosProgress = rect.bottom - fi.dwHeight - PROGRESSANIME_YBORDER;
  343. }
  344. }
  345. }
  346. // Setup the progress animation
  347. if (!gpWizardState->hwndProgressAnime && !gpWizardState->cmnStateData.bHideProgressAnime)
  348. {
  349. // calculate the y-position of the progress animation
  350. if (-1 == yPosProgress)
  351. {
  352. GetClientRect(hWndAnimeParent, &rect);
  353. yPosProgress = rect.bottom - PROGRESSANIME_YPOS;
  354. }
  355. //Create the animation / progress control
  356. gpWizardState->hwndProgressAnime = CreateWindow(ANIMATE_CLASS,
  357. TEXT(""),
  358. ACS_TRANSPARENT | WS_CHILD,
  359. xPosProgress,
  360. yPosProgress,
  361. 0, 0,
  362. hWndAnimeParent,
  363. NULL,
  364. ghInstanceResDll,
  365. NULL);
  366. //Set the avi
  367. Animate_Open (gpWizardState->hwndProgressAnime, lpszAnimateFile);
  368. }
  369. return (S_OK);
  370. }
  371. //converse of the previous function
  372. HRESULT CICWApprentice::SetStateDataFromDllToExe(LPCMNSTATEDATA lpData)
  373. {
  374. ASSERT(gpWizardState);
  375. memcpy(lpData, &gpWizardState->cmnStateData, sizeof(CMNSTATEDATA));
  376. return (S_OK);
  377. }
  378. //+----------------------------------------------------------------------------
  379. //
  380. // Function CICWApprentice::QueryInterface
  381. //
  382. // Synopsis This is the standard QI, with support for
  383. // IID_Unknown, IICW_Extension and IID_ICWApprentice
  384. // (stolen from Inside COM, chapter 7)
  385. //
  386. // History 4/23/97 jmazner created
  387. //
  388. //-----------------------------------------------------------------------------
  389. HRESULT CICWApprentice::QueryInterface( REFIID riid, void** ppv )
  390. {
  391. TraceMsg(TF_APPRENTICE, "CICWApprentice::QueryInterface");
  392. if (ppv == NULL)
  393. return(E_INVALIDARG);
  394. *ppv = NULL;
  395. // IID_IICWApprentice
  396. if (IID_IICW50Apprentice == riid)
  397. *ppv = (void *)(IICW50Apprentice *)this;
  398. // IID_IICW50Extension
  399. else if (IID_IICW50Extension == riid)
  400. *ppv = (void *)(IICW50Extension *)this;
  401. // IID_IUnknown
  402. else if (IID_IUnknown == riid)
  403. *ppv = (void *)this;
  404. else
  405. return(E_NOINTERFACE);
  406. ((LPUNKNOWN)*ppv)->AddRef();
  407. return(S_OK);
  408. }
  409. //+----------------------------------------------------------------------------
  410. //
  411. // Function CICWApprentice::AddRef
  412. //
  413. // Synopsis This is the standard AddRef
  414. //
  415. // History 4/23/97 jmazner created
  416. //
  417. //-----------------------------------------------------------------------------
  418. ULONG CICWApprentice::AddRef( void )
  419. {
  420. TraceMsg(TF_APPRENTICE, "CICWApprentice::AddRef %d", m_lRefCount + 1);
  421. return InterlockedIncrement(&m_lRefCount) ;
  422. }
  423. //+----------------------------------------------------------------------------
  424. //
  425. // Function CICWApprentice::Release
  426. //
  427. // Synopsis This is the standard Release
  428. //
  429. // History 4/23/97 jmazner created
  430. //
  431. //-----------------------------------------------------------------------------
  432. ULONG CICWApprentice::Release( void )
  433. {
  434. ASSERT( m_lRefCount > 0 );
  435. InterlockedDecrement(&m_lRefCount);
  436. TraceMsg(TF_APPRENTICE, "CICWApprentice::Release %d", m_lRefCount);
  437. if( 0 == m_lRefCount )
  438. {
  439. m_pIICW50Ext->Release();
  440. m_pIICW50Ext = NULL;
  441. delete( this );
  442. return( 0 );
  443. }
  444. else
  445. {
  446. return( m_lRefCount );
  447. }
  448. }
  449. //+----------------------------------------------------------------------------
  450. //
  451. // Function CICWApprentice::CICWApprentice
  452. //
  453. // Synopsis This is the constructor, nothing fancy
  454. //
  455. // History 4/23/97 jmazner created
  456. //
  457. //-----------------------------------------------------------------------------
  458. CICWApprentice::CICWApprentice( void )
  459. {
  460. TraceMsg(TF_APPRENTICE, "CICWApprentice constructor called");
  461. m_lRefCount = 0;
  462. m_pIICW50Ext = NULL;
  463. }
  464. //+----------------------------------------------------------------------------
  465. //
  466. // Function CICWApprentice::~CICWApprentice
  467. //
  468. // Synopsis This is the destructor. We want to clean up all the memory
  469. // we allocated in ::Initialize
  470. //
  471. // History 4/23/97 jmazner created
  472. //
  473. //-----------------------------------------------------------------------------
  474. CICWApprentice::~CICWApprentice( void )
  475. {
  476. TraceMsg(TF_APPRENTICE, "CICWApprentice destructor called with ref count of %d", m_lRefCount);
  477. if( m_pIICW50Ext )
  478. {
  479. m_pIICW50Ext->Release();
  480. m_pIICW50Ext = NULL;
  481. }
  482. if( gpWizardState)
  483. {
  484. CleanupWizardState(gpWizardState);
  485. delete gpWizardState;
  486. gpWizardState = NULL;
  487. }
  488. }