Update ooo320-m1
[ooovba.git] / UnoControls / source / base / basecontrol.cxx
blob8a587492d60aa1b21d6c5c6214598b60b9bb5214
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: basecontrol.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 //____________________________________________________________________________________________________________
32 // my own include
33 //____________________________________________________________________________________________________________
35 #include "basecontrol.hxx"
37 //____________________________________________________________________________________________________________
38 // includes of other projects
39 //____________________________________________________________________________________________________________
40 #include <com/sun/star/awt/XDevice.hpp>
41 #include <com/sun/star/awt/XDisplayBitmap.hpp>
42 #include <com/sun/star/awt/DeviceInfo.hpp>
43 #include <com/sun/star/awt/WindowAttribute.hpp>
44 #include <com/sun/star/awt/PosSize.hpp>
45 #include <cppuhelper/typeprovider.hxx>
47 //____________________________________________________________________________________________________________
48 // includes of my own project
49 //____________________________________________________________________________________________________________
51 //____________________________________________________________________________________________________________
52 // namespaces
53 //____________________________________________________________________________________________________________
55 using namespace ::cppu ;
56 using namespace ::osl ;
57 using namespace ::rtl ;
58 using namespace ::com::sun::star::uno ;
59 using namespace ::com::sun::star::lang ;
60 using namespace ::com::sun::star::awt ;
62 namespace unocontrols{
64 //____________________________________________________________________________________________________________
65 // defines
66 //____________________________________________________________________________________________________________
68 #define DEFAULT_PMULTIPLEXER NULL
69 #define DEFAULT_X 0
70 #define DEFAULT_Y 0
71 #define DEFAULT_WIDTH 100
72 #define DEFAULT_HEIGHT 100
73 #define DEFAULT_VISIBLE sal_False
74 #define DEFAULT_INDESIGNMODE sal_False
75 #define DEFAULT_ENABLE sal_True
76 #define SERVICE_VCLTOOLKIT "com.sun.star.awt.Toolkit"
78 //____________________________________________________________________________________________________________
79 // construct/destruct
80 //____________________________________________________________________________________________________________
82 BaseControl::BaseControl( const Reference< XMultiServiceFactory >& xFactory )
83 : IMPL_MutexContainer ( )
84 , OComponentHelper ( m_aMutex )
85 , m_xFactory ( xFactory )
86 , m_pMultiplexer ( DEFAULT_PMULTIPLEXER )
87 , m_nX ( DEFAULT_X )
88 , m_nY ( DEFAULT_Y )
89 , m_nWidth ( DEFAULT_WIDTH )
90 , m_nHeight ( DEFAULT_HEIGHT )
91 , m_bVisible ( DEFAULT_VISIBLE )
92 , m_bInDesignMode ( DEFAULT_INDESIGNMODE )
93 , m_bEnable ( DEFAULT_ENABLE )
97 BaseControl::~BaseControl()
101 //____________________________________________________________________________________________________________
102 // XInterface
103 //____________________________________________________________________________________________________________
105 Any SAL_CALL BaseControl::queryInterface( const Type& rType ) throw( RuntimeException )
107 Any aReturn ;
108 if ( m_xDelegator.is() == sal_True )
110 // If an delegator exist, forward question to his queryInterface.
111 // Delegator will ask his own queryAggregation!
112 aReturn = m_xDelegator->queryInterface( rType );
114 else
116 // If an delegator unknown, forward question to own queryAggregation.
117 aReturn = queryAggregation( rType );
120 return aReturn ;
123 //____________________________________________________________________________________________________________
124 // XInterface
125 //____________________________________________________________________________________________________________
127 void SAL_CALL BaseControl::acquire() throw()
129 // Attention:
130 // Don't use mutex or guard in this method!!! Is a method of XInterface.
132 // Forward to baseclass
133 OComponentHelper::acquire();
136 //____________________________________________________________________________________________________________
137 // XInterface
138 //____________________________________________________________________________________________________________
140 void SAL_CALL BaseControl::release() throw()
142 // Attention:
143 // Don't use mutex or guard in this method!!! Is a method of XInterface.
145 // Forward to baseclass
146 OComponentHelper::release();
149 //____________________________________________________________________________________________________________
150 // XTypeProvider
151 //____________________________________________________________________________________________________________
153 Sequence< Type > SAL_CALL BaseControl::getTypes() throw( RuntimeException )
155 // Optimize this method !
156 // We initialize a static variable only one time. And we don't must use a mutex at every call!
157 // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
158 static OTypeCollection* pTypeCollection = NULL ;
160 if ( pTypeCollection == NULL )
162 // Ready for multithreading; get global mutex for first call of this method only! see before
163 MutexGuard aGuard( Mutex::getGlobalMutex() );
165 // Control these pointer again ... it can be, that another instance will be faster then these!
166 if ( pTypeCollection == NULL )
168 // Create a static typecollection ...
169 static OTypeCollection aTypeCollection ( ::getCppuType(( const Reference< XPaintListener >*)NULL ) ,
170 ::getCppuType(( const Reference< XWindowListener>*)NULL ) ,
171 ::getCppuType(( const Reference< XView >*)NULL ) ,
172 ::getCppuType(( const Reference< XWindow >*)NULL ) ,
173 ::getCppuType(( const Reference< XServiceInfo >*)NULL ) ,
174 ::getCppuType(( const Reference< XControl >*)NULL ) ,
175 OComponentHelper::getTypes()
178 // ... and set his address to static pointer!
179 pTypeCollection = &aTypeCollection ;
183 return pTypeCollection->getTypes();
186 //____________________________________________________________________________________________________________
187 // XTypeProvider
188 //____________________________________________________________________________________________________________
190 Sequence< sal_Int8 > SAL_CALL BaseControl::getImplementationId() throw( RuntimeException )
192 // Create one Id for all instances of this class.
193 // Use ethernet address to do this! (sal_True)
195 // Optimize this method
196 // We initialize a static variable only one time. And we don't must use a mutex at every call!
197 // For the first call; pID is NULL - for the second call pID is different from NULL!
198 static OImplementationId* pID = NULL ;
200 if ( pID == NULL )
202 // Ready for multithreading; get global mutex for first call of this method only! see before
203 MutexGuard aGuard( Mutex::getGlobalMutex() );
205 // Control these pointer again ... it can be, that another instance will be faster then these!
206 if ( pID == NULL )
208 // Create a new static ID ...
209 static OImplementationId aID( sal_False );
210 // ... and set his address to static pointer!
211 pID = &aID ;
215 return pID->getImplementationId();
218 //____________________________________________________________________________________________________________
219 // XAggregation
220 //____________________________________________________________________________________________________________
222 void SAL_CALL BaseControl::setDelegator( const Reference< XInterface >& xDel ) throw( RuntimeException )
224 // Ready for multithreading
225 MutexGuard aGuard( m_aMutex );
226 m_xDelegator = xDel;
229 //____________________________________________________________________________________________________________
230 // XAggregation
231 //____________________________________________________________________________________________________________
233 Any SAL_CALL BaseControl::queryAggregation( const Type& aType ) throw( RuntimeException )
235 // Ask for my own supported interfaces ...
236 // Attention: XTypeProvider and XInterface are supported by OComponentHelper!
237 Any aReturn ( ::cppu::queryInterface( aType ,
238 static_cast< XPaintListener*> ( this ) ,
239 static_cast< XWindowListener*> ( this ) ,
240 static_cast< XView* > ( this ) ,
241 static_cast< XWindow* > ( this ) ,
242 static_cast< XServiceInfo* > ( this ) ,
243 static_cast< XControl* > ( this )
247 // If searched interface supported by this class ...
248 if ( aReturn.hasValue() == sal_True )
250 // ... return this information.
251 return aReturn ;
253 else
255 // Else; ... ask baseclass for interfaces!
256 return OComponentHelper::queryAggregation( aType );
260 //____________________________________________________________________________________________________________
261 // XServiceInfo
262 //____________________________________________________________________________________________________________
264 OUString SAL_CALL BaseControl::getImplementationName() throw( RuntimeException )
266 return impl_getStaticImplementationName();
269 //____________________________________________________________________________________________________________
270 // XServiceInfo
271 //____________________________________________________________________________________________________________
273 sal_Bool SAL_CALL BaseControl::supportsService( const OUString& sServiceName ) throw( RuntimeException )
275 Sequence< OUString > seqServiceNames = getSupportedServiceNames();
276 const OUString* pArray = seqServiceNames.getConstArray();
277 for ( sal_Int32 nCounter=0; nCounter<seqServiceNames.getLength(); nCounter++ )
279 if ( pArray[nCounter] == sServiceName )
281 return sal_True ;
284 return sal_False ;
287 //____________________________________________________________________________________________________________
288 // XServiceInfo
289 //____________________________________________________________________________________________________________
291 Sequence< OUString > SAL_CALL BaseControl::getSupportedServiceNames() throw( RuntimeException )
293 return impl_getStaticSupportedServiceNames();
296 //____________________________________________________________________________________________________________
297 // XComponent
298 //____________________________________________________________________________________________________________
300 void SAL_CALL BaseControl::dispose() throw( RuntimeException )
302 // Ready for multithreading
303 MutexGuard aGuard( m_aMutex );
305 if ( m_pMultiplexer != NULL )
307 // to all other paint, focus, etc.
308 m_pMultiplexer->disposeAndClear();
311 // set the service manager to disposed
312 OComponentHelper::dispose();
314 // release context and peer
315 m_xContext = Reference< XInterface >();
316 impl_releasePeer();
318 // release view
319 if ( m_xGraphicsView.is() == sal_True )
321 m_xGraphicsView = Reference< XGraphics >();
325 //____________________________________________________________________________________________________________
326 // XComponent
327 //____________________________________________________________________________________________________________
329 void SAL_CALL BaseControl::addEventListener( const Reference< XEventListener >& xListener ) throw( RuntimeException )
331 // Ready for multithreading
332 MutexGuard aGuard( m_aMutex );
333 OComponentHelper::addEventListener( xListener );
336 //____________________________________________________________________________________________________________
337 // XComponent
338 //____________________________________________________________________________________________________________
340 void SAL_CALL BaseControl::removeEventListener( const Reference< XEventListener >& xListener ) throw( RuntimeException )
342 // Ready for multithreading
343 MutexGuard aGuard( m_aMutex );
344 OComponentHelper::removeEventListener( xListener );
347 //____________________________________________________________________________________________________________
348 // XControl
349 //____________________________________________________________________________________________________________
351 void SAL_CALL BaseControl::createPeer( const Reference< XToolkit >& xToolkit ,
352 const Reference< XWindowPeer >& xParentPeer ) throw( RuntimeException )
354 // Ready for multithreading
355 MutexGuard aGuard( m_aMutex );
357 if ( m_xPeer.is() == sal_False )
359 // use method "BaseControl::getWindowDescriptor()" fot change window attributes !!!
360 WindowDescriptor* pDescriptor = impl_getWindowDescriptor( xParentPeer );
362 if ( m_bVisible == sal_True )
364 pDescriptor->WindowAttributes |= WindowAttribute::SHOW ;
367 // very slow under remote conditions!
368 // create the window on the server
369 Reference< XToolkit > xLocalToolkit = xToolkit ;
370 if ( xLocalToolkit.is() == sal_False )
372 // but first create wellknown toolkit, if it not exist
373 xLocalToolkit = Reference< XToolkit > ( m_xFactory->createInstance( OUString::createFromAscii( SERVICE_VCLTOOLKIT ) ), UNO_QUERY );
375 m_xPeer = xLocalToolkit->createWindow( *pDescriptor );
376 m_xPeerWindow = Reference< XWindow >( m_xPeer, UNO_QUERY );
378 // don't forget to release the memory!
379 delete pDescriptor ;
381 if ( m_xPeerWindow.is() == sal_True )
383 if ( m_pMultiplexer != NULL )
385 m_pMultiplexer->setPeer( m_xPeerWindow );
388 // create new referenz to xgraphics for painting on a peer
389 // and add a paint listener
390 Reference< XDevice > xDevice( m_xPeerWindow, UNO_QUERY );
392 if ( xDevice.is() == sal_True )
394 m_xGraphicsPeer = xDevice->createGraphics();
397 if ( m_xGraphicsPeer.is() == sal_True )
399 addPaintListener( this );
400 addWindowListener( this );
403 // PosSize_POSSIZE defined in <stardiv/uno/awt/window.hxx>
404 m_xPeerWindow->setPosSize( m_nX, m_nY, m_nWidth, m_nHeight, PosSize::POSSIZE );
405 m_xPeerWindow->setEnable( m_bEnable );
406 m_xPeerWindow->setVisible( m_bVisible && !m_bInDesignMode );
411 //____________________________________________________________________________________________________________
412 // XControl
413 //____________________________________________________________________________________________________________
415 void SAL_CALL BaseControl::setContext( const Reference< XInterface >& xContext ) throw( RuntimeException )
417 // Ready for multithreading
418 MutexGuard aGuard( m_aMutex );
419 m_xContext = xContext ;
422 //____________________________________________________________________________________________________________
423 // XControl
424 //____________________________________________________________________________________________________________
426 void SAL_CALL BaseControl::setDesignMode( sal_Bool bOn ) throw( RuntimeException )
428 // Ready for multithreading
429 MutexGuard aGuard( m_aMutex );
430 m_bInDesignMode = bOn ;
433 //____________________________________________________________________________________________________________
434 // XControl
435 //____________________________________________________________________________________________________________
437 Reference< XInterface > SAL_CALL BaseControl::getContext() throw( RuntimeException )
439 // Ready for multithreading
440 MutexGuard aGuard( m_aMutex );
441 return m_xContext ;
444 //____________________________________________________________________________________________________________
445 // XControl
446 //____________________________________________________________________________________________________________
448 Reference< XWindowPeer > SAL_CALL BaseControl::getPeer() throw( RuntimeException )
450 // Ready for multithreading
451 MutexGuard aGuard( m_aMutex );
452 return m_xPeer ;
455 //____________________________________________________________________________________________________________
456 // XControl
457 //____________________________________________________________________________________________________________
459 Reference< XView > SAL_CALL BaseControl::getView() throw( RuntimeException )
461 // Ready for multithreading
462 MutexGuard aGuard( m_aMutex );
463 return Reference< XView >( (OWeakObject*)this, UNO_QUERY );
466 //____________________________________________________________________________________________________________
467 // XControl
468 //____________________________________________________________________________________________________________
470 sal_Bool SAL_CALL BaseControl::isDesignMode() throw( RuntimeException )
472 // Ready for multithreading
473 MutexGuard aGuard( m_aMutex );
474 return m_bInDesignMode ;
477 //____________________________________________________________________________________________________________
478 // XControl
479 //____________________________________________________________________________________________________________
481 sal_Bool SAL_CALL BaseControl::isTransparent() throw( RuntimeException )
483 return sal_False ;
486 //____________________________________________________________________________________________________________
487 // XWindow
488 //____________________________________________________________________________________________________________
490 void SAL_CALL BaseControl::setPosSize( sal_Int32 nX ,
491 sal_Int32 nY ,
492 sal_Int32 nWidth ,
493 sal_Int32 nHeight ,
494 sal_Int16 nFlags ) throw( RuntimeException )
496 // - change size and position of window and save the values
497 // - "nFlags" declared in <stardiv/uno/awt/window.hxx> ("#define PosSize_X .....")
499 // Ready for multithreading
500 MutexGuard aGuard( m_aMutex );
502 sal_Bool bChanged = sal_False ;
504 if ( nFlags & PosSize::X )
506 bChanged |= m_nX != nX, m_nX = nX ;
509 if ( nFlags & PosSize::Y )
511 bChanged |= m_nY != nY, m_nY = nY ;
514 if ( nFlags & PosSize::WIDTH )
516 bChanged |= m_nWidth != nWidth, m_nWidth = nWidth ;
519 if ( nFlags & PosSize::HEIGHT )
521 bChanged |= m_nHeight != nHeight, m_nHeight = nHeight ;
524 if ( bChanged && m_xPeerWindow.is() )
526 m_xPeerWindow->setPosSize( m_nX, m_nY, m_nWidth, m_nHeight, nFlags );
530 //____________________________________________________________________________________________________________
531 // XWindow
532 //____________________________________________________________________________________________________________
534 void SAL_CALL BaseControl::setVisible( sal_Bool bVisible ) throw( RuntimeException )
536 // Ready for multithreading
537 MutexGuard aGuard( m_aMutex );
539 // Set new state of flag
540 m_bVisible = bVisible ;
542 if ( m_xPeerWindow.is() == sal_True )
544 // Set it also on peerwindow
545 m_xPeerWindow->setVisible( m_bVisible );
549 //____________________________________________________________________________________________________________
550 // XWindow
551 //____________________________________________________________________________________________________________
553 void SAL_CALL BaseControl::setEnable( sal_Bool bEnable ) throw( RuntimeException )
555 // Ready for multithreading
556 MutexGuard aGuard( m_aMutex );
558 // Set new state of flag
559 m_bEnable = bEnable ;
561 if ( m_xPeerWindow.is() == sal_True )
563 // Set it also on peerwindow
564 m_xPeerWindow->setEnable( m_bEnable );
568 //____________________________________________________________________________________________________________
569 // XWindow
570 //____________________________________________________________________________________________________________
572 void SAL_CALL BaseControl::setFocus() throw( RuntimeException )
574 // Ready for multithreading
575 MutexGuard aGuard( m_aMutex );
577 if ( m_xPeerWindow.is() == sal_True )
579 m_xPeerWindow->setFocus();
583 //____________________________________________________________________________________________________________
584 // XWindow
585 //____________________________________________________________________________________________________________
587 Rectangle SAL_CALL BaseControl::getPosSize() throw( RuntimeException )
589 // Ready for multithreading
590 MutexGuard aGuard( m_aMutex );
591 return Rectangle( m_nX, m_nY , m_nWidth, m_nHeight );
594 //____________________________________________________________________________________________________________
595 // XWindow
596 //____________________________________________________________________________________________________________
598 void SAL_CALL BaseControl::addWindowListener( const Reference< XWindowListener >& xListener ) throw( RuntimeException )
600 impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XWindowListener >*)0), xListener );
603 //____________________________________________________________________________________________________________
604 // XWindow
605 //____________________________________________________________________________________________________________
607 void SAL_CALL BaseControl::addFocusListener( const Reference< XFocusListener >& xListener ) throw( RuntimeException )
609 impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XFocusListener >*)0), xListener );
612 //____________________________________________________________________________________________________________
613 // XWindow
614 //____________________________________________________________________________________________________________
616 void SAL_CALL BaseControl::addKeyListener( const Reference< XKeyListener >& xListener ) throw( RuntimeException )
618 impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XKeyListener >*)0), xListener );
621 //____________________________________________________________________________________________________________
622 // XWindow
623 //____________________________________________________________________________________________________________
625 void SAL_CALL BaseControl::addMouseListener( const Reference< XMouseListener >& xListener ) throw( RuntimeException )
627 impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XMouseListener >*)0), xListener );
630 //____________________________________________________________________________________________________________
631 // XWindow
632 //____________________________________________________________________________________________________________
634 void SAL_CALL BaseControl::addMouseMotionListener( const Reference< XMouseMotionListener >& xListener ) throw( RuntimeException )
636 impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XMouseMotionListener >*)0), xListener );
639 //____________________________________________________________________________________________________________
640 // XWindow
641 //____________________________________________________________________________________________________________
643 void SAL_CALL BaseControl::addPaintListener( const Reference< XPaintListener >& xListener ) throw( RuntimeException )
645 impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XPaintListener >*)0), xListener );
648 //____________________________________________________________________________________________________________
649 // XWindow
650 //____________________________________________________________________________________________________________
652 void SAL_CALL BaseControl::removeWindowListener( const Reference< XWindowListener >& xListener ) throw( RuntimeException )
654 impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XWindowListener >*)0), xListener );
657 //____________________________________________________________________________________________________________
658 // XWindow
659 //____________________________________________________________________________________________________________
661 void SAL_CALL BaseControl::removeFocusListener( const Reference< XFocusListener >& xListener ) throw( RuntimeException )
663 impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XFocusListener >*)0), xListener );
666 //____________________________________________________________________________________________________________
667 // XWindow
668 //____________________________________________________________________________________________________________
670 void SAL_CALL BaseControl::removeKeyListener( const Reference< XKeyListener >& xListener ) throw( RuntimeException )
672 impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XKeyListener >*)0), xListener );
675 //____________________________________________________________________________________________________________
676 // XWindow
677 //____________________________________________________________________________________________________________
679 void SAL_CALL BaseControl::removeMouseListener( const Reference< XMouseListener >& xListener ) throw( RuntimeException )
681 impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XMouseListener >*)0), xListener );
684 //____________________________________________________________________________________________________________
685 // XWindow
686 //____________________________________________________________________________________________________________
688 void SAL_CALL BaseControl::removeMouseMotionListener( const Reference< XMouseMotionListener >& xListener ) throw( RuntimeException )
690 impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XMouseMotionListener >*)0), xListener );
693 //____________________________________________________________________________________________________________
694 // XWindow
695 //____________________________________________________________________________________________________________
697 void SAL_CALL BaseControl::removePaintListener( const Reference< XPaintListener >& xListener ) throw( RuntimeException )
699 impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XPaintListener >*)0), xListener );
702 //____________________________________________________________________________________________________________
703 // XView
704 //____________________________________________________________________________________________________________
706 void SAL_CALL BaseControl::draw( sal_Int32 nX ,
707 sal_Int32 nY ) throw( RuntimeException )
709 // Ready for multithreading
710 MutexGuard aGuard( m_aMutex );
712 // - paint to an view
713 // - use the method "paint()"
714 // - see also "windowPaint()"
715 impl_paint( nX, nY, m_xGraphicsView );
718 //____________________________________________________________________________________________________________
719 // XView
720 //____________________________________________________________________________________________________________
722 sal_Bool SAL_CALL BaseControl::setGraphics( const Reference< XGraphics >& xDevice ) throw( RuntimeException )
724 // - set the graphics for an view
725 // - in this class exist 2 graphics-member ... one for peer[_xGraphicsPeer] and one for view[_xGraphicsView]
726 // - they are used by "windowPaint() and draw()", forwarded to "paint ()"
727 sal_Bool bReturn = sal_False ;
728 if ( xDevice.is() == sal_True )
730 // Ready for multithreading
731 MutexGuard aGuard( m_aMutex );
733 m_xGraphicsView = xDevice ;
734 bReturn = sal_True ;
737 return bReturn ;
740 //____________________________________________________________________________________________________________
741 // XView
742 //____________________________________________________________________________________________________________
744 void SAL_CALL BaseControl::setZoom( float /*fZoomX*/ ,
745 float /*fZoomY*/ ) throw( RuntimeException )
747 // Not implemented yet
750 //____________________________________________________________________________________________________________
751 // XView
752 //____________________________________________________________________________________________________________
754 Reference< XGraphics > SAL_CALL BaseControl::getGraphics() throw( RuntimeException )
756 // Ready for multithreading
757 MutexGuard aGuard( m_aMutex );
758 return m_xGraphicsView ;
761 //____________________________________________________________________________________________________________
762 // XView
763 //____________________________________________________________________________________________________________
765 Size SAL_CALL BaseControl::getSize() throw( RuntimeException )
767 // Ready for multithreading
768 MutexGuard aGuard( m_aMutex );
769 return Size( m_nWidth, m_nHeight );
772 //____________________________________________________________________________________________________________
773 // XEventListener
774 //____________________________________________________________________________________________________________
776 void SAL_CALL BaseControl::disposing( const EventObject& /*aSource*/ ) throw( RuntimeException )
778 // Ready for multithreading
779 MutexGuard aGuard( m_aMutex );
781 // - release ALL references
782 // - it must be !!!
783 if ( m_xGraphicsPeer.is() == sal_True )
785 removePaintListener( this );
786 removeWindowListener( this );
787 m_xGraphicsPeer = Reference< XGraphics >();
790 if ( m_xGraphicsView.is() == sal_True )
792 m_xGraphicsView = Reference< XGraphics >();
796 //____________________________________________________________________________________________________________
797 // XPaintListener
798 //____________________________________________________________________________________________________________
800 void SAL_CALL BaseControl::windowPaint( const PaintEvent& /*aEvent*/ ) throw( RuntimeException )
802 // Ready for multithreading
803 MutexGuard aGuard( m_aMutex );
805 // - repaint the peer
806 // - use the method "paint ()" for painting on a peer and a print device !!!
807 // - see also "draw ()"
808 impl_paint( 0, 0, m_xGraphicsPeer );
811 //____________________________________________________________________________________________________________
812 // XWindowListener
813 //____________________________________________________________________________________________________________
815 void SAL_CALL BaseControl::windowResized( const WindowEvent& aEvent ) throw( RuntimeException )
817 // Ready for multithreading
818 MutexGuard aGuard( m_aMutex );
820 m_nWidth = aEvent.Width ;
821 m_nHeight = aEvent.Height ;
822 WindowEvent aMappedEvent = aEvent;
823 aMappedEvent.X = 0;
824 aMappedEvent.Y = 0;
825 impl_recalcLayout( aMappedEvent );
828 //____________________________________________________________________________________________________________
829 // XWindowListener
830 //____________________________________________________________________________________________________________
832 void SAL_CALL BaseControl::windowMoved( const WindowEvent& aEvent ) throw( RuntimeException )
834 // Ready for multithreading
835 MutexGuard aGuard( m_aMutex );
837 m_nWidth = aEvent.Width ;
838 m_nHeight = aEvent.Height ;
839 WindowEvent aMappedEvent = aEvent;
840 aMappedEvent.X = 0;
841 aMappedEvent.Y = 0;
842 impl_recalcLayout( aMappedEvent );
845 //____________________________________________________________________________________________________________
846 // XWindowListener
847 //____________________________________________________________________________________________________________
849 void SAL_CALL BaseControl::windowShown( const EventObject& /*aEvent*/ ) throw( RuntimeException )
853 //____________________________________________________________________________________________________________
854 // XWindowListener
855 //____________________________________________________________________________________________________________
857 void SAL_CALL BaseControl::windowHidden( const EventObject& /*aEvent*/ ) throw( RuntimeException )
861 //____________________________________________________________________________________________________________
862 // impl but public method to register service in DLL
863 // (In this BASE-implementation not implemented! Overwrite it in derived classes.)
864 //____________________________________________________________________________________________________________
866 const Sequence< OUString > BaseControl::impl_getStaticSupportedServiceNames()
868 return Sequence< OUString >();
871 //____________________________________________________________________________________________________________
872 // impl but public method to register service in DLL
873 // (In this BASE-implementation not implemented! Overwrite it in derived classes.)
874 //____________________________________________________________________________________________________________
876 const OUString BaseControl::impl_getStaticImplementationName()
878 return OUString();
881 //____________________________________________________________________________________________________________
882 // protected method
883 //____________________________________________________________________________________________________________
885 const Reference< XMultiServiceFactory > BaseControl::impl_getMultiServiceFactory()
887 return m_xFactory ;
890 //____________________________________________________________________________________________________________
891 // protected method
892 //____________________________________________________________________________________________________________
894 const Reference< XWindow > BaseControl::impl_getPeerWindow()
896 return m_xPeerWindow ;
899 //____________________________________________________________________________________________________________
900 // protected method
901 //____________________________________________________________________________________________________________
903 const Reference< XGraphics > BaseControl::impl_getGraphicsPeer()
905 return m_xGraphicsPeer ;
908 //____________________________________________________________________________________________________________
909 // protected method
910 //____________________________________________________________________________________________________________
912 const sal_Int32& BaseControl::impl_getWidth()
914 return m_nWidth ;
917 //____________________________________________________________________________________________________________
918 // protected method
919 //____________________________________________________________________________________________________________
921 const sal_Int32& BaseControl::impl_getHeight()
923 return m_nHeight ;
926 //____________________________________________________________________________________________________________
927 // protected method
928 //____________________________________________________________________________________________________________
930 WindowDescriptor* BaseControl::impl_getWindowDescriptor( const Reference< XWindowPeer >& xParentPeer )
932 // - used from "createPeer()" to set the values of an ::com::sun::star::awt::WindowDescriptor !!!
933 // - if you will change the descriptor-values, you must override this virtuell function
934 // - the caller must release the memory for this dynamical descriptor !!!
936 WindowDescriptor* pDescriptor = new WindowDescriptor ;
938 pDescriptor->Type = WindowClass_SIMPLE ;
939 pDescriptor->WindowServiceName = OUString::createFromAscii( "window" ) ;
940 pDescriptor->ParentIndex = -1 ;
941 pDescriptor->Parent = xParentPeer ;
942 pDescriptor->Bounds = getPosSize () ;
943 pDescriptor->WindowAttributes = 0 ;
945 return pDescriptor ;
948 //____________________________________________________________________________________________________________
949 // protected method
950 //____________________________________________________________________________________________________________
952 void BaseControl::impl_paint( sal_Int32 /*nX*/ ,
953 sal_Int32 /*nY*/ ,
954 const Reference< XGraphics >& /*xGraphics*/ )
956 // - one paint method for peer AND view !!!
957 // (see also => "windowPaint()" and "draw()")
958 // - not used in this implementation, but its not necessary to make it pure virtual !!!
961 //____________________________________________________________________________________________________________
962 // protected method
963 //____________________________________________________________________________________________________________
965 void BaseControl::impl_recalcLayout( const WindowEvent& /*aEvent*/ )
967 // We need as virtual function to support automaticly resizing of derived controls!
968 // But we make it not pure virtual because it's not neccessary for all derived classes!
971 //____________________________________________________________________________________________________________
972 // protected method
973 //____________________________________________________________________________________________________________
975 Reference< XInterface > BaseControl::impl_getDelegator()
977 return m_xDelegator ;
980 //____________________________________________________________________________________________________________
981 // private method
982 //____________________________________________________________________________________________________________
984 void BaseControl::impl_releasePeer()
986 if ( m_xPeer.is() == sal_True )
988 if ( m_xGraphicsPeer.is() == sal_True )
990 removePaintListener( this );
991 removeWindowListener( this );
992 m_xGraphicsPeer = Reference< XGraphics >();
995 m_xPeer->dispose();
996 m_xPeerWindow = Reference< XWindow >();
997 m_xPeer = Reference< XWindowPeer >();
999 if ( m_pMultiplexer != NULL )
1001 // take changes on multiplexer
1002 m_pMultiplexer->setPeer( Reference< XWindow >() );
1007 //____________________________________________________________________________________________________________
1008 // private method
1009 //____________________________________________________________________________________________________________
1011 OMRCListenerMultiplexerHelper* BaseControl::impl_getMultiplexer()
1013 if ( m_pMultiplexer == NULL )
1015 m_pMultiplexer = new OMRCListenerMultiplexerHelper( (XWindow*)this, m_xPeerWindow );
1016 m_xMultiplexer = Reference< XInterface >( (OWeakObject*)m_pMultiplexer, UNO_QUERY );
1019 return m_pMultiplexer ;
1022 } // namespace unocontrols