Update ooo320-m1
[ooovba.git] / dtrans / source / win32 / dtobj / XTDataObject.hxx
blob598458cf92e1620e5b0c604a3a4612254062f07e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XTDataObject.hxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #ifndef _XTDATAOBJECT_HXX_
33 #define _XTDATAOBJECT_HXX_
36 //------------------------------------------------------------------------
37 // includes
38 //------------------------------------------------------------------------
40 #include <com/sun/star/datatransfer/XTransferable.hpp>
41 #include <com/sun/star/datatransfer/clipboard/XClipboardOwner.hpp>
43 #ifndef _DATAFORMATTRANSLATOR_HXX_
44 #include "DataFmtTransl.hxx"
45 #endif
47 #ifndef _FETCLIST_HXX_
48 #include "FEtcList.hxx"
49 #endif
51 #if defined _MSC_VER
52 #pragma warning(push,1)
53 #endif
54 #include <windows.h>
55 #include <ole2.h>
56 #include <objidl.h>
57 #if defined _MSC_VER
58 #pragma warning(pop)
59 #endif
61 /*--------------------------------------------------------------------------
62 - the function principle of the windows clipboard:
63 a data provider offers all formats he can deliver on the clipboard
64 a clipboard client ask for the available formats on the clipboard
65 and decides if there is a format he can use
66 if there is one, he requests the data in this format
68 - This class inherits from IDataObject an so can be placed on the
69 OleClipboard. The class wrapps a transferable object which is the
70 original DataSource
71 - DataFlavors offerd by this transferable will be translated into
72 appropriate clipboard formats
73 - if the transferable contains text data always text and unicodetext
74 will be offered or vice versa
75 - text data will be automaticaly converted between text und unicode text
76 - although the transferable may support text in different charsets
77 (codepages) only text in one codepage can be offered by the clipboard
79 ----------------------------------------------------------------------------*/
81 class CStgTransferHelper;
83 class CXTDataObject : public IDataObject
85 public:
86 CXTDataObject( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aServiceManager,
87 const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >& aXTransferable );
88 virtual ~CXTDataObject() {}
90 //-----------------------------------------------------------------
91 // ole interface implementation
92 //-----------------------------------------------------------------
94 //IUnknown interface methods
95 STDMETHODIMP QueryInterface(REFIID iid, LPVOID* ppvObject);
96 STDMETHODIMP_( ULONG ) AddRef( );
97 STDMETHODIMP_( ULONG ) Release( );
99 // IDataObject interface methods
100 STDMETHODIMP GetData( LPFORMATETC pFormatetc, LPSTGMEDIUM pmedium );
101 STDMETHODIMP GetDataHere( LPFORMATETC pFormatetc, LPSTGMEDIUM pmedium );
102 STDMETHODIMP QueryGetData( LPFORMATETC pFormatetc );
103 STDMETHODIMP GetCanonicalFormatEtc( LPFORMATETC pFormatectIn, LPFORMATETC pFormatetcOut );
104 STDMETHODIMP SetData( LPFORMATETC pFormatetc, LPSTGMEDIUM pmedium, BOOL fRelease );
105 STDMETHODIMP EnumFormatEtc( DWORD dwDirection, IEnumFORMATETC** ppenumFormatetc );
106 STDMETHODIMP DAdvise( LPFORMATETC pFormatetc, DWORD advf, LPADVISESINK pAdvSink, DWORD* pdwConnection );
107 STDMETHODIMP DUnadvise( DWORD dwConnection );
108 STDMETHODIMP EnumDAdvise( LPENUMSTATDATA* ppenumAdvise );
110 operator IDataObject*( );
112 private:
113 com::sun::star::datatransfer::DataFlavor SAL_CALL formatEtcToDataFlavor( const FORMATETC& aFormatEtc ) const;
115 void SAL_CALL renderDataAndSetupStgMedium( const sal_Int8* lpStorage,
116 const FORMATETC& fetc,
117 sal_uInt32 nInitStgSize,
118 sal_uInt32 nBytesToTransfer,
119 STGMEDIUM& stgmedium );
121 void SAL_CALL renderLocaleAndSetupStgMedium( FORMATETC& fetc, STGMEDIUM& stgmedium );
122 void SAL_CALL renderUnicodeAndSetupStgMedium( FORMATETC& fetc, STGMEDIUM& stgmedium );
123 void SAL_CALL renderAnyDataAndSetupStgMedium( FORMATETC& fetc, STGMEDIUM& stgmedium );
125 HRESULT SAL_CALL renderSynthesizedFormatAndSetupStgMedium( FORMATETC& fetc, STGMEDIUM& stgmedium );
126 void SAL_CALL renderSynthesizedUnicodeAndSetupStgMedium( FORMATETC& fetc, STGMEDIUM& stgmedium );
127 void SAL_CALL renderSynthesizedTextAndSetupStgMedium( FORMATETC& fetc, STGMEDIUM& stgmedium );
128 void SAL_CALL renderSynthesizedHtmlAndSetupStgMedium( FORMATETC& fetc, STGMEDIUM& stgmedium );
130 void SAL_CALL setupStgMedium( const FORMATETC& fetc,
131 CStgTransferHelper& stgTransHlp,
132 STGMEDIUM& stgmedium );
134 void validateFormatEtc( LPFORMATETC lpFormatEtc ) const;
135 void SAL_CALL invalidateStgMedium( STGMEDIUM& stgmedium ) const;
137 HRESULT SAL_CALL translateStgExceptionCode( HRESULT hr ) const;
139 inline void SAL_CALL InitializeFormatEtcContainer( );
141 private:
142 LONG m_nRefCnt;
143 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_SrvMgr;
144 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > m_XTransferable;
145 CFormatEtcContainer m_FormatEtcContainer;
146 sal_Bool m_bFormatEtcContainerInitialized;
147 CDataFormatTranslator m_DataFormatTranslator;
148 CFormatRegistrar m_FormatRegistrar;
151 //------------------------------------------------------------------------
153 //------------------------------------------------------------------------
155 class CEnumFormatEtc : public IEnumFORMATETC
157 public:
158 CEnumFormatEtc( LPUNKNOWN lpUnkOuter, const CFormatEtcContainer& aFormatEtcContainer );
159 virtual ~CEnumFormatEtc() {}
161 // IUnknown
162 STDMETHODIMP QueryInterface( REFIID iid, LPVOID* ppvObject );
163 STDMETHODIMP_( ULONG ) AddRef( );
164 STDMETHODIMP_( ULONG ) Release( );
166 //IEnumFORMATETC
167 STDMETHODIMP Next( ULONG nRequested, LPFORMATETC lpDest, ULONG* lpFetched );
168 STDMETHODIMP Skip( ULONG celt );
169 STDMETHODIMP Reset( );
170 STDMETHODIMP Clone( IEnumFORMATETC** ppenum );
172 private:
173 LONG m_nRefCnt;
174 LPUNKNOWN m_lpUnkOuter;
175 CFormatEtcContainer m_FormatEtcContainer;
178 typedef CEnumFormatEtc *PCEnumFormatEtc;
180 #endif