1*48123e16SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*48123e16SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*48123e16SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*48123e16SAndrew Rist  * distributed with this work for additional information
6*48123e16SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*48123e16SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*48123e16SAndrew Rist  * "License"); you may not use this file except in compliance
9*48123e16SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*48123e16SAndrew Rist  *
11*48123e16SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*48123e16SAndrew Rist  *
13*48123e16SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*48123e16SAndrew Rist  * software distributed under the License is distributed on an
15*48123e16SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*48123e16SAndrew Rist  * KIND, either express or implied.  See the License for the
17*48123e16SAndrew Rist  * specific language governing permissions and limitations
18*48123e16SAndrew Rist  * under the License.
19*48123e16SAndrew Rist  *
20*48123e16SAndrew Rist  *************************************************************/
21*48123e16SAndrew Rist 
22*48123e16SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dtrans.hxx"
26cdf0e10cSrcweir #include <osl/diagnose.h>
27cdf0e10cSrcweir #include "XNotifyingDataObject.hxx"
28cdf0e10cSrcweir #include "..\clipb\WinClipbImpl.hxx"
29cdf0e10cSrcweir #include "..\clipb\WinClipboard.hxx"
30cdf0e10cSrcweir #include "..\..\inc\DtObjFactory.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #ifdef __MINGW32__
33cdf0e10cSrcweir #define __uuidof(I) IID_##I
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir 
36cdf0e10cSrcweir using namespace com::sun::star::datatransfer;
37cdf0e10cSrcweir using namespace com::sun::star::datatransfer::clipboard;
38cdf0e10cSrcweir using com::sun::star::uno::RuntimeException;
39cdf0e10cSrcweir using com::sun::star::uno::Reference;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 
CXNotifyingDataObject(const IDataObjectPtr & aIDataObject,const Reference<XTransferable> & aXTransferable,const Reference<XClipboardOwner> & aXClipOwner,CWinClipbImpl * theWinClipImpl)42cdf0e10cSrcweir CXNotifyingDataObject::CXNotifyingDataObject(
43cdf0e10cSrcweir 	const IDataObjectPtr& aIDataObject,
44cdf0e10cSrcweir 	const Reference< XTransferable >& aXTransferable,
45cdf0e10cSrcweir 	const Reference< XClipboardOwner >& aXClipOwner,
46cdf0e10cSrcweir 	CWinClipbImpl* theWinClipImpl ) :
47cdf0e10cSrcweir 	m_nRefCnt( 0 ),
48cdf0e10cSrcweir 	m_aIDataObject( aIDataObject ),
49cdf0e10cSrcweir 	m_XTransferable( aXTransferable ),
50cdf0e10cSrcweir 	m_XClipboardOwner( aXClipOwner ),
51cdf0e10cSrcweir 	m_pWinClipImpl( theWinClipImpl )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
QueryInterface(REFIID iid,LPVOID * ppvObject)55cdf0e10cSrcweir STDMETHODIMP CXNotifyingDataObject::QueryInterface( REFIID iid, LPVOID* ppvObject )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir 	if ( NULL == ppvObject )
58cdf0e10cSrcweir 		return E_INVALIDARG;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 	HRESULT hr = E_NOINTERFACE;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 	*ppvObject = NULL;
63cdf0e10cSrcweir 	if ( ( __uuidof( IUnknown ) == iid ) ||
64cdf0e10cSrcweir 		 ( __uuidof( IDataObject ) == iid ) )
65cdf0e10cSrcweir 	{
66cdf0e10cSrcweir 		*ppvObject = static_cast< IUnknown* >( this );
67cdf0e10cSrcweir 		( (LPUNKNOWN)*ppvObject )->AddRef( );
68cdf0e10cSrcweir 		hr = S_OK;
69cdf0e10cSrcweir 	}
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	return hr;
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
STDMETHODIMP_(ULONG)74cdf0e10cSrcweir STDMETHODIMP_(ULONG) CXNotifyingDataObject::AddRef( )
75cdf0e10cSrcweir {
76cdf0e10cSrcweir 	return static_cast< ULONG >( InterlockedIncrement( &m_nRefCnt ) );
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
STDMETHODIMP_(ULONG)79cdf0e10cSrcweir STDMETHODIMP_(ULONG) CXNotifyingDataObject::Release( )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir 	ULONG nRefCnt =
82cdf0e10cSrcweir 		static_cast< ULONG >( InterlockedDecrement( &m_nRefCnt ) );
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 	if ( 0 == nRefCnt )
85cdf0e10cSrcweir 	{
86cdf0e10cSrcweir 		if ( m_pWinClipImpl )
87cdf0e10cSrcweir 			m_pWinClipImpl->onReleaseDataObject( this );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 		delete this;
90cdf0e10cSrcweir 	}
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 	return nRefCnt;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
GetData(LPFORMATETC pFormatetc,LPSTGMEDIUM pmedium)95cdf0e10cSrcweir STDMETHODIMP CXNotifyingDataObject::GetData( LPFORMATETC pFormatetc, LPSTGMEDIUM pmedium )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir     return m_aIDataObject->GetData(pFormatetc, pmedium);
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
EnumFormatEtc(DWORD dwDirection,IEnumFORMATETC ** ppenumFormatetc)100cdf0e10cSrcweir STDMETHODIMP CXNotifyingDataObject::EnumFormatEtc(
101cdf0e10cSrcweir 	DWORD dwDirection, IEnumFORMATETC** ppenumFormatetc )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir 	return m_aIDataObject->EnumFormatEtc(dwDirection, ppenumFormatetc);
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
QueryGetData(LPFORMATETC pFormatetc)106cdf0e10cSrcweir STDMETHODIMP CXNotifyingDataObject::QueryGetData( LPFORMATETC pFormatetc )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir 	return m_aIDataObject->QueryGetData(pFormatetc);
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
GetDataHere(LPFORMATETC lpFetc,LPSTGMEDIUM lpStgMedium)111cdf0e10cSrcweir STDMETHODIMP CXNotifyingDataObject::GetDataHere( LPFORMATETC lpFetc, LPSTGMEDIUM lpStgMedium )
112cdf0e10cSrcweir {
113cdf0e10cSrcweir 	return m_aIDataObject->GetDataHere(lpFetc, lpStgMedium);
114cdf0e10cSrcweir }
115cdf0e10cSrcweir 
GetCanonicalFormatEtc(LPFORMATETC lpFetc,LPFORMATETC lpCanonicalFetc)116cdf0e10cSrcweir STDMETHODIMP CXNotifyingDataObject::GetCanonicalFormatEtc( LPFORMATETC lpFetc, LPFORMATETC lpCanonicalFetc )
117cdf0e10cSrcweir {
118cdf0e10cSrcweir 	return m_aIDataObject->GetCanonicalFormatEtc(lpFetc, lpCanonicalFetc);
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
SetData(LPFORMATETC lpFetc,LPSTGMEDIUM lpStgMedium,BOOL bRelease)121cdf0e10cSrcweir STDMETHODIMP CXNotifyingDataObject::SetData( LPFORMATETC lpFetc, LPSTGMEDIUM lpStgMedium, BOOL bRelease )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir 	return m_aIDataObject->SetData( lpFetc, lpStgMedium, bRelease );
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
DAdvise(LPFORMATETC lpFetc,DWORD advf,LPADVISESINK lpAdvSink,DWORD * pdwConnection)126cdf0e10cSrcweir STDMETHODIMP CXNotifyingDataObject::DAdvise(
127cdf0e10cSrcweir 	LPFORMATETC lpFetc, DWORD advf, LPADVISESINK lpAdvSink, DWORD* pdwConnection )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir 	return m_aIDataObject->DAdvise( lpFetc, advf, lpAdvSink, pdwConnection );
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
DUnadvise(DWORD dwConnection)132cdf0e10cSrcweir STDMETHODIMP CXNotifyingDataObject::DUnadvise( DWORD dwConnection )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir 	return m_aIDataObject->DUnadvise( dwConnection );
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
EnumDAdvise(LPENUMSTATDATA * ppenumAdvise)137cdf0e10cSrcweir STDMETHODIMP CXNotifyingDataObject::EnumDAdvise( LPENUMSTATDATA * ppenumAdvise )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir 	return m_aIDataObject->EnumDAdvise( ppenumAdvise );
140cdf0e10cSrcweir }
141cdf0e10cSrcweir 
operator IDataObject*()142cdf0e10cSrcweir CXNotifyingDataObject::operator IDataObject*( )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir 	return static_cast< IDataObject* >( this );
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
lostOwnership()147cdf0e10cSrcweir void SAL_CALL CXNotifyingDataObject::lostOwnership( )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir 	try
150cdf0e10cSrcweir 	{
151cdf0e10cSrcweir 		if (m_XClipboardOwner.is())
152cdf0e10cSrcweir 			m_XClipboardOwner->lostOwnership(
153cdf0e10cSrcweir 				static_cast<XClipboardEx*>(m_pWinClipImpl->m_pWinClipboard ), m_XTransferable);
154cdf0e10cSrcweir 	}
155cdf0e10cSrcweir 	catch(RuntimeException&)
156cdf0e10cSrcweir 	{
157cdf0e10cSrcweir 		OSL_ENSURE( sal_False, "RuntimeException caught" );
158cdf0e10cSrcweir 	}
159cdf0e10cSrcweir }
160