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_vcl.hxx" 30 31 #include "vos/mutex.hxx" 32 33 #include "osl/mutex.hxx" 34 35 #include "vcl/svapp.hxx" 36 37 #include "svdata.hxx" 38 #include "salinst.hxx" 39 40 #include "com/sun/star/lang/XServiceInfo.hpp" 41 #include "com/sun/star/lang/XSingleServiceFactory.hpp" 42 #include "com/sun/star/lang/XInitialization.hpp" 43 #include "com/sun/star/lang/DisposedException.hpp" 44 #include "com/sun/star/datatransfer/XTransferable.hpp" 45 #include "com/sun/star/datatransfer/clipboard/XClipboard.hpp" 46 #include "com/sun/star/datatransfer/clipboard/XClipboardEx.hpp" 47 #include "com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp" 48 #include "com/sun/star/datatransfer/clipboard/XClipboardListener.hpp" 49 #include "com/sun/star/datatransfer/dnd/XDragSource.hpp" 50 #include "com/sun/star/datatransfer/dnd/XDropTarget.hpp" 51 #include "com/sun/star/datatransfer/dnd/DNDConstants.hpp" 52 53 #include "cppuhelper/compbase1.hxx" 54 #include "cppuhelper/compbase2.hxx" 55 #include "cppuhelper/compbase3.hxx" 56 #include "cppuhelper/implbase1.hxx" 57 58 using rtl::OUString; 59 using namespace com::sun::star; 60 using namespace com::sun::star::uno; 61 using namespace com::sun::star::lang; 62 63 // ----------------------------------------------------------------------- 64 65 namespace vcl 66 { 67 // generic implementation to satisfy SalInstance 68 class GenericClipboard : 69 public cppu::WeakComponentImplHelper3 < 70 datatransfer::clipboard::XClipboardEx, 71 datatransfer::clipboard::XClipboardNotifier, 72 XServiceInfo 73 > 74 { 75 osl::Mutex m_aMutex; 76 Reference< ::com::sun::star::datatransfer::XTransferable > m_aContents; 77 Reference< ::com::sun::star::datatransfer::clipboard::XClipboardOwner > m_aOwner; 78 std::list< Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener > > m_aListeners; 79 80 void fireChangedContentsEvent(); 81 void clearContents(); 82 83 public: 84 85 GenericClipboard() : cppu::WeakComponentImplHelper3< 86 datatransfer::clipboard::XClipboardEx, 87 datatransfer::clipboard::XClipboardNotifier, 88 XServiceInfo 89 >( m_aMutex ) 90 {} 91 virtual ~GenericClipboard(); 92 93 /* 94 * XServiceInfo 95 */ 96 97 virtual rtl::OUString SAL_CALL getImplementationName() throw( RuntimeException ); 98 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw( RuntimeException ); 99 virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( RuntimeException ); 100 101 static rtl::OUString getImplementationName_static(); 102 static Sequence< rtl::OUString > getSupportedServiceNames_static(); 103 104 /* 105 * XClipboard 106 */ 107 108 virtual Reference< ::com::sun::star::datatransfer::XTransferable > SAL_CALL getContents() 109 throw(RuntimeException); 110 111 virtual void SAL_CALL setContents( 112 const Reference< ::com::sun::star::datatransfer::XTransferable >& xTrans, 113 const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardOwner >& xClipboardOwner ) 114 throw(RuntimeException); 115 116 virtual ::rtl::OUString SAL_CALL getName() 117 throw(RuntimeException); 118 119 /* 120 * XClipboardEx 121 */ 122 123 virtual sal_Int8 SAL_CALL getRenderingCapabilities() 124 throw(RuntimeException); 125 126 /* 127 * XClipboardNotifier 128 */ 129 virtual void SAL_CALL addClipboardListener( 130 const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener >& listener ) 131 throw(RuntimeException); 132 133 virtual void SAL_CALL removeClipboardListener( 134 const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener >& listener ) 135 throw(RuntimeException); 136 }; 137 138 GenericClipboard::~GenericClipboard() 139 { 140 } 141 142 rtl::OUString GenericClipboard::getImplementationName_static() 143 { 144 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.datatransfer.VCLGenericClipboard" ) ); 145 } 146 147 Sequence< rtl::OUString > GenericClipboard::getSupportedServiceNames_static() 148 { 149 Sequence< OUString > aRet(1); 150 aRet[0] = OUString::createFromAscii("com.sun.star.datatransfer.clipboard.SystemClipboard"); 151 return aRet; 152 } 153 154 rtl::OUString GenericClipboard::getImplementationName() throw( RuntimeException ) 155 { 156 return getImplementationName_static(); 157 } 158 159 Sequence< rtl::OUString > GenericClipboard::getSupportedServiceNames() throw( RuntimeException ) 160 { 161 return getSupportedServiceNames_static(); 162 } 163 164 sal_Bool GenericClipboard::supportsService( const ::rtl::OUString& ServiceName ) throw( RuntimeException ) 165 { 166 Sequence< OUString > aServices( getSupportedServiceNames() ); 167 sal_Int32 nServices = aServices.getLength(); 168 for( sal_Int32 i = 0; i < nServices; i++ ) 169 { 170 if( aServices[i] == ServiceName ) 171 return sal_True; 172 } 173 return sal_False; 174 } 175 176 Reference< ::com::sun::star::datatransfer::XTransferable > GenericClipboard::getContents() throw( RuntimeException ) 177 { 178 return m_aContents; 179 } 180 181 void GenericClipboard::setContents( 182 const Reference< ::com::sun::star::datatransfer::XTransferable >& xTrans, 183 const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardOwner >& xClipboardOwner ) 184 throw( RuntimeException ) 185 { 186 osl::ClearableMutexGuard aGuard( m_aMutex ); 187 Reference< datatransfer::clipboard::XClipboardOwner > xOldOwner( m_aOwner ); 188 Reference< datatransfer::XTransferable > xOldContents( m_aContents ); 189 m_aContents = xTrans; 190 m_aOwner = xClipboardOwner; 191 192 std::list< Reference< datatransfer::clipboard::XClipboardListener > > xListeners( m_aListeners ); 193 datatransfer::clipboard::ClipboardEvent aEv; 194 aEv.Contents = m_aContents; 195 196 aGuard.clear(); 197 198 if( xOldOwner.is() && xOldOwner != xClipboardOwner ) 199 xOldOwner->lostOwnership( this, xOldContents ); 200 for( std::list< Reference< datatransfer::clipboard::XClipboardListener > >::iterator it = 201 xListeners.begin(); it != xListeners.end() ; ++it ) 202 { 203 (*it)->changedContents( aEv ); 204 } 205 } 206 207 rtl::OUString GenericClipboard::getName() throw( RuntimeException ) 208 { 209 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CLIPBOARD" ) ); 210 } 211 212 sal_Int8 GenericClipboard::getRenderingCapabilities() throw( RuntimeException ) 213 { 214 return 0; 215 } 216 217 void GenericClipboard::addClipboardListener( const Reference< datatransfer::clipboard::XClipboardListener >& listener ) 218 throw( RuntimeException ) 219 { 220 osl::ClearableMutexGuard aGuard( m_aMutex ); 221 222 m_aListeners.push_back( listener ); 223 } 224 225 void GenericClipboard::removeClipboardListener( const Reference< datatransfer::clipboard::XClipboardListener >& listener ) 226 throw( RuntimeException ) 227 { 228 osl::ClearableMutexGuard aGuard( m_aMutex ); 229 230 m_aListeners.remove( listener ); 231 } 232 233 // ------------------------------------------------------------------------ 234 235 class ClipboardFactory : public ::cppu::WeakComponentImplHelper1< 236 com::sun::star::lang::XSingleServiceFactory 237 > 238 { 239 osl::Mutex m_aMutex; 240 public: 241 ClipboardFactory(); 242 virtual ~ClipboardFactory(); 243 244 /* 245 * XSingleServiceFactory 246 */ 247 virtual Reference< XInterface > SAL_CALL createInstance() throw(); 248 virtual Reference< XInterface > SAL_CALL createInstanceWithArguments( const Sequence< Any >& rArgs ) throw(); 249 }; 250 251 // ------------------------------------------------------------------------ 252 253 ClipboardFactory::ClipboardFactory() : 254 cppu::WeakComponentImplHelper1< 255 com::sun::star::lang::XSingleServiceFactory 256 >( m_aMutex ) 257 { 258 } 259 260 // ------------------------------------------------------------------------ 261 262 ClipboardFactory::~ClipboardFactory() 263 { 264 } 265 266 // ------------------------------------------------------------------------ 267 268 Reference< XInterface > ClipboardFactory::createInstance() throw() 269 { 270 return createInstanceWithArguments( Sequence< Any >() ); 271 } 272 273 // ------------------------------------------------------------------------ 274 275 Reference< XInterface > ClipboardFactory::createInstanceWithArguments( const Sequence< Any >& arguments ) throw() 276 { 277 vos::OGuard aGuard( Application::GetSolarMutex() ); 278 Reference< XInterface > xResult = ImplGetSVData()->mpDefInst->CreateClipboard( arguments ); 279 return xResult; 280 } 281 282 // ------------------------------------------------------------------------ 283 284 Sequence< OUString > SAL_CALL Clipboard_getSupportedServiceNames() 285 { 286 Sequence< OUString > aRet(1); 287 aRet[0] = OUString::createFromAscii("com.sun.star.datatransfer.clipboard.SystemClipboard"); 288 return aRet; 289 } 290 291 OUString SAL_CALL Clipboard_getImplementationName() 292 { 293 #if defined UNX 294 return OUString( RTL_CONSTASCII_USTRINGPARAM( 295 #if ! defined QUARTZ 296 "com.sun.star.datatransfer.X11ClipboardSupport" 297 #else 298 "com.sun.star.datatransfer.clipboard.AquaClipboard" 299 #endif 300 ) ); 301 #else 302 return GenericClipboard::getImplementationName_static(); 303 #endif 304 } 305 306 Reference< XSingleServiceFactory > SAL_CALL Clipboard_createFactory( const Reference< XMultiServiceFactory > & ) 307 { 308 return Reference< XSingleServiceFactory >( new ClipboardFactory() ); 309 } 310 311 /* 312 * generic DragSource dummy 313 */ 314 class GenericDragSource : public cppu::WeakComponentImplHelper2< 315 datatransfer::dnd::XDragSource, 316 XInitialization 317 > 318 { 319 osl::Mutex m_aMutex; 320 public: 321 GenericDragSource() : cppu::WeakComponentImplHelper2< datatransfer::dnd::XDragSource, XInitialization >( m_aMutex ) {} 322 virtual ~GenericDragSource(); 323 324 // XDragSource 325 virtual sal_Bool SAL_CALL isDragImageSupported() throw(); 326 virtual sal_Int32 SAL_CALL getDefaultCursor( sal_Int8 dragAction ) throw(); 327 virtual void SAL_CALL startDrag( 328 const datatransfer::dnd::DragGestureEvent& trigger, 329 sal_Int8 sourceActions, sal_Int32 cursor, sal_Int32 image, 330 const Reference< datatransfer::XTransferable >& transferable, 331 const Reference< datatransfer::dnd::XDragSourceListener >& listener 332 ) throw(); 333 334 // XInitialization 335 virtual void SAL_CALL initialize( const Sequence< Any >& arguments ) throw( ::com::sun::star::uno::Exception ); 336 337 static Sequence< OUString > getSupportedServiceNames_static() 338 { 339 Sequence< OUString > aRet( 1 ); 340 aRet[0] = OUString::createFromAscii( "com.sun.star.datatransfer.dnd.GenericDragSource" ); 341 return aRet; 342 } 343 344 static OUString getImplementationName_static() 345 { 346 return OUString::createFromAscii( "com.sun.star.datatransfer.dnd.VclGenericDragSource" ); 347 } 348 }; 349 350 GenericDragSource::~GenericDragSource() 351 { 352 } 353 354 sal_Bool GenericDragSource::isDragImageSupported() throw() 355 { 356 return sal_False; 357 } 358 359 sal_Int32 GenericDragSource::getDefaultCursor( sal_Int8 ) throw() 360 { 361 return 0; 362 } 363 364 void GenericDragSource::startDrag( const datatransfer::dnd::DragGestureEvent&, 365 sal_Int8 /*sourceActions*/, sal_Int32 /*cursor*/, sal_Int32 /*image*/, 366 const Reference< datatransfer::XTransferable >&, 367 const Reference< datatransfer::dnd::XDragSourceListener >& listener 368 ) throw() 369 { 370 datatransfer::dnd::DragSourceDropEvent aEv; 371 aEv.DropAction = datatransfer::dnd::DNDConstants::ACTION_COPY; 372 aEv.DropSuccess = sal_False; 373 listener->dragDropEnd( aEv ); 374 } 375 376 void GenericDragSource::initialize( const Sequence< Any >& ) throw( Exception ) 377 { 378 } 379 380 381 Sequence< OUString > SAL_CALL DragSource_getSupportedServiceNames() 382 { 383 #if defined UNX 384 static OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( 385 #if ! defined QUARTZ 386 "com.sun.star.datatransfer.dnd.X11DragSource" 387 #else 388 "com.sun.star.datatransfer.dnd.OleDragSource" 389 #endif 390 ) ); 391 static Sequence< OUString > aServiceNames( &aServiceName, 1 ); 392 return aServiceNames; 393 #else 394 return GenericDragSource::getSupportedServiceNames_static(); 395 #endif 396 } 397 398 OUString SAL_CALL DragSource_getImplementationName() 399 { 400 #if defined UNX 401 return OUString( RTL_CONSTASCII_USTRINGPARAM( 402 #if ! defined QUARTZ 403 "com.sun.star.datatransfer.dnd.XdndSupport" 404 #else 405 "com.sun.star.comp.datatransfer.dnd.OleDragSource_V1" 406 #endif 407 ) ); 408 #else 409 return GenericDragSource::getImplementationName_static(); 410 #endif 411 } 412 413 Reference< XInterface > SAL_CALL DragSource_createInstance( const Reference< XMultiServiceFactory >& ) 414 { 415 vos::OGuard aGuard( Application::GetSolarMutex() ); 416 Reference< XInterface > xResult = ImplGetSVData()->mpDefInst->CreateDragSource(); 417 return xResult; 418 } 419 420 /* 421 * generic DragSource dummy 422 */ 423 424 class GenericDropTarget : public cppu::WeakComponentImplHelper2< 425 datatransfer::dnd::XDropTarget, 426 XInitialization 427 > 428 { 429 osl::Mutex m_aMutex; 430 public: 431 GenericDropTarget() : cppu::WeakComponentImplHelper2< 432 datatransfer::dnd::XDropTarget, 433 XInitialization 434 > ( m_aMutex ) 435 {} 436 virtual ~GenericDropTarget(); 437 438 // XInitialization 439 virtual void SAL_CALL initialize( const Sequence< Any >& args ) throw ( Exception ); 440 441 // XDropTarget 442 virtual void SAL_CALL addDropTargetListener( const Reference< ::com::sun::star::datatransfer::dnd::XDropTargetListener >& ) throw(); 443 virtual void SAL_CALL removeDropTargetListener( const Reference< ::com::sun::star::datatransfer::dnd::XDropTargetListener >& ) throw(); 444 virtual sal_Bool SAL_CALL isActive() throw(); 445 virtual void SAL_CALL setActive( sal_Bool active ) throw(); 446 virtual sal_Int8 SAL_CALL getDefaultActions() throw(); 447 virtual void SAL_CALL setDefaultActions( sal_Int8 actions ) throw(); 448 449 static Sequence< OUString > getSupportedServiceNames_static() 450 { 451 Sequence< OUString > aRet( 1 ); 452 aRet[0] = OUString::createFromAscii( "com.sun.star.datatransfer.dnd.GenericDropTarget" ); 453 return aRet; 454 } 455 456 static OUString getImplementationName_static() 457 { 458 return OUString::createFromAscii( "com.sun.star.datatransfer.dnd.VclGenericDropTarget" ); 459 } 460 }; 461 462 GenericDropTarget::~GenericDropTarget() 463 { 464 } 465 466 void GenericDropTarget::initialize( const Sequence< Any >& ) throw( Exception ) 467 { 468 } 469 470 void GenericDropTarget::addDropTargetListener( const Reference< ::com::sun::star::datatransfer::dnd::XDropTargetListener >& ) throw() 471 { 472 } 473 474 void GenericDropTarget::removeDropTargetListener( const Reference< ::com::sun::star::datatransfer::dnd::XDropTargetListener >& ) throw() 475 { 476 } 477 478 sal_Bool GenericDropTarget::isActive() throw() 479 { 480 return sal_False; 481 } 482 483 void GenericDropTarget::setActive( sal_Bool ) throw() 484 { 485 } 486 487 sal_Int8 GenericDropTarget::getDefaultActions() throw() 488 { 489 return 0; 490 } 491 492 void GenericDropTarget::setDefaultActions( sal_Int8) throw() 493 { 494 } 495 496 Sequence< OUString > SAL_CALL DropTarget_getSupportedServiceNames() 497 { 498 #if defined UNX 499 static OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( 500 #if ! defined QUARTZ 501 "com.sun.star.datatransfer.dnd.X11DropTarget" 502 #else 503 "com.sun.star.datatransfer.dnd.OleDropTarget" 504 #endif 505 ) ); 506 static Sequence< OUString > aServiceNames( &aServiceName, 1 ); 507 return aServiceNames; 508 #else 509 return GenericDropTarget::getSupportedServiceNames_static(); 510 #endif 511 } 512 513 OUString SAL_CALL DropTarget_getImplementationName() 514 { 515 #if defined UNX 516 return OUString( RTL_CONSTASCII_USTRINGPARAM( 517 #if ! defined QUARTZ 518 "com.sun.star.datatransfer.dnd.XdndDropTarget" 519 #else 520 "com.sun.star.comp.datatransfer.dnd.OleDropTarget_V1" 521 #endif 522 ) ); 523 #else 524 return GenericDropTarget::getImplementationName_static(); 525 #endif 526 } 527 528 Reference< XInterface > SAL_CALL DropTarget_createInstance( const Reference< XMultiServiceFactory >& ) 529 { 530 vos::OGuard aGuard( Application::GetSolarMutex() ); 531 Reference< XInterface > xResult = ImplGetSVData()->mpDefInst->CreateDropTarget(); 532 return xResult; 533 } 534 535 536 } // namespace vcl 537 538 /* 539 * SalInstance generic 540 */ 541 Reference< XInterface > SalInstance::CreateClipboard( const Sequence< Any >& ) 542 { 543 return Reference< XInterface >( ( cppu::OWeakObject * )new vcl::GenericClipboard() ); 544 } 545 546 Reference< XInterface > SalInstance::CreateDragSource() 547 { 548 return Reference< XInterface >( ( cppu::OWeakObject * )new vcl::GenericDragSource() ); 549 } 550 551 Reference< XInterface > SalInstance::CreateDropTarget() 552 { 553 return Reference< XInterface >( ( cppu::OWeakObject * )new vcl::GenericDropTarget() ); 554 } 555 556