1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef _DTRANS_X11_SELECTION_HXX_
29*cdf0e10cSrcweir #define _DTRANS_X11_SELECTION_HXX_
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <cppuhelper/compbase3.hxx>
32*cdf0e10cSrcweir #include <cppuhelper/compbase4.hxx>
33*cdf0e10cSrcweir #include <com/sun/star/datatransfer/XTransferable.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/XDragSource.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/awt/XDisplayConnection.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/script/XInvocation.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp>
41*cdf0e10cSrcweir #include <osl/thread.h>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #ifndef _OSL_CONDITION_HXX_
44*cdf0e10cSrcweir #include <osl/conditn.hxx>
45*cdf0e10cSrcweir #endif
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #include <hash_map>
48*cdf0e10cSrcweir #include <list>
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include "tools/prex.h"
51*cdf0e10cSrcweir #include <X11/Xlib.h>
52*cdf0e10cSrcweir #include "tools/postx.h"
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir #define XDND_IMPLEMENTATION_NAME "com.sun.star.datatransfer.dnd.XdndSupport"
55*cdf0e10cSrcweir #define XDND_DROPTARGET_IMPLEMENTATION_NAME "com.sun.star.datatransfer.dnd.XdndDropTarget"
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir namespace x11 {
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir 	class PixmapHolder; // in bmp.hxx
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir // ------------------------------------------------------------------------
64*cdf0e10cSrcweir 	rtl_TextEncoding getTextPlainEncoding( const ::rtl::OUString& rMimeType );
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir 	class SelectionAdaptor
67*cdf0e10cSrcweir 	{
68*cdf0e10cSrcweir 	public:
69*cdf0e10cSrcweir 		virtual com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > getTransferable() = 0;
70*cdf0e10cSrcweir 		virtual void clearTransferable() = 0;
71*cdf0e10cSrcweir         virtual void fireContentsChanged() = 0;
72*cdf0e10cSrcweir         virtual com::sun::star::uno::Reference< XInterface > getReference() = 0;
73*cdf0e10cSrcweir         // returns a reference that will keep the SelectionAdaptor alive until the
74*cdf0e10cSrcweir         // refernce is released
75*cdf0e10cSrcweir 	};
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir 	class DropTarget :
78*cdf0e10cSrcweir 		public ::cppu::WeakComponentImplHelper3<
79*cdf0e10cSrcweir 			::com::sun::star::datatransfer::dnd::XDropTarget,
80*cdf0e10cSrcweir 			::com::sun::star::lang::XInitialization,
81*cdf0e10cSrcweir 			::com::sun::star::lang::XServiceInfo
82*cdf0e10cSrcweir 		>
83*cdf0e10cSrcweir 	{
84*cdf0e10cSrcweir 	public:
85*cdf0e10cSrcweir 		::osl::Mutex				m_aMutex;
86*cdf0e10cSrcweir 		bool						m_bActive;
87*cdf0e10cSrcweir 		sal_Int8					m_nDefaultActions;
88*cdf0e10cSrcweir 		XLIB_Window					m_aTargetWindow;
89*cdf0e10cSrcweir 		class SelectionManager*		m_pSelectionManager;
90*cdf0e10cSrcweir 		com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSource >
91*cdf0e10cSrcweir 									m_xSelectionManager;
92*cdf0e10cSrcweir 		::std::list< com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDropTargetListener > >
93*cdf0e10cSrcweir 							m_aListeners;
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 		DropTarget();
96*cdf0e10cSrcweir 		virtual ~DropTarget();
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 		// convenience functions that loop over listeners
99*cdf0e10cSrcweir 		void dragEnter( const ::com::sun::star::datatransfer::dnd::DropTargetDragEnterEvent& dtde ) throw();
100*cdf0e10cSrcweir 		void dragExit( const ::com::sun::star::datatransfer::dnd::DropTargetEvent& dte ) throw();
101*cdf0e10cSrcweir 		void dragOver( const ::com::sun::star::datatransfer::dnd::DropTargetDragEvent& dtde ) throw();
102*cdf0e10cSrcweir 		void drop( const ::com::sun::star::datatransfer::dnd::DropTargetDropEvent& dtde ) throw();
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 		// XInitialization
105*cdf0e10cSrcweir 		virtual void		SAL_CALL initialize( const Sequence< Any >& args ) throw ( ::com::sun::star::uno::Exception );
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 		// XDropTarget
108*cdf0e10cSrcweir 		virtual void		SAL_CALL addDropTargetListener( const com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDropTargetListener >& ) throw();
109*cdf0e10cSrcweir 		virtual void		SAL_CALL removeDropTargetListener( const com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDropTargetListener >& ) throw();
110*cdf0e10cSrcweir 		virtual sal_Bool	SAL_CALL isActive() throw();
111*cdf0e10cSrcweir 		virtual void		SAL_CALL setActive( sal_Bool active ) throw();
112*cdf0e10cSrcweir 		virtual sal_Int8 	SAL_CALL getDefaultActions() throw();
113*cdf0e10cSrcweir 		virtual void		SAL_CALL setDefaultActions( sal_Int8 actions ) throw();
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 		// XServiceInfo
116*cdf0e10cSrcweir 		virtual ::rtl::OUString SAL_CALL getImplementationName() throw();
117*cdf0e10cSrcweir 		virtual sal_Bool	SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw();
118*cdf0e10cSrcweir 		virtual ::com::sun::star::uno::Sequence< ::rtl::OUString >
119*cdf0e10cSrcweir 							SAL_CALL getSupportedServiceNames() throw();
120*cdf0e10cSrcweir 	};
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 	class SelectionManagerHolder :
123*cdf0e10cSrcweir 		public ::cppu::WeakComponentImplHelper3<
124*cdf0e10cSrcweir 			::com::sun::star::datatransfer::dnd::XDragSource,
125*cdf0e10cSrcweir 			::com::sun::star::lang::XInitialization,
126*cdf0e10cSrcweir 			::com::sun::star::lang::XServiceInfo
127*cdf0e10cSrcweir 		>
128*cdf0e10cSrcweir 	{
129*cdf0e10cSrcweir 		::osl::Mutex m_aMutex;
130*cdf0e10cSrcweir 		com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSource >
131*cdf0e10cSrcweir 			m_xRealDragSource;
132*cdf0e10cSrcweir 	public:
133*cdf0e10cSrcweir 		SelectionManagerHolder();
134*cdf0e10cSrcweir 		virtual ~SelectionManagerHolder();
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir 		// XServiceInfo
137*cdf0e10cSrcweir 		virtual ::rtl::OUString SAL_CALL getImplementationName() throw();
138*cdf0e10cSrcweir 		virtual sal_Bool	SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw();
139*cdf0e10cSrcweir 		virtual ::com::sun::star::uno::Sequence< ::rtl::OUString >
140*cdf0e10cSrcweir 							SAL_CALL getSupportedServiceNames() throw();
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 		// XInitialization
143*cdf0e10cSrcweir 		virtual void		SAL_CALL initialize( const Sequence< Any >& arguments ) throw( ::com::sun::star::uno::Exception );
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 		// XDragSource
146*cdf0e10cSrcweir 		virtual sal_Bool	SAL_CALL isDragImageSupported() throw();
147*cdf0e10cSrcweir 		virtual sal_Int32	SAL_CALL getDefaultCursor( sal_Int8 dragAction ) throw();
148*cdf0e10cSrcweir 		virtual void		SAL_CALL startDrag(
149*cdf0e10cSrcweir 			const ::com::sun::star::datatransfer::dnd::DragGestureEvent& trigger,
150*cdf0e10cSrcweir 			sal_Int8 sourceActions, sal_Int32 cursor, sal_Int32 image,
151*cdf0e10cSrcweir 			const com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >& transferable,
152*cdf0e10cSrcweir 			const com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSourceListener >& listener
153*cdf0e10cSrcweir 			) throw();
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 	};
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 	class SelectionManager :
159*cdf0e10cSrcweir 		public ::cppu::WeakImplHelper4<
160*cdf0e10cSrcweir 			::com::sun::star::datatransfer::dnd::XDragSource,
161*cdf0e10cSrcweir 			::com::sun::star::lang::XInitialization,
162*cdf0e10cSrcweir 			::com::sun::star::awt::XEventHandler,
163*cdf0e10cSrcweir 			::com::sun::star::frame::XTerminateListener
164*cdf0e10cSrcweir 		>,
165*cdf0e10cSrcweir 		public SelectionAdaptor
166*cdf0e10cSrcweir 	{
167*cdf0e10cSrcweir         static ::std::hash_map< ::rtl::OUString, SelectionManager*, ::rtl::OUStringHash >& getInstances();
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 		// for INCR type selection transfer
170*cdf0e10cSrcweir 		// INCR protocol is used if the data cannot
171*cdf0e10cSrcweir 		// be transported at once but in parts
172*cdf0e10cSrcweir 		// IncrementalTransfer holds the bytes to be transmitted
173*cdf0e10cSrcweir 		// as well a the current position
174*cdf0e10cSrcweir 		// INCR triggers the delivery of the next part by deleting the
175*cdf0e10cSrcweir 		// property used to transfer the data
176*cdf0e10cSrcweir 		struct IncrementalTransfer
177*cdf0e10cSrcweir 		{
178*cdf0e10cSrcweir 			Sequence< sal_Int8 >			m_aData;
179*cdf0e10cSrcweir 			int								m_nBufferPos;
180*cdf0e10cSrcweir 			XLIB_Window							m_aRequestor;
181*cdf0e10cSrcweir 			Atom							m_aProperty;
182*cdf0e10cSrcweir 			Atom							m_aTarget;
183*cdf0e10cSrcweir 			int								m_nFormat;
184*cdf0e10cSrcweir 			int								m_nTransferStartTime;
185*cdf0e10cSrcweir 		};
186*cdf0e10cSrcweir         int m_nIncrementalThreshold;
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 		// a struct to hold the data associated with a selection
189*cdf0e10cSrcweir 		struct Selection
190*cdf0e10cSrcweir 		{
191*cdf0e10cSrcweir 			enum State
192*cdf0e10cSrcweir 			{
193*cdf0e10cSrcweir 				Inactive, WaitingForResponse, WaitingForData, IncrementalTransfer
194*cdf0e10cSrcweir 			};
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir 			State						m_eState;
197*cdf0e10cSrcweir 			SelectionAdaptor*			m_pAdaptor;
198*cdf0e10cSrcweir 			Atom						m_aAtom;
199*cdf0e10cSrcweir 			::osl::Condition			m_aDataArrived;
200*cdf0e10cSrcweir 			Sequence< sal_Int8 >		m_aData;
201*cdf0e10cSrcweir 			Sequence< ::com::sun::star::datatransfer::DataFlavor >
202*cdf0e10cSrcweir 										m_aTypes;
203*cdf0e10cSrcweir             std::vector< Atom >			m_aNativeTypes;
204*cdf0e10cSrcweir 			// this is used for caching
205*cdf0e10cSrcweir 			// m_aTypes is invalid after 2 seconds
206*cdf0e10cSrcweir             // m_aNativeTypes contains the corresponding original atom
207*cdf0e10cSrcweir             Atom						m_aRequestedType;
208*cdf0e10cSrcweir             // m_aRequestedType is only valid while WaitingForResponse and WaitingFotData
209*cdf0e10cSrcweir 			int							m_nLastTimestamp;
210*cdf0e10cSrcweir 			bool						m_bHaveUTF16;
211*cdf0e10cSrcweir             Atom                        m_aUTF8Type;
212*cdf0e10cSrcweir             bool						m_bHaveCompound;
213*cdf0e10cSrcweir             bool						m_bOwner;
214*cdf0e10cSrcweir             XLIB_Window					m_aLastOwner;
215*cdf0e10cSrcweir             PixmapHolder*				m_pPixmap;
216*cdf0e10cSrcweir             // m_nOrigXLIB_Timestamp contains the XLIB_Timestamp at which the seclection
217*cdf0e10cSrcweir             // was acquired; needed for XLIB_TimeSTAMP target
218*cdf0e10cSrcweir             XLIB_Time                        m_nOrigTimestamp;
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir 			Selection() : m_eState( Inactive ),
221*cdf0e10cSrcweir 						  m_pAdaptor( NULL ),
222*cdf0e10cSrcweir 						  m_aAtom( None ),
223*cdf0e10cSrcweir                           m_aRequestedType( None ),
224*cdf0e10cSrcweir 						  m_nLastTimestamp( 0 ),
225*cdf0e10cSrcweir 						  m_bHaveUTF16( false ),
226*cdf0e10cSrcweir                           m_aUTF8Type( None ),
227*cdf0e10cSrcweir                           m_bHaveCompound( false ),
228*cdf0e10cSrcweir                           m_bOwner( false ),
229*cdf0e10cSrcweir                           m_aLastOwner( None ),
230*cdf0e10cSrcweir                           m_pPixmap( NULL ),
231*cdf0e10cSrcweir                           m_nOrigTimestamp( CurrentTime )
232*cdf0e10cSrcweir 				{}
233*cdf0e10cSrcweir 		};
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir 		// a struct to hold data associated with a XDropTarget
236*cdf0e10cSrcweir 		struct DropTargetEntry
237*cdf0e10cSrcweir 		{
238*cdf0e10cSrcweir 			DropTarget*		m_pTarget;
239*cdf0e10cSrcweir 			XLIB_Window		m_aRootWindow;
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir 			DropTargetEntry() : m_pTarget( NULL ), m_aRootWindow( None ) {}
242*cdf0e10cSrcweir 			DropTargetEntry( DropTarget* pTarget ) :
243*cdf0e10cSrcweir 					m_pTarget( pTarget ),
244*cdf0e10cSrcweir 					m_aRootWindow( None )
245*cdf0e10cSrcweir 				{}
246*cdf0e10cSrcweir 			DropTargetEntry( const DropTargetEntry& rEntry ) :
247*cdf0e10cSrcweir 					m_pTarget( rEntry.m_pTarget ),
248*cdf0e10cSrcweir 					m_aRootWindow( rEntry.m_aRootWindow )
249*cdf0e10cSrcweir 				{}
250*cdf0e10cSrcweir 			~DropTargetEntry() {}
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 			DropTarget* operator->() const { return m_pTarget; }
253*cdf0e10cSrcweir 			DropTargetEntry& operator=(const DropTargetEntry& rEntry)
254*cdf0e10cSrcweir 				{ m_pTarget = rEntry.m_pTarget; m_aRootWindow = rEntry.m_aRootWindow; return *this; }
255*cdf0e10cSrcweir 		};
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir 		// internal data
258*cdf0e10cSrcweir 		Display*					m_pDisplay;
259*cdf0e10cSrcweir 		oslThread					m_aThread;
260*cdf0e10cSrcweir 		oslThread					m_aDragExecuteThread;
261*cdf0e10cSrcweir         ::osl::Condition			m_aDragRunning;
262*cdf0e10cSrcweir 		XLIB_Window					m_aWindow;
263*cdf0e10cSrcweir 		com::sun::star::uno::Reference< ::com::sun::star::awt::XDisplayConnection >
264*cdf0e10cSrcweir 									m_xDisplayConnection;
265*cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::script::XInvocation >
266*cdf0e10cSrcweir         							m_xBitmapConverter;
267*cdf0e10cSrcweir         sal_Int32                   m_nSelectionTimeout;
268*cdf0e10cSrcweir         XLIB_Time                   m_nSelectionTimestamp;
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir 		// members used for Xdnd
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 		// drop only
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir 		// contains the XdndEnterEvent of a drop action running
276*cdf0e10cSrcweir 		// with one of our targets. The data.l[0] member
277*cdf0e10cSrcweir 		// (conatining the drag source XLIB_Window) is set
278*cdf0e10cSrcweir 		// to None while that is not the case
279*cdf0e10cSrcweir 		XClientMessageEvent			m_aDropEnterEvent;
280*cdf0e10cSrcweir 		// set to false on XdndEnter
281*cdf0e10cSrcweir 		// set to true on first XdndPosition or XdndLeave
282*cdf0e10cSrcweir 		bool						m_bDropEnterSent;
283*cdf0e10cSrcweir 		XLIB_Window					m_aCurrentDropWindow;
284*cdf0e10cSrcweir 		// XLIB_Time code of XdndDrop
285*cdf0e10cSrcweir 		XLIB_Time					m_nDropTime;
286*cdf0e10cSrcweir 		sal_Int8					m_nLastDropAction;
287*cdf0e10cSrcweir 		// XTransferable for Xdnd with foreign drag source
288*cdf0e10cSrcweir 		com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >
289*cdf0e10cSrcweir 									m_xDropTransferable;
290*cdf0e10cSrcweir 		int							m_nLastX, m_nLastY;
291*cdf0e10cSrcweir 		XLIB_Time					m_nDropTimestamp;
292*cdf0e10cSrcweir         // set to true when calling drop()
293*cdf0e10cSrcweir         // if another XdndEnter is received this shows that
294*cdf0e10cSrcweir         // someone forgot to call dropComplete - we should reset
295*cdf0e10cSrcweir         // and react to the new drop
296*cdf0e10cSrcweir         bool                        m_bDropWaitingForCompletion;
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 		// drag only
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir 		// None if no Dnd action is running with us as source
301*cdf0e10cSrcweir 		XLIB_Window					m_aDropWindow;
302*cdf0e10cSrcweir 		// either m_aDropXLIB_Window or its XdndProxy
303*cdf0e10cSrcweir 		XLIB_Window					m_aDropProxy;
304*cdf0e10cSrcweir         XLIB_Window					m_aDragSourceWindow;
305*cdf0e10cSrcweir 		// XTransferable for Xdnd when we are drag source
306*cdf0e10cSrcweir 		com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >
307*cdf0e10cSrcweir 									m_xDragSourceTransferable;
308*cdf0e10cSrcweir 		com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSourceListener >
309*cdf0e10cSrcweir 									m_xDragSourceListener;
310*cdf0e10cSrcweir 		// root coordinates
311*cdf0e10cSrcweir 		int							m_nLastDragX, m_nLastDragY;
312*cdf0e10cSrcweir 		Sequence< ::com::sun::star::datatransfer::DataFlavor >
313*cdf0e10cSrcweir 									m_aDragFlavors;
314*cdf0e10cSrcweir 		// the rectangle the pointer must leave until a new XdndPosition should
315*cdf0e10cSrcweir 		// be sent. empty unless the drop target told to fill
316*cdf0e10cSrcweir 		int							m_nNoPosX, m_nNoPosY, m_nNoPosWidth, m_nNoPosHeight;
317*cdf0e10cSrcweir 		unsigned int				m_nDragButton;
318*cdf0e10cSrcweir 		sal_Int8					m_nUserDragAction;
319*cdf0e10cSrcweir         sal_Int8					m_nTargetAcceptAction;
320*cdf0e10cSrcweir 		sal_Int8					m_nSourceActions;
321*cdf0e10cSrcweir         bool						m_bLastDropAccepted;
322*cdf0e10cSrcweir 		bool						m_bDropSuccess;
323*cdf0e10cSrcweir 		bool						m_bDropSent;
324*cdf0e10cSrcweir 		time_t						m_nDropTimeout;
325*cdf0e10cSrcweir 		bool						m_bWaitingForPrimaryConversion;
326*cdf0e10cSrcweir 		XLIB_Time					m_nDragTimestamp;
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir 		// drag cursors
329*cdf0e10cSrcweir 		XLIB_Cursor                 m_aMoveCursor;
330*cdf0e10cSrcweir 		XLIB_Cursor                 m_aCopyCursor;
331*cdf0e10cSrcweir 		XLIB_Cursor                 m_aLinkCursor;
332*cdf0e10cSrcweir 		XLIB_Cursor                 m_aNoneCursor;
333*cdf0e10cSrcweir 		XLIB_Cursor                 m_aCurrentCursor;
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir 		// drag and drop
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir 		int							m_nCurrentProtocolVersion;
339*cdf0e10cSrcweir 		::std::hash_map< XLIB_Window, DropTargetEntry >
340*cdf0e10cSrcweir 									m_aDropTargets;
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir 		// some special atoms that are needed often
344*cdf0e10cSrcweir 		Atom						m_nCLIPBOARDAtom;
345*cdf0e10cSrcweir 		Atom						m_nTARGETSAtom;
346*cdf0e10cSrcweir         Atom                        m_nTIMESTAMPAtom;
347*cdf0e10cSrcweir 		Atom						m_nTEXTAtom;
348*cdf0e10cSrcweir 		Atom						m_nINCRAtom;
349*cdf0e10cSrcweir         Atom						m_nCOMPOUNDAtom;
350*cdf0e10cSrcweir         Atom						m_nMULTIPLEAtom;
351*cdf0e10cSrcweir         Atom						m_nUTF16Atom;
352*cdf0e10cSrcweir         Atom                        m_nImageBmpAtom;
353*cdf0e10cSrcweir 		Atom						m_nXdndAware;
354*cdf0e10cSrcweir 		Atom						m_nXdndEnter;
355*cdf0e10cSrcweir 		Atom						m_nXdndLeave;
356*cdf0e10cSrcweir 		Atom						m_nXdndPosition;
357*cdf0e10cSrcweir 		Atom						m_nXdndStatus;
358*cdf0e10cSrcweir 		Atom						m_nXdndDrop;
359*cdf0e10cSrcweir 		Atom						m_nXdndFinished;
360*cdf0e10cSrcweir 		Atom						m_nXdndSelection;
361*cdf0e10cSrcweir 		Atom						m_nXdndTypeList;
362*cdf0e10cSrcweir 		Atom						m_nXdndProxy;
363*cdf0e10cSrcweir 		Atom						m_nXdndActionCopy;
364*cdf0e10cSrcweir 		Atom						m_nXdndActionMove;
365*cdf0e10cSrcweir 		Atom						m_nXdndActionLink;
366*cdf0e10cSrcweir 		Atom						m_nXdndActionAsk;
367*cdf0e10cSrcweir 		Atom						m_nXdndActionPrivate;
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir 		// caching for atoms
370*cdf0e10cSrcweir 		::std::hash_map< Atom, ::rtl::OUString >
371*cdf0e10cSrcweir 									m_aAtomToString;
372*cdf0e10cSrcweir 		::std::hash_map< ::rtl::OUString, Atom, ::rtl::OUStringHash >
373*cdf0e10cSrcweir 									m_aStringToAtom;
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir 		// the registered selections
376*cdf0e10cSrcweir 		::std::hash_map< Atom, Selection* >
377*cdf0e10cSrcweir 									m_aSelections;
378*cdf0e10cSrcweir 		// IncrementalTransfers in progress
379*cdf0e10cSrcweir 		std::hash_map< XLIB_Window, std::hash_map< Atom, IncrementalTransfer > >
380*cdf0e10cSrcweir 									m_aIncrementals;
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir 		// do not use X11 multithreading capabilities
383*cdf0e10cSrcweir 		// since this leads to deadlocks in different Xlib implentations
384*cdf0e10cSrcweir 		// (XFree as well as Xsun) use an own mutex instead
385*cdf0e10cSrcweir 		::osl::Mutex				m_aMutex;
386*cdf0e10cSrcweir         bool                        m_bShutDown;
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir 		SelectionManager();
389*cdf0e10cSrcweir 		~SelectionManager();
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir 		SelectionAdaptor* getAdaptor( Atom selection );
392*cdf0e10cSrcweir         PixmapHolder* getPixmapHolder( Atom selection );
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir 		// handle various events
395*cdf0e10cSrcweir 		bool handleSelectionRequest( XSelectionRequestEvent& rRequest );
396*cdf0e10cSrcweir 		bool handleSendPropertyNotify( XPropertyEvent& rNotify );
397*cdf0e10cSrcweir 		bool handleReceivePropertyNotify( XPropertyEvent& rNotify );
398*cdf0e10cSrcweir 		bool handleSelectionNotify( XSelectionEvent& rNotify );
399*cdf0e10cSrcweir 		bool handleDragEvent( XEvent& rMessage );
400*cdf0e10cSrcweir 		bool handleDropEvent( XClientMessageEvent& rMessage );
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir 		// dnd helpers
403*cdf0e10cSrcweir 		void sendDragStatus( Atom nDropAction );
404*cdf0e10cSrcweir 		void sendDropPosition( bool bForce, XLIB_Time eventXLIB_Time );
405*cdf0e10cSrcweir 		bool updateDragAction( int modifierState );
406*cdf0e10cSrcweir 		int getXdndVersion( XLIB_Window aXLIB_Window, XLIB_Window& rProxy );
407*cdf0e10cSrcweir 		XLIB_Cursor createCursor( const char* pPointerData, const char* pMaskData, int width, int height, int hotX, int hotY );
408*cdf0e10cSrcweir 		// coordinates on root XLIB_Window
409*cdf0e10cSrcweir 		void updateDragWindow( int nX, int nY, XLIB_Window aRoot );
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir 		bool getPasteData( Atom selection, Atom type, Sequence< sal_Int8 >& rData );
412*cdf0e10cSrcweir 		// returns true if conversion was successful
413*cdf0e10cSrcweir 		bool convertData( const com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >& xTransferable,
414*cdf0e10cSrcweir 						  Atom nType,
415*cdf0e10cSrcweir                           Atom nSelection,
416*cdf0e10cSrcweir                           int & rFormat,
417*cdf0e10cSrcweir 						  Sequence< sal_Int8 >& rData );
418*cdf0e10cSrcweir         bool sendData( SelectionAdaptor* pAdaptor, XLIB_Window requestor, Atom target, Atom property, Atom selection );
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 		// thread dispatch loop
421*cdf0e10cSrcweir         public:
422*cdf0e10cSrcweir         // public for extern "C" stub
423*cdf0e10cSrcweir 		static void run( void* );
424*cdf0e10cSrcweir         private:
425*cdf0e10cSrcweir 		void dispatchEvent( int millisec );
426*cdf0e10cSrcweir 		// drag thread dispatch
427*cdf0e10cSrcweir         public:
428*cdf0e10cSrcweir         // public for extern "C" stub
429*cdf0e10cSrcweir 		static void runDragExecute( void* );
430*cdf0e10cSrcweir         private:
431*cdf0e10cSrcweir 		void dragDoDispatch();
432*cdf0e10cSrcweir 		bool handleXEvent( XEvent& rEvent );
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir         // compound text conversion
435*cdf0e10cSrcweir         ::rtl::OString convertToCompound( const ::rtl::OUString& rText );
436*cdf0e10cSrcweir         ::rtl::OUString convertFromCompound( const char* pText, int nLen = -1 );
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir         sal_Int8 getUserDragAction() const;
439*cdf0e10cSrcweir         sal_Int32 getSelectionTimeout();
440*cdf0e10cSrcweir 	public:
441*cdf0e10cSrcweir 		static SelectionManager& get( const ::rtl::OUString& rDisplayName = ::rtl::OUString() );
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir 		Display * getDisplay() { return m_pDisplay; };
444*cdf0e10cSrcweir 		XLIB_Window getWindow() { return m_aWindow; };
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir 		void registerHandler( Atom selection, SelectionAdaptor& rAdaptor );
448*cdf0e10cSrcweir 		void deregisterHandler( Atom selection );
449*cdf0e10cSrcweir 		bool requestOwnership( Atom selection );
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir         // allow for synchronization over one mutex for XClipboard
452*cdf0e10cSrcweir         osl::Mutex& getMutex() { return m_aMutex; }
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir 		Atom getAtom( const ::rtl::OUString& rString );
456*cdf0e10cSrcweir 		const ::rtl::OUString& getString( Atom nAtom );
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir 		// type conversion
459*cdf0e10cSrcweir         // note: convertTypeToNative does NOT clear the list, so you can append
460*cdf0e10cSrcweir         // multiple types to the same list
461*cdf0e10cSrcweir 		void convertTypeToNative( const ::rtl::OUString& rType, Atom selection, int& rFormat, ::std::list< Atom >& rConversions, bool bPushFront = false );
462*cdf0e10cSrcweir 		::rtl::OUString convertTypeFromNative( Atom nType, Atom selection, int& rFormat );
463*cdf0e10cSrcweir         void getNativeTypeList( const Sequence< com::sun::star::datatransfer::DataFlavor >& rTypes, std::list< Atom >& rOutTypeList, Atom targetselection );
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir 		// methods for transferable
466*cdf0e10cSrcweir 		bool getPasteDataTypes( Atom selection, Sequence< ::com::sun::star::datatransfer::DataFlavor >& rTypes );
467*cdf0e10cSrcweir 		bool getPasteData( Atom selection, const ::rtl::OUString& rType, Sequence< sal_Int8 >& rData );
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir 		// for XDropTarget to register/deregister itself
470*cdf0e10cSrcweir 		void registerDropTarget( XLIB_Window aXLIB_Window, DropTarget* pTarget );
471*cdf0e10cSrcweir 		void deregisterDropTarget( XLIB_Window aXLIB_Window );
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir 		// for XDropTarget{Drag|Drop}Context
474*cdf0e10cSrcweir 		void accept( sal_Int8 dragOperation, XLIB_Window aDropXLIB_Window, XLIB_Time aXLIB_Timestamp );
475*cdf0e10cSrcweir 		void reject( XLIB_Window aDropXLIB_Window, XLIB_Time aXLIB_Timestamp );
476*cdf0e10cSrcweir 		void dropComplete( sal_Bool success, XLIB_Window aDropXLIB_Window, XLIB_Time aXLIB_Timestamp );
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir 		// for XDragSourceContext
479*cdf0e10cSrcweir 		sal_Int32 getCurrentCursor();
480*cdf0e10cSrcweir 		void setCursor( sal_Int32 cursor, XLIB_Window aDropXLIB_Window, XLIB_Time aXLIB_Timestamp );
481*cdf0e10cSrcweir 		void setImage( sal_Int32 image, XLIB_Window aDropXLIB_Window, XLIB_Time aXLIB_Timestamp );
482*cdf0e10cSrcweir 		void transferablesFlavorsChanged();
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir         void shutdown() throw();
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir 		// XInitialization
487*cdf0e10cSrcweir 		virtual void		SAL_CALL initialize( const Sequence< Any >& arguments ) throw( ::com::sun::star::uno::Exception );
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir 		// XEventHandler
490*cdf0e10cSrcweir 		virtual sal_Bool	SAL_CALL handleEvent( const Any& event ) throw();
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir 		// XDragSource
493*cdf0e10cSrcweir 		virtual sal_Bool	SAL_CALL isDragImageSupported() throw();
494*cdf0e10cSrcweir 		virtual sal_Int32	SAL_CALL getDefaultCursor( sal_Int8 dragAction ) throw();
495*cdf0e10cSrcweir 		virtual void		SAL_CALL startDrag(
496*cdf0e10cSrcweir 			const ::com::sun::star::datatransfer::dnd::DragGestureEvent& trigger,
497*cdf0e10cSrcweir 			sal_Int8 sourceActions, sal_Int32 cursor, sal_Int32 image,
498*cdf0e10cSrcweir 			const com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >& transferable,
499*cdf0e10cSrcweir 			const com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSourceListener >& listener
500*cdf0e10cSrcweir 			) throw();
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir 		// SelectionAdaptor for XdndSelection Drag (we are drag source)
503*cdf0e10cSrcweir 		virtual com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > getTransferable() throw();
504*cdf0e10cSrcweir 		virtual void clearTransferable() throw();
505*cdf0e10cSrcweir         virtual void fireContentsChanged() throw();
506*cdf0e10cSrcweir         virtual com::sun::star::uno::Reference< XInterface > getReference() throw();
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir         // XEventListener
509*cdf0e10cSrcweir         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw( ::com::sun::star::uno::RuntimeException );
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir         // XTerminateListener
512*cdf0e10cSrcweir         virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& aEvent )
513*cdf0e10cSrcweir                 throw( ::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException );
514*cdf0e10cSrcweir         virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& aEvent )
515*cdf0e10cSrcweir                 throw( ::com::sun::star::uno::RuntimeException );
516*cdf0e10cSrcweir 	};
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir // ------------------------------------------------------------------------
519*cdf0e10cSrcweir 
520*cdf0e10cSrcweir 	::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL Xdnd_getSupportedServiceNames();
521*cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL Xdnd_createInstance(
522*cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xMultiServiceFactory);
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir 	::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL Xdnd_dropTarget_getSupportedServiceNames();
525*cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL Xdnd_dropTarget_createInstance(
526*cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xMultiServiceFactory);
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir // ------------------------------------------------------------------------
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir }
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir #endif
533