LCOV - code coverage report
Current view: top level - libreoffice/vcl/source/components - dtranscomp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 126 0.0 %
Date: 2012-12-27 Functions: 0 47 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10