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