LibreOffice Module dtrans (master)  1
generic_clipboard.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 "generic_clipboard.hxx"
21 #include <com/sun/star/lang/DisposedException.hpp>
22 #include <com/sun/star/datatransfer/clipboard/RenderingCapabilities.hpp>
23 #include <com/sun/star/uno/XComponentContext.hpp>
25 
26 using namespace com::sun::star::datatransfer;
28 using namespace com::sun::star::lang;
29 using namespace com::sun::star::uno;
30 using namespace cppu;
31 using namespace osl;
32 
33 using ::dtrans::GenericClipboard;
34 
35 GenericClipboard::GenericClipboard() :
36  WeakComponentImplHelper< XClipboardEx, XClipboardNotifier, XServiceInfo, XInitialization > (m_aMutex),
37  m_bInitialized(false)
38 {
39 }
40 
42 {
43 }
44 
45 void SAL_CALL GenericClipboard::initialize( const Sequence< Any >& aArguments )
46 {
47  if (!m_bInitialized)
48  {
49  for (Any const & arg : aArguments)
50  if (arg.getValueType() == cppu::UnoType<OUString>::get())
51  {
52  arg >>= m_aName;
53  break;
54  }
55  }
56 }
57 
59 {
60  return "com.sun.star.comp.datatransfer.clipboard.GenericClipboard";
61 }
62 
63 sal_Bool SAL_CALL GenericClipboard::supportsService( const OUString& ServiceName )
64 {
65  return cppu::supportsService(this, ServiceName);
66 }
67 
69 {
70  return { "com.sun.star.datatransfer.clipboard.GenericClipboard" };
71 }
72 
74 {
75  MutexGuard aGuard(m_aMutex);
76  return m_aContents;
77 }
78 
80  const Reference< XClipboardOwner >& xClipboardOwner )
81 {
82  // remember old values for callbacks before setting the new ones.
83  ClearableMutexGuard aGuard(m_aMutex);
84 
86  m_aOwner = xClipboardOwner;
87 
89  m_aContents = xTrans;
90 
91  aGuard.clear();
92 
93  // notify old owner on loss of ownership
94  if( oldOwner.is() )
95  oldOwner->lostOwnership(static_cast < XClipboard * > (this), oldContents);
96 
97  // notify all listeners on content changes
98  OInterfaceContainerHelper *pContainer =
99  rBHelper.aLC.getContainer(cppu::UnoType<XClipboardListener>::get());
100  if (pContainer)
101  {
102  ClipboardEvent aEvent(static_cast < XClipboard * > (this), m_aContents);
103  OInterfaceIteratorHelper aIterator(*pContainer);
104 
105  while (aIterator.hasMoreElements())
106  {
107  Reference < XClipboardListener > xListener(aIterator.next(), UNO_QUERY);
108  if (xListener.is())
109  xListener->changedContents(aEvent);
110  }
111  }
112 }
113 
114 OUString SAL_CALL GenericClipboard::getName()
115 {
116  return m_aName;
117 }
118 
120 {
121  return RenderingCapabilities::Delayed;
122 }
123 
125 {
126  MutexGuard aGuard( rBHelper.rMutex );
127  OSL_ENSURE( !rBHelper.bInDispose, "do not add listeners in the dispose call" );
128  OSL_ENSURE( !rBHelper.bDisposed, "object is disposed" );
129  if (!rBHelper.bInDispose && !rBHelper.bDisposed)
130  rBHelper.aLC.addInterface( cppu::UnoType<XClipboardListener>::get(), listener );
131 }
132 
134 {
135  MutexGuard aGuard( rBHelper.rMutex );
136  OSL_ENSURE( !rBHelper.bDisposed, "object is disposed" );
137  if (!rBHelper.bInDispose && !rBHelper.bDisposed)
138  rBHelper.aLC.removeInterface( cppu::UnoType<XClipboardListener>::get(), listener );
139 }
140 
141 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
143  css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
144 {
145  return cppu::acquire(static_cast<cppu::OWeakObject*>(new GenericClipboard()));
146 }
147 
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
osl::Mutex m_aMutex
signed char sal_Int8
virtual ~GenericClipboard() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::uno::XInterface *SAL_CALL next()
virtual void SAL_CALL removeClipboardListener(const css::uno::Reference< css::datatransfer::clipboard::XClipboardListener > &listener) override
css::uno::Reference< css::datatransfer::clipboard::XClipboardOwner > m_aOwner
virtual css::uno::Reference< css::datatransfer::XTransferable > SAL_CALL getContents() override
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
css::uno::Reference< css::datatransfer::XTransferable > m_aContents
virtual sal_Int8 SAL_CALL getRenderingCapabilities() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual OUString SAL_CALL getImplementationName() override
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * dtrans_GenericClipboard_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
unsigned char sal_Bool
css::uno::Type const & get()
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
virtual void SAL_CALL setContents(const css::uno::Reference< css::datatransfer::XTransferable > &xTrans, const css::uno::Reference< css::datatransfer::clipboard::XClipboardOwner > &xClipboardOwner) override
virtual OUString SAL_CALL getName() override
AnyEventRef aEvent
virtual void SAL_CALL addClipboardListener(const css::uno::Reference< css::datatransfer::clipboard::XClipboardListener > &listener) override
bool SAL_CALL hasMoreElements() const