summaryrefslogtreecommitdiff
path: root/dtrans
diff options
context:
space:
mode:
authorPhilipp Lohmann <pl@openoffice.org>2001-06-22 16:47:46 +0000
committerPhilipp Lohmann <pl@openoffice.org>2001-06-22 16:47:46 +0000
commit24486e50813d0d2d6d615b8f6e5c3e8c06e38662 (patch)
tree6a2268aa3415e7b4802e07d23d7f3c9811e2b1e7 /dtrans
parent88db28ee2337e8c4a0388ef46204caa0a70097cc (diff)
#88680# implement XClipboardNotifier
Diffstat (limited to 'dtrans')
-rw-r--r--dtrans/source/X11/X11_clipboard.cxx72
-rw-r--r--dtrans/source/X11/X11_clipboard.hxx44
-rw-r--r--dtrans/source/X11/X11_selection.cxx40
-rw-r--r--dtrans/source/X11/X11_selection.hxx12
4 files changed, 119 insertions, 49 deletions
diff --git a/dtrans/source/X11/X11_clipboard.cxx b/dtrans/source/X11/X11_clipboard.cxx
index e11733e3e041..f246ef6ec188 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.5 $
+ * $Revision: 1.6 $
*
- * last change: $Author: obr $ $Date: 2001-05-07 11:12:22 $
+ * last change: $Author: pl $ $Date: 2001-06-22 17:47:46 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -187,23 +187,21 @@ X11Clipboard::~X11Clipboard()
void X11Clipboard::fireChangedContentsEvent()
{
-#if 0
- OInterfaceContainerHelper *pContainer =
- rBHelper.aLC.getContainer(getCppuType( (Reference < XClipboardListener > *) 0));
+ ClearableMutexGuard aGuard( m_aMutex );
+#ifdef DEBUG
+ fprintf( stderr, "X11Clipboard::fireChangedContentsEvent for %s (%d listeners)\n",
+ OUStringToOString( m_rSelectionManager.getString( m_aSelection ), RTL_TEXTENCODING_ISO_8859_1 ).getStr(), m_aListeners.size() );
+#endif
+ ::std::list< Reference< XClipboardListener > > listeners( m_aListeners );
+ aGuard.clear();
- if (pContainer)
+ ClipboardEvent aEvent( m_pHolder, m_aContents);
+ while( listeners.begin() != listeners.end() )
{
- ClipboardEvent aEvent(static_cast < XClipboard * > (this), m_aContents);
- OInterfaceIteratorHelper aIterator(*pContainer);
-
- while (aIterator.hasMoreElements())
- {
- Reference < XClipboardListener > xListener(aIterator.next(), UNO_QUERY);
- if (xListener.is())
- xListener->changedContents(aEvent);
- }
+ if( listeners.front().is() )
+ listeners.front()->changedContents(aEvent);
+ listeners.pop_front();
}
-#endif
}
// ------------------------------------------------------------------------
@@ -212,7 +210,8 @@ void X11Clipboard::clearContents()
{
MutexGuard aGuard(m_aMutex);
- if ( m_aOwner.is() ) {
+ if ( m_aOwner.is() )
+ {
m_aOwner->lostOwnership(static_cast < XClipboard * > (this), m_aContents);
m_aOwner.clear();
}
@@ -286,11 +285,11 @@ sal_Int8 SAL_CALL X11Clipboard::getRenderingCapabilities()
// ------------------------------------------------------------------------
-#if 0
void SAL_CALL X11Clipboard::addClipboardListener( const Reference< XClipboardListener >& listener )
throw(RuntimeException)
{
- rBHelper.addListener( getCppuType( (const ::com::sun::star::uno::Reference< XClipboard > *) 0), listener );
+ MutexGuard aGuard( m_aMutex );
+ m_aListeners.push_back( listener );
}
// ------------------------------------------------------------------------
@@ -298,10 +297,10 @@ void SAL_CALL X11Clipboard::addClipboardListener( const Reference< XClipboardLis
void SAL_CALL X11Clipboard::removeClipboardListener( const Reference< XClipboardListener >& listener )
throw(RuntimeException)
{
- rBHelper.removeListener( getCppuType( (const Reference< XClipboardListener > *) 0 ), listener );
+ MutexGuard aGuard( m_aMutex );
+ m_aListeners.remove( listener );
}
-#endif
// ------------------------------------------------------------------------
@@ -317,13 +316,21 @@ void X11Clipboard::clearTransferable()
clearContents();
}
+// ------------------------------------------------------------------------
+
+void X11Clipboard::fireContentsChanged()
+{
+ fireChangedContentsEvent();
+}
+
/*
* X11ClipboardHolder
*/
X11ClipboardHolder::X11ClipboardHolder() :
- ::cppu::WeakComponentImplHelper3<
+ ::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 )
@@ -370,7 +377,10 @@ void X11ClipboardHolder::initialize( const Sequence< Any >& arguments )
nSelection = rManager.getAtom( OUString::createFromAscii( "CLIPBOARD" ) );
}
- m_xRealClipboard = X11Clipboard::get( aDisplayName, nSelection );
+ X11Clipboard* pClipboard = X11Clipboard::get( aDisplayName, nSelection );
+ m_xRealClipboard = pClipboard;
+ m_xRealNotifier = pClipboard;
+ pClipboard->setHolder( this );
}
// ------------------------------------------------------------------------
@@ -382,6 +392,22 @@ Reference< XTransferable > X11ClipboardHolder::getContents() throw(RuntimeExcept
// ------------------------------------------------------------------------
+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
diff --git a/dtrans/source/X11/X11_clipboard.hxx b/dtrans/source/X11/X11_clipboard.hxx
index 8caf8125c398..9d7d3ee7332d 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.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: pl $ $Date: 2001-02-16 14:37:50 $
+ * last change: $Author: pl $ $Date: 2001-06-22 17:47:46 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -71,15 +71,15 @@
#endif
#ifndef _COM_SUN_STAR_DATATRANSFER_CLIPBAORD_XCLIPBOARDNOTIFIER_HPP_
-//#include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
+#include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
#endif
-#ifndef _CPPUHELPER_COMPBASE3_HXX_
-#include <cppuhelper/compbase3.hxx>
+#ifndef _CPPUHELPER_COMPBASE4_HXX_
+#include <cppuhelper/compbase4.hxx>
#endif
-#ifndef _CPPUHELPER_COMPBASE1_HXX_
-#include <cppuhelper/compbase1.hxx>
+#ifndef _CPPUHELPER_COMPBASE2_HXX_
+#include <cppuhelper/compbase2.hxx>
#endif
// ------------------------------------------------------------------------
@@ -89,15 +89,18 @@
namespace x11 {
class X11ClipboardHolder :
- public ::cppu::WeakComponentImplHelper3 <
- ::com::sun::star::datatransfer::clipboard::XClipboardEx,
- ::com::sun::star::lang::XServiceInfo,
- ::com::sun::star::lang::XInitialization
- >
+ 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();
@@ -145,20 +148,18 @@ namespace x11 {
/*
* XClipboardNotifier
*/
-#if 0
- virtual void SAL_CALL addClipboardListener(
- const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener >& listener )
+ 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);
-#endif
};
class X11Clipboard :
- public ::cppu::WeakImplHelper1 <
- ::com::sun::star::datatransfer::clipboard::XClipboardEx
+ public ::cppu::WeakImplHelper2 <
+ ::com::sun::star::datatransfer::clipboard::XClipboardEx,
+ ::com::sun::star::datatransfer::clipboard::XClipboardNotifier
>,
public SelectionAdaptor
{
@@ -172,7 +173,9 @@ namespace x11 {
SelectionManager& m_rSelectionManager;
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:
@@ -189,6 +192,7 @@ 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; }
/*
* XClipboard
@@ -215,7 +219,6 @@ namespace x11 {
/*
* XClipboardNotifier
*/
-#if 0
virtual void SAL_CALL addClipboardListener(
const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener >& listener )
throw(RuntimeException);
@@ -223,14 +226,13 @@ namespace x11 {
virtual void SAL_CALL removeClipboardListener(
const Reference< ::com::sun::star::datatransfer::clipboard::XClipboardListener >& listener )
throw(RuntimeException);
-#endif
/*
* SelectionAdaptor
*/
virtual Reference< ::com::sun::star::datatransfer::XTransferable > getTransferable();
virtual void clearTransferable();
- // returns true if conversion was successful
+ virtual void fireContentsChanged();
};
// ------------------------------------------------------------------------
diff --git a/dtrans/source/X11/X11_selection.cxx b/dtrans/source/X11/X11_selection.cxx
index a8945cf2b468..05e9009dd48a 100644
--- a/dtrans/source/X11/X11_selection.cxx
+++ b/dtrans/source/X11/X11_selection.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: X11_selection.cxx,v $
*
- * $Revision: 1.28 $
+ * $Revision: 1.29 $
*
- * last change: $Author: pl $ $Date: 2001-06-19 18:32:11 $
+ * last change: $Author: pl $ $Date: 2001-06-22 17:47:46 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -639,6 +639,7 @@ bool SelectionManager::requestOwnership( Atom selection )
bSuccess ? "acquired" : "failed to acquire",
OUStringToOString( getString( selection ), RTL_TEXTENCODING_ISO_8859_1 ).getStr() );
#endif
+ m_aSelections[ selection ]->m_bOwner = bSuccess;
}
#ifdef DEBUG
else
@@ -2555,6 +2556,9 @@ void SelectionManager::handleXEvent( XEvent& rEvent )
SelectionAdaptor* pAdaptor = getAdaptor( rEvent.xselectionclear.selection );
if ( pAdaptor )
pAdaptor->clearTransferable();
+ ::std::hash_map< Atom, Selection* >::iterator it( m_aSelections.find( rEvent.xselectionclear.selection ) );
+ if( it != m_aSelections.end() )
+ it->second->m_bOwner = false;
}
break;
@@ -2653,11 +2657,37 @@ void SelectionManager::run( void* pThis )
SelectionManager* This = (SelectionManager*)pThis;
+ time_t nLast = time( NULL );
osl_yieldThread();
while( osl_scheduleThread(This->m_aThread) )
{
osl_yieldThread();
This->dispatchEvent( 200 );
+ time_t nNow = time( NULL );
+ if( nNow - nLast > 0 )
+ {
+ ClearableMutexGuard aGuard(This->m_aMutex);
+ ::std::list< SelectionAdaptor* > aChangeList;
+ nLast = nNow;
+ for( ::std::hash_map< Atom, Selection* >::iterator it = This->m_aSelections.begin(); it != This->m_aSelections.end(); ++it )
+ {
+ if( it->first != This->m_nXdndSelection && ! it->second->m_bOwner )
+ {
+ Window aOwner = XGetSelectionOwner( This->m_pDisplay, it->first );
+ if( aOwner != it->second->m_aLastOwner )
+ {
+ it->second->m_aLastOwner = aOwner;
+ aChangeList.push_back( it->second->m_pAdaptor );
+ }
+ }
+ }
+ aGuard.clear();
+ while( aChangeList.begin() != aChangeList.end() )
+ {
+ aChangeList.front()->fireContentsChanged();
+ aChangeList.pop_front();
+ }
+ }
}
}
@@ -2759,6 +2789,12 @@ void SelectionManager::clearTransferable()
// ------------------------------------------------------------------------
+void SelectionManager::fireContentsChanged()
+{
+}
+
+// ------------------------------------------------------------------------
+
/*
* SelectionManagerHolder
*/
diff --git a/dtrans/source/X11/X11_selection.hxx b/dtrans/source/X11/X11_selection.hxx
index 198e0f9bb180..1e8516beee4b 100644
--- a/dtrans/source/X11/X11_selection.hxx
+++ b/dtrans/source/X11/X11_selection.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: X11_selection.hxx,v $
*
- * $Revision: 1.12 $
+ * $Revision: 1.13 $
*
- * last change: $Author: pl $ $Date: 2001-05-23 13:46:58 $
+ * last change: $Author: pl $ $Date: 2001-06-22 17:47:46 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -123,6 +123,7 @@ namespace x11 {
public:
virtual Reference< ::com::sun::star::datatransfer::XTransferable > getTransferable() = 0;
virtual void clearTransferable() = 0;
+ virtual void fireContentsChanged() = 0;
};
class DropTarget :
@@ -258,12 +259,16 @@ namespace x11 {
// m_aTypes is invalid after 2 seconds
int m_nLastTimestamp;
bool m_bHaveUTF16;
+ bool m_bOwner;
+ Window m_aLastOwner;
Selection() : m_eState( Inactive ),
m_pAdaptor( NULL ),
m_aAtom( None ),
m_nLastTimestamp( 0 ),
- m_bHaveUTF16( false )
+ m_bHaveUTF16( false ),
+ m_bOwner( false ),
+ m_aLastOwner( None )
{}
};
@@ -494,6 +499,7 @@ namespace x11 {
// SelectionAdaptor for XdndSelection Drag (we are drag source)
virtual Reference< ::com::sun::star::datatransfer::XTransferable > getTransferable();
virtual void clearTransferable();
+ virtual void fireContentsChanged();
};
// ------------------------------------------------------------------------