LibreOffice Module vcl (master)  1
dtranscomp.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/mutex.hxx>
21 
22 #include <vcl/svapp.hxx>
23 
24 #include <factory.hxx>
25 #include <svdata.hxx>
26 #include <salinst.hxx>
27 
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
31 #include <com/sun/star/lang/XInitialization.hpp>
32 #include <com/sun/star/datatransfer/XTransferable.hpp>
33 #include <com/sun/star/datatransfer/clipboard/XClipboardListener.hpp>
34 #include <com/sun/star/datatransfer/clipboard/XSystemClipboard.hpp>
35 #include <com/sun/star/datatransfer/dnd/XDragSource.hpp>
36 #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
37 #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
38 
39 #include <cppuhelper/compbase.hxx>
41 
42 using namespace com::sun::star;
43 using namespace com::sun::star::uno;
44 using namespace com::sun::star::lang;
45 
46 namespace vcl
47 {
48 // generic implementation to satisfy SalInstance
50  public cppu::WeakComponentImplHelper<
51  datatransfer::clipboard::XSystemClipboard,
52  XServiceInfo
53  >
54 {
55  osl::Mutex m_aMutex;
58  std::vector< Reference< css::datatransfer::clipboard::XClipboardListener > > m_aListeners;
59 
60 public:
61 
62  GenericClipboard() : cppu::WeakComponentImplHelper<
63  datatransfer::clipboard::XSystemClipboard,
64  XServiceInfo
65  >( m_aMutex )
66  {}
67 
68  /*
69  * XServiceInfo
70  */
71 
72  virtual OUString SAL_CALL getImplementationName() override;
73  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
74  virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
75 
76  static Sequence< OUString > getSupportedServiceNames_static();
77 
78  /*
79  * XClipboard
80  */
81 
82  virtual Reference< css::datatransfer::XTransferable > SAL_CALL getContents() override;
83 
84  virtual void SAL_CALL setContents(
86  const Reference< css::datatransfer::clipboard::XClipboardOwner >& xClipboardOwner ) override;
87 
88  virtual OUString SAL_CALL getName() override;
89 
90  /*
91  * XClipboardEx
92  */
93 
94  virtual sal_Int8 SAL_CALL getRenderingCapabilities() override;
95 
96  /*
97  * XClipboardNotifier
98  */
99  virtual void SAL_CALL addClipboardListener(
101 
102  virtual void SAL_CALL removeClipboardListener(
104 };
105 
106 Sequence< OUString > GenericClipboard::getSupportedServiceNames_static()
107 {
108  Sequence< OUString > aRet { "com.sun.star.datatransfer.clipboard.SystemClipboard" };
109  return aRet;
110 }
111 
112 OUString GenericClipboard::getImplementationName()
113 {
114  return "com.sun.star.datatransfer.VCLGenericClipboard";
115 }
116 
117 Sequence< OUString > GenericClipboard::getSupportedServiceNames()
118 {
119  return getSupportedServiceNames_static();
120 }
121 
122 sal_Bool GenericClipboard::supportsService( const OUString& ServiceName )
123 {
124  return cppu::supportsService(this, ServiceName);
125 }
126 
127 Reference< css::datatransfer::XTransferable > GenericClipboard::getContents()
128 {
129  return m_aContents;
130 }
131 
132 void GenericClipboard::setContents(
135 {
136  osl::ClearableMutexGuard aGuard( m_aMutex );
138  Reference< datatransfer::XTransferable > xOldContents( m_aContents );
139  m_aContents = xTrans;
140  m_aOwner = xClipboardOwner;
141 
142  std::vector< Reference< datatransfer::clipboard::XClipboardListener > > aListeners( m_aListeners );
143  datatransfer::clipboard::ClipboardEvent aEv;
144  aEv.Contents = m_aContents;
145 
146  aGuard.clear();
147 
148  if( xOldOwner.is() && xOldOwner != xClipboardOwner )
149  xOldOwner->lostOwnership( this, xOldContents );
150  for (auto const& listener : aListeners)
151  {
152  listener->changedContents( aEv );
153  }
154 }
155 
156 OUString GenericClipboard::getName()
157 {
158  return "CLIPBOARD";
159 }
160 
161 sal_Int8 GenericClipboard::getRenderingCapabilities()
162 {
163  return 0;
164 }
165 
166 void GenericClipboard::addClipboardListener( const Reference< datatransfer::clipboard::XClipboardListener >& listener )
167 {
168  osl::MutexGuard aGuard(m_aMutex);
169 
170  m_aListeners.push_back( listener );
171 }
172 
173 void GenericClipboard::removeClipboardListener( const Reference< datatransfer::clipboard::XClipboardListener >& listener )
174 {
175  osl::MutexGuard aGuard(m_aMutex);
176 
177  m_aListeners.erase(std::remove(m_aListeners.begin(), m_aListeners.end(), listener), m_aListeners.end());
178 }
179 
180 class ClipboardFactory : public ::cppu::WeakComponentImplHelper<
181  css::lang::XSingleServiceFactory
182 >
183 {
184  osl::Mutex m_aMutex;
185 public:
187 
188  /*
189  * XSingleServiceFactory
190  */
191  virtual Reference< XInterface > SAL_CALL createInstance() override;
192  virtual Reference< XInterface > SAL_CALL createInstanceWithArguments( const Sequence< Any >& rArgs ) override;
193 };
194 
195 ClipboardFactory::ClipboardFactory() :
196  cppu::WeakComponentImplHelper<
197  css::lang::XSingleServiceFactory
198 >( m_aMutex )
199 {
200 }
201 
203 {
205 }
206 
208 {
209  SolarMutexGuard aGuard;
211  return xResult;
212 }
213 
215 {
216  return
217  #if defined MACOSX
218  "com.sun.star.datatransfer.clipboard.AquaClipboard"
219  #elif defined IOS
220  "com.sun.star.datatransfer.clipboard.iOSClipboard"
221  #elif defined ANDROID
222  "com.sun.star.datatransfer.VCLGenericClipboard"
223  #elif defined UNX
224  "com.sun.star.datatransfer.X11ClipboardSupport"
225  #else
226  "com.sun.star.datatransfer.VCLGenericClipboard"
227  #endif
228  ;
229 }
230 
232 {
234 }
235 
236 /*
237 * generic DragSource dummy
238 */
239 class GenericDragSource : public cppu::WeakComponentImplHelper<
240  datatransfer::dnd::XDragSource,
241  XInitialization,
242  css::lang::XServiceInfo
243  >
244 {
245  osl::Mutex m_aMutex;
246 public:
247  GenericDragSource() : WeakComponentImplHelper( m_aMutex ) {}
248 
249  // XDragSource
250  virtual sal_Bool SAL_CALL isDragImageSupported() override;
251  virtual sal_Int32 SAL_CALL getDefaultCursor( sal_Int8 dragAction ) override;
252  virtual void SAL_CALL startDrag(
253  const datatransfer::dnd::DragGestureEvent& trigger,
254  sal_Int8 sourceActions, sal_Int32 cursor, sal_Int32 image,
255  const Reference< datatransfer::XTransferable >& transferable,
257  ) override;
258 
259  // XInitialization
260  virtual void SAL_CALL initialize( const Sequence< Any >& arguments ) override;
261 
262  OUString SAL_CALL getImplementationName() override
263  { return "com.sun.star.datatransfer.dnd.VclGenericDragSource"; }
264 
265  sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
266  { return cppu::supportsService(this, ServiceName); }
267 
268  css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
269  { return getSupportedServiceNames_static(); }
270 
272  {
273  Sequence<OUString> aRet { "com.sun.star.datatransfer.dnd.GenericDragSource" };
274  return aRet;
275  }
276 };
277 
279 {
280  return false;
281 }
282 
284 {
285  return 0;
286 }
287 
288 void GenericDragSource::startDrag( const datatransfer::dnd::DragGestureEvent&,
289  sal_Int8 /*sourceActions*/, sal_Int32 /*cursor*/, sal_Int32 /*image*/,
292  )
293 {
294  datatransfer::dnd::DragSourceDropEvent aEv;
295  aEv.DropAction = datatransfer::dnd::DNDConstants::ACTION_COPY;
296  aEv.DropSuccess = false;
297  listener->dragDropEnd( aEv );
298 }
299 
301 {
302 }
303 
305 {
306 #if defined MACOSX
307  return { "com.sun.star.datatransfer.dnd.OleDragSource" };
308 #elif defined UNX
309  return { "com.sun.star.datatransfer.dnd.X11DragSource" };
310 #else
311  return { "com.sun.star.datatransfer.dnd.VclGenericDragSource" };
312 #endif
313 }
314 
316 {
317 #if defined MACOSX
318  return "com.sun.star.comp.datatransfer.dnd.OleDragSource_V1";
319 #elif defined UNX
320  return "com.sun.star.datatransfer.dnd.XdndSupport";
321 #else
322  return "com.sun.star.datatransfer.dnd.VclGenericDragSource";
323 #endif
324 }
325 
327 {
328  SolarMutexGuard aGuard;
330  return xResult;
331 }
332 
333 /*
334 * generic DragSource dummy
335 */
336 
337 class GenericDropTarget : public cppu::WeakComponentImplHelper<
338  datatransfer::dnd::XDropTarget,
339  XInitialization,
340  css::lang::XServiceInfo
341  >
342 {
343  osl::Mutex m_aMutex;
344 public:
345  GenericDropTarget() : WeakComponentImplHelper( m_aMutex )
346  {}
347 
348  // XInitialization
349  virtual void SAL_CALL initialize( const Sequence< Any >& args ) override;
350 
351  // XDropTarget
354  virtual sal_Bool SAL_CALL isActive() override;
355  virtual void SAL_CALL setActive( sal_Bool active ) override;
356  virtual sal_Int8 SAL_CALL getDefaultActions() override;
357  virtual void SAL_CALL setDefaultActions( sal_Int8 actions ) override;
358 
359  OUString SAL_CALL getImplementationName() override
360  { return "com.sun.star.datatransfer.dnd.VclGenericDropTarget"; }
361 
362  sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
363  { return cppu::supportsService(this, ServiceName); }
364 
365  css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
366  { return getSupportedServiceNames_static(); }
367 
369  {
370  Sequence<OUString> aRet { "com.sun.star.datatransfer.dnd.GenericDropTarget" };
371  return aRet;
372  }
373 };
374 
376 {
377 }
378 
380 {
381 }
382 
384 {
385 }
386 
388 {
389  return false;
390 }
391 
393 {
394 }
395 
397 {
398  return 0;
399 }
400 
402 {
403 }
404 
406 {
407 #if defined MACOSX
408  return { "com.sun.star.datatransfer.dnd.OleDropTarget" };
409 #elif defined UNX
410  return { "com.sun.star.datatransfer.dnd.X11DropTarget" };
411 #else
413 #endif
414 }
415 
417 {
418  return
419  #if defined MACOSX
420  "com.sun.star.comp.datatransfer.dnd.OleDropTarget_V1"
421  #elif defined UNX
422  "com.sun.star.datatransfer.dnd.XdndDropTarget"
423  #else
424  "com.sun.star.datatransfer.dnd.VclGenericDropTarget"
425  #endif
426  ;
427 }
428 
430 {
431  SolarMutexGuard aGuard;
433  return xResult;
434 }
435 
436 } // namespace vcl
437 
438 /*
439 * SalInstance generic
440 */
442 {
443  return Reference< XInterface >( static_cast<cppu::OWeakObject *>(new vcl::GenericClipboard()) );
444 }
445 
447 {
448  return Reference< XInterface >( static_cast<cppu::OWeakObject *>(new vcl::GenericDragSource()) );
449 }
450 
452 {
453  return Reference< XInterface >( static_cast<cppu::OWeakObject *>(new vcl::GenericDropTarget()) );
454 }
455 
456 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::osl::Mutex m_aMutex
virtual void SAL_CALL startDrag(const datatransfer::dnd::DragGestureEvent &trigger, sal_Int8 sourceActions, sal_Int32 cursor, sal_Int32 image, const Reference< datatransfer::XTransferable > &transferable, const Reference< datatransfer::dnd::XDragSourceListener > &listener) override
Definition: dtranscomp.cxx:288
virtual css::uno::Reference< css::uno::XInterface > CreateDropTarget()
Definition: dtranscomp.cxx:451
Reference< css::datatransfer::XTransferable > m_aContents
Definition: dtranscomp.cxx:56
virtual css::uno::Reference< css::uno::XInterface > CreateClipboard(const css::uno::Sequence< css::uno::Any > &i_rArguments)
Definition: dtranscomp.cxx:441
signed char sal_Int8
Reference< XSingleServiceFactory > Clipboard_createFactory()
Definition: dtranscomp.cxx:231
virtual sal_Bool SAL_CALL isDragImageSupported() override
Definition: dtranscomp.cxx:278
Reference< css::datatransfer::clipboard::XClipboardOwner > m_aOwner
Definition: dtranscomp.cxx:57
OUString getImplementationName()
OUString DragSource_getImplementationName()
Definition: dtranscomp.cxx:315
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: dtranscomp.cxx:268
virtual sal_Int32 SAL_CALL getDefaultCursor(sal_Int8 dragAction) override
Definition: dtranscomp.cxx:283
virtual void SAL_CALL setActive(sal_Bool active) override
Definition: dtranscomp.cxx:392
OUString Clipboard_getImplementationName()
Definition: dtranscomp.cxx:214
OUString SAL_CALL getImplementationName() override
Definition: dtranscomp.cxx:359
virtual css::uno::Reference< css::uno::XInterface > CreateDragSource()
Definition: dtranscomp.cxx:446
sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
Definition: dtranscomp.cxx:265
sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
Definition: dtranscomp.cxx:362
static Sequence< OUString > getSupportedServiceNames_static()
Definition: dtranscomp.cxx:271
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Listeners aListeners
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:67
Sequence< OUString > DropTarget_getSupportedServiceNames()
Definition: dtranscomp.cxx:405
virtual Reference< XInterface > SAL_CALL createInstanceWithArguments(const Sequence< Any > &rArgs) override
Definition: dtranscomp.cxx:207
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString SAL_CALL getImplementationName() override
Definition: dtranscomp.cxx:262
Reference< XInterface > DragSource_createInstance(const Reference< XMultiServiceFactory > &)
Definition: dtranscomp.cxx:326
std::vector< Reference< css::datatransfer::clipboard::XClipboardListener > > m_aListeners
Definition: dtranscomp.cxx:58
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: dtranscomp.cxx:365
HRESULT createInstance(REFIID iid, Ifc **ppIfc)
unsigned char sal_Bool
virtual void SAL_CALL addDropTargetListener(const Reference< css::datatransfer::dnd::XDropTargetListener > &) override
Definition: dtranscomp.cxx:379
Sequence< OUString > DragSource_getSupportedServiceNames()
Definition: dtranscomp.cxx:304
virtual void SAL_CALL initialize(const Sequence< Any > &args) override
Definition: dtranscomp.cxx:375
virtual Reference< XInterface > SAL_CALL createInstance() override
Definition: dtranscomp.cxx:202
virtual sal_Int8 SAL_CALL getDefaultActions() override
Definition: dtranscomp.cxx:396
virtual sal_Bool SAL_CALL isActive() override
Definition: dtranscomp.cxx:387
virtual void SAL_CALL setDefaultActions(sal_Int8 actions) override
Definition: dtranscomp.cxx:401
OUString DropTarget_getImplementationName()
Definition: dtranscomp.cxx:416
virtual void SAL_CALL initialize(const Sequence< Any > &arguments) override
Definition: dtranscomp.cxx:300
virtual void SAL_CALL removeDropTargetListener(const Reference< css::datatransfer::dnd::XDropTargetListener > &) override
Definition: dtranscomp.cxx:383
static Sequence< OUString > getSupportedServiceNames_static()
Definition: dtranscomp.cxx:368
Reference< XInterface > DropTarget_createInstance(const Reference< XMultiServiceFactory > &)
Definition: dtranscomp.cxx:429
SalInstance * mpDefInst
Definition: svdata.hxx:336