diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2000-09-18 15:18:56 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2000-09-18 15:18:56 +0000 |
commit | 95117e7fefa9ae82431dcdffd1e58495730f6f54 (patch) | |
tree | 158386e9f19cda5c69023d678c4d3313435a206d /UnoControls/source/base |
initial import
Diffstat (limited to 'UnoControls/source/base')
-rw-r--r-- | UnoControls/source/base/basecontainercontrol.cxx | 683 | ||||
-rw-r--r-- | UnoControls/source/base/basecontrol.cxx | 1008 | ||||
-rw-r--r-- | UnoControls/source/base/makefile.mk | 104 | ||||
-rw-r--r-- | UnoControls/source/base/multiplexer.cxx | 610 | ||||
-rw-r--r-- | UnoControls/source/base/registercontrols.cxx | 393 |
5 files changed, 2798 insertions, 0 deletions
diff --git a/UnoControls/source/base/basecontainercontrol.cxx b/UnoControls/source/base/basecontainercontrol.cxx new file mode 100644 index 000000000000..81733b3eecba --- /dev/null +++ b/UnoControls/source/base/basecontainercontrol.cxx @@ -0,0 +1,683 @@ +/************************************************************************* + * + * $RCSfile: basecontainercontrol.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:11:17 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +//____________________________________________________________________________________________________________ +// my own includes +//____________________________________________________________________________________________________________ + +#ifndef _UNOCONTROLS_BASECONTAINERCONTROL_CTRL_HXX +#include "basecontainercontrol.hxx" +#endif + +//____________________________________________________________________________________________________________ +// includes of other projects +//____________________________________________________________________________________________________________ + +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif + +//____________________________________________________________________________________________________________ +// includes of my own project +//____________________________________________________________________________________________________________ + +//____________________________________________________________________________________________________________ +// namespaces +//____________________________________________________________________________________________________________ + +using namespace ::cppu ; +using namespace ::osl ; +using namespace ::rtl ; +using namespace ::com::sun::star::uno ; +using namespace ::com::sun::star::lang ; +using namespace ::com::sun::star::awt ; +using namespace ::com::sun::star::container ; + +namespace unocontrols{ + +//____________________________________________________________________________________________________________ +// construct/destruct +//____________________________________________________________________________________________________________ + +BaseContainerControl::BaseContainerControl( const Reference< XMultiServiceFactory >& xFactory ) + : BaseControl ( xFactory ) + , m_aListeners ( m_aMutex ) +{ + // initialize info list for controls + m_pControlInfoList = new IMPL_ControlInfoList ; +} + +BaseContainerControl::~BaseContainerControl() +{ + impl_cleanMemory(); +} + +//____________________________________________________________________________________________________________ +// XInterface +//____________________________________________________________________________________________________________ + +Any SAL_CALL BaseContainerControl::queryInterface( const Type& rType ) throw( RuntimeException ) +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + Any aReturn ; + Reference< XInterface > xDelegator = BaseControl::impl_getDelegator(); + if ( xDelegator.is() == sal_True ) + { + // If an delegator exist, forward question to his queryInterface. + // Delegator will ask his own queryAggregation! + aReturn = xDelegator->queryInterface( rType ); + } + else + { + // If an delegator unknown, forward question to own queryAggregation. + aReturn = queryAggregation( rType ); + } + + return aReturn ; +} + +//____________________________________________________________________________________________________________ +// XTypeProvider +//____________________________________________________________________________________________________________ + +Sequence< Type > SAL_CALL BaseContainerControl::getTypes() throw( RuntimeException ) +{ + // Optimize this method ! + // We initialize a static variable only one time. And we don't must use a mutex at every call! + // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL! + static OTypeCollection* pTypeCollection = NULL ; + + if ( pTypeCollection == NULL ) + { + // Ready for multithreading; get global mutex for first call of this method only! see before + MutexGuard aGuard( Mutex::getGlobalMutex() ); + + // Control these pointer again ... it can be, that another instance will be faster then these! + if ( pTypeCollection == NULL ) + { + // Create a static typecollection ... + static OTypeCollection aTypeCollection ( ::getCppuType(( const Reference< XControlModel >*)NULL ) , + ::getCppuType(( const Reference< XControlContainer >*)NULL ) , + BaseControl::getTypes() + ); + // ... and set his address to static pointer! + pTypeCollection = &aTypeCollection ; + } + } + + return pTypeCollection->getTypes(); +} + +//____________________________________________________________________________________________________________ +// XAggregation +//____________________________________________________________________________________________________________ + +Any SAL_CALL BaseContainerControl::queryAggregation( const Type& aType ) throw( RuntimeException ) +{ + // Ask for my own supported interfaces ... + // Attention: XTypeProvider and XInterface are supported by OComponentHelper! + Any aReturn ( ::cppu::queryInterface( aType , + static_cast< XControlModel* > ( this ) , + static_cast< XControlContainer* > ( this ) + ) + ); + + // If searched interface supported by this class ... + if ( aReturn.hasValue() == sal_True ) + { + // ... return this information. + return aReturn ; + } + else + { + // Else; ... ask baseclass for interfaces! + return BaseControl::queryAggregation( aType ); + } +} + +//____________________________________________________________________________________________________________ +// XControl +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseContainerControl::createPeer( const Reference< XToolkit >& xToolkit , + const Reference< XWindowPeer >& xParent ) throw( RuntimeException ) +{ + if ( getPeer().is() == sal_False ) + { + // create own peer + BaseControl::createPeer( xToolkit, xParent ); + + // create peers at all childs + Sequence< Reference< XControl > > seqControlList = getControls(); + sal_uInt32 nControls = seqControlList.getLength(); + + for ( sal_uInt32 n=0; n<nControls; n++ ) + { + seqControlList.getArray()[n]->createPeer( xToolkit, getPeer() ); + } + + // activate new tab order + impl_activateTabControllers(); + +/* + Reference< XVclContainerPeer > xC; + mxPeer->queryInterface( ::getCppuType((const Reference< XVclContainerPeer >*)0), xC ); + xC->enableDialogControl( sal_True ); +*/ + + } +} + +//____________________________________________________________________________________________________________ +// XControl +//____________________________________________________________________________________________________________ + +sal_Bool SAL_CALL BaseContainerControl::setModel( const Reference< XControlModel >& xModel ) throw( RuntimeException ) +{ + // This object has NO model. + return sal_False ; +} + +//____________________________________________________________________________________________________________ +// XControl +//____________________________________________________________________________________________________________ + +Reference< XControlModel > SAL_CALL BaseContainerControl::getModel() throw( RuntimeException ) +{ + // This object has NO model. + // return (XControlModel*)this ; + return Reference< XControlModel >(); +} + +//____________________________________________________________________________________________________________ +// XComponent +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseContainerControl::dispose() throw( RuntimeException ) +{ + // Zuerst der Welt mitteilen, da der Container wegfliegt. Dieses ist um einiges + // schneller wenn die Welt sowohl an den Controls als auch am Container horcht + + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // remove listeners + EventObject aObject ; + + aObject.Source = Reference< XComponent > ( (XControlContainer*)this, UNO_QUERY ); + m_aListeners.disposeAndClear( aObject ); + + // remove controls + Sequence< Reference< XControl > > seqCtrls = getControls(); + Reference< XControl > * pCtrls = seqCtrls.getArray(); + sal_uInt32 nCtrls = seqCtrls.getLength(); + sal_uInt32 nMaxCount = m_pControlInfoList->Count(); + sal_uInt32 nCount = 0; + + for ( nCount = 0; nCount < nMaxCount; ++nCount ) + { + delete m_pControlInfoList->GetObject( 0 ); + } + m_pControlInfoList->Clear(); + + for ( nCount = 0; nCount < nCtrls; ++nCount ) + { + pCtrls [ nCount ] -> removeEventListener ( this ) ; + pCtrls [ nCount ] -> dispose ( ) ; + } + + // call baseclass + BaseControl::dispose(); +} + +//____________________________________________________________________________________________________________ +// XEventListener +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseContainerControl::disposing( const EventObject& rEvent ) throw( RuntimeException ) +{ + Reference< XControl > xControl( rEvent.Source, UNO_QUERY ); + + // "removeControl" remove only, when control is an active control + removeControl( xControl ); +} + +//____________________________________________________________________________________________________________ +// XControlContainer +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseContainerControl::addControl ( const OUString& rName, const Reference< XControl > & rControl ) throw( IllegalArgumentException, RuntimeException ) +{ + // only correct references can add to list!!! + if ( !rControl.is () ) + { + throw IllegalArgumentException (); + } + + // take memory for new item + IMPL_ControlInfo* pNewControl = new IMPL_ControlInfo ; + + if (pNewControl!=(IMPL_ControlInfo*)0) + { + // Ready for multithreading + MutexGuard aGuard (m_aMutex) ; + + // set control + pNewControl->sName = rName ; + pNewControl->xControl = rControl ; + + // and insert in list + m_pControlInfoList->Insert ( pNewControl, LIST_APPEND ) ; + + // initialize new control + pNewControl->xControl->setContext ( (OWeakObject*)this ) ; + pNewControl->xControl->addEventListener ( this ) ; + + // when container has a peer ... + if (getPeer().is()) + { + // .. then create a peer on child + pNewControl->xControl->createPeer ( getPeer()->getToolkit(), getPeer() ) ; + impl_activateTabControllers () ; + } + + // Send message to all listener + OInterfaceContainerHelper* pInterfaceContainer = m_aListeners.getContainer( ::getCppuType((const Reference< XContainerListener >*)0) ) ; + + if (pInterfaceContainer) + { + // Build event + ContainerEvent aEvent ; + + aEvent.Source = *this ; + aEvent.Element <<= rControl ; + + // Get all listener + OInterfaceIteratorHelper aIterator (*pInterfaceContainer) ; + + // Send event + while ( aIterator.hasMoreElements() ) + { + ((XContainerListener*)aIterator.next())->elementInserted (aEvent) ; + } + } + } +} + +//____________________________________________________________________________________________________________ +// XControlContainer +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseContainerControl::addContainerListener ( const Reference< XContainerListener > & rListener ) throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ) ; + + m_aListeners.addInterface ( ::getCppuType((const Reference< XContainerListener >*)0), rListener ) ; +} + +//____________________________________________________________________________________________________________ +// XControlContainer +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseContainerControl::removeControl ( const Reference< XControl > & rControl ) throw( RuntimeException ) +{ + if ( rControl.is() ) + { + // Ready for multithreading + MutexGuard aGuard (m_aMutex) ; + + sal_uInt32 nControls = m_pControlInfoList->Count () ; + + for ( sal_uInt32 n=0; n<nControls; n++ ) + { + // Search for right control + IMPL_ControlInfo* pControl = m_pControlInfoList->GetObject (n) ; + if ( rControl == pControl->xControl ) + { + //.is it found ... remove listener from control + pControl->xControl->removeEventListener ( this ) ; + pControl->xControl->setContext ( Reference< XInterface > () ) ; + + // ... free memory + delete pControl ; + m_pControlInfoList->Remove (n) ; + + // Send message to all other listener + OInterfaceContainerHelper * pInterfaceContainer = m_aListeners.getContainer( ::getCppuType((const Reference< XContainerListener >*)0) ) ; + + if (pInterfaceContainer) + { + ContainerEvent aEvent ; + + aEvent.Source = *this ; + aEvent.Element <<= rControl ; + + OInterfaceIteratorHelper aIterator (*pInterfaceContainer) ; + + while ( aIterator.hasMoreElements() ) + { + ((XContainerListener*)aIterator.next())->elementRemoved (aEvent) ; + } + } + // Break "for" ! + break ; + } + } + } +} + +//____________________________________________________________________________________________________________ +// XControlContainer +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseContainerControl::removeContainerListener ( const Reference< XContainerListener > & rListener ) throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ) ; + + m_aListeners.removeInterface ( ::getCppuType((const Reference< XContainerListener >*)0), rListener ) ; +} + +//____________________________________________________________________________________________________________ +// XControlContainer +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseContainerControl::setStatusText ( const OUString& rStatusText ) throw( RuntimeException ) +{ + // go down to each parent + Reference< XControlContainer > xContainer ( getContext(), UNO_QUERY ) ; + + if ( xContainer.is () ) + { + xContainer->setStatusText ( rStatusText ) ; + } +} + +//____________________________________________________________________________________________________________ +// XControlContainer +//____________________________________________________________________________________________________________ + +Reference< XControl > SAL_CALL BaseContainerControl::getControl ( const OUString& rName ) throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard ( Mutex::getGlobalMutex() ) ; + + Reference< XControl > xRetControl = Reference< XControl > () ; + sal_uInt32 nControls = m_pControlInfoList->Count () ; + + // Search for right control + for( sal_uInt32 nCount = 0; nCount < nControls; ++nCount ) + { + IMPL_ControlInfo* pSearchControl = m_pControlInfoList->GetObject ( nCount ) ; + + if ( pSearchControl->sName == rName ) + { + // We have found it ... + // Break operation and return. + return pSearchControl->xControl ; + } + } + + // We have not found it ... return NULL. + return Reference< XControl > () ; +} + +//____________________________________________________________________________________________________________ +// XControlContainer +//____________________________________________________________________________________________________________ + +Sequence< Reference< XControl > > SAL_CALL BaseContainerControl::getControls () throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard ( Mutex::getGlobalMutex() ) ; + + sal_uInt32 nControls = m_pControlInfoList->Count () ; + Sequence< Reference< XControl > > aDescriptor ( nControls ) ; + Reference< XControl > * pDestination = aDescriptor.getArray () ; + sal_uInt32 nCount = 0 ; + + // Copy controls to sequence + for( nCount = 0; nCount < nControls; ++nCount ) + { + IMPL_ControlInfo* pCopyControl = m_pControlInfoList->GetObject ( nCount ) ; + pDestination [ nCount ] = pCopyControl->xControl ; + } + + // Return sequence + return aDescriptor ; +} + +//____________________________________________________________________________________________________________ +// XUnoControlContainer +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseContainerControl::addTabController ( const Reference< XTabController > & rTabController ) throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard (m_aMutex) ; + + sal_uInt32 nOldCount = m_xTabControllerList.getLength () ; + Sequence< Reference< XTabController > > aNewList ( nOldCount + 1 ) ; + sal_uInt32 nCount = 0 ; + + // Copy old elements of sequence to new list. + for ( nCount = 0; nCount < nOldCount; ++nCount ) + { + aNewList.getArray () [nCount] = m_xTabControllerList.getConstArray () [nCount] ; + } + + // Add new controller + aNewList.getArray () [nOldCount] = rTabController ; + + // change old and new list + m_xTabControllerList = aNewList ; +} + +//____________________________________________________________________________________________________________ +// XUnoControlContainer +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseContainerControl::removeTabController ( const Reference< XTabController > & rTabController ) throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard (m_aMutex) ; + + sal_uInt32 nMaxCount = m_xTabControllerList.getLength () ; + sal_uInt32 nCount = 0 ; + + // Search right tabcontroller ... + for ( nCount = 0; nCount < nMaxCount; ++nCount ) + { + if ( m_xTabControllerList.getConstArray () [nCount] == rTabController ) + { + // ... if is it found ... remove it from list. + m_xTabControllerList.getArray()[ nCount ] = Reference< XTabController >() ; + break ; + } + } +} + +//____________________________________________________________________________________________________________ +// XUnoControlContainer +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseContainerControl::setTabControllers ( const Sequence< Reference< XTabController > >& rTabControllers ) throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard (m_aMutex) ; + + m_xTabControllerList = rTabControllers ; +} + +Sequence<Reference< XTabController > > SAL_CALL BaseContainerControl::getTabControllers () throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard (m_aMutex) ; + + return m_xTabControllerList ; +} + +//____________________________________________________________________________________________________________ +// XWindow +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseContainerControl::setVisible ( sal_Bool bVisible ) throw( RuntimeException ) +{ + // override baseclass definition + BaseControl::setVisible ( bVisible ) ; + + // is it a top window ? + if ( !getContext().is() && bVisible ) + { + // then show it automaticly + createPeer ( Reference< XToolkit > (), Reference< XWindowPeer > () ) ; + } +} + +//____________________________________________________________________________________________________________ +// protected method +//____________________________________________________________________________________________________________ + +WindowDescriptor* BaseContainerControl::impl_getWindowDescriptor ( const Reference< XWindowPeer > & rParentPeer ) +{ + // - used from "createPeer()" to set the values of an WindowDescriptor !!! + // - if you will change the descriptor-values, you must override thid virtuell function + // - the caller must release the memory for this dynamical descriptor !!! + + WindowDescriptor * aDescriptor = new WindowDescriptor ; + + aDescriptor->Type = WindowClass_CONTAINER ; + aDescriptor->WindowServiceName = OUString(RTL_CONSTASCII_USTRINGPARAM("window")) ; + aDescriptor->ParentIndex = -1 ; + aDescriptor->Parent = rParentPeer ; + aDescriptor->Bounds = getPosSize () ; + aDescriptor->WindowAttributes = 0 ; + + return aDescriptor ; +} + +//____________________________________________________________________________________________________________ +// protected method +//____________________________________________________________________________________________________________ + +void BaseContainerControl::impl_paint ( sal_Int32 nX, sal_Int32 nY, const Reference< XGraphics > & rGraphics ) +{ +/* + if (rGraphics.is()) + { + for ( sal_uInt32 n=m_pControlInfoList->Count(); n; ) + { + ControlInfo* pSearchControl = m_pControlInfoList->GetObject (--n) ; + + pSearchControl->xControl->paint ( nX, nY, rGraphics ) ; + } + } +*/ +} + +//____________________________________________________________________________________________________________ +// private method +//____________________________________________________________________________________________________________ + +void BaseContainerControl::impl_activateTabControllers () +{ + // Ready for multithreading + MutexGuard aGuard (m_aMutex) ; + + sal_uInt32 nMaxCount = m_xTabControllerList.getLength () ; + sal_uInt32 nCount = 0 ; + + for ( nCount = 0; nCount < nMaxCount; ++nCount ) + { + m_xTabControllerList.getArray () [nCount]->setContainer ( this ) ; + m_xTabControllerList.getArray () [nCount]->activateTabOrder ( ) ; + } +} + +//____________________________________________________________________________________________________________ +// private method +//____________________________________________________________________________________________________________ + +void BaseContainerControl::impl_cleanMemory () +{ + // Get count of listitems. + sal_uInt32 nMaxCount = m_pControlInfoList->Count () ; + sal_uInt32 nCount = 0 ; + + // Delete all items. + for ( nCount = 0; nCount < nMaxCount; ++nCount ) + { + // Delete everytime first element of list! + // We count from 0 to MAX, where "MAX=count of items" BEFORE we delete some elements! + // If we use "GetObject ( nCount )" ... it can be, that we have an index greater then count of current elements! + + IMPL_ControlInfo* pSearchControl = m_pControlInfoList->GetObject ( 0 ) ; + delete pSearchControl ; + } + + // Delete list himself. + m_pControlInfoList->Clear () ; + delete m_pControlInfoList ; +} + +} // namespace unocontrols diff --git a/UnoControls/source/base/basecontrol.cxx b/UnoControls/source/base/basecontrol.cxx new file mode 100644 index 000000000000..1587bebac74d --- /dev/null +++ b/UnoControls/source/base/basecontrol.cxx @@ -0,0 +1,1008 @@ +/************************************************************************* + * + * $RCSfile: basecontrol.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:11:17 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +//____________________________________________________________________________________________________________ +// my own include +//____________________________________________________________________________________________________________ + +#ifndef _UNOCONTROLS_BASECONTROL_CTRL_HXX +#include "basecontrol.hxx" +#endif + +//____________________________________________________________________________________________________________ +// includes of other projects +//____________________________________________________________________________________________________________ + +#ifndef _COM_SUN_STAR_AWT_XDEVICE_HPP_ +#include <com/sun/star/awt/XDevice.hpp> +#endif + +#ifndef _COM_SUN_STAR_AWT_XDISPLAYBITMAP_HPP_ +#include <com/sun/star/awt/XDisplayBitmap.hpp> +#endif + +#ifndef _COM_SUN_STAR_AWT_DEVICEINFO_HPP_ +#include <com/sun/star/awt/DeviceInfo.hpp> +#endif + +#ifndef _COM_SUN_STAR_AWT_WINDOWATTRIBUTE_HPP_ +#include <com/sun/star/awt/WindowAttribute.hpp> +#endif + +#ifndef _COM_SUN_STAR_AWT_POSSIZE_HPP_ +#include <com/sun/star/awt/PosSize.hpp> +#endif + +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif + +//____________________________________________________________________________________________________________ +// includes of my own project +//____________________________________________________________________________________________________________ + +//____________________________________________________________________________________________________________ +// namespaces +//____________________________________________________________________________________________________________ + +using namespace ::cppu ; +using namespace ::osl ; +using namespace ::rtl ; +using namespace ::com::sun::star::uno ; +using namespace ::com::sun::star::lang ; +using namespace ::com::sun::star::awt ; + +namespace unocontrols{ + +//____________________________________________________________________________________________________________ +// defines +//____________________________________________________________________________________________________________ + +#define DEFAULT_PMULTIPLEXER NULL +#define DEFAULT_X 0 +#define DEFAULT_Y 0 +#define DEFAULT_WIDTH 100 +#define DEFAULT_HEIGHT 100 +#define DEFAULT_VISIBLE sal_False +#define DEFAULT_INDESIGNMODE sal_False +#define DEFAULT_ENABLE sal_True +#define SERVICE_VCLTOOLKIT "com.sun.star.awt.Toolkit" + +//____________________________________________________________________________________________________________ +// construct/destruct +//____________________________________________________________________________________________________________ + +BaseControl::BaseControl( const Reference< XMultiServiceFactory >& xFactory ) + : IMPL_MutexContainer ( ) + , OComponentHelper ( m_aMutex ) + , m_xFactory ( xFactory ) + , m_pMultiplexer ( DEFAULT_PMULTIPLEXER ) + , m_nX ( DEFAULT_X ) + , m_nY ( DEFAULT_Y ) + , m_nWidth ( DEFAULT_WIDTH ) + , m_nHeight ( DEFAULT_HEIGHT ) + , m_bVisible ( DEFAULT_VISIBLE ) + , m_bInDesignMode ( DEFAULT_INDESIGNMODE ) + , m_bEnable ( DEFAULT_ENABLE ) +{ +} + +BaseControl::~BaseControl() +{ +} + +//____________________________________________________________________________________________________________ +// XInterface +//____________________________________________________________________________________________________________ + +Any SAL_CALL BaseControl::queryInterface( const Type& rType ) throw( RuntimeException ) +{ + Any aReturn ; + if ( m_xDelegator.is() == sal_True ) + { + // If an delegator exist, forward question to his queryInterface. + // Delegator will ask his own queryAggregation! + aReturn = m_xDelegator->queryInterface( rType ); + } + else + { + // If an delegator unknown, forward question to own queryAggregation. + aReturn = queryAggregation( rType ); + } + + return aReturn ; +} + +//____________________________________________________________________________________________________________ +// XInterface +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::acquire() throw( RuntimeException ) +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + OComponentHelper::acquire(); +} + +//____________________________________________________________________________________________________________ +// XInterface +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::release() throw( RuntimeException ) +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + OComponentHelper::release(); +} + +//____________________________________________________________________________________________________________ +// XTypeProvider +//____________________________________________________________________________________________________________ + +Sequence< Type > SAL_CALL BaseControl::getTypes() throw( RuntimeException ) +{ + // Optimize this method ! + // We initialize a static variable only one time. And we don't must use a mutex at every call! + // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL! + static OTypeCollection* pTypeCollection = NULL ; + + if ( pTypeCollection == NULL ) + { + // Ready for multithreading; get global mutex for first call of this method only! see before + MutexGuard aGuard( Mutex::getGlobalMutex() ); + + // Control these pointer again ... it can be, that another instance will be faster then these! + if ( pTypeCollection == NULL ) + { + // Create a static typecollection ... + static OTypeCollection aTypeCollection ( ::getCppuType(( const Reference< XPaintListener >*)NULL ) , + ::getCppuType(( const Reference< XView >*)NULL ) , + ::getCppuType(( const Reference< XWindow >*)NULL ) , + ::getCppuType(( const Reference< XServiceInfo >*)NULL ) , + ::getCppuType(( const Reference< XControl >*)NULL ) , + OComponentHelper::getTypes() + ); + + // ... and set his address to static pointer! + pTypeCollection = &aTypeCollection ; + } + } + + return pTypeCollection->getTypes(); +} + +//____________________________________________________________________________________________________________ +// XTypeProvider +//____________________________________________________________________________________________________________ + +Sequence< sal_Int8 > SAL_CALL BaseControl::getImplementationId() throw( RuntimeException ) +{ + // Create one Id for all instances of this class. + // Use ethernet address to do this! (sal_True) + + // Optimize this method + // We initialize a static variable only one time. And we don't must use a mutex at every call! + // For the first call; pID is NULL - for the second call pID is different from NULL! + static OImplementationId* pID = NULL ; + + if ( pID == NULL ) + { + // Ready for multithreading; get global mutex for first call of this method only! see before + MutexGuard aGuard( Mutex::getGlobalMutex() ); + + // Control these pointer again ... it can be, that another instance will be faster then these! + if ( pID == NULL ) + { + // Create a new static ID ... + static OImplementationId aID( sal_False ); + // ... and set his address to static pointer! + pID = &aID ; + } + } + + return pID->getImplementationId(); +} + +//____________________________________________________________________________________________________________ +// XAggregation +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::setDelegator( const Reference< XInterface >& xDelegator ) throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + m_xDelegator = xDelegator ; +} + +//____________________________________________________________________________________________________________ +// XAggregation +//____________________________________________________________________________________________________________ + +Any SAL_CALL BaseControl::queryAggregation( const Type& aType ) throw( RuntimeException ) +{ + // Ask for my own supported interfaces ... + // Attention: XTypeProvider and XInterface are supported by OComponentHelper! + Any aReturn ( ::cppu::queryInterface( aType , + static_cast< XPaintListener*> ( this ) , + static_cast< XView* > ( this ) , + static_cast< XWindow* > ( this ) , + static_cast< XServiceInfo* > ( this ) , + static_cast< XControl* > ( this ) + ) + ); + + // If searched interface supported by this class ... + if ( aReturn.hasValue() == sal_True ) + { + // ... return this information. + return aReturn ; + } + else + { + // Else; ... ask baseclass for interfaces! + return OComponentHelper::queryAggregation( aType ); + } +} + +//____________________________________________________________________________________________________________ +// XServiceInfo +//____________________________________________________________________________________________________________ + +OUString SAL_CALL BaseControl::getImplementationName() throw( RuntimeException ) +{ + return impl_getStaticImplementationName(); +} + +//____________________________________________________________________________________________________________ +// XServiceInfo +//____________________________________________________________________________________________________________ + +sal_Bool SAL_CALL BaseControl::supportsService( const OUString& sServiceName ) throw( RuntimeException ) +{ + Sequence< OUString > seqServiceNames = getSupportedServiceNames(); + const OUString* pArray = seqServiceNames.getConstArray(); + for ( sal_Int32 nCounter=0; nCounter<seqServiceNames.getLength(); nCounter++ ) + { + if ( pArray[nCounter] == sServiceName ) + { + return sal_True ; + } + } + return sal_False ; +} + +//____________________________________________________________________________________________________________ +// XServiceInfo +//____________________________________________________________________________________________________________ + +Sequence< OUString > SAL_CALL BaseControl::getSupportedServiceNames() throw( RuntimeException ) +{ + return impl_getStaticSupportedServiceNames(); +} + +//____________________________________________________________________________________________________________ +// XComponent +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::dispose() throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + if ( m_pMultiplexer != NULL ) + { + // to all other paint, focus, etc. + m_pMultiplexer->disposeAndClear(); + } + + // set the service manager to disposed + OComponentHelper::dispose(); + + // release context and peer + m_xContext = Reference< XInterface >(); + impl_releasePeer(); + + // release view + if ( m_xGraphicsView.is() == sal_True ) + { + m_xGraphicsView = Reference< XGraphics >(); + } +} + +//____________________________________________________________________________________________________________ +// XComponent +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::addEventListener( const Reference< XEventListener >& xListener ) throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + OComponentHelper::addEventListener( xListener ); +} + +//____________________________________________________________________________________________________________ +// XComponent +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::removeEventListener( const Reference< XEventListener >& xListener ) throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + OComponentHelper::removeEventListener( xListener ); +} + +//____________________________________________________________________________________________________________ +// XControl +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::createPeer( const Reference< XToolkit >& xToolkit , + const Reference< XWindowPeer >& xParentPeer ) throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + if ( m_xPeer.is() == sal_False ) + { + // use method "BaseControl::getWindowDescriptor()" fot change window attributes !!! + WindowDescriptor* pDescriptor = impl_getWindowDescriptor( xParentPeer ); + + if ( m_bVisible == sal_True ) + { + pDescriptor->WindowAttributes |= WindowAttribute::SHOW ; + } + + // very slow under remote conditions! + // create the window on the server + Reference< XToolkit > xLocalToolkit = xToolkit ; + if ( xLocalToolkit.is() == sal_False ) + { + // but first create wellknown toolkit, if it not exist + xLocalToolkit = Reference< XToolkit > ( m_xFactory->createInstance( OUString::createFromAscii( SERVICE_VCLTOOLKIT ) ), UNO_QUERY ); + } + m_xPeer = xLocalToolkit->createWindow( *pDescriptor ); + m_xPeerWindow = Reference< XWindow >( m_xPeer, UNO_QUERY ); + + // don't forget to release the memory! + delete pDescriptor ; + + if ( m_xPeerWindow.is() == sal_True ) + { + if ( m_pMultiplexer != NULL ) + { + m_pMultiplexer->setPeer( m_xPeerWindow ); + } + + // create new referenz to xgraphics for painting on a peer + // and add a paint listener + Reference< XDevice > xDevice( m_xPeerWindow, UNO_QUERY ); + + if ( xDevice.is() == sal_True ) + { + m_xGraphicsPeer = xDevice->createGraphics(); + } + + if ( m_xGraphicsPeer.is() == sal_True ) + { + addPaintListener( this ); + } + + // PosSize_POSSIZE defined in <stardiv/uno/awt/window.hxx> + m_xPeerWindow->setPosSize( m_nX, m_nY, m_nWidth, m_nHeight, PosSize::POSSIZE ); + m_xPeerWindow->setEnable( m_bEnable ); + m_xPeerWindow->setVisible( m_bVisible && !m_bInDesignMode ); + } + } +} + +//____________________________________________________________________________________________________________ +// XControl +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::setContext( const Reference< XInterface >& xContext ) throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + m_xContext = xContext ; +} + +//____________________________________________________________________________________________________________ +// XControl +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::setDesignMode( sal_Bool bOn ) throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + m_bInDesignMode = bOn ; +} + +//____________________________________________________________________________________________________________ +// XControl +//____________________________________________________________________________________________________________ + +Reference< XInterface > SAL_CALL BaseControl::getContext() throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + return m_xContext ; +} + +//____________________________________________________________________________________________________________ +// XControl +//____________________________________________________________________________________________________________ + +Reference< XWindowPeer > SAL_CALL BaseControl::getPeer() throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + return m_xPeer ; +} + +//____________________________________________________________________________________________________________ +// XControl +//____________________________________________________________________________________________________________ + +Reference< XView > SAL_CALL BaseControl::getView() throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + return Reference< XView >( (OWeakObject*)this, UNO_QUERY ); +} + +//____________________________________________________________________________________________________________ +// XControl +//____________________________________________________________________________________________________________ + +sal_Bool SAL_CALL BaseControl::isDesignMode() throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + return m_bInDesignMode ; +} + +//____________________________________________________________________________________________________________ +// XControl +//____________________________________________________________________________________________________________ + +sal_Bool SAL_CALL BaseControl::isTransparent() throw( RuntimeException ) +{ + return sal_False ; +} + +//____________________________________________________________________________________________________________ +// XWindow +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::setPosSize( sal_Int32 nX , + sal_Int32 nY , + sal_Int32 nWidth , + sal_Int32 nHeight , + sal_Int16 nFlags ) throw( RuntimeException ) +{ + // - change size and position of window and save the values + // - "nFlags" declared in <stardiv/uno/awt/window.hxx> ("#define PosSize_X .....") + + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + sal_Bool bChanged = sal_False ; + + if ( nFlags & PosSize::X ) + { + bChanged |= m_nX != nX, m_nX = nX ; + } + + if ( nFlags & PosSize::Y ) + { + bChanged |= m_nY != nY, m_nY = nY ; + } + + if ( nFlags & PosSize::WIDTH ) + { + bChanged |= m_nWidth != nWidth, m_nWidth = nWidth ; + } + + if ( nFlags & PosSize::HEIGHT ) + { + bChanged |= m_nHeight != nHeight, m_nHeight = nHeight ; + } + + if ( bChanged && m_xPeerWindow.is() ) + { + m_xPeerWindow->setPosSize( m_nX, m_nY, m_nWidth, m_nHeight, nFlags ); + } +} + +//____________________________________________________________________________________________________________ +// XWindow +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::setVisible( sal_Bool bVisible ) throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // Set new state of flag + m_bVisible = bVisible ; + + if ( m_xPeerWindow.is() == sal_True ) + { + // Set it also on peerwindow + m_xPeerWindow->setVisible( m_bVisible ); + } +} + +//____________________________________________________________________________________________________________ +// XWindow +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::setEnable( sal_Bool bEnable ) throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // Set new state of flag + m_bEnable = bEnable ; + + if ( m_xPeerWindow.is() == sal_True ) + { + // Set it also on peerwindow + m_xPeerWindow->setEnable( m_bEnable ); + } +} + +//____________________________________________________________________________________________________________ +// XWindow +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::setFocus() throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + if ( m_xPeerWindow.is() == sal_True ) + { + m_xPeerWindow->setFocus(); + } +} + +//____________________________________________________________________________________________________________ +// XWindow +//____________________________________________________________________________________________________________ + +Rectangle SAL_CALL BaseControl::getPosSize() throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + return Rectangle( m_nX, m_nY , m_nWidth, m_nHeight ); +} + +//____________________________________________________________________________________________________________ +// XWindow +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::addWindowListener( const Reference< XWindowListener >& xListener ) throw( RuntimeException ) +{ + impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XWindowListener >*)0), xListener ); +} + +//____________________________________________________________________________________________________________ +// XWindow +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::addFocusListener( const Reference< XFocusListener >& xListener ) throw( RuntimeException ) +{ + impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XFocusListener >*)0), xListener ); +} + +//____________________________________________________________________________________________________________ +// XWindow +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::addKeyListener( const Reference< XKeyListener >& xListener ) throw( RuntimeException ) +{ + impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XKeyListener >*)0), xListener ); +} + +//____________________________________________________________________________________________________________ +// XWindow +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::addMouseListener( const Reference< XMouseListener >& xListener ) throw( RuntimeException ) +{ + impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XMouseListener >*)0), xListener ); +} + +//____________________________________________________________________________________________________________ +// XWindow +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::addMouseMotionListener( const Reference< XMouseMotionListener >& xListener ) throw( RuntimeException ) +{ + impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XMouseMotionListener >*)0), xListener ); +} + +//____________________________________________________________________________________________________________ +// XWindow +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::addPaintListener( const Reference< XPaintListener >& xListener ) throw( RuntimeException ) +{ + impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XPaintListener >*)0), xListener ); +} + +//____________________________________________________________________________________________________________ +// XWindow +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::removeWindowListener( const Reference< XWindowListener >& xListener ) throw( RuntimeException ) +{ + impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XWindowListener >*)0), xListener ); +} + +//____________________________________________________________________________________________________________ +// XWindow +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::removeFocusListener( const Reference< XFocusListener >& xListener ) throw( RuntimeException ) +{ + impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XFocusListener >*)0), xListener ); +} + +//____________________________________________________________________________________________________________ +// XWindow +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::removeKeyListener( const Reference< XKeyListener >& xListener ) throw( RuntimeException ) +{ + impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XKeyListener >*)0), xListener ); +} + +//____________________________________________________________________________________________________________ +// XWindow +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::removeMouseListener( const Reference< XMouseListener >& xListener ) throw( RuntimeException ) +{ + impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XMouseListener >*)0), xListener ); +} + +//____________________________________________________________________________________________________________ +// XWindow +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::removeMouseMotionListener( const Reference< XMouseMotionListener >& xListener ) throw( RuntimeException ) +{ + impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XMouseMotionListener >*)0), xListener ); +} + +//____________________________________________________________________________________________________________ +// XWindow +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::removePaintListener( const Reference< XPaintListener >& xListener ) throw( RuntimeException ) +{ + impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XPaintListener >*)0), xListener ); +} + +//____________________________________________________________________________________________________________ +// XView +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::draw( sal_Int32 nX , + sal_Int32 nY ) throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // - paint to an view + // - use the method "paint()" + // - see also "windowPaint()" + impl_paint( nX, nY, m_xGraphicsView ); +} + +//____________________________________________________________________________________________________________ +// XView +//____________________________________________________________________________________________________________ + +sal_Bool SAL_CALL BaseControl::setGraphics( const Reference< XGraphics >& xDevice ) throw( RuntimeException ) +{ + // - set the graphics for an view + // - in this class exist 2 graphics-member ... one for peer[_xGraphicsPeer] and one for view[_xGraphicsView] + // - they are used by "windowPaint() and draw()", forwarded to "paint ()" + sal_Bool bReturn = sal_False ; + if ( xDevice.is() == sal_True ) + { + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + m_xGraphicsView = xDevice ; + bReturn = sal_True ; + } + + return bReturn ; +} + +//____________________________________________________________________________________________________________ +// XView +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::setZoom( float fZoomX , + float fZoomY ) throw( RuntimeException ) +{ + // Not implemented yet +} + +//____________________________________________________________________________________________________________ +// XView +//____________________________________________________________________________________________________________ + +Reference< XGraphics > SAL_CALL BaseControl::getGraphics() throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + return m_xGraphicsView ; +} + +//____________________________________________________________________________________________________________ +// XView +//____________________________________________________________________________________________________________ + +Size SAL_CALL BaseControl::getSize() throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + return Size( m_nWidth, m_nHeight ); +} + +//____________________________________________________________________________________________________________ +// XEventListener +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::disposing( const EventObject& aSource ) throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // - release ALL references + // - it must be !!! + if ( m_xGraphicsPeer.is() == sal_True ) + { + removePaintListener( this ); + m_xGraphicsPeer = Reference< XGraphics >(); + } + + if ( m_xGraphicsView.is() == sal_True ) + { + m_xGraphicsView = Reference< XGraphics >(); + } +} + +//____________________________________________________________________________________________________________ +// XPaintListener +//____________________________________________________________________________________________________________ + +void SAL_CALL BaseControl::windowPaint( const PaintEvent& aEvent ) throw( RuntimeException ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // - repaint the peer + // - use the method "paint ()" for painting on a peer and a print device !!! + // - see also "draw ()" + impl_paint( 0, 0, m_xGraphicsPeer ); +} + +//____________________________________________________________________________________________________________ +// impl but public method to register service in DLL +// (In this BASE-implementation not implemented! Overwrite it in derived classes.) +//____________________________________________________________________________________________________________ + +const Sequence< OUString > BaseControl::impl_getStaticSupportedServiceNames() +{ + return Sequence< OUString >(); +} + +//____________________________________________________________________________________________________________ +// impl but public method to register service in DLL +// (In this BASE-implementation not implemented! Overwrite it in derived classes.) +//____________________________________________________________________________________________________________ + +const OUString BaseControl::impl_getStaticImplementationName() +{ + return OUString(); +} + +//____________________________________________________________________________________________________________ +// protected method +//____________________________________________________________________________________________________________ + +const Reference< XMultiServiceFactory > BaseControl::impl_getMultiServiceFactory() +{ + return m_xFactory ; +} + +//____________________________________________________________________________________________________________ +// protected method +//____________________________________________________________________________________________________________ + +const Reference< XWindow > BaseControl::impl_getPeerWindow() +{ + return m_xPeerWindow ; +} + +//____________________________________________________________________________________________________________ +// protected method +//____________________________________________________________________________________________________________ + +const Reference< XGraphics > BaseControl::impl_getGraphicsPeer() +{ + return m_xGraphicsPeer ; +} + +//____________________________________________________________________________________________________________ +// protected method +//____________________________________________________________________________________________________________ + +const sal_Int32& BaseControl::impl_getWidth() +{ + return m_nWidth ; +} + +//____________________________________________________________________________________________________________ +// protected method +//____________________________________________________________________________________________________________ + +const sal_Int32& BaseControl::impl_getHeight() +{ + return m_nHeight ; +} + +//____________________________________________________________________________________________________________ +// protected method +//____________________________________________________________________________________________________________ + +WindowDescriptor* BaseControl::impl_getWindowDescriptor( const Reference< XWindowPeer >& xParentPeer ) +{ + // - used from "createPeer()" to set the values of an ::com::sun::star::awt::WindowDescriptor !!! + // - if you will change the descriptor-values, you must override thid virtuell function + // - the caller must release the memory for this dynamical descriptor !!! + + WindowDescriptor* pDescriptor = new WindowDescriptor ; + + pDescriptor->Type = WindowClass_SIMPLE ; + pDescriptor->WindowServiceName = OUString::createFromAscii( "window" ) ; + pDescriptor->ParentIndex = -1 ; + pDescriptor->Parent = xParentPeer ; + pDescriptor->Bounds = getPosSize () ; + pDescriptor->WindowAttributes = 0 ; + + return pDescriptor ; +} + +//____________________________________________________________________________________________________________ +// protected method +//____________________________________________________________________________________________________________ + +void BaseControl::impl_paint( sal_Int32 nX , + sal_Int32 nY , + const Reference< XGraphics >& xGraphics ) +{ + // - one paint method for peer AND view !!! + // (see also => "windowPaint()" and "draw()") + // - not used in this implementation, but its not necessary to make it pure virtual !!! +} + +//____________________________________________________________________________________________________________ +// protected method +//____________________________________________________________________________________________________________ + +Reference< XInterface > BaseControl::impl_getDelegator() +{ + return m_xDelegator ; +} + +//____________________________________________________________________________________________________________ +// private method +//____________________________________________________________________________________________________________ + +void BaseControl::impl_releasePeer() +{ + if ( m_xPeer.is() == sal_True ) + { + if ( m_xGraphicsPeer.is() == sal_True ) + { + removePaintListener( this ); + m_xGraphicsPeer = Reference< XGraphics >(); + } + + m_xPeer->dispose(); + m_xPeerWindow = Reference< XWindow >(); + m_xPeer = Reference< XWindowPeer >(); + + if ( m_pMultiplexer != NULL ) + { + // take changes on multiplexer + m_pMultiplexer->setPeer( Reference< XWindow >() ); + } + } +} + +//____________________________________________________________________________________________________________ +// private method +//____________________________________________________________________________________________________________ + +OMRCListenerMultiplexerHelper* BaseControl::impl_getMultiplexer() +{ + if ( m_pMultiplexer == NULL ) + { + m_pMultiplexer = new OMRCListenerMultiplexerHelper( (XWindow*)this, m_xPeerWindow ); + m_xMultiplexer = Reference< XInterface >( (OWeakObject*)m_pMultiplexer, UNO_QUERY ); + } + + return m_pMultiplexer ; +} + +} // namespace unocontrols diff --git a/UnoControls/source/base/makefile.mk b/UnoControls/source/base/makefile.mk new file mode 100644 index 000000000000..584aefb810ec --- /dev/null +++ b/UnoControls/source/base/makefile.mk @@ -0,0 +1,104 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 16:11:17 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* +PRJ=..$/.. + +PRJNAME=UnoControls +TARGET=base +ENABLE_EXCEPTIONS=TRUE +#LIBTARGET=NO +#USE_LDUMP2=TRUE +#USE_DEFFILE=TRUE + +# --- Settings ----------------------------------------------------- +.INCLUDE : $(PRJ)$/util$/makefile.pmk + + +# --- Files -------------------------------------------------------- +SLOFILES= $(SLO)$/multiplexer.obj \ + $(SLO)$/basecontrol.obj \ + $(SLO)$/basecontainercontrol.obj \ + $(SLO)$/registercontrols.obj + +#LIB1TARGET= $(SLB)$/$(TARGET).lib +#LIB1OBJFILES= $(SLOFILES) + +#SHL1TARGET= $(TARGET)$(UPD)$(DLLPOSTFIX) + +#SHL1STDLIBS=\ +# $(ONELIB) \ +# $(USRLIB) \ +# $(UNOLIB) \ +# $(VOSLIB) \ +# $(OSLLIB) \ +# $(TOOLSLIB) \ +# $(RTLLIB) + +#SHL1DEPN= makefile.mk +#SHL1LIBS= $(LIB1TARGET) +#SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +#DEF1NAME= $(SHL1TARGET) +#DEF1EXPORTFILE= exports.dxp + +# --- Targets ------------------------------------------------------ +.INCLUDE : target.mk +#.INCLUDE : $(PRJ)$/util$/target.pmk diff --git a/UnoControls/source/base/multiplexer.cxx b/UnoControls/source/base/multiplexer.cxx new file mode 100644 index 000000000000..38c1d7297423 --- /dev/null +++ b/UnoControls/source/base/multiplexer.cxx @@ -0,0 +1,610 @@ +/************************************************************************* + * + * $RCSfile: multiplexer.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:11:17 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +//____________________________________________________________________________________________________________ +// my own include +//____________________________________________________________________________________________________________ + +#ifndef _UNOCONTROLS_MULTIPLEXER_HXX +#include "multiplexer.hxx" +#endif + +//____________________________________________________________________________________________________________ +// includes of other projects +//____________________________________________________________________________________________________________ + +#ifndef _VOS_DIAGNOSE_H_ +#include <vos/diagnose.hxx> +#endif + +//____________________________________________________________________________________________________________ +// includes of my own project +//____________________________________________________________________________________________________________ + +//____________________________________________________________________________________________________________ +// namespaces +//____________________________________________________________________________________________________________ + +using namespace ::cppu ; +using namespace ::osl ; +using namespace ::com::sun::star::uno ; +using namespace ::com::sun::star::awt ; +using namespace ::com::sun::star::lang ; + +namespace unocontrols{ + +//____________________________________________________________________________________________________________ +// macros +//____________________________________________________________________________________________________________ + +#define MULTIPLEX( INTERFACE, METHOD, EVENTTYP, EVENT ) \ + \ + /* First get all interfaces from container with right type.*/ \ + OInterfaceContainerHelper* pContainer = m_aListenerHolder.getContainer( ::getCppuType((const Reference< INTERFACE## >*)0) ); \ + /* Do the follow only, if elements in container exist.*/ \ + if( pContainer != NULL ) \ + { \ + OInterfaceIteratorHelper aIterator( *pContainer ); \ + EVENTTYP aLocalEvent = EVENT##; \ + /* Remark: The control is the event source not the peer.*/ \ + /* We must change the source of the event. */ \ + aLocalEvent.Source = m_xControl ; \ + /* Is the control not destroyed? */ \ + if( aLocalEvent.Source.is() == sal_True ) \ + { \ + if( aIterator.hasMoreElements() ) \ + { \ + INTERFACE## * pListener = (INTERFACE## *)aIterator.next(); \ + try \ + { \ + pListener->METHOD##( aLocalEvent ); \ + } \ + catch( RuntimeException& ) \ + { \ + /* Ignore all system exceptions from the listener! */ \ + } \ + } \ + } \ + } + +//____________________________________________________________________________________________________________ +// construct/destruct +//____________________________________________________________________________________________________________ + +OMRCListenerMultiplexerHelper::OMRCListenerMultiplexerHelper( const Reference< XWindow >& xControl , + const Reference< XWindow >& xPeer ) + : m_aListenerHolder ( m_aMutex ) + , m_xControl ( xControl ) + , m_xPeer ( xPeer ) +{ +} + +OMRCListenerMultiplexerHelper::OMRCListenerMultiplexerHelper( const OMRCListenerMultiplexerHelper& aCopyInstance ) + : m_aListenerHolder ( m_aMutex ) +{ +} + +OMRCListenerMultiplexerHelper::~OMRCListenerMultiplexerHelper() +{ +} + +//____________________________________________________________________________________________________________ +// XInterface +//____________________________________________________________________________________________________________ + +Any SAL_CALL OMRCListenerMultiplexerHelper::queryInterface( const Type& rType ) throw( RuntimeException ) +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Ask for my own supported interfaces ... + // Attention: XTypeProvider and XInterface are supported by OComponentHelper! + Any aReturn ( ::cppu::queryInterface( rType , + static_cast< XWindowListener* > ( this ) , + static_cast< XKeyListener* > ( this ) , + static_cast< XFocusListener* > ( this ) , + static_cast< XMouseListener* > ( this ) , + static_cast< XMouseMotionListener* > ( this ) , + static_cast< XPaintListener* > ( this ) , + static_cast< XTopWindowListener* > ( this ) , + static_cast< XTopWindowListener* > ( this ) + ) + ); + + // If searched interface supported by this class ... + if ( aReturn.hasValue() == sal_True ) + { + // ... return this information. + return aReturn ; + } + else + { + // Else; ... ask baseclass for interfaces! + return OWeakObject::queryInterface( rType ); + } +} + +//____________________________________________________________________________________________________________ +// XInterface +//____________________________________________________________________________________________________________ + +void SAL_CALL OMRCListenerMultiplexerHelper::acquire() throw( RuntimeException ) +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + OWeakObject::acquire(); +} + +//____________________________________________________________________________________________________________ +// XInterface +//____________________________________________________________________________________________________________ + +void SAL_CALL OMRCListenerMultiplexerHelper::release() throw( RuntimeException ) +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + OWeakObject::release(); +} + +//____________________________________________________________________________________________________________ +// operator +//____________________________________________________________________________________________________________ + +OMRCListenerMultiplexerHelper::operator Reference< XInterface >() const +{ + return ((OWeakObject*)this) ; +} + +//____________________________________________________________________________________________________________ +// operator +//____________________________________________________________________________________________________________ + +//OMRCListenerMultiplexerHelper& OMRCListenerMultiplexerHelper::operator= ( const OMRCListenerMultiplexerHelper& aCopyInstance ) +//{ +// return this ; +//} + +//____________________________________________________________________________________________________________ +// container method +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::setPeer( const Reference< XWindow >& xPeer ) +{ + MutexGuard aGuard( m_aMutex ); + if( m_xPeer != xPeer ) + { + if( m_xPeer.is() ) + { + // get all types from the listener added to the peer + Sequence< Type > aContainedTypes = m_aListenerHolder.getContainedTypes(); + const Type* pArray = aContainedTypes.getConstArray(); + sal_Int32 nCount = aContainedTypes.getLength(); + // loop over all listener types and remove the listeners from the peer + for( sal_Int32 i=0; i<nCount; i++ ) + impl_unadviseFromPeer( m_xPeer, pArray[i] ); + } + m_xPeer = xPeer; + if( m_xPeer.is() ) + { + // get all types from the listener added to the peer + Sequence< Type > aContainedTypes = m_aListenerHolder.getContainedTypes(); + const Type* pArray = aContainedTypes.getConstArray(); + sal_Int32 nCount = aContainedTypes.getLength(); + // loop over all listener types and add the listeners to the peer + for( sal_Int32 i = 0; i < nCount; i++ ) + impl_adviseToPeer( m_xPeer, pArray[i] ); + } + } +} + +//____________________________________________________________________________________________________________ +// container method +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::disposeAndClear() +{ + EventObject aEvent ; + aEvent.Source = m_xControl ; + m_aListenerHolder.disposeAndClear( aEvent ); +} + +//____________________________________________________________________________________________________________ +// container method +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::advise( const Type& aType , + const Reference< XInterface >& xListener ) +{ + MutexGuard aGuard( m_aMutex ); + if( m_aListenerHolder.addInterface( aType, xListener ) == 1 ) + { + // the first listener is added + if( m_xPeer.is() ) + { + impl_adviseToPeer( m_xPeer, aType ); + } + } +} + +//____________________________________________________________________________________________________________ +// container method +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::unadvise( const Type& aType , + const Reference< XInterface >& xListener ) +{ + MutexGuard aGuard( m_aMutex ); + if( m_aListenerHolder.removeInterface( aType, xListener ) == 0 ) + { + // the last listener is removed + if ( m_xPeer.is() ) + { + impl_unadviseFromPeer( m_xPeer, aType ); + } + } +} + +//____________________________________________________________________________________________________________ +// XEventListener +//____________________________________________________________________________________________________________ + +void SAL_CALL OMRCListenerMultiplexerHelper::disposing( const EventObject& aSource ) throw( RuntimeException ) +{ + MutexGuard aGuard( m_aMutex ); + // peer is disposed, clear the reference + m_xPeer = Reference< XWindow >(); +} + +//____________________________________________________________________________________________________________ +// XFcousListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::focusGained(const FocusEvent& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) +{ +/* + OInterfaceContainerHelper * pCont = aListenerHolder.getContainer( ::getCppuType((const Reference< XFocusListener >*)0) ); + if( pCont ) + { + OInterfaceIteratorHelper aIt( *pCont ); + FocusEvent aEvt = e; + // Reamark: The control is the event source not the peer. We must change + // the source of the event + xControl.queryHardRef( ((XInterface*)NULL)->getSmartUik(), aEvt.Source ); + //.is the control not destroyed + if( aEvt.Source.is() ) + { + if( aIt.hasMoreElements() ) + { + XFocusListener * pListener = (XFocusListener *)aIt.next(); + TRY + { + pListener->focusGained( aEvt ); + } + CATCH( RuntimeException, e ) + { + // ignore all usr system exceptions from the listener + } + END_CATCH; + } + } + } +*/ + MULTIPLEX( XFocusListener, focusGained, FocusEvent, aEvent ) +} + +//____________________________________________________________________________________________________________ +// XFcousListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::focusLost(const FocusEvent& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) +{ + MULTIPLEX( XFocusListener, focusLost, FocusEvent, aEvent ) +} + +//____________________________________________________________________________________________________________ +// XWindowListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::windowResized(const WindowEvent& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) +{ + MULTIPLEX( XWindowListener, windowResized, WindowEvent, aEvent ) +} + +//____________________________________________________________________________________________________________ +// XWindowListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::windowMoved(const WindowEvent& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) +{ + MULTIPLEX( XWindowListener, windowMoved, WindowEvent, aEvent ) +} + +//____________________________________________________________________________________________________________ +// XWindowListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::windowShown(const EventObject& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) +{ + MULTIPLEX( XWindowListener, windowShown, EventObject, aEvent ) +} + +//____________________________________________________________________________________________________________ +// XWindowListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::windowHidden(const EventObject& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) +{ + MULTIPLEX( XWindowListener, windowHidden, EventObject, aEvent ) +} + +//____________________________________________________________________________________________________________ +// XKeyListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::keyPressed(const KeyEvent& aEvent) throw( UNO3_RUNTIMEEXCEPTION ) +{ + MULTIPLEX( XKeyListener, keyPressed, KeyEvent, aEvent ) +} + +//____________________________________________________________________________________________________________ +// XKeyListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::keyReleased(const KeyEvent& aEvent) throw( UNO3_RUNTIMEEXCEPTION ) +{ + MULTIPLEX( XKeyListener, keyReleased, KeyEvent, aEvent ) +} + +//____________________________________________________________________________________________________________ +// XMouseListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::mousePressed(const MouseEvent& aEvent) throw( UNO3_RUNTIMEEXCEPTION ) +{ + MULTIPLEX( XMouseListener, mousePressed, MouseEvent, aEvent ) +} + +//____________________________________________________________________________________________________________ +// XMouseListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::mouseReleased(const MouseEvent& aEvent) throw( UNO3_RUNTIMEEXCEPTION ) +{ + MULTIPLEX( XMouseListener, mouseReleased, MouseEvent, aEvent ) +} + +//____________________________________________________________________________________________________________ +// XMouseListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::mouseEntered(const MouseEvent& aEvent) throw( UNO3_RUNTIMEEXCEPTION ) +{ + MULTIPLEX( XMouseListener, mouseEntered, MouseEvent, aEvent ) +} + +//____________________________________________________________________________________________________________ +// XMouseListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::mouseExited(const MouseEvent& aEvent) throw( UNO3_RUNTIMEEXCEPTION ) +{ + MULTIPLEX( XMouseListener, mouseExited, MouseEvent, aEvent ) +} + +//____________________________________________________________________________________________________________ +// XMouseMotionListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::mouseDragged(const MouseEvent& aEvent) throw( UNO3_RUNTIMEEXCEPTION ) +{ + MULTIPLEX( XMouseMotionListener, mouseDragged, MouseEvent, aEvent ) +} + +//____________________________________________________________________________________________________________ +// XMouseMotionListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::mouseMoved(const MouseEvent& aEvent) throw( UNO3_RUNTIMEEXCEPTION ) +{ + MULTIPLEX( XMouseMotionListener, mouseMoved, MouseEvent, aEvent ) +} + +//____________________________________________________________________________________________________________ +// XPaintListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::windowPaint(const PaintEvent& aEvent) throw( UNO3_RUNTIMEEXCEPTION ) +{ + MULTIPLEX( XPaintListener, windowPaint, PaintEvent, aEvent ) +} + +//____________________________________________________________________________________________________________ +// XTopWindowListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::windowOpened(const EventObject& aEvent) throw( UNO3_RUNTIMEEXCEPTION ) +{ + MULTIPLEX( XTopWindowListener, windowOpened, EventObject, aEvent ) +} + +//____________________________________________________________________________________________________________ +// XTopWindowListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::windowClosing( const EventObject& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) +{ + MULTIPLEX( XTopWindowListener, windowClosing, EventObject, aEvent ) +} + +//____________________________________________________________________________________________________________ +// XTopWindowListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::windowClosed( const EventObject& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) +{ + MULTIPLEX( XTopWindowListener, windowClosed, EventObject, aEvent ) +} + +//____________________________________________________________________________________________________________ +// XTopWindowListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::windowMinimized( const EventObject& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) +{ + MULTIPLEX( XTopWindowListener, windowMinimized, EventObject, aEvent ) +} + +//____________________________________________________________________________________________________________ +// XTopWindowListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::windowNormalized( const EventObject& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) +{ + MULTIPLEX( XTopWindowListener, windowNormalized, EventObject, aEvent ) +} + +//____________________________________________________________________________________________________________ +// XTopWindowListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::windowActivated( const EventObject& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) +{ + MULTIPLEX( XTopWindowListener, windowActivated, EventObject, aEvent ) +} + +//____________________________________________________________________________________________________________ +// XTopWindowListener +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::windowDeactivated( const EventObject& aEvent ) throw( UNO3_RUNTIMEEXCEPTION ) +{ + MULTIPLEX( XTopWindowListener, windowDeactivated, EventObject, aEvent ) +} + +//____________________________________________________________________________________________________________ +// protected method +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::impl_adviseToPeer( const Reference< XWindow >& xPeer , + const Type& aType ) +{ + // add a listener to the source (peer) + if( aType == ::getCppuType((const Reference< XWindowListener >*)0) ) + xPeer->addWindowListener( this ); + else if( aType == ::getCppuType((const Reference< XKeyListener >*)0) ) + xPeer->addKeyListener( this ); + else if( aType == ::getCppuType((const Reference< XFocusListener >*)0) ) + xPeer->addFocusListener( this ); + else if( aType == ::getCppuType((const Reference< XMouseListener >*)0) ) + xPeer->addMouseListener( this ); + else if( aType == ::getCppuType((const Reference< XMouseMotionListener >*)0) ) + xPeer->addMouseMotionListener( this ); + else if( aType == ::getCppuType((const Reference< XPaintListener >*)0) ) + xPeer->addPaintListener( this ); + else if( aType == ::getCppuType((const Reference< XTopWindowListener >*)0) ) + { + Reference< XTopWindow > xTop( xPeer, UNO_QUERY ); + if( xTop.is() ) + xTop->addTopWindowListener( this ); + } + else + { + VOS_ENSHURE( sal_False, "unknown listener" ); + } +} + +//____________________________________________________________________________________________________________ +// protected method +//____________________________________________________________________________________________________________ + +void OMRCListenerMultiplexerHelper::impl_unadviseFromPeer( const Reference< XWindow >& xPeer , + const Type& aType ) +{ + // the last listener is removed, remove the listener from the source (peer) + if( aType == ::getCppuType((const Reference< XWindowListener >*)0) ) + xPeer->removeWindowListener( this ); + else if( aType == ::getCppuType((const Reference< XKeyListener >*)0) ) + xPeer->removeKeyListener( this ); + else if( aType == ::getCppuType((const Reference< XFocusListener >*)0) ) + xPeer->removeFocusListener( this ); + else if( aType == ::getCppuType((const Reference< XMouseListener >*)0) ) + xPeer->removeMouseListener( this ); + else if( aType == ::getCppuType((const Reference< XMouseMotionListener >*)0) ) + xPeer->removeMouseMotionListener( this ); + else if( aType == ::getCppuType((const Reference< XPaintListener >*)0) ) + xPeer->removePaintListener( this ); + else if( aType == ::getCppuType((const Reference< XTopWindowListener >*)0) ) + { + Reference< XTopWindow > xTop( xPeer, UNO_QUERY ); + if( xTop.is() ) + xTop->removeTopWindowListener( this ); + } + else + { + VOS_ENSHURE( sal_False, "unknown listener" ); + } +} + +} // namespace unocontrols diff --git a/UnoControls/source/base/registercontrols.cxx b/UnoControls/source/base/registercontrols.cxx new file mode 100644 index 000000000000..3357e1fc7765 --- /dev/null +++ b/UnoControls/source/base/registercontrols.cxx @@ -0,0 +1,393 @@ +/************************************************************************* + * + * $RCSfile: registercontrols.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 16:11:17 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +//______________________________________________________________________________________________________________ +// includes of other projects +//______________________________________________________________________________________________________________ + +#ifndef _CPPUHELPER_FACTORY_HXX_ +#include <cppuhelper/factory.hxx> +#endif + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif + +#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#endif + +#ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_ +#include <com/sun/star/registry/XRegistryKey.hpp> +#endif + +#ifndef _COM_SUN_STAR_CONTAINER_XSET_HPP_ +#include <com/sun/star/container/XSet.hpp> +#endif + +#include <stdio.h> + +//______________________________________________________________________________________________________________ +// includes of my own project +//______________________________________________________________________________________________________________ + +//============================================================================= +// Add new include line to use new services. +//============================================================================= +#ifndef _UNOCONTROLS_FRAMECONTROL_CTRL_HXX +#include "framecontrol.hxx" +#endif + +#ifndef _UNOCONTROLS_PROGRESSBAR_CTRL_HXX +#include "progressbar.hxx" +#endif + +#ifndef _UNOCONTROLS_PROGRESSMONITOR_CTRL_HXX +#include "progressmonitor.hxx" +#endif +//============================================================================= + +//______________________________________________________________________________________________________________ +// defines +//______________________________________________________________________________________________________________ + +// If you will debug macros of this file ... you must define follow constant! +// Ths switch on another macro AS_DBG_OUT(...), which will print text to "stdout". + +//#define AS_DBG_SWITCH + +//______________________________________________________________________________________________________________ +// namespaces +//______________________________________________________________________________________________________________ + +using namespace ::rtl ; +using namespace ::cppu ; +using namespace ::unocontrols ; +using namespace ::com::sun::star::uno ; +using namespace ::com::sun::star::container ; +using namespace ::com::sun::star::lang ; +using namespace ::com::sun::star::registry ; + +//______________________________________________________________________________________________________________ +// macros +//______________________________________________________________________________________________________________ + +//****************************************************************************************************************************** +// See AS_DBG_SWITCH below !!! +#ifdef AS_DBG_SWITCH + #define AS_DBG_OUT(OUTPUT) printf( OUTPUT ); +#else + #define AS_DBG_OUT(OUTPUT) +#endif + +//****************************************************************************************************************************** +#define CREATEINSTANCE(CLASS) \ + \ + static Reference< XInterface > SAL_CALL CLASS##_createInstance ( const Reference< XMultiServiceFactory >& rServiceManager ) throw ( Exception ) \ + { \ + AS_DBG_OUT ( "\tCREATEINSTANCE():\tOK\n" ) \ + return Reference< XInterface >( *(OWeakObject*)(new CLASS##( rServiceManager )) ); \ + } + +//****************************************************************************************************************************** +#define COMPONENT_INFO(CLASS) \ + \ + AS_DBG_OUT ( "\tCOMPONENT_INFO():\t[start]\n" ) \ + try \ + { \ + /* Set default result of follow operations !!! */ \ + bReturn = sal_False ; \ + \ + /* Do the follow only, if given key is valid ! */ \ + if ( xKey.is () ) \ + { \ + AS_DBG_OUT ( "\tCOMPONENT_INFO():\t\txkey is valid ...\n" ) \ + /* Build new keyname */ \ + sKeyName = OUString::createFromAscii( "/" ) ; \ + sKeyName += CLASS##::impl_getStaticImplementationName() ; \ + sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ); \ + \ + /* Create new key with new name. */ \ + xNewKey = xKey->createKey( sKeyName ); \ + \ + /* If this new key valid ... */ \ + if ( xNewKey.is () ) \ + { \ + AS_DBG_OUT ( "\tCOMPONENT_INFO():\t\txNewkey is valid ...\n" ) \ + /* Get information about supported services. */ \ + seqServiceNames = CLASS##::impl_getStaticSupportedServiceNames() ; \ + pArray = seqServiceNames.getArray() ; \ + nLength = seqServiceNames.getLength() ; \ + nCounter = 0 ; \ + \ + AS_DBG_OUT ( "\tCOMPONENT_INFO():\t\tloop ..." ) \ + /* Then set this information on this key. */ \ + for ( nCounter = 0; nCounter < nLength; ++nCounter ) \ + { \ + xNewKey->createKey( pArray [nCounter] ); \ + } \ + AS_DBG_OUT ( " OK\n" ) \ + \ + /* Result of this operations = OK. */ \ + bReturn = sal_True ; \ + } \ + AS_DBG_OUT ( "\tCOMPONENT_INFO():\t\t... leave xNewKey\n" ) \ + } \ + AS_DBG_OUT ( "\tCOMPONENT_INFO():\t\t... leave xKey\n" ) \ + } \ + catch( InvalidRegistryException& ) \ + { \ + AS_DBG_OUT ( "\tCOMPONENT_INFO():\t\tInvalidRegistryException detected!!!\n" ) \ + bReturn = sal_False ; \ + } \ + AS_DBG_OUT ( "\tCOMPONENT_INFO():\t[end]\n" ) + +//****************************************************************************************************************************** +#define CREATEFACTORY_ONEINSTANCE(CLASS) \ + \ + AS_DBG_OUT ( "\tCREATEFACTORY_ONEINSTANCE():\t[start]\n" ) \ + /* Create right factory ... */ \ + xFactory = Reference< XSingleServiceFactory > \ + ( \ + cppu::createOneInstanceFactory ( xServiceManager , \ + CLASS##::impl_getStaticImplementationName () , \ + CLASS##_createInstance , \ + CLASS##::impl_getStaticSupportedServiceNames () ) \ + ) ; \ + AS_DBG_OUT ( "\tCREATEFACTORY_ONEINSTANCE():\t[end]\n" ) + +//****************************************************************************************************************************** +#define CREATEFACTORY_SINGLE(CLASS) \ + \ + AS_DBG_OUT ( "\tCREATEFACTORY_SINGLE():\t[start]\n" ) \ + /* Create right factory ... */ \ + xFactory = Reference< XSingleServiceFactory > \ + ( \ + cppu::createSingleFactory ( xServiceManager , \ + CLASS##::impl_getStaticImplementationName () , \ + CLASS##_createInstance , \ + CLASS##::impl_getStaticSupportedServiceNames () ) \ + ) ; \ + AS_DBG_OUT ( "\tCREATEFACTORY_SINGLE():\t[end]\n" ) + +//****************************************************************************************************************************** +#ifdef MACOSX +#define IF_NAME_CREATECOMPONENTFACTORY_ONEINSTANCE(CLASS) \ + \ + if ( CLASS##::impl_getStaticImplementationName().equals( OUString::createFromAscii( pImplementationName ) ) ) \ + { \ + AS_DBG_OUT ( "\tIF_NAME_CREATECOMPONENTFACTORY_ONEINSTANCE():\timplementationname found\n" ) \ + CREATEFACTORY_ONEINSTANCE ( CLASS ) \ + } +#else /* MACOSX */ +#define IF_NAME_CREATECOMPONENTFACTORY_ONEINSTANCE(CLASS) \ + \ + if ( CLASS##::impl_getStaticImplementationName().equals( OUString::createFromAscii( pImplementationName ) ) ) \ + { \ + AS_DBG_OUT ( "\tIF_NAME_CREATECOMPONENTFACTORY_ONEINSTANCE():\timplementationname found\n" ) \ + CREATEFACTORY_ONEINSTANCE ( CLASS## ) \ + } +#endif /* MACOSX */ + +//****************************************************************************************************************************** +#ifdef MACOSX +#define IF_NAME_CREATECOMPONENTFACTORY_SINGLE(CLASS) \ + \ + if ( CLASS##::impl_getStaticImplementationName().equals( OUString::createFromAscii( pImplementationName ) ) ) \ + { \ + AS_DBG_OUT ( "\tIF_NAME_CREATECOMPONENTFACTORY_SINGLE():\timplementationname found\n" ) \ + CREATEFACTORY_SINGLE ( CLASS ) \ + } +#else /* MACOSX */ +#define IF_NAME_CREATECOMPONENTFACTORY_SINGLE(CLASS) \ + \ + if ( CLASS##::impl_getStaticImplementationName().equals( OUString::createFromAscii( pImplementationName ) ) ) \ + { \ + AS_DBG_OUT ( "\tIF_NAME_CREATECOMPONENTFACTORY_SINGLE():\timplementationname found\n" ) \ + CREATEFACTORY_SINGLE ( CLASS## ) \ + } +#endif /* MACOSX */ + +//______________________________________________________________________________________________________________ +// declare functions to create a new instance of service +//______________________________________________________________________________________________________________ + +//============================================================================= +// Add new macro line to use new services. +// +// !!! ATTENTION !!! +// Write no ";" at end of line! (see macro) +//============================================================================= +CREATEINSTANCE ( FrameControl ) +CREATEINSTANCE ( ProgressBar ) +CREATEINSTANCE ( ProgressMonitor ) +//============================================================================= + +//______________________________________________________________________________________________________________ +// return environment +//______________________________________________________________________________________________________________ + +extern "C" void SAL_CALL component_getImplementationEnvironment( const sal_Char** ppEnvironmentTypeName , + uno_Environment** ppEnvironment ) +{ + *ppEnvironmentTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ; +} + +//______________________________________________________________________________________________________________ +// write component info to registry +//______________________________________________________________________________________________________________ + +extern "C" sal_Bool SAL_CALL component_writeInfo( void* pServiceManager , + void* pRegistryKey ) +{ + AS_DBG_OUT ( "component_writeInfo():\t[start]\n" ) + + // Set default return value for this operation - if it failed. + sal_Bool bReturn = sal_False ; + + if ( pRegistryKey != NULL ) + { + AS_DBG_OUT ( "component_writeInfo():\t\tpRegistryKey is valid ... enter scope\n" ) + + // Define variables for following macros! + // bReturn is set automaticly. + Reference< XRegistryKey > xKey( reinterpret_cast< XRegistryKey* >( pRegistryKey ) ) ; + Reference< XRegistryKey > xNewKey ; + Sequence< OUString > seqServiceNames ; + const OUString* pArray ; + sal_Int32 nLength ; + sal_Int32 nCounter ; + OUString sKeyName ; + + //============================================================================= + // Add new macro line to register new services. + // + // !!! ATTENTION !!! + // Write no ";" at end of line! (see macro) + //============================================================================= + COMPONENT_INFO ( FrameControl ) + COMPONENT_INFO ( ProgressBar ) + COMPONENT_INFO ( ProgressMonitor ) + //============================================================================= + + AS_DBG_OUT ( "component_writeInfo():\t\t... leave pRegistryKey scope\n" ) + } + + AS_DBG_OUT ( "component_writeInfo():\t[end]\n" ) + + // Return with result of this operation. + return bReturn ; +} + +//______________________________________________________________________________________________________________ +// create right component factory +//______________________________________________________________________________________________________________ + +extern "C" void* SAL_CALL component_getFactory( const sal_Char* pImplementationName , + void* pServiceManager , + void* pRegistryKey ) +{ + AS_DBG_OUT( "component_getFactory():\t[start]\n" ) + + // Set default return value for this operation - if it failed. + void* pReturn = NULL ; + + if ( + ( pImplementationName != NULL ) && + ( pServiceManager != NULL ) + ) + { + AS_DBG_OUT( "component_getFactory():\t\t... enter scope - pointer are valid\n" ) + + // Define variables which are used in following macros. + Reference< XSingleServiceFactory > xFactory ; + Reference< XMultiServiceFactory > xServiceManager( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ; + + //============================================================================= + // Add new macro line to handle new service. + // + // !!! ATTENTION !!! + // Write no ";" at end of line and dont forget "else" ! (see macro) + //============================================================================= + IF_NAME_CREATECOMPONENTFACTORY_SINGLE( FrameControl ) + else + IF_NAME_CREATECOMPONENTFACTORY_SINGLE( ProgressBar ) + else + IF_NAME_CREATECOMPONENTFACTORY_SINGLE( ProgressMonitor ) + //============================================================================= + + // Factory is valid - service was found. + if ( xFactory.is() ) + { + AS_DBG_OUT( "component_getFactory():\t\t\t... xFactory valid - service was found\n" ) + + xFactory->acquire(); + pReturn = xFactory.get(); + } + + AS_DBG_OUT( "component_getFactory():\t\t... leave scope\n" ) + } + + AS_DBG_OUT ( "component_getFactory():\t[end]\n" ) + + // Return with result of this operation. + return pReturn ; +} |