1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <osl/diagnose.h>
21 #include <tools/diagnose_ex.h>
22 #include "XNotifyingDataObject.hxx"
23 #include "WinClipboard.hxx"
24 
25 using namespace com::sun::star::datatransfer;
26 using namespace com::sun::star::datatransfer::clipboard;
27 using com::sun::star::uno::RuntimeException;
28 using com::sun::star::uno::Reference;
29 
CXNotifyingDataObject(const IDataObjectPtr & aIDataObject,const Reference<XTransferable> & aXTransferable,const Reference<XClipboardOwner> & aXClipOwner,CWinClipboard * const theWinClipoard)30 CXNotifyingDataObject::CXNotifyingDataObject(
31     const IDataObjectPtr& aIDataObject,
32     const Reference< XTransferable >& aXTransferable,
33     const Reference< XClipboardOwner >& aXClipOwner,
34     CWinClipboard* const theWinClipoard) :
35     m_nRefCnt( 0 ),
36     m_aIDataObject( aIDataObject ),
37     m_XTransferable( aXTransferable ),
38     m_XClipboardOwner( aXClipOwner ),
39     m_pWinClipImpl( theWinClipoard )
40 {
41 }
42 
QueryInterface(REFIID iid,void ** ppvObject)43 STDMETHODIMP CXNotifyingDataObject::QueryInterface( REFIID iid, void** ppvObject )
44 {
45     if ( nullptr == ppvObject )
46         return E_INVALIDARG;
47 
48     HRESULT hr = E_NOINTERFACE;
49 
50     *ppvObject = nullptr;
51     if ( ( __uuidof( IUnknown ) == iid ) ||
52          ( __uuidof( IDataObject ) == iid ) )
53     {
54         *ppvObject = static_cast< IUnknown* >( this );
55         static_cast<LPUNKNOWN>(*ppvObject)->AddRef( );
56         hr = S_OK;
57     }
58 
59     return hr;
60 }
61 
STDMETHODIMP_(ULONG)62 STDMETHODIMP_(ULONG) CXNotifyingDataObject::AddRef( )
63 {
64     return static_cast< ULONG >( InterlockedIncrement( &m_nRefCnt ) );
65 }
66 
STDMETHODIMP_(ULONG)67 STDMETHODIMP_(ULONG) CXNotifyingDataObject::Release( )
68 {
69     ULONG nRefCnt =
70         static_cast< ULONG >( InterlockedDecrement( &m_nRefCnt ) );
71 
72     if ( 0 == nRefCnt )
73     {
74         if ( m_pWinClipImpl )
75             m_pWinClipImpl->onReleaseDataObject( this );
76 
77         delete this;
78     }
79 
80     return nRefCnt;
81 }
82 
GetData(FORMATETC * pFormatetc,STGMEDIUM * pmedium)83 STDMETHODIMP CXNotifyingDataObject::GetData( FORMATETC * pFormatetc, STGMEDIUM * pmedium )
84 {
85     return m_aIDataObject->GetData(pFormatetc, pmedium);
86 }
87 
EnumFormatEtc(DWORD dwDirection,IEnumFORMATETC ** ppenumFormatetc)88 STDMETHODIMP CXNotifyingDataObject::EnumFormatEtc(
89     DWORD dwDirection, IEnumFORMATETC** ppenumFormatetc )
90 {
91     return m_aIDataObject->EnumFormatEtc(dwDirection, ppenumFormatetc);
92 }
93 
QueryGetData(FORMATETC * pFormatetc)94 STDMETHODIMP CXNotifyingDataObject::QueryGetData( FORMATETC * pFormatetc )
95 {
96     return m_aIDataObject->QueryGetData(pFormatetc);
97 }
98 
GetDataHere(FORMATETC * lpFetc,STGMEDIUM * lpStgMedium)99 STDMETHODIMP CXNotifyingDataObject::GetDataHere( FORMATETC * lpFetc, STGMEDIUM * lpStgMedium )
100 {
101     return m_aIDataObject->GetDataHere(lpFetc, lpStgMedium);
102 }
103 
GetCanonicalFormatEtc(FORMATETC * lpFetc,FORMATETC * lpCanonicalFetc)104 STDMETHODIMP CXNotifyingDataObject::GetCanonicalFormatEtc( FORMATETC * lpFetc, FORMATETC * lpCanonicalFetc )
105 {
106     return m_aIDataObject->GetCanonicalFormatEtc(lpFetc, lpCanonicalFetc);
107 }
108 
SetData(FORMATETC * lpFetc,STGMEDIUM * lpStgMedium,BOOL bRelease)109 STDMETHODIMP CXNotifyingDataObject::SetData( FORMATETC * lpFetc, STGMEDIUM * lpStgMedium, BOOL bRelease )
110 {
111     return m_aIDataObject->SetData( lpFetc, lpStgMedium, bRelease );
112 }
113 
DAdvise(FORMATETC * lpFetc,DWORD advf,IAdviseSink * lpAdvSink,DWORD * pdwConnection)114 STDMETHODIMP CXNotifyingDataObject::DAdvise(
115     FORMATETC * lpFetc, DWORD advf, IAdviseSink * lpAdvSink, DWORD* pdwConnection )
116 {
117     return m_aIDataObject->DAdvise( lpFetc, advf, lpAdvSink, pdwConnection );
118 }
119 
DUnadvise(DWORD dwConnection)120 STDMETHODIMP CXNotifyingDataObject::DUnadvise( DWORD dwConnection )
121 {
122     return m_aIDataObject->DUnadvise( dwConnection );
123 }
124 
EnumDAdvise(IEnumSTATDATA ** ppenumAdvise)125 STDMETHODIMP CXNotifyingDataObject::EnumDAdvise( IEnumSTATDATA ** ppenumAdvise )
126 {
127     return m_aIDataObject->EnumDAdvise( ppenumAdvise );
128 }
129 
operator IDataObject*()130 CXNotifyingDataObject::operator IDataObject*( )
131 {
132     return static_cast< IDataObject* >( this );
133 }
134 
lostOwnership()135 void CXNotifyingDataObject::lostOwnership( )
136 {
137     try
138     {
139         if (m_XClipboardOwner.is())
140             m_XClipboardOwner->lostOwnership(
141                 static_cast<XClipboardEx*>(m_pWinClipImpl), m_XTransferable);
142     }
143     catch(RuntimeException&)
144     {
145         TOOLS_WARN_EXCEPTION( "vcl",  "" );
146     }
147 }
148 
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
150