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.

185 lines
5.7 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 2000
  4. *
  5. * TITLE: ATTACH.H
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 10/26/2000
  12. *
  13. * DESCRIPTION:
  14. *
  15. *******************************************************************************/
  16. #ifndef __ATTACH_H_INCLUDED
  17. #define __ATTACH_H_INCLUDED
  18. #include <windows.h>
  19. #include <simstr.h>
  20. #include "wiaffmt.h"
  21. #include "itranhlp.h"
  22. #include "wiadevdp.h"
  23. class CAnnotation
  24. {
  25. private:
  26. CComPtr<IWiaItem> m_pWiaItem;
  27. mutable CWiaFileFormat m_WiaFileFormat;
  28. public:
  29. CAnnotation( const CAnnotation &other )
  30. : m_pWiaItem(other.WiaItem()),
  31. m_WiaFileFormat(other.FileFormat())
  32. {
  33. }
  34. CAnnotation( IWiaItem *pWiaItem=NULL )
  35. : m_pWiaItem(pWiaItem)
  36. {
  37. }
  38. HRESULT InitializeFileFormat( HICON hDefIcon, const CSimpleString &strDefaultUnknownDescription, const CSimpleString &strEmptyDescriptionMask, const CSimpleString &strDefUnknownExtension )
  39. {
  40. WIA_PUSH_FUNCTION((TEXT("CAnnotation::InitializeFileFormat")));
  41. CComPtr<IWiaAnnotationHelpers> pWiaAnnotationHelpers;
  42. HRESULT hr = CoCreateInstance( CLSID_WiaDefaultUi, NULL, CLSCTX_INPROC_SERVER, IID_IWiaAnnotationHelpers, (void**)&pWiaAnnotationHelpers );
  43. if (SUCCEEDED(hr))
  44. {
  45. GUID guidFormat = IID_NULL;
  46. hr = pWiaAnnotationHelpers->GetAnnotationFormat(m_pWiaItem,guidFormat);
  47. if (SUCCEEDED(hr))
  48. {
  49. //
  50. // Get the extension
  51. //
  52. CSimpleString strExtension = CWiaFileFormat::GetExtension( guidFormat, TYMED_FILE, m_pWiaItem );
  53. //
  54. // Set the format information. If we can't get them, we will compensate below.
  55. //
  56. m_WiaFileFormat.Format(guidFormat);
  57. m_WiaFileFormat.Extension(strExtension);
  58. m_WiaFileFormat.AcquireIcon(hDefIcon);
  59. m_WiaFileFormat.AcquireDescription();
  60. //
  61. // If we couldn't get an icon, use the default.
  62. //
  63. if (!m_WiaFileFormat.Icon())
  64. {
  65. m_WiaFileFormat.Icon(hDefIcon);
  66. }
  67. //
  68. // If we couldn't get a description, create one
  69. //
  70. if (!m_WiaFileFormat.Description().Length())
  71. {
  72. //
  73. // If we have an extension, use it to create a description string
  74. //
  75. if (m_WiaFileFormat.Extension().Length())
  76. {
  77. CSimpleString strDescription;
  78. strDescription.Format( strEmptyDescriptionMask, m_WiaFileFormat.Extension().String() );
  79. m_WiaFileFormat.Description(strDescription);
  80. }
  81. //
  82. // Otherwise, use the default unknown type description
  83. //
  84. else
  85. {
  86. m_WiaFileFormat.Description(strDefaultUnknownDescription);
  87. }
  88. }
  89. //
  90. // If we don't have an extension, use the default
  91. //
  92. if (!m_WiaFileFormat.Extension().Length())
  93. {
  94. m_WiaFileFormat.Extension(strDefUnknownExtension);
  95. }
  96. }
  97. else
  98. {
  99. WIA_PRINTHRESULT((hr,TEXT("GetAnnotationFormat returned")));
  100. }
  101. }
  102. if (SUCCEEDED(hr))
  103. {
  104. if (m_WiaFileFormat.IsValid())
  105. {
  106. return S_OK;
  107. }
  108. else
  109. {
  110. WIA_TRACE((TEXT("m_WiaFileFormat returned false")));
  111. hr = E_FAIL;
  112. }
  113. }
  114. return hr;
  115. }
  116. ~CAnnotation(void)
  117. {
  118. Destroy();
  119. }
  120. void Destroy(void)
  121. {
  122. m_pWiaItem = NULL;
  123. m_WiaFileFormat.Destroy();
  124. }
  125. CAnnotation &operator=( const CAnnotation &other )
  126. {
  127. if (this != &other)
  128. {
  129. Destroy();
  130. m_pWiaItem = other.WiaItem();
  131. m_WiaFileFormat = other.FileFormat();
  132. }
  133. return *this;
  134. }
  135. bool operator==( const CAnnotation &other )
  136. {
  137. return (other.FullItemName() == FullItemName());
  138. }
  139. IWiaItem *WiaItem(void) const
  140. {
  141. return m_pWiaItem;
  142. }
  143. IWiaItem *WiaItem(void)
  144. {
  145. return m_pWiaItem;
  146. }
  147. const CWiaFileFormat &FileFormat(void) const
  148. {
  149. return m_WiaFileFormat;
  150. }
  151. CSimpleString Name(void) const
  152. {
  153. CSimpleStringWide strResult;
  154. PropStorageHelpers::GetProperty( m_pWiaItem, WIA_IPA_ITEM_NAME, strResult );
  155. return CSimpleStringConvert::NaturalString(strResult);
  156. }
  157. CSimpleStringWide FullItemName(void) const
  158. {
  159. CSimpleStringWide strResult;
  160. PropStorageHelpers::GetProperty( m_pWiaItem, WIA_IPA_FULL_ITEM_NAME, strResult );
  161. return strResult;
  162. }
  163. LONG Size(void)
  164. {
  165. LONG nSize = 0;
  166. CComPtr<IWiaAnnotationHelpers> pWiaAnnotationHelpers;
  167. HRESULT hr = CoCreateInstance( CLSID_WiaDefaultUi, NULL, CLSCTX_INPROC_SERVER, IID_IWiaAnnotationHelpers, (void**)&pWiaAnnotationHelpers );
  168. if (SUCCEEDED(hr))
  169. {
  170. GUID guidFormat = IID_NULL;
  171. pWiaAnnotationHelpers->GetAnnotationSize(m_pWiaItem,nSize,TYMED_FILE);
  172. }
  173. return nSize;
  174. }
  175. };
  176. #endif // __ATTACH_H_INCLUDED