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.

505 lines
15 KiB

  1. /*****************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 2000
  4. *
  5. * TITLE: printwiz.cpp
  6. *
  7. * VERSION: 1.0, stolen from netplwiz (pubwiz.cpp)
  8. *
  9. * AUTHOR: RickTu
  10. *
  11. * DATE: 10/12/00
  12. *
  13. * DESCRIPTION: Implements IWizardExtension for printing wizard
  14. *
  15. *****************************************************************************/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. class CPrintPhotosWizard : public IPrintPhotosWizardSetInfo
  19. {
  20. public:
  21. CPrintPhotosWizard();
  22. ~CPrintPhotosWizard();
  23. // IUnknown
  24. STDMETHOD(QueryInterface)(REFIID riid, void **ppvObj);
  25. STDMETHOD_(ULONG,AddRef)(void);
  26. STDMETHOD_(ULONG,Release)(void);
  27. // IPrintPhotosWizardSetInfo
  28. STDMETHODIMP SetFileListDataObject( IDataObject * pdo );
  29. STDMETHODIMP SetFileListArray( LPITEMIDLIST *aidl, int cidl, int iSelectedItem);
  30. STDMETHODIMP RunWizard( VOID );
  31. private:
  32. LONG _cRef; // object lifetime count
  33. HPROPSHEETPAGE _aWizPages[MAX_WIZPAGES]; // page handles for this wizard (so we can navigate)
  34. CComPtr<IDataObject> _pdo; // dataobject which contains files to print
  35. LPITEMIDLIST* _aidl;
  36. int _cidl;
  37. int _iSelection;
  38. HRESULT _CreateWizardPages(void); // construct and load our wizard pages
  39. // Get a pointer to our wizard class from static members
  40. static CPrintPhotosWizard* s_GetPPW(HWND hwnd, UINT uMsg, LPARAM lParam);
  41. // DlgProc's for our wizard pages -- we forward through s_GetPPW
  42. CStartPage * _pStartPage;
  43. CPhotoSelectionPage * _pPhotoSelectionPage;
  44. CPrintOptionsPage * _pPrintOptionsPage;
  45. CSelectTemplatePage * _pSelectTemplatePage;
  46. CStatusPage * _pStatusPage;
  47. CEndPage * _pEndPage;
  48. static INT_PTR s_StartPageDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) \
  49. { \
  50. CPrintPhotosWizard *ppw = s_GetPPW(hwnd, uMsg, lParam); \
  51. if (ppw && ppw->_pStartPage) \
  52. { \
  53. return ppw->_pStartPage->DoHandleMessage(hwnd, uMsg, wParam, lParam); \
  54. } \
  55. return FALSE; \
  56. }
  57. static INT_PTR s_PictureSelectionDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) \
  58. { \
  59. CPrintPhotosWizard *ppw = s_GetPPW(hwnd, uMsg, lParam); \
  60. if (ppw && ppw->_pPhotoSelectionPage) \
  61. { \
  62. return ppw->_pPhotoSelectionPage->DoHandleMessage(hwnd, uMsg, wParam, lParam); \
  63. } \
  64. return FALSE; \
  65. }
  66. static INT_PTR s_PrintOptionsDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) \
  67. { \
  68. CPrintPhotosWizard *ppw = s_GetPPW(hwnd, uMsg, lParam); \
  69. if (ppw && ppw->_pPrintOptionsPage) \
  70. { \
  71. return ppw->_pPrintOptionsPage->DoHandleMessage(hwnd, uMsg, wParam, lParam); \
  72. } \
  73. return FALSE; \
  74. }
  75. static INT_PTR s_SelectTemplateDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  76. { \
  77. CPrintPhotosWizard *ppw = s_GetPPW(hwnd, uMsg, lParam); \
  78. if (ppw && ppw->_pSelectTemplatePage) \
  79. { \
  80. return ppw->_pSelectTemplatePage->DoHandleMessage(hwnd, uMsg, wParam, lParam); \
  81. } \
  82. return FALSE; \
  83. }
  84. static INT_PTR s_StatusPageDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) \
  85. { \
  86. CPrintPhotosWizard *ppw = s_GetPPW(hwnd, uMsg, lParam); \
  87. if (ppw && ppw->_pStatusPage) \
  88. { \
  89. return ppw->_pStatusPage->DoHandleMessage(hwnd, uMsg, wParam, lParam); \
  90. } \
  91. return FALSE; \
  92. }
  93. static INT_PTR s_EndPageDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) \
  94. { \
  95. CPrintPhotosWizard *ppw = s_GetPPW(hwnd, uMsg, lParam); \
  96. if (ppw && ppw->_pEndPage) \
  97. { \
  98. return ppw->_pEndPage->DoHandleMessage(hwnd, uMsg, wParam, lParam); \
  99. } \
  100. return FALSE; \
  101. }
  102. };
  103. /*****************************************************************************
  104. CPrintPhotosWizard constructor/destructor
  105. <Notes>
  106. *****************************************************************************/
  107. CPrintPhotosWizard::CPrintPhotosWizard() :
  108. _cRef(1),
  109. _pStartPage(NULL),
  110. _pPhotoSelectionPage(NULL),
  111. _pPrintOptionsPage(NULL),
  112. _pSelectTemplatePage(NULL),
  113. _pStatusPage(NULL),
  114. _pEndPage(NULL),
  115. _cidl(0),
  116. _aidl(NULL),
  117. _iSelection(0)
  118. {
  119. WIA_PUSH_FUNCTION_MASK((TRACE_WIZ,TEXT("CPrintPhotosWizard::CPrintPhotosWizard( this == 0x%x )"), this));
  120. DllAddRef();
  121. }
  122. CPrintPhotosWizard::~CPrintPhotosWizard()
  123. {
  124. WIA_PUSH_FUNCTION_MASK((TRACE_WIZ,TEXT("CPrintPhotosWizard::~CPrintPhotosWizard( this == 0x%x )"), this));
  125. if (_aidl)
  126. {
  127. for (int i=0;i<_cidl;i++)
  128. {
  129. ILFree(_aidl[i]);
  130. }
  131. delete[] _aidl;
  132. }
  133. DllRelease();
  134. }
  135. /*****************************************************************************
  136. CPrintPhotosWizard IUnknown methods
  137. <Notes>
  138. *****************************************************************************/
  139. ULONG CPrintPhotosWizard::AddRef()
  140. {
  141. ULONG ul = InterlockedIncrement(&_cRef);
  142. WIA_PUSH_FUNCTION_MASK((TRACE_REF_COUNTS,TEXT("CPrintPhotosWizard::AddRef( new count is %d )"),ul));
  143. return ul;
  144. }
  145. ULONG CPrintPhotosWizard::Release()
  146. {
  147. ULONG ul = InterlockedDecrement(&_cRef);
  148. WIA_PUSH_FUNCTION_MASK((TRACE_REF_COUNTS,TEXT("CPrintPhotosWizard::Release( new count is %d )"),ul));
  149. if (ul)
  150. return ul;
  151. WIA_TRACE((TEXT("deleting object ( this == 0x%x ) because ref count is zero."),this));
  152. delete this;
  153. return 0;
  154. }
  155. HRESULT CPrintPhotosWizard::QueryInterface(REFIID riid, void **ppv)
  156. {
  157. WIA_PUSH_FUNCTION_MASK((TRACE_REF_COUNTS,TEXT("CPrintPhotosWizard::QueryInterface()")));
  158. static const QITAB qit[] =
  159. {
  160. QITABENT(CPrintPhotosWizard, IPrintPhotosWizardSetInfo), // IID_IPrintPhotosWizardSetInfo
  161. {0, 0 },
  162. };
  163. HRESULT hr = QISearch(this, qit, riid, ppv);
  164. WIA_RETURN_HR(hr);
  165. }
  166. /*****************************************************************************
  167. CPrintPhotosWizard_CreateInstance
  168. Creates an instance of our wizard
  169. *****************************************************************************/
  170. STDAPI CPrintPhotosWizard_CreateInstance(IUnknown* pUnkOuter, IUnknown** ppunk, LPCOBJECTINFO poi)
  171. {
  172. WIA_PUSH_FUNCTION_MASK((TRACE_WIZ,TEXT("CPrintPhotosWizard_CreateInstance()")));
  173. CPrintPhotosWizard *pwiz = new CPrintPhotosWizard();
  174. if (!pwiz)
  175. {
  176. *ppunk = NULL; // incase of failure
  177. WIA_ERROR((TEXT("returning E_OUTOFMEMORY")));
  178. return E_OUTOFMEMORY;
  179. }
  180. HRESULT hr = pwiz->QueryInterface(IID_PPV_ARG(IUnknown, ppunk));
  181. pwiz->Release(); // we do this release because the new of CPrintPhotosWizard
  182. // set the ref count to 1, doing the QI bumps it up to 2,
  183. // and we want to leave this function with the ref count
  184. // at zero...
  185. WIA_RETURN_HR(hr);
  186. }
  187. /*****************************************************************************
  188. CPrintPhotosWizard::s_GetPPW
  189. static function that stores the "this" pointer for the class in
  190. user data slot of dlg, so that we can have our wndproc's as methods
  191. of this class.
  192. *****************************************************************************/
  193. CPrintPhotosWizard* CPrintPhotosWizard::s_GetPPW(HWND hwnd, UINT uMsg, LPARAM lParam)
  194. {
  195. WIA_PUSH_FUNCTION_MASK((TRACE_DLGPROC,TEXT("CPrintPhotosWizard::s_GetPPW()")));
  196. if (uMsg == WM_INITDIALOG)
  197. {
  198. PROPSHEETPAGE *ppsp = (PROPSHEETPAGE*)lParam;
  199. SetWindowLongPtr(hwnd, GWLP_USERDATA, ppsp->lParam);
  200. return (CPrintPhotosWizard*)ppsp->lParam;
  201. }
  202. return (CPrintPhotosWizard*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  203. }
  204. /*****************************************************************************
  205. CPrintPhotosWizard::_CreateWizardPages
  206. utility function to contruct and then create our wizard pages (property
  207. sheets).
  208. *****************************************************************************/
  209. HRESULT CPrintPhotosWizard::_CreateWizardPages( VOID )
  210. {
  211. WIA_PUSH_FUNCTION_MASK((TRACE_WIZ,TEXT("CPrintPhotosWizard::_CreateWizardPages()")));
  212. #define WIZDLG(name, dlgproc, title, sub, dwFlags) \
  213. { MAKEINTRESOURCE(##name##), dlgproc, MAKEINTRESOURCE(##title##), MAKEINTRESOURCE(##sub##), dwFlags }
  214. static const WIZPAGE c_wpPages[] =
  215. {
  216. WIZDLG(IDD_START_PAGE, CPrintPhotosWizard::s_StartPageDlgProc, 0, 0, PSP_HIDEHEADER),
  217. WIZDLG(IDD_PICTURE_SELECTION, CPrintPhotosWizard::s_PictureSelectionDlgProc, IDS_WIZ_SEL_PICTURE_TITLE, IDS_WIZ_SEL_PICTURE_SUBTITLE, PSP_PREMATURE),
  218. WIZDLG(IDD_PRINTING_OPTIONS, CPrintPhotosWizard::s_PrintOptionsDlgProc, IDS_WIZ_PRINTER_OPT_TITLE, IDS_WIZ_PRINTER_OPT_SUBTITLE, 0),
  219. WIZDLG(IDD_SELECT_TEMPLATE, CPrintPhotosWizard::s_SelectTemplateDlgProc, IDS_WIZ_SEL_TEMPLATE_TITLE, IDS_WIZ_SEL_TEMPLATE_SUBTITLE, PSP_PREMATURE),
  220. WIZDLG(IDD_PRINT_PROGRESS, CPrintPhotosWizard::s_StatusPageDlgProc, IDS_WIZ_PRINT_PROGRESS_TITLE, IDS_WIZ_PRINT_PROGRESS_SUBTITLE, PSP_PREMATURE),
  221. WIZDLG(IDD_END_PAGE, CPrintPhotosWizard::s_EndPageDlgProc, 0, 0, PSP_HIDEHEADER),
  222. };
  223. // if we haven't created the pages yet, then lets initialize our array of handlers.
  224. if (!_aWizPages[0])
  225. {
  226. WIA_TRACE((TEXT("Pages have not been created yet, creating them now...")));
  227. INITCOMMONCONTROLSEX iccex = { 0 };
  228. iccex.dwSize = sizeof (iccex);
  229. iccex.dwICC = ICC_LISTVIEW_CLASSES | ICC_USEREX_CLASSES | ICC_PROGRESS_CLASS;
  230. WIA_TRACE((TEXT("Initializing common controls...")));
  231. InitCommonControlsEx(&iccex);
  232. for (int i = 0; i < ARRAYSIZE(c_wpPages) ; i++ )
  233. {
  234. PROPSHEETPAGE psp = { 0 };
  235. psp.dwSize = SIZEOF(PROPSHEETPAGE);
  236. psp.hInstance = g_hInst;
  237. psp.lParam = (LPARAM)this;
  238. psp.dwFlags = PSP_USETITLE | PSP_DEFAULT |
  239. PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE |
  240. c_wpPages[i].dwFlags;
  241. psp.pszTemplate = c_wpPages[i].idPage;
  242. psp.pfnDlgProc = c_wpPages[i].pDlgProc;
  243. psp.pszTitle = MAKEINTRESOURCE(IDS_WIZ_TITLE);
  244. psp.pszHeaderTitle = c_wpPages[i].pHeading;
  245. psp.pszHeaderSubTitle = c_wpPages[i].pSubHeading;
  246. WIA_TRACE((TEXT("attempting to create page %d"),i));
  247. _aWizPages[i] = CreatePropertySheetPage(&psp);
  248. if (!_aWizPages[i])
  249. {
  250. WIA_ERROR((TEXT("returning E_FAIL because wizard page %d didn't create."),i));
  251. return E_FAIL;
  252. }
  253. }
  254. }
  255. else
  256. {
  257. WIA_TRACE((TEXT("Wizard pages already created.")));
  258. }
  259. return S_OK;
  260. }
  261. /*****************************************************************************
  262. CPrintPhotosWizard [IPrintPhotosWizardSetInfo methods]
  263. <Notes>
  264. *****************************************************************************/
  265. STDMETHODIMP CPrintPhotosWizard::SetFileListDataObject( IDataObject * pdo )
  266. {
  267. WIA_PUSH_FUNCTION_MASK((TRACE_WIZ,TEXT("CPrintPhotosWizard::SetFileListDataObject()")));
  268. HRESULT hr = E_INVALIDARG;
  269. if (pdo)
  270. {
  271. _pdo = pdo;
  272. hr = S_OK;
  273. }
  274. WIA_RETURN_HR(hr);
  275. }
  276. STDMETHODIMP CPrintPhotosWizard::SetFileListArray( LPITEMIDLIST *aidl, int cidl, int iSelection )
  277. {
  278. WIA_PUSH_FUNCTION_MASK((TRACE_WIZ,TEXT("CPrintPhotosWizard::SetFileListArray()")));
  279. HRESULT hr = E_INVALIDARG;
  280. if (aidl && cidl)
  281. {
  282. _aidl = new LPITEMIDLIST[cidl];
  283. if (_aidl)
  284. {
  285. for (int i=0;i<cidl;i++)
  286. {
  287. _aidl[i] = ILClone(aidl[i]);
  288. }
  289. if (iSelection > 0)
  290. {
  291. LPITEMIDLIST pTemp = _aidl[0];
  292. _aidl[0] = _aidl[iSelection];
  293. _aidl[iSelection] = pTemp;
  294. }
  295. _cidl = cidl;
  296. _iSelection = iSelection;
  297. hr = S_OK;
  298. }
  299. else
  300. {
  301. hr = E_OUTOFMEMORY;
  302. }
  303. }
  304. WIA_RETURN_HR(hr);
  305. }
  306. STDMETHODIMP CPrintPhotosWizard::RunWizard( VOID )
  307. {
  308. HRESULT hr = E_FAIL;
  309. WIA_PUSH_FUNCTION_MASK((TRACE_WIZ,TEXT("CPrintPhotosWizard::RunWizard()")));
  310. //
  311. // Create wizard blob
  312. //
  313. CWizardInfoBlob * pBlob = new CWizardInfoBlob( _aidl?NULL:_pdo, TRUE, FALSE );
  314. if (pBlob && _aidl)
  315. {
  316. pBlob->AddPhotosFromList(_aidl, _cidl, _iSelection >= 0? FALSE:TRUE);
  317. }
  318. //
  319. // Create each page handling class
  320. //
  321. _pStartPage = new CStartPage( pBlob );
  322. _pPhotoSelectionPage = new CPhotoSelectionPage( pBlob );
  323. _pPrintOptionsPage = new CPrintOptionsPage( pBlob );
  324. _pSelectTemplatePage = new CSelectTemplatePage( pBlob );
  325. _pStatusPage = new CStatusPage( pBlob );
  326. _pEndPage = new CEndPage( pBlob );
  327. //
  328. // Create the wizard pages...
  329. //
  330. hr = _CreateWizardPages();
  331. WIA_CHECK_HR(hr,"_CreateWizardPages()");
  332. if (SUCCEEDED(hr))
  333. {
  334. PROPSHEETHEADER psh = {0};
  335. psh.dwSize = sizeof(PROPSHEETHEADER);
  336. psh.dwFlags = PSH_WIZARD | PSH_WIZARD97 | PSH_WATERMARK | PSH_HEADER;
  337. psh.hwndParent = NULL;
  338. psh.hInstance = g_hInst;
  339. psh.nPages = MAX_WIZPAGES;
  340. psh.nStartPage = 0;
  341. psh.phpage = (HPROPSHEETPAGE *)_aWizPages;
  342. psh.pszbmHeader = MAKEINTRESOURCE(IDB_BANNER);
  343. psh.pszbmWatermark = MAKEINTRESOURCE(IDB_WATERMARK);
  344. WIA_TRACE((TEXT("Wizard pages created, trying to start wizard via PropertySheet()...")));
  345. if (PropertySheet( &psh ))
  346. {
  347. hr = S_OK;
  348. }
  349. else
  350. {
  351. WIA_ERROR((TEXT("PropertySheet() failed")));
  352. }
  353. }
  354. //
  355. // Give wizard a chance to shut down in an orderly fashion...
  356. //
  357. pBlob->ShutDownWizard();
  358. //
  359. // clean up page handling classes...
  360. //
  361. if (_pStartPage)
  362. {
  363. delete _pStartPage;
  364. _pStartPage = NULL;
  365. }
  366. if (_pPhotoSelectionPage)
  367. {
  368. delete _pPhotoSelectionPage;
  369. _pPhotoSelectionPage = NULL;
  370. }
  371. if (_pPrintOptionsPage)
  372. {
  373. delete _pPrintOptionsPage;
  374. _pPrintOptionsPage = NULL;
  375. }
  376. if (_pSelectTemplatePage)
  377. {
  378. delete _pSelectTemplatePage;
  379. _pSelectTemplatePage = NULL;
  380. }
  381. if (_pStatusPage)
  382. {
  383. delete _pStatusPage;
  384. _pStatusPage = NULL;
  385. }
  386. if (_pEndPage)
  387. {
  388. delete _pEndPage;
  389. _pEndPage = NULL;
  390. }
  391. WIA_RETURN_HR(hr);
  392. }