diff options
author | Philipp Lohmann <pl@openoffice.org> | 2001-06-25 09:50:58 +0000 |
---|---|---|
committer | Philipp Lohmann <pl@openoffice.org> | 2001-06-25 09:50:58 +0000 |
commit | 823e82dc779efe4b2229188d1d8fa11558409fb1 (patch) | |
tree | efa190f78af32605db071876eb249c6201e3b431 /dtrans | |
parent | d8a880c3c0ca75da7fa1934be411938cf96f526e (diff) |
#88680# get rid of X11ClipboardHolder
Diffstat (limited to 'dtrans')
-rw-r--r-- | dtrans/source/X11/X11_clipboard.cxx | 169 | ||||
-rw-r--r-- | dtrans/source/X11/X11_clipboard.hxx | 99 | ||||
-rw-r--r-- | dtrans/source/X11/X11_service.cxx | 111 |
3 files changed, 138 insertions, 241 deletions
diff --git a/dtrans/source/X11/X11_clipboard.cxx b/dtrans/source/X11/X11_clipboard.cxx index f246ef6ec188..f3d56e399129 100644 --- a/dtrans/source/X11/X11_clipboard.cxx +++ b/dtrans/source/X11/X11_clipboard.cxx @@ -2,9 +2,9 @@ * * $RCSfile: X11_clipboard.cxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: pl $ $Date: 2001-06-22 17:47:46 $ + * last change: $Author: pl $ $Date: 2001-06-25 10:50:58 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -110,27 +110,14 @@ using namespace osl; using namespace rtl; using namespace x11; -::std::hash_map< OUString, ::std::hash_map< Atom, X11Clipboard* >, ::rtl::OUStringHash > X11Clipboard::m_aInstances; - -// ------------------------------------------------------------------------ - -X11Clipboard* X11Clipboard::get( const OUString & rDisplayName, Atom aSelection ) -{ - MutexGuard aGuard( *Mutex::getGlobalMutex() ); - ::std::hash_map< Atom, X11Clipboard* >& rMap( m_aInstances[ rDisplayName ] ); - ::std::hash_map< Atom, X11Clipboard* >::iterator it = rMap.find( aSelection ); - if( it != rMap.end() ) - return it->second; - - SelectionManager& rManager( SelectionManager::get( rDisplayName ) ); - X11Clipboard* pClipboard = new X11Clipboard( rManager, aSelection ); - rMap[ aSelection ] = pClipboard; - - return pClipboard; -} - - X11Clipboard::X11Clipboard( SelectionManager& rManager, Atom aSelection ) : + ::cppu::WeakComponentImplHelper4< + ::com::sun::star::datatransfer::clipboard::XClipboardEx, + ::com::sun::star::datatransfer::clipboard::XClipboardNotifier, + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::lang::XInitialization + >( m_aMutex ), + m_rSelectionManager( rManager ), m_xSelectionManager( & rManager ), m_aSelection( aSelection ) @@ -157,7 +144,7 @@ X11Clipboard::~X11Clipboard() MutexGuard aGuard( *Mutex::getGlobalMutex() ); #ifdef DEBUG - fprintf( stderr, "shutting down instance of X11Clipboard (this=%x)\n", this ); + fprintf( stderr, "shutting down instance of X11Clipboard (this=%x, Selecttion=\"%s\")\n", this, OUStringToOString( m_rSelectionManager.getString( m_aSelection ), RTL_TEXTENCODING_ISO_8859_1 ).getStr() ); #endif if( m_aSelection != None ) m_rSelectionManager.deregisterHandler( m_aSelection ); @@ -166,20 +153,6 @@ X11Clipboard::~X11Clipboard() m_rSelectionManager.deregisterHandler( XA_PRIMARY ); m_rSelectionManager.deregisterHandler( m_rSelectionManager.getAtom( OUString::createFromAscii( "CLIPBOARD" ) ) ); } - - ::std::hash_map< OUString, ::std::hash_map< Atom, X11Clipboard* >, OUStringHash >::iterator mapit; - - for( mapit = m_aInstances.begin(); mapit != m_aInstances.end(); ++mapit ) - { - ::std::hash_map< Atom, X11Clipboard* >::iterator it; - ::std::hash_map< Atom, X11Clipboard* >& rMap( mapit->second ); - for( it = rMap.begin(); it != rMap.end(); ++it ) - if( it->second == this ) - { - rMap.erase( it ); - break; - } - } } @@ -195,7 +168,7 @@ void X11Clipboard::fireChangedContentsEvent() ::std::list< Reference< XClipboardListener > > listeners( m_aListeners ); aGuard.clear(); - ClipboardEvent aEvent( m_pHolder, m_aContents); + ClipboardEvent aEvent( static_cast<OWeakObject*>(this), m_aContents); while( listeners.begin() != listeners.end() ) { if( listeners.front().is() ) @@ -323,117 +296,9 @@ void X11Clipboard::fireContentsChanged() fireChangedContentsEvent(); } -/* - * X11ClipboardHolder - */ - -X11ClipboardHolder::X11ClipboardHolder() : - ::cppu::WeakComponentImplHelper4< - ::com::sun::star::datatransfer::clipboard::XClipboardEx, - ::com::sun::star::datatransfer::clipboard::XClipboardNotifier, - ::com::sun::star::lang::XServiceInfo, - ::com::sun::star::lang::XInitialization - >( m_aMutex ) -{ -} - -X11ClipboardHolder::~X11ClipboardHolder() -{ -} - -void X11ClipboardHolder::initialize( const Sequence< Any >& arguments ) -{ - OUString aDisplayName; - Atom nSelection; - - // extract display name from connection argument. An exception is thrown - // by SelectionManager.initialize() if no display connection is given. - if( arguments.getLength() > 0 ) - { - Reference< XDisplayConnection > xConn; - arguments.getConstArray()[0] >>= xConn; - - if( xConn.is() ) - { - Any aIdentifier = xConn->getIdentifier(); - aIdentifier >>= aDisplayName; - } - } - - SelectionManager& rManager = SelectionManager::get( aDisplayName ); - rManager.initialize( arguments ); - - // check if any other selection than clipboard selection is specified - if( arguments.getLength() > 1 ) - { - OUString aSelectionName; - - arguments.getConstArray()[1] >>= aSelectionName; - nSelection = rManager.getAtom( aSelectionName ); - } - else - { - // default atom is clipboard selection - nSelection = rManager.getAtom( OUString::createFromAscii( "CLIPBOARD" ) ); - } - - X11Clipboard* pClipboard = X11Clipboard::get( aDisplayName, nSelection ); - m_xRealClipboard = pClipboard; - m_xRealNotifier = pClipboard; - pClipboard->setHolder( this ); -} - // ------------------------------------------------------------------------ -Reference< XTransferable > X11ClipboardHolder::getContents() throw(RuntimeException) -{ - return m_xRealClipboard.is() ? m_xRealClipboard->getContents() : Reference< XTransferable >(); -} - -// ------------------------------------------------------------------------ - -void X11ClipboardHolder::addClipboardListener( const Reference< XClipboardListener >& xListener ) throw(RuntimeException) -{ - if( m_xRealNotifier.is() ) - m_xRealNotifier->addClipboardListener( xListener ); -} - -// ------------------------------------------------------------------------ - -void X11ClipboardHolder::removeClipboardListener( const Reference< XClipboardListener >& xListener ) throw(RuntimeException) -{ - if( m_xRealNotifier.is() ) - m_xRealNotifier->removeClipboardListener( xListener ); -} - -// ------------------------------------------------------------------------ - -void X11ClipboardHolder::setContents( - const Reference< XTransferable >& xTrans, - const Reference< XClipboardOwner >& xOwner - ) throw(RuntimeException) -{ - if( m_xRealClipboard.is() ) - m_xRealClipboard->setContents( xTrans, xOwner ); -} - -// ------------------------------------------------------------------------ - -OUString X11ClipboardHolder::getName() throw(RuntimeException) -{ - return m_xRealClipboard.is() ? m_xRealClipboard->getName() : OUString(); -} - -// ------------------------------------------------------------------------ - -sal_Int8 X11ClipboardHolder::getRenderingCapabilities() throw(RuntimeException) -{ - return m_xRealClipboard.is() ? m_xRealClipboard->getRenderingCapabilities() : 0; -} - -// ------------------------------------------------------------------------ - -OUString SAL_CALL X11ClipboardHolder::getImplementationName( ) +OUString SAL_CALL X11Clipboard::getImplementationName( ) throw(RuntimeException) { return OUString::createFromAscii(X11_CLIPBOARD_IMPLEMENTATION_NAME); @@ -441,7 +306,7 @@ OUString SAL_CALL X11ClipboardHolder::getImplementationName( ) // ------------------------------------------------------------------------ -sal_Bool SAL_CALL X11ClipboardHolder::supportsService( const OUString& ServiceName ) +sal_Bool SAL_CALL X11Clipboard::supportsService( const OUString& ServiceName ) throw(RuntimeException) { Sequence < OUString > SupportedServicesNames = X11Clipboard_getSupportedServiceNames(); @@ -455,7 +320,13 @@ sal_Bool SAL_CALL X11ClipboardHolder::supportsService( const OUString& ServiceNa // ------------------------------------------------------------------------ -Sequence< OUString > SAL_CALL X11ClipboardHolder::getSupportedServiceNames( ) +void SAL_CALL X11Clipboard::initialize( const Sequence< Any >& rArgs ) +{ +} + +// ------------------------------------------------------------------------ + +Sequence< OUString > SAL_CALL X11Clipboard::getSupportedServiceNames( ) throw(RuntimeException) { return X11Clipboard_getSupportedServiceNames(); diff --git a/dtrans/source/X11/X11_clipboard.hxx b/dtrans/source/X11/X11_clipboard.hxx index 9d7d3ee7332d..f9821586dd8d 100644 --- a/dtrans/source/X11/X11_clipboard.hxx +++ b/dtrans/source/X11/X11_clipboard.hxx @@ -2,9 +2,9 @@ * * $RCSfile: X11_clipboard.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: pl $ $Date: 2001-06-22 17:47:46 $ + * last change: $Author: pl $ $Date: 2001-06-25 10:50:58 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -78,94 +78,21 @@ #include <cppuhelper/compbase4.hxx> #endif -#ifndef _CPPUHELPER_COMPBASE2_HXX_ -#include <cppuhelper/compbase2.hxx> -#endif - // ------------------------------------------------------------------------ #define X11_CLIPBOARD_IMPLEMENTATION_NAME "com.sun.star.datatransfer.X11ClipboardSupport" namespace x11 { - class X11ClipboardHolder : + class X11Clipboard : public ::cppu::WeakComponentImplHelper4 < ::com::sun::star::datatransfer::clipboard::XClipboardEx, ::com::sun::star::datatransfer::clipboard::XClipboardNotifier, ::com::sun::star::lang::XServiceInfo, ::com::sun::star::lang::XInitialization - > - { - ::osl::Mutex m_aMutex; - Reference< ::com::sun::star::datatransfer::clipboard::XClipboardEx > - m_xRealClipboard; - Reference< ::com::sun::star::datatransfer::clipboard::XClipboardNotifier > - m_xRealNotifier; - public: - X11ClipboardHolder(); - virtual ~X11ClipboardHolder(); - - /* - * XInitialization - */ - virtual void SAL_CALL initialize( const Sequence< Any >& arguments ); - - /* - * XServiceInfo - */ - - virtual ::rtl::OUString SAL_CALL getImplementationName( ) - throw(RuntimeException); - - virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) - throw(RuntimeException); - - virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) - throw(RuntimeException); - - /* - * XClipboard - */ - - virtual Reference< ::com::sun::star::datatransfer::XTransferable > SAL_CALL getContents() - throw(RuntimeException); - - virtual void SAL_CALL setContents( - const Reference< ::com::sun::star::datatransfer::XTransferable >& xTrans, - const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardOwner >& xClipboardOwner ) - throw(RuntimeException); - - virtual ::rtl::OUString SAL_CALL getName() - throw(RuntimeException); - - /* - * XClipboardEx - */ - - virtual sal_Int8 SAL_CALL getRenderingCapabilities() - throw(RuntimeException); - - /* - * XClipboardNotifier - */ - virtual void SAL_CALL addClipboardListener( const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener >& listener ) - throw(RuntimeException); - - virtual void SAL_CALL removeClipboardListener( - const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener >& listener ) - throw(RuntimeException); - }; - - class X11Clipboard : - public ::cppu::WeakImplHelper2 < - ::com::sun::star::datatransfer::clipboard::XClipboardEx, - ::com::sun::star::datatransfer::clipboard::XClipboardNotifier >, public SelectionAdaptor { - static ::std::hash_map< ::rtl::OUString, ::std::hash_map< Atom, X11Clipboard* >, ::rtl::OUStringHash > - m_aInstances; - ::osl::Mutex m_aMutex; Reference< ::com::sun::star::datatransfer::XTransferable > m_aContents; @@ -175,7 +102,6 @@ namespace x11 { Reference< ::com::sun::star::lang::XInitialization > m_xSelectionManager; ::std::list< Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener > > m_aListeners; Atom m_aSelection; - ::com::sun::star::datatransfer::clipboard::XClipboardEx* m_pHolder; protected: @@ -192,7 +118,24 @@ namespace x11 { virtual ~X11Clipboard(); static X11Clipboard* get( const ::rtl::OUString& rDisplayName, Atom aSelection ); - void setHolder( ::com::sun::star::datatransfer::clipboard::XClipboardEx* pHolder ) { m_pHolder = pHolder; } + + /* + * XInitialization + */ + virtual void SAL_CALL initialize( const Sequence< Any >& arguments ); + + /* + * XServiceInfo + */ + + virtual ::rtl::OUString SAL_CALL getImplementationName( ) + throw(RuntimeException); + + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) + throw(RuntimeException); + + virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) + throw(RuntimeException); /* * XClipboard diff --git a/dtrans/source/X11/X11_service.cxx b/dtrans/source/X11/X11_service.cxx index c51995dbce61..ad9900abc334 100644 --- a/dtrans/source/X11/X11_service.cxx +++ b/dtrans/source/X11/X11_service.cxx @@ -2,9 +2,9 @@ * * $RCSfile: X11_service.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: pl $ $Date: 2001-02-16 14:37:50 $ + * last change: $Author: pl $ $Date: 2001-06-25 10:50:58 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -82,27 +82,114 @@ #ifndef _CPPUHELPER_FACTORY_HXX_ #include <cppuhelper/factory.hxx> #endif +#ifndef _CPPUHELPER_COMPBASE1_HXX_ +#include <cppuhelper/compbase1.hxx> +#endif using namespace rtl; using namespace cppu; using namespace com::sun::star::lang; +using namespace com::sun::star::datatransfer::clipboard; +using namespace com::sun::star::awt; using namespace x11; namespace x11 { -Sequence< OUString > SAL_CALL X11Clipboard_getSupportedServiceNames() +class X11ClipboardFactory : public ::cppu::WeakComponentImplHelper1 < + ::com::sun::star::lang::XSingleServiceFactory +> +{ + ::osl::Mutex m_aMutex; + ::std::hash_map< OUString, ::std::hash_map< Atom, Reference< XClipboard > >, ::rtl::OUStringHash > m_aInstances; +public: + X11ClipboardFactory(); + virtual ~X11ClipboardFactory(); + + /* + * XSingleServiceFactory + */ + virtual Reference< XInterface > createInstance(); + virtual Reference< XInterface > createInstanceWithArguments( const Sequence< Any >& rArgs ); +}; + +// ------------------------------------------------------------------------ + +X11ClipboardFactory::X11ClipboardFactory() : + ::cppu::WeakComponentImplHelper1< + ::com::sun::star::lang::XSingleServiceFactory +>( m_aMutex ) { - Sequence< OUString > aRet(1); - aRet[0] = OUString::createFromAscii("com.sun.star.datatransfer.clipboard.SystemClipboard"); - return aRet; } // ------------------------------------------------------------------------ -Reference< XInterface > SAL_CALL X11Clipboard_createInstance( - const Reference< XMultiServiceFactory > & xMultiServiceFactory) +X11ClipboardFactory::~X11ClipboardFactory() +{ +} + +// ------------------------------------------------------------------------ + +Reference< XInterface > X11ClipboardFactory::createInstance() +{ + return createInstanceWithArguments( Sequence< Any >() ); +} + +// ------------------------------------------------------------------------ + +Reference< XInterface > X11ClipboardFactory::createInstanceWithArguments( const Sequence< Any >& arguments ) +{ + OUString aDisplayName; + Atom nSelection; + + // extract display name from connection argument. An exception is thrown + // by SelectionManager.initialize() if no display connection is given. + if( arguments.getLength() > 0 ) + { + Reference< XDisplayConnection > xConn; + arguments.getConstArray()[0] >>= xConn; + + if( xConn.is() ) + { + Any aIdentifier = xConn->getIdentifier(); + aIdentifier >>= aDisplayName; + } + } + + SelectionManager& rManager = SelectionManager::get( aDisplayName ); + rManager.initialize( arguments ); + + // check if any other selection than clipboard selection is specified + if( arguments.getLength() > 1 ) + { + OUString aSelectionName; + + arguments.getConstArray()[1] >>= aSelectionName; + nSelection = rManager.getAtom( aSelectionName ); + } + else + { + // default atom is clipboard selection + nSelection = rManager.getAtom( OUString::createFromAscii( "CLIPBOARD" ) ); + } + + ::std::hash_map< Atom, Reference< XClipboard > >& rMap( m_aInstances[ aDisplayName ] ); + ::std::hash_map< Atom, Reference< XClipboard > >::iterator it = rMap.find( nSelection ); + if( it != rMap.end() ) + return it->second; + + X11Clipboard* pClipboard = new X11Clipboard( rManager, nSelection ); + rMap[ nSelection ] = pClipboard; + + return static_cast<OWeakObject*>(pClipboard); +} + +// ------------------------------------------------------------------------ + +Sequence< OUString > SAL_CALL X11Clipboard_getSupportedServiceNames() { - return Reference < XInterface >( ( OWeakObject * ) new X11ClipboardHolder()); + Sequence< OUString > aRet(1); + aRet[0] = OUString::createFromAscii("com.sun.star.datatransfer.clipboard.SystemClipboard"); + return aRet; } // ------------------------------------------------------------------------ @@ -237,11 +324,7 @@ extern "C" { ); Reference< ::com::sun::star::lang::XSingleServiceFactory > xFactory; if( aImplName.equals( getClipboardImplementationName() ) ) - { - xFactory = ::cppu::createSingleFactory( - xMgr, aImplName, X11Clipboard_createInstance, - X11Clipboard_getSupportedServiceNames() ); - } + xFactory = new X11ClipboardFactory(); else if( aImplName.equals( getXdndImplementationName() ) ) { xFactory = ::cppu::createSingleFactory( |