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