xref: /trunk/main/dtrans/source/win32/dtobj/XTDataObject.hxx (revision c58c98639aee672dad53c365db9757a13bf51016)
1fbcf0fe9SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3fbcf0fe9SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4fbcf0fe9SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5fbcf0fe9SAndrew Rist  * distributed with this work for additional information
6fbcf0fe9SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7fbcf0fe9SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8fbcf0fe9SAndrew Rist  * "License"); you may not use this file except in compliance
9fbcf0fe9SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11fbcf0fe9SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13fbcf0fe9SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14fbcf0fe9SAndrew Rist  * software distributed under the License is distributed on an
15fbcf0fe9SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16fbcf0fe9SAndrew Rist  * KIND, either express or implied.  See the License for the
17fbcf0fe9SAndrew Rist  * specific language governing permissions and limitations
18fbcf0fe9SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20fbcf0fe9SAndrew Rist  *************************************************************/
21fbcf0fe9SAndrew Rist 
22fbcf0fe9SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _XTDATAOBJECT_HXX_
25cdf0e10cSrcweir #define _XTDATAOBJECT_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir //------------------------------------------------------------------------
29cdf0e10cSrcweir // includes
30cdf0e10cSrcweir //------------------------------------------------------------------------
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <com/sun/star/datatransfer/XTransferable.hpp>
33cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XClipboardOwner.hpp>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #ifndef _DATAFORMATTRANSLATOR_HXX_
36cdf0e10cSrcweir #include "DataFmtTransl.hxx"
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #ifndef _FETCLIST_HXX_
40cdf0e10cSrcweir #include "FetcList.hxx"
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #if defined _MSC_VER
44cdf0e10cSrcweir #pragma warning(push,1)
45cdf0e10cSrcweir #endif
46cdf0e10cSrcweir #include <windows.h>
47cdf0e10cSrcweir #include <ole2.h>
48cdf0e10cSrcweir #include <objidl.h>
49cdf0e10cSrcweir #if defined _MSC_VER
50cdf0e10cSrcweir #pragma warning(pop)
51cdf0e10cSrcweir #endif
52cdf0e10cSrcweir 
53cdf0e10cSrcweir /*--------------------------------------------------------------------------
54cdf0e10cSrcweir     - the function principle of the windows clipboard:
55cdf0e10cSrcweir       a data provider offers all formats he can deliver on the clipboard
56cdf0e10cSrcweir       a clipboard client ask for the available formats on the clipboard
57cdf0e10cSrcweir       and decides if there is a format he can use
58cdf0e10cSrcweir       if there is one, he requests the data in this format
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     - This class inherits from IDataObject an so can be placed on the
61*c58c9863Smseidel       OleClipboard. The class wraps a transferable object which is the
62cdf0e10cSrcweir       original DataSource
63*c58c9863Smseidel     - DataFlavors offered by this transferable will be translated into
64cdf0e10cSrcweir       appropriate clipboard formats
65cdf0e10cSrcweir     - if the transferable contains text data always text and unicodetext
66cdf0e10cSrcweir       will be offered or vice versa
67*c58c9863Smseidel     - text data will be automatically converted between text and unicode text
68cdf0e10cSrcweir     - although the transferable may support text in different charsets
69cdf0e10cSrcweir       (codepages) only text in one codepage can be offered by the clipboard
70cdf0e10cSrcweir 
71cdf0e10cSrcweir ----------------------------------------------------------------------------*/
72cdf0e10cSrcweir 
73cdf0e10cSrcweir class CStgTransferHelper;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir class CXTDataObject : public IDataObject
76cdf0e10cSrcweir {
77cdf0e10cSrcweir public:
78cdf0e10cSrcweir     CXTDataObject( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aServiceManager,
79cdf0e10cSrcweir                    const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >& aXTransferable );
~CXTDataObject()80cdf0e10cSrcweir     virtual ~CXTDataObject() {}
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     //-----------------------------------------------------------------
83cdf0e10cSrcweir     // ole interface implementation
84cdf0e10cSrcweir     //-----------------------------------------------------------------
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     //IUnknown interface methods
87cdf0e10cSrcweir     STDMETHODIMP           QueryInterface(REFIID iid, LPVOID* ppvObject);
88cdf0e10cSrcweir     STDMETHODIMP_( ULONG ) AddRef( );
89cdf0e10cSrcweir     STDMETHODIMP_( ULONG ) Release( );
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     // IDataObject interface methods
92cdf0e10cSrcweir     STDMETHODIMP GetData( LPFORMATETC pFormatetc, LPSTGMEDIUM pmedium );
93cdf0e10cSrcweir     STDMETHODIMP GetDataHere( LPFORMATETC pFormatetc, LPSTGMEDIUM pmedium );
94cdf0e10cSrcweir     STDMETHODIMP QueryGetData( LPFORMATETC pFormatetc );
95cdf0e10cSrcweir     STDMETHODIMP GetCanonicalFormatEtc( LPFORMATETC pFormatectIn, LPFORMATETC pFormatetcOut );
96cdf0e10cSrcweir     STDMETHODIMP SetData( LPFORMATETC pFormatetc, LPSTGMEDIUM pmedium, BOOL fRelease );
97cdf0e10cSrcweir     STDMETHODIMP EnumFormatEtc( DWORD dwDirection, IEnumFORMATETC** ppenumFormatetc );
98cdf0e10cSrcweir     STDMETHODIMP DAdvise( LPFORMATETC pFormatetc, DWORD advf, LPADVISESINK pAdvSink, DWORD* pdwConnection );
99cdf0e10cSrcweir     STDMETHODIMP DUnadvise( DWORD dwConnection );
100cdf0e10cSrcweir     STDMETHODIMP EnumDAdvise( LPENUMSTATDATA* ppenumAdvise );
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     operator IDataObject*( );
103cdf0e10cSrcweir 
104cdf0e10cSrcweir private:
105cdf0e10cSrcweir     com::sun::star::datatransfer::DataFlavor SAL_CALL formatEtcToDataFlavor( const FORMATETC& aFormatEtc ) const;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     void SAL_CALL renderDataAndSetupStgMedium( const sal_Int8* lpStorage,
108cdf0e10cSrcweir                                                const FORMATETC& fetc,
109cdf0e10cSrcweir                                                sal_uInt32 nInitStgSize,
110cdf0e10cSrcweir                                                sal_uInt32 nBytesToTransfer,
111cdf0e10cSrcweir                                                STGMEDIUM& stgmedium );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     void SAL_CALL renderLocaleAndSetupStgMedium( FORMATETC& fetc, STGMEDIUM& stgmedium );
114cdf0e10cSrcweir     void SAL_CALL renderUnicodeAndSetupStgMedium( FORMATETC& fetc, STGMEDIUM& stgmedium );
115cdf0e10cSrcweir     void SAL_CALL renderAnyDataAndSetupStgMedium( FORMATETC& fetc, STGMEDIUM& stgmedium );
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     HRESULT SAL_CALL renderSynthesizedFormatAndSetupStgMedium( FORMATETC& fetc, STGMEDIUM& stgmedium );
118cdf0e10cSrcweir     void    SAL_CALL renderSynthesizedUnicodeAndSetupStgMedium( FORMATETC& fetc, STGMEDIUM& stgmedium );
119cdf0e10cSrcweir     void    SAL_CALL renderSynthesizedTextAndSetupStgMedium( FORMATETC& fetc, STGMEDIUM& stgmedium );
120cdf0e10cSrcweir     void    SAL_CALL renderSynthesizedHtmlAndSetupStgMedium( FORMATETC& fetc, STGMEDIUM& stgmedium );
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     void SAL_CALL setupStgMedium( const FORMATETC& fetc,
123cdf0e10cSrcweir                                   CStgTransferHelper& stgTransHlp,
124cdf0e10cSrcweir                                   STGMEDIUM& stgmedium );
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     void validateFormatEtc( LPFORMATETC lpFormatEtc ) const;
127cdf0e10cSrcweir     void SAL_CALL invalidateStgMedium( STGMEDIUM& stgmedium ) const;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     HRESULT SAL_CALL translateStgExceptionCode( HRESULT hr ) const;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     inline void SAL_CALL InitializeFormatEtcContainer( );
132cdf0e10cSrcweir 
133cdf0e10cSrcweir private:
134cdf0e10cSrcweir     LONG m_nRefCnt;
135cdf0e10cSrcweir     const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_SrvMgr;
136cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >      m_XTransferable;
137cdf0e10cSrcweir     CFormatEtcContainer                                                                    m_FormatEtcContainer;
138cdf0e10cSrcweir     sal_Bool                                                                               m_bFormatEtcContainerInitialized;
139cdf0e10cSrcweir     CDataFormatTranslator                                                                  m_DataFormatTranslator;
140cdf0e10cSrcweir     CFormatRegistrar                                                                       m_FormatRegistrar;
141cdf0e10cSrcweir };
142cdf0e10cSrcweir 
143cdf0e10cSrcweir //------------------------------------------------------------------------
144cdf0e10cSrcweir //
145cdf0e10cSrcweir //------------------------------------------------------------------------
146cdf0e10cSrcweir 
147cdf0e10cSrcweir class CEnumFormatEtc : public IEnumFORMATETC
148cdf0e10cSrcweir {
149cdf0e10cSrcweir public:
150cdf0e10cSrcweir     CEnumFormatEtc( LPUNKNOWN lpUnkOuter, const CFormatEtcContainer& aFormatEtcContainer );
~CEnumFormatEtc()151cdf0e10cSrcweir     virtual ~CEnumFormatEtc() {}
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     // IUnknown
154cdf0e10cSrcweir     STDMETHODIMP           QueryInterface( REFIID iid, LPVOID* ppvObject );
155cdf0e10cSrcweir     STDMETHODIMP_( ULONG ) AddRef( );
156cdf0e10cSrcweir     STDMETHODIMP_( ULONG ) Release( );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     // IEnumFORMATETC
159cdf0e10cSrcweir     STDMETHODIMP Next( ULONG nRequested, LPFORMATETC lpDest, ULONG* lpFetched );
160cdf0e10cSrcweir     STDMETHODIMP Skip( ULONG celt );
161cdf0e10cSrcweir     STDMETHODIMP Reset( );
162cdf0e10cSrcweir     STDMETHODIMP Clone( IEnumFORMATETC** ppenum );
163cdf0e10cSrcweir 
164cdf0e10cSrcweir private:
165cdf0e10cSrcweir     LONG                m_nRefCnt;
166cdf0e10cSrcweir     LPUNKNOWN           m_lpUnkOuter;
167cdf0e10cSrcweir     CFormatEtcContainer m_FormatEtcContainer;
168cdf0e10cSrcweir };
169cdf0e10cSrcweir 
170cdf0e10cSrcweir typedef CEnumFormatEtc *PCEnumFormatEtc;
171cdf0e10cSrcweir 
172cdf0e10cSrcweir #endif
173