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.

292 lines
7.5 KiB

  1. /*****************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 2000
  4. *
  5. * TITLE: xmltools2.h
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: RickTu, based on work by LazarI
  10. *
  11. * DATE: 2/19/01
  12. *
  13. * DESCRIPTION: Class which encapsulates reading templates from xml file, and
  14. * class which encapsulates the template for use by the app.
  15. *
  16. *****************************************************************************/
  17. #ifndef _xmltools2_h_
  18. #define _xmltools2_h_
  19. #define LOCAL_DEPENDENT_INDEX 0
  20. #define LOCAL_INDEPENDENT_INDEX 1
  21. #define NUMBER_OF_TEMPLATE_TYPES 2
  22. class CTemplateInfo
  23. {
  24. public:
  25. // common properties
  26. // accessible through IDs
  27. enum
  28. {
  29. PROP_GUID,
  30. PROP_GROUP,
  31. PROP_TITLE,
  32. PROP_DESCRIPTION,
  33. PROP_REPEAT_PHOTOS,
  34. PROP_USE_THUMBNAILS_TO_PRINT,
  35. PROP_PRINT_FILENAME,
  36. PROP_CAN_ROTATE,
  37. PROP_CAN_CROP,
  38. PROP_LAST
  39. };
  40. CTemplateInfo( IXMLDOMElement * pTheTemplate ); // loads templates from XML file
  41. CTemplateInfo(); // creates full page template without going to XML file
  42. ~CTemplateInfo();
  43. //
  44. // These are the inherent properties of this template
  45. //
  46. INT PhotosPerPage()
  47. {
  48. WIA_PUSH_FUNCTION_MASK((TRACE_TEMPLATE,TEXT("CTemplateInfo::PhotosPerPage( returning %d )"),_arrLayout.Count()));
  49. return _arrLayout.Count();
  50. }
  51. HRESULT GetGroup( CSimpleString * pstrGroup )
  52. {
  53. WIA_PUSH_FUNCTION_MASK((TRACE_TEMPLATE,TEXT("CTemplateInfo::GetGroup( returning %s )"),_strGroup.String()));
  54. if (pstrGroup)
  55. {
  56. pstrGroup->Assign( _strGroup.String() );
  57. return S_OK;
  58. }
  59. return E_INVALIDARG;
  60. }
  61. HRESULT GetTitle( CSimpleString * pstrTitle )
  62. {
  63. WIA_PUSH_FUNCTION_MASK((TRACE_TEMPLATE,TEXT("CTemplateInfo::GetTitle( returning %s )"),_strTitle.String()));
  64. if (pstrTitle)
  65. {
  66. pstrTitle->Assign( _strTitle.String() );
  67. return S_OK;
  68. }
  69. return E_INVALIDARG;
  70. }
  71. HRESULT GetDescription( CSimpleString * pstrDescription )
  72. {
  73. WIA_PUSH_FUNCTION_MASK((TRACE_TEMPLATE,TEXT("CTemplateInfo::GetDesciption( returning %s )"),_strDescription.String()));
  74. if (pstrDescription)
  75. {
  76. pstrDescription->Assign( _strDescription.String() );
  77. return S_OK;
  78. }
  79. return E_INVALIDARG;
  80. }
  81. HRESULT GetRepeatPhotos( BOOL * pBool )
  82. {
  83. WIA_PUSH_FUNCTION_MASK((TRACE_TEMPLATE,TEXT("CTemplateInfo::GetRepeatPhotos( returning 0x%x )"),_bRepeatPhotos));
  84. if (pBool)
  85. {
  86. *pBool = _bRepeatPhotos;
  87. return S_OK;
  88. }
  89. return E_INVALIDARG;
  90. }
  91. HRESULT GetUseThumbnailsToPrint( BOOL * pBool )
  92. {
  93. WIA_PUSH_FUNCTION_MASK((TRACE_TEMPLATE,TEXT("CTemplateInfo::GetUseThumbnailsToPrint( returning 0x%x )"),_bUseThumbnailsToPrint));
  94. if (pBool)
  95. {
  96. *pBool = _bUseThumbnailsToPrint;
  97. return S_OK;
  98. }
  99. return E_INVALIDARG;
  100. }
  101. HRESULT GetPrintFilename( BOOL * pBool )
  102. {
  103. WIA_PUSH_FUNCTION_MASK((TRACE_TEMPLATE,TEXT("CTemplateInfo::GetPrintFilename( returning 0x%x )"),_bPrintFilename));
  104. if (pBool)
  105. {
  106. *pBool = _bPrintFilename;
  107. return S_OK;
  108. }
  109. return E_INVALIDARG;
  110. }
  111. HRESULT GetCanRotate( BOOL * pBool )
  112. {
  113. WIA_PUSH_FUNCTION_MASK((TRACE_TEMPLATE,TEXT("CTemplateInfo::GetCanRotate( returning 0x%x )"),_bCanRotate));
  114. if (pBool)
  115. {
  116. *pBool = _bCanRotate;
  117. return S_OK;
  118. }
  119. return E_INVALIDARG;
  120. }
  121. HRESULT GetCanCrop( BOOL * pBool )
  122. {
  123. WIA_PUSH_FUNCTION_MASK((TRACE_TEMPLATE,TEXT("CTemplateInfo::GetCanCrop( returning 0x%x )"),_bCanCrop));
  124. if (pBool)
  125. {
  126. *pBool = _bCanCrop;
  127. return S_OK;
  128. }
  129. return E_INVALIDARG;
  130. }
  131. HRESULT GetNominalRectForPhoto( INT iIndex, RECT * pRect )
  132. {
  133. WIA_PUSH_FUNCTION_MASK((TRACE_TEMPLATE,TEXT("CTemplateInfo::GetNominalRectForPhoto( )")));
  134. CAutoCriticalSection lock(_cs);
  135. if (pRect)
  136. {
  137. if (iIndex < _arrLayout.Count())
  138. {
  139. *pRect = _arrLayout[iIndex];
  140. return S_OK;
  141. }
  142. }
  143. return E_INVALIDARG;
  144. }
  145. HRESULT GetNominalRectForImageableArea( RECT * pRect )
  146. {
  147. WIA_PUSH_FUNCTION_MASK((TRACE_TEMPLATE,TEXT("CTemplateInfo::GetNominalRectForImageableArea( returning %d,%d,%d,%d )"),_rcImageableArea.left,_rcImageableArea.top,_rcImageableArea.right,_rcImageableArea.bottom));
  148. CAutoCriticalSection lock(_cs);
  149. if (pRect)
  150. {
  151. *pRect = _rcImageableArea;
  152. return S_OK;
  153. }
  154. return E_INVALIDARG;
  155. }
  156. HRESULT GetPreviewImageStream(IStream **pps)
  157. {
  158. WIA_PUSH_FUNCTION_MASK((TRACE_TEMPLATE,TEXT("CTemplateInfo::GetImagePreviewStream( )")));
  159. if (pps)
  160. {
  161. //
  162. // Since _pStream is an ATL CComPtr, it does
  163. // an addref in it's operator =, so we're returning
  164. // an addref'd IStream.
  165. //
  166. *pps = _pStream;
  167. if (*pps)
  168. {
  169. (*pps)->AddRef();
  170. return S_OK;
  171. }
  172. }
  173. return E_INVALIDARG;
  174. }
  175. //
  176. // These are used to set which orientation the template should be in
  177. //
  178. HRESULT RotateForLandscape();
  179. HRESULT RotateForPortrait();
  180. private:
  181. BOOL _bPortrait;
  182. CSimpleCriticalSection _cs;
  183. //
  184. // Properties from XML
  185. //
  186. RECT _rcImageableArea;
  187. CSimpleArray<RECT> _arrLayout;
  188. CSimpleString _strGroup;
  189. CSimpleString _strTitle;
  190. CSimpleString _strDescription;
  191. BOOL _bRepeatPhotos;
  192. BOOL _bUseThumbnailsToPrint;
  193. BOOL _bPrintFilename;
  194. BOOL _bCanRotate;
  195. BOOL _bCanCrop;
  196. IStream * _pStream;
  197. };
  198. ////////////////////////////
  199. // CPhotoTemplates
  200. class CPhotoTemplates
  201. {
  202. public:
  203. enum
  204. {
  205. MEASURE_INDEPENDENT,
  206. MEASURE_METRIC,
  207. MEASURE_US,
  208. MEASURE_UNKNOWN
  209. };
  210. //
  211. // construction/destruction
  212. //
  213. CPhotoTemplates();
  214. ~CPhotoTemplates();
  215. //
  216. // public interface
  217. //
  218. HRESULT Init(IXMLDOMDocument *pDoc); // init from XML doc
  219. HRESULT InitForPrintTo(); // init for PrintTo situation
  220. HRESULT AddTemplates(LPCTSTR pLocale); // add the templates for the given locale
  221. LONG Count(); // number of templates
  222. HRESULT GetTemplate( INT iIndex, CTemplateInfo ** ppTemplateInfo );
  223. private:
  224. static HRESULT _GetLocaleMeasurements(int *pMeasurements);
  225. static HRESULT _BuildLocaleQueryString(int Measure, LPTSTR pStr, UINT cch);
  226. static HRESULT _BuildGUIDQueryString(const GUID &guid, CComBSTR &bstr);
  227. int _Measure;
  228. CSimpleCriticalSection _csList;
  229. CComPtr<IXMLDOMElement> _pRoot;
  230. HDPA _hdpaTemplates;
  231. };
  232. #endif // _xmltools2_h_