update dev300-m58
[ooovba.git] / dtrans / source / win32 / dtobj / XNotifyingDataObject.cxx
blob60d45203b7e83bcc41cd9722b69bbb9070a8da2d
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: XNotifyingDataObject.cxx,v $
10 * $Revision: 1.7 $
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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dtrans.hxx"
33 #include <osl/diagnose.h>
34 #include "XNotifyingDataObject.hxx"
35 #include "..\clipb\WinClipbImpl.hxx"
36 #include "..\clipb\WinClipboard.hxx"
37 #include "..\..\inc\DtObjFactory.hxx"
39 #ifdef __MINGW32__
40 #define __uuidof(I) IID_##I
41 #endif
43 using namespace com::sun::star::datatransfer;
44 using namespace com::sun::star::datatransfer::clipboard;
45 using com::sun::star::uno::RuntimeException;
46 using com::sun::star::uno::Reference;
49 CXNotifyingDataObject::CXNotifyingDataObject(
50 const IDataObjectPtr& aIDataObject,
51 const Reference< XTransferable >& aXTransferable,
52 const Reference< XClipboardOwner >& aXClipOwner,
53 CWinClipbImpl* theWinClipImpl ) :
54 m_nRefCnt( 0 ),
55 m_aIDataObject( aIDataObject ),
56 m_XTransferable( aXTransferable ),
57 m_XClipboardOwner( aXClipOwner ),
58 m_pWinClipImpl( theWinClipImpl )
62 STDMETHODIMP CXNotifyingDataObject::QueryInterface( REFIID iid, LPVOID* ppvObject )
64 if ( NULL == ppvObject )
65 return E_INVALIDARG;
67 HRESULT hr = E_NOINTERFACE;
69 *ppvObject = NULL;
70 if ( ( __uuidof( IUnknown ) == iid ) ||
71 ( __uuidof( IDataObject ) == iid ) )
73 *ppvObject = static_cast< IUnknown* >( this );
74 ( (LPUNKNOWN)*ppvObject )->AddRef( );
75 hr = S_OK;
78 return hr;
81 STDMETHODIMP_(ULONG) CXNotifyingDataObject::AddRef( )
83 return static_cast< ULONG >( InterlockedIncrement( &m_nRefCnt ) );
86 STDMETHODIMP_(ULONG) CXNotifyingDataObject::Release( )
88 ULONG nRefCnt =
89 static_cast< ULONG >( InterlockedDecrement( &m_nRefCnt ) );
91 if ( 0 == nRefCnt )
93 if ( m_pWinClipImpl )
94 m_pWinClipImpl->onReleaseDataObject( this );
96 delete this;
99 return nRefCnt;
102 STDMETHODIMP CXNotifyingDataObject::GetData( LPFORMATETC pFormatetc, LPSTGMEDIUM pmedium )
104 return m_aIDataObject->GetData(pFormatetc, pmedium);
107 STDMETHODIMP CXNotifyingDataObject::EnumFormatEtc(
108 DWORD dwDirection, IEnumFORMATETC** ppenumFormatetc )
110 return m_aIDataObject->EnumFormatEtc(dwDirection, ppenumFormatetc);
113 STDMETHODIMP CXNotifyingDataObject::QueryGetData( LPFORMATETC pFormatetc )
115 return m_aIDataObject->QueryGetData(pFormatetc);
118 STDMETHODIMP CXNotifyingDataObject::GetDataHere( LPFORMATETC lpFetc, LPSTGMEDIUM lpStgMedium )
120 return m_aIDataObject->GetDataHere(lpFetc, lpStgMedium);
123 STDMETHODIMP CXNotifyingDataObject::GetCanonicalFormatEtc( LPFORMATETC lpFetc, LPFORMATETC lpCanonicalFetc )
125 return m_aIDataObject->GetCanonicalFormatEtc(lpFetc, lpCanonicalFetc);
128 STDMETHODIMP CXNotifyingDataObject::SetData( LPFORMATETC lpFetc, LPSTGMEDIUM lpStgMedium, BOOL bRelease )
130 return m_aIDataObject->SetData( lpFetc, lpStgMedium, bRelease );
133 STDMETHODIMP CXNotifyingDataObject::DAdvise(
134 LPFORMATETC lpFetc, DWORD advf, LPADVISESINK lpAdvSink, DWORD* pdwConnection )
136 return m_aIDataObject->DAdvise( lpFetc, advf, lpAdvSink, pdwConnection );
139 STDMETHODIMP CXNotifyingDataObject::DUnadvise( DWORD dwConnection )
141 return m_aIDataObject->DUnadvise( dwConnection );
144 STDMETHODIMP CXNotifyingDataObject::EnumDAdvise( LPENUMSTATDATA * ppenumAdvise )
146 return m_aIDataObject->EnumDAdvise( ppenumAdvise );
149 CXNotifyingDataObject::operator IDataObject*( )
151 return static_cast< IDataObject* >( this );
154 void SAL_CALL CXNotifyingDataObject::lostOwnership( )
158 if (m_XClipboardOwner.is())
159 m_XClipboardOwner->lostOwnership(
160 static_cast<XClipboardEx*>(m_pWinClipImpl->m_pWinClipboard ), m_XTransferable);
162 catch(RuntimeException&)
164 OSL_ENSURE( sal_False, "RuntimeException caught" );