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.

245 lines
10 KiB

  1. /*****************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 2000
  4. *
  5. * TITLE: wizblob.h
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: RickTu
  10. *
  11. * DATE: 10/18/98
  12. *
  13. * DESCRIPTION: Defines the blob of information pass around to each
  14. * page of the wizard...
  15. *
  16. *****************************************************************************/
  17. #ifndef _PRINT_PHOTOS_WIZARD_WIZ_BLOB_
  18. #define _PRINT_PHOTOS_WIZARD_WIZ_BLOB_
  19. #define NOMINAL_MULTIPLIER 10000.0 // 1/10000 of inch
  20. #define MM_PER_INCH 25.4
  21. #define MM_TO_INCH(x) ((DOUBLE)x / (DOUBLE)MM_PER_INCH ))
  22. #define MM_TO_NOMINAL(x) ((INT)((DOUBLE)MM_TO_INCH(x) * (DOUBLE)NOMINAL_MULTIPLIER))
  23. #define IN_TO_NOMINAL(x) ((INT)((DOUBLE)x * (DOUBLE)NOMINAL_MULTIPLIER))
  24. #define WIZ_MSG_STARTUP_GDI_PLUS (WM_USER+250)
  25. #define WIZ_MSG_SHUTDOWN_GDI_PLUS (WM_USER+251)
  26. #define WIZ_MSG_COPIES_CHANGED (WM_USER+252) // wParam holds number of copies
  27. #define DEFAULT_DPA_SIZE 50
  28. #define MINIMUM_MEMORY_SIZE 140000
  29. #define LARGE_MINIMUM_MEMORY_SIZE 400000
  30. #define LARGE_IMAGE_SIZE 1048576
  31. #define REALLY_LARGE_IMAGE_SIZE 5242880
  32. class CWizardInfoBlob {
  33. typedef struct {
  34. BOOL bValid;
  35. SIZE DPI;
  36. RECT rcDevice;
  37. SIZE PhysicalSize;
  38. SIZE PhysicalOffset;
  39. } WIZ_PRINTER_INFO, *LPWIZ_PRINTER_INFO;
  40. public:
  41. CWizardInfoBlob( IDataObject * pdo, BOOL bShowUI, BOOL bOnlyUseSelection );
  42. ~CWizardInfoBlob();
  43. VOID AddRef();
  44. VOID Release();
  45. // PhotoItem stuff
  46. INT CountOfPhotos(BOOL bIncludeCopies);
  47. INT CountOfSelectedPhotos(BOOL bIncludeCopies);
  48. INT GetIndexOfNextPrintableItem(INT iStartIndex);
  49. CListItem * GetListItem(INT iIndex, BOOL bIncludeCopies);
  50. VOID ToggleSelectionStateOnCopies( CListItem * pRootItem, BOOL bState );
  51. // PhotoTemplate stuff
  52. HRESULT TemplateGetPreviewBitmap(INT iIndex, const SIZE &sizeDesired, HBITMAP *phBmp);
  53. HRESULT GetTemplateByIndex( INT iIndex, CTemplateInfo ** ppTemplateInfo );
  54. INT CountOfTemplates() { return _templates.Count(); }
  55. // Layout stuff
  56. VOID _RenderFilenameOfPhoto( Gdiplus::Graphics * g, RECT * pPhotoDest, CListItem * pPhoto );
  57. HBITMAP RenderPreview( INT iTemplateIndex, HWND hwndScreen );
  58. HRESULT RenderPrintedPage( INT iTemplateIndex, INT iPage, HDC hDC, HWND hwndProgress, float fProgressStep, float * pPercent );
  59. INT PhotosPerTemplate( INT iTemplateIndex );
  60. VOID _SetupDimensionsForScreen( CTemplateInfo * pTemplateInfo, HWND hwndScreen, RENDER_DIMENSIONS * pDim );
  61. VOID _SetupDimensionsForPrinting( HDC hDC, CTemplateInfo * pTemplateInfo, RENDER_DIMENSIONS * pDim );
  62. // Printing stuff
  63. HRESULT SetPrinterToUse( LPCTSTR pszPrinterName );
  64. HRESULT SetDevModeToUse( PDEVMODE pDevMode );
  65. LPCTSTR GetPrinterToUse();
  66. PDEVMODE GetDevModeToUse();
  67. HRESULT GetCountOfPrintedPages( INT iTemplate, INT * pPageCount );
  68. VOID UpdateCachedPrinterInfo();
  69. VOID GetCachedPrinterInfo() { CAutoCriticalSection lock(_csPrinterInfo); if (!_WizPrinterInfo.bValid) {UpdateCachedPrinterInfo();} return; }
  70. HDC GetCachedPrinterDC() { CAutoCriticalSection lock(_csPrinterInfo); return _hCachedPrinterDC;}
  71. VOID SetCachedPrinterDC( HDC hDC ) {CAutoCriticalSection lock(_csPrinterInfo); if (_hCachedPrinterDC) {DeleteDC(_hCachedPrinterDC);} _hCachedPrinterDC = hDC; UpdateCachedPrinterInfo(); return;}
  72. VOID ConstructPrintToTemplate();
  73. // Util stuff
  74. HWND GetPreviewWnd() {return _hwndPreview;}
  75. VOID SetPreviewWnd(HWND hwnd);
  76. VOID SetPreviewWindowClass( CPreviewWindow * pPreview ) {if (_pPreview) {delete _pPreview;} _pPreview = pPreview;}
  77. VOID InvalidateAllPreviews() {if (_pPreview) {_pPreview->InvalidateAllPreviews();} }
  78. VOID GenerateStillWorkingBitmap() {if (_pPreview && _hwndPreview) {_pPreview->GenerateWorkingBitmap(_hwndPreview);} }
  79. VOID SetStatusWnd(HWND hwnd) {_hwndStatus = hwnd; _hOuterDlg = GetParent( hwnd );}
  80. VOID SetStatusPageClass( CStatusPage * pStatus ) { _pStatusPage = pStatus; }
  81. VOID SetPhotoSelectionPageClass( CPhotoSelectionPage * pPhotoSel ) { _pPhotoSelPage = pPhotoSel; }
  82. HFONT GetIntroFont(HWND hwnd);
  83. VOID SetCurrentTemplateIndex(INT i) { _iCurTemplate = i; }
  84. INT GetCurrentTemplateIndex() { return _iCurTemplate; }
  85. CPreviewWindow * GetPreviewWindowClass() {return _pPreview;}
  86. VOID SetPreviewsAreDirty( BOOL b ) {_bPreviewsAreDirty = b;}
  87. BOOL GetPreviewsAreDirty( ) {return _bPreviewsAreDirty;}
  88. BOOL SetRepeat( BOOL b ) { if (_bRepeat == b) {return FALSE;} _bRepeat = b; return TRUE; }
  89. BOOL GetRepeat( ) {return _bRepeat;}
  90. HICON GetSmallIcon() {return _hSmallIcon;}
  91. HICON GetLargeIcon() {return _hLargeIcon;}
  92. INT ShowError( HWND hwnd, HRESULT hr, UINT idText, BOOL bTryAgain = FALSE, LPITEMIDLIST pidl = NULL );
  93. BOOL AllPicturesAdded() {return _bAllPicturesAdded;}
  94. BOOL ItemsWereRejected() {return _bItemsWereRejected;}
  95. UINT ItemsInInitialSelection() {return _uItemsInInitialSelection;}
  96. VOID ShutDownWizard();
  97. BOOL IsWizardShuttingDown() {return (BOOL)_bWizardIsShuttingDown;}
  98. VOID PhotoSelIsShutDown() { if (_hPhotoSelIsDone) SetEvent(_hPhotoSelIsDone); }
  99. VOID StatusIsShutDown() { if (_hStatusIsDone) SetEvent(_hStatusIsDone); }
  100. VOID PreviewIsShutDown() { if (_hPreviewIsDone) SetEvent(_hPreviewIsDone); }
  101. LRESULT UserPressedCancel();
  102. INT NumberOfErrorsEncountered() { return _iNumErrorsWhileRunningWizard; }
  103. VOID ResetErrorCount() { _iNumErrorsWhileRunningWizard = 0; }
  104. VOID SetNumberOfCopies( UINT uCopies );
  105. BOOL IsSystemMemoryLimited() { return _bMinimumMemorySystem; }
  106. BOOL IsSystemMemoryLarge() { return _bLargeMemorySystem; }
  107. BOOL GetForceSelectAll() { return _bForceSelectAll; }
  108. VOID GdiPlusStartupShutdownThreadIsReady()
  109. {
  110. WIA_PUSH_FUNCTION_MASK((0x08000000, TEXT("CWizardInfoBlob::GdiPlusStartupShutdownThreadIsReady()")));
  111. if (_hGdiPlusMsgQueueCreated)
  112. {
  113. WIA_TRACE((TEXT("Setting _hGdiPlusMsgQueueCreated...")));
  114. SetEvent(_hGdiPlusMsgQueueCreated);
  115. }
  116. }
  117. VOID AddAllPhotosFromDataObject();
  118. VOID AddPhotosFromList(LPITEMIDLIST *aidl, int cidl, BOOL bSelectAll);
  119. VOID RemoveAllCopiesOfPhotos();
  120. VOID AddCopiesOfPhotos( UINT uCopies );
  121. // constants to use for wizard
  122. SIZE _sizeThumbnails;
  123. SIZE _sizeTemplatePreview;
  124. LONG _nDefaultThumbnailImageListIndex;
  125. private:
  126. // Used to add items
  127. HRESULT AddPhoto( LPITEMIDLIST pidlFull );
  128. // thread message handlers
  129. VOID _DoHandleThreadMessage( LPMSG pMSG );
  130. // worker thread proc
  131. static DWORD s_GdiPlusStartupShutdownThreadProc( LPVOID lpv )
  132. {
  133. WIA_PUSH_FUNCTION_MASK((0x80, TEXT("CWizardInfoBlob::s_GdiPlusStartupShutdownThreadProc()")));
  134. MSG msg;
  135. LONG lRes = 0;
  136. CWizardInfoBlob * pWizInfo = (CWizardInfoBlob *)lpv;
  137. if (pWizInfo)
  138. {
  139. HMODULE hDll = GetThreadHMODULE( s_GdiPlusStartupShutdownThreadProc );
  140. HRESULT hrCo = PPWCoInitialize();
  141. PeekMessage( &msg, NULL, WM_USER, WM_USER, PM_NOREMOVE );
  142. pWizInfo->GdiPlusStartupShutdownThreadIsReady();
  143. do {
  144. lRes = GetMessage( &msg, NULL, 0, 0 );
  145. if (lRes > 0)
  146. {
  147. pWizInfo->_DoHandleThreadMessage( &msg );
  148. }
  149. } while ( (lRes != 0) && (lRes != -1) );
  150. PPWCoUninitialize(hrCo);
  151. if (hDll)
  152. {
  153. WIA_TRACE((TEXT("CWizardInfoBlob::s_GdiPlusStartupShutdownThreadProc - exiting thread now via FLAET...")));
  154. FreeLibraryAndExitThread( hDll, 0 );
  155. }
  156. }
  157. WIA_TRACE((TEXT("CWizardInfoBlob::s_GdiPlusStartupShutdownThreadProc - exiting thread now...")));
  158. return 0;
  159. }
  160. private:
  161. CComPtr<IDataObject> _pdo;
  162. LONG _cRef;
  163. HDPA _hdpaItems;
  164. CSimpleCriticalSection _csItems;
  165. CSimpleCriticalSection _csPrinterInfo;
  166. CPhotoTemplates _templates;
  167. PDEVMODE _hDevMode;
  168. CSimpleString _strPrinterName;
  169. RECT _rcInitSize;
  170. SIZE _Center;
  171. HWND _hwndPreview;
  172. HWND _hwndStatus;
  173. CPreviewWindow * _pPreview;
  174. CStatusPage * _pStatusPage;
  175. CPhotoSelectionPage * _pPhotoSelPage;
  176. INT _iCurTemplate;
  177. BOOL _bGdiplusInitialized;
  178. BOOL _bAllPicturesAdded;
  179. ULONG_PTR _pGdiplusToken;
  180. HFONT _hfontIntro;
  181. BOOL _bPreviewsAreDirty;
  182. BOOL _bRepeat;
  183. HICON _hSmallIcon;
  184. HICON _hLargeIcon;
  185. UINT _uItemsInInitialSelection;
  186. BOOL _bAlreadyAddedPhotos;
  187. BOOL _bItemsWereRejected;
  188. LONG _bWizardIsShuttingDown;
  189. HANDLE _hGdiPlusThread;
  190. DWORD _dwGdiPlusThreadId;
  191. HANDLE _hGdiPlusMsgQueueCreated;
  192. HDC _hCachedPrinterDC;
  193. HWND _hOuterDlg;
  194. INT _iNumErrorsWhileRunningWizard;
  195. BOOL _bShowUI;
  196. BOOL _bOnlyUseSelection;
  197. WIZ_PRINTER_INFO _WizPrinterInfo;
  198. INT _iSelectedItem;
  199. INT _iCopiesOfEachItem;
  200. BOOL _bMinimumMemorySystem;
  201. BOOL _bLargeMemorySystem;
  202. BOOL _bForceSelectAll;
  203. //
  204. // These handles are here for each of the background threads
  205. // to signal so that we can know they have shut down...
  206. //
  207. HANDLE _hPhotoSelIsDone;
  208. HANDLE _hStatusIsDone;
  209. HANDLE _hPreviewIsDone;
  210. };
  211. #endif