Source code of Windows XP (NT5)
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.

191 lines
5.7 KiB

  1. /*
  2. * _DXFROBJ.H
  3. *
  4. * Purpose:
  5. * Class declaration for an OLE data transfer object (for use in
  6. * drag drop and clipboard operations)
  7. *
  8. * Author:
  9. * alexgo (4/25/95)
  10. *
  11. * Copyright (c) 1995-2000, Microsoft Corporation. All rights reserved.
  12. */
  13. #ifndef __DXFEROBJ_H__
  14. #define __DXFEROBJ_H__
  15. class CTxtRange;
  16. EXTERN_C const IID IID_IRichEditDO;
  17. /*
  18. * CDataTransferObj
  19. *
  20. * Purpose:
  21. * holds a "snapshot" of some rich-text data that can be used
  22. * for drag drop or clipboard operations
  23. *
  24. * Notes:
  25. * FUTURE (alexgo): add in support for TOM<-->TOM optimized data
  26. * transfers
  27. */
  28. class CDataTransferObj : public IDataObject, public ITxNotify
  29. {
  30. public:
  31. // IUnknown methods
  32. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObj);
  33. STDMETHOD_(ULONG, AddRef)();
  34. STDMETHOD_(ULONG, Release)();
  35. // IDataObject methods
  36. STDMETHOD(DAdvise)( FORMATETC * pFormatetc, DWORD advf,
  37. IAdviseSink *pAdvSink, DWORD *pdwConnection);
  38. STDMETHOD(DUnadvise)( DWORD dwConnection);
  39. STDMETHOD(EnumDAdvise)( IEnumSTATDATA ** ppenumAdvise);
  40. STDMETHOD(EnumFormatEtc)( DWORD dwDirection,
  41. IEnumFORMATETC **ppenumFormatEtc);
  42. STDMETHOD(GetCanonicalFormatEtc)( FORMATETC *pformatetc,
  43. FORMATETC *pformatetcOut);
  44. STDMETHOD(GetData)( FORMATETC *pformatetcIn, STGMEDIUM *pmedium );
  45. STDMETHOD(GetDataHere)( FORMATETC *pformatetc, STGMEDIUM *pmedium);
  46. STDMETHOD(QueryGetData)( FORMATETC *pformatetc );
  47. STDMETHOD(SetData)( FORMATETC *pformatetc, STGMEDIUM *pmedium,
  48. BOOL fRelease);
  49. // ITxNotify methods
  50. virtual void OnPreReplaceRange( LONG cp, LONG cchDel, LONG cchNew,
  51. LONG cpFormatMin, LONG cpFormatMax, NOTIFY_DATA *pNotifyData );
  52. virtual void OnPostReplaceRange( LONG cp, LONG cchDel, LONG cchNew,
  53. LONG cpFormatMin, LONG cpFormatMax, NOTIFY_DATA *pNotifyData );
  54. virtual void Zombie();
  55. static CDataTransferObj * Create(CTxtEdit *ped, CTxtRange *prg, LONG lStreamFormat);
  56. private:
  57. // NOTE: private cons/destructor, may not be allocated on the stack as
  58. // this would break OLE's current object liveness rules
  59. CDataTransferObj(CTxtEdit *ped);
  60. ~CDataTransferObj();
  61. BOOL IsZombie() {return !_ped;}
  62. ULONG _crefs;
  63. ULONG _cTotal; // total number of formats supported
  64. FORMATETC * _prgFormats; // the array of supported formats
  65. LONG _lStreamFormat; // Stream format to use in Rtf conversion
  66. // for 1.0 compatability
  67. DWORD _dwFlags;
  68. DWORD _dwUser;
  69. DWORD _dvaspect;
  70. enum TEXTKIND
  71. {
  72. tPlain,
  73. tRtf,
  74. tRtfUtf8,
  75. tRtfNCRforNonASCII
  76. };
  77. HGLOBAL TextToHglobal( HGLOBAL &hText, TEXTKIND tKind );
  78. LPSTORAGE GetDataForEmbeddedObject( LPOLEOBJECT pOleObj, LPSTORAGE lpstgdest );
  79. HGLOBAL GetDataForObjectDescriptor( LPOLEOBJECT pOleObj, DWORD dwAspect, SIZEUV* psize );
  80. public:
  81. CTxtEdit * _ped;
  82. HGLOBAL _hPlainText; // handle to the plain UNICODE text
  83. HGLOBAL _hRtfText; // handle to the RTF UNICODE text
  84. HGLOBAL _hRtfUtf8; // Handle to UTF8 encoding of RTF
  85. HGLOBAL _hRtfNCRforNonASCII; // Handle to NCRforNonASCII encoding of RTF
  86. IOleObject * _pOleObj; // Embedded Object
  87. LPSTORAGE _pObjStg; // Embedded object data
  88. HGLOBAL _hObjDesc; // Embedded object descriptor
  89. HMETAFILE _hMFPict; // Embedded object metafile
  90. LONG _cch; // number of "characters" in the this
  91. // dxfer object
  92. LONG _cpMin; // Starting cp for this dxfer object
  93. LONG _cObjs; // number of objects in this dxfer object.
  94. };
  95. /*
  96. * class CEnumFormatEtc
  97. *
  98. * Purpose:
  99. * implements a generic format enumerator for IDataObject
  100. */
  101. class CEnumFormatEtc : public IEnumFORMATETC
  102. {
  103. public:
  104. STDMETHOD(QueryInterface)(REFIID riid, void **ppvObj);
  105. STDMETHOD_(ULONG,AddRef)(void);
  106. STDMETHOD_(ULONG,Release)(void);
  107. STDMETHOD(Next) (ULONG celt, FORMATETC *rgelt,
  108. ULONG *pceltFetched);
  109. STDMETHOD(Skip) (ULONG celt);
  110. STDMETHOD(Reset) (void);
  111. STDMETHOD(Clone) (IEnumFORMATETC **ppenum);
  112. static HRESULT Create(FORMATETC *prgFormats, DWORD cFormats,
  113. IEnumFORMATETC **ppenum);
  114. private:
  115. CEnumFormatEtc();
  116. ~CEnumFormatEtc();
  117. ULONG _crefs;
  118. ULONG _iCurrent; // current clipboard format
  119. ULONG _cTotal; // total number of formats
  120. FORMATETC * _prgFormats; // array of available formats
  121. };
  122. //
  123. // Some globally useful FORMATETCs
  124. extern FORMATETC g_rgFETC[];
  125. extern const DWORD g_rgDOI[];
  126. #define CFETC 17 // Dimension of g_rgFETC[]
  127. enum FETCINDEX // Keep in sync with g_rgFETC[]
  128. {
  129. iRtfUtf8, // RTF in UTF8 encoding
  130. iRtfFETC, // RTF
  131. iRtfNCRforNonASCII, // RTF with NCR for nonASCII
  132. iEmbObj, // Embedded Object
  133. iEmbSrc, // Embed Source
  134. iObtDesc, // Object Descriptor
  135. iLnkSrc, // Link Source
  136. iMfPict, // Metafile
  137. iDIB, // DIB
  138. iBitmap, // Bitmap
  139. iRtfNoObjs, // RTF with no objects
  140. iUnicodeFETC, // Unicode plain text
  141. iAnsiFETC, // ANSI plain text
  142. iFilename, // Filename
  143. iRtfAsTextFETC, // Pastes RTF as text
  144. iTxtObj, // Richedit Text
  145. iRichEdit // RichEdit Text w/formatting
  146. };
  147. #define cf_RICHEDIT g_rgFETC[iRichEdit].cfFormat
  148. #define cf_EMBEDDEDOBJECT g_rgFETC[iEmbObj].cfFormat
  149. #define cf_EMBEDSOURCE g_rgFETC[iEmbSrc].cfFormat
  150. #define cf_OBJECTDESCRIPTOR g_rgFETC[iObtDesc].cfFormat
  151. #define cf_LINKSOURCE g_rgFETC[iLnkSrc].cfFormat
  152. #define cf_RTF g_rgFETC[iRtfFETC].cfFormat
  153. #define cf_RTFUTF8 g_rgFETC[iRtfUtf8].cfFormat
  154. #define cf_RTFNCRFORNONASCII g_rgFETC[iRtfNCRforNonASCII].cfFormat
  155. #define cf_RTFNOOBJS g_rgFETC[iRtfNoObjs].cfFormat
  156. #define cf_TEXTOBJECT g_rgFETC[iTxtObj].cfFormat
  157. #define cf_RTFASTEXT g_rgFETC[iRtfAsTextFETC].cfFormat
  158. #define cf_FILENAME g_rgFETC[iFilename].cfFormat
  159. #endif // !__DXFROBJ_H__