1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #ifndef _UNOCONTROLS_MULTIPLEXER_HXX
30 #define _UNOCONTROLS_MULTIPLEXER_HXX
32 //____________________________________________________________________________________________________________
33 // includes of other projects
34 //____________________________________________________________________________________________________________
36 #include <com/sun/star/awt/XKeyListener.hpp>
37 #include <com/sun/star/awt/XPaintListener.hpp>
38 #include <com/sun/star/awt/KeyEvent.hpp>
39 #include <com/sun/star/awt/KeyModifier.hpp>
40 #include <com/sun/star/awt/XMouseMotionListener.hpp>
41 #include <com/sun/star/awt/FocusEvent.hpp>
42 #include <com/sun/star/awt/XWindowListener.hpp>
43 #include <com/sun/star/awt/XActivateListener.hpp>
44 #include <com/sun/star/awt/MouseEvent.hpp>
45 #include <com/sun/star/awt/XTopWindowListener.hpp>
46 #include <com/sun/star/awt/PaintEvent.hpp>
47 #include <com/sun/star/awt/InputEvent.hpp>
48 #include <com/sun/star/awt/KeyGroup.hpp>
49 #include <com/sun/star/awt/Key.hpp>
50 #include <com/sun/star/awt/WindowEvent.hpp>
51 #include <com/sun/star/awt/XMouseListener.hpp>
52 #include <com/sun/star/awt/KeyFunction.hpp>
53 #include <com/sun/star/awt/FocusChangeReason.hpp>
54 #include <com/sun/star/awt/MouseButton.hpp>
55 #include <com/sun/star/awt/XFocusListener.hpp>
56 #include <com/sun/star/awt/XTopWindow.hpp>
57 #include <com/sun/star/awt/XWindow.hpp>
58 #include <com/sun/star/awt/PosSize.hpp>
59 #include <cppuhelper/weak.hxx>
60 #include <cppuhelper/interfacecontainer.hxx>
61 //____________________________________________________________________________________________________________
62 // includes of my own project
63 //____________________________________________________________________________________________________________
65 //____________________________________________________________________________________________________________
67 //____________________________________________________________________________________________________________
69 namespace unocontrols
{
71 //____________________________________________________________________________________________________________
73 //____________________________________________________________________________________________________________
75 class OMRCListenerMultiplexerHelper
: public ::com::sun::star::awt::XFocusListener
76 , public ::com::sun::star::awt::XWindowListener
77 , public ::com::sun::star::awt::XKeyListener
78 , public ::com::sun::star::awt::XMouseListener
79 , public ::com::sun::star::awt::XMouseMotionListener
80 , public ::com::sun::star::awt::XPaintListener
81 , public ::com::sun::star::awt::XTopWindowListener
82 , public ::cppu::OWeakObject
85 //____________________________________________________________________________________________________________
87 //____________________________________________________________________________________________________________
91 //________________________________________________________________________________________________________
93 //________________________________________________________________________________________________________
95 /**_______________________________________________________________________________________________________
97 @descr Create a Multiplexer of XWindowEvents.
101 @param rControl The control. All listeners think that this is the original broadcaster.
102 @param rPeer The peer from which the original events are dispatched. Null is allowed.
109 OMRCListenerMultiplexerHelper( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& xControl
,
110 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& xPeer
);
112 /**_______________________________________________________________________________________________________
113 @short copy-constructor
118 @param rCopyInstance C++-Reference to instance to make copy from.
125 OMRCListenerMultiplexerHelper( const OMRCListenerMultiplexerHelper
& aCopyInstance
);
127 /**_______________________________________________________________________________________________________
140 ~OMRCListenerMultiplexerHelper();
142 //________________________________________________________________________________________________________
144 //________________________________________________________________________________________________________
146 /**_______________________________________________________________________________________________________
147 @short give answer, if interface is supported
148 @descr The interfaces are searched by type.
152 @param "rType" is the type of searched interface.
154 @return Any information about found interface
156 @onerror A RuntimeException is thrown.
159 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& aType
)
160 throw( ::com::sun::star::uno::RuntimeException
);
162 /**_______________________________________________________________________________________________________
163 @short increment refcount
173 @onerror A RuntimeException is thrown.
176 virtual void SAL_CALL
acquire() throw();
178 /**_______________________________________________________________________________________________________
179 @short decrement refcount
189 @onerror A RuntimeException is thrown.
192 virtual void SAL_CALL
release() throw();
194 //________________________________________________________________________________________________________
196 //________________________________________________________________________________________________________
198 /**_______________________________________________________________________________________________________
211 operator ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>() const;
213 /**_______________________________________________________________________________________________________
226 OMRCListenerMultiplexerHelper
& operator= ( const OMRCListenerMultiplexerHelper
& aCopyInstance
);
228 //________________________________________________________________________________________________________
230 //________________________________________________________________________________________________________
232 /**_______________________________________________________________________________________________________
233 @short Remove all listeners from the previous set peer and add the needed listeners to rPeer.
238 @param rPeer The peer from which the original events are dispatched. Null is allowed.
245 void setPeer( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& xPeer
);
247 /**_______________________________________________________________________________________________________
248 @short Remove all listeners and send a disposing message.
260 void disposeAndClear();
262 /**_______________________________________________________________________________________________________
263 @short Add the specified listener to the source.
275 void advise( const ::com::sun::star::uno::Type
& aType
,
276 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xListener
);
278 /**_______________________________________________________________________________________________________
279 @short Remove the specified listener from the source.
291 void unadvise( const ::com::sun::star::uno::Type
& aType
,
292 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xListener
);
294 //________________________________________________________________________________________________________
296 //________________________________________________________________________________________________________
298 /**_______________________________________________________________________________________________________
312 virtual void SAL_CALL
disposing(const ::com::sun::star::lang::EventObject
& aSource
)
313 throw( ::com::sun::star::uno::RuntimeException
) ;
315 //________________________________________________________________________________________________________
317 //________________________________________________________________________________________________________
319 /**_______________________________________________________________________________________________________
333 virtual void SAL_CALL
focusGained(const ::com::sun::star::awt::FocusEvent
& aEvent
)
334 throw( ::com::sun::star::uno::RuntimeException
) ;
336 /**_______________________________________________________________________________________________________
350 virtual void SAL_CALL
focusLost(const ::com::sun::star::awt::FocusEvent
& aEvent
)
351 throw( ::com::sun::star::uno::RuntimeException
) ;
353 //________________________________________________________________________________________________________
355 //________________________________________________________________________________________________________
357 /**_______________________________________________________________________________________________________
371 virtual void SAL_CALL
windowResized(const ::com::sun::star::awt::WindowEvent
& aEvent
)
372 throw( ::com::sun::star::uno::RuntimeException
) ;
374 /**_______________________________________________________________________________________________________
388 virtual void SAL_CALL
windowMoved(const ::com::sun::star::awt::WindowEvent
& aEvent
)
389 throw( ::com::sun::star::uno::RuntimeException
) ;
391 /**_______________________________________________________________________________________________________
405 virtual void SAL_CALL
windowShown(const ::com::sun::star::lang::EventObject
& aEvent
)
406 throw( ::com::sun::star::uno::RuntimeException
) ;
408 /**_______________________________________________________________________________________________________
422 virtual void SAL_CALL
windowHidden(const ::com::sun::star::lang::EventObject
& aEvent
)
423 throw( ::com::sun::star::uno::RuntimeException
) ;
425 //________________________________________________________________________________________________________
427 //________________________________________________________________________________________________________
429 /**_______________________________________________________________________________________________________
443 virtual void SAL_CALL
keyPressed( const ::com::sun::star::awt::KeyEvent
& aEvent
)
444 throw( ::com::sun::star::uno::RuntimeException
) ;
446 /**_______________________________________________________________________________________________________
460 virtual void SAL_CALL
keyReleased( const ::com::sun::star::awt::KeyEvent
& aEvent
)
461 throw( ::com::sun::star::uno::RuntimeException
) ;
463 //________________________________________________________________________________________________________
465 //________________________________________________________________________________________________________
467 /**_______________________________________________________________________________________________________
481 virtual void SAL_CALL
mousePressed(const ::com::sun::star::awt::MouseEvent
& aEvent
)
482 throw( ::com::sun::star::uno::RuntimeException
) ;
484 /**_______________________________________________________________________________________________________
498 virtual void SAL_CALL
mouseReleased(const ::com::sun::star::awt::MouseEvent
& aEvent
)
499 throw( ::com::sun::star::uno::RuntimeException
) ;
501 /**_______________________________________________________________________________________________________
515 virtual void SAL_CALL
mouseEntered(const ::com::sun::star::awt::MouseEvent
& aEvent
)
516 throw( ::com::sun::star::uno::RuntimeException
) ;
518 /**_______________________________________________________________________________________________________
532 virtual void SAL_CALL
mouseExited(const ::com::sun::star::awt::MouseEvent
& aEvent
)
533 throw( ::com::sun::star::uno::RuntimeException
) ;
535 //________________________________________________________________________________________________________
536 // XMouseMotionListener
537 //________________________________________________________________________________________________________
539 /**_______________________________________________________________________________________________________
553 virtual void SAL_CALL
mouseDragged(const ::com::sun::star::awt::MouseEvent
& aEvent
)
554 throw( ::com::sun::star::uno::RuntimeException
) ;
556 /**_______________________________________________________________________________________________________
570 virtual void SAL_CALL
mouseMoved(const ::com::sun::star::awt::MouseEvent
& aEvent
)
571 throw( ::com::sun::star::uno::RuntimeException
) ;
573 //________________________________________________________________________________________________________
575 //________________________________________________________________________________________________________
577 /**_______________________________________________________________________________________________________
591 virtual void SAL_CALL
windowPaint(const ::com::sun::star::awt::PaintEvent
& aEvent
)
592 throw( ::com::sun::star::uno::RuntimeException
) ;
594 //________________________________________________________________________________________________________
595 // XTopWindowListener
596 //________________________________________________________________________________________________________
598 /**_______________________________________________________________________________________________________
612 virtual void SAL_CALL
windowOpened( const ::com::sun::star::lang::EventObject
& aEvent
)
613 throw( ::com::sun::star::uno::RuntimeException
) ;
615 /**_______________________________________________________________________________________________________
629 virtual void SAL_CALL
windowClosing( const ::com::sun::star::lang::EventObject
& aEvent
)
630 throw( ::com::sun::star::uno::RuntimeException
) ;
632 /**_______________________________________________________________________________________________________
646 virtual void SAL_CALL
windowClosed( const ::com::sun::star::lang::EventObject
& aEvent
)
647 throw( ::com::sun::star::uno::RuntimeException
) ;
649 /**_______________________________________________________________________________________________________
663 virtual void SAL_CALL
windowMinimized( const ::com::sun::star::lang::EventObject
& aEvent
)
664 throw( ::com::sun::star::uno::RuntimeException
) ;
666 /**_______________________________________________________________________________________________________
680 virtual void SAL_CALL
windowNormalized( const ::com::sun::star::lang::EventObject
& aEvent
)
681 throw( ::com::sun::star::uno::RuntimeException
) ;
683 /**_______________________________________________________________________________________________________
697 virtual void SAL_CALL
windowActivated( const ::com::sun::star::lang::EventObject
& aEvent
)
698 throw( ::com::sun::star::uno::RuntimeException
) ;
700 /**_______________________________________________________________________________________________________
714 virtual void SAL_CALL
windowDeactivated( const ::com::sun::star::lang::EventObject
& aEvent
)
715 throw( ::com::sun::star::uno::RuntimeException
) ;
717 //____________________________________________________________________________________________________________
719 //____________________________________________________________________________________________________________
723 /**_______________________________________________________________________________________________________
724 @short Remove the listener from the peer.
729 @param xPeer The peer from which the listener is removed.
730 @param rType The listener type, which specify the type of the listener.
737 void impl_adviseToPeer( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& xPeer
,
738 const ::com::sun::star::uno::Type
& aType
);
740 /**_______________________________________________________________________________________________________
741 @short Add the listener to the peer.
746 @param xPeer The peer to which the listener is added.
747 @param rType The listener type, which specify the type of the listener.
754 void impl_unadviseFromPeer( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& xPeer
,
755 const ::com::sun::star::uno::Type
& aType
);
757 //____________________________________________________________________________________________________________
759 //____________________________________________________________________________________________________________
763 ::osl::Mutex m_aMutex
;
764 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> m_xPeer
; /// The source of the events. Normally this is the peer object.
765 ::com::sun::star::uno::WeakReference
< ::com::sun::star::awt::XWindow
> m_xControl
;
766 ::cppu::OMultiTypeInterfaceContainerHelper m_aListenerHolder
;
768 }; // class OMRCListenerMultiplexerHelper
770 } // namespace unocontrols
772 #endif // ifndef _UNOCONTROLS_MULTIPLEXER_HXX
774 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */