1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dtrans.hxx"
30 #include <osl/diagnose.h>
31 #include "XNotifyingDataObject.hxx"
32 #include "..\clipb\WinClipbImpl.hxx"
33 #include "..\clipb\WinClipboard.hxx"
34 #include "..\..\inc\DtObjFactory.hxx"
35 
36 #ifdef __MINGW32__
37 #define __uuidof(I) IID_##I
38 #endif
39 
40 using namespace com::sun::star::datatransfer;
41 using namespace com::sun::star::datatransfer::clipboard;
42 using com::sun::star::uno::RuntimeException;
43 using com::sun::star::uno::Reference;
44 
45 
46 CXNotifyingDataObject::CXNotifyingDataObject(
47 	const IDataObjectPtr& aIDataObject,
48 	const Reference< XTransferable >& aXTransferable,
49 	const Reference< XClipboardOwner >& aXClipOwner,
50 	CWinClipbImpl* theWinClipImpl ) :
51 	m_nRefCnt( 0 ),
52 	m_aIDataObject( aIDataObject ),
53 	m_XTransferable( aXTransferable ),
54 	m_XClipboardOwner( aXClipOwner ),
55 	m_pWinClipImpl( theWinClipImpl )
56 {
57 }
58 
59 STDMETHODIMP CXNotifyingDataObject::QueryInterface( REFIID iid, LPVOID* ppvObject )
60 {
61 	if ( NULL == ppvObject )
62 		return E_INVALIDARG;
63 
64 	HRESULT hr = E_NOINTERFACE;
65 
66 	*ppvObject = NULL;
67 	if ( ( __uuidof( IUnknown ) == iid ) ||
68 		 ( __uuidof( IDataObject ) == iid ) )
69 	{
70 		*ppvObject = static_cast< IUnknown* >( this );
71 		( (LPUNKNOWN)*ppvObject )->AddRef( );
72 		hr = S_OK;
73 	}
74 
75 	return hr;
76 }
77 
78 STDMETHODIMP_(ULONG) CXNotifyingDataObject::AddRef( )
79 {
80 	return static_cast< ULONG >( InterlockedIncrement( &m_nRefCnt ) );
81 }
82 
83 STDMETHODIMP_(ULONG) CXNotifyingDataObject::Release( )
84 {
85 	ULONG nRefCnt =
86 		static_cast< ULONG >( InterlockedDecrement( &m_nRefCnt ) );
87 
88 	if ( 0 == nRefCnt )
89 	{
90 		if ( m_pWinClipImpl )
91 			m_pWinClipImpl->onReleaseDataObject( this );
92 
93 		delete this;
94 	}
95 
96 	return nRefCnt;
97 }
98 
99 STDMETHODIMP CXNotifyingDataObject::GetData( LPFORMATETC pFormatetc, LPSTGMEDIUM pmedium )
100 {
101     return m_aIDataObject->GetData(pFormatetc, pmedium);
102 }
103 
104 STDMETHODIMP CXNotifyingDataObject::EnumFormatEtc(
105 	DWORD dwDirection, IEnumFORMATETC** ppenumFormatetc )
106 {
107 	return m_aIDataObject->EnumFormatEtc(dwDirection, ppenumFormatetc);
108 }
109 
110 STDMETHODIMP CXNotifyingDataObject::QueryGetData( LPFORMATETC pFormatetc )
111 {
112 	return m_aIDataObject->QueryGetData(pFormatetc);
113 }
114 
115 STDMETHODIMP CXNotifyingDataObject::GetDataHere( LPFORMATETC lpFetc, LPSTGMEDIUM lpStgMedium )
116 {
117 	return m_aIDataObject->GetDataHere(lpFetc, lpStgMedium);
118 }
119 
120 STDMETHODIMP CXNotifyingDataObject::GetCanonicalFormatEtc( LPFORMATETC lpFetc, LPFORMATETC lpCanonicalFetc )
121 {
122 	return m_aIDataObject->GetCanonicalFormatEtc(lpFetc, lpCanonicalFetc);
123 }
124 
125 STDMETHODIMP CXNotifyingDataObject::SetData( LPFORMATETC lpFetc, LPSTGMEDIUM lpStgMedium, BOOL bRelease )
126 {
127 	return m_aIDataObject->SetData( lpFetc, lpStgMedium, bRelease );
128 }
129 
130 STDMETHODIMP CXNotifyingDataObject::DAdvise(
131 	LPFORMATETC lpFetc, DWORD advf, LPADVISESINK lpAdvSink, DWORD* pdwConnection )
132 {
133 	return m_aIDataObject->DAdvise( lpFetc, advf, lpAdvSink, pdwConnection );
134 }
135 
136 STDMETHODIMP CXNotifyingDataObject::DUnadvise( DWORD dwConnection )
137 {
138 	return m_aIDataObject->DUnadvise( dwConnection );
139 }
140 
141 STDMETHODIMP CXNotifyingDataObject::EnumDAdvise( LPENUMSTATDATA * ppenumAdvise )
142 {
143 	return m_aIDataObject->EnumDAdvise( ppenumAdvise );
144 }
145 
146 CXNotifyingDataObject::operator IDataObject*( )
147 {
148 	return static_cast< IDataObject* >( this );
149 }
150 
151 void SAL_CALL CXNotifyingDataObject::lostOwnership( )
152 {
153 	try
154 	{
155 		if (m_XClipboardOwner.is())
156 			m_XClipboardOwner->lostOwnership(
157 				static_cast<XClipboardEx*>(m_pWinClipImpl->m_pWinClipboard ), m_XTransferable);
158 	}
159 	catch(RuntimeException&)
160 	{
161 		OSL_ENSURE( sal_False, "RuntimeException caught" );
162 	}
163 }
164