LibreOffice Module dtrans (master)  1
XNotifyingDataObject.cxx
Go to the documentation of this file.
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 "XNotifyingDataObject.hxx"
22 #include "../clipb/WinClipbImpl.hxx"
23 #include "../clipb/WinClipboard.hxx"
24 
25 using namespace com::sun::star::datatransfer;
27 using com::sun::star::uno::RuntimeException;
29 
31  const IDataObjectPtr& aIDataObject,
32  const Reference< XTransferable >& aXTransferable,
33  const Reference< XClipboardOwner >& aXClipOwner,
34  CWinClipbImpl* theWinClipImpl ) :
35  m_nRefCnt( 0 ),
36  m_aIDataObject( aIDataObject ),
37  m_XTransferable( aXTransferable ),
38  m_XClipboardOwner( aXClipOwner ),
39  m_pWinClipImpl( theWinClipImpl )
40 {
41 }
42 
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 
63 {
64  return static_cast< ULONG >( InterlockedIncrement( &m_nRefCnt ) );
65 }
66 
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 
83 STDMETHODIMP CXNotifyingDataObject::GetData( FORMATETC * pFormatetc, STGMEDIUM * pmedium )
84 {
85  return m_aIDataObject->GetData(pFormatetc, pmedium);
86 }
87 
89  DWORD dwDirection, IEnumFORMATETC** ppenumFormatetc )
90 {
91  return m_aIDataObject->EnumFormatEtc(dwDirection, ppenumFormatetc);
92 }
93 
94 STDMETHODIMP CXNotifyingDataObject::QueryGetData( FORMATETC * pFormatetc )
95 {
96  return m_aIDataObject->QueryGetData(pFormatetc);
97 }
98 
99 STDMETHODIMP CXNotifyingDataObject::GetDataHere( FORMATETC * lpFetc, STGMEDIUM * lpStgMedium )
100 {
101  return m_aIDataObject->GetDataHere(lpFetc, lpStgMedium);
102 }
103 
104 STDMETHODIMP CXNotifyingDataObject::GetCanonicalFormatEtc( FORMATETC * lpFetc, FORMATETC * lpCanonicalFetc )
105 {
106  return m_aIDataObject->GetCanonicalFormatEtc(lpFetc, lpCanonicalFetc);
107 }
108 
109 STDMETHODIMP CXNotifyingDataObject::SetData( FORMATETC * lpFetc, STGMEDIUM * lpStgMedium, BOOL bRelease )
110 {
111  return m_aIDataObject->SetData( lpFetc, lpStgMedium, bRelease );
112 }
113 
115  FORMATETC * lpFetc, DWORD advf, IAdviseSink * lpAdvSink, DWORD* pdwConnection )
116 {
117  return m_aIDataObject->DAdvise( lpFetc, advf, lpAdvSink, pdwConnection );
118 }
119 
120 STDMETHODIMP CXNotifyingDataObject::DUnadvise( DWORD dwConnection )
121 {
122  return m_aIDataObject->DUnadvise( dwConnection );
123 }
124 
125 STDMETHODIMP CXNotifyingDataObject::EnumDAdvise( IEnumSTATDATA ** ppenumAdvise )
126 {
127  return m_aIDataObject->EnumDAdvise( ppenumAdvise );
128 }
129 
130 CXNotifyingDataObject::operator IDataObject*( )
131 {
132  return static_cast< IDataObject* >( this );
133 }
134 
136 {
137  try
138  {
139  if (m_XClipboardOwner.is())
140  m_XClipboardOwner->lostOwnership(
141  static_cast<XClipboardEx*>(m_pWinClipImpl->m_pWinClipboard ), m_XTransferable);
142  }
143  catch(RuntimeException&)
144  {
145  OSL_FAIL( "RuntimeException caught" );
146  }
147 }
148 
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
STDMETHODIMP EnumDAdvise(IEnumSTATDATA **ppenumAdvise) override
const css::uno::Reference< css::datatransfer::XTransferable > m_XTransferable
EXTERN_C BOOL BOOL const wchar_t *pProgramPath HRESULT hr
STDMETHODIMP QueryGetData(FORMATETC *pFormatetc) override
const css::uno::Reference< css::datatransfer::clipboard::XClipboardOwner > m_XClipboardOwner
STDMETHODIMP QueryInterface(REFIID iid, void **ppvObject) override
const wchar_t *typedef BOOL
STDMETHODIMP DUnadvise(DWORD dwConnection) override
STDMETHODIMP DAdvise(FORMATETC *pFormatetc, DWORD advf, IAdviseSink *pAdvSink, DWORD *pdwConnection) override
STDMETHODIMP GetData(FORMATETC *pFormatetc, STGMEDIUM *pmedium) override
STDMETHODIMP_(ULONG) CXNotifyingDataObject
STDMETHODIMP GetDataHere(FORMATETC *pFormatetc, STGMEDIUM *pmedium) override
STDMETHODIMP SetData(FORMATETC *pFormatetc, STGMEDIUM *pmedium, BOOL fRelease) override
STDMETHODIMP GetCanonicalFormatEtc(FORMATETC *pFormatectIn, FORMATETC *pFormatetcOut) override
CWinClipboard * m_pWinClipboard
CXNotifyingDataObject(const IDataObjectPtr &aIDataObject, const css::uno::Reference< css::datatransfer::XTransferable > &aXTransferable, const css::uno::Reference< css::datatransfer::clipboard::XClipboardOwner > &aXClipOwner, CWinClipbImpl *theWinClipImpl)
STDMETHODIMP EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC **ppenumFormatetc) override