diff options
Diffstat (limited to 'toolkit/source')
131 files changed, 49787 insertions, 0 deletions
diff --git a/toolkit/source/awt/asynccallback.cxx b/toolkit/source/awt/asynccallback.cxx new file mode 100644 index 000000000000..593feb582274 --- /dev/null +++ b/toolkit/source/awt/asynccallback.cxx @@ -0,0 +1,199 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + +#include "vcl/svapp.hxx" +#include "vos/mutex.hxx" +#include "sal/config.h" +#include "cppuhelper/factory.hxx" +#include "cppuhelper/implementationentry.hxx" +#include "cppuhelper/implbase2.hxx" +#include "com/sun/star/lang/XServiceInfo.hpp" +#include "com/sun/star/awt/XRequestCallback.hpp" + + +// component helper namespace +namespace comp_AsyncCallback { + +namespace css = ::com::sun::star; + +// component and service helper functions: +::rtl::OUString SAL_CALL _getImplementationName(); +css::uno::Sequence< ::rtl::OUString > SAL_CALL _getSupportedServiceNames(); +css::uno::Reference< css::uno::XInterface > SAL_CALL _create( css::uno::Reference< css::uno::XComponentContext > const & context ); + +} // closing component helper namespace + + + +/// anonymous implementation namespace +namespace { + +namespace css = ::com::sun::star; + +class AsyncCallback: + public ::cppu::WeakImplHelper2< + css::lang::XServiceInfo, + css::awt::XRequestCallback> +{ +public: + explicit AsyncCallback(css::uno::Reference< css::uno::XComponentContext > const & context); + + // ::com::sun::star::lang::XServiceInfo: + virtual ::rtl::OUString SAL_CALL getImplementationName() throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL supportsService(const ::rtl::OUString & ServiceName) throw (css::uno::RuntimeException); + virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (css::uno::RuntimeException); + + // ::com::sun::star::awt::XRequestCallback: + virtual void SAL_CALL addCallback(const css::uno::Reference< css::awt::XCallback > & xCallback, const ::com::sun::star::uno::Any & aData) throw (css::uno::RuntimeException); + +private: + + struct CallbackData + { + CallbackData( const css::uno::Reference< css::awt::XCallback >& rCallback, const css::uno::Any& rAny ) : + xCallback( rCallback ), aData( rAny ) {} + + css::uno::Reference< css::awt::XCallback > xCallback; + css::uno::Any aData; + }; + + DECL_STATIC_LINK( AsyncCallback, Notify_Impl, CallbackData* ); + + AsyncCallback(AsyncCallback &); // not defined + void operator =(AsyncCallback &); // not defined + + virtual ~AsyncCallback() {} + + css::uno::Reference< css::uno::XComponentContext > m_xContext; +}; + +AsyncCallback::AsyncCallback(css::uno::Reference< css::uno::XComponentContext > const & context) : + m_xContext(context) +{} + +// com.sun.star.uno.XServiceInfo: +::rtl::OUString SAL_CALL AsyncCallback::getImplementationName() throw (css::uno::RuntimeException) +{ + return comp_AsyncCallback::_getImplementationName(); +} + +::sal_Bool SAL_CALL AsyncCallback::supportsService(::rtl::OUString const & serviceName) throw (css::uno::RuntimeException) +{ + const css::uno::Sequence< ::rtl::OUString > serviceNames = comp_AsyncCallback::_getSupportedServiceNames(); + for (::sal_Int32 i = 0; i < serviceNames.getLength(); ++i) { + if (serviceNames[i] == serviceName) + return sal_True; + } + return sal_False; +} + +css::uno::Sequence< ::rtl::OUString > SAL_CALL AsyncCallback::getSupportedServiceNames() throw (css::uno::RuntimeException) +{ + return comp_AsyncCallback::_getSupportedServiceNames(); +} + +// ::com::sun::star::awt::XRequestCallback: +void SAL_CALL AsyncCallback::addCallback(const css::uno::Reference< css::awt::XCallback > & xCallback, const ::com::sun::star::uno::Any & aData) throw (css::uno::RuntimeException) +{ + if ( Application::IsInMain() ) + { + osl::Guard< vos::IMutex > aSolarGuard( Application::GetSolarMutex() ); + CallbackData* pCallbackData = new CallbackData( xCallback, aData ); + Application::PostUserEvent( STATIC_LINK( this, AsyncCallback, Notify_Impl ), pCallbackData ); + } +} + +// private asynchronous link to call reference to the callback object +IMPL_STATIC_LINK_NOINSTANCE( AsyncCallback, Notify_Impl, CallbackData*, pCallbackData ) +{ + try + { + // Asynchronous execution + // Check pointer and reference before! + if ( pCallbackData && pCallbackData->xCallback.is() ) + pCallbackData->xCallback->notify( pCallbackData->aData ); + } + catch ( css::uno::Exception& ) + { + } + + delete pCallbackData; + return 0; +} + +} // closing anonymous implementation namespace + + + +// component helper namespace +namespace comp_AsyncCallback { + +::rtl::OUString SAL_CALL _getImplementationName() { + return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.awt.comp.AsyncCallback")); +} + +css::uno::Sequence< ::rtl::OUString > SAL_CALL _getSupportedServiceNames() +{ + css::uno::Sequence< ::rtl::OUString > s(1); + s[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.awt.AsyncCallback")); + return s; +} + +css::uno::Reference< css::uno::XInterface > SAL_CALL _create( + const css::uno::Reference< css::uno::XComponentContext > & context) + SAL_THROW((css::uno::Exception)) +{ + return static_cast< ::cppu::OWeakObject * >(new AsyncCallback(context)); +} + +} // closing component helper namespace + +static ::cppu::ImplementationEntry const entries[] = { + { &comp_AsyncCallback::_create, + &comp_AsyncCallback::_getImplementationName, + &comp_AsyncCallback::_getSupportedServiceNames, + &::cppu::createSingleComponentFactory, 0, 0 }, + { 0, 0, 0, 0, 0, 0 } +}; + +void * SAL_CALL comp_AsyncCallback_component_getFactory( + const char * implName, void * serviceManager, void * registryKey) +{ + return ::cppu::component_getFactoryHelper( + implName, serviceManager, registryKey, entries); +} + +sal_Bool SAL_CALL comp_AsyncCallback_component_writeInfo( + void * serviceManager, void * registryKey) +{ + return ::cppu::component_writeInfoHelper(serviceManager, registryKey, entries); +} diff --git a/toolkit/source/awt/forward.hxx b/toolkit/source/awt/forward.hxx new file mode 100644 index 000000000000..0228be562b2c --- /dev/null +++ b/toolkit/source/awt/forward.hxx @@ -0,0 +1,73 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef AWT_FORWARD_HXX +#define AWT_FORWARD_HXX + +#include <comphelper/uno3.hxx> + +#define IMPLEMENT_FORWARD_XTYPEPROVIDER1( classname, baseclass ) \ + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL classname::getTypes( ) throw (::com::sun::star::uno::RuntimeException) \ + { return baseclass::getTypes(); } \ + IMPLEMENT_GET_IMPLEMENTATION_ID( classname ) + +#define IMPLEMENT_2_FORWARD_XINTERFACE1( classname, refcountbase1, refcountbase2 ) \ + void SAL_CALL classname::acquire() throw() { refcountbase1::acquire(); refcountbase2::acquire(); } \ + void SAL_CALL classname::release() throw() { refcountbase1::release(); refcountbase2::release(); } \ + ::com::sun::star::uno::Any SAL_CALL classname::queryInterface( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException) \ + { \ + ::com::sun::star::uno::Any aReturn = refcountbase1::queryInterface( _rType ); \ + if ( !aReturn.hasValue() ) \ + { \ + aReturn = refcountbase2::queryInterface( _rType ); \ + } \ + return aReturn; \ + } + +#define IMPLEMENT_2_FORWARD_XINTERFACE2( classname, refcountbase1, refcountbase2, baseclass3 ) \ + void SAL_CALL classname::acquire() throw() { refcountbase1::acquire(); refcountbase2::acquire(); } \ + void SAL_CALL classname::release() throw() { refcountbase1::release(); refcountbase2::release(); } \ + ::com::sun::star::uno::Any SAL_CALL classname::queryInterface( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException) \ + { \ + ::com::sun::star::uno::Any aReturn = refcountbase1::queryInterface( _rType ); \ + if ( !aReturn.hasValue() ) \ + { \ + aReturn = refcountbase2::queryInterface( _rType ); \ + if ( !aReturn.hasValue() ) \ + aReturn = baseclass3::queryInterface( _rType ); \ + } \ + return aReturn; \ + } + +#if defined (_MSC_VER) && (_MSC_VER <= 1310) +// Windows .Net2003 build fix +#define W3K_EXPLICIT_CAST(x) static_cast <XWindow2*> (&x) +#else // !(defined (_MSC_VER) && (_MSC_VER <= 1310)) +#define W3K_EXPLICIT_CAST(x) x +#endif // !(defined (_MSC_VER) && (_MSC_VER <= 1310)) + +#endif /* AWT_FORWARD_HXX */ diff --git a/toolkit/source/awt/makefile.mk b/toolkit/source/awt/makefile.mk new file mode 100644 index 000000000000..a53e9e22ba2d --- /dev/null +++ b/toolkit/source/awt/makefile.mk @@ -0,0 +1,83 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=toolkit +TARGET=awt + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/util$/makefile.pmk + +# --- Files -------------------------------------------------------- + +.IF "$(GUIBASE)"=="aqua" +CFLAGSCXX+=$(OBJCXXFLAGS) +.ENDIF # "$(GUIBASE)"=="aqua" + +SLOFILES= \ + $(SLO)$/vclxaccessiblecomponent.obj \ + $(SLO)$/vclxbitmap.obj \ + $(SLO)$/vclxcontainer.obj \ + $(SLO)$/vclxdevice.obj \ + $(SLO)$/vclxfont.obj \ + $(SLO)$/vclxgraphics.obj \ + $(SLO)$/vclxmenu.obj \ + $(SLO)$/vclxpointer.obj \ + $(SLO)$/vclxprinter.obj \ + $(SLO)$/vclxregion.obj \ + $(SLO)$/vclxsystemdependentwindow.obj \ + $(SLO)$/vclxtoolkit.obj \ + $(SLO)$/vclxtopwindow.obj \ + $(SLO)$/vclxwindow.obj \ + $(SLO)$/vclxwindow1.obj \ + $(SLO)$/vclxwindows.obj \ + $(SLO)$/vclxspinbutton.obj \ + $(SLO)$/xsimpleanimation.obj \ + $(SLO)$/xthrobber.obj \ + $(SLO)$/asynccallback.obj\ + $(SLO)/vclxbutton.obj\ + $(SLO)/vclxdialog.obj\ + $(SLO)/vclxfixedline.obj\ + $(SLO)/vclxplugin.obj\ + $(SLO)/vclxscroller.obj\ + $(SLO)/vclxsplitter.obj\ + $(SLO)/vclxtabcontrol.obj\ + $(SLO)/vclxtabpage.obj + +SRS1NAME=$(TARGET) +SRC1FILES=\ + xthrobber.src + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + diff --git a/toolkit/source/awt/non-interactable-containers.xml b/toolkit/source/awt/non-interactable-containers.xml new file mode 100644 index 000000000000..0ffdb7e9d58d --- /dev/null +++ b/toolkit/source/awt/non-interactable-containers.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dialog xmlns="http://openoffice.org/2007/layout" + xmlns:cnt="http://openoffice.org/2007/layout/container" + title="Interactable Containers" optimumsize="true" + border="true" sizeable="true" moveable="true"> + <hbox> + <table columns="3" cnt:title="Page 1"> + <pushbutton cnt:x-expand="false" cnt:row-span="2" label="1,1" /> + <pushbutton cnt:y-expand="false" label="1,2" /> + <pushbutton cnt:y-expand="false" label="1,3" /> + <pushbutton cnt:col-span="2" label="2,1" /> + </table> + </hbox> +</dialog> diff --git a/toolkit/source/awt/vclxaccessiblecomponent.cxx b/toolkit/source/awt/vclxaccessiblecomponent.cxx new file mode 100644 index 000000000000..175289d1ac84 --- /dev/null +++ b/toolkit/source/awt/vclxaccessiblecomponent.cxx @@ -0,0 +1,924 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + + +#include <com/sun/star/accessibility/AccessibleRole.hpp> +#include <com/sun/star/accessibility/AccessibleStateType.hpp> +#include <com/sun/star/accessibility/AccessibleEventId.hpp> +#include <com/sun/star/accessibility/XAccessibleEventListener.hpp> +#include <com/sun/star/accessibility/AccessibleRelationType.hpp> +#include <toolkit/awt/vclxaccessiblecomponent.hxx> +#include <toolkit/helper/externallock.hxx> +#include <toolkit/awt/vclxwindow.hxx> +#include <toolkit/helper/convert.hxx> +#include <toolkit/awt/vclxfont.hxx> +#include <vcl/dialog.hxx> +#include <vcl/window.hxx> +#include <tools/debug.hxx> +#include <unotools/accessiblestatesethelper.hxx> +#include <unotools/accessiblerelationsethelper.hxx> +#include <vcl/svapp.hxx> +#include <vcl/menu.hxx> + +#ifndef VCLEVENT_WINDOW_FRAMETITLECHANGED +#define VCLEVENT_WINDOW_FRAMETITLECHANGED 1018 // pData = XubString* = oldTitle +#endif + +using namespace ::com::sun::star; +using namespace ::comphelper; + + +DBG_NAME(VCLXAccessibleComponent) + + +// ---------------------------------------------------- +// class VCLXAccessibleComponent +// ---------------------------------------------------- +VCLXAccessibleComponent::VCLXAccessibleComponent( VCLXWindow* pVCLXindow ) + : AccessibleExtendedComponentHelper_BASE( new VCLExternalSolarLock() ) + , OAccessibleImplementationAccess( ) +{ + DBG_CTOR( VCLXAccessibleComponent, 0 ); + mpVCLXindow = pVCLXindow; + mxWindow = pVCLXindow; + + m_pSolarLock = static_cast< VCLExternalSolarLock* >( getExternalLock( ) ); + + DBG_ASSERT( pVCLXindow->GetWindow(), "VCLXAccessibleComponent - no window!" ); + if ( pVCLXindow->GetWindow() ) + { + pVCLXindow->GetWindow()->AddEventListener( LINK( this, VCLXAccessibleComponent, WindowEventListener ) ); + pVCLXindow->GetWindow()->AddChildEventListener( LINK( this, VCLXAccessibleComponent, WindowChildEventListener ) ); + } + + // announce the XAccessible of our creator to the base class + lateInit( pVCLXindow ); +} + +VCLXAccessibleComponent::~VCLXAccessibleComponent() +{ + DBG_DTOR( VCLXAccessibleComponent, 0 ); + + ensureDisposed(); + + if ( mpVCLXindow && mpVCLXindow->GetWindow() ) + { + mpVCLXindow->GetWindow()->RemoveEventListener( LINK( this, VCLXAccessibleComponent, WindowEventListener ) ); + mpVCLXindow->GetWindow()->RemoveChildEventListener( LINK( this, VCLXAccessibleComponent, WindowChildEventListener ) ); + } + + delete m_pSolarLock; + m_pSolarLock = NULL; + // This is not completely safe. If we assume that the base class dtor calls some method which + // uses this lock, the we crash. However, as the base class' dtor does not have a chance to call _out_ + // virtual methods, this is no problem as long as the base class is safe, i.e. does not use the external + // lock from within it's dtor. At the moment, we _know_ the base class is safe in this respect, so + // let's assume it keeps this way. + // @see OAccessibleContextHelper::OAccessibleContextHelper( IMutex* ) +} + +IMPLEMENT_FORWARD_XINTERFACE3( VCLXAccessibleComponent, AccessibleExtendedComponentHelper_BASE, OAccessibleImplementationAccess, VCLXAccessibleComponent_BASE ) +IMPLEMENT_FORWARD_XTYPEPROVIDER3( VCLXAccessibleComponent, AccessibleExtendedComponentHelper_BASE, OAccessibleImplementationAccess, VCLXAccessibleComponent_BASE ) + +::rtl::OUString VCLXAccessibleComponent::getImplementationName() throw (uno::RuntimeException) +{ + return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleWindow" ); +} + +sal_Bool VCLXAccessibleComponent::supportsService( const ::rtl::OUString& rServiceName ) throw (uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() ); + const ::rtl::OUString* pNames = aNames.getConstArray(); + const ::rtl::OUString* pEnd = pNames + aNames.getLength(); + for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames ) + ; + + return pNames != pEnd; +} + +uno::Sequence< ::rtl::OUString > VCLXAccessibleComponent::getSupportedServiceNames() throw (uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString > aNames(1); + aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleWindow" ); + return aNames; +} + +IMPL_LINK( VCLXAccessibleComponent, WindowEventListener, VclSimpleEvent*, pEvent ) +{ + DBG_CHKTHIS(VCLXAccessibleComponent,0); + + DBG_ASSERT( pEvent && pEvent->ISA( VclWindowEvent ), "Unknown WindowEvent!" ); + + /* Ignore VCLEVENT_WINDOW_ENDPOPUPMODE, because the UNO accessibility wrapper + * might have been destroyed by the previous VCLEventListener (if no AT tool + * is running), e.g. sub-toolbars in impress. + */ + if ( pEvent && pEvent->ISA( VclWindowEvent ) && mxWindow.is() /* #122218# */ && (pEvent->GetId() != VCLEVENT_WINDOW_ENDPOPUPMODE) ) + { + DBG_ASSERT( ((VclWindowEvent*)pEvent)->GetWindow(), "Window???" ); + if( !((VclWindowEvent*)pEvent)->GetWindow()->IsAccessibilityEventsSuppressed() || ( pEvent->GetId() == VCLEVENT_OBJECT_DYING ) ) + { + ProcessWindowEvent( *(VclWindowEvent*)pEvent ); + } + } + return 0; +} + +IMPL_LINK( VCLXAccessibleComponent, WindowChildEventListener, VclSimpleEvent*, pEvent ) +{ + DBG_CHKTHIS(VCLXAccessibleComponent,0); + + DBG_ASSERT( pEvent && pEvent->ISA( VclWindowEvent ), "Unknown WindowEvent!" ); + if ( pEvent && pEvent->ISA( VclWindowEvent ) && mxWindow.is() /* #i68079# */ ) + { + DBG_ASSERT( ((VclWindowEvent*)pEvent)->GetWindow(), "Window???" ); + if( !((VclWindowEvent*)pEvent)->GetWindow()->IsAccessibilityEventsSuppressed() ) + { + // #103087# to prevent an early release of the component + uno::Reference< accessibility::XAccessibleContext > xTmp = this; + + ProcessWindowChildEvent( *(VclWindowEvent*)pEvent ); + } + } + return 0; +} + +uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::GetChildAccessible( const VclWindowEvent& rVclWindowEvent ) +{ + // checks if the data in the window event is our direct child + // and returns its accessible + + // MT: Change this later, normaly a show/hide event shouldn't have the Window* in pData. + Window* pChildWindow = (Window *) rVclWindowEvent.GetData(); + if( pChildWindow && GetWindow() == pChildWindow->GetAccessibleParentWindow() ) + return pChildWindow->GetAccessible( rVclWindowEvent.GetId() == VCLEVENT_WINDOW_SHOW ); + else + return uno::Reference< accessibility::XAccessible > (); +} + +void VCLXAccessibleComponent::ProcessWindowChildEvent( const VclWindowEvent& rVclWindowEvent ) +{ + uno::Any aOldValue, aNewValue; + uno::Reference< accessibility::XAccessible > xAcc; + + switch ( rVclWindowEvent.GetId() ) + { + case VCLEVENT_WINDOW_SHOW: // send create on show for direct accessible children + { + xAcc = GetChildAccessible( rVclWindowEvent ); + if( xAcc.is() ) + { + aNewValue <<= xAcc; + NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue ); + } + } + break; + case VCLEVENT_WINDOW_HIDE: // send destroy on hide for direct accessible children + { + xAcc = GetChildAccessible( rVclWindowEvent ); + if( xAcc.is() ) + { + aOldValue <<= xAcc; + NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue ); + } + } + break; + } +} + +void VCLXAccessibleComponent::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) +{ + uno::Any aOldValue, aNewValue; + + Window* pAccWindow = rVclWindowEvent.GetWindow(); + DBG_ASSERT( pAccWindow, "VCLXAccessibleComponent::ProcessWindowEvent - Window?" ); + + switch ( rVclWindowEvent.GetId() ) + { + case VCLEVENT_OBJECT_DYING: + { + pAccWindow->RemoveEventListener( LINK( this, VCLXAccessibleComponent, WindowEventListener ) ); + pAccWindow->RemoveChildEventListener( LINK( this, VCLXAccessibleComponent, WindowChildEventListener ) ); + mxWindow.clear(); + mpVCLXindow = NULL; + } + break; + // + // dont handle CHILDCREATED events here + // they are handled separately as child events, see ProcessWindowChildEvent above + // + /* + case VCLEVENT_WINDOW_CHILDCREATED: + { + Window* pWindow = (Window*) rVclWindowEvent.GetData(); + DBG_ASSERT( pWindow, "VCLEVENT_WINDOW_CHILDCREATED - Window=?" ); + aNewValue <<= pWindow->GetAccessible(); + NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue ); + } + break; + */ + case VCLEVENT_WINDOW_CHILDDESTROYED: + { + Window* pWindow = (Window*) rVclWindowEvent.GetData(); + DBG_ASSERT( pWindow, "VCLEVENT_WINDOW_CHILDDESTROYED - Window=?" ); + if ( pWindow->GetAccessible( FALSE ).is() ) + { + aOldValue <<= pWindow->GetAccessible( FALSE ); + NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue ); + } + } + break; + + // + // show and hide will be handled as child events only and are + // responsible for sending create/destroy events, see ProcessWindowChildEvent above + // + /* + case VCLEVENT_WINDOW_SHOW: + { + aNewValue <<= accessibility::AccessibleStateType::VISIBLE; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + + aNewValue <<= accessibility::AccessibleStateType::SHOWING; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + + aNewValue.clear(); + aOldValue <<= accessibility::AccessibleStateType::INVALID; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + } + break; + case VCLEVENT_WINDOW_HIDE: + { + aOldValue <<= accessibility::AccessibleStateType::VISIBLE; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + + aOldValue <<= accessibility::AccessibleStateType::SHOWING; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + + aOldValue.clear(); + aNewValue <<= accessibility::AccessibleStateType::INVALID; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + } + break; + */ + case VCLEVENT_WINDOW_ACTIVATE: + { + // avoid notification if a child frame is already active + // only one frame may be active at a given time + if ( !pAccWindow->HasActiveChildFrame() && + ( getAccessibleRole() == accessibility::AccessibleRole::FRAME || + getAccessibleRole() == accessibility::AccessibleRole::ALERT || + getAccessibleRole() == accessibility::AccessibleRole::DIALOG ) ) // #i18891# + { + aNewValue <<= accessibility::AccessibleStateType::ACTIVE; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + } + } + break; + case VCLEVENT_WINDOW_DEACTIVATE: + { + if ( getAccessibleRole() == accessibility::AccessibleRole::FRAME || + getAccessibleRole() == accessibility::AccessibleRole::ALERT || + getAccessibleRole() == accessibility::AccessibleRole::DIALOG ) // #i18891# + { + aOldValue <<= accessibility::AccessibleStateType::ACTIVE; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + } + } + break; + case VCLEVENT_WINDOW_GETFOCUS: + case VCLEVENT_CONTROL_GETFOCUS: + { + if( (pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VCLEVENT_CONTROL_GETFOCUS) || + (!pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VCLEVENT_WINDOW_GETFOCUS) ) + { + // if multiple listeners were registered it is possible that the + // focus was changed during event processing (eg SfxTopWindow ) + // #106082# allow ChildPathFocus only for CompoundControls, for windows the focus must be in the window itself + if( (pAccWindow->IsCompoundControl() && pAccWindow->HasChildPathFocus()) || + (!pAccWindow->IsCompoundControl() && pAccWindow->HasFocus()) ) + { + aNewValue <<= accessibility::AccessibleStateType::FOCUSED; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + } + } + } + break; + case VCLEVENT_WINDOW_LOSEFOCUS: + case VCLEVENT_CONTROL_LOSEFOCUS: + { + if( (pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VCLEVENT_CONTROL_LOSEFOCUS) || + (!pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VCLEVENT_WINDOW_LOSEFOCUS) ) + { + aOldValue <<= accessibility::AccessibleStateType::FOCUSED; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + } + } + break; + case VCLEVENT_WINDOW_FRAMETITLECHANGED: + { + ::rtl::OUString aOldName( *((::rtl::OUString*) rVclWindowEvent.GetData()) ); + ::rtl::OUString aNewName( getAccessibleName() ); + aOldValue <<= aOldName; + aNewValue <<= aNewName; + NotifyAccessibleEvent( accessibility::AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue ); + } + break; + case VCLEVENT_WINDOW_ENABLED: + { + aNewValue <<= accessibility::AccessibleStateType::ENABLED; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + aNewValue <<= accessibility::AccessibleStateType::SENSITIVE; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + } + break; + case VCLEVENT_WINDOW_DISABLED: + { + aOldValue <<= accessibility::AccessibleStateType::SENSITIVE; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + + aOldValue <<= accessibility::AccessibleStateType::ENABLED; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + } + break; + case VCLEVENT_WINDOW_MOVE: + case VCLEVENT_WINDOW_RESIZE: + { + NotifyAccessibleEvent( accessibility::AccessibleEventId::BOUNDRECT_CHANGED, aOldValue, aNewValue ); + } + break; + case VCLEVENT_WINDOW_MENUBARADDED: + { + MenuBar* pMenuBar = (MenuBar*) rVclWindowEvent.GetData(); + if ( pMenuBar ) + { + uno::Reference< accessibility::XAccessible > xChild( pMenuBar->GetAccessible() ); + if ( xChild.is() ) + { + aNewValue <<= xChild; + NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue ); + } + } + } + break; + case VCLEVENT_WINDOW_MENUBARREMOVED: + { + MenuBar* pMenuBar = (MenuBar*) rVclWindowEvent.GetData(); + if ( pMenuBar ) + { + uno::Reference< accessibility::XAccessible > xChild( pMenuBar->GetAccessible() ); + if ( xChild.is() ) + { + aOldValue <<= xChild; + NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue ); + } + } + } + break; + case VCLEVENT_WINDOW_MINIMIZE: + { + aNewValue <<= accessibility::AccessibleStateType::ICONIFIED; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + } + break; + case VCLEVENT_WINDOW_NORMALIZE: + { + aOldValue <<= accessibility::AccessibleStateType::ICONIFIED; + NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); + } + break; + default: + { + } + break; + } +} + +void VCLXAccessibleComponent::disposing() +{ + if ( mpVCLXindow && mpVCLXindow->GetWindow() ) + { + mpVCLXindow->GetWindow()->RemoveEventListener( LINK( this, VCLXAccessibleComponent, WindowEventListener ) ); + mpVCLXindow->GetWindow()->RemoveChildEventListener( LINK( this, VCLXAccessibleComponent, WindowChildEventListener ) ); + } + + AccessibleExtendedComponentHelper_BASE::disposing(); + + mxWindow.clear(); + mpVCLXindow = NULL; +} + +Window* VCLXAccessibleComponent::GetWindow() const +{ + return GetVCLXWindow() ? GetVCLXWindow()->GetWindow() : NULL; +} + +void VCLXAccessibleComponent::FillAccessibleRelationSet( utl::AccessibleRelationSetHelper& rRelationSet ) +{ + Window* pWindow = GetWindow(); + if ( pWindow ) + { + Window *pLabeledBy = pWindow->GetLabeledBy(); + if ( pLabeledBy && pLabeledBy != pWindow ) + { + uno::Sequence< uno::Reference< uno::XInterface > > aSequence(1); + aSequence[0] = pLabeledBy->GetAccessible(); + rRelationSet.AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::LABELED_BY, aSequence ) ); + } + + Window* pLabelFor = pWindow->GetLabelFor(); + if ( pLabelFor && pLabelFor != pWindow ) + { + uno::Sequence< uno::Reference< uno::XInterface > > aSequence(1); + aSequence[0] = pLabelFor->GetAccessible(); + rRelationSet.AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::LABEL_FOR, aSequence ) ); + } + } +} + +void VCLXAccessibleComponent::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet ) +{ + Window* pWindow = GetWindow(); + if ( pWindow ) + { + if ( pWindow->IsVisible() ) + { + rStateSet.AddState( accessibility::AccessibleStateType::VISIBLE ); + rStateSet.AddState( accessibility::AccessibleStateType::SHOWING ); + } + else + { + rStateSet.AddState( accessibility::AccessibleStateType::INVALID ); + } + + if ( pWindow->IsEnabled() ) + { + rStateSet.AddState( accessibility::AccessibleStateType::ENABLED ); + rStateSet.AddState( accessibility::AccessibleStateType::SENSITIVE ); + } + + if ( pWindow->HasChildPathFocus() && + ( getAccessibleRole() == accessibility::AccessibleRole::FRAME || + getAccessibleRole() == accessibility::AccessibleRole::ALERT || + getAccessibleRole() == accessibility::AccessibleRole::DIALOG ) ) // #i18891# + rStateSet.AddState( accessibility::AccessibleStateType::ACTIVE ); + + // #104290# MT: This way, a ComboBox doesn't get state FOCUSED. + // I also don't understand + // a) why WINDOW_FIRSTCHILD is used here (which btw is a border window in the case of a combo box) + // b) why HasFocus() is nout "enough" for a compound control + /* + Window* pChild = pWindow->GetWindow( WINDOW_FIRSTCHILD ); + if ( ( !pWindow->IsCompoundControl() && pWindow->HasFocus() ) || + ( pWindow->IsCompoundControl() && pChild && pChild->HasFocus() ) ) + rStateSet.AddState( accessibility::AccessibleStateType::FOCUSED ); + */ + if ( pWindow->HasFocus() || ( pWindow->IsCompoundControl() && pWindow->HasChildPathFocus() ) ) + rStateSet.AddState( accessibility::AccessibleStateType::FOCUSED ); + + if ( pWindow->IsWait() ) + rStateSet.AddState( accessibility::AccessibleStateType::BUSY ); + + if ( pWindow->GetStyle() & WB_SIZEABLE ) + rStateSet.AddState( accessibility::AccessibleStateType::RESIZABLE ); + + if( pWindow->IsDialog() ) + { + Dialog *pDlg = static_cast< Dialog* >( pWindow ); + if( pDlg->IsInExecute() ) + rStateSet.AddState( accessibility::AccessibleStateType::MODAL ); + } + } + else + { + rStateSet.AddState( accessibility::AccessibleStateType::DEFUNC ); + } + +/* + +MUST BE SET FROM DERIVED CLASSES: + +CHECKED +COLLAPSED +EXPANDED +EXPANDABLE +EDITABLE +FOCUSABLE +HORIZONTAL +VERTICAL +ICONIFIED +MULTILINE +MULTI_SELECTABLE +PRESSED +SELECTABLE +SELECTED +SINGLE_LINE +TRANSIENT + + */ +} + + +// accessibility::XAccessibleContext +sal_Int32 VCLXAccessibleComponent::getAccessibleChildCount() throw (uno::RuntimeException) +{ + OExternalLockGuard aGuard( this ); + + sal_Int32 nChildren = 0; + if ( GetWindow() ) + nChildren = GetWindow()->GetAccessibleChildWindowCount(); + + return nChildren; +} + +uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getAccessibleChild( sal_Int32 i ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) +{ + OExternalLockGuard aGuard( this ); + + if ( i >= getAccessibleChildCount() ) + throw lang::IndexOutOfBoundsException(); + + uno::Reference< accessibility::XAccessible > xAcc; + if ( GetWindow() ) + { + Window* pChild = GetWindow()->GetAccessibleChildWindow( (USHORT)i ); + if ( pChild ) + xAcc = pChild->GetAccessible(); + } + + return xAcc; +} + +uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getVclParent() const +{ + uno::Reference< accessibility::XAccessible > xAcc; + if ( GetWindow() ) + { + Window* pParent = GetWindow()->GetAccessibleParentWindow(); + if ( pParent ) + xAcc = pParent->GetAccessible(); + } + return xAcc; +} + +uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getAccessibleParent( ) throw (uno::RuntimeException) +{ + OExternalLockGuard aGuard( this ); + + uno::Reference< accessibility::XAccessible > xAcc( implGetForeignControlledParent() ); + if ( !xAcc.is() ) + // we do _not_ have a foreign-controlled parent -> default to our VCL parent + xAcc = getVclParent(); + + return xAcc; +} + +sal_Int32 VCLXAccessibleComponent::getAccessibleIndexInParent( ) throw (uno::RuntimeException) +{ + OExternalLockGuard aGuard( this ); + + sal_Int32 nIndex = -1; + + uno::Reference< accessibility::XAccessible > xAcc( implGetForeignControlledParent() ); + if ( xAcc.is() ) + { // we _do_ have a foreign-controlled parent -> use the base class' implementation, + // which goes the UNO way + nIndex = AccessibleExtendedComponentHelper_BASE::getAccessibleIndexInParent( ); + } + else + { + if ( GetWindow() ) + { + Window* pParent = GetWindow()->GetAccessibleParentWindow(); + if ( pParent ) + { + /* + for ( USHORT n = pParent->GetAccessibleChildWindowCount(); n; ) + { + Window* pChild = pParent->GetAccessibleChildWindow( --n ); + if ( pChild == GetWindow() ) + { + nIndex = n; + break; + } + } + */ + // Iterate over all the parent's children and search for this object. + // this should be compatible with the code in SVX + uno::Reference< accessibility::XAccessible > xParentAcc( pParent->GetAccessible() ); + if ( xParentAcc.is() ) + { + uno::Reference< accessibility::XAccessibleContext > xParentContext ( xParentAcc->getAccessibleContext() ); + if ( xParentContext.is() ) + { + sal_Int32 nChildCount = xParentContext->getAccessibleChildCount(); + for ( sal_Int32 i=0; i<nChildCount; i++ ) + { + uno::Reference< accessibility::XAccessible > xChild( xParentContext->getAccessibleChild(i) ); + if ( xChild.is() ) + { + uno::Reference< accessibility::XAccessibleContext > xChildContext = xChild->getAccessibleContext(); + if ( xChildContext == (accessibility::XAccessibleContext*) this ) + { + nIndex = i; + break; + } + } + } + } + } + } + } + } + return nIndex; +} + +sal_Int16 VCLXAccessibleComponent::getAccessibleRole( ) throw (uno::RuntimeException) +{ + OExternalLockGuard aGuard( this ); + + sal_Int16 nRole = 0; + + if ( GetWindow() ) + nRole = GetWindow()->GetAccessibleRole(); + + return nRole; +} + +::rtl::OUString VCLXAccessibleComponent::getAccessibleDescription( ) throw (uno::RuntimeException) +{ + OExternalLockGuard aGuard( this ); + + ::rtl::OUString aDescription; + + if ( GetWindow() ) + aDescription = GetWindow()->GetAccessibleDescription(); + + return aDescription; +} + +::rtl::OUString VCLXAccessibleComponent::getAccessibleName( ) throw (uno::RuntimeException) +{ + OExternalLockGuard aGuard( this ); + + ::rtl::OUString aName; + if ( GetWindow() ) + { + aName = GetWindow()->GetAccessibleName(); +#if OSL_DEBUG_LEVEL > 1 + aName += String( RTL_CONSTASCII_USTRINGPARAM( " (Type = " ) ); + aName += String::CreateFromInt32( GetWindow()->GetType() ); + aName += String( RTL_CONSTASCII_USTRINGPARAM( ")" ) ); +#endif + } + return aName; +} + +uno::Reference< accessibility::XAccessibleRelationSet > VCLXAccessibleComponent::getAccessibleRelationSet( ) throw (uno::RuntimeException) +{ + OExternalLockGuard aGuard( this ); + + utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper; + uno::Reference< accessibility::XAccessibleRelationSet > xSet = pRelationSetHelper; + FillAccessibleRelationSet( *pRelationSetHelper ); + return xSet; +} + +uno::Reference< accessibility::XAccessibleStateSet > VCLXAccessibleComponent::getAccessibleStateSet( ) throw (uno::RuntimeException) +{ + OExternalLockGuard aGuard( this ); + + utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper; + uno::Reference< accessibility::XAccessibleStateSet > xSet = pStateSetHelper; + FillAccessibleStateSet( *pStateSetHelper ); + return xSet; +} + +lang::Locale VCLXAccessibleComponent::getLocale() throw (accessibility::IllegalAccessibleComponentStateException, uno::RuntimeException) +{ + OExternalLockGuard aGuard( this ); + + return Application::GetSettings().GetLocale(); +} + +uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getAccessibleAtPoint( const awt::Point& rPoint ) throw (uno::RuntimeException) +{ + OExternalLockGuard aGuard( this ); + + uno::Reference< accessibility::XAccessible > xChild; + for ( sal_uInt32 i = 0, nCount = getAccessibleChildCount(); i < nCount; ++i ) + { + uno::Reference< accessibility::XAccessible > xAcc = getAccessibleChild( i ); + if ( xAcc.is() ) + { + uno::Reference< accessibility::XAccessibleComponent > xComp( xAcc->getAccessibleContext(), uno::UNO_QUERY ); + if ( xComp.is() ) + { + Rectangle aRect = VCLRectangle( xComp->getBounds() ); + Point aPos = VCLPoint( rPoint ); + if ( aRect.IsInside( aPos ) ) + { + xChild = xAcc; + break; + } + } + } + } + + return xChild; +} + +// accessibility::XAccessibleComponent +awt::Rectangle VCLXAccessibleComponent::implGetBounds() throw (uno::RuntimeException) +{ + awt::Rectangle aBounds ( 0, 0, 0, 0 ); + + Window* pWindow = GetWindow(); + if ( pWindow ) + { + Rectangle aRect = pWindow->GetWindowExtentsRelative( NULL ); + aBounds = AWTRectangle( aRect ); + Window* pParent = pWindow->GetAccessibleParentWindow(); + if ( pParent ) + { + Rectangle aParentRect = pParent->GetWindowExtentsRelative( NULL ); + awt::Point aParentScreenLoc = AWTPoint( aParentRect.TopLeft() ); + aBounds.X -= aParentScreenLoc.X; + aBounds.Y -= aParentScreenLoc.Y; + } + } + + uno::Reference< accessibility::XAccessible > xParent( implGetForeignControlledParent() ); + if ( xParent.is() ) + { // hmm, we can't rely on our VCL coordinates, as in the Accessibility Hierarchy, somebody gave + // us a parent which is different from our VCL parent + // (actually, we did not check if it's really different ...) + + // the screen location of the foreign parent + uno::Reference< accessibility::XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), uno::UNO_QUERY ); + DBG_ASSERT( xParentComponent.is(), "VCLXAccessibleComponent::implGetBounds: invalid (foreign) parent component!" ); + + awt::Point aScreenLocForeign( 0, 0 ); + if ( xParentComponent.is() ) + aScreenLocForeign = xParentComponent->getLocationOnScreen(); + + // the screen location of the VCL parent + xParent = getVclParent(); + if ( xParent.is() ) + xParentComponent = xParentComponent.query( xParent->getAccessibleContext() ); + + awt::Point aScreenLocVCL( 0, 0 ); + if ( xParentComponent.is() ) + aScreenLocVCL = xParentComponent->getLocationOnScreen(); + + // the difference between them + awt::Size aOffset( aScreenLocVCL.X - aScreenLocForeign.X, aScreenLocVCL.Y - aScreenLocForeign.Y ); + // move the bounds + aBounds.X += aOffset.Width; + aBounds.Y += aOffset.Height; + } + + return aBounds; +} + +awt::Point VCLXAccessibleComponent::getLocationOnScreen( ) throw (uno::RuntimeException) +{ + OExternalLockGuard aGuard( this ); + + awt::Point aPos; + if ( GetWindow() ) + { + Rectangle aRect = GetWindow()->GetWindowExtentsRelative( NULL ); + aPos.X = aRect.Left(); + aPos.Y = aRect.Top(); + } + + return aPos; +} + +void VCLXAccessibleComponent::grabFocus( ) throw (uno::RuntimeException) +{ + OExternalLockGuard aGuard( this ); + + uno::Reference< accessibility::XAccessibleStateSet > xStates = getAccessibleStateSet(); + if ( mxWindow.is() && xStates.is() && xStates->contains( accessibility::AccessibleStateType::FOCUSABLE ) ) + mxWindow->setFocus(); +} + +sal_Int32 SAL_CALL VCLXAccessibleComponent::getForeground( ) throw (uno::RuntimeException) +{ + OExternalLockGuard aGuard( this ); + + sal_Int32 nColor = 0; + Window* pWindow = GetWindow(); + if ( pWindow ) + { + if ( pWindow->IsControlForeground() ) + nColor = pWindow->GetControlForeground().GetColor(); + else + { + Font aFont; + if ( pWindow->IsControlFont() ) + aFont = pWindow->GetControlFont(); + else + aFont = pWindow->GetFont(); + nColor = aFont.GetColor().GetColor(); + } + } + + return nColor; +} + +sal_Int32 SAL_CALL VCLXAccessibleComponent::getBackground( ) throw (uno::RuntimeException) +{ + OExternalLockGuard aGuard( this ); + + sal_Int32 nColor = 0; + Window* pWindow = GetWindow(); + if ( pWindow ) + { + if ( pWindow->IsControlBackground() ) + nColor = pWindow->GetControlBackground().GetColor(); + else + nColor = pWindow->GetBackground().GetColor().GetColor(); + } + + return nColor; +} + +// XAccessibleExtendedComponent + +uno::Reference< awt::XFont > SAL_CALL VCLXAccessibleComponent::getFont( ) throw (uno::RuntimeException) +{ + OExternalLockGuard aGuard( this ); + + uno::Reference< awt::XFont > xFont; + Window* pWindow = GetWindow(); + if ( pWindow ) + { + uno::Reference< awt::XDevice > xDev( pWindow->GetComponentInterface(), uno::UNO_QUERY ); + if ( xDev.is() ) + { + Font aFont; + if ( pWindow->IsControlFont() ) + aFont = pWindow->GetControlFont(); + else + aFont = pWindow->GetFont(); + VCLXFont* pVCLXFont = new VCLXFont; + pVCLXFont->Init( *xDev.get(), aFont ); + xFont = pVCLXFont; + } + } + + return xFont; +} + +::rtl::OUString SAL_CALL VCLXAccessibleComponent::getTitledBorderText( ) throw (uno::RuntimeException) +{ + OExternalLockGuard aGuard( this ); + + ::rtl::OUString sRet; + if ( GetWindow() ) + sRet = GetWindow()->GetText(); + + return sRet; +} + +::rtl::OUString SAL_CALL VCLXAccessibleComponent::getToolTipText( ) throw (uno::RuntimeException) +{ + OExternalLockGuard aGuard( this ); + + ::rtl::OUString sRet; + if ( GetWindow() ) + sRet = GetWindow()->GetQuickHelpText(); + + return sRet; +} + diff --git a/toolkit/source/awt/vclxbitmap.cxx b/toolkit/source/awt/vclxbitmap.cxx new file mode 100644 index 000000000000..44d909674ca4 --- /dev/null +++ b/toolkit/source/awt/vclxbitmap.cxx @@ -0,0 +1,93 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + + +#include <toolkit/awt/vclxbitmap.hxx> +#include <toolkit/helper/macros.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <tools/stream.hxx> +#include <rtl/memory.h> +#include <rtl/uuid.h> + +// ---------------------------------------------------- +// class VCLXBitmap +// ---------------------------------------------------- + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXBitmap::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XBitmap*, this ), + SAL_STATIC_CAST( ::com::sun::star::awt::XDisplayBitmap*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XUnoTunnel*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ) ); + return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); +} + +// ::com::sun::star::lang::XUnoTunnel +IMPL_XUNOTUNNEL( VCLXBitmap ) + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXBitmap ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDisplayBitmap>* ) NULL ) +IMPL_XTYPEPROVIDER_END + + +// ::com::sun::star::awt::XBitmap +::com::sun::star::awt::Size VCLXBitmap::getSize() throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::awt::Size aSize( maBitmap.GetSizePixel().Width(), maBitmap.GetSizePixel().Height() ); + return aSize; +} + +::com::sun::star::uno::Sequence< sal_Int8 > VCLXBitmap::getDIB() throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + SvMemoryStream aMem; + aMem << maBitmap.GetBitmap(); + return ::com::sun::star::uno::Sequence<sal_Int8>( (sal_Int8*) aMem.GetData(), aMem.Tell() ); +} + +::com::sun::star::uno::Sequence< sal_Int8 > VCLXBitmap::getMaskDIB() throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + SvMemoryStream aMem; + aMem << maBitmap.GetMask(); + return ::com::sun::star::uno::Sequence<sal_Int8>( (sal_Int8*) aMem.GetData(), aMem.Tell() ); +} + + + + diff --git a/toolkit/source/awt/vclxbutton.cxx b/toolkit/source/awt/vclxbutton.cxx new file mode 100644 index 000000000000..3701eee409c3 --- /dev/null +++ b/toolkit/source/awt/vclxbutton.cxx @@ -0,0 +1,126 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vclxbutton.hxx" + +#include <layout/core/helper.hxx> +#include <com/sun/star/awt/ImagePosition.hpp> +#include <vcl/button.hxx> + +namespace css = com::sun::star; + +namespace layoutimpl +{ + +VCLXIconButton::VCLXIconButton( Window *p, rtl::OUString aDefaultLabel, char const *pGraphName ) + : VCLXButton() +{ + /* FIXME: before Window is set, setLabel, setProperty->setImage + * are silent no-ops. */ + p->SetComponentInterface( this ); + + setLabel( aDefaultLabel ); + setProperty( rtl::OUString::createFromAscii( "Graphic" ), + css::uno::Any( layoutimpl::loadGraphic( pGraphName ) ) ); + setProperty( rtl::OUString::createFromAscii( "ImagePosition" ), + css::uno::Any( css::awt::ImagePosition::LeftCenter ) ); + setProperty( rtl::OUString::createFromAscii( "Align" ), + css::uno::Any( (sal_Int16) 1 /* magic - center */ ) ); +} + +// FIXME: l10n/i18n of Reset & Apply + +VCLXOKButton::VCLXOKButton( Window *p ) + : VCLXIconButton( p, Button::GetStandardText( BUTTON_OK ), + "res/commandimagelist/sc_ok.png" ) +{ +} + +VCLXCancelButton::VCLXCancelButton( Window *p ) + : VCLXIconButton( p, Button::GetStandardText( BUTTON_CANCEL ), +// : VCLXIconButton( xButton, rtl::OUString::createFromAscii( "~Cancel " ), + "res/commandimagelist/sc_cancel.png" ) +{ +} + +VCLXYesButton::VCLXYesButton( Window *p ) + : VCLXIconButton( p, Button::GetStandardText( BUTTON_YES ), + "res/commandimagelist/sc_yes.png" ) +{ +} + +VCLXNoButton::VCLXNoButton( Window *p ) + : VCLXIconButton( p, Button::GetStandardText( BUTTON_NO ), + "res/commandimagelist/sc_no.png" ) +{ +} + +VCLXRetryButton::VCLXRetryButton( Window *p ) + : VCLXIconButton( p, Button::GetStandardText( BUTTON_RETRY ), + "res/commandimagelist/sc_retry.png" ) +{ +} + +VCLXIgnoreButton::VCLXIgnoreButton( Window *p ) + : VCLXIconButton( p, Button::GetStandardText( BUTTON_IGNORE ), + "res/commandimagelist/sc_ignore.png" ) +{ +} + +VCLXResetButton::VCLXResetButton( Window *p ) + : VCLXIconButton( p, rtl::OUString::createFromAscii( "~Reset " ), + "res/commandimagelist/sc_reset.png" ) +{ +} + +VCLXApplyButton::VCLXApplyButton( Window *p ) + : VCLXIconButton( p, rtl::OUString::createFromAscii( "Apply" ), + "res/commandimagelist/sc_apply.png" ) +{ +} + +VCLXHelpButton::VCLXHelpButton( Window *p ) + : VCLXIconButton( p, Button::GetStandardText( BUTTON_HELP ), + "res/commandimagelist/sc_help.png" ) +{ +} + +VCLXMoreButton::VCLXMoreButton( Window *p ) + : VCLXIconButton( p, Button::GetStandardText( BUTTON_MORE ), +// : VCLXIconButton( p, rtl::OUString::createFromAscii( "More " ), + "res/commandimagelist/sc_more.png" ) +{ +} + +VCLXAdvancedButton::VCLXAdvancedButton( Window *p ) +// : VCLXIconButton( p, Button::GetStandardText( BUTTON_ADVANCED ), + : VCLXIconButton( p, rtl::OUString::createFromAscii( "Advanced " ), + "res/commandimagelist/sc_advanced.png" ) +{ +} + +} // namespace layoutimpl diff --git a/toolkit/source/awt/vclxbutton.hxx b/toolkit/source/awt/vclxbutton.hxx new file mode 100644 index 000000000000..5ec29321cb4f --- /dev/null +++ b/toolkit/source/awt/vclxbutton.hxx @@ -0,0 +1,114 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_AWT_VCLXBUTTON_HXX +#define LAYOUT_AWT_VCLXBUTTON_HXX + +#include <toolkit/awt/vclxwindows.hxx> + +/* Replacements for broken toolkit/ impls. of ok, cancel, help button, etc. */ + +namespace layoutimpl +{ + +class VCLXIconButton : public VCLXButton +{ +public: + VCLXIconButton( Window* p, rtl::OUString aDefaultLabel, const char *pGraphName ); + void Show (); +}; + +class VCLXOKButton : public VCLXIconButton +{ +public: + VCLXOKButton( Window *p ); +}; + +class VCLXCancelButton : public VCLXIconButton +{ +public: + VCLXCancelButton( Window *p ); +}; + +class VCLXYesButton : public VCLXIconButton +{ +public: + VCLXYesButton( Window *p ); +}; + +class VCLXNoButton : public VCLXIconButton +{ +public: + VCLXNoButton( Window *p ); +}; + +class VCLXRetryButton : public VCLXIconButton +{ +public: + VCLXRetryButton( Window *p ); +}; + +class VCLXIgnoreButton : public VCLXIconButton +{ +public: + VCLXIgnoreButton( Window *p ); +}; + +class VCLXResetButton : public VCLXIconButton +{ +public: + VCLXResetButton( Window *p ); +}; + +class VCLXApplyButton : public VCLXIconButton +{ +public: + VCLXApplyButton( Window *p ); +}; + +class VCLXHelpButton : public VCLXIconButton +{ +public: + VCLXHelpButton( Window *p ); +}; + +// TODO. Reuse vcl/Morebutton, or make AdvancedButton reuse me? +class VCLXMoreButton : public VCLXIconButton +{ +public: + VCLXMoreButton( Window *p ); +}; + +class VCLXAdvancedButton : public VCLXIconButton +{ +public: + VCLXAdvancedButton( Window *p ); +}; + +} // namespace layoutimpl + +#endif // LAYOUT_AWT_VCLXBUTTON_HXX diff --git a/toolkit/source/awt/vclxcontainer.cxx b/toolkit/source/awt/vclxcontainer.cxx new file mode 100644 index 000000000000..d86b3bbb5591 --- /dev/null +++ b/toolkit/source/awt/vclxcontainer.cxx @@ -0,0 +1,239 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + + +#include <toolkit/awt/vclxcontainer.hxx> +#include <toolkit/helper/macros.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <rtl/memory.h> +#include <rtl/uuid.h> + +#include <vcl/window.hxx> +#include <tools/debug.hxx> + +// ---------------------------------------------------- +// class VCLXContainer +// ---------------------------------------------------- + +void VCLXContainer::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + VCLXWindow::ImplGetPropertyIds( rIds ); +} + +VCLXContainer::VCLXContainer() +{ +} + +VCLXContainer::~VCLXContainer() +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXContainer::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XVclContainer*, this ), + SAL_STATIC_CAST( ::com::sun::star::awt::XVclContainerPeer*, this ) ); + return (aRet.hasValue() ? aRet : VCLXWindow::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXContainer ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclContainer>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclContainerPeer>* ) NULL ), + VCLXWindow::getTypes() +IMPL_XTYPEPROVIDER_END + + +// ::com::sun::star::awt::XVclContainer +void VCLXContainer::addVclContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclContainerListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + GetContainerListeners().addInterface( rxListener ); +} + +void VCLXContainer::removeVclContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclContainerListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + GetContainerListeners().removeInterface( rxListener ); +} + +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > > VCLXContainer::getWindows( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + // Bei allen Childs das Container-Interface abfragen... + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > > aSeq; + Window* pWindow = GetWindow(); + if ( pWindow ) + { + sal_uInt16 nChilds = pWindow->GetChildCount(); + if ( nChilds ) + { + aSeq = ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > >( nChilds ); + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > * pChildRefs = aSeq.getArray(); + for ( sal_uInt16 n = 0; n < nChilds; n++ ) + { + Window* pChild = pWindow->GetChild( n ); + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xWP = pChild->GetComponentInterface( sal_True ); + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xW( xWP, ::com::sun::star::uno::UNO_QUERY ); + pChildRefs[n] = xW; + } + } + } + return aSeq; +} + + +// ::com::sun::star::awt::XVclContainerPeer +void VCLXContainer::enableDialogControl( sal_Bool bEnable ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if ( pWindow ) + { + WinBits nStyle = pWindow->GetStyle(); + if ( bEnable ) + nStyle |= WB_DIALOGCONTROL; + else + nStyle &= (~WB_DIALOGCONTROL); + pWindow->SetStyle( nStyle ); + } +} + +void VCLXContainer::setTabOrder( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > >& Components, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Tabs, sal_Bool bGroupControl ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + sal_uInt32 nCount = Components.getLength(); + DBG_ASSERT( nCount == (sal_uInt32)Tabs.getLength(), "setTabOrder: TabCount != ComponentCount" ); + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > * pComps = Components.getConstArray(); + const ::com::sun::star::uno::Any* pTabs = Tabs.getConstArray(); + + Window* pPrevWin = NULL; + for ( sal_uInt32 n = 0; n < nCount; n++ ) + { + // ::com::sun::star::style::TabStop + Window* pWin = VCLUnoHelper::GetWindow( pComps[n] ); + // NULL kann vorkommen, wenn die ::com::sun::star::uno::Sequence vom TabController kommt und eine Peer fehlt! + if ( pWin ) + { + // Reihenfolge der Fenster vor der Manipulation des Styles, + // weil z.B. der RadioButton in StateChanged das PREV-Window beruecksichtigt. + if ( pPrevWin ) + pWin->SetZOrder( pPrevWin, WINDOW_ZORDER_BEHIND ); + + WinBits nStyle = pWin->GetStyle(); + nStyle &= ~(WB_TABSTOP|WB_NOTABSTOP|WB_GROUP); + if ( pTabs[n].getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_BOOLEAN ) + { + sal_Bool bTab = false; + pTabs[n] >>= bTab; + nStyle |= ( bTab ? WB_TABSTOP : WB_NOTABSTOP ); + } + pWin->SetStyle( nStyle ); + + if ( bGroupControl ) + { + if ( n == 0 ) + pWin->SetDialogControlStart( sal_True ); + else + pWin->SetDialogControlStart( sal_False ); + } + + pPrevWin = pWin; + } + } +} + +void VCLXContainer::setGroup( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > >& Components ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + sal_uInt32 nCount = Components.getLength(); + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > * pComps = Components.getConstArray(); + + Window* pPrevWin = NULL; + Window* pPrevRadio = NULL; + for ( sal_uInt32 n = 0; n < nCount; n++ ) + { + Window* pWin = VCLUnoHelper::GetWindow( pComps[n] ); + if ( pWin ) + { + Window* pSortBehind = pPrevWin; + // #57096# Alle Radios hintereinander sortieren... + sal_Bool bNewPrevWin = sal_True; + if ( pWin->GetType() == WINDOW_RADIOBUTTON ) + { + if ( pPrevRadio ) + { + bNewPrevWin = ( pPrevWin == pPrevRadio ); // Radio-Button wurde vor das PreWin sortiert.... + pSortBehind = pPrevRadio; + } + pPrevRadio = pWin; + } + + // Z-Order + if ( pSortBehind ) + pWin->SetZOrder( pSortBehind, WINDOW_ZORDER_BEHIND ); + + WinBits nStyle = pWin->GetStyle(); + if ( n == 0 ) + nStyle |= WB_GROUP; + else + nStyle &= (~WB_GROUP); + pWin->SetStyle( nStyle ); + + // Ein WB_GROUP hinter die Gruppe, falls keine Gruppe mehr folgt. + if ( n == ( nCount - 1 ) ) + { + Window* pBehindLast = pWin->GetWindow( WINDOW_NEXT ); + if ( pBehindLast ) + { + WinBits nLastStyle = pBehindLast->GetStyle(); + nLastStyle |= WB_GROUP; + pBehindLast->SetStyle( nLastStyle ); + } + } + + if ( bNewPrevWin ) + pPrevWin = pWin; + } + } +} + + + + + diff --git a/toolkit/source/awt/vclxdevice.cxx b/toolkit/source/awt/vclxdevice.cxx new file mode 100644 index 000000000000..310f01a97679 --- /dev/null +++ b/toolkit/source/awt/vclxdevice.cxx @@ -0,0 +1,382 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <com/sun/star/awt/DeviceCapability.hpp> + +#include <com/sun/star/util/MeasureUnit.hpp> + +#include <toolkit/awt/vclxdevice.hxx> +#include <toolkit/awt/vclxfont.hxx> +#include <toolkit/awt/vclxbitmap.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <toolkit/helper/macros.hxx> +#include <cppuhelper/typeprovider.hxx> + +#include <rtl/memory.h> +#include <rtl/uuid.h> + +#include <vcl/svapp.hxx> +#include <vcl/outdev.hxx> +#include <vcl/window.hxx> +#include <vcl/print.hxx> +#include <vcl/virdev.hxx> +#include <vcl/bitmapex.hxx> +#include <vcl/font.hxx> + +// ---------------------------------------------------- +// class VCLXDevice +// ---------------------------------------------------- +VCLXDevice::VCLXDevice() : mrMutex( Application::GetSolarMutex() ) +{ + mpOutputDevice = NULL; + nFlags = 0; +} + +VCLXDevice::~VCLXDevice() +{ +// Was thought for #88347#, but didn't help, because the interface will not be released +// But would be a good idea anyway, check after 6.0, it's a little bit dangerous now +// if( mpOutputDevice && IsCreatedWithToolkit() ) +// { +// delete mpOutputDevice; +// } +} + +void VCLXDevice::DestroyOutputDevice() +{ + delete mpOutputDevice; + mpOutputDevice = NULL; +} + +void VCLXDevice::SetCreatedWithToolkit( sal_Bool bCreatedWithToolkit ) +{ + if ( bCreatedWithToolkit ) + nFlags |= FLAGS_CREATEDWITHTOOLKIT; + else + nFlags &= ~FLAGS_CREATEDWITHTOOLKIT; +} + +sal_Bool VCLXDevice::IsCreatedWithToolkit() const +{ + return ( nFlags & FLAGS_CREATEDWITHTOOLKIT ) != 0; +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXDevice::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XDevice*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XUnoTunnel*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ), + SAL_STATIC_CAST( ::com::sun::star::awt::XUnitConversion*, this ) ); + return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); +} + +// ::com::sun::star::lang::XUnoTunnel +IMPL_XUNOTUNNEL( VCLXDevice ) + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXDevice ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XUnitConversion>* ) NULL ) +IMPL_XTYPEPROVIDER_END + + +// ::com::sun::star::awt::XDevice, +::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics > VCLXDevice::createGraphics( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics > xRef; + + if ( mpOutputDevice ) + xRef = mpOutputDevice->CreateUnoGraphics(); + + return xRef; +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > VCLXDevice::createDevice( sal_Int32 nWidth, sal_Int32 nHeight ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > xRef; + if ( GetOutputDevice() ) + { + VCLXVirtualDevice* pVDev = new VCLXVirtualDevice; + VirtualDevice* pVclVDev = new VirtualDevice( *GetOutputDevice() ); + pVclVDev->SetOutputSizePixel( Size( nWidth, nHeight ) ); + pVDev->SetVirtualDevice( pVclVDev ); + xRef = pVDev; + } + return xRef; +} + +::com::sun::star::awt::DeviceInfo VCLXDevice::getInfo() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::awt::DeviceInfo aInfo; + + if( mpOutputDevice ) + { + Size aDevSz; + OutDevType eDevType = mpOutputDevice->GetOutDevType(); + if ( eDevType == OUTDEV_WINDOW ) + { + aDevSz = ((Window*)mpOutputDevice)->GetSizePixel(); + ((Window*)mpOutputDevice)->GetBorder( aInfo.LeftInset, aInfo.TopInset, aInfo.RightInset, aInfo.BottomInset ); + } + else if ( eDevType == OUTDEV_PRINTER ) + { + aDevSz = ((Printer*)mpOutputDevice)->GetPaperSizePixel(); + Size aOutSz = mpOutputDevice->GetOutputSizePixel(); + Point aOffset = ((Printer*)mpOutputDevice)->GetPageOffset(); + aInfo.LeftInset = aOffset.X(); + aInfo.TopInset = aOffset.Y(); + aInfo.RightInset = aDevSz.Width() - aOutSz.Width() - aOffset.X(); + aInfo.BottomInset = aDevSz.Height() - aOutSz.Height() - aOffset.Y(); + } + else // VirtualDevice + { + aDevSz = mpOutputDevice->GetOutputSizePixel(); + aInfo.LeftInset = 0; + aInfo.TopInset = 0; + aInfo.RightInset = 0; + aInfo.BottomInset = 0; + } + + aInfo.Width = aDevSz.Width(); + aInfo.Height = aDevSz.Height(); + + Size aTmpSz = mpOutputDevice->LogicToPixel( Size( 1000, 1000 ), MapMode( MAP_CM ) ); + aInfo.PixelPerMeterX = aTmpSz.Width()/10; + aInfo.PixelPerMeterY = aTmpSz.Height()/10; + + aInfo.BitsPerPixel = mpOutputDevice->GetBitCount(); + + aInfo.Capabilities = 0; + if ( mpOutputDevice->GetOutDevType() != OUTDEV_PRINTER ) + aInfo.Capabilities = ::com::sun::star::awt::DeviceCapability::RASTEROPERATIONS|::com::sun::star::awt::DeviceCapability::GETBITS; + } + + return aInfo; +} + +::com::sun::star::uno::Sequence< ::com::sun::star::awt::FontDescriptor > VCLXDevice::getFontDescriptors( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Sequence< ::com::sun::star::awt::FontDescriptor> aFonts; + if( mpOutputDevice ) + { + int nFonts = mpOutputDevice->GetDevFontCount(); + if ( nFonts ) + { + aFonts = ::com::sun::star::uno::Sequence< ::com::sun::star::awt::FontDescriptor>( nFonts ); + ::com::sun::star::awt::FontDescriptor* pFonts = aFonts.getArray(); + for ( int n = 0; n < nFonts; n++ ) + pFonts[n] = VCLUnoHelper::CreateFontDescriptor( mpOutputDevice->GetDevFont( n ) ); + } + } + return aFonts; +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XFont > VCLXDevice::getFont( const ::com::sun::star::awt::FontDescriptor& rDescriptor ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFont > xRef; + if( mpOutputDevice ) + { + VCLXFont* pMetric = new VCLXFont; + pMetric->Init( *this, VCLUnoHelper::CreateFont( rDescriptor, mpOutputDevice->GetFont() ) ); + xRef = pMetric; + } + return xRef; +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap > VCLXDevice::createBitmap( sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap > xBmp; + if( mpOutputDevice ) + { + Bitmap aBmp = mpOutputDevice->GetBitmap( Point( nX, nY ), Size( nWidth, nHeight ) ); + + VCLXBitmap* pBmp = new VCLXBitmap; + pBmp->SetBitmap( BitmapEx( aBmp ) ); + xBmp = pBmp; + } + return xBmp; +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XDisplayBitmap > VCLXDevice::createDisplayBitmap( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap >& rxBitmap ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + BitmapEx aBmp = VCLUnoHelper::GetBitmap( rxBitmap ); + VCLXBitmap* pBmp = new VCLXBitmap; + pBmp->SetBitmap( aBmp ); + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDisplayBitmap > xDBmp = pBmp; + return xDBmp; +} + + +VCLXVirtualDevice::~VCLXVirtualDevice() +{ + ::vos::OGuard aGuard( GetMutex() ); + + DestroyOutputDevice(); +} + + +// ----------------------------------------------------------------------------- +// ::com::sun::star::awt::XTextConstraints +// ----------------------------------------------------------------------------- +// ::sal_Int32 SAL_CALL VCLXDevice::getTextWidth( const ::rtl::OUString& Text ) throw (::com::sun::star::uno::RuntimeException) +// { +// ::vos::OGuard aGuard( GetMutex() ); +// if (Text.getLength() == 0) +// { +// return 0; +// } +// +// return 1; +// } +// +// ::sal_Int32 SAL_CALL VCLXDevice::getTextHeight( ) throw (::com::sun::star::uno::RuntimeException) +// { +// ::vos::OGuard aGuard( GetMutex() ); +// return 1; +// } + + +// ----------------------------------------------------------------------------- +// Interface implementation of ::com::sun::star::awt::XUnitConversion +// ----------------------------------------------------------------------------- + +::com::sun::star::awt::Point SAL_CALL VCLXDevice::convertPointToLogic( const ::com::sun::star::awt::Point& aPoint, ::sal_Int16 TargetUnit ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) +{ + (void)aPoint; + ::vos::OGuard aGuard( GetMutex() ); + if (TargetUnit == com::sun::star::util::MeasureUnit::PERCENT ) + { + // percentage not allowed here + throw ::com::sun::star::lang::IllegalArgumentException(); + } + + ::com::sun::star::awt::Point aAWTPoint(0,0); + // X,Y + + if( mpOutputDevice ) + { + MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit)); + ::Point aVCLPoint = VCLUnoHelper::ConvertToVCLPoint(aPoint); + ::Point aDevPoint = mpOutputDevice->PixelToLogic(aVCLPoint, aMode ); + aAWTPoint = VCLUnoHelper::ConvertToAWTPoint(aDevPoint); + } + + return aAWTPoint; +} + + +::com::sun::star::awt::Point SAL_CALL VCLXDevice::convertPointToPixel( const ::com::sun::star::awt::Point& aPoint, ::sal_Int16 SourceUnit ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) +{ + (void)aPoint; + ::vos::OGuard aGuard( GetMutex() ); + if (SourceUnit == com::sun::star::util::MeasureUnit::PERCENT || + SourceUnit == com::sun::star::util::MeasureUnit::PIXEL ) + { + // pixel or percentage not allowed here + throw ::com::sun::star::lang::IllegalArgumentException(); + } + + ::com::sun::star::awt::Point aAWTPoint(0,0); + + if( mpOutputDevice ) + { + MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit)); + ::Point aVCLPoint = VCLUnoHelper::ConvertToVCLPoint(aPoint); + ::Point aDevPoint = mpOutputDevice->LogicToPixel(aVCLPoint, aMode ); + aAWTPoint = VCLUnoHelper::ConvertToAWTPoint(aDevPoint); + } + + return aAWTPoint; +} + +::com::sun::star::awt::Size SAL_CALL VCLXDevice::convertSizeToLogic( const ::com::sun::star::awt::Size& aSize, ::sal_Int16 TargetUnit ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) +{ + (void)aSize; + ::vos::OGuard aGuard( GetMutex() ); + if (TargetUnit == com::sun::star::util::MeasureUnit::PERCENT) + { + // percentage not allowed here + throw ::com::sun::star::lang::IllegalArgumentException(); + } + + ::com::sun::star::awt::Size aAWTSize(0,0); + // Width, Height + + + if( mpOutputDevice ) + { + MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(TargetUnit)); + ::Size aVCLSize = VCLUnoHelper::ConvertToVCLSize(aSize); + ::Size aDevSz = mpOutputDevice->PixelToLogic(aVCLSize, aMode ); + aAWTSize = VCLUnoHelper::ConvertToAWTSize(aDevSz); + } + + return aAWTSize; +} + +::com::sun::star::awt::Size SAL_CALL VCLXDevice::convertSizeToPixel( const ::com::sun::star::awt::Size& aSize, ::sal_Int16 SourceUnit ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) +{ + (void)aSize; + ::vos::OGuard aGuard( GetMutex() ); + if (SourceUnit == com::sun::star::util::MeasureUnit::PERCENT || + SourceUnit == com::sun::star::util::MeasureUnit::PIXEL) + { + // pixel or percentage not allowed here + throw ::com::sun::star::lang::IllegalArgumentException(); + } + + ::com::sun::star::awt::Size aAWTSize(0,0); + // Width, Height + if( mpOutputDevice ) + { + MapMode aMode(VCLUnoHelper::ConvertToMapModeUnit(SourceUnit)); + ::Size aVCLSize = VCLUnoHelper::ConvertToVCLSize(aSize); + ::Size aDevSz = mpOutputDevice->LogicToPixel(aVCLSize, aMode ); + aAWTSize = VCLUnoHelper::ConvertToAWTSize(aDevSz); + } + + return aAWTSize; +} + diff --git a/toolkit/source/awt/vclxdialog.cxx b/toolkit/source/awt/vclxdialog.cxx new file mode 100644 index 000000000000..43861c3ed347 --- /dev/null +++ b/toolkit/source/awt/vclxdialog.cxx @@ -0,0 +1,279 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vclxdialog.hxx" + +#include <com/sun/star/awt/PosSize.hpp> +#include <com/sun/star/awt/SystemDependentXWindow.hpp> +#include <com/sun/star/lang/SystemDependent.hpp> + +#include <cppuhelper/typeprovider.hxx> + +#include <toolkit/awt/vclxmenu.hxx> +#include <toolkit/helper/macros.hxx> +#include <toolkit/helper/property.hxx> + +#ifdef WNT +#include <tools/prewin.h> +#include <windows.h> +#include <tools/postwin.h> +#elif defined ( QUARTZ ) +#include "premac.h" +#include <Cocoa/Cocoa.h> +#include "postmac.h" +#endif + +#include <vcl/dialog.hxx> +#include <vcl/msgbox.hxx> +#include <vcl/svapp.hxx> +#include <vcl/sysdata.hxx> +#include <vcl/wrkwin.hxx> + +#include "forward.hxx" + +namespace layoutimpl +{ + +DBG_NAME( VCLXDialog ) + +VCLXDialog::VCLXDialog() + : VCLXWindow() + , VCLXTopWindow_Base( true ) + , VCLXDialog_Base() + , Bin() + , bRealized( false ) + , bResizeSafeguard( false ) +{ + DBG_CTOR( VCLXDialog, NULL ); + +/* mxLayoutUnit = uno::Reference< awt::XLayoutUnit >( new LayoutUnit() ); + assert(mxLayoutUnit.is());*/ +} + +VCLXDialog::~VCLXDialog() +{ + DBG_DTOR( VCLXDialog, NULL ); +} + +vos::IMutex& VCLXDialog::GetMutexImpl() +{ + return VCLXWindow::GetMutex(); +} + +Window* VCLXDialog::GetWindowImpl() +{ + return VCLXWindow::GetWindow(); +} + +::cppu::OInterfaceContainerHelper& VCLXDialog::GetTopWindowListenersImpl() +{ + return GetTopWindowListeners(); +} + +IMPLEMENT_2_FORWARD_XINTERFACE2( VCLXDialog, VCLXWindow, Bin, VCLXDialog_Base ); + +IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXDialog, VCLXWindow, VCLXDialog_Base ); + +void SAL_CALL VCLXDialog::dispose() throw(::com::sun::star::uno::RuntimeException) +{ + { + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::lang::EventObject aDisposeEvent; + aDisposeEvent.Source = W3K_EXPLICIT_CAST (*this); +// maTabListeners.disposeAndClear( aDisposeEvent ); + } + + VCLXWindow::dispose(); +} + +void VCLXDialog::resizedCb() +{ + queueResize(); +} + +void SAL_CALL VCLXDialog::allocateArea( const css::awt::Rectangle &rArea ) + throw (css::uno::RuntimeException) +{ + ::com::sun::star::awt::Size reqSize = Bin::getMinimumSize(); + reqSize.Height = getHeightForWidth( rArea.Width ); + + if ( !bRealized ) + { + setPosSize( 0, 0, reqSize.Width, reqSize.Height, ::com::sun::star::awt::PosSize::SIZE ); + bRealized = true; + setVisible( true ); + } + else + { + ::com::sun::star::awt::Size curSize = getSize(); + if ( reqSize.Width > curSize.Width ) + setPosSize( 0, 0, reqSize.Width, 0, ::com::sun::star::awt::PosSize::WIDTH ); + if ( reqSize.Height > curSize.Height ) + setPosSize( 0, 0, 0, reqSize.Height, ::com::sun::star::awt::PosSize::HEIGHT ); + } + + ::com::sun::star::awt::Size size = getSize(); + maAllocation.Width = size.Width; + maAllocation.Height = size.Height; + + Bin::allocateArea( maAllocation ); +} + +void VCLXDialog::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ) +{ + ::vos::OClearableGuard aGuard( GetMutex() ); + + switch ( _rVclWindowEvent.GetId() ) + { + case VCLEVENT_WINDOW_RESIZE: + resizedCb(); + default: + aGuard.clear(); + VCLXWindow::ProcessWindowEvent( _rVclWindowEvent ); + break; + } +} + +void SAL_CALL VCLXDialog::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any &Value ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + { +/* sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); + switch ( nPropertyId ) + { + default: +*/ + VCLXWindow::setProperty( PropertyName, Value ); +/* } +*/ + } +} + +::com::sun::star::uno::Any SAL_CALL VCLXDialog::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Any aReturn; + if ( GetWindow() ) + { +/* + sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); + switch ( nPropertyId ) + { + default: +*/ + aReturn = VCLXWindow::getProperty( PropertyName ); +/* + } +*/ + } + return aReturn; +} + +void VCLXDialog::setTitle( const ::rtl::OUString& Title ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if ( pWindow ) + pWindow->SetText( Title ); +} + +void VCLXDialog::setHelpId( sal_Int32 id ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if ( pWindow ) + pWindow->SetHelpId( id ); +} + +::rtl::OUString VCLXDialog::getTitle() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::rtl::OUString aTitle; + Window* pWindow = GetWindow(); + if ( pWindow ) + aTitle = pWindow->GetText(); + return aTitle; +} + +sal_Int16 VCLXDialog::execute() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + sal_Int16 nRet = 0; + if ( GetWindow() ) + { + Dialog* pDlg = (Dialog*) GetWindow(); + Window* pParent = pDlg->GetWindow( WINDOW_PARENTOVERLAP ); + Window* pOldParent = NULL; + if ( pParent && !pParent->IsReallyVisible() ) + { + pOldParent = pDlg->GetParent(); + Window* pFrame = pDlg->GetWindow( WINDOW_FRAME ); + if ( pFrame != pDlg ) + pDlg->SetParent( pFrame ); + } + nRet = pDlg->Execute(); + if ( pOldParent ) + pDlg->SetParent( pOldParent ); + } + return nRet; +} + +void VCLXDialog::endDialog( sal_Int32 nResult ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( nResult == BUTTONID_HELP ) + { + // UGH: c&p button.cxx + ::Window* pFocusWin = Application::GetFocusWindow(); + if ( !pFocusWin ) + pFocusWin = GetWindow(); + + HelpEvent aEvt( pFocusWin->GetPointerPosPixel(), HELPMODE_CONTEXT ); + pFocusWin->RequestHelp( aEvt ); + return; + } + + Dialog* pDlg = (Dialog*) GetWindow(); + if ( pDlg ) + pDlg->EndDialog( nResult ); +} + +void VCLXDialog::endExecute() throw(::com::sun::star::uno::RuntimeException) +{ + endDialog( 0 ); +} + +} // namespace layoutimpl diff --git a/toolkit/source/awt/vclxdialog.hxx b/toolkit/source/awt/vclxdialog.hxx new file mode 100644 index 000000000000..64b2c03f90d5 --- /dev/null +++ b/toolkit/source/awt/vclxdialog.hxx @@ -0,0 +1,107 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_AWT_VCLXDIALOG_HXX +#define LAYOUT_AWT_VCLXDIALOG_HXX + +#include <com/sun/star/awt/XDialog2.hpp> +#include <com/sun/star/awt/XSystemDependentWindowPeer.hpp> +#include <com/sun/star/awt/XTopWindow.hpp> +#include <comphelper/uno3.hxx> +#include <layout/core/bin.hxx> +#include <toolkit/awt/vclxtopwindow.hxx> + +namespace layoutimpl +{ + +typedef ::cppu::ImplHelper1 < ::com::sun::star::awt::XDialog2 > VCLXDialog_Base; + +class TOOLKIT_DLLPUBLIC VCLXDialog : public VCLXWindow + , public VCLXTopWindow_Base + , public VCLXDialog_Base + , public Bin +{ +private: + bool bRealized, bResizeSafeguard; + css::uno::Reference< css::awt::XLayoutUnit > mxLayoutUnit; + + VCLXDialog( const VCLXDialog& ); // never implemented + VCLXDialog& operator=( const VCLXDialog& ); // never implemented + +protected: + vos::IMutex& GetMutexImpl(); + Window* GetWindowImpl(); + ::cppu::OInterfaceContainerHelper& GetTopWindowListenersImpl(); + + ~VCLXDialog(); + + // XInterface + DECLARE_XINTERFACE() + + // XTypeProvider + DECLARE_XTYPEPROVIDER() + + // XComponent + void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException); + + // VclWindowPeer + virtual void SAL_CALL setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value ) throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException); + + // VCLXWindow + void ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ); + + // ::com::sun::star::awt::XDialog + void SAL_CALL setTitle( const ::rtl::OUString& Title ) throw(::com::sun::star::uno::RuntimeException); + ::rtl::OUString SAL_CALL getTitle() throw(::com::sun::star::uno::RuntimeException); + sal_Int16 SAL_CALL execute() throw(::com::sun::star::uno::RuntimeException); + void SAL_CALL endExecute() throw(::com::sun::star::uno::RuntimeException); + + // ::com::sun::star::awt::XLayoutContainer + virtual void SAL_CALL allocateArea( const css::awt::Rectangle &rArea ) + throw (css::uno::RuntimeException); + + void resizedCb(); + + static void ImplGetPropertyIds( std::list< sal_uInt16 > &/*aIds*/ ) + { + } + virtual void GetPropertyIds( std::list< sal_uInt16 > &aIds ) { return ImplGetPropertyIds( aIds ); } + + +public: + VCLXDialog(); + + // ::com::sun::star::awt::XDialog2 + void SAL_CALL endDialog( sal_Int32 nResult ) throw(::com::sun::star::uno::RuntimeException); + void SAL_CALL setHelpId( sal_Int32 id ) throw(::com::sun::star::uno::RuntimeException); + +}; + +} // namespace layoutimpl + +#endif /* LAYOUT_AWT_VCLXDIALOG_HXX */ diff --git a/toolkit/source/awt/vclxfixedline.cxx b/toolkit/source/awt/vclxfixedline.cxx new file mode 100644 index 000000000000..8c77a4f35e19 --- /dev/null +++ b/toolkit/source/awt/vclxfixedline.cxx @@ -0,0 +1,132 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vclxfixedline.hxx" + +#include <com/sun/star/awt/PosSize.hpp> +#include <toolkit/helper/property.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <tools/debug.hxx> +#include <vcl/fixed.hxx> + +#include "forward.hxx" + +namespace layoutimpl +{ + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star; + +DBG_NAME( VCLXFixedLine ) + +VCLXFixedLine::VCLXFixedLine() + : VCLXWindow() +{ + DBG_CTOR( VCLXFixedLine, NULL ); +} + +VCLXFixedLine::~VCLXFixedLine() +{ + DBG_DTOR( VCLXFixedLine, NULL ); +} + +IMPLEMENT_FORWARD_XTYPEPROVIDER1( VCLXFixedLine, VCLXWindow ); + +void SAL_CALL VCLXFixedLine::dispose() throw(RuntimeException) +{ + { + ::vos::OGuard aGuard( GetMutex() ); + + EventObject aDisposeEvent; + aDisposeEvent.Source = W3K_EXPLICIT_CAST (*this); + } + + VCLXWindow::dispose(); +} + +::com::sun::star::awt::Size SAL_CALL VCLXFixedLine::getMinimumSize() + throw(::com::sun::star::uno::RuntimeException) +{ + return awt::Size( 8, 8 ); +} + +void VCLXFixedLine::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ) +{ + ::vos::OClearableGuard aGuard( GetMutex() ); +/* + switch ( _rVclWindowEvent.GetId() ) + { + default: + aGuard.clear(); +*/ + VCLXWindow::ProcessWindowEvent( _rVclWindowEvent ); +/* + break; + } +*/ +} + +void SAL_CALL VCLXFixedLine::setProperty( const ::rtl::OUString& PropertyName, const Any &Value ) throw(RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + { +/* + sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); + switch ( nPropertyId ) + { + default: +*/ + VCLXWindow::setProperty( PropertyName, Value ); +// } + } +} + +Any SAL_CALL VCLXFixedLine::getProperty( const ::rtl::OUString& PropertyName ) throw(RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Any aReturn; + if ( GetWindow() ) + { +/* + sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); + switch ( nPropertyId ) + { + default: +*/ + aReturn = VCLXWindow::getProperty( PropertyName ); + // } + } + return aReturn; +} + +} // namespace layoutimpl diff --git a/toolkit/source/awt/vclxfixedline.hxx b/toolkit/source/awt/vclxfixedline.hxx new file mode 100644 index 000000000000..d7dfd76d961f --- /dev/null +++ b/toolkit/source/awt/vclxfixedline.hxx @@ -0,0 +1,75 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_AWT_VCLXFIXEDLINE_HXX +#define LAYOUT_AWT_VCLXFIXEDLINE_HXX + +#include <comphelper/uno3.hxx> +#include <toolkit/awt/vclxwindow.hxx> + +/* We just provide our own FixedLine, because default has no width... */ + +class FixedLine; + +namespace layoutimpl +{ + +class VCLXFixedLine :public VCLXWindow +{ +public: + VCLXFixedLine(); + +protected: + ~VCLXFixedLine(); + + // XInterface + // DECLARE_XINTERFACE() + + // XTypeProvider + DECLARE_XTYPEPROVIDER() + + // XComponent + void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException); + + virtual ::com::sun::star::awt::Size SAL_CALL getMinimumSize() + throw(::com::sun::star::uno::RuntimeException); + + // VclWindowPeer + virtual void SAL_CALL setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value ) throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException); + + // VCLXWindow + void ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ); + +private: + VCLXFixedLine( const VCLXFixedLine& ); // never implemented + VCLXFixedLine& operator=( const VCLXFixedLine& ); // never implemented +}; + +} // namespace layoutimpl + +#endif /* LAYOUT_AWT_VCLXFIXEDLINE_HXX */ diff --git a/toolkit/source/awt/vclxfont.cxx b/toolkit/source/awt/vclxfont.cxx new file mode 100644 index 000000000000..53175ec79d24 --- /dev/null +++ b/toolkit/source/awt/vclxfont.cxx @@ -0,0 +1,252 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + + +#include <toolkit/awt/vclxfont.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <toolkit/helper/macros.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <rtl/memory.h> +#include <rtl/uuid.h> +#include <rtl/ustring.h> + +#include <vcl/outdev.hxx> + +// ---------------------------------------------------- +// class VCLXFont +// ---------------------------------------------------- +VCLXFont::VCLXFont() +{ + mpFontMetric = NULL; +} + +VCLXFont::~VCLXFont() +{ + delete mpFontMetric; +} + +void VCLXFont::Init( ::com::sun::star::awt::XDevice& rxDev, const Font& rFont ) +{ + mxDevice = &rxDev; + + delete mpFontMetric; + mpFontMetric = NULL; + + maFont = rFont; +} + +BOOL VCLXFont::ImplAssertValidFontMetric() +{ + if ( !mpFontMetric && mxDevice.is() ) + { + OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice ); + if ( pOutDev ) + { + Font aOldFont = pOutDev->GetFont(); + pOutDev->SetFont( maFont ); + mpFontMetric = new FontMetric( pOutDev->GetFontMetric() ); + pOutDev->SetFont( aOldFont ); + } + } + return mpFontMetric ? TRUE : FALSE; +} + + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXFont::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XFont*, this ), + SAL_STATIC_CAST( ::com::sun::star::awt::XFont2*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XUnoTunnel*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ) ); + return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); +} + +// ::com::sun::star::lang::XUnoTunnel +IMPL_XUNOTUNNEL( VCLXFont ) + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXFont ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFont2>* ) NULL ) +IMPL_XTYPEPROVIDER_END + + +::com::sun::star::awt::FontDescriptor VCLXFont::getFontDescriptor( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return VCLUnoHelper::CreateFontDescriptor( maFont ); + +} + +::com::sun::star::awt::SimpleFontMetric VCLXFont::getFontMetric( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::awt::SimpleFontMetric aFM; + if ( ImplAssertValidFontMetric() ) + aFM = VCLUnoHelper::CreateFontMetric( *mpFontMetric ); + return aFM; +} + +sal_Int16 VCLXFont::getCharWidth( sal_Unicode c ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + sal_Int16 nRet = -1; + OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice ); + if ( pOutDev ) + { + Font aOldFont = pOutDev->GetFont(); + pOutDev->SetFont( maFont ); + + nRet = sal::static_int_cast< sal_Int16 >( + pOutDev->GetTextWidth( String(c) )); + + pOutDev->SetFont( aOldFont ); + } + return nRet; +} + +::com::sun::star::uno::Sequence< sal_Int16 > VCLXFont::getCharWidths( sal_Unicode nFirst, sal_Unicode nLast ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::uno::Sequence<sal_Int16> aSeq; + OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice ); + if ( pOutDev ) + { + Font aOldFont = pOutDev->GetFont(); + pOutDev->SetFont( maFont ); + + sal_Int16 nCount = nLast-nFirst + 1; + aSeq = ::com::sun::star::uno::Sequence<sal_Int16>( nCount ); + for ( USHORT n = 0; n < nCount; n++ ) + { + aSeq.getArray()[n] = sal::static_int_cast< sal_Int16 >( + pOutDev->GetTextWidth( + String(static_cast< sal_Unicode >(nFirst+n)) )); + } + + pOutDev->SetFont( aOldFont ); + } + return aSeq; +} + +sal_Int32 VCLXFont::getStringWidth( const ::rtl::OUString& str ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + sal_Int32 nRet = -1; + OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice ); + if ( pOutDev ) + { + Font aOldFont = pOutDev->GetFont(); + pOutDev->SetFont( maFont ); + nRet = pOutDev->GetTextWidth( str ); + pOutDev->SetFont( aOldFont ); + } + return nRet; +} + +sal_Int32 VCLXFont::getStringWidthArray( const ::rtl::OUString& str, ::com::sun::star::uno::Sequence< sal_Int32 >& rDXArray ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + sal_Int32 nRet = -1; + OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice ); + if ( pOutDev ) + { + Font aOldFont = pOutDev->GetFont(); + pOutDev->SetFont( maFont ); + rDXArray = ::com::sun::star::uno::Sequence<sal_Int32>( str.getLength() ); + nRet = pOutDev->GetTextArray( str, rDXArray.getArray() ); + pOutDev->SetFont( aOldFont ); + } + return nRet; +} + +void VCLXFont::getKernPairs( ::com::sun::star::uno::Sequence< sal_Unicode >& rnChars1, ::com::sun::star::uno::Sequence< sal_Unicode >& rnChars2, ::com::sun::star::uno::Sequence< sal_Int16 >& rnKerns ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice ); + if( pOutDev ) + { + Font aOldFont = pOutDev->GetFont(); + pOutDev->SetFont( maFont ); + + ULONG nPairs = pOutDev->GetKerningPairCount(); + if ( nPairs ) + { + KerningPair* pData = new KerningPair[ nPairs ]; + pOutDev->GetKerningPairs( nPairs, pData ); + + rnChars1 = ::com::sun::star::uno::Sequence<sal_Unicode>( nPairs ); + rnChars2 = ::com::sun::star::uno::Sequence<sal_Unicode>( nPairs ); + rnKerns = ::com::sun::star::uno::Sequence<sal_Int16>( nPairs ); + + sal_Unicode* pChars1 = rnChars1.getArray(); + sal_Unicode* pChars2 = rnChars2.getArray(); + sal_Int16* pKerns = rnKerns.getArray(); + + for ( ULONG n = 0; n < nPairs; n++ ) + { + pChars1[n] = pData[n].nChar1; + pChars2[n] = pData[n].nChar2; + pKerns[n] = sal::static_int_cast< sal_Int16 >(pData[n].nKern); + } + + + delete[] pData; + } + pOutDev->SetFont( aOldFont ); + } +} + +// ::com::sun::star::awt::XFont2 +sal_Bool VCLXFont::hasGlyphs( const ::rtl::OUString& aText ) + throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice ); + if ( pOutDev ) + { + String aStr( aText ); + if ( pOutDev->HasGlyphs( maFont, aStr, 0, aStr.Len() ) == STRING_LEN ) + { + return sal_True; + } + } + + return sal_False; +} diff --git a/toolkit/source/awt/vclxgraphics.cxx b/toolkit/source/awt/vclxgraphics.cxx new file mode 100644 index 000000000000..bfbdb531e8d2 --- /dev/null +++ b/toolkit/source/awt/vclxgraphics.cxx @@ -0,0 +1,478 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + +#include <toolkit/awt/vclxgraphics.hxx> +#include <toolkit/awt/vclxdevice.hxx> +#include <toolkit/helper/macros.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <rtl/memory.h> +#include <rtl/uuid.h> + +#include <vcl/svapp.hxx> +#include <vcl/outdev.hxx> +#include <vcl/gradient.hxx> +#include <tools/debug.hxx> + + +// ---------------------------------------------------- +// class VCLXGraphics +// ---------------------------------------------------- + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXGraphics::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XGraphics*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XUnoTunnel*, this ) ); + return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); +} + +// ::com::sun::star::lang::XUnoTunnel +IMPL_XUNOTUNNEL( VCLXGraphics ) + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXGraphics ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics>* ) NULL ) +IMPL_XTYPEPROVIDER_END + +VCLXGraphics::VCLXGraphics() : mrMutex( Application::GetSolarMutex() ) +{ + mpOutputDevice = NULL; + mpClipRegion = NULL; +} + +VCLXGraphics::~VCLXGraphics() +{ + List* pLst = mpOutputDevice ? mpOutputDevice->GetUnoGraphicsList() : NULL; + if ( pLst ) + pLst->Remove( this ); + + delete mpClipRegion; +} + +void VCLXGraphics::SetOutputDevice( OutputDevice* pOutDev ) +{ + mpOutputDevice = pOutDev; + mxDevice = NULL; +} + +void VCLXGraphics::Init( OutputDevice* pOutDev ) +{ + DBG_ASSERT( !mpOutputDevice, "VCLXGraphics::Init allready has pOutDev !" ); + mpOutputDevice = pOutDev; + + maFont = mpOutputDevice->GetFont(); + maTextColor = COL_BLACK; + maTextFillColor = COL_TRANSPARENT; + maLineColor = COL_BLACK; + maFillColor = COL_WHITE; + meRasterOp = ROP_OVERPAINT; + mpClipRegion = NULL; + + // Register at OutputDevice + List* pLst = mpOutputDevice->GetUnoGraphicsList(); + if ( !pLst ) + pLst = mpOutputDevice->CreateUnoGraphicsList(); + pLst->Insert( this, LIST_APPEND ); +} + +void VCLXGraphics::InitOutputDevice( sal_uInt16 nFlags ) +{ + if(mpOutputDevice) + { + NAMESPACE_VOS(OGuard) aVclGuard( Application::GetSolarMutex() ); + + if ( nFlags & INITOUTDEV_FONT ) + { + mpOutputDevice->SetFont( maFont ); + mpOutputDevice->SetTextColor( maTextColor ); + mpOutputDevice->SetTextFillColor( maTextFillColor ); + } + + if ( nFlags & INITOUTDEV_COLORS ) + { + mpOutputDevice->SetLineColor( maLineColor ); + mpOutputDevice->SetFillColor( maFillColor ); + } + + if ( nFlags & INITOUTDEV_RASTEROP ) + { + mpOutputDevice->SetRasterOp( meRasterOp ); + } + + if ( nFlags & INITOUTDEV_CLIPREGION ) + { + if( mpClipRegion ) + mpOutputDevice->SetClipRegion( *mpClipRegion ); + else + mpOutputDevice->SetClipRegion(); + } + } +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > VCLXGraphics::getDevice() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if( !mxDevice.is() && mpOutputDevice ) + { + VCLXDevice* pDev = new VCLXDevice; + pDev->SetOutputDevice( mpOutputDevice ); + mxDevice = pDev; + } + return mxDevice; +} + +::com::sun::star::awt::SimpleFontMetric VCLXGraphics::getFontMetric() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::awt::SimpleFontMetric aM; + if( mpOutputDevice ) + { + mpOutputDevice->SetFont( maFont ); + aM = VCLUnoHelper::CreateFontMetric( mpOutputDevice->GetFontMetric() ); + } + return aM; +} + +void VCLXGraphics::setFont( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFont >& rxFont ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + maFont = VCLUnoHelper::CreateFont( rxFont ); +} + +void VCLXGraphics::selectFont( const ::com::sun::star::awt::FontDescriptor& rDescription ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + maFont = VCLUnoHelper::CreateFont( rDescription, Font() ); +} + +void VCLXGraphics::setTextColor( sal_Int32 nColor ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + maTextColor = Color( (sal_uInt32)nColor ); +} + +void VCLXGraphics::setTextFillColor( sal_Int32 nColor ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + maTextFillColor = Color( (sal_uInt32)nColor ); +} + +void VCLXGraphics::setLineColor( sal_Int32 nColor ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + maLineColor = Color( (sal_uInt32)nColor ); +} + +void VCLXGraphics::setFillColor( sal_Int32 nColor ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + maFillColor = Color( (sal_uInt32)nColor ); +} + +void VCLXGraphics::setRasterOp( ::com::sun::star::awt::RasterOperation eROP ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + meRasterOp = (RasterOp)eROP; +} + +void VCLXGraphics::setClipRegion( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion >& rxRegion ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + delete mpClipRegion; + if ( rxRegion.is() ) + mpClipRegion = new Region( VCLUnoHelper::GetRegion( rxRegion ) ); + else + mpClipRegion = NULL; +} + +void VCLXGraphics::intersectClipRegion( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion >& rxRegion ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( rxRegion.is() ) + { + Region aRegion( VCLUnoHelper::GetRegion( rxRegion ) ); + if ( !mpClipRegion ) + mpClipRegion = new Region( aRegion ); + else + mpClipRegion->Intersect( aRegion ); + } +} + +void VCLXGraphics::push( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + + if( mpOutputDevice ) + mpOutputDevice->Push(); +} + +void VCLXGraphics::pop( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + + if( mpOutputDevice ) + mpOutputDevice->Pop(); +} + +void VCLXGraphics::copy( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice >& rxSource, sal_Int32 nSourceX, sal_Int32 nSourceY, sal_Int32 nSourceWidth, sal_Int32 nSourceHeight, sal_Int32 nDestX, sal_Int32 nDestY, sal_Int32 nDestWidth, sal_Int32 nDestHeight ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( mpOutputDevice ) + { + VCLXDevice* pFromDev = VCLXDevice::GetImplementation( rxSource ); + DBG_ASSERT( pFromDev, "VCLXGraphics::copy - invalid device" ); + if ( pFromDev ) + { + InitOutputDevice( INITOUTDEV_CLIPREGION|INITOUTDEV_RASTEROP ); + mpOutputDevice->DrawOutDev( Point( nDestX, nDestY ), Size( nDestWidth, nDestHeight ), + Point( nSourceX, nSourceY ), Size( nSourceWidth, nSourceHeight ), *pFromDev->GetOutputDevice() ); + } + } +} + +void VCLXGraphics::draw( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDisplayBitmap >& rxBitmapHandle, sal_Int32 nSourceX, sal_Int32 nSourceY, sal_Int32 nSourceWidth, sal_Int32 nSourceHeight, sal_Int32 nDestX, sal_Int32 nDestY, sal_Int32 nDestWidth, sal_Int32 nDestHeight ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if( mpOutputDevice ) + { + InitOutputDevice( INITOUTDEV_CLIPREGION|INITOUTDEV_RASTEROP); + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap > xBitmap( rxBitmapHandle, ::com::sun::star::uno::UNO_QUERY ); + BitmapEx aBmpEx = VCLUnoHelper::GetBitmap( xBitmap ); + + Point aPos(nDestX - nSourceX, nDestY - nSourceY); + Size aSz = aBmpEx.GetSizePixel(); + + if(nDestWidth != nSourceWidth) + { + float zoomX = (float)nDestWidth / (float)nSourceWidth; + aSz.Width() = (long) ((float)aSz.Width() * zoomX); + } + + if(nDestHeight != nSourceHeight) + { + float zoomY = (float)nDestHeight / (float)nSourceHeight; + aSz.Height() = (long) ((float)aSz.Height() * zoomY); + } + + if(nSourceX || nSourceY || aSz.Width() != nSourceWidth || aSz.Height() != nSourceHeight) + mpOutputDevice->IntersectClipRegion(Region(Rectangle(nDestX, nDestY, nDestX + nDestWidth - 1, nDestY + nDestHeight - 1))); + + mpOutputDevice->DrawBitmapEx( aPos, aSz, aBmpEx ); + } +} + +void VCLXGraphics::drawPixel( sal_Int32 x, sal_Int32 y ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if( mpOutputDevice ) + { + InitOutputDevice( INITOUTDEV_CLIPREGION|INITOUTDEV_RASTEROP|INITOUTDEV_COLORS ); + mpOutputDevice->DrawPixel( Point( x, y ) ); + } +} + +void VCLXGraphics::drawLine( sal_Int32 x1, sal_Int32 y1, sal_Int32 x2, sal_Int32 y2 ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if( mpOutputDevice ) + { + InitOutputDevice( INITOUTDEV_CLIPREGION|INITOUTDEV_RASTEROP|INITOUTDEV_COLORS ); + mpOutputDevice->DrawLine( Point( x1, y1 ), Point( x2, y2 ) ); + } +} + +void VCLXGraphics::drawRect( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_Int32 height ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if( mpOutputDevice ) + { + InitOutputDevice( INITOUTDEV_CLIPREGION|INITOUTDEV_RASTEROP|INITOUTDEV_COLORS ); + mpOutputDevice->DrawRect( Rectangle( Point( x, y ), Size( width, height ) ) ); + } +} + +void VCLXGraphics::drawRoundedRect( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_Int32 height, sal_Int32 nHorzRound, sal_Int32 nVertRound ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if( mpOutputDevice ) + { + InitOutputDevice( INITOUTDEV_CLIPREGION|INITOUTDEV_RASTEROP|INITOUTDEV_COLORS ); + mpOutputDevice->DrawRect( Rectangle( Point( x, y ), Size( width, height ) ), nHorzRound, nVertRound ); + } +} + +void VCLXGraphics::drawPolyLine( const ::com::sun::star::uno::Sequence< sal_Int32 >& DataX, const ::com::sun::star::uno::Sequence< sal_Int32 >& DataY ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if( mpOutputDevice ) + { + InitOutputDevice( INITOUTDEV_CLIPREGION|INITOUTDEV_RASTEROP|INITOUTDEV_COLORS ); + mpOutputDevice->DrawPolyLine( VCLUnoHelper::CreatePolygon( DataX, DataY ) ); + } +} + +void VCLXGraphics::drawPolygon( const ::com::sun::star::uno::Sequence< sal_Int32 >& DataX, const ::com::sun::star::uno::Sequence< sal_Int32 >& DataY ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if( mpOutputDevice ) + { + InitOutputDevice( INITOUTDEV_CLIPREGION|INITOUTDEV_RASTEROP|INITOUTDEV_COLORS ); + mpOutputDevice->DrawPolygon( VCLUnoHelper::CreatePolygon( DataX, DataY ) ); + } +} + +void VCLXGraphics::drawPolyPolygon( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< sal_Int32 > >& DataX, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< sal_Int32 > >& DataY ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if( mpOutputDevice ) + { + InitOutputDevice( INITOUTDEV_CLIPREGION|INITOUTDEV_RASTEROP|INITOUTDEV_COLORS ); + sal_uInt16 nPolys = (sal_uInt16) DataX.getLength(); + PolyPolygon aPolyPoly( nPolys ); + for ( sal_uInt16 n = 0; n < nPolys; n++ ) + aPolyPoly[n] = VCLUnoHelper::CreatePolygon( DataX.getConstArray()[n], DataY.getConstArray()[n] ); + + mpOutputDevice->DrawPolyPolygon( aPolyPoly ); + } +} + +void VCLXGraphics::drawEllipse( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_Int32 height ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if( mpOutputDevice ) + { + InitOutputDevice( INITOUTDEV_CLIPREGION|INITOUTDEV_RASTEROP|INITOUTDEV_COLORS ); + mpOutputDevice->DrawEllipse( Rectangle( Point( x, y ), Size( width, height ) ) ); + } +} + +void VCLXGraphics::drawArc( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_Int32 height, sal_Int32 x1, sal_Int32 y1, sal_Int32 x2, sal_Int32 y2 ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if( mpOutputDevice ) + { + InitOutputDevice( INITOUTDEV_CLIPREGION|INITOUTDEV_RASTEROP|INITOUTDEV_COLORS ); + mpOutputDevice->DrawArc( Rectangle( Point( x, y ), Size( width, height ) ), Point( x1, y1 ), Point( x2, y2 ) ); + } +} + +void VCLXGraphics::drawPie( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_Int32 height, sal_Int32 x1, sal_Int32 y1, sal_Int32 x2, sal_Int32 y2 ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if( mpOutputDevice ) + { + InitOutputDevice( INITOUTDEV_CLIPREGION|INITOUTDEV_RASTEROP|INITOUTDEV_COLORS ); + mpOutputDevice->DrawPie( Rectangle( Point( x, y ), Size( width, height ) ), Point( x1, y1 ), Point( x2, y2 ) ); + } +} + +void VCLXGraphics::drawChord( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_Int32 height, sal_Int32 x1, sal_Int32 y1, sal_Int32 x2, sal_Int32 y2 ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if( mpOutputDevice ) + { + InitOutputDevice( INITOUTDEV_CLIPREGION|INITOUTDEV_RASTEROP|INITOUTDEV_COLORS ); + mpOutputDevice->DrawChord( Rectangle( Point( x, y ), Size( width, height ) ), Point( x1, y1 ), Point( x2, y2 ) ); + } +} + +void VCLXGraphics::drawGradient( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_Int32 height, const ::com::sun::star::awt::Gradient& rGradient ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if( mpOutputDevice ) + { + InitOutputDevice( INITOUTDEV_CLIPREGION|INITOUTDEV_RASTEROP|INITOUTDEV_COLORS ); + Gradient aGradient((GradientStyle)rGradient.Style, rGradient.StartColor, rGradient.EndColor); + aGradient.SetAngle(rGradient.Angle); + aGradient.SetBorder(rGradient.Border); + aGradient.SetOfsX(rGradient.XOffset); + aGradient.SetOfsY(rGradient.YOffset); + aGradient.SetStartIntensity(rGradient.StartIntensity); + aGradient.SetEndIntensity(rGradient.EndIntensity); + aGradient.SetSteps(rGradient.StepCount); + mpOutputDevice->DrawGradient( Rectangle( Point( x, y ), Size( width, height ) ), aGradient ); + } +} + +void VCLXGraphics::drawText( sal_Int32 x, sal_Int32 y, const ::rtl::OUString& rText ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if( mpOutputDevice ) + { + InitOutputDevice( INITOUTDEV_CLIPREGION|INITOUTDEV_RASTEROP|INITOUTDEV_COLORS |INITOUTDEV_FONT); + mpOutputDevice->DrawText( Point( x, y ), rText ); + } +} + +void VCLXGraphics::drawTextArray( sal_Int32 x, sal_Int32 y, const ::rtl::OUString& rText, const ::com::sun::star::uno::Sequence< sal_Int32 >& rLongs ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if( mpOutputDevice ) + { + InitOutputDevice( INITOUTDEV_CLIPREGION|INITOUTDEV_RASTEROP|INITOUTDEV_COLORS|INITOUTDEV_FONT ); + mpOutputDevice->DrawTextArray( Point( x, y ), rText, rLongs.getConstArray() ); + } +} + + + + diff --git a/toolkit/source/awt/vclxmenu.cxx b/toolkit/source/awt/vclxmenu.cxx new file mode 100644 index 000000000000..1992a8d721a6 --- /dev/null +++ b/toolkit/source/awt/vclxmenu.cxx @@ -0,0 +1,1059 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + + +#include <toolkit/awt/vclxmenu.hxx> +#include <toolkit/helper/macros.hxx> +#include <toolkit/helper/servicenames.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <toolkit/helper/convert.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <rtl/memory.h> +#include <rtl/uuid.h> + +#include <vcl/menu.hxx> +#include <vcl/keycod.hxx> +#include <vcl/image.hxx> +#include <vcl/mnemonic.hxx> + +#include <com/sun/star/awt/KeyModifier.hpp> + + +#ifdef DBG_UTIL + #define THROW_MENUITEM_NOT_FOUND( Func, nItemId ) \ + if ( MENU_ITEM_NOTFOUND == mpMenu->GetItemPos( nItemId ) ) \ + throw ::com::sun::star::container::NoSuchElementException( \ + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( Func ) ) \ + += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ": There is no menu item with " ) ) \ + += ::rtl::OUString::valueOf( sal_Int32( nItemId ) ) \ + += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " as identifier" ) ), \ + *this \ + ); + #define THROW_MENUPOS_NOT_FOUND( Func, nPos ) \ + if ( MENU_ITEM_NOTFOUND == sal_uInt16( nPos ) ) \ + throw ::com::sun::star::container::NoSuchElementException( \ + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( Func ) ) \ + += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ": There is no menu item at position " ) ) \ + += ::rtl::OUString::valueOf( sal_Int32( nPos ) ), \ + *this \ + ); +#else + #define THROW_MENUITEM_NOT_FOUND( Func, nItemId ) \ + if ( MENU_ITEM_NOTFOUND == mpMenu->GetItemPos( nItemId ) ) \ + throw ::com::sun::star::container::NoSuchElementException(); + #define THROW_MENUPOS_NOT_FOUND( Func, nPos ) \ + if ( MENU_ITEM_NOTFOUND == sal_uInt16( nPos ) ) \ + throw ::com::sun::star::container::NoSuchElementException(); +#endif + + +// ---------------------------------------------------- +// class VCLXMenu +// ---------------------------------------------------- + +DBG_NAME(VCLXMenu) + +VCLXMenu::VCLXMenu() : maMenuListeners( *this ) +{ + DBG_CTOR( VCLXMenu, 0 ); + mpMenu = NULL; +} + +VCLXMenu::VCLXMenu( Menu* pMenu ) : maMenuListeners( *this ) +{ + DBG_CTOR( VCLXMenu, 0 ); + mpMenu = pMenu; +} + +VCLXMenu::~VCLXMenu() +{ + DBG_DTOR( VCLXMenu, 0 ); + for ( sal_uInt32 n = maPopupMenueRefs.Count(); n; ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu > * pRef = maPopupMenueRefs.GetObject( --n ); + delete pRef; + } + if ( mpMenu ) + { + mpMenu->RemoveEventListener( LINK( this, VCLXMenu, MenuEventListener ) ); + delete mpMenu; + } +} + +BOOL VCLXMenu::IsPopupMenu() const +{ + return (mpMenu && ! mpMenu->IsMenuBar()); +} + +void VCLXMenu::ImplCreateMenu( sal_Bool bPopup ) +{ + DBG_ASSERT( !mpMenu, "CreateMenu: Menu exists!" ); + + if ( bPopup ) + mpMenu = new PopupMenu; + else + mpMenu = new MenuBar; + + mpMenu->AddEventListener( LINK( this, VCLXMenu, MenuEventListener ) ); +} + +IMPL_LINK( VCLXMenu, MenuEventListener, VclSimpleEvent*, pEvent ) +{ + DBG_ASSERT( pEvent && pEvent->ISA( VclMenuEvent ), "Unknown Event!" ); + if ( pEvent && pEvent->ISA( VclMenuEvent ) ) + { + DBG_ASSERT( ((VclMenuEvent*)pEvent)->GetMenu() && mpMenu, "Menu???" ); + + VclMenuEvent* pMenuEvent = (VclMenuEvent*)pEvent; + if ( pMenuEvent->GetMenu() == mpMenu ) // Also called for the root menu + { + switch ( pMenuEvent->GetId() ) + { + case VCLEVENT_MENU_SELECT: + { + if ( maMenuListeners.getLength() ) + { + ::com::sun::star::awt::MenuEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.MenuId = mpMenu->GetCurItemId(); + maMenuListeners.select( aEvent ); + } + } + break; + case VCLEVENT_OBJECT_DYING: + { + mpMenu = NULL; + } + break; + case VCLEVENT_MENU_HIGHLIGHT: + { + if ( maMenuListeners.getLength() ) + { + ::com::sun::star::awt::MenuEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.MenuId = mpMenu->GetCurItemId(); + maMenuListeners.highlight( aEvent ); + } + } + break; + case VCLEVENT_MENU_ACTIVATE: + { + if ( maMenuListeners.getLength() ) + { + ::com::sun::star::awt::MenuEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.MenuId = mpMenu->GetCurItemId(); + maMenuListeners.activate( aEvent ); + } + } + break; + case VCLEVENT_MENU_DEACTIVATE: + { + if ( maMenuListeners.getLength() ) + { + ::com::sun::star::awt::MenuEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.MenuId = mpMenu->GetCurItemId(); + maMenuListeners.deactivate( aEvent ); + } + } + break; + + // ignore accessibility events + case VCLEVENT_MENU_ENABLE: + case VCLEVENT_MENU_INSERTITEM: + case VCLEVENT_MENU_REMOVEITEM: + case VCLEVENT_MENU_SUBMENUACTIVATE: + case VCLEVENT_MENU_SUBMENUDEACTIVATE: + case VCLEVENT_MENU_SUBMENUCHANGED: + case VCLEVENT_MENU_DEHIGHLIGHT: + case VCLEVENT_MENU_DISABLE: + case VCLEVENT_MENU_ITEMTEXTCHANGED: + case VCLEVENT_MENU_ITEMCHECKED: + case VCLEVENT_MENU_ITEMUNCHECKED: + case VCLEVENT_MENU_SHOW: + case VCLEVENT_MENU_HIDE: + break; + + default: DBG_ERROR( "MenuEventListener - Unknown event!" ); + } + } + } + return 0; +} + + +//============================================================================= +//============================================================================= +//============================================================================= + + +// ::com::sun::star::lang::XServiceInfo +::rtl::OUString SAL_CALL VCLXMenu::getImplementationName( ) +throw (::com::sun::star::uno::RuntimeException) +{ + ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() ); + const sal_Bool bIsPopupMenu = IsPopupMenu(); + aGuard.clear(); + + ::rtl::OUString implName( RTL_CONSTASCII_USTRINGPARAM( "stardiv.Toolkit." ) ); + if ( bIsPopupMenu ) + implName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VCLXPopupMenu" ) ); + else + implName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VCLXMenuBar" ) ); + + return implName; +} + + +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL VCLXMenu::getSupportedServiceNames( ) +throw (::com::sun::star::uno::RuntimeException) +{ + ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() ); + const sal_Bool bIsPopupMenu = IsPopupMenu(); + aGuard.clear(); + + ::com::sun::star::uno::Sequence< ::rtl::OUString > aNames( 1 ); + if ( bIsPopupMenu ) + aNames[ 0 ] = ::rtl::OUString::createFromAscii( szServiceName2_PopupMenu ); + else + aNames[ 0 ] = ::rtl::OUString::createFromAscii( szServiceName2_MenuBar ); + + return aNames; +} + + +::sal_Bool SAL_CALL VCLXMenu::supportsService( const ::rtl::OUString& rServiceName ) +throw (::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Sequence< ::rtl::OUString > aServiceNames( getSupportedServiceNames() ); + + if ( aServiceNames[ 0 ] == rServiceName ) + return sal_True; + + return sal_False; +} + + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXMenu::queryInterface( const ::com::sun::star::uno::Type & rType ) +throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() ); + const sal_Bool bIsPopupMenu = IsPopupMenu(); + aGuard.clear(); + + ::com::sun::star::uno::Any aRet; + + if ( bIsPopupMenu ) + aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XMenu*, (::com::sun::star::awt::XMenuBar*) this ), + SAL_STATIC_CAST( ::com::sun::star::awt::XPopupMenu*, this ), + SAL_STATIC_CAST( ::com::sun::star::awt::XPopupMenuExtended*, this ), + SAL_STATIC_CAST( ::com::sun::star::awt::XMenuExtended*, (::com::sun::star::awt::XPopupMenuExtended*) this ), + SAL_STATIC_CAST( ::com::sun::star::awt::XMenuExtended2*, (::com::sun::star::awt::XPopupMenuExtended*) this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XServiceInfo*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XUnoTunnel*, this ) ); + else + aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XMenu*, (::com::sun::star::awt::XMenuBar*) this ), + SAL_STATIC_CAST( ::com::sun::star::awt::XMenuBar*, this ), + SAL_STATIC_CAST( ::com::sun::star::awt::XMenuBarExtended*, this ), + SAL_STATIC_CAST( ::com::sun::star::awt::XMenuExtended*, (::com::sun::star::awt::XMenuBarExtended*) this ), + SAL_STATIC_CAST( ::com::sun::star::awt::XMenuExtended2*, (::com::sun::star::awt::XMenuBarExtended*) this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XServiceInfo*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XUnoTunnel*, this ) ); + + return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); +} + +// ::com::sun::star::lang::XUnoTunnel +IMPL_XUNOTUNNEL( VCLXMenu ) + +// ::com::sun::star::lang::XTypeProvider +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > VCLXMenu::getTypes() +throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() ); + const sal_Bool bIsPopupMenu = IsPopupMenu(); + aGuard.clear(); + + static ::cppu::OTypeCollection* pCollectionMenuBar = NULL; + static ::cppu::OTypeCollection* pCollectionPopupMenu = NULL; + + if ( bIsPopupMenu ) + { + if( !pCollectionPopupMenu ) + { + ::osl::Guard< ::osl::Mutex > aGlobalGuard( ::osl::Mutex::getGlobalMutex() ); + if( !pCollectionPopupMenu ) + { + static ::cppu::OTypeCollection collectionPopupMenu( + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XTypeProvider>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenu>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenuExtended>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuExtended>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuExtended2>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XServiceInfo>* ) NULL ) ); + pCollectionPopupMenu = &collectionPopupMenu; + } + } + + return (*pCollectionPopupMenu).getTypes(); + } + else + { + if( !pCollectionMenuBar ) + { + ::osl::Guard< ::osl::Mutex > aGlobalGuard( ::osl::Mutex::getGlobalMutex() ); + if( !pCollectionMenuBar ) + { + static ::cppu::OTypeCollection collectionMenuBar( + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XTypeProvider>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenu>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuBar>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuBarExtended>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuExtended>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuExtended2>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XServiceInfo>* ) NULL ) ); + pCollectionMenuBar = &collectionMenuBar; + } + } + return (*pCollectionMenuBar).getTypes(); + } +} + + +::com::sun::star::uno::Sequence< sal_Int8 > VCLXMenu::getImplementationId() +throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() ); + const sal_Bool bIsPopupMenu = IsPopupMenu(); + aGuard.clear(); + + static ::cppu::OImplementationId* pIdMenuBar = NULL; + static ::cppu::OImplementationId* pIdPopupMenu = NULL; + + if ( bIsPopupMenu ) + { + if( !pIdPopupMenu ) + { + ::osl::Guard< ::osl::Mutex > aGlobalGuard( ::osl::Mutex::getGlobalMutex() ); + if( !pIdPopupMenu ) + { + static ::cppu::OImplementationId idPopupMenu( sal_False ); + pIdPopupMenu = &idPopupMenu; + } + } + + return (*pIdPopupMenu).getImplementationId(); + } + else + { + if( !pIdMenuBar ) + { + ::osl::Guard< ::osl::Mutex > aGlobalGuard( ::osl::Mutex::getGlobalMutex() ); + if( !pIdMenuBar ) + { + static ::cppu::OImplementationId idMenuBar( sal_False ); + pIdMenuBar = &idMenuBar; + } + } + + return (*pIdMenuBar).getImplementationId(); + } +} + + +//============================================================================= +//============================================================================= +//============================================================================= + + +void VCLXMenu::addMenuListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maMenuListeners.addInterface( rxListener ); +} + +void VCLXMenu::removeMenuListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maMenuListeners.removeInterface( rxListener ); +} + +void VCLXMenu::insertItem( sal_Int16 nItemId, const ::rtl::OUString& aText, sal_Int16 nItemStyle, sal_Int16 nPos ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu ) + mpMenu->InsertItem( nItemId, aText, (MenuItemBits)nItemStyle, nPos ); +} + +void VCLXMenu::removeItem( sal_Int16 nPos, sal_Int16 nCount ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + sal_Int32 nItemCount = (sal_Int32)mpMenu->GetItemCount(); + if ( mpMenu && ( nCount > 0 ) && ( nPos >= 0 ) && ( nPos < nItemCount ) && ( nItemCount > 0 )) + { + sal_Int16 nP = sal::static_int_cast< sal_Int16 >( + Min( (int)(nPos+nCount), (int)nItemCount )); + while( nP-nPos > 0 ) + mpMenu->RemoveItem( --nP ); + } +} + +sal_Int16 VCLXMenu::getItemCount( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return mpMenu ? mpMenu->GetItemCount() : 0; +} + +sal_Int16 VCLXMenu::getItemId( sal_Int16 nPos ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return mpMenu ? mpMenu->GetItemId( nPos ) : 0; +} + +sal_Int16 VCLXMenu::getItemPos( sal_Int16 nId ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return mpMenu ? mpMenu->GetItemPos( nId ) : 0; +} + +void VCLXMenu::enableItem( sal_Int16 nItemId, sal_Bool bEnable ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu ) + mpMenu->EnableItem( nItemId, bEnable ); +} + +sal_Bool VCLXMenu::isItemEnabled( sal_Int16 nItemId ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return mpMenu ? mpMenu->IsItemEnabled( nItemId ) : sal_False; +} + +void VCLXMenu::setItemText( sal_Int16 nItemId, const ::rtl::OUString& aText ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu ) + mpMenu->SetItemText( nItemId, aText ); +} + +::rtl::OUString VCLXMenu::getItemText( sal_Int16 nItemId ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::rtl::OUString aItemText; + if ( mpMenu ) + aItemText = mpMenu->GetItemText( nItemId ); + return aItemText; +} + +void VCLXMenu::setPopupMenu( sal_Int16 nItemId, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu >& rxPopupMenu ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + VCLXMenu* pVCLMenu = VCLXMenu::GetImplementation( rxPopupMenu ); + DBG_ASSERT( pVCLMenu && pVCLMenu->GetMenu() && pVCLMenu->IsPopupMenu(), "setPopupMenu: Invalid Menu!" ); + + if ( mpMenu && pVCLMenu && pVCLMenu->GetMenu() && pVCLMenu->IsPopupMenu() ) + { + // Selbst eine Ref halten! + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu > * pNewRef = new ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu > ; + *pNewRef = rxPopupMenu; + maPopupMenueRefs.Insert( pNewRef, LIST_APPEND ); + + mpMenu->SetPopupMenu( nItemId, (PopupMenu*) pVCLMenu->GetMenu() ); + } +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu > VCLXMenu::getPopupMenu( sal_Int16 nItemId ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu > aRef; + Menu* pMenu = mpMenu ? mpMenu->GetPopupMenu( nItemId ) : NULL; + if ( pMenu ) + { + for ( sal_uInt32 n = maPopupMenueRefs.Count(); n; ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu > * pRef = maPopupMenueRefs.GetObject( --n ); + Menu* pM = ((VCLXMenu*)pRef->get())->GetMenu(); + if ( pM == pMenu ) + { + aRef = *pRef; + break; + } + } + } + return aRef; +} + +// ::com::sun::star::awt::XPopupMenu +void VCLXMenu::insertSeparator( sal_Int16 nPos ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu ) + mpMenu->InsertSeparator( nPos ); +} + +void VCLXMenu::setDefaultItem( sal_Int16 nItemId ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu ) + mpMenu->SetDefaultItem( nItemId ); +} + +sal_Int16 VCLXMenu::getDefaultItem( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return mpMenu ? mpMenu->GetDefaultItem() : 0; +} + +void VCLXMenu::checkItem( sal_Int16 nItemId, sal_Bool bCheck ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu ) + mpMenu->CheckItem( nItemId, bCheck ); +} + +sal_Bool VCLXMenu::isItemChecked( sal_Int16 nItemId ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return mpMenu ? mpMenu->IsItemChecked( nItemId ) : sal_False; +} + +sal_Int16 VCLXMenu::execute( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& rxWindowPeer, const ::com::sun::star::awt::Rectangle& rArea, sal_Int16 nFlags ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + sal_Int16 nRet = 0; + if ( mpMenu && IsPopupMenu() ) + nRet = ((PopupMenu*)mpMenu)->Execute( VCLUnoHelper::GetWindow( rxWindowPeer ), VCLRectangle(rArea), nFlags | POPUPMENU_NOMOUSEUPCLOSE ); + return nRet; +} + + +void SAL_CALL VCLXMenu::setCommand( sal_Int16 nItemId, const ::rtl::OUString& aCommand ) throw (::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu ) + mpMenu->SetItemCommand( nItemId, aCommand ); +} + +::rtl::OUString SAL_CALL VCLXMenu::getCommand( sal_Int16 nItemId ) throw (::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::rtl::OUString aItemCommand; + if ( mpMenu ) + aItemCommand = mpMenu->GetItemCommand( nItemId ); + return aItemCommand; +} + +void SAL_CALL VCLXMenu::setHelpCommand( sal_Int16 nItemId, const ::rtl::OUString& aHelp ) throw (::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu ) + mpMenu->SetHelpCommand( nItemId, aHelp ); +} + +::rtl::OUString SAL_CALL VCLXMenu::getHelpCommand( sal_Int16 nItemId ) throw (::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::rtl::OUString aHelpCommand; + if ( mpMenu ) + aHelpCommand = mpMenu->GetHelpCommand( nItemId ); + return aHelpCommand; +} + + +// ============================================================================ +// ============================================================================ +// ============================================================================ + + +// BEGIN ANONYMOUS NAMESPACE +namespace +{ + namespace css = ::com::sun::star; + + Image lcl_XGraphic2VCLImage( + const css::uno::Reference< css::graphic::XGraphic >& xGraphic, + sal_Bool bResize ) + { + Image aImage; + if ( !xGraphic.is() ) + return aImage; + + aImage = Image( xGraphic ); + const ::Size aCurSize = aImage.GetSizePixel(); + const sal_Int32 nCurWidth = aCurSize.Width(); + const sal_Int32 nCurHeight = aCurSize.Height(); + const sal_Int32 nIdeal( 16 ); + + if ( nCurWidth > 0 && nCurHeight > 0 ) + { + if ( bResize && ( nCurWidth > nIdeal || nCurHeight > nIdeal ) ) + { + sal_Int32 nIdealWidth = nCurWidth > nIdeal ? nIdeal : nCurWidth; + sal_Int32 nIdealHeight = nCurHeight > nIdeal ? nIdeal : nCurHeight; + + ::Size aNewSize( nIdealWidth, nIdealHeight ); + + sal_Bool bModified( sal_False ); + BitmapEx aBitmapEx = aImage.GetBitmapEx(); + bModified = aBitmapEx.Scale( aNewSize, BMP_SCALE_INTERPOLATE ); + + if ( bModified ) + aImage = Image( aBitmapEx ); + } + } + return aImage; + } + + /** + As svtools builds after toolkit, we can not include/use + svtools/inc/acceleratorexecute.hxx + So I just copy here svt::AcceleratorExecute::st_AWTKey2VCLKey + and svt::AcceleratorExecute::st_VCLKey2AWTKey + */ + css::awt::KeyEvent lcl_VCLKey2AWTKey(const KeyCode& aVCLKey) + { + css::awt::KeyEvent aAWTKey; + aAWTKey.Modifiers = 0; + aAWTKey.KeyCode = (sal_Int16)aVCLKey.GetCode(); + + if (aVCLKey.IsShift()) + aAWTKey.Modifiers |= css::awt::KeyModifier::SHIFT; + if (aVCLKey.IsMod1()) + aAWTKey.Modifiers |= css::awt::KeyModifier::MOD1; + if (aVCLKey.IsMod2()) + aAWTKey.Modifiers |= css::awt::KeyModifier::MOD2; + if (aVCLKey.IsMod3()) + aAWTKey.Modifiers |= css::awt::KeyModifier::MOD3; + + return aAWTKey; + } + + KeyCode lcl_AWTKey2VCLKey(const css::awt::KeyEvent& aAWTKey) + { + sal_Bool bShift = ((aAWTKey.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT ); + sal_Bool bMod1 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD1 ) == css::awt::KeyModifier::MOD1 ); + sal_Bool bMod2 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD2 ) == css::awt::KeyModifier::MOD2 ); + sal_Bool bMod3 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD3 ) == css::awt::KeyModifier::MOD3 ); + USHORT nKey = (USHORT)aAWTKey.KeyCode; + + return KeyCode(nKey, bShift, bMod1, bMod2, bMod3); + } + +} // END ANONYMOUS NAMESPACE + + +// ============================================================================ +// ============================================================================ +// ============================================================================ + + +// XMenuExtended2 Methods + +::sal_Bool SAL_CALL VCLXMenu::isPopupMenu( ) throw (::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + return IsPopupMenu(); +} + +void SAL_CALL VCLXMenu::clear( ) throw (::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + if ( mpMenu ) + mpMenu->Clear(); +} + + +::com::sun::star::awt::MenuItemType SAL_CALL VCLXMenu::getItemType( ::sal_Int16 nItemPos ) +throw ( ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::awt::MenuItemType aMenuItemType = + ::com::sun::star::awt::MenuItemType_DONTKNOW; + if ( mpMenu ) + { + THROW_MENUPOS_NOT_FOUND( "VCLXMenu::getItemType()", nItemPos ) + aMenuItemType = ( (::com::sun::star::awt::MenuItemType) mpMenu->GetItemType( nItemPos ) ); + } + + return aMenuItemType; +} + +void SAL_CALL VCLXMenu::hideDisabledEntries( ::sal_Bool bHide ) +throw (::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + if ( mpMenu ) + { + if ( bHide ) + mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() | MENU_FLAG_HIDEDISABLEDENTRIES ); + else + mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() & ~MENU_FLAG_HIDEDISABLEDENTRIES ); + } +} + + +// ============================================================================ +// ============================================================================ +// ============================================================================ + + +// XPopupMenuExtended Methods + +::sal_Bool SAL_CALL VCLXMenu::isInExecute( ) +throw (::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu && IsPopupMenu() ) + return ( (PopupMenu*) mpMenu )->IsInExecute(); + else + return sal_False; +} + + +void SAL_CALL VCLXMenu::endExecute() +throw (::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu && IsPopupMenu() ) + ( (PopupMenu*) mpMenu )->EndExecute(); +} + + +void SAL_CALL VCLXMenu::setLogo( const ::com::sun::star::awt::MenuLogo& aMenuLogo ) +throw (::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu ) + { + if ( aMenuLogo.Graphic.is() ) + { + Image aImage = lcl_XGraphic2VCLImage( aMenuLogo.Graphic, sal_False ); + MenuLogo aVCLMenuLogo; + + aVCLMenuLogo.aBitmap = aImage.GetBitmapEx(); + aVCLMenuLogo.aStartColor = Color( (sal_uInt32)(aMenuLogo.StartColor) ); + aVCLMenuLogo.aEndColor = Color( (sal_uInt32)(aMenuLogo.EndColor) ); + + mpMenu->SetLogo( aVCLMenuLogo ); + } + else + mpMenu->SetLogo(); + } +} + + +::com::sun::star::awt::MenuLogo SAL_CALL VCLXMenu::getLogo( ) +throw (::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::awt::MenuLogo aAWTMenuLogo; + if ( mpMenu ) + { + if ( mpMenu->HasLogo() ) + { + MenuLogo aVCLMenuLogo = mpMenu->GetLogo(); + aAWTMenuLogo.Graphic = Image(aVCLMenuLogo.aBitmap).GetXGraphic(); + aAWTMenuLogo.StartColor = aVCLMenuLogo.aStartColor.GetColor(); + aAWTMenuLogo.EndColor = aVCLMenuLogo.aEndColor.GetColor(); + } + } + return aAWTMenuLogo; +} + + +void SAL_CALL VCLXMenu::enableAutoMnemonics( ::sal_Bool bEnable ) +throw (::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + if ( mpMenu ) + { + if ( !bEnable ) + mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() | MENU_FLAG_NOAUTOMNEMONICS ); + else + mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() & ~MENU_FLAG_NOAUTOMNEMONICS ); + } +} + + +void SAL_CALL VCLXMenu::setAcceleratorKeyEvent( ::sal_Int16 nItemId, + const ::com::sun::star::awt::KeyEvent& aKeyEvent ) +throw ( ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu && IsPopupMenu() ) + { + THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setAcceleratorKeyEvent()", nItemId ) + KeyCode aVCLKeyCode = lcl_AWTKey2VCLKey( aKeyEvent ); + mpMenu->SetAccelKey( nItemId, aVCLKeyCode ); + } +} + + +::com::sun::star::awt::KeyEvent SAL_CALL VCLXMenu::getAcceleratorKeyEvent( ::sal_Int16 nItemId ) +throw ( ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::awt::KeyEvent aKeyEvent; + if ( mpMenu && IsPopupMenu() ) + { + THROW_MENUITEM_NOT_FOUND( "VCLXMenu::getAcceleratorKeyEvent()", nItemId ) + KeyCode nKeyCode = mpMenu->GetAccelKey( nItemId ); + aKeyEvent = lcl_VCLKey2AWTKey( nKeyCode ); + } + + return aKeyEvent; +} + + +void SAL_CALL VCLXMenu::setHelpText( ::sal_Int16 nItemId, const ::rtl::OUString& sHelpText ) +throw ( ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu && IsPopupMenu() ) + { + THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setHelpText()", nItemId ) + mpMenu->SetHelpText( nItemId, sHelpText ); + } +} + + +::rtl::OUString SAL_CALL VCLXMenu::getHelpText( ::sal_Int16 nItemId ) +throw ( ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + rtl::OUString sHelpText; + if ( mpMenu && IsPopupMenu() ) + { + THROW_MENUITEM_NOT_FOUND( "VCLXMenu::getHelpText()", nItemId ) + sHelpText = mpMenu->GetHelpText( nItemId ); + } + + return sHelpText; +} + + +void SAL_CALL VCLXMenu::setTipHelpText( ::sal_Int16 nItemId, const ::rtl::OUString& sTipHelpText ) +throw ( ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu && IsPopupMenu() ) + { + THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setTipHelpText()", nItemId ) + mpMenu->SetTipHelpText( nItemId, sTipHelpText ); + } +} + + +::rtl::OUString SAL_CALL VCLXMenu::getTipHelpText( ::sal_Int16 nItemId ) +throw ( ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + rtl::OUString sTipHelpText; + if ( mpMenu && IsPopupMenu() ) + { + THROW_MENUITEM_NOT_FOUND( "VCLXMenu::getTipHelpText()", nItemId ) + sTipHelpText = mpMenu->GetTipHelpText( nItemId ); + } + return sTipHelpText; +} + + +void SAL_CALL VCLXMenu::setItemImage( + ::sal_Int16 nItemId, + const ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >& xGraphic, ::sal_Bool bScale ) +throw ( ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu && IsPopupMenu() ) + { + THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setItemImage()", nItemId ) + Image aImage = lcl_XGraphic2VCLImage( xGraphic, bScale ); + mpMenu->SetItemImage( nItemId, aImage ); + } +} + + +::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > SAL_CALL VCLXMenu::getItemImage( ::sal_Int16 nItemId ) +throw ( ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > rxGraphic; + + if ( mpMenu && IsPopupMenu() ) + { + THROW_MENUITEM_NOT_FOUND( "VCLXMenu::getItemImage()", nItemId ) + Image aImage = mpMenu->GetItemImage( nItemId ); + if ( !!aImage ) + rxGraphic = aImage.GetXGraphic(); + } + return rxGraphic; +} + + +void SAL_CALL VCLXMenu::setItemImageAngle( ::sal_Int16 nItemId, ::sal_Int32 nAngle ) +throw ( ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu && IsPopupMenu() ) + { + THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setItemImageAngle()", nItemId ) + mpMenu->SetItemImageAngle( nItemId, nAngle ); + } +} + + +::sal_Int32 SAL_CALL VCLXMenu::getItemImageAngle( ::sal_Int16 nItemId ) +throw ( ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::sal_Int32 nItemImageAngle( 0 ); + if ( mpMenu && IsPopupMenu() ) + { + THROW_MENUITEM_NOT_FOUND( "VCLXMenu::getItemImageAngle()", nItemId ) + nItemImageAngle = mpMenu->GetItemImageAngle( nItemId ); + } + return nItemImageAngle; +} + + +void SAL_CALL VCLXMenu::setItemImageMirrorMode( ::sal_Int16 nItemId, ::sal_Bool bMirror ) +throw ( ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( mpMenu && IsPopupMenu() ) + { + THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setItemImageMirrorMode()", nItemId ) + mpMenu->SetItemImageMirrorMode( nItemId, bMirror ); + } +} + + +::sal_Bool SAL_CALL VCLXMenu::isItemImageInMirrorMode( ::sal_Int16 nItemId ) +throw ( ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + sal_Bool bMirrorMode( sal_False ); + if ( mpMenu && IsPopupMenu() ) + { + THROW_MENUITEM_NOT_FOUND( "VCLXMenu::isItemImageInMirrorMode()", nItemId ) + bMirrorMode = mpMenu->GetItemImageMirrorMode( nItemId ); + } + return bMirrorMode; +} + + +// ---------------------------------------------------- +// class VCLXMenuBar +// ---------------------------------------------------- + +DBG_NAME(VCLXMenuBar); + +VCLXMenuBar::VCLXMenuBar() +{ + DBG_CTOR( VCLXMenuBar, 0 ); + ImplCreateMenu( FALSE ); +} + +VCLXMenuBar::VCLXMenuBar( MenuBar* pMenuBar ) : VCLXMenu( (Menu *)pMenuBar ) +{ + DBG_CTOR( VCLXMenuBar, 0 ); +} + +// ---------------------------------------------------- +// class VCLXPopupMenu +// ---------------------------------------------------- + +DBG_NAME(VCLXPopupMenu); + +VCLXPopupMenu::VCLXPopupMenu() +{ + DBG_CTOR( VCLXPopupMenu, 0 ); + ImplCreateMenu( TRUE ); +} diff --git a/toolkit/source/awt/vclxplugin.cxx b/toolkit/source/awt/vclxplugin.cxx new file mode 100644 index 000000000000..29264ef0a85d --- /dev/null +++ b/toolkit/source/awt/vclxplugin.cxx @@ -0,0 +1,80 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vclxplugin.hxx" + +#include <com/sun/star/awt/PosSize.hpp> +#include <toolkit/helper/convert.hxx> +#include <toolkit/helper/property.hxx> +#include <vcl/ctrl.hxx> + +#include "forward.hxx" + +namespace layoutimpl +{ + +using namespace ::com::sun::star; + +VCLXPlugin::VCLXPlugin( Window *p, WinBits b ) + : VCLXWindow() + , mpWindow( p ) + , mpPlugin( 0 ) + , mStyle( b ) +{ +} + +VCLXPlugin::~VCLXPlugin() +{ +} + +void SAL_CALL VCLXPlugin::dispose() throw(uno::RuntimeException) +{ + { + ::vos::OGuard aGuard( GetMutex() ); + + lang::EventObject aDisposeEvent; + aDisposeEvent.Source = W3K_EXPLICIT_CAST (*this); + } + + VCLXWindow::dispose(); +} + +void VCLXPlugin::SetPlugin( ::Control *p ) +{ + mpPlugin = p; +} + +awt::Size SAL_CALL VCLXPlugin::getMinimumSize() + throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OClearableGuard aGuard( GetMutex() ); + if ( mpPlugin ) + return AWTSize( mpPlugin->GetSizePixel() ); + return awt::Size(); +} + +} // namespace layoutimpl diff --git a/toolkit/source/awt/vclxplugin.hxx b/toolkit/source/awt/vclxplugin.hxx new file mode 100644 index 000000000000..49a2b2950854 --- /dev/null +++ b/toolkit/source/awt/vclxplugin.hxx @@ -0,0 +1,67 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_AWT_VCLXPLUGIN_HXX +#define LAYOUT_AWT_VCLXPLUGIN_HXX + +#include <toolkit/awt/vclxwindow.hxx> +#include <vcl/wintypes.hxx> + +class Control; +namespace layoutimpl +{ + +namespace css = ::com::sun::star; + +class VCLXPlugin : public VCLXWindow +{ +public: + Window *mpWindow; + ::Control *mpPlugin; + WinBits mStyle; + + VCLXPlugin( Window *p, WinBits b ); + + void SetPlugin( ::Control *p ); + +protected: + ~VCLXPlugin(); + + // XComponent + void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException); + + virtual ::com::sun::star::awt::Size SAL_CALL getMinimumSize() + throw(::com::sun::star::uno::RuntimeException); + +private: + VCLXPlugin( VCLXPlugin const & ); + VCLXPlugin& operator=( VCLXPlugin const & ); +}; + +} // namespace layoutimpl + +#endif /* LAYOUT_AWT_VCLXPLUGIN_HXX */ diff --git a/toolkit/source/awt/vclxpointer.cxx b/toolkit/source/awt/vclxpointer.cxx new file mode 100644 index 000000000000..d6f2160fb694 --- /dev/null +++ b/toolkit/source/awt/vclxpointer.cxx @@ -0,0 +1,80 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + + +#include <toolkit/awt/vclxpointer.hxx> +#include <toolkit/helper/macros.hxx> +#include <cppuhelper/typeprovider.hxx> + +// ---------------------------------------------------- +// class VCLXPointer +// ---------------------------------------------------- +VCLXPointer::VCLXPointer() +{ +} + +VCLXPointer::~VCLXPointer() +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXPointer::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XPointer*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XUnoTunnel*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ) ); + return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); +} + +// ::com::sun::star::lang::XUnoTunnel +IMPL_XUNOTUNNEL( VCLXPointer ) + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXPointer ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPointer>* ) NULL ) +IMPL_XTYPEPROVIDER_END + +void VCLXPointer::setType( sal_Int32 nType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maPointer = Pointer( (PointerStyle)nType ); +} + +sal_Int32 VCLXPointer::getType() throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return (sal_Int32)maPointer.GetStyle(); +} + + + diff --git a/toolkit/source/awt/vclxprinter.cxx b/toolkit/source/awt/vclxprinter.cxx new file mode 100644 index 000000000000..3c100c7c2186 --- /dev/null +++ b/toolkit/source/awt/vclxprinter.cxx @@ -0,0 +1,463 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + + +#include <toolkit/awt/vclxprinter.hxx> +#include <toolkit/helper/macros.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <rtl/memory.h> +#include <rtl/uuid.h> + + +#include <vcl/print.hxx> +#include <vcl/jobset.hxx> +#include <vcl/svapp.hxx> + +#include <tools/debug.hxx> +#include <tools/stream.hxx> + +#include <toolkit/awt/vclxdevice.hxx> + + +#define BINARYSETUPMARKER 0x23864691 + +#define PROPERTY_Orientation 0 +#define PROPERTY_Horizontal 1 + +::com::sun::star::beans::Property* ImplGetProperties( sal_uInt16& rElementCount ) +{ + static ::com::sun::star::beans::Property* pProperties = NULL; + static sal_uInt16 nElements = 0; + if( !pProperties ) + { + ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !pProperties ) + { + static ::com::sun::star::beans::Property __FAR_DATA aPropTable[] = + { + ::com::sun::star::beans::Property( ::rtl::OUString::createFromAscii( "Orientation" ), PROPERTY_Orientation, ::getCppuType((const sal_Int16*)0), 0 ), + ::com::sun::star::beans::Property( ::rtl::OUString::createFromAscii( "Horizontal" ), PROPERTY_Horizontal, ::getBooleanCppuType(), 0 ) + }; + pProperties = aPropTable; + nElements = sizeof( aPropTable ) / sizeof( ::com::sun::star::beans::Property ); + } + } + rElementCount = nElements; + return pProperties; +} + +// ---------------------------------------------------- +// class VCLXPrinterPropertySet +// ---------------------------------------------------- + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXPrinterPropertySet::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::beans::XMultiPropertySet*, this ), + SAL_STATIC_CAST( ::com::sun::star::beans::XFastPropertySet*, this ), + SAL_STATIC_CAST( ::com::sun::star::beans::XPropertySet*, (::cppu::OPropertySetHelper*) this ), + SAL_STATIC_CAST( ::com::sun::star::awt::XPrinterPropertySet*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ) ); + return (aRet.hasValue() ? aRet : OPropertySetHelper::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXPrinterPropertySet ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPrinterPropertySet>* ) NULL ) +IMPL_XTYPEPROVIDER_END + +VCLXPrinterPropertySet::VCLXPrinterPropertySet( const String& rPrinterName ) + : OPropertySetHelper( BrdcstHelper ) + , mpPrinter( new Printer( rPrinterName ) ) +{ + osl::Guard< vos::IMutex > aSolarGuard( Application::GetSolarMutex() ); + + mnOrientation = 0; + mbHorizontal = sal_False; +} + +VCLXPrinterPropertySet::~VCLXPrinterPropertySet() +{ + osl::Guard< vos::IMutex > aSolarGuard( Application::GetSolarMutex() ); + mpPrinter.reset(); +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > VCLXPrinterPropertySet::GetDevice() +{ + if ( !mxPrnDevice.is() ) + { + VCLXDevice* pDev = new VCLXDevice; + pDev->SetOutputDevice( GetPrinter() ); + mxPrnDevice = pDev; + } + return mxPrnDevice; +} + +::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > VCLXPrinterPropertySet::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException) +{ + static ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + +::cppu::IPropertyArrayHelper& VCLXPrinterPropertySet::getInfoHelper() +{ + static ::cppu::OPropertyArrayHelper* pPropertyArrayHelper = NULL; + if ( !pPropertyArrayHelper ) + { + ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !pPropertyArrayHelper ) + { + sal_uInt16 nElements; + ::com::sun::star::beans::Property* pProps = ImplGetProperties( nElements ); + pPropertyArrayHelper = new ::cppu::OPropertyArrayHelper( pProps, nElements, sal_False ); + } + } + return *pPropertyArrayHelper ; +} + +sal_Bool VCLXPrinterPropertySet::convertFastPropertyValue( ::com::sun::star::uno::Any & rConvertedValue, ::com::sun::star::uno::Any & rOldValue, sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::lang::IllegalArgumentException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( Mutex ); + + sal_Bool bDifferent = sal_False; + switch ( nHandle ) + { + case PROPERTY_Orientation: + { + sal_Int16 n; + if( ( rValue >>= n ) && ( n != mnOrientation ) ) + { + rConvertedValue <<= n; + rOldValue <<= mnOrientation; + bDifferent = sal_True; + } + } + break; + case PROPERTY_Horizontal: + { + sal_Bool b; + if( ( rValue >>= b ) && ( b != mbHorizontal ) ) + { + rConvertedValue <<= b; + rOldValue <<= mbHorizontal; + bDifferent = sal_True; + } + } + break; + default: + { + DBG_ERROR( "VCLXPrinterPropertySet_Impl::convertFastPropertyValue - invalid Handle" ); + } + } + return bDifferent; +} + +void VCLXPrinterPropertySet::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::uno::Exception) +{ + ::osl::Guard< ::osl::Mutex > aGuard( Mutex ); + + switch( nHandle ) + { + case PROPERTY_Orientation: + { + rValue >>= mnOrientation; + } + break; + case PROPERTY_Horizontal: + { + rValue >>= mbHorizontal; + } + break; + default: + { + DBG_ERROR( "VCLXPrinterPropertySet_Impl::convertFastPropertyValue - invalid Handle" ); + } + } +} + +void VCLXPrinterPropertySet::getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const +{ + ::osl::Guard< ::osl::Mutex > aGuard( ((VCLXPrinterPropertySet*)this)->Mutex ); + + switch( nHandle ) + { + case PROPERTY_Orientation: + rValue <<= mnOrientation; + break; + case PROPERTY_Horizontal: + rValue <<= mbHorizontal; + break; + default: + { + DBG_ERROR( "VCLXPrinterPropertySet_Impl::convertFastPropertyValue - invalid Handle" ); + } + } +} + +// ::com::sun::star::awt::XPrinterPropertySet +void VCLXPrinterPropertySet::setHorizontal( sal_Bool bHorizontal ) throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( Mutex ); + + ::com::sun::star::uno::Any aValue; + aValue <<= bHorizontal; + setFastPropertyValue( PROPERTY_Horizontal, aValue ); +} + +::com::sun::star::uno::Sequence< ::rtl::OUString > VCLXPrinterPropertySet::getFormDescriptions( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( Mutex ); + + sal_uInt16 nPaperBinCount = GetPrinter()->GetPaperBinCount(); + ::com::sun::star::uno::Sequence< ::rtl::OUString > aDescriptions( nPaperBinCount ); + for ( sal_uInt16 n = 0; n < nPaperBinCount; n++ ) + { + // Format: <DisplayFormName;FormNameId;DisplayPaperBinName;PaperBinNameId;DisplayPaperName;PaperNameId> + String aDescr( RTL_CONSTASCII_USTRINGPARAM( "*;*;" ) ); + aDescr += GetPrinter()->GetPaperBinName( n ); + aDescr += ';'; + aDescr += n; + aDescr.AppendAscii( ";*;*", 4 ); + + aDescriptions.getArray()[n] = aDescr; + } + return aDescriptions; +} + +void VCLXPrinterPropertySet::selectForm( const ::rtl::OUString& rFormDescription ) throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( Mutex ); + + sal_Int32 nIndex = 0; + sal_uInt16 nPaperBin = sal::static_int_cast< sal_uInt16 >( + rFormDescription.getToken( 3, ';', nIndex ).toInt32()); + GetPrinter()->SetPaperBin( nPaperBin ); +} + +::com::sun::star::uno::Sequence< sal_Int8 > VCLXPrinterPropertySet::getBinarySetup( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( Mutex ); + + SvMemoryStream aMem; + aMem << BINARYSETUPMARKER; + aMem << GetPrinter()->GetJobSetup(); + return ::com::sun::star::uno::Sequence<sal_Int8>( (sal_Int8*) aMem.GetData(), aMem.Tell() ); +} + +void VCLXPrinterPropertySet::setBinarySetup( const ::com::sun::star::uno::Sequence< sal_Int8 >& data ) throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( Mutex ); + + SvMemoryStream aMem( (char*) data.getConstArray(), data.getLength(), STREAM_READ ); + sal_uInt32 nMarker; + aMem >> nMarker; + DBG_ASSERT( nMarker == BINARYSETUPMARKER, "setBinarySetup - invalid!" ); + if ( nMarker == BINARYSETUPMARKER ) + { + JobSetup aSetup; + aMem >> aSetup; + GetPrinter()->SetJobSetup( aSetup ); + } +} + + +// ---------------------------------------------------- +// class VCLXPrinter +// ---------------------------------------------------- +VCLXPrinter::VCLXPrinter( const String& rPrinterName ) + : VCLXPrinterPropertySet( rPrinterName ) +{ +} + +VCLXPrinter::~VCLXPrinter() +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXPrinter::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XPrinter*, this ) ); + + if ( !aRet.hasValue() ) + aRet = VCLXPrinterPropertySet::queryInterface( rType ); + + return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXPrinter ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPrinter>* ) NULL ), + VCLXPrinterPropertySet::getTypes() +IMPL_XTYPEPROVIDER_END + +sal_Bool VCLXPrinter::start( const ::rtl::OUString& /*rJobName*/, sal_Int16 /*nCopies*/, sal_Bool /*bCollate*/ ) throw(::com::sun::star::awt::PrinterException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( Mutex ); + + sal_Bool bDone = sal_True; + if ( mpListener.get() ) + { + maInitJobSetup = mpPrinter->GetJobSetup(); + mpListener.reset( new vcl::OldStylePrintAdaptor( mpPrinter ) ); + } + + return bDone; +} + +void VCLXPrinter::end( ) throw(::com::sun::star::awt::PrinterException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( Mutex ); + + if ( mpListener.get() ) + { + Printer::PrintJob( mpListener, maInitJobSetup ); + mpListener.reset(); + } +} + +void VCLXPrinter::terminate( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( Mutex ); + + mpListener.reset(); +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > VCLXPrinter::startPage( ) throw(::com::sun::star::awt::PrinterException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( Mutex ); + + if ( mpListener.get() ) + { + mpListener->StartPage(); + } + return GetDevice(); +} + +void VCLXPrinter::endPage( ) throw(::com::sun::star::awt::PrinterException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( Mutex ); + + if ( mpListener.get() ) + { + mpListener->EndPage(); + } +} + + +// ---------------------------------------------------- +// class VCLXInfoPrinter +// ---------------------------------------------------- + +VCLXInfoPrinter::VCLXInfoPrinter( const String& rPrinterName ) + : VCLXPrinterPropertySet( rPrinterName ) +{ +} + +VCLXInfoPrinter::~VCLXInfoPrinter() +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXInfoPrinter::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XInfoPrinter*, this ) ); + + if ( !aRet.hasValue() ) + aRet = VCLXPrinterPropertySet::queryInterface( rType ); + + return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXInfoPrinter ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XInfoPrinter>* ) NULL ), + VCLXPrinterPropertySet::getTypes() +IMPL_XTYPEPROVIDER_END + +// ::com::sun::star::awt::XInfoPrinter +::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > VCLXInfoPrinter::createDevice( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( Mutex ); + + return GetDevice(); +} + +// ---------------------------------------------------- +// class VCLXPrinterServer +// ---------------------------------------------------- + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXPrinterServer::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XPrinterServer*, this ) ); + return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXPrinterServer ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPrinterServer>* ) NULL ) +IMPL_XTYPEPROVIDER_END + +// ::com::sun::star::awt::XPrinterServer +::com::sun::star::uno::Sequence< ::rtl::OUString > VCLXPrinterServer::getPrinterNames( ) throw(::com::sun::star::uno::RuntimeException) +{ + const std::vector<rtl::OUString>& rQueues = Printer::GetPrinterQueues(); + sal_uInt32 nPrinters = rQueues.size(); + + ::com::sun::star::uno::Sequence< ::rtl::OUString > aNames( nPrinters ); + for ( sal_uInt32 n = 0; n < nPrinters; n++ ) + aNames.getArray()[n] = rQueues[n]; + + return aNames; +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XPrinter > VCLXPrinterServer::createPrinter( const ::rtl::OUString& rPrinterName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPrinter > xP; + xP = new VCLXPrinter( rPrinterName ); + return xP; +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XInfoPrinter > VCLXPrinterServer::createInfoPrinter( const ::rtl::OUString& rPrinterName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XInfoPrinter > xP; + xP = new VCLXInfoPrinter( rPrinterName ); + return xP; +} + + + diff --git a/toolkit/source/awt/vclxregion.cxx b/toolkit/source/awt/vclxregion.cxx new file mode 100644 index 000000000000..3c4bbcad2d79 --- /dev/null +++ b/toolkit/source/awt/vclxregion.cxx @@ -0,0 +1,171 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + + +#include <toolkit/awt/vclxregion.hxx> +#include <toolkit/helper/macros.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <toolkit/helper/convert.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <rtl/memory.h> +#include <rtl/uuid.h> +#include <vcl/svapp.hxx> + +// ---------------------------------------------------- +// class VCLXRegion +// ---------------------------------------------------- +VCLXRegion::VCLXRegion() +{ +} + +VCLXRegion::~VCLXRegion() +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXRegion::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XRegion*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XUnoTunnel*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ) ); + return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); +} + +// ::com::sun::star::lang::XUnoTunnel +IMPL_XUNOTUNNEL( VCLXRegion ) + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXRegion ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion>* ) NULL ) +IMPL_XTYPEPROVIDER_END + + + +::com::sun::star::awt::Rectangle VCLXRegion::getBounds() throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return AWTRectangle( maRegion.GetBoundRect() ); +} + +void VCLXRegion::clear() throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maRegion.SetEmpty(); +} + +void VCLXRegion::move( sal_Int32 nHorzMove, sal_Int32 nVertMove ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maRegion.Move( nHorzMove, nVertMove ); +} + +void VCLXRegion::unionRectangle( const ::com::sun::star::awt::Rectangle& rRect ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maRegion.Union( VCLRectangle( rRect ) ); +} + +void VCLXRegion::intersectRectangle( const ::com::sun::star::awt::Rectangle& rRect ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maRegion.Intersect( VCLRectangle( rRect ) ); +} + +void VCLXRegion::excludeRectangle( const ::com::sun::star::awt::Rectangle& rRect ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maRegion.Exclude( VCLRectangle( rRect ) ); +} + +void VCLXRegion::xOrRectangle( const ::com::sun::star::awt::Rectangle& rRect ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maRegion.XOr( VCLRectangle( rRect ) ); +} + +void VCLXRegion::unionRegion( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion >& rxRegion ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( rxRegion.is() ) + maRegion.Union( VCLUnoHelper::GetRegion( rxRegion ) ); +} + +void VCLXRegion::intersectRegion( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion >& rxRegion ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( rxRegion.is() ) + maRegion.Intersect( VCLUnoHelper::GetRegion( rxRegion ) ); +} + +void VCLXRegion::excludeRegion( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion >& rxRegion ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( rxRegion.is() ) + maRegion.Exclude( VCLUnoHelper::GetRegion( rxRegion ) ); +} + +void VCLXRegion::xOrRegion( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion >& rxRegion ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if ( rxRegion.is() ) + maRegion.XOr( VCLUnoHelper::GetRegion( rxRegion ) ); +} + +::com::sun::star::uno::Sequence< ::com::sun::star::awt::Rectangle > VCLXRegion::getRectangles() throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ULONG nRects = maRegion.GetRectCount(); + ::com::sun::star::uno::Sequence< ::com::sun::star::awt::Rectangle > aRects( nRects ); + + Rectangle aRect; + sal_uInt32 nR = 0; + RegionHandle h = maRegion.BeginEnumRects(); + while ( maRegion.GetNextEnumRect( h, aRect ) ) + aRects.getArray()[nR++] = AWTRectangle( aRect ); + maRegion.EndEnumRects( h ); + + return aRects; +} + + + diff --git a/toolkit/source/awt/vclxscroller.cxx b/toolkit/source/awt/vclxscroller.cxx new file mode 100644 index 000000000000..834632a7548b --- /dev/null +++ b/toolkit/source/awt/vclxscroller.cxx @@ -0,0 +1,212 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vclxscroller.hxx" + +#include <assert.h> +#include <com/sun/star/awt/PosSize.hpp> +#include <com/sun/star/awt/ScrollBarOrientation.hpp> +#include <sal/macros.h> +#include <toolkit/helper/property.hxx> +#include <tools/debug.hxx> +#include <vcl/scrbar.hxx> + +#include "forward.hxx" + +namespace layoutimpl +{ + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star; + +DBG_NAME( VCLXScroller ) + +VCLXScroller::VCLXScroller() + : VCLXWindow() + , Bin() +{ + DBG_CTOR( VCLXScroller, NULL ); + mpHorScrollBar = mpVerScrollBar = 0; +} + +VCLXScroller::~VCLXScroller() +{ + DBG_DTOR( VCLXScroller, NULL ); +} + +IMPLEMENT_2_FORWARD_XINTERFACE1( VCLXScroller, VCLXWindow, Container ); + +IMPLEMENT_FORWARD_XTYPEPROVIDER1( VCLXScroller, VCLXWindow ); + +void SAL_CALL VCLXScroller::dispose() throw(RuntimeException) +{ + { + ::vos::OGuard aGuard( GetMutex() ); + + EventObject aDisposeEvent; + aDisposeEvent.Source = W3K_EXPLICIT_CAST (*this); +// maTabListeners.disposeAndClear( aDisposeEvent ); + } + + VCLXWindow::dispose(); +} + +void VCLXScroller::ensureScrollBars() +{ + + if ( !mpVerScrollBar ) + { + mpVerScrollBar = new ScrollBar( GetWindow() , WB_VERT ); + mpVerScrollBar->SetLineSize( 4 ); + mpVerScrollBar->SetPageSize( 15 ); + mpVerScrollBar->Show(); + mpVerScrollBar->SetScrollHdl( LINK( this, VCLXScroller, ScrollHdl ) ); + } + if ( !mpHorScrollBar ) + { + mpHorScrollBar = new ScrollBar( GetWindow() , WB_HORZ ); + mpHorScrollBar->SetLineSize( 4 ); + mpHorScrollBar->SetPageSize( 15 ); + mpHorScrollBar->Show(); + mpHorScrollBar->SetScrollHdl( LINK( this, VCLXScroller, ScrollHdl ) ); + } // mpContent = new FixedImage( this, ImplGetWinBits( WindowAttributes, 0 ) ); + +} + +void SAL_CALL VCLXScroller::allocateArea( + const ::com::sun::star::awt::Rectangle &rArea ) + throw (::com::sun::star::uno::RuntimeException) +{ + ensureScrollBars(); // shouldn't be needed + + maAllocation = rArea; + setPosSize( rArea.X, rArea.Y, rArea.Width, rArea.Height, PosSize::POSSIZE ); + + mpHorScrollBar->SetRangeMin( 0 ); + mpHorScrollBar->SetRangeMax( SAL_MAX( maChildRequisition.Width - rArea.Width, 0 ) ); + mpVerScrollBar->SetRangeMin( 0 ); + mpVerScrollBar->SetRangeMax( SAL_MAX( maChildRequisition.Height - rArea.Height, 0 ) ); + + int thumbX = mpHorScrollBar->GetThumbPos(); + int thumbY = mpVerScrollBar->GetThumbPos(); + int thumbWidth = mpVerScrollBar->GetSizePixel().getWidth(); + int thumbHeight = mpHorScrollBar->GetSizePixel().getHeight(); + + mpHorScrollBar->SetPosSizePixel( rArea.X, rArea.Y + rArea.Height - thumbHeight - 2, + rArea.Width - thumbWidth, thumbHeight ); + mpVerScrollBar->SetPosSizePixel( rArea.X + rArea.Width - thumbWidth - 2, rArea.Y-2, + thumbWidth, rArea.Height - thumbHeight ); + + awt::Rectangle childRect( rArea.X - thumbX, rArea.Y - thumbY, + SAL_MAX( maChildRequisition.Width, rArea.Width ) - thumbWidth - 4, + SAL_MAX( maChildRequisition.Height, rArea.Height ) - thumbHeight - 4 ); + if ( mxChild.is() ) + allocateChildAt( mxChild, childRect ); +} + +#define MAX_CHILD_REQ 40 +::com::sun::star::awt::Size SAL_CALL VCLXScroller::getMinimumSize() + throw(::com::sun::star::uno::RuntimeException) +{ + ensureScrollBars(); + assert( mpHorScrollBar && mpVerScrollBar ); + awt::Size childSize = Bin::getMinimumSize(); + int thumbWidth = mpVerScrollBar->GetSizePixel().getWidth(); + int thumbHeight = mpHorScrollBar->GetSizePixel().getHeight(); + maRequisition = awt::Size( + SAL_MIN( MAX_CHILD_REQ, childSize.Width ) + thumbWidth, + SAL_MIN( MAX_CHILD_REQ, childSize.Height ) + thumbHeight ); + return maRequisition; +} + +void VCLXScroller::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ) +{ +/* + ::vos::OClearableGuard aGuard( GetMutex() ); + + switch ( _rVclWindowEvent.GetId() ) + { + default: + aGuard.clear(); +*/ + VCLXWindow::ProcessWindowEvent( _rVclWindowEvent ); +/* + break; + } +*/ +} + +void SAL_CALL VCLXScroller::setProperty( const ::rtl::OUString& PropertyName, const Any &Value ) throw(RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + { +/* + sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); + switch ( nPropertyId ) + { + default: +*/ + VCLXWindow::setProperty( PropertyName, Value ); +/* + } +*/ + } +} + +Any SAL_CALL VCLXScroller::getProperty( const ::rtl::OUString& PropertyName ) throw(RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Any aReturn; + if ( GetWindow() ) + { +/* + sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); + switch ( nPropertyId ) + { + default: +*/ + aReturn = VCLXWindow::getProperty( PropertyName ); + +// } + } + return aReturn; +} + +IMPL_LINK( VCLXScroller, ScrollHdl, ScrollBar *, pScrollBar ) +{ + (void) pScrollBar; + forceRecalc(); + return 0; +} + +} // namespace layoutimpl diff --git a/toolkit/source/awt/vclxscroller.hxx b/toolkit/source/awt/vclxscroller.hxx new file mode 100644 index 000000000000..be2524020c72 --- /dev/null +++ b/toolkit/source/awt/vclxscroller.hxx @@ -0,0 +1,87 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_AWT_VCLXSCROLLER_HXX +#define LAYOUT_AWT_VCLXSCROLLER_HXX + +#include <comphelper/uno3.hxx> +#include <layout/core/bin.hxx> +#include <toolkit/awt/vclxwindow.hxx> + +class ScrollBar; +class FixedImage; + +namespace layoutimpl +{ + +class VCLXScroller :public VCLXWindow + ,public Bin +{ +public: + VCLXScroller(); + +protected: + ~VCLXScroller(); + + // XInterface + DECLARE_XINTERFACE() + + // XTypeProvider + DECLARE_XTYPEPROVIDER() + + // XComponent + void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException); + + // ::com::sun::star::awt::XLayoutContainer + virtual void SAL_CALL allocateArea( const ::com::sun::star::awt::Rectangle &rArea ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::awt::Size SAL_CALL getMinimumSize() + throw(::com::sun::star::uno::RuntimeException); + + // VclWindowPeer + virtual void SAL_CALL setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value ) throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException); + + // VCLXWindow + void ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ); + +private: + VCLXScroller( const VCLXScroller& ); // never implemented + VCLXScroller& operator=( const VCLXScroller& ); // never implemented + + // because the underlying window is only setup-ed after construction, init + // scrollbars at play-time + void ensureScrollBars(); + + FixedImage *mpContent; // dummy + ScrollBar *mpHorScrollBar, *mpVerScrollBar; + DECL_LINK( ScrollHdl, ScrollBar* ); +}; + +} // namespace layoutimpl + +#endif /* LAYOUT_AWT_VCLXSCROLLER_HXX */ diff --git a/toolkit/source/awt/vclxspinbutton.cxx b/toolkit/source/awt/vclxspinbutton.cxx new file mode 100644 index 000000000000..e9c2b3271396 --- /dev/null +++ b/toolkit/source/awt/vclxspinbutton.cxx @@ -0,0 +1,355 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include "toolkit/awt/vclxspinbutton.hxx" +#include "toolkit/helper/property.hxx" +#include <com/sun/star/awt/ScrollBarOrientation.hpp> + + +#include <tools/debug.hxx> +#include <vcl/spin.hxx> + +namespace toolkit +{ + void setButtonLikeFaceColor( Window* _pWindow, const ::com::sun::star::uno::Any& _rColorValue ); + ::com::sun::star::uno::Any getButtonLikeFaceColor( const Window* _pWindow ); +} + +//........................................................................ +namespace toolkit +{ +//........................................................................ + + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::awt; + using namespace ::com::sun::star::lang; + using namespace ::com::sun::star::beans; + + //-------------------------------------------------------------------- + namespace + { + void lcl_modifyStyle( Window* _pWindow, WinBits _nStyleBits, sal_Bool _bShouldBePresent ) + { + WinBits nStyle = _pWindow->GetStyle(); + if ( _bShouldBePresent ) + nStyle |= _nStyleBits; + else + nStyle &= ~_nStyleBits; + _pWindow->SetStyle( nStyle ); + } + } + + //==================================================================== + //= VCLXSpinButton + //==================================================================== + DBG_NAME( VCLXSpinButton ) + //-------------------------------------------------------------------- + VCLXSpinButton::VCLXSpinButton() + :maAdjustmentListeners( *this ) + { + DBG_CTOR( VCLXSpinButton, NULL ); + } + + //-------------------------------------------------------------------- + VCLXSpinButton::~VCLXSpinButton() + { + DBG_DTOR( VCLXSpinButton, NULL ); + } + + //-------------------------------------------------------------------- + IMPLEMENT_FORWARD_XINTERFACE2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base ) + + //-------------------------------------------------------------------- + IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base ) + + //-------------------------------------------------------------------- + void SAL_CALL VCLXSpinButton::dispose( ) throw(RuntimeException) + { + { + ::vos::OGuard aGuard( GetMutex() ); + + EventObject aDisposeEvent; + aDisposeEvent.Source = *this; + maAdjustmentListeners.disposeAndClear( aDisposeEvent ); + } + + VCLXWindow::dispose(); + } + + //-------------------------------------------------------------------- + void SAL_CALL VCLXSpinButton::addAdjustmentListener( const Reference< XAdjustmentListener >& listener ) throw (RuntimeException) + { + if ( listener.is() ) + maAdjustmentListeners.addInterface( listener ); + } + + //-------------------------------------------------------------------- + void SAL_CALL VCLXSpinButton::removeAdjustmentListener( const Reference< XAdjustmentListener >& listener ) throw (RuntimeException) + { + if ( listener.is() ) + maAdjustmentListeners.removeInterface( listener ); + } + + namespace + { + typedef void (SpinButton::*SetSpinButtonValue) (long); + typedef long (SpinButton::*GetSpinButtonValue) (void) const; + + //................................................................ + void lcl_setSpinButtonValue( ::vos::IMutex& _rMutex, Window* _pWindow, SetSpinButtonValue _pSetter, sal_Int32 _nValue ) + { + ::vos::OGuard aGuard( _rMutex ); + + SpinButton* pSpinButton = static_cast< SpinButton* >( _pWindow ); + if ( pSpinButton ) + (pSpinButton->*_pSetter)( _nValue ); + } + + //................................................................ + sal_Int32 lcl_getSpinButtonValue( ::vos::IMutex& _rMutex, const Window* _pWindow, GetSpinButtonValue _pGetter ) + { + ::vos::OGuard aGuard( _rMutex ); + + sal_Int32 nValue = 0; + + const SpinButton* pSpinButton = static_cast< const SpinButton* >( _pWindow ); + if ( pSpinButton ) + nValue = (pSpinButton->*_pGetter)( ); + return nValue; + } + } + + //-------------------------------------------------------------------- + void SAL_CALL VCLXSpinButton::setValue( sal_Int32 n ) throw (RuntimeException) + { + lcl_setSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::SetValue, n ); + } + + //-------------------------------------------------------------------- + void SAL_CALL VCLXSpinButton::setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue ) throw (RuntimeException) + { + ::vos::OGuard aGuard( GetMutex() ); + + setMinimum( minValue ); + setMaximum( maxValue ); + setValue( currentValue ); + } + + //-------------------------------------------------------------------- + sal_Int32 SAL_CALL VCLXSpinButton::getValue( ) throw (RuntimeException) + { + return lcl_getSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::GetValue ); + } + + //-------------------------------------------------------------------- + void SAL_CALL VCLXSpinButton::setMinimum( sal_Int32 minValue ) throw (RuntimeException) + { + lcl_setSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::SetRangeMin, minValue ); + } + + //-------------------------------------------------------------------- + void SAL_CALL VCLXSpinButton::setMaximum( sal_Int32 maxValue ) throw (RuntimeException) + { + lcl_setSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::SetRangeMax, maxValue ); + } + + //-------------------------------------------------------------------- + sal_Int32 SAL_CALL VCLXSpinButton::getMinimum( ) throw (RuntimeException) + { + return lcl_getSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::GetRangeMin ); + } + + //-------------------------------------------------------------------- + sal_Int32 SAL_CALL VCLXSpinButton::getMaximum( ) throw (RuntimeException) + { + return lcl_getSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::GetRangeMax ); + } + + //-------------------------------------------------------------------- + void SAL_CALL VCLXSpinButton::setSpinIncrement( sal_Int32 spinIncrement ) throw (RuntimeException) + { + lcl_setSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::SetValueStep, spinIncrement ); + } + + //-------------------------------------------------------------------- + sal_Int32 SAL_CALL VCLXSpinButton::getSpinIncrement( ) throw (RuntimeException) + { + return lcl_getSpinButtonValue( GetMutex(), GetWindow(), &SpinButton::GetValueStep ); + } + + //-------------------------------------------------------------------- + void SAL_CALL VCLXSpinButton::setOrientation( sal_Int32 orientation ) throw (NoSupportException, RuntimeException) + { + ::vos::OGuard aGuard( GetMutex() ); + + lcl_modifyStyle( GetWindow(), WB_HSCROLL, orientation == ScrollBarOrientation::HORIZONTAL ); + } + + //-------------------------------------------------------------------- + sal_Int32 SAL_CALL VCLXSpinButton::getOrientation( ) throw (RuntimeException) + { + return ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL ) ) + ? ScrollBarOrientation::HORIZONTAL + : ScrollBarOrientation::VERTICAL; + } + + //-------------------------------------------------------------------- + void VCLXSpinButton::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ) + { + ::vos::OClearableGuard aGuard( GetMutex() ); + Reference< XSpinValue > xKeepAlive( this ); + SpinButton* pSpinButton = static_cast< SpinButton* >( GetWindow() ); + if ( !pSpinButton ) + return; + + switch ( _rVclWindowEvent.GetId() ) + { + case VCLEVENT_SPINBUTTON_UP: + case VCLEVENT_SPINBUTTON_DOWN: + if ( maAdjustmentListeners.getLength() ) + { + AdjustmentEvent aEvent; + aEvent.Source = *this; + aEvent.Value = pSpinButton->GetValue(); + + aGuard.clear(); + maAdjustmentListeners.adjustmentValueChanged( aEvent ); + } + break; + + default: + xKeepAlive.clear(); + aGuard.clear(); + VCLXWindow::ProcessWindowEvent( _rVclWindowEvent ); + break; + } + } + + //-------------------------------------------------------------------- + void SAL_CALL VCLXSpinButton::setProperty( const ::rtl::OUString& PropertyName, const Any& Value ) throw(RuntimeException) + { + ::vos::OGuard aGuard( GetMutex() ); + + sal_Int32 nValue = 0; + sal_Bool bIsLongValue = ( Value >>= nValue ); + + if ( GetWindow() ) + { + sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); + switch ( nPropertyId ) + { + case BASEPROPERTY_BACKGROUNDCOLOR: + // the default implementation of the base class doesn't work here, since our + // interpretation for this property is slightly different + setButtonLikeFaceColor( GetWindow(), Value); + break; + + case BASEPROPERTY_SPINVALUE: + if ( bIsLongValue ) + setValue( nValue ); + break; + + case BASEPROPERTY_SPINVALUE_MIN: + if ( bIsLongValue ) + setMinimum( nValue ); + break; + + case BASEPROPERTY_SPINVALUE_MAX: + if ( bIsLongValue ) + setMaximum( nValue ); + break; + + case BASEPROPERTY_SPININCREMENT: + if ( bIsLongValue ) + setSpinIncrement( nValue ); + break; + + case BASEPROPERTY_ORIENTATION: + if ( bIsLongValue ) + lcl_modifyStyle( GetWindow(), WB_HSCROLL, nValue == ScrollBarOrientation::HORIZONTAL ); + break; + + default: + VCLXWindow::setProperty( PropertyName, Value ); + } + } + } + + //-------------------------------------------------------------------- + Any SAL_CALL VCLXSpinButton::getProperty( const ::rtl::OUString& PropertyName ) throw(RuntimeException) + { + ::vos::OGuard aGuard( GetMutex() ); + + Any aReturn; + + if ( GetWindow() ) + { + sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); + switch ( nPropertyId ) + { + case BASEPROPERTY_BACKGROUNDCOLOR: + // the default implementation of the base class doesn't work here, since our + // interpretation for this property is slightly different + aReturn = getButtonLikeFaceColor( GetWindow() ); + break; + + case BASEPROPERTY_SPINVALUE: + aReturn <<= (sal_Int32)getValue( ); + break; + + case BASEPROPERTY_SPINVALUE_MIN: + aReturn <<= (sal_Int32)getMinimum( ); + break; + + case BASEPROPERTY_SPINVALUE_MAX: + aReturn <<= (sal_Int32)getMaximum( ); + break; + + case BASEPROPERTY_SPININCREMENT: + aReturn <<= (sal_Int32)getSpinIncrement( ); + break; + + case BASEPROPERTY_ORIENTATION: + aReturn <<= (sal_Int32) + ( ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL ) ) + ? ScrollBarOrientation::HORIZONTAL + : ScrollBarOrientation::VERTICAL + ); + break; + + default: + aReturn = VCLXWindow::getProperty( PropertyName ); + } + } + return aReturn; + } + +//........................................................................ +} // namespace toolkit +//........................................................................ diff --git a/toolkit/source/awt/vclxsplitter.cxx b/toolkit/source/awt/vclxsplitter.cxx new file mode 100644 index 000000000000..07fcf96cb813 --- /dev/null +++ b/toolkit/source/awt/vclxsplitter.cxx @@ -0,0 +1,245 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vclxsplitter.hxx" + +#include <assert.h> +#include <com/sun/star/awt/PosSize.hpp> +#include <sal/macros.h> +#include <toolkit/helper/property.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <vcl/split.hxx> + +#include "forward.hxx" + +namespace layoutimpl +{ + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star; + +VCLXSplitter::ChildProps::ChildProps( VCLXSplitter::ChildData *pData ) +{ + addProp( RTL_CONSTASCII_USTRINGPARAM( "Shrink" ), + ::getCppuType( static_cast< const rtl::OUString* >( NULL ) ), + &(pData->mbShrink) ); +} + +VCLXSplitter::ChildData::ChildData( uno::Reference< awt::XLayoutConstrains > const& xChild ) + : Box_Base::ChildData( xChild ) + , mbShrink( false ) +{ +} + +VCLXSplitter::ChildData* +VCLXSplitter::createChild( uno::Reference< awt::XLayoutConstrains > const& xChild ) +{ + return new ChildData( xChild ); +} + +VCLXSplitter::ChildProps* +VCLXSplitter::createChildProps( Box_Base::ChildData *pData ) +{ + return new ChildProps( static_cast<VCLXSplitter::ChildData*> ( pData ) ); +} + + +DBG_NAME( VCLXSplitter ); + +VCLXSplitter::VCLXSplitter( bool bHorizontal ) + : VCLXWindow() + , Box_Base() +{ + DBG_CTOR( VCLXSplitter, NULL ); + mnHandleRatio = 0.5; + mbHandlePressed = false; + mbHorizontal = bHorizontal; + mpSplitter = NULL; +} + +VCLXSplitter::~VCLXSplitter() +{ + DBG_DTOR( VCLXSplitter, NULL ); +} + +IMPLEMENT_2_FORWARD_XINTERFACE1( VCLXSplitter, VCLXWindow, Container ); + +IMPLEMENT_FORWARD_XTYPEPROVIDER1( VCLXSplitter, VCLXWindow ); + +VCLXSplitter::ChildData* +VCLXSplitter::getChild( int i ) +{ + if ( maChildren.size() && i == 0 ) + return static_cast<VCLXSplitter::ChildData*>( maChildren.front() ); + else if ( maChildren.size() > 1 && i == 1 ) + return static_cast<VCLXSplitter::ChildData*>( maChildren.back() ); + return 0; +} + +void SAL_CALL VCLXSplitter::dispose() throw(RuntimeException) +{ + { + ::vos::OGuard aGuard( GetMutex() ); + + EventObject aDisposeEvent; + aDisposeEvent.Source = W3K_EXPLICIT_CAST (*this); +// maTabListeners.disposeAndClear( aDisposeEvent ); + } + + VCLXWindow::dispose(); +} + +void VCLXSplitter::ensureSplitter() +{ + if ( !mpSplitter ) + { + mpSplitter = new Splitter( GetWindow() , mbHorizontal ? WB_HORZ : WB_VERT ); + mpSplitter->Show(); + mpSplitter->SetEndSplitHdl( LINK( this, VCLXSplitter, HandleMovedHdl ) ); + } +} + +void SAL_CALL VCLXSplitter::addChild( + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains > &xChild ) + throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::awt::MaxChildrenException) +{ + if ( maChildren.size() == 2 ) + throw css::awt::MaxChildrenException(); + Box_Base::addChild( xChild ); +} + +void SAL_CALL VCLXSplitter::allocateArea( + const ::com::sun::star::awt::Rectangle &rArea ) + throw (::com::sun::star::uno::RuntimeException) +{ + ensureSplitter(); // shouldn't be needed... + getMinimumSize(); + int splitDiff; + if ( mbHorizontal ) + splitDiff = rArea.Width - maAllocation.Width; + else + splitDiff = rArea.Height - maAllocation.Height; + + assert( mpSplitter ); + if ( splitDiff ) + mpSplitter->SetSplitPosPixel( mpSplitter->GetSplitPosPixel() + splitDiff/2 ); + + maAllocation = rArea; + int width = mbHorizontal ? rArea.Width : rArea.Height; + int splitLen = 2; + int splitPos = mpSplitter->GetSplitPosPixel(); + setPosSize( rArea.X, rArea.Y, rArea.Width, rArea.Height, PosSize::POSSIZE ); + if ( mbHorizontal ) + mpSplitter->SetPosSizePixel( splitPos, 0, splitLen, rArea.Height, PosSize::POSSIZE ); + else + mpSplitter->SetPosSizePixel( 0, splitPos, rArea.Width, splitLen, PosSize::POSSIZE ); + mpSplitter->SetDragRectPixel( ::Rectangle( 0, 0, rArea.Width, rArea.Height ) ); + int leftWidth = splitPos; + int rightWidth = width - splitPos; + + if ( getChild( 0 ) && getChild( 0 )->mxChild.is() ) + { + awt::Rectangle childRect( 0, 0, rArea.Width, rArea.Height ); + + if ( mbHorizontal ) + childRect.Width = leftWidth - 2; + else + childRect.Height = leftWidth - 2; + allocateChildAt( getChild( 0 )->mxChild, childRect ); + } + if ( getChild( 0 ) && getChild( 0 )->mxChild.is() ) + { + awt::Rectangle childRect( 0, 0, rArea.Width, rArea.Height ); + + if ( mbHorizontal ) + { + childRect.X += leftWidth + splitLen + 2; + childRect.Width = rightWidth; + } + else + { + childRect.Y += leftWidth + splitLen + 2; + childRect.Height = rightWidth; + } + allocateChildAt( getChild( 1 )->mxChild, childRect ); + } +} + +::com::sun::star::awt::Size SAL_CALL VCLXSplitter::getMinimumSize() + throw(::com::sun::star::uno::RuntimeException) +{ + ensureSplitter(); + + awt::Size size( mbHorizontal ? 2 : 0, mbHorizontal ? 0 : 2 ); + for ( unsigned int i = 0; i < 2; i++ ) + { + if ( getChild( i ) && getChild( i )->mxChild.is() ) + { + awt::Size childSize = getChild( i )->mxChild->getMinimumSize(); + if ( mbHorizontal ) + { + size.Width += childSize.Width; + size.Height = SAL_MAX( size.Height, childSize.Height ); + } + else + { + size.Width = SAL_MAX( size.Width, childSize.Width ); + size.Height += childSize.Height; + } + } + } + + maRequisition = size; + return size; +} + +void VCLXSplitter::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ) +{ + VCLXWindow::ProcessWindowEvent( _rVclWindowEvent ); +} + +void SAL_CALL VCLXSplitter::setProperty( const ::rtl::OUString& PropertyName, const Any &Value ) throw(RuntimeException) +{ + VCLXWindow::setProperty( PropertyName, Value ); +} + +Any SAL_CALL VCLXSplitter::getProperty( const ::rtl::OUString& PropertyName ) throw(RuntimeException) +{ + return VCLXWindow::getProperty( PropertyName ); +} + +IMPL_LINK( VCLXSplitter, HandleMovedHdl, Splitter *, pSplitter ) +{ + (void) pSplitter; + forceRecalc(); + return 0; +} + +} // namespace layoutimpl diff --git a/toolkit/source/awt/vclxsplitter.hxx b/toolkit/source/awt/vclxsplitter.hxx new file mode 100644 index 000000000000..69be466e6be8 --- /dev/null +++ b/toolkit/source/awt/vclxsplitter.hxx @@ -0,0 +1,121 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_AWT_VCLXSPLITTER_HXX +#define LAYOUT_AWT_VCLXSPLITTER_HXX + +#include <com/sun/star/awt/MaxChildrenException.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <comphelper/uno3.hxx> +#include <layout/core/box-base.hxx> +#include <toolkit/awt/vclxwindow.hxx> + +class Splitter; + +namespace layoutimpl +{ + +class VCLXSplitter :public VCLXWindow + ,public Box_Base +{ +private: + VCLXSplitter( const VCLXSplitter& ); // never implemented + VCLXSplitter& operator=( const VCLXSplitter& ); // never implemented + +public: + VCLXSplitter( bool bHorizontal ); + +protected: + ~VCLXSplitter(); + + // XInterface + DECLARE_XINTERFACE() + + // XTypeProvider + DECLARE_XTYPEPROVIDER() + + // XComponent + void SAL_CALL dispose( ) throw(::com::sun::star::uno::RuntimeException); + + // ::com::sun::star::awt::XLayoutContainer + virtual void SAL_CALL addChild( + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains >& Child ) + throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::awt::MaxChildrenException); + + virtual void SAL_CALL allocateArea( const ::com::sun::star::awt::Rectangle &rArea ) + throw (::com::sun::star::uno::RuntimeException); + + virtual ::com::sun::star::awt::Size SAL_CALL getMinimumSize() + throw(::com::sun::star::uno::RuntimeException); + + // unimplemented: + virtual sal_Bool SAL_CALL hasHeightForWidth() + throw(css::uno::RuntimeException) + { return false; } + virtual sal_Int32 SAL_CALL getHeightForWidth( sal_Int32 /*nWidth*/ ) + throw(css::uno::RuntimeException) + { return maRequisition.Height; } + + // VclWindowPeer + virtual void SAL_CALL setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value ) throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException); + + // VCLXWindow + void ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ); + +public: + // Maps page ids to child references + struct ChildData : public Box_Base::ChildData + { + sal_Bool mbShrink; + ChildData( css::uno::Reference< css::awt::XLayoutConstrains > const& xChild ); + }; + + struct ChildProps : public Box_Base::ChildProps + { + ChildProps( VCLXSplitter::ChildData *pData ); + }; + +protected: + + ChildData *createChild( css::uno::Reference< css::awt::XLayoutConstrains > const& xChild ); + ChildProps *createChildProps( Box_Base::ChildData* pData ); + + ChildData* getChild( int i ); + + float mnHandleRatio; + bool mbHandlePressed; + + DECL_LINK( HandleMovedHdl, Splitter* ); + bool mbHorizontal; + Splitter *mpSplitter; + void ensureSplitter(); +}; + +} // namespace layoutimpl + +#endif /* LAYOUT_AWT_VCLXSPLITTER_HXX */ diff --git a/toolkit/source/awt/vclxsystemdependentwindow.cxx b/toolkit/source/awt/vclxsystemdependentwindow.cxx new file mode 100644 index 000000000000..a0d8febb44f0 --- /dev/null +++ b/toolkit/source/awt/vclxsystemdependentwindow.cxx @@ -0,0 +1,124 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + + +#include <com/sun/star/lang/SystemDependent.hpp> + +#if defined UNX && ! defined QUARTZ && ! defined _COM_SUN_STAR_AWT_SYSTEMDEPENDENTXWINDOW_HPP_ +#include <com/sun/star/awt/SystemDependentXWindow.hpp> +#endif + +#include <toolkit/awt/vclxsystemdependentwindow.hxx> +#include <toolkit/helper/macros.hxx> +#include <cppuhelper/typeprovider.hxx> + +#ifdef WNT +#include <tools/prewin.h> +#include <windows.h> +#include <tools/postwin.h> +#elif defined ( QUARTZ ) +#include "premac.h" +#include <Cocoa/Cocoa.h> +#include "postmac.h" +#endif + +#include <vcl/syschild.hxx> +#include <vcl/sysdata.hxx> + +// ---------------------------------------------------- +// class VCLXSystemDependentWindow +// ---------------------------------------------------- +VCLXSystemDependentWindow::VCLXSystemDependentWindow() +{ +} + +VCLXSystemDependentWindow::~VCLXSystemDependentWindow() +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXSystemDependentWindow::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XSystemDependentWindowPeer*, this ) ); + return (aRet.hasValue() ? aRet : VCLXWindow::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXSystemDependentWindow ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XSystemDependentWindowPeer>* ) NULL ), + VCLXWindow::getTypes() +IMPL_XTYPEPROVIDER_END + +::com::sun::star::uno::Any VCLXSystemDependentWindow::getWindowHandle( const ::com::sun::star::uno::Sequence< sal_Int8 >& /*ProcessId*/, sal_Int16 SystemType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + // TODO, check the process id + ::com::sun::star::uno::Any aRet; + Window* pWindow = GetWindow(); + if ( pWindow ) + { + const SystemEnvData* pSysData = ((SystemChildWindow *)pWindow)->GetSystemData(); + if( pSysData ) + { +#if (defined WNT) + if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_WIN32 ) + { + aRet <<= (sal_Int32)pSysData->hWnd; + } +#elif (defined OS2) + if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_OS2 ) + { + aRet <<= (sal_Int32)pSysData->hWnd; + } +#elif (defined QUARTZ) + if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_MAC ) + { + aRet <<= (sal_IntPtr)pSysData->pView; + } +#elif (defined UNX) + if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_XWINDOW ) + { + ::com::sun::star::awt::SystemDependentXWindow aSD; + aSD.DisplayPointer = sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_IntPtr >(pSysData->pDisplay)); + aSD.WindowHandle = pSysData->aWindow; + aRet <<= aSD; + } +#endif + } + } + return aRet; +} + + + + + diff --git a/toolkit/source/awt/vclxtabcontrol.cxx b/toolkit/source/awt/vclxtabcontrol.cxx new file mode 100644 index 000000000000..1dfd52678957 --- /dev/null +++ b/toolkit/source/awt/vclxtabcontrol.cxx @@ -0,0 +1,540 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vclxtabcontrol.hxx" + +#include <com/sun/star/awt/PosSize.hpp> +#include <sal/macros.h> +#include <toolkit/helper/property.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <vcl/tabctrl.hxx> +#include <vcl/tabpage.hxx> + +#include "forward.hxx" + +namespace layoutimpl +{ + +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star; + +VCLXTabControl::ChildProps::ChildProps( VCLXTabControl::ChildData *pData ) +{ + addProp( RTL_CONSTASCII_USTRINGPARAM( "Title" ), + ::getCppuType( static_cast< const rtl::OUString* >( NULL ) ), + &(pData->maTitle) ); +} + +VCLXTabControl::ChildData::ChildData( uno::Reference< awt::XLayoutConstrains > const& xChild ) + : Box_Base::ChildData( xChild ) + , maTitle() +{ +} + +VCLXTabControl::ChildData* +VCLXTabControl::createChild( uno::Reference< awt::XLayoutConstrains > const& xChild ) +{ + return new ChildData( xChild ); +} + +VCLXTabControl::ChildProps* +VCLXTabControl::createChildProps( Box_Base::ChildData *pData ) +{ + return new ChildProps( static_cast<VCLXTabControl::ChildData*> ( pData ) ); +} + +DBG_NAME( VCLXTabControl ); + +#if !defined (__GNUC__) +#define __PRETTY_FUNCTION__ __FUNCTION__ +#endif /* !__GNUC__ */ + +VCLXTabControl::VCLXTabControl() + : VCLXWindow() + , VCLXTabControl_Base() + , Box_Base() + , mTabId (1) + , bRealized (false) +{ +#ifndef __SUNPRO_CC + OSL_TRACE ("\n********%s:%x", __PRETTY_FUNCTION__, this); +#endif + DBG_CTOR( VCLXTabControl, NULL ); +} + +VCLXTabControl::~VCLXTabControl() +{ + DBG_DTOR( VCLXTabControl, NULL ); +} + +IMPLEMENT_2_FORWARD_XINTERFACE2( VCLXTabControl, VCLXWindow, Container, VCLXTabControl_Base ); + +IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXTabControl, VCLXWindow, VCLXTabControl_Base ); + +void SAL_CALL VCLXTabControl::dispose( ) throw(uno::RuntimeException) +{ + { + ::vos::OGuard aGuard( GetMutex() ); + + EventObject aDisposeEvent; + aDisposeEvent.Source = W3K_EXPLICIT_CAST (*this); +// maTabListeners.disposeAndClear( aDisposeEvent ); + } + + VCLXWindow::dispose(); +} + +#if 0 +void SAL_CALL VCLXTabControl::addTabListener( const Reference< XTabListener >& listener ) throw (uno::RuntimeException) +{ + if ( listener.is() ) + maTabListeners.addInterface( listener ); +} + +void SAL_CALL VCLXTabControl::removeTabListener( const Reference< XTabListener >& listener ) throw (uno::RuntimeException) +{ + if ( listener.is() ) + maTabListeners.removeInterface( listener ); +} +#endif + +TabControl *VCLXTabControl::getTabControl() const throw (uno::RuntimeException) +{ + TabControl *pTabControl = static_cast< TabControl* >( GetWindow() ); + if ( pTabControl ) + return pTabControl; + throw uno::RuntimeException(); +} + +sal_Int32 SAL_CALL VCLXTabControl::insertTab() throw (uno::RuntimeException) +{ + TabControl *pTabControl = getTabControl(); + USHORT id = sal::static_int_cast< USHORT >( mTabId++ ); + rtl::OUString title (RTL_CONSTASCII_USTRINGPARAM( "" ) ); + pTabControl->InsertPage( id, title.getStr(), TAB_APPEND ); + pTabControl->SetTabPage( id, new TabPage( pTabControl ) ); + return id; +} + +void SAL_CALL VCLXTabControl::removeTab( sal_Int32 ID ) throw (uno::RuntimeException, IndexOutOfBoundsException) +{ + TabControl *pTabControl = getTabControl(); + if ( pTabControl->GetTabPage( sal::static_int_cast< USHORT >( ID ) ) == NULL ) + throw IndexOutOfBoundsException(); + pTabControl->RemovePage( sal::static_int_cast< USHORT >( ID ) ); +} + +void SAL_CALL VCLXTabControl::activateTab( sal_Int32 ID ) throw (uno::RuntimeException, IndexOutOfBoundsException) +{ + TabControl *pTabControl = getTabControl(); + if ( pTabControl->GetTabPage( sal::static_int_cast< USHORT >( ID ) ) == NULL ) + throw IndexOutOfBoundsException(); + pTabControl->SelectTabPage( sal::static_int_cast< USHORT >( ID ) ); +} + +sal_Int32 SAL_CALL VCLXTabControl::getActiveTabID() throw (uno::RuntimeException) +{ + return getTabControl()->GetCurPageId( ); +} + +void SAL_CALL VCLXTabControl::addTabListener( const uno::Reference< awt::XTabListener >& xListener ) throw (uno::RuntimeException) +{ + for ( std::list< uno::Reference + < awt::XTabListener > >::const_iterator it + = mxTabListeners.begin(); it != mxTabListeners.end(); it++ ) + { + if ( *it == xListener ) + // already added + return; + } + mxTabListeners.push_back( xListener ); +} + +void SAL_CALL VCLXTabControl::removeTabListener( const uno::Reference< awt::XTabListener >& xListener ) throw (uno::RuntimeException) +{ + for ( std::list< uno::Reference + < awt::XTabListener > >::iterator it + = mxTabListeners.begin(); it != mxTabListeners.end(); it++ ) + { + if ( *it == xListener ) + { + mxTabListeners.erase( it ); + break; + } + } +} + +void SAL_CALL VCLXTabControl::setTabProps( sal_Int32 ID, const uno::Sequence< NamedValue >& Properties ) throw (uno::RuntimeException, IndexOutOfBoundsException) +{ + TabControl *pTabControl = getTabControl(); + if ( pTabControl->GetTabPage( sal::static_int_cast< USHORT >( ID ) ) == NULL ) + throw IndexOutOfBoundsException(); + + for ( int i = 0; i < Properties.getLength(); i++ ) + { + const rtl::OUString &name = Properties[i].Name; + const uno::Any &value = Properties[i].Value; + + if ( name == rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ) ) + { + rtl::OUString title = value.get<rtl::OUString>(); + pTabControl->SetPageText( sal::static_int_cast< USHORT >( ID ), title.getStr() ); + } + } +} + +uno::Sequence< NamedValue > SAL_CALL VCLXTabControl::getTabProps( sal_Int32 ID ) + throw (IndexOutOfBoundsException, uno::RuntimeException) +{ + TabControl *pTabControl = getTabControl(); + if ( pTabControl->GetTabPage( sal::static_int_cast< USHORT >( ID ) ) == NULL ) + throw IndexOutOfBoundsException(); + +#define ADD_PROP( seq, i, name, val ) { \ + NamedValue value; \ + value.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( name ) ); \ + value.Value = uno::makeAny( val ); \ + seq[i] = value; \ + } + + uno::Sequence< NamedValue > props( 2 ); + ADD_PROP( props, 0, "Title", rtl::OUString( pTabControl->GetPageText( sal::static_int_cast< USHORT >( ID ) ) ) ); + ADD_PROP( props, 1, "Position", pTabControl->GetPagePos( sal::static_int_cast< USHORT >( ID ) ) ); +#undef ADD_PROP + return props; +} + +// TODO: draw tab border here +void SAL_CALL VCLXTabControl::draw( sal_Int32 nX, sal_Int32 nY ) throw(uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + TabControl *pTabControl = getTabControl(); + TabPage *pTabPage = pTabControl->GetTabPage( sal::static_int_cast< USHORT >( getActiveTabID() ) ); + if ( pTabPage ) + { + ::Point aPos( nX, nY ); + ::Size aSize = pTabPage->GetSizePixel(); + + OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( getGraphics() ); + aPos = pDev->PixelToLogic( aPos ); + aSize = pDev->PixelToLogic( aSize ); + + pTabPage->Draw( pDev, aPos, aSize, 0 ); + } + + VCLXWindow::draw( nX, nY ); +} + +void VCLXTabControl::AddChild (uno::Reference< awt::XLayoutConstrains > const& xChild) + +{ +#ifndef __SUNPRO_CC + OSL_TRACE ("%s: children: %d", __PRETTY_FUNCTION__, maChildren.size ()); +#endif + mIdMap[ xChild ] = mTabId++; + Box_Base::AddChild( xChild ); +#ifndef __SUNPRO_CC + OSL_TRACE ("%s: children: %d", __PRETTY_FUNCTION__, maChildren.size ()); +#endif +} + +void SAL_CALL VCLXTabControl::addChild( + const uno::Reference< awt::XLayoutConstrains > &xChild ) + throw (uno::RuntimeException, awt::MaxChildrenException) +{ + mIdMap[ xChild ] = insertTab(); + Box_Base::addChild( xChild ); +} + +void SAL_CALL VCLXTabControl::removeChild( const uno::Reference< awt::XLayoutConstrains > &xChild ) + throw (uno::RuntimeException) +{ + removeTab( mIdMap[xChild] ); + mIdMap[ xChild ] = -1; + Box_Base::removeChild( xChild ); +} + +static void setChildrenVisible( uno::Reference < awt::XLayoutConstrains > xChild, bool visible ) +{ + uno::Reference< awt::XWindow > xWin( xChild, uno::UNO_QUERY); + if ( xWin.is() ) + { + xWin->setVisible( visible ); + } + + uno::Reference < awt::XLayoutContainer > xCont( xChild, uno::UNO_QUERY ); + if ( xCont.is()) + { + uno::Sequence< uno::Reference < awt::XLayoutConstrains > > children = xCont->getChildren(); + for ( int i = 0; i < children.getLength(); i++ ) + { + setChildrenVisible( children[i], visible ); + } + } +} + +void SAL_CALL VCLXTabControl::allocateArea (awt::Rectangle const &area) + throw (uno::RuntimeException) +{ +#ifndef __SUNPRO_CC + OSL_TRACE ("\n%s", __PRETTY_FUNCTION__); +#endif + maAllocation = area; + + TabControl *pTabControl = getTabControl(); + +// FIXME: this is wrong. We just want to set tab controls pos/size for +// the tabs menu, otherwise, it gets events that should go to children +// (I guess we could solve this by making the tabcontrol as the actual +// XWindow parent of its children, when importing...) Not sure about +// TabPage drawing... That doesn't work on gtk+; just ignoring that. +// LATER: Nah, the proper fix is to get the XWindow hierarchy +// straight. + +#if 0 + setPosSize( area.X, area.Y, area.Width, area.Height, awt::PosSize::POSSIZE ); +#else + awt::Size currentSize = getSize(); + awt::Size requestedSize (area.Width, area.Height); +// requestedSize.Height = getHeightForWidth( area.Width ); + + awt::Size minimumSize = getMinimumSize(); + if (requestedSize.Width < minimumSize.Width) + requestedSize.Width = minimumSize.Width; + if (requestedSize.Height < minimumSize.Height) + requestedSize.Height = minimumSize.Height; + + Size pageSize = static_cast<TabControl*> (GetWindow ())->GetTabPageSizePixel (); + awt::Size pageBasedSize (0, 0); + pageBasedSize.Width = pageSize.Width (); + pageBasedSize.Height = pageSize.Height (); + + const int wc = 0; + const int hc = 20; + static int pwc = 0; + static int phc = 40; + + if (requestedSize.Width < pageBasedSize.Width) + requestedSize.Width = pageBasedSize.Width + wc; + if (requestedSize.Height < pageBasedSize.Height) + requestedSize.Height = pageBasedSize.Height + hc; + + Size windowSize = GetWindow()->GetSizePixel(); + Window *parent = GetWindow()->GetParent(); + Size parentSize = parent->GetSizePixel(); + +#ifndef __SUNPRO_CC +#ifdef GCC_MAJOR + OSL_TRACE ("\n%s", __PRETTY_FUNCTION__); +#endif /* GCC_MAJOR */ + OSL_TRACE ("%s: cursize: %d ,%d", __FUNCTION__, currentSize.Width, currentSize.Height ); + OSL_TRACE ("%s: area: %d, %d", __FUNCTION__, area.Width, area.Height ); + OSL_TRACE ("%s: minimum: %d, %d", __FUNCTION__, minimumSize.Width, minimumSize.Height ); + OSL_TRACE ("%s: requestedSize: %d, %d", __FUNCTION__, requestedSize.Width, requestedSize.Height ); + OSL_TRACE ("%s: pageBasedSize: %d, %d", __FUNCTION__, pageBasedSize.Width, pageBasedSize.Height ); + + //OSL_TRACE ("%s: parent: %d, %d", __FUNCTION__, parentSize.Width(), parentSize.Height() ); + //OSL_TRACE ("%s: window: %d, %d", __FUNCTION__, windowSize.Width(), windowSize.Height() ); +#endif + + //bRealized = false; + if (!bRealized) + { + setPosSize( area.X, area.Y, requestedSize.Width, requestedSize.Height, awt::PosSize::POSSIZE ); + bRealized = true; + } + else + { + if ( requestedSize.Width > currentSize.Width + 10) + setPosSize( 0, 0, requestedSize.Width, 0, awt::PosSize::WIDTH ); + if ( requestedSize.Height > currentSize.Height + 10) + setPosSize( 0, 0, 0, requestedSize.Height, awt::PosSize::HEIGHT ); + } +#endif + + if (pageBasedSize.Width > parentSize.Width () + || pageBasedSize.Height > parentSize.Height ()) + //parent->SetSizePixel ( Size (pageBasedSize.Width, pageBasedSize.Height)); + //parent->SetSizePixel ( Size (pageBasedSize.Width + pwc, pageBasedSize.Height + phc)); + parent->SetSizePixel ( Size (requestedSize.Width + pwc, requestedSize.Height + phc)); + + // FIXME: we can save cycles by setting visibility more sensibly. Having + // it here does makes it easier when changing tabs (just needs a recalc()) + unsigned i = 0; + for ( std::list<Box_Base::ChildData *>::const_iterator it + = maChildren.begin(); it != maChildren.end(); it++, i++ ) + { + ChildData *child = static_cast<VCLXTabControl::ChildData*> ( *it ); + uno::Reference + < awt::XLayoutConstrains > xChild( child->mxChild ); + if ( xChild.is() ) + { + uno::Reference< awt::XWindow > xWin( xChild, uno::UNO_QUERY ); + bool active = (i+1 == (unsigned) getActiveTabID()); + + // HACK: since our layout:: container don't implement XWindow, we have no easy + // way to set them invisible; lets just set all their children as such :P +#if 0 + if ( xWin.is() ) + xWin->setVisible( active ); +#else + setChildrenVisible( xChild, active ); +#endif + + if ( active ) + { + ::Rectangle label_rect = pTabControl->GetTabBounds( sal::static_int_cast< USHORT >( i+1 ) ); + ::Rectangle page_rect = pTabControl->GetTabPageBounds( sal::static_int_cast< USHORT >( i+1 ) ); + + awt::Rectangle childRect; + childRect.X = page_rect.Left(); + childRect.Y = SAL_MAX( label_rect.Bottom(), page_rect.Top() ); + childRect.Width = page_rect.Right() - page_rect.Left(); + childRect.Height = page_rect.Bottom() - childRect.Y; + + allocateChildAt( xChild, childRect ); + } + } + } +} + +awt::Size SAL_CALL VCLXTabControl::getMinimumSize() + throw(uno::RuntimeException) +{ + awt::Size requestedSize = VCLXWindow::getMinimumSize(); + awt::Size childrenSize( 0, 0 ); + + TabControl* pTabControl = static_cast< TabControl* >( GetWindow() ); + if ( !pTabControl ) + return requestedSize; + + // calculate size to accomodate all children + unsigned i = 0; + for ( std::list<Box_Base::ChildData *>::const_iterator it + = maChildren.begin(); it != maChildren.end(); it++, i++ ) + { + ChildData *child = static_cast<VCLXTabControl::ChildData*> ( *it ); + if ( child->mxChild.is() ) + { + // set the title prop here... + pTabControl->SetPageText( sal::static_int_cast< USHORT >( i+1 ), child->maTitle.getStr() ); + + awt::Size childSize( child->mxChild->getMinimumSize() ); + childrenSize.Width = SAL_MAX( childSize.Width, childrenSize.Width ); + childrenSize.Height = SAL_MAX( childSize.Height, childrenSize.Height ); + } + } + +#ifndef __SUNPRO_CC +#ifdef GCC_MAJOR + OSL_TRACE ("\n%s", __PRETTY_FUNCTION__); +#endif /* GCC_MAJOR */ + OSL_TRACE ("%s: children: %d", __FUNCTION__, i); + OSL_TRACE ("%s: childrenSize: %d, %d", __FUNCTION__, childrenSize.Width, childrenSize.Height ); +#endif + + requestedSize.Width += childrenSize.Width; + requestedSize.Height += childrenSize.Height + 20; + + maRequisition = requestedSize; + return requestedSize; +} + +void VCLXTabControl::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ) +{ + ::vos::OClearableGuard aGuard( GetMutex() ); + TabControl* pTabControl = static_cast< TabControl* >( GetWindow() ); + if ( !pTabControl ) + return; + + switch ( _rVclWindowEvent.GetId() ) + { + case VCLEVENT_TABPAGE_ACTIVATE: + forceRecalc(); + case VCLEVENT_TABPAGE_DEACTIVATE: + case VCLEVENT_TABPAGE_INSERTED: + case VCLEVENT_TABPAGE_REMOVED: + case VCLEVENT_TABPAGE_REMOVEDALL: + case VCLEVENT_TABPAGE_PAGETEXTCHANGED: + { + ULONG page = (ULONG) _rVclWindowEvent.GetData(); + for ( std::list< uno::Reference + < awt::XTabListener > >::iterator it + = mxTabListeners.begin(); it != mxTabListeners.end(); it++) + { + uno::Reference + < awt::XTabListener > listener = *it; + + switch ( _rVclWindowEvent.GetId() ) + { + + case VCLEVENT_TABPAGE_ACTIVATE: + listener->activated( page ); + break; + case VCLEVENT_TABPAGE_DEACTIVATE: + listener->deactivated( page ); + break; + case VCLEVENT_TABPAGE_INSERTED: + listener->inserted( page ); + break; + case VCLEVENT_TABPAGE_REMOVED: + listener->removed( page ); + break; + case VCLEVENT_TABPAGE_REMOVEDALL: + for ( int i = 1; i < mTabId; i++) + { + if ( pTabControl->GetTabPage( sal::static_int_cast< USHORT >( i ) ) ) + listener->removed( i ); + } + break; + case VCLEVENT_TABPAGE_PAGETEXTCHANGED: + listener->changed( page, getTabProps( page ) ); + break; + } + } + break; + } + default: + aGuard.clear(); + VCLXWindow::ProcessWindowEvent( _rVclWindowEvent ); + break; + } +} + +void SAL_CALL VCLXTabControl::setProperty( const ::rtl::OUString& PropertyName, const uno::Any &Value ) throw(uno::RuntimeException) +{ + VCLXWindow::setProperty( PropertyName, Value ); +} + +uno::Any SAL_CALL VCLXTabControl::getProperty( const ::rtl::OUString& PropertyName ) throw(uno::RuntimeException) +{ + return VCLXWindow::getProperty( PropertyName ); +} + +} // namespace layoutimpl diff --git a/toolkit/source/awt/vclxtabcontrol.hxx b/toolkit/source/awt/vclxtabcontrol.hxx new file mode 100644 index 000000000000..8f5debf2626c --- /dev/null +++ b/toolkit/source/awt/vclxtabcontrol.hxx @@ -0,0 +1,144 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_AWT_VCLXTABCONTROLLER_HXX +#define LAYOUT_AWT_VCLXTABCONTROLLER_HXX + +#include <com/sun/star/awt/XSimpleTabController.hpp> +#include <comphelper/uno3.hxx> +#include <layout/core/box-base.hxx> +#include <map> +#include <toolkit/awt/vclxwindow.hxx> + +class TabControl; + +namespace layoutimpl +{ + +typedef ::cppu::ImplHelper1 < ::com::sun::star::awt::XSimpleTabController + > VCLXTabControl_Base; + +class VCLXTabControl :public VCLXWindow + ,public VCLXTabControl_Base + ,public Box_Base +{ + int mTabId; + bool bRealized; + +public: + VCLXTabControl(); + + void AddChild (css::uno::Reference <css::awt::XLayoutConstrains> const &); + +protected: + ~VCLXTabControl(); + + // XInterface + DECLARE_XINTERFACE() + + // XTypeProvider + DECLARE_XTYPEPROVIDER() + + // XComponent + void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL draw( sal_Int32 nX, sal_Int32 nY ) throw (::com::sun::star::uno::RuntimeException); + + // XSimpleTabController + virtual ::sal_Int32 SAL_CALL insertTab() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeTab( ::sal_Int32 ID ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL setTabProps( ::sal_Int32 ID, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& Properties ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > SAL_CALL getTabProps( ::sal_Int32 ID ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL activateTab( ::sal_Int32 ID ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getActiveTabID() throw (::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL addTabListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTabListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeTabListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTabListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); + + // ::com::sun::star::awt::XLayoutContainer + virtual void SAL_CALL addChild( + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains >& Child ) + throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::awt::MaxChildrenException); + virtual void SAL_CALL removeChild( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains >& Child ) + throw (::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL allocateArea( const ::com::sun::star::awt::Rectangle &rArea ) + throw (::com::sun::star::uno::RuntimeException); + + virtual ::com::sun::star::awt::Size SAL_CALL getMinimumSize() + throw(::com::sun::star::uno::RuntimeException); + + // unimplemented: + virtual sal_Bool SAL_CALL hasHeightForWidth() + throw(css::uno::RuntimeException) + { return false; } + virtual sal_Int32 SAL_CALL getHeightForWidth( sal_Int32 /*nWidth*/ ) + throw(css::uno::RuntimeException) + { return maRequisition.Height; } + + // VclWindowPeer + virtual void SAL_CALL setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value ) throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException); + + // VCLXWindow + void ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ); + +public: + // Maps page ids to child references + struct ChildData : public Box_Base::ChildData + { + rtl::OUString maTitle; + ChildData( css::uno::Reference< css::awt::XLayoutConstrains > const& xChild ); + }; + + struct ChildProps : public Box_Base::ChildProps + { + ChildProps( VCLXTabControl::ChildData *pData ); + }; + +protected: + ChildData *createChild( css::uno::Reference< css::awt::XLayoutConstrains > const& xChild ); + ChildProps *createChildProps( Box_Base::ChildData* pData ); + + + std::map< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains >, sal_Int32 > mIdMap; + // FIXME: we might want to use a Multiplexer + std::list< ::com::sun::star::uno::Reference + < ::com::sun::star::awt::XTabListener > > mxTabListeners; + + inline TabControl *getTabControl() const throw (::com::sun::star::uno::RuntimeException); + +private: + VCLXTabControl( const VCLXTabControl& ); // never implemented + VCLXTabControl& operator=( const VCLXTabControl& ); // never implemented +}; + +} // namespace layoutimpl + +#endif /* LAYOUT_AWT_VCLXTABCONTROLLER_HXX */ diff --git a/toolkit/source/awt/vclxtabpage.cxx b/toolkit/source/awt/vclxtabpage.cxx new file mode 100644 index 000000000000..6523f7e98c5f --- /dev/null +++ b/toolkit/source/awt/vclxtabpage.cxx @@ -0,0 +1,156 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vclxtabpage.hxx" +#include "forward.hxx" + +#include <com/sun/star/awt/PosSize.hpp> +#include <toolkit/helper/convert.hxx> +#include <vcl/tabpage.hxx> +#include <vcl/tabctrl.hxx> + +#if !defined (__GNUC__) +#define __PRETTY_FUNCTION__ __FUNCTION__ +#endif /* !__GNUC__ */ + +namespace layoutimpl +{ + +using namespace ::com::sun::star; + +// XInterface +IMPLEMENT_FORWARD_XINTERFACE2( VCLXTabPage, VCLXWindow, Bin ); + +// XTypeProvider +IMPLEMENT_FORWARD_XTYPEPROVIDER1( VCLXTabPage, VCLXWindow ); + +VCLXTabPage::VCLXTabPage( Window *p ) + : VCLXWindow() + , Bin() + , bRealized( false ) +{ + /* FIXME: before Window is set, setLabel, setProperty->setImage + * are silent no-ops. */ + p->SetComponentInterface( this ); +} + +VCLXTabPage::~VCLXTabPage() +{ +} + +void SAL_CALL VCLXTabPage::dispose() throw(uno::RuntimeException) +{ + { + ::vos::OGuard aGuard( GetMutex() ); + + lang::EventObject aDisposeEvent; + aDisposeEvent.Source = W3K_EXPLICIT_CAST (*this); + } + + VCLXWindow::dispose(); +} + +void SAL_CALL VCLXTabPage::allocateArea( awt::Rectangle const& area ) + throw (uno::RuntimeException) +{ + awt::Size currentSize = getSize(); + awt::Size requestedSize = getMinimumSize(); + requestedSize.Height = getHeightForWidth( area.Width ); + + if ( currentSize.Width > 0 && currentSize.Height > 0 + && requestedSize.Width > currentSize.Width ) + requestedSize.Width = currentSize.Width; + if ( currentSize.Width > 0 && currentSize.Height > 0 + && requestedSize.Height > currentSize.Height ) + requestedSize.Height = currentSize.Height; + + // FIXME: missing destructor? + if ( !GetWindow() ) + return; + + Size windowSize = GetWindow()->GetSizePixel(); + Window *parent = GetWindow()->GetParent(); + Size parentSize = parent->GetSizePixel(); + + Point pos = GetWindow()->GetPosPixel(); +#ifndef __SUNPRO_CC + OSL_TRACE ("\n%s", __PRETTY_FUNCTION__); + OSL_TRACE ("%s: curpos: %d ,%d", __FUNCTION__, pos.X(), pos.Y() ); + + OSL_TRACE ("%s: cursize: %d ,%d", __FUNCTION__, currentSize.Width, currentSize.Height ); + OSL_TRACE ("%s: area: %d, %d", __FUNCTION__, area.Width, area.Height ); + OSL_TRACE ("%s: requestedSize: %d, %d", __FUNCTION__, requestedSize.Width, requestedSize.Height ); + OSL_TRACE ("%s: parent: %d, %d", __FUNCTION__, parentSize.Width(), parentSize.Height() ); + OSL_TRACE ("%s: window: %d, %d", __FUNCTION__, windowSize.Width(), windowSize.Height() ); +#endif + +#if 0 + if (requestedSize.Width > parentSize.Width () + || requestedSize.Height > parentSize.Height ()) + { +#ifndef __SUNPRO_CC + OSL_TRACE ("%s: ***setting parent: %d, %d", __FUNCTION__, requestedSize.Width, requestedSize.Height ); +#endif + parent->SetSizePixel ( Size (requestedSize.Width, requestedSize.Height) ); + + if (Window *grand_parent = parent->GetParent ()) + grand_parent->SetSizePixel ( Size (requestedSize.Width, requestedSize.Height) ); + } +#endif + + if ( !bRealized ) + { + setPosSize( area.X, area.Y, requestedSize.Width, requestedSize.Height, awt::PosSize::SIZE ); + bRealized = true; + } + else + { + if ( requestedSize.Width > currentSize.Width + 10) + setPosSize( 0, 0, requestedSize.Width, 0, awt::PosSize::WIDTH ); + if ( requestedSize.Height > currentSize.Height + 10) + setPosSize( 0, 0, 0, requestedSize.Height, awt::PosSize::HEIGHT ); + } + + awt::Size newSize = getSize(); +#ifndef __SUNPRO_CC + OSL_TRACE ("%s: newSize: %d, %d", __FUNCTION__, newSize.Width, newSize.Height ); +#endif + maAllocation.Width = newSize.Width; + maAllocation.Height = newSize.Height; + + Bin::allocateArea( maAllocation ); +} + +awt::Size SAL_CALL VCLXTabPage::getMinimumSize() + throw(uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + return Bin::getMinimumSize(); +} + +} // namespace layoutimpl diff --git a/toolkit/source/awt/vclxtabpage.hxx b/toolkit/source/awt/vclxtabpage.hxx new file mode 100644 index 000000000000..215ee49c5716 --- /dev/null +++ b/toolkit/source/awt/vclxtabpage.hxx @@ -0,0 +1,73 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_AWT_VCLXTABPAGE_HXX +#define LAYOUT_AWT_VCLXTABPAGE_HXX + +#include <toolkit/awt/vclxwindow.hxx> +#include <layout/core/bin.hxx> +#include <comphelper/uno3.hxx> + +namespace layoutimpl +{ + +namespace css = ::com::sun::star; + +class VCLXTabPage : public VCLXWindow + , public Bin +{ + bool bRealized; + +public: + VCLXTabPage( Window *p ); + + // XInterface + DECLARE_XINTERFACE() + + // XTypeProvider + DECLARE_XTYPEPROVIDER() + +protected: + ~VCLXTabPage(); + + // XComponent + void SAL_CALL dispose() throw(css::uno::RuntimeException); + + // ::com::sun::star::awt::XLayoutContainer + virtual void SAL_CALL allocateArea( css::awt::Rectangle const& rArea ) + throw (css::uno::RuntimeException); + virtual css::awt::Size SAL_CALL getMinimumSize() + throw(css::uno::RuntimeException); + +private: + VCLXTabPage( VCLXTabPage const & ); + VCLXTabPage& operator=( VCLXTabPage const & ); +}; + +} // namespace layoutimpl + +#endif /* LAYOUT_AWT_VCLXTABPAGE_HXX */ diff --git a/toolkit/source/awt/vclxtoolkit.cxx b/toolkit/source/awt/vclxtoolkit.cxx new file mode 100644 index 000000000000..2eeafa73d2d2 --- /dev/null +++ b/toolkit/source/awt/vclxtoolkit.cxx @@ -0,0 +1,1697 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> + +#ifndef _SVWIN_HXX +#include <tools/svwin.h> +#endif +#include <stdio.h> +#include <com/sun/star/awt/WindowAttribute.hpp> +#include <com/sun/star/awt/VclWindowPeerAttribute.hpp> +#include <com/sun/star/awt/WindowClass.hpp> +#include <com/sun/star/awt/MessageBoxButtons.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/SystemDependent.hpp> +#include <com/sun/star/awt/FocusEvent.hpp> +#include <com/sun/star/awt/KeyEvent.hpp> +#include <com/sun/star/awt/KeyModifier.hpp> +#include <com/sun/star/lang/EventObject.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/beans/NamedValue.hpp> +#include <cppuhelper/typeprovider.hxx> +#include <osl/conditn.hxx> +#include <rtl/memory.h> +#include <rtl/uuid.h> +#include <rtl/process.h> + +#ifdef WNT +#include <tools/prewin.h> +#include <windows.h> +#include <tools/postwin.h> +#elif (defined QUARTZ) +#include "premac.h" +#include <Cocoa/Cocoa.h> +#include "postmac.h" +#endif +#include <vcl/sysdata.hxx> + +#include <toolkit/awt/vclxwindows.hxx> +#include <toolkit/awt/vclxsystemdependentwindow.hxx> +#include <toolkit/awt/vclxregion.hxx> +#include <toolkit/awt/vclxtoolkit.hxx> + +#include <toolkit/awt/xsimpleanimation.hxx> +#include <toolkit/awt/xthrobber.hxx> +#include <toolkit/awt/vclxtopwindow.hxx> +#include <toolkit/awt/vclxwindow.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <toolkit/helper/unowrapper.hxx> +#include <toolkit/helper/servicenames.hxx> + + +#include <toolkit/helper/macros.hxx> +#include <toolkit/helper/convert.hxx> +#include <vcl/unohelp.hxx> +#include <vcl/btndlg.hxx> +#ifndef _SV_BUTTON_HXX +#include <vcl/button.hxx> +#endif +#include <vcl/combobox.hxx> +#include <vcl/ctrl.hxx> +#include <vcl/dialog.hxx> +#include <vcl/dockingarea.hxx> +#include <vcl/dockwin.hxx> +#include <vcl/edit.hxx> +#include <vcl/field.hxx> +#include <vcl/fixed.hxx> +#include <vcl/floatwin.hxx> +#include <vcl/group.hxx> +#include <vcl/imgctrl.hxx> +#include <vcl/longcurr.hxx> +#include <vcl/lstbox.hxx> +#include <vcl/menubtn.hxx> +#include <vcl/morebtn.hxx> +#include <vcl/msgbox.hxx> +#include <vcl/scrbar.hxx> +#include <vcl/spin.hxx> +#include <vcl/split.hxx> +#include <vcl/splitwin.hxx> +#include <vcl/status.hxx> +#include <vcl/svapp.hxx> +#include <vcl/syschild.hxx> +#include <vcl/tabctrl.hxx> +#include <vcl/tabdlg.hxx> +#include <vcl/tabpage.hxx> +#include <vcl/toolbox.hxx> +#include <vcl/virdev.hxx> +#include <vcl/window.hxx> +#include <vcl/wrkwin.hxx> +#include "toolkit/awt/vclxspinbutton.hxx" + +#include <tools/debug.hxx> +#include <comphelper/processfactory.hxx> + +namespace css = ::com::sun::star; + +#define VCLWINDOW_FRAMEWINDOW 0x1000 +#define VCLWINDOW_SYSTEMCHILDWINDOW 0x1001 + +#if (defined WNT) +#define SYSTEM_DEPENDENT_TYPE ::com::sun::star::lang::SystemDependent::SYSTEM_WIN32 +#elif (defined OS2) +#define SYSTEM_DEPENDENT_TYPE ::com::sun::star::lang::SystemDependent::SYSTEM_OS2 +#elif (defined QUARTZ) +#define SYSTEM_DEPENDENT_TYPE ::com::sun::star::lang::SystemDependent::SYSTEM_MAC +#elif (defined UNX) +#define SYSTEM_DEPENDENT_TYPE ::com::sun::star::lang::SystemDependent::SYSTEM_XWINDOW +#endif + +TOOLKIT_DLLPUBLIC WinBits ImplGetWinBits( sal_uInt32 nComponentAttribs, sal_uInt16 nCompType ) +{ + WinBits nWinBits = 0; + + sal_Bool bMessBox = sal_False; + if ( ( nCompType == WINDOW_INFOBOX ) || + ( nCompType == WINDOW_MESSBOX ) || + ( nCompType == WINDOW_QUERYBOX ) || + ( nCompType == WINDOW_WARNINGBOX ) || + ( nCompType == WINDOW_ERRORBOX ) ) + { + bMessBox = sal_True; + } + + bool bDecoratedWindow = false; + if ( bMessBox + || ( nCompType == WINDOW_DIALOG ) + || ( nCompType == WINDOW_MODELESSDIALOG ) + || ( nCompType == WINDOW_MODALDIALOG ) + || ( nCompType == WINDOW_SYSTEMDIALOG ) + || ( nCompType == WINDOW_PATHDIALOG ) + || ( nCompType == WINDOW_FILEDIALOG ) + || ( nCompType == WINDOW_PRINTERSETUPDIALOG ) + || ( nCompType == WINDOW_PRINTDIALOG ) + || ( nCompType == WINDOW_COLORDIALOG ) + || ( nCompType == WINDOW_FONTDIALOG ) + || ( nCompType == WINDOW_DOCKINGWINDOW ) + || ( nCompType == WINDOW_TABDIALOG ) + || ( nCompType == WINDOW_BUTTONDIALOG ) + || ( nCompType == WINDOW_SYSTEMCHILDWINDOW ) + ) + { + bDecoratedWindow = true; + } + + if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::BORDER ) + nWinBits |= WB_BORDER; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::NOBORDER ) + nWinBits |= WB_NOBORDER; + if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::SIZEABLE ) + nWinBits |= WB_SIZEABLE; + if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::MOVEABLE ) + nWinBits |= WB_MOVEABLE; + if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::CLOSEABLE ) + nWinBits |= WB_CLOSEABLE; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::HSCROLL ) + nWinBits |= WB_HSCROLL; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::VSCROLL ) + nWinBits |= WB_VSCROLL; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::LEFT ) + nWinBits |= WB_LEFT; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::CENTER ) + nWinBits |= WB_CENTER; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::RIGHT ) + nWinBits |= WB_RIGHT; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::SPIN ) + nWinBits |= WB_SPIN; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::SORT ) + nWinBits |= WB_SORT; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DROPDOWN ) + nWinBits |= WB_DROPDOWN; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEFBUTTON ) + nWinBits |= WB_DEFBUTTON; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::READONLY ) + nWinBits |= WB_READONLY; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::CLIPCHILDREN ) + nWinBits |= WB_CLIPCHILDREN; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::GROUP ) + nWinBits |= WB_GROUP; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::NOLABEL ) //added for issue79712 + nWinBits |= WB_NOLABEL; + + // These bits are not uniqe + if ( bMessBox ) + { + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::OK ) + nWinBits |= WB_OK; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::OK_CANCEL ) + nWinBits |= WB_OK_CANCEL; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::YES_NO ) + nWinBits |= WB_YES_NO; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::YES_NO_CANCEL ) + nWinBits |= WB_YES_NO_CANCEL; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::RETRY_CANCEL ) + nWinBits |= WB_RETRY_CANCEL; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_OK ) + nWinBits |= WB_DEF_OK; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_CANCEL ) + nWinBits |= WB_DEF_CANCEL; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_RETRY ) + nWinBits |= WB_DEF_RETRY; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_YES ) + nWinBits |= WB_DEF_YES; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::DEF_NO ) + nWinBits |= WB_DEF_NO; + } + if ( nCompType == WINDOW_MULTILINEEDIT ) + { + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::AUTOHSCROLL ) + nWinBits |= WB_AUTOHSCROLL; + if( nComponentAttribs & ::com::sun::star::awt::VclWindowPeerAttribute::AUTOVSCROLL ) + nWinBits |= WB_AUTOVSCROLL; + } + + + if ( bDecoratedWindow ) + { + if( nComponentAttribs & ::com::sun::star::awt::WindowAttribute::NODECORATION ) + { + // No decoration removes several window attributes and must + // set WB_NOBORDER! + nWinBits &= ~WB_BORDER; + nWinBits &= ~WB_SIZEABLE; + nWinBits &= ~WB_MOVEABLE; + nWinBits &= ~WB_CLOSEABLE; + nWinBits |= WB_NOBORDER; + } + } + + return nWinBits; +} + +struct ComponentInfo +{ + const char* pName; + WindowType nWinType; +}; + +static ComponentInfo __FAR_DATA aComponentInfos [] = +{ + { "buttondialog", WINDOW_BUTTONDIALOG }, + { "cancelbutton", WINDOW_CANCELBUTTON }, + { "checkbox", WINDOW_CHECKBOX }, + { "combobox", WINDOW_COMBOBOX }, + { "control", WINDOW_CONTROL }, + { "currencybox", WINDOW_CURRENCYBOX }, + { "currencyfield", WINDOW_CURRENCYFIELD }, + { "datebox", WINDOW_DATEBOX }, + { "datefield", WINDOW_DATEFIELD }, + { "dialog", WINDOW_DIALOG }, + { "dockingarea", WINDOW_DOCKINGAREA }, + { "dockingwindow", WINDOW_DOCKINGWINDOW }, + { "edit", WINDOW_EDIT }, + { "errorbox", WINDOW_ERRORBOX }, + { "fixedbitmap", WINDOW_FIXEDBITMAP }, + { "fixedimage", WINDOW_FIXEDIMAGE }, + { "fixedline", WINDOW_FIXEDLINE }, + { "fixedtext", WINDOW_FIXEDTEXT }, + { "floatingwindow", WINDOW_FLOATINGWINDOW }, + { "framewindow", VCLWINDOW_FRAMEWINDOW }, + { "groupbox", WINDOW_GROUPBOX }, + { "helpbutton", WINDOW_HELPBUTTON }, + { "imagebutton", WINDOW_IMAGEBUTTON }, + { "imageradiobutton", WINDOW_IMAGERADIOBUTTON }, + { "infobox", WINDOW_INFOBOX }, + { "listbox", WINDOW_LISTBOX }, + { "longcurrencybox", WINDOW_LONGCURRENCYBOX }, + { "longcurrencyfield", WINDOW_LONGCURRENCYFIELD }, + { "menubutton", WINDOW_MENUBUTTON }, + { "messbox", WINDOW_MESSBOX }, + { "metricbox", WINDOW_METRICBOX }, + { "metricfield", WINDOW_METRICFIELD }, + { "modaldialog", WINDOW_MODALDIALOG }, + { "modelessdialog", WINDOW_MODELESSDIALOG }, + { "morebutton", WINDOW_MOREBUTTON }, + { "multilineedit", WINDOW_MULTILINEEDIT }, + { "multilistbox", WINDOW_MULTILISTBOX }, + { "numericbox", WINDOW_NUMERICBOX }, + { "numericfield", WINDOW_NUMERICFIELD }, + { "okbutton", WINDOW_OKBUTTON }, + { "patternbox", WINDOW_PATTERNBOX }, + { "patternfield", WINDOW_PATTERNFIELD }, + { "pushbutton", WINDOW_PUSHBUTTON }, + { "querybox", WINDOW_QUERYBOX }, + { "radiobutton", WINDOW_RADIOBUTTON }, + { "scrollbar", WINDOW_SCROLLBAR }, + { "scrollbarbox", WINDOW_SCROLLBARBOX }, + { "simpleanimation", WINDOW_CONTROL }, + { "spinbutton", WINDOW_SPINBUTTON }, + { "spinfield", WINDOW_SPINFIELD }, + { "throbber", WINDOW_CONTROL }, + { "splitter", WINDOW_SPLITTER }, + { "splitwindow", WINDOW_SPLITWINDOW }, + { "statusbar", WINDOW_STATUSBAR }, + { "systemchildwindow", VCLWINDOW_SYSTEMCHILDWINDOW }, + { "tabcontrol", WINDOW_TABCONTROL }, + { "tabdialog", WINDOW_TABDIALOG }, + { "tabpage", WINDOW_TABPAGE }, + { "timebox", WINDOW_TIMEBOX }, + { "timefield", WINDOW_TIMEFIELD }, + { "toolbox", WINDOW_TOOLBOX }, + { "tristatebox", WINDOW_TRISTATEBOX }, + { "warningbox", WINDOW_WARNINGBOX }, + { "window", WINDOW_WINDOW }, + { "workwindow", WINDOW_WORKWINDOW } +}; + +extern "C" +{ +static int +#if defined( WNT ) + __cdecl +#endif +#if defined( ICC ) && defined( OS2 ) +_Optlink +#endif + ComponentInfoCompare( const void* pFirst, const void* pSecond) +{ + return( strcmp( ((ComponentInfo*)pFirst)->pName, + ((ComponentInfo*)pSecond)->pName ) ); +} +} + +sal_uInt16 ImplGetComponentType( const String& rServiceName ) +{ + static sal_Bool bSorted = sal_False; + if( !bSorted ) + { + qsort( (void*) aComponentInfos, + sizeof( aComponentInfos ) / sizeof( ComponentInfo ), + sizeof( ComponentInfo ), + ComponentInfoCompare ); + bSorted = sal_True; + } + + + ComponentInfo aSearch; + ByteString aServiceName( rServiceName, gsl_getSystemTextEncoding() ); + aServiceName.ToLowerAscii(); + if ( aServiceName.Len() ) + aSearch.pName = aServiceName.GetBuffer(); + else + aSearch.pName = "window"; + + ComponentInfo* pInf = (ComponentInfo*) bsearch( &aSearch, + (void*) aComponentInfos, + sizeof( aComponentInfos ) / sizeof( ComponentInfo ), + sizeof( ComponentInfo ), + ComponentInfoCompare ); + + return pInf ? pInf->nWinType : 0; +} + + +// ---------------------------------------------------- +// class VCLXToolkit +// ---------------------------------------------------- + +static sal_Int32 nVCLToolkitInstanceCount = 0; +static BOOL bInitedByVCLToolkit = sal_False; +//static cppu::OInterfaceContainerHelper * pToolkits = 0; + +static osl::Mutex & getInitMutex() +{ + static osl::Mutex * pM; + if( !pM ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if( !pM ) + { + static osl::Mutex aMutex; + pM = &aMutex; + } + } + return *pM; +} + +static osl::Condition & getInitCondition() +{ + static osl::Condition * pC = 0; + if( !pC ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if( !pC ) + { + static osl::Condition aCondition; + pC = &aCondition; + } + } + return *pC; +} + +struct ToolkitThreadData +{ + VCLXToolkit * pTk; + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xSMgr; + + ToolkitThreadData( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr, VCLXToolkit * pTk_ ) + : pTk( pTk_ ) + , xSMgr( rSMgr ) + { + } +}; + +extern "C" +{ +static void SAL_CALL ToolkitWorkerFunction( void* pArgs ) +{ + ToolkitThreadData * pTTD = (ToolkitThreadData *)pArgs; + bInitedByVCLToolkit = InitVCL( pTTD->xSMgr ); + if( bInitedByVCLToolkit ) + { + UnoWrapper* pUnoWrapper = new UnoWrapper( pTTD->pTk ); + Application::SetUnoWrapper( pUnoWrapper ); + } + getInitCondition().set(); + if( bInitedByVCLToolkit ) + { + { + osl::Guard< vos::IMutex > aGuard( Application::GetSolarMutex() ); + Application::Execute(); + } + try + { + pTTD->pTk->dispose(); + } + catch( com::sun::star::uno::Exception & ) + { + } + /* + if( pToolkits ) + { + cppu::OInterfaceIteratorHelper aIt( *pToolkits ); + ::com::sun::star::uno::XInterface * pI; + while( pI = aIt.next() ) + ((::com::sun::star::lang::XComponent *)pI)->dispose(); + + // delete toolkit container + osl::Guard< osl::Mutex > aGuard( getInitMutex() ); + delete pToolkits; + pToolkits = 0; + } + */ + DeInitVCL(); + } + else + { + JoinMainLoopThread(); + } + delete pTTD; +} +} + +// contructor, which might initialize VCL +VCLXToolkit::VCLXToolkit( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr ): + cppu::WeakComponentImplHelper7< + ::com::sun::star::awt::XToolkit, + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::awt::XSystemChildFactory, + ::com::sun::star::awt::XMessageBoxFactory, + ::com::sun::star::awt::XDataTransferProviderAccess, + ::com::sun::star::awt::XExtendedToolkit, + ::com::sun::star::awt::XReschedule>( GetMutex() ), + m_aTopWindowListeners(rBHelper.rMutex), + m_aKeyHandlers(rBHelper.rMutex), + m_aFocusListeners(rBHelper.rMutex), + m_aEventListenerLink(LINK(this, VCLXToolkit, eventListenerHandler)), + m_aKeyListenerLink(LINK(this, VCLXToolkit, keyListenerHandler)), + m_bEventListener(false), + m_bKeyListener(false) +{ + hSvToolsLib = NULL; + fnSvtCreateWindow = NULL; + + osl::Guard< osl::Mutex > aGuard( getInitMutex() ); + nVCLToolkitInstanceCount++; + if( ( nVCLToolkitInstanceCount == 1 ) && ( !Application::IsInMain() ) ) + { + // setup execute thread + CreateMainLoopThread( ToolkitWorkerFunction, new ToolkitThreadData( rSMgr, this ) ); + getInitCondition().wait(); + /* + if( bInitedByVCLToolkit ) + { + // insert in disposing list + if( !pToolkits ) + pToolkits = new cppu::OInterfaceContainerHelper( getInitMutex() ); + pToolkits->addInterface( (::com::sun::star::lang::XComponent *)this ); + } + */ + } +} + +VCLXToolkit::~VCLXToolkit() +{ +} + + +void SAL_CALL VCLXToolkit::disposing() +{ + if ( hSvToolsLib ) + { + osl_unloadModule( hSvToolsLib ); + hSvToolsLib = NULL; + fnSvtCreateWindow = NULL; + } + + { + osl::Guard< osl::Mutex > aGuard( getInitMutex() ); + if( --nVCLToolkitInstanceCount == 0 ) + { + if( bInitedByVCLToolkit ) + { + Application::Quit(); + JoinMainLoopThread(); + bInitedByVCLToolkit = sal_False; + } + } + } + + if (m_bEventListener) + { + ::Application::RemoveEventListener(m_aEventListenerLink); + m_bEventListener = false; + } + if (m_bKeyListener) + { + ::Application::RemoveKeyListener(m_aKeyListenerLink); + m_bKeyListener = false; + } + ::css::lang::EventObject aEvent( + static_cast< ::cppu::OWeakObject * >(this)); + m_aTopWindowListeners.disposeAndClear(aEvent); + m_aKeyHandlers.disposeAndClear(aEvent); + m_aFocusListeners.disposeAndClear(aEvent); + +/* + osl::Guard< osl::Mutex > aGuard( getInitMutex() ); + // insert in disposing list + if( pToolkits ) + { + // remove from the disposing list + pToolkits->removeInterface( (::com::sun::star::lang::XComponent *)this ); + } +*/ +} + + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > VCLXToolkit::getDesktopWindow( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xRef; + // 07/00: AppWindow doesn't exist anymore... + return xRef; +} + +::com::sun::star::awt::Rectangle VCLXToolkit::getWorkArea( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::awt::Rectangle aRect; + // 07/00: AppWindow doesn't exist anymore... + return aRect; +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > VCLXToolkit::createWindow( const ::com::sun::star::awt::WindowDescriptor& rDescriptor ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) +{ + return ImplCreateWindow( rDescriptor, WinBits(0) ); +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > VCLXToolkit::createScreenCompatibleDevice( sal_Int32 Width, sal_Int32 Height ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > xRef; + VCLXVirtualDevice* pVDev = new VCLXVirtualDevice; + + osl::Guard< vos::IMutex > aSolarGuard( Application::GetSolarMutex() ); + + VirtualDevice* pV = new VirtualDevice; + pV->SetOutputSizePixel( Size( Width, Height ) ); + pVDev->SetVirtualDevice( pV ); + + xRef = pVDev; + return xRef; +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion > VCLXToolkit::createRegion( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion > xRef = new VCLXRegion; + return xRef; +} + +Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp, + const ::com::sun::star::awt::WindowDescriptor& rDescriptor, + Window* pParent, WinBits nWinBits ) +{ + String aServiceName( rDescriptor.WindowServiceName ); + aServiceName.ToLowerAscii(); + + Window* pNewWindow = NULL; + sal_uInt16 nType = ImplGetComponentType( aServiceName ); + + if ( !pParent ) + { + // Wenn die Component einen Parent braucht, dann NULL zurueckgeben, + // spaeter mal ::com::sun::star::uno::Exception... + sal_Bool bException = sal_True; + if ( ( nType == WINDOW_DIALOG ) || ( nType == WINDOW_MODALDIALOG ) || ( nType == WINDOW_MODELESSDIALOG ) ) + bException = sal_False; + else if ( ( nType == WINDOW_WINDOW ) || + ( nType == WINDOW_WORKWINDOW ) || + ( nType == VCLWINDOW_FRAMEWINDOW ) ) + { + if ( rDescriptor.Type == ::com::sun::star::awt::WindowClass_TOP ) + bException = sal_False; + } + + if ( bException ) + { + *ppNewComp = NULL; + return NULL; + } + } + + if ( nType ) + { + NAMESPACE_VOS(OGuard) aVclGuard( Application::GetSolarMutex() ); + switch ( (WindowType)nType ) + { + case WINDOW_CANCELBUTTON: + pNewWindow = new CancelButton( pParent, nWinBits ); + *ppNewComp = new VCLXButton; + break; + case WINDOW_CHECKBOX: + pNewWindow = new CheckBox( pParent, nWinBits ); + *ppNewComp = new VCLXCheckBox; + break; + case WINDOW_COMBOBOX: + pNewWindow = new ComboBox( pParent, nWinBits|WB_AUTOHSCROLL ); + ((ComboBox*)pNewWindow)->EnableAutoSize( sal_False ); + *ppNewComp = new VCLXComboBox; + break; + case WINDOW_CURRENCYBOX: + pNewWindow = new CurrencyBox( pParent, nWinBits ); + break; + case WINDOW_CURRENCYFIELD: + pNewWindow = new CurrencyField( pParent, nWinBits ); + static_cast<CurrencyField*>(pNewWindow)->EnableEmptyFieldValue( TRUE ); + *ppNewComp = new VCLXNumericField; + ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(CurrencyField*)pNewWindow ); + break; + case WINDOW_DATEBOX: + pNewWindow = new DateBox( pParent, nWinBits ); + break; + case WINDOW_DATEFIELD: + pNewWindow = new DateField( pParent, nWinBits ); + static_cast<DateField*>(pNewWindow)->EnableEmptyFieldValue( TRUE ); + *ppNewComp = new VCLXDateField; + ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(DateField*)pNewWindow ); + break; + case WINDOW_DOCKINGAREA: + pNewWindow = new DockingAreaWindow( pParent ); + break; + case WINDOW_MULTILINEEDIT: + case WINDOW_EDIT: + pNewWindow = new Edit( pParent, nWinBits ); + *ppNewComp = new VCLXEdit; + break; + case WINDOW_ERRORBOX: + pNewWindow = new ErrorBox( pParent, nWinBits, String() ); + *ppNewComp = new VCLXMessageBox; + break; + case WINDOW_FIXEDBITMAP: + pNewWindow = new FixedBitmap( pParent, nWinBits ); + break; + case WINDOW_FIXEDIMAGE: + pNewWindow = new ImageControl( pParent, nWinBits ); + *ppNewComp = new VCLXImageControl; + break; + case WINDOW_FIXEDLINE: + pNewWindow = new FixedLine( pParent, nWinBits ); + break; + case WINDOW_FIXEDTEXT: + pNewWindow = new FixedText( pParent, nWinBits ); + *ppNewComp = new VCLXFixedText; + break; + case WINDOW_FLOATINGWINDOW: + pNewWindow = new FloatingWindow( pParent, nWinBits ); + break; + case WINDOW_GROUPBOX: + pNewWindow = new GroupBox( pParent, nWinBits ); + break; + case WINDOW_HELPBUTTON: + pNewWindow = new HelpButton( pParent, nWinBits ); + *ppNewComp = new VCLXButton; + break; + case WINDOW_IMAGEBUTTON: + pNewWindow = new ImageButton( pParent, nWinBits ); + *ppNewComp = new VCLXButton; + break; + case WINDOW_IMAGERADIOBUTTON: + pNewWindow = new ImageRadioButton( pParent, nWinBits ); + *ppNewComp = new VCLXButton; + break; + case WINDOW_INFOBOX: + pNewWindow = new InfoBox( pParent, String() ); + *ppNewComp = new VCLXMessageBox; + break; + case WINDOW_LISTBOX: + pNewWindow = new ListBox( pParent, nWinBits|WB_SIMPLEMODE|WB_AUTOHSCROLL ); + ((ListBox*)pNewWindow)->EnableAutoSize( sal_False ); + *ppNewComp = new VCLXListBox; + break; + case WINDOW_LONGCURRENCYBOX: + pNewWindow = new LongCurrencyBox( pParent, nWinBits ); + break; + case WINDOW_LONGCURRENCYFIELD: + pNewWindow = new LongCurrencyField( pParent, nWinBits ); + *ppNewComp = new VCLXCurrencyField; + ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(LongCurrencyField*)pNewWindow ); + break; + case WINDOW_MENUBUTTON: + pNewWindow = new MenuButton( pParent, nWinBits ); + *ppNewComp = new VCLXButton; + break; + case WINDOW_MESSBOX: + pNewWindow = new MessBox( pParent, nWinBits, String(), String() ); + *ppNewComp = new VCLXMessageBox; + break; + case WINDOW_METRICBOX: + pNewWindow = new MetricBox( pParent, nWinBits ); + break; + case WINDOW_METRICFIELD: + pNewWindow = new MetricField( pParent, nWinBits ); + *ppNewComp = new VCLXMetricField; + ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(MetricField*)pNewWindow ); + break; + case WINDOW_DIALOG: + case WINDOW_MODALDIALOG: + case WINDOW_MODELESSDIALOG: + { + // Modal/Modeless nur durch Show/Execute + if ( (pParent == NULL ) && ( rDescriptor.ParentIndex == -1 ) ) + pParent = DIALOG_NO_PARENT; + pNewWindow = new Dialog( pParent, nWinBits ); + *ppNewComp = new VCLXDialog; + } + break; + case WINDOW_MOREBUTTON: + pNewWindow = new MoreButton( pParent, nWinBits ); + *ppNewComp = new VCLXButton; + break; + case WINDOW_MULTILISTBOX: + pNewWindow = new MultiListBox( pParent, nWinBits ); + *ppNewComp = new VCLXListBox; + break; + case WINDOW_NUMERICBOX: + pNewWindow = new NumericBox( pParent, nWinBits ); + break; + case WINDOW_NUMERICFIELD: + pNewWindow = new NumericField( pParent, nWinBits ); + static_cast<NumericField*>(pNewWindow)->EnableEmptyFieldValue( TRUE ); + *ppNewComp = new VCLXNumericField; + ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(NumericField*)pNewWindow ); + break; + case WINDOW_OKBUTTON: + pNewWindow = new OKButton( pParent, nWinBits ); + *ppNewComp = new VCLXButton; + break; + case WINDOW_PATTERNBOX: + pNewWindow = new PatternBox( pParent, nWinBits ); + break; + case WINDOW_PATTERNFIELD: + pNewWindow = new PatternField( pParent, nWinBits ); + *ppNewComp = new VCLXPatternField; + ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(PatternField*)pNewWindow ); + break; + case WINDOW_PUSHBUTTON: + pNewWindow = new PushButton( pParent, nWinBits ); + *ppNewComp = new VCLXButton; + break; + case WINDOW_QUERYBOX: + pNewWindow = new QueryBox( pParent, nWinBits, String() ); + *ppNewComp = new VCLXMessageBox; + break; + case WINDOW_RADIOBUTTON: + pNewWindow = new RadioButton( pParent, nWinBits ); + *ppNewComp = new VCLXRadioButton; + + // by default, disable RadioCheck + // Since the VCLXRadioButton really cares for it's RadioCheck settings, this is important: + // if we enable it, the VCLXRadioButton will use RadioButton::Check instead of RadioButton::SetState + // This leads to a strange behaviour if the control is newly created: when settings the initial + // state to "checked", the RadioButton::Check (called because RadioCheck=TRUE) will uncheck + // _all_other_ radio buttons in the same group. However, at this moment the grouping of the controls + // is not really valid: the controls are grouped after they have been created, but we're still in + // the creation process, so the RadioButton::Check relies on invalid grouping information. + // 07.08.2001 - #87254# - frank.schoenheit@sun.com + static_cast<RadioButton*>(pNewWindow)->EnableRadioCheck( FALSE ); + break; + case WINDOW_SCROLLBAR: + pNewWindow = new ScrollBar( pParent, nWinBits ); + *ppNewComp = new VCLXScrollBar; + break; + case WINDOW_SCROLLBARBOX: + pNewWindow = new ScrollBarBox( pParent, nWinBits ); + break; + case WINDOW_SPINBUTTON: + pNewWindow = new SpinButton( pParent, nWinBits ); + *ppNewComp = new ::toolkit::VCLXSpinButton; + break; + case WINDOW_SPINFIELD: + pNewWindow = new SpinField( pParent, nWinBits ); + *ppNewComp = new VCLXNumericField; + break; + case WINDOW_SPLITTER: + pNewWindow = new Splitter( pParent, nWinBits ); + break; + case WINDOW_SPLITWINDOW: + pNewWindow = new SplitWindow( pParent, nWinBits ); + break; + case WINDOW_STATUSBAR: + pNewWindow = new StatusBar( pParent, nWinBits ); + break; + case VCLWINDOW_SYSTEMCHILDWINDOW: + pNewWindow = new SystemChildWindow( pParent, nWinBits ); + *ppNewComp = new VCLXSystemDependentWindow(); + break; + case WINDOW_TABCONTROL: + pNewWindow = new TabControl( pParent, nWinBits ); + break; + case WINDOW_TABDIALOG: + pNewWindow = new TabDialog( pParent, nWinBits ); + break; + case WINDOW_TABPAGE: + pNewWindow = new TabPage( pParent, nWinBits ); + *ppNewComp = new VCLXTabPage; + break; + case WINDOW_TIMEBOX: + pNewWindow = new TimeBox( pParent, nWinBits ); + break; + case WINDOW_TIMEFIELD: + pNewWindow = new TimeField( pParent, nWinBits ); + static_cast<TimeField*>(pNewWindow)->EnableEmptyFieldValue( TRUE ); + *ppNewComp = new VCLXTimeField; + ((VCLXFormattedSpinField*)*ppNewComp)->SetFormatter( (FormatterBase*)(TimeField*)pNewWindow ); + break; + case WINDOW_TOOLBOX: + pNewWindow = new ToolBox( pParent, nWinBits ); + *ppNewComp = new VCLXToolBox; + break; + case WINDOW_TRISTATEBOX: + pNewWindow = new TriStateBox( pParent, nWinBits ); + break; + case WINDOW_WARNINGBOX: + pNewWindow = new WarningBox( pParent, nWinBits, String() ); + *ppNewComp = new VCLXMessageBox; + break; + case WINDOW_WORKWINDOW: + case WINDOW_WINDOW: + case VCLWINDOW_FRAMEWINDOW: + case WINDOW_DOCKINGWINDOW: + if ( rDescriptor.Type == ::com::sun::star::awt::WindowClass_TOP ) + { + if (nType == WINDOW_DOCKINGWINDOW ) + pNewWindow = new DockingWindow( pParent, nWinBits ); + else + { + if ((pParent == NULL) && rDescriptor.Parent.is()) + { + // try to get a system dependent window handle + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XSystemDependentWindowPeer > xSystemDepParent(rDescriptor.Parent, ::com::sun::star::uno::UNO_QUERY); + + if (xSystemDepParent.is()) + { + sal_Int8 processID[16]; + + rtl_getGlobalProcessId( (sal_uInt8*)processID ); + + ::com::sun::star::uno::Sequence<sal_Int8> processIdSeq(processID, 16); + + ::com::sun::star::uno::Any anyHandle = xSystemDepParent->getWindowHandle(processIdSeq, SYSTEM_DEPENDENT_TYPE); + + // use sal_Int64 here to accomodate all int types + // uno::Any shift operator whill upcast if necessary + sal_Int64 nWindowHandle = 0; + sal_Bool bXEmbed = sal_False; + + bool bUseParentData = true; + if( ! (anyHandle >>= nWindowHandle) ) + { + css::uno::Sequence< css::beans::NamedValue > aProps; + if( anyHandle >>= aProps ) + { + const int nProps = aProps.getLength(); + const css::beans::NamedValue* pProps = aProps.getConstArray(); + for( int i = 0; i < nProps; i++ ) + { + if( pProps[i].Name.equalsAscii( "WINDOW" ) ) + pProps[i].Value >>= nWindowHandle; + else if( pProps[i].Name.equalsAscii( "XEMBED" ) ) + pProps[i].Value >>= bXEmbed; + } + } + else + bUseParentData = false; + } + + if( bUseParentData ) + { + SystemParentData aParentData; + aParentData.nSize = sizeof( aParentData ); + #if defined QUARTZ + aParentData.pView = reinterpret_cast<NSView*>(nWindowHandle); + #elif defined UNX + aParentData.aWindow = nWindowHandle; + aParentData.bXEmbedSupport = bXEmbed; + #elif defined WNT + aParentData.hWnd = reinterpret_cast<HWND>(nWindowHandle); + #elif defined OS2 + aParentData.hWnd = (HWND)nWindowHandle; + #endif + pNewWindow = new WorkWindow( &aParentData ); + } + } + } + + if (!pNewWindow) + pNewWindow = new WorkWindow( pParent, nWinBits ); + } + + *ppNewComp = new VCLXTopWindow( pNewWindow->GetType() == WINDOW_WORKWINDOW ); + } + else if ( rDescriptor.Type == ::com::sun::star::awt::WindowClass_CONTAINER ) + { + if (nType == WINDOW_DOCKINGWINDOW ) + pNewWindow = new DockingWindow( pParent, nWinBits ); + else + pNewWindow = new Window( pParent, nWinBits ); + *ppNewComp = new VCLXContainer; + } + else + { + if (nType == WINDOW_DOCKINGWINDOW ) + pNewWindow = new DockingWindow( pParent, nWinBits ); + else + pNewWindow = new Window( pParent, nWinBits ); + *ppNewComp = new VCLXWindow; + } + break; + case WINDOW_CONTROL: + if ( rDescriptor.WindowServiceName.equalsIgnoreAsciiCase( + ::rtl::OUString::createFromAscii("simpleanimation") ) ) + { + nWinBits |= WB_SCALE; + pNewWindow = new FixedImage( pParent, nWinBits ); + *ppNewComp = new ::toolkit::XSimpleAnimation; + } + else if ( rDescriptor.WindowServiceName.equalsIgnoreAsciiCase( + ::rtl::OUString::createFromAscii("throbber") ) ) + { + nWinBits |= WB_SCALE; + pNewWindow = new FixedImage( pParent, nWinBits ); + *ppNewComp = new ::toolkit::XThrobber; + } + break; + default: DBG_ERRORFILE( "UNO3!" ); + } + } + + return pNewWindow; +} + +extern "C" { static void SAL_CALL thisModule() {} } + +css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::ImplCreateWindow( + const css::awt::WindowDescriptor& rDescriptor, + WinBits nForceWinBits ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + osl::Guard< vos::IMutex > aSolarGuard( Application::GetSolarMutex() ); + + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xRef; + + Window* pParent = NULL; + if ( rDescriptor.Parent.is() ) + { + VCLXWindow* pParentComponent = VCLXWindow::GetImplementation( rDescriptor.Parent ); + + // #103939# Don't through assertion, may be it's a system dependend window, used in ImplCreateWindow. + // DBG_ASSERT( pParentComponent, "ParentComponent not valid" ); + + if ( pParentComponent ) + pParent = pParentComponent->GetWindow(); + } + + WinBits nWinBits = ImplGetWinBits( rDescriptor.WindowAttributes, + ImplGetComponentType( rDescriptor.WindowServiceName ) ); + nWinBits |= nForceWinBits; + + VCLXWindow* pNewComp = NULL; + + Window* pNewWindow = NULL; + // Try to create the window with SvTools + // (do this _before_ creating it on our own: The old mechanism (extended toolkit in SvTools) did it this way, + // and we need to stay compatible) + // try to load the lib + if ( !fnSvtCreateWindow && !hSvToolsLib ) + { + ::rtl::OUString aLibName = ::vcl::unohelper::CreateLibraryName( "svt", TRUE ); + hSvToolsLib = osl_loadModuleRelative( + &thisModule, aLibName.pData, SAL_LOADMODULE_DEFAULT ); + if ( hSvToolsLib ) + { + ::rtl::OUString aFunctionName( RTL_CONSTASCII_USTRINGPARAM( "CreateWindow" ) ); + fnSvtCreateWindow = (FN_SvtCreateWindow)osl_getFunctionSymbol( hSvToolsLib, aFunctionName.pData ); + } + } + // ask the SvTool creation function + if ( fnSvtCreateWindow ) + pNewWindow = fnSvtCreateWindow( &pNewComp, &rDescriptor, pParent, nWinBits ); + + // if SvTools could not provide a window, create it ourself + if ( !pNewWindow ) + pNewWindow = ImplCreateWindow( &pNewComp, rDescriptor, pParent, nWinBits ); + + DBG_ASSERT( pNewWindow, "createWindow: Unknown Component!" ); + DBG_ASSERTWARNING( pNewComp, "createWindow: No special Interface!" ); + + if ( pNewWindow ) + { + pNewWindow->SetCreatedWithToolkit( sal_True ); + //pNewWindow->SetPosPixel( Point() ); // do not force (0,0) position, keep default pos instead + + if ( rDescriptor.WindowAttributes & ::com::sun::star::awt::WindowAttribute::MINSIZE ) + { + pNewWindow->SetSizePixel( Size() ); + } + else if ( rDescriptor.WindowAttributes & ::com::sun::star::awt::WindowAttribute::FULLSIZE ) + { + if ( pParent ) + pNewWindow->SetSizePixel( pParent->GetOutputSizePixel() ); + } + else if ( !VCLUnoHelper::IsZero( rDescriptor.Bounds ) ) + { + Rectangle aRect = VCLRectangle( rDescriptor.Bounds ); + pNewWindow->SetPosSizePixel( aRect.TopLeft(), aRect.GetSize() ); + } + + if ( !pNewComp ) + { + // Default-Interface + xRef = pNewWindow->GetComponentInterface( sal_True ); + } + else + { + pNewComp->SetCreatedWithToolkit( TRUE ); + xRef = pNewComp; + pNewWindow->SetComponentInterface( xRef ); + } + DBG_ASSERT( pNewWindow->GetComponentInterface( FALSE ) == xRef, + "VCLXToolkit::createWindow: did #133706# resurge?" ); + + if ( rDescriptor.WindowAttributes & ::com::sun::star::awt::WindowAttribute::SHOW ) + pNewWindow->Show(); + } + + return xRef; +} + +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > > VCLXToolkit::createWindows( const ::com::sun::star::uno::Sequence< ::com::sun::star::awt::WindowDescriptor >& rDescriptors ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + sal_uInt32 nComponents = rDescriptors.getLength(); + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > > aSeq( nComponents ); + for ( sal_uInt32 n = 0; n < nComponents; n++ ) + { + ::com::sun::star::awt::WindowDescriptor aDescr = rDescriptors.getConstArray()[n]; + + if ( aDescr.ParentIndex == (-1) ) + aDescr.Parent = NULL; + else if ( ( aDescr.ParentIndex >= 0 ) && ( aDescr.ParentIndex < (short)n ) ) + aDescr.Parent = aSeq.getConstArray()[aDescr.ParentIndex]; + aSeq.getArray()[n] = createWindow( aDescr ); + } + return aSeq; +} + +// ::com::sun::star::awt::XSystemChildFactory +::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > VCLXToolkit::createSystemChild( const ::com::sun::star::uno::Any& Parent, const ::com::sun::star::uno::Sequence< sal_Int8 >& /*ProcessId*/, sal_Int16 nSystemType ) throw(::com::sun::star::uno::RuntimeException) +{ + Window* pChildWindow = NULL; + if ( nSystemType == SYSTEM_DEPENDENT_TYPE ) + { + // use sal_Int64 here to accomodate all int types + // uno::Any shift operator whill upcast if necessary + sal_Int64 nWindowHandle = 0; + sal_Bool bXEmbed = sal_False; + + bool bUseParentData = true; + if( ! (Parent >>= nWindowHandle) ) + { + css::uno::Sequence< css::beans::NamedValue > aProps; + if( Parent >>= aProps ) + { + const int nProps = aProps.getLength(); + const css::beans::NamedValue* pProps = aProps.getConstArray(); + for( int i = 0; i < nProps; i++ ) + { + if( pProps[i].Name.equalsAscii( "WINDOW" ) ) + pProps[i].Value >>= nWindowHandle; + else if( pProps[i].Name.equalsAscii( "XEMBED" ) ) + pProps[i].Value >>= bXEmbed; + } + } + else + bUseParentData = false; + } + + if( bUseParentData ) + { + SystemParentData aParentData; + aParentData.nSize = sizeof( aParentData ); + #if defined QUARTZ + aParentData.pView = reinterpret_cast<NSView*>(nWindowHandle); + #elif defined UNX + aParentData.aWindow = nWindowHandle; + aParentData.bXEmbedSupport = bXEmbed; + #elif defined WNT + aParentData.hWnd = reinterpret_cast<HWND>(nWindowHandle); + #elif defined OS2 + aParentData.hWnd = (HWND)nWindowHandle; + #endif + osl::Guard< vos::IMutex > aGuard( Application::GetSolarMutex() ); + try + { + pChildWindow = new WorkWindow( &aParentData ); + } + catch ( ::com::sun::star::uno::RuntimeException & rEx ) + { + // system child window could not be created + OSL_TRACE( + "VCLXToolkit::createSystemChild: caught %s\n", + ::rtl::OUStringToOString( + rEx.Message, RTL_TEXTENCODING_UTF8).getStr()); + pChildWindow = NULL; + } + } + } + else if (nSystemType == com::sun::star::lang::SystemDependent::SYSTEM_JAVA) + { + osl::Guard< vos::IMutex > aGuard(Application::GetSolarMutex()); + pChildWindow = new WorkWindow(0, Parent); + } + + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xPeer; + if ( pChildWindow ) + { + VCLXTopWindow* pPeer = new VCLXTopWindow(true); + osl::Guard< vos::IMutex > aGuard( Application::GetSolarMutex() ); + pPeer->SetWindow( pChildWindow ); + xPeer = pPeer; + } + + return xPeer; +} + +// ::com::sun::star::awt::XMessageBoxFactory +::com::sun::star::uno::Reference< ::com::sun::star::awt::XMessageBox > SAL_CALL VCLXToolkit::createMessageBox( + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& aParent, + const ::com::sun::star::awt::Rectangle& aPosSize, + const ::rtl::OUString& aType, + ::sal_Int32 aButtons, + const ::rtl::OUString& aTitle, + const ::rtl::OUString& aMessage ) throw (::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::awt::WindowDescriptor aDescriptor; + + sal_Int32 nWindowAttributes = css::awt::WindowAttribute::BORDER|css::awt::WindowAttribute::MOVEABLE|css::awt::WindowAttribute::CLOSEABLE; + + // Map button definitions to window attributes + if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK ) + nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK; + else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK_CANCEL ) + nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK_CANCEL; + else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO ) + nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO; + else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO_CANCEL ) + nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO_CANCEL; + else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_RETRY_CANCEL ) + nWindowAttributes |= css::awt::VclWindowPeerAttribute::RETRY_CANCEL; + + // Map default button definitions to window attributes + if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_OK ) + nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_OK; + else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_CANCEL ) + nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_CANCEL; + else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_YES ) + nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_YES; + else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_NO ) + nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_NO; + else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_RETRY ) + nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_RETRY; + + // No more bits for VclWindowPeerAttribute possible. Mapping must be + // done explicitly using VCL methods + WinBits nAddWinBits( 0 ); + if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_ABORT_IGNORE_RETRY ) + nAddWinBits |= WB_ABORT_RETRY_IGNORE; + if ( sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_IGNORE ) + nAddWinBits |= WB_DEF_IGNORE; + + aDescriptor.Type = css::awt::WindowClass_MODALTOP; + aDescriptor.WindowServiceName = aType; + aDescriptor.ParentIndex = -1; + aDescriptor.Parent = aParent; + aDescriptor.Bounds = aPosSize; + aDescriptor.WindowAttributes = nWindowAttributes; + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMessageBox > xMsgBox( + ImplCreateWindow( aDescriptor, nAddWinBits ), css::uno::UNO_QUERY ); + css::uno::Reference< css::awt::XWindow > xWindow( xMsgBox, css::uno::UNO_QUERY ); + if ( xMsgBox.is() && xWindow.is() ) + { + Window * pWindow = VCLUnoHelper::GetWindow( xWindow ); + if ( pWindow ) + { + osl::Guard< vos::IMutex > aGuard(Application::GetSolarMutex()); + xMsgBox->setCaptionText( aTitle ); + xMsgBox->setMessageText( aMessage ); + } + } + + return xMsgBox; +} + +::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragGestureRecognizer > SAL_CALL VCLXToolkit::getDragGestureRecognizer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& window ) throw(::com::sun::star::uno::RuntimeException) +{ + Window * pWindow = VCLUnoHelper::GetWindow( window ); + + if( pWindow ) + return pWindow->GetDragGestureRecognizer(); + + return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragGestureRecognizer >(); +} + +::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSource > SAL_CALL VCLXToolkit::getDragSource( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& window ) throw(::com::sun::star::uno::RuntimeException) +{ + Window * pWindow = VCLUnoHelper::GetWindow( window ); + + if( pWindow ) + return pWindow->GetDragSource(); + + return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSource >(); +} + +::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDropTarget > SAL_CALL VCLXToolkit::getDropTarget( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& window ) throw(::com::sun::star::uno::RuntimeException) +{ + Window * pWindow = VCLUnoHelper::GetWindow( window ); + + if( pWindow ) + return pWindow->GetDropTarget(); + + return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDropTarget >(); +} + +::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard > SAL_CALL VCLXToolkit::getClipboard( const ::rtl::OUString& clipboardName ) throw(::com::sun::star::uno::RuntimeException) +{ + if( clipboardName.getLength() == 0 ) + { + if( !mxClipboard.is() ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); + if ( xFactory.is() ) + { + // remember clipboard here + mxClipboard = ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard > ( + xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.datatransfer.clipboard.SystemClipboard" ) ), ::com::sun::star::uno::UNO_QUERY ); + } + } + + return mxClipboard; + } + + else if( clipboardName.equals( ::rtl::OUString::createFromAscii("Selection") ) ) + { + return mxSelection; + } + + return ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard >(); +} + +// XServiceInfo +::rtl::OUString VCLXToolkit::getImplementationName() throw(::com::sun::star::uno::RuntimeException) +{ + return rtl::OUString::createFromAscii( "stardiv.Toolkit.VCLXToolkit" ); +} + +sal_Bool VCLXToolkit::supportsService( const ::rtl::OUString& rServiceName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::MutexGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames(); + const ::rtl::OUString* pArray = aSNL.getConstArray(); + const ::rtl::OUString* pArrayEnd = aSNL.getConstArray(); + for (; pArray != pArrayEnd; ++pArray ) + if( *pArray == rServiceName ) + break; + + return pArray != pArrayEnd; +} + +::com::sun::star::uno::Sequence< ::rtl::OUString > VCLXToolkit::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException) +{ + ::rtl::OUString aServiceName( ::rtl::OUString::createFromAscii( szServiceName2_Toolkit ) ); + return ::com::sun::star::uno::Sequence< ::rtl::OUString >( &aServiceName, 1); +} + +// css::awt::XExtendedToolkit: + +// virtual +::sal_Int32 SAL_CALL VCLXToolkit::getTopWindowCount() + throw (::css::uno::RuntimeException) +{ + return static_cast< ::sal_Int32 >(::Application::GetTopWindowCount()); + // XXX numeric overflow +} + +// virtual +::css::uno::Reference< ::css::awt::XTopWindow > SAL_CALL +VCLXToolkit::getTopWindow(::sal_Int32 nIndex) + throw (::css::uno::RuntimeException) +{ + ::Window * p = ::Application::GetTopWindow(static_cast< long >(nIndex)); + // XXX numeric overflow + return ::css::uno::Reference< ::css::awt::XTopWindow >( + p == 0 ? 0 : static_cast< ::css::awt::XWindow * >(p->GetWindowPeer()), + ::css::uno::UNO_QUERY); +} + +// virtual +::css::uno::Reference< ::css::awt::XTopWindow > SAL_CALL +VCLXToolkit::getActiveTopWindow() throw (::css::uno::RuntimeException) +{ + ::Window * p = ::Application::GetActiveTopWindow(); + return ::css::uno::Reference< ::css::awt::XTopWindow >( + p == 0 ? 0 : static_cast< ::css::awt::XWindow * >(p->GetWindowPeer()), + ::css::uno::UNO_QUERY); +} + +// virtual +void SAL_CALL VCLXToolkit::addTopWindowListener( + ::css::uno::Reference< ::css::awt::XTopWindowListener > const & rListener) + throw (::css::uno::RuntimeException) +{ + OSL_ENSURE(rListener.is(), "Null rListener"); + ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex); + if (rBHelper.bDisposed || rBHelper.bInDispose) + { + aGuard.clear(); + rListener->disposing( + ::css::lang::EventObject( + static_cast< ::cppu::OWeakObject * >(this))); + } + else if (m_aTopWindowListeners.addInterface(rListener) == 1 + && !m_bEventListener) + { + m_bEventListener = true; + ::Application::AddEventListener(m_aEventListenerLink); + } +} + +// virtual +void SAL_CALL VCLXToolkit::removeTopWindowListener( + ::css::uno::Reference< ::css::awt::XTopWindowListener > const & rListener) + throw (::css::uno::RuntimeException) +{ + ::osl::MutexGuard aGuard(rBHelper.rMutex); + if (!(rBHelper.bDisposed || rBHelper.bInDispose) + && m_aTopWindowListeners.removeInterface(rListener) == 0 + && m_aFocusListeners.getLength() == 0 && m_bEventListener) + { + ::Application::RemoveEventListener(m_aEventListenerLink); + m_bEventListener = false; + } +} + +// virtual +void SAL_CALL VCLXToolkit::addKeyHandler( + ::css::uno::Reference< ::css::awt::XKeyHandler > const & rHandler) + throw (::css::uno::RuntimeException) +{ + OSL_ENSURE(rHandler.is(), "Null rHandler"); + ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex); + if (rBHelper.bDisposed || rBHelper.bInDispose) + { + aGuard.clear(); + rHandler->disposing( + ::css::lang::EventObject( + static_cast< ::cppu::OWeakObject * >(this))); + } + else if (m_aKeyHandlers.addInterface(rHandler) == 1 && !m_bKeyListener) + { + m_bKeyListener = true; + ::Application::AddKeyListener(m_aKeyListenerLink); + } +} + +// virtual +void SAL_CALL VCLXToolkit::removeKeyHandler( + ::css::uno::Reference< ::css::awt::XKeyHandler > const & rHandler) + throw (::css::uno::RuntimeException) +{ + ::osl::MutexGuard aGuard(rBHelper.rMutex); + if (!(rBHelper.bDisposed || rBHelper.bInDispose) + && m_aKeyHandlers.removeInterface(rHandler) == 0 && m_bKeyListener) + { + ::Application::RemoveKeyListener(m_aKeyListenerLink); + m_bKeyListener = false; + } +} + +// virtual +void SAL_CALL VCLXToolkit::addFocusListener( + ::css::uno::Reference< ::css::awt::XFocusListener > const & rListener) + throw (::css::uno::RuntimeException) +{ + OSL_ENSURE(rListener.is(), "Null rListener"); + ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex); + if (rBHelper.bDisposed || rBHelper.bInDispose) + { + aGuard.clear(); + rListener->disposing( + ::css::lang::EventObject( + static_cast< ::cppu::OWeakObject * >(this))); + } + else if (m_aFocusListeners.addInterface(rListener) == 1 + && !m_bEventListener) + { + m_bEventListener = true; + ::Application::AddEventListener(m_aEventListenerLink); + } +} + +// virtual +void SAL_CALL VCLXToolkit::removeFocusListener( + ::css::uno::Reference< ::css::awt::XFocusListener > const & rListener) + throw (::css::uno::RuntimeException) +{ + ::osl::MutexGuard aGuard(rBHelper.rMutex); + if (!(rBHelper.bDisposed || rBHelper.bInDispose) + && m_aFocusListeners.removeInterface(rListener) == 0 + && m_aTopWindowListeners.getLength() == 0 && m_bEventListener) + { + ::Application::RemoveEventListener(m_aEventListenerLink); + m_bEventListener = false; + } +} + +// virtual +void SAL_CALL VCLXToolkit::fireFocusGained( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XInterface > const &) + throw (::com::sun::star::uno::RuntimeException) +{ +} + +// virtual +void SAL_CALL VCLXToolkit::fireFocusLost( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XInterface > const &) + throw (::com::sun::star::uno::RuntimeException) +{ +} + + +IMPL_LINK(VCLXToolkit, eventListenerHandler, ::VclSimpleEvent const *, pEvent) +{ + switch (pEvent->GetId()) + { + case VCLEVENT_WINDOW_SHOW: + callTopWindowListeners( + pEvent, &::css::awt::XTopWindowListener::windowOpened); + break; + case VCLEVENT_WINDOW_HIDE: + callTopWindowListeners( + pEvent, &::css::awt::XTopWindowListener::windowClosed); + break; + case VCLEVENT_WINDOW_ACTIVATE: + callTopWindowListeners( + pEvent, &::css::awt::XTopWindowListener::windowActivated); + break; + case VCLEVENT_WINDOW_DEACTIVATE: + callTopWindowListeners( + pEvent, &::css::awt::XTopWindowListener::windowDeactivated); + break; + case VCLEVENT_WINDOW_CLOSE: + callTopWindowListeners( + pEvent, &::css::awt::XTopWindowListener::windowClosing); + break; + case VCLEVENT_WINDOW_GETFOCUS: + callFocusListeners(pEvent, true); + break; + case VCLEVENT_WINDOW_LOSEFOCUS: + callFocusListeners(pEvent, false); + break; + case VCLEVENT_WINDOW_MINIMIZE: + callTopWindowListeners( + pEvent, &::css::awt::XTopWindowListener::windowMinimized); + break; + case VCLEVENT_WINDOW_NORMALIZE: + callTopWindowListeners( + pEvent, &::css::awt::XTopWindowListener::windowNormalized); + break; + } + return 0; +} + +IMPL_LINK(VCLXToolkit, keyListenerHandler, ::VclSimpleEvent const *, pEvent) +{ + switch (pEvent->GetId()) + { + case VCLEVENT_WINDOW_KEYINPUT: + return callKeyHandlers(pEvent, true); + case VCLEVENT_WINDOW_KEYUP: + return callKeyHandlers(pEvent, false); + } + return 0; +} + +void VCLXToolkit::callTopWindowListeners( + ::VclSimpleEvent const * pEvent, + void (SAL_CALL ::css::awt::XTopWindowListener::* pFn)( + ::css::lang::EventObject const &)) +{ + ::Window * pWindow + = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow(); + if (pWindow->IsTopWindow()) + { + ::css::uno::Sequence< ::css::uno::Reference< ::css::uno::XInterface > > + aListeners(m_aTopWindowListeners.getElements()); + if (aListeners.hasElements()) + { + ::css::lang::EventObject aAwtEvent( + static_cast< ::css::awt::XWindow * >(pWindow->GetWindowPeer())); + for (::sal_Int32 i = 0; i < aListeners.getLength(); ++i) + { + ::css::uno::Reference< ::css::awt::XTopWindowListener > + xListener(aListeners[i], ::css::uno::UNO_QUERY); + try + { + (xListener.get()->*pFn)(aAwtEvent); + } + catch (::css::uno::RuntimeException & rEx) + { + OSL_TRACE( + "VCLXToolkit::callTopWindowListeners: caught %s\n", + ::rtl::OUStringToOString( + rEx.Message, RTL_TEXTENCODING_UTF8).getStr()); + } + } + } + } +} + +long VCLXToolkit::callKeyHandlers(::VclSimpleEvent const * pEvent, + bool bPressed) +{ + ::css::uno::Sequence< ::css::uno::Reference< ::css::uno::XInterface > > + aHandlers(m_aKeyHandlers.getElements()); + + if (aHandlers.hasElements()) + { + ::Window * pWindow = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow(); + + // See implementation in vclxwindow.cxx for mapping between VCL and UNO AWT event + ::KeyEvent * pKeyEvent = static_cast< ::KeyEvent * >( + static_cast< ::VclWindowEvent const * >(pEvent)->GetData()); + ::css::awt::KeyEvent aAwtEvent( + static_cast< ::css::awt::XWindow * >(pWindow->GetWindowPeer()), + (pKeyEvent->GetKeyCode().IsShift() + ? ::css::awt::KeyModifier::SHIFT : 0) + | (pKeyEvent->GetKeyCode().IsMod1() + ? ::css::awt::KeyModifier::MOD1 : 0) + | (pKeyEvent->GetKeyCode().IsMod2() + ? ::css::awt::KeyModifier::MOD2 : 0) + | (pKeyEvent->GetKeyCode().IsMod3() + ? ::css::awt::KeyModifier::MOD3 : 0), + pKeyEvent->GetKeyCode().GetCode(), pKeyEvent->GetCharCode(), + sal::static_int_cast< sal_Int16 >( + pKeyEvent->GetKeyCode().GetFunction())); + for (::sal_Int32 i = 0; i < aHandlers.getLength(); ++i) + { + ::css::uno::Reference< ::css::awt::XKeyHandler > xHandler( + aHandlers[i], ::css::uno::UNO_QUERY); + try + { + if ((bPressed ? xHandler->keyPressed(aAwtEvent) + : xHandler->keyReleased(aAwtEvent))) + return 1; + } + catch (::css::uno::RuntimeException & rEx) + { + OSL_TRACE( + "VCLXToolkit::callKeyHandlers: caught %s\n", + ::rtl::OUStringToOString( + rEx.Message, RTL_TEXTENCODING_UTF8).getStr()); + } + } + } + return 0; +} + +void VCLXToolkit::callFocusListeners(::VclSimpleEvent const * pEvent, + bool bGained) +{ + ::Window * pWindow + = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow(); + if (pWindow->IsTopWindow()) + { + ::css::uno::Sequence< ::css::uno::Reference< ::css::uno::XInterface > > + aListeners(m_aFocusListeners.getElements()); + if (aListeners.hasElements()) + { + // Ignore the interior of compound controls when determining the + // window that gets the focus next (see implementation in + // vclxwindow.cxx for mapping between VCL and UNO AWT event): + ::css::uno::Reference< css::uno::XInterface > xNext; + ::Window * pFocus = ::Application::GetFocusWindow(); + for (::Window * p = pFocus; p != 0; p = p->GetParent()) + if (!p->IsCompoundControl()) + { + pFocus = p; + break; + } + if (pFocus != 0) + xNext = pFocus->GetComponentInterface(true); + ::css::awt::FocusEvent aAwtEvent( + static_cast< ::css::awt::XWindow * >(pWindow->GetWindowPeer()), + pWindow->GetGetFocusFlags(), xNext, false); + for (::sal_Int32 i = 0; i < aListeners.getLength(); ++i) + { + ::css::uno::Reference< ::css::awt::XFocusListener > xListener( + aListeners[i], ::css::uno::UNO_QUERY); + try + { + bGained ? xListener->focusGained(aAwtEvent) + : xListener->focusLost(aAwtEvent); + } + catch (::css::uno::RuntimeException & rEx) + { + OSL_TRACE( + "VCLXToolkit::callFocusListeners: caught %s\n", + ::rtl::OUStringToOString( + rEx.Message, RTL_TEXTENCODING_UTF8).getStr()); + } + } + } + } +} + +// css::awt::XReschedule: + +void SAL_CALL VCLXToolkit::reschedule() + throw (::com::sun::star::uno::RuntimeException) +{ + Application::Reschedule(true); +} + diff --git a/toolkit/source/awt/vclxtopwindow.cxx b/toolkit/source/awt/vclxtopwindow.cxx new file mode 100644 index 000000000000..10220a87de63 --- /dev/null +++ b/toolkit/source/awt/vclxtopwindow.cxx @@ -0,0 +1,345 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <com/sun/star/lang/SystemDependent.hpp> +#include <com/sun/star/awt/SystemDependentXWindow.hpp> + +#ifdef WNT +#include <tools/prewin.h> +#include <windows.h> +#include <tools/postwin.h> +#elif defined ( QUARTZ ) +#include "premac.h" +#include <Cocoa/Cocoa.h> +#include "postmac.h" +#endif + +#include <vcl/syschild.hxx> +#include <vcl/sysdata.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <comphelper/sequence.hxx> + +#include <toolkit/awt/vclxtopwindow.hxx> +#include <toolkit/awt/vclxmenu.hxx> +#include <toolkit/helper/macros.hxx> + +#include <vcl/wrkwin.hxx> +#include <vcl/syswin.hxx> +#include <vcl/menu.hxx> +#include <vcl/svapp.hxx> + +#include <tools/debug.hxx> + +using ::com::sun::star::uno::RuntimeException; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Type; +using ::com::sun::star::uno::Any; +using ::com::sun::star::lang::IndexOutOfBoundsException; + +VCLXTopWindow_Base::VCLXTopWindow_Base( const bool _bSupportSystemWindowPeer ) + :m_bWHWND( _bSupportSystemWindowPeer ) +{ +} + +VCLXTopWindow_Base::~VCLXTopWindow_Base() +{ +} + +Any VCLXTopWindow_Base::queryInterface( const Type & rType ) throw(RuntimeException) +{ + ::com::sun::star::uno::Any aRet( VCLXTopWindow_XBase::queryInterface( rType ) ); + + // do not expose XSystemDependentWindowPeer if we do not have a system window handle + if ( !aRet.hasValue() && m_bWHWND ) + aRet = VCLXTopWindow_SBase::queryInterface( rType ); + + return aRet; +} + +Sequence< Type > VCLXTopWindow_Base::getTypes() throw(RuntimeException) +{ + Sequence< Type > aTypes( VCLXTopWindow_XBase::getTypes() ); + if ( m_bWHWND ) + aTypes = ::comphelper::concatSequences( aTypes, VCLXTopWindow_SBase::getTypes() ); + return aTypes; +} + +::com::sun::star::uno::Any VCLXTopWindow_Base::getWindowHandle( const ::com::sun::star::uno::Sequence< sal_Int8 >& /*ProcessId*/, sal_Int16 SystemType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutexImpl() ); + + // TODO, check the process id + ::com::sun::star::uno::Any aRet; + Window* pWindow = GetWindowImpl(); + if ( pWindow ) + { + const SystemEnvData* pSysData = ((SystemWindow *)pWindow)->GetSystemData(); + if( pSysData ) + { +#if (defined WNT) + if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_WIN32 ) + { + aRet <<= (sal_Int32)pSysData->hWnd; + } +#elif (defined OS2) + if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_OS2 ) + { + aRet <<= (sal_Int32)pSysData->hWnd; + } +#elif (defined QUARTZ) + if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_MAC ) + { + aRet <<= (sal_IntPtr)pSysData->pView; + } +#elif (defined UNX) + if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_XWINDOW ) + { + ::com::sun::star::awt::SystemDependentXWindow aSD; + aSD.DisplayPointer = sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_IntPtr >(pSysData->pDisplay)); + aSD.WindowHandle = pSysData->aWindow; + aRet <<= aSD; + } +#endif + } + } + return aRet; +} + +void VCLXTopWindow_Base::addTopWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindowListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutexImpl() ); + + GetTopWindowListenersImpl().addInterface( rxListener ); +} + +void VCLXTopWindow_Base::removeTopWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindowListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutexImpl() ); + + GetTopWindowListenersImpl().removeInterface( rxListener ); +} + +void VCLXTopWindow_Base::toFront( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutexImpl() ); + + Window* pWindow = GetWindowImpl(); + if ( pWindow ) + ((WorkWindow*)pWindow)->ToTop( TOTOP_RESTOREWHENMIN ); +} + +void VCLXTopWindow_Base::toBack( ) throw(::com::sun::star::uno::RuntimeException) +{ +#if 0 // Not possible in VCL... + + ::vos::OGuard aGuard( GetMutexImpl() ); + + Window* pWindow = GetWindowImpl(); + if ( pWindow ) + { + ((WorkWindow*)pWindow)->ToBack(); + } +#endif +} + +void VCLXTopWindow_Base::setMenuBar( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuBar >& rxMenu ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutexImpl() ); + + SystemWindow* pWindow = (SystemWindow*) GetWindowImpl(); + if ( pWindow ) + { + pWindow->SetMenuBar( NULL ); + if ( rxMenu.is() ) + { + VCLXMenu* pMenu = VCLXMenu::GetImplementation( rxMenu ); + if ( pMenu && !pMenu->IsPopupMenu() ) + pWindow->SetMenuBar( (MenuBar*) pMenu->GetMenu() ); + } + } + mxMenuBar = rxMenu; +} + +//-------------------------------------------------------------------- +::sal_Bool SAL_CALL VCLXTopWindow_Base::getIsMaximized() throw (RuntimeException) +{ + ::vos::OGuard aGuard( GetMutexImpl() ); + + const WorkWindow* pWindow = dynamic_cast< const WorkWindow* >( GetWindowImpl() ); + if ( !pWindow ) + return sal_False; + + return pWindow->IsMaximized(); +} + +//-------------------------------------------------------------------- +void SAL_CALL VCLXTopWindow_Base::setIsMaximized( ::sal_Bool _ismaximized ) throw (RuntimeException) +{ + ::vos::OGuard aGuard( GetMutexImpl() ); + + WorkWindow* pWindow = dynamic_cast< WorkWindow* >( GetWindowImpl() ); + if ( !pWindow ) + return; + + pWindow->Maximize( _ismaximized ); +} + +//-------------------------------------------------------------------- +::sal_Bool SAL_CALL VCLXTopWindow_Base::getIsMinimized() throw (RuntimeException) +{ + ::vos::OGuard aGuard( GetMutexImpl() ); + + const WorkWindow* pWindow = dynamic_cast< const WorkWindow* >( GetWindowImpl() ); + if ( !pWindow ) + return sal_False; + + return pWindow->IsMinimized(); +} + +//-------------------------------------------------------------------- +void SAL_CALL VCLXTopWindow_Base::setIsMinimized( ::sal_Bool _isMinimized ) throw (RuntimeException) +{ + ::vos::OGuard aGuard( GetMutexImpl() ); + + WorkWindow* pWindow = dynamic_cast< WorkWindow* >( GetWindowImpl() ); + if ( !pWindow ) + return; + + _isMinimized ? pWindow->Minimize() : pWindow->Restore(); +} + +//-------------------------------------------------------------------- +::sal_Int32 SAL_CALL VCLXTopWindow_Base::getDisplay() throw (RuntimeException) +{ + ::vos::OGuard aGuard( GetMutexImpl() ); + + const SystemWindow* pWindow = dynamic_cast< const SystemWindow* >( GetWindowImpl() ); + if ( !pWindow ) + return 0; + + return pWindow->GetScreenNumber(); +} + +//-------------------------------------------------------------------- +void SAL_CALL VCLXTopWindow_Base::setDisplay( ::sal_Int32 _display ) throw (RuntimeException, IndexOutOfBoundsException) +{ + ::vos::OGuard aGuard( GetMutexImpl() ); + + if ( ( _display < 0 ) || ( _display >= (sal_Int32)Application::GetScreenCount() ) ) + throw IndexOutOfBoundsException(); + + SystemWindow* pWindow = dynamic_cast< SystemWindow* >( GetWindowImpl() ); + if ( !pWindow ) + return; + + pWindow->SetScreenNumber( _display ); +} + +// ---------------------------------------------------- +// class VCLXTopWindow +// ---------------------------------------------------- + +void VCLXTopWindow::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + VCLXContainer::ImplGetPropertyIds( rIds ); +} + +VCLXTopWindow::VCLXTopWindow(bool bWHWND) + : VCLXTopWindow_Base( bWHWND ) +{ +} + +VCLXTopWindow::~VCLXTopWindow() +{ +} + +vos::IMutex& VCLXTopWindow::GetMutexImpl() +{ + return VCLXContainer::GetMutex(); +} + +Window* VCLXTopWindow::GetWindowImpl() +{ + return VCLXContainer::GetWindow(); +} + +::cppu::OInterfaceContainerHelper& VCLXTopWindow::GetTopWindowListenersImpl() +{ + return GetTopWindowListeners(); +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXTopWindow::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet( VCLXTopWindow_Base::queryInterface( rType ) ); + + if ( !aRet.hasValue() ) + aRet = VCLXContainer::queryInterface( rType ); + + return aRet; +} + +::com::sun::star::uno::Sequence< sal_Int8 > VCLXTopWindow::getImplementationId() throw(::com::sun::star::uno::RuntimeException) +{ + static ::cppu::OImplementationId* pId = NULL; + static ::cppu::OImplementationId* pIdWithHandle = NULL; + if ( isSystemDependentWindowPeer() ) + { + if( !pIdWithHandle ) + { + ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !pIdWithHandle ) + { + static ::cppu::OImplementationId idWithHandle( sal_False ); + pIdWithHandle = &idWithHandle; + } + } + + return (*pIdWithHandle).getImplementationId(); + } + else + { + if( !pId ) + { + ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !pId ) + { + static ::cppu::OImplementationId id( sal_False ); + pId = &id; + } + } + + return (*pId).getImplementationId(); + } +} + +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > VCLXTopWindow::getTypes() throw(::com::sun::star::uno::RuntimeException) +{ + return ::comphelper::concatSequences( VCLXTopWindow_Base::getTypes(), VCLXContainer::getTypes() ); +} diff --git a/toolkit/source/awt/vclxwindow.cxx b/toolkit/source/awt/vclxwindow.cxx new file mode 100644 index 000000000000..248571819067 --- /dev/null +++ b/toolkit/source/awt/vclxwindow.cxx @@ -0,0 +1,2776 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <com/sun/star/awt/WindowEvent.hpp> +#include <com/sun/star/awt/KeyEvent.hpp> +#include <com/sun/star/awt/KeyModifier.hpp> +#include <com/sun/star/awt/MouseEvent.hpp> +#include <com/sun/star/awt/MouseButton.hpp> +#include <com/sun/star/awt/MouseWheelBehavior.hpp> +#include <com/sun/star/awt/XTopWindow.hpp> +#include <com/sun/star/awt/Style.hpp> +#include <com/sun/star/accessibility/AccessibleRole.hpp> +#include <com/sun/star/awt/DockingEvent.hpp> +#include <com/sun/star/awt/EndDockingEvent.hpp> +#include <com/sun/star/awt/EndPopupModeEvent.hpp> +#include <com/sun/star/awt/XWindowListener2.hpp> +#include <com/sun/star/style/VerticalAlignment.hpp> +#include <com/sun/star/text/WritingMode2.hpp> +#include <toolkit/awt/vclxwindow.hxx> +#include <toolkit/awt/vclxpointer.hxx> +#include <toolkit/awt/vclxwindows.hxx> +#include <toolkit/helper/macros.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <toolkit/helper/convert.hxx> +#include <toolkit/helper/macros.hxx> +#include <toolkit/helper/property.hxx> +#include <toolkit/helper/accessibilityclient.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <rtl/memory.h> +#include <rtl/uuid.h> +#include <rtl/ustrbuf.hxx> +#include <vcl/svapp.hxx> +#include <vcl/window.hxx> +#include <tools/color.hxx> +#include <vcl/dockwin.hxx> +#include <vcl/pdfextoutdevdata.hxx> +#include <vcl/tabpage.hxx> +#include <vcl/button.hxx> +#include <comphelper/asyncnotification.hxx> +#include <toolkit/helper/solarrelease.hxx> + +#include <toolkit/helper/unopropertyarrayhelper.hxx> + +using namespace ::com::sun::star; + +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::UNO_QUERY; +using ::com::sun::star::lang::EventObject; +using ::com::sun::star::awt::XWindowListener2; +using ::com::sun::star::awt::XDockableWindowListener; +using ::com::sun::star::awt::XDevice; +using ::com::sun::star::style::VerticalAlignment; +using ::com::sun::star::style::VerticalAlignment_TOP; +using ::com::sun::star::style::VerticalAlignment_MIDDLE; +using ::com::sun::star::style::VerticalAlignment_BOTTOM; +using ::com::sun::star::style::VerticalAlignment_MAKE_FIXED_SIZE; + +namespace WritingMode2 = ::com::sun::star::text::WritingMode2; +namespace MouseWheelBehavior = ::com::sun::star::awt::MouseWheelBehavior; + + +//==================================================================== +//= misc helpers +//==================================================================== +namespace +{ + //................................................................ + //. FlagGuard + //................................................................ + class FlagGuard + { + private: + bool& m_rFlag; + + public: + FlagGuard( bool& _rFlag ) + :m_rFlag( _rFlag ) + { + m_rFlag = true; + } + ~FlagGuard() + { + m_rFlag = false; + } + }; + + //................................................................ + //. MouseEventType + //................................................................ + enum MouseEventType + { + META_FIRST_MOUSE_EVENT = 0, + + EVENT_MOUSE_PRESSED = 0, + EVENT_MOUSE_RELEASED = 1, + EVENT_MOUSE_ENTERED = 2, + EVENT_MOUSE_EXITED = 3, + + META_LAST_MOUSE_EVENT = 3 + }; + + //................................................................ + //. PlainEventType + //................................................................ + enum PlainEventType + { + META_FIRST_PLAIN_EVENT = 4, + + EVENT_WINDOW_ENABLED = 4, + EVENT_WINDOW_DISABLED = 5, + + META_LAST_PLAIN_EVENT = 5 + }; + +#if OSL_DEBUG_LEVEL > 0 + static void checkEventDefinitions() + { + OSL_ENSURE( (int)META_LAST_MOUSE_EVENT < (int)META_FIRST_PLAIN_EVENT, "checkEventDefinitions: invalid event definitions!" ); + } + #define DBG_CHECK_EVENTS() checkEventDefinitions() +#else + #define DBG_CHECK_EVENTS() +#endif + + //................................................................ + //. AnyWindowEvent + //................................................................ + struct AnyWindowEvent : public ::comphelper::AnyEvent + { + private: + awt::MouseEvent m_aMouseEvent; + lang::EventObject m_aPlainEvent; + + sal_Int32 m_nEventType; + + public: + AnyWindowEvent( const awt::MouseEvent& _rEvent, MouseEventType _nType ) + :comphelper::AnyEvent() + ,m_aMouseEvent( _rEvent ) + ,m_nEventType( static_cast< sal_Int32 >( _nType ) ) + { + DBG_CHECK_EVENTS(); + } + + AnyWindowEvent( const lang::EventObject& _rEvent, PlainEventType _nType ) + :comphelper::AnyEvent() + ,m_aPlainEvent( _rEvent ) + ,m_nEventType( static_cast< sal_Int32 >( _nType ) ) + { + DBG_CHECK_EVENTS(); + } + + bool isMouseEvent() const + { + return ( META_FIRST_MOUSE_EVENT <= m_nEventType ) && ( m_nEventType <= META_LAST_MOUSE_EVENT ); + } + + bool isPlainEvent() const + { + return ( META_FIRST_PLAIN_EVENT <= m_nEventType ) && ( m_nEventType <= META_LAST_PLAIN_EVENT ); + } + + const awt::MouseEvent& getMouseEvent() const + { + OSL_ENSURE( isMouseEvent(), "AnyWindowEvent::getMouseEvent: no mouse event!" ); + return m_aMouseEvent; + } + + MouseEventType getMouseEventType() const + { + OSL_ENSURE( isMouseEvent(), "AnyWindowEvent::getMouseEventType: no mouse event!" ); + return static_cast< MouseEventType >( m_nEventType ); + } + + const lang::EventObject& getPlainEvent() const + { + OSL_ENSURE( isPlainEvent(), "AnyWindowEvent::getPlainEvent: no plain event!" ); + return m_aPlainEvent; + } + + PlainEventType getPlainEventType() const + { + OSL_ENSURE( isPlainEvent(), "AnyWindowEvent::getPlainEventType: no mouse event!" ); + return static_cast< PlainEventType >( m_nEventType ); + } + }; +} + +//==================================================================== +//= VCLXWindowImpl +//==================================================================== +class SAL_DLLPRIVATE VCLXWindowImpl : public ::comphelper::IEventProcessor +{ +private: + typedef ::std::vector< ::rtl::Reference< ::comphelper::AnyEvent > > + EventArray; + +private: + VCLXWindow& mrAntiImpl; + ::vos::IMutex& mrMutex; + ::toolkit::AccessibilityClient maAccFactory; + bool mbDisposed; + bool mbDrawingOntoParent; // no bit mask, is passed around by reference + sal_Bool mbEnableVisible; + sal_Bool mbDirectVisible; + + ::osl::Mutex maListenerContainerMutex; + ::cppu::OInterfaceContainerHelper maWindow2Listeners; + ::cppu::OInterfaceContainerHelper maDockableWindowListeners; + EventListenerMultiplexer maEventListeners; + FocusListenerMultiplexer maFocusListeners; + WindowListenerMultiplexer maWindowListeners; + KeyListenerMultiplexer maKeyListeners; + MouseListenerMultiplexer maMouseListeners; + MouseMotionListenerMultiplexer maMouseMotionListeners; + PaintListenerMultiplexer maPaintListeners; + VclContainerListenerMultiplexer maContainerListeners; + TopWindowListenerMultiplexer maTopWindowListeners; + + EventArray maEvents; + ULONG mnEventId; + +public: + bool mbDisposing : 1; + bool mbDesignMode : 1; + bool mbSynthesizingVCLEvent : 1; + bool mbWithDefaultProps : 1; + + ULONG mnListenerLockLevel; + sal_Int16 mnWritingMode; + sal_Int16 mnContextWritingMode; + + UnoPropertyArrayHelper* mpPropHelper; + + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPointer > + mxPointer; + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > + mxAccessibleContext; + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics > + mxViewGraphics; + +public: + bool& getDrawingOntoParent_ref() { return mbDrawingOntoParent; } + +public: + /** ctor + @param _pAntiImpl + the <type>VCLXWindow</type> instance which the object belongs to. Must + live longer then the object just being constructed. + */ + VCLXWindowImpl( VCLXWindow& _rAntiImpl, ::vos::IMutex& _rMutex, bool _bWithDefaultProps ); + + /** synchronously mbEnableVisible + */ + void setEnableVisible( sal_Bool bEnableVisible ) { mbEnableVisible = bEnableVisible; } + sal_Bool isEnableVisible() { return mbEnableVisible; } + /** synchronously mbDirectVisible; + */ + void setDirectVisible( sal_Bool bDirectVisible ) { mbDirectVisible = bDirectVisible; } + sal_Bool isDirectVisible() { return mbDirectVisible; } + + /** asynchronously notifies a mouse event to the VCLXWindow's XMouseListeners + */ + void notifyMouseEvent( const awt::MouseEvent& _rMouseEvent, MouseEventType _nType ); + + /** asynchronously notifies an event described by an EventObject to the respective listeners + */ + void notifyPlainEvent( const lang::EventObject& _rPlainEvent, PlainEventType _nType ); + + /** notifies the object that its VCLXWindow is being disposed + */ + void disposing(); + + inline ::toolkit::AccessibilityClient& getAccessibleFactory() + { + return maAccFactory; + } + + /** returns the container of registered XWindowListener2 listeners + */ + inline ::cppu::OInterfaceContainerHelper& getWindow2Listeners() { return maWindow2Listeners; } + inline ::cppu::OInterfaceContainerHelper& getDockableWindowListeners(){ return maDockableWindowListeners; } + inline EventListenerMultiplexer& getEventListeners() { return maEventListeners; } + inline FocusListenerMultiplexer& getFocusListeners() { return maFocusListeners; } + inline WindowListenerMultiplexer& getWindowListeners() { return maWindowListeners; } + inline KeyListenerMultiplexer& getKeyListeners() { return maKeyListeners; } + inline MouseListenerMultiplexer& getMouseListeners() { return maMouseListeners; } + inline MouseMotionListenerMultiplexer& getMouseMotionListeners() { return maMouseMotionListeners; } + inline PaintListenerMultiplexer& getPaintListeners() { return maPaintListeners; } + inline VclContainerListenerMultiplexer& getContainerListeners() { return maContainerListeners; } + inline TopWindowListenerMultiplexer& getTopWindowListeners() { return maTopWindowListeners; } + + virtual ~VCLXWindowImpl(); + +protected: + virtual void SAL_CALL acquire(); + virtual void SAL_CALL release(); + + // IEventProcessor + virtual void processEvent( const ::comphelper::AnyEvent& _rEvent ); + +private: + DECL_LINK( OnProcessEvent, void* ); + +private: + /** notifies an arbitrary event + @param _rEvent + the event to notify + */ + void impl_notifyAnyEvent( + const ::rtl::Reference< ::comphelper::AnyEvent >& _rEvent + ); + +private: + /** determines whether the instance is already disposed + @precond + m_aMutex must be acquired + */ + inline bool impl_isDisposed() + { + return mbDisposed; + } + +private: + VCLXWindowImpl(); // never implemented + VCLXWindowImpl( const VCLXWindowImpl& ); // never implemented + VCLXWindowImpl& operator=( const VCLXWindowImpl& ); // never implemented +}; + +//-------------------------------------------------------------------- +VCLXWindowImpl::VCLXWindowImpl( VCLXWindow& _rAntiImpl, ::vos::IMutex& _rMutex, bool _bWithDefaultProps ) + :mrAntiImpl( _rAntiImpl ) + ,mrMutex( _rMutex ) + ,mbDisposed( false ) + ,mbDrawingOntoParent( false ) + ,mbEnableVisible(sal_True) + ,mbDirectVisible(sal_True) + ,maListenerContainerMutex( ) + ,maWindow2Listeners( maListenerContainerMutex ) + ,maDockableWindowListeners( maListenerContainerMutex ) + ,maEventListeners( _rAntiImpl ) + ,maFocusListeners( _rAntiImpl ) + ,maWindowListeners( _rAntiImpl ) + ,maKeyListeners( _rAntiImpl ) + ,maMouseListeners( _rAntiImpl ) + ,maMouseMotionListeners( _rAntiImpl ) + ,maPaintListeners( _rAntiImpl ) + ,maContainerListeners( _rAntiImpl ) + ,maTopWindowListeners( _rAntiImpl ) + ,mnEventId( 0 ) + ,mbDisposing( false ) + ,mbDesignMode( false ) + ,mbSynthesizingVCLEvent( false ) + ,mbWithDefaultProps( _bWithDefaultProps ) + ,mnListenerLockLevel( 0 ) + ,mnWritingMode( WritingMode2::CONTEXT ) + ,mnContextWritingMode( WritingMode2::CONTEXT ) + ,mpPropHelper( NULL ) +{ +} + +VCLXWindowImpl::~VCLXWindowImpl() +{ + delete mpPropHelper; +} + +//-------------------------------------------------------------------- +void VCLXWindowImpl::disposing() +{ + ::vos::OGuard aGuard( mrMutex ); + if ( mnEventId ) + Application::RemoveUserEvent( mnEventId ); + mnEventId = 0; + mbDisposed= true; + + ::com::sun::star::lang::EventObject aEvent; + aEvent.Source = mrAntiImpl; + + maEventListeners.disposeAndClear( aEvent ); + maFocusListeners.disposeAndClear( aEvent ); + maWindowListeners.disposeAndClear( aEvent ); + maKeyListeners.disposeAndClear( aEvent ); + maMouseListeners.disposeAndClear( aEvent ); + maMouseMotionListeners.disposeAndClear( aEvent ); + maPaintListeners.disposeAndClear( aEvent ); + maContainerListeners.disposeAndClear( aEvent ); + maTopWindowListeners.disposeAndClear( aEvent ); + +} + +//-------------------------------------------------------------------- +void VCLXWindowImpl::impl_notifyAnyEvent( const ::rtl::Reference< ::comphelper::AnyEvent >& _rEvent ) +{ + maEvents.push_back( _rEvent ); + if ( !mnEventId ) + mnEventId = Application::PostUserEvent( LINK( this, VCLXWindowImpl, OnProcessEvent ) ); +} + +//-------------------------------------------------------------------- +void VCLXWindowImpl::notifyMouseEvent( const awt::MouseEvent& _rMouseEvent, MouseEventType _nType ) +{ + ::vos::OClearableGuard aGuard( mrMutex ); + if ( maMouseListeners.getLength() ) + impl_notifyAnyEvent( new AnyWindowEvent( _rMouseEvent, _nType ) ); +} + +//-------------------------------------------------------------------- +void VCLXWindowImpl::notifyPlainEvent( const lang::EventObject& _rPlainEvent, PlainEventType _nType ) +{ + ::vos::OClearableGuard aGuard( mrMutex ); + if ( maWindow2Listeners.getLength() ) + impl_notifyAnyEvent( new AnyWindowEvent( _rPlainEvent, _nType ) ); +} + +//-------------------------------------------------------------------- +IMPL_LINK( VCLXWindowImpl, OnProcessEvent, void*, EMPTYARG ) +{ + // work on a copy of the events array + EventArray aEventsCopy; + { + ::vos::OGuard aGuard( mrMutex ); + aEventsCopy = maEvents; + maEvents.clear(); + + if ( !mnEventId ) + // we were disposed while waiting for the mutex to lock + return 1L; + + mnEventId = 0; + } + + { + ::toolkit::ReleaseSolarMutex aReleaseSolar; + for ( EventArray::const_iterator loop = aEventsCopy.begin(); + loop != aEventsCopy.end(); + ++loop + ) + { + processEvent( *(*loop) ); + } + } + + return 0L; +} + +//-------------------------------------------------------------------- +void VCLXWindowImpl::processEvent( const ::comphelper::AnyEvent& _rEvent ) +{ + ::vos::OGuard aGuard( mrMutex ); + if ( impl_isDisposed() ) + // while we were waiting for our mutex, another thread disposed us + return; + + const AnyWindowEvent& rEventDescriptor( static_cast< const AnyWindowEvent& >( _rEvent ) ); + if ( rEventDescriptor.isMouseEvent() ) + { + const awt::MouseEvent& rEvent( rEventDescriptor.getMouseEvent() ); + switch ( rEventDescriptor.getMouseEventType() ) + { + case EVENT_MOUSE_PRESSED: + maMouseListeners.mousePressed( rEvent ); + break; + case EVENT_MOUSE_RELEASED: + maMouseListeners.mouseReleased( rEvent ); + break; + case EVENT_MOUSE_ENTERED: + maMouseListeners.mouseEntered( rEvent ); + break; + case EVENT_MOUSE_EXITED: + maMouseListeners.mouseExited( rEvent ); + break; + default: + DBG_ERROR( "VCLXWindowImpl::processEvent: what kind of event *is* this (1)?" ); + break; + } + } + else if ( rEventDescriptor.isPlainEvent() ) + { + const lang::EventObject& rEvent( rEventDescriptor.getPlainEvent() ); + switch ( rEventDescriptor.getPlainEventType() ) + { + case EVENT_WINDOW_ENABLED: + maWindow2Listeners.notifyEach( &XWindowListener2::windowEnabled, rEvent ); + break; + case EVENT_WINDOW_DISABLED: + maWindow2Listeners.notifyEach( &XWindowListener2::windowDisabled, rEvent ); + break; + default: + DBG_ERROR( "VCLXWindowImpl::processEvent: what kind of event *is* this (2)?" ); + break; + } + } + else + { + DBG_ERROR( "VCLXWindowImpl::processEvent: what kind of event *is* this (3)?" ); + } +} + +//-------------------------------------------------------------------- +void SAL_CALL VCLXWindowImpl::acquire() +{ + mrAntiImpl.acquire(); +} + +//-------------------------------------------------------------------- +void SAL_CALL VCLXWindowImpl::release() +{ + mrAntiImpl.release(); +} + +//==================================================================== +//==================================================================== + +// Mit Out-Parameter besser als Rueckgabewert, wegen Ref-Objekt... + +void ImplInitWindowEvent( ::com::sun::star::awt::WindowEvent& rEvent, Window* pWindow ) +{ + Point aPos = pWindow->GetPosPixel(); + Size aSz = pWindow->GetSizePixel(); + + rEvent.X = aPos.X(); + rEvent.Y = aPos.Y(); + + rEvent.Width = aSz.Width(); + rEvent.Height = aSz.Height(); + + pWindow->GetBorder( rEvent.LeftInset, rEvent.TopInset, rEvent.RightInset, rEvent.BottomInset ); +} + +// ---------------------------------------------------- +// class VCLXWindow +// ---------------------------------------------------- + +DBG_NAME(VCLXWindow); + +VCLXWindow::VCLXWindow( bool _bWithDefaultProps ) + :mpImpl( NULL ) +{ + DBG_CTOR( VCLXWindow, 0 ); + + mpImpl = new VCLXWindowImpl( *this, GetMutex(), _bWithDefaultProps ); +} + +VCLXWindow::~VCLXWindow() +{ + DBG_DTOR( VCLXWindow, 0 ); + + delete mpImpl; + + if ( GetWindow() ) + { + GetWindow()->RemoveEventListener( LINK( this, VCLXWindow, WindowEventListener ) ); + GetWindow()->SetWindowPeer( NULL, NULL ); + GetWindow()->SetAccessible( NULL ); + } +} + +::toolkit::IAccessibleFactory& VCLXWindow::getAccessibleFactory() +{ + return mpImpl->getAccessibleFactory().getFactory(); +} + +void VCLXWindow::SetWindow( Window* pWindow ) +{ + if ( GetWindow() ) + { + GetWindow()->RemoveEventListener( LINK( this, VCLXWindow, WindowEventListener ) ); +// GetWindow()->DbgAssertNoEventListeners(); + } + + SetOutputDevice( pWindow ); + + if ( GetWindow() ) + { + GetWindow()->AddEventListener( LINK( this, VCLXWindow, WindowEventListener ) ); + sal_Bool bDirectVisible = pWindow ? pWindow->IsVisible() : false; + mpImpl->setDirectVisible( bDirectVisible ); + } + +} + +void VCLXWindow::suspendVclEventListening( ) +{ + ++mpImpl->mnListenerLockLevel; +} + +void VCLXWindow::resumeVclEventListening( ) +{ + DBG_ASSERT( mpImpl->mnListenerLockLevel, "VCLXWindow::resumeVclEventListening: not suspended!" ); + --mpImpl->mnListenerLockLevel; +} + +void VCLXWindow::notifyWindowRemoved( Window& _rWindow ) +{ + if ( mpImpl->getContainerListeners().getLength() ) + { + awt::VclContainerEvent aEvent; + aEvent.Source = *this; + aEvent.Child = static_cast< XWindow* >( _rWindow.GetWindowPeer() ); + mpImpl->getContainerListeners().windowRemoved( aEvent ); + } +} + +IMPL_LINK( VCLXWindow, WindowEventListener, VclSimpleEvent*, pEvent ) +{ + if ( mpImpl->mnListenerLockLevel ) + return 0L; + + DBG_ASSERT( pEvent && pEvent->ISA( VclWindowEvent ), "Unknown WindowEvent!" ); + if ( pEvent && pEvent->ISA( VclWindowEvent ) ) + { + DBG_ASSERT( ((VclWindowEvent*)pEvent)->GetWindow() && GetWindow(), "Window???" ); + ProcessWindowEvent( *(VclWindowEvent*)pEvent ); + } + return 0; +} + +void VCLXWindow::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) +{ + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xThis( (::cppu::OWeakObject*)this ); + + switch ( rVclWindowEvent.GetId() ) + { + case VCLEVENT_WINDOW_ENABLED: + case VCLEVENT_WINDOW_DISABLED: + { + bool bEnabled = ( VCLEVENT_WINDOW_ENABLED == rVclWindowEvent.GetId() ); + EventObject aEvent( *this ); + mpImpl->notifyPlainEvent( aEvent, + bEnabled ? EVENT_WINDOW_ENABLED : EVENT_WINDOW_DISABLED ); + } + break; + + case VCLEVENT_WINDOW_PAINT: + { + if ( mpImpl->getPaintListeners().getLength() ) + { + ::com::sun::star::awt::PaintEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.UpdateRect = AWTRectangle( *(Rectangle*)rVclWindowEvent.GetData() ); + aEvent.Count = 0; + mpImpl->getPaintListeners().windowPaint( aEvent ); + } + } + break; + case VCLEVENT_WINDOW_MOVE: + { + if ( mpImpl->getWindowListeners().getLength() ) + { + ::com::sun::star::awt::WindowEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + ImplInitWindowEvent( aEvent, rVclWindowEvent.GetWindow() ); + mpImpl->getWindowListeners().windowMoved( aEvent ); + } + } + break; + case VCLEVENT_WINDOW_RESIZE: + { + if ( mpImpl->getWindowListeners().getLength() ) + { + ::com::sun::star::awt::WindowEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + ImplInitWindowEvent( aEvent, rVclWindowEvent.GetWindow() ); + mpImpl->getWindowListeners().windowResized( aEvent ); + } + } + break; + case VCLEVENT_WINDOW_SHOW: + { + if ( mpImpl->getWindowListeners().getLength() ) + { + ::com::sun::star::awt::WindowEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + ImplInitWindowEvent( aEvent, rVclWindowEvent.GetWindow() ); + mpImpl->getWindowListeners().windowShown( aEvent ); + } + + // For TopWindows this means opened... + if ( mpImpl->getTopWindowListeners().getLength() ) + { + ::com::sun::star::lang::EventObject aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + mpImpl->getTopWindowListeners().windowOpened( aEvent ); + } + } + break; + case VCLEVENT_WINDOW_HIDE: + { + if ( mpImpl->getWindowListeners().getLength() ) + { + ::com::sun::star::awt::WindowEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + ImplInitWindowEvent( aEvent, rVclWindowEvent.GetWindow() ); + mpImpl->getWindowListeners().windowHidden( aEvent ); + } + + // For TopWindows this means closed... + if ( mpImpl->getTopWindowListeners().getLength() ) + { + ::com::sun::star::lang::EventObject aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + mpImpl->getTopWindowListeners().windowClosed( aEvent ); + } + } + break; + case VCLEVENT_WINDOW_ACTIVATE: + { + if ( mpImpl->getTopWindowListeners().getLength() ) + { + ::com::sun::star::lang::EventObject aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + mpImpl->getTopWindowListeners().windowActivated( aEvent ); + } + } + break; + case VCLEVENT_WINDOW_DEACTIVATE: + { + if ( mpImpl->getTopWindowListeners().getLength() ) + { + ::com::sun::star::lang::EventObject aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + mpImpl->getTopWindowListeners().windowDeactivated( aEvent ); + } + } + break; + case VCLEVENT_WINDOW_CLOSE: + { + if ( mpImpl->getDockableWindowListeners().getLength() ) + { + ::com::sun::star::lang::EventObject aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::closed, aEvent ); + } + if ( mpImpl->getTopWindowListeners().getLength() ) + { + ::com::sun::star::lang::EventObject aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + mpImpl->getTopWindowListeners().windowClosing( aEvent ); + } + } + break; + case VCLEVENT_CONTROL_GETFOCUS: + case VCLEVENT_WINDOW_GETFOCUS: + { + if ( ( rVclWindowEvent.GetWindow()->IsCompoundControl() + && rVclWindowEvent.GetId() == VCLEVENT_CONTROL_GETFOCUS + ) + || ( !rVclWindowEvent.GetWindow()->IsCompoundControl() + && rVclWindowEvent.GetId() == VCLEVENT_WINDOW_GETFOCUS + ) + ) + { + if ( mpImpl->getFocusListeners().getLength() ) + { + ::com::sun::star::awt::FocusEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.FocusFlags = rVclWindowEvent.GetWindow()->GetGetFocusFlags(); + aEvent.Temporary = sal_False; + mpImpl->getFocusListeners().focusGained( aEvent ); + } + } + } + break; + case VCLEVENT_CONTROL_LOSEFOCUS: + case VCLEVENT_WINDOW_LOSEFOCUS: + { + if ( ( rVclWindowEvent.GetWindow()->IsCompoundControl() + && rVclWindowEvent.GetId() == VCLEVENT_CONTROL_LOSEFOCUS + ) + || ( !rVclWindowEvent.GetWindow()->IsCompoundControl() + && rVclWindowEvent.GetId() == VCLEVENT_WINDOW_LOSEFOCUS + ) + ) + { + if ( mpImpl->getFocusListeners().getLength() ) + { + ::com::sun::star::awt::FocusEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.FocusFlags = rVclWindowEvent.GetWindow()->GetGetFocusFlags(); + aEvent.Temporary = sal_False; + + Window* pNext = Application::GetFocusWindow(); + if ( pNext ) + { + // Bei zusammengesetzten Controls interessiert sich keiner fuer das Innenleben: + Window* pNextC = pNext; + while ( pNextC && !pNextC->IsCompoundControl() ) + pNextC = pNextC->GetParent(); + if ( pNextC ) + pNext = pNextC; + + pNext->GetComponentInterface( sal_True ); + aEvent.NextFocus = (::cppu::OWeakObject*)pNext->GetWindowPeer(); + } + mpImpl->getFocusListeners().focusLost( aEvent ); + } + } + } + break; + case VCLEVENT_WINDOW_MINIMIZE: + { + if ( mpImpl->getTopWindowListeners().getLength() ) + { + ::com::sun::star::lang::EventObject aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + mpImpl->getTopWindowListeners().windowMinimized( aEvent ); + } + } + break; + case VCLEVENT_WINDOW_NORMALIZE: + { + if ( mpImpl->getTopWindowListeners().getLength() ) + { + ::com::sun::star::lang::EventObject aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + mpImpl->getTopWindowListeners().windowNormalized( aEvent ); + } + } + break; + case VCLEVENT_WINDOW_KEYINPUT: + { + if ( mpImpl->getKeyListeners().getLength() ) + { + ::com::sun::star::awt::KeyEvent aEvent( VCLUnoHelper::createKeyEvent( + *(KeyEvent*)rVclWindowEvent.GetData(), *this + ) ); + mpImpl->getKeyListeners().keyPressed( aEvent ); + } + } + break; + case VCLEVENT_WINDOW_KEYUP: + { + if ( mpImpl->getKeyListeners().getLength() ) + { + ::com::sun::star::awt::KeyEvent aEvent( VCLUnoHelper::createKeyEvent( + *(KeyEvent*)rVclWindowEvent.GetData(), *this + ) ); + mpImpl->getKeyListeners().keyReleased( aEvent ); + } + } + break; + case VCLEVENT_WINDOW_COMMAND: + { + CommandEvent* pCmdEvt = (CommandEvent*)rVclWindowEvent.GetData(); + if ( mpImpl->getMouseListeners().getLength() && ( pCmdEvt->GetCommand() == COMMAND_CONTEXTMENU ) ) + { + // COMMAND_CONTEXTMENU als mousePressed mit PopupTrigger = sal_True versenden... + Point aWhere = static_cast< CommandEvent* >( rVclWindowEvent.GetData() )->GetMousePosPixel(); + if ( !pCmdEvt->IsMouseEvent() ) + { // for keyboard events, we set the coordinates to -1,-1. This is a slight HACK, but the current API + // handles a context menu command as special case of a mouse event, which is simply wrong. + // Without extending the API, we would not have another chance to notify listeners of a + // keyboard-triggered context menu request + // 102205 - 16.08.2002 - fs@openoffice.org + aWhere = Point( -1, -1 ); + } + + MouseEvent aMEvt( aWhere, 1, MOUSE_SIMPLECLICK, MOUSE_LEFT, 0 ); + awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( aMEvt, *this ) ); + aEvent.PopupTrigger = sal_True; + mpImpl->notifyMouseEvent( aEvent, EVENT_MOUSE_PRESSED ); + } + } + break; + case VCLEVENT_WINDOW_MOUSEMOVE: + { + MouseEvent* pMouseEvt = (MouseEvent*)rVclWindowEvent.GetData(); + if ( mpImpl->getMouseListeners().getLength() && ( pMouseEvt->IsEnterWindow() || pMouseEvt->IsLeaveWindow() ) ) + { + awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( *pMouseEvt, *this ) ); + mpImpl->notifyMouseEvent( + aEvent, + pMouseEvt->IsEnterWindow() ? EVENT_MOUSE_ENTERED : EVENT_MOUSE_EXITED + ); + } + + if ( mpImpl->getMouseMotionListeners().getLength() && !pMouseEvt->IsEnterWindow() && !pMouseEvt->IsLeaveWindow() ) + { + awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( *pMouseEvt, *this ) ); + aEvent.ClickCount = 0; // #92138# + if ( pMouseEvt->GetMode() & MOUSE_SIMPLEMOVE ) + mpImpl->getMouseMotionListeners().mouseMoved( aEvent ); + else + mpImpl->getMouseMotionListeners().mouseDragged( aEvent ); + } + } + break; + case VCLEVENT_WINDOW_MOUSEBUTTONDOWN: + { + if ( mpImpl->getMouseListeners().getLength() ) + { + awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( *(MouseEvent*)rVclWindowEvent.GetData(), *this ) ); + mpImpl->notifyMouseEvent( aEvent, EVENT_MOUSE_PRESSED ); + } + } + break; + case VCLEVENT_WINDOW_MOUSEBUTTONUP: + { + if ( mpImpl->getMouseListeners().getLength() ) + { + awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( *(MouseEvent*)rVclWindowEvent.GetData(), *this ) ); + mpImpl->notifyMouseEvent( aEvent, EVENT_MOUSE_RELEASED ); + } + } + break; + case VCLEVENT_WINDOW_STARTDOCKING: + { + if ( mpImpl->getDockableWindowListeners().getLength() ) + { + DockingData *pData = (DockingData*)rVclWindowEvent.GetData(); + + if( pData ) + { + ::com::sun::star::awt::DockingEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.TrackingRectangle = AWTRectangle( pData->maTrackRect ); + aEvent.MousePos.X = pData->maMousePos.X(); + aEvent.MousePos.Y = pData->maMousePos.Y(); + aEvent.bLiveMode = pData->mbLivemode; + aEvent.bInteractive = pData->mbInteractive; + + mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::startDocking, aEvent ); + } + } + } + break; + case VCLEVENT_WINDOW_DOCKING: + { + if ( mpImpl->getDockableWindowListeners().getLength() ) + { + DockingData *pData = (DockingData*)rVclWindowEvent.GetData(); + + if( pData ) + { + ::com::sun::star::awt::DockingEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.TrackingRectangle = AWTRectangle( pData->maTrackRect ); + aEvent.MousePos.X = pData->maMousePos.X(); + aEvent.MousePos.Y = pData->maMousePos.Y(); + aEvent.bLiveMode = pData->mbLivemode; + aEvent.bInteractive = pData->mbInteractive; + + Reference< XDockableWindowListener > xFirstListener; + ::cppu::OInterfaceIteratorHelper aIter( mpImpl->getDockableWindowListeners() ); + while ( aIter.hasMoreElements() && !xFirstListener.is() ) + { + xFirstListener.set( aIter.next(), UNO_QUERY ); + } + + ::com::sun::star::awt::DockingData aDockingData = + xFirstListener->docking( aEvent ); + pData->maTrackRect = VCLRectangle( aDockingData.TrackingRectangle ); + pData->mbFloating = aDockingData.bFloating; + } + } + } + break; + case VCLEVENT_WINDOW_ENDDOCKING: + { + if ( mpImpl->getDockableWindowListeners().getLength() ) + { + EndDockingData *pData = (EndDockingData*)rVclWindowEvent.GetData(); + + if( pData ) + { + ::com::sun::star::awt::EndDockingEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.WindowRectangle = AWTRectangle( pData->maWindowRect ); + aEvent.bFloating = pData->mbFloating; + aEvent.bCancelled = pData->mbCancelled; + mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::endDocking, aEvent ); + } + } + } + break; + case VCLEVENT_WINDOW_PREPARETOGGLEFLOATING: + { + if ( mpImpl->getDockableWindowListeners().getLength() ) + { + BOOL *p_bFloating = (BOOL*)rVclWindowEvent.GetData(); + + ::com::sun::star::lang::EventObject aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + + Reference< XDockableWindowListener > xFirstListener; + ::cppu::OInterfaceIteratorHelper aIter( mpImpl->getDockableWindowListeners() ); + while ( aIter.hasMoreElements() && !xFirstListener.is() ) + { + xFirstListener.set( aIter.next(), UNO_QUERY ); + } + + *p_bFloating = xFirstListener->prepareToggleFloatingMode( aEvent ); + } + } + break; + case VCLEVENT_WINDOW_TOGGLEFLOATING: + { + if ( mpImpl->getDockableWindowListeners().getLength() ) + { + ::com::sun::star::lang::EventObject aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::toggleFloatingMode, aEvent ); + } + } + break; + case VCLEVENT_WINDOW_ENDPOPUPMODE: + { + if ( mpImpl->getDockableWindowListeners().getLength() ) + { + EndPopupModeData *pData = (EndPopupModeData*)rVclWindowEvent.GetData(); + + if( pData ) + { + ::com::sun::star::awt::EndPopupModeEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.FloatingPosition.X = pData->maFloatingPos.X(); + aEvent.FloatingPosition.Y = pData->maFloatingPos.Y(); + aEvent.bTearoff = pData->mbTearoff; + mpImpl->getDockableWindowListeners().notifyEach( &XDockableWindowListener::endPopupMode, aEvent ); + } + } + } + break; + + } +} + +uno::Reference< accessibility::XAccessibleContext > VCLXWindow::CreateAccessibleContext() +{ + ::vos::OGuard aGuard( GetMutex() ); + return getAccessibleFactory().createAccessibleContext( this ); +} + +void VCLXWindow::SetSynthesizingVCLEvent( sal_Bool _b ) +{ + mpImpl->mbSynthesizingVCLEvent = _b; +} + +BOOL VCLXWindow::IsSynthesizingVCLEvent() const +{ + return mpImpl->mbSynthesizingVCLEvent; +} + +Size VCLXWindow::ImplCalcWindowSize( const Size& rOutSz ) const +{ + Size aSz = rOutSz; + + Window* pWindow = GetWindow(); + if ( pWindow ) + { + sal_Int32 nLeft, nTop, nRight, nBottom; + pWindow->GetBorder( nLeft, nTop, nRight, nBottom ); + aSz.Width() += nLeft+nRight; + aSz.Height() += nTop+nBottom; + } + return aSz; +} + + +// ::com::sun::star::lang::XUnoTunnel +IMPL_XUNOTUNNEL2( VCLXWindow, VCLXDevice ) + +// ::com::sun::star::lang::Component +void VCLXWindow::dispose( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + mpImpl->mxViewGraphics = NULL; + + if ( !mpImpl->mbDisposing ) + { + mpImpl->mbDisposing = true; + + mpImpl->disposing(); + + if ( GetWindow() ) + { + OutputDevice* pOutDev = GetOutputDevice(); + SetWindow( NULL ); // Damit ggf. Handler abgemeldet werden (virtuell). + SetOutputDevice( pOutDev ); + DestroyOutputDevice(); + } + + // #i14103# dispose the accessible context after the window has been destroyed, + // otherwise the old value in the child event fired in VCLXAccessibleComponent::ProcessWindowEvent() + // for VCLEVENT_WINDOW_CHILDDESTROYED contains a reference to an already disposed accessible object + try + { + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xComponent( mpImpl->mxAccessibleContext, ::com::sun::star::uno::UNO_QUERY ); + if ( xComponent.is() ) + xComponent->dispose(); + } + catch ( const ::com::sun::star::uno::Exception& ) + { + DBG_ERROR( "VCLXWindow::dispose: could not dispose the accessible context!" ); + } + mpImpl->mxAccessibleContext.clear(); + + mpImpl->mbDisposing = false; + } +} + +void VCLXWindow::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + mpImpl->getEventListeners().addInterface( rxListener ); +} + +void VCLXWindow::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + mpImpl->getEventListeners().removeInterface( rxListener ); +} + + +// ::com::sun::star::awt::XWindow +void VCLXWindow::setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + { + if( Window::GetDockingManager()->IsDockable( GetWindow() ) ) + Window::GetDockingManager()->SetPosSizePixel( GetWindow() , X, Y, Width, Height, Flags ); + else + GetWindow()->SetPosSizePixel( X, Y, Width, Height, Flags ); + } +} + +::com::sun::star::awt::Rectangle VCLXWindow::getPosSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::awt::Rectangle aBounds; + if ( GetWindow() ) + { + if( Window::GetDockingManager()->IsDockable( GetWindow() ) ) + aBounds = AWTRectangle( Window::GetDockingManager()->GetPosSizePixel( GetWindow() ) ); + else + aBounds = AWTRectangle( Rectangle( GetWindow()->GetPosPixel(), GetWindow()->GetSizePixel() ) ); + } + + return aBounds; +} + +void VCLXWindow::setVisible( sal_Bool bVisible ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if ( pWindow ) + { +/* + if ( bVisible ) + { + // #57167# TopWindows mit unsichtbaren Parent anzeigen... + ::com::sun::star::uno::Any aTest = queryInterface( ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindow >*) 0 ) ); + if ( aTest.hasValue() ) + { + Window* pParent = pWindow->GetWindow( WINDOW_PARENTOVERLAP ); + if ( pParent && !pParent->IsReallyVisible() ) + pWindow->SetParent( pWindow->GetWindow( WINDOW_FRAME ) ); + } + } +*/ + mpImpl->setDirectVisible( bVisible ); + pWindow->Show( bVisible && mpImpl->isEnableVisible() ); + } +} + +void VCLXWindow::setEnable( sal_Bool bEnable ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if ( pWindow ) + { + pWindow->Enable( bEnable, FALSE ); // #95824# without children! + pWindow->EnableInput( bEnable ); + } +} + +void VCLXWindow::setFocus( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + GetWindow()->GrabFocus(); +} + +void VCLXWindow::addWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + mpImpl->getWindowListeners().addInterface( rxListener ); + + Reference< XWindowListener2 > xListener2( rxListener, UNO_QUERY ); + if ( xListener2.is() ) + mpImpl->getWindow2Listeners().addInterface( xListener2 ); + + // #100119# Get all resize events, even if height or width 0, or invisible + if ( GetWindow() ) + GetWindow()->EnableAllResize( TRUE ); +} + +void VCLXWindow::removeWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Reference< XWindowListener2 > xListener2( rxListener, UNO_QUERY ); + if ( xListener2.is() ) + mpImpl->getWindow2Listeners().removeInterface( xListener2 ); + + mpImpl->getWindowListeners().removeInterface( rxListener ); +} + +void VCLXWindow::addFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + mpImpl->getFocusListeners().addInterface( rxListener ); +} + +void VCLXWindow::removeFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + mpImpl->getFocusListeners().removeInterface( rxListener ); +} + +void VCLXWindow::addKeyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + mpImpl->getKeyListeners().addInterface( rxListener ); +} + +void VCLXWindow::removeKeyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + mpImpl->getKeyListeners().removeInterface( rxListener ); +} + +void VCLXWindow::addMouseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + mpImpl->getMouseListeners().addInterface( rxListener ); +} + +void VCLXWindow::removeMouseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + mpImpl->getMouseListeners().removeInterface( rxListener ); +} + +void VCLXWindow::addMouseMotionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseMotionListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + mpImpl->getMouseMotionListeners().addInterface( rxListener ); +} + +void VCLXWindow::removeMouseMotionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseMotionListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + mpImpl->getMouseMotionListeners().removeInterface( rxListener ); +} + +void VCLXWindow::addPaintListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + mpImpl->getPaintListeners().addInterface( rxListener ); +} + +void VCLXWindow::removePaintListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + mpImpl->getPaintListeners().removeInterface( rxListener ); +} + +// ::com::sun::star::awt::XWindowPeer +::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit > VCLXWindow::getToolkit( ) throw(::com::sun::star::uno::RuntimeException) +{ + // no guard. nothing to guard here. + // 82463 - 12/21/00 - fs + return Application::GetVCLToolkit(); +} + +void VCLXWindow::setPointer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPointer >& rxPointer ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + VCLXPointer* pPointer = VCLXPointer::GetImplementation( rxPointer ); + if ( pPointer ) + { + mpImpl->mxPointer = rxPointer; + if ( GetWindow() ) + GetWindow()->SetPointer( pPointer->GetPointer() ); + } +} + +void VCLXWindow::setBackground( sal_Int32 nColor ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + { + Color aColor( (sal_uInt32)nColor ); + GetWindow()->SetBackground( aColor ); + GetWindow()->SetControlBackground( aColor ); + + WindowType eWinType = GetWindow()->GetType(); + if ( ( eWinType == WINDOW_WINDOW ) || + ( eWinType == WINDOW_WORKWINDOW ) || + ( eWinType == WINDOW_FLOATINGWINDOW ) ) + { + GetWindow()->Invalidate(); + } + } +} + +void VCLXWindow::invalidate( sal_Int16 nInvalidateFlags ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + GetWindow()->Invalidate( (sal_uInt16) nInvalidateFlags ); +} + +void VCLXWindow::invalidateRect( const ::com::sun::star::awt::Rectangle& rRect, sal_Int16 nInvalidateFlags ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + GetWindow()->Invalidate( VCLRectangle(rRect), (sal_uInt16) nInvalidateFlags ); +} + + +// ::com::sun::star::awt::XVclWindowPeer +sal_Bool VCLXWindow::isChild( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& rxPeer ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + sal_Bool bIsChild = sal_False; + Window* pWindow = GetWindow(); + if ( pWindow ) + { + Window* pPeerWindow = VCLUnoHelper::GetWindow( rxPeer ); + bIsChild = pPeerWindow && pWindow->IsChild( pPeerWindow ); + } + + return bIsChild; +} + +void VCLXWindow::setDesignMode( sal_Bool bOn ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + mpImpl->mbDesignMode = bOn; +} + +sal_Bool VCLXWindow::isDesignMode( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + return mpImpl->mbDesignMode; +} + +void VCLXWindow::enableClipSiblings( sal_Bool bClip ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + GetWindow()->EnableClipSiblings( bClip ); +} + +void VCLXWindow::setForeground( sal_Int32 nColor ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + { + Color aColor( (sal_uInt32)nColor ); + GetWindow()->SetControlForeground( aColor ); + } +} + +void VCLXWindow::setControlFont( const ::com::sun::star::awt::FontDescriptor& rFont ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + GetWindow()->SetControlFont( VCLUnoHelper::CreateFont( rFont, GetWindow()->GetControlFont() ) ); +} + +void VCLXWindow::getStyles( sal_Int16 nType, ::com::sun::star::awt::FontDescriptor& Font, sal_Int32& ForegroundColor, sal_Int32& BackgroundColor ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + { + const StyleSettings& rStyleSettings = GetWindow()->GetSettings().GetStyleSettings(); + + switch ( nType ) + { + case ::com::sun::star::awt::Style::FRAME: + { + Font = VCLUnoHelper::CreateFontDescriptor( rStyleSettings.GetAppFont() ); + ForegroundColor = rStyleSettings.GetWindowTextColor().GetColor(); + BackgroundColor = rStyleSettings.GetWindowColor().GetColor(); + } + break; + case ::com::sun::star::awt::Style::DIALOG: + { + Font = VCLUnoHelper::CreateFontDescriptor( rStyleSettings.GetAppFont() ); + ForegroundColor = rStyleSettings.GetDialogTextColor().GetColor(); + BackgroundColor = rStyleSettings.GetDialogColor().GetColor(); + } + break; + default: DBG_ERROR( "VCLWindow::getStyles() - unknown Type" ); + } + + } +} + +namespace toolkit +{ + static void setColorSettings( Window* _pWindow, const ::com::sun::star::uno::Any& _rValue, + void (StyleSettings::*pSetter)( const Color& ), const Color& (StyleSettings::*pGetter)( ) const ) + { + sal_Int32 nColor = 0; + if ( !( _rValue >>= nColor ) ) + nColor = (Application::GetSettings().GetStyleSettings().*pGetter)().GetColor(); + + AllSettings aSettings = _pWindow->GetSettings(); + StyleSettings aStyleSettings = aSettings.GetStyleSettings(); + + (aStyleSettings.*pSetter)( Color( nColor ) ); + + aSettings.SetStyleSettings( aStyleSettings ); + _pWindow->SetSettings( aSettings, TRUE ); + } +} + +// Terminated by BASEPROPERTY_NOTFOUND (or 0) +void VCLXWindow::PushPropertyIds( std::list< sal_uInt16 > &rIds, + int nFirstId, ...) +{ + va_list pVarArgs; + va_start( pVarArgs, nFirstId ); + + for ( int nId = nFirstId; nId != BASEPROPERTY_NOTFOUND; + nId = va_arg( pVarArgs, int ) ) + rIds.push_back( (sal_uInt16) nId ); + + va_end( pVarArgs ); +} + +void VCLXWindow::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds, bool bWithDefaults ) +{ + // These are common across ~all VCLXWindow derived classes + if( bWithDefaults ) + PushPropertyIds( rIds, + BASEPROPERTY_ALIGN, + BASEPROPERTY_BACKGROUNDCOLOR, + BASEPROPERTY_BORDER, + BASEPROPERTY_BORDERCOLOR, + BASEPROPERTY_DEFAULTCONTROL, + BASEPROPERTY_ENABLED, + BASEPROPERTY_FONTDESCRIPTOR, + BASEPROPERTY_HELPTEXT, + BASEPROPERTY_HELPURL, + BASEPROPERTY_TEXT, + BASEPROPERTY_PRINTABLE, + BASEPROPERTY_ENABLEVISIBLE, // for visibility + BASEPROPERTY_TABSTOP, + 0); + + // lovely hack from: + // void UnoControlModel::ImplRegisterProperty( sal_uInt16 nPropId ) + std::list< sal_uInt16 >::const_iterator iter; + for( iter = rIds.begin(); iter != rIds.end(); iter++) { + if( *iter == BASEPROPERTY_FONTDESCRIPTOR ) + { + // some properties are not included in the FontDescriptor, but everytime + // when we have a FontDescriptor we want to have these properties too. + // => Easier to register the here, istead everywhere where I register the FontDescriptor... + + rIds.push_back( BASEPROPERTY_TEXTCOLOR ); + rIds.push_back( BASEPROPERTY_TEXTLINECOLOR ); + rIds.push_back( BASEPROPERTY_FONTRELIEF ); + rIds.push_back( BASEPROPERTY_FONTEMPHASISMARK ); + break; + } + } +} + +void VCLXWindow::GetPropertyIds( std::list< sal_uInt16 >& _out_rIds ) +{ + return ImplGetPropertyIds( _out_rIds, mpImpl->mbWithDefaultProps ); +} + +::cppu::OInterfaceContainerHelper& VCLXWindow::GetContainerListeners() +{ + return mpImpl->getContainerListeners(); +} + +::cppu::OInterfaceContainerHelper& VCLXWindow::GetTopWindowListeners() +{ + return mpImpl->getTopWindowListeners(); +} + +namespace +{ + void lcl_updateWritingMode( Window& _rWindow, const sal_Int16 _nWritingMode, const sal_Int16 _nContextWritingMode ) + { + BOOL bEnableRTL = FALSE; + switch ( _nWritingMode ) + { + case WritingMode2::LR_TB: bEnableRTL = FALSE; break; + case WritingMode2::RL_TB: bEnableRTL = TRUE; break; + case WritingMode2::CONTEXT: + { + // consult our ContextWritingMode. If it has an explicit RTL/LTR value, then use + // it. If it doesn't (but is CONTEXT itself), then just ask the parent window of our + // own window for its RTL mode + switch ( _nContextWritingMode ) + { + case WritingMode2::LR_TB: bEnableRTL = FALSE; break; + case WritingMode2::RL_TB: bEnableRTL = TRUE; break; + case WritingMode2::CONTEXT: + { + const Window* pParent = _rWindow.GetParent(); + OSL_ENSURE( pParent, "lcl_updateWritingMode: cannot determine context's writing mode!" ); + if ( pParent ) + bEnableRTL = pParent->IsRTLEnabled(); + } + break; + } + } + break; + default: + OSL_ENSURE( false, "lcl_updateWritingMode: unsupported WritingMode!" ); + } // switch ( nWritingMode ) + + _rWindow.EnableRTL( bEnableRTL ); + } +} + +void VCLXWindow::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if ( !pWindow ) + return; + + sal_Bool bVoid = Value.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID; + + WindowType eWinType = pWindow->GetType(); + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_REFERENCE_DEVICE: + { + Control* pControl = dynamic_cast< Control* >( pWindow ); + OSL_ENSURE( pControl, "VCLXWindow::setProperty( RefDevice ): need a Control for this!" ); + if ( !pControl ) + break; + Reference< XDevice > xDevice( Value, UNO_QUERY ); + OutputDevice* pDevice = VCLUnoHelper::GetOutputDevice( xDevice ); + pControl->SetReferenceDevice( pDevice ); + } + break; + + case BASEPROPERTY_CONTEXT_WRITING_MODE: + { + OSL_VERIFY( Value >>= mpImpl->mnContextWritingMode ); + if ( mpImpl->mnWritingMode == WritingMode2::CONTEXT ) + lcl_updateWritingMode( *pWindow, mpImpl->mnWritingMode, mpImpl->mnContextWritingMode ); + } + break; + + case BASEPROPERTY_WRITING_MODE: + { + sal_Bool bProperType = ( Value >>= mpImpl->mnWritingMode ); + OSL_ENSURE( bProperType, "VCLXWindow::setProperty( 'WritingMode' ): illegal value type!" ); + if ( bProperType ) + lcl_updateWritingMode( *pWindow, mpImpl->mnWritingMode, mpImpl->mnContextWritingMode ); + } + break; + + case BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR: + { + sal_uInt16 nWheelBehavior( MouseWheelBehavior::SCROLL_FOCUS_ONLY ); + OSL_VERIFY( Value >>= nWheelBehavior ); + + AllSettings aSettings = pWindow->GetSettings(); + MouseSettings aMouseSettings = aSettings.GetMouseSettings(); + + USHORT nVclBehavior( MOUSE_WHEEL_FOCUS_ONLY ); + switch ( nWheelBehavior ) + { + case MouseWheelBehavior::SCROLL_DISABLED: nVclBehavior = MOUSE_WHEEL_DISABLE; break; + case MouseWheelBehavior::SCROLL_FOCUS_ONLY: nVclBehavior = MOUSE_WHEEL_FOCUS_ONLY; break; + case MouseWheelBehavior::SCROLL_ALWAYS: nVclBehavior = MOUSE_WHEEL_ALWAYS; break; + default: + OSL_ENSURE( false, "VCLXWindow::setProperty( 'MouseWheelBehavior' ): illegal property value!" ); + } + + aMouseSettings.SetWheelBehavior( nWheelBehavior ); + aSettings.SetMouseSettings( aMouseSettings ); + pWindow->SetSettings( aSettings, TRUE ); + } + break; + + case BASEPROPERTY_NATIVE_WIDGET_LOOK: + { + sal_Bool bEnable( sal_True ); + OSL_VERIFY( Value >>= bEnable ); + pWindow->EnableNativeWidget( bEnable ); + } + break; + + case BASEPROPERTY_PLUGINPARENT: + { + // set parent handle + SetSystemParent_Impl( Value ); + } + break; + + case BASEPROPERTY_ENABLED: + { + sal_Bool b = sal_Bool(); + if ( Value >>= b ) + setEnable( b ); + } + break; + case BASEPROPERTY_ENABLEVISIBLE: + { + sal_Bool b = sal_False; + if ( Value >>= b ) + { + if( b != mpImpl->isEnableVisible() ) + { + mpImpl->setEnableVisible( b ); + pWindow->Show( b && mpImpl->isDirectVisible() ); + } + } + } + break; + case BASEPROPERTY_TEXT: + case BASEPROPERTY_LABEL: + case BASEPROPERTY_TITLE: + { + ::rtl::OUString aText; + if ( Value >>= aText ) + { + switch (eWinType) + { + case WINDOW_OKBUTTON: + case WINDOW_CANCELBUTTON: + case WINDOW_HELPBUTTON: + // Standard Button: overwrite only if not empty. + if (aText.getLength()) + pWindow->SetText( aText ); + break; + + default: + pWindow->SetText( aText ); + break; + } + } + } + break; + case BASEPROPERTY_ACCESSIBLENAME: + { + ::rtl::OUString aText; + if ( Value >>= aText ) + pWindow->SetAccessibleName( aText ); + } + break; + case BASEPROPERTY_HELPURL: + { + ::rtl::OUString aURL; + if ( Value >>= aURL ) + { + String aHelpURL( aURL ); + String aPattern( RTL_CONSTASCII_USTRINGPARAM( "HID:" ) ); + if ( aHelpURL.CompareIgnoreCaseToAscii( aPattern, aPattern.Len() ) == COMPARE_EQUAL ) + { + String aID = aHelpURL.Copy( aPattern.Len() ); + pWindow->SetHelpId( aID.ToInt32() ); + } + else + { + pWindow->SetSmartHelpId( SmartId( aHelpURL ) ); + } + } + } + break; + case BASEPROPERTY_HELPTEXT: + { + ::rtl::OUString aHelpText; + if ( Value >>= aHelpText ) + { + pWindow->SetQuickHelpText( aHelpText ); + } + } + break; + case BASEPROPERTY_FONTDESCRIPTOR: + { + if ( bVoid ) + pWindow->SetControlFont( Font() ); + else + { + ::com::sun::star::awt::FontDescriptor aFont; + if ( Value >>= aFont ) + pWindow->SetControlFont( VCLUnoHelper::CreateFont( aFont, pWindow->GetControlFont() ) ); + } + } + break; + case BASEPROPERTY_FONTRELIEF: + { + sal_Int16 n = sal_Int16(); + if ( Value >>= n ) + { + Font aFont = pWindow->GetControlFont(); + aFont.SetRelief( (FontRelief)n ); + pWindow->SetControlFont( aFont ); + } + } + break; + case BASEPROPERTY_FONTEMPHASISMARK: + { + sal_Int16 n = sal_Int16(); + if ( Value >>= n ) + { + Font aFont = pWindow->GetControlFont(); + aFont.SetEmphasisMark( n ); + pWindow->SetControlFont( aFont ); + } + } + break; + case BASEPROPERTY_BACKGROUNDCOLOR: + if ( bVoid ) + { + switch ( eWinType ) + { + // set dialog color for default + case WINDOW_DIALOG: + case WINDOW_MESSBOX: + case WINDOW_INFOBOX: + case WINDOW_WARNINGBOX: + case WINDOW_ERRORBOX: + case WINDOW_QUERYBOX: + case WINDOW_TABPAGE: + { + Color aColor = pWindow->GetSettings().GetStyleSettings().GetDialogColor(); + pWindow->SetBackground( aColor ); + pWindow->SetControlBackground( aColor ); + break; + } + + case WINDOW_FIXEDTEXT: + case WINDOW_CHECKBOX: + case WINDOW_RADIOBUTTON: + case WINDOW_GROUPBOX: + case WINDOW_FIXEDLINE: + { + // support transparency only for special controls + pWindow->SetBackground(); + pWindow->SetControlBackground(); + pWindow->SetPaintTransparent( TRUE ); + break; + } + + default: + { + // default code which enables transparency for + // compound controls. It's not real transparency + // as most of these controls repaint their client + // area completely new. + if ( pWindow->IsCompoundControl() ) + pWindow->SetBackground(); + pWindow->SetControlBackground(); + break; + } + } + } + else + { + sal_Int32 nColor = 0; + if ( Value >>= nColor ) + { + Color aColor( nColor ); + pWindow->SetControlBackground( aColor ); + pWindow->SetBackground( aColor ); + switch ( eWinType ) + { + // reset paint transparent mode + case WINDOW_FIXEDTEXT: + case WINDOW_CHECKBOX: + case WINDOW_RADIOBUTTON: + case WINDOW_GROUPBOX: + case WINDOW_FIXEDLINE: + pWindow->SetPaintTransparent( FALSE ); + default: ; + } + pWindow->Invalidate(); // Falls das Control nicht drauf reagiert + } + } + break; + case BASEPROPERTY_TEXTCOLOR: + if ( bVoid ) + { + pWindow->SetControlForeground(); + } + else + { + sal_Int32 nColor = 0; + if ( Value >>= nColor ) + { + Color aColor( nColor ); + pWindow->SetTextColor( aColor ); + pWindow->SetControlForeground( aColor ); + } + } + break; + case BASEPROPERTY_TEXTLINECOLOR: + if ( bVoid ) + { + pWindow->SetTextLineColor(); + } + else + { + sal_Int32 nColor = 0; + if ( Value >>= nColor ) + { + Color aColor( nColor ); + pWindow->SetTextLineColor( aColor ); + } + } + break; + case BASEPROPERTY_FILLCOLOR: + if ( bVoid ) + pWindow->SetFillColor(); + else + { + sal_Int32 nColor = 0; + if ( Value >>= nColor ) + { + Color aColor( nColor ); + pWindow->SetFillColor( aColor ); + } + } + break; + case BASEPROPERTY_LINECOLOR: + if ( bVoid ) + pWindow->SetLineColor(); + else + { + sal_Int32 nColor = 0; + if ( Value >>= nColor ) + { + Color aColor( nColor ); + pWindow->SetLineColor( aColor ); + } + } + break; + case BASEPROPERTY_BORDER: + { + WinBits nStyle = pWindow->GetStyle(); + sal_uInt16 nBorder = 0; + Value >>= nBorder; + if ( !nBorder ) + { + pWindow->SetStyle( nStyle & ~WB_BORDER ); + } + else + { + pWindow->SetStyle( nStyle | WB_BORDER ); + pWindow->SetBorderStyle( nBorder ); + } + } + break; + case BASEPROPERTY_TABSTOP: + { + WinBits nStyle = pWindow->GetStyle() & ~WB_TABSTOP; + if ( !bVoid ) + { + sal_Bool bTab = false; + Value >>= bTab; + if ( bTab ) + nStyle |= WB_TABSTOP; + else + nStyle |= WB_NOTABSTOP; + } + pWindow->SetStyle( nStyle ); + } + break; + case BASEPROPERTY_VERTICALALIGN: + { + VerticalAlignment eAlign = VerticalAlignment_MAKE_FIXED_SIZE; + WinBits nStyle = pWindow->GetStyle(); + nStyle &= ~(WB_TOP|WB_VCENTER|WB_BOTTOM); + if ( !bVoid ) + Value >>= eAlign; + switch ( eAlign ) + { + case VerticalAlignment_TOP: + nStyle |= WB_TOP; + break; + case VerticalAlignment_MIDDLE: + nStyle |= WB_VCENTER; + break; + case VerticalAlignment_BOTTOM: + nStyle |= WB_BOTTOM; + break; + default: ; // for warning free code, MAKE_FIXED_SIZE + } + pWindow->SetStyle( nStyle ); + } + break; + case BASEPROPERTY_ALIGN: + { + sal_Int16 nAlign = PROPERTY_ALIGN_LEFT; + switch ( eWinType ) + { + case WINDOW_COMBOBOX: + case WINDOW_BUTTON: + case WINDOW_PUSHBUTTON: + case WINDOW_OKBUTTON: + case WINDOW_CANCELBUTTON: + case WINDOW_HELPBUTTON: + nAlign = PROPERTY_ALIGN_CENTER; + // no break here! + case WINDOW_FIXEDTEXT: + case WINDOW_EDIT: + case WINDOW_MULTILINEEDIT: + case WINDOW_CHECKBOX: + case WINDOW_RADIOBUTTON: + case WINDOW_LISTBOX: + { + WinBits nStyle = pWindow->GetStyle(); + nStyle &= ~(WB_LEFT|WB_CENTER|WB_RIGHT); + if ( !bVoid ) + Value >>= nAlign; + if ( nAlign == PROPERTY_ALIGN_LEFT ) + nStyle |= WB_LEFT; + else if ( nAlign == PROPERTY_ALIGN_CENTER ) + nStyle |= WB_CENTER; + else + nStyle |= WB_RIGHT; + pWindow->SetStyle( nStyle ); + } + break; + } + } + break; + case BASEPROPERTY_MULTILINE: + { + if ( ( eWinType == WINDOW_FIXEDTEXT ) + || ( eWinType == WINDOW_CHECKBOX ) + || ( eWinType == WINDOW_RADIOBUTTON ) + || ( eWinType == WINDOW_BUTTON ) + || ( eWinType == WINDOW_PUSHBUTTON ) + || ( eWinType == WINDOW_OKBUTTON ) + || ( eWinType == WINDOW_CANCELBUTTON ) + || ( eWinType == WINDOW_HELPBUTTON ) + ) + { + WinBits nStyle = pWindow->GetStyle(); + sal_Bool bMulti = false; + Value >>= bMulti; + if ( bMulti ) + nStyle |= WB_WORDBREAK; + else + nStyle &= ~WB_WORDBREAK; + pWindow->SetStyle( nStyle ); + } + } + break; + case BASEPROPERTY_ORIENTATION: + { + switch ( eWinType ) + { + case WINDOW_FIXEDLINE: + { + sal_Int32 nOrientation = 0; + if ( Value >>= nOrientation ) + { + WinBits nStyle = pWindow->GetStyle(); + nStyle &= ~(WB_HORZ|WB_VERT); + if ( nOrientation == 0 ) + nStyle |= WB_HORZ; + else + nStyle |= WB_VERT; + + pWindow->SetStyle( nStyle ); + } + } + break; + } + } + break; + case BASEPROPERTY_AUTOMNEMONICS: + { + sal_Bool bAutoMnemonics = false; + Value >>= bAutoMnemonics; + AllSettings aSettings = pWindow->GetSettings(); + StyleSettings aStyleSettings = aSettings.GetStyleSettings(); + if ( aStyleSettings.GetAutoMnemonic() != bAutoMnemonics ) + { + aStyleSettings.SetAutoMnemonic( bAutoMnemonics ); + aSettings.SetStyleSettings( aStyleSettings ); + pWindow->SetSettings( aSettings ); + } + } + break; + case BASEPROPERTY_MOUSETRANSPARENT: + { + sal_Bool bMouseTransparent = false; + Value >>= bMouseTransparent; + pWindow->SetMouseTransparent( bMouseTransparent ); + } + break; + case BASEPROPERTY_PAINTTRANSPARENT: + { + sal_Bool bPaintTransparent = false; + Value >>= bPaintTransparent; + pWindow->SetPaintTransparent( bPaintTransparent ); +// pWindow->SetBackground(); + } + break; + + case BASEPROPERTY_REPEAT: + { + sal_Bool bRepeat( FALSE ); + Value >>= bRepeat; + + WinBits nStyle = pWindow->GetStyle(); + if ( bRepeat ) + nStyle |= WB_REPEAT; + else + nStyle &= ~WB_REPEAT; + pWindow->SetStyle( nStyle ); + } + break; + + case BASEPROPERTY_REPEAT_DELAY: + { + sal_Int32 nRepeatDelay = 0; + if ( Value >>= nRepeatDelay ) + { + AllSettings aSettings = pWindow->GetSettings(); + MouseSettings aMouseSettings = aSettings.GetMouseSettings(); + + aMouseSettings.SetButtonRepeat( nRepeatDelay ); + aSettings.SetMouseSettings( aMouseSettings ); + + pWindow->SetSettings( aSettings, TRUE ); + } + } + break; + + case BASEPROPERTY_SYMBOL_COLOR: + ::toolkit::setColorSettings( pWindow, Value, &StyleSettings::SetButtonTextColor, &StyleSettings::GetButtonTextColor ); + break; + + case BASEPROPERTY_BORDERCOLOR: + ::toolkit::setColorSettings( pWindow, Value, &StyleSettings::SetMonoColor, &StyleSettings::GetMonoColor); + break; + case BASEPROPERTY_DEFAULTCONTROL: + { + rtl::OUString aName; + Value >>= aName; + break; + } + } +} + +::com::sun::star::uno::Any VCLXWindow::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Any aProp; + if ( GetWindow() ) + { + WindowType eWinType = GetWindow()->GetType(); + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_REFERENCE_DEVICE: + { + Control* pControl = dynamic_cast< Control* >( GetWindow() ); + OSL_ENSURE( pControl, "VCLXWindow::setProperty( RefDevice ): need a Control for this!" ); + if ( !pControl ) + break; + + VCLXDevice* pDevice = new VCLXDevice; + pDevice->SetOutputDevice( pControl->GetReferenceDevice() ); + aProp <<= Reference< XDevice >( pDevice ); + } + break; + + case BASEPROPERTY_CONTEXT_WRITING_MODE: + aProp <<= mpImpl->mnContextWritingMode; + break; + + case BASEPROPERTY_WRITING_MODE: + aProp <<= mpImpl->mnWritingMode; + break; + + case BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR: + { + USHORT nVclBehavior = GetWindow()->GetSettings().GetMouseSettings().GetWheelBehavior(); + sal_Int16 nBehavior = MouseWheelBehavior::SCROLL_FOCUS_ONLY; + switch ( nVclBehavior ) + { + case MOUSE_WHEEL_DISABLE: nBehavior = MouseWheelBehavior::SCROLL_DISABLED; break; + case MOUSE_WHEEL_FOCUS_ONLY: nBehavior = MouseWheelBehavior::SCROLL_FOCUS_ONLY; break; + case MOUSE_WHEEL_ALWAYS: nBehavior = MouseWheelBehavior::SCROLL_ALWAYS; break; + default: + OSL_ENSURE( false, "VCLXWindow::getProperty( 'MouseWheelBehavior' ): illegal VCL value!" ); + } + aProp <<= nBehavior; + } + break; + + case BASEPROPERTY_NATIVE_WIDGET_LOOK: + aProp <<= (sal_Bool) GetWindow()->IsNativeWidgetEnabled(); + break; + + case BASEPROPERTY_ENABLED: + aProp <<= (sal_Bool) GetWindow()->IsEnabled(); + break; + + case BASEPROPERTY_ENABLEVISIBLE: + aProp <<= (sal_Bool) mpImpl->isEnableVisible(); + break; + + case BASEPROPERTY_HIGHCONTRASTMODE: + aProp <<= (sal_Bool) GetWindow()->GetSettings().GetStyleSettings().GetHighContrastMode(); + break; + + case BASEPROPERTY_TEXT: + case BASEPROPERTY_LABEL: + case BASEPROPERTY_TITLE: + { + ::rtl::OUString aText = GetWindow()->GetText(); + aProp <<= aText; + } + break; + case BASEPROPERTY_ACCESSIBLENAME: + { + ::rtl::OUString aText = GetWindow()->GetAccessibleName(); + aProp <<= aText; + } + break; + case BASEPROPERTY_HELPTEXT: + { + ::rtl::OUString aText = GetWindow()->GetQuickHelpText(); + aProp <<= aText; + } + break; + case BASEPROPERTY_HELPURL: + { + SmartId aSmartId = GetWindow()->GetSmartHelpId(); + if( aSmartId.HasString() ) + { + String aStrHelpId = aSmartId.GetStr(); + aProp <<= ::rtl::OUString( aStrHelpId ); + } + else + { + ::rtl::OUStringBuffer aURL; + aURL.appendAscii( "HID:" ); + aURL.append( (sal_Int32) GetWindow()->GetHelpId() ); + aProp <<= aURL.makeStringAndClear(); + } + } + break; + case BASEPROPERTY_FONTDESCRIPTOR: + { + Font aFont = GetWindow()->GetControlFont(); + ::com::sun::star::awt::FontDescriptor aFD = VCLUnoHelper::CreateFontDescriptor( aFont ); + aProp <<= aFD; + } + break; + case BASEPROPERTY_BACKGROUNDCOLOR: + aProp <<= (sal_Int32) GetWindow()->GetControlBackground().GetColor(); + break; + case BASEPROPERTY_DISPLAYBACKGROUNDCOLOR: + aProp <<= (sal_Int32) GetWindow()->GetDisplayBackground().GetColor().GetColor(); + break; + case BASEPROPERTY_FONTRELIEF: + aProp <<= (sal_Int16) GetWindow()->GetControlFont().GetRelief(); + break; + case BASEPROPERTY_FONTEMPHASISMARK: + aProp <<= (sal_Int16) GetWindow()->GetControlFont().GetEmphasisMark(); + break; + case BASEPROPERTY_TEXTCOLOR: + aProp <<= (sal_Int32) GetWindow()->GetControlForeground().GetColor(); + break; + case BASEPROPERTY_TEXTLINECOLOR: + aProp <<= (sal_Int32) GetWindow()->GetTextLineColor().GetColor(); + break; + case BASEPROPERTY_FILLCOLOR: + aProp <<= (sal_Int32) GetWindow()->GetFillColor().GetColor(); + break; + case BASEPROPERTY_LINECOLOR: + aProp <<= (sal_Int32) GetWindow()->GetLineColor().GetColor(); + break; + case BASEPROPERTY_BORDER: + { + sal_Int16 nBorder = 0; + if ( GetWindow()->GetStyle() & WB_BORDER ) + nBorder = GetWindow()->GetBorderStyle(); + aProp <<= nBorder; + } + break; + case BASEPROPERTY_TABSTOP: + aProp <<= (sal_Bool) ( GetWindow()->GetStyle() & WB_TABSTOP ) ? sal_True : sal_False; + break; + case BASEPROPERTY_VERTICALALIGN: + { + WinBits nStyle = GetWindow()->GetStyle(); + if ( nStyle & WB_TOP ) + aProp <<= VerticalAlignment_TOP; + else if ( nStyle & WB_VCENTER ) + aProp <<= VerticalAlignment_MIDDLE; + else if ( nStyle & WB_BOTTOM ) + aProp <<= VerticalAlignment_BOTTOM; + } + break; + case BASEPROPERTY_ALIGN: + { + switch ( eWinType ) + { + case WINDOW_FIXEDTEXT: + case WINDOW_EDIT: + case WINDOW_MULTILINEEDIT: + case WINDOW_CHECKBOX: + case WINDOW_RADIOBUTTON: + case WINDOW_LISTBOX: + case WINDOW_COMBOBOX: + case WINDOW_BUTTON: + case WINDOW_PUSHBUTTON: + case WINDOW_OKBUTTON: + case WINDOW_CANCELBUTTON: + case WINDOW_HELPBUTTON: + { + WinBits nStyle = GetWindow()->GetStyle(); + if ( nStyle & WB_LEFT ) + aProp <<= (sal_Int16) PROPERTY_ALIGN_LEFT; + else if ( nStyle & WB_CENTER ) + aProp <<= (sal_Int16) PROPERTY_ALIGN_CENTER; + else if ( nStyle & WB_RIGHT ) + aProp <<= (sal_Int16) PROPERTY_ALIGN_RIGHT; + } + break; + } + } + case BASEPROPERTY_MULTILINE: + { + if ( ( eWinType == WINDOW_FIXEDTEXT ) + || ( eWinType == WINDOW_CHECKBOX ) + || ( eWinType == WINDOW_RADIOBUTTON ) + || ( eWinType == WINDOW_BUTTON ) + || ( eWinType == WINDOW_PUSHBUTTON ) + || ( eWinType == WINDOW_OKBUTTON ) + || ( eWinType == WINDOW_CANCELBUTTON ) + || ( eWinType == WINDOW_HELPBUTTON ) + ) + aProp <<= (sal_Bool) ( GetWindow()->GetStyle() & WB_WORDBREAK ) ? sal_True : sal_False; + } + break; + case BASEPROPERTY_AUTOMNEMONICS: + { + sal_Bool bAutoMnemonics = GetWindow()->GetSettings().GetStyleSettings().GetAutoMnemonic(); + aProp <<= bAutoMnemonics; + } + break; + case BASEPROPERTY_MOUSETRANSPARENT: + { + sal_Bool bMouseTransparent = GetWindow()->IsMouseTransparent(); + aProp <<= bMouseTransparent; + } + break; + case BASEPROPERTY_PAINTTRANSPARENT: + { + sal_Bool bPaintTransparent = GetWindow()->IsPaintTransparent(); + aProp <<= bPaintTransparent; + } + break; + + case BASEPROPERTY_REPEAT: + aProp <<= (sal_Bool)( 0 != ( GetWindow()->GetStyle() & WB_REPEAT ) ); + break; + + case BASEPROPERTY_REPEAT_DELAY: + { + sal_Int32 nButtonRepeat = GetWindow()->GetSettings().GetMouseSettings().GetButtonRepeat(); + aProp <<= (sal_Int32)nButtonRepeat; + } + break; + + case BASEPROPERTY_SYMBOL_COLOR: + aProp <<= (sal_Int32)GetWindow()->GetSettings().GetStyleSettings().GetButtonTextColor().GetColor(); + break; + + case BASEPROPERTY_BORDERCOLOR: + aProp <<= (sal_Int32)GetWindow()->GetSettings().GetStyleSettings().GetMonoColor().GetColor(); + break; + } + } + return aProp; +} + + +// ::com::sun::star::awt::XLayoutConstrains +::com::sun::star::awt::Size VCLXWindow::getMinimumSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + // Diese Methode sollte nur fuer Componenten gerufen werden, die zwar + // ueber das ::com::sun::star::awt::Toolkit erzeugt werden koennen, aber fuer die es + // kein Interface gibt. + + Size aSz; + if ( GetWindow() ) + { + WindowType nWinType = GetWindow()->GetType(); + switch ( nWinType ) + { + case WINDOW_CONTROL: + aSz.Width() = GetWindow()->GetTextWidth( GetWindow()->GetText() )+2*12; + aSz.Height() = GetWindow()->GetTextHeight()+2*6; + break; + + case WINDOW_PATTERNBOX: + case WINDOW_NUMERICBOX: + case WINDOW_METRICBOX: + case WINDOW_CURRENCYBOX: + case WINDOW_DATEBOX: + case WINDOW_TIMEBOX: + case WINDOW_LONGCURRENCYBOX: + aSz.Width() = GetWindow()->GetTextWidth( GetWindow()->GetText() )+2*2; + aSz.Height() = GetWindow()->GetTextHeight()+2*2; + break; + case WINDOW_SCROLLBARBOX: + return VCLXScrollBar::implGetMinimumSize( GetWindow() ); + default: + aSz = GetWindow()->GetOptimalSize( WINDOWSIZE_MINIMUM ); + } + } + + return ::com::sun::star::awt::Size( aSz.Width(), aSz.Height() ); +} + +::com::sun::star::awt::Size VCLXWindow::getPreferredSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + return getMinimumSize(); +} + +::com::sun::star::awt::Size VCLXWindow::calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::awt::Size aNewSize( rNewSize ); + ::com::sun::star::awt::Size aMinSize = getMinimumSize(); + + if ( aNewSize.Width < aMinSize.Width ) + aNewSize.Width = aMinSize.Width; + if ( aNewSize.Height < aMinSize.Height ) + aNewSize.Height = aMinSize.Height; + + return aNewSize; +} + + +// ::com::sun::star::awt::XView +sal_Bool VCLXWindow::setGraphics( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics >& rxDevice ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( VCLUnoHelper::GetOutputDevice( rxDevice ) ) + mpImpl->mxViewGraphics = rxDevice; + else + mpImpl->mxViewGraphics = NULL; + + return mpImpl->mxViewGraphics.is(); +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics > VCLXWindow::getGraphics( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + return mpImpl->mxViewGraphics; +} + +::com::sun::star::awt::Size VCLXWindow::getSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Size aSz; + if ( GetWindow() ) + aSz = GetWindow()->GetSizePixel(); + return ::com::sun::star::awt::Size( aSz.Width(), aSz.Height() ); +} + +void VCLXWindow::draw( sal_Int32 nX, sal_Int32 nY ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if ( !pWindow ) + return; + + if ( isDesignMode() || mpImpl->isEnableVisible() ) + { + TabPage* pTabPage = dynamic_cast< TabPage* >( pWindow ); + if ( pTabPage ) + { + Point aPos( nX, nY ); + Size aSize = pWindow->GetSizePixel(); + + OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( mpImpl->mxViewGraphics ); + aPos = pDev->PixelToLogic( aPos ); + aSize = pDev->PixelToLogic( aSize ); + + pTabPage->Draw( pDev, aPos, aSize, 0 ); + return; + } + + OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( mpImpl->mxViewGraphics ); + Point aPos( nX, nY ); + + if ( !pDev ) + pDev = pWindow->GetParent(); + + if ( pWindow->GetParent() && !pWindow->IsSystemWindow() && ( pWindow->GetParent() == pDev ) ) + { + // #i40647# don't draw here if this is a recursive call + // sometimes this is called recursively, because the Update call on the parent + // (strangely) triggers another paint. Prevent a stack overflow here + // Yes, this is only fixing symptoms for the moment .... + // #i40647# / 2005-01-18 / frank.schoenheit@sun.com + if ( !mpImpl->getDrawingOntoParent_ref() ) + { + FlagGuard aDrawingflagGuard( mpImpl->getDrawingOntoParent_ref() ); + + BOOL bWasVisible = pWindow->IsVisible(); + Point aOldPos( pWindow->GetPosPixel() ); + + if ( bWasVisible && aOldPos == aPos ) + { + pWindow->Update(); + return; + } + + pWindow->SetPosPixel( aPos ); + + // Erstmal ein Update auf den Parent, damit nicht beim Update + // auf dieses Fenster noch ein Paint vom Parent abgearbeitet wird, + // wo dann ggf. dieses Fenster sofort wieder gehidet wird. + if( pWindow->GetParent() ) + pWindow->GetParent()->Update(); + + pWindow->Show(); + pWindow->Update(); + pWindow->SetParentUpdateMode( sal_False ); + pWindow->Hide(); + pWindow->SetParentUpdateMode( sal_True ); + + pWindow->SetPosPixel( aOldPos ); + if ( bWasVisible ) + pWindow->Show( TRUE ); + } + } + else if ( pDev ) + { + Size aSz = pWindow->GetSizePixel(); + aSz = pDev->PixelToLogic( aSz ); + Point aP = pDev->PixelToLogic( aPos ); + + vcl::PDFExtOutDevData* pPDFExport = dynamic_cast<vcl::PDFExtOutDevData*>(pDev->GetExtOutDevData()); + bool bDrawSimple = ( pDev->GetOutDevType() == OUTDEV_PRINTER ) + || ( pDev->GetOutDevViewType() == OUTDEV_VIEWTYPE_PRINTPREVIEW ) + || ( pPDFExport != NULL ); + if ( bDrawSimple ) + { + pWindow->Draw( pDev, aP, aSz, WINDOW_DRAW_NOCONTROLS ); + } + else + { + BOOL bOldNW =pWindow->IsNativeWidgetEnabled(); + if( bOldNW ) + pWindow->EnableNativeWidget(FALSE); + pWindow->PaintToDevice( pDev, aP, aSz ); + if( bOldNW ) + pWindow->EnableNativeWidget(TRUE); + } + } + } +} + +void VCLXWindow::setZoom( float fZoomX, float /*fZoomY*/ ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + { + // Fraction::Fraction takes a double, but we have a float only. + // The implicit conversion from float to double can result in a precision loss, i.e. 1.2 is converted to + // 1.200000000047something. To prevent this, we convert explicitly to double, and round it. + double nZoom( fZoomX ); + nZoom = ::rtl::math::round( nZoom, 4 ); + GetWindow()->SetZoom( Fraction( nZoom ) ); + } +} + +// ::com::sun::star::lang::XEventListener +void SAL_CALL VCLXWindow::disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw (::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + // check if it comes from our AccessibleContext + uno::Reference< uno::XInterface > aAC( mpImpl->mxAccessibleContext, uno::UNO_QUERY ); + uno::Reference< uno::XInterface > xSource( _rSource.Source, uno::UNO_QUERY ); + + if ( aAC.get() == xSource.get() ) + { // yep, it does + mpImpl->mxAccessibleContext = uno::Reference< accessibility::XAccessibleContext >(); + } +} + +// ::com::sun::star::accessibility::XAccessible +::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > VCLXWindow::getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException) +{ + using namespace ::com::sun::star; + + ::vos::OGuard aGuard( GetMutex() ); + + // already disposed + if( ! mpImpl ) + return uno::Reference< accessibility::XAccessibleContext >(); + + if ( !mpImpl->mxAccessibleContext.is() && GetWindow() ) + { + mpImpl->mxAccessibleContext = CreateAccessibleContext(); + + // add as event listener to this component + // in case somebody disposes it, we do not want to have a (though weak) reference to a dead + // object + uno::Reference< lang::XComponent > xComp( mpImpl->mxAccessibleContext, uno::UNO_QUERY ); + if ( xComp.is() ) + xComp->addEventListener( this ); + } + + return mpImpl->mxAccessibleContext; +} + +// ::com::sun::star::awt::XDockable +void SAL_CALL VCLXWindow::addDockableWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDockableWindowListener >& xListener ) throw (::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( xListener.is() ) + mpImpl->getDockableWindowListeners().addInterface( xListener ); + +} + +void SAL_CALL VCLXWindow::removeDockableWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDockableWindowListener >& xListener ) throw (::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + mpImpl->getDockableWindowListeners().removeInterface( xListener ); +} + +void SAL_CALL VCLXWindow::enableDocking( sal_Bool bEnable ) throw (::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if ( pWindow ) + pWindow->EnableDocking( bEnable ); +} + +sal_Bool SAL_CALL VCLXWindow::isFloating( ) throw (::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if( pWindow ) + return Window::GetDockingManager()->IsFloating( pWindow ); + else + return FALSE; +} + +void SAL_CALL VCLXWindow::setFloatingMode( sal_Bool bFloating ) throw (::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if( pWindow ) + Window::GetDockingManager()->SetFloatingMode( pWindow, bFloating ); +} + +sal_Bool SAL_CALL VCLXWindow::isLocked( ) throw (::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if( pWindow ) + return Window::GetDockingManager()->IsLocked( pWindow ); + else + return FALSE; +} + +void SAL_CALL VCLXWindow::lock( ) throw (::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if( pWindow && !Window::GetDockingManager()->IsFloating( pWindow ) ) + Window::GetDockingManager()->Lock( pWindow ); +} + +void SAL_CALL VCLXWindow::unlock( ) throw (::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if( pWindow && !Window::GetDockingManager()->IsFloating( pWindow ) ) + Window::GetDockingManager()->Unlock( pWindow ); +} +void SAL_CALL VCLXWindow::startPopupMode( const ::com::sun::star::awt::Rectangle& ) throw (::com::sun::star::uno::RuntimeException) +{ + // TODO: remove interface in the next incompatible build + ::vos::OGuard aGuard( GetMutex() ); + +} + +sal_Bool SAL_CALL VCLXWindow::isInPopupMode( ) throw (::com::sun::star::uno::RuntimeException) +{ + // TODO: remove interface in the next incompatible build + ::vos::OGuard aGuard( GetMutex() ); + return FALSE; +} + + +// ::com::sun::star::awt::XWindow2 + +void SAL_CALL VCLXWindow::setOutputSize( const ::com::sun::star::awt::Size& aSize ) throw (::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + Window *pWindow; + if( (pWindow = GetWindow()) != NULL ) + { + DockingWindow *pDockingWindow = dynamic_cast< DockingWindow* >(pWindow); + if( pDockingWindow ) + pDockingWindow->SetOutputSizePixel( VCLSize( aSize ) ); + else + pWindow->SetOutputSizePixel( VCLSize( aSize ) ); + } +} + +::com::sun::star::awt::Size SAL_CALL VCLXWindow::getOutputSize( ) throw (::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + Window *pWindow; + if( (pWindow = GetWindow()) != NULL ) + { + DockingWindow *pDockingWindow = dynamic_cast< DockingWindow* >(pWindow); + if( pDockingWindow ) + return AWTSize( pDockingWindow->GetOutputSizePixel() ); + else + return AWTSize( pWindow->GetOutputSizePixel() ); + } + else + return ::com::sun::star::awt::Size(); +} + +sal_Bool SAL_CALL VCLXWindow::isVisible( ) throw (::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + if( GetWindow() ) + return GetWindow()->IsVisible(); + else + return FALSE; +} + +sal_Bool SAL_CALL VCLXWindow::isActive( ) throw (::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + if( GetWindow() ) + return GetWindow()->IsActive(); + else + return FALSE; + +} + +sal_Bool SAL_CALL VCLXWindow::isEnabled( ) throw (::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + if( GetWindow() ) + return GetWindow()->IsEnabled(); + else + return FALSE; +} + +sal_Bool SAL_CALL VCLXWindow::hasFocus( ) throw (::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + if( GetWindow() ) + return GetWindow()->HasFocus(); + else + return FALSE; +} + +// ::com::sun::star::beans::XPropertySetInfo + +UnoPropertyArrayHelper * +VCLXWindow::GetPropHelper() +{ + ::vos::OGuard aGuard( GetMutex() ); + if ( mpImpl->mpPropHelper == NULL ) + { + std::list< sal_uInt16 > aIDs; + GetPropertyIds( aIDs ); + mpImpl->mpPropHelper = new UnoPropertyArrayHelper( aIDs ); + } + return mpImpl->mpPropHelper; +} + +::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > SAL_CALL +VCLXWindow::getProperties() throw (::com::sun::star::uno::RuntimeException) +{ + return GetPropHelper()->getProperties(); +} +::com::sun::star::beans::Property SAL_CALL +VCLXWindow::getPropertyByName( const ::rtl::OUString& rName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException) +{ + return GetPropHelper()->getPropertyByName( rName ); +} + +::sal_Bool SAL_CALL +VCLXWindow::hasPropertyByName( const ::rtl::OUString& rName ) throw (::com::sun::star::uno::RuntimeException) +{ + return GetPropHelper()->hasPropertyByName( rName ); +} diff --git a/toolkit/source/awt/vclxwindow1.cxx b/toolkit/source/awt/vclxwindow1.cxx new file mode 100644 index 000000000000..daea557d241a --- /dev/null +++ b/toolkit/source/awt/vclxwindow1.cxx @@ -0,0 +1,108 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + +#include <tools/svwin.h> +#include <toolkit/awt/vclxwindow.hxx> +#include <com/sun/star/beans/NamedValue.hpp> +#ifndef _SV_WORKWIN +#include <vcl/wrkwin.hxx> +#endif +#include <vcl/window.hxx> + +#ifdef WNT +#include <tools/prewin.h> +#include <windows.h> +#include <tools/postwin.h> +#elif defined ( QUARTZ ) +#include "premac.h" +#include <Cocoa/Cocoa.h> +#include "postmac.h" +#endif +#include <vcl/sysdata.hxx> + +/// helper method to set a window handle into a SystemParentData struct +void VCLXWindow::SetSystemParent_Impl( const com::sun::star::uno::Any& rHandle ) +{ + // does only work for WorkWindows + Window *pWindow = GetWindow(); + if ( pWindow->GetType() != WINDOW_WORKWINDOW ) + { + ::com::sun::star::uno::Exception *pException = + new ::com::sun::star::uno::RuntimeException; + pException->Message = ::rtl::OUString::createFromAscii( "not a work window" ); + throw pException; + } + + // use sal_Int64 here to accomodate all int types + // uno::Any shift operator whill upcast if necessary + sal_Int64 nHandle = 0; + sal_Bool bXEmbed = sal_False; + bool bThrow = false; + if( ! (rHandle >>= nHandle) ) + { + com::sun::star::uno::Sequence< com::sun::star::beans::NamedValue > aProps; + if( rHandle >>= aProps ) + { + const int nProps = aProps.getLength(); + const com::sun::star::beans::NamedValue* pProps = aProps.getConstArray(); + for( int i = 0; i < nProps; i++ ) + { + if( pProps[i].Name.equalsAscii( "WINDOW" ) ) + pProps[i].Value >>= nHandle; + else if( pProps[i].Name.equalsAscii( "XEMBED" ) ) + pProps[i].Value >>= bXEmbed; + } + } + else + bThrow = true; + } + if( bThrow ) + { + ::com::sun::star::uno::Exception *pException = + new ::com::sun::star::uno::RuntimeException; + pException->Message = ::rtl::OUString::createFromAscii( "incorrect window handle type" ); + throw pException; + } + // create system parent data + SystemParentData aSysParentData; + aSysParentData.nSize = sizeof ( SystemParentData ); +#if defined( WIN ) || defined( WNT ) || defined ( OS2 ) + aSysParentData.hWnd = (HWND) nHandle; +#elif defined( QUARTZ ) + aSysParentData.pView = reinterpret_cast<NSView*>(nHandle); +#elif defined( UNX ) + aSysParentData.aWindow = (long)nHandle; + aSysParentData.bXEmbedSupport = bXEmbed; +#endif + + // set system parent + ((WorkWindow*)pWindow)->SetPluginParent( &aSysParentData ); +} + diff --git a/toolkit/source/awt/vclxwindows.cxx b/toolkit/source/awt/vclxwindows.cxx new file mode 100644 index 000000000000..e2fc78421d5e --- /dev/null +++ b/toolkit/source/awt/vclxwindows.cxx @@ -0,0 +1,6036 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <toolkit/awt/vclxwindows.hxx> +#include <com/sun/star/awt/ScrollBarOrientation.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> +#include <toolkit/helper/vclunohelper.hxx> +#include <toolkit/helper/macros.hxx> +#include <toolkit/helper/property.hxx> +#include <toolkit/helper/convert.hxx> +#include <toolkit/helper/imagealign.hxx> +#include <toolkit/helper/accessibilityclient.hxx> +#include <toolkit/helper/fixedhyperbase.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <com/sun/star/awt/VisualEffect.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/system/XSystemShellExecute.hpp> +#include <com/sun/star/system/SystemShellExecuteFlags.hpp> +#include <com/sun/star/awt/ImageScaleMode.hpp> +#include <comphelper/processfactory.hxx> + +#ifndef _SV_BUTTON_HXX +#include <vcl/button.hxx> +#endif +#include <vcl/lstbox.hxx> +#include <vcl/combobox.hxx> +#include <vcl/field.hxx> +#include <vcl/longcurr.hxx> +#include <vcl/imgctrl.hxx> +#include <vcl/dialog.hxx> +#include <vcl/msgbox.hxx> +#include <vcl/scrbar.hxx> +#include <vcl/svapp.hxx> +#include <vcl/tabpage.hxx> +#include <tools/debug.hxx> + +using ::com::sun::star::uno::Any; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::makeAny; +using ::com::sun::star::graphic::XGraphic; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::awt::VisualEffect; +namespace ImageScaleMode = ::com::sun::star::awt::ImageScaleMode; + +static double ImplCalcLongValue( double nValue, sal_uInt16 nDigits ) +{ + double n = nValue; + for ( sal_uInt16 d = 0; d < nDigits; d++ ) + n *= 10; + return n; +} + +static double ImplCalcDoubleValue( double nValue, sal_uInt16 nDigits ) +{ + double n = nValue; + for ( sal_uInt16 d = 0; d < nDigits; d++ ) + n /= 10; + return n; +} + +namespace toolkit +{ + /** sets the "face color" for button like controls (scroll bar, spin button) + */ + void setButtonLikeFaceColor( Window* _pWindow, const ::com::sun::star::uno::Any& _rColorValue ) + { + AllSettings aSettings = _pWindow->GetSettings(); + StyleSettings aStyleSettings = aSettings.GetStyleSettings(); + + if ( !_rColorValue.hasValue() ) + { + const StyleSettings& aAppStyle = Application::GetSettings().GetStyleSettings(); + aStyleSettings.SetFaceColor( aAppStyle.GetFaceColor( ) ); + aStyleSettings.SetCheckedColor( aAppStyle.GetCheckedColor( ) ); + aStyleSettings.SetLightBorderColor( aAppStyle.GetLightBorderColor() ); + aStyleSettings.SetLightColor( aAppStyle.GetLightColor() ); + aStyleSettings.SetShadowColor( aAppStyle.GetShadowColor() ); + aStyleSettings.SetDarkShadowColor( aAppStyle.GetDarkShadowColor() ); + } + else + { + sal_Int32 nBackgroundColor = 0; + _rColorValue >>= nBackgroundColor; + aStyleSettings.SetFaceColor( nBackgroundColor ); + + // for the real background (everything except the buttons and the thumb), + // use an average between the desired color and "white" + Color aWhite( COL_WHITE ); + Color aBackground( nBackgroundColor ); + aBackground.SetRed( ( aBackground.GetRed() + aWhite.GetRed() ) / 2 ); + aBackground.SetGreen( ( aBackground.GetGreen() + aWhite.GetGreen() ) / 2 ); + aBackground.SetBlue( ( aBackground.GetBlue() + aWhite.GetBlue() ) / 2 ); + aStyleSettings.SetCheckedColor( aBackground ); + + sal_Int32 nBackgroundLuminance = Color( nBackgroundColor ).GetLuminance(); + sal_Int32 nWhiteLuminance = Color( COL_WHITE ).GetLuminance(); + + Color aLightShadow( nBackgroundColor ); + aLightShadow.IncreaseLuminance( (UINT8)( ( nWhiteLuminance - nBackgroundLuminance ) * 2 / 3 ) ); + aStyleSettings.SetLightBorderColor( aLightShadow ); + + Color aLight( nBackgroundColor ); + aLight.IncreaseLuminance( (UINT8)( ( nWhiteLuminance - nBackgroundLuminance ) * 1 / 3 ) ); + aStyleSettings.SetLightColor( aLight ); + + Color aShadow( nBackgroundColor ); + aShadow.DecreaseLuminance( (UINT8)( nBackgroundLuminance * 1 / 3 ) ); + aStyleSettings.SetShadowColor( aShadow ); + + Color aDarkShadow( nBackgroundColor ); + aDarkShadow.DecreaseLuminance( (UINT8)( nBackgroundLuminance * 2 / 3 ) ); + aStyleSettings.SetDarkShadowColor( aDarkShadow ); + } + + aSettings.SetStyleSettings( aStyleSettings ); + _pWindow->SetSettings( aSettings, TRUE ); + } + + Any getButtonLikeFaceColor( const Window* _pWindow ) + { + sal_Int32 nBackgroundColor = _pWindow->GetSettings().GetStyleSettings().GetFaceColor().GetColor(); + return makeAny( nBackgroundColor ); + } + + static void adjustBooleanWindowStyle( const Any& _rValue, Window* _pWindow, WinBits _nBits, sal_Bool _bInverseSemantics ) + { + WinBits nStyle = _pWindow->GetStyle(); + sal_Bool bValue( sal_False ); + OSL_VERIFY( _rValue >>= bValue ); + if ( bValue != _bInverseSemantics ) + nStyle |= _nBits; + else + nStyle &= ~_nBits; + _pWindow->SetStyle( nStyle ); + } + + static void setVisualEffect( const Any& _rValue, Window* _pWindow, void (StyleSettings::*pSetter)( USHORT ), sal_Int16 _nFlatBits, sal_Int16 _n3DBits ) + { + AllSettings aSettings = _pWindow->GetSettings(); + StyleSettings aStyleSettings = aSettings.GetStyleSettings(); + + sal_Int16 nStyle = LOOK3D; + OSL_VERIFY( _rValue >>= nStyle ); + switch ( nStyle ) + { + case FLAT: + (aStyleSettings.*pSetter)( _nFlatBits ); + break; + case LOOK3D: + default: + (aStyleSettings.*pSetter)( _n3DBits ); + } + aSettings.SetStyleSettings( aStyleSettings ); + _pWindow->SetSettings( aSettings ); + } + + static Any getVisualEffect( Window* _pWindow, USHORT (StyleSettings::*pGetter)( ) const, sal_Int16 _nFlatBits ) + { + Any aEffect; + + StyleSettings aStyleSettings = _pWindow->GetSettings().GetStyleSettings(); + if ( (aStyleSettings.*pGetter)() == _nFlatBits ) + aEffect <<= (sal_Int16)FLAT; + else + aEffect <<= (sal_Int16)LOOK3D; + return aEffect; + } +} + +// ---------------------------------------------------- +// class VCLXImageConsumer +// ---------------------------------------------------- + +void VCLXImageConsumer::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + VCLXWindow::ImplGetPropertyIds( rIds ); +} + +void VCLXImageConsumer::ImplSetNewImage() +{ + OSL_PRECOND( GetWindow(), "VCLXImageConsumer::ImplSetNewImage: window is required to be not-NULL!" ); + Button* pButton = static_cast< Button* >( GetWindow() ); + pButton->SetModeBitmap( GetBitmap() ); +} + +void VCLXImageConsumer::ImplUpdateImage( sal_Bool bGetNewImage ) +{ + if ( !GetWindow() ) + return; + + if ( bGetNewImage && !maImageConsumer.GetData( maImage ) ) + return; + + ImplSetNewImage(); +} + +void VCLXImageConsumer::setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, short Flags ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + { + Size aOldSize = GetWindow()->GetSizePixel(); + VCLXWindow::setPosSize( X, Y, Width, Height, Flags ); + if ( ( aOldSize.Width() != Width ) || ( aOldSize.Height() != Height ) ) + ImplUpdateImage( sal_False ); + } +} + +void VCLXImageConsumer::init( sal_Int32 Width, sal_Int32 Height ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + maImageConsumer.Init( Width, Height ); +} + +void VCLXImageConsumer::setColorModel( sal_Int16 BitCount, const ::com::sun::star::uno::Sequence< sal_Int32 >& RGBAPal, sal_Int32 RedMask, sal_Int32 GreenMask, sal_Int32 BlueMask, sal_Int32 AlphaMask ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + maImageConsumer.SetColorModel( BitCount, RGBAPal.getLength(), (const sal_uInt32*) RGBAPal.getConstArray(), RedMask, GreenMask, BlueMask, AlphaMask ); +} + +void VCLXImageConsumer::setPixelsByBytes( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, const ::com::sun::star::uno::Sequence< sal_Int8 >& ProducerData, sal_Int32 Offset, sal_Int32 Scansize ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + maImageConsumer.SetPixelsByBytes( X, Y, Width, Height, (sal_uInt8*)ProducerData.getConstArray(), Offset, Scansize ); + ImplUpdateImage( sal_True ); +} + +void VCLXImageConsumer::setPixelsByLongs( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, const ::com::sun::star::uno::Sequence< sal_Int32 >& ProducerData, sal_Int32 Offset, sal_Int32 Scansize ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + maImageConsumer.SetPixelsByLongs( X, Y, Width, Height, (const sal_uInt32*) ProducerData.getConstArray(), Offset, Scansize ); + ImplUpdateImage( sal_True ); +} + +void VCLXImageConsumer::complete( sal_Int32 Status, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageProducer > & ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + maImageConsumer.Completed( Status ); + ImplUpdateImage( sal_True ); +} + +void VCLXImageConsumer::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Button* pButton = static_cast< Button* >( GetWindow() ); + if ( !pButton ) + return; + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_GRAPHIC: + { + Reference< XGraphic > xGraphic; + OSL_VERIFY( Value >>= xGraphic ); + maImage = Image( xGraphic ); + ImplSetNewImage(); + } + break; + + case BASEPROPERTY_IMAGEALIGN: + { + WindowType eType = GetWindow()->GetType(); + if ( ( eType == WINDOW_PUSHBUTTON ) + || ( eType == WINDOW_RADIOBUTTON ) + || ( eType == WINDOW_CHECKBOX ) + ) + { + sal_Int16 nAlignment = sal_Int16(); + if ( Value >>= nAlignment ) + pButton->SetImageAlign( static_cast< ImageAlign >( nAlignment ) ); + } + } + break; + case BASEPROPERTY_IMAGEPOSITION: + { + WindowType eType = GetWindow()->GetType(); + if ( ( eType == WINDOW_PUSHBUTTON ) + || ( eType == WINDOW_RADIOBUTTON ) + || ( eType == WINDOW_CHECKBOX ) + ) + { + sal_Int16 nImagePosition = 2; + OSL_VERIFY( Value >>= nImagePosition ); + pButton->SetImageAlign( ::toolkit::translateImagePosition( nImagePosition ) ); + } + } + break; + default: + VCLXWindow::setProperty( PropertyName, Value ); + break; + } +} + +::com::sun::star::uno::Any VCLXImageConsumer::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Any aProp; + if ( !GetWindow() ) + return aProp; + + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_GRAPHIC: + aProp <<= maImage.GetXGraphic(); + break; + case BASEPROPERTY_IMAGEALIGN: + { + WindowType eType = GetWindow()->GetType(); + if ( ( eType == WINDOW_PUSHBUTTON ) + || ( eType == WINDOW_RADIOBUTTON ) + || ( eType == WINDOW_CHECKBOX ) + ) + { + aProp <<= ::toolkit::getCompatibleImageAlign( static_cast< Button* >( GetWindow() )->GetImageAlign() ); + } + } + break; + case BASEPROPERTY_IMAGEPOSITION: + { + WindowType eType = GetWindow()->GetType(); + if ( ( eType == WINDOW_PUSHBUTTON ) + || ( eType == WINDOW_RADIOBUTTON ) + || ( eType == WINDOW_CHECKBOX ) + ) + { + aProp <<= ::toolkit::translateImagePosition( static_cast< Button* >( GetWindow() )->GetImageAlign() ); + } + } + break; + default: + { + aProp <<= VCLXWindow::getProperty( PropertyName ); + } + break; + } + return aProp; +} + +//-------------------------------------------------------------------- +// class VCLXButton +// ---------------------------------------------------- + +void VCLXButton::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + PushPropertyIds( rIds, + BASEPROPERTY_BACKGROUNDCOLOR, + BASEPROPERTY_DEFAULTBUTTON, + BASEPROPERTY_DEFAULTCONTROL, + BASEPROPERTY_ENABLED, + BASEPROPERTY_ENABLEVISIBLE, + BASEPROPERTY_FONTDESCRIPTOR, + BASEPROPERTY_GRAPHIC, + BASEPROPERTY_HELPTEXT, + BASEPROPERTY_HELPURL, + BASEPROPERTY_IMAGEALIGN, + BASEPROPERTY_IMAGEPOSITION, + BASEPROPERTY_IMAGEURL, + BASEPROPERTY_LABEL, + BASEPROPERTY_PRINTABLE, + BASEPROPERTY_PUSHBUTTONTYPE, + BASEPROPERTY_REPEAT, + BASEPROPERTY_REPEAT_DELAY, + BASEPROPERTY_STATE, + BASEPROPERTY_TABSTOP, + BASEPROPERTY_TOGGLE, + BASEPROPERTY_FOCUSONCLICK, + BASEPROPERTY_MULTILINE, + BASEPROPERTY_ALIGN, + BASEPROPERTY_VERTICALALIGN, + BASEPROPERTY_WRITING_MODE, + BASEPROPERTY_CONTEXT_WRITING_MODE, + BASEPROPERTY_REFERENCE_DEVICE, + 0); + VCLXImageConsumer::ImplGetPropertyIds( rIds ); +} + +VCLXButton::VCLXButton() + :maActionListeners( *this ) + ,maItemListeners( *this ) +{ +} + +VCLXButton::~VCLXButton() +{ +} + +::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > VCLXButton::CreateAccessibleContext() +{ + return getAccessibleFactory().createAccessibleContext( this ); +} + +void VCLXButton::dispose() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::lang::EventObject aObj; + aObj.Source = (::cppu::OWeakObject*)this; + maActionListeners.disposeAndClear( aObj ); + maItemListeners.disposeAndClear( aObj ); + VCLXImageConsumer::dispose(); +} + +void VCLXButton::addActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener > & l )throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maActionListeners.addInterface( l ); +} + +void VCLXButton::removeActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maActionListeners.removeInterface( l ); +} + +void VCLXButton::addItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener > & l )throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maItemListeners.addInterface( l ); +} + +void VCLXButton::removeItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maItemListeners.removeInterface( l ); +} + +void VCLXButton::setLabel( const ::rtl::OUString& rLabel ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if ( pWindow ) + pWindow->SetText( rLabel ); +} + +void VCLXButton::setActionCommand( const ::rtl::OUString& rCommand ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + maActionCommand = rCommand; +} + +::com::sun::star::awt::Size VCLXButton::getMinimumSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Size aSz; + PushButton* pButton = (PushButton*) GetWindow(); + if ( pButton ) + aSz = pButton->CalcMinimumSize(); + return AWTSize(aSz); +} + +::com::sun::star::awt::Size VCLXButton::getPreferredSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::awt::Size aSz = getMinimumSize(); + aSz.Width += 16; + aSz.Height += 10; + return aSz; +} + +::com::sun::star::awt::Size VCLXButton::calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Size aSz = VCLSize(rNewSize); + PushButton* pButton = (PushButton*) GetWindow(); + if ( pButton ) + { + Size aMinSz = pButton->CalcMinimumSize(); + // Kein Text, also Image + if ( !pButton->GetText().Len() ) + { + if ( aSz.Width() < aMinSz.Width() ) + aSz.Width() = aMinSz.Width(); + if ( aSz.Height() < aMinSz.Height() ) + aSz.Height() = aMinSz.Height(); + } + else + { + if ( ( aSz.Width() > aMinSz.Width() ) && ( aSz.Height() < aMinSz.Height() ) ) + aSz.Height() = aMinSz.Height(); + else + aSz = aMinSz; + } + } + return AWTSize(aSz); +} + +void VCLXButton::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Button* pButton = (Button*)GetWindow(); + if ( pButton ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_FOCUSONCLICK: + ::toolkit::adjustBooleanWindowStyle( Value, pButton, WB_NOPOINTERFOCUS, sal_True ); + break; + + case BASEPROPERTY_TOGGLE: + ::toolkit::adjustBooleanWindowStyle( Value, pButton, WB_TOGGLE, sal_False ); + break; + + case BASEPROPERTY_DEFAULTBUTTON: + { + WinBits nStyle = pButton->GetStyle() | WB_DEFBUTTON; + sal_Bool b = sal_Bool(); + if ( ( Value >>= b ) && !b ) + nStyle &= ~WB_DEFBUTTON; + pButton->SetStyle( nStyle ); + } + break; + case BASEPROPERTY_STATE: + { + if ( GetWindow()->GetType() == WINDOW_PUSHBUTTON ) + { + sal_Int16 n = sal_Int16(); + if ( Value >>= n ) + ((PushButton*)pButton)->SetState( (TriState)n ); + } + } + break; + default: + { + VCLXImageConsumer::setProperty( PropertyName, Value ); + } + } + } +} + +::com::sun::star::uno::Any VCLXButton::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Any aProp; + Button* pButton = (Button*)GetWindow(); + if ( pButton ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_FOCUSONCLICK: + aProp <<= (sal_Bool)( ( pButton->GetStyle() & WB_NOPOINTERFOCUS ) == 0 ); + break; + + case BASEPROPERTY_TOGGLE: + aProp <<= (sal_Bool)( ( pButton->GetStyle() & WB_TOGGLE ) != 0 ); + break; + + case BASEPROPERTY_DEFAULTBUTTON: + { + aProp <<= (sal_Bool) ( ( pButton->GetStyle() & WB_DEFBUTTON ) ? sal_True : sal_False ); + } + break; + case BASEPROPERTY_STATE: + { + if ( GetWindow()->GetType() == WINDOW_PUSHBUTTON ) + { + aProp <<= (sal_Int16)((PushButton*)pButton)->GetState(); + } + } + break; + default: + { + aProp <<= VCLXImageConsumer::getProperty( PropertyName ); + } + } + } + return aProp; +} + +void VCLXButton::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) +{ + switch ( rVclWindowEvent.GetId() ) + { + case VCLEVENT_BUTTON_CLICK: + { + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xKeepAlive( this ); + // since we call listeners below, there is a potential that we will be destroyed + // during the listener call. To prevent the resulting crashs, we keep us + // alive as long as we're here + // #20178# - 2003-10-01 - fs@openoffice.org + + if ( maActionListeners.getLength() ) + { + ::com::sun::star::awt::ActionEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.ActionCommand = maActionCommand; + maActionListeners.actionPerformed( aEvent ); + } + } + break; + + case VCLEVENT_PUSHBUTTON_TOGGLE: + { + PushButton& rButton = dynamic_cast< PushButton& >( *rVclWindowEvent.GetWindow() ); + + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xKeepAlive( this ); + if ( maItemListeners.getLength() ) + { + ::com::sun::star::awt::ItemEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.Selected = ( rButton.GetState() == STATE_CHECK ) ? 1 : 0; + maItemListeners.itemStateChanged( aEvent ); + } + } + break; + + default: + VCLXImageConsumer::ProcessWindowEvent( rVclWindowEvent ); + break; + } +} + +// ---------------------------------------------------- +// class VCLXImageControl +// ---------------------------------------------------- + +void VCLXImageControl::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + PushPropertyIds( rIds, + BASEPROPERTY_BACKGROUNDCOLOR, + BASEPROPERTY_BORDER, + BASEPROPERTY_BORDERCOLOR, + BASEPROPERTY_DEFAULTCONTROL, + BASEPROPERTY_ENABLED, + BASEPROPERTY_ENABLEVISIBLE, + BASEPROPERTY_GRAPHIC, + BASEPROPERTY_HELPTEXT, + BASEPROPERTY_HELPURL, + BASEPROPERTY_IMAGEURL, + BASEPROPERTY_PRINTABLE, + BASEPROPERTY_SCALEIMAGE, + BASEPROPERTY_IMAGE_SCALE_MODE, + BASEPROPERTY_TABSTOP, + BASEPROPERTY_WRITING_MODE, + BASEPROPERTY_CONTEXT_WRITING_MODE, + 0); + VCLXImageConsumer::ImplGetPropertyIds( rIds ); +} + +VCLXImageControl::VCLXImageControl() +{ +} + +VCLXImageControl::~VCLXImageControl() +{ +} + +void VCLXImageControl::ImplSetNewImage() +{ + OSL_PRECOND( GetWindow(), "VCLXImageControl::ImplSetNewImage: window is required to be not-NULL!" ); + ImageControl* pControl = static_cast< ImageControl* >( GetWindow() ); + pControl->SetBitmap( GetBitmap() ); +} + +::com::sun::star::awt::Size VCLXImageControl::getMinimumSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Size aSz = GetBitmap().GetSizePixel(); + aSz = ImplCalcWindowSize( aSz ); + + return AWTSize(aSz); +} + +::com::sun::star::awt::Size VCLXImageControl::getPreferredSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + return getMinimumSize(); +} + +::com::sun::star::awt::Size VCLXImageControl::calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::awt::Size aSz = rNewSize; + ::com::sun::star::awt::Size aMinSz = getMinimumSize(); + if ( aSz.Width < aMinSz.Width ) + aSz.Width = aMinSz.Width; + if ( aSz.Height < aMinSz.Height ) + aSz.Height = aMinSz.Height; + return aSz; +} + +void VCLXImageControl::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ImageControl* pImageControl = (ImageControl*)GetWindow(); + + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_IMAGE_SCALE_MODE: + { + sal_Int16 nScaleMode( ImageScaleMode::Anisotropic ); + if ( pImageControl && ( Value >>= nScaleMode ) ) + { + pImageControl->SetScaleMode( nScaleMode ); + } + } + break; + + case BASEPROPERTY_SCALEIMAGE: + { + // this is for compatibility only, nowadays, the ImageScaleMode property should be used + sal_Bool bScaleImage = sal_False; + if ( pImageControl && ( Value >>= bScaleImage ) ) + { + pImageControl->SetScaleMode( bScaleImage ? ImageScaleMode::Anisotropic : ImageScaleMode::None ); + } + } + break; + + default: + VCLXImageConsumer::setProperty( PropertyName, Value ); + break; + } +} + +::com::sun::star::uno::Any VCLXImageControl::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Any aProp; + ImageControl* pImageControl = (ImageControl*)GetWindow(); + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + + switch ( nPropType ) + { + case BASEPROPERTY_IMAGE_SCALE_MODE: + aProp <<= ( pImageControl ? pImageControl->GetScaleMode() : ImageScaleMode::Anisotropic ); + break; + + case BASEPROPERTY_SCALEIMAGE: + aProp <<= ( pImageControl && pImageControl->GetScaleMode() != ImageScaleMode::None ) ? sal_True : sal_False; + break; + + default: + aProp = VCLXImageConsumer::getProperty( PropertyName ); + break; + } + return aProp; +} + +// ---------------------------------------------------- +// class VCLXCheckBox +// ---------------------------------------------------- + + +void VCLXCheckBox::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + PushPropertyIds( rIds, + BASEPROPERTY_DEFAULTCONTROL, + BASEPROPERTY_ENABLED, + BASEPROPERTY_ENABLEVISIBLE, + BASEPROPERTY_FONTDESCRIPTOR, + BASEPROPERTY_GRAPHIC, + BASEPROPERTY_HELPTEXT, + BASEPROPERTY_HELPURL, + BASEPROPERTY_IMAGEPOSITION, + BASEPROPERTY_IMAGEURL, + BASEPROPERTY_LABEL, + BASEPROPERTY_PRINTABLE, + BASEPROPERTY_STATE, + BASEPROPERTY_TABSTOP, + BASEPROPERTY_TRISTATE, + BASEPROPERTY_VISUALEFFECT, + BASEPROPERTY_MULTILINE, + BASEPROPERTY_BACKGROUNDCOLOR, + BASEPROPERTY_ALIGN, + BASEPROPERTY_VERTICALALIGN, + BASEPROPERTY_WRITING_MODE, + BASEPROPERTY_CONTEXT_WRITING_MODE, + BASEPROPERTY_REFERENCE_DEVICE, + 0); + VCLXImageConsumer::ImplGetPropertyIds( rIds ); +} + +VCLXCheckBox::VCLXCheckBox() : maActionListeners( *this ), maItemListeners( *this ) +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXCheckBox::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XButton*, this ), + SAL_STATIC_CAST( ::com::sun::star::awt::XCheckBox*, this ) ); + return (aRet.hasValue() ? aRet : VCLXImageConsumer::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXCheckBox ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XButton>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XCheckBox>* ) NULL ), + VCLXImageConsumer::getTypes() +IMPL_XTYPEPROVIDER_END + +::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > VCLXCheckBox::CreateAccessibleContext() +{ + return getAccessibleFactory().createAccessibleContext( this ); +} + +void VCLXCheckBox::dispose() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::lang::EventObject aObj; + aObj.Source = (::cppu::OWeakObject*)this; + maItemListeners.disposeAndClear( aObj ); + VCLXImageConsumer::dispose(); +} + +void VCLXCheckBox::addItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maItemListeners.addInterface( l ); +} + +void VCLXCheckBox::removeItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maItemListeners.removeInterface( l ); +} + +void VCLXCheckBox::addActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener > & l )throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maActionListeners.addInterface( l ); +} + +void VCLXCheckBox::removeActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maActionListeners.removeInterface( l ); +} + +void VCLXCheckBox::setActionCommand( const ::rtl::OUString& rCommand ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maActionCommand = rCommand; +} + +void VCLXCheckBox::setLabel( const ::rtl::OUString& rLabel ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if ( pWindow ) + pWindow->SetText( rLabel ); +} + +void VCLXCheckBox::setState( short n ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + CheckBox* pCheckBox = (CheckBox*)GetWindow(); + if ( pCheckBox) + { + TriState eState; + switch ( n ) + { + case 0: eState = STATE_NOCHECK; break; + case 1: eState = STATE_CHECK; break; + case 2: eState = STATE_DONTKNOW; break; + default: eState = STATE_NOCHECK; + } + pCheckBox->SetState( eState ); + + // #105198# call C++ click listeners (needed for accessibility) + // pCheckBox->GetClickHdl().Call( pCheckBox ); + + // #107218# Call same virtual methods and listeners like VCL would do after user interaction + SetSynthesizingVCLEvent( sal_True ); + pCheckBox->Toggle(); + pCheckBox->Click(); + SetSynthesizingVCLEvent( sal_False ); + } +} + +short VCLXCheckBox::getState() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + short nState = -1; + CheckBox* pCheckBox = (CheckBox*)GetWindow(); + if ( pCheckBox ) + { + switch ( pCheckBox->GetState() ) + { + case STATE_NOCHECK: nState = 0; break; + case STATE_CHECK: nState = 1; break; + case STATE_DONTKNOW: nState = 2; break; + default: DBG_ERROR( "VCLXCheckBox::getState(): unknown TriState!" ); + } + } + + return nState; +} + +void VCLXCheckBox::enableTriState( sal_Bool b ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + CheckBox* pCheckBox = (CheckBox*)GetWindow(); + if ( pCheckBox) + pCheckBox->EnableTriState( b ); +} + +::com::sun::star::awt::Size VCLXCheckBox::getMinimumSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Size aSz; + CheckBox* pCheckBox = (CheckBox*) GetWindow(); + if ( pCheckBox ) + aSz = pCheckBox->CalcMinimumSize(); + return AWTSize(aSz); +} + +::com::sun::star::awt::Size VCLXCheckBox::getPreferredSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + return getMinimumSize(); +} + +::com::sun::star::awt::Size VCLXCheckBox::calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Size aSz = VCLSize(rNewSize); + CheckBox* pCheckBox = (CheckBox*) GetWindow(); + if ( pCheckBox ) + { + Size aMinSz = pCheckBox->CalcMinimumSize(); + if ( ( aSz.Width() > aMinSz.Width() ) && ( aSz.Height() < aMinSz.Height() ) ) + aSz.Height() = aMinSz.Height(); + else + aSz = aMinSz; + } + return AWTSize(aSz); +} + +void VCLXCheckBox::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + CheckBox* pCheckBox = (CheckBox*)GetWindow(); + if ( pCheckBox ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_VISUALEFFECT: + ::toolkit::setVisualEffect( Value, pCheckBox, &StyleSettings::SetCheckBoxStyle, STYLE_CHECKBOX_MONO, STYLE_CHECKBOX_WIN ); + break; + + case BASEPROPERTY_TRISTATE: + { + sal_Bool b = sal_Bool(); + if ( Value >>= b ) + pCheckBox->EnableTriState( b ); + } + break; + case BASEPROPERTY_STATE: + { + sal_Int16 n = sal_Int16(); + if ( Value >>= n ) + setState( n ); + } + break; + default: + { + VCLXImageConsumer::setProperty( PropertyName, Value ); + } + } + } +} + +::com::sun::star::uno::Any VCLXCheckBox::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Any aProp; + CheckBox* pCheckBox = (CheckBox*)GetWindow(); + if ( pCheckBox ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_VISUALEFFECT: + aProp = ::toolkit::getVisualEffect( pCheckBox, &StyleSettings::GetCheckBoxStyle, STYLE_CHECKBOX_MONO ); + break; + case BASEPROPERTY_TRISTATE: + aProp <<= (sal_Bool)pCheckBox->IsTriStateEnabled(); + break; + case BASEPROPERTY_STATE: + aProp <<= (sal_Int16)pCheckBox->GetState(); + break; + default: + { + aProp <<= VCLXImageConsumer::getProperty( PropertyName ); + } + } + } + return aProp; +} + +void VCLXCheckBox::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) +{ + switch ( rVclWindowEvent.GetId() ) + { + case VCLEVENT_CHECKBOX_TOGGLE: + { + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xKeepAlive( this ); + // since we call listeners below, there is a potential that we will be destroyed + // in during the listener call. To prevent the resulting crashs, we keep us + // alive as long as we're here + // #20178# - 2003-10-01 - fs@openoffice.org + + CheckBox* pCheckBox = (CheckBox*)GetWindow(); + if ( pCheckBox ) + { + if ( maItemListeners.getLength() ) + { + ::com::sun::star::awt::ItemEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.Highlighted = sal_False; + aEvent.Selected = pCheckBox->GetState(); + maItemListeners.itemStateChanged( aEvent ); + } + if ( !IsSynthesizingVCLEvent() && maActionListeners.getLength() ) + { + ::com::sun::star::awt::ActionEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.ActionCommand = maActionCommand; + maActionListeners.actionPerformed( aEvent ); + } + } + } + break; + + default: + VCLXImageConsumer::ProcessWindowEvent( rVclWindowEvent ); + break; + } +} + +// ---------------------------------------------------- +// class VCLXRadioButton +// ---------------------------------------------------- +void VCLXRadioButton::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + PushPropertyIds( rIds, + BASEPROPERTY_DEFAULTCONTROL, + BASEPROPERTY_ENABLED, + BASEPROPERTY_ENABLEVISIBLE, + BASEPROPERTY_FONTDESCRIPTOR, + BASEPROPERTY_GRAPHIC, + BASEPROPERTY_HELPTEXT, + BASEPROPERTY_HELPURL, + BASEPROPERTY_IMAGEPOSITION, + BASEPROPERTY_IMAGEURL, + BASEPROPERTY_LABEL, + BASEPROPERTY_PRINTABLE, + BASEPROPERTY_STATE, + BASEPROPERTY_TABSTOP, + BASEPROPERTY_VISUALEFFECT, + BASEPROPERTY_MULTILINE, + BASEPROPERTY_BACKGROUNDCOLOR, + BASEPROPERTY_ALIGN, + BASEPROPERTY_VERTICALALIGN, + BASEPROPERTY_WRITING_MODE, + BASEPROPERTY_CONTEXT_WRITING_MODE, + BASEPROPERTY_REFERENCE_DEVICE, + 0); + VCLXImageConsumer::ImplGetPropertyIds( rIds ); +} + + +VCLXRadioButton::VCLXRadioButton() : maItemListeners( *this ), maActionListeners( *this ) +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXRadioButton::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XRadioButton*, this ), + SAL_STATIC_CAST( ::com::sun::star::awt::XButton*, this ) ); + return (aRet.hasValue() ? aRet : VCLXImageConsumer::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXRadioButton ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRadioButton>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XButton>* ) NULL ), + VCLXImageConsumer::getTypes() +IMPL_XTYPEPROVIDER_END + +::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > VCLXRadioButton::CreateAccessibleContext() +{ + return getAccessibleFactory().createAccessibleContext( this ); +} + +void VCLXRadioButton::dispose() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::lang::EventObject aObj; + aObj.Source = (::cppu::OWeakObject*)this; + maItemListeners.disposeAndClear( aObj ); + VCLXImageConsumer::dispose(); +} + +void VCLXRadioButton::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + RadioButton* pButton = (RadioButton*)GetWindow(); + if ( pButton ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_VISUALEFFECT: + ::toolkit::setVisualEffect( Value, pButton, &StyleSettings::SetRadioButtonStyle, STYLE_RADIOBUTTON_MONO, STYLE_RADIOBUTTON_WIN ); + break; + + case BASEPROPERTY_STATE: + { + sal_Int16 n = sal_Int16(); + if ( Value >>= n ) + { + BOOL b = n ? sal_True : sal_False; + if ( pButton->IsRadioCheckEnabled() ) + pButton->Check( b ); + else + pButton->SetState( b ); + } + } + break; + case BASEPROPERTY_AUTOTOGGLE: + { + sal_Bool b = sal_Bool(); + if ( Value >>= b ) + pButton->EnableRadioCheck( b ); + } + break; + default: + { + VCLXImageConsumer::setProperty( PropertyName, Value ); + } + } + } +} + +::com::sun::star::uno::Any VCLXRadioButton::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Any aProp; + RadioButton* pButton = (RadioButton*)GetWindow(); + if ( pButton ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_VISUALEFFECT: + aProp = ::toolkit::getVisualEffect( pButton, &StyleSettings::GetRadioButtonStyle, STYLE_RADIOBUTTON_MONO ); + break; + case BASEPROPERTY_STATE: + aProp <<= (sal_Int16) ( pButton->IsChecked() ? 1 : 0 ); + break; + case BASEPROPERTY_AUTOTOGGLE: + aProp <<= (sal_Bool) pButton->IsRadioCheckEnabled(); + break; + default: + { + aProp <<= VCLXImageConsumer::getProperty( PropertyName ); + } + } + } + return aProp; +} + +void VCLXRadioButton::addItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maItemListeners.addInterface( l ); +} + +void VCLXRadioButton::removeItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maItemListeners.removeInterface( l ); +} + +void VCLXRadioButton::addActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener > & l )throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maActionListeners.addInterface( l ); +} + +void VCLXRadioButton::removeActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maActionListeners.removeInterface( l ); +} + +void VCLXRadioButton::setLabel( const ::rtl::OUString& rLabel ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if ( pWindow ) + pWindow->SetText( rLabel ); +} + +void VCLXRadioButton::setActionCommand( const ::rtl::OUString& rCommand ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maActionCommand = rCommand; +} + +void VCLXRadioButton::setState( sal_Bool b ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + RadioButton* pRadioButton = (RadioButton*)GetWindow(); + if ( pRadioButton) + { + pRadioButton->Check( b ); + // #102717# item listeners are called, but not C++ click listeners in StarOffice code => call click hdl + // But this is needed in old code because Accessibility API uses it. + // pRadioButton->GetClickHdl().Call( pRadioButton ); + + // #107218# Call same virtual methods and listeners like VCL would do after user interaction + SetSynthesizingVCLEvent( sal_True ); + pRadioButton->Click(); + SetSynthesizingVCLEvent( sal_False ); + } +} + +sal_Bool VCLXRadioButton::getState() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + RadioButton* pRadioButton = (RadioButton*)GetWindow(); + return pRadioButton ? pRadioButton->IsChecked() : sal_False; +} + +::com::sun::star::awt::Size VCLXRadioButton::getMinimumSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Size aSz; + RadioButton* pRadioButton = (RadioButton*) GetWindow(); + if ( pRadioButton ) + aSz = pRadioButton->CalcMinimumSize(); + return AWTSize(aSz); +} + +::com::sun::star::awt::Size VCLXRadioButton::getPreferredSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + return getMinimumSize(); +} + +::com::sun::star::awt::Size VCLXRadioButton::calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Size aSz = VCLSize(rNewSize); + RadioButton* pRadioButton = (RadioButton*) GetWindow(); + if ( pRadioButton ) + { + Size aMinSz = pRadioButton->CalcMinimumSize(); + if ( ( aSz.Width() > aMinSz.Width() ) && ( aSz.Height() < aMinSz.Height() ) ) + aSz.Height() = aMinSz.Height(); + else + aSz = aMinSz; + } + return AWTSize(aSz); +} + +void VCLXRadioButton::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) +{ + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xKeepAlive( this ); + // since we call listeners below, there is a potential that we will be destroyed + // in during the listener call. To prevent the resulting crashs, we keep us + // alive as long as we're here + // #20178# - 2003-10-01 - fs@openoffice.org + + switch ( rVclWindowEvent.GetId() ) + { + case VCLEVENT_BUTTON_CLICK: + if ( !IsSynthesizingVCLEvent() && maActionListeners.getLength() ) + { + ::com::sun::star::awt::ActionEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.ActionCommand = maActionCommand; + maActionListeners.actionPerformed( aEvent ); + } + ImplClickedOrToggled( FALSE ); + break; + + case VCLEVENT_RADIOBUTTON_TOGGLE: + ImplClickedOrToggled( TRUE ); + break; + + default: + VCLXImageConsumer::ProcessWindowEvent( rVclWindowEvent ); + break; + } +} + +void VCLXRadioButton::ImplClickedOrToggled( BOOL bToggled ) +{ + // In the formulars, RadioChecked is not enabled, call itemStateChanged only for click + // In the dialog editor, RadioChecked is enabled, call itemStateChanged only for bToggled + RadioButton* pRadioButton = (RadioButton*)GetWindow(); + if ( pRadioButton && ( pRadioButton->IsRadioCheckEnabled() == bToggled ) && ( bToggled || pRadioButton->IsStateChanged() ) && maItemListeners.getLength() ) + { + ::com::sun::star::awt::ItemEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.Highlighted = sal_False; + aEvent.Selected = pRadioButton->IsChecked(); + maItemListeners.itemStateChanged( aEvent ); + } +} + +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > VCLXRadioButton::getFirstActionListener () +{ + if (!maItemListeners.getLength ()) + return ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > (); + return maActionListeners.getElements()[0]; +} + +// ---------------------------------------------------- +// class VCLXSpinField +// ---------------------------------------------------- +void VCLXSpinField::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + PushPropertyIds( rIds, + BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR, + 0 ); + VCLXEdit::ImplGetPropertyIds( rIds ); +} + +VCLXSpinField::VCLXSpinField() : maSpinListeners( *this ) +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXSpinField::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XSpinField*, this ) ); + return (aRet.hasValue() ? aRet : VCLXEdit::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXSpinField ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XSpinField>* ) NULL ), + VCLXEdit::getTypes() +IMPL_XTYPEPROVIDER_END + +void VCLXSpinField::addSpinListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XSpinListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maSpinListeners.addInterface( l ); +} + +void VCLXSpinField::removeSpinListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XSpinListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maSpinListeners.removeInterface( l ); +} + +void VCLXSpinField::up() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + SpinField* pSpinField = (SpinField*) GetWindow(); + if ( pSpinField ) + pSpinField->Up(); +} + +void VCLXSpinField::down() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + SpinField* pSpinField = (SpinField*) GetWindow(); + if ( pSpinField ) + pSpinField->Down(); +} + +void VCLXSpinField::first() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + SpinField* pSpinField = (SpinField*) GetWindow(); + if ( pSpinField ) + pSpinField->First(); +} + +void VCLXSpinField::last() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + SpinField* pSpinField = (SpinField*) GetWindow(); + if ( pSpinField ) + pSpinField->Last(); +} + +void VCLXSpinField::enableRepeat( sal_Bool bRepeat ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if ( pWindow ) + { + WinBits nStyle = pWindow->GetStyle(); + if ( bRepeat ) + nStyle |= WB_REPEAT; + else + nStyle &= ~WB_REPEAT; + pWindow->SetStyle( nStyle ); + } +} + +void VCLXSpinField::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) +{ + switch ( rVclWindowEvent.GetId() ) + { + case VCLEVENT_SPINFIELD_UP: + case VCLEVENT_SPINFIELD_DOWN: + case VCLEVENT_SPINFIELD_FIRST: + case VCLEVENT_SPINFIELD_LAST: + { + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xKeepAlive( this ); + // since we call listeners below, there is a potential that we will be destroyed + // in during the listener call. To prevent the resulting crashs, we keep us + // alive as long as we're here + // #20178# - 2003-10-01 - fs@openoffice.org + + if ( maSpinListeners.getLength() ) + { + ::com::sun::star::awt::SpinEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + switch ( rVclWindowEvent.GetId() ) + { + case VCLEVENT_SPINFIELD_UP: maSpinListeners.up( aEvent ); + break; + case VCLEVENT_SPINFIELD_DOWN: maSpinListeners.down( aEvent ); + break; + case VCLEVENT_SPINFIELD_FIRST: maSpinListeners.first( aEvent ); + break; + case VCLEVENT_SPINFIELD_LAST: maSpinListeners.last( aEvent ); + break; + } + + } + } + break; + + default: + VCLXEdit::ProcessWindowEvent( rVclWindowEvent ); + break; + } +} + + +// ---------------------------------------------------- +// class VCLXListBox +// ---------------------------------------------------- +void VCLXListBox::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + PushPropertyIds( rIds, + BASEPROPERTY_BACKGROUNDCOLOR, + BASEPROPERTY_BORDER, + BASEPROPERTY_BORDERCOLOR, + BASEPROPERTY_DEFAULTCONTROL, + BASEPROPERTY_DROPDOWN, + BASEPROPERTY_ENABLED, + BASEPROPERTY_ENABLEVISIBLE, + BASEPROPERTY_FONTDESCRIPTOR, + BASEPROPERTY_HELPTEXT, + BASEPROPERTY_HELPURL, + BASEPROPERTY_LINECOUNT, + BASEPROPERTY_MULTISELECTION, + BASEPROPERTY_PRINTABLE, + BASEPROPERTY_SELECTEDITEMS, + BASEPROPERTY_STRINGITEMLIST, + BASEPROPERTY_TABSTOP, + BASEPROPERTY_READONLY, + BASEPROPERTY_ALIGN, + BASEPROPERTY_WRITING_MODE, + BASEPROPERTY_CONTEXT_WRITING_MODE, + BASEPROPERTY_REFERENCE_DEVICE, + BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR, + 0); + VCLXWindow::ImplGetPropertyIds( rIds ); +} + + +VCLXListBox::VCLXListBox() + : maActionListeners( *this ), + maItemListeners( *this ) +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXListBox::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XListBox*, this ), + SAL_STATIC_CAST( ::com::sun::star::awt::XTextLayoutConstrains*, this ) ); + return (aRet.hasValue() ? aRet : VCLXWindow::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXListBox ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XListBox>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextLayoutConstrains>* ) NULL ), + VCLXWindow::getTypes() +IMPL_XTYPEPROVIDER_END + +void VCLXListBox::dispose() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::lang::EventObject aObj; + aObj.Source = (::cppu::OWeakObject*)this; + maItemListeners.disposeAndClear( aObj ); + maActionListeners.disposeAndClear( aObj ); + VCLXWindow::dispose(); +} + +void VCLXListBox::addItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maItemListeners.addInterface( l ); +} + +void VCLXListBox::removeItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maItemListeners.removeInterface( l ); +} + +void VCLXListBox::addActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maActionListeners.addInterface( l ); +} + +void VCLXListBox::removeActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maActionListeners.removeInterface( l ); +} + +void VCLXListBox::addItem( const ::rtl::OUString& aItem, sal_Int16 nPos ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ListBox* pBox = (ListBox*) GetWindow(); + if ( pBox ) + pBox->InsertEntry( aItem, nPos ); +} + +void VCLXListBox::addItems( const ::com::sun::star::uno::Sequence< ::rtl::OUString>& aItems, sal_Int16 nPos ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ListBox* pBox = (ListBox*) GetWindow(); + if ( pBox ) + { + sal_uInt16 nP = nPos; + const ::rtl::OUString* pItems = aItems.getConstArray(); + const ::rtl::OUString* pItemsEnd = aItems.getConstArray() + aItems.getLength(); + while ( pItems != pItemsEnd ) + { + if ( (sal_uInt16)nP == 0xFFFF ) + { + OSL_ENSURE( false, "VCLXListBox::addItems: too many entries!" ); + // skip remaining entries, list cannot hold them, anyway + break; + } + + pBox->InsertEntry( *pItems++, nP++ ); + } + } +} + +void VCLXListBox::removeItems( sal_Int16 nPos, sal_Int16 nCount ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ListBox* pBox = (ListBox*) GetWindow(); + if ( pBox ) + { + for ( sal_uInt16 n = nCount; n; ) + pBox->RemoveEntry( nPos + (--n) ); + } +} + +sal_Int16 VCLXListBox::getItemCount() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ListBox* pBox = (ListBox*) GetWindow(); + return pBox ? pBox->GetEntryCount() : 0; +} + +::rtl::OUString VCLXListBox::getItem( sal_Int16 nPos ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + String aItem; + ListBox* pBox = (ListBox*) GetWindow(); + if ( pBox ) + aItem = pBox->GetEntry( nPos ); + return aItem; +} + +::com::sun::star::uno::Sequence< ::rtl::OUString> VCLXListBox::getItems() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Sequence< ::rtl::OUString> aSeq; + ListBox* pBox = (ListBox*) GetWindow(); + if ( pBox ) + { + sal_uInt16 nEntries = pBox->GetEntryCount(); + aSeq = ::com::sun::star::uno::Sequence< ::rtl::OUString>( nEntries ); + for ( sal_uInt16 n = nEntries; n; ) + { + --n; + aSeq.getArray()[n] = ::rtl::OUString( pBox->GetEntry( n ) ); + } + } + return aSeq; +} + +sal_Int16 VCLXListBox::getSelectedItemPos() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ListBox* pBox = (ListBox*) GetWindow(); + return pBox ? pBox->GetSelectEntryPos() : 0; +} + +::com::sun::star::uno::Sequence<sal_Int16> VCLXListBox::getSelectedItemsPos() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Sequence<sal_Int16> aSeq; + ListBox* pBox = (ListBox*) GetWindow(); + if ( pBox ) + { + sal_uInt16 nSelEntries = pBox->GetSelectEntryCount(); + aSeq = ::com::sun::star::uno::Sequence<sal_Int16>( nSelEntries ); + for ( sal_uInt16 n = 0; n < nSelEntries; n++ ) + aSeq.getArray()[n] = pBox->GetSelectEntryPos( n ); + } + return aSeq; +} + +::rtl::OUString VCLXListBox::getSelectedItem() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + String aItem; + ListBox* pBox = (ListBox*) GetWindow(); + if ( pBox ) + aItem = pBox->GetSelectEntry(); + return aItem; +} + +::com::sun::star::uno::Sequence< ::rtl::OUString> VCLXListBox::getSelectedItems() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Sequence< ::rtl::OUString> aSeq; + ListBox* pBox = (ListBox*) GetWindow(); + if ( pBox ) + { + sal_uInt16 nSelEntries = pBox->GetSelectEntryCount(); + aSeq = ::com::sun::star::uno::Sequence< ::rtl::OUString>( nSelEntries ); + for ( sal_uInt16 n = 0; n < nSelEntries; n++ ) + aSeq.getArray()[n] = ::rtl::OUString( pBox->GetSelectEntry( n ) ); + } + return aSeq; +} + +void VCLXListBox::selectItemPos( sal_Int16 nPos, sal_Bool bSelect ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ListBox* pBox = (ListBox*) GetWindow(); + if ( pBox && ( pBox->IsEntryPosSelected( nPos ) != bSelect ) ) + { + pBox->SelectEntryPos( nPos, bSelect ); + + // VCL doesn't call select handler after API call. + // ImplCallItemListeners(); + + // #107218# Call same listeners like VCL would do after user interaction + SetSynthesizingVCLEvent( sal_True ); + pBox->Select(); + SetSynthesizingVCLEvent( sal_False ); + } +} + +void VCLXListBox::selectItemsPos( const ::com::sun::star::uno::Sequence<sal_Int16>& aPositions, sal_Bool bSelect ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ListBox* pBox = (ListBox*) GetWindow(); + if ( pBox ) + { + BOOL bChanged = FALSE; + for ( sal_uInt16 n = (sal_uInt16)aPositions.getLength(); n; ) + { + USHORT nPos = (USHORT) aPositions.getConstArray()[--n]; + if ( pBox->IsEntryPosSelected( nPos ) != bSelect ) + { + pBox->SelectEntryPos( nPos, bSelect ); + bChanged = TRUE; + } + } + + if ( bChanged ) + { + // VCL doesn't call select handler after API call. + // ImplCallItemListeners(); + + // #107218# Call same listeners like VCL would do after user interaction + SetSynthesizingVCLEvent( sal_True ); + pBox->Select(); + SetSynthesizingVCLEvent( sal_False ); + } + } +} + +void VCLXListBox::selectItem( const ::rtl::OUString& rItemText, sal_Bool bSelect ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ListBox* pBox = (ListBox*) GetWindow(); + if ( pBox ) + { + String aItemText( rItemText ); + selectItemPos( pBox->GetEntryPos( aItemText ), bSelect ); + } +} + + +void VCLXListBox::setDropDownLineCount( sal_Int16 nLines ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ListBox* pBox = (ListBox*) GetWindow(); + if ( pBox ) + pBox->SetDropDownLineCount( nLines ); +} + +sal_Int16 VCLXListBox::getDropDownLineCount() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + sal_Int16 nLines = 0; + ListBox* pBox = (ListBox*) GetWindow(); + if ( pBox ) + nLines = pBox->GetDropDownLineCount(); + return nLines; +} + +sal_Bool VCLXListBox::isMutipleMode() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + sal_Bool bMulti = sal_False; + ListBox* pBox = (ListBox*) GetWindow(); + if ( pBox ) + bMulti = pBox->IsMultiSelectionEnabled(); + return bMulti; +} + +void VCLXListBox::setMultipleMode( sal_Bool bMulti ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ListBox* pBox = (ListBox*) GetWindow(); + if ( pBox ) + pBox->EnableMultiSelection( bMulti ); +} + +void VCLXListBox::makeVisible( sal_Int16 nEntry ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ListBox* pBox = (ListBox*) GetWindow(); + if ( pBox ) + pBox->SetTopEntry( nEntry ); +} + +void VCLXListBox::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) +{ + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xKeepAlive( this ); + // since we call listeners below, there is a potential that we will be destroyed + // in during the listener call. To prevent the resulting crashs, we keep us + // alive as long as we're here + // #20178# - 2003-10-01 - fs@openoffice.org + + switch ( rVclWindowEvent.GetId() ) + { + case VCLEVENT_LISTBOX_SELECT: + { + ListBox* pListBox = (ListBox*)GetWindow(); + + if( pListBox ) + { + sal_Bool bDropDown = ( pListBox->GetStyle() & WB_DROPDOWN ) ? sal_True : sal_False; + if ( bDropDown && !IsSynthesizingVCLEvent() && maActionListeners.getLength() ) + { + // Bei DropDown den ActionListener rufen... + ::com::sun::star::awt::ActionEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.ActionCommand = pListBox->GetSelectEntry(); + maActionListeners.actionPerformed( aEvent ); + } + + if ( maItemListeners.getLength() ) + { + ImplCallItemListeners(); + } + } + } + break; + + case VCLEVENT_LISTBOX_DOUBLECLICK: + if ( GetWindow() && maActionListeners.getLength() ) + { + ::com::sun::star::awt::ActionEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.ActionCommand = ((ListBox*)GetWindow())->GetSelectEntry(); + maActionListeners.actionPerformed( aEvent ); + } + break; + + default: + VCLXWindow::ProcessWindowEvent( rVclWindowEvent ); + break; + } +} + +::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > VCLXListBox::CreateAccessibleContext() +{ + ::vos::OGuard aGuard( GetMutex() ); + + return getAccessibleFactory().createAccessibleContext( this ); +} + +void VCLXListBox::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ListBox* pListBox = (ListBox*)GetWindow(); + if ( pListBox ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_READONLY: + { + sal_Bool b = sal_Bool(); + if ( Value >>= b ) + pListBox->SetReadOnly( b); + } + break; + case BASEPROPERTY_MULTISELECTION: + { + sal_Bool b = sal_Bool(); + if ( Value >>= b ) + pListBox->EnableMultiSelection( b ); + } + break; + case BASEPROPERTY_LINECOUNT: + { + sal_Int16 n = sal_Int16(); + if ( Value >>= n ) + pListBox->SetDropDownLineCount( n ); + } + break; + case BASEPROPERTY_STRINGITEMLIST: + { + ::com::sun::star::uno::Sequence< ::rtl::OUString> aItems; + if ( Value >>= aItems ) + { + pListBox->Clear(); + addItems( aItems, 0 ); + } + } + break; + case BASEPROPERTY_SELECTEDITEMS: + { + ::com::sun::star::uno::Sequence<sal_Int16> aItems; + if ( Value >>= aItems ) + { + for ( sal_uInt16 n = pListBox->GetEntryCount(); n; ) + pListBox->SelectEntryPos( --n, sal_False ); + + if ( aItems.getLength() ) + selectItemsPos( aItems, sal_True ); + else + pListBox->SetNoSelection(); + + if ( !pListBox->GetSelectEntryCount() ) + pListBox->SetTopEntry( 0 ); + } + } + break; + default: + { + VCLXWindow::setProperty( PropertyName, Value ); + } + } + } +} + +::com::sun::star::uno::Any VCLXListBox::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Any aProp; + ListBox* pListBox = (ListBox*)GetWindow(); + if ( pListBox ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_READONLY: + { + aProp <<= (sal_Bool) pListBox->IsReadOnly(); + } + break; + case BASEPROPERTY_MULTISELECTION: + { + aProp <<= (sal_Bool) pListBox->IsMultiSelectionEnabled(); + } + break; + case BASEPROPERTY_LINECOUNT: + { + aProp <<= (sal_Int16) pListBox->GetDropDownLineCount(); + } + break; + case BASEPROPERTY_STRINGITEMLIST: + { + sal_uInt16 nItems = pListBox->GetEntryCount(); + ::com::sun::star::uno::Sequence< ::rtl::OUString> aSeq( nItems ); + ::rtl::OUString* pStrings = aSeq.getArray(); + for ( sal_uInt16 n = 0; n < nItems; n++ ) + pStrings[n] = pListBox->GetEntry( n ); + aProp <<= aSeq; + + } + break; + default: + { + aProp <<= VCLXWindow::getProperty( PropertyName ); + } + } + } + return aProp; +} + +::com::sun::star::awt::Size VCLXListBox::getMinimumSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Size aSz; + ListBox* pListBox = (ListBox*) GetWindow(); + if ( pListBox ) + aSz = pListBox->CalcMinimumSize(); + return AWTSize(aSz); +} + +::com::sun::star::awt::Size VCLXListBox::getPreferredSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Size aSz; + ListBox* pListBox = (ListBox*) GetWindow(); + if ( pListBox ) + { + aSz = pListBox->CalcMinimumSize(); + if ( pListBox->GetStyle() & WB_DROPDOWN ) + aSz.Height() += 4; + } + return AWTSize(aSz); +} + +::com::sun::star::awt::Size VCLXListBox::calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Size aSz = VCLSize(rNewSize); + ListBox* pListBox = (ListBox*) GetWindow(); + if ( pListBox ) + aSz = pListBox->CalcAdjustedSize( aSz ); + return AWTSize(aSz); +} + +::com::sun::star::awt::Size VCLXListBox::getMinimumSize( sal_Int16 nCols, sal_Int16 nLines ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Size aSz; + ListBox* pListBox = (ListBox*) GetWindow(); + if ( pListBox ) + aSz = pListBox->CalcSize( nCols, nLines ); + return AWTSize(aSz); +} + +void VCLXListBox::getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + nCols = nLines = 0; + ListBox* pListBox = (ListBox*) GetWindow(); + if ( pListBox ) + { + sal_uInt16 nC, nL; + pListBox->GetMaxVisColumnsAndLines( nC, nL ); + nCols = nC; + nLines = nL; + } +} + +void VCLXListBox::ImplCallItemListeners() +{ + ListBox* pListBox = (ListBox*) GetWindow(); + if ( pListBox && maItemListeners.getLength() ) + { + ::com::sun::star::awt::ItemEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.Highlighted = sal_False; + + // Bei Mehrfachselektion 0xFFFF, sonst die ID + aEvent.Selected = (pListBox->GetSelectEntryCount() == 1 ) ? pListBox->GetSelectEntryPos() : 0xFFFF; + + maItemListeners.itemStateChanged( aEvent ); + } +} + + +// ---------------------------------------------------- +// class VCLXMessageBox +// ---------------------------------------------------- + +void VCLXMessageBox::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + VCLXTopWindow::ImplGetPropertyIds( rIds ); +} + +VCLXMessageBox::VCLXMessageBox() +{ +} + +VCLXMessageBox::~VCLXMessageBox() +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXMessageBox::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XMessageBox*, this ) ); + return (aRet.hasValue() ? aRet : VCLXTopWindow::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXMessageBox ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMessageBox>* ) NULL ), + VCLXTopWindow::getTypes() +IMPL_XTYPEPROVIDER_END + +void VCLXMessageBox::setCaptionText( const ::rtl::OUString& rText ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if ( pWindow ) + pWindow->SetText( rText ); +} + +::rtl::OUString VCLXMessageBox::getCaptionText() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + String aText; + Window* pWindow = GetWindow(); + if ( pWindow ) + aText = pWindow->GetText(); + return aText; +} + +void VCLXMessageBox::setMessageText( const ::rtl::OUString& rText ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + MessBox* pBox = (MessBox*)GetWindow(); + if ( pBox ) + pBox->SetMessText( rText ); +} + +::rtl::OUString VCLXMessageBox::getMessageText() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::rtl::OUString aText; + MessBox* pBox = (MessBox*)GetWindow(); + if ( pBox ) + aText = pBox->GetMessText(); + return aText; +} + +sal_Int16 VCLXMessageBox::execute() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + MessBox* pBox = (MessBox*)GetWindow(); + return pBox ? pBox->Execute() : 0; +} + +::com::sun::star::awt::Size SAL_CALL VCLXMessageBox::getMinimumSize() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + return ::com::sun::star::awt::Size( 250, 100 ); +} + +// ---------------------------------------------------- +// class VCLXDialog +// ---------------------------------------------------- +void VCLXDialog::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + VCLXTopWindow::ImplGetPropertyIds( rIds ); +} + +VCLXDialog::VCLXDialog() +{ +} + +VCLXDialog::~VCLXDialog() +{ +#ifndef __SUNPRO_CC + OSL_TRACE ("%s", __FUNCTION__); +#endif +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXDialog::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XDialog*, this ) ); + return (aRet.hasValue() ? aRet : VCLXTopWindow::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXDialog ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDialog>* ) NULL ), + VCLXTopWindow::getTypes() +IMPL_XTYPEPROVIDER_END + +void VCLXDialog::setTitle( const ::rtl::OUString& Title ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if ( pWindow ) + pWindow->SetText( Title ); +} + +::rtl::OUString VCLXDialog::getTitle() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::rtl::OUString aTitle; + Window* pWindow = GetWindow(); + if ( pWindow ) + aTitle = pWindow->GetText(); + return aTitle; +} + +sal_Int16 VCLXDialog::execute() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + sal_Int16 nRet = 0; + if ( GetWindow() ) + { + Dialog* pDlg = (Dialog*) GetWindow(); + Window* pParent = pDlg->GetWindow( WINDOW_PARENTOVERLAP ); + Window* pOldParent = NULL; + if ( pParent && !pParent->IsReallyVisible() ) + { + pOldParent = pDlg->GetParent(); + Window* pFrame = pDlg->GetWindow( WINDOW_FRAME ); + if( pFrame != pDlg ) + pDlg->SetParent( pFrame ); + } + nRet = pDlg->Execute(); + if ( pOldParent ) + pDlg->SetParent( pOldParent ); + } + return nRet; +} + +void VCLXDialog::endExecute() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Dialog* pDlg = (Dialog*) GetWindow(); + if ( pDlg ) + pDlg->EndDialog( 0 ); +} + +void SAL_CALL VCLXDialog::draw( sal_Int32 nX, sal_Int32 nY ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + Window* pWindow = GetWindow(); + + if ( pWindow ) + { + OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( getGraphics() ); + if ( !pDev ) + pDev = pWindow->GetParent(); + + Size aSize = pDev->PixelToLogic( pWindow->GetSizePixel() ); + Point aPos = pDev->PixelToLogic( Point( nX, nY ) ); + + pWindow->Draw( pDev, aPos, aSize, WINDOW_DRAW_NOCONTROLS ); + } +} + +::com::sun::star::awt::DeviceInfo VCLXDialog::getInfo() throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::awt::DeviceInfo aInfo = VCLXDevice::getInfo(); + + ::vos::OGuard aGuard( GetMutex() ); + Dialog* pDlg = (Dialog*) GetWindow(); + if ( pDlg ) + pDlg->GetDrawWindowBorder( aInfo.LeftInset, aInfo.TopInset, aInfo.RightInset, aInfo.BottomInset ); + + return aInfo; +} + + +void SAL_CALL VCLXDialog::setProperty( + const ::rtl::OUString& PropertyName, + const ::com::sun::star::uno::Any& Value ) +throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Dialog* pDialog = (Dialog*)GetWindow(); + if ( pDialog ) + { + sal_Bool bVoid = Value.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID; + + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_GRAPHIC: + { + Reference< XGraphic > xGraphic; + if (( Value >>= xGraphic ) && xGraphic.is() ) + { + Image aImage( xGraphic ); + + Wallpaper aWallpaper( aImage.GetBitmapEx()); + aWallpaper.SetStyle( WALLPAPER_SCALE ); + pDialog->SetBackground( aWallpaper ); + } + else if ( bVoid || !xGraphic.is() ) + { + Color aColor = pDialog->GetControlBackground().GetColor(); + if ( aColor == COL_AUTO ) + aColor = pDialog->GetSettings().GetStyleSettings().GetDialogColor(); + + Wallpaper aWallpaper( aColor ); + pDialog->SetBackground( aWallpaper ); + } + } + break; + + default: + { + VCLXWindow::setProperty( PropertyName, Value ); + } + } + } +} + +// ---------------------------------------------------- +// class VCLXTabPage +// ---------------------------------------------------- +VCLXTabPage::VCLXTabPage() +{ +} + +VCLXTabPage::~VCLXTabPage() +{ +} + +::com::sun::star::uno::Any SAL_CALL VCLXTabPage::queryInterface(const ::com::sun::star::uno::Type & rType ) +throw(::com::sun::star::uno::RuntimeException) +{ + return VCLXContainer::queryInterface( rType ); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXTabPage ) + VCLXContainer::getTypes() +IMPL_XTYPEPROVIDER_END + +// ::com::sun::star::awt::XView +void SAL_CALL VCLXTabPage::draw( sal_Int32 nX, sal_Int32 nY ) +throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + Window* pWindow = GetWindow(); + + if ( pWindow ) + { + OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( getGraphics() ); + if ( !pDev ) + pDev = pWindow->GetParent(); + + Size aSize = pDev->PixelToLogic( pWindow->GetSizePixel() ); + Point aPos = pDev->PixelToLogic( Point( nX, nY ) ); + + pWindow->Draw( pDev, aPos, aSize, WINDOW_DRAW_NOCONTROLS ); + } +} + +// ::com::sun::star::awt::XDevice, +::com::sun::star::awt::DeviceInfo SAL_CALL VCLXTabPage::getInfo() +throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::awt::DeviceInfo aInfo = VCLXDevice::getInfo(); + return aInfo; +} + +void SAL_CALL VCLXTabPage::setProperty( + const ::rtl::OUString& PropertyName, + const ::com::sun::star::uno::Any& Value ) +throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + TabPage* pTabPage = (TabPage*)GetWindow(); + if ( pTabPage ) + { + sal_Bool bVoid = Value.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID; + + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_GRAPHIC: + { + Reference< XGraphic > xGraphic; + if (( Value >>= xGraphic ) && xGraphic.is() ) + { + Image aImage( xGraphic ); + + Wallpaper aWallpaper( aImage.GetBitmapEx()); + aWallpaper.SetStyle( WALLPAPER_SCALE ); + pTabPage->SetBackground( aWallpaper ); + } + else if ( bVoid || !xGraphic.is() ) + { + Color aColor = pTabPage->GetControlBackground().GetColor(); + if ( aColor == COL_AUTO ) + aColor = pTabPage->GetSettings().GetStyleSettings().GetDialogColor(); + + Wallpaper aWallpaper( aColor ); + pTabPage->SetBackground( aWallpaper ); + } + } + break; + + default: + { + VCLXContainer::setProperty( PropertyName, Value ); + } + } + } +} + +// ---------------------------------------------------- +// class VCLXFixedHyperlink +// ---------------------------------------------------- +VCLXFixedHyperlink::VCLXFixedHyperlink() : + + maActionListeners( *this ) + +{ +} + +VCLXFixedHyperlink::~VCLXFixedHyperlink() +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXFixedHyperlink::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XFixedHyperlink*, this ) ); + return (aRet.hasValue() ? aRet : VCLXWindow::queryInterface( rType )); +} + +void VCLXFixedHyperlink::dispose() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::lang::EventObject aObj; + aObj.Source = (::cppu::OWeakObject*)this; + maActionListeners.disposeAndClear( aObj ); + VCLXWindow::dispose(); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXFixedHyperlink ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFixedHyperlink>* ) NULL ), + VCLXWindow::getTypes() +IMPL_XTYPEPROVIDER_END + +void VCLXFixedHyperlink::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) +{ + switch ( rVclWindowEvent.GetId() ) + { + case VCLEVENT_BUTTON_CLICK: + { + if ( maActionListeners.getLength() ) + { + ::com::sun::star::awt::ActionEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + maActionListeners.actionPerformed( aEvent ); + } + else + { + // open the URL + ::rtl::OUString sURL; + ::toolkit::FixedHyperlinkBase* pBase = (::toolkit::FixedHyperlinkBase*)GetWindow(); + if ( pBase ) + sURL = pBase->GetURL(); + Reference< ::com::sun::star::system::XSystemShellExecute > xSystemShellExecute( + ::comphelper::getProcessServiceFactory()->createInstance( + ::rtl::OUString::createFromAscii( "com.sun.star.system.SystemShellExecute" )), uno::UNO_QUERY ); + if ( sURL.getLength() > 0 && xSystemShellExecute.is() ) + { + try + { + // start browser + xSystemShellExecute->execute( + sURL, ::rtl::OUString(), ::com::sun::star::system::SystemShellExecuteFlags::DEFAULTS ); + } + catch( uno::Exception& ) + { + } + } + } + } + + default: + VCLXWindow::ProcessWindowEvent( rVclWindowEvent ); + break; + } +} + +::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > VCLXFixedHyperlink::CreateAccessibleContext() +{ + return getAccessibleFactory().createAccessibleContext( this ); +} + +void VCLXFixedHyperlink::setText( const ::rtl::OUString& Text ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::toolkit::FixedHyperlinkBase* pBase = (::toolkit::FixedHyperlinkBase*)GetWindow(); + if ( pBase ) + pBase->SetDescription( Text ); +} + +::rtl::OUString VCLXFixedHyperlink::getText() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::rtl::OUString aText; + Window* pWindow = GetWindow(); + if ( pWindow ) + aText = pWindow->GetText(); + return aText; +} + +void VCLXFixedHyperlink::setURL( const ::rtl::OUString& URL ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::toolkit::FixedHyperlinkBase* pBase = (::toolkit::FixedHyperlinkBase*)GetWindow(); + if ( pBase ) + pBase->SetURL( URL ); +} + +::rtl::OUString VCLXFixedHyperlink::getURL( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::rtl::OUString aText; + ::toolkit::FixedHyperlinkBase* pBase = (::toolkit::FixedHyperlinkBase*)GetWindow(); + if ( pBase ) + aText = pBase->GetURL(); + return aText; +} + +void VCLXFixedHyperlink::setAlignment( short nAlign ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if ( pWindow ) + { + WinBits nNewBits = 0; + if ( nAlign == ::com::sun::star::awt::TextAlign::LEFT ) + nNewBits = WB_LEFT; + else if ( nAlign == ::com::sun::star::awt::TextAlign::CENTER ) + nNewBits = WB_CENTER; + else + nNewBits = WB_RIGHT; + + WinBits nStyle = pWindow->GetStyle(); + nStyle &= ~(WB_LEFT|WB_CENTER|WB_RIGHT); + pWindow->SetStyle( nStyle | nNewBits ); + } +} + +short VCLXFixedHyperlink::getAlignment() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + short nAlign = 0; + Window* pWindow = GetWindow(); + if ( pWindow ) + { + WinBits nStyle = pWindow->GetStyle(); + if ( nStyle & WB_LEFT ) + nAlign = ::com::sun::star::awt::TextAlign::LEFT; + else if ( nStyle & WB_CENTER ) + nAlign = ::com::sun::star::awt::TextAlign::CENTER; + else + nAlign = ::com::sun::star::awt::TextAlign::RIGHT; + } + return nAlign; +} + +void VCLXFixedHyperlink::addActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener > & l )throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maActionListeners.addInterface( l ); +} + +void VCLXFixedHyperlink::removeActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maActionListeners.removeInterface( l ); +} + +::com::sun::star::awt::Size VCLXFixedHyperlink::getMinimumSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Size aSz; + FixedText* pFixedText = (FixedText*)GetWindow(); + if ( pFixedText ) + aSz = pFixedText->CalcMinimumSize(); + return AWTSize(aSz); +} + +::com::sun::star::awt::Size VCLXFixedHyperlink::getPreferredSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + return getMinimumSize(); +} + +::com::sun::star::awt::Size VCLXFixedHyperlink::calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::awt::Size aSz = rNewSize; + ::com::sun::star::awt::Size aMinSz = getMinimumSize(); + if ( aSz.Height != aMinSz.Height ) + aSz.Height = aMinSz.Height; + + return aSz; +} + +void VCLXFixedHyperlink::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::toolkit::FixedHyperlinkBase* pBase = (::toolkit::FixedHyperlinkBase*)GetWindow(); + if ( pBase ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_LABEL: + { + ::rtl::OUString sNewLabel; + if ( Value >>= sNewLabel ) + pBase->SetDescription( sNewLabel ); + break; + } + + case BASEPROPERTY_URL: + { + ::rtl::OUString sNewURL; + if ( Value >>= sNewURL ) + pBase->SetURL( sNewURL ); + break; + } + + default: + { + VCLXWindow::setProperty( PropertyName, Value ); + } + } + } +} + +::com::sun::star::uno::Any VCLXFixedHyperlink::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Any aProp; + ::toolkit::FixedHyperlinkBase* pBase = (::toolkit::FixedHyperlinkBase*)GetWindow(); + if ( pBase ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_URL: + { + aProp = makeAny( ::rtl::OUString( pBase->GetURL() ) ); + break; + } + + default: + { + aProp <<= VCLXWindow::getProperty( PropertyName ); + } + } + } + return aProp; +} + +void VCLXFixedHyperlink::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + PushPropertyIds( rIds, + BASEPROPERTY_ALIGN, + BASEPROPERTY_BACKGROUNDCOLOR, + BASEPROPERTY_BORDER, + BASEPROPERTY_BORDERCOLOR, + BASEPROPERTY_DEFAULTCONTROL, + BASEPROPERTY_ENABLED, + BASEPROPERTY_ENABLEVISIBLE, + BASEPROPERTY_FONTDESCRIPTOR, + BASEPROPERTY_HELPTEXT, + BASEPROPERTY_HELPURL, + BASEPROPERTY_LABEL, + BASEPROPERTY_MULTILINE, + BASEPROPERTY_NOLABEL, + BASEPROPERTY_PRINTABLE, + BASEPROPERTY_TABSTOP, + BASEPROPERTY_VERTICALALIGN, + BASEPROPERTY_URL, + BASEPROPERTY_WRITING_MODE, + BASEPROPERTY_CONTEXT_WRITING_MODE, + 0); + VCLXWindow::ImplGetPropertyIds( rIds ); +} + +// ---------------------------------------------------- +// class VCLXFixedText +// ---------------------------------------------------- +void VCLXFixedText::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + PushPropertyIds( rIds, + BASEPROPERTY_ALIGN, + BASEPROPERTY_BACKGROUNDCOLOR, + BASEPROPERTY_BORDER, + BASEPROPERTY_BORDERCOLOR, + BASEPROPERTY_DEFAULTCONTROL, + BASEPROPERTY_ENABLED, + BASEPROPERTY_ENABLEVISIBLE, + BASEPROPERTY_FONTDESCRIPTOR, + BASEPROPERTY_HELPTEXT, + BASEPROPERTY_HELPURL, + BASEPROPERTY_LABEL, + BASEPROPERTY_MULTILINE, + BASEPROPERTY_NOLABEL, + BASEPROPERTY_PRINTABLE, + BASEPROPERTY_TABSTOP, + BASEPROPERTY_VERTICALALIGN, + BASEPROPERTY_WRITING_MODE, + BASEPROPERTY_CONTEXT_WRITING_MODE, + BASEPROPERTY_REFERENCE_DEVICE, + 0); + VCLXWindow::ImplGetPropertyIds( rIds ); +} + +VCLXFixedText::VCLXFixedText() +{ +} + +VCLXFixedText::~VCLXFixedText() +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXFixedText::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XFixedText*, this ) ); + return (aRet.hasValue() ? aRet : VCLXWindow::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXFixedText ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFixedText>* ) NULL ), + VCLXWindow::getTypes() +IMPL_XTYPEPROVIDER_END + +::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > VCLXFixedText::CreateAccessibleContext() +{ + return getAccessibleFactory().createAccessibleContext( this ); +} + +void VCLXFixedText::setText( const ::rtl::OUString& Text ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if ( pWindow ) + pWindow->SetText( Text ); +} + +::rtl::OUString VCLXFixedText::getText() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::rtl::OUString aText; + Window* pWindow = GetWindow(); + if ( pWindow ) + aText = pWindow->GetText(); + return aText; +} + +void VCLXFixedText::setAlignment( short nAlign ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if ( pWindow ) + { + WinBits nNewBits = 0; + if ( nAlign == ::com::sun::star::awt::TextAlign::LEFT ) + nNewBits = WB_LEFT; + else if ( nAlign == ::com::sun::star::awt::TextAlign::CENTER ) + nNewBits = WB_CENTER; + else + nNewBits = WB_RIGHT; + + WinBits nStyle = pWindow->GetStyle(); + nStyle &= ~(WB_LEFT|WB_CENTER|WB_RIGHT); + pWindow->SetStyle( nStyle | nNewBits ); + } +} + +short VCLXFixedText::getAlignment() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + short nAlign = 0; + Window* pWindow = GetWindow(); + if ( pWindow ) + { + WinBits nStyle = pWindow->GetStyle(); + if ( nStyle & WB_LEFT ) + nAlign = ::com::sun::star::awt::TextAlign::LEFT; + else if ( nStyle & WB_CENTER ) + nAlign = ::com::sun::star::awt::TextAlign::CENTER; + else + nAlign = ::com::sun::star::awt::TextAlign::RIGHT; + } + return nAlign; +} + +::com::sun::star::awt::Size VCLXFixedText::getMinimumSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Size aSz; + FixedText* pFixedText = (FixedText*)GetWindow(); + if ( pFixedText ) + aSz = pFixedText->CalcMinimumSize(); + return AWTSize(aSz); +} + +::com::sun::star::awt::Size VCLXFixedText::getPreferredSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + return getMinimumSize(); +} + +::com::sun::star::awt::Size VCLXFixedText::calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::awt::Size aSz = rNewSize; + ::com::sun::star::awt::Size aMinSz = getMinimumSize(); + if ( aSz.Height != aMinSz.Height ) + aSz.Height = aMinSz.Height; + + return aSz; +} + +// ---------------------------------------------------- +// class VCLXScrollBar +// ---------------------------------------------------- +void VCLXScrollBar::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + PushPropertyIds( rIds, + BASEPROPERTY_BACKGROUNDCOLOR, + BASEPROPERTY_BLOCKINCREMENT, + BASEPROPERTY_BORDER, + BASEPROPERTY_BORDERCOLOR, + BASEPROPERTY_DEFAULTCONTROL, + BASEPROPERTY_ENABLED, + BASEPROPERTY_ENABLEVISIBLE, + BASEPROPERTY_HELPTEXT, + BASEPROPERTY_HELPURL, + BASEPROPERTY_LINEINCREMENT, + BASEPROPERTY_LIVE_SCROLL, + BASEPROPERTY_ORIENTATION, + BASEPROPERTY_PRINTABLE, + BASEPROPERTY_REPEAT_DELAY, + BASEPROPERTY_SCROLLVALUE, + BASEPROPERTY_SCROLLVALUE_MAX, + BASEPROPERTY_SCROLLVALUE_MIN, + BASEPROPERTY_SYMBOL_COLOR, + BASEPROPERTY_TABSTOP, + BASEPROPERTY_VISIBLESIZE, + BASEPROPERTY_WRITING_MODE, + BASEPROPERTY_CONTEXT_WRITING_MODE, + 0); + VCLXWindow::ImplGetPropertyIds( rIds ); +} + +VCLXScrollBar::VCLXScrollBar() : maAdjustmentListeners( *this ) +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXScrollBar::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XScrollBar*, this ) ); + return (aRet.hasValue() ? aRet : VCLXWindow::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXScrollBar ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XScrollBar>* ) NULL ), + VCLXWindow::getTypes() +IMPL_XTYPEPROVIDER_END + +::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > VCLXScrollBar::CreateAccessibleContext() +{ + return getAccessibleFactory().createAccessibleContext( this ); +} + +// ::com::sun::star::lang::XComponent +void VCLXScrollBar::dispose() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::lang::EventObject aObj; + aObj.Source = (::cppu::OWeakObject*)this; + maAdjustmentListeners.disposeAndClear( aObj ); + VCLXWindow::dispose(); +} + +// ::com::sun::star::awt::XScrollbar +void VCLXScrollBar::addAdjustmentListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XAdjustmentListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maAdjustmentListeners.addInterface( l ); +} + +void VCLXScrollBar::removeAdjustmentListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XAdjustmentListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maAdjustmentListeners.removeInterface( l ); +} + +void VCLXScrollBar::setValue( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ScrollBar* pScrollBar = (ScrollBar*) GetWindow(); + if ( pScrollBar ) + pScrollBar->DoScroll( n ); +} + +void VCLXScrollBar::setValues( sal_Int32 nValue, sal_Int32 nVisible, sal_Int32 nMax ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ScrollBar* pScrollBar = (ScrollBar*) GetWindow(); + if ( pScrollBar ) + { + pScrollBar->SetVisibleSize( nVisible ); + pScrollBar->SetRangeMax( nMax ); + pScrollBar->DoScroll( nValue ); + } +} + +sal_Int32 VCLXScrollBar::getValue() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ScrollBar* pScrollBar = (ScrollBar*) GetWindow(); + return pScrollBar ? pScrollBar->GetThumbPos() : 0; +} + +void VCLXScrollBar::setMaximum( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ScrollBar* pScrollBar = (ScrollBar*) GetWindow(); + if ( pScrollBar ) + pScrollBar->SetRangeMax( n ); +} + +sal_Int32 VCLXScrollBar::getMaximum() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ScrollBar* pScrollBar = (ScrollBar*) GetWindow(); + return pScrollBar ? pScrollBar->GetRangeMax() : 0; +} + +void VCLXScrollBar::setMinimum( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ScrollBar* pScrollBar = static_cast< ScrollBar* >( GetWindow() ); + if ( pScrollBar ) + pScrollBar->SetRangeMin( n ); +} + +sal_Int32 VCLXScrollBar::getMinimum() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ScrollBar* pScrollBar = static_cast< ScrollBar* >( GetWindow() ); + return pScrollBar ? pScrollBar->GetRangeMin() : 0; +} + +void VCLXScrollBar::setLineIncrement( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ScrollBar* pScrollBar = (ScrollBar*) GetWindow(); + if ( pScrollBar ) + pScrollBar->SetLineSize( n ); +} + +sal_Int32 VCLXScrollBar::getLineIncrement() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ScrollBar* pScrollBar = (ScrollBar*) GetWindow(); + return pScrollBar ? pScrollBar->GetLineSize() : 0; +} + +void VCLXScrollBar::setBlockIncrement( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ScrollBar* pScrollBar = (ScrollBar*) GetWindow(); + if ( pScrollBar ) + pScrollBar->SetPageSize( n ); +} + +sal_Int32 VCLXScrollBar::getBlockIncrement() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ScrollBar* pScrollBar = (ScrollBar*) GetWindow(); + return pScrollBar ? pScrollBar->GetPageSize() : 0; +} + +void VCLXScrollBar::setVisibleSize( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ScrollBar* pScrollBar = (ScrollBar*) GetWindow(); + if ( pScrollBar ) + pScrollBar->SetVisibleSize( n ); +} + +sal_Int32 VCLXScrollBar::getVisibleSize() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ScrollBar* pScrollBar = (ScrollBar*) GetWindow(); + return pScrollBar ? pScrollBar->GetVisibleSize() : 0; +} + +void VCLXScrollBar::setOrientation( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Window* pWindow = GetWindow(); + if ( pWindow ) + { + WinBits nStyle = pWindow->GetStyle(); + nStyle &= ~(WB_HORZ|WB_VERT); + if ( n == ::com::sun::star::awt::ScrollBarOrientation::HORIZONTAL ) + nStyle |= WB_HORZ; + else + nStyle |= WB_VERT; + + pWindow->SetStyle( nStyle ); + pWindow->Resize(); + } +} + +sal_Int32 VCLXScrollBar::getOrientation() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + sal_Int32 n = 0; + Window* pWindow = GetWindow(); + if ( pWindow ) + { + WinBits nStyle = pWindow->GetStyle(); + if ( nStyle & WB_HORZ ) + n = ::com::sun::star::awt::ScrollBarOrientation::HORIZONTAL; + else + n = ::com::sun::star::awt::ScrollBarOrientation::VERTICAL; + } + return n; + +} + +// ::com::sun::star::awt::VclWindowPeer +void VCLXScrollBar::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ScrollBar* pScrollBar = (ScrollBar*)GetWindow(); + if ( pScrollBar ) + { + sal_Bool bVoid = Value.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID; + + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_LIVE_SCROLL: + { + sal_Bool bDo = sal_False; + if ( !bVoid ) + { + OSL_VERIFY( Value >>= bDo ); + } + AllSettings aSettings( pScrollBar->GetSettings() ); + StyleSettings aStyle( aSettings.GetStyleSettings() ); + ULONG nDragOptions = aStyle.GetDragFullOptions(); + if ( bDo ) + nDragOptions |= DRAGFULL_OPTION_SCROLL; + else + nDragOptions &= ~DRAGFULL_OPTION_SCROLL; + aStyle.SetDragFullOptions( nDragOptions ); + aSettings.SetStyleSettings( aStyle ); + pScrollBar->SetSettings( aSettings ); + } + break; + + case BASEPROPERTY_SCROLLVALUE: + { + if ( !bVoid ) + { + sal_Int32 n = 0; + if ( Value >>= n ) + setValue( n ); + } + } + break; + case BASEPROPERTY_SCROLLVALUE_MAX: + case BASEPROPERTY_SCROLLVALUE_MIN: + { + if ( !bVoid ) + { + sal_Int32 n = 0; + if ( Value >>= n ) + { + if ( nPropType == BASEPROPERTY_SCROLLVALUE_MAX ) + setMaximum( n ); + else + setMinimum( n ); + } + } + } + break; + case BASEPROPERTY_LINEINCREMENT: + { + if ( !bVoid ) + { + sal_Int32 n = 0; + if ( Value >>= n ) + setLineIncrement( n ); + } + } + break; + case BASEPROPERTY_BLOCKINCREMENT: + { + if ( !bVoid ) + { + sal_Int32 n = 0; + if ( Value >>= n ) + setBlockIncrement( n ); + } + } + break; + case BASEPROPERTY_VISIBLESIZE: + { + if ( !bVoid ) + { + sal_Int32 n = 0; + if ( Value >>= n ) + setVisibleSize( n ); + } + } + break; + case BASEPROPERTY_ORIENTATION: + { + if ( !bVoid ) + { + sal_Int32 n = 0; + if ( Value >>= n ) + setOrientation( n ); + } + } + break; + + case BASEPROPERTY_BACKGROUNDCOLOR: + { + // the default implementation of the base class doesn't work here, since our + // interpretation for this property is slightly different + ::toolkit::setButtonLikeFaceColor( pScrollBar, Value); + } + break; + + default: + { + VCLXWindow::setProperty( PropertyName, Value ); + } + } + } +} + +::com::sun::star::uno::Any VCLXScrollBar::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Any aProp; + ScrollBar* pScrollBar = (ScrollBar*)GetWindow(); + if ( pScrollBar ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + + switch ( nPropType ) + { + case BASEPROPERTY_LIVE_SCROLL: + { + aProp <<= (sal_Bool)( 0 != ( pScrollBar->GetSettings().GetStyleSettings().GetDragFullOptions() & DRAGFULL_OPTION_SCROLL ) ); + } + break; + case BASEPROPERTY_SCROLLVALUE: + { + aProp <<= (sal_Int32) getValue(); + } + break; + case BASEPROPERTY_SCROLLVALUE_MAX: + { + aProp <<= (sal_Int32) getMaximum(); + } + break; + case BASEPROPERTY_SCROLLVALUE_MIN: + { + aProp <<= (sal_Int32) getMinimum(); + } + break; + case BASEPROPERTY_LINEINCREMENT: + { + aProp <<= (sal_Int32) getLineIncrement(); + } + break; + case BASEPROPERTY_BLOCKINCREMENT: + { + aProp <<= (sal_Int32) getBlockIncrement(); + } + break; + case BASEPROPERTY_VISIBLESIZE: + { + aProp <<= (sal_Int32) getVisibleSize(); + } + break; + case BASEPROPERTY_ORIENTATION: + { + aProp <<= (sal_Int32) getOrientation(); + } + break; + case BASEPROPERTY_BACKGROUNDCOLOR: + { + // the default implementation of the base class doesn't work here, since our + // interpretation for this property is slightly different + aProp = ::toolkit::getButtonLikeFaceColor( pScrollBar ); + } + break; + + default: + { + aProp <<= VCLXWindow::getProperty( PropertyName ); + } + } + } + return aProp; +} + +void VCLXScrollBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) +{ + switch ( rVclWindowEvent.GetId() ) + { + case VCLEVENT_SCROLLBAR_SCROLL: + { + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xKeepAlive( this ); + // since we call listeners below, there is a potential that we will be destroyed + // in during the listener call. To prevent the resulting crashs, we keep us + // alive as long as we're here + // #20178# - 2003-10-01 - fs@openoffice.org + + if ( maAdjustmentListeners.getLength() ) + { + ScrollBar* pScrollBar = (ScrollBar*)GetWindow(); + + if( pScrollBar ) + { + ::com::sun::star::awt::AdjustmentEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.Value = pScrollBar->GetThumbPos(); + + // set adjustment type + ScrollType aType = pScrollBar->GetType(); + if ( aType == SCROLL_LINEUP || aType == SCROLL_LINEDOWN ) + { + aEvent.Type = ::com::sun::star::awt::AdjustmentType_ADJUST_LINE; + } + else if ( aType == SCROLL_PAGEUP || aType == SCROLL_PAGEDOWN ) + { + aEvent.Type = ::com::sun::star::awt::AdjustmentType_ADJUST_PAGE; + } + else if ( aType == SCROLL_DRAG ) + { + aEvent.Type = ::com::sun::star::awt::AdjustmentType_ADJUST_ABS; + } + + maAdjustmentListeners.adjustmentValueChanged( aEvent ); + } + } + } + break; + + default: + VCLXWindow::ProcessWindowEvent( rVclWindowEvent ); + break; + } +} + +::com::sun::star::awt::Size SAL_CALL VCLXScrollBar::implGetMinimumSize( Window* p ) throw(::com::sun::star::uno::RuntimeException) +{ + long n = p->GetSettings().GetStyleSettings().GetScrollBarSize(); + return ::com::sun::star::awt::Size( n, n ); +} + +::com::sun::star::awt::Size SAL_CALL VCLXScrollBar::getMinimumSize() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + return implGetMinimumSize( GetWindow() ); +} + + +// ---------------------------------------------------- +// class VCLXEdit +// ---------------------------------------------------- + +void VCLXEdit::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + PushPropertyIds( rIds, + BASEPROPERTY_ALIGN, + BASEPROPERTY_BACKGROUNDCOLOR, + BASEPROPERTY_BORDER, + BASEPROPERTY_BORDERCOLOR, + BASEPROPERTY_DEFAULTCONTROL, + BASEPROPERTY_ECHOCHAR, + BASEPROPERTY_ENABLED, + BASEPROPERTY_ENABLEVISIBLE, + BASEPROPERTY_FONTDESCRIPTOR, + BASEPROPERTY_HARDLINEBREAKS, + BASEPROPERTY_HELPTEXT, + BASEPROPERTY_HELPURL, + BASEPROPERTY_HSCROLL, + BASEPROPERTY_LINE_END_FORMAT, + BASEPROPERTY_MAXTEXTLEN, + BASEPROPERTY_MULTILINE, + BASEPROPERTY_PRINTABLE, + BASEPROPERTY_READONLY, + BASEPROPERTY_TABSTOP, + BASEPROPERTY_TEXT, + BASEPROPERTY_VSCROLL, + BASEPROPERTY_HIDEINACTIVESELECTION, + BASEPROPERTY_PAINTTRANSPARENT, + BASEPROPERTY_AUTOHSCROLL, + BASEPROPERTY_AUTOVSCROLL, + BASEPROPERTY_VERTICALALIGN, + BASEPROPERTY_WRITING_MODE, + BASEPROPERTY_CONTEXT_WRITING_MODE, + 0); + VCLXWindow::ImplGetPropertyIds( rIds ); +} + +VCLXEdit::VCLXEdit() : maTextListeners( *this ) +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXEdit::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XTextComponent*, this ), + SAL_STATIC_CAST( ::com::sun::star::awt::XTextEditField*, this ), + SAL_STATIC_CAST( ::com::sun::star::awt::XTextLayoutConstrains*, this ) ); + return (aRet.hasValue() ? aRet : VCLXWindow::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXEdit ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextComponent>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextEditField>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextLayoutConstrains>* ) NULL ), + VCLXWindow::getTypes() +IMPL_XTYPEPROVIDER_END + +::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > VCLXEdit::CreateAccessibleContext() +{ + return getAccessibleFactory().createAccessibleContext( this ); +} + +void VCLXEdit::dispose() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::lang::EventObject aObj; + aObj.Source = (::cppu::OWeakObject*)this; + maTextListeners.disposeAndClear( aObj ); + VCLXWindow::dispose(); +} + +void VCLXEdit::addTextListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + GetTextListeners().addInterface( l ); +} + +void VCLXEdit::removeTextListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + GetTextListeners().removeInterface( l ); +} + +void VCLXEdit::setText( const ::rtl::OUString& aText ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Edit* pEdit = (Edit*)GetWindow(); + if ( pEdit ) + { + pEdit->SetText( aText ); + + // #107218# Call same listeners like VCL would do after user interaction + SetSynthesizingVCLEvent( sal_True ); + pEdit->SetModifyFlag(); + pEdit->Modify(); + SetSynthesizingVCLEvent( sal_False ); + } +} + +void VCLXEdit::insertText( const ::com::sun::star::awt::Selection& rSel, const ::rtl::OUString& aText ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Edit* pEdit = (Edit*)GetWindow(); + if ( pEdit ) + { + pEdit->SetSelection( Selection( rSel.Min, rSel.Max ) ); + pEdit->ReplaceSelected( aText ); + + // #107218# Call same listeners like VCL would do after user interaction + SetSynthesizingVCLEvent( sal_True ); + pEdit->SetModifyFlag(); + pEdit->Modify(); + SetSynthesizingVCLEvent( sal_False ); + } +} + +::rtl::OUString VCLXEdit::getText() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::rtl::OUString aText; + Window* pWindow = GetWindow(); + if ( pWindow ) + aText = pWindow->GetText(); + return aText; +} + +::rtl::OUString VCLXEdit::getSelectedText() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::rtl::OUString aText; + Edit* pEdit = (Edit*) GetWindow(); + if ( pEdit) + aText = pEdit->GetSelected(); + return aText; + +} + +void VCLXEdit::setSelection( const ::com::sun::star::awt::Selection& aSelection ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Edit* pEdit = (Edit*) GetWindow(); + if ( pEdit ) + pEdit->SetSelection( Selection( aSelection.Min, aSelection.Max ) ); +} + +::com::sun::star::awt::Selection VCLXEdit::getSelection() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Selection aSel; + Edit* pEdit = (Edit*) GetWindow(); + if ( pEdit ) + aSel = pEdit->GetSelection(); + return ::com::sun::star::awt::Selection( aSel.Min(), aSel.Max() ); +} + +sal_Bool VCLXEdit::isEditable() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Edit* pEdit = (Edit*) GetWindow(); + return ( pEdit && !pEdit->IsReadOnly() && pEdit->IsEnabled() ) ? sal_True : sal_False; +} + +void VCLXEdit::setEditable( sal_Bool bEditable ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Edit* pEdit = (Edit*) GetWindow(); + if ( pEdit ) + pEdit->SetReadOnly( !bEditable ); +} + + +void VCLXEdit::setMaxTextLen( sal_Int16 nLen ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Edit* pEdit = (Edit*) GetWindow(); + if ( pEdit ) + pEdit->SetMaxTextLen( nLen ); +} + +sal_Int16 VCLXEdit::getMaxTextLen() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Edit* pEdit = (Edit*) GetWindow(); + return pEdit ? pEdit->GetMaxTextLen() : 0; +} + +void VCLXEdit::setEchoChar( sal_Unicode cEcho ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Edit* pEdit = (Edit*) GetWindow(); + if ( pEdit ) + pEdit->SetEchoChar( cEcho ); +} + +void VCLXEdit::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Edit* pEdit = (Edit*)GetWindow(); + if ( pEdit ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_HIDEINACTIVESELECTION: + ::toolkit::adjustBooleanWindowStyle( Value, pEdit, WB_NOHIDESELECTION, sal_True ); + if ( pEdit->GetSubEdit() ) + ::toolkit::adjustBooleanWindowStyle( Value, pEdit->GetSubEdit(), WB_NOHIDESELECTION, sal_True ); + break; + + case BASEPROPERTY_READONLY: + { + sal_Bool b = sal_Bool(); + if ( Value >>= b ) + pEdit->SetReadOnly( b ); + } + break; + case BASEPROPERTY_ECHOCHAR: + { + sal_Int16 n = sal_Int16(); + if ( Value >>= n ) + pEdit->SetEchoChar( n ); + } + break; + case BASEPROPERTY_MAXTEXTLEN: + { + sal_Int16 n = sal_Int16(); + if ( Value >>= n ) + pEdit->SetMaxTextLen( n ); + } + break; + default: + { + VCLXWindow::setProperty( PropertyName, Value ); + } + } + } +} + +::com::sun::star::uno::Any VCLXEdit::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Any aProp; + Edit* pEdit = (Edit*)GetWindow(); + if ( pEdit ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_HIDEINACTIVESELECTION: + aProp <<= (sal_Bool)( ( pEdit->GetStyle() & WB_NOHIDESELECTION ) == 0 ); + break; + case BASEPROPERTY_READONLY: + aProp <<= (sal_Bool) pEdit->IsReadOnly(); + break; + case BASEPROPERTY_ECHOCHAR: + aProp <<= (sal_Int16) pEdit->GetEchoChar(); + break; + case BASEPROPERTY_MAXTEXTLEN: + aProp <<= (sal_Int16) pEdit->GetMaxTextLen(); + break; + default: + { + aProp = VCLXWindow::getProperty( PropertyName ); + } + } + } + return aProp; +} + +::com::sun::star::awt::Size VCLXEdit::getMinimumSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Size aSz; + Edit* pEdit = (Edit*) GetWindow(); + if ( pEdit ) + aSz = pEdit->CalcMinimumSize(); + return AWTSize(aSz); +} + +::com::sun::star::awt::Size VCLXEdit::getPreferredSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Size aSz; + Edit* pEdit = (Edit*) GetWindow(); + if ( pEdit ) + { + aSz = pEdit->CalcMinimumSize(); + aSz.Height() += 4; + } + return AWTSize(aSz); +} + +::com::sun::star::awt::Size VCLXEdit::calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::awt::Size aSz = rNewSize; + ::com::sun::star::awt::Size aMinSz = getMinimumSize(); + if ( aSz.Height != aMinSz.Height ) + aSz.Height = aMinSz.Height; + + return aSz; +} + +::com::sun::star::awt::Size VCLXEdit::getMinimumSize( sal_Int16 nCols, sal_Int16 ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Size aSz; + Edit* pEdit = (Edit*) GetWindow(); + if ( pEdit ) + { + if ( nCols ) + aSz = pEdit->CalcSize( nCols ); + else + aSz = pEdit->CalcMinimumSize(); + } + return AWTSize(aSz); +} + +void VCLXEdit::getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + nLines = 1; + nCols = 0; + Edit* pEdit = (Edit*) GetWindow(); + if ( pEdit ) + nCols = pEdit->GetMaxVisChars(); +} + +void VCLXEdit::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) +{ + switch ( rVclWindowEvent.GetId() ) + { + case VCLEVENT_EDIT_MODIFY: + { + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xKeepAlive( this ); + // since we call listeners below, there is a potential that we will be destroyed + // during the listener call. To prevent the resulting crashs, we keep us + // alive as long as we're here + // #20178# - 2003-10-01 - fs@openoffice.org + + if ( GetTextListeners().getLength() ) + { + ::com::sun::star::awt::TextEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + GetTextListeners().textChanged( aEvent ); + } + } + break; + + default: + VCLXWindow::ProcessWindowEvent( rVclWindowEvent ); + break; + } +} + +// ---------------------------------------------------- +// class VCLXComboBox +// ---------------------------------------------------- + +void VCLXComboBox::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + PushPropertyIds( rIds, + BASEPROPERTY_AUTOCOMPLETE, + BASEPROPERTY_BACKGROUNDCOLOR, + BASEPROPERTY_BORDER, + BASEPROPERTY_BORDERCOLOR, + BASEPROPERTY_DEFAULTCONTROL, + BASEPROPERTY_DROPDOWN, + BASEPROPERTY_ENABLED, + BASEPROPERTY_ENABLEVISIBLE, + BASEPROPERTY_FONTDESCRIPTOR, + BASEPROPERTY_HELPTEXT, + BASEPROPERTY_HELPURL, + BASEPROPERTY_LINECOUNT, + BASEPROPERTY_MAXTEXTLEN, + BASEPROPERTY_PRINTABLE, + BASEPROPERTY_READONLY, + BASEPROPERTY_STRINGITEMLIST, + BASEPROPERTY_TABSTOP, + BASEPROPERTY_TEXT, + BASEPROPERTY_HIDEINACTIVESELECTION, + BASEPROPERTY_ALIGN, + BASEPROPERTY_WRITING_MODE, + BASEPROPERTY_CONTEXT_WRITING_MODE, + BASEPROPERTY_REFERENCE_DEVICE, + BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR, + 0); + // no, don't call VCLXEdit here - it has properties which we do *not* want to have at at combo box + // #i92690# / 2008-08-12 / frank.schoenheit@sun.com + // VCLXEdit::ImplGetPropertyIds( rIds ); + VCLXWindow::ImplGetPropertyIds( rIds ); +} + +VCLXComboBox::VCLXComboBox() + : maActionListeners( *this ), maItemListeners( *this ) +{ +} + +VCLXComboBox::~VCLXComboBox() +{ +#ifndef __SUNPRO_CC + OSL_TRACE ("%s", __FUNCTION__); +#endif +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXComboBox::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XComboBox*, this ) ); + return (aRet.hasValue() ? aRet : VCLXEdit::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXComboBox ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XComboBox>* ) NULL ), + VCLXEdit::getTypes() +IMPL_XTYPEPROVIDER_END + +::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > VCLXComboBox::CreateAccessibleContext() +{ + ::vos::OGuard aGuard( GetMutex() ); + + return getAccessibleFactory().createAccessibleContext( this ); +} + +void VCLXComboBox::dispose() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::lang::EventObject aObj; + aObj.Source = (::cppu::OWeakObject*)this; + maItemListeners.disposeAndClear( aObj ); + maActionListeners.disposeAndClear( aObj ); + VCLXEdit::dispose(); +} + + +void VCLXComboBox::addItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maItemListeners.addInterface( l ); +} + +void VCLXComboBox::removeItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maItemListeners.removeInterface( l ); +} + +void VCLXComboBox::addActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maActionListeners.addInterface( l ); +} + +void VCLXComboBox::removeActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener > & l ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + maActionListeners.removeInterface( l ); +} + +void VCLXComboBox::addItem( const ::rtl::OUString& aItem, sal_Int16 nPos ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ComboBox* pBox = (ComboBox*) GetWindow(); + if ( pBox ) + pBox->InsertEntry( aItem, nPos ); +} + +void VCLXComboBox::addItems( const ::com::sun::star::uno::Sequence< ::rtl::OUString>& aItems, sal_Int16 nPos ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ComboBox* pBox = (ComboBox*) GetWindow(); + if ( pBox ) + { + sal_uInt16 nP = nPos; + for ( sal_uInt16 n = 0; n < aItems.getLength(); n++ ) + { + pBox->InsertEntry( aItems.getConstArray()[n], nP ); + if ( (sal_uInt16)nPos < 0xFFFF ) // Nicht wenn 0xFFFF, weil LIST_APPEND + nP++; + } + } +} + +void VCLXComboBox::removeItems( sal_Int16 nPos, sal_Int16 nCount ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ComboBox* pBox = (ComboBox*) GetWindow(); + if ( pBox ) + { + for ( sal_uInt16 n = nCount; n; ) + pBox->RemoveEntry( nPos + (--n) ); + } +} + +sal_Int16 VCLXComboBox::getItemCount() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ComboBox* pBox = (ComboBox*) GetWindow(); + return pBox ? pBox->GetEntryCount() : 0; +} + +::rtl::OUString VCLXComboBox::getItem( sal_Int16 nPos ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::rtl::OUString aItem; + ComboBox* pBox = (ComboBox*) GetWindow(); + if ( pBox ) + aItem = pBox->GetEntry( nPos ); + return aItem; +} + +::com::sun::star::uno::Sequence< ::rtl::OUString> VCLXComboBox::getItems() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Sequence< ::rtl::OUString> aSeq; + ComboBox* pBox = (ComboBox*) GetWindow(); + if ( pBox ) + { + sal_uInt16 nEntries = pBox->GetEntryCount(); + aSeq = ::com::sun::star::uno::Sequence< ::rtl::OUString>( nEntries ); + for ( sal_uInt16 n = nEntries; n; ) + { + --n; + aSeq.getArray()[n] = pBox->GetEntry( n ); + } + } + return aSeq; +} + +void VCLXComboBox::setDropDownLineCount( sal_Int16 nLines ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ComboBox* pBox = (ComboBox*) GetWindow(); + if ( pBox ) + pBox->SetDropDownLineCount( nLines ); +} + +sal_Int16 VCLXComboBox::getDropDownLineCount() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + sal_Int16 nLines = 0; + ComboBox* pBox = (ComboBox*) GetWindow(); + if ( pBox ) + nLines = pBox->GetDropDownLineCount(); + return nLines; +} + +void VCLXComboBox::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ComboBox* pComboBox = (ComboBox*)GetWindow(); + if ( pComboBox ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_LINECOUNT: + { + sal_Int16 n = sal_Int16(); + if ( Value >>= n ) + pComboBox->SetDropDownLineCount( n ); + } + break; + case BASEPROPERTY_AUTOCOMPLETE: + { + sal_Int16 n = sal_Int16(); + if ( Value >>= n ) + pComboBox->EnableAutocomplete( n != 0 ); + } + break; + case BASEPROPERTY_STRINGITEMLIST: + { + ::com::sun::star::uno::Sequence< ::rtl::OUString> aItems; + if ( Value >>= aItems ) + { + sal_Bool bUpdate = pComboBox->IsUpdateMode(); + pComboBox->SetUpdateMode( sal_False ); + pComboBox->Clear(); + const ::rtl::OUString* pStrings = aItems.getConstArray(); + sal_Int32 nItems = aItems.getLength(); + for ( sal_Int32 n = 0; n < nItems; n++ ) + pComboBox->InsertEntry( pStrings[n], LISTBOX_APPEND ); + pComboBox->SetUpdateMode( bUpdate ); + } + } + break; + default: + { + VCLXEdit::setProperty( PropertyName, Value ); + + // #109385# SetBorderStyle is not virtual + if ( nPropType == BASEPROPERTY_BORDER ) + { + sal_uInt16 nBorder = sal_uInt16(); + if ( (Value >>= nBorder) && nBorder != 0 ) + pComboBox->SetBorderStyle( nBorder ); + } + } + } + } +} + +::com::sun::star::uno::Any VCLXComboBox::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Any aProp; + ComboBox* pComboBox = (ComboBox*)GetWindow(); + if ( pComboBox ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_LINECOUNT: + { + aProp <<= (sal_Int16) pComboBox->GetDropDownLineCount(); + } + break; + case BASEPROPERTY_AUTOCOMPLETE: + { + aProp <<= (sal_Bool) pComboBox->IsAutocompleteEnabled(); + } + break; + case BASEPROPERTY_STRINGITEMLIST: + { + sal_uInt16 nItems = pComboBox->GetEntryCount(); + ::com::sun::star::uno::Sequence< ::rtl::OUString> aSeq( nItems ); + ::rtl::OUString* pStrings = aSeq.getArray(); + for ( sal_uInt16 n = 0; n < nItems; n++ ) + pStrings[n] = pComboBox->GetEntry( n ); + aProp <<= aSeq; + + } + break; + default: + { + aProp <<= VCLXEdit::getProperty( PropertyName ); + } + } + } + return aProp; +} + +void VCLXComboBox::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) +{ + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xKeepAlive( this ); + // since we call listeners below, there is a potential that we will be destroyed + // during the listener call. To prevent the resulting crashs, we keep us + // alive as long as we're here + // #20178# - 2003-10-01 - fs@openoffice.org + + switch ( rVclWindowEvent.GetId() ) + { + case VCLEVENT_COMBOBOX_SELECT: + if ( maItemListeners.getLength() ) + { + ComboBox* pComboBox = (ComboBox*)GetWindow(); + if( pComboBox ) + { + if ( !pComboBox->IsTravelSelect() ) + { + ::com::sun::star::awt::ItemEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; + aEvent.Highlighted = sal_False; + + // Bei Mehrfachselektion 0xFFFF, sonst die ID + aEvent.Selected = pComboBox->GetEntryPos( pComboBox->GetText() ); + + maItemListeners.itemStateChanged( aEvent ); + } + } + } + break; + + case VCLEVENT_COMBOBOX_DOUBLECLICK: + if ( maActionListeners.getLength() ) + { + ::com::sun::star::awt::ActionEvent aEvent; + aEvent.Source = (::cppu::OWeakObject*)this; +// aEvent.ActionCommand = ...; + maActionListeners.actionPerformed( aEvent ); + } + break; + + default: + VCLXEdit::ProcessWindowEvent( rVclWindowEvent ); + break; + } +} + +::com::sun::star::awt::Size VCLXComboBox::getMinimumSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Size aSz; + ComboBox* pComboBox = (ComboBox*) GetWindow(); + if ( pComboBox ) + aSz = pComboBox->CalcMinimumSize(); + return AWTSize(aSz); +} + +::com::sun::star::awt::Size VCLXComboBox::getPreferredSize( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Size aSz; + ComboBox* pComboBox = (ComboBox*) GetWindow(); + if ( pComboBox ) + { + aSz = pComboBox->CalcMinimumSize(); + if ( pComboBox->GetStyle() & WB_DROPDOWN ) + aSz.Height() += 4; + } + return AWTSize(aSz); +} + +::com::sun::star::awt::Size VCLXComboBox::calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Size aSz = VCLSize(rNewSize); + ComboBox* pComboBox = (ComboBox*) GetWindow(); + if ( pComboBox ) + aSz = pComboBox->CalcAdjustedSize( aSz ); + return AWTSize(aSz); +} + +::com::sun::star::awt::Size VCLXComboBox::getMinimumSize( sal_Int16 nCols, sal_Int16 nLines ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + Size aSz; + ComboBox* pComboBox = (ComboBox*) GetWindow(); + if ( pComboBox ) + aSz = pComboBox->CalcSize( nCols, nLines ); + return AWTSize(aSz); +} + +void VCLXComboBox::getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + nCols = nLines = 0; + ComboBox* pComboBox = (ComboBox*) GetWindow(); + if ( pComboBox ) + { + sal_uInt16 nC, nL; + pComboBox->GetMaxVisColumnsAndLines( nC, nL ); + nCols = nC; + nLines = nL; + } +} + +// ---------------------------------------------------- +// class VCLXFormattedSpinField +// ---------------------------------------------------- +void VCLXFormattedSpinField::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + // Interestingly in the UnoControl API this is + // - not derived from XEdit ultimately, (correct ?) - so cut this here ... +// VCLXSpinField::ImplGetPropertyIds( rIds ); + VCLXWindow::ImplGetPropertyIds( rIds ); +} + +VCLXFormattedSpinField::VCLXFormattedSpinField() +{ +} + +VCLXFormattedSpinField::~VCLXFormattedSpinField() +{ +} + +void VCLXFormattedSpinField::setStrictFormat( sal_Bool bStrict ) +{ + ::vos::OGuard aGuard( GetMutex() ); + + FormatterBase* pFormatter = GetFormatter(); + if ( pFormatter ) + pFormatter->SetStrictFormat( bStrict ); +} + +sal_Bool VCLXFormattedSpinField::isStrictFormat() +{ + FormatterBase* pFormatter = GetFormatter(); + return pFormatter ? pFormatter->IsStrictFormat() : sal_False; +} + + +void VCLXFormattedSpinField::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + FormatterBase* pFormatter = GetFormatter(); + if ( pFormatter ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_SPIN: + { + sal_Bool b = sal_Bool(); + if ( Value >>= b ) + { + WinBits nStyle = GetWindow()->GetStyle() | WB_SPIN; + if ( !b ) + nStyle &= ~WB_SPIN; + GetWindow()->SetStyle( nStyle ); + } + } + break; + case BASEPROPERTY_STRICTFORMAT: + { + sal_Bool b = sal_Bool(); + if ( Value >>= b ) + { + pFormatter->SetStrictFormat( b ); + } + } + break; + default: + { + VCLXSpinField::setProperty( PropertyName, Value ); + } + } + } +} + +::com::sun::star::uno::Any VCLXFormattedSpinField::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Any aProp; + FormatterBase* pFormatter = GetFormatter(); + if ( pFormatter ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_TABSTOP: + { + aProp <<= (sal_Bool) ( ( GetWindow()->GetStyle() & WB_SPIN ) ? sal_True : sal_False ); + } + break; + case BASEPROPERTY_STRICTFORMAT: + { + aProp <<= (sal_Bool) pFormatter->IsStrictFormat(); + } + break; + default: + { + aProp <<= VCLXSpinField::getProperty( PropertyName ); + } + } + } + return aProp; +} + + +// ---------------------------------------------------- +// class VCLXDateField +// ---------------------------------------------------- + +void VCLXDateField::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + PushPropertyIds( rIds, + BASEPROPERTY_ALIGN, + BASEPROPERTY_BACKGROUNDCOLOR, + BASEPROPERTY_BORDER, + BASEPROPERTY_BORDERCOLOR, + BASEPROPERTY_DATE, + BASEPROPERTY_DATEMAX, + BASEPROPERTY_DATEMIN, + BASEPROPERTY_DATESHOWCENTURY, + BASEPROPERTY_DEFAULTCONTROL, + BASEPROPERTY_DROPDOWN, + BASEPROPERTY_ENABLED, + BASEPROPERTY_ENABLEVISIBLE, + BASEPROPERTY_EXTDATEFORMAT, + BASEPROPERTY_FONTDESCRIPTOR, + BASEPROPERTY_HELPTEXT, + BASEPROPERTY_HELPURL, + BASEPROPERTY_PRINTABLE, + BASEPROPERTY_READONLY, + BASEPROPERTY_REPEAT, + BASEPROPERTY_REPEAT_DELAY, + BASEPROPERTY_SPIN, + BASEPROPERTY_STRICTFORMAT, + BASEPROPERTY_TABSTOP, + BASEPROPERTY_ENFORCE_FORMAT, + BASEPROPERTY_TEXT, + BASEPROPERTY_HIDEINACTIVESELECTION, + BASEPROPERTY_VERTICALALIGN, + BASEPROPERTY_WRITING_MODE, + BASEPROPERTY_CONTEXT_WRITING_MODE, + BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR, + 0); + VCLXFormattedSpinField::ImplGetPropertyIds( rIds ); +} + +VCLXDateField::VCLXDateField() +{ +} + +VCLXDateField::~VCLXDateField() +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXDateField::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XDateField*, this ) ); + return (aRet.hasValue() ? aRet : VCLXFormattedSpinField::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXDateField ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDateField>* ) NULL ), + VCLXFormattedSpinField::getTypes() +IMPL_XTYPEPROVIDER_END + +void VCLXDateField::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + { + sal_Bool bVoid = Value.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID; + + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_DATE: + { + if ( bVoid ) + { + ((DateField*)GetWindow())->EnableEmptyFieldValue( sal_True ); + ((DateField*)GetWindow())->SetEmptyFieldValue(); + } + else + { + sal_Int32 n = 0; + if ( Value >>= n ) + setDate( n ); + } + } + break; + case BASEPROPERTY_DATEMIN: + { + sal_Int32 n = 0; + if ( Value >>= n ) + setMin( n ); + } + break; + case BASEPROPERTY_DATEMAX: + { + sal_Int32 n = 0; + if ( Value >>= n ) + setMax( n ); + } + break; + case BASEPROPERTY_EXTDATEFORMAT: + { + sal_Int16 n = sal_Int16(); + if ( Value >>= n ) + ((DateField*)GetWindow())->SetExtDateFormat( (ExtDateFieldFormat) n ); + } + break; + case BASEPROPERTY_DATESHOWCENTURY: + { + sal_Bool b = sal_Bool(); + if ( Value >>= b ) + ((DateField*)GetWindow())->SetShowDateCentury( b ); + } + break; + case BASEPROPERTY_ENFORCE_FORMAT: + { + sal_Bool bEnforce( sal_True ); + OSL_VERIFY( Value >>= bEnforce ); + static_cast< DateField* >( GetWindow() )->EnforceValidValue( bEnforce ); + } + break; + default: + { + VCLXFormattedSpinField::setProperty( PropertyName, Value ); + } + } + } +} + +::com::sun::star::uno::Any VCLXDateField::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Any aProp; + FormatterBase* pFormatter = GetFormatter(); + if ( pFormatter ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_DATE: + { + aProp <<= (sal_Int32) getDate(); + } + break; + case BASEPROPERTY_DATEMIN: + { + aProp <<= (sal_Int32) getMin(); + } + break; + case BASEPROPERTY_DATEMAX: + { + aProp <<= (sal_Int32) getMax(); + } + break; + case BASEPROPERTY_DATESHOWCENTURY: + { + aProp <<= ((DateField*)GetWindow())->IsShowDateCentury(); + } + break; + case BASEPROPERTY_ENFORCE_FORMAT: + { + aProp <<= (sal_Bool)static_cast< DateField* >( GetWindow() )->IsEnforceValidValue( ); + } + break; + default: + { + aProp <<= VCLXFormattedSpinField::getProperty( PropertyName ); + } + } + } + return aProp; +} + + +void VCLXDateField::setDate( sal_Int32 nDate ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + DateField* pDateField = (DateField*) GetWindow(); + if ( pDateField ) + { + pDateField->SetDate( nDate ); + + // #107218# Call same listeners like VCL would do after user interaction + SetSynthesizingVCLEvent( sal_True ); + pDateField->SetModifyFlag(); + pDateField->Modify(); + SetSynthesizingVCLEvent( sal_False ); + } +} + +sal_Int32 VCLXDateField::getDate() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + sal_Int32 nDate = 0; + DateField* pDateField = (DateField*) GetWindow(); + if ( pDateField ) + nDate = pDateField->GetDate().GetDate(); + + return nDate; +} + +void VCLXDateField::setMin( sal_Int32 nDate ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + DateField* pDateField = (DateField*) GetWindow(); + if ( pDateField ) + pDateField->SetMin( nDate ); +} + +sal_Int32 VCLXDateField::getMin() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + sal_Int32 nDate = 0; + DateField* pDateField = (DateField*) GetWindow(); + if ( pDateField ) + nDate = pDateField->GetMin().GetDate(); + + return nDate; +} + +void VCLXDateField::setMax( sal_Int32 nDate ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + DateField* pDateField = (DateField*) GetWindow(); + if ( pDateField ) + pDateField->SetMax( nDate ); +} + +sal_Int32 VCLXDateField::getMax() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + sal_Int32 nDate = 0; + DateField* pDateField = (DateField*) GetWindow(); + if ( pDateField ) + nDate = pDateField->GetMax().GetDate(); + + return nDate; +} + +void VCLXDateField::setFirst( sal_Int32 nDate ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + DateField* pDateField = (DateField*) GetWindow(); + if ( pDateField ) + pDateField->SetFirst( nDate ); +} + +sal_Int32 VCLXDateField::getFirst() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + sal_Int32 nDate = 0; + DateField* pDateField = (DateField*) GetWindow(); + if ( pDateField ) + nDate = pDateField->GetFirst().GetDate(); + + return nDate; +} + +void VCLXDateField::setLast( sal_Int32 nDate ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + DateField* pDateField = (DateField*) GetWindow(); + if ( pDateField ) + pDateField->SetLast( nDate ); +} + +sal_Int32 VCLXDateField::getLast() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + sal_Int32 nDate = 0; + DateField* pDateField = (DateField*) GetWindow(); + if ( pDateField ) + nDate = pDateField->GetLast().GetDate(); + + return nDate; +} + +void VCLXDateField::setLongFormat( sal_Bool bLong ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + DateField* pDateField = (DateField*) GetWindow(); + if ( pDateField ) + pDateField->SetLongFormat( bLong ); +} + +sal_Bool VCLXDateField::isLongFormat() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + DateField* pDateField = (DateField*) GetWindow(); + return pDateField ? pDateField->IsLongFormat() : sal_False; +} + +void VCLXDateField::setEmpty() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + DateField* pDateField = (DateField*) GetWindow(); + if ( pDateField ) + { + pDateField->SetEmptyDate(); + + // #107218# Call same listeners like VCL would do after user interaction + SetSynthesizingVCLEvent( sal_True ); + pDateField->SetModifyFlag(); + pDateField->Modify(); + SetSynthesizingVCLEvent( sal_False ); + } +} + +sal_Bool VCLXDateField::isEmpty() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + DateField* pDateField = (DateField*) GetWindow(); + return pDateField ? pDateField->IsEmptyDate() : sal_False; +} + +void VCLXDateField::setStrictFormat( sal_Bool bStrict ) throw(::com::sun::star::uno::RuntimeException) +{ + VCLXFormattedSpinField::setStrictFormat( bStrict ); +} + +sal_Bool VCLXDateField::isStrictFormat() throw(::com::sun::star::uno::RuntimeException) +{ + return VCLXFormattedSpinField::isStrictFormat(); +} + + +// ---------------------------------------------------- +// class VCLXTimeField +// ---------------------------------------------------- + +void VCLXTimeField::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + PushPropertyIds( rIds, + BASEPROPERTY_ALIGN, + BASEPROPERTY_BACKGROUNDCOLOR, + BASEPROPERTY_BORDER, + BASEPROPERTY_BORDERCOLOR, + BASEPROPERTY_DEFAULTCONTROL, + BASEPROPERTY_ENABLED, + BASEPROPERTY_ENABLEVISIBLE, + BASEPROPERTY_EXTTIMEFORMAT, + BASEPROPERTY_FONTDESCRIPTOR, + BASEPROPERTY_HELPTEXT, + BASEPROPERTY_HELPURL, + BASEPROPERTY_PRINTABLE, + BASEPROPERTY_READONLY, + BASEPROPERTY_REPEAT, + BASEPROPERTY_REPEAT_DELAY, + BASEPROPERTY_SPIN, + BASEPROPERTY_STRICTFORMAT, + BASEPROPERTY_TABSTOP, + BASEPROPERTY_TIME, + BASEPROPERTY_TIMEMAX, + BASEPROPERTY_TIMEMIN, + BASEPROPERTY_ENFORCE_FORMAT, + BASEPROPERTY_TEXT, + BASEPROPERTY_HIDEINACTIVESELECTION, + BASEPROPERTY_VERTICALALIGN, + BASEPROPERTY_WRITING_MODE, + BASEPROPERTY_CONTEXT_WRITING_MODE, + BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR, + 0); + VCLXFormattedSpinField::ImplGetPropertyIds( rIds ); +} + +VCLXTimeField::VCLXTimeField() +{ +} + +VCLXTimeField::~VCLXTimeField() +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXTimeField::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XTimeField*, this ) ); + return (aRet.hasValue() ? aRet : VCLXFormattedSpinField::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXTimeField ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTimeField>* ) NULL ), + VCLXFormattedSpinField::getTypes() +IMPL_XTYPEPROVIDER_END + +void VCLXTimeField::setTime( sal_Int32 nTime ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + TimeField* pTimeField = (TimeField*) GetWindow(); + if ( pTimeField ) + { + pTimeField->SetTime( nTime ); + + // #107218# Call same listeners like VCL would do after user interaction + SetSynthesizingVCLEvent( sal_True ); + pTimeField->SetModifyFlag(); + pTimeField->Modify(); + SetSynthesizingVCLEvent( sal_False ); + } +} + +sal_Int32 VCLXTimeField::getTime() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + sal_Int32 nTime = 0; + TimeField* pTimeField = (TimeField*) GetWindow(); + if ( pTimeField ) + nTime = pTimeField->GetTime().GetTime(); + + return nTime; +} + +void VCLXTimeField::setMin( sal_Int32 nTime ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + TimeField* pTimeField = (TimeField*) GetWindow(); + if ( pTimeField ) + pTimeField->SetMin( nTime ); +} + +sal_Int32 VCLXTimeField::getMin() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + sal_Int32 nTime = 0; + TimeField* pTimeField = (TimeField*) GetWindow(); + if ( pTimeField ) + nTime = pTimeField->GetMin().GetTime(); + + return nTime; +} + +void VCLXTimeField::setMax( sal_Int32 nTime ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + TimeField* pTimeField = (TimeField*) GetWindow(); + if ( pTimeField ) + pTimeField->SetMax( nTime ); +} + +sal_Int32 VCLXTimeField::getMax() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + sal_Int32 nTime = 0; + TimeField* pTimeField = (TimeField*) GetWindow(); + if ( pTimeField ) + nTime = pTimeField->GetMax().GetTime(); + + return nTime; +} + +void VCLXTimeField::setFirst( sal_Int32 nTime ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + TimeField* pTimeField = (TimeField*) GetWindow(); + if ( pTimeField ) + pTimeField->SetFirst( nTime ); +} + +sal_Int32 VCLXTimeField::getFirst() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + sal_Int32 nTime = 0; + TimeField* pTimeField = (TimeField*) GetWindow(); + if ( pTimeField ) + nTime = pTimeField->GetFirst().GetTime(); + + return nTime; +} + +void VCLXTimeField::setLast( sal_Int32 nTime ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + TimeField* pTimeField = (TimeField*) GetWindow(); + if ( pTimeField ) + pTimeField->SetLast( nTime ); +} + +sal_Int32 VCLXTimeField::getLast() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + sal_Int32 nTime = 0; + TimeField* pTimeField = (TimeField*) GetWindow(); + if ( pTimeField ) + nTime = pTimeField->GetLast().GetTime(); + + return nTime; +} + +void VCLXTimeField::setEmpty() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + TimeField* pTimeField = (TimeField*) GetWindow(); + if ( pTimeField ) + pTimeField->SetEmptyTime(); +} + +sal_Bool VCLXTimeField::isEmpty() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + TimeField* pTimeField = (TimeField*) GetWindow(); + return pTimeField ? pTimeField->IsEmptyTime() : sal_False; +} + +void VCLXTimeField::setStrictFormat( sal_Bool bStrict ) throw(::com::sun::star::uno::RuntimeException) +{ + VCLXFormattedSpinField::setStrictFormat( bStrict ); +} + +sal_Bool VCLXTimeField::isStrictFormat() throw(::com::sun::star::uno::RuntimeException) +{ + return VCLXFormattedSpinField::isStrictFormat(); +} + + +void VCLXTimeField::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + { + sal_Bool bVoid = Value.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID; + + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_TIME: + { + if ( bVoid ) + { + ((TimeField*)GetWindow())->EnableEmptyFieldValue( sal_True ); + ((TimeField*)GetWindow())->SetEmptyFieldValue(); + } + else + { + sal_Int32 n = 0; + if ( Value >>= n ) + setTime( n ); + } + } + break; + case BASEPROPERTY_TIMEMIN: + { + sal_Int32 n = 0; + if ( Value >>= n ) + setMin( n ); + } + break; + case BASEPROPERTY_TIMEMAX: + { + sal_Int32 n = 0; + if ( Value >>= n ) + setMax( n ); + } + break; + case BASEPROPERTY_EXTTIMEFORMAT: + { + sal_Int16 n = sal_Int16(); + if ( Value >>= n ) + ((TimeField*)GetWindow())->SetExtFormat( (ExtTimeFieldFormat) n ); + } + break; + case BASEPROPERTY_ENFORCE_FORMAT: + { + sal_Bool bEnforce( sal_True ); + OSL_VERIFY( Value >>= bEnforce ); + static_cast< TimeField* >( GetWindow() )->EnforceValidValue( bEnforce ); + } + break; + default: + { + VCLXFormattedSpinField::setProperty( PropertyName, Value ); + } + } + } +} + +::com::sun::star::uno::Any VCLXTimeField::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Any aProp; + if ( GetWindow() ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_TIME: + { + aProp <<= (sal_Int32) getTime(); + } + break; + case BASEPROPERTY_TIMEMIN: + { + aProp <<= (sal_Int32) getMin(); + } + break; + case BASEPROPERTY_TIMEMAX: + { + aProp <<= (sal_Int32) getMax(); + } + break; + case BASEPROPERTY_ENFORCE_FORMAT: + { + aProp <<= (sal_Bool)static_cast< TimeField* >( GetWindow() )->IsEnforceValidValue( ); + } + break; + default: + { + aProp <<= VCLXFormattedSpinField::getProperty( PropertyName ); + } + } + } + return aProp; +} + +// ---------------------------------------------------- +// class VCLXNumericField +// ---------------------------------------------------- + +void VCLXNumericField::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + PushPropertyIds( rIds, + BASEPROPERTY_ALIGN, + BASEPROPERTY_BACKGROUNDCOLOR, + BASEPROPERTY_BORDER, + BASEPROPERTY_BORDERCOLOR, + BASEPROPERTY_DECIMALACCURACY, + BASEPROPERTY_DEFAULTCONTROL, + BASEPROPERTY_ENABLED, + BASEPROPERTY_ENABLEVISIBLE, + BASEPROPERTY_FONTDESCRIPTOR, + BASEPROPERTY_HELPTEXT, + BASEPROPERTY_HELPURL, + BASEPROPERTY_NUMSHOWTHOUSANDSEP, + BASEPROPERTY_PRINTABLE, + BASEPROPERTY_READONLY, + BASEPROPERTY_REPEAT, + BASEPROPERTY_REPEAT_DELAY, + BASEPROPERTY_SPIN, + BASEPROPERTY_STRICTFORMAT, + BASEPROPERTY_TABSTOP, + BASEPROPERTY_VALUEMAX_DOUBLE, + BASEPROPERTY_VALUEMIN_DOUBLE, + BASEPROPERTY_VALUESTEP_DOUBLE, + BASEPROPERTY_VALUE_DOUBLE, + BASEPROPERTY_ENFORCE_FORMAT, + BASEPROPERTY_HIDEINACTIVESELECTION, + BASEPROPERTY_VERTICALALIGN, + BASEPROPERTY_WRITING_MODE, + BASEPROPERTY_CONTEXT_WRITING_MODE, + BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR, + 0); + VCLXFormattedSpinField::ImplGetPropertyIds( rIds ); +} + +VCLXNumericField::VCLXNumericField() +{ +} + +VCLXNumericField::~VCLXNumericField() +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXNumericField::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XNumericField*, this ) ); + return (aRet.hasValue() ? aRet : VCLXFormattedSpinField::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXNumericField ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XNumericField>* ) NULL ), + VCLXFormattedSpinField::getTypes() +IMPL_XTYPEPROVIDER_END + +void VCLXNumericField::setValue( double Value ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + NumericFormatter* pNumericFormatter = (NumericFormatter*) GetFormatter(); + if ( pNumericFormatter ) + { + // z.B. 105, 2 Digits => 1,05 + // ein float 1,05 muss also eine 105 einstellen... + pNumericFormatter->SetValue( + (long)ImplCalcLongValue( Value, pNumericFormatter->GetDecimalDigits() ) ); + + // #107218# Call same listeners like VCL would do after user interaction + Edit* pEdit = (Edit*)GetWindow(); + if ( pEdit ) + { + SetSynthesizingVCLEvent( sal_True ); + pEdit->SetModifyFlag(); + pEdit->Modify(); + SetSynthesizingVCLEvent( sal_False ); + } + } +} + +double VCLXNumericField::getValue() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + NumericFormatter* pNumericFormatter = (NumericFormatter*) GetFormatter(); + return pNumericFormatter + ? ImplCalcDoubleValue( (double)pNumericFormatter->GetValue(), pNumericFormatter->GetDecimalDigits() ) + : 0; +} + +void VCLXNumericField::setMin( double Value ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + NumericFormatter* pNumericFormatter = (NumericFormatter*) GetFormatter(); + if ( pNumericFormatter ) + pNumericFormatter->SetMin( + (long)ImplCalcLongValue( Value, pNumericFormatter->GetDecimalDigits() ) ); +} + +double VCLXNumericField::getMin() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + NumericFormatter* pNumericFormatter = (NumericFormatter*) GetFormatter(); + return pNumericFormatter + ? ImplCalcDoubleValue( (double)pNumericFormatter->GetMin(), pNumericFormatter->GetDecimalDigits() ) + : 0; +} + +void VCLXNumericField::setMax( double Value ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + NumericFormatter* pNumericFormatter = (NumericFormatter*) GetFormatter(); + if ( pNumericFormatter ) + pNumericFormatter->SetMax( + (long)ImplCalcLongValue( Value, pNumericFormatter->GetDecimalDigits() ) ); +} + +double VCLXNumericField::getMax() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + NumericFormatter* pNumericFormatter = (NumericFormatter*) GetFormatter(); + return pNumericFormatter + ? ImplCalcDoubleValue( (double)pNumericFormatter->GetMax(), pNumericFormatter->GetDecimalDigits() ) + : 0; +} + +void VCLXNumericField::setFirst( double Value ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + NumericField* pNumericField = (NumericField*) GetWindow(); + if ( pNumericField ) + pNumericField->SetFirst( + (long)ImplCalcLongValue( Value, pNumericField->GetDecimalDigits() ) ); +} + +double VCLXNumericField::getFirst() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + NumericField* pNumericField = (NumericField*) GetWindow(); + return pNumericField + ? ImplCalcDoubleValue( (double)pNumericField->GetFirst(), pNumericField->GetDecimalDigits() ) + : 0; +} + +void VCLXNumericField::setLast( double Value ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + NumericField* pNumericField = (NumericField*) GetWindow(); + if ( pNumericField ) + pNumericField->SetLast( + (long)ImplCalcLongValue( Value, pNumericField->GetDecimalDigits() ) ); +} + +double VCLXNumericField::getLast() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + NumericField* pNumericField = (NumericField*) GetWindow(); + return pNumericField + ? ImplCalcDoubleValue( (double)pNumericField->GetLast(), pNumericField->GetDecimalDigits() ) + : 0; +} + +void VCLXNumericField::setStrictFormat( sal_Bool bStrict ) throw(::com::sun::star::uno::RuntimeException) +{ + VCLXFormattedSpinField::setStrictFormat( bStrict ); +} + +sal_Bool VCLXNumericField::isStrictFormat() throw(::com::sun::star::uno::RuntimeException) +{ + return VCLXFormattedSpinField::isStrictFormat(); +} + + +void VCLXNumericField::setSpinSize( double Value ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + NumericField* pNumericField = (NumericField*) GetWindow(); + if ( pNumericField ) + pNumericField->SetSpinSize( + (long)ImplCalcLongValue( Value, pNumericField->GetDecimalDigits() ) ); +} + +double VCLXNumericField::getSpinSize() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + NumericField* pNumericField = (NumericField*) GetWindow(); + return pNumericField + ? ImplCalcDoubleValue( (double)pNumericField->GetSpinSize(), pNumericField->GetDecimalDigits() ) + : 0; +} + +void VCLXNumericField::setDecimalDigits( sal_Int16 Value ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + NumericFormatter* pNumericFormatter = (NumericFormatter*) GetFormatter(); + if ( pNumericFormatter ) + { + double n = getValue(); + pNumericFormatter->SetDecimalDigits( Value ); + setValue( n ); + } +} + +sal_Int16 VCLXNumericField::getDecimalDigits() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + NumericFormatter* pNumericFormatter = (NumericFormatter*) GetFormatter(); + return pNumericFormatter ? pNumericFormatter->GetDecimalDigits() : 0; +} + +void VCLXNumericField::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + { + sal_Bool bVoid = Value.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID; + + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_VALUE_DOUBLE: + { + if ( bVoid ) + { + ((NumericField*)GetWindow())->EnableEmptyFieldValue( sal_True ); + ((NumericField*)GetWindow())->SetEmptyFieldValue(); + } + else + { + double d = 0; + if ( Value >>= d ) + setValue( d ); + } + } + break; + case BASEPROPERTY_VALUEMIN_DOUBLE: + { + double d = 0; + if ( Value >>= d ) + setMin( d ); + } + break; + case BASEPROPERTY_VALUEMAX_DOUBLE: + { + double d = 0; + if ( Value >>= d ) + setMax( d ); + } + break; + case BASEPROPERTY_VALUESTEP_DOUBLE: + { + double d = 0; + if ( Value >>= d ) + setSpinSize( d ); + } + break; + case BASEPROPERTY_DECIMALACCURACY: + { + sal_Int16 n = sal_Int16(); + if ( Value >>= n ) + setDecimalDigits( n ); + } + break; + case BASEPROPERTY_NUMSHOWTHOUSANDSEP: + { + sal_Bool b = sal_Bool(); + if ( Value >>= b ) + ((NumericField*)GetWindow())->SetUseThousandSep( b ); + } + break; + default: + { + VCLXFormattedSpinField::setProperty( PropertyName, Value ); + } + } + } +} + +::com::sun::star::uno::Any VCLXNumericField::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Any aProp; + FormatterBase* pFormatter = GetFormatter(); + if ( pFormatter ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_VALUE_DOUBLE: + { + aProp <<= (double) getValue(); + } + break; + case BASEPROPERTY_VALUEMIN_DOUBLE: + { + aProp <<= (double) getMin(); + } + break; + case BASEPROPERTY_VALUEMAX_DOUBLE: + { + aProp <<= (double) getMax(); + } + break; + case BASEPROPERTY_VALUESTEP_DOUBLE: + { + aProp <<= (double) getSpinSize(); + } + break; + case BASEPROPERTY_NUMSHOWTHOUSANDSEP: + { + aProp <<= (sal_Bool) ((NumericField*)GetWindow())->IsUseThousandSep(); + } + break; + default: + { + aProp <<= VCLXFormattedSpinField::getProperty( PropertyName ); + } + } + } + return aProp; +} + + +// ---------------------------------------------------- +// class VCLXMetricField +// ---------------------------------------------------- + +void VCLXMetricField::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + PushPropertyIds( rIds, + BASEPROPERTY_ALIGN, + BASEPROPERTY_BACKGROUNDCOLOR, + BASEPROPERTY_BORDER, + BASEPROPERTY_BORDERCOLOR, + BASEPROPERTY_DECIMALACCURACY, + BASEPROPERTY_DEFAULTCONTROL, + BASEPROPERTY_ENABLED, + BASEPROPERTY_ENABLEVISIBLE, + BASEPROPERTY_FONTDESCRIPTOR, + BASEPROPERTY_HELPTEXT, + BASEPROPERTY_HELPURL, + BASEPROPERTY_NUMSHOWTHOUSANDSEP, + BASEPROPERTY_PRINTABLE, + BASEPROPERTY_READONLY, + BASEPROPERTY_REPEAT, + BASEPROPERTY_REPEAT_DELAY, + BASEPROPERTY_SPIN, + BASEPROPERTY_STRICTFORMAT, + BASEPROPERTY_TABSTOP, + BASEPROPERTY_ENFORCE_FORMAT, + BASEPROPERTY_HIDEINACTIVESELECTION, + BASEPROPERTY_UNIT, + BASEPROPERTY_CUSTOMUNITTEXT, + BASEPROPERTY_WRITING_MODE, + BASEPROPERTY_CONTEXT_WRITING_MODE, + BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR, + 0); + VCLXFormattedSpinField::ImplGetPropertyIds( rIds ); +} + +VCLXMetricField::VCLXMetricField() +{ +} + +VCLXMetricField::~VCLXMetricField() +{ +} + +MetricFormatter *VCLXMetricField::GetMetricFormatter() throw(::com::sun::star::uno::RuntimeException) +{ + MetricFormatter *pFormatter = (MetricFormatter *) GetFormatter(); + if (!pFormatter) + throw ::com::sun::star::uno::RuntimeException(); + return pFormatter; +} + +MetricField *VCLXMetricField::GetMetricField() throw(::com::sun::star::uno::RuntimeException) +{ + MetricField *pField = (MetricField *) GetWindow(); + if (!pField) + throw ::com::sun::star::uno::RuntimeException(); + return pField; +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXMetricField::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XMetricField*, this ) ); + return (aRet.hasValue() ? aRet : VCLXFormattedSpinField::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXMetricField ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMetricField>* ) NULL ), + VCLXFormattedSpinField::getTypes() +IMPL_XTYPEPROVIDER_END + +// FIXME: later ... +#define MetricUnitUnoToVcl(a) ((FieldUnit)(a)) + +#define METRIC_MAP_PAIR(method,parent) \ + sal_Int64 VCLXMetricField::get##method( sal_Int16 nUnit ) throw (::com::sun::star::uno::RuntimeException) \ + { \ + ::vos::OGuard aGuard( GetMutex() ); \ + return GetMetric##parent()->Get##method( MetricUnitUnoToVcl( nUnit ) ); \ + } \ + void VCLXMetricField::set##method( sal_Int64 nValue, sal_Int16 nUnit ) throw (::com::sun::star::uno::RuntimeException) \ + { \ + ::vos::OGuard aGuard( GetMutex() ); \ + GetMetric##parent()->Set##method( nValue, MetricUnitUnoToVcl( nUnit ) ); \ + } + +METRIC_MAP_PAIR(Min, Formatter) +METRIC_MAP_PAIR(Max, Formatter) +METRIC_MAP_PAIR(First, Field) +METRIC_MAP_PAIR(Last, Field) + +#undef METRIC_MAP_PAIR + +::sal_Int64 VCLXMetricField::getValue( ::sal_Int16 nUnit ) throw (::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + return GetMetricFormatter()->GetValue( MetricUnitUnoToVcl( nUnit ) ); +} + +::sal_Int64 VCLXMetricField::getCorrectedValue( ::sal_Int16 nUnit ) throw (::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + return GetMetricFormatter()->GetCorrectedValue( MetricUnitUnoToVcl( nUnit ) ); +} + +// FIXME: acute cut/paste evilness - move this to the parent Edit class ? +void VCLXMetricField::CallListeners() +{ + // #107218# Call same listeners like VCL would do after user interaction + Edit* pEdit = (Edit*)GetWindow(); + if ( pEdit ) + { + SetSynthesizingVCLEvent( sal_True ); + pEdit->SetModifyFlag(); + pEdit->Modify(); + SetSynthesizingVCLEvent( sal_False ); + } +} + +void VCLXMetricField::setValue( ::sal_Int64 Value, ::sal_Int16 Unit ) throw (::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + GetMetricFormatter()->SetValue( Value, MetricUnitUnoToVcl( Unit ) ); + CallListeners(); +} + +void VCLXMetricField::setUserValue( ::sal_Int64 Value, ::sal_Int16 Unit ) throw (::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + GetMetricFormatter()->SetUserValue( Value, MetricUnitUnoToVcl( Unit ) ); + CallListeners(); +} + +void VCLXMetricField::setStrictFormat( sal_Bool bStrict ) throw(::com::sun::star::uno::RuntimeException) +{ + VCLXFormattedSpinField::setStrictFormat( bStrict ); +} + +sal_Bool VCLXMetricField::isStrictFormat() throw(::com::sun::star::uno::RuntimeException) +{ + return VCLXFormattedSpinField::isStrictFormat(); +} + +void VCLXMetricField::setSpinSize( sal_Int64 Value ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + GetMetricField()->SetSpinSize( Value ); +} + +sal_Int64 VCLXMetricField::getSpinSize() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + return GetMetricField()->GetSpinSize(); +} + +void VCLXMetricField::setDecimalDigits( sal_Int16 Value ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + GetMetricFormatter()->SetDecimalDigits( Value ); +} + +sal_Int16 VCLXMetricField::getDecimalDigits() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + NumericFormatter* pNumericFormatter = (NumericFormatter*) GetFormatter(); + return pNumericFormatter ? pNumericFormatter->GetDecimalDigits() : 0; +} + +void VCLXMetricField::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_DECIMALACCURACY: + { + sal_Int16 n = 0; + if ( Value >>= n ) + setDecimalDigits( n ); + break; + } + case BASEPROPERTY_NUMSHOWTHOUSANDSEP: + { + sal_Bool b = sal_False; + if ( Value >>= b ) + ((NumericField*)GetWindow())->SetUseThousandSep( b ); + } + break; + case BASEPROPERTY_UNIT: + { + sal_uInt16 nVal = 0; + if ( Value >>= nVal ) + ((MetricField*)GetWindow())->SetUnit( (FieldUnit) nVal ); + break; + } + case BASEPROPERTY_CUSTOMUNITTEXT: + { + rtl::OUString aStr; + if ( Value >>= aStr ) + ((MetricField*)GetWindow())->SetCustomUnitText( aStr ); + break; + } + default: + { + VCLXFormattedSpinField::setProperty( PropertyName, Value ); + break; + } + } + } +} + +::com::sun::star::uno::Any VCLXMetricField::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Any aProp; + FormatterBase* pFormatter = GetFormatter(); + if ( pFormatter ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_NUMSHOWTHOUSANDSEP: + aProp <<= (sal_Bool) ((NumericField*)GetWindow())->IsUseThousandSep(); + break; + case BASEPROPERTY_UNIT: + aProp <<= (sal_uInt16) ((MetricField*)GetWindow())->GetUnit(); + break; + case BASEPROPERTY_CUSTOMUNITTEXT: + aProp <<= rtl::OUString (((MetricField*)GetWindow())->GetCustomUnitText()); + break; + default: + { + aProp <<= VCLXFormattedSpinField::getProperty( PropertyName ); + break; + } + } + } + return aProp; +} + + +// ---------------------------------------------------- +// class VCLXCurrencyField +// ---------------------------------------------------- + +void VCLXCurrencyField::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + PushPropertyIds( rIds, + BASEPROPERTY_ALIGN, + BASEPROPERTY_BACKGROUNDCOLOR, + BASEPROPERTY_BORDER, + BASEPROPERTY_BORDERCOLOR, + BASEPROPERTY_CURRENCYSYMBOL, + BASEPROPERTY_CURSYM_POSITION, + BASEPROPERTY_DECIMALACCURACY, + BASEPROPERTY_DEFAULTCONTROL, + BASEPROPERTY_ENABLED, + BASEPROPERTY_ENABLEVISIBLE, + BASEPROPERTY_FONTDESCRIPTOR, + BASEPROPERTY_HELPTEXT, + BASEPROPERTY_HELPURL, + BASEPROPERTY_NUMSHOWTHOUSANDSEP, + BASEPROPERTY_PRINTABLE, + BASEPROPERTY_READONLY, + BASEPROPERTY_REPEAT, + BASEPROPERTY_REPEAT_DELAY, + BASEPROPERTY_SPIN, + BASEPROPERTY_STRICTFORMAT, + BASEPROPERTY_TABSTOP, + BASEPROPERTY_VALUEMAX_DOUBLE, + BASEPROPERTY_VALUEMIN_DOUBLE, + BASEPROPERTY_VALUESTEP_DOUBLE, + BASEPROPERTY_VALUE_DOUBLE, + BASEPROPERTY_ENFORCE_FORMAT, + BASEPROPERTY_HIDEINACTIVESELECTION, + BASEPROPERTY_VERTICALALIGN, + BASEPROPERTY_WRITING_MODE, + BASEPROPERTY_CONTEXT_WRITING_MODE, + BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR, + 0); + VCLXFormattedSpinField::ImplGetPropertyIds( rIds ); +} + +VCLXCurrencyField::VCLXCurrencyField() +{ +} + +VCLXCurrencyField::~VCLXCurrencyField() +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXCurrencyField::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XCurrencyField*, this ) ); + return (aRet.hasValue() ? aRet : VCLXFormattedSpinField::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXCurrencyField ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XCurrencyField>* ) NULL ), + VCLXFormattedSpinField::getTypes() +IMPL_XTYPEPROVIDER_END + +void VCLXCurrencyField::setValue( double Value ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + LongCurrencyFormatter* pCurrencyFormatter = (LongCurrencyFormatter*) GetFormatter(); + if ( pCurrencyFormatter ) + { + // z.B. 105, 2 Digits => 1,05 + // ein float 1,05 muss also eine 105 einstellen... + pCurrencyFormatter->SetValue( + ImplCalcLongValue( Value, pCurrencyFormatter->GetDecimalDigits() ) ); + + // #107218# Call same listeners like VCL would do after user interaction + Edit* pEdit = (Edit*)GetWindow(); + if ( pEdit ) + { + SetSynthesizingVCLEvent( sal_True ); + pEdit->SetModifyFlag(); + pEdit->Modify(); + SetSynthesizingVCLEvent( sal_False ); + } + } +} + +double VCLXCurrencyField::getValue() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + LongCurrencyFormatter* pCurrencyFormatter = (LongCurrencyFormatter*) GetFormatter(); + return pCurrencyFormatter + ? ImplCalcDoubleValue( (double)pCurrencyFormatter->GetValue(), pCurrencyFormatter->GetDecimalDigits() ) + : 0; +} + +void VCLXCurrencyField::setMin( double Value ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + LongCurrencyFormatter* pCurrencyFormatter = (LongCurrencyFormatter*) GetFormatter(); + if ( pCurrencyFormatter ) + pCurrencyFormatter->SetMin( + ImplCalcLongValue( Value, pCurrencyFormatter->GetDecimalDigits() ) ); +} + +double VCLXCurrencyField::getMin() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + LongCurrencyFormatter* pCurrencyFormatter = (LongCurrencyFormatter*) GetFormatter(); + return pCurrencyFormatter + ? ImplCalcDoubleValue( (double)pCurrencyFormatter->GetMin(), pCurrencyFormatter->GetDecimalDigits() ) + : 0; +} + +void VCLXCurrencyField::setMax( double Value ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + LongCurrencyFormatter* pCurrencyFormatter = (LongCurrencyFormatter*) GetFormatter(); + if ( pCurrencyFormatter ) + pCurrencyFormatter->SetMax( + ImplCalcLongValue( Value, pCurrencyFormatter->GetDecimalDigits() ) ); +} + +double VCLXCurrencyField::getMax() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + LongCurrencyFormatter* pCurrencyFormatter = (LongCurrencyFormatter*) GetFormatter(); + return pCurrencyFormatter + ? ImplCalcDoubleValue( (double)pCurrencyFormatter->GetMax(), pCurrencyFormatter->GetDecimalDigits() ) + : 0; +} + +void VCLXCurrencyField::setFirst( double Value ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + LongCurrencyField* pCurrencyField = (LongCurrencyField*) GetWindow(); + if ( pCurrencyField ) + pCurrencyField->SetFirst( + ImplCalcLongValue( Value, pCurrencyField->GetDecimalDigits() ) ); +} + +double VCLXCurrencyField::getFirst() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + LongCurrencyField* pCurrencyField = (LongCurrencyField*) GetWindow(); + return pCurrencyField + ? ImplCalcDoubleValue( (double)pCurrencyField->GetFirst(), pCurrencyField->GetDecimalDigits() ) + : 0; +} + +void VCLXCurrencyField::setLast( double Value ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + LongCurrencyField* pCurrencyField = (LongCurrencyField*) GetWindow(); + if ( pCurrencyField ) + pCurrencyField->SetLast( + ImplCalcLongValue( Value, pCurrencyField->GetDecimalDigits() ) ); +} + +double VCLXCurrencyField::getLast() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + LongCurrencyField* pCurrencyField = (LongCurrencyField*) GetWindow(); + return pCurrencyField + ? ImplCalcDoubleValue( (double)pCurrencyField->GetLast(), pCurrencyField->GetDecimalDigits() ) + : 0; +} + +void VCLXCurrencyField::setSpinSize( double Value ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + LongCurrencyField* pCurrencyField = (LongCurrencyField*) GetWindow(); + if ( pCurrencyField ) + pCurrencyField->SetSpinSize( + ImplCalcLongValue( Value, pCurrencyField->GetDecimalDigits() ) ); +} + +double VCLXCurrencyField::getSpinSize() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + LongCurrencyField* pCurrencyField = (LongCurrencyField*) GetWindow(); + return pCurrencyField + ? ImplCalcDoubleValue( (double)pCurrencyField->GetSpinSize(), pCurrencyField->GetDecimalDigits() ) + : 0; +} + +void VCLXCurrencyField::setStrictFormat( sal_Bool bStrict ) throw(::com::sun::star::uno::RuntimeException) +{ + VCLXFormattedSpinField::setStrictFormat( bStrict ); +} + +sal_Bool VCLXCurrencyField::isStrictFormat() throw(::com::sun::star::uno::RuntimeException) +{ + return VCLXFormattedSpinField::isStrictFormat(); +} + + +void VCLXCurrencyField::setDecimalDigits( sal_Int16 Value ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + LongCurrencyFormatter* pCurrencyFormatter = (LongCurrencyFormatter*) GetFormatter(); + if ( pCurrencyFormatter ) + { + double n = getValue(); + pCurrencyFormatter->SetDecimalDigits( Value ); + setValue( n ); + } +} + +sal_Int16 VCLXCurrencyField::getDecimalDigits() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + LongCurrencyFormatter* pCurrencyFormatter = (LongCurrencyFormatter*) GetFormatter(); + return pCurrencyFormatter ? pCurrencyFormatter->GetDecimalDigits() : 0; +} + +void VCLXCurrencyField::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + { + sal_Bool bVoid = Value.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID; + + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_VALUE_DOUBLE: + { + if ( bVoid ) + { + ((LongCurrencyField*)GetWindow())->EnableEmptyFieldValue( sal_True ); + ((LongCurrencyField*)GetWindow())->SetEmptyFieldValue(); + } + else + { + double d = 0; + if ( Value >>= d ) + setValue( d ); + } + } + break; + case BASEPROPERTY_VALUEMIN_DOUBLE: + { + double d = 0; + if ( Value >>= d ) + setMin( d ); + } + break; + case BASEPROPERTY_VALUEMAX_DOUBLE: + { + double d = 0; + if ( Value >>= d ) + setMax( d ); + } + break; + case BASEPROPERTY_VALUESTEP_DOUBLE: + { + double d = 0; + if ( Value >>= d ) + setSpinSize( d ); + } + break; + case BASEPROPERTY_DECIMALACCURACY: + { + sal_Int16 n = sal_Int16(); + if ( Value >>= n ) + setDecimalDigits( n ); + } + break; + case BASEPROPERTY_CURRENCYSYMBOL: + { + ::rtl::OUString aString; + if ( Value >>= aString ) + ((LongCurrencyField*)GetWindow())->SetCurrencySymbol( aString ); + } + break; + case BASEPROPERTY_NUMSHOWTHOUSANDSEP: + { + sal_Bool b = sal_Bool(); + if ( Value >>= b ) + ((LongCurrencyField*)GetWindow())->SetUseThousandSep( b ); + } + break; + default: + { + VCLXFormattedSpinField::setProperty( PropertyName, Value ); + } + } + } +} + +::com::sun::star::uno::Any VCLXCurrencyField::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Any aProp; + FormatterBase* pFormatter = GetFormatter(); + if ( pFormatter ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_VALUE_DOUBLE: + { + aProp <<= (double) getValue(); + } + break; + case BASEPROPERTY_VALUEMIN_DOUBLE: + { + aProp <<= (double) getMin(); + } + break; + case BASEPROPERTY_VALUEMAX_DOUBLE: + { + aProp <<= (double) getMax(); + } + break; + case BASEPROPERTY_VALUESTEP_DOUBLE: + { + aProp <<= (double) getSpinSize(); + } + break; + case BASEPROPERTY_CURRENCYSYMBOL: + { + aProp <<= ::rtl::OUString( ((LongCurrencyField*)GetWindow())->GetCurrencySymbol() ); + } + break; + case BASEPROPERTY_NUMSHOWTHOUSANDSEP: + { + aProp <<= (sal_Bool) ((LongCurrencyField*)GetWindow())->IsUseThousandSep(); + } + break; + default: + { + aProp <<= VCLXFormattedSpinField::getProperty( PropertyName ); + } + } + } + return aProp; +} + +// ---------------------------------------------------- +// class VCLXPatternField +// ---------------------------------------------------- + +void VCLXPatternField::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) +{ + PushPropertyIds( rIds, + BASEPROPERTY_ALIGN, + BASEPROPERTY_BACKGROUNDCOLOR, + BASEPROPERTY_BORDER, + BASEPROPERTY_BORDERCOLOR, + BASEPROPERTY_DEFAULTCONTROL, + BASEPROPERTY_EDITMASK, + BASEPROPERTY_ENABLED, + BASEPROPERTY_ENABLEVISIBLE, + BASEPROPERTY_FONTDESCRIPTOR, + BASEPROPERTY_HELPTEXT, + BASEPROPERTY_HELPURL, + BASEPROPERTY_LITERALMASK, + BASEPROPERTY_MAXTEXTLEN, + BASEPROPERTY_PRINTABLE, + BASEPROPERTY_READONLY, + BASEPROPERTY_STRICTFORMAT, + BASEPROPERTY_TABSTOP, + BASEPROPERTY_TEXT, + BASEPROPERTY_HIDEINACTIVESELECTION, + BASEPROPERTY_VERTICALALIGN, + BASEPROPERTY_WRITING_MODE, + BASEPROPERTY_CONTEXT_WRITING_MODE, + BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR, + 0); + VCLXFormattedSpinField::ImplGetPropertyIds( rIds ); +} + +VCLXPatternField::VCLXPatternField() +{ +} + +VCLXPatternField::~VCLXPatternField() +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any VCLXPatternField::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XPatternField*, this ) ); + return (aRet.hasValue() ? aRet : VCLXFormattedSpinField::queryInterface( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( VCLXPatternField ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPatternField>* ) NULL ), + VCLXFormattedSpinField::getTypes() +IMPL_XTYPEPROVIDER_END + +void VCLXPatternField::setMasks( const ::rtl::OUString& EditMask, const ::rtl::OUString& LiteralMask ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + PatternField* pPatternField = (PatternField*) GetWindow(); + if ( pPatternField ) + { + pPatternField->SetMask( ByteString( UniString( EditMask ), RTL_TEXTENCODING_ASCII_US ), LiteralMask ); + } +} + +void VCLXPatternField::getMasks( ::rtl::OUString& EditMask, ::rtl::OUString& LiteralMask ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + PatternField* pPatternField = (PatternField*) GetWindow(); + if ( pPatternField ) + { + EditMask = String( pPatternField->GetEditMask(), RTL_TEXTENCODING_ASCII_US ); + LiteralMask = pPatternField->GetLiteralMask(); + } +} + +void VCLXPatternField::setString( const ::rtl::OUString& Str ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + PatternField* pPatternField = (PatternField*) GetWindow(); + if ( pPatternField ) + { + pPatternField->SetString( Str ); + } +} + +::rtl::OUString VCLXPatternField::getString() throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::rtl::OUString aString; + PatternField* pPatternField = (PatternField*) GetWindow(); + if ( pPatternField ) + aString = pPatternField->GetString(); + return aString; +} + +void VCLXPatternField::setStrictFormat( sal_Bool bStrict ) throw(::com::sun::star::uno::RuntimeException) +{ + VCLXFormattedSpinField::setStrictFormat( bStrict ); +} + +sal_Bool VCLXPatternField::isStrictFormat() throw(::com::sun::star::uno::RuntimeException) +{ + return VCLXFormattedSpinField::isStrictFormat(); +} + +void VCLXPatternField::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any& Value) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_EDITMASK: + case BASEPROPERTY_LITERALMASK: + { + ::rtl::OUString aString; + if ( Value >>= aString ) + { + ::rtl::OUString aEditMask, aLiteralMask; + getMasks( aEditMask, aLiteralMask ); + if ( nPropType == BASEPROPERTY_EDITMASK ) + aEditMask = aString; + else + aLiteralMask = aString; + setMasks( aEditMask, aLiteralMask ); + } + } + break; + default: + { + VCLXFormattedSpinField::setProperty( PropertyName, Value ); + } + } + } +} + +::com::sun::star::uno::Any VCLXPatternField::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + ::com::sun::star::uno::Any aProp; + if ( GetWindow() ) + { + sal_uInt16 nPropType = GetPropertyId( PropertyName ); + switch ( nPropType ) + { + case BASEPROPERTY_EDITMASK: + case BASEPROPERTY_LITERALMASK: + { + ::rtl::OUString aEditMask, aLiteralMask; + getMasks( aEditMask, aLiteralMask ); + if ( nPropType == BASEPROPERTY_EDITMASK ) + aProp <<= aEditMask; + else + aProp <<= aLiteralMask; + } + break; + default: + { + aProp <<= VCLXFormattedSpinField::getProperty( PropertyName ); + } + } + } + return aProp; +} + +// ---------------------------------------------------- +// class VCLXToolBox +// ---------------------------------------------------- +VCLXToolBox::VCLXToolBox() +{ +} + +VCLXToolBox::~VCLXToolBox() +{ +} + +::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > VCLXToolBox::CreateAccessibleContext() +{ + return getAccessibleFactory().createAccessibleContext( this ); +} + diff --git a/toolkit/source/awt/xsimpleanimation.cxx b/toolkit/source/awt/xsimpleanimation.cxx new file mode 100644 index 000000000000..c7ccbde118f4 --- /dev/null +++ b/toolkit/source/awt/xsimpleanimation.cxx @@ -0,0 +1,165 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include "toolkit/awt/xsimpleanimation.hxx" +#include "toolkit/helper/property.hxx" +#include "toolkit/helper/throbberimpl.hxx" +#include <tools/debug.hxx> + +//........................................................................ +namespace toolkit +{ +//........................................................................ + + using namespace ::com::sun::star; + + //==================================================================== + //= XSimpleAnimation + //==================================================================== + DBG_NAME( XSimpleAnimation ) + + //-------------------------------------------------------------------- + XSimpleAnimation::XSimpleAnimation() + { + DBG_CTOR( XSimpleAnimation, NULL ); + mbRepeat = sal_True; + mnStepTime = 100; + mpThrobber = new Throbber_Impl( this, mnStepTime, mbRepeat ); + } + + //-------------------------------------------------------------------- + XSimpleAnimation::~XSimpleAnimation() + { + DBG_DTOR( XSimpleAnimation, NULL ); + delete mpThrobber; + } + + //-------------------------------------------------------------------- + IMPLEMENT_FORWARD_XINTERFACE2( XSimpleAnimation, VCLXWindow, XSimpleAnimation_Base ) + + //-------------------------------------------------------------------- + IMPLEMENT_FORWARD_XTYPEPROVIDER2( XSimpleAnimation, VCLXWindow, XSimpleAnimation_Base ) + + //-------------------------------------------------------------------- + void SAL_CALL XSimpleAnimation::start() throw ( uno::RuntimeException ) + { + mpThrobber->start(); + } + + //-------------------------------------------------------------------- + void SAL_CALL XSimpleAnimation::stop() throw ( uno::RuntimeException ) + { + mpThrobber->stop(); + } + + //-------------------------------------------------------------------- + void SAL_CALL XSimpleAnimation::setImageList( const uno::Sequence< uno::Reference< graphic::XGraphic > >& rImageList ) + throw ( uno::RuntimeException ) + { + mpThrobber->setImageList( rImageList ); + } + + //-------------------------------------------------------------------- + void XSimpleAnimation::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ) + { + // TODO: XSimpleAnimation::ProcessWindowEvent + //::vos::OClearableGuard aGuard( GetMutex() ); + //Reference< XSimpleAnimation > xKeepAlive( this ); + //SpinButton* pSpinButton = static_cast< SpinButton* >( GetWindow() ); + //if ( !pSpinButton ) + // return; + + VCLXWindow::ProcessWindowEvent( _rVclWindowEvent ); + } + + //-------------------------------------------------------------------- + void SAL_CALL XSimpleAnimation::setProperty( const ::rtl::OUString& PropertyName, const uno::Any& Value ) + throw( uno::RuntimeException ) + { + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + { + sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); + switch ( nPropertyId ) + { + case BASEPROPERTY_STEP_TIME: { + sal_Int32 nStepTime( 0 ); + if ( Value >>= nStepTime ) + { + mnStepTime = nStepTime; + mpThrobber->setStepTime( mnStepTime ); + } + + break; + } + case BASEPROPERTY_REPEAT: { + sal_Bool bRepeat( sal_True ); + if ( Value >>= bRepeat ) + { + mbRepeat = bRepeat; + mpThrobber->setRepeat( mbRepeat ); + } + break; + } + default: + VCLXWindow::setProperty( PropertyName, Value ); + } + } + } + + //-------------------------------------------------------------------- + uno::Any SAL_CALL XSimpleAnimation::getProperty( const ::rtl::OUString& PropertyName ) + throw( uno::RuntimeException ) + { + ::vos::OGuard aGuard( GetMutex() ); + + uno::Any aReturn; + + if ( GetWindow() ) + { + sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); + switch ( nPropertyId ) + { + case BASEPROPERTY_STEP_TIME: + aReturn <<= mnStepTime; + break; + case BASEPROPERTY_REPEAT: + aReturn <<= mbRepeat; + break; + default: + aReturn = VCLXWindow::getProperty( PropertyName ); + } + } + return aReturn; + } + +//........................................................................ +} // namespace toolkit +//........................................................................ diff --git a/toolkit/source/awt/xthrobber.cxx b/toolkit/source/awt/xthrobber.cxx new file mode 100644 index 000000000000..439fb49c1cbe --- /dev/null +++ b/toolkit/source/awt/xthrobber.cxx @@ -0,0 +1,158 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include "toolkit/awt/xthrobber.hxx" +#include "toolkit/helper/property.hxx" +#include <toolkit/helper/tkresmgr.hxx> +#include <toolkit/helper/throbberimpl.hxx> + +#ifndef _TOOLKIT_AWT_XTHROBBER_HRC_ +#include "xthrobber.hrc" +#endif +#include <tools/debug.hxx> +#include <vcl/fixed.hxx> +#include <vcl/timer.hxx> + +//........................................................................ +namespace toolkit +{ +//........................................................................ + + using namespace ::com::sun::star; + + //==================================================================== + //= XThrobber + //==================================================================== + DBG_NAME( XThrobber ) + + //-------------------------------------------------------------------- + XThrobber::XThrobber() + { + DBG_CTOR( XThrobber, NULL ); + + mpThrobber = new Throbber_Impl( this, 100, sal_True ); + + InitImageList(); + } + + //-------------------------------------------------------------------- + XThrobber::~XThrobber() + { + DBG_DTOR( XThrobber, NULL ); + delete mpThrobber; + } + + //-------------------------------------------------------------------- + IMPLEMENT_FORWARD_XINTERFACE2( XThrobber, VCLXWindow, XThrobber_Base ) + + //-------------------------------------------------------------------- + IMPLEMENT_FORWARD_XTYPEPROVIDER2( XThrobber, VCLXWindow, XThrobber_Base ) + + //-------------------------------------------------------------------- + void SAL_CALL XThrobber::start() throw ( uno::RuntimeException ) + { + mpThrobber->start(); + } + + //-------------------------------------------------------------------- + void SAL_CALL XThrobber::stop() throw ( uno::RuntimeException ) + { + mpThrobber->stop(); + } + + //-------------------------------------------------------------------- + void XThrobber::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ) + { + static bool bInit = false; + if ( !bInit ) + { + // Images won't be shown if set too early + mpThrobber->initImage(); + bInit = true; + } + // TODO: XSimpleAnimation::ProcessWindowEvent + //::vos::OClearableGuard aGuard( GetMutex() ); + //Reference< XSimpleAnimation > xKeepAlive( this ); + //SpinButton* pSpinButton = static_cast< SpinButton* >( GetWindow() ); + //if ( !pSpinButton ) + // return; + + VCLXWindow::ProcessWindowEvent( _rVclWindowEvent ); + } + + //-------------------------------------------------------------------- + void SAL_CALL XThrobber::setProperty( const ::rtl::OUString& PropertyName, const uno::Any& Value ) + throw( uno::RuntimeException ) + { + ::vos::OGuard aGuard( GetMutex() ); + + if ( GetWindow() ) + { + VCLXWindow::setProperty( PropertyName, Value ); + } + } + + //-------------------------------------------------------------------- + uno::Any SAL_CALL XThrobber::getProperty( const ::rtl::OUString& PropertyName ) + throw( uno::RuntimeException ) + { + ::vos::OGuard aGuard( GetMutex() ); + + uno::Any aReturn; + + if ( GetWindow() ) + { + aReturn = VCLXWindow::getProperty( PropertyName ); + } + return aReturn; + } + + //-------------------------------------------------------------------- + void SAL_CALL XThrobber::InitImageList() + throw( uno::RuntimeException ) + { + ::vos::OGuard aGuard( GetMutex() ); + uno::Sequence< uno::Reference< graphic::XGraphic > > aImageList(12); + sal_uInt16 nIconIdStart = RID_TK_ICON_THROBBER_START; + + if ( mpThrobber->isHCMode() ) + nIconIdStart = RID_TK_HC_ICON_THROBBER_START; + + for ( sal_uInt16 i=0; i<12; i++ ) + { + Image aImage = TK_RES_IMAGE( nIconIdStart + i ); + aImageList[i] = aImage.GetXGraphic(); + } + + mpThrobber->setImageList( aImageList ); + } + +//........................................................................ +} // namespace toolkit +//........................................................................ diff --git a/toolkit/source/awt/xthrobber.hrc b/toolkit/source/awt/xthrobber.hrc new file mode 100644 index 000000000000..32c068ff8a85 --- /dev/null +++ b/toolkit/source/awt/xthrobber.hrc @@ -0,0 +1,39 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _TOOLKIT_AWT_XTHROBBER_HRC_ +#define _TOOLKIT_AWT_XTHROBBER_HRC_ + + +//------------------------------------------------------------------------------ + +#define RID_TK_ICON_THROBBER_START 1000 +#define RID_TK_HC_ICON_THROBBER_START 1020 + +// ----------------------------------------------------------------------------- + +#endif // _TOOLKIT_AWT_XTHROBBER_HRC_ diff --git a/toolkit/source/awt/xthrobber.src b/toolkit/source/awt/xthrobber.src new file mode 100644 index 000000000000..199b25015056 --- /dev/null +++ b/toolkit/source/awt/xthrobber.src @@ -0,0 +1,177 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _TOOLKIT_AWT_XTHROBBER_HRC_ +#include <xthrobber.hrc> +#endif + +#define STD_MASK_COLOR MaskColor = Color { Red = 0xFFFF; Green = 0x0000; Blue = 0xFFFF; }; + +Image RID_TK_ICON_THROBBER_START +{ + ImageBitmap = Bitmap{ file = "spinner03-grey_01.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_ICON_THROBBER_START + 1 +{ + ImageBitmap = Bitmap{ file = "spinner03-grey_02.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_ICON_THROBBER_START + 2 +{ + ImageBitmap = Bitmap{ file = "spinner03-grey_03.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_ICON_THROBBER_START + 3 +{ + ImageBitmap = Bitmap{ file = "spinner03-grey_04.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_ICON_THROBBER_START + 4 +{ + ImageBitmap = Bitmap{ file = "spinner03-grey_05.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_ICON_THROBBER_START + 5 +{ + ImageBitmap = Bitmap{ file = "spinner03-grey_06.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_ICON_THROBBER_START + 6 +{ + ImageBitmap = Bitmap{ file = "spinner03-grey_07.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_ICON_THROBBER_START + 7 +{ + ImageBitmap = Bitmap{ file = "spinner03-grey_08.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_ICON_THROBBER_START + 8 +{ + ImageBitmap = Bitmap{ file = "spinner03-grey_09.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_ICON_THROBBER_START + 9 +{ + ImageBitmap = Bitmap{ file = "spinner03-grey_10.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_ICON_THROBBER_START + 10 +{ + ImageBitmap = Bitmap{ file = "spinner03-grey_11.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_ICON_THROBBER_START + 11 +{ + ImageBitmap = Bitmap{ file = "spinner03-grey_12.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_HC_ICON_THROBBER_START +{ + ImageBitmap = Bitmap{ file = "spinner03-32-hc_01.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_HC_ICON_THROBBER_START + 1 +{ + ImageBitmap = Bitmap{ file = "spinner03-32-hc_02.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_HC_ICON_THROBBER_START + 2 +{ + ImageBitmap = Bitmap{ file = "spinner03-32-hc_03.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_HC_ICON_THROBBER_START + 3 +{ + ImageBitmap = Bitmap{ file = "spinner03-32-hc_04.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_HC_ICON_THROBBER_START + 4 +{ + ImageBitmap = Bitmap{ file = "spinner03-32-hc_05.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_HC_ICON_THROBBER_START + 5 +{ + ImageBitmap = Bitmap{ file = "spinner03-32-hc_06.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_HC_ICON_THROBBER_START + 6 +{ + ImageBitmap = Bitmap{ file = "spinner03-32-hc_07.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_HC_ICON_THROBBER_START + 7 +{ + ImageBitmap = Bitmap{ file = "spinner03-32-hc_08.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_HC_ICON_THROBBER_START + 8 +{ + ImageBitmap = Bitmap{ file = "spinner03-32-hc_09.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_HC_ICON_THROBBER_START + 9 +{ + ImageBitmap = Bitmap{ file = "spinner03-32-hc_10.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_HC_ICON_THROBBER_START + 10 +{ + ImageBitmap = Bitmap{ file = "spinner03-32-hc_11.png"; }; + STD_MASK_COLOR +}; + +Image RID_TK_HC_ICON_THROBBER_START + 11 +{ + ImageBitmap = Bitmap{ file = "spinner03-32-hc_12.png"; }; + STD_MASK_COLOR +}; + diff --git a/toolkit/source/controls/accessiblecontrolcontext.cxx b/toolkit/source/controls/accessiblecontrolcontext.cxx new file mode 100644 index 000000000000..2611b2f37a91 --- /dev/null +++ b/toolkit/source/controls/accessiblecontrolcontext.cxx @@ -0,0 +1,380 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <toolkit/controls/accessiblecontrolcontext.hxx> +#include <unotools/accessiblestatesethelper.hxx> +#include <com/sun/star/awt/XControl.hpp> +#include <com/sun/star/awt/XWindow.hpp> +#include <vcl/svapp.hxx> +#include <com/sun/star/accessibility/AccessibleStateType.hpp> +#include <com/sun/star/accessibility/AccessibleRole.hpp> +#include <toolkit/helper/vclunohelper.hxx> +#include <vcl/window.hxx> + +//........................................................................ +namespace toolkit +{ +//........................................................................ + + using ::comphelper::OContextEntryGuard; + using namespace ::com::sun::star; + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::lang; + using namespace ::com::sun::star::beans; + using namespace ::com::sun::star::accessibility; + + //==================================================================== + //= OAccessibleControlContext + //==================================================================== + //-------------------------------------------------------------------- + OAccessibleControlContext::OAccessibleControlContext() + :OAccessibleControlContext_Base( ) + { + // nothing to do here, we have a late ctor + } + + //-------------------------------------------------------------------- + OAccessibleControlContext::~OAccessibleControlContext() + { + ensureDisposed(); + } + + //-------------------------------------------------------------------- + IMPLEMENT_FORWARD_XINTERFACE3( OAccessibleControlContext, OAccessibleControlContext_Base, OAccessibleImplementationAccess, OAccessibleControlContext_IBase ) + IMPLEMENT_FORWARD_XTYPEPROVIDER3( OAccessibleControlContext, OAccessibleControlContext_Base, OAccessibleImplementationAccess, OAccessibleControlContext_IBase ) + // (order matters: the first is the class name, the second is the class doing the ref counting) + + //-------------------------------------------------------------------- + void OAccessibleControlContext::Init( const Reference< XAccessible >& _rxCreator ) SAL_THROW( ( Exception ) ) + { + OContextEntryGuard aGuard( this ); + + // retrieve the model of the control + OSL_ENSURE( !m_xControlModel.is(), "OAccessibleControlContext::Init: already know a control model....!???" ); + + Reference< awt::XControl > xControl( _rxCreator, UNO_QUERY ); + if ( xControl.is() ) + m_xControlModel = m_xControlModel.query( xControl->getModel() ); + OSL_ENSURE( m_xControlModel.is(), "OAccessibleControlContext::Init: invalid creator (no control, or control without model!" ); + if ( !m_xControlModel.is() ) + throw DisposedException(); // caught by the caller (the create method) + + // start listening at the model + startModelListening(); + + // announce the XAccessible to our base class + OAccessibleControlContext_Base::lateInit( _rxCreator ); + } + + //-------------------------------------------------------------------- + OAccessibleControlContext* OAccessibleControlContext::create( const Reference< XAccessible >& _rxCreator ) SAL_THROW( ( ) ) + { + OAccessibleControlContext* pNew = NULL; + try + { + pNew = new OAccessibleControlContext; + pNew->Init( _rxCreator ); + } + catch( const Exception& ) + { + OSL_ENSURE( sal_False, "OAccessibleControlContext::create: caught an exception from the late ctor!" ); + } + return pNew; + } + + //-------------------------------------------------------------------- + void OAccessibleControlContext::startModelListening( ) SAL_THROW( ( Exception ) ) + { + Reference< XComponent > xModelComp( m_xControlModel, UNO_QUERY ); + OSL_ENSURE( xModelComp.is(), "OAccessibleControlContext::startModelListening: invalid model!" ); + if ( xModelComp.is() ) + xModelComp->addEventListener( this ); + } + + //-------------------------------------------------------------------- + void OAccessibleControlContext::stopModelListening( ) SAL_THROW( ( Exception ) ) + { + Reference< XComponent > xModelComp( m_xControlModel, UNO_QUERY ); + OSL_ENSURE( xModelComp.is(), "OAccessibleControlContext::stopModelListening: invalid model!" ); + if ( xModelComp.is() ) + xModelComp->removeEventListener( this ); + } + + //-------------------------------------------------------------------- + sal_Int32 SAL_CALL OAccessibleControlContext::getAccessibleChildCount( ) throw (RuntimeException) + { + // we do not have children + return 0; + } + + //-------------------------------------------------------------------- + Reference< XAccessible > SAL_CALL OAccessibleControlContext::getAccessibleChild( sal_Int32 ) throw (IndexOutOfBoundsException, RuntimeException) + { + // we do not have children + throw IndexOutOfBoundsException(); + } + + //-------------------------------------------------------------------- + Reference< XAccessible > SAL_CALL OAccessibleControlContext::getAccessibleParent( ) throw (RuntimeException) + { + OContextEntryGuard aGuard( this ); + OSL_ENSURE( implGetForeignControlledParent().is(), "OAccessibleControlContext::getAccessibleParent: somebody forgot to set a parent!" ); + // this parent of us is foreign controlled - somebody has to set it using the OAccessibleImplementationAccess + // class, before integrating our instance into an AccessibleDocumentModel + return implGetForeignControlledParent(); + } + + //-------------------------------------------------------------------- + sal_Int16 SAL_CALL OAccessibleControlContext::getAccessibleRole( ) throw (RuntimeException) + { + return AccessibleRole::SHAPE; + } + + //-------------------------------------------------------------------- + ::rtl::OUString SAL_CALL OAccessibleControlContext::getAccessibleDescription( ) throw (RuntimeException) + { + OContextEntryGuard aGuard( this ); + return getModelStringProperty( "HelpText" ); + } + + //-------------------------------------------------------------------- + ::rtl::OUString SAL_CALL OAccessibleControlContext::getAccessibleName( ) throw (RuntimeException) + { + OContextEntryGuard aGuard( this ); + return getModelStringProperty( "Name" ); + } + + //-------------------------------------------------------------------- + Reference< XAccessibleRelationSet > SAL_CALL OAccessibleControlContext::getAccessibleRelationSet( ) throw (RuntimeException) + { + return NULL; + } + + //-------------------------------------------------------------------- + Reference< XAccessibleStateSet > SAL_CALL OAccessibleControlContext::getAccessibleStateSet( ) throw (RuntimeException) + { + ::osl::MutexGuard aGuard( GetMutex() ); + // no OContextEntryGuard here, as we do not want to throw an exception in case we're not alive anymore + + ::utl::AccessibleStateSetHelper* pStateSet = NULL; + if ( isAlive() ) + { + // no own states, only the ones which are foreign controlled + pStateSet = new ::utl::AccessibleStateSetHelper( implGetForeignControlledStates() ); + } + else + { // only the DEFUNC state if we're already disposed + pStateSet = new ::utl::AccessibleStateSetHelper; + pStateSet->AddState( AccessibleStateType::DEFUNC ); + } + return pStateSet; + } + + //-------------------------------------------------------------------- + void SAL_CALL OAccessibleControlContext::disposing( const EventObject& + #if OSL_DEBUG_LEVEL > 0 + _rSource + #endif + ) throw ( RuntimeException ) + { + OSL_ENSURE( Reference< XPropertySet >( _rSource.Source, UNO_QUERY ).get() == m_xControlModel.get(), + "OAccessibleControlContext::disposing: where did this come from?" ); + + stopModelListening( ); + m_xControlModel.clear(); + m_xModelPropsInfo.clear(); + + OAccessibleControlContext_Base::disposing(); + } + + //-------------------------------------------------------------------- + ::rtl::OUString OAccessibleControlContext::getModelStringProperty( const sal_Char* _pPropertyName ) + { + ::rtl::OUString sReturn; + try + { + if ( !m_xModelPropsInfo.is() && m_xControlModel.is() ) + m_xModelPropsInfo = m_xControlModel->getPropertySetInfo(); + + ::rtl::OUString sPropertyName( ::rtl::OUString::createFromAscii( _pPropertyName ) ); + if ( m_xModelPropsInfo.is() && m_xModelPropsInfo->hasPropertyByName( sPropertyName ) ) + m_xControlModel->getPropertyValue( sPropertyName ) >>= sReturn; + } + catch( const Exception& ) + { + OSL_ENSURE( sal_False, "OAccessibleControlContext::getModelStringProperty: caught an exception!" ); + } + return sReturn; + } + + //-------------------------------------------------------------------- + Window* OAccessibleControlContext::implGetWindow( Reference< awt::XWindow >* _pxUNOWindow ) const + { + Reference< awt::XControl > xControl( getAccessibleCreator(), UNO_QUERY ); + Reference< awt::XWindow > xWindow; + if ( xControl.is() ) + xWindow = xWindow.query( xControl->getPeer() ); + + Window* pWindow = xWindow.is() ? VCLUnoHelper::GetWindow( xWindow ) : NULL; + + if ( _pxUNOWindow ) + *_pxUNOWindow = xWindow; + return pWindow; + } + + //-------------------------------------------------------------------- + awt::Rectangle SAL_CALL OAccessibleControlContext::implGetBounds( ) throw (RuntimeException) + { + ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + // want to do some VCL stuff here ... + OContextEntryGuard aGuard( this ); + + OSL_ENSURE( sal_False, "OAccessibleControlContext::implGetBounds: performance issue: forced to calc the size myself!" ); + // In design mode (and this is what this class is for), the surrounding shape (if any) should handle this call + // The problem is that in design mode, our size may not be correct (in the drawing layer, controls are + // positioned/sized for painting only), and that calculation of our position is expensive + + // what we know (or can obtain from somewhere): + // * the PosSize of our peer, relative to it's parent window + // * the parent window which the PosSize is relative to + // * our foreign controlled accessible parent + // from this info, we can determine the the position of our peer relative to the foreign parent + + // our control + Reference< awt::XWindow > xWindow; + Window* pVCLWindow = implGetWindow( &xWindow ); + + awt::Rectangle aBounds( 0, 0, 0, 0 ); + if ( xWindow.is() ) + { + // ugly, but .... though the XWindow has a getPosSize, it is impossible to determine the + // parent which this position/size is relative to. This means we must tunnel UNO and ask the + // implementation + Window* pVCLParent = pVCLWindow ? pVCLWindow->GetParent() : NULL; + + // the relative location of the window + ::Point aWindowRelativePos( 0, 0); + if ( pVCLWindow ) + aWindowRelativePos = pVCLWindow->GetPosPixel(); + + // the screnn position of the "window parent" of the control + ::Point aVCLParentScreenPos( 0, 0 ); + if ( pVCLParent ) + aVCLParentScreenPos = pVCLParent->GetPosPixel(); + + // the screen position of the "accessible parent" of the control + Reference< XAccessible > xParentAcc( implGetForeignControlledParent() ); + Reference< XAccessibleComponent > xParentAccComponent; + if ( xParentAcc.is() ) + xParentAccComponent = xParentAccComponent.query( xParentAcc->getAccessibleContext() ); + awt::Point aAccParentScreenPos( 0, 0 ); + if ( xParentAccComponent.is() ) + aAccParentScreenPos = xParentAccComponent->getLocationOnScreen(); + + // now the size of the control + aBounds = xWindow->getPosSize(); + + // correct the pos + aBounds.X = aWindowRelativePos.X() + aVCLParentScreenPos.X() - aAccParentScreenPos.X; + aBounds.Y = aWindowRelativePos.Y() + aVCLParentScreenPos.Y() - aAccParentScreenPos.Y; + } + + return aBounds; + } + + //-------------------------------------------------------------------- + Reference< XAccessible > SAL_CALL OAccessibleControlContext::getAccessibleAtPoint( const awt::Point& /* _rPoint */ ) throw (RuntimeException) + { + // no children at all + return NULL; + } + + //-------------------------------------------------------------------- + void SAL_CALL OAccessibleControlContext::grabFocus( ) throw (RuntimeException) + { + OSL_ENSURE( sal_False, "OAccessibleControlContext::grabFocus: !isFocusTraversable, but grabFocus!" ); + } + + //-------------------------------------------------------------------- + Any SAL_CALL OAccessibleControlContext::getAccessibleKeyBinding( ) throw (RuntimeException) + { + // we do not have any key bindings to activate a UNO control in design mode + return Any(); + } + + //-------------------------------------------------------------------- + sal_Int32 SAL_CALL OAccessibleControlContext::getForeground( ) throw (::com::sun::star::uno::RuntimeException) + { + ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + // want to do some VCL stuff here ... + OContextEntryGuard aGuard( this ); + + Window* pWindow = implGetWindow( ); + sal_Int32 nColor = 0; + if ( pWindow ) + { + if ( pWindow->IsControlForeground() ) + nColor = pWindow->GetControlForeground().GetColor(); + else + { + Font aFont; + if ( pWindow->IsControlFont() ) + aFont = pWindow->GetControlFont(); + else + aFont = pWindow->GetFont(); + nColor = aFont.GetColor().GetColor(); + } + } + return nColor; + } + + //-------------------------------------------------------------------- + sal_Int32 SAL_CALL OAccessibleControlContext::getBackground( ) throw (::com::sun::star::uno::RuntimeException) + { + ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + // want to do some VCL stuff here ... + OContextEntryGuard aGuard( this ); + + Window* pWindow = implGetWindow( ); + sal_Int32 nColor = 0; + if ( pWindow ) + { + if ( pWindow->IsControlBackground() ) + nColor = pWindow->GetControlBackground().GetColor(); + else + nColor = pWindow->GetBackground().GetColor().GetColor(); + } + + return nColor; + } + +//........................................................................ +} //namespace toolkit +//........................................................................ + diff --git a/toolkit/source/controls/dialogcontrol.cxx b/toolkit/source/controls/dialogcontrol.cxx new file mode 100644 index 000000000000..db9634fb44a1 --- /dev/null +++ b/toolkit/source/controls/dialogcontrol.cxx @@ -0,0 +1,2104 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + +#include <vcl/svapp.hxx> +#include <vcl/window.hxx> +#include <vcl/wall.hxx> +#include <vos/mutex.hxx> +#include <toolkit/controls/dialogcontrol.hxx> +#include <toolkit/helper/property.hxx> +#include <toolkit/helper/unopropertyarrayhelper.hxx> +#include <toolkit/controls/geometrycontrolmodel.hxx> +#include <toolkit/controls/unocontrols.hxx> +#include "toolkit/controls/formattedcontrol.hxx" +#include "toolkit/controls/roadmapcontrol.hxx" +#ifndef TOOLKIT_INC_TOOLKIT_CONTROLS_TKSCROLLBAR_HXX +#include "toolkit/controls/tkscrollbar.hxx" +#endif +#include <toolkit/controls/stdtabcontroller.hxx> +#include <com/sun/star/awt/PosSize.hpp> +#include <com/sun/star/awt/WindowAttribute.hpp> +#include <com/sun/star/resource/XStringResourceResolver.hpp> +#include <com/sun/star/graphic/XGraphicProvider.hpp> +#include <tools/list.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <tools/debug.hxx> +#include <tools/diagnose_ex.h> +#include <comphelper/processfactory.hxx> +#include <vcl/svapp.hxx> +#include <vcl/outdev.hxx> +#include <comphelper/types.hxx> + +#include <comphelper/componentcontext.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <unotools/ucbstreamhelper.hxx> +#include <vcl/graph.hxx> +#include <vcl/image.hxx> + +#include "tree/treecontrol.hxx" +#include "grid/gridcontrol.hxx" + +#include <map> +#include <algorithm> +#include <functional> +#include "tools/urlobj.hxx" +#include "osl/file.hxx" + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::util; +using namespace toolkit; + +#define PROPERTY_RESOURCERESOLVER ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceResolver" )) +#define PROPERTY_DIALOGSOURCEURL ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogSourceURL" )) +#define PROPERTY_IMAGEURL ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ImageURL" )) +#define PROPERTY_GRAPHIC ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Graphic" )) + +//HELPER +::rtl::OUString getPhysicalLocation( const ::com::sun::star::uno::Any& rbase, const ::com::sun::star::uno::Any& rUrl ); + +struct LanguageDependentProp +{ + const char* pPropName; + sal_Int32 nPropNameLength; +}; + +// ---------------------------------------------------------------------------- +namespace +{ + static const Sequence< ::rtl::OUString >& lcl_getLanguageDependentProperties() + { + static Sequence< ::rtl::OUString > s_aLanguageDependentProperties; + if ( s_aLanguageDependentProperties.getLength() == 0 ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if ( s_aLanguageDependentProperties.getLength() == 0 ) + { + s_aLanguageDependentProperties.realloc( 2 ); + s_aLanguageDependentProperties[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HelpText" ) ); + s_aLanguageDependentProperties[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ); + // note: properties must be sorted + } + } + return s_aLanguageDependentProperties; + } + + static uno::Reference< graphic::XGraphic > lcl_getGraphicFromURL_nothrow( const ::rtl::OUString& _rURL ) + { + uno::Reference< graphic::XGraphic > xGraphic; + if ( !_rURL.getLength() ) + return xGraphic; + + try + { + ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); + uno::Reference< graphic::XGraphicProvider > xProvider; + if ( aContext.createComponent( "com.sun.star.graphic.GraphicProvider", xProvider ) ) + { + uno::Sequence< beans::PropertyValue > aMediaProperties(1); + aMediaProperties[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ); + aMediaProperties[0].Value <<= _rURL; + xGraphic = xProvider->queryGraphic( aMediaProperties ); + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + + return xGraphic; + } + +} + +// ---------------------------------------------------------------------------- +// functor for disposing a control model +struct DisposeControlModel : public ::std::unary_function< Reference< XControlModel >, void > +{ + void operator()( Reference< XControlModel >& _rxModel ) + { + try + { + ::comphelper::disposeComponent( _rxModel ); + } + catch( const Exception& ) + { + DBG_ERROR( "DisposeControlModel::(): caught an exception while disposing a component!" ); + } + } +}; + +// ---------------------------------------------------------------------------- +// functor for searching control model by name +struct FindControlModel : public ::std::unary_function< UnoControlDialogModel::UnoControlModelHolder, bool > +{ +private: + const ::rtl::OUString& m_rName; + +public: + FindControlModel( const ::rtl::OUString& _rName ) : m_rName( _rName ) { } + + bool operator()( const UnoControlDialogModel::UnoControlModelHolder& _rCompare ) + { + return ( _rCompare.second == m_rName ) ? true : false; + } +}; + +// ---------------------------------------------------------------------------- +// functor for cloning a control model, and insertion into a target list +struct CloneControlModel : public ::std::unary_function< UnoControlDialogModel::UnoControlModelHolder, void > +{ +private: + UnoControlDialogModel::UnoControlModelHolderList& m_rTargetList; + +public: + CloneControlModel( UnoControlDialogModel::UnoControlModelHolderList& _rTargetList ) + :m_rTargetList( _rTargetList ) + { + } + + void operator()( const UnoControlDialogModel::UnoControlModelHolder& _rSource ) + { + // clone the source object + Reference< XCloneable > xCloneSource( _rSource.first, UNO_QUERY ); + Reference< XControlModel > xClone( xCloneSource->createClone(), UNO_QUERY ); + // add to target list + m_rTargetList.push_back( UnoControlDialogModel::UnoControlModelHolder( xClone, _rSource.second ) ); + } +}; + +// ---------------------------------------------------------------------------- +// functor for comparing a XControlModel with a given reference +struct CompareControlModel : public ::std::unary_function< UnoControlDialogModel::UnoControlModelHolder, bool > +{ +private: + Reference< XControlModel > m_xReference; +public: + CompareControlModel( const Reference< XControlModel >& _rxReference ) : m_xReference( _rxReference ) { } + + bool operator()( const UnoControlDialogModel::UnoControlModelHolder& _rCompare ) + { + return ( _rCompare.first.get() == m_xReference.get() ) ? true : false; + } +}; + +// ---------------------------------------------------------------------------- +static void lcl_throwIllegalArgumentException( ) +{ // throwing is expensive (in terms of code size), thus we hope the compiler does not inline this .... + throw IllegalArgumentException(); +} + +// ---------------------------------------------------------------------------- +static void lcl_throwNoSuchElementException( ) +{ // throwing is expensive (in terms of code size), thus we hope the compiler does not inline this .... + throw NoSuchElementException(); +} + +// ---------------------------------------------------------------------------- +static void lcl_throwElementExistException( ) +{ // throwing is expensive (in terms of code size), thus we hope the compiler does not inline this .... + throw ElementExistException(); +} + +// ---------------------------------------------------------------------------- +static const ::rtl::OUString& getTabIndexPropertyName( ) +{ + static const ::rtl::OUString s_sTabIndexProperty( RTL_CONSTASCII_USTRINGPARAM( "TabIndex" ) ); + return s_sTabIndexProperty; +} + +// ---------------------------------------------------------------------------- +static const ::rtl::OUString& getStepPropertyName( ) +{ + static const ::rtl::OUString s_sStepProperty( RTL_CONSTASCII_USTRINGPARAM( "Step" ) ); + return s_sStepProperty; +} + +// ---------------------------------------------------- +// class UnoControlDialogModel +// ---------------------------------------------------- +UnoControlDialogModel::UnoControlDialogModel() + :maContainerListeners( *this ) + ,maChangeListeners ( GetMutex() ) + ,mbGroupsUpToDate( sal_False ) +{ + ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR ); +// ImplRegisterProperty( BASEPROPERTY_BORDER ); + ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL ); + ImplRegisterProperty( BASEPROPERTY_ENABLED ); + ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR ); +// ImplRegisterProperty( BASEPROPERTY_PRINTABLE ); + ImplRegisterProperty( BASEPROPERTY_HELPTEXT ); + ImplRegisterProperty( BASEPROPERTY_HELPURL ); + ImplRegisterProperty( BASEPROPERTY_TITLE ); + ImplRegisterProperty( BASEPROPERTY_SIZEABLE ); + ImplRegisterProperty( BASEPROPERTY_DESKTOP_AS_PARENT ); + ImplRegisterProperty( BASEPROPERTY_DECORATION ); + ImplRegisterProperty( BASEPROPERTY_DIALOGSOURCEURL ); + ImplRegisterProperty( BASEPROPERTY_GRAPHIC ); + ImplRegisterProperty( BASEPROPERTY_IMAGEURL ); + + Any aBool; + aBool <<= (sal_Bool) sal_True; + ImplRegisterProperty( BASEPROPERTY_MOVEABLE, aBool ); + ImplRegisterProperty( BASEPROPERTY_CLOSEABLE, aBool ); +} + +UnoControlDialogModel::UnoControlDialogModel( const UnoControlDialogModel& rModel ) + : UnoControlDialogModel_IBase( rModel ) + , UnoControlDialogModel_Base( rModel ) + , maContainerListeners( *this ) + , maChangeListeners ( GetMutex() ) + , mbGroupsUpToDate( sal_False ) +{ +} + +UnoControlDialogModel::~UnoControlDialogModel() +{ + maModels.clear(); + mbGroupsUpToDate = sal_False; +} + +Any UnoControlDialogModel::queryAggregation( const Type & rType ) throw(RuntimeException) +{ + Any aRet( UnoControlDialogModel_IBase::queryInterface( rType ) ); + return (aRet.hasValue() ? aRet : UnoControlDialogModel_Base::queryAggregation( rType )); +} + +// XTypeProvider +IMPL_IMPLEMENTATION_ID( UnoControlDialogModel ) +Sequence< Type > UnoControlDialogModel::getTypes() throw(RuntimeException) +{ + return ::comphelper::concatSequences( + UnoControlDialogModel_IBase::getTypes(), + UnoControlDialogModel_Base::getTypes() + ); +} + +::rtl::OUString UnoControlDialogModel::getServiceName( ) throw(RuntimeException) +{ + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlDialogModel ); +} + +Any UnoControlDialogModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + Any aAny; + + switch ( nPropId ) + { + case BASEPROPERTY_DEFAULTCONTROL: + aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlDialog ); + break; + default: + aAny = UnoControlModel::ImplGetDefaultValue( nPropId ); + } + + return aAny; +} + +::cppu::IPropertyArrayHelper& UnoControlDialogModel::getInfoHelper() +{ + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + +void SAL_CALL UnoControlDialogModel::dispose( ) throw(RuntimeException) +{ + // ==================================================================== + // tell our listeners + { + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + EventObject aDisposeEvent; + aDisposeEvent.Source = static_cast< XAggregation* >( static_cast< ::cppu::OWeakAggObject* >( this ) ); + + maContainerListeners.disposeAndClear( aDisposeEvent ); + maChangeListeners.disposeAndClear( aDisposeEvent ); + } + + // ==================================================================== + // call the base class + UnoControlModel::dispose(); + + // ==================================================================== + // dispose our child models + // for this, collect the models (we collect them from maModels, and this is modified when disposing children) + ::std::vector< Reference< XControlModel > > aChildModels( maModels.size() ); + + ::std::transform( + maModels.begin(), maModels.end(), // source range + aChildModels.begin(), // target location + ::std::select1st< UnoControlModelHolder >( ) // operation to apply -> select the XControlModel part + ); + + // now dispose + ::std::for_each( aChildModels.begin(), aChildModels.end(), DisposeControlModel() ); + aChildModels.clear(); + + mbGroupsUpToDate = sal_False; +} + +// XMultiPropertySet +Reference< XPropertySetInfo > UnoControlDialogModel::getPropertySetInfo( ) throw(RuntimeException) +{ + static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + +UnoControlModel* UnoControlDialogModel::Clone() const +{ + // clone the container itself + UnoControlDialogModel* pClone = new UnoControlDialogModel( *this ); + + // clone all children + ::std::for_each( + maModels.begin(), maModels.end(), + CloneControlModel( pClone->maModels ) + ); + + return pClone; +} + +UnoControlDialogModel::UnoControlModelHolderList::iterator UnoControlDialogModel::ImplFindElement( const ::rtl::OUString& rName ) +{ + return ::std::find_if( maModels.begin(), maModels.end(), FindControlModel( rName ) ); +} + +// ::XMultiServiceFactory +Reference< XInterface > UnoControlDialogModel::createInstance( const ::rtl::OUString& aServiceSpecifier ) throw(Exception, RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + + OGeometryControlModel_Base* pNewModel = NULL; + + if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlEditModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoControlEditModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlFormattedFieldModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoControlFormattedFieldModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlFileControlModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoControlFileControlModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlButtonModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoControlButtonModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlImageControlModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoControlImageControlModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlRadioButtonModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoControlRadioButtonModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlCheckBoxModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoControlCheckBoxModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName_UnoControlFixedHyperlinkModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoControlFixedHyperlinkModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName_UnoControlFixedTextModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoControlFixedTextModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlGroupBoxModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoControlGroupBoxModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlListBoxModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoControlListBoxModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlComboBoxModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoControlComboBoxModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlDateFieldModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoControlDateFieldModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlTimeFieldModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoControlTimeFieldModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlNumericFieldModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoControlNumericFieldModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlCurrencyFieldModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoControlCurrencyFieldModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlPatternFieldModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoControlPatternFieldModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlProgressBarModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoControlProgressBarModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlScrollBarModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoControlScrollBarModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlFixedLineModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoControlFixedLineModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlRoadmapModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoControlRoadmapModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName_TreeControlModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoTreeModel >; + else if ( aServiceSpecifier.compareToAscii( szServiceName_GridControlModel ) == 0 ) + pNewModel = new OGeometryControlModel< UnoGridModel >; + + if ( !pNewModel ) + { + Reference< XMultiServiceFactory > xORB( ::comphelper::getProcessServiceFactory() ); + if ( xORB.is() ) + { + Reference< XInterface > xObject = xORB->createInstance( aServiceSpecifier ); + Reference< XServiceInfo > xSI( xObject, UNO_QUERY ); + Reference< XCloneable > xCloneAccess( xSI, UNO_QUERY ); + Reference< XAggregation > xAgg( xCloneAccess, UNO_QUERY ); + if ( xAgg.is() ) + { + if ( xSI->supportsService( ::rtl::OUString::createFromAscii( "com.sun.star.awt.UnoControlModel" ) ) ) + { + // release 3 of the 4 references we have to the object + xAgg.clear(); + xSI.clear(); + xObject.clear(); + + pNewModel = new OCommonGeometryControlModel( xCloneAccess, aServiceSpecifier ); + } + } + } + } + + Reference< XInterface > xNewModel = (::cppu::OWeakObject*)pNewModel; + return xNewModel; +} + +Reference< XInterface > UnoControlDialogModel::createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const Sequence< Any >& /* Arguments */ ) throw(Exception, RuntimeException) +{ + return createInstance( ServiceSpecifier ); +} + +Sequence< ::rtl::OUString > UnoControlDialogModel::getAvailableServiceNames() throw(RuntimeException) +{ + static Sequence< ::rtl::OUString >* pNamesSeq = NULL; + if ( !pNamesSeq ) + { + pNamesSeq = new Sequence< ::rtl::OUString >( 21 ); + ::rtl::OUString* pNames = pNamesSeq->getArray(); + pNames[0] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlEditModel ); + pNames[1] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlFormattedFieldModel ); + pNames[2] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlFileControlModel ); + pNames[3] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlButtonModel ); + pNames[4] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlImageControlModel ); + pNames[5] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlRadioButtonModel ); + pNames[6] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlCheckBoxModel ); + pNames[7] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlFixedTextModel ); + pNames[8] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlGroupBoxModel ); + pNames[9] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlListBoxModel ); + pNames[10] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlComboBoxModel ); + pNames[11] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlDateFieldModel ); + pNames[12] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlTimeFieldModel ); + pNames[13] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlNumericFieldModel ); + pNames[14] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlCurrencyFieldModel ); + pNames[15] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlPatternFieldModel ); + pNames[16] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlProgressBarModel ); + pNames[17] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlScrollBarModel ); + pNames[18] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlFixedLineModel ); + pNames[19] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlRoadmapModel ); + pNames[20] = ::rtl::OUString::createFromAscii( szServiceName_TreeControlModel ); + pNames[20] = ::rtl::OUString::createFromAscii( szServiceName_GridControlModel ); + + } + return *pNamesSeq; +} + +// XContainer +void UnoControlDialogModel::addContainerListener( const Reference< XContainerListener >& l ) throw(RuntimeException) +{ + maContainerListeners.addInterface( l ); +} + +void UnoControlDialogModel::removeContainerListener( const Reference< XContainerListener >& l ) throw(RuntimeException) +{ + maContainerListeners.removeInterface( l ); +} + +// XElementAcces +Type UnoControlDialogModel::getElementType() throw(RuntimeException) +{ + Type aType = getCppuType( ( Reference< XControlModel>* ) NULL ); + return aType; +} + +sal_Bool UnoControlDialogModel::hasElements() throw(RuntimeException) +{ + return !maModels.empty(); +} + +// XNameContainer, XNameReplace, XNameAccess +void UnoControlDialogModel::replaceByName( const ::rtl::OUString& aName, const Any& aElement ) throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + + Reference< XControlModel > xNewModel; + aElement >>= xNewModel; + if ( !xNewModel.is() ) + lcl_throwIllegalArgumentException(); + + UnoControlModelHolderList::iterator aElementPos = ImplFindElement( aName ); + if ( maModels.end() == aElementPos ) + lcl_throwNoSuchElementException(); + + // stop listening at the old model + stopControlListening( aElementPos->first ); + Reference< XControlModel > xReplaced( aElementPos->first ); + // remember the new model, and start listening + aElementPos->first = xNewModel; + startControlListening( xNewModel ); + + ContainerEvent aEvent; + aEvent.Source = *this; + aEvent.Element = aElement; + aEvent.ReplacedElement <<= xReplaced; + aEvent.Accessor <<= aName; + + // notify the container listener + maContainerListeners.elementReplaced( aEvent ); + + // our "tab controller model" has potentially changed -> notify this + implNotifyTabModelChange( aName ); +} + +Any UnoControlDialogModel::getByName( const ::rtl::OUString& aName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException) +{ + UnoControlModelHolderList::iterator aElementPos = ImplFindElement( aName ); + if ( maModels.end() == aElementPos ) + lcl_throwNoSuchElementException(); + + return makeAny( aElementPos->first ); +} + +Sequence< ::rtl::OUString > UnoControlDialogModel::getElementNames() throw(RuntimeException) +{ + Sequence< ::rtl::OUString > aNames( maModels.size() ); + + ::std::transform( + maModels.begin(), maModels.end(), // source range + aNames.getArray(), // target range + ::std::select2nd< UnoControlModelHolder >() // operator to apply: select the second element (the name) + ); + + return aNames; +} + +sal_Bool UnoControlDialogModel::hasByName( const ::rtl::OUString& aName ) throw(RuntimeException) +{ + return maModels.end() != ImplFindElement( aName ); +} + +void UnoControlDialogModel::insertByName( const ::rtl::OUString& aName, const Any& aElement ) throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + + Reference< XControlModel > xM; + aElement >>= xM; + + if ( xM.is() ) + { + Reference< beans::XPropertySet > xProps( xM, UNO_QUERY ); + if ( xProps.is() ) + { + + Reference< beans::XPropertySetInfo > xPropInfo = xProps.get()->getPropertySetInfo(); + + ::rtl::OUString sImageSourceProperty = GetPropertyName( BASEPROPERTY_IMAGEURL ); + if ( xPropInfo.get()->hasPropertyByName( sImageSourceProperty )) + { + Any aUrl = xProps.get()->getPropertyValue( sImageSourceProperty ); + + ::rtl::OUString absoluteUrl = + getPhysicalLocation( getPropertyValue( GetPropertyName( BASEPROPERTY_DIALOGSOURCEURL ) ), aUrl ); + + aUrl <<= absoluteUrl; + + xProps.get()->setPropertyValue( sImageSourceProperty , aUrl ); + } + } + } + + + + if ( !aName.getLength() || !xM.is() ) + lcl_throwIllegalArgumentException(); + + UnoControlModelHolderList::iterator aElementPos = ImplFindElement( aName ); + if ( maModels.end() != aElementPos ) + lcl_throwElementExistException(); + + maModels.push_back( UnoControlModelHolder( xM, aName ) ); + mbGroupsUpToDate = sal_False; + startControlListening( xM ); + + ContainerEvent aEvent; + aEvent.Source = *this; + aEvent.Element <<= aElement; + aEvent.Accessor <<= aName; + maContainerListeners.elementInserted( aEvent ); + + // our "tab controller model" has potentially changed -> notify this + implNotifyTabModelChange( aName ); +} + +void UnoControlDialogModel::removeByName( const ::rtl::OUString& aName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + + UnoControlModelHolderList::iterator aElementPos = ImplFindElement( aName ); + if ( maModels.end() == aElementPos ) + lcl_throwNoSuchElementException(); + + ContainerEvent aEvent; + aEvent.Source = *this; + aEvent.Element <<= aElementPos->first; + aEvent.Accessor <<= aName; + maContainerListeners.elementRemoved( aEvent ); + + stopControlListening( aElementPos->first ); + Reference< XPropertySet > xPS( aElementPos->first, UNO_QUERY ); + maModels.erase( aElementPos ); + mbGroupsUpToDate = sal_False; + + if ( xPS.is() ) + try + { + xPS->setPropertyValue( PROPERTY_RESOURCERESOLVER, makeAny( Reference< resource::XStringResourceResolver >() ) ); + } + catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); } + + // our "tab controller model" has potentially changed -> notify this + implNotifyTabModelChange( aName ); +} + +// ---------------------------------------------------------------------------- +sal_Bool SAL_CALL UnoControlDialogModel::getGroupControl( ) throw (RuntimeException) +{ + return sal_True; +} + +// ---------------------------------------------------------------------------- +void SAL_CALL UnoControlDialogModel::setGroupControl( sal_Bool ) throw (RuntimeException) +{ + DBG_ERROR( "UnoControlDialogModel::setGroupControl: explicit grouping not supported" ); +} + +// ---------------------------------------------------------------------------- +void SAL_CALL UnoControlDialogModel::setControlModels( const Sequence< Reference< XControlModel > >& _rControls ) throw (RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + + // set the tab indexes according to the order of models in the sequence + const Reference< XControlModel >* pControls = _rControls.getConstArray( ); + const Reference< XControlModel >* pControlsEnd = _rControls.getConstArray( ) + _rControls.getLength(); + + sal_Int16 nTabIndex = 1; + + for ( ; pControls != pControlsEnd; ++pControls ) + { + // look up the control in our own structure. This is to prevent invalid arguments + UnoControlModelHolderList::const_iterator aPos = + ::std::find_if( + maModels.begin(), maModels.end(), + CompareControlModel( *pControls ) + ); + if ( maModels.end() != aPos ) + { + // okay, this is an existent model + // now set the TabIndex property (if applicable) + Reference< XPropertySet > xProps( aPos->first, UNO_QUERY ); + Reference< XPropertySetInfo > xPSI; + if ( xProps.is() ) + xPSI = xProps->getPropertySetInfo(); + if ( xPSI.is() && xPSI->hasPropertyByName( getTabIndexPropertyName() ) ) + xProps->setPropertyValue( getTabIndexPropertyName(), makeAny( nTabIndex++ ) ); + } + mbGroupsUpToDate = sal_False; + } +} + + +typedef ::std::multimap< sal_Int32, Reference< XControlModel >, ::std::less< sal_Int32 > > MapIndexToModel; + +// ---------------------------------------------------------------------------- +Sequence< Reference< XControlModel > > SAL_CALL UnoControlDialogModel::getControlModels( ) throw (RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + + MapIndexToModel aSortedModels; + // will be the sorted container of all models which have a tab index property + ::std::vector< Reference< XControlModel > > aUnindexedModels; + // will be the container of all models which do not have a tab index property + + UnoControlModelHolderList::const_iterator aLoop = maModels.begin(); + for ( ; aLoop != maModels.end(); ++aLoop ) + { + Reference< XControlModel > xModel( aLoop->first ); + + // see if the model has a TabIndex property + Reference< XPropertySet > xControlProps( xModel, UNO_QUERY ); + Reference< XPropertySetInfo > xPSI; + if ( xControlProps.is() ) + xPSI = xControlProps->getPropertySetInfo( ); + DBG_ASSERT( xPSI.is(), "UnoControlDialogModel::getControlModels: invalid child model!" ); + + // has it? + if ( xPSI.is() && xPSI->hasPropertyByName( getTabIndexPropertyName() ) ) + { // yes + sal_Int32 nTabIndex = -1; + xControlProps->getPropertyValue( getTabIndexPropertyName() ) >>= nTabIndex; + + aSortedModels.insert( MapIndexToModel::value_type( nTabIndex, xModel ) ); + } + else if ( xModel.is() ) + // no, it hasn't, but we have to include it, anyway + aUnindexedModels.push_back( xModel ); + } + + // okay, here we have a container of all our models, sorted by tab index, + // plus a container of "unindexed" models + // -> merge them + Sequence< Reference< XControlModel > > aReturn( aUnindexedModels.size() + aSortedModels.size() ); + ::std::transform( + aSortedModels.begin(), aSortedModels.end(), + ::std::copy( aUnindexedModels.begin(), aUnindexedModels.end(), aReturn.getArray() ), + ::std::select2nd< MapIndexToModel::value_type >( ) + ); + + return aReturn; +} + +// ---------------------------------------------------------------------------- +void SAL_CALL UnoControlDialogModel::setGroup( const Sequence< Reference< XControlModel > >&, const ::rtl::OUString& ) throw (RuntimeException) +{ + // not supported. We have only implicit grouping: + // We only have a sequence of control models, and we _know_ (yes, that's a HACK relying on + // implementation details) that VCL does grouping according to the order of controls automatically + // At least VCL does this for all we're interested in: Radio buttons. + DBG_ERROR( "UnoControlDialogModel::setGroup: grouping not supported" ); +} + +// ---------------------------------------------------------------------------- +namespace +{ + enum GroupingMachineState + { + eLookingForGroup, + eExpandingGroup + }; + + // ........................................................................ + static sal_Int32 lcl_getDialogStep( const Reference< XControlModel >& _rxModel ) + { + sal_Int32 nStep = 0; + try + { + Reference< XPropertySet > xModelProps( _rxModel, UNO_QUERY ); + xModelProps->getPropertyValue( getStepPropertyName() ) >>= nStep; + } + catch( const Exception& ) + { + DBG_ERROR( "lcl_getDialogStep: caught an exception while determining the dialog page!" ); + } + return nStep; + } +} + +// ---------------------------------------------------------------------------- +sal_Int32 SAL_CALL UnoControlDialogModel::getGroupCount( ) throw (RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + + implUpdateGroupStructure(); + + return maGroups.size(); +} + +// ---------------------------------------------------------------------------- +void SAL_CALL UnoControlDialogModel::getGroup( sal_Int32 _nGroup, Sequence< Reference< XControlModel > >& _rGroup, ::rtl::OUString& _rName ) throw (RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + + implUpdateGroupStructure(); + + if ( ( _nGroup < 0 ) || ( _nGroup >= (sal_Int32)maGroups.size() ) ) + { + DBG_ERROR( "UnoControlDialogModel::getGroup: invalid argument and I am not allowed to throw an exception!" ); + _rGroup.realloc( 0 ); + _rName = ::rtl::OUString(); + } + else + { + AllGroups::const_iterator aGroupPos = maGroups.begin() + _nGroup; + _rGroup.realloc( aGroupPos->size() ); + // copy the models + ::std::copy( aGroupPos->begin(), aGroupPos->end(), _rGroup.getArray() ); + // give the group a name + _rName = ::rtl::OUString::valueOf( _nGroup ); + } +} + +// ---------------------------------------------------------------------------- +void SAL_CALL UnoControlDialogModel::getGroupByName( const ::rtl::OUString& _rName, Sequence< Reference< XControlModel > >& _rGroup ) throw (RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + + ::rtl::OUString sDummyName; + getGroup( _rName.toInt32( ), _rGroup, sDummyName ); +} + +// ---------------------------------------------------------------------------- +void SAL_CALL UnoControlDialogModel::addChangesListener( const Reference< XChangesListener >& _rxListener ) throw (RuntimeException) +{ + maChangeListeners.addInterface( _rxListener ); +} + +// ---------------------------------------------------------------------------- +void SAL_CALL UnoControlDialogModel::removeChangesListener( const Reference< XChangesListener >& _rxListener ) throw (RuntimeException) +{ + maChangeListeners.removeInterface( _rxListener ); +} + +// ---------------------------------------------------------------------------- +void UnoControlDialogModel::implNotifyTabModelChange( const ::rtl::OUString& _rAccessor ) +{ + // multiplex to our change listeners: + // the changes event + ChangesEvent aEvent; + aEvent.Source = *this; + aEvent.Base <<= aEvent.Source; // the "base of the changes root" is also ourself + aEvent.Changes.realloc( 1 ); // exactly one change + aEvent.Changes[ 0 ].Accessor <<= _rAccessor; + + + Sequence< Reference< XInterface > > aChangeListeners( maChangeListeners.getElements() ); + const Reference< XInterface >* pListener = aChangeListeners.getConstArray(); + const Reference< XInterface >* pListenerEnd = aChangeListeners.getConstArray() + aChangeListeners.getLength(); + for ( ; pListener != pListenerEnd; ++pListener ) + { + if ( pListener->is() ) + static_cast< XChangesListener* >( pListener->get() )->changesOccurred( aEvent ); + } +} + + +// ---------------------------------------------------------------------------- +void UnoControlDialogModel::implUpdateGroupStructure() +{ + if ( mbGroupsUpToDate ) + // nothing to do + return; + + // conditions for a group: + // * all elements of the group are radio buttons + // * all elements of the group are on the same dialog page + // * in the overall control order (determined by the tab index), all elements are subsequent + + maGroups.clear(); + + Sequence< Reference< XControlModel > > aControlModels = getControlModels(); + const Reference< XControlModel >* pControlModels = aControlModels.getConstArray(); + const Reference< XControlModel >* pControlModelsEnd = pControlModels + aControlModels.getLength(); + + // in extreme we have as much groups as controls + maGroups.reserve( aControlModels.getLength() ); + + GroupingMachineState eState = eLookingForGroup; // the current state of our machine + Reference< XServiceInfo > xModelSI; // for checking for a radion button + AllGroups::iterator aCurrentGroup = maGroups.end(); // the group which we're currently building + sal_Int32 nCurrentGroupStep = -1; // the step which all controls of the current group belong to + sal_Bool bIsRadioButton; // is it a radio button? + +#if OSL_DEBUG_LEVEL > 1 + ::std::vector< ::rtl::OUString > aCurrentGroupLabels; +#endif + + for ( ; pControlModels != pControlModelsEnd; ++pControlModels ) + { + // we'll need this in every state + xModelSI = xModelSI.query( *pControlModels ); + bIsRadioButton = xModelSI.is() && xModelSI->supportsService( ::rtl::OUString::createFromAscii( szServiceName2_UnoControlRadioButtonModel ) ); + + switch ( eState ) + { + case eLookingForGroup: + { + if ( !bIsRadioButton ) + // this is no radio button -> still looking for the beginning of a group + continue; + // the current model is a radio button + // -> we found the beginning of a new group + // create the place for this group + size_t nGroups = maGroups.size(); + maGroups.resize( nGroups + 1 ); + aCurrentGroup = maGroups.begin() + nGroups; + // and add the (only, til now) member + aCurrentGroup->push_back( *pControlModels ); + + // get the step which all controls of this group now have to belong to + nCurrentGroupStep = lcl_getDialogStep( *pControlModels ); + // new state: looking for further members + eState = eExpandingGroup; + +#if OSL_DEBUG_LEVEL > 1 + Reference< XPropertySet > xModelProps( *pControlModels, UNO_QUERY ); + ::rtl::OUString sLabel; + if ( xModelProps.is() && xModelProps->getPropertySetInfo().is() && xModelProps->getPropertySetInfo()->hasPropertyByName( ::rtl::OUString::createFromAscii( "Label" ) ) ) + xModelProps->getPropertyValue( ::rtl::OUString::createFromAscii( "Label" ) ) >>= sLabel; + aCurrentGroupLabels.push_back( sLabel ); +#endif + } + break; + + case eExpandingGroup: + { + if ( !bIsRadioButton ) + { // no radio button -> the group is done + aCurrentGroup = maGroups.end(); + eState = eLookingForGroup; +#if OSL_DEBUG_LEVEL > 1 + aCurrentGroupLabels.clear(); +#endif + continue; + } + + // it is a radio button - is it on the proper page? + const sal_Int32 nThisModelStep = lcl_getDialogStep( *pControlModels ); + if ( ( nThisModelStep == nCurrentGroupStep ) // the current button is on the same dialog page + || ( 0 == nThisModelStep ) // the current button appears on all pages + ) + { + // -> it belongs to the same group + aCurrentGroup->push_back( *pControlModels ); + // state still is eExpandingGroup - we're looking for further elements + eState = eExpandingGroup; + +#if OSL_DEBUG_LEVEL > 1 + Reference< XPropertySet > xModelProps( *pControlModels, UNO_QUERY ); + ::rtl::OUString sLabel; + if ( xModelProps.is() && xModelProps->getPropertySetInfo().is() && xModelProps->getPropertySetInfo()->hasPropertyByName( ::rtl::OUString::createFromAscii( "Label" ) ) ) + xModelProps->getPropertyValue( ::rtl::OUString::createFromAscii( "Label" ) ) >>= sLabel; + aCurrentGroupLabels.push_back( sLabel ); +#endif + continue; + } + + // it's a radio button, but on a different page + // -> we open a new group for it + + // close the old group + aCurrentGroup = maGroups.end(); +#if OSL_DEBUG_LEVEL > 1 + aCurrentGroupLabels.clear(); +#endif + + // open a new group + size_t nGroups = maGroups.size(); + maGroups.resize( nGroups + 1 ); + aCurrentGroup = maGroups.begin() + nGroups; + // and add the (only, til now) member + aCurrentGroup->push_back( *pControlModels ); + + nCurrentGroupStep = nThisModelStep; + + // state is the same: we still are looking for further elements of the current group + eState = eExpandingGroup; +#if OSL_DEBUG_LEVEL > 1 + Reference< XPropertySet > xModelProps( *pControlModels, UNO_QUERY ); + ::rtl::OUString sLabel; + if ( xModelProps.is() && xModelProps->getPropertySetInfo().is() && xModelProps->getPropertySetInfo()->hasPropertyByName( ::rtl::OUString::createFromAscii( "Label" ) ) ) + xModelProps->getPropertyValue( ::rtl::OUString::createFromAscii( "Label" ) ) >>= sLabel; + aCurrentGroupLabels.push_back( sLabel ); +#endif + } + break; + } + } + + mbGroupsUpToDate = sal_True; +} + +// ---------------------------------------------------------------------------- +void SAL_CALL UnoControlDialogModel::propertyChange( const PropertyChangeEvent& _rEvent ) throw (RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + + DBG_ASSERT( 0 == _rEvent.PropertyName.compareToAscii( "TabIndex" ), + "UnoControlDialogModel::propertyChange: not listening for this property!" ); + + // the accessor for the changed element + ::rtl::OUString sAccessor; + UnoControlModelHolderList::const_iterator aPos = + ::std::find_if( + maModels.begin(), maModels.end(), + CompareControlModel( Reference< XControlModel >( _rEvent.Source, UNO_QUERY ) ) + ); + OSL_ENSURE( maModels.end() != aPos, "UnoControlDialogModel::propertyChange: don't know this model!" ); + if ( maModels.end() != aPos ) + sAccessor = aPos->second; + + // our groups are not up-to-date + mbGroupsUpToDate = sal_False; + + // notify + implNotifyTabModelChange( sAccessor ); +} + +// ---------------------------------------------------------------------------- +void SAL_CALL UnoControlDialogModel::disposing( const EventObject& /*rEvent*/ ) throw (RuntimeException) +{ +} + +// ---------------------------------------------------------------------------- +void UnoControlDialogModel::startControlListening( const Reference< XControlModel >& _rxChildModel ) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + + Reference< XPropertySet > xModelProps( _rxChildModel, UNO_QUERY ); + Reference< XPropertySetInfo > xPSI; + if ( xModelProps.is() ) + xPSI = xModelProps->getPropertySetInfo(); + + if ( xPSI.is() && xPSI->hasPropertyByName( getTabIndexPropertyName() ) ) + xModelProps->addPropertyChangeListener( getTabIndexPropertyName(), this ); +} + +// ---------------------------------------------------------------------------- +void UnoControlDialogModel::stopControlListening( const Reference< XControlModel >& _rxChildModel ) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + + Reference< XPropertySet > xModelProps( _rxChildModel, UNO_QUERY ); + Reference< XPropertySetInfo > xPSI; + if ( xModelProps.is() ) + xPSI = xModelProps->getPropertySetInfo(); + + if ( xPSI.is() && xPSI->hasPropertyByName( getTabIndexPropertyName() ) ) + xModelProps->removePropertyChangeListener( getTabIndexPropertyName(), this ); +} + +// ============================================================================ +// = class ResourceListener +// ============================================================================ + +ResourceListener::ResourceListener( + const Reference< util::XModifyListener >& rListener ) : + OWeakObject(), + m_xListener( rListener ), + m_bListening( false ) +{ +} + +ResourceListener::~ResourceListener() +{ +} + +// XInterface +Any SAL_CALL ResourceListener::queryInterface( const Type& rType ) +throw ( RuntimeException ) +{ + Any a = ::cppu::queryInterface( + rType , + static_cast< XModifyListener* >( this ), + static_cast< XEventListener* >( this )); + + if ( a.hasValue() ) + return a; + + return OWeakObject::queryInterface( rType ); +} + +void SAL_CALL ResourceListener::acquire() throw () +{ + OWeakObject::acquire(); +} + +void SAL_CALL ResourceListener::release() throw () +{ + OWeakObject::release(); +} + +void ResourceListener::startListening( + const Reference< resource::XStringResourceResolver >& rResource ) +{ + Reference< util::XModifyBroadcaster > xModifyBroadcaster( rResource, UNO_QUERY ); + + { + // --- SAFE --- + ::osl::ResettableGuard < ::osl::Mutex > aGuard( m_aMutex ); + bool bListening( m_bListening ); + bool bResourceSet( m_xResource.is() ); + aGuard.clear(); + // --- SAFE --- + + if ( bListening && bResourceSet ) + stopListening(); + + // --- SAFE --- + aGuard.reset(); + m_xResource = rResource; + aGuard.clear(); + // --- SAFE --- + } + + Reference< util::XModifyListener > xThis( static_cast<OWeakObject*>( this ), UNO_QUERY ); + if ( xModifyBroadcaster.is() ) + { + try + { + xModifyBroadcaster->addModifyListener( xThis ); + + // --- SAFE --- + ::osl::ResettableGuard < ::osl::Mutex > aGuard( m_aMutex ); + m_bListening = true; + // --- SAFE --- + } + catch ( RuntimeException& ) + { + throw; + } + catch ( Exception& ) + { + } + } +} + +void ResourceListener::stopListening() +{ + Reference< util::XModifyBroadcaster > xModifyBroadcaster; + + // --- SAFE --- + ::osl::ResettableGuard < ::osl::Mutex > aGuard( m_aMutex ); + if ( m_bListening && m_xResource.is() ) + xModifyBroadcaster = Reference< util::XModifyBroadcaster >( m_xResource, UNO_QUERY ); + aGuard.clear(); + // --- SAFE --- + + Reference< util::XModifyListener > xThis( static_cast< OWeakObject* >( this ), UNO_QUERY ); + if ( xModifyBroadcaster.is() ) + { + try + { + // --- SAFE --- + aGuard.reset(); + m_bListening = false; + m_xResource.clear(); + aGuard.clear(); + // --- SAFE --- + + xModifyBroadcaster->removeModifyListener( xThis ); + } + catch ( RuntimeException& ) + { + throw; + } + catch ( Exception& ) + { + } + } +} + +// XModifyListener +void SAL_CALL ResourceListener::modified( + const lang::EventObject& aEvent ) +throw ( RuntimeException ) +{ + Reference< util::XModifyListener > xListener; + + // --- SAFE --- + ::osl::ResettableGuard < ::osl::Mutex > aGuard( m_aMutex ); + xListener = m_xListener; + aGuard.clear(); + // --- SAFE --- + + if ( xListener.is() ) + { + try + { + xListener->modified( aEvent ); + } + catch ( RuntimeException& ) + { + throw; + } + catch ( Exception& ) + { + } + } +} + +// XEventListener +void SAL_CALL ResourceListener::disposing( + const EventObject& Source ) +throw ( RuntimeException ) +{ + Reference< lang::XEventListener > xListener; + Reference< resource::XStringResourceResolver > xResource; + + // --- SAFE --- + ::osl::ResettableGuard < ::osl::Mutex > aGuard( m_aMutex ); + Reference< XInterface > xIfacRes( m_xResource, UNO_QUERY ); + Reference< XInterface > xIfacList( m_xListener, UNO_QUERY ); + aGuard.clear(); + // --- SAFE --- + + if ( Source.Source == xIfacRes ) + { + // --- SAFE --- + aGuard.reset(); + m_bListening = false; + xResource = m_xResource; + xListener = Reference< lang::XEventListener >( m_xListener, UNO_QUERY ); + m_xResource.clear(); + aGuard.clear(); + // --- SAFE --- + + if ( xListener.is() ) + { + try + { + xListener->disposing( Source ); + } + catch ( RuntimeException& ) + { + throw; + } + catch ( Exception& ) + { + } + } + } + else if ( Source.Source == xIfacList ) + { + // --- SAFE --- + aGuard.reset(); + m_bListening = false; + xListener = Reference< lang::XEventListener >( m_xListener, UNO_QUERY ); + xResource = m_xResource; + m_xResource.clear(); + m_xListener.clear(); + aGuard.clear(); + // --- SAFE --- + + // Remove ourself as listener from resource resolver + Reference< util::XModifyBroadcaster > xModifyBroadcaster( xResource, UNO_QUERY ); + Reference< util::XModifyListener > xThis( static_cast< OWeakObject* >( this ), UNO_QUERY ); + if ( xModifyBroadcaster.is() ) + { + try + { + xModifyBroadcaster->removeModifyListener( xThis ); + } + catch ( RuntimeException& ) + { + throw; + } + catch ( Exception& ) + { + } + } + } +} + +// ============================================================================ +// = class UnoDialogControl +// ============================================================================ + +UnoDialogControl::UnoDialogControl() : + maTopWindowListeners( *this ), + mbWindowListener(false), + mbSizeModified(false), + mbPosModified(false) +{ + maComponentInfos.nWidth = 300; + maComponentInfos.nHeight = 450; + mxListener = new ResourceListener( Reference< util::XModifyListener >( + static_cast< OWeakObject* >( this ), UNO_QUERY )); +} + +::rtl::OUString UnoDialogControl::GetComponentServiceName() +{ + + sal_Bool bDecoration( sal_True ); + ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_DECORATION )) >>= bDecoration; + if ( bDecoration ) + return ::rtl::OUString::createFromAscii( "Dialog" ); + else + return ::rtl::OUString::createFromAscii( "TabPage" ); +} + +// XInterface +Any UnoDialogControl::queryAggregation( const Type & rType ) throw(RuntimeException) +{ + Any aRet( UnoDialogControl_IBase::queryInterface( rType ) ); + return (aRet.hasValue() ? aRet : UnoControlContainer::queryAggregation( rType )); +} + +// XTypeProvider +IMPL_IMPLEMENTATION_ID( UnoDialogControl ) +Sequence< Type > UnoDialogControl::getTypes() throw(RuntimeException) +{ + return ::comphelper::concatSequences( + UnoDialogControl_IBase::getTypes(), + UnoControlContainer::getTypes() + ); +} + +void UnoDialogControl::ImplInsertControl( Reference< XControlModel >& rxModel, const ::rtl::OUString& rName ) +{ + Reference< XPropertySet > xP( rxModel, UNO_QUERY ); + + ::rtl::OUString aDefCtrl; + xP->getPropertyValue( GetPropertyName( BASEPROPERTY_DEFAULTCONTROL ) ) >>= aDefCtrl; + + // Add our own resource resolver to a newly created control + Reference< resource::XStringResourceResolver > xStringResourceResolver; + rtl::OUString aPropName( PROPERTY_RESOURCERESOLVER ); + + Any aAny; + ImplGetPropertyValue( aPropName ) >>= xStringResourceResolver; + + aAny <<= xStringResourceResolver; + xP->setPropertyValue( aPropName, aAny ); + + Reference< XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory(); + Reference < XControl > xCtrl( xMSF->createInstance( aDefCtrl ), UNO_QUERY ); + + DBG_ASSERT( xCtrl.is(), "UnoDialogControl::ImplInsertControl: could not create the control!" ); + if ( xCtrl.is() ) + { + xCtrl->setModel( rxModel ); + addControl( rName, xCtrl ); + // will implicitly call addingControl, where we can add the PropertiesChangeListener to the model + // (which we formerly did herein) + // 08.01.2001 - 96008 - fs@openoffice.org + + ImplSetPosSize( xCtrl ); + } +} + +void UnoDialogControl::ImplRemoveControl( Reference< XControlModel >& rxModel ) +{ + Sequence< Reference< XControl > > aControls = getControls(); + Reference< XControl > xCtrl = StdTabController::FindControl( aControls, rxModel ); + if ( xCtrl.is() ) + removeControl( xCtrl ); +} + +void UnoDialogControl::ImplSetPosSize( Reference< XControl >& rxCtrl ) +{ + Reference< XPropertySet > xP( rxCtrl->getModel(), UNO_QUERY ); + + sal_Int32 nX = 0, nY = 0, nWidth = 0, nHeight = 0; + xP->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) ) ) >>= nX; + xP->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PositionY" ) ) ) >>= nY; + xP->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" ) ) ) >>= nWidth; + xP->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Height" ) ) ) >>= nHeight; + + // Currentley we are simply using MAP_APPFONT + OutputDevice*pOutDev = Application::GetDefaultDevice(); + DBG_ASSERT( pOutDev, "Missing Default Device!" ); + if ( pOutDev ) + { + ::Size aTmp( nX, nY ); + aTmp = pOutDev->LogicToPixel( aTmp, MAP_APPFONT ); + nX = aTmp.Width(); + nY = aTmp.Height(); + aTmp = ::Size( nWidth, nHeight ); + aTmp = pOutDev->LogicToPixel( aTmp, MAP_APPFONT ); + nWidth = aTmp.Width(); + nHeight = aTmp.Height(); + } + else + { + Reference< XWindowPeer > xPeer = ImplGetCompatiblePeer( sal_True ); + Reference< XDevice > xD( xPeer, UNO_QUERY ); + + SimpleFontMetric aFM; + FontDescriptor aFD; + Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_FONTDESCRIPTOR ) ); + aVal >>= aFD; + if ( aFD.StyleName.getLength() ) + { + Reference< XFont > xFont = xD->getFont( aFD ); + aFM = xFont->getFontMetric(); + } + else + { + Reference< XGraphics > xG = xD->createGraphics(); + aFM = xG->getFontMetric(); + } + + sal_Int16 nH = aFM.Ascent + aFM.Descent; + sal_Int16 nW = nH/2; // calculate avarage width?! + + nX *= nW; + nX /= 4; + nWidth *= nW; + nWidth /= 4; + nY *= nH; + nY /= 8; + nHeight *= nH; + nHeight /= 8; + } + Reference < XWindow > xW( rxCtrl, UNO_QUERY ); + xW->setPosSize( nX, nY, nWidth, nHeight, PosSize::POSSIZE ); +} + +void UnoDialogControl::dispose() throw(RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + + EventObject aEvt; + aEvt.Source = static_cast< ::cppu::OWeakObject* >( this ); + maTopWindowListeners.disposeAndClear( aEvt ); + + // Notify our listener helper about dispose + // --- SAFE --- + ::osl::ResettableGuard< ::osl::Mutex > aGuard( GetMutex() ); + Reference< XEventListener > xListener( mxListener, UNO_QUERY ); + mxListener.clear(); + aGuard.clear(); + // --- SAFE --- + + if ( xListener.is() ) + xListener->disposing( aEvt ); + + UnoControlContainer::dispose(); +} + +void SAL_CALL UnoDialogControl::disposing( + const EventObject& Source ) +throw(RuntimeException) +{ + rtl::OUString aPropName( PROPERTY_RESOURCERESOLVER ); + Reference< resource::XStringResourceResolver > xStringResourceResolver; + + ImplGetPropertyValue( aPropName ) >>= xStringResourceResolver; + Reference< XInterface > xIfac( xStringResourceResolver, UNO_QUERY ); + + if ( Source.Source == xIfac ) + { + Any aAny; + + // Reset resource resolver reference + ImplSetPropertyValue( aPropName, aAny, sal_True ); + ImplUpdateResourceResolver(); + } + else + { + UnoControlContainer::disposing( Source ); + } +} + +sal_Bool UnoDialogControl::setModel( const Reference< XControlModel >& rxModel ) throw(RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + + // destroy the old tab controller, if existent + if ( mxTabController.is() ) + { + mxTabController->setModel( NULL ); // just to be sure, should not be necessary + removeTabController( mxTabController ); + ::comphelper::disposeComponent( mxTabController ); // just to be sure, should not be necessary + mxTabController.clear(); + } + + if ( getModel().is() ) + { + Sequence< Reference< XControl > > aControls = getControls(); + const Reference< XControl >* pCtrls = aControls.getConstArray(); + const Reference< XControl >* pCtrlsEnd = pCtrls + aControls.getLength(); + + for ( ; pCtrls < pCtrlsEnd; ++pCtrls ) + removeControl( *pCtrls ); + // will implicitly call removingControl, which will remove the PropertyChangeListener + // (which we formerly did herein) + // 08.01.2001 - 96008 - fs@openoffice.org + + Reference< XContainer > xC( getModel(), UNO_QUERY ); + if ( xC.is() ) + xC->removeContainerListener( this ); + + Reference< XChangesNotifier > xChangeNotifier( getModel(), UNO_QUERY ); + if ( xChangeNotifier.is() ) + xChangeNotifier->removeChangesListener( this ); + } + + sal_Bool bRet = UnoControl::setModel( rxModel ); + + if ( getModel().is() ) + { + Reference< XNameAccess > xNA( getModel(), UNO_QUERY ); + if ( xNA.is() ) + { + Sequence< ::rtl::OUString > aNames = xNA->getElementNames(); + const ::rtl::OUString* pNames = aNames.getConstArray(); + sal_uInt32 nCtrls = aNames.getLength(); + + Reference< XControlModel > xCtrlModel; + for( sal_uInt32 n = 0; n < nCtrls; ++n, ++pNames ) + { + xNA->getByName( *pNames ) >>= xCtrlModel; + ImplInsertControl( xCtrlModel, *pNames ); + } + } + + Reference< XContainer > xC( getModel(), UNO_QUERY ); + if ( xC.is() ) + xC->addContainerListener( this ); + + Reference< XChangesNotifier > xChangeNotifier( getModel(), UNO_QUERY ); + if ( xChangeNotifier.is() ) + xChangeNotifier->addChangesListener( this ); + } + + Reference< XTabControllerModel > xTabbing( getModel(), UNO_QUERY ); + if ( xTabbing.is() ) + { + mxTabController = new StdTabController; + mxTabController->setModel( xTabbing ); + addTabController( mxTabController ); + } + ImplStartListingForResourceEvents(); + + return bRet; +} + +void UnoDialogControl::setDesignMode( sal_Bool bOn ) throw(RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + UnoControl::setDesignMode( bOn ); + + Sequence< Reference< XControl > > xCtrls = getControls(); + sal_Int32 nControls = xCtrls.getLength(); + Reference< XControl >* pControls = xCtrls.getArray(); + for ( sal_Int32 n = 0; n < nControls; n++ ) + pControls[n]->setDesignMode( bOn ); + + // #109067# in design mode the tab controller is not notified about + // tab index changes, therefore the tab order must be activated + // when switching from design mode to live mode + if ( mxTabController.is() && !bOn ) + mxTabController->activateTabOrder(); +} + +void UnoDialogControl::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer > & rParentPeer ) throw(RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + + UnoControlContainer::createPeer( rxToolkit, rParentPeer ); + + Reference < XTopWindow > xTW( getPeer(), UNO_QUERY ); + if ( xTW.is() ) + { + xTW->setMenuBar( mxMenuBar ); + + if ( !mbWindowListener ) + { + Reference< XWindowListener > xWL( static_cast< cppu::OWeakObject*>( this ), UNO_QUERY ); + addWindowListener( xWL ); + mbWindowListener = true; + } + + if ( maTopWindowListeners.getLength() ) + xTW->addTopWindowListener( &maTopWindowListeners ); + } +} + +void UnoDialogControl::PrepareWindowDescriptor( ::com::sun::star::awt::WindowDescriptor& rDesc ) +{ + sal_Bool bDecoration( sal_True ); + ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_DECORATION )) >>= bDecoration; + if ( !bDecoration ) + { + // Now we have to manipulate the WindowDescriptor + rDesc.WindowAttributes = rDesc.WindowAttributes | ::com::sun::star::awt::WindowAttribute::NODECORATION; + } + + // We have to set the graphic property before the peer + // will be created. Otherwise the properties will be copied + // into the peer via propertiesChangeEvents. As the order of + // can lead to overwrites we have to set the graphic property + // before the propertiesChangeEvents are sent! + ::rtl::OUString aImageURL; + Reference< graphic::XGraphic > xGraphic; + if (( ImplGetPropertyValue( PROPERTY_IMAGEURL ) >>= aImageURL ) && + ( aImageURL.getLength() > 0 )) + { + ::rtl::OUString absoluteUrl = + getPhysicalLocation( ImplGetPropertyValue( PROPERTY_DIALOGSOURCEURL ), + ImplGetPropertyValue( PROPERTY_IMAGEURL )); + + xGraphic = lcl_getGraphicFromURL_nothrow( absoluteUrl ); + ImplSetPropertyValue( PROPERTY_GRAPHIC, uno::makeAny( xGraphic ), sal_True ); + } +} + +void UnoDialogControl::elementInserted( const ContainerEvent& Event ) throw(RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + + Reference< XControlModel > xModel; + ::rtl::OUString aName; + + Event.Accessor >>= aName; + Event.Element >>= xModel; + ImplInsertControl( xModel, aName ); +} + +void UnoDialogControl::elementRemoved( const ContainerEvent& Event ) throw(RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + + Reference< XControlModel > xModel; + Event.Element >>= xModel; + if ( xModel.is() ) + ImplRemoveControl( xModel ); +} + +void UnoDialogControl::elementReplaced( const ContainerEvent& Event ) throw(RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + + Reference< XControlModel > xModel; + Event.ReplacedElement >>= xModel; + if ( xModel.is() ) + ImplRemoveControl( xModel ); + + ::rtl::OUString aName; + Event.Accessor >>= aName; + Event.Element >>= xModel; + ImplInsertControl( xModel, aName ); +} + +void UnoDialogControl::addTopWindowListener( const Reference< XTopWindowListener >& rxListener ) throw (RuntimeException) +{ + maTopWindowListeners.addInterface( rxListener ); + if( getPeer().is() && maTopWindowListeners.getLength() == 1 ) + { + Reference < XTopWindow > xTW( getPeer(), UNO_QUERY ); + xTW->addTopWindowListener( &maTopWindowListeners ); + } +} + +void UnoDialogControl::removeTopWindowListener( const Reference< XTopWindowListener >& rxListener ) throw (RuntimeException) +{ + if( getPeer().is() && maTopWindowListeners.getLength() == 1 ) + { + Reference < XTopWindow > xTW( getPeer(), UNO_QUERY ); + xTW->removeTopWindowListener( &maTopWindowListeners ); + } + maTopWindowListeners.removeInterface( rxListener ); +} + +void UnoDialogControl::toFront( ) throw (RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + if ( getPeer().is() ) + { + Reference< XTopWindow > xTW( getPeer(), UNO_QUERY ); + if( xTW.is() ) + xTW->toFront(); + } +} + +void UnoDialogControl::toBack( ) throw (RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + if ( getPeer().is() ) + { + Reference< XTopWindow > xTW( getPeer(), UNO_QUERY ); + if( xTW.is() ) + xTW->toBack(); + } +} + +void UnoDialogControl::setMenuBar( const Reference< XMenuBar >& rxMenuBar ) throw (RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + mxMenuBar = rxMenuBar; + if ( getPeer().is() ) + { + Reference< XTopWindow > xTW( getPeer(), UNO_QUERY ); + if( xTW.is() ) + xTW->setMenuBar( mxMenuBar ); + } +} + +static ::Size ImplMapPixelToAppFont( OutputDevice* pOutDev, const ::Size& aSize ) +{ + ::Size aTmp = pOutDev->PixelToLogic( aSize, MAP_APPFONT ); + return aTmp; +} + +// ::com::sun::star::awt::XWindowListener +void SAL_CALL UnoDialogControl::windowResized( const ::com::sun::star::awt::WindowEvent& e ) +throw (::com::sun::star::uno::RuntimeException) +{ + OutputDevice*pOutDev = Application::GetDefaultDevice(); + DBG_ASSERT( pOutDev, "Missing Default Device!" ); + if ( pOutDev && !mbSizeModified ) + { + // Currentley we are simply using MAP_APPFONT + ::Size aAppFontSize( e.Width, e.Height ); + + Reference< XControl > xDialogControl( *this, UNO_QUERY_THROW ); + Reference< XDevice > xDialogDevice( xDialogControl->getPeer(), UNO_QUERY ); + OSL_ENSURE( xDialogDevice.is(), "UnoDialogControl::windowResized: no peer, but a windowResized event?" ); + if ( xDialogDevice.is() ) + { + DeviceInfo aDeviceInfo( xDialogDevice->getInfo() ); + aAppFontSize.Width() -= aDeviceInfo.LeftInset + aDeviceInfo.RightInset; + aAppFontSize.Height() -= aDeviceInfo.TopInset + aDeviceInfo.BottomInset; + } + + aAppFontSize = ImplMapPixelToAppFont( pOutDev, aAppFontSize ); + + // Remember that changes have been done by listener. No need to + // update the position because of property change event. + mbSizeModified = true; + Sequence< rtl::OUString > aProps( 2 ); + Sequence< Any > aValues( 2 ); + // Properties in a sequence must be sorted! + aProps[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Height" )); + aProps[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" )); + aValues[0] <<= aAppFontSize.Height(); + aValues[1] <<= aAppFontSize.Width(); + + ImplSetPropertyValues( aProps, aValues, true ); + mbSizeModified = false; + } +} + +void SAL_CALL UnoDialogControl::windowMoved( const ::com::sun::star::awt::WindowEvent& e ) +throw (::com::sun::star::uno::RuntimeException) +{ + OutputDevice*pOutDev = Application::GetDefaultDevice(); + DBG_ASSERT( pOutDev, "Missing Default Device!" ); + if ( pOutDev && !mbPosModified ) + { + // Currentley we are simply using MAP_APPFONT + Any aAny; + ::Size aTmp( e.X, e.Y ); + aTmp = ImplMapPixelToAppFont( pOutDev, aTmp ); + + // Remember that changes have been done by listener. No need to + // update the position because of property change event. + mbPosModified = true; + Sequence< rtl::OUString > aProps( 2 ); + Sequence< Any > aValues( 2 ); + aProps[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PositionX" )); + aProps[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PositionY" )); + aValues[0] <<= aTmp.Width(); + aValues[1] <<= aTmp.Height(); + + ImplSetPropertyValues( aProps, aValues, true ); + mbPosModified = false; + } +} + +void SAL_CALL UnoDialogControl::windowShown( const ::com::sun::star::lang::EventObject& e ) +throw (::com::sun::star::uno::RuntimeException) +{ + (void)e; +} + +void SAL_CALL UnoDialogControl::windowHidden( const ::com::sun::star::lang::EventObject& e ) +throw (::com::sun::star::uno::RuntimeException) +{ + (void)e; +} + +// XPropertiesChangeListener +void UnoDialogControl::ImplModelPropertiesChanged( const Sequence< PropertyChangeEvent >& rEvents ) throw(RuntimeException) +{ + if( !isDesignMode() && !mbCreatingCompatiblePeer ) + { + ::rtl::OUString s1( RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) ); + ::rtl::OUString s2( RTL_CONSTASCII_USTRINGPARAM( "PositionY" ) ); + ::rtl::OUString s3( RTL_CONSTASCII_USTRINGPARAM( "Width" ) ); + ::rtl::OUString s4( RTL_CONSTASCII_USTRINGPARAM( "Height" ) ); + + sal_Int32 nLen = rEvents.getLength(); + for( sal_Int32 i = 0; i < nLen; i++ ) + { + const PropertyChangeEvent& rEvt = rEvents.getConstArray()[i]; + Reference< XControlModel > xModel( rEvt.Source, UNO_QUERY ); + sal_Bool bOwnModel = (XControlModel*)xModel.get() == (XControlModel*)getModel().get(); + if ( ( rEvt.PropertyName == s1 ) || + ( rEvt.PropertyName == s2 ) || + ( rEvt.PropertyName == s3 ) || + ( rEvt.PropertyName == s4 ) ) + { + if ( bOwnModel ) + { + if ( !mbPosModified && !mbSizeModified ) + { + // Don't set new pos/size if we get new values from window listener + Reference< XControl > xThis( (XAggregation*)(::cppu::OWeakAggObject*)this, UNO_QUERY ); + ImplSetPosSize( xThis ); + } + } + else + { + Sequence<Reference<XControl> > aControlSequence(getControls()); + Reference<XControl> aControlRef( StdTabController::FindControl( aControlSequence, xModel ) ); + ImplSetPosSize( aControlRef ); + } + break; + } + else if ( bOwnModel && rEvt.PropertyName.equalsAsciiL( "ResourceResolver", 16 )) + { + ImplStartListingForResourceEvents(); + } + } + } + + sal_Int32 nLen = rEvents.getLength(); + for( sal_Int32 i = 0; i < nLen; i++ ) + { + const PropertyChangeEvent& rEvt = rEvents.getConstArray()[i]; + Reference< XControlModel > xModel( rEvt.Source, UNO_QUERY ); + sal_Bool bOwnModel = (XControlModel*)xModel.get() == (XControlModel*)getModel().get(); + if ( bOwnModel && rEvt.PropertyName.equalsAsciiL( "ImageURL", 8 )) + { + ::rtl::OUString aImageURL; + Reference< graphic::XGraphic > xGraphic; + if (( ImplGetPropertyValue( PROPERTY_IMAGEURL ) >>= aImageURL ) && + ( aImageURL.getLength() > 0 )) + { + ::rtl::OUString absoluteUrl = + getPhysicalLocation( ImplGetPropertyValue( PROPERTY_DIALOGSOURCEURL ), + ImplGetPropertyValue( PROPERTY_IMAGEURL )); + + xGraphic = lcl_getGraphicFromURL_nothrow( absoluteUrl ); + } + + ImplSetPropertyValue( PROPERTY_GRAPHIC, uno::makeAny( xGraphic ), sal_True ); + break; + } + } + + UnoControlContainer::ImplModelPropertiesChanged( rEvents ); +} + +void UnoDialogControl::ImplStartListingForResourceEvents() +{ + Reference< resource::XStringResourceResolver > xStringResourceResolver; + + ImplGetPropertyValue( PROPERTY_RESOURCERESOLVER ) >>= xStringResourceResolver; + + // Add our helper as listener to retrieve notifications about changes + Reference< util::XModifyListener > rListener( mxListener ); + ResourceListener* pResourceListener = static_cast< ResourceListener* >( rListener.get() ); + + // resource listener will stop listening if resolver reference is empty + if ( pResourceListener ) + pResourceListener->startListening( xStringResourceResolver ); + ImplUpdateResourceResolver(); +} + +void UnoDialogControl::ImplUpdateResourceResolver() +{ + rtl::OUString aPropName( PROPERTY_RESOURCERESOLVER ); + Reference< resource::XStringResourceResolver > xStringResourceResolver; + + ImplGetPropertyValue( aPropName ) >>= xStringResourceResolver; + if ( !xStringResourceResolver.is() ) + return; + + Any xNewStringResourceResolver; xNewStringResourceResolver <<= xStringResourceResolver; + + Sequence< rtl::OUString > aPropNames(1); + aPropNames[0] = aPropName; + + const Sequence< Reference< awt::XControl > > aSeq = getControls(); + for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ ) + { + Reference< XControl > xControl( aSeq[i] ); + Reference< XPropertySet > xPropertySet; + + if ( xControl.is() ) + xPropertySet = Reference< XPropertySet >( xControl->getModel(), UNO_QUERY ); + + if ( !xPropertySet.is() ) + continue; + + try + { + Reference< resource::XStringResourceResolver > xCurrStringResourceResolver; + Any aOldValue = xPropertySet->getPropertyValue( aPropName ); + if ( ( aOldValue >>= xCurrStringResourceResolver ) + && ( xStringResourceResolver == xCurrStringResourceResolver ) + ) + { + Reference< XMultiPropertySet > xMultiPropSet( xPropertySet, UNO_QUERY ); + Reference< XPropertiesChangeListener > xListener( xPropertySet, UNO_QUERY ); + xMultiPropSet->firePropertiesChangeEvent( aPropNames, xListener ); + } + else + xPropertySet->setPropertyValue( aPropName, xNewStringResourceResolver ); + } + /*catch ( NoSuchElementException& )*/ // that's nonsense, this is never thrown above ... + catch ( const Exception& ) + { + } + } + + // propagate resource resolver changes to language dependent props of the dialog + Reference< XPropertySet > xPropertySet( getModel(), UNO_QUERY ); + if ( xPropertySet.is() ) + { + Reference< XMultiPropertySet > xMultiPropSet( xPropertySet, UNO_QUERY ); + Reference< XPropertiesChangeListener > xListener( xPropertySet, UNO_QUERY ); + xMultiPropSet->firePropertiesChangeEvent( lcl_getLanguageDependentProperties(), xListener ); + } +} + +void UnoDialogControl::setTitle( const ::rtl::OUString& Title ) throw(RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + Any aAny; + aAny <<= Title; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TITLE ), aAny, sal_True ); +} + +::rtl::OUString UnoDialogControl::getTitle() throw(RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + return ImplGetPropertyValue_UString( BASEPROPERTY_TITLE ); +} + +sal_Int16 UnoDialogControl::execute() throw(RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + sal_Int16 nDone = -1; + if ( getPeer().is() ) + { + Reference< XDialog > xDlg( getPeer(), UNO_QUERY ); + if( xDlg.is() ) + { + GetComponentInfos().bVisible = sal_True; + nDone = xDlg->execute(); + GetComponentInfos().bVisible = sal_False; + } + } + return nDone; +} + +void UnoDialogControl::endExecute() throw(RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + if ( getPeer().is() ) + { + Reference< XDialog > xDlg( getPeer(), UNO_QUERY ); + if( xDlg.is() ) + { + xDlg->endExecute(); + GetComponentInfos().bVisible = sal_False; + } + } +} + +void UnoDialogControl::addingControl( const Reference< XControl >& _rxControl ) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + UnoControlContainer::addingControl( _rxControl ); + + if ( _rxControl.is() ) + { + Reference< XMultiPropertySet > xProps( _rxControl->getModel(), UNO_QUERY ); + if ( xProps.is() ) + { + Sequence< ::rtl::OUString > aNames( 4 ); + ::rtl::OUString* pNames = aNames.getArray(); + *pNames++ = ::rtl::OUString::createFromAscii( "PositionX" ); + *pNames++ = ::rtl::OUString::createFromAscii( "PositionY" ); + *pNames++ = ::rtl::OUString::createFromAscii( "Width" ); + *pNames++ = ::rtl::OUString::createFromAscii( "Height" ); + + xProps->addPropertiesChangeListener( aNames, this ); + } + } +} + +void UnoDialogControl::removingControl( const Reference< XControl >& _rxControl ) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + UnoControlContainer::removingControl( _rxControl ); + + if ( _rxControl.is() ) + { + Reference< XMultiPropertySet > xProps( _rxControl->getModel(), UNO_QUERY ); + if ( xProps.is() ) + xProps->removePropertiesChangeListener( this ); + } + +} + +void SAL_CALL UnoDialogControl::changesOccurred( const ChangesEvent& ) throw (RuntimeException) +{ + vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + // a tab controller model may have changed + + // #109067# in design mode don't notify the tab controller + // about tab index changes + if ( mxTabController.is() && !mbDesignMode ) + mxTabController->activateTabOrder(); +} + +// XModifyListener +void SAL_CALL UnoDialogControl::modified( + const lang::EventObject& /*rEvent*/ ) +throw (RuntimeException) +{ + ImplUpdateResourceResolver(); +} + +// ---------------------------------------------------- +// Helper Method to convert relative url to physical location +// ---------------------------------------------------- + +::rtl::OUString getPhysicalLocation( const ::com::sun::star::uno::Any& rbase, const ::com::sun::star::uno::Any& rUrl ) +{ + + + ::rtl::OUString ret; + + ::rtl::OUString baseLocation; + ::rtl::OUString url; + + rbase >>= baseLocation; + rUrl >>= url; + + if ( url.getLength() > 0 ) + { + INetURLObject urlObj(baseLocation); + urlObj.removeSegment(); + baseLocation = urlObj.GetMainURL( INetURLObject::NO_DECODE ); + ::osl::FileBase::getAbsoluteFileURL( baseLocation, url, ret ); + } + + return ret; +} + diff --git a/toolkit/source/controls/eventcontainer.cxx b/toolkit/source/controls/eventcontainer.cxx new file mode 100644 index 000000000000..0cbf9d4e7281 --- /dev/null +++ b/toolkit/source/controls/eventcontainer.cxx @@ -0,0 +1,214 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + + +#include <osl/mutex.hxx> +#include <cppuhelper/queryinterface.hxx> +#ifndef _CPPUHELER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif +#include <cppuhelper/factory.hxx> +#include <cppuhelper/interfacecontainer.hxx> + +#include "toolkit/controls/eventcontainer.hxx" +#include <com/sun/star/script/ScriptEventDescriptor.hpp> + + +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::container; +using namespace com::sun::star::registry; +using namespace com::sun::star::script; +using namespace cppu; +using namespace osl; +using namespace rtl; +using namespace std; + + +namespace toolkit +{ + +// Methods XElementAccess +Type NameContainer_Impl::getElementType() + throw(RuntimeException) +{ + return mType; +} + +sal_Bool NameContainer_Impl::hasElements() + throw(RuntimeException) +{ + sal_Bool bRet = (mnElementCount > 0); + return bRet; +} + +// Methods XNameAccess +Any NameContainer_Impl::getByName( const OUString& aName ) + throw(NoSuchElementException, WrappedTargetException, RuntimeException) +{ + NameContainerNameMap::iterator aIt = mHashMap.find( aName ); + if( aIt == mHashMap.end() ) + { + throw NoSuchElementException(); + } + sal_Int32 iHashResult = (*aIt).second; + Any aRetAny = mValues.getConstArray()[ iHashResult ]; + return aRetAny; +} + +Sequence< OUString > NameContainer_Impl::getElementNames() + throw(RuntimeException) +{ + return mNames; +} + +sal_Bool NameContainer_Impl::hasByName( const OUString& aName ) + throw(RuntimeException) +{ + NameContainerNameMap::iterator aIt = mHashMap.find( aName ); + sal_Bool bRet = ( aIt != mHashMap.end() ); + return bRet; +} + + +// Methods XNameReplace +void NameContainer_Impl::replaceByName( const OUString& aName, const Any& aElement ) + throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException) +{ + Type aAnyType = aElement.getValueType(); + if( mType != aAnyType ) + throw IllegalArgumentException(); + + NameContainerNameMap::iterator aIt = mHashMap.find( aName ); + if( aIt == mHashMap.end() ) + { + throw NoSuchElementException(); + } + sal_Int32 iHashResult = (*aIt).second; + Any aOldElement = mValues.getConstArray()[ iHashResult ]; + mValues.getArray()[ iHashResult ] = aElement; + + // Fire event + ContainerEvent aEvent; + aEvent.Source = *this; + aEvent.Element <<= aElement; + aEvent.ReplacedElement = aOldElement; + aEvent.Accessor <<= aName; + maContainerListeners.elementReplaced( aEvent ); +} + + +// Methods XNameContainer +void NameContainer_Impl::insertByName( const OUString& aName, const Any& aElement ) + throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException) +{ + Type aAnyType = aElement.getValueType(); + if( mType != aAnyType ) + throw IllegalArgumentException(); + + NameContainerNameMap::iterator aIt = mHashMap.find( aName ); + if( aIt != mHashMap.end() ) + { + throw ElementExistException(); + } + + sal_Int32 nCount = mNames.getLength(); + mNames.realloc( nCount + 1 ); + mValues.realloc( nCount + 1 ); + mNames.getArray()[ nCount ] = aName; + mValues.getArray()[ nCount ] = aElement; + mHashMap[ aName ] = nCount; + + // Fire event + ContainerEvent aEvent; + aEvent.Source = *this; + aEvent.Element <<= aElement; + aEvent.Accessor <<= aName; + maContainerListeners.elementInserted( aEvent ); +} + +void NameContainer_Impl::removeByName( const OUString& Name ) + throw(NoSuchElementException, WrappedTargetException, RuntimeException) +{ + NameContainerNameMap::iterator aIt = mHashMap.find( Name ); + if( aIt == mHashMap.end() ) + { + throw NoSuchElementException(); + } + + sal_Int32 iHashResult = (*aIt).second; + Any aOldElement = mValues.getConstArray()[ iHashResult ]; + + // Fire event + ContainerEvent aEvent; + aEvent.Source = *this; + aEvent.Element = aOldElement; + aEvent.Accessor <<= Name; + maContainerListeners.elementRemoved( aEvent ); + + mHashMap.erase( aIt ); + sal_Int32 iLast = mNames.getLength() - 1; + if( iLast != iHashResult ) + { + OUString* pNames = mNames.getArray(); + Any* pValues = mValues.getArray(); + pNames[ iHashResult ] = pNames[ iLast ]; + pValues[ iHashResult ] = pValues[ iLast ]; + mHashMap[ pNames[ iHashResult ] ] = iHashResult; + } + mNames.realloc( iLast ); + mValues.realloc( iLast ); + +} + +// Methods XContainer +void NameContainer_Impl::addContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& l ) throw(::com::sun::star::uno::RuntimeException) +{ + maContainerListeners.addInterface( l ); +} + +void NameContainer_Impl::removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& l ) throw(::com::sun::star::uno::RuntimeException) +{ + maContainerListeners.removeInterface( l ); +} + + + +// Ctor +ScriptEventContainer::ScriptEventContainer( void ) + : NameContainer_Impl( getCppuType( (ScriptEventDescriptor*) NULL ) ) +{ +} + +} + + + + diff --git a/toolkit/source/controls/formattedcontrol.cxx b/toolkit/source/controls/formattedcontrol.cxx new file mode 100644 index 000000000000..67c9c40ebd38 --- /dev/null +++ b/toolkit/source/controls/formattedcontrol.cxx @@ -0,0 +1,468 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <toolkit/controls/formattedcontrol.hxx> +#include <toolkit/helper/unopropertyarrayhelper.hxx> +#include <toolkit/helper/property.hxx> + +#include <com/sun/star/awt/XVclWindowPeer.hpp> +#include <com/sun/star/util/XNumberFormatsSupplier.hpp> + +#include <tools/diagnose_ex.h> +#include <comphelper/processfactory.hxx> +#include <osl/diagnose.h> + +//........................................................................ +namespace toolkit +{ +//........................................................................ + + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::awt; + using namespace ::com::sun::star::lang; + using namespace ::com::sun::star::beans; + using namespace ::com::sun::star::util; + + // ------------------------------------------------------------------- + namespace + { + // ............................................................... + ::osl::Mutex& getDefaultFormatsMutex() + { + static ::osl::Mutex s_aDefaultFormatsMutex; + return s_aDefaultFormatsMutex; + } + + // ............................................................... + Reference< XNumberFormatsSupplier >& lcl_getDefaultFormatsAccess_nothrow() + { + static Reference< XNumberFormatsSupplier > s_xDefaultFormats; + return s_xDefaultFormats; + } + + // ............................................................... + bool& lcl_getTriedCreation() + { + static bool s_bTriedCreation = false; + return s_bTriedCreation; + } + + // ............................................................... + const Reference< XNumberFormatsSupplier >& lcl_getDefaultFormats_throw() + { + ::osl::MutexGuard aGuard( getDefaultFormatsMutex() ); + + bool& rbTriedCreation = lcl_getTriedCreation(); + Reference< XNumberFormatsSupplier >& rDefaultFormats( lcl_getDefaultFormatsAccess_nothrow() ); + if ( !rDefaultFormats.is() && !rbTriedCreation ) + { + rbTriedCreation = true; + rDefaultFormats = Reference< XNumberFormatsSupplier >( + ::comphelper::createProcessComponent( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.NumberFormatsSupplier" ) ) ), + UNO_QUERY_THROW + ); + } + if ( !rDefaultFormats.is() ) + throw RuntimeException(); + + return rDefaultFormats; + } + + // ............................................................... + static oslInterlockedCount s_refCount(0); + + // ............................................................... + void lcl_registerDefaultFormatsClient() + { + osl_incrementInterlockedCount( &s_refCount ); + } + + // ............................................................... + void lcl_revokeDefaultFormatsClient() + { + ::osl::ClearableMutexGuard aGuard( getDefaultFormatsMutex() ); + if ( 0 == osl_decrementInterlockedCount( &s_refCount ) ) + { + Reference< XNumberFormatsSupplier >& rDefaultFormats( lcl_getDefaultFormatsAccess_nothrow() ); + Reference< XNumberFormatsSupplier > xReleasePotentialLastReference( rDefaultFormats ); + rDefaultFormats.clear(); + lcl_getTriedCreation() = false; + + aGuard.clear(); + xReleasePotentialLastReference.clear(); + } + } + } + + // =================================================================== + // = UnoControlFormattedFieldModel + // =================================================================== + // ------------------------------------------------------------------- + UnoControlFormattedFieldModel::UnoControlFormattedFieldModel() + :m_bRevokedAsClient( false ) + ,m_bSettingValueAndText( false ) + { + ImplRegisterProperty( BASEPROPERTY_ALIGN ); + ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR ); + ImplRegisterProperty( BASEPROPERTY_BORDER ); + ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR ); + ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL ); + ImplRegisterProperty( BASEPROPERTY_EFFECTIVE_DEFAULT ); + ImplRegisterProperty( BASEPROPERTY_EFFECTIVE_VALUE ); + ImplRegisterProperty( BASEPROPERTY_EFFECTIVE_MAX ); + ImplRegisterProperty( BASEPROPERTY_EFFECTIVE_MIN ); + ImplRegisterProperty( BASEPROPERTY_ENABLED ); + ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE ); + ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR ); + ImplRegisterProperty( BASEPROPERTY_FORMATKEY ); + ImplRegisterProperty( BASEPROPERTY_FORMATSSUPPLIER ); + ImplRegisterProperty( BASEPROPERTY_HELPTEXT ); + ImplRegisterProperty( BASEPROPERTY_HELPURL ); + ImplRegisterProperty( BASEPROPERTY_MAXTEXTLEN ); + ImplRegisterProperty( BASEPROPERTY_PRINTABLE ); + ImplRegisterProperty( BASEPROPERTY_REPEAT ); + ImplRegisterProperty( BASEPROPERTY_REPEAT_DELAY ); + ImplRegisterProperty( BASEPROPERTY_READONLY ); + ImplRegisterProperty( BASEPROPERTY_SPIN ); + ImplRegisterProperty( BASEPROPERTY_STRICTFORMAT ); + ImplRegisterProperty( BASEPROPERTY_TABSTOP ); + ImplRegisterProperty( BASEPROPERTY_TEXT ); + ImplRegisterProperty( BASEPROPERTY_TEXTCOLOR ); + ImplRegisterProperty( BASEPROPERTY_HIDEINACTIVESELECTION ); + ImplRegisterProperty( BASEPROPERTY_ENFORCE_FORMAT ); + ImplRegisterProperty( BASEPROPERTY_VERTICALALIGN ); + ImplRegisterProperty( BASEPROPERTY_WRITING_MODE ); + ImplRegisterProperty( BASEPROPERTY_CONTEXT_WRITING_MODE ); + ImplRegisterProperty( BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR ); + + Any aTreatAsNumber; + aTreatAsNumber <<= (sal_Bool) sal_True; + ImplRegisterProperty( BASEPROPERTY_TREATASNUMBER, aTreatAsNumber ); + + lcl_registerDefaultFormatsClient(); + } + + // ------------------------------------------------------------------- + UnoControlFormattedFieldModel::~UnoControlFormattedFieldModel() + { + } + + // ------------------------------------------------------------------- + ::rtl::OUString UnoControlFormattedFieldModel::getServiceName() throw(RuntimeException) + { + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlFormattedFieldModel ); + } + + // ------------------------------------------------------------------- + void SAL_CALL UnoControlFormattedFieldModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw (Exception) + { + UnoControlModel::setFastPropertyValue_NoBroadcast( nHandle, rValue ); + + switch ( nHandle ) + { + case BASEPROPERTY_EFFECTIVE_VALUE: + if ( !m_bSettingValueAndText ) + impl_updateTextFromValue_nothrow(); + break; + case BASEPROPERTY_FORMATSSUPPLIER: + impl_updateCachedFormatter_nothrow(); + impl_updateTextFromValue_nothrow(); + break; + case BASEPROPERTY_FORMATKEY: + impl_updateCachedFormatKey_nothrow(); + impl_updateTextFromValue_nothrow(); + break; + } + } + + // ------------------------------------------------------------------- + void UnoControlFormattedFieldModel::impl_updateTextFromValue_nothrow() + { + if ( !m_xCachedFormatter.is() ) + impl_updateCachedFormatter_nothrow(); + if ( !m_xCachedFormatter.is() ) + return; + + try + { + Any aEffectiveValue; + getFastPropertyValue( aEffectiveValue, BASEPROPERTY_EFFECTIVE_VALUE ); + + ::rtl::OUString sStringValue; + if ( !( aEffectiveValue >>= sStringValue ) ) + { + double nDoubleValue(0); + if ( aEffectiveValue >>= nDoubleValue ) + { + sal_Int32 nFormatKey( 0 ); + if ( m_aCachedFormat.hasValue() ) + m_aCachedFormat >>= nFormatKey; + sStringValue = m_xCachedFormatter->convertNumberToString( nFormatKey, nDoubleValue ); + } + } + + Reference< XPropertySet > xThis( *this, UNO_QUERY ); + xThis->setPropertyValue( GetPropertyName( BASEPROPERTY_TEXT ), makeAny( sStringValue ) ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + + // ------------------------------------------------------------------- + void UnoControlFormattedFieldModel::impl_updateCachedFormatter_nothrow() + { + Any aFormatsSupplier; + getFastPropertyValue( aFormatsSupplier, BASEPROPERTY_FORMATSSUPPLIER ); + try + { + Reference< XNumberFormatsSupplier > xSupplier( aFormatsSupplier, UNO_QUERY ); + if ( !xSupplier.is() ) + xSupplier = lcl_getDefaultFormats_throw(); + + if ( !m_xCachedFormatter.is() ) + { + m_xCachedFormatter = Reference< XNumberFormatter >( + ::comphelper::createProcessComponent( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.NumberFormatter" ) ) ), + UNO_QUERY_THROW + ); + } + m_xCachedFormatter->attachNumberFormatsSupplier( xSupplier ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + + // ------------------------------------------------------------------- + void UnoControlFormattedFieldModel::impl_updateCachedFormatKey_nothrow() + { + Any aFormatKey; + getFastPropertyValue( aFormatKey, BASEPROPERTY_FORMATKEY ); + m_aCachedFormat = aFormatKey; + } + + // ------------------------------------------------------------------- + void UnoControlFormattedFieldModel::dispose( ) throw(RuntimeException) + { + UnoControlModel::dispose(); + + ::osl::MutexGuard aGuard( GetMutex() ); + if ( !m_bRevokedAsClient ) + { + lcl_revokeDefaultFormatsClient(); + m_bRevokedAsClient = true; + } + } + + // ------------------------------------------------------------------- + void UnoControlFormattedFieldModel::ImplNormalizePropertySequence( const sal_Int32 _nCount, sal_Int32* _pHandles, + Any* _pValues, sal_Int32* _pValidHandles ) const SAL_THROW(()) + { + ImplEnsureHandleOrder( _nCount, _pHandles, _pValues, BASEPROPERTY_EFFECTIVE_VALUE, BASEPROPERTY_TEXT ); + + UnoControlModel::ImplNormalizePropertySequence( _nCount, _pHandles, _pValues, _pValidHandles ); + } + + // ------------------------------------------------------------------- + namespace + { + class ResetFlagOnExit + { + private: + bool& m_rFlag; + + public: + ResetFlagOnExit( bool& _rFlag ) + :m_rFlag( _rFlag ) + { + } + ~ResetFlagOnExit() + { + m_rFlag = false; + } + }; + } + + // ------------------------------------------------------------------- + void SAL_CALL UnoControlFormattedFieldModel::setPropertyValues( const Sequence< ::rtl::OUString >& _rPropertyNames, const Sequence< Any >& _rValues ) throw(PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException) + { + bool bSettingValue = false; + bool bSettingText = false; + for ( const ::rtl::OUString* pPropertyNames = _rPropertyNames.getConstArray(); + pPropertyNames != _rPropertyNames.getConstArray() + _rPropertyNames.getLength(); + ++pPropertyNames + ) + { + if ( BASEPROPERTY_EFFECTIVE_VALUE == GetPropertyId( *pPropertyNames ) ) + bSettingValue = true; + + if ( BASEPROPERTY_TEXT == GetPropertyId( *pPropertyNames ) ) + bSettingText = true; + } + + m_bSettingValueAndText = ( bSettingValue && bSettingText ); + ResetFlagOnExit aResetFlag( m_bSettingValueAndText ); + UnoControlModel::setPropertyValues( _rPropertyNames, _rValues ); + } + + // ------------------------------------------------------------------- + sal_Bool UnoControlFormattedFieldModel::convertFastPropertyValue( + Any& rConvertedValue, Any& rOldValue, sal_Int32 nPropId, + const Any& rValue ) throw (IllegalArgumentException) + { + if ( BASEPROPERTY_EFFECTIVE_DEFAULT == nPropId && rValue.hasValue() ) + { + double dVal = 0; + sal_Int32 nVal = 0; + ::rtl::OUString sVal; + sal_Bool bStreamed = (rValue >>= dVal); + if ( bStreamed ) + { + rConvertedValue <<= dVal; + } + else + { + bStreamed = (rValue >>= nVal); + if ( bStreamed ) + { + rConvertedValue <<= static_cast<double>(nVal); + } + else + { + bStreamed = (rValue >>= sVal); + if ( bStreamed ) + { + rConvertedValue <<= sVal; + } + } + } + + if ( bStreamed ) + { + getFastPropertyValue( rOldValue, nPropId ); + return !CompareProperties( rConvertedValue, rOldValue ); + } + + throw IllegalArgumentException( + ( ::rtl::OUString::createFromAscii("Unable to convert the given value for the property ") + += GetPropertyName((sal_uInt16)nPropId) ) + += ::rtl::OUString::createFromAscii(" (double, integer, or string expected)."), + static_cast< XPropertySet* >(this), + 1); + } + + return UnoControlModel::convertFastPropertyValue( rConvertedValue, rOldValue, nPropId, rValue ); + } + + // ------------------------------------------------------------------- + Any UnoControlFormattedFieldModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const + { + Any aReturn; + switch (nPropId) + { + case BASEPROPERTY_DEFAULTCONTROL: aReturn <<= ::rtl::OUString( ::rtl::OUString::createFromAscii( szServiceName_UnoControlFormattedField ) ); break; + + case BASEPROPERTY_TREATASNUMBER: aReturn <<= (sal_Bool)sal_True; break; + + case BASEPROPERTY_EFFECTIVE_DEFAULT: + case BASEPROPERTY_EFFECTIVE_VALUE: + case BASEPROPERTY_EFFECTIVE_MAX: + case BASEPROPERTY_EFFECTIVE_MIN: + case BASEPROPERTY_FORMATKEY: + case BASEPROPERTY_FORMATSSUPPLIER: + // (void) + break; + + default : aReturn = UnoControlModel::ImplGetDefaultValue( nPropId ); break; + } + + return aReturn; + } + + // ------------------------------------------------------------------- + ::cppu::IPropertyArrayHelper& UnoControlFormattedFieldModel::getInfoHelper() + { + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; + } + + // beans::XMultiPropertySet + // ------------------------------------------------------------------- + Reference< XPropertySetInfo > UnoControlFormattedFieldModel::getPropertySetInfo( ) throw(RuntimeException) + { + static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; + } + + // =================================================================== + // = UnoFormattedFieldControl + // =================================================================== + // ------------------------------------------------------------------- + UnoFormattedFieldControl::UnoFormattedFieldControl() + { + } + + // ------------------------------------------------------------------- + ::rtl::OUString UnoFormattedFieldControl::GetComponentServiceName() + { + return ::rtl::OUString::createFromAscii( "FormattedField" ); + } + + // ------------------------------------------------------------------- + void UnoFormattedFieldControl::textChanged(const TextEvent& e) throw(RuntimeException) + { + Reference< XVclWindowPeer > xPeer(getPeer(), UNO_QUERY); + OSL_ENSURE(xPeer.is(), "UnoFormattedFieldControl::textChanged : what kind of peer do I have ?"); + + Sequence< ::rtl::OUString > aNames( 2 ); + aNames[0] = GetPropertyName( BASEPROPERTY_EFFECTIVE_VALUE ); + aNames[1] = GetPropertyName( BASEPROPERTY_TEXT ); + + Sequence< Any > aValues( 2 ); + aValues[0] = xPeer->getProperty( aNames[0] ); + aValues[1] = xPeer->getProperty( aNames[1] ); + + ImplSetPropertyValues( aNames, aValues, FALSE ); + + if ( GetTextListeners().getLength() ) + GetTextListeners().textChanged( e ); + } + +//........................................................................ +} // namespace toolkit +//........................................................................ diff --git a/toolkit/source/controls/geometrycontrolmodel.cxx b/toolkit/source/controls/geometrycontrolmodel.cxx new file mode 100644 index 000000000000..ac8a6e83ae28 --- /dev/null +++ b/toolkit/source/controls/geometrycontrolmodel.cxx @@ -0,0 +1,653 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include "toolkit/controls/geometrycontrolmodel.hxx" +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <osl/diagnose.h> +#include <rtl/instance.hxx> +#include <comphelper/property.hxx> +#include <comphelper/sequence.hxx> +#ifndef _COM_SUN_STAR_XNAMECONTAINER_HPP_ +#include <toolkit/controls/eventcontainer.hxx> +#endif +#include <toolkit/helper/property.hxx> +#include <tools/debug.hxx> +#include <algorithm> +#include <functional> +#include <comphelper/sequence.hxx> + + +#define GCM_PROPERTY_ID_POS_X 1 +#define GCM_PROPERTY_ID_POS_Y 2 +#define GCM_PROPERTY_ID_WIDTH 3 +#define GCM_PROPERTY_ID_HEIGHT 4 +#define GCM_PROPERTY_ID_NAME 5 +#define GCM_PROPERTY_ID_TABINDEX 6 +#define GCM_PROPERTY_ID_STEP 7 +#define GCM_PROPERTY_ID_TAG 8 +#define GCM_PROPERTY_ID_RESOURCERESOLVER 9 + +#define GCM_PROPERTY_POS_X ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PositionX")) +#define GCM_PROPERTY_POS_Y ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PositionY")) +#define GCM_PROPERTY_WIDTH ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Width")) +#define GCM_PROPERTY_HEIGHT ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Height")) +#define GCM_PROPERTY_NAME ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name")) +#define GCM_PROPERTY_TABINDEX ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TabIndex")) +#define GCM_PROPERTY_STEP ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Step")) +#define GCM_PROPERTY_TAG ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Tag")) +#define GCM_PROPERTY_RESOURCERESOLVER ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ResourceResolver")) + +#define DEFAULT_ATTRIBS() PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT + +//........................................................................ +// namespace toolkit +// { +//........................................................................ + + using namespace ::com::sun::star; + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::lang; + using namespace ::com::sun::star::beans; + using namespace ::com::sun::star::util; + using namespace ::com::sun::star::container; + using namespace ::comphelper; + + //==================================================================== + //= OGeometryControlModel_Base + //==================================================================== + //-------------------------------------------------------------------- + OGeometryControlModel_Base::OGeometryControlModel_Base(::com::sun::star::uno::XAggregation* _pAggregateInstance) + :OPropertySetAggregationHelper( m_aBHelper ) + ,OPropertyContainer( m_aBHelper ) + ,OGCM_Base( m_aMutex ) + ,m_nPosX(0) + ,m_nPosY(0) + ,m_nWidth(0) + ,m_nHeight(0) + ,m_nTabIndex(-1) + ,m_nStep(0) + ,m_bCloneable(sal_False) + { + OSL_ENSURE(NULL != _pAggregateInstance, "OGeometryControlModel_Base::OGeometryControlModel_Base: invalid aggregate!"); + + increment(m_refCount); + { + m_xAggregate = _pAggregateInstance; + + { // check if the aggregat is cloneable + Reference< XCloneable > xCloneAccess(m_xAggregate, UNO_QUERY); + m_bCloneable = xCloneAccess.is(); + } + + setAggregation(m_xAggregate); + m_xAggregate->setDelegator(static_cast< XWeak* >(this)); + } + decrement(m_refCount); + + registerProperties(); + } + + //-------------------------------------------------------------------- + OGeometryControlModel_Base::OGeometryControlModel_Base(Reference< XCloneable >& _rxAggregateInstance) + :OPropertySetAggregationHelper( m_aBHelper ) + ,OPropertyContainer( m_aBHelper ) + ,OGCM_Base( m_aMutex ) + ,m_nPosX(0) + ,m_nPosY(0) + ,m_nWidth(0) + ,m_nHeight(0) + ,m_nTabIndex(-1) + ,m_nStep(0) + ,m_bCloneable(_rxAggregateInstance.is()) + { + increment(m_refCount); + { + { + // ensure that the temporary gets destructed NOW + m_xAggregate = Reference< XAggregation >(_rxAggregateInstance, UNO_QUERY); + } + OSL_ENSURE(m_xAggregate.is(), "OGeometryControlModel_Base::OGeometryControlModel_Base: invalid object given!"); + + // now the aggregate has a ref count of 2, but before setting the delegator it must be 1 + _rxAggregateInstance.clear(); + // now it should be the 1 we need here ... + + setAggregation(m_xAggregate); + m_xAggregate->setDelegator(static_cast< XWeak* >(this)); + } + decrement(m_refCount); + + registerProperties(); + } + + //-------------------------------------------------------------------- + Sequence< Type > SAL_CALL OGeometryControlModel_Base::getTypes( ) throw (RuntimeException) + { + // our own types + Sequence< Type > aTypes = ::comphelper::concatSequences( + OPropertySetAggregationHelper::getTypes(), + OPropertyContainer::getTypes(), + OGCM_Base::getTypes() + ); + + if ( m_xAggregate.is() ) + { + // retrieve the types of the aggregate + Reference< XTypeProvider > xAggregateTypeProv; + m_xAggregate->queryAggregation( ::getCppuType( &xAggregateTypeProv ) ) >>= xAggregateTypeProv; + OSL_ENSURE( xAggregateTypeProv.is(), "OGeometryControlModel_Base::getTypes: aggregate should be a type provider!" ); + Sequence< Type > aAggTypes; + if ( xAggregateTypeProv.is() ) + aAggTypes = xAggregateTypeProv->getTypes(); + + // concat the sequences + sal_Int32 nOldSize = aTypes.getLength(); + aTypes.realloc( nOldSize + aAggTypes.getLength() ); + ::std::copy( + aAggTypes.getConstArray(), + aAggTypes.getConstArray() + aAggTypes.getLength(), + aTypes.getArray() + nOldSize + ); + } + + return aTypes; + } + + //-------------------------------------------------------------------- + void OGeometryControlModel_Base::registerProperties() + { + // register our members for the property handling of the OPropertyContainer + registerProperty(GCM_PROPERTY_POS_X, GCM_PROPERTY_ID_POS_X, DEFAULT_ATTRIBS(), &m_nPosX, ::getCppuType(&m_nPosX)); + registerProperty(GCM_PROPERTY_POS_Y, GCM_PROPERTY_ID_POS_Y, DEFAULT_ATTRIBS(), &m_nPosY, ::getCppuType(&m_nPosY)); + registerProperty(GCM_PROPERTY_WIDTH, GCM_PROPERTY_ID_WIDTH, DEFAULT_ATTRIBS(), &m_nWidth, ::getCppuType(&m_nWidth)); + registerProperty(GCM_PROPERTY_HEIGHT, GCM_PROPERTY_ID_HEIGHT, DEFAULT_ATTRIBS(), &m_nHeight, ::getCppuType(&m_nHeight)); + registerProperty(GCM_PROPERTY_NAME, GCM_PROPERTY_ID_NAME, DEFAULT_ATTRIBS(), &m_aName, ::getCppuType(&m_aName)); + registerProperty(GCM_PROPERTY_TABINDEX, GCM_PROPERTY_ID_TABINDEX, DEFAULT_ATTRIBS(), &m_nTabIndex, ::getCppuType(&m_nTabIndex)); + registerProperty(GCM_PROPERTY_STEP, GCM_PROPERTY_ID_STEP, DEFAULT_ATTRIBS(), &m_nStep, ::getCppuType(&m_nStep)); + registerProperty(GCM_PROPERTY_TAG, GCM_PROPERTY_ID_TAG, DEFAULT_ATTRIBS(), &m_aTag, ::getCppuType(&m_aTag)); + registerProperty(GCM_PROPERTY_RESOURCERESOLVER, GCM_PROPERTY_ID_RESOURCERESOLVER, DEFAULT_ATTRIBS(), &m_xStrResolver, ::getCppuType(&m_xStrResolver)); + } + + //-------------------------------------------------------------------- + ::com::sun::star::uno::Any OGeometryControlModel_Base::ImplGetDefaultValueByHandle(sal_Int32 nHandle) const + { + ::com::sun::star::uno::Any aDefault; + + switch ( nHandle ) + { + case GCM_PROPERTY_ID_POS_X: aDefault <<= (sal_Int32) 0; break; + case GCM_PROPERTY_ID_POS_Y: aDefault <<= (sal_Int32) 0; break; + case GCM_PROPERTY_ID_WIDTH: aDefault <<= (sal_Int32) 0; break; + case GCM_PROPERTY_ID_HEIGHT: aDefault <<= (sal_Int32) 0; break; + case GCM_PROPERTY_ID_NAME: aDefault <<= ::rtl::OUString(); break; + case GCM_PROPERTY_ID_TABINDEX: aDefault <<= (sal_Int16) -1; break; + case GCM_PROPERTY_ID_STEP: aDefault <<= (sal_Int32) 0; break; + case GCM_PROPERTY_ID_TAG: aDefault <<= ::rtl::OUString(); break; + case GCM_PROPERTY_ID_RESOURCERESOLVER: aDefault <<= Reference< resource::XStringResourceResolver >(); break; + default: DBG_ERROR( "ImplGetDefaultValueByHandle - unknown Property" ); + } + + return aDefault; + } + + //-------------------------------------------------------------------- + ::com::sun::star::uno::Any OGeometryControlModel_Base::ImplGetPropertyValueByHandle(sal_Int32 nHandle) const + { + ::com::sun::star::uno::Any aValue; + + switch ( nHandle ) + { + case GCM_PROPERTY_ID_POS_X: aValue <<= m_nPosX; break; + case GCM_PROPERTY_ID_POS_Y: aValue <<= m_nPosY; break; + case GCM_PROPERTY_ID_WIDTH: aValue <<= m_nWidth; break; + case GCM_PROPERTY_ID_HEIGHT: aValue <<= m_nHeight; break; + case GCM_PROPERTY_ID_NAME: aValue <<= m_aName; break; + case GCM_PROPERTY_ID_TABINDEX: aValue <<= m_nTabIndex; break; + case GCM_PROPERTY_ID_STEP: aValue <<= m_nStep; break; + case GCM_PROPERTY_ID_TAG: aValue <<= m_aTag; break; + case GCM_PROPERTY_ID_RESOURCERESOLVER: aValue <<= m_xStrResolver; break; + default: DBG_ERROR( "ImplGetPropertyValueByHandle - unknown Property" ); + } + + return aValue; + } + + //-------------------------------------------------------------------- + void OGeometryControlModel_Base::ImplSetPropertyValueByHandle(sal_Int32 nHandle, const :: com::sun::star::uno::Any& aValue) + { + switch ( nHandle ) + { + case GCM_PROPERTY_ID_POS_X: aValue >>= m_nPosX; break; + case GCM_PROPERTY_ID_POS_Y: aValue >>= m_nPosY; break; + case GCM_PROPERTY_ID_WIDTH: aValue >>= m_nWidth; break; + case GCM_PROPERTY_ID_HEIGHT: aValue >>= m_nHeight; break; + case GCM_PROPERTY_ID_NAME: aValue >>= m_aName; break; + case GCM_PROPERTY_ID_TABINDEX: aValue >>= m_nTabIndex; break; + case GCM_PROPERTY_ID_STEP: aValue >>= m_nStep; break; + case GCM_PROPERTY_ID_TAG: aValue >>= m_aTag; break; + case GCM_PROPERTY_ID_RESOURCERESOLVER: aValue >>= m_xStrResolver; break; + default: DBG_ERROR( "ImplSetPropertyValueByHandle - unknown Property" ); + } + } + + //-------------------------------------------------------------------- + Any SAL_CALL OGeometryControlModel_Base::queryAggregation( const Type& _rType ) throw(RuntimeException) + { + Any aReturn; + if (_rType.equals(::getCppuType(static_cast< Reference< XCloneable>* >(NULL))) && !m_bCloneable) + // somebody is asking for the XCloneable interface, but our aggregate does not support it + // -> outta here + // (need this extra check, cause OGCM_Base::queryAggregation would return this interface + // in every case) + return aReturn; + + aReturn = OGCM_Base::queryAggregation(_rType); + // the basic interfaces (XInterface, XAggregation etc) + + if (!aReturn.hasValue()) + aReturn = OPropertySetAggregationHelper::queryInterface(_rType); + // the property set related interfaces + + if (!aReturn.hasValue() && m_xAggregate.is()) + aReturn = m_xAggregate->queryAggregation(_rType); + // the interfaces our aggregate can provide + + return aReturn; + } + + //-------------------------------------------------------------------- + Any SAL_CALL OGeometryControlModel_Base::queryInterface( const Type& _rType ) throw(RuntimeException) + { + return OGCM_Base::queryInterface(_rType); + } + + //-------------------------------------------------------------------- + void SAL_CALL OGeometryControlModel_Base::acquire( ) throw() + { + OGCM_Base::acquire(); + } + + //-------------------------------------------------------------------- + void SAL_CALL OGeometryControlModel_Base::release( ) throw() + { + OGCM_Base::release(); + } + + //-------------------------------------------------------------------- + void OGeometryControlModel_Base::releaseAggregation() + { + // release the aggregate (_before_ clearing m_xAggregate) + if (m_xAggregate.is()) + m_xAggregate->setDelegator(NULL); + setAggregation(NULL); + } + + //-------------------------------------------------------------------- + OGeometryControlModel_Base::~OGeometryControlModel_Base() + { + releaseAggregation(); + } + + //-------------------------------------------------------------------- + sal_Bool SAL_CALL OGeometryControlModel_Base::convertFastPropertyValue(Any& _rConvertedValue, Any& _rOldValue, + sal_Int32 _nHandle, const Any& _rValue) throw (IllegalArgumentException) + { + return OPropertyContainer::convertFastPropertyValue(_rConvertedValue, _rOldValue, _nHandle, _rValue); + } + + //-------------------------------------------------------------------- + void SAL_CALL OGeometryControlModel_Base::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle, const Any& _rValue) throw (Exception) + { + OPropertyContainer::setFastPropertyValue_NoBroadcast(_nHandle, _rValue); + } + + //-------------------------------------------------------------------- + void SAL_CALL OGeometryControlModel_Base::getFastPropertyValue(Any& _rValue, sal_Int32 _nHandle) const + { + OPropertyArrayAggregationHelper& rPH = static_cast<OPropertyArrayAggregationHelper&>(const_cast<OGeometryControlModel_Base*>(this)->getInfoHelper()); + ::rtl::OUString sPropName; + sal_Int32 nOriginalHandle = -1; + + if (rPH.fillAggregatePropertyInfoByHandle(&sPropName, &nOriginalHandle, _nHandle)) + OPropertySetAggregationHelper::getFastPropertyValue(_rValue, _nHandle); + else + OPropertyContainer::getFastPropertyValue(_rValue, _nHandle); + } + + //-------------------------------------------------------------------- + ::com::sun::star::beans::PropertyState OGeometryControlModel_Base::getPropertyStateByHandle(sal_Int32 nHandle) + { + ::com::sun::star::uno::Any aValue = ImplGetPropertyValueByHandle( nHandle ); + ::com::sun::star::uno::Any aDefault = ImplGetDefaultValueByHandle( nHandle ); + + return CompareProperties( aValue, aDefault ) ? ::com::sun::star::beans::PropertyState_DEFAULT_VALUE : ::com::sun::star::beans::PropertyState_DIRECT_VALUE; + } + + //-------------------------------------------------------------------- + void OGeometryControlModel_Base::setPropertyToDefaultByHandle(sal_Int32 nHandle) + { + ImplSetPropertyValueByHandle( nHandle , ImplGetDefaultValueByHandle( nHandle ) ); + } + + //-------------------------------------------------------------------- + ::com::sun::star::uno::Any OGeometryControlModel_Base::getPropertyDefaultByHandle( sal_Int32 nHandle ) const + { + return ImplGetDefaultValueByHandle( nHandle ); + } + + //-------------------------------------------------------------------- + Reference< XPropertySetInfo> SAL_CALL OGeometryControlModel_Base::getPropertySetInfo() throw(RuntimeException) + { + return OPropertySetAggregationHelper::createPropertySetInfo(getInfoHelper()); + } + + //-------------------------------------------------------------------- + Reference< XCloneable > SAL_CALL OGeometryControlModel_Base::createClone( ) throw(RuntimeException) + { + OSL_ENSURE(m_bCloneable, "OGeometryControlModel_Base::createClone: invalid call!"); + if (!m_bCloneable) + return Reference< XCloneable >(); + + // let the aggregate create it's own clone + // the interface + Reference< XCloneable > xCloneAccess; + m_xAggregate->queryAggregation(::getCppuType(&xCloneAccess)) >>= xCloneAccess; + OSL_ENSURE(xCloneAccess.is(), "OGeometryControlModel_Base::createClone: suspicious aggregate!"); + if (!xCloneAccess.is()) + return Reference< XCloneable >(); + // the aggregate's clone + Reference< XCloneable > xAggregateClone = xCloneAccess->createClone(); + OSL_ENSURE(xAggregateClone.is(), "OGeometryControlModel_Base::createClone: suspicious return of the aggregate!"); + + // create a new wrapper aggregating this return value + OGeometryControlModel_Base* pOwnClone = createClone_Impl(xAggregateClone); + OSL_ENSURE(pOwnClone, "OGeometryControlModel_Base::createClone: invalid derivee behaviour!"); + OSL_ENSURE(!xAggregateClone.is(), "OGeometryControlModel_Base::createClone: invalid ctor behaviour!"); + // should have been reset + + // set properties + pOwnClone->m_nPosX = m_nPosX; + pOwnClone->m_nPosY = m_nPosY; + pOwnClone->m_nWidth = m_nWidth; + pOwnClone->m_nHeight = m_nHeight; + pOwnClone->m_aName = m_aName; + pOwnClone->m_nTabIndex = m_nTabIndex; + pOwnClone->m_nStep = m_nStep; + pOwnClone->m_aTag = m_aTag; + + + // Clone event container + Reference< ::com::sun::star::script::XScriptEventsSupplier > xEventsSupplier = + static_cast< ::com::sun::star::script::XScriptEventsSupplier* >( this ); + Reference< ::com::sun::star::script::XScriptEventsSupplier > xCloneEventsSupplier = + static_cast< ::com::sun::star::script::XScriptEventsSupplier* >( pOwnClone ); + + if( xEventsSupplier.is() && xCloneEventsSupplier.is() ) + { + Reference< XNameContainer > xEventCont = xEventsSupplier->getEvents(); + Reference< XNameContainer > xCloneEventCont = xCloneEventsSupplier->getEvents(); + + ::com::sun::star::uno::Sequence< ::rtl::OUString > aNames = + xEventCont->getElementNames(); + const ::rtl::OUString* pNames = aNames.getConstArray(); + sal_Int32 i, nNameCount = aNames.getLength(); + + for( i = 0 ; i < nNameCount ; i++ ) + { + ::rtl::OUString aName = pNames[ i ]; + ::com::sun::star::uno::Any aElement = xEventCont->getByName( aName ); + xCloneEventCont->insertByName( aName, aElement ); + } + } + + return pOwnClone; + } + + //-------------------------------------------------------------------- + Reference< XNameContainer > SAL_CALL OGeometryControlModel_Base::getEvents() throw(RuntimeException) + { + if( !mxEventContainer.is() ) + mxEventContainer = (XNameContainer*)new toolkit::ScriptEventContainer(); + return mxEventContainer; + } + + //-------------------------------------------------------------------- + void SAL_CALL OGeometryControlModel_Base::disposing() + { + OGCM_Base::disposing(); + OPropertySetAggregationHelper::disposing(); + + Reference<XComponent> xComp; + if ( query_aggregation( m_xAggregate, xComp ) ) + xComp->dispose(); + } + + //==================================================================== + //= OCommonGeometryControlModel + //==================================================================== + //-------------------------------------------------------------------- + + typedef ::std::hash_map< ::rtl::OUString, sal_Int32, ::comphelper::UStringHash > HashMapString2Int; + typedef ::std::vector< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > > PropSeqArray; + typedef ::std::vector< ::std::vector< sal_Int32 > > IntArrayArray; + + // for creating class-unique PropertySetInfo's, we need some info: + namespace { struct ServiceSpecifierMap : public rtl::Static< HashMapString2Int, ServiceSpecifierMap > {}; } + // this one maps from a String, which is the service specifier for our + // aggregate, to a unique id + + namespace { struct AggregateProperties : public rtl::Static< PropSeqArray, AggregateProperties > {}; } + // this one contains the properties which belong to all the unique ids + // in ServiceSpecifierMap + + namespace { struct AmbiguousPropertyIds : public rtl::Static< IntArrayArray, AmbiguousPropertyIds > {}; } + // the ids of the properties which we as well as our aggregate supply + // For such props, we let our base class handle them, and whenever such + // a prop is set, we forward this to our aggregate. + + // With this, we can ensure that two instances of this class share the + // same PropertySetInfo if and only if both aggregates have the same + // service specifier. + + + //-------------------------------------------------------------------- + OCommonGeometryControlModel::OCommonGeometryControlModel( Reference< XCloneable >& _rxAgg, const ::rtl::OUString& _rServiceSpecifier ) + :OGeometryControlModel_Base( _rxAgg ) + ,m_sServiceSpecifier( _rServiceSpecifier ) + ,m_nPropertyMapId( 0 ) + { + Reference< XPropertySetInfo > xPI; + if ( m_xAggregateSet.is() ) + xPI = m_xAggregateSet->getPropertySetInfo(); + if ( !xPI.is() ) + { + releaseAggregation(); + throw IllegalArgumentException(); + } + + HashMapString2Int &rMap = ServiceSpecifierMap::get(); + HashMapString2Int::iterator aPropMapIdPos = rMap.find( m_sServiceSpecifier ); + if ( rMap.end() == aPropMapIdPos ) + { + PropSeqArray &rAggProperties = AggregateProperties::get(); + m_nPropertyMapId = rAggProperties.size(); + rAggProperties.push_back( xPI->getProperties() ); + AmbiguousPropertyIds::get().push_back( IntArrayArray::value_type() ); + + rMap[ m_sServiceSpecifier ] = m_nPropertyMapId; + } + else + m_nPropertyMapId = aPropMapIdPos->second; + } + + //-------------------------------------------------------------------- + struct PropertyNameLess : public ::std::binary_function< Property, Property, bool > + { + bool operator()( const Property& _rLHS, const Property& _rRHS ) + { + return _rLHS.Name < _rRHS.Name ? true : false; + } + }; + + //-------------------------------------------------------------------- + struct PropertyNameEqual : public ::std::unary_function< Property, bool > + { + const ::rtl::OUString& m_rCompare; + PropertyNameEqual( const ::rtl::OUString& _rCompare ) : m_rCompare( _rCompare ) { } + + bool operator()( const Property& _rLHS ) + { + return _rLHS.Name == m_rCompare ? true : false; + } + }; + + //-------------------------------------------------------------------- + ::cppu::IPropertyArrayHelper* OCommonGeometryControlModel::createArrayHelper( sal_Int32 _nId ) const + { + OSL_ENSURE( _nId == m_nPropertyMapId, "OCommonGeometryControlModel::createArrayHelper: invalid argument!" ); + OSL_ENSURE( _nId < (sal_Int32)AggregateProperties::get().size(), "OCommonGeometryControlModel::createArrayHelper: invalid status info (1)!" ); + OSL_ENSURE( _nId < (sal_Int32)AmbiguousPropertyIds::get().size(), "OCommonGeometryControlModel::createArrayHelper: invalid status info (2)!" ); + + // our own properties + Sequence< Property > aProps; + OPropertyContainer::describeProperties( aProps ); + + // the aggregate properties + Sequence< Property > aAggregateProps; + aAggregateProps = AggregateProperties::get()[ _nId ]; + + // look for duplicates, and remember them + IntArrayArray::value_type& rDuplicateIds = AmbiguousPropertyIds::get()[ _nId ]; + // for this, sort the aggregate properties + ::std::sort( + aAggregateProps.getArray(), + aAggregateProps.getArray() + aAggregateProps.getLength(), + PropertyNameLess() + ); + const Property* pAggProps = aAggregateProps.getConstArray(); + const Property* pAggPropsEnd = aAggregateProps.getConstArray() + aAggregateProps.getLength(); + + // now loop through our own props + const Property* pProp = aProps.getConstArray(); + const Property* pPropEnd = aProps.getConstArray() + aProps.getLength(); + while ( pProp < pPropEnd ) + { + // look for the current property in the properties of our aggregate + const Property* pAggPropPos = ::std::find_if( pAggProps, pAggPropsEnd, PropertyNameEqual( pProp->Name ) ); + if ( pAggPropPos != pAggPropsEnd ) + { // found a duplicate + // -> remove from the aggregate property sequence + ::comphelper::removeElementAt( aAggregateProps, pAggPropPos - pAggProps ); + // which means we have to adjust the pointers + pAggProps = aAggregateProps.getConstArray(), + pAggPropsEnd = aAggregateProps.getConstArray() + aAggregateProps.getLength(), + + // and additionally, remember the id of this property + rDuplicateIds.push_back( pProp->Handle ); + } + + ++pProp; + } + + // now, finally, sort the duplicates + ::std::sort( rDuplicateIds.begin(), rDuplicateIds.end(), ::std::less< sal_Int32 >() ); + + return new OPropertyArrayAggregationHelper(aProps, aAggregateProps); + } + + //-------------------------------------------------------------------- + ::cppu::IPropertyArrayHelper& SAL_CALL OCommonGeometryControlModel::getInfoHelper() + { + return *getArrayHelper( m_nPropertyMapId ); + } + + //-------------------------------------------------------------------- + OGeometryControlModel_Base* OCommonGeometryControlModel::createClone_Impl( Reference< XCloneable >& _rxAggregateInstance ) + { + return new OCommonGeometryControlModel( _rxAggregateInstance, m_sServiceSpecifier ); + } + + //-------------------------------------------------------------------- + Sequence< sal_Int8 > SAL_CALL OCommonGeometryControlModel::getImplementationId( ) throw (RuntimeException) + { + static ::cppu::OImplementationId * pId = NULL; + if ( !pId ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if ( !pId ) + { + static ::cppu::OImplementationId s_aId; + pId = &s_aId; + } + } + return pId->getImplementationId(); + } + + //-------------------------------------------------------------------- + struct Int32Equal : public ::std::unary_function< sal_Int32, bool > + { + sal_Int32 m_nCompare; + Int32Equal( sal_Int32 _nCompare ) : m_nCompare( _nCompare ) { } + + bool operator()( sal_Int32 _nLHS ) + { + return _nLHS == m_nCompare ? true : false; + } + }; + + //-------------------------------------------------------------------- + void SAL_CALL OCommonGeometryControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception ) + { + OGeometryControlModel_Base::setFastPropertyValue_NoBroadcast( _nHandle, _rValue ); + + // look if this id is one we recognized as duplicate + IntArrayArray::value_type& rDuplicateIds = AmbiguousPropertyIds::get()[ m_nPropertyMapId ]; + + IntArrayArray::value_type::const_iterator aPos = ::std::find_if( + rDuplicateIds.begin(), + rDuplicateIds.end(), + Int32Equal( _nHandle ) + ); + + if ( rDuplicateIds.end() != aPos ) + { + // yes, it is such a property + ::rtl::OUString sPropName; + sal_Int16 nAttributes(0); + static_cast< OPropertyArrayAggregationHelper* >( getArrayHelper( m_nPropertyMapId ) )->fillPropertyMembersByHandle( &sPropName, &nAttributes, _nHandle ); + + if ( m_xAggregateSet.is() && sPropName.getLength() ) + m_xAggregateSet->setPropertyValue( sPropName, _rValue ); + } + } + +//........................................................................ +// } // namespace toolkit +//........................................................................ diff --git a/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx b/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx new file mode 100644 index 000000000000..fdf91d6a6593 --- /dev/null +++ b/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx @@ -0,0 +1,239 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include "defaultgridcolumnmodel.hxx" +#include <comphelper/sequence.hxx> +#include <toolkit/helper/servicenames.hxx> +#include <rtl/ref.hxx> + +using ::rtl::OUString; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::awt::grid; +using namespace ::com::sun::star::lang; + +#define COLUMNSELECTIONALLOWED ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ColumnSelectionAllowed" )) + +namespace toolkit +{ + +/////////////////////////////////////////////////////////////////////// +// class DefaultGridColumnModel +/////////////////////////////////////////////////////////////////////// + +DefaultGridColumnModel::DefaultGridColumnModel() +: columns(std::vector< Reference< XGridColumn > >()) +{ +} + +//--------------------------------------------------------------------- + +DefaultGridColumnModel::~DefaultGridColumnModel() +{ +} + +//--------------------------------------------------------------------- + +void DefaultGridColumnModel::broadcast( broadcast_type eType, const GridColumnEvent& aEvent ) +{ + ::cppu::OInterfaceContainerHelper* pIter = BrdcstHelper.getContainer( XGridColumnListener::static_type() ); + if( pIter ) + { + ::cppu::OInterfaceIteratorHelper aListIter(*pIter); + while(aListIter.hasMoreElements()) + { + XGridColumnListener* pListener = static_cast<XGridColumnListener*>(aListIter.next()); + switch( eType ) + { + case column_added: pListener->columnAdded(aEvent); break; + case column_removed: pListener->columnRemoved(aEvent); break; + case column_changed: pListener->columnChanged(aEvent); break; + } + } + } +} + +//--------------------------------------------------------------------- + +void DefaultGridColumnModel::broadcast_changed( ::rtl::OUString name, Any oldValue, Any newValue ) +{ + Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); + GridColumnEvent aEvent( xSource, name, oldValue, newValue, 0, NULL ); + broadcast( column_changed, aEvent); +} + +//--------------------------------------------------------------------- + +void DefaultGridColumnModel::broadcast_add( sal_Int32 index, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & rColumn ) +{ + Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); + GridColumnEvent aEvent( xSource, ::rtl::OUString(), Any(), Any(), index, rColumn ); + broadcast( column_added, aEvent); +} + +//--------------------------------------------------------------------- + +void DefaultGridColumnModel::broadcast_remove( sal_Int32 index, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & rColumn ) +{ + Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); + GridColumnEvent aEvent( xSource, ::rtl::OUString(), Any(), Any(), index, rColumn ); + broadcast( column_changed, aEvent); +} + +//--------------------------------------------------------------------- +// XDefaultGridColumnModel +//--------------------------------------------------------------------- +::sal_Bool SAL_CALL DefaultGridColumnModel::getColumnSelectionAllowed() throw (::com::sun::star::uno::RuntimeException) +{ + return selectionAllowed; +} + +//--------------------------------------------------------------------- + +void SAL_CALL DefaultGridColumnModel::setColumnSelectionAllowed(::sal_Bool value) throw (::com::sun::star::uno::RuntimeException) +{ + sal_Bool oldValue = selectionAllowed; + selectionAllowed = value; + broadcast_changed( COLUMNSELECTIONALLOWED, Any(oldValue) , Any(selectionAllowed)); +} + +//--------------------------------------------------------------------- + +::sal_Int32 SAL_CALL DefaultGridColumnModel::getColumnCount() throw (::com::sun::star::uno::RuntimeException) +{ + return columns.size(); +} + +//--------------------------------------------------------------------- + +::sal_Int32 SAL_CALL DefaultGridColumnModel::addColumn(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & column) throw (::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + columns.push_back(column); + + sal_Int32 index = columns.size() - 1; + broadcast_add(index, column ); + return index; +} + +//--------------------------------------------------------------------- + +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > > SAL_CALL DefaultGridColumnModel::getColumns() throw (::com::sun::star::uno::RuntimeException) +{ + return comphelper::containerToSequence(columns); +} + +//--------------------------------------------------------------------- + +::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > SAL_CALL DefaultGridColumnModel::getColumn(::sal_Int32 index) throw (::com::sun::star::uno::RuntimeException) +{ + if ( index >=0 && index < ((sal_Int32)columns.size())) + return columns[index]; + else + return Reference< XGridColumn >(); +} + +void SAL_CALL DefaultGridColumnModel::addColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException) +{ + BrdcstHelper.addListener( XGridColumnListener::static_type(), xListener ); +} + +//--------------------------------------------------------------------- + +void SAL_CALL DefaultGridColumnModel::removeColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException) +{ + BrdcstHelper.removeListener( XGridColumnListener::static_type(), xListener ); +} + +//--------------------------------------------------------------------- +// XComponent +//--------------------------------------------------------------------- + +void SAL_CALL DefaultGridColumnModel::dispose() throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::lang::EventObject aEvent; + aEvent.Source.set( static_cast< ::cppu::OWeakObject* >( this ) ); + BrdcstHelper.aLC.disposeAndClear( aEvent ); + +} + +//--------------------------------------------------------------------- + +void SAL_CALL DefaultGridColumnModel::addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException) +{ + BrdcstHelper.addListener( XEventListener::static_type(), xListener ); +} + +//--------------------------------------------------------------------- + +void SAL_CALL DefaultGridColumnModel::removeEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException) +{ + BrdcstHelper.removeListener( XEventListener::static_type(), xListener ); +} + +//--------------------------------------------------------------------- +// XServiceInfo +//--------------------------------------------------------------------- + +::rtl::OUString SAL_CALL DefaultGridColumnModel::getImplementationName( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + static const OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "toolkit.DefaultGridColumnModel" ) ); + return aImplName; +} + +//--------------------------------------------------------------------- + +sal_Bool SAL_CALL DefaultGridColumnModel::supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + return ServiceName.equalsAscii( szServiceName_DefaultGridColumnModel ); +} + +//--------------------------------------------------------------------- + +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL DefaultGridColumnModel::getSupportedServiceNames( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + static const OUString aServiceName( OUString::createFromAscii( szServiceName_DefaultGridColumnModel ) ); + static const Sequence< OUString > aSeq( &aServiceName, 1 ); + return aSeq; +} + +} + +Reference< XInterface > SAL_CALL DefaultGridColumnModel_CreateInstance( const Reference< XMultiServiceFactory >& ) +{ + return Reference < XInterface >( ( ::cppu::OWeakObject* ) new ::toolkit::DefaultGridColumnModel ); +} + diff --git a/toolkit/source/controls/grid/defaultgridcolumnmodel.hxx b/toolkit/source/controls/grid/defaultgridcolumnmodel.hxx new file mode 100644 index 000000000000..896427ce3e2b --- /dev/null +++ b/toolkit/source/controls/grid/defaultgridcolumnmodel.hxx @@ -0,0 +1,93 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <com/sun/star/awt/grid/XGridColumnModel.hpp> +#include <com/sun/star/awt/grid/XGridColumn.hpp> +#include <com/sun/star/awt/grid/GridColumnEvent.hpp> +#include <com/sun/star/lang/XEventListener.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/implbase3.hxx> +#include <rtl/ref.hxx> +#include <vector> +#include <toolkit/helper/mutexandbroadcasthelper.hxx> + +using ::rtl::OUString; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::awt::grid; +using namespace ::com::sun::star::lang; + +namespace toolkit +{ + +enum broadcast_type { column_added, column_removed, column_changed}; + +class DefaultGridColumnModel : public ::cppu::WeakImplHelper2< XGridColumnModel, XServiceInfo >, + public MutexAndBroadcastHelper +{ +public: + DefaultGridColumnModel(); + virtual ~DefaultGridColumnModel(); + + // XGridColumnModel + + virtual ::sal_Bool SAL_CALL getColumnSelectionAllowed() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setColumnSelectionAllowed(::sal_Bool the_value) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getColumnCount() throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL addColumn(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & column) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > > SAL_CALL getColumns() throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > SAL_CALL getColumn(::sal_Int32 index) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException); + virtual void SAL_CALL removeColumnListener( const Reference< XGridColumnListener >& xListener ) throw (RuntimeException); + + // XComponent + virtual void SAL_CALL dispose( ) throw (RuntimeException); + virtual void SAL_CALL addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException); + virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& aListener ) throw (RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (RuntimeException); + virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException); + +private: + + void broadcast( broadcast_type eType, const GridColumnEvent& aEvent ); + void broadcast_changed( ::rtl::OUString name, Any oldValue, Any newValue ); + void broadcast_add( sal_Int32 index,const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & rColumn ); + void broadcast_remove( sal_Int32 index, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > & rColumn ); + + std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumn > > columns; + sal_Bool selectionAllowed; +}; + +} diff --git a/toolkit/source/controls/grid/defaultgriddatamodel.cxx b/toolkit/source/controls/grid/defaultgriddatamodel.cxx new file mode 100644 index 000000000000..70c79e0bcbfa --- /dev/null +++ b/toolkit/source/controls/grid/defaultgriddatamodel.cxx @@ -0,0 +1,307 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include "defaultgriddatamodel.hxx" +#include <comphelper/sequence.hxx> +#include <toolkit/helper/servicenames.hxx> +#include <rtl/ref.hxx> + +using ::rtl::OUString; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::awt::grid; +using namespace ::com::sun::star::lang; + +#define ROWHEIGHT ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "RowHeight" )) +#define ROWHEADERS ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "RowHeaders" )) + +namespace toolkit +{ + +/////////////////////////////////////////////////////////////////////// +// class DefaultGridDataModel +/////////////////////////////////////////////////////////////////////// + +DefaultGridDataModel::DefaultGridDataModel() +: rowHeight(0), + rowHeaders(std::vector< ::rtl::OUString >()) +{ +} + +//--------------------------------------------------------------------- + +DefaultGridDataModel::~DefaultGridDataModel() +{ +} + +void DefaultGridDataModel::broadcast( broadcast_type eType, const GridDataEvent& aEvent ) +{ + ::cppu::OInterfaceContainerHelper* pIter = BrdcstHelper.getContainer( XGridDataListener::static_type() ); + if( pIter ) + { + ::cppu::OInterfaceIteratorHelper aListIter(*pIter); + while(aListIter.hasMoreElements()) + { + XGridDataListener* pListener = static_cast<XGridDataListener*>(aListIter.next()); + switch( eType ) + { + case row_added: pListener->rowAdded(aEvent); break; + case row_removed: pListener->rowRemoved(aEvent); break; + case data_changed: pListener->dataChanged(aEvent); break; + } + } + } +} + +//--------------------------------------------------------------------- + +void DefaultGridDataModel::broadcast_changed( ::rtl::OUString name, Any oldValue, Any newValue ) +{ + Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); + GridDataEvent aEvent( xSource, name, oldValue, newValue, 0, ::rtl::OUString(), Sequence< ::rtl::OUString>() ); + broadcast( data_changed, aEvent); +} + +//--------------------------------------------------------------------- + +void DefaultGridDataModel::broadcast_add( sal_Int32 index, const ::rtl::OUString & headerName, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rowData ) +{ + Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); + GridDataEvent aEvent( xSource, ::rtl::OUString(), Any(), Any(), index, headerName, rowData ); + broadcast( row_added, aEvent); +} + +//--------------------------------------------------------------------- + +void DefaultGridDataModel::broadcast_remove( sal_Int32 index, const ::rtl::OUString & headerName, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rowData ) +{ + Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); + GridDataEvent aEvent( xSource, ::rtl::OUString(), Any(), Any(), index, headerName, rowData ); + broadcast( row_removed, aEvent); +} + +//--------------------------------------------------------------------- + +//--------------------------------------------------------------------- +// XDefaultGridDataModel +//--------------------------------------------------------------------- +::sal_Int32 SAL_CALL DefaultGridDataModel::getRowHeight() throw (::com::sun::star::uno::RuntimeException) +{ + return rowHeight; +} + +//--------------------------------------------------------------------- + +void SAL_CALL DefaultGridDataModel::setRowHeight(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException) +{ + sal_Int32 oldValue = rowHeight; + rowHeight = value; + + broadcast_changed( ROWHEIGHT, Any(oldValue), Any(value) ); +} + +//--------------------------------------------------------------------- + +::sal_Int32 SAL_CALL DefaultGridDataModel::getRowCount() throw (::com::sun::star::uno::RuntimeException) +{ + return data.size(); +} + +//--------------------------------------------------------------------- + +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL DefaultGridDataModel::getRowHeaders() throw (::com::sun::star::uno::RuntimeException) +{ + return comphelper::containerToSequence(rowHeaders); +} + +//--------------------------------------------------------------------- + +void SAL_CALL DefaultGridDataModel::setRowHeaders(const ::com::sun::star::uno::Sequence< ::rtl::OUString > & value) throw (::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Sequence< ::rtl::OUString > oldValue( comphelper::containerToSequence(rowHeaders) ); + + std::vector< rtl::OUString>::iterator iterator; + int i = 0; + int sequenceSize = value.getLength(); + + for(iterator = rowHeaders.begin(); iterator != rowHeaders.end(); iterator++) + { + if ( sequenceSize > i ) + *iterator = value[i]; + else + *iterator = ::rtl::OUString(); + i++; + } + + broadcast_changed( ROWHEADERS, Any(oldValue), Any(comphelper::containerToSequence(rowHeaders)) ); +} + +//--------------------------------------------------------------------- + +void SAL_CALL DefaultGridDataModel::addRow(const ::rtl::OUString & headername, const ::com::sun::star::uno::Sequence< ::rtl::OUString > & rRowdata) throw (::com::sun::star::uno::RuntimeException) +{ + // store header name + rowHeaders.push_back(headername); + + + // store row data + std::vector< rtl::OUString > newRow( + comphelper::sequenceToContainer< std::vector<rtl::OUString > >(rRowdata)); + + data.push_back( newRow ); + + broadcast_add( data.size()-1, headername, rRowdata); + +} + +//--------------------------------------------------------------------- + +void SAL_CALL DefaultGridDataModel::removeRow(::sal_Int32 index) throw (::com::sun::star::uno::RuntimeException) +{ + if ( index >= 0 && index <= getRowCount()-1) + { + /* if(Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->isSelectedIndex( index )) + { + ::com::sun::star::uno::Sequence<::sal_Int32> selectedRows = Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->getSelection(); + selectedRow.erase(selectedRows.begin()+index); + }*/ + + ::rtl::OUString headerName( (::rtl::OUString) rowHeaders[index] ); + rowHeaders.erase(rowHeaders.begin() + index); + + Sequence< ::rtl::OUString >& rowData ( (Sequence< ::rtl::OUString >&)data[index] ); + data.erase(data.begin() + index); + broadcast_remove( index, headerName, rowData); + } + else + return; +} +//--------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > > SAL_CALL DefaultGridDataModel::getData() throw (::com::sun::star::uno::RuntimeException) +{ + + std::vector< std::vector< ::rtl::OUString > >::iterator iterator; + std::vector< Sequence< ::rtl::OUString > > dummyContainer(0); + + + for(iterator = data.begin(); iterator != data.end(); iterator++) + { + Sequence< ::rtl::OUString > cols(comphelper::containerToSequence(*iterator)); + dummyContainer.push_back( cols ); + } + Sequence< Sequence< ::rtl::OUString > > dataSequence(comphelper::containerToSequence(dummyContainer)); + + return dataSequence; +} + +//--------------------------------------------------------------------- + +void SAL_CALL DefaultGridDataModel::addDataListener( const Reference< XGridDataListener >& xListener ) throw (RuntimeException) +{ + BrdcstHelper.addListener( XGridDataListener::static_type(), xListener ); +} + +//--------------------------------------------------------------------- + +void SAL_CALL DefaultGridDataModel::removeDataListener( const Reference< XGridDataListener >& xListener ) throw (RuntimeException) +{ + BrdcstHelper.removeListener( XGridDataListener::static_type(), xListener ); +} + +void SAL_CALL DefaultGridDataModel::removeAll() throw (RuntimeException) +{ + rowHeaders.clear(); + data.clear(); + broadcast_remove( -1, ::rtl::OUString(), 0); +} + +//--------------------------------------------------------------------- +// XComponent +//--------------------------------------------------------------------- + +void SAL_CALL DefaultGridDataModel::dispose() throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::lang::EventObject aEvent; + aEvent.Source.set( static_cast< ::cppu::OWeakObject* >( this ) ); + BrdcstHelper.aLC.disposeAndClear( aEvent ); + +} + +//--------------------------------------------------------------------- + +void SAL_CALL DefaultGridDataModel::addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException) +{ + BrdcstHelper.addListener( XEventListener::static_type(), xListener ); +} + +//--------------------------------------------------------------------- + +void SAL_CALL DefaultGridDataModel::removeEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException) +{ + BrdcstHelper.removeListener( XEventListener::static_type(), xListener ); +} +//--------------------------------------------------------------------- +// XServiceInfo +//--------------------------------------------------------------------- + +::rtl::OUString SAL_CALL DefaultGridDataModel::getImplementationName( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + static const OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "toolkit.DefaultGridDataModel" ) ); + return aImplName; +} + +//--------------------------------------------------------------------- + +sal_Bool SAL_CALL DefaultGridDataModel::supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + return ServiceName.equalsAscii( szServiceName_DefaultGridDataModel ); +} + +//--------------------------------------------------------------------- + +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL DefaultGridDataModel::getSupportedServiceNames( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + static const OUString aServiceName( OUString::createFromAscii( szServiceName_DefaultGridDataModel ) ); + static const Sequence< OUString > aSeq( &aServiceName, 1 ); + return aSeq; +} + +} + +Reference< XInterface > SAL_CALL DefaultGridDataModel_CreateInstance( const Reference< XMultiServiceFactory >& ) +{ + return Reference < XInterface >( ( ::cppu::OWeakObject* ) new ::toolkit::DefaultGridDataModel ); +} + diff --git a/toolkit/source/controls/grid/defaultgriddatamodel.hxx b/toolkit/source/controls/grid/defaultgriddatamodel.hxx new file mode 100644 index 000000000000..1aebc07bc2a8 --- /dev/null +++ b/toolkit/source/controls/grid/defaultgriddatamodel.hxx @@ -0,0 +1,96 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <com/sun/star/awt/grid/XGridDataModel.hpp> +#include <com/sun/star/awt/grid/GridDataEvent.hpp> +#include <com/sun/star/awt/grid/XGridDataListener.hpp> +#include <com/sun/star/lang/XEventListener.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/implbase3.hxx> +#include <rtl/ref.hxx> +#include <vector> +#include <toolkit/helper/mutexandbroadcasthelper.hxx> + +using ::rtl::OUString; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::awt::grid; +using namespace ::com::sun::star::lang; + +namespace toolkit +{ + +enum broadcast_type { row_added, row_removed, data_changed}; + +class DefaultGridDataModel : public ::cppu::WeakImplHelper2< XGridDataModel, XServiceInfo >, + public MutexAndBroadcastHelper +{ +public: + DefaultGridDataModel(); + virtual ~DefaultGridDataModel(); + + // XGridDataModel + virtual ::sal_Int32 SAL_CALL getRowHeight() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setRowHeight(::sal_Int32 the_value) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getRowCount() throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getRowHeaders() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setRowHeaders(const ::com::sun::star::uno::Sequence< ::rtl::OUString > & value) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > > SAL_CALL getData() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addRow(const ::rtl::OUString & headername, const ::com::sun::star::uno::Sequence< ::rtl::OUString > & data) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeRow(::sal_Int32 index) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addDataListener( const Reference< XGridDataListener >& xListener ) throw (RuntimeException); + virtual void SAL_CALL removeDataListener( const Reference< XGridDataListener >& xListener ) throw (RuntimeException); + virtual void SAL_CALL removeAll() throw (RuntimeException); + + // XComponent + virtual void SAL_CALL dispose( ) throw (RuntimeException); + virtual void SAL_CALL addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException); + virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& aListener ) throw (RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (RuntimeException); + virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException); + +private: + + void broadcast( broadcast_type eType, const GridDataEvent& aEvent ); + void broadcast_changed( ::rtl::OUString name, Any oldValue, Any newValue ); + void broadcast_add( sal_Int32 index, const ::rtl::OUString & headerName, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rowData ); + void broadcast_remove( sal_Int32 index, const ::rtl::OUString & headerName, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rowData ); + + sal_Int32 rowHeight; + std::vector< std::vector < ::rtl::OUString > > data; + std::vector< ::rtl::OUString > rowHeaders; +}; + +} diff --git a/toolkit/source/controls/grid/gridcolumn.cxx b/toolkit/source/controls/grid/gridcolumn.cxx new file mode 100644 index 000000000000..39c4960351d3 --- /dev/null +++ b/toolkit/source/controls/grid/gridcolumn.cxx @@ -0,0 +1,163 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include "gridcolumn.hxx" +#include <comphelper/sequence.hxx> +#include <toolkit/helper/servicenames.hxx> +#include <rtl/ref.hxx> + +using ::rtl::OUString; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::awt::grid; +using namespace ::com::sun::star::lang; + +namespace toolkit +{ + +/////////////////////////////////////////////////////////////////////// +// class GridColumn +/////////////////////////////////////////////////////////////////////// + +GridColumn::GridColumn() +: identifier(Any()) +{ +} + +//--------------------------------------------------------------------- + +GridColumn::~GridColumn() +{ +} + +//--------------------------------------------------------------------- + +//--------------------------------------------------------------------- +// XGridColumn +//--------------------------------------------------------------------- + +::com::sun::star::uno::Any SAL_CALL GridColumn::getIdentifier() throw (::com::sun::star::uno::RuntimeException) +{ + return identifier; +} + +//--------------------------------------------------------------------- + +void SAL_CALL GridColumn::setIdentifier(const ::com::sun::star::uno::Any & value) throw (::com::sun::star::uno::RuntimeException) +{ + value >>= identifier; +} + +//-------------------------------------------------------------------- + +::sal_Int32 SAL_CALL GridColumn::getColumnWidth() throw (::com::sun::star::uno::RuntimeException) +{ + return columnWidth; +} + +//-------------------------------------------------------------------- + +void SAL_CALL GridColumn::setColumnWidth(::sal_Int32 value) throw (::com::sun::star::uno::RuntimeException) +{ + columnWidth = value; +} + +//-------------------------------------------------------------------- + +::rtl::OUString SAL_CALL GridColumn::getTitle() throw (::com::sun::star::uno::RuntimeException) +{ + return title; +} + +//-------------------------------------------------------------------- + +void SAL_CALL GridColumn::setTitle(const ::rtl::OUString & value) throw (::com::sun::star::uno::RuntimeException) +{ + title = value; +} + +//--------------------------------------------------------------------- +// XComponent +//--------------------------------------------------------------------- + +void SAL_CALL GridColumn::dispose() throw (RuntimeException) +{ +} + +//--------------------------------------------------------------------- + +void SAL_CALL GridColumn::addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException) +{ + (void) xListener; +} + +//--------------------------------------------------------------------- + +void SAL_CALL GridColumn::removeEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException) +{ + (void) xListener; +} + +//--------------------------------------------------------------------- +// XServiceInfo +//--------------------------------------------------------------------- + +::rtl::OUString SAL_CALL GridColumn::getImplementationName( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + static const OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "toolkit.GridColumn" ) ); + return aImplName; +} + +//--------------------------------------------------------------------- + +sal_Bool SAL_CALL GridColumn::supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + return ServiceName.equalsAscii( szServiceName_GridColumn ); +} + +//--------------------------------------------------------------------- + +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL GridColumn::getSupportedServiceNames( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + static const OUString aServiceName( OUString::createFromAscii( szServiceName_GridColumn ) ); + static const Sequence< OUString > aSeq( &aServiceName, 1 ); + return aSeq; +} + +} + +Reference< XInterface > SAL_CALL GridColumn_CreateInstance( const Reference< XMultiServiceFactory >& ) +{ + return Reference < XInterface >( ( ::cppu::OWeakObject* ) new ::toolkit::GridColumn ); +} + diff --git a/toolkit/source/controls/grid/gridcolumn.hxx b/toolkit/source/controls/grid/gridcolumn.hxx new file mode 100644 index 000000000000..7f6d104127ec --- /dev/null +++ b/toolkit/source/controls/grid/gridcolumn.hxx @@ -0,0 +1,82 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <com/sun/star/awt/grid/XGridColumn.hpp> +#include <com/sun/star/lang/XEventListener.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/implbase3.hxx> +#include <rtl/ref.hxx> +#include <vector> +#include <toolkit/helper/mutexandbroadcasthelper.hxx> + +using ::rtl::OUString; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::awt::grid; +using namespace ::com::sun::star::lang; + +namespace toolkit +{ + +class GridColumn : public ::cppu::WeakImplHelper2< XGridColumn, XServiceInfo >, + public MutexAndBroadcastHelper +{ +public: + GridColumn(); + virtual ~GridColumn(); + + // XGridColumn + virtual ::com::sun::star::uno::Any SAL_CALL getIdentifier() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setIdentifier(const ::com::sun::star::uno::Any & value) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getColumnWidth() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setColumnWidth(::sal_Int32 the_value) throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getTitle() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setTitle(const ::rtl::OUString & value) throw (::com::sun::star::uno::RuntimeException); + + // XComponent + virtual void SAL_CALL dispose( ) throw (RuntimeException); + virtual void SAL_CALL addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException); + virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& aListener ) throw (RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (RuntimeException); + virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException); + + +private: + Any identifier; + sal_Int32 columnWidth; + ::rtl::OUString title; +}; + +} diff --git a/toolkit/source/controls/grid/gridcontrol.cxx b/toolkit/source/controls/grid/gridcontrol.cxx new file mode 100644 index 000000000000..f19648ab0af2 --- /dev/null +++ b/toolkit/source/controls/grid/gridcontrol.cxx @@ -0,0 +1,270 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + +#include <gridcontrol.hxx> + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/view/SelectionType.hpp> +#include <com/sun/star/awt/grid/XGridDataModel.hpp> +#include <com/sun/star/awt/grid/ScrollBarMode.hpp> +#include <toolkit/helper/unopropertyarrayhelper.hxx> +#include <toolkit/helper/property.hxx> +#include <com/sun/star/awt/XVclWindowPeer.hpp> +#include <comphelper/processfactory.hxx> +#include <osl/diagnose.h> + +using ::rtl::OUString; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::awt::grid; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::view; + +namespace toolkit +{ +// ---------------------------------------------------- +// class UnoGridModel +// ---------------------------------------------------- +UnoGridModel::UnoGridModel() +{ + ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR ); + ImplRegisterProperty( BASEPROPERTY_BORDER ); + ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR ); + ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL ); + ImplRegisterProperty( BASEPROPERTY_ENABLED ); + ImplRegisterProperty( BASEPROPERTY_FILLCOLOR ); + ImplRegisterProperty( BASEPROPERTY_HELPTEXT ); + ImplRegisterProperty( BASEPROPERTY_HELPURL ); + ImplRegisterProperty( BASEPROPERTY_PRINTABLE ); + ImplRegisterProperty( BASEPROPERTY_SIZEABLE ); // resizeable + ImplRegisterProperty( BASEPROPERTY_HSCROLL ); + ImplRegisterProperty( BASEPROPERTY_VSCROLL ); + ImplRegisterProperty( BASEPROPERTY_GRID_SHOWROWHEADER ); + ImplRegisterProperty( BASEPROPERTY_GRID_SHOWCOLUMNHEADER ); + ImplRegisterProperty( BASEPROPERTY_GRID_DATAMODEL ); + ImplRegisterProperty( BASEPROPERTY_GRID_COLUMNMODEL ); + ImplRegisterProperty( BASEPROPERTY_GRID_SELECTIONMODE ); + +} + +UnoGridModel::UnoGridModel( const UnoGridModel& rModel ) +: UnoControlModel( rModel ) +{ +} + +UnoControlModel* UnoGridModel::Clone() const +{ + return new UnoGridModel( *this ); +} + +OUString UnoGridModel::getServiceName() throw(RuntimeException) +{ + return OUString::createFromAscii( szServiceName_GridControlModel ); +} + +Any UnoGridModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + switch( nPropId ) + { + case BASEPROPERTY_DEFAULTCONTROL: + return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_GridControl ) ); + case BASEPROPERTY_GRID_SELECTIONMODE: + return uno::makeAny( SelectionType(1) ); + default: + return UnoControlModel::ImplGetDefaultValue( nPropId ); + } + +} + +::cppu::IPropertyArrayHelper& UnoGridModel::getInfoHelper() +{ + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + +// XMultiPropertySet +Reference< XPropertySetInfo > UnoGridModel::getPropertySetInfo( ) throw(RuntimeException) +{ + static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + + +// ---------------------------------------------------- +// class UnoGridControl +// ---------------------------------------------------- +UnoGridControl::UnoGridControl() +: mSelectionMode(SelectionType(1)) +{ +} + +OUString UnoGridControl::GetComponentServiceName() +{ + return OUString::createFromAscii( "Grid" ); +} + +void SAL_CALL UnoGridControl::dispose( ) throw(RuntimeException) +{ + UnoControl::dispose(); +} + +void UnoGridControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) +{ + UnoControlBase::createPeer( rxToolkit, rParentPeer ); + + Reference< XGridControl > xGrid( getPeer(), UNO_QUERY_THROW ); + + Reference<XGridDataListener> xListener ( getPeer(), UNO_QUERY_THROW ); + Reference<XPropertySet> xPropSet ( getModel(), UNO_QUERY_THROW ); + + Reference<XGridDataModel> xGridDataModel ( xPropSet->getPropertyValue(OUString::createFromAscii( "GridDataModel" )), UNO_QUERY_THROW ); + xGridDataModel->addDataListener(xListener); +} + + +// ------------------------------------------------------------------- +// XGridControl +// ------------------------------------------------------------------- + +::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumnModel > SAL_CALL UnoGridControl::getColumnModel() throw (::com::sun::star::uno::RuntimeException) +{ + Reference<XPropertySet> xPropSet ( getModel(), UNO_QUERY_THROW ); + Reference<XGridColumnModel> xGridColumnModel ( xPropSet->getPropertyValue(OUString::createFromAscii( "ColumnModel" )), UNO_QUERY_THROW ); + + return xGridColumnModel; +} + +void SAL_CALL UnoGridControl::setColumnModel(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumnModel > & model) throw (::com::sun::star::uno::RuntimeException) +{ + Reference<XPropertySet> xPropSet ( getModel(), UNO_QUERY_THROW ); + xPropSet->setPropertyValue(OUString::createFromAscii( "ColumnModel" ), Any (model)); +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridDataModel > SAL_CALL UnoGridControl::getDataModel() throw (::com::sun::star::uno::RuntimeException) +{ + Reference<XPropertySet> xPropSet ( getModel(), UNO_QUERY_THROW ); + Reference<XGridDataModel> xGridDataModel ( xPropSet->getPropertyValue(OUString::createFromAscii( "GridDataModel" )), UNO_QUERY_THROW ); + + return xGridDataModel; +} + +void SAL_CALL UnoGridControl::setDataModel(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridDataModel > & model) throw (::com::sun::star::uno::RuntimeException) +{ + Reference<XPropertySet> xPropSet ( getModel(), UNO_QUERY_THROW ); + xPropSet->setPropertyValue(OUString::createFromAscii( "GridDataModel" ), Any(model)); +} + +::sal_Int32 UnoGridControl::getItemIndexAtPoint(::sal_Int32 x, ::sal_Int32 y) throw (::com::sun::star::uno::RuntimeException) +{ + return Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->getItemIndexAtPoint( x, y ); +} + +/* +void SAL_CALL UnoGridControl::addMouseListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener > & listener) throw (::com::sun::star::uno::RuntimeException) +{ + Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->addMouseListener( listener ); +} + +void SAL_CALL UnoGridControl::removeMouseListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener > & listener) throw (::com::sun::star::uno::RuntimeException) +{ + Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->removeMouseListener( listener ); +} +*/ +// ------------------------------------------------------------------- +// XGridSelection +// ------------------------------------------------------------------- + +::sal_Int32 SAL_CALL UnoGridControl::getMinSelectionIndex() throw (::com::sun::star::uno::RuntimeException) +{ + return Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->getMinSelectionIndex(); +} + +::sal_Int32 SAL_CALL UnoGridControl::getMaxSelectionIndex() throw (::com::sun::star::uno::RuntimeException) +{ + return Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->getMaxSelectionIndex(); +} + +void SAL_CALL UnoGridControl::insertIndexIntervall(::sal_Int32 start, ::sal_Int32 length) throw (::com::sun::star::uno::RuntimeException) +{ + Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->insertIndexIntervall( start, length); +} + +void SAL_CALL UnoGridControl::removeIndexIntervall(::sal_Int32 start, ::sal_Int32 length) throw (::com::sun::star::uno::RuntimeException) +{ + Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->removeIndexIntervall( start, length ); +} + +::com::sun::star::uno::Sequence< ::sal_Int32 > SAL_CALL UnoGridControl::getSelection() throw (::com::sun::star::uno::RuntimeException) +{ + return Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->getSelection(); +} + +::sal_Bool SAL_CALL UnoGridControl::isSelectionEmpty() throw (::com::sun::star::uno::RuntimeException) +{ + return Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->isSelectionEmpty(); +} + +::sal_Bool SAL_CALL UnoGridControl::isSelectedIndex(::sal_Int32 index) throw (::com::sun::star::uno::RuntimeException) +{ + return Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->isSelectedIndex( index ); +} + +void SAL_CALL UnoGridControl::selectRow(::sal_Int32 y) throw (::com::sun::star::uno::RuntimeException) +{ + Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->selectRow( y ); +} + +void SAL_CALL UnoGridControl::addSelectionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridSelectionListener > & listener) throw (::com::sun::star::uno::RuntimeException) +{ + Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->addSelectionListener( listener ); +} + +void SAL_CALL UnoGridControl::removeSelectionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridSelectionListener > & listener) throw (::com::sun::star::uno::RuntimeException) +{ + Reference< XGridControl >( getPeer(), UNO_QUERY_THROW )->removeSelectionListener( listener ); +} +} + +Reference< XInterface > SAL_CALL GridControl_CreateInstance( const Reference< XMultiServiceFactory >& ) +{ + return Reference < XInterface >( ( ::cppu::OWeakObject* ) new ::toolkit::UnoGridControl ); +} + +Reference< XInterface > SAL_CALL GridControlModel_CreateInstance( const Reference< XMultiServiceFactory >& ) +{ + return Reference < XInterface >( ( ::cppu::OWeakObject* ) new ::toolkit::UnoGridModel ); +} diff --git a/toolkit/source/controls/grid/gridcontrol.hxx b/toolkit/source/controls/grid/gridcontrol.hxx new file mode 100644 index 000000000000..4195a1f624e5 --- /dev/null +++ b/toolkit/source/controls/grid/gridcontrol.hxx @@ -0,0 +1,121 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef TOOLKIT_GRID_CONTROL_HXX +#define TOOLKIT_GRID_CONTROL_HXX + +#include <com/sun/star/awt/grid/XGridControl.hpp> +#include <com/sun/star/view/SelectionType.hpp> +#include <toolkit/controls/unocontrols.hxx> +#include <toolkit/controls/unocontrolmodel.hxx> +#include <toolkit/helper/servicenames.hxx> +#include <cppuhelper/implbase1.hxx> + +#include <toolkit/helper/listenermultiplexer.hxx> + +namespace toolkit { + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::container; + +// =================================================================== +// = UnoGridModel +// =================================================================== +class UnoGridModel : public UnoControlModel +{ +protected: + Any ImplGetDefaultValue( sal_uInt16 nPropId ) const; + ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); + +public: + UnoGridModel(); + UnoGridModel( const UnoGridModel& rModel ); + + UnoControlModel* Clone() const; + + // ::com::sun::star::beans::XMultiPropertySet + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException); + + // ::com::sun::star::io::XPersistObject + ::rtl::OUString SAL_CALL getServiceName() throw(::com::sun::star::uno::RuntimeException); + + // XServiceInfo + DECLIMPL_SERVICEINFO_DERIVED( UnoGridModel, UnoControlModel, szServiceName_GridControlModel ) +}; + + +// =================================================================== +// = UnoGridControl +// =================================================================== +class UnoGridControl : public ::cppu::ImplInheritanceHelper1< UnoControlBase, ::com::sun::star::awt::grid::XGridControl > +{ +public: + UnoGridControl(); + ::rtl::OUString GetComponentServiceName(); + + // ::com::sun::star::lang::XComponent + void SAL_CALL dispose( ) throw(::com::sun::star::uno::RuntimeException); + + // ::com::sun::star::awt::XControl + void SAL_CALL createPeer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit >& Toolkit, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& Parent ) throw(::com::sun::star::uno::RuntimeException); + + // ::com::sun::star::awt::grid::XGridControl + virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumnModel > SAL_CALL getColumnModel() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setColumnModel(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridColumnModel > & model) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridDataModel > SAL_CALL getDataModel() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setDataModel(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridDataModel > & model) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getItemIndexAtPoint(::sal_Int32 x, ::sal_Int32 y) throw (::com::sun::star::uno::RuntimeException); + //virtual void SAL_CALL addMouseListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener > & listener) throw (::com::sun::star::uno::RuntimeException); + //virtual void SAL_CALL removeMouseListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener > & listener) throw (::com::sun::star::uno::RuntimeException); + + // ::com::sun::star::awt::grid::XGridSelection + + virtual ::sal_Int32 SAL_CALL getMinSelectionIndex() throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getMaxSelectionIndex() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL insertIndexIntervall(::sal_Int32 start, ::sal_Int32 length) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeIndexIntervall(::sal_Int32 start, ::sal_Int32 length) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::sal_Int32 > SAL_CALL getSelection() throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL isSelectionEmpty() throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL isSelectedIndex(::sal_Int32 index) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL selectRow(::sal_Int32 y) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addSelectionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridSelectionListener > & listener) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeSelectionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridSelectionListener > & listener) throw (::com::sun::star::uno::RuntimeException); + + // ::com::sun::star::lang::XServiceInfo + DECLIMPL_SERVICEINFO_DERIVED( UnoGridControl, UnoControlBase, szServiceName_GridControl ) + + using UnoControl::getPeer; +private: + ::com::sun::star::view::SelectionType mSelectionMode; +}; + +} // toolkit + +#endif // _TOOLKIT_TREE_CONTROL_HXX diff --git a/toolkit/source/controls/grid/makefile.mk b/toolkit/source/controls/grid/makefile.mk new file mode 100644 index 000000000000..70bfc34b9d02 --- /dev/null +++ b/toolkit/source/controls/grid/makefile.mk @@ -0,0 +1,50 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME=toolkit +TARGET=grid + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/util$/makefile.pmk + +# --- Files -------------------------------------------------------- + +SLOFILES= \ + $(SLO)$/gridcontrol.obj\ + $(SLO)$/defaultgriddatamodel.obj\ + $(SLO)$/defaultgridcolumnmodel.obj\ + $(SLO)$/gridcolumn.obj + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk diff --git a/toolkit/source/controls/makefile.mk b/toolkit/source/controls/makefile.mk new file mode 100644 index 000000000000..1ce9f7b22c8c --- /dev/null +++ b/toolkit/source/controls/makefile.mk @@ -0,0 +1,66 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=toolkit +TARGET=controls + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/util$/makefile.pmk + + +# --- Files -------------------------------------------------------- + +SLOFILES= \ + $(SLO)$/accessiblecontrolcontext.obj \ + $(SLO)$/geometrycontrolmodel.obj \ + $(SLO)$/eventcontainer.obj \ + $(SLO)$/stdtabcontroller.obj \ + $(SLO)$/stdtabcontrollermodel.obj \ + $(SLO)$/unocontrol.obj \ + $(SLO)$/unocontrolbase.obj \ + $(SLO)$/unocontrolcontainer.obj \ + $(SLO)$/unocontrolcontainermodel.obj \ + $(SLO)$/unocontrolmodel.obj \ + $(SLO)$/unocontrols.obj \ + $(SLO)$/formattedcontrol.obj \ + $(SLO)$/roadmapcontrol.obj \ + $(SLO)$/roadmapentry.obj \ + $(SLO)$/dialogcontrol.obj \ + $(SLO)$/tkscrollbar.obj \ + $(SLO)$/tkspinbutton.obj \ + $(SLO)$/tksimpleanimation.obj \ + $(SLO)$/tkthrobber.obj + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk diff --git a/toolkit/source/controls/roadmapcontrol.cxx b/toolkit/source/controls/roadmapcontrol.cxx new file mode 100644 index 000000000000..acfbee0c5bb6 --- /dev/null +++ b/toolkit/source/controls/roadmapcontrol.cxx @@ -0,0 +1,589 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + +#ifndef _TOOLKIT_ROADMAP_CONTROL_HXX +#include <toolkit/controls/roadmapcontrol.hxx> +#endif +#include <toolkit/helper/unopropertyarrayhelper.hxx> +#include <toolkit/helper/property.hxx> +#include <com/sun/star/awt/XVclWindowPeer.hpp> +#include <comphelper/processfactory.hxx> +#include <osl/diagnose.h> + +//........................................................................ +namespace toolkit +{ +//........................................................................ + + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::awt; + using namespace ::com::sun::star::lang; + using namespace ::com::sun::star::beans; + using namespace ::com::sun::star::container; + +// ---------------------------------------------------- +// helper +// ---------------------------------------------------- + + static void lcl_knitImageComponents( const Reference< XControlModel >& _rxModel, + const Reference< XWindowPeer >& _rxPeer, + bool _bAdd ) + { + Reference< XImageProducer > xProducer( _rxModel, UNO_QUERY ); + if ( xProducer.is() ) + { + Reference< XImageConsumer > xConsumer( _rxPeer, UNO_QUERY ); + if ( xConsumer.is() ) + { + if ( _bAdd ) + { + xProducer->addConsumer( xConsumer ); + xProducer->startProduction(); + } + else + xProducer->removeConsumer( xConsumer ); + } + } + } + +static void lcl_throwIllegalArgumentException( ) +{ // throwing is expensive (in terms of code size), thus we hope the compiler does not inline this .... + throw IllegalArgumentException(); +} + +static void lcl_throwIndexOutOfBoundsException( ) +{ // throwing is expensive (in terms of code size), thus we hope the compiler does not inline this .... + throw IndexOutOfBoundsException(); +} + + // =================================================================== + // = UnoControlRoadmapModel + // =================================================================== + // ------------------------------------------------------------------- + UnoControlRoadmapModel::UnoControlRoadmapModel() : maContainerListeners( *this ) + { + ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR ); + ImplRegisterProperty( BASEPROPERTY_BORDER ); + ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR ); + ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL ); + ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR ); + ImplRegisterProperty( BASEPROPERTY_HELPTEXT ); + ImplRegisterProperty( BASEPROPERTY_HELPURL ); + ImplRegisterProperty( BASEPROPERTY_IMAGEURL ); + ImplRegisterProperty( BASEPROPERTY_PRINTABLE ); + ImplRegisterProperty( BASEPROPERTY_COMPLETE ); + ImplRegisterProperty( BASEPROPERTY_ACTIVATED ); + ImplRegisterProperty( BASEPROPERTY_CURRENTITEMID ); + ImplRegisterProperty( BASEPROPERTY_TABSTOP ); + ImplRegisterProperty( BASEPROPERTY_TEXT ); + } + + // ------------------------------------------------------------------- + ::rtl::OUString UnoControlRoadmapModel::getServiceName() throw(RuntimeException) + { + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlRoadmapModel ); + } + + + // ------------------------------------------------------------------- + Any UnoControlRoadmapModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const + { + Any aReturn; + switch (nPropId) + { + case BASEPROPERTY_COMPLETE: + aReturn <<= (sal_Bool) sal_True; + break; + case BASEPROPERTY_ACTIVATED: + aReturn <<= (sal_Bool) sal_True; + break; + case BASEPROPERTY_CURRENTITEMID: + aReturn <<= (sal_Int16) -1; + break; + case BASEPROPERTY_TEXT: + break; + case BASEPROPERTY_BORDER: + aReturn <<= (sal_Int16) 2; // No Border + break; + case BASEPROPERTY_DEFAULTCONTROL: + aReturn <<= ::rtl::OUString( ::rtl::OUString::createFromAscii( szServiceName_UnoControlRoadmap ) ); + break; + default : aReturn = UnoControlModel::ImplGetDefaultValue( nPropId ); break; + } + + return aReturn; + } + + + Reference< XInterface > SAL_CALL UnoControlRoadmapModel::createInstance( ) throw (Exception, ::com::sun::star::uno::RuntimeException) + { + ORoadmapEntry* pRoadmapItem = new ORoadmapEntry(); + Reference< XInterface > xNewRoadmapItem = (::cppu::OWeakObject*)pRoadmapItem; + return xNewRoadmapItem; + } + + + Reference< XInterface > SAL_CALL UnoControlRoadmapModel::createInstanceWithArguments( const Sequence< Any >& /*aArguments*/ ) throw (Exception, RuntimeException) + { + // Todo: implementation of the arguments handling + ORoadmapEntry* pRoadmapItem = new ORoadmapEntry(); + Reference< XInterface > xNewRoadmapItem = (::cppu::OWeakObject*)pRoadmapItem; + return xNewRoadmapItem; + } + + + IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoControlRoadmapModel, UnoControlRoadmapModel_Base, UnoControlRoadmapModel_IBase ) + + + // ------------------------------------------------------------------- + ::com::sun::star::uno::Any SAL_CALL UnoControlRoadmapModel::queryAggregation( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) + { + Any aRet = UnoControlRoadmapModel_Base::queryAggregation( rType ); + if ( !aRet.hasValue() ) + aRet = UnoControlRoadmapModel_IBase::queryInterface( rType ); + return aRet; + } + + + // ------------------------------------------------------------------- + ::cppu::IPropertyArrayHelper& UnoControlRoadmapModel::getInfoHelper() + { + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; + } + + + // beans::XMultiPropertySet + // ------------------------------------------------------------------- + Reference< XPropertySetInfo > UnoControlRoadmapModel::getPropertySetInfo( ) throw(RuntimeException) + { + static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; + } + + + sal_Int32 SAL_CALL UnoControlRoadmapModel::getCount() throw(RuntimeException) + { + return maRoadmapItems.size(); + } + + Any SAL_CALL UnoControlRoadmapModel::getByIndex( sal_Int32 Index ) throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException ) + { + if (( Index >= (sal_Int32)maRoadmapItems.size()) || (Index < 0)) + lcl_throwIndexOutOfBoundsException( ); + Any aAny; + aAny = makeAny( maRoadmapItems.at( Index )); + return aAny; + } + + + + void UnoControlRoadmapModel::MakeRMItemValidation( sal_Int32 Index, Reference< XInterface > xRoadmapItem ) + { + if ((Index > (sal_Int32)maRoadmapItems.size()) || ( Index < 0 ) ) + lcl_throwIndexOutOfBoundsException( ); + if ( !xRoadmapItem.is() ) + lcl_throwIllegalArgumentException(); + Reference< XServiceInfo > xServiceInfo( xRoadmapItem, UNO_QUERY ); + sal_Bool bIsRoadmapItem = xServiceInfo->supportsService( ::rtl::OUString::createFromAscii( "com.sun.star.awt.RoadmapItem" ) ); + if ( !bIsRoadmapItem ) + lcl_throwIllegalArgumentException(); + } + + + void UnoControlRoadmapModel::SetRMItemDefaultProperties( const sal_Int32 , Reference< XInterface > xRoadmapItem) + { + Any aAny; + Reference< XPropertySet > xPropertySet( xRoadmapItem, UNO_QUERY ); + Reference< XPropertySet > xProps( xRoadmapItem, UNO_QUERY ); + if ( xProps.is() ) + { + sal_Int32 LocID = 0; + Any aValue = xPropertySet->getPropertyValue( ::rtl::OUString::createFromAscii( "ID" ) ); + aValue >>= LocID; + if (LocID < 0) // index may not be smaller than zero + { + aAny <<= GetUniqueID(); + xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( "ID" ), aAny ); + } + } + } + + +// The performance of this method could certainly be improved. +// As long as only vectors with up to 10 elements are +// involved it should be sufficient + sal_Int32 UnoControlRoadmapModel::GetUniqueID() + { + Any aAny; + sal_Bool bIncrement = sal_True; + sal_Int32 CurID = 0; + sal_Int32 n_CurItemID = 0; + Reference< XInterface > CurRoadmapItem; + while ( bIncrement ) + { + bIncrement = sal_False; + for ( RoadmapItemHolderList::iterator i = maRoadmapItems.begin(); i < maRoadmapItems.end(); i++ ) + { + CurRoadmapItem = *i; + Reference< XPropertySet > xPropertySet( CurRoadmapItem, UNO_QUERY ); + aAny = xPropertySet->getPropertyValue( ::rtl::OUString::createFromAscii( "ID" ) ); + aAny >>= n_CurItemID; + if (n_CurItemID == CurID) + { + bIncrement = sal_True; + CurID++; + break; + } + } + } + return CurID; + } + + + ContainerEvent UnoControlRoadmapModel::GetContainerEvent(sal_Int32 Index, Reference< XInterface > xRoadmapItem) + { + ContainerEvent aEvent; + aEvent.Source = *this; + aEvent.Element <<= xRoadmapItem; + aEvent.Accessor = makeAny(Index); + return aEvent; + } + + + sal_Int16 UnoControlRoadmapModel::GetCurrentItemID( Reference< XPropertySet > xPropertySet ) + { + Any aAny = xPropertySet->getPropertyValue( GetPropertyName( BASEPROPERTY_CURRENTITEMID ) ); + sal_Int16 n_CurrentItemID = 0; + aAny >>= n_CurrentItemID; + return n_CurrentItemID; + } + + + void SAL_CALL UnoControlRoadmapModel::insertByIndex( const sal_Int32 Index, const Any& _Element) + throw (IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException ) + { + if ( ( Index >= ( (sal_Int32)maRoadmapItems.size() + 1 ) ) || (Index < 0)) + lcl_throwIndexOutOfBoundsException( ); + Reference< XInterface > xRoadmapItem; + _Element >>= xRoadmapItem; + MakeRMItemValidation( Index, xRoadmapItem); + SetRMItemDefaultProperties( Index, xRoadmapItem ); + maRoadmapItems.insert( maRoadmapItems.begin() + Index, xRoadmapItem); + ContainerEvent aEvent = GetContainerEvent(Index, xRoadmapItem); + maContainerListeners.elementInserted( aEvent ); + Reference< XPropertySet > xPropertySet( (XAggregation*) (::cppu::OWeakAggObject*)this, UNO_QUERY ); + sal_Int16 n_CurrentItemID = GetCurrentItemID( xPropertySet ); + if ( Index <= n_CurrentItemID ) + { + Any aAny; + aAny <<= ( sal_Int16 ) ( n_CurrentItemID + 1 ); + xPropertySet->setPropertyValue( GetPropertyName( BASEPROPERTY_CURRENTITEMID ), aAny ); + } + } + + + + void SAL_CALL UnoControlRoadmapModel::removeByIndex( sal_Int32 Index) + throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException ) + { + if (( Index > (sal_Int32)maRoadmapItems.size()) || (Index < 0)) + lcl_throwIndexOutOfBoundsException( ); + Reference< XInterface > xRoadmapItem; + maRoadmapItems.erase( maRoadmapItems.begin() + Index ); + ContainerEvent aEvent = GetContainerEvent(Index, xRoadmapItem); + maContainerListeners.elementRemoved( aEvent ); + Reference< XPropertySet > xPropertySet( (XAggregation*) (::cppu::OWeakAggObject*)this, UNO_QUERY ); + sal_Int16 n_CurrentItemID = GetCurrentItemID( xPropertySet ); + Any aAny; + if ( Index <= n_CurrentItemID ) + { + if ( n_CurrentItemID >= (sal_Int32)maRoadmapItems.size() ) + { + n_CurrentItemID = sal::static_int_cast< sal_Int16 >( + maRoadmapItems.size()-1); + if ( n_CurrentItemID < 0 ) + return; + aAny <<= n_CurrentItemID; + } + else if (Index == n_CurrentItemID) + aAny <<= ( sal_Int16 ) -1; + else if( Index < n_CurrentItemID) + aAny <<= ( sal_Int16 ) ( n_CurrentItemID - 1 ); + xPropertySet->setPropertyValue( GetPropertyName( BASEPROPERTY_CURRENTITEMID ), aAny ); + } + } + + + void SAL_CALL UnoControlRoadmapModel::replaceByIndex( const sal_Int32 Index, const Any& _Element) + throw (IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException ) + { + Reference< XInterface > xRoadmapItem; + _Element >>= xRoadmapItem; + MakeRMItemValidation( Index, xRoadmapItem); + SetRMItemDefaultProperties( Index, xRoadmapItem ); + maRoadmapItems.erase( maRoadmapItems.begin() + Index ); + maRoadmapItems.insert( maRoadmapItems.begin() + Index, xRoadmapItem); //push_back( xRoadmapItem ); + ContainerEvent aEvent = GetContainerEvent(Index, xRoadmapItem); + maContainerListeners.elementReplaced( aEvent ); + } + + + Type SAL_CALL UnoControlRoadmapModel::getElementType() throw(RuntimeException) + { + Type aType = getCppuType( ( Reference< XPropertySet>* ) NULL ); + return aType; + } + + + sal_Bool SAL_CALL UnoControlRoadmapModel::hasElements() throw(RuntimeException) + { + return !maRoadmapItems.empty(); + } + + + void SAL_CALL UnoControlRoadmapModel::addContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw (::com::sun::star::uno::RuntimeException) + { + maContainerListeners.addInterface( xListener ); + } + + void SAL_CALL UnoControlRoadmapModel::removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw (::com::sun::star::uno::RuntimeException) + { + maContainerListeners.removeInterface( xListener ); + } + + + void UnoControlRoadmapModel::addConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& xConsumer ) throw (::com::sun::star::uno::RuntimeException) + { + maImageListeners.push_back( xConsumer ); + } + + + void UnoControlRoadmapModel::removeConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& xConsumer ) throw (::com::sun::star::uno::RuntimeException) + { + maImageListeners.remove( xConsumer ); + } + + + void UnoControlRoadmapModel::startProduction( ) throw (::com::sun::star::uno::RuntimeException) + { + Sequence<Any> aArgs(1); + aArgs.getArray()[0] = getPropertyValue( GetPropertyName( BASEPROPERTY_IMAGEURL ) ); + Reference< XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory(); + Reference< XImageProducer > xImageProducer( xMSF->createInstanceWithArguments( ::rtl::OUString::createFromAscii( "com.sun.star.awt.ImageProducer" ), aArgs ), UNO_QUERY ); + if ( xImageProducer.is() ) + { + std::list< Reference< XImageConsumer > >::iterator aIter( maImageListeners.begin() ); + while ( aIter != maImageListeners.end() ) + { + xImageProducer->addConsumer( *aIter ); + aIter++; + } + xImageProducer->startProduction(); + } + } + + + + + // =================================================================== + // = UnoRoadmapControl + // =================================================================== + // ------------------------------------------------------------------- + UnoRoadmapControl::UnoRoadmapControl(): maItemListeners( *this ) + { + } + +IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoRoadmapControl, UnoControlRoadmap_Base, UnoControlRoadmap_IBase ) +IMPLEMENT_FORWARD_XINTERFACE2( UnoRoadmapControl, UnoControlRoadmap_Base, UnoControlRoadmap_IBase ) + + +sal_Bool SAL_CALL UnoRoadmapControl::setModel(const Reference< XControlModel >& _rModel) throw ( RuntimeException ) + { + + + // remove the peer as image consumer from the model + lcl_knitImageComponents( getModel(), getPeer(), false ); + + Reference< XContainer > xC( getModel(), UNO_QUERY ); + if ( xC.is() ) + xC->removeContainerListener( this ); + + sal_Bool bReturn = UnoControlBase::setModel( _rModel ); + + xC = xC.query( getModel()); + if ( xC.is() ) + xC->addContainerListener( this ); + + // add the peer as image consumer to the model + lcl_knitImageComponents( getModel(), getPeer(), true ); + + return bReturn; + } + + + // ------------------------------------------------------------------- + ::rtl::OUString UnoRoadmapControl::GetComponentServiceName() + { + return ::rtl::OUString::createFromAscii( "Roadmap" ); + } + + + + void SAL_CALL UnoRoadmapControl::createPeer( const Reference<XToolkit > & rxToolkit, const Reference< XWindowPeer > & rParentPeer ) throw(RuntimeException) + { + // remove the peer as image consumer from the model + lcl_knitImageComponents( getModel(), getPeer(), false ); + + UnoControl::createPeer( rxToolkit, rParentPeer ); + + lcl_knitImageComponents( getModel(), getPeer(), true ); + + } + + + void UnoRoadmapControl::dispose() throw(RuntimeException) + { + EventObject aEvt; + aEvt.Source = (::cppu::OWeakObject*)this; + maItemListeners.disposeAndClear( aEvt ); + UnoControl::dispose(); + } + + + +void UnoRoadmapControl::ImplSetPeerProperty( const ::rtl::OUString& rPropName, const Any& rVal ) +{ + sal_uInt16 nType = GetPropertyId( rPropName ); + if ( getPeer().is() && ( nType == BASEPROPERTY_IMAGEURL ) ) + { + Reference < XImageProducer > xImgProd( getModel(), UNO_QUERY ); + Reference < XImageConsumer > xImgCons( getPeer(), UNO_QUERY ); + + if ( xImgProd.is() && xImgCons.is() ) + { + xImgProd->startProduction(); + } + } + else + UnoControlBase::ImplSetPeerProperty( rPropName, rVal ); +} + + +void UnoRoadmapControl::elementInserted( const ContainerEvent& rEvent )throw(RuntimeException) +{ + Reference< XInterface > xRoadmapItem; + rEvent.Element >>= xRoadmapItem; + Reference< XPropertySet > xRoadmapPropertySet( xRoadmapItem, UNO_QUERY ); + if ( xRoadmapPropertySet.is() ) + xRoadmapPropertySet->addPropertyChangeListener( rtl::OUString(), this ); + + Reference< XContainerListener > xPeer(getPeer(), UNO_QUERY); + if ( xPeer.is() ) + { + xPeer->elementInserted( rEvent ); + Reference < XPropertySet > xPropertySet( xPeer, UNO_QUERY ); + if ( xPropertySet.is() ) + xPropertySet->addPropertyChangeListener( rtl::OUString(), this ); + } +} + + +void UnoRoadmapControl::elementRemoved( const ContainerEvent& rEvent )throw(RuntimeException) +{ + Reference< XContainerListener > xPeer(getPeer(), UNO_QUERY); + if ( xPeer.is() ) + xPeer->elementRemoved( rEvent ); + Reference< XInterface > xRoadmapItem; + rEvent.Element >>= xRoadmapItem; + Reference< XPropertySet > xPropertySet( xRoadmapItem, UNO_QUERY ); + if ( xPropertySet.is() ) + xPropertySet->removePropertyChangeListener( rtl::OUString(), this ); +} + + +void UnoRoadmapControl::elementReplaced( const ContainerEvent& rEvent )throw(RuntimeException) +{ + Reference< XContainerListener > xPeer(getPeer(), UNO_QUERY); + if ( xPeer.is() ) + xPeer->elementReplaced( rEvent ); +} + + +void SAL_CALL UnoRoadmapControl::itemStateChanged( const ItemEvent& rEvent ) throw (RuntimeException) +{ + sal_Int16 CurItemIndex = sal::static_int_cast< sal_Int16 >(rEvent.ItemId); + Any aAny; + aAny <<= CurItemIndex; + Reference< XControlModel > xModel( getModel( ), UNO_QUERY ); + Reference< XPropertySet > xPropertySet( xModel, UNO_QUERY ); + xPropertySet->setPropertyValue( GetPropertyName( BASEPROPERTY_CURRENTITEMID ), aAny ); + if ( maItemListeners.getLength() ) + maItemListeners.itemStateChanged( rEvent ); +} + + +void SAL_CALL UnoRoadmapControl::addItemListener( const Reference< XItemListener >& l ) throw (RuntimeException) +{ + maItemListeners.addInterface( l ); + if( getPeer().is() && maItemListeners.getLength() == 1 ) + { + Reference < XItemEventBroadcaster > xRoadmap( getPeer(), UNO_QUERY ); + xRoadmap->addItemListener( this ); + } +} + + +void SAL_CALL UnoRoadmapControl::removeItemListener( const Reference< XItemListener >& l ) throw (RuntimeException) +{ + if( getPeer().is() && maItemListeners.getLength() == 1 ) + { + Reference < XItemEventBroadcaster > xRoadmap( getPeer(), UNO_QUERY ); + xRoadmap->removeItemListener( this ); + } + + maItemListeners.removeInterface( l ); +} + + +void SAL_CALL UnoRoadmapControl::propertyChange( const PropertyChangeEvent& evt ) throw (RuntimeException) +{ + Reference< XPropertyChangeListener > xPeer(getPeer(), UNO_QUERY); + if ( xPeer.is() ) + xPeer->propertyChange( evt ); +} + +} + diff --git a/toolkit/source/controls/roadmapentry.cxx b/toolkit/source/controls/roadmapentry.cxx new file mode 100644 index 000000000000..fb760e404b93 --- /dev/null +++ b/toolkit/source/controls/roadmapentry.cxx @@ -0,0 +1,126 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <toolkit/controls/roadmapentry.hxx> + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/OUString.hxx> +#endif + + +#include <com/sun/star/beans/PropertyAttribute.hpp> + + +ORoadmapEntry::ORoadmapEntry() : ORoadmapEntry_Base( ) + ,OPropertyContainer( GetBroadcastHelper() ) +{ + // registerProperty or registerMayBeVoidProperty or registerPropertyNoMember + + registerProperty( ::rtl::OUString::createFromAscii( "Label" ), RM_PROPERTY_ID_LABEL, + ::com::sun::star::beans::PropertyAttribute::BOUND | + ::com::sun::star::beans::PropertyAttribute::CONSTRAINED, + & m_sLabel, ::getCppuType( &m_sLabel ) ); + m_nID = -1; + registerProperty( ::rtl::OUString::createFromAscii( "ID" ), RM_PROPERTY_ID_ID, + ::com::sun::star::beans::PropertyAttribute::BOUND | + ::com::sun::star::beans::PropertyAttribute::CONSTRAINED, + & m_nID, ::getCppuType( &m_nID ) ); + m_bEnabled = sal_True; + registerProperty( ::rtl::OUString::createFromAscii( "Enabled" ), RM_PROPERTY_ID_ENABLED, + ::com::sun::star::beans::PropertyAttribute::BOUND | + ::com::sun::star::beans::PropertyAttribute::MAYBEDEFAULT, + & m_bEnabled, ::getCppuType( &m_bEnabled ) ); + + registerProperty( ::rtl::OUString::createFromAscii( "Interactive" ), RM_PROPERTY_ID_INTERACTIVE, + ::com::sun::star::beans::PropertyAttribute::BOUND | + ::com::sun::star::beans::PropertyAttribute::MAYBEDEFAULT, + & m_bInteractive, ::getCppuType( &m_bInteractive ) ); + + + // ... + + // Note that the list of registered properties has to be fixed: Different + // instances of this class have to register the same set of properties with + // the same attributes. + // + // This is because all instances of the class share the same PropertySetInfo + // which has been built from the registered property of _one_ instance. +} + +//-------------------------------------------------------------------------- +IMPLEMENT_FORWARD_XINTERFACE2( ORoadmapEntry, ORoadmapEntry_Base, ::comphelper::OPropertyContainer ); +IMPLEMENT_FORWARD_XTYPEPROVIDER2( ORoadmapEntry, ORoadmapEntry_Base, ::comphelper::OPropertyContainer ); + // order matters: + // the first is the class name + // the second is the class which implements the ref-counting + // the third up to n-th (when using IMPLEMENT_FORWARD_*3 and so on) are other base classes + // whose XInterface and XTypeProvider implementations should be merged + +//-------------------------------------------------------------------------- +::com::sun::star::uno::Reference< ::com::sun::star:: beans::XPropertySetInfo > SAL_CALL + ORoadmapEntry::getPropertySetInfo() + throw(::com::sun::star::uno::RuntimeException) +{ + return ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >( + createPropertySetInfo( getInfoHelper() ) ); +} + +::rtl::OUString SAL_CALL ORoadmapEntry::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) +{ + ::rtl::OUString aStr = ::rtl::OUString::createFromAscii("com.sun.star.comp.toolkit.RoadmapItem"); + return aStr; +} + +sal_Bool SAL_CALL ORoadmapEntry::supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException) +{ + return ServiceName.equals( ::rtl::OUString::createFromAscii( "com.sun.star.awt.RoadmapItem" ) ); +} + +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL ORoadmapEntry::getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Sequence< ::rtl::OUString > aRet(1); + ::rtl::OUString* pArray = aRet.getArray(); + pArray[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.RoadmapItem" ); + return aRet; +} +//-------------------------------------------------------------------------- +::cppu::IPropertyArrayHelper& ORoadmapEntry::getInfoHelper() +{ + return *getArrayHelper(); +} + +//-------------------------------------------------------------------------- +::cppu::IPropertyArrayHelper* ORoadmapEntry::createArrayHelper() const +{ + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > aProps; + // describes all properties which have been registered in the ctor + describeProperties( aProps ); + + return new ::cppu::OPropertyArrayHelper( aProps ); +} diff --git a/toolkit/source/controls/stdtabcontroller.cxx b/toolkit/source/controls/stdtabcontroller.cxx new file mode 100644 index 000000000000..012a7bc0a084 --- /dev/null +++ b/toolkit/source/controls/stdtabcontroller.cxx @@ -0,0 +1,428 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/awt/XVclContainerPeer.hpp> + +#include <toolkit/controls/stdtabcontroller.hxx> +#include <toolkit/controls/stdtabcontrollermodel.hxx> +#include <toolkit/awt/vclxwindow.hxx> +#include <toolkit/helper/macros.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <rtl/memory.h> +#include <rtl/uuid.h> + +#include <tools/debug.hxx> +#include <vcl/window.hxx> +#include <comphelper/sequence.hxx> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; + +// ---------------------------------------------------- +// class StdTabController +// ---------------------------------------------------- +StdTabController::StdTabController() +{ +} + +StdTabController::~StdTabController() +{ +} + +sal_Bool StdTabController::ImplCreateComponentSequence( + Sequence< Reference< XControl > >& rControls, + const Sequence< Reference< XControlModel > >& rModels, + Sequence< Reference< XWindow > >& rComponents, + Sequence< Any>* pTabStops, + sal_Bool bPeerComponent ) const +{ + sal_Bool bOK = sal_True; + + // nur die wirklich geforderten Controls + sal_Int32 nModels = rModels.getLength(); + if (nModels != rControls.getLength()) + { + Sequence< Reference< XControl > > aSeq( nModels ); + const Reference< XControlModel >* pModels = rModels.getConstArray(); + Reference< XControl > xCurrentControl; + + sal_Int32 nRealControls = 0; + for (sal_Int32 n = 0; n < nModels; ++n, ++pModels) + { + xCurrentControl = FindControl(rControls, *pModels); + if (xCurrentControl.is()) + aSeq.getArray()[nRealControls++] = xCurrentControl; + } + aSeq.realloc(nRealControls); + rControls = aSeq; + } +#ifdef DBG_UTIL + DBG_ASSERT( rControls.getLength() <= rModels.getLength(), "StdTabController:ImplCreateComponentSequence: inconsistence!" ); + // there may be less controls than models, but never more controls than models +#endif + + + const Reference< XControl > * pControls = rControls.getConstArray(); + sal_uInt32 nCtrls = rControls.getLength(); + rComponents.realloc( nCtrls ); + Reference< XWindow > * pComps = rComponents.getArray(); + Any* pTabs = NULL; + + + if ( pTabStops ) + { + *pTabStops = Sequence< Any>( nCtrls ); + pTabs = pTabStops->getArray(); + } + + for ( sal_uInt32 n = 0; bOK && ( n < nCtrls ); n++ ) + { + // Zum Model passendes Control suchen + Reference< XControl > xCtrl(pControls[n]); + if ( xCtrl.is() ) + { + if (bPeerComponent) + pComps[n] = Reference< XWindow > (xCtrl->getPeer(), UNO_QUERY); + else + pComps[n] = Reference< XWindow > (xCtrl, UNO_QUERY); + + // TabStop-Property + if ( pTabs ) + { + // opt: String fuer TabStop als Konstante + static const ::rtl::OUString aTabStopName( ::rtl::OUString::createFromAscii( "Tabstop" ) ); + + Reference< XPropertySet > xPSet( xCtrl->getModel(), UNO_QUERY ); + Reference< XPropertySetInfo > xInfo = xPSet->getPropertySetInfo(); + if( xInfo->hasPropertyByName( aTabStopName ) ) + *pTabs++ = xPSet->getPropertyValue( aTabStopName ); + else + ++pTabs; + } + } + else + { + DBG_TRACE( "ImplCreateComponentSequence: Control not found" ); + bOK = sal_False; + } + } + return bOK; +} + +void StdTabController::ImplActivateControl( sal_Bool bFirst ) const +{ + // HACK wegen #53688#, muss auf ein Interface abgebildet werden, wenn Controls Remote liegen koennen. + Reference< XTabController > xTabController(const_cast< ::cppu::OWeakObject* >(static_cast< const ::cppu::OWeakObject* >(this)), UNO_QUERY); + Sequence< Reference< XControl > > aCtrls = xTabController->getControls(); + const Reference< XControl > * pControls = aCtrls.getConstArray(); + sal_uInt32 nCount = aCtrls.getLength(); + + for ( sal_uInt32 n = bFirst ? 0 : nCount; bFirst ? ( n < nCount ) : n; ) + { + sal_uInt32 nCtrl = bFirst ? n++ : --n; + DBG_ASSERT( pControls[nCtrl].is(), "Control nicht im Container!" ); + if ( pControls[nCtrl].is() ) + { + Reference< XWindowPeer > xCP = pControls[nCtrl]->getPeer(); + if ( xCP.is() ) + { + VCLXWindow* pC = VCLXWindow::GetImplementation( xCP ); + if ( pC && pC->GetWindow() && ( pC->GetWindow()->GetStyle() & WB_TABSTOP ) ) + { + pC->GetWindow()->GrabFocus(); + break; + } + } + } + } +} + +// XInterface +Any StdTabController::queryAggregation( const Type & rType ) throw(RuntimeException) +{ + Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( XTabController*, this ), + SAL_STATIC_CAST( XServiceInfo*, this ), + SAL_STATIC_CAST( XTypeProvider*, this ) ); + return (aRet.hasValue() ? aRet : OWeakAggObject::queryAggregation( rType )); +} + +// XTypeProvider +IMPL_XTYPEPROVIDER_START( StdTabController ) + getCppuType( ( Reference< XTabController>* ) NULL ), + getCppuType( ( Reference< XServiceInfo>* ) NULL ) +IMPL_XTYPEPROVIDER_END + +void StdTabController::setModel( const Reference< XTabControllerModel >& Model ) throw(RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + mxModel = Model; +} + +Reference< XTabControllerModel > StdTabController::getModel( ) throw(RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return mxModel; +} + +void StdTabController::setContainer( const Reference< XControlContainer >& Container ) throw(RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + mxControlContainer = Container; +} + +Reference< XControlContainer > StdTabController::getContainer( ) throw(RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return mxControlContainer; +} + +Sequence< Reference< XControl > > StdTabController::getControls( ) throw(RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + Sequence< Reference< XControl > > aSeq; + + if ( mxControlContainer.is() ) + { + Sequence< Reference< XControlModel > > aModels = mxModel->getControlModels(); + const Reference< XControlModel > * pModels = aModels.getConstArray(); + + Sequence< Reference< XControl > > xCtrls = mxControlContainer->getControls(); + + sal_uInt32 nCtrls = aModels.getLength(); + aSeq = Sequence< Reference< XControl > >( nCtrls ); + for ( sal_uInt32 n = 0; n < nCtrls; n++ ) + { + Reference< XControlModel > xCtrlModel = pModels[n]; + // Zum Model passendes Control suchen + Reference< XControl > xCtrl = FindControl( xCtrls, xCtrlModel ); + aSeq.getArray()[n] = xCtrl; + } + } + return aSeq; +} + +void StdTabController::autoTabOrder( ) throw(RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + DBG_ASSERT( mxControlContainer.is(), "autoTabOrder: No ControlContainer!" ); + if ( !mxControlContainer.is() ) + return; + + Sequence< Reference< XControlModel > > aSeq = mxModel->getControlModels(); + Sequence< Reference< XWindow > > aCompSeq; + + // vieleicht erhalte ich hier einen TabController, + // der schneller die Liste meiner Controls ermittelt + Reference< XTabController > xTabController(static_cast< ::cppu::OWeakObject* >(this), UNO_QUERY); + Sequence< Reference< XControl > > aControls = xTabController->getControls(); + + // #58317# Es sind ggf. noch nicht alle Controls fuer die Models im Container, + // dann kommt spaeter nochmal ein autoTabOrder... + if( !ImplCreateComponentSequence( aControls, aSeq, aCompSeq, NULL, sal_False ) ) + return; + + sal_uInt32 nCtrls = aCompSeq.getLength(); + Reference< XWindow > * pComponents = aCompSeq.getArray(); + + ComponentEntryList aCtrls; + sal_uInt32 n; + for ( n = 0; n < nCtrls; n++ ) + { + XWindow* pC = (XWindow*)pComponents[n].get(); + ComponentEntry* pE = new ComponentEntry; + pE->pComponent = pC; + awt::Rectangle aPosSize = pC->getPosSize(); + pE->aPos.X() = aPosSize.X; + pE->aPos.Y() = aPosSize.Y; + + sal_uInt16 nPos; + for ( nPos = 0; nPos < aCtrls.Count(); nPos++ ) + { + ComponentEntry* pEntry = aCtrls.GetObject( nPos ); + if ( pEntry->aPos.Y() >= pE->aPos.Y() ) + { + while ( pEntry && ( pEntry->aPos.Y() == pE->aPos.Y() ) + && ( pEntry->aPos.X() < pE->aPos.X() ) ) + { + pEntry = aCtrls.GetObject( ++nPos ); + } + break; + } + } + aCtrls.Insert( pE, nPos ); + } + + Sequence< Reference< XControlModel > > aNewSeq( nCtrls ); + for ( n = 0; n < nCtrls; n++ ) + { + ComponentEntry* pE = aCtrls.GetObject( n ); + Reference< XControl > xUC( pE->pComponent, UNO_QUERY ); + aNewSeq.getArray()[n] = xUC->getModel(); + delete pE; + } + aCtrls.Clear(); + + mxModel->setControlModels( aNewSeq ); +} + +void StdTabController::activateTabOrder( ) throw(RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + // Am Container die Tab-Reihenfolge aktivieren... + + Reference< XControl > xC( mxControlContainer, UNO_QUERY ); + Reference< XVclContainerPeer > xVclContainerPeer; + if ( xC.is() ) + xVclContainerPeer = xVclContainerPeer.query( xC->getPeer() ); + if ( !xC.is() || !xVclContainerPeer.is() ) + return; + + // vieleicht erhalte ich hier einen TabController, + // der schneller die Liste meiner Controls ermittelt + Reference< XTabController > xTabController(static_cast< ::cppu::OWeakObject* >(this), UNO_QUERY); + + // Flache Liste besorgen... + Sequence< Reference< XControlModel > > aModels = mxModel->getControlModels(); + Sequence< Reference< XWindow > > aCompSeq; + Sequence< Any> aTabSeq; + + // DG: Aus Optimierungsgruenden werden die Controls mittels getControls() geholt, + // dieses hoert sich zwar wiedersinning an, fuehrt aber im konkreten Fall (Forms) zu sichtbaren + // Geschwindigkeitsvorteilen + Sequence< Reference< XControl > > aControls = xTabController->getControls(); + + // #58317# Es sind ggf. noch nicht alle Controls fuer die Models im Container, + // dann kommt spaeter nochmal ein activateTabOrder... + if( !ImplCreateComponentSequence( aControls, aModels, aCompSeq, &aTabSeq, sal_True ) ) + return; + + xVclContainerPeer->setTabOrder( aCompSeq, aTabSeq, mxModel->getGroupControl() ); + + ::rtl::OUString aName; + Sequence< Reference< XControlModel > > aThisGroupModels; + Sequence< Reference< XWindow > > aControlComponents; + + sal_uInt32 nGroups = mxModel->getGroupCount(); + for ( sal_uInt32 nG = 0; nG < nGroups; nG++ ) + { + mxModel->getGroup( nG, aThisGroupModels, aName ); + + aControls = xTabController->getControls(); + // ImplCreateComponentSequence has a really strange semantics regarding it's first parameter: + // upon method entry, it expects a super set of the controls which it returns + // this means we need to completely fill this sequence with all available controls before + // calling into ImplCreateComponentSequence + + aControlComponents.realloc( 0 ); + + ImplCreateComponentSequence( aControls, aThisGroupModels, aControlComponents, NULL, sal_True ); + xVclContainerPeer->setGroup( aControlComponents ); + } +} + +void StdTabController::activateFirst( ) throw(RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ImplActivateControl( sal_True ); +} + +void StdTabController::activateLast( ) throw(RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ImplActivateControl( sal_False ); +} + + +Reference< XControl > StdTabController::FindControl( Sequence< Reference< XControl > >& rCtrls, + const Reference< XControlModel > & rxCtrlModel ) +{ + +/* + // MT: Funktioniert nicht mehr, weil ich nicht mehr bei mir angemeldet bin, + // weil DG das abfaengt. + + // #54677# Beim Laden eines HTML-Dokuments wird nach jedem Control ein + // activateTabOrder gerufen und jede Menge Zeit in dieser Methode verbraten. + // Die Anzahl dieser Schleifendurchlaufe steigt quadratisch, also versuchen + // das Control direkt vom Model zu erhalten. + // => Wenn genau ein Control als PropertyChangeListener angemeldet ist, + // dann muss das auch das richtige sein. + + UnoControlModel* pUnoCtrlModel = UnoControlModel::GetImplementation( rxCtrlModel ); + + + if ( pUnoCtrlModel ) + { + ListenerIterator aIt( pUnoCtrlModel->maPropertiesListeners ); + while( aIt.hasMoreElements() ) + { + XEventListener* pL = aIt.next(); + Reference< XControl > xC( pL, UNO_QUERY ); + if ( xC.is() ) + { + if( xC->getContext() == mxControlContainer ) + { + xCtrl = xC; + break; + } + } + } + } + if ( !xCtrl.is() && rxCtrlModel.is()) +*/ + DBG_ASSERT( rxCtrlModel.is(), "ImplFindControl - welches ?!" ); + + const Reference< XControl > * pCtrls = rCtrls.getConstArray(); + sal_Int32 nCtrls = rCtrls.getLength(); + for ( sal_Int32 n = 0; n < nCtrls; n++ ) + { + Reference< XControlModel > xModel(pCtrls[n].is() ? pCtrls[n]->getModel() : Reference< XControlModel > ()); + if ( (XControlModel*)xModel.get() == (XControlModel*)rxCtrlModel.get() ) + { + Reference< XControl > xCtrl( pCtrls[n] ); + ::comphelper::removeElementAt( rCtrls, n ); + return xCtrl; + } + } + return Reference< XControl > (); +} diff --git a/toolkit/source/controls/stdtabcontrollermodel.cxx b/toolkit/source/controls/stdtabcontrollermodel.cxx new file mode 100644 index 000000000000..db0555762511 --- /dev/null +++ b/toolkit/source/controls/stdtabcontrollermodel.cxx @@ -0,0 +1,408 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <com/sun/star/io/XMarkableStream.hpp> + +#include <toolkit/controls/stdtabcontrollermodel.hxx> +#include <toolkit/helper/macros.hxx> +#include <toolkit/helper/servicenames.hxx> +#include <toolkit/helper/property.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <rtl/memory.h> +#include <rtl/uuid.h> + +#include <tools/debug.hxx> + +#define UNOCONTROL_STREAMVERSION (short)2 + +// ---------------------------------------------------- +// class UnoControlModelEntryList +// ---------------------------------------------------- +UnoControlModelEntryList::UnoControlModelEntryList() +{ +} + +UnoControlModelEntryList::~UnoControlModelEntryList() +{ + Reset(); +} + +void UnoControlModelEntryList::Reset() +{ + for ( sal_uInt32 n = Count(); n; ) + DestroyEntry( --n ); +} + +void UnoControlModelEntryList::DestroyEntry( sal_uInt32 nEntry ) +{ + UnoControlModelEntry* pEntry = GetObject( nEntry ); + + if ( pEntry->bGroup ) + delete pEntry->pGroup; + else + delete pEntry->pxControl; + + Remove( nEntry ); + delete pEntry; +} + +// ---------------------------------------------------- +// class StdTabControllerModel +// ---------------------------------------------------- +StdTabControllerModel::StdTabControllerModel() +{ + mbGroupControl = sal_True; +} + +StdTabControllerModel::~StdTabControllerModel() +{ +} + +sal_uInt32 StdTabControllerModel::ImplGetControlCount( const UnoControlModelEntryList& rList ) const +{ + sal_uInt32 nCount = 0; + sal_uInt32 nEntries = rList.Count(); + for ( sal_uInt32 n = 0; n < nEntries; n++ ) + { + UnoControlModelEntry* pEntry = rList.GetObject( n ); + if ( pEntry->bGroup ) + nCount += ImplGetControlCount( *pEntry->pGroup ); + else + nCount++; + } + return nCount; +} + +void StdTabControllerModel::ImplGetControlModels( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > ** ppRefs, const UnoControlModelEntryList& rList ) const +{ + sal_uInt32 nEntries = rList.Count(); + for ( sal_uInt32 n = 0; n < nEntries; n++ ) + { + UnoControlModelEntry* pEntry = rList.GetObject( n ); + if ( pEntry->bGroup ) + ImplGetControlModels( ppRefs, *pEntry->pGroup ); + else + { + **ppRefs = *pEntry->pxControl; + (*ppRefs)++; + } + } +} + +void StdTabControllerModel::ImplSetControlModels( UnoControlModelEntryList& rList, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > >& Controls ) const +{ + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > * pRefs = Controls.getConstArray(); + sal_uInt32 nControls = Controls.getLength(); + for ( sal_uInt32 n = 0; n < nControls; n++ ) + { + UnoControlModelEntry* pNewEntry = new UnoControlModelEntry; + pNewEntry->bGroup = sal_False; + pNewEntry->pxControl = new ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > ; + *pNewEntry->pxControl = pRefs[n]; + rList.Insert( pNewEntry, LIST_APPEND ); + } +} + +sal_uInt32 StdTabControllerModel::ImplGetControlPos( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > xCtrl, const UnoControlModelEntryList& rList ) const +{ + for ( sal_uInt32 n = rList.Count(); n; ) + { + UnoControlModelEntry* pEntry = rList.GetObject( --n ); + if ( !pEntry->bGroup && ( *pEntry->pxControl == xCtrl ) ) + return n; + } + return CONTROLPOS_NOTFOUND; +} + +void ImplWriteControls( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream > & OutStream, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > >& rCtrls ) +{ + ::com::sun::star::uno::Reference< ::com::sun::star::io::XMarkableStream > xMark( OutStream, ::com::sun::star::uno::UNO_QUERY ); + DBG_ASSERT( xMark.is(), "write: no XMarkableStream!" ); + + sal_uInt32 nStoredControls = 0; + sal_Int32 nDataBeginMark = xMark->createMark(); + + OutStream->writeLong( 0L ); // DataLen + OutStream->writeLong( 0L ); // nStoredControls + + sal_uInt32 nCtrls = rCtrls.getLength(); + for ( sal_uInt32 n = 0; n < nCtrls; n++ ) + { + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > xI = rCtrls.getConstArray()[n]; + ::com::sun::star::uno::Reference< ::com::sun::star::io::XPersistObject > xPO( xI, ::com::sun::star::uno::UNO_QUERY ); + DBG_ASSERT( xPO.is(), "write: Control doesn't support XPersistObject" ); + if ( xPO.is() ) + { + OutStream->writeObject( xPO ); + nStoredControls++; + } + } + sal_Int32 nDataLen = xMark->offsetToMark( nDataBeginMark ); + xMark->jumpToMark( nDataBeginMark ); + OutStream->writeLong( nDataLen ); + OutStream->writeLong( nStoredControls ); + xMark->jumpToFurthest(); + xMark->deleteMark(nDataBeginMark); +} + +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > > ImplReadControls( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream > & InStream ) +{ + ::com::sun::star::uno::Reference< ::com::sun::star::io::XMarkableStream > xMark( InStream, ::com::sun::star::uno::UNO_QUERY ); + DBG_ASSERT( xMark.is(), "write: no XMarkableStream!" ); + + sal_Int32 nDataBeginMark = xMark->createMark(); + + sal_Int32 nDataLen = InStream->readLong(); + sal_uInt32 nCtrls = InStream->readLong(); + + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > > aSeq( nCtrls ); + for ( sal_uInt32 n = 0; n < nCtrls; n++ ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::io::XPersistObject > xObj = InStream->readObject(); + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > xI( xObj, ::com::sun::star::uno::UNO_QUERY ); + aSeq.getArray()[n] = xI; + } + + // Falls bereits mehr drinsteht als diese Version kennt: + xMark->jumpToMark( nDataBeginMark ); + InStream->skipBytes( nDataLen ); + xMark->deleteMark(nDataBeginMark); + return aSeq; +} + + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any StdTabControllerModel::queryAggregation( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XTabControllerModel*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XServiceInfo*, this ), + SAL_STATIC_CAST( ::com::sun::star::io::XPersistObject*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ) ); + return (aRet.hasValue() ? aRet : OWeakAggObject::queryAggregation( rType )); +} + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( StdTabControllerModel ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTabControllerModel>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XServiceInfo>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::io::XPersistObject>* ) NULL ) +IMPL_XTYPEPROVIDER_END + +sal_Bool StdTabControllerModel::getGroupControl( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return mbGroupControl; +} + +void StdTabControllerModel::setGroupControl( sal_Bool GroupControl ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + mbGroupControl = GroupControl; +} + +void StdTabControllerModel::setControlModels( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > >& Controls ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maControls.Reset(); + ImplSetControlModels( maControls, Controls ); +} + +::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > > StdTabControllerModel::getControlModels( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > > aSeq( ImplGetControlCount( maControls ) ); + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > * pRefs = aSeq.getArray(); + ImplGetControlModels( &pRefs, maControls ); + return aSeq; +} + +void StdTabControllerModel::setGroup( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > >& Group, const ::rtl::OUString& GroupName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + // Die Controls stehen eventuel flach in der Liste und werden jetzt gruppiert. + // Verschachtelte Gruppen sind erstmal nicht moeglich... + // Das erste Element der Gruppe welches auch schon in der flachen Liste + // stand bestimmt die Position der Gruppe. + + UnoControlModelEntry* pNewEntry = new UnoControlModelEntry; + pNewEntry->bGroup = sal_True; + pNewEntry->pGroup = new UnoControlModelEntryList; + pNewEntry->pGroup->SetName( GroupName ); + ImplSetControlModels( *pNewEntry->pGroup, Group ); + + sal_Bool bInserted = sal_False; + sal_uInt32 nElements = pNewEntry->pGroup->Count(); + for ( sal_uInt32 n = 0; n < nElements; n++ ) + { + UnoControlModelEntry* pEntry = pNewEntry->pGroup->GetObject( n ); + if ( !pEntry->bGroup ) + { + sal_uInt32 nPos = ImplGetControlPos( *pEntry->pxControl, maControls ); + // Eigentlich sollten alle Controls vorher in der flachen Liste stehen + DBG_ASSERT( nPos != CONTROLPOS_NOTFOUND, "setGroup - Element not found" ); + if ( nPos != CONTROLPOS_NOTFOUND ) + { + maControls.DestroyEntry( nPos ); + if ( !bInserted ) + { + maControls.Insert( pNewEntry, nPos ); + bInserted = sal_True; + } + } + } + } + if ( !bInserted ) + maControls.Insert( pNewEntry, LIST_APPEND ); +} + +sal_Int32 StdTabControllerModel::getGroupCount( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + // erstmal nur eine Ebene... + // Das Model und die Impl-Methoden arbeiten zwar rekursiv, aber das wird + // erstmal nich nach aussen gegeben. + + sal_Int32 nGroups = 0; + sal_uInt32 nEntries = maControls.Count(); + for ( sal_uInt32 n = 0; n < nEntries; n++ ) + { + UnoControlModelEntry* pEntry = maControls.GetObject( n ); + if ( pEntry->bGroup ) + nGroups++; + } + return nGroups; +} + +void StdTabControllerModel::getGroup( sal_Int32 nGroup, ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > >& rGroup, ::rtl::OUString& rName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > > aSeq; + sal_uInt32 nG = 0; + sal_uInt32 nEntries = maControls.Count(); + for ( sal_uInt32 n = 0; n < nEntries; n++ ) + { + UnoControlModelEntry* pEntry = maControls.GetObject( n ); + if ( pEntry->bGroup ) + { + if ( nG == (sal_uInt32)nGroup ) + { + sal_uInt32 nCount = ImplGetControlCount( *pEntry->pGroup ); + aSeq = ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > >( nCount ); + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > * pRefs = aSeq.getArray(); + ImplGetControlModels( &pRefs, *pEntry->pGroup ); + rName = pEntry->pGroup->GetName(); + break; + } + nG++; + } + } + rGroup = aSeq; +} + +void StdTabControllerModel::getGroupByName( const ::rtl::OUString& rName, ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > >& rGroup ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + sal_uInt32 nGroup = 0; + sal_uInt32 nEntries = maControls.Count(); + for ( sal_uInt32 n = 0; n < nEntries; n++ ) + { + UnoControlModelEntry* pEntry = maControls.GetObject( n ); + if ( pEntry->bGroup ) + { + if ( pEntry->pGroup->GetName() == rName ) + { + ::rtl::OUString Dummy; + getGroup( nGroup, rGroup, Dummy ); + break; + } + nGroup++; + } + } +} + + +// ::com::sun::star::io::XPersistObject +::rtl::OUString StdTabControllerModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString::createFromAscii( szServiceName_TabControllerModel ); +} + +void StdTabControllerModel::write( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream >& OutStream ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::uno::Reference< ::com::sun::star::io::XMarkableStream > xMark( OutStream, ::com::sun::star::uno::UNO_QUERY ); + DBG_ASSERT( xMark.is(), "write: no XMarkableStream!" ); + + OutStream->writeShort( UNOCONTROL_STREAMVERSION ); + + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > > aCtrls = getControlModels(); + ImplWriteControls( OutStream, aCtrls ); + + sal_uInt32 nGroups = getGroupCount(); + OutStream->writeLong( nGroups ); + for ( sal_uInt32 n = 0; n < nGroups; n++ ) + { + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > > aGroupCtrls; + ::rtl::OUString aGroupName; + getGroup( n, aGroupCtrls, aGroupName ); + OutStream->writeUTF( aGroupName ); + ImplWriteControls( OutStream, aGroupCtrls ); + } +} + +void StdTabControllerModel::read( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream >& InStream ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > > aSeq = ImplReadControls( InStream ); + setControlModels( aSeq ); + + sal_uInt32 nGroups = InStream->readLong(); + for ( sal_uInt32 n = 0; n < nGroups; n++ ) + { + ::rtl::OUString aGroupName = InStream->readUTF(); + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > > aCtrlSeq = ImplReadControls( InStream ); + setGroup( aCtrlSeq, aGroupName ); + } +} + + + + + diff --git a/toolkit/source/controls/tkscrollbar.cxx b/toolkit/source/controls/tkscrollbar.cxx new file mode 100644 index 000000000000..2de8b56131c8 --- /dev/null +++ b/toolkit/source/controls/tkscrollbar.cxx @@ -0,0 +1,294 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include "toolkit/controls/tkscrollbar.hxx" +#include "toolkit/helper/property.hxx" +#include "toolkit/helper/unopropertyarrayhelper.hxx" +#include <cppuhelper/typeprovider.hxx> +#include <tools/debug.hxx> + +// for introspection +#include <toolkit/awt/vclxwindows.hxx> + +//........................................................................ +namespace toolkit +{ +//........................................................................ + + using namespace ::com::sun::star; + + //==================================================================== + //= UnoControlScrollBarModel + //==================================================================== + //-------------------------------------------------------------------- + UnoControlScrollBarModel::UnoControlScrollBarModel() + { + UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXScrollBar ); + } + + //-------------------------------------------------------------------- + ::rtl::OUString UnoControlScrollBarModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException) + { + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlScrollBarModel ); + } + + //-------------------------------------------------------------------- + uno::Any UnoControlScrollBarModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const + { + switch ( nPropId ) + { + case BASEPROPERTY_LIVE_SCROLL: + return uno::makeAny( (sal_Bool)sal_False ); + case BASEPROPERTY_DEFAULTCONTROL: + return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlScrollBar ) ); + + default: + return UnoControlModel::ImplGetDefaultValue( nPropId ); + } + } + + //-------------------------------------------------------------------- + ::cppu::IPropertyArrayHelper& UnoControlScrollBarModel::getInfoHelper() + { + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; + } + + //-------------------------------------------------------------------- + uno::Reference< beans::XPropertySetInfo > UnoControlScrollBarModel::getPropertySetInfo( ) throw(uno::RuntimeException) + { + static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; + } + + + //==================================================================== + //= UnoControlScrollBarModel + //==================================================================== + UnoScrollBarControl::UnoScrollBarControl() + : maAdjustmentListeners( *this ) + { + } + + ::rtl::OUString UnoScrollBarControl::GetComponentServiceName() + { + return ::rtl::OUString::createFromAscii( "ScrollBar" ); + } + + // ::com::sun::star::uno::XInterface + uno::Any UnoScrollBarControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) + { + uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( awt::XAdjustmentListener*, this ), + SAL_STATIC_CAST( awt::XScrollBar*, this ) ); + return (aRet.hasValue() ? aRet : UnoControlBase::queryAggregation( rType )); + } + + // ::com::sun::star::lang::XTypeProvider + IMPL_XTYPEPROVIDER_START( UnoScrollBarControl ) + getCppuType( ( uno::Reference< awt::XAdjustmentListener>* ) NULL ), + getCppuType( ( uno::Reference< awt::XScrollBar>* ) NULL ), + UnoControlBase::getTypes() + IMPL_XTYPEPROVIDER_END + + void UnoScrollBarControl::dispose() throw(uno::RuntimeException) + { + lang::EventObject aEvt; + aEvt.Source = (::cppu::OWeakObject*)this; + maAdjustmentListeners.disposeAndClear( aEvt ); + UnoControl::dispose(); + } + + void UnoScrollBarControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) + { + UnoControl::createPeer( rxToolkit, rParentPeer ); + + uno::Reference < awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); + xScrollBar->addAdjustmentListener( this ); + } + + // ::com::sun::star::awt::XAdjustmentListener + void UnoScrollBarControl::adjustmentValueChanged( const ::com::sun::star::awt::AdjustmentEvent& rEvent ) throw(::com::sun::star::uno::RuntimeException) + { + switch ( rEvent.Type ) + { + case ::com::sun::star::awt::AdjustmentType_ADJUST_LINE: + case ::com::sun::star::awt::AdjustmentType_ADJUST_PAGE: + case ::com::sun::star::awt::AdjustmentType_ADJUST_ABS: + { + uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); + + if ( xScrollBar.is() ) + { + uno::Any aAny; + aAny <<= xScrollBar->getValue(); + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), aAny, sal_False ); + } + } + break; + default: + { + DBG_ERROR( "UnoScrollBarControl::adjustmentValueChanged - unknown Type" ); + + } + } + + if ( maAdjustmentListeners.getLength() ) + maAdjustmentListeners.adjustmentValueChanged( rEvent ); + } + + // ::com::sun::star::awt::XScrollBar + void UnoScrollBarControl::addAdjustmentListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XAdjustmentListener > & l ) throw(::com::sun::star::uno::RuntimeException) + { + maAdjustmentListeners.addInterface( l ); + } + + void UnoScrollBarControl::removeAdjustmentListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XAdjustmentListener > & l ) throw(::com::sun::star::uno::RuntimeException) + { + maAdjustmentListeners.removeInterface( l ); + } + + void UnoScrollBarControl::setValue( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) + { + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), uno::makeAny( n ), sal_True ); + } + + void UnoScrollBarControl::setValues( sal_Int32 nValue, sal_Int32 nVisible, sal_Int32 nMax ) throw(::com::sun::star::uno::RuntimeException) + { + uno::Any aAny; + aAny <<= nValue; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), aAny, sal_True ); + aAny <<= nVisible; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE ), aAny, sal_True ); + aAny <<= nMax; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX ), aAny, sal_True ); + } + + sal_Int32 UnoScrollBarControl::getValue() throw(::com::sun::star::uno::RuntimeException) + { + sal_Int32 n = 0; + if ( getPeer().is() ) + { + uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); + n = xScrollBar->getValue(); + } + return n; + } + + void UnoScrollBarControl::setMaximum( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) + { + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX ), uno::makeAny( n ), sal_True ); + } + + sal_Int32 UnoScrollBarControl::getMaximum() throw(::com::sun::star::uno::RuntimeException) + { + sal_Int32 n = 0; + if ( getPeer().is() ) + { + uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); + n = xScrollBar->getMaximum(); + } + return n; + } + + void UnoScrollBarControl::setLineIncrement( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) + { + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LINEINCREMENT ), uno::makeAny( n ), sal_True ); + } + + sal_Int32 UnoScrollBarControl::getLineIncrement() throw(::com::sun::star::uno::RuntimeException) + { + sal_Int32 n = 0; + if ( getPeer().is() ) + { + uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); + n = xScrollBar->getLineIncrement(); + } + return n; + } + + void UnoScrollBarControl::setBlockIncrement( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) + { + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_BLOCKINCREMENT ), uno::makeAny( n ), sal_True ); + } + + sal_Int32 UnoScrollBarControl::getBlockIncrement() throw(::com::sun::star::uno::RuntimeException) + { + sal_Int32 n = 0; + if ( getPeer().is() ) + { + uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); + n = xScrollBar->getBlockIncrement(); + } + return n; + } + + void UnoScrollBarControl::setVisibleSize( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) + { + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE ), uno::makeAny( n ), sal_True ); + } + + sal_Int32 UnoScrollBarControl::getVisibleSize() throw(::com::sun::star::uno::RuntimeException) + { + sal_Int32 n = 0; + if ( getPeer().is() ) + { + uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); + n = xScrollBar->getVisibleSize(); + } + return n; + } + + void UnoScrollBarControl::setOrientation( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) + { + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION ), uno::makeAny( n ), sal_True ); + } + + sal_Int32 UnoScrollBarControl::getOrientation() throw(::com::sun::star::uno::RuntimeException) + { + sal_Int32 n = 0; + if ( getPeer().is() ) + { + uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); + n = xScrollBar->getOrientation(); + } + return n; + } + + + +//........................................................................ +} // namespace toolkit +//........................................................................ + diff --git a/toolkit/source/controls/tksimpleanimation.cxx b/toolkit/source/controls/tksimpleanimation.cxx new file mode 100644 index 000000000000..9c32ba500407 --- /dev/null +++ b/toolkit/source/controls/tksimpleanimation.cxx @@ -0,0 +1,211 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include "toolkit/controls/tksimpleanimation.hxx" +#include "toolkit/helper/property.hxx" +#include "toolkit/helper/unopropertyarrayhelper.hxx" +#include <cppuhelper/typeprovider.hxx> +#include <tools/debug.hxx> + +//........................................................................ +namespace toolkit +{ +//........................................................................ + + using namespace ::com::sun::star; + + //==================================================================== + //= UnoSimpleAnimationControlModel + //==================================================================== + //-------------------------------------------------------------------- + UnoSimpleAnimationControlModel::UnoSimpleAnimationControlModel() + { + ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL ); + ImplRegisterProperty( BASEPROPERTY_REPEAT ); + ImplRegisterProperty( BASEPROPERTY_STEP_TIME ); + } + + //-------------------------------------------------------------------- + ::rtl::OUString UnoSimpleAnimationControlModel::getServiceName() + throw( uno::RuntimeException ) + { + return ::rtl::OUString::createFromAscii( szServiceName_UnoSimpleAnimationControlModel ); + } + + //-------------------------------------------------------------------- + uno::Any UnoSimpleAnimationControlModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const + { + switch ( nPropId ) + { + case BASEPROPERTY_DEFAULTCONTROL: + return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoSimpleAnimationControl ) ); + + case BASEPROPERTY_STEP_TIME: + return uno::makeAny( (sal_Int32) 100 ); + + case BASEPROPERTY_REPEAT: + return uno::makeAny( (sal_Bool)sal_True ); + + default: + return UnoControlModel::ImplGetDefaultValue( nPropId ); + } + } + + //-------------------------------------------------------------------- + ::cppu::IPropertyArrayHelper& UnoSimpleAnimationControlModel::getInfoHelper() + { + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + uno::Sequence< sal_Int32 > aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; + } + + //-------------------------------------------------------------------- + uno::Reference< beans::XPropertySetInfo > UnoSimpleAnimationControlModel::getPropertySetInfo( ) + throw( uno::RuntimeException ) + { + static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; + } + + //-------------------------------------------------------------------- + ::rtl::OUString SAL_CALL UnoSimpleAnimationControlModel::getImplementationName() + throw( uno::RuntimeException ) + { + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.toolkit.UnoSimpleAnimationControlModel" ) ); + } + + //-------------------------------------------------------------------- + uno::Sequence< ::rtl::OUString > SAL_CALL UnoSimpleAnimationControlModel::getSupportedServiceNames() + throw( uno::RuntimeException ) + { + uno::Sequence< ::rtl::OUString > aServices( UnoControlModel::getSupportedServiceNames() ); + aServices.realloc( aServices.getLength() + 1 ); + aServices[ aServices.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoSimpleAnimationControlModel ); + return aServices; + } + + //==================================================================== + //= UnoSimpleAnimationControl + //==================================================================== + //-------------------------------------------------------------------- + UnoSimpleAnimationControl::UnoSimpleAnimationControl() + { + } + + //-------------------------------------------------------------------- + ::rtl::OUString UnoSimpleAnimationControl::GetComponentServiceName() + { + return ::rtl::OUString::createFromAscii( "SimpleAnimation" ); + } + + //-------------------------------------------------------------------- + uno::Any UnoSimpleAnimationControl::queryAggregation( const uno::Type & rType ) + throw( uno::RuntimeException ) + { + uno::Any aRet = UnoControlBase::queryAggregation( rType ); + if ( !aRet.hasValue() ) + aRet = UnoSimpleAnimationControl_Base::queryInterface( rType ); + return aRet; + } + + //-------------------------------------------------------------------- + IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoSimpleAnimationControl, UnoControlBase, UnoSimpleAnimationControl_Base ) + + //-------------------------------------------------------------------- + void UnoSimpleAnimationControl::dispose() throw( uno::RuntimeException ) + { + ::osl::ClearableMutexGuard aGuard( GetMutex() ); + + UnoControl::dispose(); + } + + //-------------------------------------------------------------------- + ::rtl::OUString SAL_CALL UnoSimpleAnimationControl::getImplementationName() + throw( uno::RuntimeException ) + { + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.toolkit.UnoSimpleAnimationControl" ) ); + } + + //-------------------------------------------------------------------- + uno::Sequence< ::rtl::OUString > SAL_CALL UnoSimpleAnimationControl::getSupportedServiceNames() + throw( uno::RuntimeException ) + { + uno::Sequence< ::rtl::OUString > aServices( UnoControlBase::getSupportedServiceNames() ); + aServices.realloc( aServices.getLength() + 1 ); + aServices[ aServices.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoSimpleAnimationControl ); + return aServices; + } + + //-------------------------------------------------------------------- + void UnoSimpleAnimationControl::createPeer( const uno::Reference< awt::XToolkit > &rxToolkit, + const uno::Reference< awt::XWindowPeer > &rParentPeer ) + throw( uno::RuntimeException ) + { + UnoControl::createPeer( rxToolkit, rParentPeer ); + } + + //-------------------------------------------------------------------- + void SAL_CALL UnoSimpleAnimationControl::start() throw ( uno::RuntimeException ) + { + ::osl::MutexGuard aGuard( GetMutex() ); + + uno::Reference< XSimpleAnimation > xAnimation( getPeer(), uno::UNO_QUERY ); + if ( xAnimation.is() ) + xAnimation->start(); + } + + //-------------------------------------------------------------------- + void SAL_CALL UnoSimpleAnimationControl::stop() throw ( uno::RuntimeException ) + { + ::osl::MutexGuard aGuard( GetMutex() ); + + uno::Reference< XSimpleAnimation > xAnimation( getPeer(), uno::UNO_QUERY ); + if ( xAnimation.is() ) + xAnimation->stop(); + } + + //-------------------------------------------------------------------- + void SAL_CALL UnoSimpleAnimationControl::setImageList( const uno::Sequence< uno::Reference< graphic::XGraphic > >& ImageList ) + throw ( uno::RuntimeException ) + { + ::osl::MutexGuard aGuard( GetMutex() ); + + uno::Reference< XSimpleAnimation > xAnimation( getPeer(), uno::UNO_QUERY ); + if ( xAnimation.is() ) + xAnimation->setImageList( ImageList ); + } + +//........................................................................ +} // namespace toolkit +//........................................................................ + diff --git a/toolkit/source/controls/tkspinbutton.cxx b/toolkit/source/controls/tkspinbutton.cxx new file mode 100644 index 000000000000..5929dc7a4635 --- /dev/null +++ b/toolkit/source/controls/tkspinbutton.cxx @@ -0,0 +1,350 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include "toolkit/controls/tkspinbutton.hxx" +#include "toolkit/helper/property.hxx" +#include "toolkit/helper/unopropertyarrayhelper.hxx" +#include <com/sun/star/awt/ScrollBarOrientation.hpp> + + +#include <cppuhelper/typeprovider.hxx> +#include <tools/debug.hxx> + +//........................................................................ +namespace toolkit +{ +//........................................................................ + + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::awt; + using namespace ::com::sun::star::lang; + using namespace ::com::sun::star::beans; + + //==================================================================== + //= UnoSpinButtonModel + //==================================================================== + //-------------------------------------------------------------------- + UnoSpinButtonModel::UnoSpinButtonModel() + { + ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR ); + ImplRegisterProperty( BASEPROPERTY_BORDER ); + ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR ); + ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL ); + ImplRegisterProperty( BASEPROPERTY_ENABLED ); + ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE ); + ImplRegisterProperty( BASEPROPERTY_HELPTEXT ); + ImplRegisterProperty( BASEPROPERTY_HELPURL ); + ImplRegisterProperty( BASEPROPERTY_ORIENTATION ); + ImplRegisterProperty( BASEPROPERTY_PRINTABLE ); + ImplRegisterProperty( BASEPROPERTY_REPEAT ); + ImplRegisterProperty( BASEPROPERTY_REPEAT_DELAY ); + ImplRegisterProperty( BASEPROPERTY_SYMBOL_COLOR ); + ImplRegisterProperty( BASEPROPERTY_SPINVALUE ); + ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MIN ); + ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MAX ); + ImplRegisterProperty( BASEPROPERTY_SPININCREMENT ); + ImplRegisterProperty( BASEPROPERTY_TABSTOP ); + ImplRegisterProperty( BASEPROPERTY_WRITING_MODE ); + ImplRegisterProperty( BASEPROPERTY_CONTEXT_WRITING_MODE ); + } + + //-------------------------------------------------------------------- + ::rtl::OUString UnoSpinButtonModel::getServiceName( ) throw (RuntimeException) + { + return ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonModel ); + } + + //-------------------------------------------------------------------- + Any UnoSpinButtonModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const + { + switch ( nPropId ) + { + case BASEPROPERTY_DEFAULTCONTROL: + return makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonControl ) ); + + case BASEPROPERTY_BORDER: + return makeAny( (sal_Int16) 0 ); + + case BASEPROPERTY_REPEAT: + return makeAny( (sal_Bool)sal_True ); + + default: + return UnoControlModel::ImplGetDefaultValue( nPropId ); + } + } + + //-------------------------------------------------------------------- + ::cppu::IPropertyArrayHelper& UnoSpinButtonModel::getInfoHelper() + { + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; + } + + //-------------------------------------------------------------------- + Reference< XPropertySetInfo > UnoSpinButtonModel::getPropertySetInfo( ) throw(RuntimeException) + { + static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; + } + + //-------------------------------------------------------------------- + ::rtl::OUString SAL_CALL UnoSpinButtonModel::getImplementationName( ) throw(RuntimeException) + { + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.toolkit.UnoSpinButtonModel" ) ); + } + + //-------------------------------------------------------------------- + Sequence< ::rtl::OUString > SAL_CALL UnoSpinButtonModel::getSupportedServiceNames() throw(RuntimeException) + { + Sequence< ::rtl::OUString > aServices( UnoControlModel::getSupportedServiceNames() ); + aServices.realloc( aServices.getLength() + 1 ); + aServices[ aServices.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonModel ); + return aServices; + } + + //==================================================================== + //= UnoSpinButtonControl + //==================================================================== + //-------------------------------------------------------------------- + UnoSpinButtonControl::UnoSpinButtonControl() + :maAdjustmentListeners( *this ) + { + } + + //-------------------------------------------------------------------- + ::rtl::OUString UnoSpinButtonControl::GetComponentServiceName() + { + return ::rtl::OUString::createFromAscii( "SpinButton" ); + } + + //-------------------------------------------------------------------- + Any UnoSpinButtonControl::queryAggregation( const Type & rType ) throw(RuntimeException) + { + Any aRet = UnoControlBase::queryAggregation( rType ); + if ( !aRet.hasValue() ) + aRet = UnoSpinButtonControl_Base::queryInterface( rType ); + return aRet; + } + + //-------------------------------------------------------------------- + IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoSpinButtonControl, UnoControlBase, UnoSpinButtonControl_Base ) + + //-------------------------------------------------------------------- + void UnoSpinButtonControl::dispose() throw(RuntimeException) + { + ::osl::ClearableMutexGuard aGuard( GetMutex() ); + if ( maAdjustmentListeners.getLength() ) + { + Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY ); + if ( xSpinnable.is() ) + xSpinnable->removeAdjustmentListener( this ); + + EventObject aDisposeEvent; + aDisposeEvent.Source = *this; + + aGuard.clear(); + maAdjustmentListeners.disposeAndClear( aDisposeEvent ); + } + + UnoControl::dispose(); + } + + //-------------------------------------------------------------------- + ::rtl::OUString SAL_CALL UnoSpinButtonControl::getImplementationName( ) throw(RuntimeException) + { + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.toolkit.UnoSpinButtonControl" ) ); + } + + //-------------------------------------------------------------------- + Sequence< ::rtl::OUString > SAL_CALL UnoSpinButtonControl::getSupportedServiceNames() throw(RuntimeException) + { + Sequence< ::rtl::OUString > aServices( UnoControlBase::getSupportedServiceNames() ); + aServices.realloc( aServices.getLength() + 1 ); + aServices[ aServices.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoSpinButtonControl ); + return aServices; + } + + //-------------------------------------------------------------------- + void UnoSpinButtonControl::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer > & rParentPeer ) throw(RuntimeException) + { + UnoControl::createPeer( rxToolkit, rParentPeer ); + + Reference < XSpinValue > xSpinnable( getPeer(), UNO_QUERY ); + if ( xSpinnable.is() ) + xSpinnable->addAdjustmentListener( this ); + } + + //-------------------------------------------------------------------- + void UnoSpinButtonControl::adjustmentValueChanged( const AdjustmentEvent& rEvent ) throw(RuntimeException) + { + switch ( rEvent.Type ) + { + case AdjustmentType_ADJUST_LINE: + case AdjustmentType_ADJUST_PAGE: + case AdjustmentType_ADJUST_ABS: + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), makeAny( rEvent.Value ), sal_False ); + break; + default: + DBG_ERROR( "UnoSpinButtonControl::adjustmentValueChanged - unknown Type" ); + } + + if ( maAdjustmentListeners.getLength() ) + { + AdjustmentEvent aEvent( rEvent ); + aEvent.Source = *this; + maAdjustmentListeners.adjustmentValueChanged( aEvent ); + } + } + + //-------------------------------------------------------------------- + void UnoSpinButtonControl::addAdjustmentListener( const Reference< XAdjustmentListener > & listener ) throw(RuntimeException) + { + ::osl::MutexGuard aGuard( GetMutex() ); + maAdjustmentListeners.addInterface( listener ); + } + + //-------------------------------------------------------------------- + void UnoSpinButtonControl::removeAdjustmentListener( const Reference< XAdjustmentListener > & listener ) throw(RuntimeException) + { + ::osl::MutexGuard aGuard( GetMutex() ); + maAdjustmentListeners.removeInterface( listener ); + } + + //-------------------------------------------------------------------- + void SAL_CALL UnoSpinButtonControl::setValue( sal_Int32 value ) throw (RuntimeException) + { + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), makeAny( value ), sal_True ); + } + + //-------------------------------------------------------------------- + void SAL_CALL UnoSpinButtonControl::setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue ) throw (RuntimeException) + { + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN ), makeAny( minValue ), sal_True ); + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX ), makeAny( maxValue ), sal_True ); + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), makeAny( currentValue ), sal_True ); + } + + //-------------------------------------------------------------------- + sal_Int32 SAL_CALL UnoSpinButtonControl::getValue( ) throw (RuntimeException) + { + ::osl::MutexGuard aGuard( GetMutex() ); + sal_Int32 nValue = 0; + + Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY ); + if ( xSpinnable.is() ) + nValue = xSpinnable->getValue(); + + return nValue; + } + + //-------------------------------------------------------------------- + void SAL_CALL UnoSpinButtonControl::setMinimum( sal_Int32 minValue ) throw (RuntimeException) + { + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN ), makeAny( minValue ), sal_True ); + } + + //-------------------------------------------------------------------- + void SAL_CALL UnoSpinButtonControl::setMaximum( sal_Int32 maxValue ) throw (RuntimeException) + { + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX ), makeAny( maxValue ), sal_True ); + } + + //-------------------------------------------------------------------- + sal_Int32 SAL_CALL UnoSpinButtonControl::getMinimum( ) throw (RuntimeException) + { + ::osl::MutexGuard aGuard( GetMutex() ); + sal_Int32 nMin = 0; + + Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY ); + if ( xSpinnable.is() ) + nMin = xSpinnable->getMinimum(); + + return nMin; + } + + //-------------------------------------------------------------------- + sal_Int32 SAL_CALL UnoSpinButtonControl::getMaximum( ) throw (RuntimeException) + { + ::osl::MutexGuard aGuard( GetMutex() ); + sal_Int32 nMax = 0; + + Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY ); + if ( xSpinnable.is() ) + nMax = xSpinnable->getMaximum(); + + return nMax; + } + + //-------------------------------------------------------------------- + void SAL_CALL UnoSpinButtonControl::setSpinIncrement( sal_Int32 spinIncrement ) throw (RuntimeException) + { + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPININCREMENT ), makeAny( spinIncrement ), sal_True ); + } + + //-------------------------------------------------------------------- + sal_Int32 SAL_CALL UnoSpinButtonControl::getSpinIncrement( ) throw (RuntimeException) + { + ::osl::MutexGuard aGuard( GetMutex() ); + sal_Int32 nIncrement = 0; + + Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY ); + if ( xSpinnable.is() ) + nIncrement = xSpinnable->getSpinIncrement(); + + return nIncrement; + } + + //-------------------------------------------------------------------- + void SAL_CALL UnoSpinButtonControl::setOrientation( sal_Int32 orientation ) throw (NoSupportException, RuntimeException) + { + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION ), makeAny( orientation ), sal_True ); + } + + //-------------------------------------------------------------------- + sal_Int32 SAL_CALL UnoSpinButtonControl::getOrientation( ) throw (RuntimeException) + { + ::osl::MutexGuard aGuard( GetMutex() ); + sal_Int32 nOrientation = ScrollBarOrientation::HORIZONTAL; + + Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY ); + if ( xSpinnable.is() ) + nOrientation = xSpinnable->getOrientation(); + + return nOrientation; + } + +//........................................................................ +} // namespace toolkit +//........................................................................ + diff --git a/toolkit/source/controls/tkthrobber.cxx b/toolkit/source/controls/tkthrobber.cxx new file mode 100644 index 000000000000..978d3183fe23 --- /dev/null +++ b/toolkit/source/controls/tkthrobber.cxx @@ -0,0 +1,190 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include "toolkit/controls/tkthrobber.hxx" +#include "toolkit/helper/property.hxx" +#include "toolkit/helper/unopropertyarrayhelper.hxx" +#include <cppuhelper/typeprovider.hxx> +#include <tools/debug.hxx> + +//........................................................................ +namespace toolkit +{ +//........................................................................ + + using namespace ::com::sun::star; + + //==================================================================== + //= UnoThrobberControlModel + //==================================================================== + //-------------------------------------------------------------------- + UnoThrobberControlModel::UnoThrobberControlModel() + { + ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL ); + ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR ); + } + + //-------------------------------------------------------------------- + ::rtl::OUString UnoThrobberControlModel::getServiceName( ) throw ( uno::RuntimeException ) + { + return ::rtl::OUString::createFromAscii( szServiceName_UnoThrobberControlModel ); + } + + //-------------------------------------------------------------------- + uno::Any UnoThrobberControlModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const + { + switch ( nPropId ) + { + case BASEPROPERTY_DEFAULTCONTROL: + return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoThrobberControl ) ); + default: + return UnoControlModel::ImplGetDefaultValue( nPropId ); + } + } + + //-------------------------------------------------------------------- + ::cppu::IPropertyArrayHelper& UnoThrobberControlModel::getInfoHelper() + { + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + uno::Sequence< sal_Int32 > aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; + } + + //-------------------------------------------------------------------- + uno::Reference< beans::XPropertySetInfo > UnoThrobberControlModel::getPropertySetInfo() + throw( uno::RuntimeException ) + { + static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; + } + + //-------------------------------------------------------------------- + ::rtl::OUString SAL_CALL UnoThrobberControlModel::getImplementationName() + throw( uno::RuntimeException ) + { + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.toolkit.UnoThrobberControlModel" ) ); + } + + //-------------------------------------------------------------------- + uno::Sequence< ::rtl::OUString > SAL_CALL UnoThrobberControlModel::getSupportedServiceNames() + throw( uno::RuntimeException ) + { + uno::Sequence< ::rtl::OUString > aServices( UnoControlModel::getSupportedServiceNames() ); + aServices.realloc( aServices.getLength() + 1 ); + aServices[ aServices.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoThrobberControlModel ); + return aServices; + } + + //==================================================================== + //= UnoThrobberControl + //==================================================================== + //-------------------------------------------------------------------- + UnoThrobberControl::UnoThrobberControl() + { + } + + //-------------------------------------------------------------------- + ::rtl::OUString UnoThrobberControl::GetComponentServiceName() + { + return ::rtl::OUString::createFromAscii( "Throbber" ); + } + + //-------------------------------------------------------------------- + uno::Any UnoThrobberControl::queryAggregation( const uno::Type & rType ) throw( uno::RuntimeException ) + { + uno::Any aRet = UnoControlBase::queryAggregation( rType ); + if ( !aRet.hasValue() ) + aRet = UnoThrobberControl_Base::queryInterface( rType ); + return aRet; + } + + //-------------------------------------------------------------------- + IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoThrobberControl, UnoControlBase, UnoThrobberControl_Base ) + + //-------------------------------------------------------------------- + void UnoThrobberControl::dispose() throw( uno::RuntimeException ) + { + ::osl::ClearableMutexGuard aGuard( GetMutex() ); + + UnoControl::dispose(); + } + + //-------------------------------------------------------------------- + ::rtl::OUString SAL_CALL UnoThrobberControl::getImplementationName() + throw( uno::RuntimeException ) + { + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.toolkit.UnoThrobberControl" ) ); + } + + //-------------------------------------------------------------------- + uno::Sequence< ::rtl::OUString > SAL_CALL UnoThrobberControl::getSupportedServiceNames() + throw( uno::RuntimeException ) + { + uno::Sequence< ::rtl::OUString > aServices( UnoControlBase::getSupportedServiceNames() ); + aServices.realloc( aServices.getLength() + 1 ); + aServices[ aServices.getLength() - 1 ] = ::rtl::OUString::createFromAscii( szServiceName_UnoThrobberControl ); + return aServices; + } + + //-------------------------------------------------------------------- + void UnoThrobberControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, + const uno::Reference< awt::XWindowPeer > & rParentPeer ) + throw( uno::RuntimeException ) + { + UnoControl::createPeer( rxToolkit, rParentPeer ); + } + + //-------------------------------------------------------------------- + void SAL_CALL UnoThrobberControl::start() throw ( uno::RuntimeException ) + { + ::osl::MutexGuard aGuard( GetMutex() ); + + uno::Reference< XThrobber > xAnimation( getPeer(), uno::UNO_QUERY ); + if ( xAnimation.is() ) + xAnimation->start(); + } + + //-------------------------------------------------------------------- + void SAL_CALL UnoThrobberControl::stop() throw ( uno::RuntimeException ) + { + ::osl::MutexGuard aGuard( GetMutex() ); + + uno::Reference< XThrobber > xAnimation( getPeer(), uno::UNO_QUERY ); + if ( xAnimation.is() ) + xAnimation->stop(); + } + +//........................................................................ +} // namespace toolkit +//........................................................................ + diff --git a/toolkit/source/controls/tree/makefile.mk b/toolkit/source/controls/tree/makefile.mk new file mode 100644 index 000000000000..4e72b62b416b --- /dev/null +++ b/toolkit/source/controls/tree/makefile.mk @@ -0,0 +1,48 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME=toolkit +TARGET=tree + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/util$/makefile.pmk + +# --- Files -------------------------------------------------------- + +SLOFILES= \ + $(SLO)$/treecontrol.obj\ + $(SLO)$/treedatamodel.obj + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk diff --git a/toolkit/source/controls/tree/treecontrol.cxx b/toolkit/source/controls/tree/treecontrol.cxx new file mode 100644 index 000000000000..5655e4e10abc --- /dev/null +++ b/toolkit/source/controls/tree/treecontrol.cxx @@ -0,0 +1,502 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + +#ifndef _TOOLKIT_TREE_CONTROL_HXX +#include <treecontrol.hxx> +#endif + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/view/SelectionType.hpp> +#include <com/sun/star/awt/tree/XTreeDataModel.hpp> +#include <toolkit/helper/unopropertyarrayhelper.hxx> +#include <toolkit/helper/property.hxx> +#include <com/sun/star/awt/XVclWindowPeer.hpp> +#include <comphelper/processfactory.hxx> +#include <osl/diagnose.h> + +using ::rtl::OUString; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::awt::tree; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::view; + +namespace toolkit +{ +// ---------------------------------------------------- +// class UnoTreeModel +// ---------------------------------------------------- +UnoTreeModel::UnoTreeModel() +{ + ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR ); + ImplRegisterProperty( BASEPROPERTY_BORDER ); + ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR ); + ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL ); + ImplRegisterProperty( BASEPROPERTY_ENABLED ); + ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE ); + ImplRegisterProperty( BASEPROPERTY_FILLCOLOR ); + ImplRegisterProperty( BASEPROPERTY_HELPTEXT ); + ImplRegisterProperty( BASEPROPERTY_HELPURL ); + ImplRegisterProperty( BASEPROPERTY_PRINTABLE ); + ImplRegisterProperty( BASEPROPERTY_TREE_SELECTIONTYPE ); + ImplRegisterProperty( BASEPROPERTY_TREE_EDITABLE ); + ImplRegisterProperty( BASEPROPERTY_TREE_DATAMODEL ); + ImplRegisterProperty( BASEPROPERTY_TREE_ROOTDISPLAYED ); + ImplRegisterProperty( BASEPROPERTY_TREE_SHOWSHANDLES ); + ImplRegisterProperty( BASEPROPERTY_TREE_SHOWSROOTHANDLES ); + ImplRegisterProperty( BASEPROPERTY_TREE_ROWHEIGHT ); + ImplRegisterProperty( BASEPROPERTY_TREE_INVOKESSTOPNODEEDITING ); +} + +UnoTreeModel::UnoTreeModel( const UnoTreeModel& rModel ) +: UnoControlModel( rModel ) +{ +} + +UnoControlModel* UnoTreeModel::Clone() const +{ + return new UnoTreeModel( *this ); +} + +OUString UnoTreeModel::getServiceName() throw(RuntimeException) +{ + return OUString::createFromAscii( szServiceName_TreeControlModel ); +} + +Any UnoTreeModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + switch( nPropId ) + { + case BASEPROPERTY_TREE_SELECTIONTYPE: + return Any( SelectionType_NONE ); + case BASEPROPERTY_TREE_ROWHEIGHT: + return Any( sal_Int32( 0 ) ); + case BASEPROPERTY_TREE_DATAMODEL: + return Any( Reference< XTreeDataModel >( 0 ) ); + case BASEPROPERTY_TREE_EDITABLE: + case BASEPROPERTY_TREE_INVOKESSTOPNODEEDITING: + return Any( sal_False ); + case BASEPROPERTY_TREE_ROOTDISPLAYED: + case BASEPROPERTY_TREE_SHOWSROOTHANDLES: + case BASEPROPERTY_TREE_SHOWSHANDLES: + return Any( sal_True ); + case BASEPROPERTY_DEFAULTCONTROL: + return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_TreeControl ) ); + default: + return UnoControlModel::ImplGetDefaultValue( nPropId ); + } +} + +::cppu::IPropertyArrayHelper& UnoTreeModel::getInfoHelper() +{ + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + +// XMultiPropertySet +Reference< XPropertySetInfo > UnoTreeModel::getPropertySetInfo( ) throw(RuntimeException) +{ + static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + + +// ---------------------------------------------------- +// class UnoTreeControl +// ---------------------------------------------------- +UnoTreeControl::UnoTreeControl() +: maSelectionListeners( *this ) +, maTreeExpansionListeners( *this ) +, maTreeEditListeners( *this ) +{ +} + +OUString UnoTreeControl::GetComponentServiceName() +{ + return OUString::createFromAscii( "Tree" ); +} + +// ------------------------------------------------------------------- +// ::com::sun::star::view::XSelectionSupplier +// ------------------------------------------------------------------- + +sal_Bool SAL_CALL UnoTreeControl::select( const Any& rSelection ) throw (IllegalArgumentException, RuntimeException) +{ + return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->select( rSelection ); +} + +// ------------------------------------------------------------------- + +Any SAL_CALL UnoTreeControl::getSelection() throw (RuntimeException) +{ + return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->getSelection(); +} + +// ------------------------------------------------------------------- + +void SAL_CALL UnoTreeControl::addSelectionChangeListener( const Reference< XSelectionChangeListener >& xListener ) throw (RuntimeException) +{ + maSelectionListeners.addInterface( xListener ); + if( getPeer().is() && (maSelectionListeners.getLength() == 1) ) + { + // maSelectionListeners acts as a proxy, + // add it to the peer if this is the first listener added to that proxy + Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); + Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->addSelectionChangeListener(&maSelectionListeners); + } +} + +// ------------------------------------------------------------------- + +void SAL_CALL UnoTreeControl::removeSelectionChangeListener( const Reference< XSelectionChangeListener >& xListener ) throw (RuntimeException) +{ + if( getPeer().is() && (maSelectionListeners.getLength() == 1) ) + { + // maSelectionListeners acts as a proxy, + // remove it from the peer if this is the last listener removed from that proxy + Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); + Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->removeSelectionChangeListener(&maSelectionListeners); + } + maSelectionListeners.removeInterface( xListener ); +} + +// ------------------------------------------------------------------- +// ::com::sun::star::view::XMultiSelectionSupplier +// ------------------------------------------------------------------- + +sal_Bool SAL_CALL UnoTreeControl::addSelection( const Any& rSelection ) throw (IllegalArgumentException, RuntimeException) +{ + return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->addSelection(rSelection); +} + +// ------------------------------------------------------------------- + +void SAL_CALL UnoTreeControl::removeSelection( const Any& rSelection ) throw (IllegalArgumentException, RuntimeException) +{ + Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); + Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->removeSelection(rSelection); +} + +// ------------------------------------------------------------------- + +void SAL_CALL UnoTreeControl::clearSelection() throw (RuntimeException) +{ + Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); + Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->clearSelection(); +} + +// ------------------------------------------------------------------- + +sal_Int32 SAL_CALL UnoTreeControl::getSelectionCount() throw (RuntimeException) +{ + return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->getSelectionCount(); +} + +// ------------------------------------------------------------------- + +Reference< XEnumeration > SAL_CALL UnoTreeControl::createSelectionEnumeration() throw (RuntimeException) +{ + return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->createSelectionEnumeration(); +} + +// ------------------------------------------------------------------- + +Reference< XEnumeration > SAL_CALL UnoTreeControl::createReverseSelectionEnumeration() throw (RuntimeException) +{ + return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->createReverseSelectionEnumeration(); +} + +// -------------------------------------------------------------------- +// XTreeControl +// -------------------------------------------------------------------- + +OUString SAL_CALL UnoTreeControl::getDefaultExpandedGraphicURL() throw (RuntimeException) +{ + return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->getDefaultExpandedGraphicURL(); +} + +// ------------------------------------------------------------------- + +void SAL_CALL UnoTreeControl::setDefaultExpandedGraphicURL( const OUString& _defaultexpansiongraphicurl ) throw (RuntimeException) +{ + Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); + Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->setDefaultExpandedGraphicURL(_defaultexpansiongraphicurl); +} + +// ------------------------------------------------------------------- + +OUString SAL_CALL UnoTreeControl::getDefaultCollapsedGraphicURL() throw (RuntimeException) +{ + return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->getDefaultCollapsedGraphicURL(); +} + +// ------------------------------------------------------------------- + +void SAL_CALL UnoTreeControl::setDefaultCollapsedGraphicURL( const OUString& _defaultcollapsedgraphicurl ) throw (RuntimeException) +{ + Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); + Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->setDefaultCollapsedGraphicURL(_defaultcollapsedgraphicurl); +} + +// ------------------------------------------------------------------- + +sal_Bool SAL_CALL UnoTreeControl::isNodeExpanded( const Reference< XTreeNode >& xNode ) throw (RuntimeException, IllegalArgumentException) +{ + return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->isNodeExpanded(xNode); +} + +// ------------------------------------------------------------------- + +sal_Bool SAL_CALL UnoTreeControl::isNodeCollapsed( const Reference< XTreeNode >& xNode ) throw (RuntimeException, IllegalArgumentException) +{ + return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->isNodeCollapsed(xNode); +} + +// ------------------------------------------------------------------- + +void SAL_CALL UnoTreeControl::makeNodeVisible( const Reference< XTreeNode >& xNode ) throw (RuntimeException, ExpandVetoException, IllegalArgumentException) +{ + Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); + Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->makeNodeVisible(xNode); +} + +// ------------------------------------------------------------------- + +sal_Bool SAL_CALL UnoTreeControl::isNodeVisible( const Reference< XTreeNode >& xNode ) throw (RuntimeException, IllegalArgumentException) +{ + return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->isNodeVisible(xNode); +} + +// ------------------------------------------------------------------- + +void SAL_CALL UnoTreeControl::expandNode( const Reference< XTreeNode >& xNode ) throw (RuntimeException, ExpandVetoException, IllegalArgumentException) +{ + Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); + Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->expandNode(xNode); +} + +// ------------------------------------------------------------------- + +void SAL_CALL UnoTreeControl::collapseNode( const Reference< XTreeNode >& xNode ) throw (RuntimeException, ExpandVetoException, IllegalArgumentException) +{ + Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); + Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->collapseNode(xNode); +} + +// ------------------------------------------------------------------- + +void SAL_CALL UnoTreeControl::addTreeExpansionListener( const Reference< XTreeExpansionListener >& xListener ) throw (RuntimeException) +{ + maTreeExpansionListeners.addInterface( xListener ); + if( getPeer().is() && (maTreeExpansionListeners.getLength() == 1) ) + { + // maSelectionListeners acts as a proxy, + // add it to the peer if this is the first listener added to that proxy + Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); + Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->addTreeExpansionListener(&maTreeExpansionListeners); + } +} + +// ------------------------------------------------------------------- + +void SAL_CALL UnoTreeControl::removeTreeExpansionListener( const Reference< XTreeExpansionListener >& xListener ) throw (RuntimeException) +{ + if( getPeer().is() && (maTreeExpansionListeners.getLength() == 1) ) + { + // maSelectionListeners acts as a proxy, + // remove it from the peer if this is the last listener removed from that proxy + Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); + Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->removeTreeExpansionListener(&maTreeExpansionListeners); + } + maTreeExpansionListeners.removeInterface( xListener ); +} + +// ------------------------------------------------------------------- + +Reference< XTreeNode > SAL_CALL UnoTreeControl::getNodeForLocation( sal_Int32 x, sal_Int32 y ) throw (RuntimeException) +{ + return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->getNodeForLocation(x,y); +} + +// ------------------------------------------------------------------- + +Reference< XTreeNode > SAL_CALL UnoTreeControl::getClosestNodeForLocation( sal_Int32 x, sal_Int32 y ) throw (RuntimeException) +{ + return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->getClosestNodeForLocation(x,y); +} + +// ------------------------------------------------------------------- + +sal_Bool SAL_CALL UnoTreeControl::isEditing( ) throw (RuntimeException) +{ + return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->isEditing(); +} + +// ------------------------------------------------------------------- + +sal_Bool SAL_CALL UnoTreeControl::stopEditing() throw (RuntimeException) +{ + return Reference< XTreeControl >( getPeer(), UNO_QUERY_THROW )->stopEditing(); +} + +// ------------------------------------------------------------------- + +void SAL_CALL UnoTreeControl::cancelEditing() throw (RuntimeException) +{ + Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); + Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->cancelEditing(); +} + +// ------------------------------------------------------------------- + +void SAL_CALL UnoTreeControl::startEditingAtNode( const Reference< XTreeNode >& xNode ) throw (IllegalArgumentException, RuntimeException) +{ + Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); + Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->startEditingAtNode(xNode); +} + +// ------------------------------------------------------------------- + +void SAL_CALL UnoTreeControl::addTreeEditListener( const Reference< XTreeEditListener >& xListener ) throw (RuntimeException) +{ + maTreeEditListeners.addInterface( xListener ); + if( getPeer().is() && (maTreeEditListeners.getLength() == 1) ) + { + // maSelectionListeners acts as a proxy, + // add it to the peer if this is the first listener added to that proxy + Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); + Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->addTreeEditListener(&maTreeEditListeners); + } +} + +// ------------------------------------------------------------------- + +void SAL_CALL UnoTreeControl::removeTreeEditListener( const Reference< XTreeEditListener >& xListener ) throw (RuntimeException) +{ + if( getPeer().is() && (maTreeEditListeners.getLength() == 1) ) + { + // maSelectionListeners acts as a proxy, + // remove it from the peer if this is the last listener removed from that proxy + Reference< XWindowPeer > xGcc3WorkaroundTemporary( getPeer()); + Reference< XTreeControl >( xGcc3WorkaroundTemporary, UNO_QUERY_THROW )->removeTreeEditListener(&maTreeEditListeners); + } + maTreeEditListeners.removeInterface( xListener ); +} + +// ------------------------------------------------------------------- +// XComponent +// ------------------------------------------------------------------- + +void SAL_CALL UnoTreeControl::dispose( ) throw(RuntimeException) +{ + lang::EventObject aEvt; + aEvt.Source = static_cast< ::cppu::OWeakObject* >(this); + maSelectionListeners.disposeAndClear( aEvt ); + maTreeExpansionListeners.disposeAndClear( aEvt ); + UnoControl::dispose(); +} + +void UnoTreeControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) +{ + UnoControlBase::createPeer( rxToolkit, rParentPeer ); + + Reference< XTreeControl > xTree( getPeer(), UNO_QUERY_THROW ); + if( maSelectionListeners.getLength() ) + xTree->addSelectionChangeListener( &maSelectionListeners ); + if( maTreeExpansionListeners.getLength() ) + xTree->addTreeExpansionListener( &maTreeExpansionListeners ); +} + +} + +Reference< XInterface > SAL_CALL TreeControl_CreateInstance( const Reference< XMultiServiceFactory >& ) +{ + return Reference < XInterface >( ( ::cppu::OWeakObject* ) new ::toolkit::UnoTreeControl ); +} + +Reference< XInterface > SAL_CALL TreeControlModel_CreateInstance( const Reference< XMultiServiceFactory >& ) +{ + return Reference < XInterface >( ( ::cppu::OWeakObject* ) new ::toolkit::UnoTreeModel ); +} + +void SAL_CALL TreeEditListenerMultiplexer::nodeEditing( const Reference< XTreeNode >& Node ) throw (RuntimeException, ::com::sun::star::util::VetoException) +{ + ::cppu::OInterfaceIteratorHelper aIt( *this ); + while( aIt.hasMoreElements() ) + { + Reference< XTreeEditListener > xListener(static_cast< XTreeEditListener* >( aIt.next() ) ); + try + { + xListener->nodeEditing( Node ); + } + catch( DisposedException& e ) + { + OSL_ENSURE( e.Context.is(), "caught DisposedException with empty Context field" ); + if ( e.Context == xListener || !e.Context.is() ) + aIt.remove(); + } + catch( RuntimeException& e ) + { + (void)e; + DISPLAY_EXCEPTION( TreeEditListenerMultiplexer, nodeEditing, e ) + } + } +} + +void SAL_CALL TreeEditListenerMultiplexer::nodeEdited( const Reference< XTreeNode >& Node, const OUString& NewText ) throw (RuntimeException) +{ + ::cppu::OInterfaceIteratorHelper aIt( *this ); + while( aIt.hasMoreElements() ) + { + Reference< XTreeEditListener > xListener( static_cast< XTreeEditListener* >( aIt.next() ) ); + try + { + xListener->nodeEdited( Node, NewText ); + } + catch( DisposedException& e ) + { + OSL_ENSURE( e.Context.is(), "caught DisposedException with empty Context field" ); + if ( e.Context == xListener || !e.Context.is() ) + aIt.remove(); + } + catch( RuntimeException& e ) + { + (void)e; + DISPLAY_EXCEPTION( TreeEditListenerMultiplexer, nodeEdited, e ) + } + } +} diff --git a/toolkit/source/controls/tree/treecontrol.hxx b/toolkit/source/controls/tree/treecontrol.hxx new file mode 100644 index 000000000000..0cae86616aa4 --- /dev/null +++ b/toolkit/source/controls/tree/treecontrol.hxx @@ -0,0 +1,136 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef TOOLKIT_TREE_CONTROL_HXX +#define TOOLKIT_TREE_CONTROL_HXX + +#include <com/sun/star/awt/tree/XTreeControl.hpp> +#include <toolkit/controls/unocontrols.hxx> +#include <toolkit/controls/unocontrolmodel.hxx> +#include <toolkit/helper/servicenames.hxx> +#include <cppuhelper/implbase1.hxx> + +#include <toolkit/helper/listenermultiplexer.hxx> + +namespace toolkit { + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::container; + +// =================================================================== +// = UnoTreeModel +// =================================================================== +class UnoTreeModel : public UnoControlModel +{ +protected: + Any ImplGetDefaultValue( sal_uInt16 nPropId ) const; + ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); + +public: + UnoTreeModel(); + UnoTreeModel( const UnoTreeModel& rModel ); + + UnoControlModel* Clone() const; + + // ::com::sun::star::beans::XMultiPropertySet + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException); + + // ::com::sun::star::io::XPersistObject + ::rtl::OUString SAL_CALL getServiceName() throw(::com::sun::star::uno::RuntimeException); + + // XServiceInfo + DECLIMPL_SERVICEINFO_DERIVED( UnoTreeModel, UnoControlModel, szServiceName_TreeControlModel ) +}; + + +// =================================================================== +// = UnoTreeControl +// =================================================================== +class UnoTreeControl : public ::cppu::ImplInheritanceHelper1< UnoControlBase, ::com::sun::star::awt::tree::XTreeControl > +{ +public: + UnoTreeControl(); + ::rtl::OUString GetComponentServiceName(); + + // ::com::sun::star::lang::XComponent + void SAL_CALL dispose( ) throw(::com::sun::star::uno::RuntimeException); + + // ::com::sun::star::awt::XControl + void SAL_CALL createPeer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit >& Toolkit, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& Parent ) throw(::com::sun::star::uno::RuntimeException); + + // ::com::sun::star::view::XSelectionSupplier + virtual ::sal_Bool SAL_CALL select( const ::com::sun::star::uno::Any& xSelection ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL getSelection( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addSelectionChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionChangeListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeSelectionChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionChangeListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); + + // ::com::sun::star::view::XMultiSelectionSupplier + virtual ::sal_Bool SAL_CALL addSelection( const ::com::sun::star::uno::Any& Selection ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeSelection( const ::com::sun::star::uno::Any& Selection ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL clearSelection( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getSelectionCount( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createSelectionEnumeration( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createReverseSelectionEnumeration( ) throw (::com::sun::star::uno::RuntimeException); + + // ::com::sun::star::awt::XTreeControl + virtual ::rtl::OUString SAL_CALL getDefaultExpandedGraphicURL() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setDefaultExpandedGraphicURL( const ::rtl::OUString& _defaultexpandedgraphicurl ) throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getDefaultCollapsedGraphicURL() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setDefaultCollapsedGraphicURL( const ::rtl::OUString& _defaultcollapsedgraphicurl ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL isNodeExpanded( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode >& Node ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL isNodeCollapsed( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode >& Node ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL makeNodeVisible( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode >& Node ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::awt::tree::ExpandVetoException, ::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL isNodeVisible( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode >& Node ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL expandNode( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode >& Node ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::awt::tree::ExpandVetoException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL collapseNode( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode >& Node ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::awt::tree::ExpandVetoException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addTreeExpansionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeExpansionListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeTreeExpansionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeExpansionListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode > SAL_CALL getNodeForLocation( ::sal_Int32 x, ::sal_Int32 y ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode > SAL_CALL getClosestNodeForLocation( ::sal_Int32 x, ::sal_Int32 y ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL isEditing( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL stopEditing( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL cancelEditing( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL startEditingAtNode( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode >& Node ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addTreeEditListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeEditListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeTreeEditListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeEditListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); + + // ::com::sun::star::lang::XServiceInfo + DECLIMPL_SERVICEINFO_DERIVED( UnoTreeControl, UnoControlBase, szServiceName_TreeControl ) + + using UnoControl::getPeer; +private: + TreeSelectionListenerMultiplexer maSelectionListeners; + TreeExpansionListenerMultiplexer maTreeExpansionListeners; + TreeEditListenerMultiplexer maTreeEditListeners; +}; + +} // toolkit + +#endif // _TOOLKIT_TREE_CONTROL_HXX diff --git a/toolkit/source/controls/tree/treedatamodel.cxx b/toolkit/source/controls/tree/treedatamodel.cxx new file mode 100644 index 000000000000..8ca76c0e57a8 --- /dev/null +++ b/toolkit/source/controls/tree/treedatamodel.cxx @@ -0,0 +1,673 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <com/sun/star/awt/tree/XMutableTreeDataModel.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/implbase3.hxx> +#include <rtl/ref.hxx> +#include <toolkit/helper/mutexandbroadcasthelper.hxx> +#include <toolkit/helper/servicenames.hxx> + +using ::rtl::OUString; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::awt::tree; +using namespace ::com::sun::star::lang; + +namespace toolkit +{ + + enum broadcast_type { nodes_changed, nodes_inserted, nodes_removed, structure_changed }; + +class MutableTreeNode; +class MutableTreeDataModel; + +typedef rtl::Reference< MutableTreeNode > MutableTreeNodeRef; +typedef std::vector< MutableTreeNodeRef > TreeNodeVector; +typedef rtl::Reference< MutableTreeDataModel > MutableTreeDataModelRef; + +static void implThrowIllegalArgumentException() throw( IllegalArgumentException ) +{ + throw IllegalArgumentException(); +} + +class MutableTreeDataModel : public ::cppu::WeakAggImplHelper2< XMutableTreeDataModel, XServiceInfo >, + public MutexAndBroadcastHelper +{ +public: + MutableTreeDataModel(); + virtual ~MutableTreeDataModel(); + + void broadcast( broadcast_type eType, const Reference< XTreeNode >& xParentNode, const Reference< XTreeNode >* pNodes, sal_Int32 nNodes ); + + // XMutableTreeDataModel + virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XMutableTreeNode > SAL_CALL createNode( const ::com::sun::star::uno::Any& DisplayValue, ::sal_Bool ChildsOnDemand ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setRoot( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XMutableTreeNode >& RootNode ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + + // XTreeDataModel + virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode > SAL_CALL getRoot( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addTreeDataModelListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeDataModelListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeTreeDataModelListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeDataModelListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); + + // XComponent + virtual void SAL_CALL dispose( ) throw (RuntimeException); + virtual void SAL_CALL addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException); + virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& aListener ) throw (RuntimeException); + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName( ) throw (RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException); + virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException); + +private: + bool mbDisposed; + Reference< XTreeNode > mxRootNode; +}; + +class MutableTreeNode: public ::cppu::WeakAggImplHelper2< XMutableTreeNode, XServiceInfo > +{ + friend class MutableTreeDataModel; + +public: + MutableTreeNode( const MutableTreeDataModelRef& xModel, const Any& rValue, sal_Bool bChildsOnDemand ); + virtual ~MutableTreeNode(); + + void setParent( MutableTreeNode* pParent ); + void broadcast_changes(); + void broadcast_changes(const Reference< XTreeNode >& xNode, bool bNew); + + // XMutableTreeNode + virtual ::com::sun::star::uno::Any SAL_CALL getDataValue() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setDataValue( const ::com::sun::star::uno::Any& _datavalue ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL appendChild( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XMutableTreeNode >& ChildNode ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL insertChildByIndex( ::sal_Int32 Index, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XMutableTreeNode >& ChildNode ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeChildByIndex( ::sal_Int32 Index ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setHasChildrenOnDemand( ::sal_Bool ChildrenOnDemand ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setDisplayValue( const ::com::sun::star::uno::Any& Value ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setNodeGraphicURL( const ::rtl::OUString& URL ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setExpandedGraphicURL( const ::rtl::OUString& URL ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setCollapsedGraphicURL( const ::rtl::OUString& URL ) throw (::com::sun::star::uno::RuntimeException); + + // XTreeNode + virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode > SAL_CALL getChildAt( ::sal_Int32 Index ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getChildCount( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode > SAL_CALL getParent( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getIndex( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::tree::XTreeNode >& Node ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL hasChildrenOnDemand( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL getDisplayValue( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getNodeGraphicURL( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getExpandedGraphicURL( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getCollapsedGraphicURL( ) throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName( ) throw (RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException); + virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException); + + static MutableTreeNode* getImplementation( const Reference< XTreeNode >& xNode, bool bThrows ) throw (IllegalArgumentException); + Reference< XTreeNode > getReference( MutableTreeNode* pNode ) + { + return Reference< XTreeNode >( pNode ); + } + +private: + TreeNodeVector maChilds; + Any maDisplayValue; + Any maDataValue; + sal_Bool mbHasChildsOnDemand; + ::osl::Mutex maMutex; + MutableTreeNode* mpParent; + MutableTreeDataModelRef mxModel; + OUString maNodeGraphicURL; + OUString maExpandedGraphicURL; + OUString maCollapsedGraphicURL; + bool mbIsInserted; +}; + +/////////////////////////////////////////////////////////////////////// +// class MutableTreeDataModel +/////////////////////////////////////////////////////////////////////// + +MutableTreeDataModel::MutableTreeDataModel() +: mbDisposed( false ) +{ +} + +//--------------------------------------------------------------------- + +MutableTreeDataModel::~MutableTreeDataModel() +{ +} + +//--------------------------------------------------------------------- + +void MutableTreeDataModel::broadcast( broadcast_type eType, const Reference< XTreeNode >& xParentNode, const Reference< XTreeNode >* pNodes, sal_Int32 nNodes ) +{ + ::cppu::OInterfaceContainerHelper* pIter = BrdcstHelper.getContainer( XTreeDataModelListener::static_type() ); + if( pIter ) + { + Reference< XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); + const Sequence< Reference< XTreeNode > > aNodes( pNodes, nNodes ); + TreeDataModelEvent aEvent( xSource, aNodes, xParentNode ); + + ::cppu::OInterfaceIteratorHelper aListIter(*pIter); + while(aListIter.hasMoreElements()) + { + XTreeDataModelListener* pListener = static_cast<XTreeDataModelListener*>(aListIter.next()); + switch( eType ) + { + case nodes_changed: pListener->treeNodesChanged(aEvent); break; + case nodes_inserted: pListener->treeNodesInserted(aEvent); break; + case nodes_removed: pListener->treeNodesRemoved(aEvent); break; + case structure_changed: pListener->treeStructureChanged(aEvent); break; + } + } + } +} + +//--------------------------------------------------------------------- +// XMutableTreeDataModel +//--------------------------------------------------------------------- + +Reference< XMutableTreeNode > SAL_CALL MutableTreeDataModel::createNode( const Any& aValue, sal_Bool bChildsOnDemand ) throw (RuntimeException) +{ + return new MutableTreeNode( this, aValue, bChildsOnDemand ); +} + +//--------------------------------------------------------------------- + +void SAL_CALL MutableTreeDataModel::setRoot( const Reference< XMutableTreeNode >& xNode ) throw (IllegalArgumentException, RuntimeException) +{ + if( !xNode.is() ) + throw IllegalArgumentException(); + + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + if( xNode != mxRootNode ) + { + if( mxRootNode.is() ) + { + MutableTreeNodeRef xOldImpl( dynamic_cast< MutableTreeNode* >( mxRootNode.get() ) ); + if( xOldImpl.is() ) + xOldImpl->mbIsInserted = false; + } + + MutableTreeNodeRef xImpl( dynamic_cast< MutableTreeNode* >( xNode.get() ) ); + if( !xImpl.is() || xImpl->mbIsInserted ) + throw IllegalArgumentException(); + + xImpl->mbIsInserted = true; + mxRootNode.set(xImpl.get()); + + Reference< XTreeNode > xParentNode; + broadcast( structure_changed, xParentNode, &mxRootNode, 1 ); + } +} + +//--------------------------------------------------------------------- +// XTreeDataModel +//--------------------------------------------------------------------- + +Reference< XTreeNode > SAL_CALL MutableTreeDataModel::getRoot( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + return mxRootNode; +} + +//--------------------------------------------------------------------- + +void SAL_CALL MutableTreeDataModel::addTreeDataModelListener( const Reference< XTreeDataModelListener >& xListener ) throw (RuntimeException) +{ + BrdcstHelper.addListener( XTreeDataModelListener::static_type(), xListener ); +} + +//--------------------------------------------------------------------- + +void SAL_CALL MutableTreeDataModel::removeTreeDataModelListener( const Reference< XTreeDataModelListener >& xListener ) throw (RuntimeException) +{ + BrdcstHelper.removeListener( XTreeDataModelListener::static_type(), xListener ); +} + +//--------------------------------------------------------------------- +// XComponent +//--------------------------------------------------------------------- + +void SAL_CALL MutableTreeDataModel::dispose() throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if( !mbDisposed ) + { + mbDisposed = true; + ::com::sun::star::lang::EventObject aEvent; + aEvent.Source.set( static_cast< ::cppu::OWeakObject* >( this ) ); + BrdcstHelper.aLC.disposeAndClear( aEvent ); + } +} + +//--------------------------------------------------------------------- + +void SAL_CALL MutableTreeDataModel::addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException) +{ + BrdcstHelper.addListener( XEventListener::static_type(), xListener ); +} + +//--------------------------------------------------------------------- + +void SAL_CALL MutableTreeDataModel::removeEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException) +{ + BrdcstHelper.removeListener( XEventListener::static_type(), xListener ); +} + +//--------------------------------------------------------------------- +// XServiceInfo +//--------------------------------------------------------------------- + +OUString SAL_CALL MutableTreeDataModel::getImplementationName( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + static const OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "toolkit.MutableTreeDataModel" ) ); + return aImplName; +} + +//--------------------------------------------------------------------- + +sal_Bool SAL_CALL MutableTreeDataModel::supportsService( const OUString& ServiceName ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + return ServiceName.equalsAscii( szServiceName_MutableTreeDataModel ); +} + +//--------------------------------------------------------------------- + +Sequence< OUString > SAL_CALL MutableTreeDataModel::getSupportedServiceNames( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + static const OUString aServiceName( OUString::createFromAscii( szServiceName_MutableTreeDataModel ) ); + static const Sequence< OUString > aSeq( &aServiceName, 1 ); + return aSeq; +} + +/////////////////////////////////////////////////////////////////////// +// class MutabelTreeNode +/////////////////////////////////////////////////////////////////////// + +MutableTreeNode::MutableTreeNode( const MutableTreeDataModelRef& xModel, const Any& rValue, sal_Bool bChildsOnDemand ) +: maDisplayValue( rValue ) +, mbHasChildsOnDemand( bChildsOnDemand ) +, mpParent( 0 ) +, mxModel( xModel ) +, mbIsInserted( false ) +{ +} + +//--------------------------------------------------------------------- + +MutableTreeNode::~MutableTreeNode() +{ + TreeNodeVector::iterator aIter( maChilds.begin() ); + while( aIter != maChilds.end() ) + (*aIter++)->setParent(0); +} + +//--------------------------------------------------------------------- + +void MutableTreeNode::setParent( MutableTreeNode* pParent ) +{ + mpParent = pParent; +} + +//--------------------------------------------------------------------- + +MutableTreeNode* MutableTreeNode::getImplementation( const Reference< XTreeNode >& xNode, bool bThrows ) throw (IllegalArgumentException) +{ + MutableTreeNode* pImpl = dynamic_cast< MutableTreeNode* >( xNode.get() ); + if( bThrows && !pImpl ) + implThrowIllegalArgumentException(); + + return pImpl; +} + +//--------------------------------------------------------------------- + +void MutableTreeNode::broadcast_changes() +{ + if( mxModel.is() ) + { + Reference< XTreeNode > xParent( getReference( mpParent ) ); + Reference< XTreeNode > xNode( getReference( this ) ); + mxModel->broadcast( nodes_changed, xParent, &xNode, 1 ); + } +} + +//--------------------------------------------------------------------- + +void MutableTreeNode::broadcast_changes(const Reference< XTreeNode >& xNode, bool bNew) +{ + if( mxModel.is() ) + { + Reference< XTreeNode > xParent( getReference( this ) ); + mxModel->broadcast( bNew ? nodes_inserted : nodes_removed, xParent, &xNode, 1 ); + } +} + +//--------------------------------------------------------------------- +// XMutableTreeNode +//--------------------------------------------------------------------- + +Any SAL_CALL MutableTreeNode::getDataValue() throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + return maDataValue; +} + +//--------------------------------------------------------------------- + +void SAL_CALL MutableTreeNode::setDataValue( const Any& _datavalue ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + maDataValue = _datavalue; +} + +//--------------------------------------------------------------------- + +void SAL_CALL MutableTreeNode::appendChild( const Reference< XMutableTreeNode >& xChildNode ) throw (IllegalArgumentException, RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + Reference< XTreeNode > xNode( xChildNode.get() ); + MutableTreeNodeRef xImpl( dynamic_cast< MutableTreeNode* >( xNode.get() ) ); + + if( !xImpl.is() || xImpl->mbIsInserted || (this == xImpl.get()) ) + throw IllegalArgumentException(); + + maChilds.push_back( xImpl ); + xImpl->setParent(this); + xImpl->mbIsInserted = true; + + broadcast_changes( xNode, true ); +} + +//--------------------------------------------------------------------- + +void SAL_CALL MutableTreeNode::insertChildByIndex( sal_Int32 nChildIndex, const Reference< XMutableTreeNode >& xChildNode ) throw (IllegalArgumentException, IndexOutOfBoundsException, RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + + if( (nChildIndex < 0) || (nChildIndex > (sal_Int32)maChilds.size()) ) + throw IndexOutOfBoundsException(); + + Reference< XTreeNode > xNode( xChildNode.get() ); + MutableTreeNodeRef xImpl( dynamic_cast< MutableTreeNode* >( xNode.get() ) ); + if( !xImpl.is() || xImpl->mbIsInserted || (this == xImpl.get()) ) + throw IllegalArgumentException(); + + xImpl->mbIsInserted = true; + + TreeNodeVector::iterator aIter( maChilds.begin() ); + while( (nChildIndex-- > 0) && (aIter != maChilds.end()) ) + aIter++; + + maChilds.insert( aIter, xImpl ); + xImpl->setParent( this ); + + broadcast_changes( xNode, true ); +} + +//--------------------------------------------------------------------- + +void SAL_CALL MutableTreeNode::removeChildByIndex( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + + MutableTreeNodeRef xImpl; + + if( (nChildIndex >= 0) && (nChildIndex < (sal_Int32)maChilds.size()) ) + { + TreeNodeVector::iterator aIter( maChilds.begin() ); + while( nChildIndex-- && (aIter != maChilds.end()) ) + aIter++; + + if( aIter != maChilds.end() ) + { + xImpl = (*aIter); + maChilds.erase( aIter ); + } + } + + if( !xImpl.is() ) + throw IndexOutOfBoundsException(); + + xImpl->setParent(0); + xImpl->mbIsInserted = false; + + broadcast_changes( getReference( xImpl.get() ), false ); +} + +//--------------------------------------------------------------------- + +void SAL_CALL MutableTreeNode::setHasChildrenOnDemand( sal_Bool bChildsOnDemand ) throw (RuntimeException) +{ + bool bChanged; + + { + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + bChanged = mbHasChildsOnDemand != bChildsOnDemand; + mbHasChildsOnDemand = bChildsOnDemand; + } + + if( bChanged ) + broadcast_changes(); +} + +//--------------------------------------------------------------------- + +void SAL_CALL MutableTreeNode::setDisplayValue( const Any& aValue ) throw (RuntimeException) +{ + { + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + maDisplayValue = aValue; + } + + broadcast_changes(); +} + +//--------------------------------------------------------------------- + +void SAL_CALL MutableTreeNode::setNodeGraphicURL( const OUString& rURL ) throw (RuntimeException) +{ + bool bChanged; + + { + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + bChanged = maNodeGraphicURL != rURL; + maNodeGraphicURL = rURL; + } + + if( bChanged ) + broadcast_changes(); +} + +//--------------------------------------------------------------------- + +void SAL_CALL MutableTreeNode::setExpandedGraphicURL( const OUString& rURL ) throw (RuntimeException) +{ + bool bChanged; + + { + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + bChanged = maExpandedGraphicURL != rURL; + maExpandedGraphicURL = rURL; + } + + if( bChanged ) + broadcast_changes(); +} + +//--------------------------------------------------------------------- + +void SAL_CALL MutableTreeNode::setCollapsedGraphicURL( const OUString& rURL ) throw (RuntimeException) +{ + bool bChanged; + + { + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + bChanged = maCollapsedGraphicURL != rURL; + maCollapsedGraphicURL = rURL; + } + + if( bChanged ) + broadcast_changes(); +} + +//--------------------------------------------------------------------- +// XTreeNode +//--------------------------------------------------------------------- + +Reference< XTreeNode > SAL_CALL MutableTreeNode::getChildAt( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException,RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + + if( (nChildIndex < 0) || (nChildIndex >= (sal_Int32)maChilds.size()) ) + throw IndexOutOfBoundsException(); + return getReference( maChilds[nChildIndex].get() ); +} + +//--------------------------------------------------------------------- + +sal_Int32 SAL_CALL MutableTreeNode::getChildCount( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + return (sal_Int32)maChilds.size(); +} + +//--------------------------------------------------------------------- + +Reference< XTreeNode > SAL_CALL MutableTreeNode::getParent( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + return getReference( mpParent ); +} + +//--------------------------------------------------------------------- + +sal_Int32 SAL_CALL MutableTreeNode::getIndex( const Reference< XTreeNode >& xNode ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + + MutableTreeNodeRef xImpl( MutableTreeNode::getImplementation( xNode, false ) ); + if( xImpl.is() ) + { + sal_Int32 nChildCount = maChilds.size(); + while( nChildCount-- ) + { + if( maChilds[nChildCount] == xImpl ) + return nChildCount; + } + } + + return -1; +} + +//--------------------------------------------------------------------- + +sal_Bool SAL_CALL MutableTreeNode::hasChildrenOnDemand( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + return mbHasChildsOnDemand; +} + +//--------------------------------------------------------------------- + +Any SAL_CALL MutableTreeNode::getDisplayValue( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + return maDisplayValue; +} + +//--------------------------------------------------------------------- + +OUString SAL_CALL MutableTreeNode::getNodeGraphicURL( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + return maNodeGraphicURL; +} + +//--------------------------------------------------------------------- + +OUString SAL_CALL MutableTreeNode::getExpandedGraphicURL( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + return maExpandedGraphicURL; +} + +//--------------------------------------------------------------------- + +OUString SAL_CALL MutableTreeNode::getCollapsedGraphicURL( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + return maCollapsedGraphicURL; +} + +//--------------------------------------------------------------------- +// XServiceInfo +//--------------------------------------------------------------------- + +OUString SAL_CALL MutableTreeNode::getImplementationName( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + static const OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "toolkit.MutableTreeNode" ) ); + return aImplName; +} + +//--------------------------------------------------------------------- + +sal_Bool SAL_CALL MutableTreeNode::supportsService( const OUString& ServiceName ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.awt.tree.MutableTreeNode" ) ); +} + +//--------------------------------------------------------------------- + +Sequence< OUString > SAL_CALL MutableTreeNode::getSupportedServiceNames( ) throw (RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( maMutex ); + static const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.tree.MutableTreeNode" ) ); + static const Sequence< OUString > aSeq( &aServiceName, 1 ); + return aSeq; +} + +} + +Reference< XInterface > SAL_CALL MutableTreeDataModel_CreateInstance( const Reference< XMultiServiceFactory >& ) +{ + return Reference < XInterface >( ( ::cppu::OWeakObject* ) new ::toolkit::MutableTreeDataModel ); +} diff --git a/toolkit/source/controls/unocontrol.cxx b/toolkit/source/controls/unocontrol.cxx new file mode 100644 index 000000000000..1abe0b34004f --- /dev/null +++ b/toolkit/source/controls/unocontrol.cxx @@ -0,0 +1,1537 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <com/sun/star/awt/XControlContainer.hpp> +#include <com/sun/star/awt/WindowAttribute.hpp> +#include <com/sun/star/awt/VclWindowPeerAttribute.hpp> +#include <com/sun/star/awt/PosSize.hpp> +#ifndef _COM_SUN_STAR_LAN_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/resource/XStringResourceResolver.hpp> +#include <toolkit/controls/unocontrol.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <rtl/memory.h> +#include <rtl/uuid.h> +#include <vos/mutex.hxx> +#include <tools/string.hxx> +#include <tools/table.hxx> +#include <tools/date.hxx> +#include <tools/time.hxx> +#include <tools/urlobj.hxx> +#include <tools/debug.hxx> +#include <tools/diagnose_ex.h> +#include <vcl/svapp.hxx> +#include <vcl/wrkwin.hxx> +#include <comphelper/stl_types.hxx> +#include <toolkit/helper/property.hxx> +#include <toolkit/helper/servicenames.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <toolkit/awt/vclxwindow.hxx> +#include <vcl/svapp.hxx> +#include <vos/mutex.hxx> +#include <toolkit/controls/accessiblecontrolcontext.hxx> +#include <comphelper/container.hxx> + +#include <algorithm> +#include <set> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::util; + +using ::com::sun::star::accessibility::XAccessibleContext; +using ::com::sun::star::accessibility::XAccessible; + +struct LanguageDependentProp +{ + const char* pPropName; + sal_Int32 nPropNameLength; +}; + +static const LanguageDependentProp aLanguageDependentProp[] = +{ + { "Text", 4 }, + { "Label", 5 }, + { "Title", 5 }, + { "HelpText", 8 }, + { "CurrencySymbol", 14 }, + { "StringItemList", 14 }, + { 0, 0 } +}; + +WorkWindow* lcl_GetDefaultWindow() +{ + static WorkWindow* pW = NULL; + if ( !pW ) + { + pW = new WorkWindow( NULL, 0 ); + pW->EnableChildTransparentMode(); + } + return pW; +} + +static Sequence< ::rtl::OUString> lcl_ImplGetPropertyNames( const Reference< XMultiPropertySet > & rxModel ) +{ + Sequence< ::rtl::OUString> aNames; + Reference< XPropertySetInfo > xPSInf = rxModel->getPropertySetInfo(); + DBG_ASSERT( xPSInf.is(), "UpdateFromModel: No PropertySetInfo!" ); + if ( xPSInf.is() ) + { + Sequence< Property> aProps = xPSInf->getProperties(); + sal_Int32 nLen = aProps.getLength(); + aNames = Sequence< ::rtl::OUString>( nLen ); + ::rtl::OUString* pNames = aNames.getArray(); + const Property* pProps = aProps.getConstArray(); + for ( sal_Int32 n = 0; n < nLen; ++n, ++pProps, ++pNames) + *pNames = pProps->Name; + } + return aNames; +} + +// ==================================================== +class VclListenerLock +{ +private: + VCLXWindow* m_pLockWindow; + +public: + inline VclListenerLock( VCLXWindow* _pLockWindow ) + :m_pLockWindow( _pLockWindow ) + { + if ( m_pLockWindow ) + m_pLockWindow->suspendVclEventListening( ); + } + inline ~VclListenerLock( ) + { + if ( m_pLockWindow ) + m_pLockWindow->resumeVclEventListening( ); + } + +private: + VclListenerLock(); // never implemented + VclListenerLock( const VclListenerLock& ); // never implemented + VclListenerLock& operator=( const VclListenerLock& ); // never implemented +}; + +typedef ::std::map< ::rtl::OUString, sal_Int32 > MapString2Int; +struct UnoControl_Data +{ + MapString2Int aSuspendedPropertyNotifications; + /// true if and only if our model has a property ResourceResolver + bool bLocalizationSupport; + + UnoControl_Data() + :aSuspendedPropertyNotifications() + ,bLocalizationSupport( false ) + { + } +}; + +// ---------------------------------------------------- +// class UnoControl +// ---------------------------------------------------- +DBG_NAME( UnoControl ) +UnoControl::UnoControl() + : maDisposeListeners( *this ) + , maWindowListeners( *this ) + , maFocusListeners( *this ) + , maKeyListeners( *this ) + , maMouseListeners( *this ) + , maMouseMotionListeners( *this ) + , maPaintListeners( *this ) + , maModeChangeListeners( GetMutex() ) + , mpData( new UnoControl_Data ) +{ + DBG_CTOR( UnoControl, NULL ); + mbDisposePeer = sal_True; + mbRefeshingPeer = sal_False; + mbCreatingPeer = sal_False; + mbCreatingCompatiblePeer = sal_False; + mbDesignMode = sal_False; +} + +UnoControl::~UnoControl() +{ + DELETEZ( mpData ); + DBG_DTOR( UnoControl, NULL ); +} + +::rtl::OUString UnoControl::GetComponentServiceName() +{ + return ::rtl::OUString(); +} + +Reference< XWindowPeer > UnoControl::ImplGetCompatiblePeer( sal_Bool bAcceptExistingPeer ) +{ + DBG_ASSERT( !mbCreatingCompatiblePeer, "ImplGetCompatiblePeer - rekursive?" ); + + mbCreatingCompatiblePeer = sal_True; + + Reference< XWindowPeer > xCompatiblePeer; + + if ( bAcceptExistingPeer ) + xCompatiblePeer = getPeer(); + + if ( !xCompatiblePeer.is() ) + { + // Peer unsichtbar erzeugen... + sal_Bool bVis = maComponentInfos.bVisible; + if( bVis ) + maComponentInfos.bVisible = sal_False; + + Reference< XWindowPeer > xCurrentPeer = getPeer(); + setPeer( NULL ); + + // queryInterface ourself, to allow aggregation + Reference< XControl > xMe; + OWeakAggObject::queryInterface( ::getCppuType( &xMe ) ) >>= xMe; + + WorkWindow* pWW; + { + osl::Guard< vos::IMutex > aGuard( Application::GetSolarMutex() ); + pWW = lcl_GetDefaultWindow(); + } + try + { + xMe->createPeer( NULL, pWW->GetComponentInterface( sal_True ) ); + } + catch( const Exception& ) + { + mbCreatingCompatiblePeer = sal_False; + throw; + } + xCompatiblePeer = getPeer(); + setPeer( xCurrentPeer ); + + if ( xCompatiblePeer.is() && mxGraphics.is() ) + { + Reference< XView > xPeerView( xCompatiblePeer, UNO_QUERY ); + if ( xPeerView.is() ) + xPeerView->setGraphics( mxGraphics ); + } + + if( bVis ) + maComponentInfos.bVisible = sal_True; + } + + mbCreatingCompatiblePeer = sal_False; + + return xCompatiblePeer; +} + +bool UnoControl::ImplCheckLocalize( ::rtl::OUString& _rPossiblyLocalizable ) +{ + if ( !mpData->bLocalizationSupport + || ( _rPossiblyLocalizable.getLength() == 0 ) + || ( _rPossiblyLocalizable[0] != '&' ) + // TODO: make this reasonable. At the moment, everything which by accident starts with a & is considered + // localizable, which is probably wrong. + ) + return false; + + try + { + Reference< XPropertySet > xPropSet( mxModel, UNO_QUERY_THROW ); + Reference< resource::XStringResourceResolver > xStringResourceResolver( + xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceResolver" ) ) ), + UNO_QUERY + ); + if ( xStringResourceResolver.is() ) + { + ::rtl::OUString aLocalizationKey( _rPossiblyLocalizable.copy( 1 ) ); + _rPossiblyLocalizable = xStringResourceResolver->resolveString( aLocalizationKey ); + return true; + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return false; +} + +void UnoControl::ImplSetPeerProperty( const ::rtl::OUString& rPropName, const Any& rVal ) +{ + // since a change made in propertiesChange, we can't be sure that this is called with an valid getPeer(), + // this assumption may be false in some (seldom) multi-threading scenarios (cause propertiesChange + // releases our mutex before calling here in) + // That's why this additional check + + if ( mxVclWindowPeer.is() ) + { + Any aConvertedValue( rVal ); + + if ( mpData->bLocalizationSupport ) + { + // We now support a mapping for language dependent properties. This is the + // central method to implement it. + if (( rPropName.equalsAsciiL( "Text", 4 )) || + ( rPropName.equalsAsciiL( "Label", 5 )) || + ( rPropName.equalsAsciiL( "Title", 5 )) || + ( rPropName.equalsAsciiL( "HelpText", 8 )) || + ( rPropName.equalsAsciiL( "CurrencySymbol", 14 )) || + ( rPropName.equalsAsciiL( "StringItemList", 14 )) ) + { + ::rtl::OUString aValue; + uno::Sequence< rtl::OUString > aSeqValue; + if ( aConvertedValue >>= aValue ) + { + if ( ImplCheckLocalize( aValue ) ) + aConvertedValue <<= aValue; + } + else if ( aConvertedValue >>= aSeqValue ) + { + for ( sal_Int32 i = 0; i < aSeqValue.getLength(); i++ ) + ImplCheckLocalize( aSeqValue[i] ); + aConvertedValue <<= aSeqValue; + } + } + } + + mxVclWindowPeer->setProperty( rPropName, aConvertedValue ); + } +} + +void UnoControl::PrepareWindowDescriptor( WindowDescriptor& ) +{ +} + +Reference< XWindow > UnoControl::getParentPeer() const +{ + Reference< XWindow > xPeer; + if( mxContext.is() ) + { + Reference< XControl > xContComp( mxContext, UNO_QUERY ); + if ( xContComp.is() ) + { + Reference< XWindowPeer > xP = xContComp->getPeer(); + if ( xP.is() ) + xP->queryInterface( ::getCppuType((const Reference< XWindow >*)0) ) >>= xPeer; + } + } + return xPeer; +} + +void UnoControl::updateFromModel() +{ + // Alle standard Properties werden ausgelesen und in das Peer uebertragen + if( getPeer().is() ) + { + Reference< XMultiPropertySet > xPropSet( mxModel, UNO_QUERY ); + if( xPropSet.is() ) + { + Sequence< ::rtl::OUString> aNames = lcl_ImplGetPropertyNames( xPropSet ); + xPropSet->firePropertiesChangeEvent( aNames, this ); + } + } +} + + +// XTypeProvider +IMPL_IMPLEMENTATION_ID( UnoControl ) + +void UnoControl::disposeAccessibleContext() +{ + Reference< XComponent > xContextComp( maAccessibleContext.get(), UNO_QUERY ); + if ( xContextComp.is() ) + { + maAccessibleContext = NULL; + try + { + xContextComp->removeEventListener( this ); + xContextComp->dispose(); + } + catch( const Exception& ) + { + DBG_ERROR( "UnoControl::disposeAccessibleContext: could not dispose my AccessibleContext!" ); + } + } +} + +void UnoControl::dispose( ) throw(RuntimeException) +{ + Reference< XWindowPeer > xPeer; + { + ::osl::MutexGuard aGuard( GetMutex() ); + if( mbDisposePeer ) + { + xPeer = mxPeer; + } + setPeer( NULL ); + } + if( xPeer.is() ) + { + xPeer->dispose(); + } + + // dispose and release our AccessibleContext + disposeAccessibleContext(); + + EventObject aDisposeEvent; + aDisposeEvent.Source = static_cast< XAggregation* >( this ); + + maDisposeListeners.disposeAndClear( aDisposeEvent ); + maWindowListeners.disposeAndClear( aDisposeEvent ); + maFocusListeners.disposeAndClear( aDisposeEvent ); + maKeyListeners.disposeAndClear( aDisposeEvent ); + maMouseListeners.disposeAndClear( aDisposeEvent ); + maMouseMotionListeners.disposeAndClear( aDisposeEvent ); + maPaintListeners.disposeAndClear( aDisposeEvent ); + maModeChangeListeners.disposeAndClear( aDisposeEvent ); + + // Model wieder freigeben + setModel( Reference< XControlModel > () ); + setContext( Reference< XInterface > () ); +} + +void UnoControl::addEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard( GetMutex() ); + + maDisposeListeners.addInterface( rxListener ); +} + +void UnoControl::removeEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard( GetMutex() ); + + maDisposeListeners.removeInterface( rxListener ); +} + +sal_Bool UnoControl::requiresNewPeer( const ::rtl::OUString& /* _rPropertyName */ ) const +{ + return sal_False; +} + +// XPropertiesChangeListener +void UnoControl::propertiesChange( const Sequence< PropertyChangeEvent >& rEvents ) throw(RuntimeException) +{ + Sequence< PropertyChangeEvent > aEvents( rEvents ); + { + ::osl::MutexGuard aGuard( GetMutex() ); + + if ( !mpData->aSuspendedPropertyNotifications.empty() ) + { + // strip the property which we are currently updating (somewhere up the stack) + PropertyChangeEvent* pEvents = aEvents.getArray(); + PropertyChangeEvent* pEventsEnd = pEvents + aEvents.getLength(); + for ( ; pEvents < pEventsEnd; ) + if ( mpData->aSuspendedPropertyNotifications.find( pEvents->PropertyName ) != mpData->aSuspendedPropertyNotifications.end() ) + { + if ( pEvents != pEventsEnd ) + ::std::copy( pEvents + 1, pEventsEnd, pEvents ); + --pEventsEnd; + } + else + ++pEvents; + aEvents.realloc( pEventsEnd - aEvents.getConstArray() ); + + if ( !aEvents.getLength() ) + return; + } + } + + ImplModelPropertiesChanged( aEvents ); +} + +void UnoControl::ImplLockPropertyChangeNotification( const ::rtl::OUString& rPropertyName, bool bLock ) +{ + MapString2Int::iterator pos = mpData->aSuspendedPropertyNotifications.find( rPropertyName ); + if ( bLock ) + { + if ( pos == mpData->aSuspendedPropertyNotifications.end() ) + pos = mpData->aSuspendedPropertyNotifications.insert( MapString2Int::value_type( rPropertyName, 0 ) ).first; + ++pos->second; + } + else + { + OSL_ENSURE( pos != mpData->aSuspendedPropertyNotifications.end(), "UnoControl::ImplLockPropertyChangeNotification: property not locked!" ); + if ( pos != mpData->aSuspendedPropertyNotifications.end() ) + { + OSL_ENSURE( pos->second > 0, "UnoControl::ImplLockPropertyChangeNotification: invalid suspension counter!" ); + if ( 0 == --pos->second ) + mpData->aSuspendedPropertyNotifications.erase( pos ); + } + } +} + +void UnoControl::ImplLockPropertyChangeNotifications( const Sequence< ::rtl::OUString >& rPropertyNames, bool bLock ) +{ + for ( const ::rtl::OUString* pPropertyName = rPropertyNames.getConstArray(); + pPropertyName != rPropertyNames.getConstArray() + rPropertyNames.getLength(); + ++pPropertyName + ) + ImplLockPropertyChangeNotification( *pPropertyName, bLock ); +} + +void UnoControl::ImplModelPropertiesChanged( const Sequence< PropertyChangeEvent >& rEvents ) +{ + ::osl::ClearableGuard< ::osl::Mutex > aGuard( GetMutex() ); + + if( getPeer().is() ) + { + DECLARE_STL_VECTOR( PropertyValue, PropertyValueVector); + PropertyValueVector aPeerPropertiesToSet; + sal_Int32 nIndependentPos = 0; + bool bResourceResolverSet( false ); + // position where to insert the independent properties into aPeerPropertiesToSet, + // dependent ones are inserted at the end of the vector + + sal_Bool bNeedNewPeer = sal_False; + // some properties require a re-creation of the peer, 'cause they can't be changed on the fly + + Reference< XControlModel > xOwnModel( getModel(), UNO_QUERY ); + // our own model for comparison + Reference< XPropertySet > xPS( xOwnModel, UNO_QUERY ); + Reference< XPropertySetInfo > xPSI( xPS->getPropertySetInfo(), UNO_QUERY ); + OSL_ENSURE( xPSI.is(), "UnoControl::ImplModelPropertiesChanged: should have property set meta data!" ); + + const PropertyChangeEvent* pEvents = rEvents.getConstArray(); + + sal_Int32 nLen = rEvents.getLength(); + aPeerPropertiesToSet.reserve(nLen); + + for( sal_Int32 i = 0; i < nLen; ++i, ++pEvents ) + { + Reference< XControlModel > xModel( pEvents->Source, UNO_QUERY ); + sal_Bool bOwnModel = xModel.get() == xOwnModel.get(); + if ( !bOwnModel ) + continue; + + // Detect changes on our resource resolver which invalidates + // automatically some language dependent properties. + if ( pEvents->PropertyName.equalsAsciiL( "ResourceResolver", 16 )) + { + Reference< resource::XStringResourceResolver > xStrResolver; + if ( pEvents->NewValue >>= xStrResolver ) + bResourceResolverSet = xStrResolver.is(); + } + + sal_uInt16 nPType = GetPropertyId( pEvents->PropertyName ); + if ( mbDesignMode && mbDisposePeer && !mbRefeshingPeer && !mbCreatingPeer ) + { + // if we're in design mode, then some properties can change which + // require creating a *new* peer (since these properties cannot + // be switched at existing peers) + if ( nPType ) + bNeedNewPeer = ( nPType == BASEPROPERTY_BORDER ) + || ( nPType == BASEPROPERTY_MULTILINE ) + || ( nPType == BASEPROPERTY_DROPDOWN ) + || ( nPType == BASEPROPERTY_HSCROLL ) + || ( nPType == BASEPROPERTY_VSCROLL ) + || ( nPType == BASEPROPERTY_AUTOHSCROLL ) + || ( nPType == BASEPROPERTY_AUTOVSCROLL ) + || ( nPType == BASEPROPERTY_ORIENTATION ) + || ( nPType == BASEPROPERTY_SPIN ) + || ( nPType == BASEPROPERTY_ALIGN ) + || ( nPType == BASEPROPERTY_PAINTTRANSPARENT ); + else + bNeedNewPeer = requiresNewPeer( pEvents->PropertyName ); + + if ( bNeedNewPeer ) + break; + } + + if ( nPType && ( nLen > 1 ) && DoesDependOnOthers( nPType ) ) + { + // Properties die von anderen abhaengen erst hinterher einstellen, + // weil sie von anderen Properties abhaengig sind, die aber erst spaeter + // eingestellt werden, z.B. VALUE nach VALUEMIN/MAX. + aPeerPropertiesToSet.push_back(PropertyValue(pEvents->PropertyName, 0, pEvents->NewValue, PropertyState_DIRECT_VALUE)); + } + else + { + if ( bResourceResolverSet ) + { + // The resource resolver property change should be one of the first ones. + // All language dependent properties are dependent on this property. + // As BASEPROPERTY_NATIVE_WIDGET_LOOK is not dependent on resource + // resolver. We don't need to handle a special order for these two props. + aPeerPropertiesToSet.insert( + aPeerPropertiesToSet.begin(), + PropertyValue( pEvents->PropertyName, 0, pEvents->NewValue, PropertyState_DIRECT_VALUE ) ); + ++nIndependentPos; + } + else if ( nPType == BASEPROPERTY_NATIVE_WIDGET_LOOK ) + { + // since *a lot* of other properties might be overruled by this one, we need + // a special handling: + // NativeWidgetLook needs to be set first: If it is set to ON, all other + // properties describing the look (e.g. BackgroundColor) are ignored, anyway. + // If it is switched OFF, then we need to do it first because else it will + // overrule other look-related properties, and re-initialize them from system + // defaults. + aPeerPropertiesToSet.insert( + aPeerPropertiesToSet.begin(), + PropertyValue( pEvents->PropertyName, 0, pEvents->NewValue, PropertyState_DIRECT_VALUE ) ); + ++nIndependentPos; + } + else + { + aPeerPropertiesToSet.insert(aPeerPropertiesToSet.begin() + nIndependentPos, + PropertyValue(pEvents->PropertyName, 0, pEvents->NewValue, PropertyState_DIRECT_VALUE)); + ++nIndependentPos; + } + } + } + + Reference< XWindow > xParent = getParentPeer(); + Reference< XControl > xThis( (XAggregation*)(::cppu::OWeakAggObject*)this, UNO_QUERY ); + // call createPeer via a interface got from queryInterface, so the aggregating class can intercept it + + DBG_ASSERT( !bNeedNewPeer || xParent.is(), "Need new peer, but don't have a parent!" ); + + // Check if we have to update language dependent properties + if ( !bNeedNewPeer && bResourceResolverSet ) + { + // Add language dependent properties into the peer property set. + // Our resource resolver has been changed and we must be sure + // that language dependent props use the new resolver. + const LanguageDependentProp* pLangDepProp = aLanguageDependentProp; + while ( pLangDepProp->pPropName != 0 ) + { + bool bMustBeInserted( true ); + for ( sal_uInt32 i = 0; i < aPeerPropertiesToSet.size(); i++ ) + { + if ( aPeerPropertiesToSet[i].Name.equalsAsciiL( + pLangDepProp->pPropName, pLangDepProp->nPropNameLength )) + { + bMustBeInserted = false; + break; + } + } + + if ( bMustBeInserted ) + { + // Add language dependent props at the end + ::rtl::OUString aPropName( ::rtl::OUString::createFromAscii( pLangDepProp->pPropName )); + if ( xPSI.is() && xPSI->hasPropertyByName( aPropName ) ) + { + aPeerPropertiesToSet.push_back( + PropertyValue( aPropName, 0, xPS->getPropertyValue( aPropName ), PropertyState_DIRECT_VALUE ) ); + } + } + + ++pLangDepProp; + } + } + aGuard.clear(); + + // clear the guard before creating a new peer - as usual, our peer implementations use the SolarMutex + // #82300# - 2000-12-21 - fs@openoffice.org + if (bNeedNewPeer && xParent.is()) + { + NAMESPACE_VOS(OGuard) aVclGuard( Application::GetSolarMutex() ); + // and now this is the final withdrawal: + // With 83561, I have no other idea than locking the SolarMutex here .... + // I really hate the fact that VCL is not theadsafe .... + // #83561# - 2001-03-01 - fs@openoffice.org + + // Funktioniert beim Container nicht! + getPeer()->dispose(); + mxPeer.clear(); + mxVclWindowPeer = NULL; + mbRefeshingPeer = sal_True; + Reference< XWindowPeer > xP( xParent, UNO_QUERY ); + xThis->createPeer( Reference< XToolkit > (), xP ); + mbRefeshingPeer = sal_False; + aPeerPropertiesToSet.clear(); + } + + // lock the multiplexing of VCL events to our UNO listeners + // this is for compatibility reasons: in OOo 1.0.x, changes which were done at the + // model did not cause the listeners of the controls/peers to be called + // Since the implementations for the listeners changed a lot towards 1.1, this + // would not be the case anymore, if we would not do this listener-lock below + // #i14703# - 2003-05-23 - fs@openoffice.org + Window* pVclPeer = VCLUnoHelper::GetWindow( getPeer() ); + VCLXWindow* pPeer = pVclPeer ? pVclPeer->GetWindowPeer() : NULL; + VclListenerLock aNoVclEventMultiplexing( pPeer ); + + // setting peer properties may result in an attemp to acquire the solar mutex, 'cause the peers + // usually don't have an own mutex but use the SolarMutex instead. + // To prevent deadlocks resulting from this, we do this without our own mutex locked + // 2000-11-03 - fs@openoffice.org + PropertyValueVectorIterator aEnd = aPeerPropertiesToSet.end(); + for ( PropertyValueVectorIterator aLoop = aPeerPropertiesToSet.begin(); + aLoop != aEnd; + ++aLoop + ) + { + ImplSetPeerProperty( aLoop->Name, aLoop->Value ); + } + } +} + +void UnoControl::disposing( const EventObject& rEvt ) throw(RuntimeException) +{ + ::osl::ClearableMutexGuard aGuard( GetMutex() ); + // bei "Multible Inheritance" nicht unterschiedliche Typen vergleichen. + + if ( maAccessibleContext.get() == rEvt.Source ) + { + // just in case the context is disposed, but not released - ensure that we do not re-use it in the future + maAccessibleContext = NULL; + } + else if( mxModel.get() == Reference< XControlModel >(rEvt.Source,UNO_QUERY).get() ) + { + // #62337# if the model dies, it does not make sense for us to live ... + Reference< XControl > xThis = this; + + aGuard.clear(); + xThis->dispose(); + + DBG_ASSERT( !mxModel.is(), "UnoControl::disposing: invalid dispose behaviour!" ); + mxModel.clear(); + } +} + + +void SAL_CALL UnoControl::setOutputSize( const awt::Size& aSize ) throw (RuntimeException) +{ + Reference< XWindow2 > xPeerWindow; + { + ::osl::MutexGuard aGuard( GetMutex() ); + xPeerWindow = xPeerWindow.query( getPeer() ); + } + + if ( xPeerWindow.is() ) + xPeerWindow->setOutputSize( aSize ); +} + +namespace +{ + template < typename RETVALTYPE > + RETVALTYPE lcl_askPeer( const uno::Reference< awt::XWindowPeer >& _rxPeer, RETVALTYPE (SAL_CALL XWindow2::*_pMethod)(), RETVALTYPE _aDefault ) + { + RETVALTYPE aReturn( _aDefault ); + + Reference< XWindow2 > xPeerWindow( _rxPeer, UNO_QUERY ); + if ( xPeerWindow.is() ) + aReturn = (xPeerWindow.get()->*_pMethod)(); + + return aReturn; + } +} + +awt::Size SAL_CALL UnoControl::getOutputSize( ) throw (RuntimeException) +{ + return lcl_askPeer( getPeer(), &XWindow2::getOutputSize, awt::Size() ); +} + +::sal_Bool SAL_CALL UnoControl::isVisible( ) throw (RuntimeException) +{ + return lcl_askPeer( getPeer(), &XWindow2::isVisible, maComponentInfos.bVisible ); +} + +::sal_Bool SAL_CALL UnoControl::isActive( ) throw (RuntimeException) +{ + return lcl_askPeer( getPeer(), &XWindow2::isActive, sal_False ); +} + +::sal_Bool SAL_CALL UnoControl::isEnabled( ) throw (RuntimeException) +{ + return lcl_askPeer( getPeer(), &XWindow2::isEnabled, maComponentInfos.bEnable ); +} + +::sal_Bool SAL_CALL UnoControl::hasFocus( ) throw (RuntimeException) +{ + return lcl_askPeer( getPeer(), &XWindow2::hasFocus, sal_False ); +} + +// XWindow +void UnoControl::setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags ) throw(RuntimeException) +{ + Reference< XWindow > xWindow; + { + ::osl::MutexGuard aGuard( GetMutex() ); + + if ( Flags & awt::PosSize::X ) + maComponentInfos.nX = X; + if ( Flags & awt::PosSize::Y ) + maComponentInfos.nY = Y; + if ( Flags & awt::PosSize::WIDTH ) + maComponentInfos.nWidth = Width; + if ( Flags & awt::PosSize::HEIGHT ) + maComponentInfos.nHeight = Height; + maComponentInfos.nFlags |= Flags; + + xWindow = xWindow.query( getPeer() ); + } + + if( xWindow.is() ) + xWindow->setPosSize( X, Y, Width, Height, Flags ); +} + +awt::Rectangle UnoControl::getPosSize( ) throw(RuntimeException) +{ + awt::Rectangle aRect( maComponentInfos.nX, maComponentInfos.nY, maComponentInfos.nWidth, maComponentInfos.nHeight); + Reference< XWindow > xWindow; + + { + ::osl::MutexGuard aGuard( GetMutex() ); + xWindow = xWindow.query( getPeer() ); + } + + if( xWindow.is() ) + aRect = xWindow->getPosSize(); + return aRect; +} + +void UnoControl::setVisible( sal_Bool bVisible ) throw(RuntimeException) +{ + Reference< XWindow > xWindow; + { + ::osl::MutexGuard aGuard( GetMutex() ); + + // Visible status ist Sache der View + maComponentInfos.bVisible = bVisible; + xWindow = xWindow.query( getPeer() ); + } + if ( xWindow.is() ) + xWindow->setVisible( bVisible ); +} + +void UnoControl::setEnable( sal_Bool bEnable ) throw(RuntimeException) +{ + Reference< XWindow > xWindow; + { + ::osl::MutexGuard aGuard( GetMutex() ); + + // Enable status ist Sache der View + maComponentInfos.bEnable = bEnable; + xWindow = xWindow.query( getPeer() ); + } + if ( xWindow.is() ) + xWindow->setEnable( bEnable ); +} + +void UnoControl::setFocus( ) throw(RuntimeException) +{ + Reference< XWindow > xWindow; + { + ::osl::MutexGuard aGuard( GetMutex() ); + xWindow = xWindow.query( getPeer() ); + } + if ( xWindow.is() ) + xWindow->setFocus(); +} + +void UnoControl::addWindowListener( const Reference< XWindowListener >& rxListener ) throw(RuntimeException) +{ + Reference< XWindow > xPeerWindow; + { + ::osl::MutexGuard aGuard( GetMutex() ); + maWindowListeners.addInterface( rxListener ); + if ( maWindowListeners.getLength() == 1 ) + xPeerWindow = xPeerWindow.query( getPeer() ); + } + if ( xPeerWindow.is() ) + xPeerWindow->addWindowListener( &maWindowListeners ); +} + +void UnoControl::removeWindowListener( const Reference< XWindowListener >& rxListener ) throw(RuntimeException) +{ + Reference< XWindow > xPeerWindow; + { + ::osl::MutexGuard aGuard( GetMutex() ); + if ( maWindowListeners.getLength() == 1 ) + xPeerWindow = xPeerWindow.query( getPeer() ); + maWindowListeners.removeInterface( rxListener ); + } + if ( xPeerWindow.is() ) + xPeerWindow->removeWindowListener( &maWindowListeners ); +} + +void UnoControl::addFocusListener( const Reference< XFocusListener >& rxListener ) throw(RuntimeException) +{ + Reference< XWindow > xPeerWindow; + { + ::osl::MutexGuard aGuard( GetMutex() ); + maFocusListeners.addInterface( rxListener ); + if ( maFocusListeners.getLength() == 1 ) + xPeerWindow = xPeerWindow.query( getPeer() ); + } + if ( xPeerWindow.is() ) + xPeerWindow->addFocusListener( &maFocusListeners ); +} + +void UnoControl::removeFocusListener( const Reference< XFocusListener >& rxListener ) throw(RuntimeException) +{ + Reference< XWindow > xPeerWindow; + { + ::osl::MutexGuard aGuard( GetMutex() ); + if ( maFocusListeners.getLength() == 1 ) + xPeerWindow = xPeerWindow.query( getPeer() ); + maFocusListeners.removeInterface( rxListener ); + } + if ( xPeerWindow.is() ) + xPeerWindow->removeFocusListener( &maFocusListeners ); +} + +void UnoControl::addKeyListener( const Reference< XKeyListener >& rxListener ) throw(RuntimeException) +{ + Reference< XWindow > xPeerWindow; + { + ::osl::MutexGuard aGuard( GetMutex() ); + maKeyListeners.addInterface( rxListener ); + if ( maKeyListeners.getLength() == 1 ) + xPeerWindow = xPeerWindow.query( getPeer() ); + } + if ( xPeerWindow.is() ) + xPeerWindow->addKeyListener( &maKeyListeners); +} + +void UnoControl::removeKeyListener( const Reference< XKeyListener >& rxListener ) throw(RuntimeException) +{ + Reference< XWindow > xPeerWindow; + { + ::osl::MutexGuard aGuard( GetMutex() ); + if ( maKeyListeners.getLength() == 1 ) + xPeerWindow = xPeerWindow.query( getPeer() ); + maKeyListeners.removeInterface( rxListener ); + } + if ( xPeerWindow.is() ) + xPeerWindow->removeKeyListener( &maKeyListeners); +} + +void UnoControl::addMouseListener( const Reference< XMouseListener >& rxListener ) throw(RuntimeException) +{ + Reference< XWindow > xPeerWindow; + { + ::osl::MutexGuard aGuard( GetMutex() ); + maMouseListeners.addInterface( rxListener ); + if ( maMouseListeners.getLength() == 1 ) + xPeerWindow = xPeerWindow.query( getPeer() ); + } + if ( xPeerWindow.is() ) + xPeerWindow->addMouseListener( &maMouseListeners); +} + +void UnoControl::removeMouseListener( const Reference< XMouseListener >& rxListener ) throw(RuntimeException) +{ + Reference< XWindow > xPeerWindow; + { + ::osl::MutexGuard aGuard( GetMutex() ); + if ( maMouseListeners.getLength() == 1 ) + xPeerWindow = xPeerWindow.query( getPeer() ); + maMouseListeners.removeInterface( rxListener ); + } + if ( xPeerWindow.is() ) + xPeerWindow->removeMouseListener( &maMouseListeners ); +} + +void UnoControl::addMouseMotionListener( const Reference< XMouseMotionListener >& rxListener ) throw(RuntimeException) +{ + Reference< XWindow > xPeerWindow; + { + ::osl::MutexGuard aGuard( GetMutex() ); + maMouseMotionListeners.addInterface( rxListener ); + if ( maMouseMotionListeners.getLength() == 1 ) + xPeerWindow = xPeerWindow.query( getPeer() ); + } + if ( xPeerWindow.is() ) + xPeerWindow->addMouseMotionListener( &maMouseMotionListeners); +} + +void UnoControl::removeMouseMotionListener( const Reference< XMouseMotionListener >& rxListener ) throw(RuntimeException) +{ + Reference< XWindow > xPeerWindow; + { + ::osl::MutexGuard aGuard( GetMutex() ); + if ( maMouseMotionListeners.getLength() == 1 ) + xPeerWindow = xPeerWindow.query( getPeer() ); + maMouseMotionListeners.removeInterface( rxListener ); + } + if ( xPeerWindow.is() ) + xPeerWindow->removeMouseMotionListener( &maMouseMotionListeners ); +} + +void UnoControl::addPaintListener( const Reference< XPaintListener >& rxListener ) throw(RuntimeException) +{ + Reference< XWindow > xPeerWindow; + { + ::osl::MutexGuard aGuard( GetMutex() ); + maPaintListeners.addInterface( rxListener ); + if ( maPaintListeners.getLength() == 1 ) + xPeerWindow = xPeerWindow.query( getPeer() ); + } + if ( xPeerWindow.is() ) + xPeerWindow->addPaintListener( &maPaintListeners); +} + +void UnoControl::removePaintListener( const Reference< XPaintListener >& rxListener ) throw(RuntimeException) +{ + Reference< XWindow > xPeerWindow; + { + ::osl::MutexGuard aGuard( GetMutex() ); + if ( maPaintListeners.getLength() == 1 ) + xPeerWindow = xPeerWindow.query( getPeer() ); + maPaintListeners.removeInterface( rxListener ); + } + if ( xPeerWindow.is() ) + xPeerWindow->removePaintListener( &maPaintListeners ); +} + +// XView +sal_Bool UnoControl::setGraphics( const Reference< XGraphics >& rDevice ) throw(RuntimeException) +{ + Reference< XView > xView; + { + ::osl::MutexGuard aGuard( GetMutex() ); + + mxGraphics = rDevice; + xView = xView.query( getPeer() ); + } + return xView.is() ? xView->setGraphics( rDevice ) : sal_True; +} + +Reference< XGraphics > UnoControl::getGraphics( ) throw(RuntimeException) +{ + return mxGraphics; +} + +awt::Size UnoControl::getSize( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard( GetMutex() ); + return awt::Size( maComponentInfos.nWidth, maComponentInfos.nHeight ); +} + +void UnoControl::draw( sal_Int32 x, sal_Int32 y ) throw(RuntimeException) +{ + Reference< XWindowPeer > xDrawPeer; + Reference< XView > xDrawPeerView; + + bool bDisposeDrawPeer( false ); + { + ::osl::MutexGuard aGuard( GetMutex() ); + + xDrawPeer = ImplGetCompatiblePeer( sal_True ); + bDisposeDrawPeer = xDrawPeer.is() && ( xDrawPeer != getPeer() ); + + xDrawPeerView.set( xDrawPeer, UNO_QUERY ); + DBG_ASSERT( xDrawPeerView.is(), "UnoControl::draw: no peer!" ); + } + + if ( xDrawPeerView.is() ) + { + Reference< XVclWindowPeer > xWindowPeer; + xWindowPeer.set( xDrawPeer, UNO_QUERY ); + if ( xWindowPeer.is() ) + xWindowPeer->setDesignMode( mbDesignMode ); + xDrawPeerView->draw( x, y ); + } + + if ( bDisposeDrawPeer ) + xDrawPeer->dispose(); +} + +void UnoControl::setZoom( float fZoomX, float fZoomY ) throw(RuntimeException) +{ + Reference< XView > xView; + { + ::osl::MutexGuard aGuard( GetMutex() ); + + maComponentInfos.nZoomX = fZoomX; + maComponentInfos.nZoomY = fZoomY; + + xView = xView.query( getPeer() ); + } + if ( xView.is() ) + xView->setZoom( fZoomX, fZoomY ); +} + +// XControl +void UnoControl::setContext( const Reference< XInterface >& rxContext ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard( GetMutex() ); + + mxContext = rxContext; +} + +Reference< XInterface > UnoControl::getContext( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard( GetMutex() ); + + return mxContext; +} + +void UnoControl::peerCreated() +{ + Reference< XWindow > xWindow( getPeer(), UNO_QUERY ); + if ( !xWindow.is() ) + return; + + if ( maWindowListeners.getLength() ) + xWindow->addWindowListener( &maWindowListeners ); + + if ( maFocusListeners.getLength() ) + xWindow->addFocusListener( &maFocusListeners ); + + if ( maKeyListeners.getLength() ) + xWindow->addKeyListener( &maKeyListeners ); + + if ( maMouseListeners.getLength() ) + xWindow->addMouseListener( &maMouseListeners ); + + if ( maMouseMotionListeners.getLength() ) + xWindow->addMouseMotionListener( &maMouseMotionListeners ); + + if ( maPaintListeners.getLength() ) + xWindow->addPaintListener( &maPaintListeners ); +} + +void UnoControl::createPeer( const Reference< XToolkit >& rxToolkit, const Reference< XWindowPeer >& rParentPeer ) throw(RuntimeException) +{ + ::osl::ClearableMutexGuard aGuard( GetMutex() ); + + if ( !mxModel.is() ) + { + RuntimeException aException; + aException.Message = ::rtl::OUString::createFromAscii( "createPeer: no model!" ); + aException.Context = (XAggregation*)(::cppu::OWeakAggObject*)this; + throw( aException ); + } + + if( !getPeer().is() ) + { + mbCreatingPeer = sal_True; + + WindowClass eType; + Reference< XToolkit > xToolkit = rxToolkit; + if( rParentPeer.is() && mxContext.is() ) + { + // kein TopWindow + if ( !xToolkit.is() ) + xToolkit = rParentPeer->getToolkit(); + Any aAny = OWeakAggObject::queryInterface( ::getCppuType((const Reference< XControlContainer>*)0) ); + Reference< XControlContainer > xC; + aAny >>= xC; + if( xC.is() ) + // Es ist ein Container + eType = WindowClass_CONTAINER; + else + eType = WindowClass_SIMPLE; + } + else + { // Nur richtig, wenn es sich um ein Top Window handelt + if( rParentPeer.is() ) + { + if ( !xToolkit.is() ) + xToolkit = rParentPeer->getToolkit(); + eType = WindowClass_CONTAINER; + } + else + { + if ( !xToolkit.is() ) + xToolkit = VCLUnoHelper::CreateToolkit(); + eType = WindowClass_TOP; + } + } + WindowDescriptor aDescr; + aDescr.Type = eType; + aDescr.WindowServiceName = GetComponentServiceName(); + aDescr.Parent = rParentPeer; + aDescr.Bounds = getPosSize(); + aDescr.WindowAttributes = 0; + + // Border + Reference< XPropertySet > xPSet( mxModel, UNO_QUERY ); + Reference< XPropertySetInfo > xInfo = xPSet->getPropertySetInfo(); + + Any aVal; + ::rtl::OUString aPropName = GetPropertyName( BASEPROPERTY_BORDER ); + if ( xInfo->hasPropertyByName( aPropName ) ) + { + aVal = xPSet->getPropertyValue( aPropName ); + sal_Int16 n = sal_Int16(); + if ( aVal >>= n ) + { + if ( n ) + aDescr.WindowAttributes |= WindowAttribute::BORDER; + else + aDescr.WindowAttributes |= VclWindowPeerAttribute::NOBORDER; + } + } + + // DESKTOP_AS_PARENT + if ( aDescr.Type == WindowClass_TOP ) + { + aPropName = GetPropertyName( BASEPROPERTY_DESKTOP_AS_PARENT ); + if ( xInfo->hasPropertyByName( aPropName ) ) + { + aVal = xPSet->getPropertyValue( aPropName ); + sal_Bool b = sal_Bool(); + if ( ( aVal >>= b ) && b) + aDescr.ParentIndex = -1; + } + } + // Moveable + aPropName = GetPropertyName( BASEPROPERTY_MOVEABLE ); + if ( xInfo->hasPropertyByName( aPropName ) ) + { + aVal = xPSet->getPropertyValue( aPropName ); + sal_Bool b = sal_Bool(); + if ( ( aVal >>= b ) && b) + aDescr.WindowAttributes |= WindowAttribute::MOVEABLE; + } + + // Closeable + aPropName = GetPropertyName( BASEPROPERTY_CLOSEABLE ); + if ( xInfo->hasPropertyByName( aPropName ) ) + { + aVal = xPSet->getPropertyValue( aPropName ); + sal_Bool b = sal_Bool(); + if ( ( aVal >>= b ) && b) + aDescr.WindowAttributes |= WindowAttribute::CLOSEABLE; + } + + // Dropdown + aPropName = GetPropertyName( BASEPROPERTY_DROPDOWN ); + if ( xInfo->hasPropertyByName( aPropName ) ) + { + aVal = xPSet->getPropertyValue( aPropName ); + sal_Bool b = sal_Bool(); + if ( ( aVal >>= b ) && b) + aDescr.WindowAttributes |= VclWindowPeerAttribute::DROPDOWN; + } + + // Spin + aPropName = GetPropertyName( BASEPROPERTY_SPIN ); + if ( xInfo->hasPropertyByName( aPropName ) ) + { + aVal = xPSet->getPropertyValue( aPropName ); + sal_Bool b = sal_Bool(); + if ( ( aVal >>= b ) && b) + aDescr.WindowAttributes |= VclWindowPeerAttribute::SPIN; + } + + // HScroll + aPropName = GetPropertyName( BASEPROPERTY_HSCROLL ); + if ( xInfo->hasPropertyByName( aPropName ) ) + { + aVal = xPSet->getPropertyValue( aPropName ); + sal_Bool b = sal_Bool(); + if ( ( aVal >>= b ) && b) + aDescr.WindowAttributes |= VclWindowPeerAttribute::HSCROLL; + } + + // VScroll + aPropName = GetPropertyName( BASEPROPERTY_VSCROLL ); + if ( xInfo->hasPropertyByName( aPropName ) ) + { + aVal = xPSet->getPropertyValue( aPropName ); + sal_Bool b = sal_Bool(); + if ( ( aVal >>= b ) && b) + aDescr.WindowAttributes |= VclWindowPeerAttribute::VSCROLL; + } + + // AutoHScroll + aPropName = GetPropertyName( BASEPROPERTY_AUTOHSCROLL ); + if ( xInfo->hasPropertyByName( aPropName ) ) + { + aVal = xPSet->getPropertyValue( aPropName ); + sal_Bool b = sal_Bool(); + if ( ( aVal >>= b ) && b) + aDescr.WindowAttributes |= VclWindowPeerAttribute::AUTOHSCROLL; + } + + // AutoVScroll + aPropName = GetPropertyName( BASEPROPERTY_AUTOVSCROLL ); + if ( xInfo->hasPropertyByName( aPropName ) ) + { + aVal = xPSet->getPropertyValue( aPropName ); + sal_Bool b = sal_Bool(); + if ( ( aVal >>= b ) && b) + aDescr.WindowAttributes |= VclWindowPeerAttribute::AUTOVSCROLL; + } + + //added for issue79712 + //NoLabel + aPropName = GetPropertyName( BASEPROPERTY_NOLABEL ); + if ( xInfo->hasPropertyByName( aPropName ) ) + { + aVal = xPSet->getPropertyValue( aPropName ); + sal_Bool b = sal_Bool(); + if ( ( aVal >>=b ) && b ) + aDescr.WindowAttributes |= VclWindowPeerAttribute::NOLABEL; + } + //issue79712 ends + + // Align + aPropName = GetPropertyName( BASEPROPERTY_ALIGN ); + if ( xInfo->hasPropertyByName( aPropName ) ) + { + aVal = xPSet->getPropertyValue( aPropName ); + sal_Int16 n = sal_Int16(); + if ( aVal >>= n ) + { + if ( n == PROPERTY_ALIGN_LEFT ) + aDescr.WindowAttributes |= VclWindowPeerAttribute::LEFT; + else if ( n == PROPERTY_ALIGN_CENTER ) + aDescr.WindowAttributes |= VclWindowPeerAttribute::CENTER; + else + aDescr.WindowAttributes |= VclWindowPeerAttribute::RIGHT; + } + } + + // Ableitungen die Moeglichkeit geben die Attribute zu manipulieren + PrepareWindowDescriptor(aDescr); + + // create the peer + setPeer( xToolkit->createWindow( aDescr ) ); + + // release the mutex guard (and work with copies of our members) + // this is necessary as our peer may lock the SolarMutex (actually, all currently known peers do), so calling + // into the peer with our own mutex locked may cause deadlocks + // (We _really_ need peers which do not use the SolarMutex. It's really pissing me off that from time to + // time deadlocks pop up because the low-level components like our peers use a mutex which ususally + // is locked at the top of the stack (it protects the global message looping). This is always dangerous, and + // can not always be solved by tampering with other mutexes. + // Unfortunately, the VCL used in the peers is not threadsafe, and by definition needs a locked SolarMutex.) + // 82300 - 12/21/00 - FS + UnoControlComponentInfos aComponentInfos(maComponentInfos); + sal_Bool bDesignMode(mbDesignMode); + + Reference< XGraphics > xGraphics( mxGraphics ); + Reference< XView > xView ( getPeer(), UNO_QUERY ); + Reference< XWindow > xWindow ( getPeer(), UNO_QUERY ); + + aGuard.clear(); + + // the updateFromModel is done without a locked mutex, too. + // The reason is that the only thing this method does is firing property changes, and this in general has + // to be done without locked mutexes (as every notification to external listeners). + // 82300 - 12/21/00 - FS + updateFromModel(); + + xView->setZoom( aComponentInfos.nZoomX, aComponentInfos.nZoomY ); + + setPosSize( aComponentInfos.nX, aComponentInfos.nY, aComponentInfos.nWidth, aComponentInfos.nHeight, aComponentInfos.nFlags ); + + if( aComponentInfos.bVisible && !bDesignMode ) + // Erst nach dem setzen der Daten anzeigen + xWindow->setVisible( aComponentInfos.bVisible ); + + if( !aComponentInfos.bEnable ) + xWindow->setEnable( aComponentInfos.bEnable ); + + xView->setGraphics( xGraphics ); + + peerCreated(); + + mbCreatingPeer = sal_False; + } +} + +Reference< XWindowPeer > UnoControl::getPeer() throw(RuntimeException) +{ + ::osl::MutexGuard aGuard( GetMutex() ); + return mxPeer; +} + +sal_Bool UnoControl::setModel( const Reference< XControlModel >& rxModel ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard( GetMutex() ); + + Reference< XMultiPropertySet > xPropSet( mxModel, UNO_QUERY ); + + // query for the XPropertiesChangeListener - our delegator is allowed to overwrite this interface + Reference< XPropertiesChangeListener > xListener; + queryInterface( ::getCppuType( &xListener ) ) >>= xListener; + + if( xPropSet.is() ) + xPropSet->removePropertiesChangeListener( xListener ); + + mpData->bLocalizationSupport = false; + mxModel = rxModel; + + if( mxModel.is() ) + { + try + { + xPropSet.set( mxModel, UNO_QUERY_THROW ); + Reference< XPropertySetInfo > xPSI( xPropSet->getPropertySetInfo(), UNO_SET_THROW ); + + Sequence< ::rtl::OUString> aNames = lcl_ImplGetPropertyNames( xPropSet ); + xPropSet->addPropertiesChangeListener( aNames, xListener ); + + mpData->bLocalizationSupport = xPSI->hasPropertyByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceResolver" ) ) ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + mxModel.clear(); + } + } + + return mxModel.is(); +} + +Reference< XControlModel > UnoControl::getModel( ) throw(RuntimeException) +{ + return mxModel; +} + +Reference< XView > UnoControl::getView( ) throw(RuntimeException) +{ + return static_cast< XView* >( this ); +} + +void UnoControl::setDesignMode( sal_Bool bOn ) throw(RuntimeException) +{ + ModeChangeEvent aModeChangeEvent; + + Reference< XWindow > xWindow; + { + ::osl::MutexGuard aGuard( GetMutex() ); + if ( bOn == mbDesignMode ) + return; + + // remember this + mbDesignMode = bOn; + xWindow = xWindow.query( getPeer() ); + // dispose our current AccessibleContext, if we have one + // (changing the design mode implies having a new implementation for this context, + // so the old one must be declared DEFUNC) + disposeAccessibleContext(); + + aModeChangeEvent.Source = *this; + aModeChangeEvent.NewMode = ::rtl::OUString::createFromAscii( mbDesignMode ? "design" : "alive" ); + } + + // ajust the visibility of our window + if ( xWindow.is() ) + xWindow->setVisible( !bOn ); + + // and notify our mode listeners + maModeChangeListeners.notifyEach( &XModeChangeListener::modeChanged, aModeChangeEvent ); +} + +sal_Bool UnoControl::isDesignMode( ) throw(RuntimeException) +{ + return mbDesignMode; +} + +sal_Bool UnoControl::isTransparent( ) throw(RuntimeException) +{ + return sal_False; +} + +// XServiceInfo +::rtl::OUString UnoControl::getImplementationName( ) throw(RuntimeException) +{ + DBG_ERROR( "This method should be overloaded!" ); + return ::rtl::OUString(); +} + +sal_Bool UnoControl::supportsService( const ::rtl::OUString& rServiceName ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard( GetMutex() ); + + Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames(); + const ::rtl::OUString* pArray = aSNL.getConstArray(); + const ::rtl::OUString* pArrayEnd = aSNL.getConstArray(); + for (; pArray != pArrayEnd; ++pArray ) + if( *pArray == rServiceName ) + break; + + return pArray != pArrayEnd; +} + +Sequence< ::rtl::OUString > UnoControl::getSupportedServiceNames( ) throw(RuntimeException) +{ + ::rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControl" ) ); + return Sequence< ::rtl::OUString >( &sName, 1 ); +} + +// ------------------------------------------------------------------------ +Reference< XAccessibleContext > SAL_CALL UnoControl::getAccessibleContext( ) throw (RuntimeException) +{ + // creation of the context will certainly require the SolarMutex ... + ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + ::osl::MutexGuard aGuard( GetMutex() ); + + Reference< XAccessibleContext > xCurrentContext( maAccessibleContext.get(), UNO_QUERY ); + if ( !xCurrentContext.is() ) + { + if ( !mbDesignMode ) + { // in alive mode, use the AccessibleContext of the peer + Reference< XAccessible > xPeerAcc( getPeer(), UNO_QUERY ); + if ( xPeerAcc.is() ) + xCurrentContext = xPeerAcc->getAccessibleContext( ); + } + else + // in design mode, use a fallback + xCurrentContext = ::toolkit::OAccessibleControlContext::create( this ); + + DBG_ASSERT( xCurrentContext.is(), "UnoControl::getAccessibleContext: invalid context (invalid peer?)!" ); + maAccessibleContext = xCurrentContext; + + // get notified when the context is disposed + Reference< XComponent > xContextComp( xCurrentContext, UNO_QUERY ); + if ( xContextComp.is() ) + xContextComp->addEventListener( this ); + // In an ideal world, this is not necessary - there the object would be released as soon as it has been + // disposed, and thus our weak reference would be empty, too. + // But 'til this ideal world comes (means 'til we do never have any refcount/lifetime bugs anymore), we + // need to listen for disposal and reset our weak reference then. + } + + return xCurrentContext; +} + +void SAL_CALL UnoControl::addModeChangeListener( const Reference< XModeChangeListener >& _rxListener ) throw (RuntimeException) +{ + ::osl::MutexGuard aGuard( GetMutex() ); + maModeChangeListeners.addInterface( _rxListener ); +} + +void SAL_CALL UnoControl::removeModeChangeListener( const Reference< XModeChangeListener >& _rxListener ) throw (RuntimeException) +{ + ::osl::MutexGuard aGuard( GetMutex() ); + maModeChangeListeners.removeInterface( _rxListener ); +} + +void SAL_CALL UnoControl::addModeChangeApproveListener( const Reference< XModeChangeApproveListener >& ) throw (NoSupportException, RuntimeException) +{ + throw NoSupportException( ); +} + +void SAL_CALL UnoControl::removeModeChangeApproveListener( const Reference< XModeChangeApproveListener >& ) throw (NoSupportException, RuntimeException) +{ + throw NoSupportException( ); +} + diff --git a/toolkit/source/controls/unocontrolbase.cxx b/toolkit/source/controls/unocontrolbase.cxx new file mode 100644 index 000000000000..bbd0fc507e80 --- /dev/null +++ b/toolkit/source/controls/unocontrolbase.cxx @@ -0,0 +1,285 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <com/sun/star/awt/XLayoutConstrains.hpp> +#include <com/sun/star/awt/XTextLayoutConstrains.hpp> + +#include <toolkit/controls/unocontrolbase.hxx> +#include <toolkit/helper/property.hxx> + +#include <tools/debug.hxx> + +// ---------------------------------------------------- +// class UnoControlBase +// ---------------------------------------------------- + +sal_Bool UnoControlBase::ImplHasProperty( sal_uInt16 nPropId ) +{ + ::rtl::OUString aPropName( GetPropertyName( nPropId ) ); + return ImplHasProperty( aPropName ); +} + +sal_Bool UnoControlBase::ImplHasProperty( const ::rtl::OUString& aPropertyName ) +{ + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPSet( mxModel, ::com::sun::star::uno::UNO_QUERY ); + if ( !xPSet.is() ) + return sal_False; + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo = xPSet->getPropertySetInfo(); + if ( !xInfo.is() ) + return sal_False; + + return xInfo->hasPropertyByName( aPropertyName ); +} + +void UnoControlBase::ImplSetPropertyValues( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aPropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aValues, sal_Bool bUpdateThis ) +{ + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet > xMPS( mxModel, ::com::sun::star::uno::UNO_QUERY ); + if ( !mxModel.is() ) + return; + + DBG_ASSERT( xMPS.is(), "UnoControlBase::ImplSetPropertyValues: no multi property set interface!" ); + if ( xMPS.is() ) + { + if ( !bUpdateThis ) + ImplLockPropertyChangeNotifications( aPropertyNames, true ); + + try + { + xMPS->setPropertyValues( aPropertyNames, aValues ); + } + catch( const ::com::sun::star::uno::Exception& ) + { + if ( !bUpdateThis ) + ImplLockPropertyChangeNotifications( aPropertyNames, false ); + } + if ( !bUpdateThis ) + ImplLockPropertyChangeNotifications( aPropertyNames, false ); + } + else + { + int dummy = 0; + (void)dummy; + } +} + +void UnoControlBase::ImplSetPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue, sal_Bool bUpdateThis ) +{ + // Model ggf. schon abgemeldet, aber ein Event schlaegt noch zu... + if ( mxModel.is() ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPSet( mxModel, ::com::sun::star::uno::UNO_QUERY ); + if ( !bUpdateThis ) + ImplLockPropertyChangeNotification( aPropertyName, true ); + + try + { + xPSet->setPropertyValue( aPropertyName, aValue ); + } + catch( const com::sun::star::uno::Exception& ) + { + if ( !bUpdateThis ) + ImplLockPropertyChangeNotification( aPropertyName, false ); + throw; + } + if ( !bUpdateThis ) + ImplLockPropertyChangeNotification( aPropertyName, false ); + } +} + +::com::sun::star::uno::Any UnoControlBase::ImplGetPropertyValue( const ::rtl::OUString& aPropertyName ) +{ + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPSet( mxModel, ::com::sun::star::uno::UNO_QUERY ); + if ( xPSet.is() ) + return xPSet->getPropertyValue( aPropertyName ); + else + return ::com::sun::star::uno::Any(); +} + +sal_Bool UnoControlBase::ImplGetPropertyValue_BOOL( sal_uInt16 nProp ) +{ + sal_Bool b = sal_False; + if ( mxModel.is() ) + { + ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) ); + aVal >>= b; + } + return b; +} + +sal_Int16 UnoControlBase::ImplGetPropertyValue_INT16( sal_uInt16 nProp ) +{ + sal_Int16 n = 0; + if ( mxModel.is() ) + { + ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) ); + aVal >>= n; + } + return n; +} + +sal_uInt16 UnoControlBase::ImplGetPropertyValue_UINT16( sal_uInt16 nProp ) +{ + sal_uInt16 n = 0; + if ( mxModel.is() ) + { + ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) ); + aVal >>= n; + } + return n; +} + +sal_Int32 UnoControlBase::ImplGetPropertyValue_INT32( sal_uInt16 nProp ) +{ + sal_Int32 n = 0; + if ( mxModel.is() ) + { + ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) ); + aVal >>= n; + } + return n; +} + +sal_uInt32 UnoControlBase::ImplGetPropertyValue_UINT32( sal_uInt16 nProp ) +{ + sal_uInt32 n = 0; + if ( mxModel.is() ) + { + ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) ); + aVal >>= n; + } + return n; +} + +double UnoControlBase::ImplGetPropertyValue_DOUBLE( sal_uInt16 nProp ) +{ + double n = 0; + if ( mxModel.is() ) + { + ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) ); + aVal >>= n; + } + return n; +} + +::rtl::OUString UnoControlBase::ImplGetPropertyValue_UString( sal_uInt16 nProp ) +{ + ::rtl::OUString aStr; + if ( mxModel.is() ) + { + ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) ); + aVal >>= aStr; + } + return aStr; +} + +::com::sun::star::awt::Size UnoControlBase::Impl_getMinimumSize() +{ + ::com::sun::star::awt::Size aSz; + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xP = ImplGetCompatiblePeer( sal_True ); + DBG_ASSERT( xP.is(), "Layout: No Peer!" ); + if ( xP.is() ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY ); + if ( xL.is() ) + aSz = xL->getMinimumSize(); + + if ( !getPeer().is() || ( getPeer() != xP ) ) + xP->dispose(); + } + return aSz; +} + +::com::sun::star::awt::Size UnoControlBase::Impl_getPreferredSize() +{ + ::com::sun::star::awt::Size aSz; + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xP = ImplGetCompatiblePeer( sal_True ); + DBG_ASSERT( xP.is(), "Layout: No Peer!" ); + if ( xP.is() ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY ); + if ( xL.is() ) + aSz = xL->getPreferredSize(); + + if ( !getPeer().is() || ( getPeer() != xP ) ) + xP->dispose(); + } + return aSz; +} + +::com::sun::star::awt::Size UnoControlBase::Impl_calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize ) +{ + ::com::sun::star::awt::Size aSz; + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xP = ImplGetCompatiblePeer( sal_True ); + DBG_ASSERT( xP.is(), "Layout: No Peer!" ); + if ( xP.is() ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY ); + if ( xL.is() ) + aSz = xL->calcAdjustedSize( rNewSize ); + + if ( !getPeer().is() || ( getPeer() != xP ) ) + xP->dispose(); + } + return aSz; +} + +::com::sun::star::awt::Size UnoControlBase::Impl_getMinimumSize( sal_Int16 nCols, sal_Int16 nLines ) +{ + ::com::sun::star::awt::Size aSz; + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xP = ImplGetCompatiblePeer( sal_True ); + DBG_ASSERT( xP.is(), "Layout: No Peer!" ); + if ( xP.is() ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY ); + if ( xL.is() ) + aSz = xL->getMinimumSize( nCols, nLines ); + + if ( !getPeer().is() || ( getPeer() != xP ) ) + xP->dispose(); + } + return aSz; +} + +void UnoControlBase::Impl_getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines ) +{ + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xP = ImplGetCompatiblePeer( sal_True ); + DBG_ASSERT( xP.is(), "Layout: No Peer!" ); + if ( xP.is() ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY ); + if ( xL.is() ) + xL->getColumnsAndLines( nCols, nLines ); + + if ( !getPeer().is() || ( getPeer() != xP ) ) + xP->dispose(); + } +} + + + diff --git a/toolkit/source/controls/unocontrolcontainer.cxx b/toolkit/source/controls/unocontrolcontainer.cxx new file mode 100644 index 000000000000..c3149a8cc869 --- /dev/null +++ b/toolkit/source/controls/unocontrolcontainer.cxx @@ -0,0 +1,834 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + + +#include <com/sun/star/awt/XVclContainerPeer.hpp> +#include <com/sun/star/beans/XPropertyChangeListener.hpp> + +#include <cppuhelper/typeprovider.hxx> +#include <cppuhelper/implbase1.hxx> +#include <rtl/memory.h> +#include <rtl/uuid.h> + +#include <toolkit/controls/unocontrolcontainer.hxx> +#include <toolkit/helper/property.hxx> +#include <toolkit/helper/servicenames.hxx> +#include <comphelper/sequence.hxx> + +#include <tools/debug.hxx> +#include <tools/list.hxx> +#include <vcl/svapp.hxx> +#include <vcl/window.hxx> + +#include <limits> +#include <map> +#include <boost/shared_ptr.hpp> + +using namespace ::com::sun::star; + +extern WorkWindow* lcl_GetDefaultWindow(); + +// ---------------------------------------------------- +// class UnoControlHolder +// ---------------------------------------------------- +struct UnoControlHolder +{ + uno::Reference< awt::XControl > mxControl; + ::rtl::OUString msName; + +public: + UnoControlHolder( const ::rtl::OUString& rName, const uno::Reference< awt::XControl > & rControl ) + : mxControl( rControl ), + msName( rName ) + { + } + + inline const ::rtl::OUString& getName() const { return msName; } + inline const uno::Reference< awt::XControl >& getControl() const { return mxControl; } +}; + +//DECLARE_LIST( UnoControlHolderList, UnoControlHolder* ); + +class UnoControlHolderList +{ +public: + typedef sal_Int32 ControlIdentifier; +private: + typedef ::boost::shared_ptr< UnoControlHolder > ControlInfo; + typedef ::std::map< ControlIdentifier, ControlInfo > ControlMap; + +private: + ControlMap maControls; + +public: + UnoControlHolderList(); + ~UnoControlHolderList(); + + /** adds a control with the given name to the list + @param _rxControl + the control to add. Must not be <NULL/> + @param _pBName + the name of the control, or <NULL/> if an automatic name should be generated + @return + the identifier of the newly added control + */ + ControlIdentifier addControl( const uno::Reference< awt::XControl >& _rxControl, const ::rtl::OUString* _pName ); + + /** returns the number of controls in the list + */ + inline size_t size() const { return maControls.size(); } + + /** determines whether or not the list is empty + */ + inline bool empty() const { return maControls.empty(); } + + /** retrieves all controls currently in the list + @return + the number of controls in the list + */ + size_t getControls( uno::Sequence< uno::Reference< awt::XControl > >& _out_rControls ) const; + + /** retrieves all identifiers of all controls currently in the list + @return + the number of controls in the list + */ + size_t getIdentifiers( uno::Sequence< sal_Int32 >& _out_rIdentifiers ) const; + + /** returns the first control which is registered under the given name + */ + uno::Reference< awt::XControl > + getControlForName( const ::rtl::OUString& _rName ) const; + + /** returns the identifier which a control is registered for, or -1 if the control + isn't registered + */ + ControlIdentifier + getControlIdentifier( const uno::Reference< awt::XControl >& _rxControl ); + + /** retrieves the control for a given id + @param _nIdentifier + the identifier for the control + @param _out_rxControl + takes the XControl upon successful return + @return + <TRUE/> if and only if a control with the given id is part of the list + */ + bool getControlForIdentifier( ControlIdentifier _nIdentifier, uno::Reference< awt::XControl >& _out_rxControl ) const; + + /** removes a control from the list, given by id + @param _nId + The identifier of the control to remove. + */ + void removeControlById( ControlIdentifier _nId ); + + /** replaces a control from the list with another one + @param _nId + The identifier of the control to replace + @param _rxNewControl + the new control to put into the list + */ + void replaceControlById( ControlIdentifier _nId, const uno::Reference< awt::XControl >& _rxNewControl ); + +private: + /** adds a control + @param _rxControl + the control to add to the container + @param _pName + pointer to the name of the control. Might be <NULL/>, in this case, a name is generated. + @return + the identifier of the newly inserted control + */ + ControlIdentifier impl_addControl( + const uno::Reference< awt::XControl >& _rxControl, + const ::rtl::OUString* _pName + ); + + /** finds a free identifier + @throw uno::RuntimeException + if no free identifier can be found + */ + ControlIdentifier impl_getFreeIdentifier_throw(); + + /** finds a free name + @throw uno::RuntimeException + if no free name can be found + */ + ::rtl::OUString impl_getFreeName_throw(); +}; + +//------------------------------------------------------------------------ +UnoControlHolderList::UnoControlHolderList() +{ +} + +//------------------------------------------------------------------------ +UnoControlHolderList::~UnoControlHolderList() +{ +} + +//------------------------------------------------------------------------ +UnoControlHolderList::ControlIdentifier UnoControlHolderList::addControl( const uno::Reference< awt::XControl >& _rxControl, const ::rtl::OUString* _pName ) +{ + return impl_addControl( _rxControl, _pName ); +} + +//------------------------------------------------------------------------ +size_t UnoControlHolderList::getControls( uno::Sequence< uno::Reference< awt::XControl > >& _out_rControls ) const +{ + _out_rControls.realloc( maControls.size() ); + uno::Reference< awt::XControl >* pControls = _out_rControls.getArray(); + for ( ControlMap::const_iterator loop = maControls.begin(); + loop != maControls.end(); + ++loop, ++pControls + ) + *pControls = loop->second->getControl(); + return maControls.size(); +} + +//------------------------------------------------------------------------ +size_t UnoControlHolderList::getIdentifiers( uno::Sequence< sal_Int32 >& _out_rIdentifiers ) const +{ + _out_rIdentifiers.realloc( maControls.size() ); + sal_Int32* pIndentifiers = _out_rIdentifiers.getArray(); + for ( ControlMap::const_iterator loop = maControls.begin(); + loop != maControls.end(); + ++loop, ++pIndentifiers + ) + *pIndentifiers = loop->first; + return maControls.size(); +} + +//------------------------------------------------------------------------ +uno::Reference< awt::XControl > UnoControlHolderList::getControlForName( const ::rtl::OUString& _rName ) const +{ + for ( ControlMap::const_iterator loop = maControls.begin(); + loop != maControls.end(); + ++loop + ) + if ( loop->second->getName() == _rName ) + return loop->second->getControl(); + return uno::Reference< awt::XControl >(); +} + +//------------------------------------------------------------------------ +UnoControlHolderList::ControlIdentifier UnoControlHolderList::getControlIdentifier( const uno::Reference< awt::XControl >& _rxControl ) +{ + for ( ControlMap::iterator loop = maControls.begin(); + loop != maControls.end(); + ++loop + ) + { + if ( loop->second->getControl().get() == _rxControl.get() ) + return loop->first; + } + return -1; +} + +//------------------------------------------------------------------------ +bool UnoControlHolderList::getControlForIdentifier( UnoControlHolderList::ControlIdentifier _nIdentifier, uno::Reference< awt::XControl >& _out_rxControl ) const +{ + ControlMap::const_iterator pos = maControls.find( _nIdentifier ); + if ( pos == maControls.end() ) + return false; + _out_rxControl = pos->second->getControl(); + return true; +} + +//------------------------------------------------------------------------ +void UnoControlHolderList::removeControlById( UnoControlHolderList::ControlIdentifier _nId ) +{ + ControlMap::iterator pos = maControls.find( _nId ); + DBG_ASSERT( pos != maControls.end(), "UnoControlHolderList::removeControlById: invalid id!" ); + if ( pos == maControls.end() ) + return; + + maControls.erase( pos ); +} + +//------------------------------------------------------------------------ +void UnoControlHolderList::replaceControlById( ControlIdentifier _nId, const uno::Reference< awt::XControl >& _rxNewControl ) +{ + DBG_ASSERT( _rxNewControl.is(), "UnoControlHolderList::replaceControlById: invalid new control!" ); + + ControlMap::iterator pos = maControls.find( _nId ); + DBG_ASSERT( pos != maControls.end(), "UnoControlHolderList::replaceControlById: invalid id!" ); + if ( pos == maControls.end() ) + return; + + pos->second.reset( new UnoControlHolder( pos->second->getName(), _rxNewControl ) ); +} + +//------------------------------------------------------------------------ +UnoControlHolderList::ControlIdentifier UnoControlHolderList::impl_addControl( const uno::Reference< awt::XControl >& _rxControl, const ::rtl::OUString* _pName ) +{ + DBG_ASSERT( _rxControl.is(), "UnoControlHolderList::impl_addControl: invalid control!" ); + + ::rtl::OUString sName = _pName ? *_pName : impl_getFreeName_throw(); + sal_Int32 nId = impl_getFreeIdentifier_throw(); + + maControls[ nId ] = ControlInfo( new UnoControlHolder( sName, _rxControl ) ); + return nId; +} + +//------------------------------------------------------------------------ +UnoControlHolderList::ControlIdentifier UnoControlHolderList::impl_getFreeIdentifier_throw() +{ + for ( ControlIdentifier candidateId = 0; candidateId < ::std::numeric_limits< ControlIdentifier >::max(); ++candidateId ) + { + ControlMap::const_iterator existent = maControls.find( candidateId ); + if ( existent == maControls.end() ) + return candidateId; + } + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "out of identifiers" ) ), NULL ); +} + +//------------------------------------------------------------------------ +::rtl::OUString UnoControlHolderList::impl_getFreeName_throw() +{ + ::rtl::OUString name( RTL_CONSTASCII_USTRINGPARAM( "control_" ) ); + for ( ControlIdentifier candidateId = 0; candidateId < ::std::numeric_limits< ControlIdentifier >::max(); ++candidateId ) + { + ::rtl::OUString candidateName( name + ::rtl::OUString::valueOf( candidateId ) ); + ControlMap::const_iterator loop = maControls.begin(); + for ( ; loop != maControls.end(); ++loop ) + { + if ( loop->second->getName() == candidateName ) + break; + } + if ( loop == maControls.end() ) + return candidateName; + } + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "out of identifiers" ) ), NULL ); +} +// ---------------------------------------------------- +// Function to set the controls' visibility according +// to the dialog's "Step" property +// ---------------------------------------------------- +void implUpdateVisibility +( + sal_Int32 nDialogStep, + uno::Reference< awt::XControlContainer > xControlContainer +) +{ + uno::Sequence< uno::Reference< awt::XControl > > + aCtrls = xControlContainer->getControls(); + const uno::Reference< awt::XControl >* pCtrls = aCtrls.getConstArray(); + sal_uInt32 nCtrls = aCtrls.getLength(); + sal_Bool bCompleteVisible = (nDialogStep == 0); + for( sal_uInt32 n = 0; n < nCtrls; n++ ) + { + uno::Reference< awt::XControl > xControl = pCtrls[ n ]; + + sal_Bool bVisible = bCompleteVisible; + if( !bVisible ) + { + uno::Reference< awt::XControlModel > xModel( xControl->getModel() ); + uno::Reference< beans::XPropertySet > xPSet + ( xModel, uno::UNO_QUERY ); + uno::Reference< beans::XPropertySetInfo > + xInfo = xPSet->getPropertySetInfo(); + ::rtl::OUString aPropName(RTL_CONSTASCII_USTRINGPARAM( "Step" ) ); + sal_Int32 nControlStep = 0; + if ( xInfo->hasPropertyByName( aPropName ) ) + { + uno::Any aVal = xPSet->getPropertyValue( aPropName ); + aVal >>= nControlStep; + } + bVisible = (nControlStep == 0) || (nControlStep == nDialogStep); + } + + uno::Reference< awt::XWindow> xWindow + ( xControl, uno::UNO_QUERY ); + if( xWindow.is() ) + xWindow->setVisible( bVisible ); + } +} + + +// ---------------------------------------------------- +// class DialogStepChangedListener +// ---------------------------------------------------- +typedef ::cppu::WeakImplHelper1< beans::XPropertyChangeListener > PropertyChangeListenerHelper; + +class DialogStepChangedListener: public PropertyChangeListenerHelper +{ +private: + uno::Reference< awt::XControlContainer > mxControlContainer; + +public: + DialogStepChangedListener( uno::Reference< awt::XControlContainer > xControlContainer ) + : mxControlContainer( xControlContainer ) {} + + // XEventListener + virtual void SAL_CALL disposing( const lang::EventObject& Source ) throw( uno::RuntimeException); + + // XPropertyChangeListener + virtual void SAL_CALL propertyChange( const beans::PropertyChangeEvent& evt ) throw( uno::RuntimeException); + +}; + +void SAL_CALL DialogStepChangedListener::disposing( const lang::EventObject& /*_rSource*/) + throw( uno::RuntimeException) +{ + mxControlContainer.clear(); +} + +void SAL_CALL DialogStepChangedListener::propertyChange( const beans::PropertyChangeEvent& evt ) + throw( uno::RuntimeException) +{ + // evt.PropertyName HAS to be "Step" because we only use the listener for that + sal_Int32 nDialogStep = 0; + evt.NewValue >>= nDialogStep; + implUpdateVisibility( nDialogStep, mxControlContainer ); +} + +// ---------------------------------------------------- +// class UnoControlContainer +// ---------------------------------------------------- +UnoControlContainer::UnoControlContainer() : maCListeners( *this ) +{ + mpControls = new UnoControlHolderList; +} + +UnoControlContainer::UnoControlContainer( uno::Reference< awt::XWindowPeer > xP ) + : maCListeners( *this ) +{ + setPeer( xP ); + mbDisposePeer = sal_False; + mpControls = new UnoControlHolderList; +} + +UnoControlContainer::~UnoControlContainer() +{ + DELETEZ( mpControls ); +} + +void UnoControlContainer::ImplActivateTabControllers() +{ + sal_uInt32 nCount = maTabControllers.getLength(); + for ( sal_uInt32 n = 0; n < nCount; n++ ) + { + maTabControllers.getArray()[n]->setContainer( this ); + maTabControllers.getArray()[n]->activateTabOrder(); + } +} + +// lang::XComponent +void UnoControlContainer::dispose( ) throw(uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + lang::EventObject aDisposeEvent; + aDisposeEvent.Source = static_cast< uno::XAggregation* >( this ); + + // DG: zuerst der Welt mitteilen, dass der Container wegfliegt. Dieses ist um einiges + // schneller wenn die Welt sowohl an den Controls als auch am Container horcht + maDisposeListeners.disposeAndClear( aDisposeEvent ); + maCListeners.disposeAndClear( aDisposeEvent ); + + + uno::Sequence< uno::Reference< awt::XControl > > aCtrls = getControls(); + uno::Reference< awt::XControl >* pCtrls = aCtrls.getArray(); + uno::Reference< awt::XControl >* pCtrlsEnd = pCtrls + aCtrls.getLength(); + + for( ; pCtrls < pCtrlsEnd; ++pCtrls ) + { + removingControl( *pCtrls ); + // Control wegwerfen + (*pCtrls)->dispose(); + } + + + // alle Strukturen entfernen + DELETEZ( mpControls ); + mpControls = new UnoControlHolderList; + + UnoControlBase::dispose(); +} + +// lang::XEventListener +void UnoControlContainer::disposing( const lang::EventObject& _rEvt ) throw(uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + uno::Reference< awt::XControl > xControl( _rEvt.Source, uno::UNO_QUERY ); + if ( xControl.is() ) + removeControl( xControl ); + + UnoControlBase::disposing( _rEvt ); +} + +// container::XContainer +void UnoControlContainer::addContainerListener( const uno::Reference< container::XContainerListener >& rxListener ) throw(uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maCListeners.addInterface( rxListener ); +} + +void UnoControlContainer::removeContainerListener( const uno::Reference< container::XContainerListener >& rxListener ) throw(uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maCListeners.removeInterface( rxListener ); +} + + +::sal_Int32 SAL_CALL UnoControlContainer::insert( const uno::Any& _rElement ) throw (lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + uno::Reference< awt::XControl > xControl; + if ( !( _rElement >>= xControl ) || !xControl.is() ) + throw lang::IllegalArgumentException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Elements must support the XControl interface." ) ), + *this, + 1 + ); + + return impl_addControl( xControl, NULL ); +} + +void SAL_CALL UnoControlContainer::removeByIdentifier( ::sal_Int32 _nIdentifier ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + uno::Reference< awt::XControl > xControl; + if ( !mpControls->getControlForIdentifier( _nIdentifier, xControl ) ) + throw container::NoSuchElementException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "There is no element with the given identifier." ) ), + *this + ); + + impl_removeControl( _nIdentifier, xControl, NULL ); +} + +void SAL_CALL UnoControlContainer::replaceByIdentifer( ::sal_Int32 _nIdentifier, const uno::Any& _rElement ) throw (lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + uno::Reference< awt::XControl > xExistentControl; + if ( !mpControls->getControlForIdentifier( _nIdentifier, xExistentControl ) ) + throw container::NoSuchElementException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "There is no element with the given identifier." ) ), + *this + ); + + uno::Reference< awt::XControl > xNewControl; + if ( !( _rElement >>= xNewControl ) ) + throw lang::IllegalArgumentException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Elements must support the XControl interface." ) ), + *this, + 1 + ); + + removingControl( xExistentControl ); + + mpControls->replaceControlById( _nIdentifier, xNewControl ); + + addingControl( xNewControl ); + + impl_createControlPeerIfNecessary( xNewControl ); + + if ( maCListeners.getLength() ) + { + container::ContainerEvent aEvent; + aEvent.Source = *this; + aEvent.Accessor <<= _nIdentifier; + aEvent.Element <<= xNewControl; + aEvent.ReplacedElement <<= xExistentControl; + maCListeners.elementReplaced( aEvent ); + } +} + +uno::Any SAL_CALL UnoControlContainer::getByIdentifier( ::sal_Int32 _nIdentifier ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + uno::Reference< awt::XControl > xControl; + if ( !mpControls->getControlForIdentifier( _nIdentifier, xControl ) ) + throw container::NoSuchElementException(); + return uno::makeAny( xControl ); +} + +uno::Sequence< ::sal_Int32 > SAL_CALL UnoControlContainer::getIdentifiers( ) throw (uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + uno::Sequence< ::sal_Int32 > aIdentifiers; + mpControls->getIdentifiers( aIdentifiers ); + return aIdentifiers; +} + +// container::XElementAccess +uno::Type SAL_CALL UnoControlContainer::getElementType( ) throw (uno::RuntimeException) +{ + return awt::XControlModel::static_type(); +} + +::sal_Bool SAL_CALL UnoControlContainer::hasElements( ) throw (uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + return !mpControls->empty(); +} + +// awt::XControlContainer +void UnoControlContainer::setStatusText( const ::rtl::OUString& rStatusText ) throw(uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + // In der Parenthierarchie nach unten gehen + uno::Reference< awt::XControlContainer > xContainer( mxContext, uno::UNO_QUERY ); + if( xContainer.is() ) + xContainer->setStatusText( rStatusText ); +} + +uno::Sequence< uno::Reference< awt::XControl > > UnoControlContainer::getControls( ) throw(uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + uno::Sequence< uno::Reference< awt::XControl > > aControls; + mpControls->getControls( aControls ); + return aControls; +} + +uno::Reference< awt::XControl > UnoControlContainer::getControl( const ::rtl::OUString& rName ) throw(uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + return mpControls->getControlForName( rName ); +} + +void UnoControlContainer::addingControl( const uno::Reference< awt::XControl >& _rxControl ) +{ + if ( _rxControl.is() ) + { + uno::Reference< uno::XInterface > xThis; + OWeakAggObject::queryInterface( ::getCppuType( static_cast< uno::Reference< uno::XInterface >* >( NULL ) ) ) >>= xThis; + + _rxControl->setContext( xThis ); + _rxControl->addEventListener( this ); + } +} + +void UnoControlContainer::impl_createControlPeerIfNecessary( const uno::Reference< awt::XControl >& _rxControl ) +{ + OSL_PRECOND( _rxControl.is(), "UnoControlContainer::impl_createControlPeerIfNecessary: invalid control, this will crash!" ); + + // if the container already has a peer, then also create a peer for the control + uno::Reference< awt::XWindowPeer > xMyPeer( getPeer() ); + + if( xMyPeer.is() ) + { + _rxControl->createPeer( NULL, xMyPeer ); + ImplActivateTabControllers(); + } + +} + +sal_Int32 UnoControlContainer::impl_addControl( const uno::Reference< awt::XControl >& _rxControl, const ::rtl::OUString* _pName ) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + UnoControlHolderList::ControlIdentifier id = mpControls->addControl( _rxControl, _pName ); + + addingControl( _rxControl ); + + impl_createControlPeerIfNecessary( _rxControl ); + + if ( maCListeners.getLength() ) + { + container::ContainerEvent aEvent; + aEvent.Source = *this; + _pName ? ( aEvent.Accessor <<= *_pName ) : ( aEvent.Accessor <<= (sal_Int32)id ); + aEvent.Element <<= _rxControl; + maCListeners.elementInserted( aEvent ); + } + + return id; +} + +void UnoControlContainer::addControl( const ::rtl::OUString& rName, const uno::Reference< awt::XControl >& rControl ) throw(uno::RuntimeException) +{ + if ( rControl.is() ) + impl_addControl( rControl, &rName ); +} + +void UnoControlContainer::removingControl( const uno::Reference< awt::XControl >& _rxControl ) +{ + if ( _rxControl.is() ) + { + _rxControl->removeEventListener( this ); + _rxControl->setContext( NULL ); + } +} + +void UnoControlContainer::impl_removeControl( sal_Int32 _nId, const uno::Reference< awt::XControl >& _rxControl, const ::rtl::OUString* _pNameAccessor ) +{ +#ifdef DBG_UTIL + { + uno::Reference< awt::XControl > xControl; + bool bHas = mpControls->getControlForIdentifier( _nId, xControl ); + DBG_ASSERT( bHas && xControl == _rxControl, "UnoControlContainer::impl_removeControl: inconsistency in the parameters!" ); + } +#endif + removingControl( _rxControl ); + + mpControls->removeControlById( _nId ); + + if ( maCListeners.getLength() ) + { + container::ContainerEvent aEvent; + aEvent.Source = *this; + _pNameAccessor ? ( aEvent.Accessor <<= *_pNameAccessor ) : ( aEvent.Accessor <<= _nId ); + aEvent.Element <<= _rxControl; + maCListeners.elementRemoved( aEvent ); + } +} + +void UnoControlContainer::removeControl( const uno::Reference< awt::XControl >& _rxControl ) throw(uno::RuntimeException) +{ + if ( _rxControl.is() ) + { + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + UnoControlHolderList::ControlIdentifier id = mpControls->getControlIdentifier( _rxControl ); + if ( id != -1 ) + impl_removeControl( id, _rxControl, NULL ); + } +} + + + +// awt::XUnoControlContainer +void UnoControlContainer::setTabControllers( const uno::Sequence< uno::Reference< awt::XTabController > >& TabControllers ) throw(uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maTabControllers = TabControllers; +} + +uno::Sequence< uno::Reference< awt::XTabController > > UnoControlContainer::getTabControllers( ) throw(uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return maTabControllers; +} + +void UnoControlContainer::addTabController( const uno::Reference< awt::XTabController >& TabController ) throw(uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + sal_uInt32 nCount = maTabControllers.getLength(); + maTabControllers.realloc( nCount + 1 ); + maTabControllers[ nCount ] = TabController; +} + +void UnoControlContainer::removeTabController( const uno::Reference< awt::XTabController >& TabController ) throw(uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + sal_uInt32 nCount = maTabControllers.getLength(); + const uno::Reference< awt::XTabController >* pLoop = maTabControllers.getConstArray(); + for ( sal_uInt32 n = 0; n < nCount; ++n, ++pLoop ) + { + if( pLoop->get() == TabController.get() ) + { + ::comphelper::removeElementAt( maTabControllers, n ); + break; + } + } +} + +// awt::XControl +void UnoControlContainer::createPeer( const uno::Reference< awt::XToolkit >& rxToolkit, const uno::Reference< awt::XWindowPeer >& rParent ) throw(uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + if( !getPeer().is() ) + { + sal_Bool bVis = maComponentInfos.bVisible; + if( bVis ) + UnoControl::setVisible( sal_False ); + // eigenes Peer erzeugen + UnoControl::createPeer( rxToolkit, rParent ); + + // alle Peers der Childs erzeugen + if ( !mbCreatingCompatiblePeer ) + { + // Evaluate "Step" property + uno::Reference< awt::XControlModel > xModel( getModel() ); + uno::Reference< beans::XPropertySet > xPSet + ( xModel, uno::UNO_QUERY ); + uno::Reference< beans::XPropertySetInfo > + xInfo = xPSet->getPropertySetInfo(); + ::rtl::OUString aPropName(RTL_CONSTASCII_USTRINGPARAM( "Step" ) ); + if ( xInfo->hasPropertyByName( aPropName ) ) + { + ::com::sun::star::uno::Any aVal = xPSet->getPropertyValue( aPropName ); + sal_Int32 nDialogStep = 0; + aVal >>= nDialogStep; + uno::Reference< awt::XControlContainer > xContainer = + SAL_STATIC_CAST( awt::XControlContainer*, this ); + implUpdateVisibility( nDialogStep, xContainer ); + + uno::Reference< beans::XPropertyChangeListener > xListener = + SAL_STATIC_CAST( beans::XPropertyChangeListener*, + new DialogStepChangedListener( xContainer ) ); + xPSet->addPropertyChangeListener( aPropName, xListener ); + } + + uno::Sequence< uno::Reference< awt::XControl > > aCtrls = getControls(); + sal_uInt32 nCtrls = aCtrls.getLength(); + for( sal_uInt32 n = 0; n < nCtrls; n++ ) + aCtrls.getArray()[n]->createPeer( rxToolkit, getPeer() ); + + uno::Reference< awt::XVclContainerPeer > xC( getPeer(), uno::UNO_QUERY ); + + xC->enableDialogControl( sal_True ); + ImplActivateTabControllers(); + } + + if( bVis && !isDesignMode() ) + UnoControl::setVisible( sal_True ); + } +} + + +// awt::XWindow +void UnoControlContainer::setVisible( sal_Bool bVisible ) throw(uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + UnoControl::setVisible( bVisible ); + if( !mxContext.is() && bVisible ) + // Es ist ein TopWindow, also automatisch anzeigen + createPeer( uno::Reference< awt::XToolkit > (), uno::Reference< awt::XWindowPeer > () ); +} + + + diff --git a/toolkit/source/controls/unocontrolcontainermodel.cxx b/toolkit/source/controls/unocontrolcontainermodel.cxx new file mode 100644 index 000000000000..7630971d8a57 --- /dev/null +++ b/toolkit/source/controls/unocontrolcontainermodel.cxx @@ -0,0 +1,89 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + +#include <toolkit/controls/unocontrolcontainermodel.hxx> +#include <toolkit/helper/property.hxx> +#include <toolkit/helper/servicenames.hxx> +#include <toolkit/helper/unopropertyarrayhelper.hxx> + +// ---------------------------------------------------- +// class UnoControlContainerModel +// ---------------------------------------------------- +UnoControlContainerModel::UnoControlContainerModel() +{ + ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR ); + ImplRegisterProperty( BASEPROPERTY_BORDER ); + ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR ); + ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL ); + ImplRegisterProperty( BASEPROPERTY_ENABLED ); + ImplRegisterProperty( BASEPROPERTY_HELPTEXT ); + ImplRegisterProperty( BASEPROPERTY_HELPURL ); + ImplRegisterProperty( BASEPROPERTY_PRINTABLE ); + ImplRegisterProperty( BASEPROPERTY_TEXT ); +} + +::rtl::OUString UnoControlContainerModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlContainerModel ); +} + +::com::sun::star::uno::Any UnoControlContainerModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + ::com::sun::star::uno::Any aDefault; + if ( nPropId == BASEPROPERTY_BORDER ) + aDefault <<= (sal_Int16) 0; + else + aDefault <<= UnoControlModel::ImplGetDefaultValue( nPropId ); + return aDefault; +} + + +::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > UnoControlContainerModel::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException) +{ + static ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + +::cppu::IPropertyArrayHelper& UnoControlContainerModel::getInfoHelper() +{ + ::osl::Guard< ::osl::Mutex > aGuard( ((UnoControlContainerModel*)this)->GetMutex() ); + + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + ::com::sun::star::uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + + + + diff --git a/toolkit/source/controls/unocontrolmodel.cxx b/toolkit/source/controls/unocontrolmodel.cxx new file mode 100644 index 000000000000..29b683a5ed40 --- /dev/null +++ b/toolkit/source/controls/unocontrolmodel.cxx @@ -0,0 +1,1495 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <com/sun/star/beans/PropertyState.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/awt/FontDescriptor.hpp> +#include <com/sun/star/awt/FontWidth.hpp> +#include <com/sun/star/awt/FontWeight.hpp> +#include <com/sun/star/awt/FontSlant.hpp> +#include <com/sun/star/awt/MouseWheelBehavior.hpp> +#include <com/sun/star/graphic/XGraphicProvider.hpp> +#include <com/sun/star/awt/XDevice.hpp> +#include <com/sun/star/text/WritingMode2.hpp> +#include <com/sun/star/io/XMarkableStream.hpp> +#include <toolkit/controls/unocontrolmodel.hxx> +#include <toolkit/helper/macros.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <cppuhelper/extract.hxx> +#include <rtl/memory.h> +#include <rtl/uuid.h> +#include <tools/diagnose_ex.h> +#include <tools/string.hxx> +#include <tools/table.hxx> +#include <tools/date.hxx> +#include <tools/time.hxx> +#include <tools/urlobj.hxx> +#include <tools/debug.hxx> +#include <toolkit/helper/property.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <toolkit/helper/emptyfontdescriptor.hxx> +#include <com/sun/star/lang/Locale.hpp> +#include <unotools/localedatawrapper.hxx> +#include <unotools/configmgr.hxx> +#include <comphelper/processfactory.hxx> +#include <comphelper/sequence.hxx> +#include <vcl/svapp.hxx> +#include <uno/data.h> + +#include <memory> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::i18n; +using ::com::sun::star::awt::FontDescriptor; + +struct ImplControlProperty +{ +private: + sal_uInt16 nId; + ::com::sun::star::uno::Any aValue; + +public: + ImplControlProperty( const ImplControlProperty& rProp ) : aValue( rProp.aValue ) + { + nId = rProp.nId; + } + + ImplControlProperty( sal_uInt16 nT ) + { + nId = nT; + } + + ImplControlProperty( sal_uInt16 nT, const ::com::sun::star::uno::Any& rValue ) : aValue( rValue ) + { + nId = nT; + } + + sal_uInt16 GetId() const { return nId; } + const ::com::sun::star::uno::Any& GetValue() const { return aValue; } + void SetValue( const ::com::sun::star::uno::Any& rValue ) { aValue = rValue; } +}; + +DECLARE_TABLE( ImplPropertyTable, ImplControlProperty* ) + +#define UNOCONTROL_STREAMVERSION (short)2 + +static void lcl_ImplMergeFontProperty( FontDescriptor& rFD, sal_uInt16 nPropId, const Any& rValue ) +{ + // some props are defined with other types than the matching FontDescriptor members have + // (e.g. FontWidth, FontSlant) + // 78474 - 09/19/2000 - FS + float nExtractFloat = 0; + sal_Int16 nExtractShort = 0; + + switch ( nPropId ) + { + case BASEPROPERTY_FONTDESCRIPTORPART_NAME: rValue >>= rFD.Name; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME: rValue >>= rFD.StyleName; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY: rValue >>= rFD.Family; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET: rValue >>= rFD.CharSet; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT: rValue >>= nExtractFloat; rFD.Height = (sal_Int16)nExtractFloat; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT: rValue >>= rFD.Weight; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_SLANT: if ( rValue >>= nExtractShort ) + rFD.Slant = (::com::sun::star::awt::FontSlant)nExtractShort; + else + rValue >>= rFD.Slant; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE: rValue >>= rFD.Underline; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT: rValue >>= rFD.Strikeout; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH: rValue >>= rFD.Width; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_PITCH: rValue >>= rFD.Pitch; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH: rValue >>= rFD.CharacterWidth; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION: rValue >>= rFD.Orientation; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_KERNING: rValue >>= rFD.Kerning; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE: rValue >>= rFD.WordLineMode; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_TYPE: rValue >>= rFD.Type; + break; + default: DBG_ERROR( "FontProperty?!" ); + } +} + +// ---------------------------------------------------- +// class UnoControlModel +// ---------------------------------------------------- +UnoControlModel::UnoControlModel() + : OPropertySetHelper( BrdcstHelper ), maDisposeListeners( *this ) +{ + // Die Properties muessen vom Model in die Tabelle gestopft werden, + // nur vorhandene Properties sind gueltige Properties, auch wenn VOID. + mpData = new ImplPropertyTable; +} + +UnoControlModel::UnoControlModel( const UnoControlModel& rModel ) + : XControlModel() + , XPropertyState() + , XPersistObject() + , XComponent() + , XServiceInfo() + , XTypeProvider() + , XUnoTunnel() + , XCloneable() + , MutexAndBroadcastHelper() + , OPropertySetHelper( BrdcstHelper ) + , OWeakAggObject() + , maDisposeListeners( *this ) +{ + mpData = new ImplPropertyTable; + + for ( sal_uInt32 n = rModel.mpData->Count(); n; ) + { + ImplControlProperty* pProp = rModel.mpData->GetObject( --n ); + ImplControlProperty* pNew = new ImplControlProperty( *pProp ); + mpData->Insert( pNew->GetId(), pNew ); + } +} + +UnoControlModel::~UnoControlModel() +{ + for ( sal_uInt32 n = mpData->Count(); n; ) + delete mpData->GetObject( --n ); + delete mpData; +} + +UnoControlModel* UnoControlModel::Clone() const +{ + DBG_ERROR( "UnoControlModel::Clone() ?!" ); + return NULL; +} + +::com::sun::star::uno::Sequence<sal_Int32> UnoControlModel::ImplGetPropertyIds() const +{ + sal_uInt32 nIDs = mpData->Count(); + ::com::sun::star::uno::Sequence<sal_Int32> aIDs( nIDs ); + sal_Int32* pIDs = aIDs.getArray(); + for ( sal_uInt32 n = 0; n < nIDs; n++ ) + pIDs[n] = mpData->GetObjectKey( n ); + return aIDs; +} + +sal_Bool UnoControlModel::ImplHasProperty( sal_uInt16 nPropId ) const +{ + if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) ) + nPropId = BASEPROPERTY_FONTDESCRIPTOR; + + return mpData->Get( nPropId ) ? sal_True : sal_False; +} + +void UnoControlModel::ImplPropertyChanged( sal_uInt16 ) +{ +} + +::com::sun::star::uno::Any UnoControlModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + ::com::sun::star::uno::Any aDefault; + + if ( + (nPropId == BASEPROPERTY_FONTDESCRIPTOR) || + ( + (nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START) && + (nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END) + ) + ) + { + EmptyFontDescriptor aFD; + switch ( nPropId ) + { + case BASEPROPERTY_FONTDESCRIPTOR: aDefault <<= aFD; break; + case BASEPROPERTY_FONTDESCRIPTORPART_NAME: aDefault <<= aFD.Name; break; + case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME: aDefault <<= aFD.StyleName; break; + case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY: aDefault <<= aFD.Family; break; + case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET: aDefault <<= aFD.CharSet; break; + case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT: aDefault <<= (float)aFD.Height; break; + case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT: aDefault <<= aFD.Weight; break; + case BASEPROPERTY_FONTDESCRIPTORPART_SLANT: aDefault <<= (sal_Int16)aFD.Slant; break; + case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE: aDefault <<= aFD.Underline; break; + case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT: aDefault <<= aFD.Strikeout; break; + case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH: aDefault <<= aFD.Width; break; + case BASEPROPERTY_FONTDESCRIPTORPART_PITCH: aDefault <<= aFD.Pitch; break; + case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH: aDefault <<= aFD.CharacterWidth; break; + case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION: aDefault <<= aFD.Orientation; break; + case BASEPROPERTY_FONTDESCRIPTORPART_KERNING: aDefault <<= aFD.Kerning; break; + case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE: aDefault <<= aFD.WordLineMode; break; + case BASEPROPERTY_FONTDESCRIPTORPART_TYPE: aDefault <<= aFD.Type; break; + default: DBG_ERROR( "FontProperty?!" ); + } + } + else + { + switch ( nPropId ) + { + case BASEPROPERTY_GRAPHIC: + aDefault <<= Reference< graphic::XGraphic >(); + break; + + case BASEPROPERTY_REFERENCE_DEVICE: + aDefault <<= Reference< awt::XDevice >(); + break; + + case BASEPROPERTY_VERTICALALIGN: + case BASEPROPERTY_BORDERCOLOR: + case BASEPROPERTY_SYMBOL_COLOR: + case BASEPROPERTY_TABSTOP: + case BASEPROPERTY_TEXTCOLOR: + case BASEPROPERTY_TEXTLINECOLOR: + case BASEPROPERTY_DATE: + case BASEPROPERTY_DATESHOWCENTURY: + case BASEPROPERTY_TIME: + case BASEPROPERTY_VALUE_DOUBLE: + case BASEPROPERTY_PROGRESSVALUE: + case BASEPROPERTY_SCROLLVALUE: + case BASEPROPERTY_VISIBLESIZE: + case BASEPROPERTY_BACKGROUNDCOLOR: + case BASEPROPERTY_FILLCOLOR: break; // Void + + case BASEPROPERTY_FONTRELIEF: + case BASEPROPERTY_FONTEMPHASISMARK: + case BASEPROPERTY_MAXTEXTLEN: + case BASEPROPERTY_STATE: + case BASEPROPERTY_EXTDATEFORMAT: + case BASEPROPERTY_EXTTIMEFORMAT: + case BASEPROPERTY_ECHOCHAR: aDefault <<= (sal_Int16) 0; break; + case BASEPROPERTY_BORDER: aDefault <<= (sal_Int16) 1; break; + case BASEPROPERTY_DECIMALACCURACY: aDefault <<= (sal_Int16) 2; break; + case BASEPROPERTY_LINECOUNT: aDefault <<= (sal_Int16) 5; break; + case BASEPROPERTY_ALIGN: aDefault <<= (sal_Int16) PROPERTY_ALIGN_LEFT; break; + case BASEPROPERTY_IMAGEALIGN: aDefault <<= (sal_Int16) 1 /*ImageAlign::TOP*/; break; + case BASEPROPERTY_IMAGEPOSITION: aDefault <<= (sal_Int16) 12 /*ImagePosition::Centered*/; break; + case BASEPROPERTY_PUSHBUTTONTYPE: aDefault <<= (sal_Int16) 0 /*PushButtonType::STANDARD*/; break; + case BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR:aDefault <<= (sal_Int16) awt::MouseWheelBehavior::SCROLL_FOCUS_ONLY; break; + + case BASEPROPERTY_DATEMAX: aDefault <<= (sal_Int32) Date( 31, 12, 2200 ).GetDate(); break; + case BASEPROPERTY_DATEMIN: aDefault <<= (sal_Int32) Date( 1, 1, 1900 ).GetDate(); break; + case BASEPROPERTY_TIMEMAX: aDefault <<= (sal_Int32) Time( 23, 59 ).GetTime(); break; + case BASEPROPERTY_TIMEMIN: aDefault <<= (sal_Int32) 0; break; + case BASEPROPERTY_VALUEMAX_DOUBLE: aDefault <<= (double) 1000000; break; + case BASEPROPERTY_VALUEMIN_DOUBLE: aDefault <<= (double) -1000000; break; + case BASEPROPERTY_VALUESTEP_DOUBLE: aDefault <<= (double ) 1; break; + case BASEPROPERTY_PROGRESSVALUE_MAX: aDefault <<= (sal_Int32) 100; break; + case BASEPROPERTY_PROGRESSVALUE_MIN: aDefault <<= (sal_Int32) 0; break; + case BASEPROPERTY_SCROLLVALUE_MAX: aDefault <<= (sal_Int32) 100; break; + case BASEPROPERTY_SCROLLVALUE_MIN: aDefault <<= (sal_Int32) 0; break; + case BASEPROPERTY_LINEINCREMENT: aDefault <<= (sal_Int32) 1; break; + case BASEPROPERTY_BLOCKINCREMENT: aDefault <<= (sal_Int32) 10; break; + case BASEPROPERTY_ORIENTATION: aDefault <<= (sal_Int32) 0; break; + case BASEPROPERTY_SPINVALUE: aDefault <<= (sal_Int32) 0; break; + case BASEPROPERTY_SPININCREMENT: aDefault <<= (sal_Int32) 1; break; + case BASEPROPERTY_SPINVALUE_MIN: aDefault <<= (sal_Int32) 0; break; + case BASEPROPERTY_SPINVALUE_MAX: aDefault <<= (sal_Int32) 100; break; + case BASEPROPERTY_REPEAT_DELAY: aDefault <<= (sal_Int32) 50; break; // 50 milliseconds + case BASEPROPERTY_DEFAULTCONTROL: aDefault <<= ((UnoControlModel*)this)->getServiceName(); break; + + case BASEPROPERTY_AUTOHSCROLL: + case BASEPROPERTY_AUTOVSCROLL: + case BASEPROPERTY_MOVEABLE: + case BASEPROPERTY_CLOSEABLE: + case BASEPROPERTY_SIZEABLE: + case BASEPROPERTY_HSCROLL: + case BASEPROPERTY_DEFAULTBUTTON: + case BASEPROPERTY_MULTILINE: + case BASEPROPERTY_MULTISELECTION: + case BASEPROPERTY_TRISTATE: + case BASEPROPERTY_DROPDOWN: + case BASEPROPERTY_SPIN: + case BASEPROPERTY_READONLY: + case BASEPROPERTY_VSCROLL: + case BASEPROPERTY_NUMSHOWTHOUSANDSEP: + case BASEPROPERTY_STRICTFORMAT: + case BASEPROPERTY_REPEAT: + case BASEPROPERTY_PAINTTRANSPARENT: + case BASEPROPERTY_DESKTOP_AS_PARENT: + case BASEPROPERTY_HARDLINEBREAKS: + case BASEPROPERTY_NOLABEL: aDefault <<= (sal_Bool) sal_False; break; + + case BASEPROPERTY_HIDEINACTIVESELECTION: + case BASEPROPERTY_ENFORCE_FORMAT: + case BASEPROPERTY_AUTOCOMPLETE: + case BASEPROPERTY_SCALEIMAGE: + case BASEPROPERTY_ENABLED: + case BASEPROPERTY_PRINTABLE: + case BASEPROPERTY_ENABLEVISIBLE: + case BASEPROPERTY_DECORATION: aDefault <<= (sal_Bool) sal_True; break; + + case BASEPROPERTY_HELPTEXT: + case BASEPROPERTY_HELPURL: + case BASEPROPERTY_IMAGEURL: + case BASEPROPERTY_DIALOGSOURCEURL: + case BASEPROPERTY_EDITMASK: + case BASEPROPERTY_LITERALMASK: + case BASEPROPERTY_LABEL: + case BASEPROPERTY_TITLE: + case BASEPROPERTY_TEXT: aDefault <<= ::rtl::OUString(); break; + + case BASEPROPERTY_WRITING_MODE: + case BASEPROPERTY_CONTEXT_WRITING_MODE: + aDefault <<= text::WritingMode2::CONTEXT; + break; + + case BASEPROPERTY_STRINGITEMLIST: + { + ::com::sun::star::uno::Sequence< ::rtl::OUString> aStringSeq; + aDefault <<= aStringSeq; + + } + break; + case BASEPROPERTY_SELECTEDITEMS: + { + ::com::sun::star::uno::Sequence<sal_Int16> aINT16Seq; + aDefault <<= aINT16Seq; + } + break; + case BASEPROPERTY_CURRENCYSYMBOL: + { + Any aDefaultCurrency = ::utl::ConfigManager::GetDirectConfigProperty(::utl::ConfigManager::DEFAULTCURRENCY); + DBG_ASSERT( TypeClass_STRING == aDefaultCurrency.getValueTypeClass(), "UnoControlModel::ImplGetDefaultValue: invalid currency config value!" ); + + ::rtl::OUString sDefaultCurrency; + aDefaultCurrency >>= sDefaultCurrency; + + // extract the bank symbol + sal_Int32 nSepPos = sDefaultCurrency.indexOf( '-' ); + ::rtl::OUString sBankSymbol; + if ( nSepPos >= 0 ) + { + sBankSymbol = sDefaultCurrency.copy( 0, nSepPos ); + sDefaultCurrency = sDefaultCurrency.copy( nSepPos + 1 ); + } + + // the remaming is the locale + Locale aLocale; + nSepPos = sDefaultCurrency.indexOf( '-' ); + if ( nSepPos >= 0 ) + { + aLocale.Language = sDefaultCurrency.copy( 0, nSepPos ); + aLocale.Country = sDefaultCurrency.copy( nSepPos + 1 ); + } + + LocaleDataWrapper aLocaleInfo( ::comphelper::getProcessServiceFactory(), aLocale ); + if ( !sBankSymbol.getLength() ) + sBankSymbol = aLocaleInfo.getCurrBankSymbol(); + + // look for the currency entry (for this language) which has the given bank symbol + Sequence< Currency2 > aAllCurrencies = aLocaleInfo.getAllCurrencies(); + const Currency2* pAllCurrencies = aAllCurrencies.getConstArray(); + const Currency2* pAllCurrenciesEnd = pAllCurrencies + aAllCurrencies.getLength(); + + ::rtl::OUString sCurrencySymbol = aLocaleInfo.getCurrSymbol(); + if ( !sBankSymbol.getLength() ) + { + DBG_ASSERT( pAllCurrencies != pAllCurrenciesEnd, "UnoControlModel::ImplGetDefaultValue: no currencies at all!" ); + if ( pAllCurrencies != pAllCurrenciesEnd ) + { + sBankSymbol = pAllCurrencies->BankSymbol; + sCurrencySymbol = pAllCurrencies->Symbol; + } + } + + if ( sBankSymbol.getLength() ) + { + bool bLegacy = false; + for ( ;pAllCurrencies != pAllCurrenciesEnd; ++pAllCurrencies ) + if ( pAllCurrencies->BankSymbol == sBankSymbol ) + { + sCurrencySymbol = pAllCurrencies->Symbol; + if ( pAllCurrencies->LegacyOnly ) + bLegacy = true; + else + break; + } + DBG_ASSERT( bLegacy || pAllCurrencies != pAllCurrenciesEnd, "UnoControlModel::ImplGetDefaultValue: did not find the given bank symbol!" ); + } + + aDefault <<= sCurrencySymbol; + } + break; + + default: DBG_ERROR( "ImplGetDefaultValue - unknown Property" ); + } + } + + return aDefault; +} + +void UnoControlModel::ImplRegisterProperty( sal_uInt16 nPropId, const ::com::sun::star::uno::Any& rDefault ) +{ + ImplControlProperty* pProp = new ImplControlProperty( nPropId, rDefault ); + mpData->Insert( nPropId, pProp ); +} + +void UnoControlModel::ImplRegisterProperty( sal_uInt16 nPropId ) +{ + ImplRegisterProperty( nPropId, ImplGetDefaultValue( nPropId ) ); + + if ( nPropId == BASEPROPERTY_FONTDESCRIPTOR ) + { + // some properties are not included in the FontDescriptor, but everytime + // when we have a FontDescriptor we want to have these properties too. + // => Easier to register the here, istead everywhere where I register the FontDescriptor... + + ImplRegisterProperty( BASEPROPERTY_TEXTCOLOR ); + ImplRegisterProperty( BASEPROPERTY_TEXTLINECOLOR ); + ImplRegisterProperty( BASEPROPERTY_FONTRELIEF ); + ImplRegisterProperty( BASEPROPERTY_FONTEMPHASISMARK ); + } +} + +void UnoControlModel::ImplRegisterProperties( const std::list< sal_uInt16 > &rIds ) +{ + std::list< sal_uInt16 >::const_iterator iter; + for( iter = rIds.begin(); iter != rIds.end(); iter++) { + if( !ImplHasProperty( *iter ) ) + ImplRegisterProperty( *iter, ImplGetDefaultValue( *iter ) ); + } +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any UnoControlModel::queryAggregation( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::awt::XControlModel*, this ), + SAL_STATIC_CAST( ::com::sun::star::io::XPersistObject*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XComponent*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XServiceInfo*, this ), + SAL_STATIC_CAST( ::com::sun::star::util::XCloneable*, this ), + SAL_STATIC_CAST( ::com::sun::star::beans::XPropertyState*, this ), + SAL_STATIC_CAST( ::com::sun::star::beans::XMultiPropertySet*, this ), + SAL_STATIC_CAST( ::com::sun::star::beans::XFastPropertySet*, this ), + SAL_STATIC_CAST( ::com::sun::star::beans::XPropertySet*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ), + SAL_STATIC_CAST( ::com::sun::star::lang::XUnoTunnel*, this ) ); + return (aRet.hasValue() ? aRet : OWeakAggObject::queryAggregation( rType )); +} + +// ::com::sun::star::lang::XUnoTunnel +IMPL_XUNOTUNNEL( UnoControlModel ) + +// ::com::sun::star::lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( UnoControlModel ) + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::io::XPersistObject>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XServiceInfo>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet>* ) NULL ), + getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>* ) NULL ) +IMPL_XTYPEPROVIDER_END + + +uno::Reference< util::XCloneable > UnoControlModel::createClone() throw(::com::sun::star::uno::RuntimeException) +{ + UnoControlModel* pClone = Clone(); + uno::Reference< util::XCloneable > xClone( (::cppu::OWeakObject*) pClone, uno::UNO_QUERY ); + return xClone; +} + +// ::com::sun::star::lang::XComponent +void UnoControlModel::dispose( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::lang::EventObject aEvt; + aEvt.Source = (::com::sun::star::uno::XAggregation*)(::cppu::OWeakAggObject*)this; + maDisposeListeners.disposeAndClear( aEvt ); + + // let the property set helper notify our property listeners + OPropertySetHelper::disposing(); +} + +void UnoControlModel::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maDisposeListeners.addInterface( rxListener ); +} + +void UnoControlModel::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + maDisposeListeners.removeInterface( rxListener ); +} + + +// ::com::sun::star::beans::XPropertyState +::com::sun::star::beans::PropertyState UnoControlModel::getPropertyState( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + sal_uInt16 nPropId = GetPropertyId( PropertyName ); + + ::com::sun::star::uno::Any aValue = getPropertyValue( PropertyName ); + ::com::sun::star::uno::Any aDefault = ImplGetDefaultValue( nPropId ); + + return CompareProperties( aValue, aDefault ) ? ::com::sun::star::beans::PropertyState_DEFAULT_VALUE : ::com::sun::star::beans::PropertyState_DIRECT_VALUE; +} + +::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState > UnoControlModel::getPropertyStates( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& PropertyNames ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + sal_uInt32 nNames = PropertyNames.getLength(); + const ::rtl::OUString* pNames = PropertyNames.getConstArray(); + + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState > aStates( nNames ); + ::com::sun::star::beans::PropertyState* pStates = aStates.getArray(); + + for ( sal_uInt32 n = 0; n < nNames; n++ ) + pStates[n] = getPropertyState( pNames[n] ); + + return aStates; +} + +void UnoControlModel::setPropertyToDefault( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException) +{ + Any aDefaultValue; + { + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + aDefaultValue = ImplGetDefaultValue( GetPropertyId( PropertyName ) ); + } + setPropertyValue( PropertyName, aDefaultValue ); +} + +::com::sun::star::uno::Any UnoControlModel::getPropertyDefault( const ::rtl::OUString& rPropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + return ImplGetDefaultValue( GetPropertyId( rPropertyName ) ); +} + + +// ::com::sun::star::io::XPersistObjec +::rtl::OUString UnoControlModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + DBG_ERROR( "ServiceName von UnoControlModel ?!" ); + return ::rtl::OUString(); +} + +void UnoControlModel::write( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream >& OutStream ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::uno::Reference< ::com::sun::star::io::XMarkableStream > xMark( OutStream, ::com::sun::star::uno::UNO_QUERY ); + DBG_ASSERT( xMark.is(), "write: no ::com::sun::star::io::XMarkableStream!" ); + + OutStream->writeShort( UNOCONTROL_STREAMVERSION ); + + ImplPropertyTable aProps; + sal_uInt32 i; + for ( i = mpData->Count(); i; ) + { + ImplControlProperty* pProp = mpData->GetObject( --i ); + if ( ( ( GetPropertyAttribs( pProp->GetId() ) & ::com::sun::star::beans::PropertyAttribute::TRANSIENT ) == 0 ) + && ( getPropertyState( GetPropertyName( pProp->GetId() ) ) != ::com::sun::star::beans::PropertyState_DEFAULT_VALUE ) ) + { + aProps.Insert( pProp->GetId(), pProp ); + } + } + + sal_uInt32 nProps = aProps.Count(); + + // FontProperty wegen fehlender Unterscheidung zwischen 5.0 / 5.1 + // immer im alten Format mitspeichern. + OutStream->writeLong( (long) aProps.IsKeyValid( BASEPROPERTY_FONTDESCRIPTOR ) ? ( nProps + 3 ) : nProps ); + for ( i = 0; i < nProps; i++ ) + { + sal_Int32 nPropDataBeginMark = xMark->createMark(); + OutStream->writeLong( 0L ); // DataLen + + ImplControlProperty* pProp = aProps.GetObject( i ); + OutStream->writeShort( pProp->GetId() ); + + sal_Bool bVoid = pProp->GetValue().getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID; + + OutStream->writeBoolean( bVoid ); + + if ( !bVoid ) + { + const ::com::sun::star::uno::Any& rValue = pProp->GetValue(); + const ::com::sun::star::uno::Type& rType = rValue.getValueType(); + + if ( rType == ::getBooleanCppuType() ) + { + sal_Bool b = false; + rValue >>= b; + OutStream->writeBoolean( b ); + } + else if ( rType == ::getCppuType((const ::rtl::OUString*)0) ) + { + ::rtl::OUString aUString; + rValue >>= aUString; + OutStream->writeUTF( aUString ); + } + else if ( rType == ::getCppuType((const sal_uInt16*)0) ) + { + sal_uInt16 n = 0; + rValue >>= n; + OutStream->writeShort( n ); + } + else if ( rType == ::getCppuType((const sal_Int16*)0) ) + { + sal_Int16 n = 0; + rValue >>= n; + OutStream->writeShort( n ); + } + else if ( rType == ::getCppuType((const sal_uInt32*)0) ) + { + sal_uInt32 n = 0; + rValue >>= n; + OutStream->writeLong( n ); + } + else if ( rType == ::getCppuType((const sal_Int32*)0) ) + { + sal_Int32 n = 0; + rValue >>= n; + OutStream->writeLong( n ); + } + else if ( rType == ::getCppuType((const double*)0) ) + { + double n = 0; + rValue >>= n; + OutStream->writeDouble( n ); + } + else if ( rType == ::getCppuType((const ::com::sun::star::awt::FontDescriptor*)0) ) + { + ::com::sun::star::awt::FontDescriptor aFD; + rValue >>= aFD; + OutStream->writeUTF( aFD.Name ); + OutStream->writeShort( aFD.Height ); + OutStream->writeShort( aFD.Width ); + OutStream->writeUTF( aFD.StyleName ); + OutStream->writeShort( aFD.Family ); + OutStream->writeShort( aFD.CharSet ); + OutStream->writeShort( aFD.Pitch ); + OutStream->writeDouble( aFD.CharacterWidth ); + OutStream->writeDouble( aFD.Weight ); + OutStream->writeShort( + sal::static_int_cast< sal_Int16 >(aFD.Slant) ); + OutStream->writeShort( aFD.Underline ); + OutStream->writeShort( aFD.Strikeout ); + OutStream->writeDouble( aFD.Orientation ); + OutStream->writeBoolean( aFD.Kerning ); + OutStream->writeBoolean( aFD.WordLineMode ); + OutStream->writeShort( aFD.Type ); + } + else if ( rType == ::getCppuType((const ::com::sun::star::uno::Sequence< ::rtl::OUString>*)0 ) ) + { + ::com::sun::star::uno::Sequence< ::rtl::OUString> aSeq; + rValue >>= aSeq; + long nEntries = aSeq.getLength(); + OutStream->writeLong( nEntries ); + for ( long n = 0; n < nEntries; n++ ) + OutStream->writeUTF( aSeq.getConstArray()[n] ); + } + else if ( rType == ::getCppuType((const ::com::sun::star::uno::Sequence<sal_uInt16>*)0 ) ) + { + ::com::sun::star::uno::Sequence<sal_uInt16> aSeq; + rValue >>= aSeq; + long nEntries = aSeq.getLength(); + OutStream->writeLong( nEntries ); + for ( long n = 0; n < nEntries; n++ ) + OutStream->writeShort( aSeq.getConstArray()[n] ); + } + else if ( rType == ::getCppuType((const ::com::sun::star::uno::Sequence<sal_Int16>*)0 ) ) + { + ::com::sun::star::uno::Sequence<sal_Int16> aSeq; + rValue >>= aSeq; + long nEntries = aSeq.getLength(); + OutStream->writeLong( nEntries ); + for ( long n = 0; n < nEntries; n++ ) + OutStream->writeShort( aSeq.getConstArray()[n] ); + } + else if ( rType.getTypeClass() == TypeClass_ENUM ) + { + sal_Int32 nAsInt = 0; + ::cppu::enum2int( nAsInt, rValue ); + OutStream->writeLong( nAsInt ); + } +#if OSL_DEBUG_LEVEL > 0 + else + { + ::rtl::OString sMessage( "UnoControlModel::write: don't know how to handle a property of type '" ); + ::rtl::OUString sTypeName( rType.getTypeName() ); + sMessage += ::rtl::OString( sTypeName.getStr(), sTypeName.getLength(), RTL_TEXTENCODING_ASCII_US ); + sMessage += "'.\n(Currently handling property '"; + ::rtl::OUString sPropertyName( GetPropertyName( pProp->GetId() ) ); + sMessage += ::rtl::OString( sPropertyName.getStr(), sPropertyName.getLength(), osl_getThreadTextEncoding() ); + sMessage += "'.)"; + DBG_ERROR( sMessage ); + } +#endif + } + + sal_Int32 nPropDataLen = xMark->offsetToMark( nPropDataBeginMark ); + xMark->jumpToMark( nPropDataBeginMark ); + OutStream->writeLong( nPropDataLen ); + xMark->jumpToFurthest(); + xMark->deleteMark(nPropDataBeginMark); + } + + ImplControlProperty* pProp = aProps.Get( BASEPROPERTY_FONTDESCRIPTOR ); + if ( pProp ) + { + // Solange wir keinen 5.0-Export haben, muss das alte + // Format mit rausgeschrieben werden... + ::com::sun::star::awt::FontDescriptor aFD; + pProp->GetValue() >>= aFD; + + for ( sal_uInt16 n = BASEPROPERTY_FONT_TYPE; n <= BASEPROPERTY_FONT_ATTRIBS; n++ ) + { + sal_Int32 nPropDataBeginMark = xMark->createMark(); + OutStream->writeLong( 0L ); // DataLen + OutStream->writeShort( n ); // PropId + OutStream->writeBoolean( sal_False ); // Void + + if ( n == BASEPROPERTY_FONT_TYPE ) + { + OutStream->writeUTF( aFD.Name ); + OutStream->writeUTF( aFD.StyleName ); + OutStream->writeShort( aFD.Family ); + OutStream->writeShort( aFD.CharSet ); + OutStream->writeShort( aFD.Pitch ); + } + else if ( n == BASEPROPERTY_FONT_SIZE ) + { + OutStream->writeLong( aFD.Width ); + OutStream->writeLong( aFD.Height ); + OutStream->writeShort( + sal::static_int_cast< sal_Int16 >( + VCLUnoHelper::ConvertFontWidth( aFD.CharacterWidth )) ); + } + else if ( n == BASEPROPERTY_FONT_ATTRIBS ) + { + OutStream->writeShort( + sal::static_int_cast< sal_Int16 >( + VCLUnoHelper::ConvertFontWeight( aFD.Weight )) ); + OutStream->writeShort( + sal::static_int_cast< sal_Int16 >(aFD.Slant) ); + OutStream->writeShort( aFD.Underline ); + OutStream->writeShort( aFD.Strikeout ); + OutStream->writeShort( (short)(aFD.Orientation * 10) ); + OutStream->writeBoolean( aFD.Kerning ); + OutStream->writeBoolean( aFD.WordLineMode ); + } + else + { + DBG_ERROR( "Property?!" ); + } + + sal_Int32 nPropDataLen = xMark->offsetToMark( nPropDataBeginMark ); + xMark->jumpToMark( nPropDataBeginMark ); + OutStream->writeLong( nPropDataLen ); + xMark->jumpToFurthest(); + xMark->deleteMark(nPropDataBeginMark); + } + } +} + +void UnoControlModel::read( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream >& InStream ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::uno::Reference< ::com::sun::star::io::XMarkableStream > xMark( InStream, ::com::sun::star::uno::UNO_QUERY ); + DBG_ASSERT( xMark.is(), "read: no ::com::sun::star::io::XMarkableStream!" ); + + short nVersion = InStream->readShort(); + sal_uInt32 nProps = (sal_uInt32)InStream->readLong(); + ::com::sun::star::uno::Sequence< ::rtl::OUString> aProps( nProps ); + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any> aValues( nProps ); + sal_Bool bInvalidEntries = sal_False; + + // Dummerweise kein Mark fuer den gesamten Block, es koennen also + // nur Properties geaendert werden, es koennen aber nicht spaeter mal Daten + // fuer das Model hinter den Properties geschrieben werden. + + // Fuer den Import der alten ::com::sun::star::awt::FontDescriptor-Teile + ::com::sun::star::awt::FontDescriptor* pFD = NULL; + + sal_uInt32 i; + for ( i = 0; i < nProps; i++ ) + { + sal_Int32 nPropDataBeginMark = xMark->createMark(); + sal_Int32 nPropDataLen = InStream->readLong(); + + sal_uInt16 nPropId = (sal_uInt16)InStream->readShort(); + + ::com::sun::star::uno::Any aValue; + sal_Bool bIsVoid = InStream->readBoolean(); + if ( !bIsVoid ) + { + const ::com::sun::star::uno::Type* pType = mpData->Get( nPropId ) ? GetPropertyType( nPropId ) : NULL; + if ( pType ) + { + if ( *pType == ::getBooleanCppuType() ) + { + sal_Bool b = InStream->readBoolean(); + aValue <<= b; + } + else if ( *pType == ::getCppuType((const ::rtl::OUString*)0) ) + { + ::rtl::OUString aUTF = InStream->readUTF(); + aValue <<= aUTF; + } + else if ( *pType == ::getCppuType((const sal_uInt16*)0) ) + { + sal_uInt16 n = InStream->readShort(); + aValue <<= n; + } + else if ( *pType == ::getCppuType((const sal_Int16*)0) ) + { + sal_Int16 n = InStream->readShort(); + aValue <<= n; + } + else if ( *pType == ::getCppuType((const sal_uInt32*)0) ) + { + sal_uInt32 n = InStream->readLong(); + aValue <<= n; + } + else if ( *pType == ::getCppuType((const sal_Int32*)0) ) + { + sal_Int32 n = InStream->readLong(); + aValue <<= n; + } + else if ( *pType == ::getCppuType((const double*)0) ) + { + double n = InStream->readDouble(); + aValue <<= n; + } + else if ( *pType == ::getCppuType((const ::com::sun::star::awt::FontDescriptor*)0) ) + { + ::com::sun::star::awt::FontDescriptor aFD; + aFD.Name = InStream->readUTF(); + aFD.Height = InStream->readShort(); + aFD.Width = InStream->readShort(); + aFD.StyleName = InStream->readUTF(); + aFD.Family = InStream->readShort(); + aFD.CharSet = InStream->readShort(); + aFD.Pitch = InStream->readShort(); + aFD.CharacterWidth = (float)InStream->readDouble(); + aFD.Weight = (float)InStream->readDouble(); + aFD.Slant = (::com::sun::star::awt::FontSlant)InStream->readShort(); + aFD.Underline = InStream->readShort(); + aFD.Strikeout = InStream->readShort(); + aFD.Orientation = (float)InStream->readDouble(); + aFD.Kerning = InStream->readBoolean(); + aFD.WordLineMode = InStream->readBoolean(); + aFD.Type = InStream->readShort(); + aValue <<= aFD; + } + else if ( *pType == ::getCppuType((const ::com::sun::star::uno::Sequence< ::rtl::OUString>*)0 ) ) + { + long nEntries = InStream->readLong(); + ::com::sun::star::uno::Sequence< ::rtl::OUString> aSeq( nEntries ); + for ( long n = 0; n < nEntries; n++ ) + aSeq.getArray()[n] = InStream->readUTF(); + aValue <<= aSeq; + + } + else if ( *pType == ::getCppuType((const ::com::sun::star::uno::Sequence<sal_uInt16>*)0 ) ) + + { + long nEntries = InStream->readLong(); + ::com::sun::star::uno::Sequence<sal_uInt16> aSeq( nEntries ); + for ( long n = 0; n < nEntries; n++ ) + aSeq.getArray()[n] = (sal_uInt16)InStream->readShort(); + aValue <<= aSeq; + } + else if ( *pType == ::getCppuType((const ::com::sun::star::uno::Sequence<sal_Int16>*)0 ) ) + { + long nEntries = InStream->readLong(); + ::com::sun::star::uno::Sequence<sal_Int16> aSeq( nEntries ); + for ( long n = 0; n < nEntries; n++ ) + aSeq.getArray()[n] = (sal_Int16)InStream->readShort(); + aValue <<= aSeq; + } + else if ( pType->getTypeClass() == TypeClass_ENUM ) + { + sal_Int32 nAsInt = InStream->readLong(); + aValue = ::cppu::int2enum( nAsInt, *pType ); + } + else + { + ::rtl::OString sMessage( "UnoControlModel::read: don't know how to handle a property of type '" ); + ::rtl::OUString sTypeName( pType->getTypeName() ); + sMessage += ::rtl::OString( sTypeName.getStr(), sTypeName.getLength(), RTL_TEXTENCODING_ASCII_US ); + sMessage += "'.\n(Currently handling property '"; + ::rtl::OUString sPropertyName( GetPropertyName( nPropId ) ); + sMessage += ::rtl::OString( sPropertyName.getStr(), sPropertyName.getLength(), osl_getThreadTextEncoding() ); + sMessage += "'.)"; + DBG_ERROR( sMessage ); + } + } + else + { + // Altes Geraffel aus 5.0 + if ( nPropId == BASEPROPERTY_FONT_TYPE ) + { + // Sonst ist es nur die redundante Info fuer alte Versionen + // Daten werden durch MarkableStream geskippt. + if ( nVersion < 2 ) + { + if ( !pFD ) + { + pFD = new ::com::sun::star::awt::FontDescriptor; + ImplControlProperty* pProp = mpData->Get( BASEPROPERTY_FONTDESCRIPTOR ); + if ( pProp ) // wegen den Defaults... + pProp->GetValue() >>= *pFD; + } + pFD->Name = InStream->readUTF(); + pFD->StyleName = InStream->readUTF(); + pFD->Family = InStream->readShort(); + pFD->CharSet = InStream->readShort(); + pFD->Pitch = InStream->readShort(); + } + } + else if ( nPropId == BASEPROPERTY_FONT_SIZE ) + { + if ( nVersion < 2 ) + { + if ( !pFD ) + { + pFD = new ::com::sun::star::awt::FontDescriptor; + ImplControlProperty* pProp = mpData->Get( BASEPROPERTY_FONTDESCRIPTOR ); + if ( pProp ) // wegen den Defaults... + pProp->GetValue() >>= *pFD; + } + pFD->Width = (sal_Int16)InStream->readLong(); + pFD->Height = (sal_Int16)InStream->readLong(); + InStream->readShort(); // ::com::sun::star::awt::FontWidth ignorieren - wurde mal falsch geschrieben und wird nicht gebraucht. + pFD->CharacterWidth = ::com::sun::star::awt::FontWidth::DONTKNOW; + } + } + else if ( nPropId == BASEPROPERTY_FONT_ATTRIBS ) + { + if ( nVersion < 2 ) + { + if ( !pFD ) + { + pFD = new ::com::sun::star::awt::FontDescriptor; + ImplControlProperty* pProp = mpData->Get( BASEPROPERTY_FONTDESCRIPTOR ); + if ( pProp ) // wegen den Defaults... + pProp->GetValue() >>= *pFD; + } + pFD->Weight = VCLUnoHelper::ConvertFontWeight( (FontWeight) InStream->readShort() ); + pFD->Slant = (::com::sun::star::awt::FontSlant)InStream->readShort(); + pFD->Underline = InStream->readShort(); + pFD->Strikeout = InStream->readShort(); + pFD->Orientation = ( (float)(double)InStream->readShort() ) / 10; + pFD->Kerning = InStream->readBoolean(); + pFD->WordLineMode = InStream->readBoolean(); + } + } + else + { + DBG_ERROR( "read: unknown Property!" ); + } + } + } + else // bVoid + { + if ( nPropId == BASEPROPERTY_FONTDESCRIPTOR ) + { + EmptyFontDescriptor aFD; + aValue <<= aFD; + } + } + + if ( mpData->Get( nPropId ) ) + { + aProps.getArray()[i] = GetPropertyName( nPropId ); + aValues.getArray()[i] = aValue; + } + else + { + bInvalidEntries = sal_True; + } + + // Falls bereits mehr drinsteht als diese Version kennt: + xMark->jumpToMark( nPropDataBeginMark ); + InStream->skipBytes( nPropDataLen ); + xMark->deleteMark(nPropDataBeginMark); + } + if ( bInvalidEntries ) + { + for ( i = 0; i < (sal_uInt32)aProps.getLength(); i++ ) + { + if ( !aProps.getConstArray()[i].getLength() ) + { + ::comphelper::removeElementAt( aProps, i ); + ::comphelper::removeElementAt( aValues, i ); + i--; + } + } + } + + try + { + setPropertyValues( aProps, aValues ); + } + catch ( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + + if ( pFD ) + { + ::com::sun::star::uno::Any aValue; + aValue <<= *pFD; + setPropertyValue( GetPropertyName( BASEPROPERTY_FONTDESCRIPTOR ), aValue ); + delete pFD; + } +} + + +// ::com::sun::star::lang::XServiceInfo +::rtl::OUString UnoControlModel::getImplementationName( ) throw(::com::sun::star::uno::RuntimeException) +{ + DBG_ERROR( "This method should be overloaded!" ); + return ::rtl::OUString(); + +} + +sal_Bool UnoControlModel::supportsService( const ::rtl::OUString& rServiceName ) throw(::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + ::com::sun::star::uno::Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames(); + const ::rtl::OUString * pArray = aSNL.getConstArray(); + for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) + if( pArray[i] == rServiceName ) + return sal_True; + return sal_False; +} + +::com::sun::star::uno::Sequence< ::rtl::OUString > UnoControlModel::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlModel" ) ); + return Sequence< ::rtl::OUString >( &sName, 1 ); +} + +// ::cppu::OPropertySetHelper +::cppu::IPropertyArrayHelper& UnoControlModel::getInfoHelper() +{ + DBG_ERROR( "UnoControlModel::getInfoHelper() not possible!" ); + return *(::cppu::IPropertyArrayHelper*) NULL; +} + +// ------------------------------------------------------------------ +template <class TYPE> +sal_Bool convertType(Any& _rConvertedValue, const Any& _rNewValueTest, const TYPE* /* _pTypeDisambiguation */) +{ + TYPE tValue; + if (_rNewValueTest >>= tValue) + { + _rConvertedValue <<= tValue; + return sal_True; + } +} + +// .................................................................. +sal_Bool UnoControlModel::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nPropId, const Any& rValue ) throw (IllegalArgumentException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + sal_Bool bVoid = rValue.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID; + if ( bVoid ) + { + rConvertedValue.clear(); + } + else + { + const ::com::sun::star::uno::Type* pDestType = GetPropertyType( (sal_uInt16)nPropId ); + if ( pDestType->getTypeClass() == TypeClass_ANY ) + { + rConvertedValue = rValue; + } + else + { + if ( pDestType->equals( rValue.getValueType() ) ) + { + rConvertedValue = rValue; + } + else + { + BOOL bConverted = FALSE; + // 13.03.2001 - 84923 - frank.schoenheit@germany.sun.com + + switch (pDestType->getTypeClass()) + { + case TypeClass_DOUBLE: + { + // try as double + double nAsDouble = 0; + bConverted = ( rValue >>= nAsDouble ); + if ( bConverted ) + rConvertedValue <<= nAsDouble; + else + { // try as integer - 96136 - 2002-10-08 - fs@openoffice.org + sal_Int32 nAsInteger = 0; + bConverted = ( rValue >>= nAsInteger ); + if ( bConverted ) + rConvertedValue <<= (double)nAsInteger; + } + } + break; + case TypeClass_SHORT: + { + sal_Int16 n; + bConverted = ( rValue >>= n ); + if ( bConverted ) + rConvertedValue <<= n; + } + break; + case TypeClass_UNSIGNED_SHORT: + { + sal_uInt16 n; + bConverted = ( rValue >>= n ); + if ( bConverted ) + rConvertedValue <<= n; + } + break; + case TypeClass_LONG: + { + sal_Int32 n; + bConverted = ( rValue >>= n ); + if ( bConverted ) + rConvertedValue <<= n; + } + break; + case TypeClass_UNSIGNED_LONG: + { + sal_uInt32 n; + bConverted = ( rValue >>= n ); + if ( bConverted ) + rConvertedValue <<= n; + } + break; + case TypeClass_INTERFACE: + { + if ( rValue.getValueType().getTypeClass() == TypeClass_INTERFACE ) + { + Reference< XInterface > xPure( rValue, UNO_QUERY ); + if ( xPure.is() ) + rConvertedValue = xPure->queryInterface( *pDestType ); + else + rConvertedValue.setValue( NULL, *pDestType ); + bConverted = sal_True; + } + } + break; + case TypeClass_ENUM: + { + sal_Int32 nValue = 0; + bConverted = ( rValue >>= nValue ); + if ( bConverted ) + rConvertedValue = ::cppu::int2enum( nValue, *pDestType ); + } + break; + default: ; // avoid compiler warning + } + + if (!bConverted) + { + ::rtl::OUStringBuffer aErrorMessage; + aErrorMessage.appendAscii( "Unable to convert the given value for the property " ); + aErrorMessage.append ( GetPropertyName( (sal_uInt16)nPropId ) ); + aErrorMessage.appendAscii( ".\n" ); + aErrorMessage.appendAscii( "Expected type: " ); + aErrorMessage.append ( pDestType->getTypeName() ); + aErrorMessage.appendAscii( "\n" ); + aErrorMessage.appendAscii( "Found type: " ); + aErrorMessage.append ( rValue.getValueType().getTypeName() ); + throw ::com::sun::star::lang::IllegalArgumentException( + aErrorMessage.makeStringAndClear(), + static_cast< ::com::sun::star::beans::XPropertySet* >(this), + 1); + } + } + } + } + + // the current value + getFastPropertyValue( rOldValue, nPropId ); + return !CompareProperties( rConvertedValue, rOldValue ); +} + +void UnoControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 nPropId, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::uno::Exception) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + // Fehlt: Die gefakten Einzelproperties des FontDescriptors... + + ImplControlProperty* pProp = mpData->Get( nPropId ); + if ( pProp ) + { + DBG_ASSERT( ( rValue.getValueType().getTypeClass() != ::com::sun::star::uno::TypeClass_VOID ) || ( GetPropertyAttribs( (sal_uInt16)nPropId ) & ::com::sun::star::beans::PropertyAttribute::MAYBEVOID ), "Property darf nicht VOID sein!" ); + ImplPropertyChanged( (sal_uInt16)nPropId ); + pProp->SetValue( rValue ); + } + else + { + // exception... + DBG_ERROR( "SetPropertyValues: Invalid Property!" ); + } +} + +void UnoControlModel::getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nPropId ) const +{ + ::osl::Guard< ::osl::Mutex > aGuard( ((UnoControlModel*)this)->GetMutex() ); + + ImplControlProperty* pProp = mpData->Get( nPropId ); + + if ( pProp ) + rValue = pProp->GetValue(); + else if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) ) + { + pProp = mpData->Get( BASEPROPERTY_FONTDESCRIPTOR ); + ::com::sun::star::awt::FontDescriptor aFD; + pProp->GetValue() >>= aFD; + switch ( nPropId ) + { + case BASEPROPERTY_FONTDESCRIPTORPART_NAME: rValue <<= aFD.Name; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME: rValue <<= aFD.StyleName; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY: rValue <<= aFD.Family; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET: rValue <<= aFD.CharSet; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT: rValue <<= (float)aFD.Height; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT: rValue <<= aFD.Weight; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_SLANT: rValue <<= (sal_Int16)aFD.Slant; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE: rValue <<= aFD.Underline; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT: rValue <<= aFD.Strikeout; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH: rValue <<= aFD.Width; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_PITCH: rValue <<= aFD.Pitch; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH: rValue <<= aFD.CharacterWidth; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION: rValue <<= aFD.Orientation; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_KERNING: rValue <<= aFD.Kerning; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE: rValue <<= aFD.WordLineMode; + break; + case BASEPROPERTY_FONTDESCRIPTORPART_TYPE: rValue <<= aFD.Type; + break; + default: DBG_ERROR( "FontProperty?!" ); + } + } + else + { + DBG_ERROR( "getFastPropertyValue - invalid Property!" ); + } +} + +// ::com::sun::star::beans::XPropertySet +void UnoControlModel::setPropertyValue( const ::rtl::OUString& rPropertyName, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) +{ + sal_Int32 nPropId = 0; + { + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + nPropId = (sal_Int32) GetPropertyId( rPropertyName ); + DBG_ASSERT( nPropId, "Invalid ID in UnoControlModel::setPropertyValue" ); + } + if( nPropId ) + setFastPropertyValue( nPropId, rValue ); + else + throw ::com::sun::star::beans::UnknownPropertyException(); +} + +// ::com::sun::star::beans::XFastPropertySet +void UnoControlModel::setFastPropertyValue( sal_Int32 nPropId, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) +{ + if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) ) + { + ::osl::ClearableMutexGuard aGuard( GetMutex() ); + + Any aOldSingleValue; + getFastPropertyValue( aOldSingleValue, BASEPROPERTY_FONTDESCRIPTORPART_START ); + + ImplControlProperty* pProp = mpData->Get( BASEPROPERTY_FONTDESCRIPTOR ); + FontDescriptor aOldFontDescriptor; + pProp->GetValue() >>= aOldFontDescriptor; + + FontDescriptor aNewFontDescriptor( aOldFontDescriptor ); + lcl_ImplMergeFontProperty( aNewFontDescriptor, (sal_uInt16)nPropId, rValue ); + + Any aNewValue; + aNewValue <<= aNewFontDescriptor; + sal_Int32 nDescriptorId( BASEPROPERTY_FONTDESCRIPTOR ); + nDescriptorId = BASEPROPERTY_FONTDESCRIPTOR; + + // also, we need fire a propertyChange event for the single property, since with + // the above line, only an event for the FontDescriptor property will be fired + Any aNewSingleValue; + getFastPropertyValue( aNewSingleValue, BASEPROPERTY_FONTDESCRIPTORPART_START ); + + aGuard.clear(); + setFastPropertyValues( 1, &nDescriptorId, &aNewValue, 1 ); + fire( &nPropId, &aNewSingleValue, &aOldSingleValue, 1, sal_False ); + } + else + setFastPropertyValues( 1, &nPropId, &rValue, 1 ); +} + +// ::com::sun::star::beans::XMultiPropertySet +::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > UnoControlModel::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException) +{ + DBG_ERROR( "UnoControlModel::getPropertySetInfo() not possible!" ); + return ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >(); +} + +void UnoControlModel::setPropertyValues( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rPropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Values ) throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::ClearableMutexGuard aGuard( GetMutex() ); + + sal_Int32 nProps = rPropertyNames.getLength(); + +// sal_Int32* pHandles = new sal_Int32[nProps]; + // don't do this - it leaks in case of an exception + Sequence< sal_Int32 > aHandles( nProps ); + sal_Int32* pHandles = aHandles.getArray(); + + // may need to change the order in the sequence, for this we need a non-const value sequence + // 15.05.2002 - 99314 - fs@openoffice.org + uno::Sequence< uno::Any > aValues( Values ); + uno::Any* pValues = aValues.getArray(); + + sal_Int32 nValidHandles = getInfoHelper().fillHandles( pHandles, rPropertyNames ); + + if ( nValidHandles ) + { + // if somebody sets properties which are single aspects of a font descriptor, + // remove them, and build a font descriptor instead + ::std::auto_ptr< awt::FontDescriptor > pFD; + for ( sal_uInt16 n = 0; n < nProps; ++n ) + { + if ( ( pHandles[n] >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( pHandles[n] <= BASEPROPERTY_FONTDESCRIPTORPART_END ) ) + { + if ( !pFD.get() ) + { + ImplControlProperty* pProp = mpData->Get( BASEPROPERTY_FONTDESCRIPTOR ); + pFD.reset( new awt::FontDescriptor ); + pProp->GetValue() >>= *pFD; + } + lcl_ImplMergeFontProperty( *pFD, (sal_uInt16)pHandles[n], pValues[n] ); + pHandles[n] = -1; + nValidHandles--; + } + } + + if ( nValidHandles ) + { + ImplNormalizePropertySequence( nProps, pHandles, pValues, &nValidHandles ); + aGuard.clear(); + // clear our guard before calling into setFastPropertyValues - this method + // will implicitly call property listeners, and this should not happen with + // our mutex locked + // #i23451# - 2004-03-18 - fs@openoffice.org + setFastPropertyValues( nProps, pHandles, pValues, nValidHandles ); + } + else + aGuard.clear(); + // same as a few lines above + + // FD-Propertie nicht in das Array mergen, weil sortiert... + if ( pFD.get() ) + { + ::com::sun::star::uno::Any aValue; + aValue <<= *pFD; + sal_Int32 nHandle = BASEPROPERTY_FONTDESCRIPTOR; + setFastPropertyValues( 1, &nHandle, &aValue, 1 ); + } + } +} + + + +void UnoControlModel::ImplNormalizePropertySequence( const sal_Int32, sal_Int32*, + uno::Any*, sal_Int32* ) const SAL_THROW(()) +{ + // nothing to do here +} + +void UnoControlModel::ImplEnsureHandleOrder( const sal_Int32 _nCount, sal_Int32* _pHandles, + uno::Any* _pValues, sal_Int32 _nFirstHandle, sal_Int32 _nSecondHandle ) const +{ + for ( sal_Int32 i=0; i < _nCount; ++_pHandles, ++_pValues, ++i ) + { + if ( _nSecondHandle == *_pHandles ) + { + sal_Int32* pLaterHandles = _pHandles + 1; + uno::Any* pLaterValues = _pValues + 1; + for ( sal_Int32 j = i + 1; j < _nCount; ++j, ++pLaterHandles, ++pLaterValues ) + { + if ( _nFirstHandle == *pLaterHandles ) + { + // indeed it is -> exchange the both places in the sequences + sal_Int32 nHandle( *_pHandles ); + *_pHandles = *pLaterHandles; + *pLaterHandles = nHandle; + + uno::Any aValue( *_pValues ); + *_pValues = *pLaterValues; + *pLaterValues = aValue; + + break; + // this will leave the inner loop, and continue with the outer loop. + // Note that this means we will encounter the _nSecondHandle handle, again, once we reached + // (in the outer loop) the place where we just put it. + } + } + } + } +} diff --git a/toolkit/source/controls/unocontrols.cxx b/toolkit/source/controls/unocontrols.cxx new file mode 100644 index 000000000000..ae9e59d045e7 --- /dev/null +++ b/toolkit/source/controls/unocontrols.cxx @@ -0,0 +1,3788 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <com/sun/star/awt/XTextArea.hpp> +#include <com/sun/star/awt/XVclWindowPeer.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/awt/PosSize.hpp> +#include <com/sun/star/awt/VisualEffect.hpp> +#include <com/sun/star/awt/LineEndFormat.hpp> +#include <com/sun/star/graphic/XGraphicProvider.hpp> +#include <com/sun/star/graphic/GraphicObject.hpp> +#include <com/sun/star/util/Date.hpp> +#include <com/sun/star/awt/ImageScaleMode.hpp> + + +#include <toolkit/controls/formattedcontrol.hxx> +#include <toolkit/controls/roadmapcontrol.hxx> +#include <toolkit/controls/unocontrols.hxx> +#include <toolkit/controls/geometrycontrolmodel.hxx> +#include <toolkit/controls/stdtabcontroller.hxx> +#include <toolkit/helper/property.hxx> +#include <toolkit/helper/unopropertyarrayhelper.hxx> +#include <toolkit/helper/unomemorystream.hxx> +#include <toolkit/helper/servicenames.hxx> +#include <toolkit/helper/macros.hxx> +#include <toolkit/helper/imagealign.hxx> + +// for introspection +#include <toolkit/awt/vclxwindows.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <comphelper/componentcontext.hxx> +#include <comphelper/processfactory.hxx> +#include <comphelper/extract.hxx> +#include <vcl/wrkwin.hxx> +#include <vcl/svapp.hxx> +#include <vcl/edit.hxx> +#ifndef _SV_BUTTON_HXX +#include <vcl/button.hxx> +#endif +#include <vcl/group.hxx> +#include <vcl/fixed.hxx> +#include <vcl/lstbox.hxx> +#include <vcl/combobox.hxx> +#include <tools/debug.hxx> +#include <tools/diagnose_ex.h> +#include <tools/date.hxx> +#include <tools/time.hxx> + +#include <algorithm> + +using namespace ::com::sun::star; +using namespace ::toolkit; + + +// ---------------------------------------------------- +// helper +// ---------------------------------------------------- + +static void lcl_knitImageComponents( const uno::Reference< awt::XControlModel >& _rxModel, + const uno::Reference< awt::XWindowPeer >& _rxPeer, + bool _bAdd ) +{ + uno::Reference< awt::XImageProducer > xProducer( _rxModel, uno::UNO_QUERY ); + if ( xProducer.is() ) + { + uno::Reference< awt::XImageConsumer > xConsumer( _rxPeer, uno::UNO_QUERY ); + if ( xConsumer.is() ) + { + if ( _bAdd ) + { + xProducer->addConsumer( xConsumer ); + xProducer->startProduction(); + } + else + xProducer->removeConsumer( xConsumer ); + } + } +} + +// ---------------------------------------------------- +// class UnoControlEditModel +// ---------------------------------------------------- +UnoControlEditModel::UnoControlEditModel() +{ + UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXEdit ); +} + +::rtl::OUString UnoControlEditModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlEditModel ); +} + +uno::Any UnoControlEditModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + uno::Any aReturn; + + switch ( nPropId ) + { + case BASEPROPERTY_LINE_END_FORMAT: + aReturn <<= (sal_Int16)awt::LineEndFormat::LINE_FEED; // LF + break; + case BASEPROPERTY_DEFAULTCONTROL: + aReturn <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlEdit ); + break; + default: + aReturn = UnoControlModel::ImplGetDefaultValue( nPropId ); + break; + } + return aReturn; +} + +::cppu::IPropertyArrayHelper& UnoControlEditModel::getInfoHelper() +{ + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + +// beans::XMultiPropertySet +uno::Reference< beans::XPropertySetInfo > UnoControlEditModel::getPropertySetInfo( ) throw(uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + + +// ---------------------------------------------------- +// class UnoEditControl +// ---------------------------------------------------- +UnoEditControl::UnoEditControl() + :maTextListeners( *this ) + ,mnMaxTextLen( 0 ) + ,mbSetTextInPeer( sal_False ) + ,mbSetMaxTextLenInPeer( sal_False ) + ,mbHasTextProperty( sal_False ) +{ + maComponentInfos.nWidth = 100; + maComponentInfos.nHeight = 12; + mnMaxTextLen = 0; + mbSetMaxTextLenInPeer = FALSE; +} + +uno::Any SAL_CALL UnoEditControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) +{ + uno::Any aReturn = UnoControlBase::queryAggregation( rType ); + if ( !aReturn.hasValue() ) + aReturn = UnoEditControl_Base::queryInterface( rType ); + return aReturn; +} + +uno::Any SAL_CALL UnoEditControl::queryInterface( const uno::Type & rType ) throw(uno::RuntimeException) +{ + return UnoControlBase::queryInterface( rType ); +} + +void SAL_CALL UnoEditControl::acquire( ) throw () +{ + UnoControlBase::acquire(); +} + +void SAL_CALL UnoEditControl::release( ) throw () +{ + UnoControlBase::release(); +} + +IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoEditControl, UnoControlBase, UnoEditControl_Base ) + +::rtl::OUString UnoEditControl::GetComponentServiceName() +{ + // by default, we want a simple edit field + ::rtl::OUString sName( ::rtl::OUString::createFromAscii( "Edit" ) ); + + // but maybe we are to display multi-line text? + uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_MULTILINE ) ); + sal_Bool b = sal_Bool(); + if ( ( aVal >>= b ) && b ) + sName= ::rtl::OUString::createFromAscii( "MultiLineEdit" ); + + return sName; +} + +sal_Bool SAL_CALL UnoEditControl::setModel(const uno::Reference< awt::XControlModel >& _rModel) throw ( uno::RuntimeException ) +{ + sal_Bool bReturn = UnoControlBase::setModel( _rModel ); + mbHasTextProperty = ImplHasProperty( BASEPROPERTY_TEXT ); + return bReturn; +} + +void UnoEditControl::ImplSetPeerProperty( const ::rtl::OUString& rPropName, const uno::Any& rVal ) +{ + sal_Bool bDone = sal_False; + if ( GetPropertyId( rPropName ) == BASEPROPERTY_TEXT ) + { + // #96986# use setText(), or text listener will not be called. + uno::Reference < awt::XTextComponent > xTextComponent( getPeer(), uno::UNO_QUERY ); + if ( xTextComponent.is() ) + { + ::rtl::OUString sText; + rVal >>= sText; + ImplCheckLocalize( sText ); + xTextComponent->setText( sText ); + bDone = sal_True; + } + } + + if ( !bDone ) + UnoControlBase::ImplSetPeerProperty( rPropName, rVal ); +} + +void UnoEditControl::dispose() throw(uno::RuntimeException) +{ + lang::EventObject aEvt( *this ); + maTextListeners.disposeAndClear( aEvt ); + UnoControl::dispose(); +} + +void UnoEditControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) +{ + UnoControl::createPeer( rxToolkit, rParentPeer ); + + uno::Reference< awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY ); + if ( xText.is() ) + { + xText->addTextListener( this ); + + if ( mbSetMaxTextLenInPeer ) + xText->setMaxTextLen( mnMaxTextLen ); + if ( mbSetTextInPeer ) + xText->setText( maText ); + } +} + +void UnoEditControl::textChanged(const awt::TextEvent& e) throw(uno::RuntimeException) +{ + uno::Reference< awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY ); + + if ( mbHasTextProperty ) + { + uno::Any aAny; + aAny <<= xText->getText(); + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TEXT ), aAny, sal_False ); + } + else + { + maText = xText->getText(); + } + + if ( maTextListeners.getLength() ) + maTextListeners.textChanged( e ); +} + +void UnoEditControl::addTextListener(const uno::Reference< awt::XTextListener > & l) throw(uno::RuntimeException) +{ + maTextListeners.addInterface( l ); +} + +void UnoEditControl::removeTextListener(const uno::Reference< awt::XTextListener > & l) throw(uno::RuntimeException) +{ + maTextListeners.removeInterface( l ); +} + +void UnoEditControl::setText( const ::rtl::OUString& aText ) throw(uno::RuntimeException) +{ + if ( mbHasTextProperty ) + { + uno::Any aAny; + aAny <<= aText; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TEXT ), aAny, sal_True ); + } + else + { + maText = aText; + mbSetTextInPeer = sal_True; + uno::Reference < awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY ); + if ( xText.is() ) + xText->setText( maText ); + } + + // Setting the property to the VCLXWindow doesn't call textChanged + if ( maTextListeners.getLength() ) + { + awt::TextEvent aEvent; + aEvent.Source = *this; + maTextListeners.textChanged( aEvent ); + } +} + +namespace +{ + static void lcl_normalize( awt::Selection& _rSel ) + { + if ( _rSel.Min > _rSel.Max ) + ::std::swap( _rSel.Min, _rSel.Max ); + } + +/* + static bool lcl_intersect( const awt::Selection& _rLHS, const awt::Selection& _rRHS ) + { + OSL_PRECOND( _rLHS.Min <= _rLHS.Max, "lcl_intersect: LHS to be normalized!" ); + OSL_PRECOND( _rRHS.Min <= _rRHS.Max, "lcl_intersect: RHS to be normalized!" ); + return !( ( _rLHS.Max < _rRHS.Min ) || ( _rLHS.Min > _rRHS.Max ) ); + } +*/ +} + +void UnoEditControl::insertText( const awt::Selection& rSel, const ::rtl::OUString& rNewText ) throw(uno::RuntimeException) +{ + // normalize the selection - OUString::replaceAt has a strange behaviour if the min is greater than the max + awt::Selection aSelection( rSel ); + lcl_normalize( aSelection ); + + // preserve the selection resp. cursor position + awt::Selection aNewSelection( getSelection() ); +#ifdef ALSO_PRESERVE_COMPLETE_SELECTION + // (not sure - looks uglier ...) + sal_Int32 nDeletedCharacters = ( aSelection.Max - aSelection.Min ) - rNewText.getLength(); + if ( aNewSelection.Min > aSelection.Min ) + aNewSelection.Min -= nDeletedCharacters; + if ( aNewSelection.Max > aSelection.Max ) + aNewSelection.Max -= nDeletedCharacters; +#else + aNewSelection.Max = ::std::min( aNewSelection.Min, aNewSelection.Max ) + rNewText.getLength(); + aNewSelection.Min = aNewSelection.Max; +#endif + + ::rtl::OUString aOldText = getText(); + ::rtl::OUString aNewText = aOldText.replaceAt( aSelection.Min, aSelection.Max - aSelection.Min, rNewText ); + setText( aNewText ); + + setSelection( aNewSelection ); +} + +::rtl::OUString UnoEditControl::getText() throw(uno::RuntimeException) +{ + ::rtl::OUString aText = maText; + + if ( mbHasTextProperty ) + aText = ImplGetPropertyValue_UString( BASEPROPERTY_TEXT ); + else + { + uno::Reference< awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY ); + if ( xText.is() ) + aText = xText->getText(); + } + + return aText; +} + +::rtl::OUString UnoEditControl::getSelectedText( void ) throw(uno::RuntimeException) +{ + ::rtl::OUString sSelected; + uno::Reference< awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY ); + if ( xText.is() ) + sSelected = xText->getSelectedText(); + + return sSelected; +} + +void UnoEditControl::setSelection( const awt::Selection& aSelection ) throw(uno::RuntimeException) +{ + uno::Reference< awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY ); + if ( xText.is() ) + xText->setSelection( aSelection ); +} + +awt::Selection UnoEditControl::getSelection( void ) throw(uno::RuntimeException) +{ + awt::Selection aSel; + uno::Reference< awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY ); + if ( xText.is() ) + aSel = xText->getSelection(); + return aSel; +} + +sal_Bool UnoEditControl::isEditable( void ) throw(uno::RuntimeException) +{ + return !ImplGetPropertyValue_BOOL( BASEPROPERTY_READONLY ); +} + +void UnoEditControl::setEditable( sal_Bool bEditable ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= (sal_Bool)!bEditable; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_READONLY ), aAny, sal_True ); +} + +sal_Int16 UnoEditControl::getMaxTextLen() throw(uno::RuntimeException) +{ + sal_Int16 nMaxLen = mnMaxTextLen; + + if ( ImplHasProperty( BASEPROPERTY_MAXTEXTLEN ) ) + nMaxLen = ImplGetPropertyValue_INT16( BASEPROPERTY_MAXTEXTLEN ); + + return nMaxLen; +} + +void UnoEditControl::setMaxTextLen( sal_Int16 nLen ) throw(uno::RuntimeException) +{ + if ( ImplHasProperty( BASEPROPERTY_MAXTEXTLEN) ) + { + uno::Any aAny; + aAny <<= (sal_Int16)nLen; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_MAXTEXTLEN ), aAny, sal_True ); + } + else + { + mnMaxTextLen = nLen; + mbSetMaxTextLenInPeer = sal_True; + uno::Reference < awt::XTextComponent > xText( getPeer(), uno::UNO_QUERY ); + if ( xText.is() ) + xText->setMaxTextLen( mnMaxTextLen ); + } +} + +awt::Size UnoEditControl::getMinimumSize( ) throw(uno::RuntimeException) +{ + return Impl_getMinimumSize(); +} + +awt::Size UnoEditControl::getPreferredSize( ) throw(uno::RuntimeException) +{ + return Impl_getPreferredSize(); +} + +awt::Size UnoEditControl::calcAdjustedSize( const awt::Size& rNewSize ) throw(uno::RuntimeException) +{ + return Impl_calcAdjustedSize( rNewSize ); +} + +awt::Size UnoEditControl::getMinimumSize( sal_Int16 nCols, sal_Int16 nLines ) throw(uno::RuntimeException) +{ + return Impl_getMinimumSize( nCols, nLines ); +} + +void UnoEditControl::getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines ) throw(uno::RuntimeException) +{ + Impl_getColumnsAndLines( nCols, nLines ); +} + + +// ---------------------------------------------------- +// class UnoControlFileControlModel +// ---------------------------------------------------- +UnoControlFileControlModel::UnoControlFileControlModel() +{ + ImplRegisterProperty( BASEPROPERTY_ALIGN ); + ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR ); + ImplRegisterProperty( BASEPROPERTY_BORDER ); + ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR ); + ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL ); + ImplRegisterProperty( BASEPROPERTY_ENABLED ); + ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE ); + ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR ); + ImplRegisterProperty( BASEPROPERTY_HELPTEXT ); + ImplRegisterProperty( BASEPROPERTY_HELPURL ); + ImplRegisterProperty( BASEPROPERTY_PRINTABLE ); + ImplRegisterProperty( BASEPROPERTY_READONLY ); + ImplRegisterProperty( BASEPROPERTY_TABSTOP ); + ImplRegisterProperty( BASEPROPERTY_TEXT ); + ImplRegisterProperty( BASEPROPERTY_VERTICALALIGN ); + ImplRegisterProperty( BASEPROPERTY_WRITING_MODE ); + ImplRegisterProperty( BASEPROPERTY_CONTEXT_WRITING_MODE ); + ImplRegisterProperty( BASEPROPERTY_HIDEINACTIVESELECTION ); +} + +::rtl::OUString UnoControlFileControlModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlFileControlModel ); +} + +uno::Any UnoControlFileControlModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + if ( nPropId == BASEPROPERTY_DEFAULTCONTROL ) + { + uno::Any aAny; + aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlFileControl ); + return aAny; + } + return UnoControlModel::ImplGetDefaultValue( nPropId ); +} + +::cppu::IPropertyArrayHelper& UnoControlFileControlModel::getInfoHelper() +{ + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + +// beans::XMultiPropertySet +uno::Reference< beans::XPropertySetInfo > UnoControlFileControlModel::getPropertySetInfo( ) throw(uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + +// ---------------------------------------------------- +// class UnoFileControl +// ---------------------------------------------------- +UnoFileControl::UnoFileControl() +{ +} + +::rtl::OUString UnoFileControl::GetComponentServiceName() +{ + return ::rtl::OUString::createFromAscii( "filecontrol" ); +} + +// ---------------------------------------------------- +// class ImageProducerControlModel +// ---------------------------------------------------- +uno::Any SAL_CALL ImageProducerControlModel::queryInterface( const uno::Type & rType ) throw(uno::RuntimeException) +{ + return UnoControlModel::queryInterface( rType ); +} + +uno::Any SAL_CALL ImageProducerControlModel::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) +{ + uno::Any aRet = ::cppu::queryInterface( rType, SAL_STATIC_CAST( awt::XImageProducer*, this ) ); + return (aRet.hasValue() ? aRet : UnoControlModel::queryAggregation( rType )); +} + +void SAL_CALL ImageProducerControlModel::acquire() throw() +{ + UnoControlModel::acquire(); +} + +void SAL_CALL ImageProducerControlModel::release() throw() +{ + UnoControlModel::release(); +} + +uno::Any ImageProducerControlModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + if ( nPropId == BASEPROPERTY_GRAPHIC ) + return uno::makeAny( uno::Reference< graphic::XGraphic >() ); + + return UnoControlModel::ImplGetDefaultValue( nPropId ); +} + uno::Reference< graphic::XGraphic > ImageProducerControlModel::getGraphicFromURL_nothrow( const ::rtl::OUString& _rURL ) + { + uno::Reference< graphic::XGraphic > xGraphic; + + if( ( _rURL.compareToAscii( UNO_NAME_GRAPHOBJ_URLPREFIX, RTL_CONSTASCII_LENGTH( UNO_NAME_GRAPHOBJ_URLPREFIX ) ) == 0 ) ) + { + // graphic manager uniqueid + rtl::OUString sID = _rURL.copy( sizeof( UNO_NAME_GRAPHOBJ_URLPREFIX ) - 1 ); + // get the DefaultContext + ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); + mxGrfObj = graphic::GraphicObject::createWithId( aContext.getUNOContext(), sID ); + } + else // linked + mxGrfObj = NULL; // release the GraphicObject + + if ( !_rURL.getLength() ) + return xGraphic; + + try + { + ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); + uno::Reference< graphic::XGraphicProvider > xProvider; + if ( aContext.createComponent( "com.sun.star.graphic.GraphicProvider", xProvider ) ) + { + uno::Sequence< beans::PropertyValue > aMediaProperties(1); + aMediaProperties[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ); + aMediaProperties[0].Value <<= _rURL; + xGraphic = xProvider->queryGraphic( aMediaProperties ); + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + + return xGraphic; + } + +void SAL_CALL ImageProducerControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::uno::Exception) +{ + UnoControlModel::setFastPropertyValue_NoBroadcast( nHandle, rValue ); + + // - ImageAlign and ImagePosition need to correspond to each other + // - Graphic and ImageURL need to correspond to each other + try + { + switch ( nHandle ) + { + case BASEPROPERTY_IMAGEURL: + if ( !mbAdjustingGraphic && ImplHasProperty( BASEPROPERTY_GRAPHIC ) ) + { + mbAdjustingGraphic = true; + ::rtl::OUString sImageURL; + OSL_VERIFY( rValue >>= sImageURL ); + setPropertyValue( GetPropertyName( BASEPROPERTY_GRAPHIC ), uno::makeAny( getGraphicFromURL_nothrow( sImageURL ) ) ); + mbAdjustingGraphic = false; + } + break; + + case BASEPROPERTY_GRAPHIC: + if ( !mbAdjustingGraphic && ImplHasProperty( BASEPROPERTY_IMAGEURL ) ) + { + mbAdjustingGraphic = true; + setPropertyValue( GetPropertyName( BASEPROPERTY_IMAGEURL ), uno::makeAny( ::rtl::OUString() ) ); + mbAdjustingGraphic = false; + } + break; + + case BASEPROPERTY_IMAGEALIGN: + if ( !mbAdjustingImagePosition && ImplHasProperty( BASEPROPERTY_IMAGEPOSITION ) ) + { + mbAdjustingImagePosition = true; + sal_Int16 nUNOValue = 0; + OSL_VERIFY( rValue >>= nUNOValue ); + setPropertyValue( GetPropertyName( BASEPROPERTY_IMAGEPOSITION ), uno::makeAny( getExtendedImagePosition( nUNOValue ) ) ); + mbAdjustingImagePosition = false; + } + break; + case BASEPROPERTY_IMAGEPOSITION: + if ( !mbAdjustingImagePosition && ImplHasProperty( BASEPROPERTY_IMAGEALIGN ) ) + { + mbAdjustingImagePosition = true; + sal_Int16 nUNOValue = 0; + OSL_VERIFY( rValue >>= nUNOValue ); + setPropertyValue( GetPropertyName( BASEPROPERTY_IMAGEALIGN ), uno::makeAny( getCompatibleImageAlign( translateImagePosition( nUNOValue ) ) ) ); + mbAdjustingImagePosition = false; + } + break; + } + } + catch( const ::com::sun::star::uno::Exception& ) + { + OSL_ENSURE( sal_False, "ImageProducerControlModel::setFastPropertyValue_NoBroadcast: caught an exception while aligning the ImagePosition/ImageAlign properties!" ); + mbAdjustingImagePosition = sal_False; + } +} + +void ImageProducerControlModel::addConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& xConsumer ) throw (::com::sun::star::uno::RuntimeException) +{ + maListeners.push_back( xConsumer ); +} + +void ImageProducerControlModel::removeConsumer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XImageConsumer >& xConsumer ) throw (::com::sun::star::uno::RuntimeException) +{ + maListeners.remove( xConsumer ); +} + +void ImageProducerControlModel::startProduction( ) throw (::com::sun::star::uno::RuntimeException) +{ + uno::Sequence<uno::Any> aArgs(1); + aArgs.getArray()[0] = getPropertyValue( GetPropertyName( BASEPROPERTY_IMAGEURL ) ); + uno::Reference< lang::XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory(); + uno::Reference< awt::XImageProducer > xImageProducer( xMSF->createInstanceWithArguments( ::rtl::OUString::createFromAscii( "com.sun.star.awt.ImageProducer" ), aArgs ), uno::UNO_QUERY ); + if ( xImageProducer.is() ) + { + std::list< uno::Reference< awt::XImageConsumer > >::iterator aIter( maListeners.begin() ); + while ( aIter != maListeners.end() ) + { + xImageProducer->addConsumer( *aIter ); + aIter++; + } + xImageProducer->startProduction(); + } +} + +// ---------------------------------------------------- +// class ImageConsumerControl +// ---------------------------------------------------- + +sal_Bool SAL_CALL ImageConsumerControl::setModel(const uno::Reference< awt::XControlModel >& _rModel) throw ( uno::RuntimeException ) +{ + // remove the peer as image consumer from the model + lcl_knitImageComponents( getModel(), getPeer(), false ); + + sal_Bool bReturn = UnoControlBase::setModel( _rModel ); + + // add the peer as image consumer to the model + lcl_knitImageComponents( getModel(), getPeer(), true ); + + return bReturn; +} + +void SAL_CALL ImageConsumerControl::createPeer( const uno::Reference< awt::XToolkit >& rxToolkit, const uno::Reference< awt::XWindowPeer >& rParentPeer ) throw(uno::RuntimeException) +{ + // remove the peer as image consumer from the model + lcl_knitImageComponents( getModel(), getPeer(), false ); + + UnoControlBase::createPeer( rxToolkit, rParentPeer ); + + // add the peer as image consumer to the model + lcl_knitImageComponents( getModel(), getPeer(), true ); +} + +void SAL_CALL ImageConsumerControl::dispose( ) throw(::com::sun::star::uno::RuntimeException) +{ + // remove the peer as image consumer from the model + lcl_knitImageComponents( getModel(), getPeer(), false ); + + UnoControlBase::dispose(); +} + +void ImageConsumerControl::ImplSetPeerProperty( const ::rtl::OUString& rPropName, const uno::Any& rVal ) +{ + sal_uInt16 nType = GetPropertyId( rPropName ); + if ( nType == BASEPROPERTY_IMAGEURL ) + { + uno::Reference < awt::XImageProducer > xImgProd( getModel(), uno::UNO_QUERY ); + uno::Reference < awt::XImageConsumer > xImgCons( getPeer(), uno::UNO_QUERY ); + + if ( xImgProd.is() && xImgCons.is() ) + xImgProd->startProduction(); + } + else + UnoControlBase::ImplSetPeerProperty( rPropName, rVal ); +} + +// ---------------------------------------------------- +// class UnoControlButtonModel +// ---------------------------------------------------- +UnoControlButtonModel::UnoControlButtonModel() +{ + UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXButton ); + + osl_incrementInterlockedCount( &m_refCount ); + { + setFastPropertyValue_NoBroadcast( BASEPROPERTY_IMAGEPOSITION, ImplGetDefaultValue( BASEPROPERTY_IMAGEPOSITION ) ); + // this ensures that our ImagePosition is consistent with our ImageAlign property (since both + // defaults are not per se consistent), since both are coupled in setFastPropertyValue_NoBroadcast + } + osl_decrementInterlockedCount( &m_refCount ); +} + +::rtl::OUString UnoControlButtonModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlButtonModel ); +} + +uno::Any UnoControlButtonModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + switch ( nPropId ) + { + case BASEPROPERTY_DEFAULTCONTROL: + return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlButton ) ); + case BASEPROPERTY_TOGGLE: + return uno::makeAny( (sal_Bool)sal_False ); + case BASEPROPERTY_ALIGN: + return uno::makeAny( (sal_Int16)PROPERTY_ALIGN_CENTER ); + case BASEPROPERTY_FOCUSONCLICK: + return uno::makeAny( (sal_Bool)sal_True ); + } + + return ImageProducerControlModel::ImplGetDefaultValue( nPropId ); +} + +::cppu::IPropertyArrayHelper& UnoControlButtonModel::getInfoHelper() +{ + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + +// beans::XMultiPropertySet +uno::Reference< beans::XPropertySetInfo > UnoControlButtonModel::getPropertySetInfo( ) throw(uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + +// ---------------------------------------------------- +// class UnoButtonControl +// ---------------------------------------------------- +UnoButtonControl::UnoButtonControl() + : maActionListeners( *this ) + , maItemListeners( *this ) +{ + maComponentInfos.nWidth = 50; + maComponentInfos.nHeight = 14; +} + +::rtl::OUString UnoButtonControl::GetComponentServiceName() +{ + ::rtl::OUString aName( ::rtl::OUString::createFromAscii( "pushbutton" ) ); + uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_PUSHBUTTONTYPE ) ); + sal_Int16 n = sal_Int16(); + if ( ( aVal >>= n ) && n ) + { + // Use PushButtonType later when available... + switch ( n ) + { + case 1 /*PushButtonType::OK*/: aName= ::rtl::OUString::createFromAscii( "okbutton" ); + break; + case 2 /*PushButtonType::CANCEL*/: aName= ::rtl::OUString::createFromAscii( "cancelbutton" ); + break; + case 3 /*PushButtonType::HELP*/: aName= ::rtl::OUString::createFromAscii( "helpbutton" ); + break; + default: + { + DBG_ERROR( "Unknown Button Type!" ); + } + } + } + return aName; +} + +void UnoButtonControl::dispose() throw(uno::RuntimeException) +{ + lang::EventObject aEvt; + aEvt.Source = (::cppu::OWeakObject*)this; + maActionListeners.disposeAndClear( aEvt ); + maItemListeners.disposeAndClear( aEvt ); + ImageConsumerControl::dispose(); +} + +void UnoButtonControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) +{ + ImageConsumerControl::createPeer( rxToolkit, rParentPeer ); + + uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); + xButton->setActionCommand( maActionCommand ); + if ( maActionListeners.getLength() ) + xButton->addActionListener( &maActionListeners ); + + uno::Reference< XToggleButton > xPushButton( getPeer(), uno::UNO_QUERY ); + if ( xPushButton.is() ) + xPushButton->addItemListener( this ); +} + +void UnoButtonControl::addActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) +{ + maActionListeners.addInterface( l ); + if( getPeer().is() && maActionListeners.getLength() == 1 ) + { + uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); + xButton->addActionListener( &maActionListeners ); + } +} + +void UnoButtonControl::removeActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) +{ + if( getPeer().is() && maActionListeners.getLength() == 1 ) + { + uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); + xButton->removeActionListener( &maActionListeners ); + } + maActionListeners.removeInterface( l ); +} + +void UnoButtonControl::addItemListener(const uno::Reference< awt::XItemListener > & l) throw(uno::RuntimeException) +{ + maItemListeners.addInterface( l ); +} + +void UnoButtonControl::removeItemListener(const uno::Reference< awt::XItemListener > & l) throw(uno::RuntimeException) +{ + maItemListeners.removeInterface( l ); +} + +void SAL_CALL UnoButtonControl::disposing( const lang::EventObject& Source ) throw (uno::RuntimeException) +{ + ImageConsumerControl::disposing( Source ); +} + +void SAL_CALL UnoButtonControl::itemStateChanged( const awt::ItemEvent& rEvent ) throw (uno::RuntimeException) +{ + // forward to model + uno::Any aAny; + aAny <<= (sal_Int16)rEvent.Selected; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STATE ), aAny, sal_False ); + + // multiplex + ItemEvent aEvent( rEvent ); + aEvent.Source = *this; + maItemListeners.itemStateChanged( aEvent ); +} + +void UnoButtonControl::setLabel( const ::rtl::OUString& rLabel ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= rLabel; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LABEL ), aAny, sal_True ); +} + +void UnoButtonControl::setActionCommand( const ::rtl::OUString& rCommand ) throw(uno::RuntimeException) +{ + maActionCommand = rCommand; + if ( getPeer().is() ) + { + uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); + xButton->setActionCommand( rCommand ); + } +} + +awt::Size UnoButtonControl::getMinimumSize( ) throw(uno::RuntimeException) +{ + return Impl_getMinimumSize(); +} + +awt::Size UnoButtonControl::getPreferredSize( ) throw(uno::RuntimeException) +{ + return Impl_getPreferredSize(); +} + +awt::Size UnoButtonControl::calcAdjustedSize( const awt::Size& rNewSize ) throw(uno::RuntimeException) +{ + return Impl_calcAdjustedSize( rNewSize ); +} + +// ---------------------------------------------------- +// class UnoControlImageControlModel +// ---------------------------------------------------- +UnoControlImageControlModel::UnoControlImageControlModel() + :mbAdjustingImageScaleMode( false ) +{ + UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXImageControl ); +} + +::rtl::OUString UnoControlImageControlModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlImageControlModel ); +} + +uno::Any UnoControlImageControlModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + if ( nPropId == BASEPROPERTY_DEFAULTCONTROL ) + return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlImageControl ) ); + + if ( nPropId == BASEPROPERTY_IMAGE_SCALE_MODE ) + return makeAny( awt::ImageScaleMode::Anisotropic ); + + return ImageProducerControlModel::ImplGetDefaultValue( nPropId ); +} + +::cppu::IPropertyArrayHelper& UnoControlImageControlModel::getInfoHelper() +{ + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + +// beans::XMultiPropertySet +uno::Reference< beans::XPropertySetInfo > UnoControlImageControlModel::getPropertySetInfo( ) throw(uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + +void SAL_CALL UnoControlImageControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue ) throw (::com::sun::star::uno::Exception) +{ + ImageProducerControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue ); + + // ScaleImage is an older (and less powerful) version of ScaleMode, but keep both in sync as far as possible + try + { + switch ( _nHandle ) + { + case BASEPROPERTY_IMAGE_SCALE_MODE: + if ( !mbAdjustingImageScaleMode && ImplHasProperty( BASEPROPERTY_SCALEIMAGE ) ) + { + mbAdjustingImageScaleMode = true; + sal_Int16 nScaleMode( awt::ImageScaleMode::Anisotropic ); + OSL_VERIFY( _rValue >>= nScaleMode ); + setPropertyValue( GetPropertyName( BASEPROPERTY_SCALEIMAGE ), uno::makeAny( sal_Bool( nScaleMode != awt::ImageScaleMode::None ) ) ); + mbAdjustingImageScaleMode = false; + } + break; + case BASEPROPERTY_SCALEIMAGE: + if ( !mbAdjustingImageScaleMode && ImplHasProperty( BASEPROPERTY_IMAGE_SCALE_MODE ) ) + { + mbAdjustingImageScaleMode = true; + sal_Bool bScale = sal_True; + OSL_VERIFY( _rValue >>= bScale ); + setPropertyValue( GetPropertyName( BASEPROPERTY_IMAGE_SCALE_MODE ), uno::makeAny( bScale ? awt::ImageScaleMode::Anisotropic : awt::ImageScaleMode::None ) ); + mbAdjustingImageScaleMode = false; + } + break; + } + } + catch( const Exception& ) + { + mbAdjustingImageScaleMode = false; + throw; + } +} + +// ---------------------------------------------------- +// class UnoImageControlControl +// ---------------------------------------------------- +UnoImageControlControl::UnoImageControlControl() + : maActionListeners( *this ) +{ + // Woher die Defaults nehmen? + maComponentInfos.nWidth = 100; + maComponentInfos.nHeight = 100; +} + +::rtl::OUString UnoImageControlControl::GetComponentServiceName() +{ + return ::rtl::OUString::createFromAscii( "fixedimage" ); +} + +void UnoImageControlControl::dispose() throw(uno::RuntimeException) +{ + lang::EventObject aEvt; + aEvt.Source = (::cppu::OWeakObject*)this; + maActionListeners.disposeAndClear( aEvt ); + UnoControl::dispose(); +} + +sal_Bool UnoImageControlControl::isTransparent() throw(uno::RuntimeException) +{ + return sal_True; +} + +awt::Size UnoImageControlControl::getMinimumSize( ) throw(uno::RuntimeException) +{ + return Impl_getMinimumSize(); +} + +awt::Size UnoImageControlControl::getPreferredSize( ) throw(uno::RuntimeException) +{ + return Impl_getPreferredSize(); +} + +awt::Size UnoImageControlControl::calcAdjustedSize( const awt::Size& rNewSize ) throw(uno::RuntimeException) +{ + return Impl_calcAdjustedSize( rNewSize ); +} + +// ---------------------------------------------------- +// class UnoControlRadioButtonModel +// ---------------------------------------------------- +UnoControlRadioButtonModel::UnoControlRadioButtonModel() +{ + UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXRadioButton ); +} + +::rtl::OUString UnoControlRadioButtonModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlRadioButtonModel ); +} + +uno::Any UnoControlRadioButtonModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + switch ( nPropId ) + { + case BASEPROPERTY_DEFAULTCONTROL: + return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlRadioButton ) ); + + case BASEPROPERTY_VISUALEFFECT: + return uno::makeAny( (sal_Int16)awt::VisualEffect::LOOK3D ); + } + + return ImageProducerControlModel::ImplGetDefaultValue( nPropId ); +} + +::cppu::IPropertyArrayHelper& UnoControlRadioButtonModel::getInfoHelper() +{ + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + +// beans::XMultiPropertySet +uno::Reference< beans::XPropertySetInfo > UnoControlRadioButtonModel::getPropertySetInfo( ) throw(uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + + + +// ---------------------------------------------------- +// class UnoRadioButtonControl +// ---------------------------------------------------- +UnoRadioButtonControl::UnoRadioButtonControl() + : maItemListeners( *this ), maActionListeners( *this ) +{ + maComponentInfos.nWidth = 100; + maComponentInfos.nHeight = 12; +} + +::rtl::OUString UnoRadioButtonControl::GetComponentServiceName() +{ + return ::rtl::OUString::createFromAscii( "radiobutton" ); +} + +void UnoRadioButtonControl::dispose() throw(uno::RuntimeException) +{ + lang::EventObject aEvt; + aEvt.Source = (::cppu::OWeakObject*)this; + maItemListeners.disposeAndClear( aEvt ); + ImageConsumerControl::dispose(); +} + + +sal_Bool UnoRadioButtonControl::isTransparent() throw(uno::RuntimeException) +{ + return sal_True; +} + +void UnoRadioButtonControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) +{ + ImageConsumerControl::createPeer( rxToolkit, rParentPeer ); + + uno::Reference < awt::XRadioButton > xRadioButton( getPeer(), uno::UNO_QUERY ); + xRadioButton->addItemListener( this ); + + uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); + xButton->setActionCommand( maActionCommand ); + if ( maActionListeners.getLength() ) + xButton->addActionListener( &maActionListeners ); + + // as default, set the "AutoToggle" to true + // (it is set to false in VCLXToolkit::ImplCreateWindow because of #87254#, but we want to + // have it enabled by default because of 85071) + uno::Reference< awt::XVclWindowPeer > xVclWindowPeer( getPeer(), uno::UNO_QUERY ); + if ( xVclWindowPeer.is() ) + xVclWindowPeer->setProperty( GetPropertyName( BASEPROPERTY_AUTOTOGGLE ), ::cppu::bool2any( sal_True ) ); +} + +void UnoRadioButtonControl::addItemListener(const uno::Reference < awt::XItemListener > & l) throw(uno::RuntimeException) +{ + maItemListeners.addInterface( l ); +} + +void UnoRadioButtonControl::removeItemListener(const uno::Reference < awt::XItemListener > & l) throw(uno::RuntimeException) +{ + maItemListeners.removeInterface( l ); +} + +void UnoRadioButtonControl::addActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) +{ + maActionListeners.addInterface( l ); + if( getPeer().is() && maActionListeners.getLength() == 1 ) + { + uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); + xButton->addActionListener( &maActionListeners ); + } +} + +void UnoRadioButtonControl::removeActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) +{ + if( getPeer().is() && maActionListeners.getLength() == 1 ) + { + uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); + xButton->removeActionListener( &maActionListeners ); + } + maActionListeners.removeInterface( l ); +} + +void UnoRadioButtonControl::setLabel( const ::rtl::OUString& rLabel ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= rLabel; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LABEL ), aAny, sal_True ); +} + +void UnoRadioButtonControl::setActionCommand( const ::rtl::OUString& rCommand ) throw(uno::RuntimeException) +{ + maActionCommand = rCommand; + if ( getPeer().is() ) + { + uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); + xButton->setActionCommand( rCommand ); + } +} + +void UnoRadioButtonControl::setState( sal_Bool bOn ) throw(uno::RuntimeException) +{ + sal_Int16 nState = bOn ? 1 : 0; + uno::Any aAny; + aAny <<= nState; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STATE ), aAny, sal_True ); +} + +sal_Bool UnoRadioButtonControl::getState() throw(uno::RuntimeException) +{ + sal_Int16 nState = 0; + uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STATE ) ); + aVal >>= nState; + return nState ? sal_True : sal_False; +} + +void UnoRadioButtonControl::itemStateChanged( const awt::ItemEvent& rEvent ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= (sal_Int16)rEvent.Selected; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STATE ), aAny, sal_False ); + + // compatibility: + // in OOo 1.0.x, when the user clicked a radio button in a group of buttons, this resulted + // in _one_ itemStateChanged call for exactly the radio button which's state changed from + // "0" to "1". + // Nowadays, since the listener handling changed a lot towards 1.1 (the VCLXWindow reacts on more + // basic events from the VCL-windows, not anymore on the Link-based events like in 1.0.x), this + // isn't the case anymore: For instance, this method here gets called for the radio button + // which is being implicitily _de_selected, too. This is pretty bad for compatibility. + // Thus, we suppress all events with a new state other than "1". This is unlogical, and weird, when looking + // from a pure API perspective, but it's _compatible_ with older product versions, and this is + // all which matters here. + // #i14703# - 2003-05-23 - fs@openoffice.org + if ( 1 == rEvent.Selected ) + { + if ( maItemListeners.getLength() ) + maItemListeners.itemStateChanged( rEvent ); + } + // note that speaking stricly, this is wrong: When in 1.0.x, the user would have de-selected + // a radio button _without_ selecing another one, this would have caused a notification. + // With the change done here, this today won't cause a notification anymore. + // + // Fortunately, it's not possible for the user to de-select a radio button without selecting another on, + // at least not via the regular UI. It _would_ be possible via the Accessibility API, which + // counts as "user input", too. But in 1.0.x, there was no Accessibility API, so there is nothing + // to be inconsistent with. +} + +awt::Size UnoRadioButtonControl::getMinimumSize( ) throw(uno::RuntimeException) +{ + return Impl_getMinimumSize(); +} + +awt::Size UnoRadioButtonControl::getPreferredSize( ) throw(uno::RuntimeException) +{ + return Impl_getPreferredSize(); +} + +awt::Size UnoRadioButtonControl::calcAdjustedSize( const awt::Size& rNewSize ) throw(uno::RuntimeException) +{ + return Impl_calcAdjustedSize( rNewSize ); +} + +// ---------------------------------------------------- +// class UnoControlCheckBoxModel +// ---------------------------------------------------- +UnoControlCheckBoxModel::UnoControlCheckBoxModel() +{ + UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXCheckBox ); +} + +::rtl::OUString UnoControlCheckBoxModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlCheckBoxModel ); +} + +uno::Any UnoControlCheckBoxModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + switch ( nPropId ) + { + case BASEPROPERTY_DEFAULTCONTROL: + return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlCheckBox ) ); + + case BASEPROPERTY_VISUALEFFECT: + return uno::makeAny( (sal_Int16)awt::VisualEffect::LOOK3D ); + } + + return ImageProducerControlModel::ImplGetDefaultValue( nPropId ); +} + +::cppu::IPropertyArrayHelper& UnoControlCheckBoxModel::getInfoHelper() +{ + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + +// beans::XMultiPropertySet +uno::Reference< beans::XPropertySetInfo > UnoControlCheckBoxModel::getPropertySetInfo( ) throw(uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + + + +// ---------------------------------------------------- +// class UnoCheckBoxControl +// ---------------------------------------------------- +UnoCheckBoxControl::UnoCheckBoxControl() + : maItemListeners( *this ), maActionListeners( *this ) +{ + maComponentInfos.nWidth = 100; + maComponentInfos.nHeight = 12; +} + +::rtl::OUString UnoCheckBoxControl::GetComponentServiceName() +{ + return ::rtl::OUString::createFromAscii( "checkbox" ); +} + +void UnoCheckBoxControl::dispose() throw(uno::RuntimeException) +{ + lang::EventObject aEvt; + aEvt.Source = (::cppu::OWeakObject*)this; + maItemListeners.disposeAndClear( aEvt ); + ImageConsumerControl::dispose(); +} + +sal_Bool UnoCheckBoxControl::isTransparent() throw(uno::RuntimeException) +{ + return sal_True; +} + +void UnoCheckBoxControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) +{ + ImageConsumerControl::createPeer( rxToolkit, rParentPeer ); + + uno::Reference < awt::XCheckBox > xCheckBox( getPeer(), uno::UNO_QUERY ); + xCheckBox->addItemListener( this ); + + uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); + xButton->setActionCommand( maActionCommand ); + if ( maActionListeners.getLength() ) + xButton->addActionListener( &maActionListeners ); +} + +void UnoCheckBoxControl::addItemListener(const uno::Reference < awt::XItemListener > & l) throw(uno::RuntimeException) +{ + maItemListeners.addInterface( l ); +} + +void UnoCheckBoxControl::removeItemListener(const uno::Reference < awt::XItemListener > & l) throw(uno::RuntimeException) +{ + maItemListeners.removeInterface( l ); +} + +void UnoCheckBoxControl::addActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) +{ + maActionListeners.addInterface( l ); + if( getPeer().is() && maActionListeners.getLength() == 1 ) + { + uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); + xButton->addActionListener( &maActionListeners ); + } +} + +void UnoCheckBoxControl::removeActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) +{ + if( getPeer().is() && maActionListeners.getLength() == 1 ) + { + uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); + xButton->removeActionListener( &maActionListeners ); + } + maActionListeners.removeInterface( l ); +} + +void UnoCheckBoxControl::setActionCommand( const ::rtl::OUString& rCommand ) throw(uno::RuntimeException) +{ + maActionCommand = rCommand; + if ( getPeer().is() ) + { + uno::Reference < awt::XButton > xButton( getPeer(), uno::UNO_QUERY ); + xButton->setActionCommand( rCommand ); + } +} + + +void UnoCheckBoxControl::setLabel( const ::rtl::OUString& rLabel ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= rLabel; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LABEL ), aAny, sal_True ); +} + +void UnoCheckBoxControl::setState( short n ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= (sal_Int16)n; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STATE ), aAny, sal_True ); +} + +short UnoCheckBoxControl::getState() throw(uno::RuntimeException) +{ + short nState = 0; + uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STATE ) ); + aVal >>= nState; + return nState; +} + +void UnoCheckBoxControl::enableTriState( sal_Bool b ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= b; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TRISTATE ), aAny, sal_True ); +} + +void UnoCheckBoxControl::itemStateChanged( const awt::ItemEvent& rEvent ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= (sal_Int16)rEvent.Selected; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STATE ), aAny, sal_False ); + + if ( maItemListeners.getLength() ) + maItemListeners.itemStateChanged( rEvent ); +} + +awt::Size UnoCheckBoxControl::getMinimumSize( ) throw(uno::RuntimeException) +{ + return Impl_getMinimumSize(); +} + +awt::Size UnoCheckBoxControl::getPreferredSize( ) throw(uno::RuntimeException) +{ + return Impl_getPreferredSize(); +} + +awt::Size UnoCheckBoxControl::calcAdjustedSize( const awt::Size& rNewSize ) throw(uno::RuntimeException) +{ + return Impl_calcAdjustedSize( rNewSize ); +} + +// ---------------------------------------------------- +// class UnoControlFixedHyperlinkModel +// ---------------------------------------------------- +UnoControlFixedHyperlinkModel::UnoControlFixedHyperlinkModel() +{ + UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXFixedHyperlink ); +} + +::rtl::OUString UnoControlFixedHyperlinkModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlFixedHyperlinkModel ); +} + +uno::Any UnoControlFixedHyperlinkModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + if ( nPropId == BASEPROPERTY_DEFAULTCONTROL ) + { + uno::Any aAny; + aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlFixedHyperlink ); + return aAny; + } + else if ( nPropId == BASEPROPERTY_BORDER ) + { + uno::Any aAny; + aAny <<= (sal_Int16)0; + return aAny; + } + else if ( nPropId == BASEPROPERTY_URL ) + { + uno::Any aAny; + aAny <<= ::rtl::OUString(); + return aAny; + } + + return UnoControlModel::ImplGetDefaultValue( nPropId ); +} + +::cppu::IPropertyArrayHelper& UnoControlFixedHyperlinkModel::getInfoHelper() +{ + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + +// beans::XMultiPropertySet +uno::Reference< beans::XPropertySetInfo > UnoControlFixedHyperlinkModel::getPropertySetInfo( ) throw(uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + +// ---------------------------------------------------- +// class UnoFixedHyperlinkControl +// ---------------------------------------------------- +UnoFixedHyperlinkControl::UnoFixedHyperlinkControl() + : maActionListeners( *this ) +{ + maComponentInfos.nWidth = 100; + maComponentInfos.nHeight = 12; +} + +::rtl::OUString UnoFixedHyperlinkControl::GetComponentServiceName() +{ + return ::rtl::OUString::createFromAscii( "fixedhyperlink" ); +} + +// uno::XInterface +uno::Any UnoFixedHyperlinkControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) +{ + uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( awt::XFixedHyperlink*, this ), + SAL_STATIC_CAST( awt::XLayoutConstrains*, this ) ); + return (aRet.hasValue() ? aRet : UnoControlBase::queryAggregation( rType )); +} + +// lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( UnoFixedHyperlinkControl ) + getCppuType( ( uno::Reference< awt::XFixedHyperlink>* ) NULL ), + getCppuType( ( uno::Reference< awt::XLayoutConstrains>* ) NULL ), + UnoControlBase::getTypes() +IMPL_XTYPEPROVIDER_END + +sal_Bool UnoFixedHyperlinkControl::isTransparent() throw(uno::RuntimeException) +{ + return sal_True; +} + +void UnoFixedHyperlinkControl::setText( const ::rtl::OUString& Text ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= Text; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LABEL ), aAny, sal_True ); +} + +::rtl::OUString UnoFixedHyperlinkControl::getText() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_UString( BASEPROPERTY_LABEL ); +} + +void UnoFixedHyperlinkControl::setURL( const ::rtl::OUString& URL ) throw(::com::sun::star::uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= URL; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_URL ), aAny, sal_True ); +} + +::rtl::OUString UnoFixedHyperlinkControl::getURL( ) throw(::com::sun::star::uno::RuntimeException) +{ + return ImplGetPropertyValue_UString( BASEPROPERTY_URL ); +} + +void UnoFixedHyperlinkControl::setAlignment( short nAlign ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= (sal_Int16)nAlign; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ALIGN ), aAny, sal_True ); +} + +short UnoFixedHyperlinkControl::getAlignment() throw(uno::RuntimeException) +{ + short nAlign = 0; + if ( mxModel.is() ) + { + uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_ALIGN ) ); + aVal >>= nAlign; + } + return nAlign; +} + +awt::Size UnoFixedHyperlinkControl::getMinimumSize( ) throw(uno::RuntimeException) +{ + return Impl_getMinimumSize(); +} + +awt::Size UnoFixedHyperlinkControl::getPreferredSize( ) throw(uno::RuntimeException) +{ + return Impl_getPreferredSize(); +} + +awt::Size UnoFixedHyperlinkControl::calcAdjustedSize( const awt::Size& rNewSize ) throw(uno::RuntimeException) +{ + return Impl_calcAdjustedSize( rNewSize ); +} + +void UnoFixedHyperlinkControl::dispose() throw(uno::RuntimeException) +{ + lang::EventObject aEvt; + aEvt.Source = (::cppu::OWeakObject*)this; + maActionListeners.disposeAndClear( aEvt ); + UnoControlBase::dispose(); +} + +void UnoFixedHyperlinkControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) +{ + UnoControlBase::createPeer( rxToolkit, rParentPeer ); + + uno::Reference < awt::XFixedHyperlink > xFixedHyperlink( getPeer(), uno::UNO_QUERY ); + if ( maActionListeners.getLength() ) + xFixedHyperlink->addActionListener( &maActionListeners ); +} + +void UnoFixedHyperlinkControl::addActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) +{ + maActionListeners.addInterface( l ); + if( getPeer().is() && maActionListeners.getLength() == 1 ) + { + uno::Reference < awt::XFixedHyperlink > xFixedHyperlink( getPeer(), uno::UNO_QUERY ); + xFixedHyperlink->addActionListener( &maActionListeners ); + } +} + +void UnoFixedHyperlinkControl::removeActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) +{ + if( getPeer().is() && maActionListeners.getLength() == 1 ) + { + uno::Reference < awt::XFixedHyperlink > xFixedHyperlink( getPeer(), uno::UNO_QUERY ); + xFixedHyperlink->removeActionListener( &maActionListeners ); + } + maActionListeners.removeInterface( l ); +} + +// ---------------------------------------------------- +// class UnoControlFixedTextModel +// ---------------------------------------------------- +UnoControlFixedTextModel::UnoControlFixedTextModel() +{ + UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXFixedText ); +} + +::rtl::OUString UnoControlFixedTextModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlFixedTextModel ); +} + +uno::Any UnoControlFixedTextModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + if ( nPropId == BASEPROPERTY_DEFAULTCONTROL ) + { + uno::Any aAny; + aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlFixedText ); + return aAny; + } + else if ( nPropId == BASEPROPERTY_BORDER ) + { + uno::Any aAny; + aAny <<= (sal_Int16)0; + return aAny; + } + + return UnoControlModel::ImplGetDefaultValue( nPropId ); +} + +::cppu::IPropertyArrayHelper& UnoControlFixedTextModel::getInfoHelper() +{ + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + +// beans::XMultiPropertySet +uno::Reference< beans::XPropertySetInfo > UnoControlFixedTextModel::getPropertySetInfo( ) throw(uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + + +// ---------------------------------------------------- +// class UnoFixedTextControl +// ---------------------------------------------------- +UnoFixedTextControl::UnoFixedTextControl() +{ + maComponentInfos.nWidth = 100; + maComponentInfos.nHeight = 12; +} + +::rtl::OUString UnoFixedTextControl::GetComponentServiceName() +{ + return ::rtl::OUString::createFromAscii( "fixedtext" ); +} + +// uno::XInterface +uno::Any UnoFixedTextControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) +{ + uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( awt::XFixedText*, this ), + SAL_STATIC_CAST( awt::XLayoutConstrains*, this ) ); + return (aRet.hasValue() ? aRet : UnoControlBase::queryAggregation( rType )); +} + +// lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( UnoFixedTextControl ) + getCppuType( ( uno::Reference< awt::XFixedText>* ) NULL ), + getCppuType( ( uno::Reference< awt::XLayoutConstrains>* ) NULL ), + UnoControlBase::getTypes() +IMPL_XTYPEPROVIDER_END + +sal_Bool UnoFixedTextControl::isTransparent() throw(uno::RuntimeException) +{ + return sal_True; +} + +void UnoFixedTextControl::setText( const ::rtl::OUString& Text ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= Text; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LABEL ), aAny, sal_True ); +} + +::rtl::OUString UnoFixedTextControl::getText() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_UString( BASEPROPERTY_LABEL ); +} + +void UnoFixedTextControl::setAlignment( short nAlign ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= (sal_Int16)nAlign; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ALIGN ), aAny, sal_True ); +} + +short UnoFixedTextControl::getAlignment() throw(uno::RuntimeException) +{ + short nAlign = 0; + if ( mxModel.is() ) + { + uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_ALIGN ) ); + aVal >>= nAlign; + } + return nAlign; +} + +awt::Size UnoFixedTextControl::getMinimumSize( ) throw(uno::RuntimeException) +{ + return Impl_getMinimumSize(); +} + +awt::Size UnoFixedTextControl::getPreferredSize( ) throw(uno::RuntimeException) +{ + return Impl_getPreferredSize(); +} + +awt::Size UnoFixedTextControl::calcAdjustedSize( const awt::Size& rNewSize ) throw(uno::RuntimeException) +{ + return Impl_calcAdjustedSize( rNewSize ); +} + +// ---------------------------------------------------- +// class UnoControlGroupBoxModel +// ---------------------------------------------------- +UnoControlGroupBoxModel::UnoControlGroupBoxModel() +{ + ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL ); + ImplRegisterProperty( BASEPROPERTY_ENABLED ); + ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE ); + ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR ); + ImplRegisterProperty( BASEPROPERTY_HELPTEXT ); + ImplRegisterProperty( BASEPROPERTY_HELPURL ); + ImplRegisterProperty( BASEPROPERTY_LABEL ); + ImplRegisterProperty( BASEPROPERTY_PRINTABLE ); + ImplRegisterProperty( BASEPROPERTY_WRITING_MODE ); + ImplRegisterProperty( BASEPROPERTY_CONTEXT_WRITING_MODE ); +} + +::rtl::OUString UnoControlGroupBoxModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlGroupBoxModel ); +} + +uno::Any UnoControlGroupBoxModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + if ( nPropId == BASEPROPERTY_DEFAULTCONTROL ) + { + uno::Any aAny; + aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlGroupBox ); + return aAny; + } + return UnoControlModel::ImplGetDefaultValue( nPropId ); +} + +::cppu::IPropertyArrayHelper& UnoControlGroupBoxModel::getInfoHelper() +{ + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + +// beans::XMultiPropertySet +uno::Reference< beans::XPropertySetInfo > UnoControlGroupBoxModel::getPropertySetInfo( ) throw(uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + +// ---------------------------------------------------- +// class UnoGroupBoxControl +// ---------------------------------------------------- +UnoGroupBoxControl::UnoGroupBoxControl() +{ + maComponentInfos.nWidth = 100; + maComponentInfos.nHeight = 100; +} + +::rtl::OUString UnoGroupBoxControl::GetComponentServiceName() +{ + return ::rtl::OUString::createFromAscii( "groupbox" ); +} + +sal_Bool UnoGroupBoxControl::isTransparent() throw(uno::RuntimeException) +{ + return sal_True; +} + +// ---------------------------------------------------- +// class UnoControlListBoxModel +// ---------------------------------------------------- +UnoControlListBoxModel::UnoControlListBoxModel() +{ + UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXListBox ); +} + +::rtl::OUString UnoControlListBoxModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlListBoxModel ); +} + +uno::Any UnoControlListBoxModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + if ( nPropId == BASEPROPERTY_DEFAULTCONTROL ) + { + uno::Any aAny; + aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlListBox ); + return aAny; + } + return UnoControlModel::ImplGetDefaultValue( nPropId ); +} + +::cppu::IPropertyArrayHelper& UnoControlListBoxModel::getInfoHelper() +{ + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + +// beans::XMultiPropertySet +uno::Reference< beans::XPropertySetInfo > UnoControlListBoxModel::getPropertySetInfo( ) throw(uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + +void UnoControlListBoxModel::ImplPropertyChanged( sal_uInt16 nPropId ) +{ + if ( nPropId == BASEPROPERTY_STRINGITEMLIST ) + { + uno::Sequence<sal_Int16> aSeq; + uno::Any aAny; + aAny <<= aSeq; + setPropertyValue( GetPropertyName( BASEPROPERTY_SELECTEDITEMS ), aAny ); + } + + UnoControlModel::ImplPropertyChanged( nPropId ); +} + +void UnoControlListBoxModel::ImplNormalizePropertySequence( const sal_Int32 _nCount, sal_Int32* _pHandles, + uno::Any* _pValues, sal_Int32* _pValidHandles ) const SAL_THROW(()) +{ + // dependencies we know: + // BASEPROPERTY_STRINGITEMLIST->BASEPROPERTY_SELECTEDITEMS + ImplEnsureHandleOrder( _nCount, _pHandles, _pValues, BASEPROPERTY_STRINGITEMLIST, BASEPROPERTY_SELECTEDITEMS ); + + UnoControlModel::ImplNormalizePropertySequence( _nCount, _pHandles, _pValues, _pValidHandles ); +} + +// ---------------------------------------------------- +// class UnoListBoxControl +// ---------------------------------------------------- +UnoListBoxControl::UnoListBoxControl() + : maActionListeners( *this ), + maItemListeners( *this ) +{ + maComponentInfos.nWidth = 100; + maComponentInfos.nHeight = 12; +} + +::rtl::OUString UnoListBoxControl::GetComponentServiceName() +{ + return ::rtl::OUString::createFromAscii( "listbox" ); +} + +// uno::XInterface +uno::Any UnoListBoxControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) +{ + uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( awt::XListBox*, this ), + SAL_STATIC_CAST( awt::XItemListener*, this ), + SAL_STATIC_CAST( lang::XEventListener*, SAL_STATIC_CAST( awt::XItemListener*, this ) ), + SAL_STATIC_CAST( awt::XLayoutConstrains*, this ), + SAL_STATIC_CAST( awt::XTextLayoutConstrains*, this ) ); + return (aRet.hasValue() ? aRet : UnoControlBase::queryAggregation( rType )); +} + +// lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( UnoListBoxControl ) + getCppuType( ( uno::Reference< awt::XListBox>* ) NULL ), + getCppuType( ( uno::Reference< awt::XItemListener>* ) NULL ), + getCppuType( ( uno::Reference< awt::XLayoutConstrains>* ) NULL ), + getCppuType( ( uno::Reference< awt::XTextLayoutConstrains>* ) NULL ), + UnoControlBase::getTypes() +IMPL_XTYPEPROVIDER_END + +void UnoListBoxControl::dispose() throw(uno::RuntimeException) +{ + lang::EventObject aEvt; + aEvt.Source = (::cppu::OWeakObject*)this; + maActionListeners.disposeAndClear( aEvt ); + maItemListeners.disposeAndClear( aEvt ); + UnoControl::dispose(); +} + +void UnoListBoxControl::ImplUpdateSelectedItemsProperty() +{ + if ( getPeer().is() ) + { + uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY ); + DBG_ASSERT( xListBox.is(), "XListBox?" ); + + uno::Sequence<sal_Int16> aSeq = xListBox->getSelectedItemsPos(); + uno::Any aAny; + aAny <<= aSeq; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SELECTEDITEMS ), aAny, sal_False ); + } +} + +void UnoListBoxControl::ImplSetPeerProperty( const ::rtl::OUString& rPropName, const uno::Any& rVal ) +{ + UnoControl::ImplSetPeerProperty( rPropName, rVal ); + + // Wenn die SelectedItems vor der StringItemList gesetzt werden, + // hat das keine Auswirkung... + if ( rPropName == GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) ) + { + ::rtl::OUString aSelPropName = GetPropertyName( BASEPROPERTY_SELECTEDITEMS ); + uno::Any aVal = ImplGetPropertyValue( aSelPropName ); + if ( !( aVal.getValueType().getTypeClass() == uno::TypeClass_VOID ) ) + { + uno::Reference< awt::XVclWindowPeer > xW( getPeer(), uno::UNO_QUERY ); + if (xW.is()) + // same comment as in UnoControl::ImplSetPeerProperty - see there + xW->setProperty( aSelPropName, aVal ); + } + } +} + +void UnoListBoxControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) +{ + UnoControl::createPeer( rxToolkit, rParentPeer ); + + uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY ); + xListBox->addItemListener( this ); + + if ( maActionListeners.getLength() ) + xListBox->addActionListener( &maActionListeners ); +} + +void UnoListBoxControl::addActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) +{ + maActionListeners.addInterface( l ); + if( getPeer().is() && maActionListeners.getLength() == 1 ) + { + uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY ); + xListBox->addActionListener( &maActionListeners ); + } +} + +void UnoListBoxControl::removeActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) +{ + if( getPeer().is() && maActionListeners.getLength() == 1 ) + { + uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY ); + xListBox->removeActionListener( &maActionListeners ); + } + maActionListeners.removeInterface( l ); +} + +void UnoListBoxControl::addItemListener(const uno::Reference < awt::XItemListener > & l) throw(uno::RuntimeException) +{ + maItemListeners.addInterface( l ); +} + +void UnoListBoxControl::removeItemListener(const uno::Reference < awt::XItemListener > & l) throw(uno::RuntimeException) +{ + maItemListeners.removeInterface( l ); +} + +void UnoListBoxControl::addItem( const ::rtl::OUString& aItem, sal_Int16 nPos ) throw(uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString> aSeq( 1 ); + aSeq.getArray()[0] = aItem; + addItems( aSeq, nPos ); +} + +void UnoListBoxControl::addItems( const uno::Sequence< ::rtl::OUString>& aItems, sal_Int16 nPos ) throw(uno::RuntimeException) +{ + uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) ); + uno::Sequence< ::rtl::OUString> aSeq; + aVal >>= aSeq; + sal_uInt16 nNewItems = (sal_uInt16)aItems.getLength(); + sal_uInt16 nOldLen = (sal_uInt16)aSeq.getLength(); + sal_uInt16 nNewLen = nOldLen + nNewItems; + + uno::Sequence< ::rtl::OUString> aNewSeq( nNewLen ); + ::rtl::OUString* pNewData = aNewSeq.getArray(); + ::rtl::OUString* pOldData = aSeq.getArray(); + + if ( ( nPos < 0 ) || ( nPos > nOldLen ) ) + nPos = (sal_uInt16) nOldLen; + + sal_uInt16 n; + // Items vor der Einfuege-Position + for ( n = 0; n < nPos; n++ ) + pNewData[n] = pOldData[n]; + + // Neue Items + for ( n = 0; n < nNewItems; n++ ) + pNewData[nPos+n] = aItems.getConstArray()[n]; + + // Rest der alten Items + for ( n = nPos; n < nOldLen; n++ ) + pNewData[nNewItems+n] = pOldData[n]; + + uno::Any aAny; + aAny <<= aNewSeq; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ), aAny, sal_True ); +} + +void UnoListBoxControl::removeItems( sal_Int16 nPos, sal_Int16 nCount ) throw(uno::RuntimeException) +{ + uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) ); + uno::Sequence< ::rtl::OUString> aSeq; + aVal >>= aSeq; + sal_uInt16 nOldLen = (sal_uInt16)aSeq.getLength(); + if ( nOldLen && ( nPos < nOldLen ) ) + { + if ( nCount > ( nOldLen-nPos ) ) + nCount = nOldLen-nPos; + + sal_uInt16 nNewLen = nOldLen - nCount; + + uno::Sequence< ::rtl::OUString> aNewSeq( nNewLen ); + ::rtl::OUString* pNewData = aNewSeq.getArray(); + ::rtl::OUString* pOldData = aSeq.getArray(); + + sal_uInt16 n; + // Items vor der Entfern-Position + for ( n = 0; n < nPos; n++ ) + pNewData[n] = pOldData[n]; + + // Rest der Items + for ( n = nPos; n < (nOldLen-nCount); n++ ) + pNewData[n] = pOldData[n+nCount]; + + uno::Any aAny; + aAny <<= aNewSeq; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ), aAny, sal_True ); + } +} + +sal_Int16 UnoListBoxControl::getItemCount() throw(uno::RuntimeException) +{ + uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) ); + uno::Sequence< ::rtl::OUString> aSeq; + aVal >>= aSeq; + return (sal_Int16)aSeq.getLength(); +} + +::rtl::OUString UnoListBoxControl::getItem( sal_Int16 nPos ) throw(uno::RuntimeException) +{ + ::rtl::OUString aItem; + uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) ); + uno::Sequence< ::rtl::OUString> aSeq; + aVal >>= aSeq; + if ( nPos < aSeq.getLength() ) + aItem = aSeq.getConstArray()[nPos]; + return aItem; +} + +uno::Sequence< ::rtl::OUString> UnoListBoxControl::getItems() throw(uno::RuntimeException) +{ + uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) ); + uno::Sequence< ::rtl::OUString> aSeq; + aVal >>= aSeq; + return aSeq; +} + +sal_Int16 UnoListBoxControl::getSelectedItemPos() throw(uno::RuntimeException) +{ + sal_Int16 n = -1; + if ( getPeer().is() ) + { + uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY ); + n = xListBox->getSelectedItemPos(); + } + return n; +} + +uno::Sequence<sal_Int16> UnoListBoxControl::getSelectedItemsPos() throw(uno::RuntimeException) +{ + uno::Sequence<sal_Int16> aSeq; + if ( getPeer().is() ) + { + uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY ); + aSeq = xListBox->getSelectedItemsPos(); + } + return aSeq; +} + +::rtl::OUString UnoListBoxControl::getSelectedItem() throw(uno::RuntimeException) +{ + ::rtl::OUString aItem; + if ( getPeer().is() ) + { + uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY ); + aItem = xListBox->getSelectedItem(); + } + return aItem; +} + +uno::Sequence< ::rtl::OUString> UnoListBoxControl::getSelectedItems() throw(uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString> aSeq; + if ( getPeer().is() ) + { + uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY ); + aSeq = xListBox->getSelectedItems(); + } + return aSeq; +} + +void UnoListBoxControl::selectItemPos( sal_Int16 nPos, sal_Bool bSelect ) throw(uno::RuntimeException) +{ + if ( getPeer().is() ) + { + uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY ); + xListBox->selectItemPos( nPos, bSelect ); + } + ImplUpdateSelectedItemsProperty(); +} + +void UnoListBoxControl::selectItemsPos( const uno::Sequence<sal_Int16>& aPositions, sal_Bool bSelect ) throw(uno::RuntimeException) +{ + if ( getPeer().is() ) + { + uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY ); + xListBox->selectItemsPos( aPositions, bSelect ); + } + ImplUpdateSelectedItemsProperty(); +} + +void UnoListBoxControl::selectItem( const ::rtl::OUString& aItem, sal_Bool bSelect ) throw(uno::RuntimeException) +{ + if ( getPeer().is() ) + { + uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY ); + xListBox->selectItem( aItem, bSelect ); + } + ImplUpdateSelectedItemsProperty(); +} + +void UnoListBoxControl::makeVisible( sal_Int16 nEntry ) throw(uno::RuntimeException) +{ + if ( getPeer().is() ) + { + uno::Reference < awt::XListBox > xListBox( getPeer(), uno::UNO_QUERY ); + xListBox->makeVisible( nEntry ); + } +} + +void UnoListBoxControl::setDropDownLineCount( sal_Int16 nLines ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= (sal_Int16)nLines; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LINECOUNT ), aAny, sal_True ); +} + +sal_Int16 UnoListBoxControl::getDropDownLineCount() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_INT16( BASEPROPERTY_LINECOUNT ); +} + +sal_Bool UnoListBoxControl::isMutipleMode() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_BOOL( BASEPROPERTY_MULTISELECTION ); +} + +void UnoListBoxControl::setMultipleMode( sal_Bool bMulti ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= bMulti; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_MULTISELECTION ), aAny, sal_True ); +} + +void UnoListBoxControl::itemStateChanged( const awt::ItemEvent& rEvent ) throw(uno::RuntimeException) +{ + ImplUpdateSelectedItemsProperty(); + if ( maItemListeners.getLength() ) + { + try + { + maItemListeners.itemStateChanged( rEvent ); + } + catch( const Exception& e ) + { +#if OSL_DEBUG_LEVEL == 0 + (void) e; // suppress warning +#else + ::rtl::OString sMessage( "UnoListBoxControl::itemStateChanged: caught an exception:\n" ); + sMessage += ::rtl::OString( e.Message.getStr(), e.Message.getLength(), RTL_TEXTENCODING_ASCII_US ); + OSL_ENSURE( sal_False, sMessage.getStr() ); +#endif + } + } +} + +awt::Size UnoListBoxControl::getMinimumSize( ) throw(uno::RuntimeException) +{ + return Impl_getMinimumSize(); +} + +awt::Size UnoListBoxControl::getPreferredSize( ) throw(uno::RuntimeException) +{ + return Impl_getPreferredSize(); +} + +awt::Size UnoListBoxControl::calcAdjustedSize( const awt::Size& rNewSize ) throw(uno::RuntimeException) +{ + return Impl_calcAdjustedSize( rNewSize ); +} + +awt::Size UnoListBoxControl::getMinimumSize( sal_Int16 nCols, sal_Int16 nLines ) throw(uno::RuntimeException) +{ + return Impl_getMinimumSize( nCols, nLines ); +} + +void UnoListBoxControl::getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines ) throw(uno::RuntimeException) +{ + Impl_getColumnsAndLines( nCols, nLines ); +} + +// ---------------------------------------------------- +// class UnoControlComboBoxModel +// ---------------------------------------------------- +UnoControlComboBoxModel::UnoControlComboBoxModel() +{ + UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXComboBox ); +} + +::rtl::OUString UnoControlComboBoxModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlComboBoxModel ); +} + +uno::Any UnoControlComboBoxModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + if ( nPropId == BASEPROPERTY_DEFAULTCONTROL ) + { + uno::Any aAny; + aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlComboBox ); + return aAny; + } + return UnoControlModel::ImplGetDefaultValue( nPropId ); +} + + +::cppu::IPropertyArrayHelper& UnoControlComboBoxModel::getInfoHelper() +{ + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + +// beans::XMultiPropertySet +uno::Reference< beans::XPropertySetInfo > UnoControlComboBoxModel::getPropertySetInfo( ) throw(uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + + + +// ---------------------------------------------------- +// class UnoComboBoxControl +// ---------------------------------------------------- +UnoComboBoxControl::UnoComboBoxControl() + : maActionListeners( *this ), + maItemListeners( *this ) +{ + maComponentInfos.nWidth = 100; + maComponentInfos.nHeight = 12; +} + +::rtl::OUString UnoComboBoxControl::GetComponentServiceName() +{ + return ::rtl::OUString::createFromAscii( "combobox" ); +} + +// uno::XInterface +uno::Any UnoComboBoxControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) +{ + uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( awt::XComboBox*, this ) ); + return (aRet.hasValue() ? aRet : UnoEditControl::queryAggregation( rType )); +} + +// lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( UnoComboBoxControl ) + getCppuType( ( uno::Reference< awt::XComboBox>* ) NULL ), + UnoEditControl::getTypes() +IMPL_XTYPEPROVIDER_END + +void UnoComboBoxControl::dispose() throw(uno::RuntimeException) +{ + lang::EventObject aEvt; + aEvt.Source = (::cppu::OWeakObject*)this; + maActionListeners.disposeAndClear( aEvt ); + maItemListeners.disposeAndClear( aEvt ); + UnoControl::dispose(); +} + +void UnoComboBoxControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) +{ + UnoEditControl::createPeer( rxToolkit, rParentPeer ); + + uno::Reference < awt::XComboBox > xComboBox( getPeer(), uno::UNO_QUERY ); + if ( maActionListeners.getLength() ) + xComboBox->addActionListener( &maActionListeners ); + if ( maItemListeners.getLength() ) + xComboBox->addItemListener( &maItemListeners ); +} + +void UnoComboBoxControl::addActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) +{ + maActionListeners.addInterface( l ); + if( getPeer().is() && maActionListeners.getLength() == 1 ) + { + uno::Reference < awt::XComboBox > xComboBox( getPeer(), uno::UNO_QUERY ); + xComboBox->addActionListener( &maActionListeners ); + } +} + +void UnoComboBoxControl::removeActionListener(const uno::Reference< awt::XActionListener > & l) throw(uno::RuntimeException) +{ + if( getPeer().is() && maActionListeners.getLength() == 1 ) + { + uno::Reference < awt::XComboBox > xComboBox( getPeer(), uno::UNO_QUERY ); + xComboBox->removeActionListener( &maActionListeners ); + } + maActionListeners.removeInterface( l ); +} + +void UnoComboBoxControl::addItemListener(const uno::Reference < awt::XItemListener > & l) throw(uno::RuntimeException) +{ + maItemListeners.addInterface( l ); + if( getPeer().is() && maItemListeners.getLength() == 1 ) + { + uno::Reference < awt::XComboBox > xComboBox( getPeer(), uno::UNO_QUERY ); + xComboBox->addItemListener( &maItemListeners ); + } +} + +void UnoComboBoxControl::removeItemListener(const uno::Reference < awt::XItemListener > & l) throw(uno::RuntimeException) +{ + if( getPeer().is() && maItemListeners.getLength() == 1 ) + { + uno::Reference < awt::XComboBox > xComboBox( getPeer(), uno::UNO_QUERY ); // MT: Mal alles so umstellen, schoener als Ref anlegen und query rufen + xComboBox->removeItemListener( &maItemListeners ); + } + maItemListeners.removeInterface( l ); +} + +void UnoComboBoxControl::addItem( const ::rtl::OUString& aItem, sal_Int16 nPos ) throw(uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString> aSeq( 1 ); + aSeq.getArray()[0] = aItem; + addItems( aSeq, nPos ); +} + +void UnoComboBoxControl::addItems( const uno::Sequence< ::rtl::OUString>& aItems, sal_Int16 nPos ) throw(uno::RuntimeException) +{ + uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) ); + uno::Sequence< ::rtl::OUString> aSeq; + aVal >>= aSeq; + sal_uInt16 nNewItems = (sal_uInt16)aItems.getLength(); + sal_uInt16 nOldLen = (sal_uInt16)aSeq.getLength(); + sal_uInt16 nNewLen = nOldLen + nNewItems; + + uno::Sequence< ::rtl::OUString> aNewSeq( nNewLen ); + ::rtl::OUString* pNewData = aNewSeq.getArray(); + const ::rtl::OUString* pOldData = aSeq.getConstArray(); + + if ( ( nPos < 0 ) || ( nPos > nOldLen ) ) + nPos = (sal_uInt16) nOldLen; + + sal_uInt16 n; + // Items vor der Einfuege-Position + for ( n = 0; n < nPos; n++ ) + pNewData[n] = pOldData[n]; + + // Neue Items + for ( n = 0; n < nNewItems; n++ ) + pNewData[nPos+n] = aItems.getConstArray()[n]; + + // Rest der alten Items + for ( n = nPos; n < nOldLen; n++ ) + pNewData[nNewItems+n] = pOldData[n]; + + uno::Any aAny; + aAny <<= aNewSeq; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ), aAny, sal_True ); +} + +void UnoComboBoxControl::removeItems( sal_Int16 nPos, sal_Int16 nCount ) throw(uno::RuntimeException) +{ + uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) ); + uno::Sequence< ::rtl::OUString> aSeq; + aVal >>= aSeq; + sal_uInt16 nOldLen = (sal_uInt16)aSeq.getLength(); + if ( nOldLen && ( nPos < nOldLen ) ) + { + if ( nCount > ( nOldLen-nPos ) ) + nCount = nOldLen-nPos; + + sal_uInt16 nNewLen = nOldLen - nCount; + + uno::Sequence< ::rtl::OUString> aNewSeq( nNewLen ); + ::rtl::OUString* pNewData = aNewSeq.getArray(); + ::rtl::OUString* pOldData = aSeq.getArray(); + + sal_uInt16 n; + // Items vor der Entfern-Position + for ( n = 0; n < nPos; n++ ) + pNewData[n] = pOldData[n]; + + // Rest der Items + for ( n = nPos; n < (nOldLen-nCount); n++ ) + pNewData[n] = pOldData[n+nCount]; + + uno::Any aAny; + aAny <<= aNewSeq; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ), aAny, sal_True ); + } +} + +sal_Int16 UnoComboBoxControl::getItemCount() throw(uno::RuntimeException) +{ + uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) ); + uno::Sequence< ::rtl::OUString> aSeq; + aVal >>= aSeq; + return (sal_Int16)aSeq.getLength(); +} + +::rtl::OUString UnoComboBoxControl::getItem( sal_Int16 nPos ) throw(uno::RuntimeException) +{ + ::rtl::OUString aItem; + uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) ); + uno::Sequence< ::rtl::OUString> aSeq; + aVal >>= aSeq; + if ( nPos < aSeq.getLength() ) + aItem = aSeq.getConstArray()[nPos]; + return aItem; +} + +uno::Sequence< ::rtl::OUString> UnoComboBoxControl::getItems() throw(uno::RuntimeException) +{ + uno::Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_STRINGITEMLIST ) ); + uno::Sequence< ::rtl::OUString> aSeq; + aVal >>= aSeq; + return aSeq; +} + +void UnoComboBoxControl::setDropDownLineCount( sal_Int16 nLines ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= nLines; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LINECOUNT ), aAny, sal_True ); +} + +sal_Int16 UnoComboBoxControl::getDropDownLineCount() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_INT16( BASEPROPERTY_LINECOUNT ); +} + + +// ---------------------------------------------------- +// UnoSpinFieldControl +// ---------------------------------------------------- +UnoSpinFieldControl::UnoSpinFieldControl() : maSpinListeners( *this ) +{ + mbRepeat = sal_False; +} + +// uno::XInterface +uno::Any UnoSpinFieldControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) +{ + uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( awt::XSpinField*, this ) ); + return (aRet.hasValue() ? aRet : UnoEditControl::queryAggregation( rType )); +} + +// lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( UnoSpinFieldControl ) + getCppuType( ( uno::Reference< awt::XSpinField>* ) NULL ), + UnoEditControl::getTypes() +IMPL_XTYPEPROVIDER_END + +void UnoSpinFieldControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) +{ + UnoEditControl::createPeer( rxToolkit, rParentPeer ); + + uno::Reference < awt::XSpinField > xField( getPeer(), uno::UNO_QUERY ); + xField->enableRepeat( mbRepeat ); + if ( maSpinListeners.getLength() ) + xField->addSpinListener( &maSpinListeners ); +} + + // ::com::sun::star::awt::XSpinField +void UnoSpinFieldControl::addSpinListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XSpinListener >& l ) throw(::com::sun::star::uno::RuntimeException) +{ + maSpinListeners.addInterface( l ); + if( getPeer().is() && maSpinListeners.getLength() == 1 ) + { + uno::Reference < awt::XSpinField > xField( getPeer(), uno::UNO_QUERY ); + xField->addSpinListener( &maSpinListeners ); + } +} + +void UnoSpinFieldControl::removeSpinListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XSpinListener >& l ) throw(::com::sun::star::uno::RuntimeException) +{ + if( getPeer().is() && maSpinListeners.getLength() == 1 ) + { + uno::Reference < awt::XSpinField > xField( getPeer(), uno::UNO_QUERY ); + xField->removeSpinListener( &maSpinListeners ); + } + maSpinListeners.removeInterface( l ); +} + +void UnoSpinFieldControl::up() throw(::com::sun::star::uno::RuntimeException) +{ + uno::Reference < awt::XSpinField > xField( getPeer(), uno::UNO_QUERY ); + if ( xField.is() ) + xField->up(); +} + +void UnoSpinFieldControl::down() throw(::com::sun::star::uno::RuntimeException) +{ + uno::Reference < awt::XSpinField > xField( getPeer(), uno::UNO_QUERY ); + if ( xField.is() ) + xField->down(); +} + +void UnoSpinFieldControl::first() throw(::com::sun::star::uno::RuntimeException) +{ + uno::Reference < awt::XSpinField > xField( getPeer(), uno::UNO_QUERY ); + if ( xField.is() ) + xField->first(); +} + +void UnoSpinFieldControl::last() throw(::com::sun::star::uno::RuntimeException) +{ + uno::Reference < awt::XSpinField > xField( getPeer(), uno::UNO_QUERY ); + if ( xField.is() ) + xField->last(); +} + +void UnoSpinFieldControl::enableRepeat( sal_Bool bRepeat ) throw(::com::sun::star::uno::RuntimeException) +{ + mbRepeat = bRepeat; + + uno::Reference < awt::XSpinField > xField( getPeer(), uno::UNO_QUERY ); + if ( xField.is() ) + xField->enableRepeat( bRepeat ); +} + +// ---------------------------------------------------- +// class UnoControlDateFieldModel +// ---------------------------------------------------- +UnoControlDateFieldModel::UnoControlDateFieldModel() +{ + UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXDateField ); +} + +::rtl::OUString UnoControlDateFieldModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlDateFieldModel ); +} + +uno::Any UnoControlDateFieldModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + if ( nPropId == BASEPROPERTY_DEFAULTCONTROL ) + { + uno::Any aAny; + aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlDateField ); + return aAny; + } + return UnoControlModel::ImplGetDefaultValue( nPropId ); +} + + +::cppu::IPropertyArrayHelper& UnoControlDateFieldModel::getInfoHelper() +{ + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + +// beans::XMultiPropertySet +uno::Reference< beans::XPropertySetInfo > UnoControlDateFieldModel::getPropertySetInfo( ) throw(uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + + + +// ---------------------------------------------------- +// class UnoDateFieldControl +// ---------------------------------------------------- +UnoDateFieldControl::UnoDateFieldControl() +{ + mnFirst = Date( 1, 1, 1900 ).GetDate(); + mnLast = Date( 31, 12, 2200 ).GetDate(); + mbLongFormat = 2; +} + +::rtl::OUString UnoDateFieldControl::GetComponentServiceName() +{ + return ::rtl::OUString::createFromAscii( "datefield" ); +} + +// uno::XInterface +uno::Any UnoDateFieldControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) +{ + uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( awt::XDateField*, this ) ); + return (aRet.hasValue() ? aRet : UnoSpinFieldControl::queryAggregation( rType )); +} + +// lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( UnoDateFieldControl ) + getCppuType( ( uno::Reference< awt::XDateField>* ) NULL ), + UnoSpinFieldControl::getTypes() +IMPL_XTYPEPROVIDER_END + +void UnoDateFieldControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) +{ + UnoSpinFieldControl::createPeer( rxToolkit, rParentPeer ); + + uno::Reference < awt::XDateField > xField( getPeer(), uno::UNO_QUERY ); + xField->setFirst( mnFirst ); + xField->setLast( mnLast ); + if ( mbLongFormat != 2 ) // not set + xField->setLongFormat( mbLongFormat ); +} + + +void UnoDateFieldControl::textChanged( const awt::TextEvent& e ) throw(uno::RuntimeException) +{ + uno::Reference< awt::XVclWindowPeer > xPeer( getPeer(), uno::UNO_QUERY ); + + // also change the text property (#i25106#) + if ( xPeer.is() ) + { + ::rtl::OUString sTextPropertyName = GetPropertyName( BASEPROPERTY_TEXT ); + ImplSetPropertyValue( sTextPropertyName, xPeer->getProperty( sTextPropertyName ), sal_False ); + } + + // re-calc the Date property + uno::Reference < awt::XDateField > xField( getPeer(), uno::UNO_QUERY ); + uno::Any aValue; + if ( xField->isEmpty() ) + { + // the field says it's empty + sal_Bool bEnforceFormat = sal_True; + if ( xPeer.is() ) + xPeer->getProperty( GetPropertyName( BASEPROPERTY_ENFORCE_FORMAT ) ) >>= bEnforceFormat; + if ( !bEnforceFormat ) + { + // and it also says that it is currently accepting invalid inputs, without + // forcing it to a valid date + uno::Reference< awt::XTextComponent > xText( xPeer, uno::UNO_QUERY ); + if ( xText.is() && xText->getText().getLength() ) + // and in real, the text of the peer is *not* empty + // -> simulate an invalid date, which is different from "no date" + aValue <<= util::Date( 0, 0, 0 ); + } + } + else + aValue <<= xField->getDate(); + + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_DATE ), aValue, sal_False ); + + // multiplex the event + if ( GetTextListeners().getLength() ) + GetTextListeners().textChanged( e ); +} + +void UnoDateFieldControl::setDate( sal_Int32 Date ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= Date; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_DATE ), aAny, sal_True ); +} + +sal_Int32 UnoDateFieldControl::getDate() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_INT32( BASEPROPERTY_DATE ); +} + +void UnoDateFieldControl::setMin( sal_Int32 Date ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= Date; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_DATEMIN ), aAny, sal_True ); +} + +sal_Int32 UnoDateFieldControl::getMin() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_INT32( BASEPROPERTY_DATEMIN ); +} + +void UnoDateFieldControl::setMax( sal_Int32 Date ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= Date; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_DATEMAX ), aAny, sal_True ); +} + +sal_Int32 UnoDateFieldControl::getMax() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_INT32( BASEPROPERTY_DATEMAX ); +} + +void UnoDateFieldControl::setFirst( sal_Int32 Date ) throw(uno::RuntimeException) +{ + mnFirst = Date; + if ( getPeer().is() ) + { + uno::Reference < awt::XDateField > xField( getPeer(), uno::UNO_QUERY ); + xField->setFirst( Date ); + } +} + +sal_Int32 UnoDateFieldControl::getFirst() throw(uno::RuntimeException) +{ + return mnFirst; +} + +void UnoDateFieldControl::setLast( sal_Int32 Date ) throw(uno::RuntimeException) +{ + mnLast = Date; + if ( getPeer().is() ) + { + uno::Reference < awt::XDateField > xField( getPeer(), uno::UNO_QUERY ); + xField->setLast( Date ); + } +} + +sal_Int32 UnoDateFieldControl::getLast() throw(uno::RuntimeException) +{ + return mnLast; +} + +void UnoDateFieldControl::setLongFormat( sal_Bool bLong ) throw(uno::RuntimeException) +{ + mbLongFormat = bLong; + if ( getPeer().is() ) + { + uno::Reference < awt::XDateField > xField( getPeer(), uno::UNO_QUERY ); + xField->setLongFormat( bLong ); + } +} + +sal_Bool UnoDateFieldControl::isLongFormat() throw(uno::RuntimeException) +{ + return ( mbLongFormat != 2 ) ? mbLongFormat : sal_False; +} + +void UnoDateFieldControl::setEmpty() throw(uno::RuntimeException) +{ + if ( getPeer().is() ) + { + uno::Reference < awt::XDateField > xField( getPeer(), uno::UNO_QUERY ); + xField->setEmpty(); + } +} + +sal_Bool UnoDateFieldControl::isEmpty() throw(uno::RuntimeException) +{ + sal_Bool bEmpty = sal_False; + if ( getPeer().is() ) + { + uno::Reference < awt::XDateField > xField( getPeer(), uno::UNO_QUERY ); + bEmpty = xField->isEmpty(); + } + return bEmpty; +} + +void UnoDateFieldControl::setStrictFormat( sal_Bool bStrict ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= bStrict; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRICTFORMAT ), aAny, sal_True ); +} + +sal_Bool UnoDateFieldControl::isStrictFormat() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_BOOL( BASEPROPERTY_STRICTFORMAT ); +} + +// ---------------------------------------------------- +// class UnoControlTimeFieldModel +// ---------------------------------------------------- +UnoControlTimeFieldModel::UnoControlTimeFieldModel() +{ + UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXTimeField ); +} + +::rtl::OUString UnoControlTimeFieldModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlTimeFieldModel ); +} + +uno::Any UnoControlTimeFieldModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + if ( nPropId == BASEPROPERTY_DEFAULTCONTROL ) + { + uno::Any aAny; + aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlTimeField ); + return aAny; + } + return UnoControlModel::ImplGetDefaultValue( nPropId ); +} + + +::cppu::IPropertyArrayHelper& UnoControlTimeFieldModel::getInfoHelper() +{ + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + +// beans::XMultiPropertySet +uno::Reference< beans::XPropertySetInfo > UnoControlTimeFieldModel::getPropertySetInfo( ) throw(uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + + + +// ---------------------------------------------------- +// class UnoTimeFieldControl +// ---------------------------------------------------- +UnoTimeFieldControl::UnoTimeFieldControl() +{ + mnFirst = Time( 0, 0 ).GetTime(); + mnLast = Time( 23, 59, 59, 99 ).GetTime(); +} + +::rtl::OUString UnoTimeFieldControl::GetComponentServiceName() +{ + return ::rtl::OUString::createFromAscii( "timefield" ); +} + +// uno::XInterface +uno::Any UnoTimeFieldControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) +{ + uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( awt::XTimeField*, this ) ); + return (aRet.hasValue() ? aRet : UnoSpinFieldControl::queryAggregation( rType )); +} + +// lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( UnoTimeFieldControl ) + getCppuType( ( uno::Reference< awt::XTimeField>* ) NULL ), + UnoSpinFieldControl::getTypes() +IMPL_XTYPEPROVIDER_END + +void UnoTimeFieldControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) +{ + UnoSpinFieldControl::createPeer( rxToolkit, rParentPeer ); + + uno::Reference < awt::XTimeField > xField( getPeer(), uno::UNO_QUERY ); + xField->setFirst( mnFirst ); + xField->setLast( mnLast ); +} + +void UnoTimeFieldControl::textChanged( const awt::TextEvent& e ) throw(uno::RuntimeException) +{ + // also change the text property (#i25106#) + uno::Reference< awt::XVclWindowPeer > xPeer( getPeer(), uno::UNO_QUERY ); + ::rtl::OUString sTextPropertyName = GetPropertyName( BASEPROPERTY_TEXT ); + ImplSetPropertyValue( sTextPropertyName, xPeer->getProperty( sTextPropertyName ), sal_False ); + + // re-calc the Time property + uno::Reference < awt::XTimeField > xField( getPeer(), uno::UNO_QUERY ); + uno::Any aValue; + if ( !xField->isEmpty() ) + aValue <<= xField->getTime(); + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TIME ), aValue, sal_False ); + + // multiplex the event + if ( GetTextListeners().getLength() ) + GetTextListeners().textChanged( e ); +} + +void UnoTimeFieldControl::setTime( sal_Int32 Time ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= Time; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TIME ), aAny, sal_True ); +} + +sal_Int32 UnoTimeFieldControl::getTime() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_INT32( BASEPROPERTY_TIME ); +} + +void UnoTimeFieldControl::setMin( sal_Int32 Time ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= Time; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TIMEMIN ), aAny, sal_True ); +} + +sal_Int32 UnoTimeFieldControl::getMin() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_INT32( BASEPROPERTY_TIMEMIN ); +} + +void UnoTimeFieldControl::setMax( sal_Int32 Time ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= Time; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TIMEMAX ), aAny, sal_True ); +} + +sal_Int32 UnoTimeFieldControl::getMax() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_INT32( BASEPROPERTY_TIMEMAX ); +} + +void UnoTimeFieldControl::setFirst( sal_Int32 Time ) throw(uno::RuntimeException) +{ + mnFirst = Time; + if ( getPeer().is() ) + { + uno::Reference < awt::XTimeField > xField( getPeer(), uno::UNO_QUERY ); + xField->setFirst( mnFirst ); + } +} + +sal_Int32 UnoTimeFieldControl::getFirst() throw(uno::RuntimeException) +{ + return mnFirst; +} + +void UnoTimeFieldControl::setLast( sal_Int32 Time ) throw(uno::RuntimeException) +{ + mnLast = Time; + if ( getPeer().is() ) + { + uno::Reference < awt::XTimeField > xField( getPeer(), uno::UNO_QUERY ); + xField->setFirst( mnLast ); + } +} + +sal_Int32 UnoTimeFieldControl::getLast() throw(uno::RuntimeException) +{ + return mnLast; +} + +void UnoTimeFieldControl::setEmpty() throw(uno::RuntimeException) +{ + if ( getPeer().is() ) + { + uno::Reference < awt::XTimeField > xField( getPeer(), uno::UNO_QUERY ); + xField->setEmpty(); + } +} + +sal_Bool UnoTimeFieldControl::isEmpty() throw(uno::RuntimeException) +{ + sal_Bool bEmpty = sal_False; + if ( getPeer().is() ) + { + uno::Reference < awt::XTimeField > xField( getPeer(), uno::UNO_QUERY ); + bEmpty = xField->isEmpty(); + } + return bEmpty; +} + +void UnoTimeFieldControl::setStrictFormat( sal_Bool bStrict ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= bStrict; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRICTFORMAT ), aAny, sal_True ); +} + +sal_Bool UnoTimeFieldControl::isStrictFormat() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_BOOL( BASEPROPERTY_STRICTFORMAT ); +} + +// ---------------------------------------------------- +// class UnoControlNumericFieldModel +// ---------------------------------------------------- +UnoControlNumericFieldModel::UnoControlNumericFieldModel() +{ + UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXNumericField ); +} + +::rtl::OUString UnoControlNumericFieldModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlNumericFieldModel ); +} + +uno::Any UnoControlNumericFieldModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + if ( nPropId == BASEPROPERTY_DEFAULTCONTROL ) + { + uno::Any aAny; + aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlNumericField ); + return aAny; + } + return UnoControlModel::ImplGetDefaultValue( nPropId ); +} + + +::cppu::IPropertyArrayHelper& UnoControlNumericFieldModel::getInfoHelper() +{ + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + +// beans::XMultiPropertySet +uno::Reference< beans::XPropertySetInfo > UnoControlNumericFieldModel::getPropertySetInfo( ) throw(uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + + + +// ---------------------------------------------------- +// class UnoNumericFieldControl +// ---------------------------------------------------- +UnoNumericFieldControl::UnoNumericFieldControl() +{ + mnFirst = 0; + mnLast = 0x7FFFFFFF; +} + +::rtl::OUString UnoNumericFieldControl::GetComponentServiceName() +{ + return ::rtl::OUString::createFromAscii( "numericfield" ); +} + +// uno::XInterface +uno::Any UnoNumericFieldControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) +{ + uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( awt::XNumericField*, this ) ); + return (aRet.hasValue() ? aRet : UnoSpinFieldControl::queryAggregation( rType )); +} + +// lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( UnoNumericFieldControl ) + getCppuType( ( uno::Reference< awt::XNumericField>* ) NULL ), + UnoSpinFieldControl::getTypes() +IMPL_XTYPEPROVIDER_END + +void UnoNumericFieldControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) +{ + UnoSpinFieldControl::createPeer( rxToolkit, rParentPeer ); + + uno::Reference < awt::XNumericField > xField( getPeer(), uno::UNO_QUERY ); + xField->setFirst( mnFirst ); + xField->setLast( mnLast ); +} + + +void UnoNumericFieldControl::textChanged( const awt::TextEvent& e ) throw(uno::RuntimeException) +{ + uno::Reference < awt::XNumericField > xField( getPeer(), uno::UNO_QUERY ); + uno::Any aAny; + aAny <<= xField->getValue(); + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUE_DOUBLE ), aAny, sal_False ); + + if ( GetTextListeners().getLength() ) + GetTextListeners().textChanged( e ); +} + +void UnoNumericFieldControl::setValue( double Value ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= Value; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUE_DOUBLE ), aAny, sal_True ); +} + +double UnoNumericFieldControl::getValue() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUE_DOUBLE ); +} + +void UnoNumericFieldControl::setMin( double Value ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= Value; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUEMIN_DOUBLE ), aAny, sal_True ); +} + +double UnoNumericFieldControl::getMin() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUEMIN_DOUBLE ); +} + +void UnoNumericFieldControl::setMax( double Value ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= Value; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUEMAX_DOUBLE ), aAny, sal_True ); +} + +double UnoNumericFieldControl::getMax() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUEMAX_DOUBLE ); +} + +void UnoNumericFieldControl::setFirst( double Value ) throw(uno::RuntimeException) +{ + mnFirst = Value; + if ( getPeer().is() ) + { + uno::Reference < awt::XNumericField > xField( getPeer(), uno::UNO_QUERY ); + xField->setFirst( mnFirst ); + } +} + +double UnoNumericFieldControl::getFirst() throw(uno::RuntimeException) +{ + return mnFirst; +} + +void UnoNumericFieldControl::setLast( double Value ) throw(uno::RuntimeException) +{ + mnLast = Value; + if ( getPeer().is() ) + { + uno::Reference < awt::XNumericField > xField( getPeer(), uno::UNO_QUERY ); + xField->setLast( mnLast ); + } +} + +double UnoNumericFieldControl::getLast() throw(uno::RuntimeException) +{ + return mnLast; +} + +void UnoNumericFieldControl::setStrictFormat( sal_Bool bStrict ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= bStrict; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRICTFORMAT ), aAny, sal_True ); +} + +sal_Bool UnoNumericFieldControl::isStrictFormat() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_BOOL( BASEPROPERTY_STRICTFORMAT ); +} + +void UnoNumericFieldControl::setSpinSize( double Digits ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= Digits; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUESTEP_DOUBLE ), aAny, sal_True ); +} + +double UnoNumericFieldControl::getSpinSize() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUESTEP_DOUBLE ); +} + +void UnoNumericFieldControl::setDecimalDigits( sal_Int16 Digits ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= Digits; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_DECIMALACCURACY ), aAny, sal_True ); +} + +sal_Int16 UnoNumericFieldControl::getDecimalDigits() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_INT16( BASEPROPERTY_DECIMALACCURACY ); +} + +// ---------------------------------------------------- +// class UnoControlCurrencyFieldModel +// ---------------------------------------------------- +UnoControlCurrencyFieldModel::UnoControlCurrencyFieldModel() +{ + UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXCurrencyField ); +} + +::rtl::OUString UnoControlCurrencyFieldModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlCurrencyFieldModel ); +} + +uno::Any UnoControlCurrencyFieldModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + if ( nPropId == BASEPROPERTY_DEFAULTCONTROL ) + { + uno::Any aAny; + aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlCurrencyField ); + return aAny; + } + if ( nPropId == BASEPROPERTY_CURSYM_POSITION ) + { + uno::Any aAny; + aAny <<= (sal_Bool)sal_False; + return aAny; + } + + return UnoControlModel::ImplGetDefaultValue( nPropId ); +} + +::cppu::IPropertyArrayHelper& UnoControlCurrencyFieldModel::getInfoHelper() +{ + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + +// beans::XMultiPropertySet +uno::Reference< beans::XPropertySetInfo > UnoControlCurrencyFieldModel::getPropertySetInfo( ) throw(uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + +// ---------------------------------------------------- +// class UnoCurrencyFieldControl +// ---------------------------------------------------- +UnoCurrencyFieldControl::UnoCurrencyFieldControl() +{ + mnFirst = 0; + mnLast = 0x7FFFFFFF; +} + +::rtl::OUString UnoCurrencyFieldControl::GetComponentServiceName() +{ + return ::rtl::OUString::createFromAscii( "longcurrencyfield" ); +} + +// uno::XInterface +uno::Any UnoCurrencyFieldControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) +{ + uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( awt::XCurrencyField*, this ) ); + return (aRet.hasValue() ? aRet : UnoSpinFieldControl::queryAggregation( rType )); +} + +// lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( UnoCurrencyFieldControl ) + getCppuType( ( uno::Reference< awt::XCurrencyField>* ) NULL ), + UnoSpinFieldControl::getTypes() +IMPL_XTYPEPROVIDER_END + +void UnoCurrencyFieldControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) +{ + UnoSpinFieldControl::createPeer( rxToolkit, rParentPeer ); + + uno::Reference < awt::XCurrencyField > xField( getPeer(), uno::UNO_QUERY ); + xField->setFirst( mnFirst ); + xField->setLast( mnLast ); +} + +void UnoCurrencyFieldControl::textChanged( const awt::TextEvent& e ) throw(uno::RuntimeException) +{ + uno::Reference < awt::XCurrencyField > xField( getPeer(), uno::UNO_QUERY ); + uno::Any aAny; + aAny <<= xField->getValue(); + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUE_DOUBLE ), aAny, sal_False ); + + if ( GetTextListeners().getLength() ) + GetTextListeners().textChanged( e ); +} + +void UnoCurrencyFieldControl::setValue( double Value ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= Value; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUE_DOUBLE ), aAny, sal_True ); +} + +double UnoCurrencyFieldControl::getValue() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUE_DOUBLE ); +} + +void UnoCurrencyFieldControl::setMin( double Value ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= Value; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUEMIN_DOUBLE ), aAny, sal_True ); +} + +double UnoCurrencyFieldControl::getMin() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUEMIN_DOUBLE ); +} + +void UnoCurrencyFieldControl::setMax( double Value ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= Value; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUEMAX_DOUBLE ), aAny, sal_True ); +} + +double UnoCurrencyFieldControl::getMax() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUEMAX_DOUBLE ); +} + +void UnoCurrencyFieldControl::setFirst( double Value ) throw(uno::RuntimeException) +{ + mnFirst = Value; + if ( getPeer().is() ) + { + uno::Reference < awt::XCurrencyField > xField( getPeer(), uno::UNO_QUERY ); + xField->setFirst( mnFirst ); + } +} + +double UnoCurrencyFieldControl::getFirst() throw(uno::RuntimeException) +{ + return mnFirst; +} + +void UnoCurrencyFieldControl::setLast( double Value ) throw(uno::RuntimeException) +{ + mnLast = Value; + if ( getPeer().is() ) + { + uno::Reference < awt::XCurrencyField > xField( getPeer(), uno::UNO_QUERY ); + xField->setLast( mnLast ); + } +} + +double UnoCurrencyFieldControl::getLast() throw(uno::RuntimeException) +{ + return mnLast; +} + +void UnoCurrencyFieldControl::setStrictFormat( sal_Bool bStrict ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= bStrict; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRICTFORMAT ), aAny, sal_True ); +} + +sal_Bool UnoCurrencyFieldControl::isStrictFormat() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_BOOL( BASEPROPERTY_STRICTFORMAT ); +} + +void UnoCurrencyFieldControl::setSpinSize( double Digits ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= Digits; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VALUESTEP_DOUBLE ), aAny, sal_True ); +} + +double UnoCurrencyFieldControl::getSpinSize() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_DOUBLE( BASEPROPERTY_VALUESTEP_DOUBLE ); +} + +void UnoCurrencyFieldControl::setDecimalDigits( sal_Int16 Digits ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= Digits; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_DECIMALACCURACY ), aAny, sal_True ); +} + +sal_Int16 UnoCurrencyFieldControl::getDecimalDigits() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_INT16( BASEPROPERTY_DECIMALACCURACY ); +} + +// ---------------------------------------------------- +// class UnoControlPatternFieldModel +// ---------------------------------------------------- +UnoControlPatternFieldModel::UnoControlPatternFieldModel() +{ + UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXPatternField ); +} + +::rtl::OUString UnoControlPatternFieldModel::getServiceName() throw(::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlPatternFieldModel ); +} + +uno::Any UnoControlPatternFieldModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + if ( nPropId == BASEPROPERTY_DEFAULTCONTROL ) + { + uno::Any aAny; + aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlPatternField ); + return aAny; + } + return UnoControlModel::ImplGetDefaultValue( nPropId ); +} + +::cppu::IPropertyArrayHelper& UnoControlPatternFieldModel::getInfoHelper() +{ + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + +// beans::XMultiPropertySet +uno::Reference< beans::XPropertySetInfo > UnoControlPatternFieldModel::getPropertySetInfo( ) throw(uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + + +// ---------------------------------------------------- +// class UnoPatternFieldControl +// ---------------------------------------------------- +UnoPatternFieldControl::UnoPatternFieldControl() +{ +} + +::rtl::OUString UnoPatternFieldControl::GetComponentServiceName() +{ + return ::rtl::OUString::createFromAscii( "patternfield" ); +} + +void UnoPatternFieldControl::ImplSetPeerProperty( const ::rtl::OUString& rPropName, const uno::Any& rVal ) +{ + sal_uInt16 nType = GetPropertyId( rPropName ); + if ( ( nType == BASEPROPERTY_TEXT ) || ( nType == BASEPROPERTY_EDITMASK ) || ( nType == BASEPROPERTY_LITERALMASK ) ) + { + // Die Masken koennen nicht nacheinander gesetzt werden. + ::rtl::OUString Text = ImplGetPropertyValue_UString( BASEPROPERTY_TEXT ); + ::rtl::OUString EditMask = ImplGetPropertyValue_UString( BASEPROPERTY_EDITMASK ); + ::rtl::OUString LiteralMask = ImplGetPropertyValue_UString( BASEPROPERTY_LITERALMASK ); + + uno::Reference < awt::XPatternField > xPF( getPeer(), uno::UNO_QUERY ); + if (xPF.is()) + { + // same comment as in UnoControl::ImplSetPeerProperty - see there + ::rtl::OUString sText( Text ); + ImplCheckLocalize( sText ); + xPF->setString( sText ); + xPF->setMasks( EditMask, LiteralMask ); + } + } + else + UnoSpinFieldControl::ImplSetPeerProperty( rPropName, rVal ); +} + + +// uno::XInterface +uno::Any UnoPatternFieldControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) +{ + uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( awt::XPatternField*, this ) ); + return (aRet.hasValue() ? aRet : UnoSpinFieldControl::queryAggregation( rType )); +} + +// lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( UnoPatternFieldControl ) + getCppuType( ( uno::Reference< awt::XPatternField>* ) NULL ), + UnoSpinFieldControl::getTypes() +IMPL_XTYPEPROVIDER_END + +void UnoPatternFieldControl::setString( const ::rtl::OUString& rString ) throw(uno::RuntimeException) +{ + setText( rString ); +} + +::rtl::OUString UnoPatternFieldControl::getString() throw(uno::RuntimeException) +{ + return getText(); +} + +void UnoPatternFieldControl::setMasks( const ::rtl::OUString& EditMask, const ::rtl::OUString& LiteralMask ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= EditMask; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_EDITMASK ), aAny, sal_True ); + aAny <<= LiteralMask; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LITERALMASK ), aAny, sal_True ); +} + +void UnoPatternFieldControl::getMasks( ::rtl::OUString& EditMask, ::rtl::OUString& LiteralMask ) throw(uno::RuntimeException) +{ + EditMask = ImplGetPropertyValue_UString( BASEPROPERTY_EDITMASK ); + LiteralMask = ImplGetPropertyValue_UString( BASEPROPERTY_LITERALMASK ); +} + +void UnoPatternFieldControl::setStrictFormat( sal_Bool bStrict ) throw(uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= bStrict; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_STRICTFORMAT ), aAny, sal_True ); +} + +sal_Bool UnoPatternFieldControl::isStrictFormat() throw(uno::RuntimeException) +{ + return ImplGetPropertyValue_BOOL( BASEPROPERTY_STRICTFORMAT ); +} + + +// ---------------------------------------------------- +// class UnoControlProgressBarModel +// ---------------------------------------------------- +UnoControlProgressBarModel::UnoControlProgressBarModel() +{ + ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR ); + ImplRegisterProperty( BASEPROPERTY_BORDER ); + ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR ); + ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL ); + ImplRegisterProperty( BASEPROPERTY_ENABLED ); + ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE ); + ImplRegisterProperty( BASEPROPERTY_FILLCOLOR ); + ImplRegisterProperty( BASEPROPERTY_HELPTEXT ); + ImplRegisterProperty( BASEPROPERTY_HELPURL ); + ImplRegisterProperty( BASEPROPERTY_PRINTABLE ); + ImplRegisterProperty( BASEPROPERTY_PROGRESSVALUE ); + ImplRegisterProperty( BASEPROPERTY_PROGRESSVALUE_MAX ); + ImplRegisterProperty( BASEPROPERTY_PROGRESSVALUE_MIN ); +} + +::rtl::OUString UnoControlProgressBarModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlProgressBarModel ); +} + +uno::Any UnoControlProgressBarModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + if ( nPropId == BASEPROPERTY_DEFAULTCONTROL ) + { + uno::Any aAny; + aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlProgressBar ); + return aAny; + } + + return UnoControlModel::ImplGetDefaultValue( nPropId ); +} + +::cppu::IPropertyArrayHelper& UnoControlProgressBarModel::getInfoHelper() +{ + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + +// beans::XMultiPropertySet +uno::Reference< beans::XPropertySetInfo > UnoControlProgressBarModel::getPropertySetInfo( ) throw(uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + + +// ---------------------------------------------------- +// class UnoProgressBarControl +// ---------------------------------------------------- +UnoProgressBarControl::UnoProgressBarControl() +{ +} + +::rtl::OUString UnoProgressBarControl::GetComponentServiceName() +{ + return ::rtl::OUString::createFromAscii( "ProgressBar" ); +} + +// uno::XInterface +uno::Any UnoProgressBarControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) +{ + uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( awt::XProgressBar*, this ) ); + return (aRet.hasValue() ? aRet : UnoControlBase::queryAggregation( rType )); +} + +// lang::XTypeProvider +IMPL_XTYPEPROVIDER_START( UnoProgressBarControl ) + getCppuType( ( uno::Reference< awt::XProgressBar>* ) NULL ), + UnoControlBase::getTypes() +IMPL_XTYPEPROVIDER_END + +// ::com::sun::star::awt::XProgressBar +void UnoProgressBarControl::setForegroundColor( sal_Int32 nColor ) throw(::com::sun::star::uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= nColor; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_FILLCOLOR ), aAny, sal_True ); +} + +void UnoProgressBarControl::setBackgroundColor( sal_Int32 nColor ) throw(::com::sun::star::uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= nColor; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_BACKGROUNDCOLOR ), aAny, sal_True ); +} + +void UnoProgressBarControl::setValue( sal_Int32 nValue ) throw(::com::sun::star::uno::RuntimeException) +{ + uno::Any aAny; + aAny <<= nValue; + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_PROGRESSVALUE ), aAny, sal_True ); +} + +void UnoProgressBarControl::setRange( sal_Int32 nMin, sal_Int32 nMax ) throw(::com::sun::star::uno::RuntimeException ) +{ + uno::Any aMin; + uno::Any aMax; + + if ( nMin < nMax ) + { + // take correct min and max + aMin <<= nMin; + aMax <<= nMax; + } + else + { + // change min and max + aMin <<= nMax; + aMax <<= nMin; + } + + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_PROGRESSVALUE_MIN ), aMin, sal_True ); + ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_PROGRESSVALUE_MAX ), aMax, sal_True ); +} + +sal_Int32 UnoProgressBarControl::getValue() throw(::com::sun::star::uno::RuntimeException) +{ + return ImplGetPropertyValue_INT32( BASEPROPERTY_PROGRESSVALUE ); +} + + +// ---------------------------------------------------- +// class UnoControlFixedLineModel +// ---------------------------------------------------- +UnoControlFixedLineModel::UnoControlFixedLineModel() +{ + ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR ); + ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL ); + ImplRegisterProperty( BASEPROPERTY_ENABLED ); + ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE ); + ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR ); + ImplRegisterProperty( BASEPROPERTY_HELPTEXT ); + ImplRegisterProperty( BASEPROPERTY_HELPURL ); + ImplRegisterProperty( BASEPROPERTY_LABEL ); + ImplRegisterProperty( BASEPROPERTY_ORIENTATION ); + ImplRegisterProperty( BASEPROPERTY_PRINTABLE ); +} + +::rtl::OUString UnoControlFixedLineModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString::createFromAscii( szServiceName_UnoControlFixedLineModel ); +} + +uno::Any UnoControlFixedLineModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const +{ + if ( nPropId == BASEPROPERTY_DEFAULTCONTROL ) + { + uno::Any aAny; + aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlFixedLine ); + return aAny; + } + return UnoControlModel::ImplGetDefaultValue( nPropId ); +} + +::cppu::IPropertyArrayHelper& UnoControlFixedLineModel::getInfoHelper() +{ + static UnoPropertyArrayHelper* pHelper = NULL; + if ( !pHelper ) + { + uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); + pHelper = new UnoPropertyArrayHelper( aIDs ); + } + return *pHelper; +} + +// beans::XMultiPropertySet +uno::Reference< beans::XPropertySetInfo > UnoControlFixedLineModel::getPropertySetInfo( ) throw(uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} + +// ---------------------------------------------------- +// class UnoFixedLineControl +// ---------------------------------------------------- +UnoFixedLineControl::UnoFixedLineControl() +{ + maComponentInfos.nWidth = 100; // ?? + maComponentInfos.nHeight = 100; // ?? +} + +::rtl::OUString UnoFixedLineControl::GetComponentServiceName() +{ + return ::rtl::OUString::createFromAscii( "FixedLine" ); +} + +sal_Bool UnoFixedLineControl::isTransparent() throw(uno::RuntimeException) +{ + return sal_True; +} diff --git a/toolkit/source/helper/accessibilityclient.cxx b/toolkit/source/helper/accessibilityclient.cxx new file mode 100644 index 000000000000..ba466ac6959d --- /dev/null +++ b/toolkit/source/helper/accessibilityclient.cxx @@ -0,0 +1,277 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <toolkit/helper/accessibilityclient.hxx> +#include <toolkit/helper/accessiblefactory.hxx> +#include <osl/module.h> +#include <osl/diagnose.h> +#include <tools/solar.h> + +// #define UNLOAD_ON_LAST_CLIENT_DYING + // this is not recommended currently. If enabled, the implementation will log + // the number of active clients, and unload the acc library when the last client + // goes away. + // Sounds like a good idea, unfortunately, there's no guarantee that all objects + // implemented in this library are already dead. + // Iow, just because an object implementing an XAccessible (implemented in this lib + // here) died, it's not said that everybody released all references to the + // XAccessibleContext used by this component, and implemented in the acc lib. + // So we cannot really unload the lib. + // + // Alternatively, if the lib would us own "usage counting", i.e. every component + // implemented therein would affect a static ref count, the acc lib could care + // for unloading itself. + +//........................................................................ +namespace toolkit +{ +//........................................................................ + + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::accessibility; + + namespace + { +#ifdef UNLOAD_ON_LAST_CLIENT_DYING + static oslInterlockedCount s_nAccessibilityClients = 0; +#endif // UNLOAD_ON_LAST_CLIENT_DYING + static oslModule s_hAccessibleImplementationModule = NULL; + static GetStandardAccComponentFactory s_pAccessibleFactoryFunc = NULL; + static ::rtl::Reference< IAccessibleFactory > s_pFactory; + } + + //==================================================================== + //= AccessibleDummyFactory + //==================================================================== + class AccessibleDummyFactory : public IAccessibleFactory + { + public: + AccessibleDummyFactory(); + + protected: + virtual ~AccessibleDummyFactory(); + + private: + AccessibleDummyFactory( const AccessibleDummyFactory& ); // never implemented + AccessibleDummyFactory& operator=( const AccessibleDummyFactory& ); // never implemented + + oslInterlockedCount m_refCount; + + public: + // IReference + virtual oslInterlockedCount SAL_CALL acquire(); + virtual oslInterlockedCount SAL_CALL release(); + + // IAccessibleFactory + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > + createAccessibleContext( VCLXButton* /*_pXWindow*/ ) + { + return NULL; + } + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > + createAccessibleContext( VCLXCheckBox* /*_pXWindow*/ ) + { + return NULL; + } + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > + createAccessibleContext( VCLXRadioButton* /*_pXWindow*/ ) + { + return NULL; + } + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > + createAccessibleContext( VCLXListBox* /*_pXWindow*/ ) + { + return NULL; + } + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > + createAccessibleContext( VCLXFixedHyperlink* /*_pXWindow*/ ) + { + return NULL; + } + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > + createAccessibleContext( VCLXFixedText* /*_pXWindow*/ ) + { + return NULL; + } + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > + createAccessibleContext( VCLXScrollBar* /*_pXWindow*/ ) + { + return NULL; + } + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > + createAccessibleContext( VCLXEdit* /*_pXWindow*/ ) + { + return NULL; + } + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > + createAccessibleContext( VCLXComboBox* /*_pXWindow*/ ) + { + return NULL; + } + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > + createAccessibleContext( VCLXToolBox* /*_pXWindow*/ ) + { + return NULL; + } + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > + createAccessibleContext( VCLXWindow* /*_pXWindow*/ ) + { + return NULL; + } + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > + createAccessible( Menu* /*_pMenu*/, sal_Bool /*_bIsMenuBar*/ ) + { + return NULL; + } + }; + + //-------------------------------------------------------------------- + AccessibleDummyFactory::AccessibleDummyFactory() + { + } + + //-------------------------------------------------------------------- + AccessibleDummyFactory::~AccessibleDummyFactory() + { + } + + //-------------------------------------------------------------------- + oslInterlockedCount SAL_CALL AccessibleDummyFactory::acquire() + { + return osl_incrementInterlockedCount( &m_refCount ); + } + + //-------------------------------------------------------------------- + oslInterlockedCount SAL_CALL AccessibleDummyFactory::release() + { + if ( 0 == osl_decrementInterlockedCount( &m_refCount ) ) + { + delete this; + return 0; + } + return m_refCount; + } + + //==================================================================== + //= AccessibilityClient + //==================================================================== + //-------------------------------------------------------------------- + AccessibilityClient::AccessibilityClient() + :m_bInitialized( false ) + { + } + + //-------------------------------------------------------------------- + extern "C" { static void SAL_CALL thisModule() {} } + + void AccessibilityClient::ensureInitialized() + { + if ( m_bInitialized ) + return; + + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + +#ifdef UNLOAD_ON_LAST_CLIENT_DYING + if ( 1 == osl_incrementInterlockedCount( &s_nAccessibilityClients ) ) + { // the first client +#endif // UNLOAD_ON_LAST_CLIENT_DYING + // load the library implementing the factory + if ( !s_pFactory.get() ) + { + const ::rtl::OUString sModuleName = ::rtl::OUString::createFromAscii( + SVLIBRARY( "acc" ) + ); + s_hAccessibleImplementationModule = osl_loadModuleRelative( &thisModule, sModuleName.pData, 0 ); + if ( s_hAccessibleImplementationModule != NULL ) + { + const ::rtl::OUString sFactoryCreationFunc = + ::rtl::OUString::createFromAscii( "getStandardAccessibleFactory" ); + s_pAccessibleFactoryFunc = (GetStandardAccComponentFactory) + osl_getFunctionSymbol( s_hAccessibleImplementationModule, sFactoryCreationFunc.pData ); + + } + OSL_ENSURE( s_pAccessibleFactoryFunc, "AccessibilityClient::ensureInitialized: could not load the library, or not retrieve the needed symbol!" ); + + // get a factory instance + if ( s_pAccessibleFactoryFunc ) + { + IAccessibleFactory* pFactory = static_cast< IAccessibleFactory* >( (*s_pAccessibleFactoryFunc)() ); + OSL_ENSURE( pFactory, "AccessibilityClient::ensureInitialized: no factory provided by the A11Y lib!" ); + if ( pFactory ) + { + s_pFactory = pFactory; + pFactory->release(); + } + } + } + + if ( !s_pFactory.get() ) + // the attempt to load the lib, or to create the factory, failed + // -> fall back to a dummy factory + s_pFactory = new AccessibleDummyFactory; +#ifdef UNLOAD_ON_LAST_CLIENT_DYING + } +#endif + + m_bInitialized = true; + } + + //-------------------------------------------------------------------- + AccessibilityClient::~AccessibilityClient() + { + if ( m_bInitialized ) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + +#ifdef UNLOAD_ON_LAST_CLIENT_DYING + if( 0 == osl_decrementInterlockedCount( &s_nAccessibilityClients ) ) + { + s_pFactory = NULL; + s_pAccessibleFactoryFunc = NULL; + if ( s_hAccessibleImplementationModule ) + { + osl_unloadModule( s_hAccessibleImplementationModule ); + s_hAccessibleImplementationModule = NULL; + } + } +#endif // UNLOAD_ON_LAST_CLIENT_DYING + } + } + + //-------------------------------------------------------------------- + IAccessibleFactory& AccessibilityClient::getFactory() + { + ensureInitialized(); + OSL_ENSURE( s_pFactory.is(), "AccessibilityClient::getFactory: at least a dummy factory should have been created!" ); + return *s_pFactory; + } + +//........................................................................ +} // namespace toolkit +//........................................................................ diff --git a/toolkit/source/helper/externallock.cxx b/toolkit/source/helper/externallock.cxx new file mode 100644 index 000000000000..c0eb2427936f --- /dev/null +++ b/toolkit/source/helper/externallock.cxx @@ -0,0 +1,46 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <toolkit/helper/externallock.hxx> +#include <vos/mutex.hxx> +#include <vcl/svapp.hxx> + +// ----------------------------------------------------------------------------- +// class VCLExternalSolarLock +// ----------------------------------------------------------------------------- +void VCLExternalSolarLock::acquire() +{ + Application::GetSolarMutex().acquire(); +} +// ----------------------------------------------------------------------------- +void VCLExternalSolarLock::release() +{ + Application::GetSolarMutex().release(); +} + diff --git a/toolkit/source/helper/fixedhyperbase.cxx b/toolkit/source/helper/fixedhyperbase.cxx new file mode 100644 index 000000000000..d6c22e936116 --- /dev/null +++ b/toolkit/source/helper/fixedhyperbase.cxx @@ -0,0 +1,72 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + +#include <toolkit/helper/fixedhyperbase.hxx> + +//........................................................................ +namespace toolkit +{ +//........................................................................ + +// ---------------------------------------------------- +// class FixedHyperlinkBase +// ---------------------------------------------------- + +FixedHyperlinkBase::FixedHyperlinkBase( Window* pParent, const ResId& rId ) : + FixedText( pParent, rId ) +{ +} + +FixedHyperlinkBase::FixedHyperlinkBase( Window* pParent, WinBits nWinStyle ) : + FixedText( pParent, nWinStyle ) +{ +} + +FixedHyperlinkBase::~FixedHyperlinkBase() +{ +} + +void FixedHyperlinkBase::SetURL( const String& ) +{ +} + +String FixedHyperlinkBase::GetURL() const +{ + return String::EmptyString(); +} + +void FixedHyperlinkBase::SetDescription( const String& ) +{ +} + +//........................................................................ +} // namespace toolkit +//........................................................................ + diff --git a/toolkit/source/helper/formpdfexport.cxx b/toolkit/source/helper/formpdfexport.cxx new file mode 100644 index 000000000000..bff2d6008d10 --- /dev/null +++ b/toolkit/source/helper/formpdfexport.cxx @@ -0,0 +1,639 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + +#ifndef _TOOLKIT_HELPER_FORM_FORMPDFEXPORT_HXX +#include <toolkit/helper/formpdfexport.hxx> +#endif + +/** === begin UNO includes === **/ +#ifndef _COM_SUN_STAR_CONTAINER_XINDEXACCESS_HPP_ +#include <com/sun/star/container/XIndexAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_ +#include <com/sun/star/container/XNameAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_ +#include <com/sun/star/container/XNameContainer.hpp> +#endif +#ifndef _COM_SUN_STAR_FORM_XFORM_HPP_ +#include <com/sun/star/form/XForm.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_ +#include <com/sun/star/container/XChild.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include <com/sun/star/lang/XServiceInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_ +#include <com/sun/star/beans/XPropertySet.hpp> +#endif +#ifndef _COM_SUN_STAR_FORM_FORMCOMPONENTTYPE_HPP_ +#include <com/sun/star/form/FormComponentType.hpp> +#endif +#ifndef _COM_SUN_STAR_AWT_TEXTALIGN_HPP_ +#include <com/sun/star/awt/TextAlign.hpp> +#endif +#ifndef _COM_SUN_STAR_STYLE_VERTICALALIGNMENT_HPP_ +#include <com/sun/star/style/VerticalAlignment.hpp> +#endif +#ifndef _COM_SUN_STAR_FORM_FORMBUTTONTYPE_HPP_ +#include <com/sun/star/form/FormButtonType.hpp> +#endif +#ifndef _COM_SUN_STAR_FORM_SUBMITMETHOD_HPP_ +#include <com/sun/star/form/FormSubmitMethod.hpp> +#endif +/** === end UNO includes === **/ + +#ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_ +#include <toolkit/helper/vclunohelper.hxx> +#endif +#ifndef _VCL_PDFEXTOUTDEVDATA_HXX +#include <vcl/pdfextoutdevdata.hxx> +#endif +#ifndef _SV_OUTDEV_HXX +#include <vcl/outdev.hxx> +#endif + +#include <functional> +#include <algorithm> + +//........................................................................ +namespace toolkitform +{ +//........................................................................ + + using namespace ::com::sun::star; + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::awt; + using namespace ::com::sun::star::style; + using namespace ::com::sun::star::beans; + using namespace ::com::sun::star::form; + using namespace ::com::sun::star::lang; + using namespace ::com::sun::star::container; + + // used strings + static const ::rtl::OUString FM_PROP_CLASSID(RTL_CONSTASCII_USTRINGPARAM("ClassId")); + static const ::rtl::OUString FM_PROP_NAME(RTL_CONSTASCII_USTRINGPARAM("Name")); + static const ::rtl::OUString FM_PROP_STRINGITEMLIST(RTL_CONSTASCII_USTRINGPARAM("StringItemList")); + static const ::rtl::OUString FM_PROP_HELPTEXT(RTL_CONSTASCII_USTRINGPARAM("HelpText")); + static const ::rtl::OUString FM_PROP_TEXT(RTL_CONSTASCII_USTRINGPARAM("Text")); + static const ::rtl::OUString FM_PROP_LABEL(RTL_CONSTASCII_USTRINGPARAM("Label")); + static const ::rtl::OUString FM_PROP_READONLY(RTL_CONSTASCII_USTRINGPARAM("ReadOnly")); + static const ::rtl::OUString FM_PROP_BORDER(RTL_CONSTASCII_USTRINGPARAM("Border")); + static const ::rtl::OUString FM_PROP_BACKGROUNDCOLOR(RTL_CONSTASCII_USTRINGPARAM("BackgroundColor")); + static const ::rtl::OUString FM_PROP_TEXTCOLOR(RTL_CONSTASCII_USTRINGPARAM("TextColor")); + static const ::rtl::OUString FM_PROP_MULTILINE(RTL_CONSTASCII_USTRINGPARAM("MultiLine")); + static const ::rtl::OUString FM_PROP_ALIGN(RTL_CONSTASCII_USTRINGPARAM("Align")); + static const ::rtl::OUString FM_PROP_FONT(RTL_CONSTASCII_USTRINGPARAM("FontDescriptor")); + static const ::rtl::OUString FM_PROP_MAXTEXTLEN(RTL_CONSTASCII_USTRINGPARAM("MaxTextLen")); + static const ::rtl::OUString FM_PROP_TARGET_URL(RTL_CONSTASCII_USTRINGPARAM("TargetURL")); + static const ::rtl::OUString FM_PROP_STATE(RTL_CONSTASCII_USTRINGPARAM("State")); + static const ::rtl::OUString FM_PROP_REFVALUE(RTL_CONSTASCII_USTRINGPARAM("RefValue")); + static const ::rtl::OUString FM_PROP_DROPDOWN(RTL_CONSTASCII_USTRINGPARAM("Dropdown")); + static const ::rtl::OUString FM_SUN_COMPONENT_FILECONTROL(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.FileControl")); + + namespace + { + //-------------------------------------------------------------------- + /** determines the FormComponentType of a form control + */ + sal_Int16 classifyFormControl( const Reference< XPropertySet >& _rxModel ) SAL_THROW(( Exception )) + { + sal_Int16 nControlType = FormComponentType::CONTROL; + + Reference< XPropertySetInfo > xPSI; + if ( _rxModel.is() ) + xPSI = _rxModel->getPropertySetInfo(); + if ( xPSI.is() && xPSI->hasPropertyByName( FM_PROP_CLASSID ) ) + { + OSL_VERIFY( _rxModel->getPropertyValue( FM_PROP_CLASSID ) >>= nControlType ); + } + + return nControlType; + } + + //-------------------------------------------------------------------- + /** (default-)creates a PDF widget according to a given FormComponentType + */ + ::vcl::PDFWriter::AnyWidget* createDefaultWidget( sal_Int16 _nFormComponentType ) + { + switch ( _nFormComponentType ) + { + case FormComponentType::COMMANDBUTTON: + return new ::vcl::PDFWriter::PushButtonWidget; + case FormComponentType::CHECKBOX: + return new ::vcl::PDFWriter::CheckBoxWidget; + case FormComponentType::RADIOBUTTON: + return new ::vcl::PDFWriter::RadioButtonWidget; + case FormComponentType::LISTBOX: + return new ::vcl::PDFWriter::ListBoxWidget; + case FormComponentType::COMBOBOX: + return new ::vcl::PDFWriter::ComboBoxWidget; + + case FormComponentType::TEXTFIELD: + case FormComponentType::FILECONTROL: + case FormComponentType::DATEFIELD: + case FormComponentType::TIMEFIELD: + case FormComponentType::NUMERICFIELD: + case FormComponentType::CURRENCYFIELD: + case FormComponentType::PATTERNFIELD: + return new ::vcl::PDFWriter::EditWidget; + } + return NULL; + } + + //-------------------------------------------------------------------- + /** determines a unique number for the radio group which the given radio + button model belongs to + + The number is guaranteed to be + <ul><li>unique within the document in which the button lives</li> + <li>the same for subsequent calls with other radio button models, + which live in the same document, and belong to the same group</li> + </ul> + + @precond + the model must be part of the form component hierarchy in a document + */ + sal_Int32 determineRadioGroupId( const Reference< XPropertySet >& _rxRadioModel ) SAL_THROW((Exception)) + { + OSL_ENSURE( classifyFormControl( _rxRadioModel ) == FormComponentType::RADIOBUTTON, + "determineRadioGroupId: this *is* no radio button model!" ); + // The fact that radio button groups need to be unique within the complete + // host document makes it somewhat difficult ... + // Problem is that two form radio buttons belong to the same group if + // - they have the same parent + // - AND they have the same name + // This implies that we need some knowledge about (potentially) *all* radio button + // groups in the document. + + // get the root-level container + Reference< XChild > xChild( _rxRadioModel, UNO_QUERY ); + Reference< XForm > xParentForm( xChild.is() ? xChild->getParent() : Reference< XInterface >(), UNO_QUERY ); + OSL_ENSURE( xParentForm.is(), "determineRadioGroupId: no parent form -> group id!" ); + if ( !xParentForm.is() ) + return -1; + + while ( xParentForm.is() ) + { + xChild = xParentForm.get(); + xParentForm = xParentForm.query( xChild->getParent() ); + } + Reference< XIndexAccess > xRoot( xChild->getParent(), UNO_QUERY ); + OSL_ENSURE( xRoot.is(), "determineRadioGroupId: unable to determine the root of the form component hierarchy!" ); + if ( !xRoot.is() ) + return -1; + + // count the leafs in the hierarchy, until we encounter radio button + ::std::vector< Reference< XIndexAccess > > aAncestors; + ::std::vector< sal_Int32 > aPath; + + Reference< XInterface > xNormalizedLookup( _rxRadioModel, UNO_QUERY ); + ::rtl::OUString sRadioGroupName; + OSL_VERIFY( _rxRadioModel->getPropertyValue( FM_PROP_NAME ) >>= sRadioGroupName ); + + Reference< XIndexAccess > xCurrentContainer( xRoot ); + sal_Int32 nStartWithChild = 0; + sal_Int32 nGroupsEncountered = 0; + do + { + Reference< XNameAccess > xElementNameAccess( xCurrentContainer, UNO_QUERY ); + OSL_ENSURE( xElementNameAccess.is(), "determineRadioGroupId: no name container?" ); + if ( !xElementNameAccess.is() ) + return -1; + + if ( nStartWithChild == 0 ) + { // we encounter this container the first time. In particular, we did not + // just step up + nGroupsEncountered += xElementNameAccess->getElementNames().getLength(); + // this is way too much: Not all of the elements in the current container + // may form groups, especially if they're forms. But anyway, this number is + // sufficient for our purpose. Finally, the container contains *at most* + // that much groups + } + + sal_Int32 nCount = xCurrentContainer->getCount(); + sal_Int32 i; + for ( i = nStartWithChild; i < nCount; ++i ) + { + Reference< XInterface > xElement( xCurrentContainer->getByIndex( i ), UNO_QUERY ); + if ( !xElement.is() ) + { + OSL_ENSURE( sal_False, "determineRadioGroupId: very suspicious!" ); + continue; + } + + Reference< XIndexAccess > xNewContainer( xElement, UNO_QUERY ); + if ( xNewContainer.is() ) + { + // step down the hierarchy + aAncestors.push_back( xCurrentContainer ); + xCurrentContainer = xNewContainer; + aPath.push_back( i ); + nStartWithChild = 0; + break; + // out of the inner loop, but continue with the outer loop + } + + if ( xElement.get() == xNormalizedLookup.get() ) + { + // look up the name of the radio group in the list of all element names + Sequence< ::rtl::OUString > aElementNames( xElementNameAccess->getElementNames() ); + const ::rtl::OUString* pElementNames = aElementNames.getConstArray(); + const ::rtl::OUString* pElementNamesEnd = pElementNames + aElementNames.getLength(); + while ( pElementNames != pElementNamesEnd ) + { + if ( *pElementNames == sRadioGroupName ) + { + sal_Int32 nLocalGroupIndex = pElementNames - aElementNames.getConstArray(); + OSL_ENSURE( nLocalGroupIndex < xElementNameAccess->getElementNames().getLength(), + "determineRadioGroupId: inconsistency!" ); + + sal_Int32 nGlobalGroupId = nGroupsEncountered - xElementNameAccess->getElementNames().getLength() + nLocalGroupIndex; + return nGlobalGroupId; + } + ++pElementNames; + } + OSL_ENSURE( sal_False, "determineRadioGroupId: did not find the radios element name!" ); + } + } + + if ( !( i < nCount ) ) + { + // the loop terminated because there were no more elements + // -> step up, if possible + if ( aAncestors.empty() ) + break; + + xCurrentContainer = aAncestors.back(); aAncestors.pop_back(); + nStartWithChild = aPath.back() + 1; aPath.pop_back(); + } + } + while ( true ); + return -1; + } + + //-------------------------------------------------------------------- + /** copies a StringItemList to a PDF widget's list + */ + void getStringItemVector( const Reference< XPropertySet >& _rxModel, ::std::vector< ::rtl::OUString >& _rVector ) + { + Sequence< ::rtl::OUString > aListEntries; + OSL_VERIFY( _rxModel->getPropertyValue( FM_PROP_STRINGITEMLIST ) >>= aListEntries ); + ::std::copy( aListEntries.getConstArray(), aListEntries.getConstArray() + aListEntries.getLength(), + ::std::back_insert_iterator< ::std::vector< ::rtl::OUString > >( _rVector ) ); + } + } + + //-------------------------------------------------------------------- + /** creates a PDF compatible control descriptor for the given control + */ + void TOOLKIT_DLLPUBLIC describePDFControl( const Reference< XControl >& _rxControl, ::std::auto_ptr< ::vcl::PDFWriter::AnyWidget >& _rpDescriptor ) SAL_THROW(()) + { + _rpDescriptor.reset( NULL ); + OSL_ENSURE( _rxControl.is(), "describePDFControl: invalid (NULL) control!" ); + if ( !_rxControl.is() ) + return; + + try + { + Reference< XPropertySet > xModelProps( _rxControl->getModel(), UNO_QUERY ); + sal_Int16 nControlType = classifyFormControl( xModelProps ); + _rpDescriptor.reset( createDefaultWidget( nControlType ) ); + if ( !_rpDescriptor.get() ) + // no PDF widget available for this + return; + + Reference< XPropertySetInfo > xPSI( xModelProps->getPropertySetInfo() ); + Reference< XServiceInfo > xSI( xModelProps, UNO_QUERY ); + OSL_ENSURE( xSI.is(), "describePDFControl: no service info!" ); + // if we survived classifyFormControl, then it's a real form control, and they all have + // service infos + + // ================================ + // set the common widget properties + + // -------------------------------- + // Name, Description, Text + OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_NAME ) >>= _rpDescriptor->Name ); + OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_HELPTEXT ) >>= _rpDescriptor->Description ); + Any aText; + if ( xPSI->hasPropertyByName( FM_PROP_TEXT ) ) + aText = xModelProps->getPropertyValue( FM_PROP_TEXT ); + else if ( xPSI->hasPropertyByName( FM_PROP_LABEL ) ) + aText = xModelProps->getPropertyValue( FM_PROP_LABEL ); + if ( aText.hasValue() ) + OSL_VERIFY( aText >>= _rpDescriptor->Text ); + + // -------------------------------- + // readonly + if ( xPSI->hasPropertyByName( FM_PROP_READONLY ) ) + OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_READONLY ) >>= _rpDescriptor->ReadOnly ); + + // -------------------------------- + // border + { + if ( xPSI->hasPropertyByName( FM_PROP_BORDER ) ) + { + sal_Int16 nBorderType = 0; + OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_BORDER ) >>= nBorderType ); + _rpDescriptor->Border = ( nBorderType != 0 ); + + ::rtl::OUString sBorderColorPropertyName( RTL_CONSTASCII_USTRINGPARAM( "BorderColor" ) ); + if ( xPSI->hasPropertyByName( sBorderColorPropertyName ) ) + { + sal_Int32 nBoderColor = COL_TRANSPARENT; + if ( xModelProps->getPropertyValue( sBorderColorPropertyName ) >>= nBoderColor ) + _rpDescriptor->BorderColor = Color( nBoderColor ); + else + _rpDescriptor->BorderColor = Color( COL_BLACK ); + } + } + } + + // -------------------------------- + // background color + if ( xPSI->hasPropertyByName( FM_PROP_BACKGROUNDCOLOR ) ) + { + sal_Int32 nBackColor = COL_TRANSPARENT; + xModelProps->getPropertyValue( FM_PROP_BACKGROUNDCOLOR ) >>= nBackColor; + _rpDescriptor->Background = true; + _rpDescriptor->BackgroundColor = Color( nBackColor ); + } + + // -------------------------------- + // text color + if ( xPSI->hasPropertyByName( FM_PROP_TEXTCOLOR ) ) + { + sal_Int32 nTextColor = COL_TRANSPARENT; + xModelProps->getPropertyValue( FM_PROP_TEXTCOLOR ) >>= nTextColor; + _rpDescriptor->TextColor = Color( nTextColor ); + } + + // -------------------------------- + // text style + _rpDescriptor->TextStyle = 0; + // ............................ + // multi line and word break + // The MultiLine property of the control is mapped to both the "MULTILINE" and + // "WORDBREAK" style flags + if ( xPSI->hasPropertyByName( FM_PROP_MULTILINE ) ) + { + sal_Bool bMultiLine = sal_False; + OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_MULTILINE ) >>= bMultiLine ); + if ( bMultiLine ) + _rpDescriptor->TextStyle |= TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK; + } + // ............................ + // horizontal alignment + if ( xPSI->hasPropertyByName( FM_PROP_ALIGN ) ) + { + sal_Int16 nAlign = awt::TextAlign::LEFT; + xModelProps->getPropertyValue( FM_PROP_ALIGN ) >>= nAlign; + // TODO: when the property is VOID - are there situations/UIs where this + // means something else than LEFT? + switch ( nAlign ) + { + case awt::TextAlign::LEFT: _rpDescriptor->TextStyle |= TEXT_DRAW_LEFT; break; + case awt::TextAlign::CENTER: _rpDescriptor->TextStyle |= TEXT_DRAW_CENTER; break; + case awt::TextAlign::RIGHT: _rpDescriptor->TextStyle |= TEXT_DRAW_RIGHT; break; + default: + OSL_ENSURE( sal_False, "describePDFControl: invalid text align!" ); + } + } + // ............................ + // vertical alignment + { + ::rtl::OUString sVertAlignPropertyName( RTL_CONSTASCII_USTRINGPARAM( "VerticalAlign" ) ); + if ( xPSI->hasPropertyByName( sVertAlignPropertyName ) ) + { + sal_Int16 nAlign = VerticalAlignment_MIDDLE; + xModelProps->getPropertyValue( sVertAlignPropertyName ) >>= nAlign; + switch ( nAlign ) + { + case VerticalAlignment_TOP: _rpDescriptor->TextStyle |= TEXT_DRAW_TOP; break; + case VerticalAlignment_MIDDLE: _rpDescriptor->TextStyle |= TEXT_DRAW_VCENTER; break; + case VerticalAlignment_BOTTOM: _rpDescriptor->TextStyle |= TEXT_DRAW_BOTTOM; break; + default: + OSL_ENSURE( sal_False, "describePDFControl: invalid vertical text align!" ); + } + } + } + + // font + if ( xPSI->hasPropertyByName( FM_PROP_FONT ) ) + { + FontDescriptor aUNOFont; + OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_FONT ) >>= aUNOFont ); + _rpDescriptor->TextFont = VCLUnoHelper::CreateFont( aUNOFont, Font() ); + } + + // tab order + rtl::OUString aTabIndexString( RTL_CONSTASCII_USTRINGPARAM( "TabIndex" ) ); + if ( xPSI->hasPropertyByName( aTabIndexString ) ) + { + sal_Int16 nIndex = -1; + OSL_VERIFY( xModelProps->getPropertyValue( aTabIndexString ) >>= nIndex ); + _rpDescriptor->TabOrder = nIndex; + } + + // ================================ + // special widget properties + // -------------------------------- + // edits + if ( _rpDescriptor->getType() == ::vcl::PDFWriter::Edit ) + { + ::vcl::PDFWriter::EditWidget* pEditWidget = static_cast< ::vcl::PDFWriter::EditWidget* >( _rpDescriptor.get() ); + // ............................ + // multiline (already flagged in the TextStyle) + pEditWidget->MultiLine = ( _rpDescriptor->TextStyle & TEXT_DRAW_MULTILINE ) != 0; + // ............................ + // password input + ::rtl::OUString sEchoCharPropName( RTL_CONSTASCII_USTRINGPARAM( "EchoChar" ) ); + if ( xPSI->hasPropertyByName( sEchoCharPropName ) ) + { + sal_Int16 nEchoChar = 0; + if ( ( xModelProps->getPropertyValue( sEchoCharPropName ) >>= nEchoChar ) && ( nEchoChar != 0 ) ) + pEditWidget->Password = true; + } + // ............................ + // file select + if ( xSI->supportsService( FM_SUN_COMPONENT_FILECONTROL ) ) + pEditWidget->FileSelect = true; + // ............................ + // maximum text length + if ( xPSI->hasPropertyByName( FM_PROP_MAXTEXTLEN ) ) + { + sal_Int16 nMaxTextLength = 0; + OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_MAXTEXTLEN ) >>= nMaxTextLength ); + if ( nMaxTextLength <= 0 ) + // "-1" has a special meaning for database-bound controls + nMaxTextLength = 0; + pEditWidget->MaxLen = nMaxTextLength; + } + } + + // -------------------------------- + // buttons + if ( _rpDescriptor->getType() == ::vcl::PDFWriter::PushButton ) + { + ::vcl::PDFWriter::PushButtonWidget* pButtonWidget = static_cast< ::vcl::PDFWriter::PushButtonWidget* >( _rpDescriptor.get() ); + FormButtonType eButtonType = FormButtonType_PUSH; + OSL_VERIFY( xModelProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ButtonType" ) ) ) >>= eButtonType ); + if ( eButtonType == FormButtonType_SUBMIT ) + { + // if a button is a submit button, then it uses the URL at it's parent form + Reference< XChild > xChild( xModelProps, UNO_QUERY ); + Reference < XPropertySet > xParentProps; + if ( xChild.is() ) + xParentProps = xParentProps.query( xChild->getParent() ); + if ( xParentProps.is() ) + { + Reference< XServiceInfo > xParentSI( xParentProps, UNO_QUERY ); + if ( xParentSI.is() && xParentSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.component.HTMLForm" ) ) ) ) + { + OSL_VERIFY( xParentProps->getPropertyValue( FM_PROP_TARGET_URL ) >>= pButtonWidget->URL ); + pButtonWidget->Submit = true; + FormSubmitMethod eMethod = FormSubmitMethod_POST; + OSL_VERIFY( xParentProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SubmitMethod" ) ) ) >>= eMethod ); + pButtonWidget->SubmitGet = (eMethod == FormSubmitMethod_GET); + } + } + } + else if ( eButtonType == FormButtonType_URL ) + { + OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_TARGET_URL ) >>= pButtonWidget->URL); + pButtonWidget->Submit = false; + } + + // TODO: + // In PDF files, buttons are either reset, url or submit buttons. So if we have a simple PUSH button + // in a document, then this means that we do not export a SubmitToURL, which means that in PDF, + // the button is used as reset button. + // Is this desired? If no, we would have to reset _rpDescriptor to NULL here, in case eButtonType + // != FormButtonType_SUBMIT && != FormButtonType_RESET + + // the PDF exporter defaults the text style, if 0. To prevent this, we have to transfer the UNO + // defaults to the PDF widget + if ( !pButtonWidget->TextStyle ) + pButtonWidget->TextStyle = TEXT_DRAW_CENTER | TEXT_DRAW_VCENTER; + } + + // -------------------------------- + // check boxes + if ( _rpDescriptor->getType() == ::vcl::PDFWriter::CheckBox ) + { + ::vcl::PDFWriter::CheckBoxWidget* pCheckBoxWidget = static_cast< ::vcl::PDFWriter::CheckBoxWidget* >( _rpDescriptor.get() ); + sal_Int16 nState = 0; + OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_STATE ) >>= nState ); + pCheckBoxWidget->Checked = ( nState != 0 ); + } + + // -------------------------------- + // radio buttons + if ( _rpDescriptor->getType() == ::vcl::PDFWriter::RadioButton ) + { + ::vcl::PDFWriter::RadioButtonWidget* pRadioWidget = static_cast< ::vcl::PDFWriter::RadioButtonWidget* >( _rpDescriptor.get() ); + sal_Int16 nState = 0; + OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_STATE ) >>= nState ); + pRadioWidget->Selected = ( nState != 0 ); + pRadioWidget->RadioGroup = determineRadioGroupId( xModelProps ); + try + { + xModelProps->getPropertyValue( FM_PROP_REFVALUE ) >>= pRadioWidget->OnValue; + } + catch(...) + { + pRadioWidget->OnValue = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "On" ) ); + } + } + + // -------------------------------- + // list boxes + if ( _rpDescriptor->getType() == ::vcl::PDFWriter::ListBox ) + { + ::vcl::PDFWriter::ListBoxWidget* pListWidget = static_cast< ::vcl::PDFWriter::ListBoxWidget* >( _rpDescriptor.get() ); + // ............................ + // drop down + OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_DROPDOWN ) >>= pListWidget->DropDown ); + // ............................ + // multi selection + OSL_VERIFY( xModelProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MultiSelection" ) ) ) >>= pListWidget->MultiSelect ); + // ............................ + // entries + getStringItemVector( xModelProps, pListWidget->Entries ); + // since we explicitly list the entries in the order in which they appear, they should not be + // resorted by the PDF viewer + pListWidget->Sort = false; + + // get selected items + Sequence< sal_Int16 > aSelectIndices; + OSL_VERIFY( xModelProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SelectedItems" ) ) ) >>= aSelectIndices ); + if( aSelectIndices.getLength() > 0 ) + { + pListWidget->SelectedEntries.resize( 0 ); + for( sal_Int32 i = 0; i < aSelectIndices.getLength(); i++ ) + { + sal_Int16 nIndex = aSelectIndices.getConstArray()[i]; + if( nIndex >= 0 && nIndex < (sal_Int16)pListWidget->Entries.size() ) + pListWidget->SelectedEntries.push_back( nIndex ); + } + } + } + + // -------------------------------- + // combo boxes + if ( _rpDescriptor->getType() == ::vcl::PDFWriter::ComboBox ) + { + ::vcl::PDFWriter::ComboBoxWidget* pComboWidget = static_cast< ::vcl::PDFWriter::ComboBoxWidget* >( _rpDescriptor.get() ); + // ............................ + // entries + getStringItemVector( xModelProps, pComboWidget->Entries ); + // same reasoning as above + pComboWidget->Sort = false; + } + + // ================================ + // some post-processing + // -------------------------------- + // text line ends + // some controls may (always or dependent on other settings) return UNIX line ends + String aConverter( _rpDescriptor->Text ); + _rpDescriptor->Text = aConverter.ConvertLineEnd( LINEEND_CRLF ); + } + catch( const Exception& ) + { + OSL_ENSURE( sal_False, "describePDFControl: caught an exception!" ); + } + } + +//........................................................................ +} // namespace toolkitform +//........................................................................ diff --git a/toolkit/source/helper/imagealign.cxx b/toolkit/source/helper/imagealign.cxx new file mode 100644 index 000000000000..c5e8781d478b --- /dev/null +++ b/toolkit/source/helper/imagealign.cxx @@ -0,0 +1,135 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <toolkit/helper/imagealign.hxx> +#include <com/sun/star/awt/ImagePosition.hpp> +#include <com/sun/star/awt/ImageAlign.hpp> + +//........................................................................ +namespace toolkit +{ +//........................................................................ + + using namespace ::com::sun::star::awt::ImagePosition; + using namespace ::com::sun::star::awt::ImageAlign; + + sal_Int16 translateImagePosition( ImageAlign _eVCLAlign ) + { + sal_Int16 nReturn = AboveCenter; + switch ( _eVCLAlign ) + { + case IMAGEALIGN_LEFT: nReturn = LeftCenter; break; + case IMAGEALIGN_TOP: nReturn = AboveCenter; break; + case IMAGEALIGN_RIGHT: nReturn = RightCenter; break; + case IMAGEALIGN_BOTTOM: nReturn = BelowCenter; break; + case IMAGEALIGN_LEFT_TOP: nReturn = LeftTop; break; + case IMAGEALIGN_LEFT_BOTTOM: nReturn = LeftBottom; break; + case IMAGEALIGN_TOP_LEFT: nReturn = AboveLeft; break; + case IMAGEALIGN_TOP_RIGHT: nReturn = AboveRight; break; + case IMAGEALIGN_RIGHT_TOP: nReturn = RightTop; break; + case IMAGEALIGN_RIGHT_BOTTOM: nReturn = RightBottom; break; + case IMAGEALIGN_BOTTOM_LEFT: nReturn = BelowLeft; break; + case IMAGEALIGN_BOTTOM_RIGHT: nReturn = BelowRight; break; + case IMAGEALIGN_CENTER: nReturn = Centered; break; + default: + OSL_ENSURE( sal_False, "translateImagePosition: unknown IMAGEALIGN value!" ); + } + return nReturn; + } + + ImageAlign translateImagePosition( sal_Int16 _eUNOAlign ) + { + ImageAlign nReturn = IMAGEALIGN_TOP; + switch ( _eUNOAlign ) + { + case LeftCenter: nReturn = IMAGEALIGN_LEFT; break; + case AboveCenter: nReturn = IMAGEALIGN_TOP; break; + case RightCenter: nReturn = IMAGEALIGN_RIGHT; break; + case BelowCenter: nReturn = IMAGEALIGN_BOTTOM; break; + case LeftTop: nReturn = IMAGEALIGN_LEFT_TOP; break; + case LeftBottom: nReturn = IMAGEALIGN_LEFT_BOTTOM; break; + case AboveLeft: nReturn = IMAGEALIGN_TOP_LEFT; break; + case AboveRight: nReturn = IMAGEALIGN_TOP_RIGHT; break; + case RightTop: nReturn = IMAGEALIGN_RIGHT_TOP; break; + case RightBottom: nReturn = IMAGEALIGN_RIGHT_BOTTOM; break; + case BelowLeft: nReturn = IMAGEALIGN_BOTTOM_LEFT; break; + case BelowRight: nReturn = IMAGEALIGN_BOTTOM_RIGHT; break; + case Centered: nReturn = IMAGEALIGN_CENTER; break; + default: + OSL_ENSURE( sal_False, "translateImagePosition: unknown css.awt.ImagePosition value!" ); + } + return nReturn; + } + + sal_Int16 getCompatibleImageAlign( ImageAlign _eAlign ) + { + sal_Int16 nReturn = TOP; + switch ( _eAlign ) + { + case IMAGEALIGN_LEFT_TOP: + case IMAGEALIGN_LEFT: + case IMAGEALIGN_LEFT_BOTTOM: nReturn = LEFT; break; + + case IMAGEALIGN_TOP_LEFT: + case IMAGEALIGN_TOP: + case IMAGEALIGN_TOP_RIGHT: nReturn = TOP; break; + + case IMAGEALIGN_RIGHT_TOP: + case IMAGEALIGN_RIGHT: + case IMAGEALIGN_RIGHT_BOTTOM: nReturn = RIGHT; break; + + case IMAGEALIGN_BOTTOM_LEFT: + case IMAGEALIGN_BOTTOM: + case IMAGEALIGN_BOTTOM_RIGHT: nReturn = BOTTOM; break; + + case IMAGEALIGN_CENTER: nReturn = TOP; break; + default: + OSL_ENSURE( sal_False, "getCompatibleImageAlign: unknown IMAGEALIGN value!" ); + } + return nReturn; + } + + sal_Int16 getExtendedImagePosition( sal_Int16 _nImageAlign ) + { + sal_Int16 nReturn = AboveCenter; + switch ( _nImageAlign ) + { + case LEFT: nReturn = LeftCenter; break; + case TOP: nReturn = AboveCenter; break; + case RIGHT: nReturn = RightCenter; break; + case BOTTOM: nReturn = BelowCenter; break; + default: + OSL_ENSURE( sal_False, "getExtendedImagePosition: unknown ImageAlign value!" ); + } + return nReturn; + } + +//........................................................................ +} // namespace toolkit +//........................................................................ diff --git a/toolkit/source/helper/listenermultiplexer.cxx b/toolkit/source/helper/listenermultiplexer.cxx new file mode 100644 index 000000000000..fcfd6214780e --- /dev/null +++ b/toolkit/source/helper/listenermultiplexer.cxx @@ -0,0 +1,208 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +//#include "precompiled_toolkit.hxx" +#include "precompiled_toolkit.hxx" +#include <toolkit/helper/listenermultiplexer.hxx> +#include <com/sun/star/lang/DisposedException.hpp> + +// ---------------------------------------------------- +// class ListenerMultiplexerBase +// ---------------------------------------------------- +ListenerMultiplexerBase::ListenerMultiplexerBase( ::cppu::OWeakObject& rSource ) + : ::cppu::OInterfaceContainerHelper( GetMutex() ), mrContext( rSource ) +{ +} + +ListenerMultiplexerBase::~ListenerMultiplexerBase() +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any ListenerMultiplexerBase::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + return ::cppu::queryInterface( rType, SAL_STATIC_CAST( ::com::sun::star::uno::XInterface*, this ) ); +} + + +// ---------------------------------------------------- +// class EventListenerMultiplexer +// ---------------------------------------------------- +EventListenerMultiplexer::EventListenerMultiplexer( ::cppu::OWeakObject& rSource ) + : ListenerMultiplexerBase( rSource ) +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any EventListenerMultiplexer::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::lang::XEventListener*, this ) ); + return (aRet.hasValue() ? aRet : ListenerMultiplexerBase::queryInterface( rType )); +} + +// ::com::sun::star::lang::XEventListener +void EventListenerMultiplexer::disposing( const ::com::sun::star::lang::EventObject& ) throw(::com::sun::star::uno::RuntimeException) +{ +} + +// ---------------------------------------------------- +// class FocusListenerMultiplexer +// ---------------------------------------------------- +IMPL_LISTENERMULTIPLEXER_BASEMETHODS( FocusListenerMultiplexer, ::com::sun::star::awt::XFocusListener ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( FocusListenerMultiplexer, ::com::sun::star::awt::XFocusListener, focusGained, ::com::sun::star::awt::FocusEvent ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( FocusListenerMultiplexer, ::com::sun::star::awt::XFocusListener, focusLost, ::com::sun::star::awt::FocusEvent ) + +// ---------------------------------------------------- +// class WindowListenerMultiplexer +// ---------------------------------------------------- +IMPL_LISTENERMULTIPLEXER_BASEMETHODS( WindowListenerMultiplexer, ::com::sun::star::awt::XWindowListener ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( WindowListenerMultiplexer, ::com::sun::star::awt::XWindowListener, windowResized, ::com::sun::star::awt::WindowEvent ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( WindowListenerMultiplexer, ::com::sun::star::awt::XWindowListener, windowMoved, ::com::sun::star::awt::WindowEvent ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( WindowListenerMultiplexer, ::com::sun::star::awt::XWindowListener, windowShown, ::com::sun::star::lang::EventObject ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( WindowListenerMultiplexer, ::com::sun::star::awt::XWindowListener, windowHidden, ::com::sun::star::lang::EventObject ) + +// ---------------------------------------------------- +// class VclContainerListenerMultiplexer +// ---------------------------------------------------- +IMPL_LISTENERMULTIPLEXER_BASEMETHODS( VclContainerListenerMultiplexer, ::com::sun::star::awt::XVclContainerListener ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( VclContainerListenerMultiplexer, ::com::sun::star::awt::XVclContainerListener, windowAdded, ::com::sun::star::awt::VclContainerEvent ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( VclContainerListenerMultiplexer, ::com::sun::star::awt::XVclContainerListener, windowRemoved, ::com::sun::star::awt::VclContainerEvent ) + +// ---------------------------------------------------- +// class KeyListenerMultiplexer +// ---------------------------------------------------- +IMPL_LISTENERMULTIPLEXER_BASEMETHODS( KeyListenerMultiplexer, ::com::sun::star::awt::XKeyListener ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( KeyListenerMultiplexer, ::com::sun::star::awt::XKeyListener, keyPressed, ::com::sun::star::awt::KeyEvent ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( KeyListenerMultiplexer, ::com::sun::star::awt::XKeyListener, keyReleased, ::com::sun::star::awt::KeyEvent ) + +// ---------------------------------------------------- +// class MouseListenerMultiplexer +// ---------------------------------------------------- +IMPL_LISTENERMULTIPLEXER_BASEMETHODS( MouseListenerMultiplexer, ::com::sun::star::awt::XMouseListener ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( MouseListenerMultiplexer, ::com::sun::star::awt::XMouseListener, mousePressed, ::com::sun::star::awt::MouseEvent ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( MouseListenerMultiplexer, ::com::sun::star::awt::XMouseListener, mouseReleased, ::com::sun::star::awt::MouseEvent ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( MouseListenerMultiplexer, ::com::sun::star::awt::XMouseListener, mouseEntered, ::com::sun::star::awt::MouseEvent ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( MouseListenerMultiplexer, ::com::sun::star::awt::XMouseListener, mouseExited, ::com::sun::star::awt::MouseEvent ) + +// ---------------------------------------------------- +// class MouseMotionListenerMultiplexer +// ---------------------------------------------------- +IMPL_LISTENERMULTIPLEXER_BASEMETHODS( MouseMotionListenerMultiplexer, ::com::sun::star::awt::XMouseMotionListener ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( MouseMotionListenerMultiplexer, ::com::sun::star::awt::XMouseMotionListener, mouseDragged, ::com::sun::star::awt::MouseEvent ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( MouseMotionListenerMultiplexer, ::com::sun::star::awt::XMouseMotionListener, mouseMoved, ::com::sun::star::awt::MouseEvent ) + +// ---------------------------------------------------- +// class PaintListenerMultiplexer +// ---------------------------------------------------- +IMPL_LISTENERMULTIPLEXER_BASEMETHODS( PaintListenerMultiplexer, ::com::sun::star::awt::XPaintListener ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( PaintListenerMultiplexer, ::com::sun::star::awt::XPaintListener, windowPaint, ::com::sun::star::awt::PaintEvent ) + +// ---------------------------------------------------- +// class TopWindowListenerMultiplexer +// ---------------------------------------------------- +IMPL_LISTENERMULTIPLEXER_BASEMETHODS( TopWindowListenerMultiplexer, ::com::sun::star::awt::XTopWindowListener ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( TopWindowListenerMultiplexer, ::com::sun::star::awt::XTopWindowListener, windowOpened, ::com::sun::star::lang::EventObject ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( TopWindowListenerMultiplexer, ::com::sun::star::awt::XTopWindowListener, windowClosing, ::com::sun::star::lang::EventObject ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( TopWindowListenerMultiplexer, ::com::sun::star::awt::XTopWindowListener, windowClosed, ::com::sun::star::lang::EventObject ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( TopWindowListenerMultiplexer, ::com::sun::star::awt::XTopWindowListener, windowMinimized, ::com::sun::star::lang::EventObject ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( TopWindowListenerMultiplexer, ::com::sun::star::awt::XTopWindowListener, windowNormalized, ::com::sun::star::lang::EventObject ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( TopWindowListenerMultiplexer, ::com::sun::star::awt::XTopWindowListener, windowActivated, ::com::sun::star::lang::EventObject ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( TopWindowListenerMultiplexer, ::com::sun::star::awt::XTopWindowListener, windowDeactivated, ::com::sun::star::lang::EventObject ) + +// ---------------------------------------------------- +// class TextListenerMultiplexer +// ---------------------------------------------------- +IMPL_LISTENERMULTIPLEXER_BASEMETHODS( TextListenerMultiplexer, ::com::sun::star::awt::XTextListener ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( TextListenerMultiplexer, ::com::sun::star::awt::XTextListener, textChanged, ::com::sun::star::awt::TextEvent ) + +// ---------------------------------------------------- +// class ActionListenerMultiplexer +// ---------------------------------------------------- +IMPL_LISTENERMULTIPLEXER_BASEMETHODS( ActionListenerMultiplexer, ::com::sun::star::awt::XActionListener ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( ActionListenerMultiplexer, ::com::sun::star::awt::XActionListener, actionPerformed, ::com::sun::star::awt::ActionEvent ) + +// ---------------------------------------------------- +// class ItemListenerMultiplexer +// ---------------------------------------------------- +IMPL_LISTENERMULTIPLEXER_BASEMETHODS( ItemListenerMultiplexer, ::com::sun::star::awt::XItemListener ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( ItemListenerMultiplexer, ::com::sun::star::awt::XItemListener, itemStateChanged, ::com::sun::star::awt::ItemEvent ) + +// ---------------------------------------------------- +// class ContainerListenerMultiplexer +// ---------------------------------------------------- +IMPL_LISTENERMULTIPLEXER_BASEMETHODS( ContainerListenerMultiplexer, ::com::sun::star::container::XContainerListener ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( ContainerListenerMultiplexer, ::com::sun::star::container::XContainerListener, elementInserted, ::com::sun::star::container::ContainerEvent ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( ContainerListenerMultiplexer, ::com::sun::star::container::XContainerListener, elementRemoved, ::com::sun::star::container::ContainerEvent ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( ContainerListenerMultiplexer, ::com::sun::star::container::XContainerListener, elementReplaced, ::com::sun::star::container::ContainerEvent ) + +// ---------------------------------------------------- +// class SpinListenerMultiplexer +// ---------------------------------------------------- +IMPL_LISTENERMULTIPLEXER_BASEMETHODS( SpinListenerMultiplexer, ::com::sun::star::awt::XSpinListener ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( SpinListenerMultiplexer, ::com::sun::star::awt::XSpinListener, up, ::com::sun::star::awt::SpinEvent ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( SpinListenerMultiplexer, ::com::sun::star::awt::XSpinListener, down, ::com::sun::star::awt::SpinEvent ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( SpinListenerMultiplexer, ::com::sun::star::awt::XSpinListener, first, ::com::sun::star::awt::SpinEvent ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( SpinListenerMultiplexer, ::com::sun::star::awt::XSpinListener, last, ::com::sun::star::awt::SpinEvent ) + +// ---------------------------------------------------- +// class AdjustmentListenerMultiplexer +// ---------------------------------------------------- +IMPL_LISTENERMULTIPLEXER_BASEMETHODS( AdjustmentListenerMultiplexer, ::com::sun::star::awt::XAdjustmentListener ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( AdjustmentListenerMultiplexer, ::com::sun::star::awt::XAdjustmentListener, adjustmentValueChanged, ::com::sun::star::awt::AdjustmentEvent ) + +// ---------------------------------------------------- +// class MenuListenerMultiplexer +// ---------------------------------------------------- +IMPL_LISTENERMULTIPLEXER_BASEMETHODS( MenuListenerMultiplexer, ::com::sun::star::awt::XMenuListener ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( MenuListenerMultiplexer, ::com::sun::star::awt::XMenuListener, highlight, ::com::sun::star::awt::MenuEvent ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( MenuListenerMultiplexer, ::com::sun::star::awt::XMenuListener, select, ::com::sun::star::awt::MenuEvent ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( MenuListenerMultiplexer, ::com::sun::star::awt::XMenuListener, activate, ::com::sun::star::awt::MenuEvent ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( MenuListenerMultiplexer, ::com::sun::star::awt::XMenuListener, deactivate, ::com::sun::star::awt::MenuEvent ) + +// ---------------------------------------------------- +// class TreeSelectionListenerMultiplexer +// ---------------------------------------------------- +IMPL_LISTENERMULTIPLEXER_BASEMETHODS( TreeSelectionListenerMultiplexer, ::com::sun::star::view::XSelectionChangeListener ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( TreeSelectionListenerMultiplexer, ::com::sun::star::view::XSelectionChangeListener, selectionChanged, ::com::sun::star::lang::EventObject ) + +// ---------------------------------------------------- +// class TreeSelectionListenerMultiplexer +// ---------------------------------------------------- +IMPL_LISTENERMULTIPLEXER_BASEMETHODS( TreeExpansionListenerMultiplexer, ::com::sun::star::awt::tree::XTreeExpansionListener ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( TreeExpansionListenerMultiplexer, ::com::sun::star::awt::tree::XTreeExpansionListener, requestChildNodes, ::com::sun::star::awt::tree::TreeExpansionEvent ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD_EXCEPTION( TreeExpansionListenerMultiplexer, ::com::sun::star::awt::tree::XTreeExpansionListener, treeExpanding, ::com::sun::star::awt::tree::TreeExpansionEvent, ::com::sun::star::awt::tree::ExpandVetoException ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD_EXCEPTION( TreeExpansionListenerMultiplexer, ::com::sun::star::awt::tree::XTreeExpansionListener, treeCollapsing, ::com::sun::star::awt::tree::TreeExpansionEvent, ::com::sun::star::awt::tree::ExpandVetoException ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( TreeExpansionListenerMultiplexer, ::com::sun::star::awt::tree::XTreeExpansionListener, treeExpanded, ::com::sun::star::awt::tree::TreeExpansionEvent ) +IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD( TreeExpansionListenerMultiplexer, ::com::sun::star::awt::tree::XTreeExpansionListener, treeCollapsed, ::com::sun::star::awt::tree::TreeExpansionEvent ) + +// ---------------------------------------------------- +// class TreeEditListenerMultiplexer +// ---------------------------------------------------- +IMPL_LISTENERMULTIPLEXER_BASEMETHODS( TreeEditListenerMultiplexer, ::com::sun::star::awt::tree::XTreeEditListener ) + diff --git a/toolkit/source/helper/makefile.mk b/toolkit/source/helper/makefile.mk new file mode 100644 index 000000000000..bf10b0aa0178 --- /dev/null +++ b/toolkit/source/helper/makefile.mk @@ -0,0 +1,64 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=toolkit +TARGET=helper + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +.INCLUDE : $(PRJ)$/util$/makefile.pmk + + +# --- Files -------------------------------------------------------- + +SLOFILES= \ + $(SLO)$/listenermultiplexer.obj \ + $(SLO)$/property.obj \ + $(SLO)$/registerservices.obj \ + $(SLO)$/servicenames.obj \ + $(SLO)$/tkresmgr.obj \ + $(SLO)$/unomemorystream.obj \ + $(SLO)$/unopropertyarrayhelper.obj \ + $(SLO)$/unowrapper.obj \ + $(SLO)$/vclunohelper.obj \ + $(SLO)$/externallock.obj \ + $(SLO)$/imagealign.obj \ + $(SLO)$/throbberimpl.obj \ + $(SLO)$/formpdfexport.obj \ + $(SLO)$/accessibilityclient.obj \ + $(SLO)$/fixedhyperbase.obj + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + diff --git a/toolkit/source/helper/property.cxx b/toolkit/source/helper/property.cxx new file mode 100644 index 000000000000..7ede81d485d7 --- /dev/null +++ b/toolkit/source/helper/property.cxx @@ -0,0 +1,399 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + + +#include <toolkit/helper/property.hxx> +#include <toolkit/helper/macros.hxx> +#include <osl/mutex.hxx> + +#include <stdlib.h> // qsort/bsearch +#include <tools/debug.hxx> +#include <com/sun/star/awt/FontWeight.hpp> +#include <com/sun/star/awt/FontSlant.hpp> +#include <com/sun/star/awt/CharSet.hpp> +#include <com/sun/star/awt/FontDescriptor.hpp> +#include <com/sun/star/awt/FontWidth.hpp> +#include <com/sun/star/awt/FontType.hpp> +#include <com/sun/star/awt/FontUnderline.hpp> +#include <com/sun/star/awt/FontStrikeout.hpp> +#include <com/sun/star/awt/FontPitch.hpp> +#include <com/sun/star/awt/XDevice.hpp> +#include <com/sun/star/awt/tree/XTreeDataModel.hpp> +#include <com/sun/star/awt/grid/XGridDataModel.hpp> +#include <com/sun/star/awt/grid/XGridColumnModel.hpp> +#include <com/sun/star/awt/grid/ScrollBarMode.hpp> +#include <com/sun/star/view/SelectionType.hpp> +#include <com/sun/star/style/VerticalAlignment.hpp> +#include <com/sun/star/util/XNumberFormatsSupplier.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> +#include <com/sun/star/resource/XStringResourceResolver.hpp> +#include <comphelper/types.hxx> +#include <functional> +#include <algorithm> +#include <toolkit/helper/property.hxx> + +using ::com::sun::star::uno::Any; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::awt::XDevice; +using ::com::sun::star::awt::FontDescriptor; +using ::com::sun::star::style::VerticalAlignment; + +struct ImplPropertyInfo +{ + ::rtl::OUString aName; + sal_uInt16 nPropId; + ::com::sun::star::uno::Type aType; + sal_Int16 nAttribs; + sal_Bool bDependsOnOthers; // eg. VALUE depends on MIN/MAX and must be set after MIN/MAX. + + ImplPropertyInfo() + { + nPropId = 0; + nAttribs = 0; + bDependsOnOthers = sal_False; + } + + ImplPropertyInfo( const sal_Unicode* pName, sal_uInt16 nId, const ::com::sun::star::uno::Type& rType, + sal_Int16 nAttrs, sal_Bool bDepends = sal_False ) + : aName( pName ) + { + nPropId = nId; + aType = rType; + nAttribs = nAttrs; + bDependsOnOthers = bDepends; + } + +}; + +#define DECL_PROP_1( asciiname, id, type, attrib1 ) \ + ImplPropertyInfo( ::rtl::OUString::createFromAscii( asciiname ), BASEPROPERTY_##id, ::getCppuType( static_cast< const type* >( NULL ) ), ::com::sun::star::beans::PropertyAttribute::attrib1 ) +#define DECL_PROP_2( asciiname, id, type, attrib1, attrib2 ) \ + ImplPropertyInfo( ::rtl::OUString::createFromAscii( asciiname ), BASEPROPERTY_##id, ::getCppuType( static_cast< const type* >( NULL ) ), ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2 ) +#define DECL_PROP_3( asciiname, id, type, attrib1, attrib2, attrib3 ) \ + ImplPropertyInfo( ::rtl::OUString::createFromAscii( asciiname ), BASEPROPERTY_##id, ::getCppuType( static_cast< const type* >( NULL ) ), ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2 | ::com::sun::star::beans::PropertyAttribute::attrib3 ) +#define DECL_PROP_4( asciiname, id, type, attrib1, attrib2, attrib3, attrib4 ) \ + ImplPropertyInfo( ::rtl::OUString::createFromAscii( asciiname ), BASEPROPERTY_##id, ::getCppuType( static_cast< const type* >( NULL ) ), ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2 | ::com::sun::star::beans::PropertyAttribute::attrib3 | ::com::sun::star::beans::PropertyAttribute::attrib4 ) + +#define DECL_DEP_PROP_1( asciiname, id, type, attrib1 ) \ + ImplPropertyInfo( ::rtl::OUString::createFromAscii( asciiname ), BASEPROPERTY_##id, ::getCppuType( static_cast< const type* >( NULL ) ), ::com::sun::star::beans::PropertyAttribute::attrib1, sal_True ) +#define DECL_DEP_PROP_2( asciiname, id, type, attrib1, attrib2 ) \ + ImplPropertyInfo( ::rtl::OUString::createFromAscii( asciiname ), BASEPROPERTY_##id, ::getCppuType( static_cast< const type* >( NULL ) ), ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2, sal_True ) +#define DECL_DEP_PROP_3( asciiname, id, type, attrib1, attrib2, attrib3 ) \ + ImplPropertyInfo( ::rtl::OUString::createFromAscii( asciiname ), BASEPROPERTY_##id, ::getCppuType( static_cast< const type* >( NULL ) ), ::com::sun::star::beans::PropertyAttribute::attrib1 | ::com::sun::star::beans::PropertyAttribute::attrib2 | ::com::sun::star::beans::PropertyAttribute::attrib3, sal_True ) + +ImplPropertyInfo* ImplGetPropertyInfos( sal_uInt16& rElementCount ) +{ + static ImplPropertyInfo* pPropertyInfos = NULL; + static sal_uInt16 nElements = 0; + if( !pPropertyInfos ) + { + ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !pPropertyInfos ) + { + static ImplPropertyInfo __FAR_DATA aImplPropertyInfos [] = + { + DECL_PROP_2 ( "AccessibleName", ACCESSIBLENAME, ::rtl::OUString, BOUND, MAYBEDEFAULT ), + DECL_PROP_3 ( "Align", ALIGN, sal_Int16, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_2 ( "Autocomplete", AUTOCOMPLETE, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "AutoHScroll", AUTOHSCROLL, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_1 ( "AutoMnemonics", AUTOMNEMONICS, bool, BOUND ), + DECL_PROP_2 ( "AutoToggle", AUTOTOGGLE, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "AutoVScroll", AUTOVSCROLL, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_3 ( "BackgroundColor", BACKGROUNDCOLOR, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_DEP_PROP_2 ( "BlockIncrement", BLOCKINCREMENT, sal_Int32, BOUND, MAYBEDEFAULT ), + DECL_PROP_3 ( "Border", BORDER, sal_Int16, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_DEP_PROP_3 ( "BorderColor", BORDERCOLOR, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_2 ( "Closeable", CLOSEABLE, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "CurrencySymbol", CURRENCYSYMBOL, ::rtl::OUString, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "CustomUnitText", CUSTOMUNITTEXT, ::rtl::OUString, BOUND, MAYBEDEFAULT ), + DECL_DEP_PROP_3 ( "Date", DATE, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_2 ( "DateFormat", EXTDATEFORMAT, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "DateMax", DATEMAX, sal_Int32, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "DateMin", DATEMIN, sal_Int32, BOUND, MAYBEDEFAULT ), + DECL_PROP_3 ( "DateShowCentury", DATESHOWCENTURY, bool, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_2 ( "DecimalAccuracy", DECIMALACCURACY, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "DefaultButton", DEFAULTBUTTON, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "DefaultControl", DEFAULTCONTROL, ::rtl::OUString, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "DesktopAsParent", DESKTOP_AS_PARENT, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "DisplayBackgroundColor", DISPLAYBACKGROUNDCOLOR, sal_Int32, BOUND, MAYBEVOID ), + DECL_PROP_2 ( "Dropdown", DROPDOWN, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "EchoChar", ECHOCHAR, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "EditMask", EDITMASK, ::rtl::OUString, BOUND, MAYBEDEFAULT ), + DECL_PROP_3 ( "EffectiveDefault", EFFECTIVE_DEFAULT, Any, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_3 ( "EffectiveMax", EFFECTIVE_MAX, double, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_3 ( "EffectiveMin", EFFECTIVE_MIN, double, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_DEP_PROP_3 ( "EffectiveValue", EFFECTIVE_VALUE, Any, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_2 ( "Enabled", ENABLED, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "EnforceFormat", ENFORCE_FORMAT, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_3 ( "FillColor", FILLCOLOR, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_2 ( "FocusOnClick", FOCUSONCLICK, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "FontRelief", FONTRELIEF, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "FontEmphasisMark", FONTEMPHASISMARK, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "FontDescriptor", FONTDESCRIPTOR, FontDescriptor, BOUND, MAYBEDEFAULT ), + + // Teile des ::com::sun::star::awt::FontDescriptor + DECL_PROP_2 ( "FontName", FONTDESCRIPTORPART_NAME, ::rtl::OUString,BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "FontStyleName", FONTDESCRIPTORPART_STYLENAME, ::rtl::OUString,BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "FontFamily", FONTDESCRIPTORPART_FAMILY, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "FontCharset", FONTDESCRIPTORPART_CHARSET, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "FontHeight", FONTDESCRIPTORPART_HEIGHT, float, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "FontWidth", FONTDESCRIPTORPART_WIDTH, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "FontPitch", FONTDESCRIPTORPART_PITCH, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "FontWeight", FONTDESCRIPTORPART_WEIGHT, float, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "FontCharWidth", FONTDESCRIPTORPART_CHARWIDTH, float, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "FontOrientation", FONTDESCRIPTORPART_ORIENTATION, float, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "FontSlant", FONTDESCRIPTORPART_SLANT, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "FontUnderline", FONTDESCRIPTORPART_UNDERLINE, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "FontStrikeout", FONTDESCRIPTORPART_STRIKEOUT, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "FontKerning", FONTDESCRIPTORPART_KERNING, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "FontWordLineMode", FONTDESCRIPTORPART_WORDLINEMODE, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "FontType", FONTDESCRIPTORPART_TYPE, sal_Int16, BOUND, MAYBEDEFAULT ), + + DECL_PROP_3 ( "FormatKey", FORMATKEY, sal_Int32, BOUND, MAYBEVOID, TRANSIENT ), + DECL_PROP_3 ( "FormatsSupplier", FORMATSSUPPLIER, Reference< ::com::sun::star::util::XNumberFormatsSupplier >, BOUND, MAYBEVOID, TRANSIENT ), + + DECL_PROP_2 ( "Graphic", GRAPHIC, Reference< ::com::sun::star::graphic::XGraphic >, BOUND, TRANSIENT ), + DECL_PROP_2 ( "HelpText", HELPTEXT, ::rtl::OUString, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "HelpURL", HELPURL, ::rtl::OUString, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "HideInactiveSelection", HIDEINACTIVESELECTION, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "HighContrastMode", HIGHCONTRASTMODE, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "HScroll", HSCROLL, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "HardLineBreaks", HARDLINEBREAKS, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "ImageAlign", IMAGEALIGN, sal_Int16, BOUND, MAYBEDEFAULT), + DECL_PROP_2 ( "ImagePosition", IMAGEPOSITION, sal_Int16, BOUND, MAYBEDEFAULT), + DECL_PROP_2 ( "ImageURL", IMAGEURL, ::rtl::OUString, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "Label", LABEL, ::rtl::OUString, BOUND, MAYBEDEFAULT ), + DECL_PROP_3 ( "LineColor", LINECOLOR, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_2 ( "LineCount", LINECOUNT, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "LineEndFormat", LINE_END_FORMAT, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_DEP_PROP_2 ( "LineIncrement", LINEINCREMENT, sal_Int32, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "LiteralMask", LITERALMASK, ::rtl::OUString, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "LiveScroll", LIVE_SCROLL, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "MaxTextLen", MAXTEXTLEN, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "Moveable", MOVEABLE, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_1 ( "MouseTransparent", MOUSETRANSPARENT, bool, BOUND ), + DECL_PROP_2 ( "MultiLine", MULTILINE, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "MultiSelection", MULTISELECTION, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "NativeWidgetLook", NATIVE_WIDGET_LOOK, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "NoLabel", NOLABEL, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "Orientation", ORIENTATION, sal_Int32, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "PaintTransparent", PAINTTRANSPARENT, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "PluginParent", PLUGINPARENT, sal_Int64, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "PrependCurrencySymbol", CURSYM_POSITION, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "Printable", PRINTABLE, bool, BOUND, MAYBEDEFAULT ), + DECL_DEP_PROP_3 ( "ProgressValue", PROGRESSVALUE, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_2 ( "ProgressValueMax", PROGRESSVALUE_MAX, sal_Int32, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "ProgressValueMin", PROGRESSVALUE_MIN, sal_Int32, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "PushButtonType", PUSHBUTTONTYPE, sal_Int16, BOUND, MAYBEDEFAULT), + DECL_PROP_2 ( "ReadOnly", READONLY, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "Repeat", REPEAT, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "RepeatDelay", REPEAT_DELAY, sal_Int32, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "ScaleImage", SCALEIMAGE, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "ScaleMode", IMAGE_SCALE_MODE, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_DEP_PROP_3 ( "ScrollValue", SCROLLVALUE, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_2 ( "ScrollValueMax", SCROLLVALUE_MAX, sal_Int32, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "ScrollValueMin", SCROLLVALUE_MIN, sal_Int32, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "SelectedItems", SELECTEDITEMS, Sequence<sal_Int16>, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "ShowThousandsSeparator", NUMSHOWTHOUSANDSEP, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "Sizeable", SIZEABLE, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "Spin", SPIN, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "SpinIncrement", SPININCREMENT, sal_Int32, BOUND, MAYBEDEFAULT ), + DECL_DEP_PROP_2 ( "SpinValue", SPINVALUE, sal_Int32, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "SpinValueMax", SPINVALUE_MAX, sal_Int32, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "SpinValueMin", SPINVALUE_MIN, sal_Int32, BOUND, MAYBEDEFAULT ), + DECL_DEP_PROP_2 ( "State", STATE, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "StrictFormat", STRICTFORMAT, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "StringItemList", STRINGITEMLIST, Sequence< ::rtl::OUString >, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "VisualEffect", VISUALEFFECT, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_PROP_3 ( "SymbolColor", SYMBOL_COLOR, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_3 ( "Tabstop", TABSTOP, bool, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_2 ( "Text", TEXT, ::rtl::OUString, BOUND, MAYBEDEFAULT ), + DECL_PROP_3 ( "TextColor", TEXTCOLOR, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_3 ( "TextLineColor", TEXTLINECOLOR, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_DEP_PROP_3 ( "Time", TIME, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_2 ( "TimeFormat", EXTTIMEFORMAT, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "TimeMax", TIMEMAX, sal_Int32, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "TimeMin", TIMEMIN, sal_Int32, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "Title", TITLE, ::rtl::OUString, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "Toggle", TOGGLE, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_3 ( "TreatAsNumber", TREATASNUMBER, bool, BOUND, MAYBEDEFAULT,TRANSIENT ), + DECL_PROP_2 ( "TriState", TRISTATE, bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "Unit", UNIT, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "VScroll", VSCROLL, bool, BOUND, MAYBEDEFAULT ), + DECL_DEP_PROP_3 ( "Value", VALUE_DOUBLE, double, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_2 ( "ValueMax", VALUEMAX_DOUBLE, double, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "ValueMin", VALUEMIN_DOUBLE, double, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "ValueStep", VALUESTEP_DOUBLE, double, BOUND, MAYBEDEFAULT ), + DECL_PROP_3 ( "VerticalAlign", VERTICALALIGN, VerticalAlignment, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_DEP_PROP_3 ( "VisibleSize", VISIBLESIZE, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_2 ( "Activated", ACTIVATED, sal_Bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "Complete", COMPLETE, sal_Bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "CurrentItemID", CURRENTITEMID, sal_Int16, BOUND, MAYBEDEFAULT ), + + DECL_PROP_2 ( "MouseWheelBehavior", MOUSE_WHEEL_BEHAVIOUR, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "StepTime", STEP_TIME, sal_Int32, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "Decoration", DECORATION, sal_Bool, BOUND, MAYBEDEFAULT ), + + DECL_PROP_2 ( "SelectionType", TREE_SELECTIONTYPE, ::com::sun::star::view::SelectionType, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "Editable", TREE_EDITABLE, sal_Bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_3 ( "DataModel", TREE_DATAMODEL, Reference< ::com::sun::star::awt::tree::XTreeDataModel >, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_2 ( "RootDisplayed", TREE_ROOTDISPLAYED, sal_Bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "ShowsHandles", TREE_SHOWSHANDLES, sal_Bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "ShowsRootHandles", TREE_SHOWSROOTHANDLES, sal_Bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_3 ( "RowHeight", TREE_ROWHEIGHT, sal_Int32, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_2 ( "InvokesStopNodeEditing", TREE_INVOKESSTOPNODEEDITING, sal_Bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "DialogSourceURL", DIALOGSOURCEURL, ::rtl::OUString, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "URL", URL, ::rtl::OUString, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "WritingMode", WRITING_MODE, sal_Int16, BOUND, MAYBEDEFAULT ), + DECL_PROP_3 ( "ContextWritingMode", CONTEXT_WRITING_MODE, sal_Int16, BOUND, MAYBEDEFAULT, TRANSIENT ), + DECL_PROP_2 ( "ShowRowHeader", GRID_SHOWROWHEADER, sal_Bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_2 ( "ShowColumnHeader", GRID_SHOWCOLUMNHEADER, sal_Bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_3 ( "GridDataModel", GRID_DATAMODEL, Reference< ::com::sun::star::awt::grid::XGridDataModel >, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_3 ( "ColumnModel", GRID_COLUMNMODEL, Reference< ::com::sun::star::awt::grid::XGridColumnModel >, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_3 ( "SelectionModel", GRID_SELECTIONMODE, ::com::sun::star::view::SelectionType, BOUND, MAYBEDEFAULT, MAYBEVOID ), + DECL_PROP_2 ( "EnableVisible", ENABLEVISIBLE, sal_Bool, BOUND, MAYBEDEFAULT ), + DECL_PROP_3 ( "ReferenceDevice", REFERENCE_DEVICE, Reference< XDevice >,BOUND, MAYBEDEFAULT, TRANSIENT ) + }; + pPropertyInfos = aImplPropertyInfos; + nElements = sizeof( aImplPropertyInfos ) / sizeof( ImplPropertyInfo ); + } + } + rElementCount = nElements; + return pPropertyInfos; +} + + +struct ImplPropertyInfoCompareFunctor : ::std::binary_function<ImplPropertyInfo,::rtl::OUString,bool> +{ + inline bool operator()(const ImplPropertyInfo& lhs,const ImplPropertyInfo& rhs) const + { + return lhs.aName.compareTo(rhs.aName) < 0; + } + inline bool operator()(const ImplPropertyInfo& lhs,const ::rtl::OUString& rhs) const + { + return lhs.aName.compareTo(rhs) < 0; + } + inline bool operator()(const ::rtl::OUString& lhs,const ImplPropertyInfo& rhs) const + { + return lhs.compareTo(rhs.aName) < 0; + } +}; + +void ImplAssertValidPropertyArray() +{ + static sal_Bool bSorted = sal_False; + if( !bSorted ) + { + sal_uInt16 nElements; + ImplPropertyInfo* pInfos = ImplGetPropertyInfos( nElements ); + ::std::sort(pInfos, pInfos+nElements,ImplPropertyInfoCompareFunctor()); + bSorted = sal_True; + } +} + +sal_uInt16 GetPropertyId( const ::rtl::OUString& rPropertyName ) +{ + ImplAssertValidPropertyArray(); + + sal_uInt16 nElements; + ImplPropertyInfo* pInfos = ImplGetPropertyInfos( nElements ); + ImplPropertyInfo* pInf = ::std::lower_bound(pInfos,pInfos+nElements,rPropertyName,ImplPropertyInfoCompareFunctor()); +/* + (ImplPropertyInfo*) + bsearch( &aSearch, pInfos, nElements, sizeof( ImplPropertyInfo ), ImplPropertyInfoCompare ); +*/ + + return ( pInf && pInf != (pInfos+nElements) && pInf->aName == rPropertyName) ? pInf->nPropId: 0; +} + +const ImplPropertyInfo* ImplGetImplPropertyInfo( sal_uInt16 nPropertyId ) +{ + ImplAssertValidPropertyArray(); + + sal_uInt16 nElements; + ImplPropertyInfo* pInfos = ImplGetPropertyInfos( nElements ); + sal_uInt16 n; + for ( n = 0; n < nElements && pInfos[n].nPropId != nPropertyId; ++n) + ; + + return (n < nElements) ? &pInfos[n] : NULL; +} + +sal_uInt16 GetPropertyOrderNr( sal_uInt16 nPropertyId ) +{ + ImplAssertValidPropertyArray(); + + sal_uInt16 nElements; + ImplPropertyInfo* pInfos = ImplGetPropertyInfos( nElements ); + for ( sal_uInt16 n = nElements; n; ) + { + if ( pInfos[--n].nPropId == nPropertyId ) + return n; + } + return 0xFFFF; +} + +const ::rtl::OUString& GetPropertyName( sal_uInt16 nPropertyId ) +{ + const ImplPropertyInfo* pImplPropertyInfo = ImplGetImplPropertyInfo( nPropertyId ); + DBG_ASSERT( pImplPropertyInfo, "Invalid PropertyId!" ); + return pImplPropertyInfo->aName; +} + +const ::com::sun::star::uno::Type* GetPropertyType( sal_uInt16 nPropertyId ) +{ + const ImplPropertyInfo* pImplPropertyInfo = ImplGetImplPropertyInfo( nPropertyId ); + DBG_ASSERT( pImplPropertyInfo, "Invalid PropertyId!" ); + return pImplPropertyInfo ? &pImplPropertyInfo->aType : NULL; +} + +sal_Int16 GetPropertyAttribs( sal_uInt16 nPropertyId ) +{ + const ImplPropertyInfo* pImplPropertyInfo = ImplGetImplPropertyInfo( nPropertyId ); + DBG_ASSERT( pImplPropertyInfo, "Invalid PropertyId!" ); + return pImplPropertyInfo ? pImplPropertyInfo->nAttribs : 0; +} + +sal_Bool DoesDependOnOthers( sal_uInt16 nPropertyId ) +{ + const ImplPropertyInfo* pImplPropertyInfo = ImplGetImplPropertyInfo( nPropertyId ); + DBG_ASSERT( pImplPropertyInfo, "Invalid PropertyId!" ); + return pImplPropertyInfo ? pImplPropertyInfo->bDependsOnOthers : sal_False; +} + +sal_Bool CompareProperties( const ::com::sun::star::uno::Any& r1, const ::com::sun::star::uno::Any& r2 ) +{ + return ::comphelper::compare( r1, r2 ); +} + + + diff --git a/toolkit/source/helper/registerservices.cxx b/toolkit/source/helper/registerservices.cxx new file mode 100644 index 000000000000..7d1dcaeb2762 --- /dev/null +++ b/toolkit/source/helper/registerservices.cxx @@ -0,0 +1,399 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/registry/XRegistryKey.hpp> +#include <toolkit/controls/geometrycontrolmodel.hxx> +#include <cppuhelper/factory.hxx> +#include <cppuhelper/weak.hxx> +#include <osl/mutex.hxx> +#include <toolkit/helper/servicenames.hxx> +#include <toolkit/helper/macros.hxx> +#include <toolkit/awt/vclxtoolkit.hxx> +#include <toolkit/awt/vclxmenu.hxx> +#include <toolkit/awt/vclxpointer.hxx> +#include <toolkit/awt/vclxprinter.hxx> +#include <toolkit/controls/unocontrols.hxx> +#include <toolkit/controls/unocontrolcontainer.hxx> +#include <toolkit/controls/unocontrolcontainermodel.hxx> +#include <toolkit/controls/stdtabcontroller.hxx> +#include <toolkit/controls/stdtabcontrollermodel.hxx> +#include <toolkit/controls/formattedcontrol.hxx> +#include <toolkit/controls/roadmapcontrol.hxx> +#include <toolkit/controls/tkscrollbar.hxx> +#include "toolkit/controls/tkspinbutton.hxx" +#include <toolkit/controls/tksimpleanimation.hxx> +#include <toolkit/controls/tkthrobber.hxx> +#include <toolkit/controls/dialogcontrol.hxx> +#include "toolkit/dllapi.h" + +namespace toolkit +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::lang; + using namespace ::com::sun::star::registry; + + //......................................................................... + Reference< XRegistryKey > registerServices( const Reference< XRegistryKey >& _rxParentKey, + const sal_Char* _pAsciiImplName, const sal_Char* _pAsciiServiceName ) + { + ::rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM( "/stardiv.Toolkit." ) ); + sImplName += ::rtl::OUString::createFromAscii( _pAsciiImplName ); + sImplName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/UNO/SERVICES" ) ); + + Reference< XRegistryKey > xNewKey = _rxParentKey->createKey( sImplName ); + xNewKey->createKey( ::rtl::OUString::createFromAscii( _pAsciiServiceName ) ); + + return xNewKey; + } + + //......................................................................... + Reference< XRegistryKey > registerServices( const Reference< XRegistryKey >& _rxParentKey, + const sal_Char* _pAsciiImplName, const sal_Char* _pAsciiServiceName1, const sal_Char* _pAsciiServiceName2 ) + { + Reference< XRegistryKey > xComponentServicesKey = registerServices( _rxParentKey, _pAsciiImplName, _pAsciiServiceName1 ); + xComponentServicesKey->createKey( ::rtl::OUString::createFromAscii( _pAsciiServiceName2 ) ); + return xComponentServicesKey; + } + + //......................................................................... + void* tryCreateFactory( const sal_Char* _pRequiredImplName, const sal_Char* _pComponentImplName, + const sal_Char* _pAsciiServiceName1, const sal_Char* _pAsciiServiceName2, + ::cppu::ComponentInstantiation _pInstantiation, const Reference< XMultiServiceFactory >& _rxServiceFactory ) + { + void* pReturn = NULL; + + if ( rtl_str_compare( _pRequiredImplName, _pComponentImplName ) == 0 ) + { + Sequence< ::rtl::OUString > aServiceNames( _pAsciiServiceName2 ? 2 : 1 ); + aServiceNames.getArray()[ 0 ] = ::rtl::OUString::createFromAscii( _pAsciiServiceName1 ); + if ( _pAsciiServiceName2 ) + aServiceNames.getArray()[ 1 ] = ::rtl::OUString::createFromAscii( _pAsciiServiceName2 ); + Reference< XSingleServiceFactory > xFactory( ::cppu::createSingleFactory( + _rxServiceFactory, ::rtl::OUString::createFromAscii( _pComponentImplName ), + _pInstantiation, aServiceNames + ) ); + + if ( xFactory.is() ) + { + xFactory->acquire(); + pReturn = xFactory.get(); + } + } + + return pReturn; + } + + +} + +#define IMPL_CREATEINSTANCE( ImplName ) \ + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL ImplName##_CreateInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& ) \ + { return ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface >( ( ::cppu::OWeakObject* ) new ImplName ); } + +#define IMPL_CREATEINSTANCE2( ImplName ) \ + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL ImplName##_CreateInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rSMgr) \ + { return ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface >( ( ::cppu::OWeakObject* ) new ImplName( rSMgr ) ); } + +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL UnoControlDialogModel_CreateInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& ) +{ + return ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface >( ( ::cppu::OWeakObject* ) new OGeometryControlModel<UnoControlDialogModel> ); +} + +#define CHECKANDCREATEFACTORY( ImplName, ServiceName1, ServiceName2 ) \ + pRet = tryCreateFactory( sImplementationName, "stardiv.Toolkit." #ImplName, \ + ServiceName1, ServiceName2, \ + ImplName##_CreateInstance, xServiceFactory \ + ); \ + if ( pRet ) \ + return pRet; \ + +using namespace toolkit; + +IMPL_CREATEINSTANCE2( VCLXToolkit ) +IMPL_CREATEINSTANCE( StdTabController ) +IMPL_CREATEINSTANCE( StdTabControllerModel ) +IMPL_CREATEINSTANCE( UnoButtonControl ) +IMPL_CREATEINSTANCE( UnoCheckBoxControl ) +IMPL_CREATEINSTANCE( UnoComboBoxControl ) +IMPL_CREATEINSTANCE( UnoControlButtonModel ) +IMPL_CREATEINSTANCE( UnoControlCheckBoxModel ) +IMPL_CREATEINSTANCE( UnoControlComboBoxModel ) +IMPL_CREATEINSTANCE( UnoControlContainer ) +IMPL_CREATEINSTANCE( UnoControlContainerModel ) +IMPL_CREATEINSTANCE( UnoControlCurrencyFieldModel ) +IMPL_CREATEINSTANCE( UnoControlDateFieldModel ) +IMPL_CREATEINSTANCE( UnoControlEditModel ) +IMPL_CREATEINSTANCE( UnoControlFileControlModel ) +IMPL_CREATEINSTANCE( UnoControlFixedHyperlinkModel ) +IMPL_CREATEINSTANCE( UnoControlFixedTextModel ) +IMPL_CREATEINSTANCE( UnoControlFormattedFieldModel ) +IMPL_CREATEINSTANCE( UnoControlGroupBoxModel ) +IMPL_CREATEINSTANCE( UnoControlImageControlModel ) +IMPL_CREATEINSTANCE( UnoControlListBoxModel ) +IMPL_CREATEINSTANCE( UnoControlNumericFieldModel ) +IMPL_CREATEINSTANCE( UnoControlPatternFieldModel ) +IMPL_CREATEINSTANCE( UnoControlRadioButtonModel ) +IMPL_CREATEINSTANCE( UnoControlTimeFieldModel ) +IMPL_CREATEINSTANCE( UnoControlProgressBarModel ) +IMPL_CREATEINSTANCE( UnoControlScrollBarModel ) +IMPL_CREATEINSTANCE( UnoSpinButtonModel ) +IMPL_CREATEINSTANCE( UnoControlFixedLineModel ) +IMPL_CREATEINSTANCE( UnoCurrencyFieldControl ) +IMPL_CREATEINSTANCE( UnoDateFieldControl ) +IMPL_CREATEINSTANCE( UnoDialogControl ) +IMPL_CREATEINSTANCE( UnoEditControl ) +IMPL_CREATEINSTANCE( UnoFileControl ) +IMPL_CREATEINSTANCE( UnoFixedHyperlinkControl ) +IMPL_CREATEINSTANCE( UnoFixedTextControl ) +IMPL_CREATEINSTANCE( UnoFormattedFieldControl ) +IMPL_CREATEINSTANCE( UnoGroupBoxControl ) +IMPL_CREATEINSTANCE( UnoImageControlControl ) +IMPL_CREATEINSTANCE( UnoListBoxControl ) +IMPL_CREATEINSTANCE( UnoNumericFieldControl ) +IMPL_CREATEINSTANCE( UnoPatternFieldControl ) +IMPL_CREATEINSTANCE( UnoRadioButtonControl ) +IMPL_CREATEINSTANCE( UnoTimeFieldControl ) +IMPL_CREATEINSTANCE( UnoProgressBarControl ) +IMPL_CREATEINSTANCE( UnoScrollBarControl ) +IMPL_CREATEINSTANCE( UnoSpinButtonControl ) +IMPL_CREATEINSTANCE( UnoFixedLineControl ) +IMPL_CREATEINSTANCE( VCLXMenuBar ) +IMPL_CREATEINSTANCE( VCLXPointer ) +IMPL_CREATEINSTANCE( VCLXPopupMenu ) +IMPL_CREATEINSTANCE( VCLXPrinterServer ) +IMPL_CREATEINSTANCE( UnoRoadmapControl ) +IMPL_CREATEINSTANCE( UnoControlRoadmapModel ) +IMPL_CREATEINSTANCE( UnoSimpleAnimationControl ) +IMPL_CREATEINSTANCE( UnoSimpleAnimationControlModel ) +IMPL_CREATEINSTANCE( UnoThrobberControl ) +IMPL_CREATEINSTANCE( UnoThrobberControlModel ) + +extern ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL TreeControl_CreateInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& ); +extern ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL TreeControlModel_CreateInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& ); +extern ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL MutableTreeDataModel_CreateInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& ); +extern ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL GridControl_CreateInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& ); +extern ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL GridControlModel_CreateInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& ); +extern ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL DefaultGridDataModel_CreateInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& ); +extern ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL DefaultGridColumnModel_CreateInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& ); +extern ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL GridColumn_CreateInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& ); + +extern sal_Bool SAL_CALL comp_AsyncCallback_component_writeInfo( void * serviceManager, void * registryKey ); +extern void * SAL_CALL comp_AsyncCallback_component_getFactory( const char * implName, void * serviceManager, void * registryKey ); + +extern sal_Bool SAL_CALL comp_Layout_component_writeInfo( void * serviceManager, void * registryKey ); +extern void * SAL_CALL comp_Layout_component_getFactory( const char * implName, void * serviceManager, void * registryKey ); + +extern "C" +{ + +TOOLKIT_DLLPUBLIC void SAL_CALL component_getImplementationEnvironment( const sal_Char** ppEnvTypeName, uno_Environment** ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +TOOLKIT_DLLPUBLIC sal_Bool SAL_CALL component_writeInfo( void* _pServiceManager, void* _pRegistryKey ) +{ + if (_pRegistryKey) + { + ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey > xRegistryKey = + static_cast< ::com::sun::star::registry::XRegistryKey* >( _pRegistryKey ); + + registerServices( xRegistryKey, "VCLXToolkit", szServiceName_Toolkit, szServiceName2_Toolkit ); + registerServices( xRegistryKey, "VCLXPopupMenu", szServiceName_PopupMenu, szServiceName2_PopupMenu ); + registerServices( xRegistryKey, "VCLXMenuBar", szServiceName_MenuBar, szServiceName2_MenuBar ); + registerServices( xRegistryKey, "VCLXPointer", szServiceName_Pointer, szServiceName2_Pointer ); + registerServices( xRegistryKey, "UnoControlContainer", szServiceName_UnoControlContainer, szServiceName2_UnoControlContainer ); + registerServices( xRegistryKey, "UnoControlContainerModel", szServiceName_UnoControlContainerModel, szServiceName2_UnoControlContainerModel ); + registerServices( xRegistryKey, "StdTabController", szServiceName_TabController, szServiceName2_TabController ); + registerServices( xRegistryKey, "StdTabControllerModel", szServiceName_TabControllerModel, szServiceName2_TabControllerModel ); + registerServices( xRegistryKey, "UnoDialogControl", szServiceName_UnoControlDialog, szServiceName2_UnoControlDialog ); + registerServices( xRegistryKey, "UnoControlDialogModel", szServiceName_UnoControlDialogModel, szServiceName2_UnoControlDialogModel ); + registerServices( xRegistryKey, "UnoEditControl", szServiceName_UnoControlEdit, szServiceName2_UnoControlEdit ); + registerServices( xRegistryKey, "UnoControlEditModel", szServiceName_UnoControlEditModel, szServiceName2_UnoControlEditModel ); + registerServices( xRegistryKey, "UnoDateFieldControl", szServiceName_UnoControlDateField, szServiceName2_UnoControlDateField ); + registerServices( xRegistryKey, "UnoControlDateFieldModel", szServiceName_UnoControlDateFieldModel, szServiceName2_UnoControlDateFieldModel ); + registerServices( xRegistryKey, "UnoTimeFieldControl", szServiceName_UnoControlTimeField, szServiceName2_UnoControlTimeField ); + registerServices( xRegistryKey, "UnoControlTimeFieldModel", szServiceName_UnoControlTimeFieldModel, szServiceName2_UnoControlTimeFieldModel ); + registerServices( xRegistryKey, "UnoNumericFieldControl", szServiceName_UnoControlNumericField, szServiceName2_UnoControlNumericField ); + registerServices( xRegistryKey, "UnoControlNumericFieldModel", szServiceName_UnoControlNumericFieldModel, szServiceName2_UnoControlNumericFieldModel ); + registerServices( xRegistryKey, "UnoCurrencyFieldControl", szServiceName_UnoControlCurrencyField, szServiceName2_UnoControlCurrencyField ); + registerServices( xRegistryKey, "UnoControlCurrencyFieldModel", szServiceName_UnoControlCurrencyFieldModel, szServiceName2_UnoControlCurrencyFieldModel ); + registerServices( xRegistryKey, "UnoPatternFieldControl", szServiceName_UnoControlPatternField, szServiceName2_UnoControlPatternField ); + registerServices( xRegistryKey, "UnoControlPatternFieldModel", szServiceName_UnoControlPatternFieldModel, szServiceName2_UnoControlPatternFieldModel ); + registerServices( xRegistryKey, "UnoFormattedFieldControl", szServiceName_UnoControlFormattedField, szServiceName2_UnoControlFormattedField ); + registerServices( xRegistryKey, "UnoControlFormattedFieldModel", szServiceName_UnoControlFormattedFieldModel, szServiceName2_UnoControlFormattedFieldModel ); + registerServices( xRegistryKey, "UnoFileControl", szServiceName_UnoControlFileControl, szServiceName2_UnoControlFileControl ); + registerServices( xRegistryKey, "UnoControlFileControlModel", szServiceName_UnoControlFileControlModel, szServiceName2_UnoControlFileControlModel ); + registerServices( xRegistryKey, "UnoButtonControl", szServiceName_UnoControlButton, szServiceName2_UnoControlButton ); + registerServices( xRegistryKey, "UnoControlButtonModel", szServiceName_UnoControlButtonModel, szServiceName2_UnoControlButtonModel ); + registerServices( xRegistryKey, "UnoImageControlControl", szServiceName_UnoControlImageButton, szServiceName2_UnoControlImageButton ); + registerServices( xRegistryKey, "UnoControlImageControlModel", szServiceName_UnoControlImageButtonModel, szServiceName2_UnoControlImageButtonModel ); + registerServices( xRegistryKey, "UnoImageControlControl", szServiceName_UnoControlImageControl, szServiceName2_UnoControlImageControl ); + registerServices( xRegistryKey, "UnoControlImageControlModel", szServiceName_UnoControlImageControlModel, szServiceName2_UnoControlImageControlModel ); + registerServices( xRegistryKey, "UnoRadioButtonControl", szServiceName_UnoControlRadioButton, szServiceName2_UnoControlRadioButton ); + registerServices( xRegistryKey, "UnoControlRadioButtonModel", szServiceName_UnoControlRadioButtonModel, szServiceName2_UnoControlRadioButtonModel ); + registerServices( xRegistryKey, "UnoCheckBoxControl", szServiceName_UnoControlCheckBox, szServiceName2_UnoControlCheckBox ); + registerServices( xRegistryKey, "UnoControlCheckBoxModel", szServiceName_UnoControlCheckBoxModel, szServiceName2_UnoControlCheckBoxModel ); + registerServices( xRegistryKey, "UnoListBoxControl", szServiceName_UnoControlListBox, szServiceName2_UnoControlListBox ); + registerServices( xRegistryKey, "UnoControlListBoxModel", szServiceName_UnoControlListBoxModel, szServiceName2_UnoControlListBoxModel ); + registerServices( xRegistryKey, "UnoComboBoxControl", szServiceName_UnoControlComboBox, szServiceName2_UnoControlComboBox ); + registerServices( xRegistryKey, "UnoControlComboBoxModel", szServiceName_UnoControlComboBoxModel, szServiceName2_UnoControlComboBoxModel ); + registerServices( xRegistryKey, "UnoFixedTextControl", szServiceName_UnoControlFixedText, szServiceName2_UnoControlFixedText ); + registerServices( xRegistryKey, "UnoControlFixedTextModel", szServiceName_UnoControlFixedTextModel, szServiceName2_UnoControlFixedTextModel ); + registerServices( xRegistryKey, "UnoGroupBoxControl", szServiceName_UnoControlGroupBox, szServiceName2_UnoControlGroupBox ); + registerServices( xRegistryKey, "UnoControlGroupBoxModel", szServiceName_UnoControlGroupBoxModel, szServiceName2_UnoControlGroupBoxModel ); + registerServices( xRegistryKey, "UnoProgressBarControl", szServiceName_UnoControlProgressBar, szServiceName2_UnoControlProgressBar ); + registerServices( xRegistryKey, "UnoControlProgressBarModel", szServiceName_UnoControlProgressBarModel, szServiceName2_UnoControlProgressBarModel ); + registerServices( xRegistryKey, "UnoScrollBarControl", szServiceName_UnoControlScrollBar, szServiceName2_UnoControlScrollBar ); + registerServices( xRegistryKey, "UnoControlScrollBarModel", szServiceName_UnoControlScrollBarModel, szServiceName2_UnoControlScrollBarModel ); + registerServices( xRegistryKey, "UnoSpinButtonModel", szServiceName_UnoSpinButtonModel ); + registerServices( xRegistryKey, "UnoSpinButtonControl", szServiceName_UnoSpinButtonControl ); + registerServices( xRegistryKey, "UnoFixedLineControl", szServiceName_UnoControlFixedLine, szServiceName2_UnoControlFixedLine ); + registerServices( xRegistryKey, "UnoControlFixedLineModel", szServiceName_UnoControlFixedLineModel, szServiceName2_UnoControlFixedLineModel ); + registerServices( xRegistryKey, "VCLXPrinterServer", szServiceName_PrinterServer, szServiceName2_PrinterServer ); + registerServices( xRegistryKey, "UnoRoadmapControl", szServiceName_UnoControlRoadmap, szServiceName2_UnoControlRoadmap ); + registerServices( xRegistryKey, "UnoControlRoadmapModel", szServiceName_UnoControlRoadmapModel, szServiceName2_UnoControlRoadmapModel ); + registerServices( xRegistryKey, "TreeControl", szServiceName_TreeControl ); + registerServices( xRegistryKey, "TreeControlModel", szServiceName_TreeControlModel ); + registerServices( xRegistryKey, "MutableTreeDataModel", szServiceName_MutableTreeDataModel ); + registerServices( xRegistryKey, "UnoSimpleAnimationControlModel", szServiceName_UnoSimpleAnimationControlModel ); + registerServices( xRegistryKey, "UnoSimpleAnimationControl", szServiceName_UnoSimpleAnimationControl ); + registerServices( xRegistryKey, "UnoThrobberControlModel", szServiceName_UnoThrobberControlModel ); + registerServices( xRegistryKey, "UnoThrobberControl", szServiceName_UnoThrobberControl ); + registerServices( xRegistryKey, "UnoFixedHyperlinkControl", szServiceName_UnoControlFixedHyperlink ); + registerServices( xRegistryKey, "UnoControlFixedHyperlinkModel", szServiceName_UnoControlFixedHyperlinkModel ); + registerServices( xRegistryKey, "GridControl", szServiceName_GridControl ); + registerServices( xRegistryKey, "GridControlModel", szServiceName_GridControlModel ); + registerServices( xRegistryKey, "DefaultGridDataModel", szServiceName_DefaultGridDataModel ); + registerServices( xRegistryKey, "DefaultGridColumnModel", szServiceName_DefaultGridColumnModel ); + registerServices( xRegistryKey, "GridColumn", szServiceName_GridColumn ); + + comp_AsyncCallback_component_writeInfo( _pServiceManager, _pRegistryKey ); + comp_Layout_component_writeInfo( _pServiceManager, _pRegistryKey ); + + return sal_True; + } + return sal_False; +} + +TOOLKIT_DLLPUBLIC void* SAL_CALL component_getFactory( const sal_Char* sImplementationName, void* _pServiceManager, void* _pRegistryKey ) +{ + void* pRet = NULL; + + if ( _pServiceManager ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory = + static_cast< ::com::sun::star::lang::XMultiServiceFactory* >( _pServiceManager ); + + CHECKANDCREATEFACTORY( VCLXToolkit, szServiceName_Toolkit, szServiceName2_Toolkit ) + CHECKANDCREATEFACTORY( VCLXPopupMenu, szServiceName_PopupMenu, szServiceName2_PopupMenu ) + CHECKANDCREATEFACTORY( VCLXMenuBar, szServiceName_MenuBar, szServiceName2_MenuBar ) + CHECKANDCREATEFACTORY( VCLXPointer, szServiceName_Pointer, szServiceName2_Pointer ) + CHECKANDCREATEFACTORY( UnoControlContainer, szServiceName_UnoControlContainer, szServiceName2_UnoControlContainer ) + CHECKANDCREATEFACTORY( UnoControlContainerModel, szServiceName_UnoControlContainerModel, szServiceName2_UnoControlContainerModel ) + CHECKANDCREATEFACTORY( StdTabController, szServiceName_TabController, szServiceName2_TabController ) + CHECKANDCREATEFACTORY( StdTabControllerModel, szServiceName_TabControllerModel, szServiceName2_TabControllerModel ) + CHECKANDCREATEFACTORY( UnoDialogControl, szServiceName_UnoControlDialog, szServiceName2_UnoControlDialog ) + CHECKANDCREATEFACTORY( UnoControlDialogModel, szServiceName_UnoControlDialogModel, szServiceName2_UnoControlDialogModel ) + CHECKANDCREATEFACTORY( UnoEditControl, szServiceName_UnoControlEdit, szServiceName2_UnoControlEdit ) + CHECKANDCREATEFACTORY( UnoControlEditModel, szServiceName_UnoControlEditModel, szServiceName2_UnoControlEditModel ) + CHECKANDCREATEFACTORY( UnoDateFieldControl, szServiceName_UnoControlDateField, szServiceName2_UnoControlDateField ) + CHECKANDCREATEFACTORY( UnoControlDateFieldModel, szServiceName_UnoControlDateFieldModel, szServiceName2_UnoControlDateFieldModel ) + CHECKANDCREATEFACTORY( UnoTimeFieldControl, szServiceName_UnoControlTimeField, szServiceName2_UnoControlTimeField ) + CHECKANDCREATEFACTORY( UnoControlTimeFieldModel, szServiceName_UnoControlTimeFieldModel, szServiceName2_UnoControlTimeFieldModel ) + CHECKANDCREATEFACTORY( UnoNumericFieldControl, szServiceName_UnoControlNumericField, szServiceName2_UnoControlNumericField ) + CHECKANDCREATEFACTORY( UnoControlNumericFieldModel, szServiceName_UnoControlNumericFieldModel, szServiceName2_UnoControlNumericFieldModel ) + CHECKANDCREATEFACTORY( UnoCurrencyFieldControl, szServiceName_UnoControlCurrencyField, szServiceName2_UnoControlCurrencyField ) + CHECKANDCREATEFACTORY( UnoControlCurrencyFieldModel, szServiceName_UnoControlCurrencyFieldModel, szServiceName2_UnoControlCurrencyFieldModel ) + CHECKANDCREATEFACTORY( UnoPatternFieldControl, szServiceName_UnoControlPatternField, szServiceName2_UnoControlPatternField ) + CHECKANDCREATEFACTORY( UnoControlPatternFieldModel, szServiceName_UnoControlPatternFieldModel, szServiceName2_UnoControlPatternFieldModel ) + CHECKANDCREATEFACTORY( UnoFormattedFieldControl, szServiceName_UnoControlFormattedField, szServiceName2_UnoControlFormattedField ) + CHECKANDCREATEFACTORY( UnoControlFormattedFieldModel, szServiceName_UnoControlFormattedFieldModel, szServiceName2_UnoControlFormattedFieldModel ) + CHECKANDCREATEFACTORY( UnoFileControl, szServiceName_UnoControlFileControl, szServiceName2_UnoControlFileControl ) + CHECKANDCREATEFACTORY( UnoControlFileControlModel, szServiceName_UnoControlFileControlModel, szServiceName2_UnoControlFileControlModel ) + CHECKANDCREATEFACTORY( UnoButtonControl, szServiceName_UnoControlButton, szServiceName2_UnoControlButton ) + CHECKANDCREATEFACTORY( UnoControlButtonModel, szServiceName_UnoControlButtonModel, szServiceName2_UnoControlButtonModel ) + CHECKANDCREATEFACTORY( UnoImageControlControl, szServiceName_UnoControlImageButton, szServiceName2_UnoControlImageButton ) + CHECKANDCREATEFACTORY( UnoControlImageControlModel, szServiceName_UnoControlImageButtonModel, szServiceName2_UnoControlImageButtonModel ) + CHECKANDCREATEFACTORY( UnoImageControlControl, szServiceName_UnoControlImageControl, szServiceName2_UnoControlImageControl ) + CHECKANDCREATEFACTORY( UnoControlImageControlModel, szServiceName_UnoControlImageControlModel, szServiceName2_UnoControlImageControlModel ) + CHECKANDCREATEFACTORY( UnoRadioButtonControl, szServiceName_UnoControlRadioButton, szServiceName2_UnoControlRadioButton ) + CHECKANDCREATEFACTORY( UnoControlRadioButtonModel, szServiceName_UnoControlRadioButtonModel, szServiceName2_UnoControlRadioButtonModel ) + CHECKANDCREATEFACTORY( UnoCheckBoxControl, szServiceName_UnoControlCheckBox, szServiceName2_UnoControlCheckBox ) + CHECKANDCREATEFACTORY( UnoControlCheckBoxModel, szServiceName_UnoControlCheckBoxModel, szServiceName2_UnoControlCheckBoxModel ) + CHECKANDCREATEFACTORY( UnoListBoxControl, szServiceName_UnoControlListBox, szServiceName2_UnoControlListBox ) + CHECKANDCREATEFACTORY( UnoControlListBoxModel, szServiceName_UnoControlListBoxModel, szServiceName2_UnoControlListBoxModel ) + CHECKANDCREATEFACTORY( UnoComboBoxControl, szServiceName_UnoControlComboBox, szServiceName2_UnoControlComboBox ) + CHECKANDCREATEFACTORY( UnoControlComboBoxModel, szServiceName_UnoControlComboBoxModel, szServiceName2_UnoControlComboBoxModel ) + CHECKANDCREATEFACTORY( UnoFixedTextControl, szServiceName_UnoControlFixedText, szServiceName2_UnoControlFixedText ) + CHECKANDCREATEFACTORY( UnoControlFixedTextModel, szServiceName_UnoControlFixedTextModel, szServiceName2_UnoControlFixedTextModel ) + CHECKANDCREATEFACTORY( UnoGroupBoxControl, szServiceName_UnoControlGroupBox, szServiceName2_UnoControlGroupBox ) + CHECKANDCREATEFACTORY( UnoControlGroupBoxModel, szServiceName_UnoControlGroupBoxModel, szServiceName2_UnoControlGroupBoxModel ) + CHECKANDCREATEFACTORY( UnoProgressBarControl, szServiceName_UnoControlProgressBar, szServiceName2_UnoControlProgressBar ) + CHECKANDCREATEFACTORY( UnoControlProgressBarModel, szServiceName_UnoControlProgressBarModel, szServiceName2_UnoControlProgressBarModel ) + CHECKANDCREATEFACTORY( UnoScrollBarControl, szServiceName_UnoControlScrollBar, szServiceName2_UnoControlScrollBar ) + CHECKANDCREATEFACTORY( UnoControlScrollBarModel, szServiceName_UnoControlScrollBarModel, szServiceName2_UnoControlScrollBarModel ) + CHECKANDCREATEFACTORY( UnoFixedLineControl, szServiceName_UnoControlFixedLine, szServiceName2_UnoControlFixedLine ) + CHECKANDCREATEFACTORY( UnoControlFixedLineModel, szServiceName_UnoControlFixedLineModel, szServiceName2_UnoControlFixedLineModel ) + CHECKANDCREATEFACTORY( VCLXPrinterServer, szServiceName_PrinterServer, szServiceName2_PrinterServer ) + CHECKANDCREATEFACTORY( UnoRoadmapControl, szServiceName_UnoControlRoadmap, szServiceName2_UnoControlRoadmap ) + CHECKANDCREATEFACTORY( UnoControlRoadmapModel, szServiceName_UnoControlRoadmapModel, szServiceName2_UnoControlRoadmapModel ) + CHECKANDCREATEFACTORY( UnoSpinButtonModel, szServiceName_UnoSpinButtonModel, NULL ) + CHECKANDCREATEFACTORY( UnoSpinButtonControl, szServiceName_UnoSpinButtonControl, NULL ) + CHECKANDCREATEFACTORY( TreeControl, szServiceName_TreeControl, NULL ) + CHECKANDCREATEFACTORY( TreeControlModel, szServiceName_TreeControlModel, NULL ) + CHECKANDCREATEFACTORY( MutableTreeDataModel, szServiceName_MutableTreeDataModel, NULL ) + CHECKANDCREATEFACTORY( UnoSimpleAnimationControlModel, szServiceName_UnoSimpleAnimationControlModel, NULL ) + CHECKANDCREATEFACTORY( UnoSimpleAnimationControl, szServiceName_UnoSimpleAnimationControl, NULL ) + CHECKANDCREATEFACTORY( UnoThrobberControlModel, szServiceName_UnoThrobberControlModel, NULL ) + CHECKANDCREATEFACTORY( UnoThrobberControl, szServiceName_UnoThrobberControl, NULL ) + CHECKANDCREATEFACTORY( UnoFixedHyperlinkControl, szServiceName_UnoControlFixedHyperlink, NULL ) + CHECKANDCREATEFACTORY( UnoControlFixedHyperlinkModel, szServiceName_UnoControlFixedHyperlinkModel, NULL ) + CHECKANDCREATEFACTORY( GridControl, szServiceName_GridControl, NULL ); + CHECKANDCREATEFACTORY( GridControlModel, szServiceName_GridControlModel, NULL ); + CHECKANDCREATEFACTORY( DefaultGridDataModel, szServiceName_DefaultGridDataModel, NULL ); + CHECKANDCREATEFACTORY( DefaultGridColumnModel, szServiceName_DefaultGridColumnModel, NULL ); + CHECKANDCREATEFACTORY( GridColumn, szServiceName_GridColumn, NULL ); + + + if ( rtl_str_compare( sImplementationName, "com.sun.star.awt.comp.AsyncCallback" ) == 0 ) + return comp_AsyncCallback_component_getFactory( sImplementationName, _pServiceManager, _pRegistryKey ); + + + if( pRet == 0 ) + pRet = comp_Layout_component_getFactory( sImplementationName, _pServiceManager, _pRegistryKey ); + } + return pRet; +} +} + + + diff --git a/toolkit/source/helper/servicenames.cxx b/toolkit/source/helper/servicenames.cxx new file mode 100644 index 000000000000..1885387561cb --- /dev/null +++ b/toolkit/source/helper/servicenames.cxx @@ -0,0 +1,105 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <sal/types.h> +#include <tools/solar.h> + +#include <toolkit/helper/servicenames.hxx> + +const sal_Char __FAR_DATA szServiceName_Toolkit[] = "stardiv.vcl.VclToolkit", szServiceName2_Toolkit[] = "com.sun.star.awt.Toolkit"; +const sal_Char __FAR_DATA szServiceName_PopupMenu[] = "stardiv.vcl.PopupMenu", szServiceName2_PopupMenu[] = "com.sun.star.awt.PopupMenu"; +const sal_Char __FAR_DATA szServiceName_MenuBar[] = "stardiv.vcl.MenuBar", szServiceName2_MenuBar[] = "com.sun.star.awt.MenuBar"; +const sal_Char __FAR_DATA szServiceName_Pointer[] = "stardiv.vcl.Pointer", szServiceName2_Pointer[] = "com.sun.star.awt.Pointer"; +const sal_Char __FAR_DATA szServiceName_UnoControlContainer[] = "stardiv.vcl.control.ControlContainer", szServiceName2_UnoControlContainer[] = "com.sun.star.awt.UnoControlContainer"; +const sal_Char __FAR_DATA szServiceName_UnoControlContainerModel[] = "stardiv.vcl.controlmodel.ControlContainer", szServiceName2_UnoControlContainerModel[] = "com.sun.star.awt.UnoControlContainerModel"; +const sal_Char __FAR_DATA szServiceName_TabController[] = "stardiv.vcl.control.TabController", szServiceName2_TabController[] = "com.sun.star.awt.TabController"; +const sal_Char __FAR_DATA szServiceName_TabControllerModel[] = "stardiv.vcl.controlmodel.TabController", szServiceName2_TabControllerModel[] = "com.sun.star.awt.TabControllerModel"; +const sal_Char __FAR_DATA szServiceName_UnoControlDialog[] = "stardiv.vcl.control.Dialog", szServiceName2_UnoControlDialog[] = "com.sun.star.awt.UnoControlDialog"; +const sal_Char __FAR_DATA szServiceName_UnoControlDialogModel[] = "stardiv.vcl.controlmodel.Dialog", szServiceName2_UnoControlDialogModel[] = "com.sun.star.awt.UnoControlDialogModel"; +const sal_Char __FAR_DATA szServiceName_UnoControlEdit[] = "stardiv.vcl.control.Edit", szServiceName2_UnoControlEdit[] = "com.sun.star.awt.UnoControlEdit"; +const sal_Char __FAR_DATA szServiceName_UnoControlEditModel[] = "stardiv.vcl.controlmodel.Edit", szServiceName2_UnoControlEditModel[] = "com.sun.star.awt.UnoControlEditModel"; +const sal_Char __FAR_DATA szServiceName_UnoControlFileControl[] = "stardiv.vcl.control.FileControl", szServiceName2_UnoControlFileControl[] = "com.sun.star.awt.UnoControlFileControl"; +const sal_Char __FAR_DATA szServiceName_UnoControlFileControlModel[] = "stardiv.vcl.controlmodel.FileControl", szServiceName2_UnoControlFileControlModel[] = "com.sun.star.awt.UnoControlFileControlModel"; +const sal_Char __FAR_DATA szServiceName_UnoControlButton[] = "stardiv.vcl.control.Button", szServiceName2_UnoControlButton[] = "com.sun.star.awt.UnoControlButton"; +const sal_Char __FAR_DATA szServiceName_UnoControlButtonModel[] = "stardiv.vcl.controlmodel.Button", szServiceName2_UnoControlButtonModel[] = "com.sun.star.awt.UnoControlButtonModel"; +const sal_Char __FAR_DATA szServiceName_UnoControlImageButton[] = "stardiv.vcl.control.ImageButton", szServiceName2_UnoControlImageButton[] = "com.sun.star.awt.UnoControlImageButton"; +const sal_Char __FAR_DATA szServiceName_UnoControlImageButtonModel[] = "stardiv.vcl.controlmodel.ImageButton", szServiceName2_UnoControlImageButtonModel[] = "com.sun.star.awt.UnoControlImageButtonModel"; +const sal_Char __FAR_DATA szServiceName_UnoControlImageControl[] = "stardiv.vcl.control.ImageControl", szServiceName2_UnoControlImageControl[] = "com.sun.star.awt.UnoControlImageControl"; +const sal_Char __FAR_DATA szServiceName_UnoControlImageControlModel[] = "stardiv.vcl.controlmodel.ImageControl", szServiceName2_UnoControlImageControlModel[] = "com.sun.star.awt.UnoControlImageControlModel"; +const sal_Char __FAR_DATA szServiceName_UnoControlRadioButton[] = "stardiv.vcl.control.RadioButton", szServiceName2_UnoControlRadioButton[] = "com.sun.star.awt.UnoControlRadioButton"; +const sal_Char __FAR_DATA szServiceName_UnoControlRadioButtonModel[] = "stardiv.vcl.controlmodel.RadioButton", szServiceName2_UnoControlRadioButtonModel[] = "com.sun.star.awt.UnoControlRadioButtonModel"; +const sal_Char __FAR_DATA szServiceName_UnoControlCheckBox[] = "stardiv.vcl.control.CheckBox", szServiceName2_UnoControlCheckBox[] = "com.sun.star.awt.UnoControlCheckBox"; +const sal_Char __FAR_DATA szServiceName_UnoControlCheckBoxModel[] = "stardiv.vcl.controlmodel.CheckBox", szServiceName2_UnoControlCheckBoxModel[] = "com.sun.star.awt.UnoControlCheckBoxModel"; +const sal_Char __FAR_DATA szServiceName_UnoControlListBox[] = "stardiv.vcl.control.ListBox", szServiceName2_UnoControlListBox[] = "com.sun.star.awt.UnoControlListBox"; +const sal_Char __FAR_DATA szServiceName_UnoControlListBoxModel[] = "stardiv.vcl.controlmodel.ListBox", szServiceName2_UnoControlListBoxModel[] = "com.sun.star.awt.UnoControlListBoxModel"; +const sal_Char __FAR_DATA szServiceName_UnoControlComboBox[] = "stardiv.vcl.control.ComboBox", szServiceName2_UnoControlComboBox[] = "com.sun.star.awt.UnoControlComboBox"; +const sal_Char __FAR_DATA szServiceName_UnoControlComboBoxModel[] = "stardiv.vcl.controlmodel.ComboBox", szServiceName2_UnoControlComboBoxModel[] = "com.sun.star.awt.UnoControlComboBoxModel"; +const sal_Char __FAR_DATA szServiceName_UnoControlFixedText[] = "stardiv.vcl.control.FixedText", szServiceName2_UnoControlFixedText[] = "com.sun.star.awt.UnoControlFixedText"; +const sal_Char __FAR_DATA szServiceName_UnoControlFixedTextModel[] = "stardiv.vcl.controlmodel.FixedText", szServiceName2_UnoControlFixedTextModel[] = "com.sun.star.awt.UnoControlFixedTextModel"; +const sal_Char __FAR_DATA szServiceName_UnoControlGroupBox[] = "stardiv.vcl.control.GroupBox", szServiceName2_UnoControlGroupBox[] = "com.sun.star.awt.UnoControlGroupBox"; +const sal_Char __FAR_DATA szServiceName_UnoControlGroupBoxModel[] = "stardiv.vcl.controlmodel.GroupBox", szServiceName2_UnoControlGroupBoxModel[] = "com.sun.star.awt.UnoControlGroupBoxModel"; +const sal_Char __FAR_DATA szServiceName_UnoControlDateField[] = "stardiv.vcl.control.DateField", szServiceName2_UnoControlDateField[] = "com.sun.star.awt.UnoControlDateField"; +const sal_Char __FAR_DATA szServiceName_UnoControlDateFieldModel[] = "stardiv.vcl.controlmodel.DateField", szServiceName2_UnoControlDateFieldModel[] = "com.sun.star.awt.UnoControlDateFieldModel"; +const sal_Char __FAR_DATA szServiceName_UnoControlTimeField[] = "stardiv.vcl.control.TimeField", szServiceName2_UnoControlTimeField[] = "com.sun.star.awt.UnoControlTimeField"; +const sal_Char __FAR_DATA szServiceName_UnoControlTimeFieldModel[] = "stardiv.vcl.controlmodel.TimeField", szServiceName2_UnoControlTimeFieldModel[] = "com.sun.star.awt.UnoControlTimeFieldModel"; +const sal_Char __FAR_DATA szServiceName_UnoControlNumericField[] = "stardiv.vcl.control.NumericField", szServiceName2_UnoControlNumericField[] = "com.sun.star.awt.UnoControlNumericField"; +const sal_Char __FAR_DATA szServiceName_UnoControlNumericFieldModel[] = "stardiv.vcl.controlmodel.NumericField", szServiceName2_UnoControlNumericFieldModel[] = "com.sun.star.awt.UnoControlNumericFieldModel"; +const sal_Char __FAR_DATA szServiceName_UnoControlCurrencyField[] = "stardiv.vcl.control.CurrencyField", szServiceName2_UnoControlCurrencyField[] = "com.sun.star.awt.UnoControlCurrencyField"; +const sal_Char __FAR_DATA szServiceName_UnoControlCurrencyFieldModel[] = "stardiv.vcl.controlmodel.CurrencyField", szServiceName2_UnoControlCurrencyFieldModel[] = "com.sun.star.awt.UnoControlCurrencyFieldModel"; +const sal_Char __FAR_DATA szServiceName_UnoControlPatternField[] = "stardiv.vcl.control.PatternField", szServiceName2_UnoControlPatternField[] = "com.sun.star.awt.UnoControlPatternField"; +const sal_Char __FAR_DATA szServiceName_UnoControlPatternFieldModel[] = "stardiv.vcl.controlmodel.PatternField", szServiceName2_UnoControlPatternFieldModel[] = "com.sun.star.awt.UnoControlPatternFieldModel"; +const sal_Char __FAR_DATA szServiceName_UnoControlFormattedField[] = "stardiv.vcl.control.FormattedField", szServiceName2_UnoControlFormattedField[] = "com.sun.star.awt.UnoControlFormattedField"; +const sal_Char __FAR_DATA szServiceName_UnoControlFormattedFieldModel[] = "stardiv.vcl.controlmodel.FormattedField", szServiceName2_UnoControlFormattedFieldModel[] = "com.sun.star.awt.UnoControlFormattedFieldModel"; +const sal_Char __FAR_DATA szServiceName_MVCIntrospection[] = "stardiv.vcl.MVCIntrospection", szServiceName2_MVCIntrospection[] = "com.sun.star.awt.MVCIntrospection"; +const sal_Char __FAR_DATA szServiceName_ImageProducer[] = "stardiv.vcl.ImageProducer", szServiceName2_ImageProducer[] = "com.sun.star.awt.ImageProducer"; +const sal_Char __FAR_DATA szServiceName_PrinterServer[] = "stardiv.vcl.PrinterServer", szServiceName2_PrinterServer[] = "com.sun.star.awt.PrinterServer"; +const sal_Char __FAR_DATA szServiceName_UnoControlProgressBar[] = "stardiv.vcl.control.ProgressBar", szServiceName2_UnoControlProgressBar[] = "com.sun.star.awt.UnoControlProgressBar"; +const sal_Char __FAR_DATA szServiceName_UnoControlProgressBarModel[] = "stardiv.vcl.controlmodel.ProgressBar", szServiceName2_UnoControlProgressBarModel[] = "com.sun.star.awt.UnoControlProgressBarModel"; +const sal_Char __FAR_DATA szServiceName_UnoControlScrollBar[] = "stardiv.vcl.control.ScrollBar", szServiceName2_UnoControlScrollBar[] = "com.sun.star.awt.UnoControlScrollBar"; +const sal_Char __FAR_DATA szServiceName_UnoControlScrollBarModel[] = "stardiv.vcl.controlmodel.ScrollBar", szServiceName2_UnoControlScrollBarModel[] = "com.sun.star.awt.UnoControlScrollBarModel"; +const sal_Char __FAR_DATA szServiceName_UnoControlFixedLine[] = "stardiv.vcl.control.FixedLine", szServiceName2_UnoControlFixedLine[] = "com.sun.star.awt.UnoControlFixedLine"; +const sal_Char __FAR_DATA szServiceName_UnoControlFixedLineModel[] = "stardiv.vcl.controlmodel.FixedLine", szServiceName2_UnoControlFixedLineModel[] = "com.sun.star.awt.UnoControlFixedLineModel"; +const sal_Char __FAR_DATA szServiceName_UnoControlRoadmap[] = "stardiv.vcl.control.Roadmap", szServiceName2_UnoControlRoadmap[] = "com.sun.star.awt.UnoControlRoadmap"; +const sal_Char __FAR_DATA szServiceName_UnoControlRoadmapModel[] = "stardiv.vcl.controlmodel.Roadmap", szServiceName2_UnoControlRoadmapModel[] = "com.sun.star.awt.UnoControlRoadmapModel"; +const sal_Char __FAR_DATA szServiceName_UnoSpinButtonControl[] = "com.sun.star.awt.UnoControlSpinButton"; +const sal_Char __FAR_DATA szServiceName_UnoSpinButtonModel[] = "com.sun.star.awt.UnoControlSpinButtonModel"; +const sal_Char __FAR_DATA szServiceName_TreeControl[] = "com.sun.star.awt.tree.TreeControl"; +const sal_Char __FAR_DATA szServiceName_TreeControlModel[] = "com.sun.star.awt.tree.TreeControlModel"; +const sal_Char __FAR_DATA szServiceName_MutableTreeDataModel[] = "com.sun.star.awt.tree.MutableTreeDataModel"; +const sal_Char __FAR_DATA szServiceName_UnoSimpleAnimationControlModel[] = "com.sun.star.awt.UnoSimpleAnimationControlModel"; +const sal_Char __FAR_DATA szServiceName_UnoSimpleAnimationControl[] = "com.sun.star.awt.UnoSimpleAnimationControl"; +const sal_Char __FAR_DATA szServiceName_UnoThrobberControlModel[] = "com.sun.star.awt.UnoThrobberControlModel"; +const sal_Char __FAR_DATA szServiceName_UnoThrobberControl[] = "com.sun.star.awt.UnoThrobberControl"; +const sal_Char __FAR_DATA szServiceName_UnoControlFixedHyperlink[] = "com.sun.star.awt.UnoControlFixedHyperlink"; +const sal_Char __FAR_DATA szServiceName_UnoControlFixedHyperlinkModel[] = "com.sun.star.awt.UnoControlFixedHyperlinkModel"; +const sal_Char __FAR_DATA szServiceName_GridControl[] = "com.sun.star.awt.grid.UnoControlGrid"; +const sal_Char __FAR_DATA szServiceName_GridControlModel[] = "com.sun.star.awt.grid.UnoControlGridModel"; +const sal_Char __FAR_DATA szServiceName_DefaultGridDataModel[] = "com.sun.star.awt.grid.DefaultGridDataModel"; +const sal_Char __FAR_DATA szServiceName_DefaultGridColumnModel[] = "com.sun.star.awt.grid.DefaultGridColumnModel"; +const sal_Char __FAR_DATA szServiceName_GridColumn[] = "com.sun.star.awt.grid.GridColumn"; diff --git a/toolkit/source/helper/throbberimpl.cxx b/toolkit/source/helper/throbberimpl.cxx new file mode 100644 index 000000000000..7a8e260ab4b8 --- /dev/null +++ b/toolkit/source/helper/throbberimpl.cxx @@ -0,0 +1,138 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "precompiled_toolkit.hxx" +#include <toolkit/helper/throbberimpl.hxx> + +#include <vcl/svapp.hxx> +#include <vcl/fixed.hxx> + +//........................................................................ +namespace toolkit +//........................................................................ +{ + using namespace ::com::sun::star; + + //-------------------------------------------------------------------- + Throbber_Impl::Throbber_Impl( uno::Reference< VCLXWindow > xParent, + sal_Int32 nStepTime, + sal_Bool bRepeat ) + :mrMutex( Application::GetSolarMutex() ) + { + mxParent = xParent; + mbRepeat = bRepeat; + mnStepTime = nStepTime; + maWaitTimer.SetTimeout( mnStepTime ); + maWaitTimer.SetTimeoutHdl( LINK( this, Throbber_Impl, TimeOutHdl ) ); + } + + //-------------------------------------------------------------------- + Throbber_Impl::~Throbber_Impl() + { + maWaitTimer.Stop(); + mxParent = NULL; + } + + //-------------------------------------------------------------------- + void Throbber_Impl::start() throw ( uno::RuntimeException ) + { + ::vos::OGuard aGuard( GetMutex() ); + + mnCurStep = 0; + maWaitTimer.Start(); + } + + //-------------------------------------------------------------------- + void Throbber_Impl::stop() throw ( uno::RuntimeException ) + { + ::vos::OGuard aGuard( GetMutex() ); + + maWaitTimer.Stop(); + } + + //-------------------------------------------------------------------- + void Throbber_Impl::setImageList( const uno::Sequence< uno::Reference< graphic::XGraphic > >& rImageList ) + throw ( uno::RuntimeException ) + { + ::vos::OGuard aGuard( GetMutex() ); + + maImageList = rImageList; + + mnStepCount = maImageList.getLength(); + FixedImage* pImage = static_cast< FixedImage* >( mxParent->GetWindow() ); + if ( pImage ) + { + if ( mnStepCount ) + pImage->SetImage( maImageList[ 0 ] ); + else + pImage->SetImage( Image() ); + } + } + + //-------------------------------------------------------------------- + void Throbber_Impl::initImage() + throw ( uno::RuntimeException ) + { + FixedImage* pImage = static_cast< FixedImage* >( mxParent->GetWindow() ); + if ( pImage && maImageList.getLength() ) + pImage->SetImage( maImageList[ 0 ] ); + } + + //-------------------------------------------------------------------- + sal_Bool Throbber_Impl::isHCMode() + throw ( uno::RuntimeException ) + { + FixedImage* pImage = static_cast< FixedImage* >( mxParent->GetWindow() ); + if ( pImage ) + return pImage->GetSettings().GetStyleSettings().GetHighContrastMode(); + else + return Application::GetSettings().GetStyleSettings().GetHighContrastMode(); + } + + // ----------------------------------------------------------------------- + IMPL_LINK( Throbber_Impl, TimeOutHdl, Throbber_Impl*, EMPTYARG ) + { + ::vos::OGuard aGuard( GetMutex() ); + + FixedImage* pImage = static_cast< FixedImage* >( mxParent->GetWindow() ); + + if ( !pImage || !maImageList.getLength() ) + return 0; + + if ( mnCurStep < mnStepCount - 1 ) + mnCurStep += 1; + else + mnCurStep = 0; + + pImage->SetImage( maImageList[ mnCurStep ] ); + + return 0; + } + +//........................................................................ +} // namespacetoolkit +//........................................................................ + diff --git a/toolkit/source/helper/tkresmgr.cxx b/toolkit/source/helper/tkresmgr.cxx new file mode 100644 index 000000000000..4e1e4153daf1 --- /dev/null +++ b/toolkit/source/helper/tkresmgr.cxx @@ -0,0 +1,100 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <toolkit/helper/tkresmgr.hxx> +#include <tools/simplerm.hxx> +#ifndef _TOOLS_RESMGR_HXX_ +#include <tools/resmgr.hxx> +#endif + + +#include <vcl/svapp.hxx> + + +// ----------------------------------------------------------------------------- +// TkResMgr +// ----------------------------------------------------------------------------- + +SimpleResMgr* TkResMgr::m_pSimpleResMgr = NULL; +ResMgr* TkResMgr::m_pResMgr = NULL; + +// ----------------------------------------------------------------------------- + +TkResMgr::EnsureDelete::~EnsureDelete() +{ + delete TkResMgr::m_pSimpleResMgr; +// delete TkResMgr::m_pResMgr; +} + +// ----------------------------------------------------------------------------- + +void TkResMgr::ensureImplExists() +{ + if (m_pSimpleResMgr) + return; + + ::com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILocale(); + + ByteString sResMgrName( "tk" ); + + m_pSimpleResMgr = SimpleResMgr::Create( sResMgrName.GetBuffer(), aLocale ); + m_pResMgr = ResMgr::CreateResMgr( sResMgrName.GetBuffer() ); + + if (m_pSimpleResMgr) + { + // now that we have a impl class, make sure it's deleted on unloading the library + static TkResMgr::EnsureDelete s_aDeleteTheImplClass; + } +} + +// ----------------------------------------------------------------------------- +::rtl::OUString TkResMgr::loadString( sal_uInt16 nResId ) +{ + ::rtl::OUString sReturn; + + ensureImplExists(); + if ( m_pSimpleResMgr ) + sReturn = m_pSimpleResMgr->ReadString( nResId ); + + return sReturn; +} + +// ----------------------------------------------------------------------------- +Image TkResMgr::loadImage( sal_uInt16 nResId ) +{ + Image aReturn; + + ensureImplExists(); + if ( m_pResMgr ) + aReturn = Image( ResId( nResId, *m_pResMgr ) ); + + return aReturn; +} + +// ----------------------------------------------------------------------------- diff --git a/toolkit/source/helper/unomemorystream.cxx b/toolkit/source/helper/unomemorystream.cxx new file mode 100644 index 000000000000..b07cee100406 --- /dev/null +++ b/toolkit/source/helper/unomemorystream.cxx @@ -0,0 +1,108 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + + +#include <toolkit/helper/unomemorystream.hxx> +#include <algorithm> + +// ---------------------------------------------------- +// class UnoMemoryStream +// ---------------------------------------------------- +UnoMemoryStream::UnoMemoryStream( sal_uInt32 nInitSize, sal_uInt32 nInitResize ) + : SvMemoryStream( nInitSize, nInitResize ) +{ +} + +// ::com::sun::star::uno::XInterface +::com::sun::star::uno::Any UnoMemoryStream::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( ::com::sun::star::io::XInputStream*, this ) ); + return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType )); +} + + +// ::com::sun::star::io::XInputStream +sal_Int32 UnoMemoryStream::readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& rData, sal_Int32 nBytesToRead ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + sal_Int32 nRead = available(); + if ( nRead > nBytesToRead ) + nRead = nBytesToRead; + + rData = ::com::sun::star::uno::Sequence< sal_Int8 >( nRead ); + Read( rData.getArray(), nRead ); + + return nRead; +} + +sal_Int32 UnoMemoryStream::readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& rData, sal_Int32 nMaxBytesToRead ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + sal_Int32 nAvailable = available(); + if( nAvailable ) + { + return readBytes( rData, std::min( nMaxBytesToRead , nAvailable ) ); + } + else + { + // Not the most effective method, but it sticks to the specification + return readBytes( rData, 1 ); + } +} + +void UnoMemoryStream::skipBytes( sal_Int32 nBytesToSkip ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + SeekRel( nBytesToSkip ); +} + +sal_Int32 UnoMemoryStream::available() throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() ); + + sal_uInt32 nStreamPos = Tell(); + sal_uInt32 nEnd = Seek( STREAM_SEEK_TO_END ); + Seek( nStreamPos ); + return nEnd - nStreamPos; +} + +void UnoMemoryStream::closeInput() throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + // nothing to do +} + + + + + diff --git a/toolkit/source/helper/unopropertyarrayhelper.cxx b/toolkit/source/helper/unopropertyarrayhelper.cxx new file mode 100644 index 000000000000..da946ffdc08a --- /dev/null +++ b/toolkit/source/helper/unopropertyarrayhelper.cxx @@ -0,0 +1,160 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + +#include <toolkit/helper/unopropertyarrayhelper.hxx> +#include <toolkit/helper/property.hxx> + +// ---------------------------------------------------- +// class UnoPropertyArrayHelper +// ---------------------------------------------------- + +UnoPropertyArrayHelper::UnoPropertyArrayHelper( const ::com::sun::star::uno::Sequence<sal_Int32>& rIDs ) +{ + sal_Int32 nIDs = rIDs.getLength(); + const sal_Int32* pIDs = rIDs.getConstArray(); + for ( sal_Int32 n = 0; n < nIDs; n++ ) + maIDs.Insert( pIDs[n], (void*)1L ); +} + +UnoPropertyArrayHelper::UnoPropertyArrayHelper( const std::list< sal_uInt16 > &rIDs ) +{ + std::list< sal_uInt16 >::const_iterator iter; + for( iter = rIDs.begin(); iter != rIDs.end(); iter++) + maIDs.Insert( *iter, (void*)1L); +} + +sal_Bool UnoPropertyArrayHelper::ImplHasProperty( sal_uInt16 nPropId ) const +{ + if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) ) + nPropId = BASEPROPERTY_FONTDESCRIPTOR; + + return maIDs.Get( nPropId ) ? sal_True : sal_False; +} + +// ::cppu::IPropertyArrayHelper +sal_Bool UnoPropertyArrayHelper::fillPropertyMembersByHandle( ::rtl::OUString * pPropName, sal_Int16 * pAttributes, sal_Int32 nPropId ) +{ + sal_uInt16 id = sal::static_int_cast< sal_uInt16 >(nPropId); + sal_Bool bValid = ImplHasProperty( id ); + if ( bValid ) + { + if ( pPropName ) + *pPropName = GetPropertyName( id ); + if ( pAttributes ) + *pAttributes = GetPropertyAttribs( id ); + } + return bValid; +} + +::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > UnoPropertyArrayHelper::getProperties() +{ + // Sortiert nach Namen... + + Table aSortedPropsIds; + sal_uInt32 nProps = maIDs.Count(); + for ( sal_uInt32 s = 0; s < nProps; s++ ) + { + sal_uInt16 nId = sal::static_int_cast< sal_uInt16 >( + maIDs.GetObjectKey( s )); + aSortedPropsIds.Insert( 1+GetPropertyOrderNr( nId ), (void*)(sal_uInt32)nId ); + + if ( nId == BASEPROPERTY_FONTDESCRIPTOR ) + { + // Einzelproperties... + for ( sal_uInt16 i = BASEPROPERTY_FONTDESCRIPTORPART_START; i <= BASEPROPERTY_FONTDESCRIPTORPART_END; i++ ) + aSortedPropsIds.Insert( 1+GetPropertyOrderNr( i ), (void*)(sal_uInt32)i ); + } + } + + nProps = aSortedPropsIds.Count(); // koennen jetzt mehr sein + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property> aProps( nProps ); + ::com::sun::star::beans::Property* pProps = aProps.getArray(); + + for ( sal_uInt32 n = 0; n < nProps; n++ ) + { + sal_uInt16 nId = (sal_uInt16)(sal_uIntPtr)aSortedPropsIds.GetObject( n ); + pProps[n].Name = GetPropertyName( nId ); + pProps[n].Handle = nId; + pProps[n].Type = *GetPropertyType( nId ); + pProps[n].Attributes = GetPropertyAttribs( nId ); + } + + return aProps; +} + +::com::sun::star::beans::Property UnoPropertyArrayHelper::getPropertyByName(const ::rtl::OUString& rPropertyName) throw (::com::sun::star::beans::UnknownPropertyException) +{ + ::com::sun::star::beans::Property aProp; + sal_uInt16 nId = GetPropertyId( rPropertyName ); + if ( ImplHasProperty( nId ) ) + { + aProp.Name = rPropertyName; + aProp.Handle = -1; + aProp.Type = *GetPropertyType( nId ); + aProp.Attributes = GetPropertyAttribs( nId ); + } + + return aProp; +} + +sal_Bool UnoPropertyArrayHelper::hasPropertyByName(const ::rtl::OUString& rPropertyName) +{ + return ImplHasProperty( GetPropertyId( rPropertyName ) ); +} + +sal_Int32 UnoPropertyArrayHelper::getHandleByName( const ::rtl::OUString & rPropertyName ) +{ + sal_Int32 nId = (sal_Int32 ) GetPropertyId( rPropertyName ); + return nId ? nId : (-1); +} + +sal_Int32 UnoPropertyArrayHelper::fillHandles( sal_Int32* pHandles, const ::com::sun::star::uno::Sequence< ::rtl::OUString > & rPropNames ) +{ + const ::rtl::OUString* pNames = rPropNames.getConstArray(); + sal_Int32 nValues = rPropNames.getLength(); + sal_Int32 nValidHandles = 0; + + for ( sal_Int32 n = 0; n < nValues; n++ ) + { + sal_uInt16 nPropId = GetPropertyId( pNames[n] ); + if ( nPropId && ImplHasProperty( nPropId ) ) + { + pHandles[n] = nPropId; + nValidHandles++; + } + else + { + pHandles[n] = -1; + } + } + return nValidHandles; +} + + diff --git a/toolkit/source/helper/unowrapper.cxx b/toolkit/source/helper/unowrapper.cxx new file mode 100644 index 000000000000..d7cec7c17354 --- /dev/null +++ b/toolkit/source/helper/unowrapper.cxx @@ -0,0 +1,335 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" +#include <com/sun/star/awt/WindowEvent.hpp> +#include <comphelper/processfactory.hxx> + +#include <toolkit/helper/unowrapper.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <toolkit/helper/convert.hxx> +#include <toolkit/awt/vclxwindow.hxx> +#include <toolkit/awt/vclxwindows.hxx> +#include <toolkit/awt/vclxcontainer.hxx> +#include <toolkit/awt/vclxtopwindow.hxx> +#include <toolkit/awt/vclxgraphics.hxx> + +#include "toolkit/dllapi.h" +#include <vcl/svapp.hxx> +#include <vcl/syswin.hxx> +#include <vcl/menu.hxx> + +#include <tools/debug.hxx> + +using namespace ::com::sun::star; + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > CreateXWindow( Window* pWindow ) +{ + switch ( pWindow->GetType() ) + { + case WINDOW_IMAGERADIOBUTTON: + case WINDOW_IMAGEBUTTON: + case WINDOW_SPINBUTTON: + case WINDOW_MENUBUTTON: + case WINDOW_MOREBUTTON: + case WINDOW_PUSHBUTTON: + case WINDOW_HELPBUTTON: + case WINDOW_OKBUTTON: + case WINDOW_CANCELBUTTON: return new VCLXButton; + case WINDOW_CHECKBOX: return new VCLXCheckBox; + // --> OD 2009-06-29 #i95042# + // A Window of type <MetricBox> is inherited from type <ComboBox>. + // Thus, it does make more sense to return a <VCLXComboBox> instance + // instead of only a <VCLXWindow> instance, especially regarding its + // corresponding accessibility API. + case WINDOW_METRICBOX: + // <-- + case WINDOW_COMBOBOX: return new VCLXComboBox; + case WINDOW_SPINFIELD: + case WINDOW_NUMERICFIELD: + case WINDOW_CURRENCYFIELD: return new VCLXNumericField; + case WINDOW_DATEFIELD: return new VCLXDateField; + case WINDOW_MULTILINEEDIT: + case WINDOW_EDIT: return new VCLXEdit; + case WINDOW_METRICFIELD: return new VCLXSpinField; + case WINDOW_MESSBOX: + case WINDOW_INFOBOX: + case WINDOW_WARNINGBOX: + case WINDOW_QUERYBOX: + case WINDOW_ERRORBOX: return new VCLXMessageBox; + case WINDOW_FIXEDIMAGE: return new VCLXImageControl; + case WINDOW_FIXEDTEXT: return new VCLXFixedText; + case WINDOW_MULTILISTBOX: + case WINDOW_LISTBOX: return new VCLXListBox; + case WINDOW_LONGCURRENCYFIELD: return new VCLXCurrencyField; + case WINDOW_DIALOG: + case WINDOW_MODALDIALOG: + case WINDOW_TABDIALOG: + case WINDOW_BUTTONDIALOG: + case WINDOW_MODELESSDIALOG: return new VCLXDialog; + case WINDOW_PATTERNFIELD: return new VCLXPatternField; + case WINDOW_RADIOBUTTON: return new VCLXRadioButton; + case WINDOW_SCROLLBAR: return new VCLXScrollBar; + case WINDOW_TIMEFIELD: return new VCLXTimeField; + + case WINDOW_SYSWINDOW: + case WINDOW_WORKWINDOW: + case WINDOW_DOCKINGWINDOW: + case WINDOW_FLOATINGWINDOW: + case WINDOW_HELPTEXTWINDOW: return new VCLXTopWindow; + + case WINDOW_WINDOW: + case WINDOW_TABPAGE: return new VCLXContainer; + + case WINDOW_TOOLBOX: return new VCLXToolBox; + + // case WINDOW_FIXEDLINE: + // case WINDOW_FIXEDBITMAP: + // case WINDOW_DATEBOX: + // case WINDOW_GROUPBOX: + // case WINDOW_LONGCURRENCYBOX: + // case WINDOW_SPLITTER: + // case WINDOW_STATUSBAR: + // case WINDOW_TABCONTROL: + // case WINDOW_NUMERICBOX: + // case WINDOW_TRISTATEBOX: + // case WINDOW_TIMEBOX: + // case WINDOW_SPLITWINDOW: + // case WINDOW_SCROLLBARBOX: + // case WINDOW_PATTERNBOX: + // case WINDOW_CURRENCYBOX: + default: return new VCLXWindow( true ); + } +} + +// ---------------------------------------------------- +// class UnoWrapper +// ---------------------------------------------------- + +extern "C" { + +TOOLKIT_DLLPUBLIC UnoWrapperBase* CreateUnoWrapper() +{ + return new UnoWrapper( NULL ); +} + +} // extern "C" + + +UnoWrapper::UnoWrapper( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit>& rxToolkit ) +{ + mxToolkit = rxToolkit; +} + +void UnoWrapper::Destroy() +{ + delete this; +} + +UnoWrapper::~UnoWrapper() +{ +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit> UnoWrapper::GetVCLToolkit() +{ + if ( !mxToolkit.is() ) + mxToolkit = VCLUnoHelper::CreateToolkit(); + return mxToolkit.get(); +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> UnoWrapper::GetWindowInterface( Window* pWindow, BOOL bCreate ) +{ + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xPeer = pWindow->GetWindowPeer(); + if ( !xPeer.is() && bCreate ) + { + xPeer = CreateXWindow( pWindow ); + SetWindowInterface( pWindow, xPeer ); + } + return xPeer; +} + +void UnoWrapper::SetWindowInterface( Window* pWindow, ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xIFace ) +{ + VCLXWindow* pVCLXWindow = VCLXWindow::GetImplementation( xIFace ); + + DBG_ASSERT( pVCLXWindow, "SetComponentInterface - unsupported type" ); + if ( pVCLXWindow ) + { + if( pWindow->GetWindowPeer() ) + { + int i = 0; + i++; + // DBG_ERROR( "UnoWrapper::SetWindowInterface: there already *is* a WindowInterface for this window!" ); + } + pVCLXWindow->SetWindow( pWindow ); + pWindow->SetWindowPeer( xIFace, pVCLXWindow ); + } +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics> UnoWrapper::CreateGraphics( OutputDevice* pOutDev ) +{ + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics> xGrf; + VCLXGraphics* pGrf = new VCLXGraphics; + xGrf = pGrf; + pGrf->Init( pOutDev ); + return xGrf; +} + +void UnoWrapper::ReleaseAllGraphics( OutputDevice* pOutDev ) +{ + List* pLst = pOutDev->GetUnoGraphicsList(); + if ( pLst ) + { + for ( sal_uInt32 n = 0; n < pLst->Count(); n++ ) + { + VCLXGraphics* pGrf = (VCLXGraphics*)pLst->GetObject( n ); + pGrf->SetOutputDevice( NULL ); + } + } + +} + +// MT: Wurde im Window-CTOR gerufen, damit Container-Listener +// vom Parent reagieren, aber hat sowieso nicht richtig funktioniert, +// weil im Window-CTOR das Interface noch nicht da ist! +// => Nur Listener rufen, wenn ueber das ::com::sun::star::awt::Toolkit erzeugt + +/* +void ImplSmartWindowCreated( Window* pNewWindow ) +{ + UNOWindowData* pParentUNOData = pNewWindow->GetParent() ? + pNewWindow->GetParent()->GetUNOData() : NULL; + + if ( pParentUNOData && pParentUNOData->GetListeners( EL_CONTAINER ) ) + { + UNOWindowData* pUNOData = pNewWindow->GetUNOData(); + if ( !pUNOData ) + pUNOData = ImplSmartCreateUNOData( pNewWindow ); + + ::com::sun::star::awt::VclContainerEvent aEvent; + aEvent.Source = (UsrObject*)pParentUNOData->GetWindowPeer(); + aEvent.Id = VCLCOMPONENT_ADDED; + aEvent.Child = (UsrObject*)pUNOData->GetWindowPeer(); + + EventList* pLst = pParentUNOData->GetListeners( EL_CONTAINER ); + for ( sal_uInt32 n = 0; n < pLst->Count(); n++ ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > * pRef = pLst->GetObject( n ); + ((::com::sun::star::awt::XVclContainerListener*)(::com::sun::star::lang::XEventListener*)*pRef)->windowAdded( aEvent ); + } + } +} +*/ + +sal_Bool lcl_ImplIsParent( Window* pParentWindow, Window* pPossibleChild ) +{ + Window* pWindow = ( pPossibleChild != pParentWindow ) ? pPossibleChild : NULL; + while ( pWindow && ( pWindow != pParentWindow ) ) + pWindow = pWindow->GetParent(); + + return pWindow ? sal_True : sal_False; +} + +void UnoWrapper::WindowDestroyed( Window* pWindow ) +{ + // ggf. existieren noch von ::com::sun::star::loader::Java erzeugte Childs, die sonst erst + // im Garbage-Collector zerstoert werden... + Window* pChild = pWindow->GetWindow( WINDOW_FIRSTCHILD ); + while ( pChild ) + { + Window* pNextChild = pChild->GetWindow( WINDOW_NEXT ); + + Window* pClient = pChild->GetWindow( WINDOW_CLIENT ); + if ( pClient->GetWindowPeer() ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xComp( pClient->GetComponentInterface( FALSE ), ::com::sun::star::uno::UNO_QUERY ); + xComp->dispose(); + } + + pChild = pNextChild; + } + + // ::com::sun::star::chaos::System-Windows suchen... + Window* pOverlap = pWindow->GetWindow( WINDOW_OVERLAP ); + pOverlap = pOverlap->GetWindow( WINDOW_FIRSTOVERLAP ); + while ( pOverlap ) + { + Window* pNextOverlap = pOverlap->GetWindow( WINDOW_NEXT ); + Window* pClient = pOverlap->GetWindow( WINDOW_CLIENT ); + + if ( pClient->GetWindowPeer() && lcl_ImplIsParent( pWindow, pClient ) ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xComp( pClient->GetComponentInterface( FALSE ), ::com::sun::star::uno::UNO_QUERY ); + xComp->dispose(); + } + + pOverlap = pNextOverlap; + } + + Window* pParent = pWindow->GetParent(); + if ( pParent && pParent->GetWindowPeer() ) + pParent->GetWindowPeer()->notifyWindowRemoved( *pWindow ); + + VCLXWindow* pWindowPeer = pWindow->GetWindowPeer(); + uno::Reference< lang::XComponent > xWindowPeerComp( pWindow->GetComponentInterface( FALSE ), uno::UNO_QUERY ); + OSL_ENSURE( ( pWindowPeer != NULL ) == ( xWindowPeerComp.is() == sal_True ), + "UnoWrapper::WindowDestroyed: inconsistency in the window's peers!" ); + if ( pWindowPeer ) + { + pWindowPeer->SetWindow( NULL ); + pWindow->SetWindowPeer( NULL, NULL ); + } + if ( xWindowPeerComp.is() ) + xWindowPeerComp->dispose(); + + // #102132# Iterate over frames after setting Window peer to NULL, + // because while destroying other frames, we get get into the method again and try + // to destroy this window again... + // #i42462#/#116855# no, don't loop: Instead, just ensure that all our top-window-children + // are disposed, too (which should also be a valid fix for #102132#, but doesn't have the extreme + // performance penalties) + if ( pWindow ) + { + Window* pTopWindowChild = pWindow->GetWindow( WINDOW_FIRSTTOPWINDOWCHILD ); + while ( pTopWindowChild ) + { + OSL_ENSURE( pTopWindowChild->GetParent() == pWindow, "UnoWrapper::WindowDestroyed: inconsistency in the SystemWindow relationship!" ); + + uno::Reference< lang::XComponent > xComp( pTopWindowChild->GetComponentInterface( FALSE ), uno::UNO_QUERY ); + pTopWindowChild = pTopWindowChild->GetWindow( WINDOW_NEXTTOPWINDOWSIBLING ); + if ( xComp.is() ) + xComp->dispose(); + } + } +} + +// ---------------------------------------------------------------------------- +::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > UnoWrapper::CreateAccessible( Menu* pMenu, sal_Bool bIsMenuBar ) +{ + return maAccessibleFactoryAccess.getFactory().createAccessible( pMenu, bIsMenuBar ); +} diff --git a/toolkit/source/helper/vclunohelper.cxx b/toolkit/source/helper/vclunohelper.cxx new file mode 100644 index 000000000000..da91945c0b0e --- /dev/null +++ b/toolkit/source/helper/vclunohelper.cxx @@ -0,0 +1,799 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_toolkit.hxx" + +#include <tools/debug.hxx> +#include <tools/stream.hxx> +#include <vcl/bitmap.hxx> +#include <vcl/window.hxx> +#include <com/sun/star/util/MeasureUnit.hpp> +#include <com/sun/star/awt/XBitmap.hpp> +#include <com/sun/star/awt/XWindow.hpp> +#include <com/sun/star/awt/XDevice.hpp> +#include <com/sun/star/awt/XPointer.hpp> +#include <com/sun/star/awt/SimpleFontMetric.hpp> +#include <com/sun/star/awt/FontDescriptor.hpp> +#include <com/sun/star/awt/XControlContainer.hpp> +#include <com/sun/star/awt/FontWeight.hpp> +#include <com/sun/star/awt/FontWidth.hpp> +#include <com/sun/star/awt/KeyModifier.hpp> +#include <com/sun/star/awt/MouseButton.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/embed/EmbedMapUnits.hpp> + +#include <com/sun/star/graphic/XGraphic.hpp> + +#include <toolkit/helper/vclunohelper.hxx> +#include <toolkit/helper/convert.hxx> +#include <toolkit/awt/vclxbitmap.hxx> +#include <toolkit/awt/vclxregion.hxx> +#include <toolkit/awt/vclxwindow.hxx> +#include <toolkit/awt/vclxgraphics.hxx> +#include <toolkit/awt/vclxpointer.hxx> +#include <toolkit/awt/vclxfont.hxx> +#include <toolkit/controls/unocontrolcontainer.hxx> +#include <toolkit/controls/unocontrolcontainermodel.hxx> + +#include <vcl/graph.hxx> +#include <comphelper/processfactory.hxx> + +#include <com/sun/star/awt/Size.hpp> +#include <com/sun/star/awt/Point.hpp> + +using namespace ::com::sun::star; + +// ---------------------------------------------------- +// class VCLUnoHelper +// ---------------------------------------------------- + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit> VCLUnoHelper::CreateToolkit() +{ + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory(); + ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > xI = xMSF->createInstance( ::rtl::OUString::createFromAscii( szServiceName2_Toolkit ) ); + + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit> xToolkit; + if ( xI.is() ) + xToolkit = ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit>( xI, ::com::sun::star::uno::UNO_QUERY ); + + return xToolkit; +} + +BitmapEx VCLUnoHelper::GetBitmap( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap>& rxBitmap ) +{ + BitmapEx aBmp; + + ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > xGraphic( rxBitmap, ::com::sun::star::uno::UNO_QUERY ); + if( xGraphic.is() ) + { + Graphic aGraphic( xGraphic ); + aBmp = aGraphic.GetBitmapEx(); + } + else if ( rxBitmap.is() ) + { + VCLXBitmap* pVCLBitmap = VCLXBitmap::GetImplementation( rxBitmap ); + if ( pVCLBitmap ) + aBmp = pVCLBitmap->GetBitmap(); + else + { + Bitmap aDIB, aMask; + { + ::com::sun::star::uno::Sequence<sal_Int8> aBytes = rxBitmap->getDIB(); + SvMemoryStream aMem( (char*) aBytes.getArray(), aBytes.getLength(), STREAM_READ ); + aMem >> aDIB; + } + { + ::com::sun::star::uno::Sequence<sal_Int8> aBytes = rxBitmap->getMaskDIB(); + SvMemoryStream aMem( (char*) aBytes.getArray(), aBytes.getLength(), STREAM_READ ); + aMem >> aMask; + } + aBmp = BitmapEx( aDIB, aMask ); + } + } + return aBmp; +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap> VCLUnoHelper::CreateBitmap( const BitmapEx& rBitmap ) +{ + Graphic aGraphic( rBitmap ); + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XBitmap> xBmp( aGraphic.GetXGraphic(), ::com::sun::star::uno::UNO_QUERY ); + return xBmp; +} + +Window* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow>& rxWindow ) +{ + VCLXWindow* pVCLXWindow = VCLXWindow::GetImplementation( rxWindow ); + return pVCLXWindow ? pVCLXWindow->GetWindow() : NULL; +} + +Window* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow2>& rxWindow ) +{ + VCLXWindow* pVCLXWindow = VCLXWindow::GetImplementation( rxWindow ); + return pVCLXWindow ? pVCLXWindow->GetWindow() : NULL; +} + +Window* VCLUnoHelper::GetWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer>& rxWindow ) +{ + VCLXWindow* pVCLXWindow = VCLXWindow::GetImplementation( rxWindow ); + return pVCLXWindow ? pVCLXWindow->GetWindow() : NULL; +} + +Region VCLUnoHelper::GetRegion( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XRegion >& rxRegion ) +{ + Region aRegion; + VCLXRegion* pVCLRegion = VCLXRegion::GetImplementation( rxRegion ); + if ( pVCLRegion ) + aRegion = pVCLRegion->GetRegion(); + else + { + ::com::sun::star::uno::Sequence< ::com::sun::star::awt::Rectangle > aRects = rxRegion->getRectangles(); + sal_Int32 nRects = aRects.getLength(); + for ( sal_Int32 n = 0; n < nRects; n++ ) + aRegion.Union( VCLRectangle( aRects.getArray()[n] ) ); + } + return aRegion; +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow> VCLUnoHelper::GetInterface( Window* pWindow ) +{ + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xWin; + if ( pWindow ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xPeer = pWindow->GetComponentInterface(); + xWin = xWin.query( xPeer ); + } + return xWin; +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XPointer> VCLUnoHelper::CreatePointer() +{ + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPointer> xPointer = new VCLXPointer; + return xPointer; +} + +OutputDevice* VCLUnoHelper::GetOutputDevice( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice>& rxDevice ) +{ + OutputDevice* pOutDev = NULL; + VCLXDevice* pDev = VCLXDevice::GetImplementation( rxDevice ); + if ( pDev ) + pOutDev = pDev->GetOutputDevice(); + return pOutDev; +} + +OutputDevice* VCLUnoHelper::GetOutputDevice( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics>& rxGraphics ) +{ + OutputDevice* pOutDev = NULL; + VCLXGraphics* pGrf = VCLXGraphics::GetImplementation( rxGraphics ); + if ( pGrf ) + pOutDev = pGrf->GetOutputDevice(); + return pOutDev; +} + +Polygon VCLUnoHelper::CreatePolygon( const ::com::sun::star::uno::Sequence< sal_Int32 >& DataX, const ::com::sun::star::uno::Sequence< sal_Int32 >& DataY ) +{ + sal_uInt32 nLen = DataX.getLength(); + const sal_Int32* pDataX = DataX.getConstArray(); + const sal_Int32* pDataY = DataY.getConstArray(); + Polygon aPoly( (sal_uInt16) nLen ); + for ( sal_uInt16 n = 0; n < nLen; n++ ) + { + Point aPnt; + aPnt.X() = pDataX[n]; + aPnt.Y() = pDataY[n]; + aPoly[n] = aPnt; + } + return aPoly; +} + +::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer> VCLUnoHelper::CreateControlContainer( Window* pWindow ) +{ + UnoControlContainer* pContainer = new UnoControlContainer( pWindow->GetComponentInterface( sal_True ) ); + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer > x = pContainer; + + UnoControlModel* pContainerModel = new UnoControlContainerModel; + pContainer->setModel( (::com::sun::star::awt::XControlModel*)pContainerModel ); + + return x; +} + +float VCLUnoHelper::ConvertFontWidth( FontWidth eWidth ) +{ + if( eWidth == WIDTH_DONTKNOW ) + return ::com::sun::star::awt::FontWidth::DONTKNOW; + else if( eWidth == WIDTH_ULTRA_CONDENSED ) + return ::com::sun::star::awt::FontWidth::ULTRACONDENSED; + else if( eWidth == WIDTH_EXTRA_CONDENSED ) + return ::com::sun::star::awt::FontWidth::EXTRACONDENSED; + else if( eWidth == WIDTH_CONDENSED ) + return ::com::sun::star::awt::FontWidth::CONDENSED; + else if( eWidth == WIDTH_SEMI_CONDENSED ) + return ::com::sun::star::awt::FontWidth::SEMICONDENSED; + else if( eWidth == WIDTH_NORMAL ) + return ::com::sun::star::awt::FontWidth::NORMAL; + else if( eWidth == WIDTH_SEMI_EXPANDED ) + return ::com::sun::star::awt::FontWidth::SEMIEXPANDED; + else if( eWidth == WIDTH_EXPANDED ) + return ::com::sun::star::awt::FontWidth::EXPANDED; + else if( eWidth == WIDTH_EXTRA_EXPANDED ) + return ::com::sun::star::awt::FontWidth::EXTRAEXPANDED; + else if( eWidth == WIDTH_ULTRA_EXPANDED ) + return ::com::sun::star::awt::FontWidth::ULTRAEXPANDED; + + DBG_ERROR( "Unknown FontWidth" ); + return ::com::sun::star::awt::FontWidth::DONTKNOW; +} + +FontWidth VCLUnoHelper::ConvertFontWidth( float f ) +{ + if( f <= ::com::sun::star::awt::FontWidth::DONTKNOW ) + return WIDTH_DONTKNOW; + else if( f <= ::com::sun::star::awt::FontWidth::ULTRACONDENSED ) + return WIDTH_ULTRA_CONDENSED; + else if( f <= ::com::sun::star::awt::FontWidth::EXTRACONDENSED ) + return WIDTH_EXTRA_CONDENSED; + else if( f <= ::com::sun::star::awt::FontWidth::CONDENSED ) + return WIDTH_CONDENSED; + else if( f <= ::com::sun::star::awt::FontWidth::SEMICONDENSED ) + return WIDTH_SEMI_CONDENSED; + else if( f <= ::com::sun::star::awt::FontWidth::NORMAL ) + return WIDTH_NORMAL; + else if( f <= ::com::sun::star::awt::FontWidth::SEMIEXPANDED ) + return WIDTH_SEMI_EXPANDED; + else if( f <= ::com::sun::star::awt::FontWidth::EXPANDED ) + return WIDTH_EXPANDED; + else if( f <= ::com::sun::star::awt::FontWidth::EXTRAEXPANDED ) + return WIDTH_EXTRA_EXPANDED; + else if( f <= ::com::sun::star::awt::FontWidth::ULTRAEXPANDED ) + return WIDTH_ULTRA_EXPANDED; + + DBG_ERROR( "Unknown FontWidth" ); + return WIDTH_DONTKNOW; +} + +float VCLUnoHelper::ConvertFontWeight( FontWeight eWeight ) +{ + if( eWeight == WEIGHT_DONTKNOW ) + return ::com::sun::star::awt::FontWeight::DONTKNOW; + else if( eWeight == WEIGHT_THIN ) + return ::com::sun::star::awt::FontWeight::THIN; + else if( eWeight == WEIGHT_ULTRALIGHT ) + return ::com::sun::star::awt::FontWeight::ULTRALIGHT; + else if( eWeight == WEIGHT_LIGHT ) + return ::com::sun::star::awt::FontWeight::LIGHT; + else if( eWeight == WEIGHT_SEMILIGHT ) + return ::com::sun::star::awt::FontWeight::SEMILIGHT; + else if( ( eWeight == WEIGHT_NORMAL ) || ( eWeight == WEIGHT_MEDIUM ) ) + return ::com::sun::star::awt::FontWeight::NORMAL; + else if( eWeight == WEIGHT_SEMIBOLD ) + return ::com::sun::star::awt::FontWeight::SEMIBOLD; + else if( eWeight == WEIGHT_BOLD ) + return ::com::sun::star::awt::FontWeight::BOLD; + else if( eWeight == WEIGHT_ULTRABOLD ) + return ::com::sun::star::awt::FontWeight::ULTRABOLD; + else if( eWeight == WEIGHT_BLACK ) + return ::com::sun::star::awt::FontWeight::BLACK; + + DBG_ERROR( "Unknown FontWeigth" ); + return ::com::sun::star::awt::FontWeight::DONTKNOW; +} + +FontWeight VCLUnoHelper::ConvertFontWeight( float f ) +{ + if( f <= ::com::sun::star::awt::FontWeight::DONTKNOW ) + return WEIGHT_DONTKNOW; + else if( f <= ::com::sun::star::awt::FontWeight::THIN ) + return WEIGHT_THIN; + else if( f <= ::com::sun::star::awt::FontWeight::ULTRALIGHT ) + return WEIGHT_ULTRALIGHT; + else if( f <= ::com::sun::star::awt::FontWeight::LIGHT ) + return WEIGHT_LIGHT; + else if( f <= ::com::sun::star::awt::FontWeight::SEMILIGHT ) + return WEIGHT_SEMILIGHT; + else if( f <= ::com::sun::star::awt::FontWeight::NORMAL ) + return WEIGHT_NORMAL; + else if( f <= ::com::sun::star::awt::FontWeight::SEMIBOLD ) + return WEIGHT_SEMIBOLD; + else if( f <= ::com::sun::star::awt::FontWeight::BOLD ) + return WEIGHT_BOLD; + else if( f <= ::com::sun::star::awt::FontWeight::ULTRABOLD ) + return WEIGHT_ULTRABOLD; + else if( f <= ::com::sun::star::awt::FontWeight::BLACK ) + return WEIGHT_BLACK; + + DBG_ERROR( "Unknown FontWeigth" ); + return WEIGHT_DONTKNOW; +} + + +::com::sun::star::awt::FontDescriptor VCLUnoHelper::CreateFontDescriptor( const Font& rFont ) +{ + ::com::sun::star::awt::FontDescriptor aFD; + aFD.Name = rFont.GetName(); + aFD.StyleName = rFont.GetStyleName(); + aFD.Height = (sal_Int16)rFont.GetSize().Height(); + aFD.Width = (sal_Int16)rFont.GetSize().Width(); + aFD.Family = sal::static_int_cast< sal_Int16 >(rFont.GetFamily()); + aFD.CharSet = rFont.GetCharSet(); + aFD.Pitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch()); + aFD.CharacterWidth = VCLUnoHelper::ConvertFontWidth( rFont.GetWidthType() ); + aFD.Weight= VCLUnoHelper::ConvertFontWeight( rFont.GetWeight() ); + aFD.Slant = (::com::sun::star::awt::FontSlant)rFont.GetItalic(); + aFD.Underline = sal::static_int_cast< sal_Int16 >(rFont.GetUnderline()); + aFD.Strikeout = sal::static_int_cast< sal_Int16 >(rFont.GetStrikeout()); + aFD.Orientation = rFont.GetOrientation(); + aFD.Kerning = rFont.IsKerning(); + aFD.WordLineMode = rFont.IsWordLineMode(); + aFD.Type = 0; // ??? => Nur an Metric... + return aFD; +} + +Font VCLUnoHelper::CreateFont( const ::com::sun::star::awt::FontDescriptor& rDescr, const Font& rInitFont ) +{ + Font aFont( rInitFont ); + if ( rDescr.Name.getLength() ) + aFont.SetName( rDescr.Name ); + if ( rDescr.StyleName.getLength() ) + aFont.SetStyleName( rDescr.StyleName ); + if ( rDescr.Height ) + aFont.SetSize( Size( rDescr.Width, rDescr.Height ) ); + if ( (FontFamily)rDescr.Family != FAMILY_DONTKNOW ) + aFont.SetFamily( (FontFamily)rDescr.Family ); + if ( (CharSet)rDescr.CharSet != RTL_TEXTENCODING_DONTKNOW ) + aFont.SetCharSet( (CharSet)rDescr.CharSet ); + if ( (FontPitch)rDescr.Pitch != PITCH_DONTKNOW ) + aFont.SetPitch( (FontPitch)rDescr.Pitch ); + if ( rDescr.CharacterWidth ) + aFont.SetWidthType( VCLUnoHelper::ConvertFontWidth( rDescr.CharacterWidth ) ); + if ( rDescr.Weight ) + aFont.SetWeight( VCLUnoHelper::ConvertFontWeight( rDescr.Weight ) ); + if ( (FontItalic)rDescr.Slant != ITALIC_DONTKNOW ) + aFont.SetItalic( (FontItalic)rDescr.Slant ); + if ( (FontUnderline)rDescr.Underline != UNDERLINE_DONTKNOW ) + aFont.SetUnderline( (FontUnderline)rDescr.Underline ); + if ( (FontStrikeout)rDescr.Strikeout != STRIKEOUT_DONTKNOW ) + aFont.SetStrikeout( (FontStrikeout)rDescr.Strikeout ); + + // Kein DONTKNOW + aFont.SetOrientation( (short)rDescr.Orientation ); + aFont.SetKerning( rDescr.Kerning ); + aFont.SetWordLineMode( rDescr.WordLineMode ); + + return aFont; +} + +Font VCLUnoHelper::CreateFont( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFont >& rxFont ) +{ + Font aFont; + VCLXFont* pVCLXFont = VCLXFont::GetImplementation( rxFont ); + if ( pVCLXFont ) + aFont = pVCLXFont->GetFont(); + return aFont; +} + + +::com::sun::star::awt::SimpleFontMetric VCLUnoHelper::CreateFontMetric( const FontMetric& rFontMetric ) +{ + ::com::sun::star::awt::SimpleFontMetric aFM; + aFM.Ascent = (sal_Int16)rFontMetric.GetAscent(); + aFM.Descent = (sal_Int16)rFontMetric.GetDescent(); + aFM.Leading = (sal_Int16)rFontMetric.GetIntLeading(); + aFM.Slant = (sal_Int16)rFontMetric.GetSlant(); + aFM.FirstChar = 0x0020; + aFM.LastChar = 0xFFFD; + return aFM; +} + +sal_Bool VCLUnoHelper::IsZero( ::com::sun::star::awt::Rectangle rRect ) +{ + return ( !rRect.X && !rRect.Y && !rRect.Width && !rRect.Height ); +} + +MapUnit VCLUnoHelper::UnoEmbed2VCLMapUnit( sal_Int32 nUnoEmbedMapUnit ) +{ + switch( nUnoEmbedMapUnit ) + { + case ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_MM: + return MAP_100TH_MM; + case ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_MM: + return MAP_10TH_MM; + case ::com::sun::star::embed::EmbedMapUnits::ONE_MM: + return MAP_MM; + case ::com::sun::star::embed::EmbedMapUnits::ONE_CM: + return MAP_CM; + case ::com::sun::star::embed::EmbedMapUnits::ONE_1000TH_INCH: + return MAP_1000TH_INCH; + case ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_INCH: + return MAP_100TH_INCH; + case ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_INCH: + return MAP_10TH_INCH; + case ::com::sun::star::embed::EmbedMapUnits::ONE_INCH: + return MAP_INCH; + case ::com::sun::star::embed::EmbedMapUnits::POINT: + return MAP_POINT; + case ::com::sun::star::embed::EmbedMapUnits::TWIP: + return MAP_TWIP; + case ::com::sun::star::embed::EmbedMapUnits::PIXEL: + return MAP_PIXEL; + } + + OSL_ENSURE( sal_False, "Unexpected UNO map mode is provided!\n" ); + return MAP_LASTENUMDUMMY; +} + +sal_Int32 VCLUnoHelper::VCL2UnoEmbedMapUnit( MapUnit nVCLMapUnit ) +{ + switch( nVCLMapUnit ) + { + case MAP_100TH_MM: + return ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_MM; + case MAP_10TH_MM: + return ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_MM; + case MAP_MM: + return ::com::sun::star::embed::EmbedMapUnits::ONE_MM; + case MAP_CM: + return ::com::sun::star::embed::EmbedMapUnits::ONE_CM; + case MAP_1000TH_INCH: + return ::com::sun::star::embed::EmbedMapUnits::ONE_1000TH_INCH; + case MAP_100TH_INCH: + return ::com::sun::star::embed::EmbedMapUnits::ONE_100TH_INCH; + case MAP_10TH_INCH: + return ::com::sun::star::embed::EmbedMapUnits::ONE_10TH_INCH; + case MAP_INCH: + return ::com::sun::star::embed::EmbedMapUnits::ONE_INCH; + case MAP_POINT: + return ::com::sun::star::embed::EmbedMapUnits::POINT; + case MAP_TWIP: + return ::com::sun::star::embed::EmbedMapUnits::TWIP; + case MAP_PIXEL: + return ::com::sun::star::embed::EmbedMapUnits::PIXEL; + default: ; // avoid compiler warning + } + + OSL_ENSURE( sal_False, "Unexpected VCL map mode is provided!\n" ); + return -1; +} + +using namespace ::com::sun::star::util; + +//==================================================================== +//= file-local helpers +//==================================================================== +namespace +{ + enum UnitConversionDirection + { + FieldUnitToMeasurementUnit, + MeasurementUnitToFieldUnit + }; + + sal_Int16 convertMeasurementUnit( sal_Int16 _nUnit, UnitConversionDirection eDirection, sal_Int16& _rFieldToUNOValueFactor ) + { + static struct _unit_table + { + FieldUnit eFieldUnit; + sal_Int16 nMeasurementUnit; + sal_Int16 nFieldToMeasureFactor; + } aUnits[] = { + { FUNIT_NONE, -1 , -1}, + { FUNIT_MM, MeasureUnit::MM, 1 }, // must precede MM_10TH + { FUNIT_MM, MeasureUnit::MM_10TH, 10 }, + { FUNIT_100TH_MM, MeasureUnit::MM_100TH, 1 }, + { FUNIT_CM, MeasureUnit::CM, 1 }, + { FUNIT_M, MeasureUnit::M, 1 }, + { FUNIT_KM, MeasureUnit::KM, 1 }, + { FUNIT_TWIP, MeasureUnit::TWIP, 1 }, + { FUNIT_POINT, MeasureUnit::POINT, 1 }, + { FUNIT_PICA, MeasureUnit::PICA, 1 }, + { FUNIT_INCH, MeasureUnit::INCH, 1 }, // must precede INCH_*TH + { FUNIT_INCH, MeasureUnit::INCH_10TH, 10 }, + { FUNIT_INCH, MeasureUnit::INCH_100TH, 100 }, + { FUNIT_INCH, MeasureUnit::INCH_1000TH, 1000 }, + { FUNIT_FOOT, MeasureUnit::FOOT, 1 }, + { FUNIT_MILE, MeasureUnit::MILE, 1 }, + }; + for ( size_t i = 0; i < sizeof( aUnits ) / sizeof( aUnits[0] ); ++i ) + { + if ( eDirection == FieldUnitToMeasurementUnit ) + { + if ( ( aUnits[ i ].eFieldUnit == (FieldUnit)_nUnit ) && ( aUnits[ i ].nFieldToMeasureFactor == _rFieldToUNOValueFactor ) ) + return aUnits[ i ].nMeasurementUnit; + } + else + { + if ( aUnits[ i ].nMeasurementUnit == _nUnit ) + { + _rFieldToUNOValueFactor = aUnits[ i ].nFieldToMeasureFactor; + return (sal_Int16)aUnits[ i ].eFieldUnit; + } + } + } + if ( eDirection == FieldUnitToMeasurementUnit ) + return -1; + + _rFieldToUNOValueFactor = 1; + return (sal_Int16)FUNIT_NONE; + } +} +//======================================================================== +//= MeasurementUnitConversion +//======================================================================== +//------------------------------------------------------------------------ +sal_Int16 VCLUnoHelper::ConvertToMeasurementUnit( FieldUnit _nFieldUnit, sal_Int16 _nUNOToFieldValueFactor ) +{ + return convertMeasurementUnit( (sal_Int16)_nFieldUnit, FieldUnitToMeasurementUnit, _nUNOToFieldValueFactor ); +} + +//------------------------------------------------------------------------ +FieldUnit VCLUnoHelper::ConvertToFieldUnit( sal_Int16 _nMeasurementUnit, sal_Int16& _rFieldToUNOValueFactor ) +{ + return (FieldUnit)convertMeasurementUnit( _nMeasurementUnit, MeasurementUnitToFieldUnit, _rFieldToUNOValueFactor ); +} + + +MapUnit /* MapModeUnit */ VCLUnoHelper::ConvertToMapModeUnit(sal_Int16 /* com.sun.star.util.MeasureUnit.* */ _nMeasureUnit) throw (::com::sun::star::lang::IllegalArgumentException) +{ + MapUnit eMode; + switch(_nMeasureUnit) + { + case com::sun::star::util::MeasureUnit::MM_100TH: + eMode = MAP_100TH_MM; + break; + + + case com::sun::star::util::MeasureUnit::MM_10TH: + eMode = MAP_10TH_MM; + break; + + case com::sun::star::util::MeasureUnit::MM: + eMode = MAP_MM; + break; + + case com::sun::star::util::MeasureUnit::CM: + eMode = MAP_CM; + break; + + case com::sun::star::util::MeasureUnit::INCH_1000TH: + eMode = MAP_1000TH_INCH; + break; + + case com::sun::star::util::MeasureUnit::INCH_100TH: + eMode = MAP_100TH_INCH; + break; + + case com::sun::star::util::MeasureUnit::INCH_10TH: + eMode = MAP_10TH_INCH; + break; + + case com::sun::star::util::MeasureUnit::INCH: + eMode = MAP_INCH; + break; + + case com::sun::star::util::MeasureUnit::POINT: + eMode = MAP_POINT; + break; + + case com::sun::star::util::MeasureUnit::TWIP: + eMode = MAP_TWIP; + break; + + case com::sun::star::util::MeasureUnit::PIXEL: + eMode = MAP_PIXEL; + break; + +/* + case com::sun::star::util::MeasureUnit::M: + break; + case com::sun::star::util::MeasureUnit::KM: + break; + case com::sun::star::util::MeasureUnit::PICA: + break; + case com::sun::star::util::MeasureUnit::FOOT: + break; + case com::sun::star::util::MeasureUnit::MILE: + break; + case com::sun::star::util::MeasureUnit::PERCENT: + break; +*/ + case com::sun::star::util::MeasureUnit::APPFONT: + eMode = MAP_APPFONT; + break; + + case com::sun::star::util::MeasureUnit::SYSFONT: + eMode = MAP_SYSFONT; + break; + +/* + case com::sun::star::util::MeasureUnit::RELATIVE: + eMode = MAP_RELATIVE; + break; + case com::sun::star::util::MeasureUnit::REALAPPFONT: + eMode = MAP_REALAPPFONT; + break; +*/ + + default: + throw ::com::sun::star::lang::IllegalArgumentException(::rtl::OUString::createFromAscii("Unsupported measure unit."), NULL, 1 ); + } + return eMode; +} + +sal_Int16 /* com.sun.star.util.MeasureUnit.* */ VCLUnoHelper::ConvertToMeasurementUnit(MapUnit /* MapModeUnit */ _eMapModeUnit) throw (::com::sun::star::lang::IllegalArgumentException) +{ + sal_Int16 nMeasureUnit = 0; + switch (_eMapModeUnit) + { + case MAP_100TH_MM: + nMeasureUnit = com::sun::star::util::MeasureUnit::MM_100TH; + break; + + case MAP_10TH_MM: + nMeasureUnit = com::sun::star::util::MeasureUnit::MM_10TH; + break; + + case MAP_MM: + nMeasureUnit = com::sun::star::util::MeasureUnit::MM; + break; + + case MAP_CM: + nMeasureUnit = com::sun::star::util::MeasureUnit::CM; + break; + + case MAP_1000TH_INCH: + nMeasureUnit = com::sun::star::util::MeasureUnit::INCH_1000TH; + break; + + case MAP_100TH_INCH: + nMeasureUnit = com::sun::star::util::MeasureUnit::INCH_100TH; + break; + + case MAP_10TH_INCH: + nMeasureUnit = com::sun::star::util::MeasureUnit::INCH_10TH; + break; + + case MAP_INCH: + nMeasureUnit = com::sun::star::util::MeasureUnit::INCH; + break; + + case MAP_POINT: + nMeasureUnit = com::sun::star::util::MeasureUnit::POINT; + break; + + case MAP_TWIP: + nMeasureUnit = com::sun::star::util::MeasureUnit::TWIP; + break; + + case MAP_PIXEL: + nMeasureUnit = com::sun::star::util::MeasureUnit::PIXEL; + break; + + case MAP_APPFONT: + nMeasureUnit = com::sun::star::util::MeasureUnit::APPFONT; + break; + + case MAP_SYSFONT: + nMeasureUnit = com::sun::star::util::MeasureUnit::SYSFONT; + break; + +/* + case MAP_RELATIVE: + break; + + case MAP_REALAPPFONT: + break; +*/ + default: + throw ::com::sun::star::lang::IllegalArgumentException(::rtl::OUString::createFromAscii("Unsupported MapMode unit."), NULL, 1 ); + } + return nMeasureUnit; +} + +::Size VCLUnoHelper::ConvertToVCLSize(com::sun::star::awt::Size const& _aSize) +{ + ::Size aVCLSize(_aSize.Width, _aSize.Height); + return aVCLSize; +} + +com::sun::star::awt::Size VCLUnoHelper::ConvertToAWTSize(::Size /* VCLSize */ const& _aSize) +{ + com::sun::star::awt::Size aAWTSize(_aSize.Width(), _aSize.Height()); + return aAWTSize; +} + + +::Point VCLUnoHelper::ConvertToVCLPoint(com::sun::star::awt::Point const& _aPoint) +{ + ::Point aVCLPoint(_aPoint.X, _aPoint.Y); + return aVCLPoint; +} + +com::sun::star::awt::Point VCLUnoHelper::ConvertToAWTPoint(::Point /* VCLPoint */ const& _aPoint) +{ + com::sun::star::awt::Point aAWTPoint(_aPoint.X(), _aPoint.Y()); + return aAWTPoint; +} + +::Rectangle VCLUnoHelper::ConvertToVCLRect( ::com::sun::star::awt::Rectangle const & _rRect ) +{ + return ::Rectangle( _rRect.X, _rRect.Y, _rRect.X + _rRect.Width - 1, _rRect.Y + _rRect.Height - 1 ); +} + +::com::sun::star::awt::Rectangle VCLUnoHelper::ConvertToAWTRect( ::Rectangle const & _rRect ) +{ + return ::com::sun::star::awt::Rectangle( _rRect.Left(), _rRect.Top(), _rRect.GetWidth(), _rRect.GetHeight() ); +} + +awt::MouseEvent VCLUnoHelper::createMouseEvent( const ::MouseEvent& _rVclEvent, const uno::Reference< uno::XInterface >& _rxContext ) +{ + awt::MouseEvent aMouseEvent; + aMouseEvent.Source = _rxContext; + + aMouseEvent.Modifiers = 0; + if ( _rVclEvent.IsShift() ) + aMouseEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::SHIFT; + if ( _rVclEvent.IsMod1() ) + aMouseEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD1; + if ( _rVclEvent.IsMod2() ) + aMouseEvent.Modifiers |= ::com::sun::star::awt::KeyModifier::MOD2; + + aMouseEvent.Buttons = 0; + if ( _rVclEvent.IsLeft() ) + aMouseEvent.Buttons |= ::com::sun::star::awt::MouseButton::LEFT; + if ( _rVclEvent.IsRight() ) + aMouseEvent.Buttons |= ::com::sun::star::awt::MouseButton::RIGHT; + if ( _rVclEvent.IsMiddle() ) + aMouseEvent.Buttons |= ::com::sun::star::awt::MouseButton::MIDDLE; + + aMouseEvent.X = _rVclEvent.GetPosPixel().X(); + aMouseEvent.Y = _rVclEvent.GetPosPixel().Y(); + aMouseEvent.ClickCount = _rVclEvent.GetClicks(); + aMouseEvent.PopupTrigger = sal_False; + + return aMouseEvent; +} + +awt::KeyEvent VCLUnoHelper::createKeyEvent( const ::KeyEvent& _rVclEvent, const uno::Reference< uno::XInterface >& _rxContext ) +{ + awt::KeyEvent aKeyEvent; + aKeyEvent.Source = _rxContext; + + aKeyEvent.Modifiers = 0; + if ( _rVclEvent.GetKeyCode().IsShift() ) + aKeyEvent.Modifiers |= awt::KeyModifier::SHIFT; + if ( _rVclEvent.GetKeyCode().IsMod1() ) + aKeyEvent.Modifiers |= awt::KeyModifier::MOD1; + if ( _rVclEvent.GetKeyCode().IsMod2() ) + aKeyEvent.Modifiers |= awt::KeyModifier::MOD2; + if ( _rVclEvent.GetKeyCode().IsMod3() ) + aKeyEvent.Modifiers |= awt::KeyModifier::MOD3; + + aKeyEvent.KeyCode = _rVclEvent.GetKeyCode().GetCode(); + aKeyEvent.KeyChar = _rVclEvent.GetCharCode(); + aKeyEvent.KeyFunc = ::sal::static_int_cast< sal_Int16 >( _rVclEvent.GetKeyCode().GetFunction()); + + return aKeyEvent; +} diff --git a/toolkit/source/layout/core/bin.cxx b/toolkit/source/layout/core/bin.cxx new file mode 100644 index 000000000000..0f0719f12bbd --- /dev/null +++ b/toolkit/source/layout/core/bin.cxx @@ -0,0 +1,198 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "bin.hxx" + +#include <sal/macros.h> + +namespace layoutimpl +{ + +using namespace css; + +/* Bin */ + +Bin::Bin() : Container() +{ +} + +void SAL_CALL +Bin::addChild( const uno::Reference< awt::XLayoutConstrains >& xChild ) + throw (uno::RuntimeException, awt::MaxChildrenException) +{ + if ( mxChild.is() ) + throw awt::MaxChildrenException(); + if ( xChild.is() ) + { + mxChild = xChild; + setChildParent( xChild ); + queueResize(); + } +} + +void SAL_CALL +Bin::removeChild( const uno::Reference< awt::XLayoutConstrains >& xChild ) + throw (uno::RuntimeException) +{ + if ( xChild == mxChild ) + { + mxChild = uno::Reference< awt::XLayoutConstrains >(); + unsetChildParent( xChild ); + queueResize(); + } +} + +uno::Sequence< uno::Reference< awt::XLayoutConstrains > > SAL_CALL +Bin::getChildren() + throw (uno::RuntimeException) +{ + return getSingleChild (mxChild); +} + +void SAL_CALL +Bin::allocateArea( const awt::Rectangle &rArea ) + throw (uno::RuntimeException) +{ + maAllocation = rArea; + if ( mxChild.is() ) + allocateChildAt( mxChild, rArea ); +} + +awt::Size SAL_CALL +Bin::getMinimumSize() + throw(uno::RuntimeException) +{ + if ( mxChild.is() ) + return maRequisition = maChildRequisition = mxChild->getMinimumSize(); + return maRequisition = awt::Size( 0, 0 ); +} + +uno::Reference< beans::XPropertySet > SAL_CALL +Bin::getChildProperties( const uno::Reference< awt::XLayoutConstrains >& ) + throw (uno::RuntimeException) +{ + return uno::Reference< beans::XPropertySet >(); +} + +sal_Bool SAL_CALL +Bin::hasHeightForWidth() + throw(uno::RuntimeException) +{ + uno::Reference< awt::XLayoutContainer > xChildCont( mxChild, uno::UNO_QUERY ); + if ( xChildCont.is() ) + return xChildCont->hasHeightForWidth(); + return false; +} + +sal_Int32 SAL_CALL +Bin::getHeightForWidth( sal_Int32 nWidth ) + throw(uno::RuntimeException) +{ + uno::Reference< awt::XLayoutContainer > xChildCont( mxChild, uno::UNO_QUERY ); + if ( xChildCont.is() ) + return xChildCont->getHeightForWidth( nWidth ); + return maRequisition.Height; +} + +/* Align */ + +Align::Align() : Bin() +{ + addProp( RTL_CONSTASCII_USTRINGPARAM( "Halign" ), + ::getCppuType( static_cast< const float* >( NULL ) ), + &fHorAlign ); + addProp( RTL_CONSTASCII_USTRINGPARAM( "Valign" ), + ::getCppuType( static_cast< const float* >( NULL ) ), + &fVerAlign ); + addProp( RTL_CONSTASCII_USTRINGPARAM( "Hfill" ), + ::getCppuType( static_cast< const float* >( NULL ) ), + &fHorFill ); + addProp( RTL_CONSTASCII_USTRINGPARAM( "Vfill" ), + ::getCppuType( static_cast< const float* >( NULL ) ), + &fVerFill ); + + fHorAlign = fVerAlign = 0.5; + fHorFill = fVerFill = 0; +} + +void SAL_CALL +Align::allocateArea( const awt::Rectangle &rArea ) + throw (uno::RuntimeException) +{ + maAllocation = rArea; + if ( !mxChild.is() ) + return; + + awt::Rectangle aChildArea; + aChildArea.Width = SAL_MIN( rArea.Width, maChildRequisition.Width ); + aChildArea.Width += (sal_Int32) SAL_MAX( + 0, (rArea.Width - maChildRequisition.Width) * fHorFill ); + aChildArea.Height = SAL_MIN( rArea.Height, maChildRequisition.Height ); + aChildArea.Height += (sal_Int32) SAL_MAX( + 0, (rArea.Height - maChildRequisition.Height) * fVerFill ); + + aChildArea.X = rArea.X + (sal_Int32)( (rArea.Width - aChildArea.Width) * fHorAlign ); + aChildArea.Y = rArea.Y + (sal_Int32)( (rArea.Height - aChildArea.Height) * fVerAlign ); + + allocateChildAt( mxChild, aChildArea ); +} + +bool +Align::emptyVisible () +{ + return true; +} + +/* MinSize */ + +MinSize::MinSize() : Bin() +{ + mnMinWidth = mnMinHeight = 0; + addProp( RTL_CONSTASCII_USTRINGPARAM( "MinWidth" ), + ::getCppuType( static_cast< const long* >( NULL ) ), + &mnMinWidth ); + addProp( RTL_CONSTASCII_USTRINGPARAM( "MinHeight" ), + ::getCppuType( static_cast< const long* >( NULL ) ), + &mnMinHeight ); +} + +bool +MinSize::emptyVisible () +{ + return true; +} + +awt::Size SAL_CALL MinSize::getMinimumSize() + throw(uno::RuntimeException) +{ + Bin::getMinimumSize(); + maRequisition.Width = SAL_MAX( maRequisition.Width, mnMinWidth ); + maRequisition.Height = SAL_MAX( maRequisition.Height, mnMinHeight ); + return maRequisition; +} + +} // namespace layoutimpl diff --git a/toolkit/source/layout/core/bin.hxx b/toolkit/source/layout/core/bin.hxx new file mode 100644 index 000000000000..554f6f1bbcf9 --- /dev/null +++ b/toolkit/source/layout/core/bin.hxx @@ -0,0 +1,113 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +/* A few simple binary containers */ + +#ifndef LAYOUT_CORE_BIN_HXX +#define LAYOUT_CORE_BIN_HXX + +#include <layout/core/container.hxx> + +namespace layoutimpl +{ + +class Bin : public Container +{ +protected: + // Child + css::awt::Size maChildRequisition; + css::uno::Reference< css::awt::XLayoutConstrains > mxChild; + +public: + Bin(); + virtual ~Bin() {} + + // css::awt::XLayoutContainer + virtual void SAL_CALL addChild( const css::uno::Reference< css::awt::XLayoutConstrains >& Child ) + throw (css::uno::RuntimeException, css::awt::MaxChildrenException); + virtual void SAL_CALL removeChild( const css::uno::Reference< css::awt::XLayoutConstrains >& Child ) + throw (css::uno::RuntimeException); + + virtual css::uno::Sequence< css::uno::Reference + < css::awt::XLayoutConstrains > > SAL_CALL getChildren() + throw (css::uno::RuntimeException); + + virtual void SAL_CALL allocateArea( const css::awt::Rectangle &rArea ) + throw (css::uno::RuntimeException); + + virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL getChildProperties( + const css::uno::Reference< css::awt::XLayoutConstrains >& Child ) + throw (css::uno::RuntimeException); + + virtual sal_Bool SAL_CALL hasHeightForWidth() + throw(css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getHeightForWidth( sal_Int32 nWidth ) + throw(css::uno::RuntimeException); + + // css::awt::XLayoutConstrains + virtual css::awt::Size SAL_CALL getMinimumSize() + throw(css::uno::RuntimeException); +}; + +// Align gives control over child position on the allocated space. +class Align : public Bin +{ + friend class AlignChildProps; +protected: + // properties + float fHorAlign, fVerAlign; + float fHorFill, fVerFill; + +public: + Align(); + + bool emptyVisible (); + + // css::awt::XLayoutContainer + virtual void SAL_CALL allocateArea( const css::awt::Rectangle &rArea ) + throw (css::uno::RuntimeException); +}; + +// Makes child request its or a specified size, whatever is larger. +class MinSize : public Bin +{ +protected: + // properties + long mnMinWidth, mnMinHeight; + +public: + MinSize(); + + bool emptyVisible (); + // css::awt::XLayoutContainer + virtual css::awt::Size SAL_CALL getMinimumSize() + throw(css::uno::RuntimeException); +}; + +} // namespace layoutimpl + +#endif /* LAYOUT_CORE_BIN_HXX */ diff --git a/toolkit/source/layout/core/box-base.cxx b/toolkit/source/layout/core/box-base.cxx new file mode 100644 index 000000000000..dbe9163e2117 --- /dev/null +++ b/toolkit/source/layout/core/box-base.cxx @@ -0,0 +1,172 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "box.hxx" + +#include <tools/debug.hxx> +#include <sal/macros.h> + +#include <com/sun/star/awt/XWindow2.hpp> + +// fixed point precision for distributing error +#define FIXED_PT 16 + +namespace layoutimpl +{ + +using namespace css; + +Box_Base::ChildData::ChildData( uno::Reference< awt::XLayoutConstrains > const& xChild ) + : mxChild( xChild ) + , mxProps() + , maRequisition() +{ +} + +static bool isVisible( uno::Reference< awt::XLayoutConstrains > xWidget ) +{ + if ( !xWidget.is() ) + { + DBG_ERROR( "FIXME: invalid child !" ); + return true; + } + + uno::Reference< awt::XWindow2 > xWindow( xWidget, uno::UNO_QUERY ); + if ( xWindow.is() && !xWindow->isVisible() ) + return false; + + uno::Reference< awt::XLayoutContainer > xContainer( xWidget, uno::UNO_QUERY ); + if ( xContainer.is() ) + { + uno::Sequence< uno::Reference< awt::XLayoutConstrains > > aChildren + = xContainer->getChildren(); + + if (!aChildren.getLength ()) + if (Container *c = dynamic_cast <Container*> (xWidget.get ())) + return c->emptyVisible (); + + for ( int i = 0; i < aChildren.getLength(); i++ ) + if ( isVisible( aChildren[i] ) ) + return true; + return false; // this would kill flow without workaround above + } + + return true; +} + +bool Box_Base::ChildData::isVisible() +{ + // FIXME: call the 'isVisible' method on it ? + return layoutimpl::isVisible( mxChild ); +} + +void +Box_Base::AddChild (uno::Reference <awt::XLayoutConstrains> const& xChild) +{ + ChildData *pData = createChild (xChild); + maChildren.push_back (pData); + queueResize (); +} + +void SAL_CALL +Box_Base::addChild (uno::Reference <awt::XLayoutConstrains> const& xChild) + throw (uno::RuntimeException, awt::MaxChildrenException) +{ + if (xChild.is ()) + { + AddChild (xChild); + setChildParent (xChild); + } +} + +Box_Base::ChildData* +Box_Base::removeChildData( std::list< ChildData* > lst, css::uno::Reference< css::awt::XLayoutConstrains > const& xChild ) +{ + for ( std::list< ChildData* >::iterator it = lst.begin(); + it != lst.end(); it++ ) + { + if ( (*it)->mxChild == xChild ) + { + lst.erase( it ); + return *it; + } + } + return 0; +} + +void SAL_CALL +Box_Base::removeChild( const uno::Reference< awt::XLayoutConstrains >& xChild ) + throw (uno::RuntimeException) +{ + if ( ChildData* p = removeChildData( maChildren, xChild ) ) + { + delete p; + unsetChildParent( xChild ); + queueResize(); + } + else + { + DBG_ERROR( "Box_Base: removeChild: no such child" ); + } +} + +uno::Sequence< uno::Reference < awt::XLayoutConstrains > > SAL_CALL +Box_Base::getChildren() + throw (uno::RuntimeException) +{ + uno::Sequence< uno::Reference< awt::XLayoutConstrains > > children( maChildren.size() ); + unsigned int index = 0; + for ( std::list< ChildData* >::iterator it = maChildren.begin(); + it != maChildren.end(); it++, index++ ) + children[index] = ( *it )->mxChild; + + return children; +} + +uno::Reference< beans::XPropertySet > SAL_CALL +Box_Base::getChildProperties( const uno::Reference< awt::XLayoutConstrains >& xChild ) + throw (uno::RuntimeException) +{ + + for ( std::list< ChildData * >::iterator it = maChildren.begin(); + it != maChildren.end(); it++) + { + if ( ( *it )->mxChild == xChild ) + { + if ( !( *it )->mxProps.is() ) + { + PropHelper *pProps = createChildProps( *it ); + pProps->setChangeListener( this ); + ( *it )->mxProps = pProps; + } + return (*it)->mxProps; + } + } + return uno::Reference< beans::XPropertySet >(); +} + +} // namespace layoutimpl diff --git a/toolkit/source/layout/core/box-base.hxx b/toolkit/source/layout/core/box-base.hxx new file mode 100644 index 000000000000..4f50f55bf5c4 --- /dev/null +++ b/toolkit/source/layout/core/box-base.hxx @@ -0,0 +1,87 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_CORE_BOX_BASE_HXX +#define LAYOUT_CORE_BOX_BASE_HXX + +#include <layout/core/container.hxx> + +#include <list> + +namespace layoutimpl +{ + +class Box_Base : public Container +{ +public: + // Children properties + struct ChildData + { + css::uno::Reference< css::awt::XLayoutConstrains > mxChild; + css::uno::Reference< css::beans::XPropertySet > mxProps; + css::awt::Size maRequisition; + virtual bool isVisible(); + + ChildData( css::uno::Reference< css::awt::XLayoutConstrains > const& xChild ); + virtual ~ChildData() { }; + }; + + struct ChildProps: public PropHelper + { + //ChildProps( ChildProps* ); + }; + +protected: + std::list< ChildData* > maChildren; + + + virtual ChildData *createChild( css::uno::Reference< css::awt::XLayoutConstrains > const& xChild ) = 0; + virtual ChildProps *createChildProps( ChildData* pData ) = 0; + + ChildData *removeChildData( std::list< ChildData *>, css::uno::Reference< css::awt::XLayoutConstrains > const& Child ); + +public: + void AddChild( const css::uno::Reference< css::awt::XLayoutConstrains >& Child); + + // css::awt::XLayoutContainer + virtual void SAL_CALL addChild( const css::uno::Reference< css::awt::XLayoutConstrains >& Child) + throw (css::uno::RuntimeException, css::awt::MaxChildrenException); + virtual void SAL_CALL removeChild( const css::uno::Reference< css::awt::XLayoutConstrains >& Child ) + throw (css::uno::RuntimeException); + + virtual css::uno::Sequence< css::uno::Reference + < css::awt::XLayoutConstrains > > SAL_CALL getChildren() + throw (css::uno::RuntimeException); + + virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL getChildProperties( + const css::uno::Reference< css::awt::XLayoutConstrains >& Child ) + throw (css::uno::RuntimeException); +}; + +} // namespace layoutimpl + +#endif /* LAYOUT_CORE_BOX_BASE HXX */ diff --git a/toolkit/source/layout/core/box.cxx b/toolkit/source/layout/core/box.cxx new file mode 100644 index 000000000000..a173bb5b7633 --- /dev/null +++ b/toolkit/source/layout/core/box.cxx @@ -0,0 +1,281 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "box.hxx" + +#include <tools/debug.hxx> +#include <sal/macros.h> + +// fixed point precision for distributing error +#define FIXED_PT 16 + +namespace layoutimpl +{ + +using namespace css; + +Box::ChildProps::ChildProps( Box::ChildData *pData ) +{ + addProp( RTL_CONSTASCII_USTRINGPARAM( "Expand" ), + ::getCppuType( static_cast< const sal_Bool* >( NULL ) ), + &(pData->mbExpand) ); + addProp( RTL_CONSTASCII_USTRINGPARAM( "Fill" ), + ::getCppuType( static_cast< const sal_Bool* >( NULL ) ), + &(pData->mbFill) ); + addProp( RTL_CONSTASCII_USTRINGPARAM( "Padding" ), + ::getCppuType( static_cast< const sal_Int32* >( NULL ) ), + &(pData->mnPadding) ); +} + +Box::ChildData::ChildData( uno::Reference< awt::XLayoutConstrains > const& xChild ) + : Box_Base::ChildData( xChild ) + , mnPadding( 0 ) + , mbExpand( true ) + , mbFill( true ) +{ +} + +Box::ChildData* +Box::createChild( uno::Reference< awt::XLayoutConstrains > const& xChild ) + { + return new ChildData( xChild ); + } + +Box::ChildProps* +Box::createChildProps( Box_Base::ChildData *pData ) +{ + return new ChildProps( static_cast<Box::ChildData*> ( pData ) ); +} + +Box::Box( bool horizontal ) + : Box_Base() + , mnSpacing( 0 ) + , mbHomogeneous( false ) + , mbHorizontal( horizontal ) +{ + addProp( RTL_CONSTASCII_USTRINGPARAM( "Homogeneous" ), + ::getCppuType( static_cast< const sal_Bool* >( NULL ) ), + &mbHomogeneous ); + addProp( RTL_CONSTASCII_USTRINGPARAM( "Spacing" ), + ::getCppuType( static_cast< const sal_Int32* >( NULL ) ), + &mnSpacing ); + mbHasFlowChildren = false; +} + +awt::Size +Box::calculateSize( long nWidth ) +{ + int nVisibleChildren = 0; + // primary vs secundary axis (instead of a X and Y) + int nPrimSize = 0; + int nSecSize = 0; + int nFlowMinWidth = 0; // in case the box only has flow children + + mbHasFlowChildren = false; + + for ( std::list<Box_Base::ChildData *>::const_iterator it + = maChildren.begin(); it != maChildren.end(); it++ ) + { + ChildData *child = static_cast<Box::ChildData*> ( *it ); + if ( !child->isVisible() ) + continue; + + uno::Reference< awt::XLayoutContainer > xChildCont( child->mxChild, uno::UNO_QUERY ); + bool bFlow = xChildCont.is() && xChildCont->hasHeightForWidth(); + + awt::Size aChildSize = child->maRequisition = child->mxChild->getMinimumSize(); + + if ( !mbHorizontal /*vertical*/ && bFlow ) + { + if ( nFlowMinWidth == 0 || nFlowMinWidth > aChildSize.Width ) + nFlowMinWidth = aChildSize.Width; + mbHasFlowChildren = true; + } + else + { + int size = primDim( aChildSize ) + child->mnPadding * 2; + if ( mbHomogeneous ) + nPrimSize = SAL_MAX( nPrimSize, size ); + else + nPrimSize += size; + + nSecSize = SAL_MAX( nSecSize, secDim( aChildSize ) ); + } + nVisibleChildren++; + } + + if ( nVisibleChildren ) + { + if ( mbHomogeneous ) + nPrimSize *= nVisibleChildren; + nPrimSize += (nVisibleChildren - 1) * mnSpacing; + } + + if ( mbHasFlowChildren ) + { + if ( nWidth == 0 ) + nWidth = nSecSize ? nSecSize : nFlowMinWidth; + for ( std::list<Box_Base::ChildData *>::const_iterator it + = maChildren.begin(); it != maChildren.end(); it++ ) + { + ChildData *child = static_cast<Box::ChildData*> ( *it ); + if ( !child->isVisible() ) + continue; + + uno::Reference< awt::XLayoutContainer > xChildCont( child->mxChild, uno::UNO_QUERY ); + bool bFlow = xChildCont.is() && xChildCont->hasHeightForWidth(); + + if ( bFlow ) + nPrimSize += xChildCont->getHeightForWidth( nWidth ); + } + } + + nPrimSize += mnBorderWidth * 2; + nSecSize += mnBorderWidth * 2; + return awt::Size( mbHorizontal ? nPrimSize : nSecSize, + mbHorizontal ? nSecSize : nPrimSize ); +} + +awt::Size SAL_CALL +Box::getMinimumSize() throw(uno::RuntimeException) +{ + maRequisition = calculateSize(); + return maRequisition; +} + +sal_Bool SAL_CALL +Box::hasHeightForWidth() + throw(uno::RuntimeException) +{ + return mbHasFlowChildren; +} + +sal_Int32 SAL_CALL +Box::getHeightForWidth( sal_Int32 nWidth ) + throw(uno::RuntimeException) +{ + if ( hasHeightForWidth() ) + return calculateSize( nWidth ).Height; + return maRequisition.Height; +} + +void SAL_CALL +Box::allocateArea( const awt::Rectangle &newArea ) + throw (uno::RuntimeException) +{ + maAllocation = newArea; + int nVisibleChildren = 0, nExpandChildren = 0; + + for ( std::list<Box_Base::ChildData *>::const_iterator it + = maChildren.begin(); it != maChildren.end(); it++ ) + { + ChildData *child = static_cast<Box::ChildData*> ( *it ); + if ( child->isVisible() ) + { + nVisibleChildren++; + if ( child->mbExpand ) + nExpandChildren++; + } + } + if ( !nVisibleChildren ) + return; + + // split rectangle for dimension helpers + awt::Point newPoint( newArea.X, newArea.Y ); + awt::Size newSize( newArea.Width, newArea.Height ); + + int nExtraSpace; + if ( mbHomogeneous ) + nExtraSpace = ( ( primDim( newSize ) - mnBorderWidth * 2 - + ( nVisibleChildren - 1 ) * mnSpacing )) / nVisibleChildren; + else if ( nExpandChildren ) + { + int reqSize = primDim( maRequisition ); + if ( !mbHorizontal && hasHeightForWidth() ) + reqSize = getHeightForWidth( newArea.Width ); + nExtraSpace = ( primDim( newSize ) - reqSize ) / nExpandChildren; + } + else + nExtraSpace = 0; + + int nChildPrimPoint, nChildSecPoint, nChildPrimSize, nChildSecSize; + + int nStartPoint = primDim( newPoint ) + mnBorderWidth; + int nBoxSecSize = SAL_MAX( 1, secDim( newSize ) - mnBorderWidth * 2 ); + + for ( std::list<Box_Base::ChildData *>::const_iterator it + = maChildren.begin(); it != maChildren.end(); it++ ) + { + ChildData *child = static_cast<Box::ChildData*> ( *it ); + if ( !child->isVisible() ) + continue; + + awt::Point aChildPos; + int nBoxPrimSize; // of the available box space + + if ( mbHomogeneous ) + nBoxPrimSize = nExtraSpace; + else + { + uno::Reference< awt::XLayoutContainer > xChildCont( child->mxChild, uno::UNO_QUERY ); + bool bFlow = xChildCont.is() && xChildCont->hasHeightForWidth(); + if ( !mbHorizontal && bFlow ) + nBoxPrimSize = xChildCont->getHeightForWidth( newArea.Width ); + else + nBoxPrimSize = primDim( child->maRequisition ); + nBoxPrimSize += child->mnPadding; + if ( child->mbExpand ) + nBoxPrimSize += nExtraSpace; + } + + nChildPrimPoint = nStartPoint + child->mnPadding; + nChildSecPoint = secDim( newPoint ) + mnBorderWidth; + + nChildSecSize = nBoxSecSize; + if ( child->mbFill ) + nChildPrimSize = SAL_MAX( 1, nBoxPrimSize - child->mnPadding); + else + { + nChildPrimSize = primDim( child->maRequisition ); + nChildPrimPoint += (nBoxPrimSize - nChildPrimSize) / 2; + + nChildSecPoint += (nBoxSecSize - nChildSecSize) / 2; + } + + awt::Rectangle area; + area.X = mbHorizontal ? nChildPrimPoint : nChildSecPoint; + area.Y = mbHorizontal ? nChildSecPoint : nChildPrimPoint; + area.Width = mbHorizontal ? nChildPrimSize : nChildSecSize; + area.Height = mbHorizontal ? nChildSecSize : nChildPrimSize; + + allocateChildAt( child->mxChild, area ); + + nStartPoint += nBoxPrimSize + mnSpacing + child->mnPadding; + } +} + +} // namespace layoutimpl diff --git a/toolkit/source/layout/core/box.hxx b/toolkit/source/layout/core/box.hxx new file mode 100644 index 000000000000..9e4652a37b2f --- /dev/null +++ b/toolkit/source/layout/core/box.hxx @@ -0,0 +1,102 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_CORE_BOX_HXX +#define LAYOUT_CORE_BOX_HXX + +#include <layout/core/box-base.hxx> + +#include <com/sun/star/awt/Point.hpp> + +namespace layoutimpl +{ + +class Box : public Box_Base +{ +protected: + // Box properties (i.e. affect all children) + sal_Int32 mnSpacing; + sal_Bool mbHomogeneous; + sal_Bool mbHorizontal; // false for Vertical + bool mbHasFlowChildren; + +public: + // Children properties + struct ChildData : public Box_Base::ChildData + { + sal_Int32 mnPadding; + sal_Bool mbExpand; + sal_Bool mbFill; + ChildData( css::uno::Reference< css::awt::XLayoutConstrains > const& xChild ); + }; + + struct ChildProps : public Box_Base::ChildProps + { + ChildProps( ChildData *pData ); + }; + +protected: + ChildData *createChild( css::uno::Reference< css::awt::XLayoutConstrains > const& xChild ); + ChildProps *createChildProps( Box_Base::ChildData* pData ); + +public: + Box( bool horizontal ); + + virtual void SAL_CALL allocateArea( const css::awt::Rectangle &rArea ) + throw (css::uno::RuntimeException); + + virtual css::awt::Size SAL_CALL getMinimumSize() + throw(css::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasHeightForWidth() + throw(css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getHeightForWidth( sal_Int32 nWidth ) + throw(css::uno::RuntimeException); + + // helper: mix of getMinimumSize() and getHeightForWidth() + css::awt::Size calculateSize( long nWidth = 0 ); + +private: + /* Helpers to deal with the joint Box directions. */ + inline int primDim (const css::awt::Size &size) + { if (mbHorizontal) return size.Width; else return size.Height; } + inline int secDim (const css::awt::Size &size) + { if (mbHorizontal) return size.Height; else return size.Width; } + inline int primDim (const css::awt::Point &point) + { if (mbHorizontal) return point.X; else return point.Y; } + inline int secDim (const css::awt::Point &point) + { if (mbHorizontal) return point.Y; else return point.X; } +}; + +struct VBox : public Box +{ VBox() : Box (false) {} }; + +struct HBox : public Box +{ HBox() : Box (true) {} }; + +} // namespace layoutimpl + +#endif /* LAYOUT_CORE_BOX_HXX */ diff --git a/toolkit/source/layout/core/byteseq.cxx b/toolkit/source/layout/core/byteseq.cxx new file mode 100644 index 000000000000..b49297d8b1c9 --- /dev/null +++ b/toolkit/source/layout/core/byteseq.cxx @@ -0,0 +1,76 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <com/sun/star/io/XInputStream.hpp> +#include <osl/file.hxx> +#include <comphelper/oslfile2streamwrap.hxx> + +using osl::File; +using osl::FileBase; +using namespace ::com::sun::star; + +namespace layoutimpl +{ + +uno::Reference< io::XInputStream > getFileAsStream( const rtl::OUString &rName ) +{ + rtl::OUString sFileURL; + if( FileBase::E_None != FileBase::getFileURLFromSystemPath( rName, sFileURL ) ) + sFileURL = rName; // maybe it already was a file url + + File * blobFile = new File(sFileURL); + File::RC errorCode = blobFile->open(OpenFlag_Read); + + uno::Reference<io::XInputStream> xResult; + switch (errorCode) + { + case osl::File::E_None: // got it + xResult.set( new comphelper::OSLInputStreamWrapper(blobFile,true) ); + break; + + case osl::File::E_NOENT: // no file => no stream + delete blobFile; + break; + + default: + delete blobFile; +/* { + rtl::OUStringBuffer sMsg; + sMsg.appendAscii("Cannot open output file \""); + sMsg.append(aURL); + sMsg.appendAscii("\" : "); + sMsg.append(configmgr::FileHelper::createOSLErrorString(errorCode)); + + throw io::IOException(sMsg.makeStringAndClear(),NULL); + } +*/ + } + + return xResult; +} + +} // namespace layoutimpl diff --git a/toolkit/source/layout/core/container.cxx b/toolkit/source/layout/core/container.cxx new file mode 100644 index 000000000000..43f837f32de5 --- /dev/null +++ b/toolkit/source/layout/core/container.cxx @@ -0,0 +1,169 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "container.hxx" + +#include <com/sun/star/awt/XWindow.hpp> +#include <com/sun/star/awt/PosSize.hpp> +#include <tools/debug.hxx> + +namespace layoutimpl { + +using namespace css; + +Container::Container() + : Container_Base() + , PropHelper() + , mnBorderWidth( 0 ) +{ + addProp( RTL_CONSTASCII_USTRINGPARAM( "Border" ), + ::getCppuType( static_cast< const sal_Int32* >( NULL ) ), + &mnBorderWidth ); + setChangeListener( this ); +} + +bool +Container::emptyVisible () +{ + return false; +} + +uno::Any +Container::queryInterface( const uno::Type & rType ) throw (uno::RuntimeException) +{ + uno::Any aRet = Container_Base::queryInterface( rType ); + return aRet.hasValue() ? aRet : PropHelper::queryInterface( rType ); +} + +void +Container::allocateChildAt( const uno::Reference< awt::XLayoutConstrains > &xChild, + const awt::Rectangle &rArea ) + throw( uno::RuntimeException ) +{ + uno::Reference< awt::XLayoutContainer > xCont( xChild, uno::UNO_QUERY ); + if ( xCont.is() ) + xCont->allocateArea( rArea ); + else + { + uno::Reference< awt::XWindow > xWindow( xChild, uno::UNO_QUERY ); + if ( xWindow.is() ) + xWindow->setPosSize( rArea.X, rArea.Y, rArea.Width, rArea.Height, + awt::PosSize::POSSIZE ); + else + { + DBG_ERROR( "Error: non-sizeable child" ); + } + } +} + +uno::Sequence< uno::Reference< awt::XLayoutConstrains > > +Container::getSingleChild ( uno::Reference< awt::XLayoutConstrains >const &xChildOrNil ) +{ + uno::Sequence< uno::Reference< awt::XLayoutConstrains > > aSeq( ( xChildOrNil.is() ? 1 : 0 ) ); + if ( xChildOrNil.is() ) + aSeq[0] = xChildOrNil; + return aSeq; +} + +void +Container::queueResize() +{ + if ( mxLayoutUnit.is() ) + mxLayoutUnit->queueResize( uno::Reference< awt::XLayoutContainer >( this ) ); +} + +void +Container::setChildParent( const uno::Reference< awt::XLayoutConstrains >& xChild ) +{ + uno::Reference< awt::XLayoutContainer > xContChild( xChild, uno::UNO_QUERY ); + if ( xContChild.is() ) + { + xContChild->setParent( uno::Reference< awt::XLayoutContainer >( this ) ); +#if 0 + assert( !mxLayoutUnit.is() ); + xContChild->setLayoutUnit( mxLayoutUnit ); +#endif + } +} + +void +Container::unsetChildParent( const uno::Reference< awt::XLayoutConstrains >& xChild ) +{ + uno::Reference< awt::XLayoutContainer > xContChild( xChild, uno::UNO_QUERY ); + if ( xContChild.is() ) + { + xContChild->setParent( uno::Reference< awt::XLayoutContainer >() ); +#if 0 + xContChild->setLayoutUnit( uno::Reference< awt::XLayoutUnit >() ); +#endif + } +} + +#if 0 +std::string +Container::getLabel() // debug label +{ + std::string depth; + uno::Reference< awt::XLayoutContainer > xContainer( this ); + while ( xContainer.is() ) + { + int node = 0; // child nb + uno::Reference< awt::XLayoutContainer > xParent = xContainer->getContainerParent(); + if ( xParent.is() ) + { + + uno::Sequence< uno::Reference< awt::XLayoutConstrains > > aChildren; + aChildren = xParent->getChildren(); + for ( node = 0; node < aChildren.getLength(); node++ ) + if ( aChildren[ node ] == xContainer ) + break; + } + + char str[ 8 ]; + snprintf( str, 8, "%d", node ); + if ( depth.empty() ) + depth = std::string( str ); + else + depth = std::string( str ) + ":" + depth; + + xContainer = xParent; + } + + return std::string( getName() ) + " (" + depth + ")"; +} +#endif + +void Container::propertiesChanged() +{ + // cl: why this assertion? This is also called to set properties at the top level widget which has no parent!? + // DBG_ASSERT( mxParent.is(), "Properties listener: error container doesn't have parent" ); + + if ( mxLayoutUnit.is() && mxParent.is() ) + mxLayoutUnit->queueResize( mxParent ); +} + +} diff --git a/toolkit/source/layout/core/container.hxx b/toolkit/source/layout/core/container.hxx new file mode 100644 index 000000000000..f236139fb1cb --- /dev/null +++ b/toolkit/source/layout/core/container.hxx @@ -0,0 +1,136 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_CORE_CONTAINER_HXX +#define LAYOUT_CORE_CONTAINER_HXX + +#include <layout/core/helper.hxx> + +#include <cppuhelper/implbase2.hxx> +#include <com/sun/star/awt/MaxChildrenException.hpp> + +namespace layoutimpl +{ +namespace css = ::com::sun::star; + +typedef ::cppu::WeakImplHelper2< css::awt::XLayoutContainer, + css::awt::XLayoutConstrains > Container_Base; + +class TOOLKIT_DLLPUBLIC Container : public Container_Base, public PropHelper, public PropHelper::Listener +{ + friend class ChildProps; +protected: + // Widget properties + css::uno::Reference< css::awt::XLayoutContainer > mxParent; + css::uno::Reference< css::awt::XLayoutUnit > mxLayoutUnit; + css::awt::Size maRequisition; + css::awt::Rectangle maAllocation; + + // Container properties + sal_Int32 mnBorderWidth; + + // Utilities + void allocateChildAt( const css::uno::Reference< css::awt::XLayoutConstrains > &xChild, + const css::awt::Rectangle &rArea ) + throw (css::uno::RuntimeException); + static css::uno::Sequence< css::uno::Reference< css::awt::XLayoutConstrains > > + getSingleChild (const css::uno::Reference< css::awt::XLayoutConstrains > &xChildOrNil); + void setChildParent( const css::uno::Reference< css::awt::XLayoutConstrains >& xChild ); + void unsetChildParent( const css::uno::Reference< css::awt::XLayoutConstrains >& xChild ); + + void queueResize(); + void forceRecalc() { allocateArea( maAllocation ); } + +public: + Container(); + virtual ~Container() {} + + virtual bool emptyVisible (); + + // XInterface + virtual void SAL_CALL acquire() throw() { PropHelper::acquire(); } + virtual void SAL_CALL release() throw() { PropHelper::release(); } + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); + + // css::awt::XLayoutContainer + virtual void SAL_CALL addChild( const css::uno::Reference< css::awt::XLayoutConstrains >& Child ) + throw (css::uno::RuntimeException, css::awt::MaxChildrenException) = 0; + virtual void SAL_CALL removeChild( const css::uno::Reference< css::awt::XLayoutConstrains >& Child ) + throw (css::uno::RuntimeException) = 0; + + virtual css::uno::Sequence< css::uno::Reference + < css::awt::XLayoutConstrains > > SAL_CALL getChildren() + throw (css::uno::RuntimeException) = 0; + + virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL getChildProperties( + const css::uno::Reference< css::awt::XLayoutConstrains >& Child ) + throw (css::uno::RuntimeException) = 0; + + virtual void SAL_CALL allocateArea( const css::awt::Rectangle &rArea ) + throw (css::uno::RuntimeException) = 0; + + void SAL_CALL setLayoutUnit( const css::uno::Reference< css::awt::XLayoutUnit > &xUnit ) + throw(css::uno::RuntimeException) + { mxLayoutUnit = xUnit; } + css::uno::Reference< css::awt::XLayoutUnit > SAL_CALL getLayoutUnit() + throw(css::uno::RuntimeException) + { return mxLayoutUnit; } + + css::awt::Size SAL_CALL getRequestedSize() throw(css::uno::RuntimeException) + { return maRequisition; } + com::sun::star::awt::Rectangle SAL_CALL getAllocatedArea() throw(css::uno::RuntimeException) + { return maAllocation; } + + virtual sal_Bool SAL_CALL hasHeightForWidth() + throw(css::uno::RuntimeException) = 0; + virtual sal_Int32 SAL_CALL getHeightForWidth( sal_Int32 nWidth ) + throw(css::uno::RuntimeException) = 0; + + // css::awt::XLayoutContainer: css::container::XChild + css::uno::Reference< css::uno::XInterface > SAL_CALL getParent() + throw (css::uno::RuntimeException) + { return mxParent; } + void SAL_CALL setParent( const css::uno::Reference< css::uno::XInterface > &xParent ) + throw (css::uno::RuntimeException) + { mxParent = css::uno::Reference< css::awt::XLayoutContainer >( xParent, css::uno::UNO_QUERY ); } + + // css::awt::XLayoutConstrains + virtual css::awt::Size SAL_CALL getMinimumSize() + throw(css::uno::RuntimeException) = 0; + // (not properly implemented in toolkit, ignore it.) + css::awt::Size SAL_CALL getPreferredSize() + throw(css::uno::RuntimeException) { return getMinimumSize(); } // TODO: use this for flow? + css::awt::Size SAL_CALL calcAdjustedSize( const css::awt::Size& rNewSize ) + throw(css::uno::RuntimeException) { return rNewSize; } + +protected: + void propertiesChanged(); +}; + +} // namespace layoutimpl + +#endif /* LAYOUT_CORE_CONTAINER_HXX */ diff --git a/toolkit/source/layout/core/dialogbuttonhbox.cxx b/toolkit/source/layout/core/dialogbuttonhbox.cxx new file mode 100644 index 000000000000..4a54fcecaf8c --- /dev/null +++ b/toolkit/source/layout/core/dialogbuttonhbox.cxx @@ -0,0 +1,289 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <awt/vclxbutton.hxx> +#include <tools/debug.hxx> +#include <toolkit/awt/vclxwindows.hxx> +#include <vcl/button.hxx> + +#include "dialogbuttonhbox.hxx" +#include "flow.hxx" +#include "proplist.hxx" + +#if TEST_LAYOUT && !defined( DBG_UTIL ) +#undef DBG_ERROR +#define DBG_ERROR OSL_TRACE +#undef DBG_ERROR1 +#define DBG_ERROR1 OSL_TRACE +#undef DBG_ERROR2 +#define DBG_ERROR2 OSL_TRACE +#endif /* TEST_LAYOUT && !DBG_UTIL */ + +namespace layoutimpl +{ + +using namespace css; + +//FIXME: how to set platform-dependant variables? +DialogButtonHBox::Ordering const DialogButtonHBox::DEFAULT_ORDERING = +#if defined( MACOSX ) + DialogButtonHBox::MACOS; +#elif defined( SAL_W32 ) +DialogButtonHBox::WINDOWS; +#elif defined( ENABLE_KDE ) +DialogButtonHBox::KDE; +#else /* !MACOSX && !SAL_W32 && !ENABLE_KDE */ +DialogButtonHBox::GNOME; +#endif /* !MACOSX && !SAL_W32 && !ENABLE_KDE */ + +DialogButtonHBox::DialogButtonHBox() + : HBox() + , mnOrdering( DEFAULT_ORDERING ) + , mFlow() + , mpAction( 0 ) + , mpAffirmative( 0 ) + , mpAlternate( 0 ) + , mpApply( 0 ) + , mpCancel( 0 ) + , mpFlow( createChild( uno::Reference< awt::XLayoutConstrains > ( &mFlow ) ) ) + , mpHelp( 0 ) + , mpReset( 0 ) +{ + mbHomogeneous = true; +} + +void +DialogButtonHBox::setOrdering( rtl::OUString const& ordering ) +{ + if ( ordering.equalsIgnoreAsciiCaseAscii( "GNOME" ) ) + mnOrdering = GNOME; + else if ( ordering.equalsIgnoreAsciiCaseAscii( "KDE" ) ) + mnOrdering = KDE; + else if ( ordering.equalsIgnoreAsciiCaseAscii( "MacOS" ) ) + mnOrdering = MACOS; + else if ( ordering.equalsIgnoreAsciiCaseAscii( "Windows" ) ) + mnOrdering = WINDOWS; + else + { + DBG_ERROR1( "DialogButtonHBox: no such ordering: %s", OUSTRING_CSTR( ordering ) ); + } +} + +void +DialogButtonHBox::addChild( uno::Reference< awt::XLayoutConstrains > const& xChild ) + throw ( uno::RuntimeException, awt::MaxChildrenException ) +{ + if ( !xChild.is() ) + return; + + ChildData *p = createChild( xChild ); + +#define IS_BUTTON(t) dynamic_cast<VCLX##t##Button *>( xChild.get () ) + + /* Sort Retry as Action */ + if ( !mpAction && IS_BUTTON( Retry ) ) + mpAction = p; + else if ( !mpAffirmative && IS_BUTTON( OK ) ) + mpAffirmative = p; + else if ( !mpAffirmative && IS_BUTTON( Yes ) ) + mpAffirmative = p; + else if ( !mpAlternate && IS_BUTTON( No ) ) + mpAlternate = p; + /* Sort Ignore as Alternate */ + else if ( !mpAlternate && IS_BUTTON( Ignore ) ) + mpAlternate = p; + else if ( !mpApply && IS_BUTTON( Apply ) ) + mpApply = p; + else if ( !mpCancel && IS_BUTTON( Cancel ) ) + mpCancel = p; + /* Let the user overwrite Flow */ + else if ( /* !mpFlow && */ dynamic_cast<Flow *>( xChild.get () ) ) + mpFlow = p; + else if ( !mpHelp && IS_BUTTON( Help ) ) + mpHelp = p; + else if ( !mpReset && IS_BUTTON( Reset ) ) + mpReset = p; + else + maOther.push_back( p ); + orderChildren(); + setChildParent( xChild ); + queueResize(); +} + +void +DialogButtonHBox::orderChildren() +{ + if ( mnOrdering == WINDOWS ) + windowsOrdering(); + else if ( mnOrdering == MACOS ) + macosOrdering(); + else if ( mnOrdering == KDE ) + kdeOrdering(); + else if ( 1 || mnOrdering == GNOME ) + gnomeOrdering(); +} + +void SAL_CALL +DialogButtonHBox::removeChild( uno::Reference< awt::XLayoutConstrains > const& xChild ) + throw ( uno::RuntimeException) +{ + if ( !xChild.is ()) + return; + + Box_Base::ChildData *p = 0; + + if ( mpAction && mpAction->mxChild == xChild ) + p = mpAction; + else if ( mpAffirmative && mpAffirmative->mxChild == xChild ) + p = mpAffirmative; + else if ( mpAlternate && mpAlternate->mxChild == xChild ) + p = mpAlternate; + else if ( mpApply && mpApply->mxChild == xChild ) + p = mpApply; + else if ( mpCancel && mpCancel->mxChild == xChild ) + p = mpCancel; + else if ( mpFlow && mpFlow->mxChild == xChild ) + p = mpFlow; + else if ( mpReset && mpReset->mxChild == xChild ) + p = mpReset; + else if ( mpHelp && mpHelp->mxChild == xChild ) + p = mpHelp; + else + p = removeChildData( maOther, xChild ); + + if ( p ) + { + delete p; + unsetChildParent( xChild ); + orderChildren(); + queueResize(); + } + else + { + DBG_ERROR( "DialogButtonHBox: removeChild: no such child" ); + } +} + +void +DialogButtonHBox::gnomeOrdering() +{ + std::list< Box_Base::ChildData * > ordered; + if ( mpHelp ) + ordered.push_back( mpHelp ); + if ( mpReset ) + ordered.push_back( mpReset ); + if ( mpFlow && ( mpHelp || mpReset ) ) + ordered.push_back( mpFlow ); + ordered.insert( ordered.end(), maOther.begin(), maOther.end() ); + if ( mpAction ) + ordered.push_back( mpAction ); + if ( mpApply ) + ordered.push_back( mpApply ); + if ( mpAlternate ) + ordered.push_back( mpAlternate ); + if ( mpCancel ) + ordered.push_back( mpCancel ); + if ( mpAffirmative ) + ordered.push_back( mpAffirmative ); + maChildren = ordered; +} + +void +DialogButtonHBox::kdeOrdering() +{ + std::list< Box_Base::ChildData * > ordered; + if ( mpHelp ) + ordered.push_back( mpHelp ); + if ( mpReset ) + ordered.push_back( mpReset ); + if ( mpFlow && ( mpHelp || mpReset ) ) + ordered.push_back( mpFlow ); + ordered.insert( ordered.end(), maOther.begin(), maOther.end() ); + if ( mpAction ) + ordered.push_back( mpAction ); + if ( mpAffirmative ) + ordered.push_back( mpAffirmative ); + if ( mpApply ) + ordered.push_back( mpApply ); + if ( mpAlternate ) + ordered.push_back( mpAlternate ); + if ( mpCancel ) + ordered.push_back( mpCancel ); + maChildren = ordered; +} + +void +DialogButtonHBox::macosOrdering() +{ + std::list< Box_Base::ChildData * > ordered; + if ( mpHelp ) + ordered.push_back( mpHelp ); + if ( mpReset ) + ordered.push_back( mpReset ); + if ( mpApply ) + ordered.push_back( mpApply ); + if ( mpAction ) + ordered.push_back( mpAction ); + ordered.insert( ordered.end(), maOther.begin(), maOther.end() ); + if ( mpFlow ) // Always flow? && ( maOther.size () || mpHelp || mpReset || mpAction ) ) + ordered.push_back( mpFlow ); + if ( mpAlternate ) + ordered.push_back( mpAlternate ); + if ( mpFlow && mpAlternate ) + ordered.push_back( mpFlow ); + if ( mpCancel ) + ordered.push_back( mpCancel ); + if ( mpAffirmative ) + ordered.push_back( mpAffirmative ); + maChildren = ordered; +} + +void +DialogButtonHBox::windowsOrdering() +{ + std::list< Box_Base::ChildData * > ordered; + if ( mpReset ) + ordered.push_back( mpReset ); + if ( mpReset && mpFlow ) + ordered.push_back( mpFlow ); + if ( mpAffirmative ) + ordered.push_back( mpAffirmative ); + if ( mpAlternate ) + ordered.push_back( mpAlternate ); + if ( mpAction ) + ordered.push_back( mpAction ); + if ( mpCancel ) + ordered.push_back( mpCancel ); + if ( mpApply ) + ordered.push_back( mpApply ); + ordered.insert( ordered.end(), maOther.begin(), maOther.end() ); + if ( mpHelp ) + ordered.push_back( mpHelp ); + maChildren = ordered; +} + +} // namespace layoutimpl diff --git a/toolkit/source/layout/core/dialogbuttonhbox.hxx b/toolkit/source/layout/core/dialogbuttonhbox.hxx new file mode 100644 index 000000000000..b1e5ca0f6ba3 --- /dev/null +++ b/toolkit/source/layout/core/dialogbuttonhbox.hxx @@ -0,0 +1,73 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_CORE_DIALOGBUTTONHBOX_HXX +#define LAYOUT_CORE_DIALOGBUTTONHBOX_HXX + +#include <layout/core/box.hxx> +#include <layout/core/flow.hxx> + +namespace layoutimpl +{ + +class DialogButtonHBox : public HBox +{ +public: + DialogButtonHBox(); + + void setOrdering( rtl::OUString const& ordering ); + void SAL_CALL addChild( css::uno::Reference< css::awt::XLayoutConstrains > const& xChild ) throw ( css::uno::RuntimeException, css::awt::MaxChildrenException ); + void SAL_CALL removeChild( css::uno::Reference< css::awt::XLayoutConstrains > const& xChild ) throw ( css::uno::RuntimeException ); + +private: + enum Ordering { PLATFORM, GNOME, KDE, MACOS, WINDOWS }; + + void orderChildren(); + void gnomeOrdering(); + void kdeOrdering(); + void macosOrdering(); + void windowsOrdering(); + + static Ordering const DEFAULT_ORDERING; + Ordering mnOrdering; + Flow mFlow; + + ChildData *mpAction; /* [..]?, [Retry?] */ + ChildData *mpAffirmative; /* OK, Yes, Save */ + ChildData *mpAlternate; /* NO, [Ignore?], Don't save, Quit without saving */ + ChildData *mpApply; /* Deprecated? */ + ChildData *mpCancel; /* Cancel, Close */ + ChildData *mpFlow; + ChildData *mpHelp; + ChildData *mpReset; + + std::list< Box_Base::ChildData *> maOther; +}; + +} // namespace layoutimpl + +#endif /* LAYOUT_CORE_DIALOGBUTTONHBOX_HXX */ diff --git a/toolkit/source/layout/core/factory.cxx b/toolkit/source/layout/core/factory.cxx new file mode 100644 index 000000000000..db9616a8cc77 --- /dev/null +++ b/toolkit/source/layout/core/factory.cxx @@ -0,0 +1,150 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "factory.hxx" + +#include <com/sun/star/registry/XRegistryKey.hpp> +#include <com/sun/star/registry/InvalidRegistryException.hpp> +#include <cppuhelper/factory.hxx> + +#include "root.hxx" + +using namespace ::com::sun::star; +using namespace layoutimpl; + +void * SAL_CALL comp_Layout_component_getFactory( const char * pImplName, void * pServiceManager, void * /*registryKey*/ ) + { + void * pRet = 0; + + ::rtl::OUString aImplName( ::rtl::OUString::createFromAscii( pImplName ) ); + uno::Reference< lang::XSingleServiceFactory > xFactory; + + if ( pServiceManager && aImplName.equals( LayoutFactory::impl_staticGetImplementationName() ) ) + xFactory = ::cppu::createOneInstanceFactory( reinterpret_cast< lang::XMultiServiceFactory*>( pServiceManager ), + LayoutFactory::impl_staticGetImplementationName(), + LayoutFactory::impl_staticCreateSelfInstance, + LayoutFactory::impl_staticGetSupportedServiceNames() ); + if ( xFactory.is() ) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + + return pRet; + } + +sal_Bool SAL_CALL comp_Layout_component_writeInfo( void * /*serviceManager*/, void * pRegistryKey ) + { + if ( pRegistryKey ) + { + try + { + uno::Reference< registry::XRegistryKey > xKey( reinterpret_cast< registry::XRegistryKey* >( pRegistryKey ) ); + uno::Reference< registry::XRegistryKey > xNewKey; + + xNewKey = xKey->createKey( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) + + LayoutFactory::impl_staticGetImplementationName() + + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "/UNO/SERVICES") ) ); + + const uno::Sequence< ::rtl::OUString > aServices = LayoutFactory::impl_staticGetSupportedServiceNames(); + for ( sal_Int32 i = 0; i < aServices.getLength(); i++ ) + xNewKey->createKey( aServices.getConstArray()[i] ); + + return sal_True; + } + catch (registry::InvalidRegistryException &) + { + OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); + } + } + return sal_False; + } + +// Component registration +::rtl::OUString SAL_CALL LayoutFactory::impl_staticGetImplementationName() +{ + return ::rtl::OUString::createFromAscii( "com.sun.star.comp.awt.Layout" ); +} + +uno::Sequence< ::rtl::OUString > SAL_CALL LayoutFactory::impl_staticGetSupportedServiceNames() +{ + uno::Sequence< ::rtl::OUString > aRet(2); + aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.awt.Layout"); + aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.awt.Layout"); + return aRet; +} + +uno::Reference< uno::XInterface > SAL_CALL LayoutFactory::impl_staticCreateSelfInstance( + const uno::Reference< lang::XMultiServiceFactory >& xServiceManager ) +{ + return uno::Reference< uno::XInterface >( *new LayoutFactory( xServiceManager ) ); +} + +// XServiceInfo +::rtl::OUString SAL_CALL LayoutFactory::getImplementationName() + throw ( uno::RuntimeException ) +{ + return impl_staticGetImplementationName(); +} + +uno::Sequence< ::rtl::OUString > SAL_CALL LayoutFactory::getSupportedServiceNames() + throw ( uno::RuntimeException ) +{ + return impl_staticGetSupportedServiceNames(); +} + +sal_Bool SAL_CALL LayoutFactory::supportsService( const ::rtl::OUString& ServiceName ) + throw ( uno::RuntimeException ) +{ + uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames(); + for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ ) + if ( ServiceName.compareTo( aSeq[i] ) == 0 ) + return sal_True; + + return sal_False; +} + +// XSingleServiceFactory +uno::Reference< uno::XInterface > SAL_CALL LayoutFactory::createInstance() + throw ( uno::Exception, + uno::RuntimeException ) +{ + return uno::Reference< uno::XInterface >( + static_cast< OWeakObject* >( new LayoutRoot( m_xFactory ) ), + uno::UNO_QUERY ); +} + +uno::Reference< uno::XInterface > SAL_CALL LayoutFactory::createInstanceWithArguments( + const uno::Sequence< uno::Any >& aArguments ) + throw ( uno::Exception, + uno::RuntimeException ) +{ + uno::Reference< uno::XInterface > layout = createInstance(); + uno::Reference< lang::XInitialization > xInit( layout, uno::UNO_QUERY ); + xInit->initialize( aArguments ); + return layout; +} diff --git a/toolkit/source/layout/core/factory.hxx b/toolkit/source/layout/core/factory.hxx new file mode 100644 index 000000000000..3e2af712b961 --- /dev/null +++ b/toolkit/source/layout/core/factory.hxx @@ -0,0 +1,74 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_CORE_FACTORY_HXX +#define LAYOUT_CORE_FACTORY_HXX + +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <cppuhelper/implbase2.hxx> +#include <toolkit/dllapi.h> + +namespace layoutimpl +{ +class Layout; +} + +class TOOLKIT_DLLPUBLIC LayoutFactory : public ::cppu::WeakImplHelper2< ::com::sun::star::lang::XSingleServiceFactory, + ::com::sun::star::lang::XServiceInfo > +{ + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; + +public: + LayoutFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory ) + : m_xFactory( xFactory ) + { + OSL_ENSURE( xFactory.is(), "No service manager is provided!\n" ); + } + + static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + impl_staticGetSupportedServiceNames(); + + static ::rtl::OUString SAL_CALL impl_staticGetImplementationName(); + + static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL + impl_staticCreateSelfInstance( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ); + + + // XSingleServiceFactory + virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceWithArguments( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (::com::sun::star::uno::RuntimeException); + +}; + +#endif /* LAYOUT_CORE_FACTORY_HXX */ diff --git a/toolkit/source/layout/core/flow.cxx b/toolkit/source/layout/core/flow.cxx new file mode 100644 index 000000000000..9a573b7487f4 --- /dev/null +++ b/toolkit/source/layout/core/flow.cxx @@ -0,0 +1,209 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "flow.hxx" + +#include <sal/macros.h> + +namespace layoutimpl +{ + +using namespace css; + +bool Flow::ChildData::isVisible() +{ + return xChild.is(); +} + +Flow::Flow() + : Container() + , mnSpacing( 0 ) + , mbHomogeneous( false ) +{ + addProp( RTL_CONSTASCII_USTRINGPARAM( "Homogeneous" ), + ::getCppuType( static_cast< const sal_Bool* >( NULL ) ), + &mbHomogeneous ); + addProp( RTL_CONSTASCII_USTRINGPARAM( "Spacing" ), + ::getCppuType( static_cast< const sal_Int32* >( NULL ) ), + &mnSpacing ); +} + +bool +Flow::emptyVisible () +{ + return true; +} + +void SAL_CALL +Flow::addChild( const uno::Reference< awt::XLayoutConstrains >& xChild ) + throw (uno::RuntimeException, css::awt::MaxChildrenException) +{ + if ( xChild.is() ) + { + ChildData *pData = new ChildData(); + pData->xChild = xChild; + maChildren.push_back( pData ); + + setChildParent( xChild ); + queueResize(); + } +} + +void SAL_CALL +Flow::removeChild( const css::uno::Reference< css::awt::XLayoutConstrains >& xChild ) + throw (css::uno::RuntimeException) +{ + for ( std::list< ChildData * >::iterator it = maChildren.begin(); + it != maChildren.end(); it++ ) + { + if ( (*it)->xChild == xChild ) + { + delete *it; + maChildren.erase( it ); + + unsetChildParent( xChild ); + queueResize(); + break; + } + } +} + +css::uno::Sequence< css::uno::Reference < css::awt::XLayoutConstrains > > SAL_CALL +Flow::getChildren() + throw (css::uno::RuntimeException) +{ + uno::Sequence< uno::Reference< awt::XLayoutConstrains > > children( maChildren.size() ); + unsigned int i = 0; + for ( std::list< ChildData * >::iterator it = maChildren.begin(); + it != maChildren.end(); it++, i++ ) + children[i] = (*it)->xChild; + + return children; +} + +uno::Reference< beans::XPropertySet > SAL_CALL +Flow::getChildProperties( const uno::Reference< awt::XLayoutConstrains >& /*xChild*/ ) + throw (uno::RuntimeException) +{ + return uno::Reference< beans::XPropertySet >(); +} + +css::awt::Size +Flow::calculateSize( long nMaxWidth ) +{ + long nNeedHeight = 0; + + std::list<ChildData *>::const_iterator it; + mnEachWidth = 0; + // first pass, for homogeneous property + for (it = maChildren.begin(); it != maChildren.end(); it++) + { + if ( !(*it)->isVisible() ) + continue; + (*it)->aRequisition = (*it)->xChild->getMinimumSize(); + if ( mbHomogeneous ) + mnEachWidth = SAL_MAX( mnEachWidth, (*it)->aRequisition.Width ); + } + + long nRowWidth = 0, nRowHeight = 0; + for (it = maChildren.begin(); it != maChildren.end(); it++) + { + if ( !(*it)->isVisible() ) + continue; + + awt::Size aChildSize = (*it)->aRequisition; + if ( mbHomogeneous ) + aChildSize.Width = mnEachWidth; + + if ( nMaxWidth && nRowWidth > 0 && nRowWidth + aChildSize.Width > nMaxWidth ) + { + nRowWidth = 0; + nNeedHeight += nRowHeight; + nRowHeight = 0; + } + nRowHeight = SAL_MAX( nRowHeight, aChildSize.Height ); + nRowWidth += aChildSize.Width; + } + nNeedHeight += nRowHeight; + + return awt::Size( nRowWidth, nNeedHeight ); +} + +awt::Size SAL_CALL +Flow::getMinimumSize() throw(uno::RuntimeException) +{ + return maRequisition = calculateSize( 0 ); +} + +sal_Bool SAL_CALL +Flow::hasHeightForWidth() + throw(css::uno::RuntimeException) +{ + return true; +} + +sal_Int32 SAL_CALL +Flow::getHeightForWidth( sal_Int32 nWidth ) + throw(css::uno::RuntimeException) +{ + return calculateSize( nWidth ).Height; +} + +void SAL_CALL +Flow::allocateArea( const css::awt::Rectangle &rArea ) + throw (css::uno::RuntimeException) +{ + maAllocation = rArea; + + std::list<ChildData *>::const_iterator it; + long nX = 0, nY = 0, nRowHeight = 0; + for (it = maChildren.begin(); it != maChildren.end(); it++) + { + ChildData *child = *it; + if ( !child->isVisible() ) + continue; + + awt::Size aChildSize( child->aRequisition ); + if ( mbHomogeneous ) + aChildSize.Width = mnEachWidth; + + if ( nX > 0 && nX + aChildSize.Width > rArea.Width ) + { + nX = 0; + nY += nRowHeight; + nRowHeight = 0; + } + nRowHeight = SAL_MAX( nRowHeight, aChildSize.Height ); + + allocateChildAt( child->xChild, + awt::Rectangle( rArea.X + nX, rArea.Y + nY, aChildSize.Width, aChildSize.Height ) ); + + nX += aChildSize.Width; + } +} + +} // namespace layoutimpl diff --git a/toolkit/source/layout/core/flow.hxx b/toolkit/source/layout/core/flow.hxx new file mode 100644 index 000000000000..e2b4708cf261 --- /dev/null +++ b/toolkit/source/layout/core/flow.hxx @@ -0,0 +1,95 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_CORE_FLOW_HXX +#define LAYOUT_CORE_FLOW_HXX + +#include <layout/core/container.hxx> + +#include <list> + +namespace layoutimpl +{ + +class Flow : public Container +{ +protected: + // Box properties (i.e. affect all children) + sal_Int32 mnSpacing; + sal_Bool mbHomogeneous; + +public: + // Children properties + struct ChildData + { + css::awt::Size aRequisition; + css::uno::Reference< css::awt::XLayoutConstrains > xChild; + css::uno::Reference< css::beans::XPropertySet > xProps; + bool isVisible(); + }; + +protected: + std::list< ChildData * > maChildren; + long mnEachWidth; // on homogeneous, the width of every child + +public: + Flow(); + + bool emptyVisible (); + + // css::awt::XLayoutContainer + virtual void SAL_CALL addChild( const css::uno::Reference< css::awt::XLayoutConstrains >& Child ) + throw (css::uno::RuntimeException, css::awt::MaxChildrenException); + virtual void SAL_CALL removeChild( const css::uno::Reference< css::awt::XLayoutConstrains >& Child ) + throw (css::uno::RuntimeException); + + virtual css::uno::Sequence< css::uno::Reference + < css::awt::XLayoutConstrains > > SAL_CALL getChildren() + throw (css::uno::RuntimeException); + + virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL getChildProperties( + const css::uno::Reference< css::awt::XLayoutConstrains >& Child ) + throw (css::uno::RuntimeException); + + virtual void SAL_CALL allocateArea( const css::awt::Rectangle &rArea ) + throw (css::uno::RuntimeException); + + virtual css::awt::Size SAL_CALL getMinimumSize() + throw(css::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasHeightForWidth() + throw(css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getHeightForWidth( sal_Int32 nWidth ) + throw(css::uno::RuntimeException); + +private: + // shared between getMinimumSize() and getHeightForWidth() + css::awt::Size calculateSize( long nMaxWidth ); +}; + +} // namespace layoutimpl + +#endif /* LAYOUT_FLOW_CORE_HXX */ diff --git a/toolkit/source/layout/core/helper.cxx b/toolkit/source/layout/core/helper.cxx new file mode 100644 index 000000000000..d18a4f615d04 --- /dev/null +++ b/toolkit/source/layout/core/helper.cxx @@ -0,0 +1,672 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "helper.hxx" + +#include <assert.h> +#include <list> +#include <com/sun/star/awt/WindowAttribute.hpp> +#include <com/sun/star/awt/XWindow.hpp> +#include <com/sun/star/awt/VclWindowPeerAttribute.hpp> +#include <toolkit/awt/vclxwindow.hxx> +#include <tools/debug.hxx> + +#include "proplist.hxx" + +#if TEST_LAYOUT && !defined( DBG_UTIL ) +#undef DBG_ERROR +#define DBG_ERROR OSL_TRACE +#undef DBG_ERROR1 +#define DBG_ERROR1 OSL_TRACE +#undef DBG_ERROR2 +#define DBG_ERROR2 OSL_TRACE +#endif /* TEST_LAYOUT && !DBG_UTIL */ + +namespace layoutimpl +{ +using namespace com::sun::star; +using rtl::OUString; + +uno::Reference< awt::XWindowPeer > +getParent( uno::Reference< uno::XInterface > xRef ) +{ + do + { + uno::Reference< awt::XWindowPeer > xPeer( xRef, uno::UNO_QUERY ); + if ( xPeer.is() ) + return xPeer; + + uno::Reference< awt::XLayoutContainer > xCont( xRef, uno::UNO_QUERY ); + if ( xCont.is() ) + xRef = xCont->getParent(); + } + while ( xRef.is() ); + + return uno::Reference< awt::XWindowPeer >(); +} + +#if 0 +static uno::Reference< awt::XWindowPeer > +getToplevel( uno::Reference< uno::XInterface > xRef ) +{ + uno::Reference< awt::XWindowPeer > xTop, i; + while ( ( i = uno::Reference< awt::XWindowPeer >( xRef, uno::UNO_QUERY ) ).is() ) + { + xTop = i; + + uno::Reference< awt::XLayoutContainer > xCont( xRef, uno::UNO_QUERY ); + if ( xCont.is() ) + xRef = xCont->getParent(); + else + xRef = uno::Reference< awt::XWindowPeer >(); + } + + return xTop; +} +#endif + +} + +#include "bin.hxx" +#include "box.hxx" +#include "dialogbuttonhbox.hxx" +#include "flow.hxx" +#include "localized-string.hxx" +#include "table.hxx" + +namespace layoutimpl +{ + +oslModule WidgetFactory::mSfx2Library = 0; +WindowCreator WidgetFactory::mSfx2CreateWidget = 0; + +uno::Reference <awt::XLayoutContainer> WidgetFactory::createContainer (OUString const& name) +{ + uno::Reference< awt::XLayoutContainer > xPeer; + + if ( name.equalsAscii( "hbox" ) ) + xPeer = uno::Reference< awt::XLayoutContainer >( new HBox() ); + else if ( name.equalsAscii( "vbox" ) ) + xPeer = uno::Reference< awt::XLayoutContainer >( new VBox() ); + else if ( name.equalsAscii( "table" ) ) + xPeer = uno::Reference< awt::XLayoutContainer >( new Table() ); + else if ( name.equalsAscii( "flow" ) ) + xPeer = uno::Reference< awt::XLayoutContainer >( new Flow() ); + else if ( name.equalsAscii( "bin" ) ) + xPeer = uno::Reference< awt::XLayoutContainer >( new Bin() ); + else if ( name.equalsAscii( "min-size" ) ) + xPeer = uno::Reference< awt::XLayoutContainer >( new MinSize() ); + else if ( name.equalsAscii( "align" ) ) + xPeer = uno::Reference< awt::XLayoutContainer >( new Align() ); + else if ( name.equalsAscii( "dialogbuttonhbox" ) ) + xPeer = uno::Reference< awt::XLayoutContainer >( new DialogButtonHBox() ); + + return xPeer; +} + +uno::Reference <awt::XLayoutConstrains> WidgetFactory::toolkitCreateWidget (uno::Reference <awt::XToolkit> xToolkit, uno::Reference <uno::XInterface> xParent, OUString const& name, long properties) +{ + uno::Reference< awt::XLayoutConstrains > xPeer; + bool bToplevel = !xParent.is(); + + // UNO Control Widget + awt::WindowDescriptor desc; + if ( bToplevel ) + desc.Type = awt::WindowClass_TOP; + else + { + desc.Type = awt::WindowClass_SIMPLE; + +#if 0 + // top container -- a wrapper for framewindow -- is de-coupled + // from awt::XWindowPeer. So, getParent() fails at it. + uno::Reference< awt::XWindowPeer > xWinParent = getParent( xParent ); +#else + uno::Reference< awt::XWindowPeer > xWinParent( xParent, uno::UNO_QUERY ); +#endif + assert( xParent.is() ); + assert( xWinParent.is() ); + /* + With the new three layer instarr/rpath feature, when + prepending toolkit/unxlngx6.pro/lib or $SOLARVER/lib to + LD_LIBRARY_PATH, VCLXWindow::GetImplementation returns 0x0 + vclxtoolkit::ImplCreateWindow failing to create any widget; + although it succeeds here. + + While developing, one now must copy libtlx.so to + $OOO_INSTALL_PREFIX/openoffice.org/basis3.0/program/libtklx.so + each time. + */ + VCLXWindow* parentComponent = VCLXWindow::GetImplementation( xWinParent ); + if ( !parentComponent ) + throw uno::RuntimeException( + OUString::createFromAscii( "parent has no implementation" ), + uno::Reference< uno::XInterface >() ); + desc.Parent = xWinParent; + } + + desc.ParentIndex = 0; + // debugging help ... + desc.Bounds.X = 0; + desc.Bounds.Y = 0; + desc.Bounds.Width = 300; + desc.Bounds.Height = 200; + + desc.WindowAttributes = properties; + desc.WindowServiceName = name; + + uno::Reference< awt::XWindowPeer > xWinPeer; + try + { + OSL_TRACE("Asking toolkit: %s", OUSTRING_CSTR( desc.WindowServiceName ) ); + xWinPeer = xToolkit->createWindow( desc ); + if ( !xWinPeer.is() ) + throw uno::RuntimeException( + OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot create peer" ) ), + uno::Reference< uno::XInterface >() ); + xPeer = uno::Reference< awt::XLayoutConstrains >( xWinPeer, uno::UNO_QUERY ); + } + catch( uno::Exception & ) + { + DBG_ERROR1( "Warning: %s is not a recognized type\n", OUSTRING_CSTR( name ) ); + return uno::Reference< awt::XLayoutConstrains >(); + } + +#if 0 // This shadows the show="false" property and seems otherwise + // unnecessary + + // default to visible, let then people change it on properties + if ( ! bToplevel ) + { + uno::Reference< awt::XWindow> xWindow( xPeer, uno::UNO_QUERY ); + if ( xWindow.is() ) + xWindow->setVisible( true ); + } +#endif + + return xPeer; +} + +uno::Reference< awt::XLayoutConstrains > +WidgetFactory::createWidget (uno::Reference< awt::XToolkit > xToolkit, uno::Reference< uno::XInterface > xParent, OUString const& name, long properties) +{ + uno::Reference< awt::XLayoutConstrains > xPeer; + + xPeer = uno::Reference <awt::XLayoutConstrains> (createContainer (name), uno::UNO_QUERY); + if ( xPeer.is() ) + return xPeer; + + xPeer = implCreateWidget (xParent, name, properties); + if (xPeer.is ()) + return xPeer; + +#define FIXED_INFO 1 +#if FIXED_INFO + OUString tName = name; + // FIXME + if ( name.equalsAscii( "fixedinfo" ) ) + tName = OUString::createFromAscii( "fixedtext" ); + xPeer = toolkitCreateWidget (xToolkit, xParent, tName, properties); +#else + xPeer = toolkitCreateWidget (xToolkit, xParent, name, properties); +#endif + + return xPeer; +} + +PropHelper::PropHelper() : LockHelper() + , cppu::OPropertySetHelper( maBrdcstHelper ) + , pHelper( NULL ) +{ +} + +void +PropHelper::addProp (const char *pName, sal_Int32 nNameLen, rtl_TextEncoding e, + uno::Type aType, void *pPtr) +{ + // this sucks rocks for effiency ... + PropDetails aDetails; + aDetails.aName = rtl::OUString::intern( pName, nNameLen, e ); + aDetails.aType = aType; + aDetails.pValue = pPtr; + maDetails.push_back( aDetails ); +} + +cppu::IPropertyArrayHelper & SAL_CALL +PropHelper::getInfoHelper() +{ + if ( ! pHelper ) + { + uno::Sequence< beans::Property > aProps( maDetails.size() ); + for ( unsigned int i = 0; i < maDetails.size(); i++) + { + aProps[i].Name = maDetails[i].aName; + aProps[i].Type = maDetails[i].aType; + aProps[i].Handle = i; + aProps[i].Attributes = 0; + } + pHelper = new cppu::OPropertyArrayHelper( aProps, false /* fixme: faster ? */ ); + + } + return *pHelper; +} + +sal_Bool SAL_CALL +PropHelper::convertFastPropertyValue( + uno::Any & rConvertedValue, + uno::Any & rOldValue, + sal_Int32 nHandle, + const uno::Any& rValue ) + throw (lang::IllegalArgumentException) +{ + OSL_ASSERT( nHandle >= 0 && nHandle < (sal_Int32) maDetails.size() ); + + // FIXME: no Any::getValue ... + getFastPropertyValue( rOldValue, nHandle ); + if ( rOldValue != rValue ) + { + rConvertedValue = rValue; + return sal_True; // changed + } + else + { + rConvertedValue.clear(); + rOldValue.clear(); + } + return sal_False; +} + + +void SAL_CALL +PropHelper::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, + const uno::Any& rValue ) + throw (uno::Exception) +{ + OSL_ASSERT( nHandle >= 0 && nHandle < (sal_Int32) maDetails.size() ); + + const PropDetails &rInfo = maDetails[ nHandle ]; + + uno_type_assignData( rInfo.pValue, rInfo.aType.getTypeLibType(), + rValue.pData, rValue.pType, + 0, 0, 0 ); + + if ( mpListener ) + mpListener->propertiesChanged(); +} + +void SAL_CALL +PropHelper::getFastPropertyValue( uno::Any& rValue, + sal_Int32 nHandle ) const +{ + OSL_ASSERT( nHandle >= 0 && nHandle < (sal_Int32) maDetails.size() ); + const PropDetails &rInfo = maDetails[ nHandle ]; +#if 0 + switch ( rInfo.aType.getTypeClass() ) + { +#define MAP(classtype,ctype) \ + case uno::TypeClass_##classtype: \ + rValue <<= *(ctype *)(rInfo.pValue); \ + break + MAP( DOUBLE, double ); + MAP( SHORT, sal_Int16 ); + MAP( LONG, sal_Int32 ); + MAP( UNSIGNED_SHORT, sal_uInt16 ); + MAP( UNSIGNED_LONG, sal_uInt32 ); + MAP( STRING, ::rtl::OUString ); + default: + DBG_ERROR( "ERROR: unknown type to map!" ); + break; + } +#undef MAP +#endif + rValue.setValue( rInfo.pValue, rInfo.aType ); +} + +::com::sun::star::uno::Any +PropHelper::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) +{ + return OPropertySetHelper::queryInterface( rType ); +} + +uno::Reference <beans::XPropertySetInfo> SAL_CALL PropHelper::getPropertySetInfo () throw (uno::RuntimeException) +{ + return css::uno::Reference <css::beans::XPropertySetInfo> (createPropertySetInfo (getInfoHelper ())); +} + +} // namespace layoutimpl + +#include <awt/vclxbutton.hxx> +#include <awt/vclxdialog.hxx> +#include <awt/vclxfixedline.hxx> +#include <awt/vclxplugin.hxx> +#include <awt/vclxscroller.hxx> +#include <awt/vclxsplitter.hxx> +#include <awt/vclxtabcontrol.hxx> +#include <awt/vclxtabpage.hxx> +#include <toolkit/awt/vclxtoolkit.hxx> +#include <toolkit/awt/vclxwindow.hxx> +#include <vcl/button.hxx> +#include <vcl/dialog.hxx> +#include <vcl/fixed.hxx> +#include <vcl/tabctrl.hxx> +#include <vcl/tabpage.hxx> +#include <vcl/unohelp.hxx> + +#include <layout/layout.hxx> +#include <toolkit/awt/vclxwindows.hxx> +#include <vcl/lstbox.hxx> +#include <vcl.hxx> + +#include <typeinfo> + +namespace layoutimpl +{ + +uno::Reference <awt::XLayoutConstrains> WidgetFactory::implCreateWidget (uno::Reference <uno::XInterface> xParent, OUString name, long attributes) +{ + Window* parent = 0; + + if (VCLXWindow* parentComponent = VCLXWindow::GetImplementation (xParent)) + parent = parentComponent->GetWindow (); + + VCLXWindow* component = 0; + Window* window = 0; //sfx2CreateWindow (&component, parent, name, attributes); + if (!window) + window = layoutCreateWindow (&component, parent, name, attributes); + + uno::Reference <awt::XLayoutConstrains> reference; + if (window) + { + window->SetCreatedWithToolkit( sal_True ); + if ( component ) + component->SetCreatedWithToolkit( true ); + reference = component; + window->SetComponentInterface( component ); + if ( attributes & awt::WindowAttribute::SHOW ) + window->Show(); + } + + return reference; +} + +extern "C" { static void SAL_CALL thisModule() {} } + +Window* WidgetFactory::sfx2CreateWindow (VCLXWindow** component, Window* parent, OUString const& name, long& attributes) +{ + OSL_TRACE("Asking sfx2: %s", OUSTRING_CSTR (name)); + + if (!mSfx2Library) + { + OUString libraryName = ::vcl::unohelper::CreateLibraryName ("sfx", TRUE); + mSfx2Library = osl_loadModuleRelative (&thisModule, libraryName.pData, SAL_LOADMODULE_DEFAULT); + if (mSfx2Library) + { + OUString functionName (RTL_CONSTASCII_USTRINGPARAM ("CreateWindow")); + mSfx2CreateWidget = (WindowCreator) osl_getFunctionSymbol (mSfx2Library, functionName.pData); + } + } + + if (mSfx2CreateWidget) + return mSfx2CreateWidget (component, name, parent, attributes); + + return 0; +} + +Window* WidgetFactory::layoutCreateWindow (VCLXWindow** component, Window *parent, OUString const& name, long& attributes) +{ + Window* window = 0; + + if (0) + { + ; + } + if ( name.equalsAscii( "dialog" ) ) + { + if ( parent == NULL ) + parent = DIALOG_NO_PARENT; + window = new Dialog( parent, ImplGetWinBits( attributes, 0 ) ); + *component = new layoutimpl::VCLXDialog(); + + attributes ^= awt::WindowAttribute::SHOW; + } + else if ( name.equalsAscii( "modaldialog" ) ) + { + if ( parent == NULL ) + parent = DIALOG_NO_PARENT; + window = new ModalDialog( parent, ImplGetWinBits( attributes, 0 ) ); + *component = new layoutimpl::VCLXDialog(); + + attributes ^= awt::WindowAttribute::SHOW; + } + else if ( name.equalsAscii( "modelessdialog" ) ) + { + if ( parent == NULL ) + parent = DIALOG_NO_PARENT; + window = new ModelessDialog (parent, ImplGetWinBits (attributes, 0)); + *component = new layoutimpl::VCLXDialog(); + + attributes ^= awt::WindowAttribute::SHOW; + } + else if ( name.equalsAscii( "sfxdialog" ) ) + { + if ( parent == NULL ) + parent = DIALOG_NO_PARENT; + window = new ClosingDialog (parent, ImplGetWinBits (attributes, 0)); + *component = new layoutimpl::VCLXDialog(); + + attributes ^= awt::WindowAttribute::SHOW; + } + else if ( name.equalsAscii( "sfxmodaldialog" ) ) + { + if ( parent == NULL ) + parent = DIALOG_NO_PARENT; + window = new ClosingModalDialog( parent, + ImplGetWinBits( attributes, 0 ) ); + *component = new layoutimpl::VCLXDialog(); + + attributes ^= awt::WindowAttribute::SHOW; + } + else if ( name.equalsAscii( "sfxmodelessdialog" ) ) + { + if ( parent == NULL ) + parent = DIALOG_NO_PARENT; + window = new ClosingModelessDialog (parent, ImplGetWinBits (attributes, 0)); + *component = new layoutimpl::VCLXDialog(); + + attributes ^= awt::WindowAttribute::SHOW; + } + else if ( name.equalsAscii( "tabcontrol" ) ) + { + window = new TabControl( parent, ImplGetWinBits( attributes, WINDOW_TABCONTROL ) ); + *component = new layoutimpl::VCLXTabControl(); + } + else if ( name.equalsAscii( "scroller" ) ) + { + // used FixedImage because I just want some empty non-intrusive widget + window = new FixedImage( parent, ImplGetWinBits( attributes, 0 ) ); + *component = new layoutimpl::VCLXScroller(); + } + else if ( name.equalsAscii( "hsplitter" ) || name.equalsAscii( "vsplitter" ) ) + { + window = new FixedImage( parent, ImplGetWinBits( attributes, 0 ) ); + *component = new layoutimpl::VCLXSplitter( name.equalsAscii( "hsplitter" ) ); + } + else if ( name.equalsAscii( "hfixedline" ) || name.equalsAscii( "vfixedline" ) ) + { + WinBits nStyle = ImplGetWinBits( attributes, 0 ); + nStyle ^= WB_HORZ; + if ( name.equalsAscii( "hfixedline" ) ) + nStyle |= WB_HORZ; + else + nStyle |= WB_VERT; + window = new FixedLine( parent, nStyle ); + *component = new layoutimpl::VCLXFixedLine(); + } + else if ( name.equalsAscii( "okbutton" ) ) + { + window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) ); + *component = new layoutimpl::VCLXOKButton( window ); + window->SetType (WINDOW_OKBUTTON); + } + else if ( name.equalsAscii( "cancelbutton" ) ) + { + window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) ); + *component = new layoutimpl::VCLXCancelButton( window ); + window->SetType (WINDOW_CANCELBUTTON); + } + else if ( name.equalsAscii( "yesbutton" ) ) + { + window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) ); + *component = new layoutimpl::VCLXYesButton( window ); + window->SetType (WINDOW_OKBUTTON); + } + else if ( name.equalsAscii( "nobutton" ) ) + { + window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) ); + window->SetType (WINDOW_CANCELBUTTON); + *component = new layoutimpl::VCLXNoButton( window ); + } + else if ( name.equalsAscii( "retrybutton" ) ) + { + window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) ); + *component = new layoutimpl::VCLXRetryButton( window ); + } + else if ( name.equalsAscii( "ignorebutton" ) ) + { + window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) ); + *component = new layoutimpl::VCLXIgnoreButton( window ); + } + else if ( name.equalsAscii( "resetbutton" ) ) + { + window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) ); + *component = new layoutimpl::VCLXResetButton( window ); + } + else if ( name.equalsAscii( "applybutton" ) ) + { + window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) ); + *component = new layoutimpl::VCLXApplyButton( window ); + } + else if ( name.equalsAscii( "helpbutton" ) ) + { + window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) ); + *component = new layoutimpl::VCLXHelpButton( window ); + window->SetType (WINDOW_HELPBUTTON); + } + else if ( name.equalsAscii( "morebutton" ) ) + { + window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) ); + *component = new layoutimpl::VCLXMoreButton( window ); + window->SetType (WINDOW_MOREBUTTON); + } + else if ( name.equalsAscii( "advancedbutton" ) ) + { + window = new PushButton( parent, ImplGetWinBits( attributes, 0 ) ); + *component = new layoutimpl::VCLXAdvancedButton( window ); + } + else if ( name.equalsAscii( "plugin" ) ) + { + window = new Control( parent, ImplGetWinBits( attributes, 0 ) ); +#ifndef __SUNPRO_CC + OSL_TRACE( "%s: parent=%p (%s)\n", __FUNCTION__, parent, typeid( *parent ).name() ); +#endif + *component = new layoutimpl::VCLXPlugin( window, ImplGetWinBits( attributes, 0 ) ); + } + else if ( name.equalsAscii( "tabpage" ) ) + { +#if 0 + if ( !parent ) + parent = layout::TabPage::global_parent; +#else + if (layout::TabPage::global_parent) + parent = layout::TabPage::global_parent; + layout::TabPage::global_parent = 0; +#endif + //window = new TabPage( parent, ImplGetWinBits( attributes, 0 ) ); + attributes ^= awt::WindowAttribute::SHOW; + WinBits nStyle = ImplGetWinBits( attributes, 0 ); + nStyle |= WB_HIDE; + + if (!parent) + { + window = new Dialog( parent, nStyle ); + *component = new VCLXDialog(); + } + else + { + window = new TabPage( parent, nStyle ); + *component = new VCLXTabPage( window ); + } + } + else if ( name.equalsAscii( "string" ) ) + { + // FIXME: move <string>s.text to simple map<string> in root? + attributes &= ~awt::WindowAttribute::SHOW; + window = new Window( parent, ImplGetWinBits( attributes, 0 ) ); + *component = new layoutimpl::LocalizedString(); + } +#if 0 // parent paranoia + else if ( name.equalsAscii( "listbox" ) ) + { + window = new ListBox (parent, ImplGetWinBits (attributes, 0)); + *component = new VCLXListBox (); + } +#endif + else if (name.equalsAscii ("svxfontlistbox") + || name.equalsAscii ("svxlanguagebox")) + { + window = new ListBox (parent, ImplGetWinBits (attributes, 0)); + *component = new VCLXListBox (); + } + return window; +} + +} // namespace layoutimpl + +// Avoid polluting the rest of the code with vcl linkage pieces ... + +#include <vcl/imagerepository.hxx> +#include <vcl/bitmapex.hxx> +#include <vcl/graph.hxx> + +namespace layoutimpl +{ + +uno::Reference< graphic::XGraphic > loadGraphic( const char *pName ) +{ + BitmapEx aBmp; + + OUString aStr( pName, strlen( pName ), RTL_TEXTENCODING_ASCII_US ); + if ( aStr.compareToAscii( ".uno:" ) == 0 ) + aStr = aStr.copy( 5 ).toAsciiLowerCase(); + + if ( !vcl::ImageRepository::loadImage( OUString::createFromAscii( pName ), aBmp, true ) ) + return uno::Reference< graphic::XGraphic >(); + + return Graphic( aBmp ).GetXGraphic(); +} + +} // namespace layoutimpl diff --git a/toolkit/source/layout/core/helper.hxx b/toolkit/source/layout/core/helper.hxx new file mode 100644 index 000000000000..2fac41ebc493 --- /dev/null +++ b/toolkit/source/layout/core/helper.hxx @@ -0,0 +1,149 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_CORE_HELPER_HXX +#define LAYOUT_CORE_HELPER_HXX + +#include <toolkit/dllapi.h> +#include <vector> + +#include <com/sun/star/awt/XLayoutConstrains.hpp> +#include <com/sun/star/awt/XLayoutContainer.hpp> +#include <com/sun/star/awt/XVclWindowPeer.hpp> +#include <com/sun/star/xml/input/XRoot.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> +#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/propshlp.hxx> +#include <osl/module.h> +#include <rtl/ustring.hxx> + +class Window; +class VCLXWindow; +extern "C" +{ + typedef Window* (SAL_CALL *WindowCreator) (VCLXWindow** component, rtl::OUString const& name, Window* parent, long& attributes); +} + +namespace layoutimpl +{ + +namespace css = ::com::sun::star; + +/* ChildProps -- a helper to set child properties for the XLayoutContainer interface. */ + +class LockHelper +{ +public: + osl::Mutex maGuard; + cppu::OBroadcastHelper maBrdcstHelper; + LockHelper() : maBrdcstHelper( maGuard ) + { + } +}; + +class PropHelper : public LockHelper + , public cppu::OPropertySetHelper + , public cppu::OWeakObject +{ + cppu::OPropertyArrayHelper *pHelper; + + struct PropDetails + { + rtl::OUString aName; + css::uno::Type aType; + void *pValue; + }; + std::vector< PropDetails > maDetails; + +protected: + void addProp( char const *pName, sal_Int32 nNameLen, rtl_TextEncoding e, + css::uno::Type aType, void *pPtr ); + +public: + PropHelper(); + + // com::sun::star::uno::XInterface + void SAL_CALL acquire() throw() { OWeakObject::acquire(); } + void SAL_CALL release() throw() { OWeakObject::release(); } + ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); + + // cppu::OPropertySetHelper + virtual cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); + virtual sal_Bool SAL_CALL convertFastPropertyValue( css::uno::Any &, + css::uno::Any &, sal_Int32 nHandle, const css::uno::Any & ) + throw(css::lang::IllegalArgumentException); + virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, + const css::uno::Any& rValue ) throw (css::uno::Exception); + using OPropertySetHelper::getFastPropertyValue; + virtual void SAL_CALL getFastPropertyValue( css::uno::Any& rValue, + sal_Int32 nHandle ) const; + + virtual css::uno::Reference <css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo () throw (css::uno::RuntimeException); + + struct Listener + { + virtual void propertiesChanged() = 0; + }; + + void setChangeListener( Listener *pListener ) + { + mpListener = pListener; + } + +protected: + Listener *mpListener; +}; + +css::uno::Any anyFromString (const rtl::OUString &value, const css::uno::Type &type); + +// The native widgets wrapper hierarchy may not reflect that of the layout +// hierarchy as some containers don't have an associated native widget. +// Use this function to get the native parent of the given peer. +css::uno::Reference< css::awt::XWindowPeer > +getParent( css::uno::Reference< css::uno::XInterface > xPeer ); + +class TOOLKIT_DLLPUBLIC WidgetFactory +{ +public: + static oslModule mSfx2Library; + static WindowCreator mSfx2CreateWidget; + + // Should use UNO services in due course + static css::uno::Reference <css::awt::XLayoutConstrains> toolkitCreateWidget (css::uno::Reference <css::awt::XToolkit> xToolkit, css::uno::Reference <css::uno::XInterface> xParent, rtl::OUString const& name, long properties); + static css::uno::Reference< css::awt::XLayoutConstrains > createWidget( css::uno::Reference <css::awt::XToolkit > xToolkit, css::uno::Reference< css::uno::XInterface > xParent, rtl::OUString const &name, long properties); + static css::uno::Reference <css::awt::XLayoutContainer> createContainer (rtl::OUString const& name); + static css::uno::Reference <css::awt::XLayoutConstrains> implCreateWidget (css::uno::Reference <css::uno::XInterface> xParent, rtl::OUString name, long attributes); + static Window* sfx2CreateWindow (VCLXWindow** component, Window* parent, rtl::OUString const& name, long& attributes); + static Window* layoutCreateWindow (VCLXWindow** component, Window *parent, rtl::OUString const& name, long& attributes); +}; + + +css::uno::Reference< css::graphic::XGraphic > loadGraphic( const char *pName ); + +} // end namespace layoutimpl + +#endif /* LAYOUT_CORE_HELPER_HXX */ diff --git a/toolkit/source/layout/core/import.cxx b/toolkit/source/layout/core/import.cxx new file mode 100644 index 000000000000..daaa8c239f50 --- /dev/null +++ b/toolkit/source/layout/core/import.cxx @@ -0,0 +1,336 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "import.hxx" + +#include <com/sun/star/awt/XButton.hpp> +#include <com/sun/star/awt/XDialog2.hpp> +#include <vcl/image.hxx> +#include <tools/debug.hxx> +#include <layout/layout.hxx> + +#include "root.hxx" +#include "helper.hxx" +#include "dialogbuttonhbox.hxx" + + +#define XMLNS_LAYOUT_URI "http://openoffice.org/2007/layout" +#define XMLNS_CONTAINER_URI "http://openoffice.org/2007/layout/container" + +namespace layoutimpl +{ +using namespace css; + +using ::rtl::OUString; + +ElementBase::~ElementBase() +SAL_THROW( () ) +{ + //delete mpImport; + //mpImport = 0; +} + +//** parser +WidgetElement::WidgetElement ( sal_Int32 nUid, const OUString &rName, + uno::Reference <xml::input::XAttributes> const &attributes, + ElementBase *pParent, + ImportContext *pImport) +SAL_THROW (()) +: ElementBase( nUid, rName, attributes, pParent, pImport ) +{ + OUString name = rName.toAsciiLowerCase(); + + PropList aProps; + propsFromAttributes( attributes, aProps, pImport->XMLNS_LAYOUT_UID ); + + OUString aId; + findAndRemove( "id", aProps, aId ); + OUString aLang; + findAndRemove( "xml-lang", aProps, aLang ); + + { +//DEBUG + uno::Reference< awt::XLayoutConstrains > xParent; + if ( pParent ) + xParent = ((WidgetElement *) pParent)->mpWidget->getPeer(); + + + mpWidget = pImport->mrRoot.create( aId, name, + getAttributeProps( aProps ), uno::Reference< awt::XLayoutContainer >( xParent, uno::UNO_QUERY ) ); + + } + + // TODO: handle with non-existing widgets + + mpWidget->setProperties( aProps ); + + uno::Reference< awt::XDialog2 > xDialog( mpWidget->getPeer(), uno::UNO_QUERY ); + if ( xDialog.is() ) + { + OUString aTitle; + if ( findAndRemove( "title", aProps, aTitle ) ) + { + OSL_TRACE("Setting title: %s", OUSTRING_CSTR( aTitle ) ); + xDialog->setTitle( aTitle ); + } + OUString aHelpId; + if ( findAndRemove( "help-id", aProps, aHelpId ) ) + { + OSL_TRACE("Setting help-id: %s", OUSTRING_CSTR( aHelpId ) ); + xDialog->setHelpId( aHelpId.toInt32 () ); + } + } // DEBUG: + else if ( pParent == NULL ) + { + DBG_ERROR( "Fatal error: top node isn't a dialog" ); + } + +#if 0 + // Hack moved to proplist.cxx + OUString aGraphic; + if ( findAndRemove( "graphic", aProps, aGraphic ) ) + //if ( layout::FixedImage *i = dynamic_cast<layout::FixedImage *> ( mpWidget->getPeer().get() ) ) + // FIXME: huh? XImageProducer::complete( XImageConsumer ) + //i->setImage( Image( loadGraphic( OUSTRING_CSTR( aGraphic ) ) ) ); + mpWidget->setProperty( OUString::createFromAscii( "graphic" ), + loadGraphic( OUSTRING_CSTR( aGraphic ) ) ); +#endif + + OUString aOrdering; + if ( findAndRemove( "ordering", aProps, aOrdering ) ) + if ( DialogButtonHBox *b = dynamic_cast<DialogButtonHBox *> ( mpWidget->getPeer().get() ) ) + b->setOrdering ( aOrdering ); + + bool bSetRadioGroup; + OUString aRadioGroup; + bSetRadioGroup = findAndRemove( "radiogroup", aProps, aRadioGroup ); + + mpWidget->setProperties( aProps ); + + // we need to add radio buttons to the group after their properties are + // set, so we can check if they should be the one selected by default or not. + // And the state changed event isn't fired when changing properties. + + uno::Reference< awt::XRadioButton > xRadio( mpWidget->getPeer(), uno::UNO_QUERY ); + if ( xRadio.is() ) + { + if (!bSetRadioGroup) + aRadioGroup = OUString::createFromAscii ("default"); + pImport->mxRadioGroups.addItem( aRadioGroup, xRadio ); + } +} + +WidgetElement::~WidgetElement() +{ + //delete mpWidget; + //mpWidget = 0; +} + +uno::Reference <xml::input::XElement> +WidgetElement::startChildElement ( sal_Int32 nUid, OUString const &name, + uno::Reference <xml::input::XAttributes> const &attributes ) + throw( xml::sax::SAXException, uno::RuntimeException ) +{ + // Adding a child to the widget + WidgetElement *pChild = new WidgetElement ( nUid, name, attributes, this, mpImport ); + + if ( !mpWidget->addChild( pChild->mpWidget ) ) + { + DBG_ERROR2( "ERROR: cannot add %s to container %s, container full", OUSTRING_CSTR( name ), OUSTRING_CSTR( getLocalName() ) ); + throw xml::sax::SAXException(); + } + + PropList aProps; + propsFromAttributes( attributes, aProps, mpImport->XMLNS_CONTAINER_UID ); + mpWidget->setChildProperties( pChild->mpWidget, aProps ); + + return pChild; +} + +// Support Ivo Hinkelmann's move label/text/title attribute to CONTENT +// transex3 hack. +void SAL_CALL +WidgetElement::characters( OUString const& rChars ) + throw (xml::sax::SAXException, uno::RuntimeException) +{ + if ( mpWidget && rChars.trim().getLength() ) + { + uno::Reference< awt::XDialog2 > xDialog( mpWidget->getPeer(), uno::UNO_QUERY ); + uno::Reference< awt::XButton > xButton( mpWidget->getPeer(), uno::UNO_QUERY ); + if ( xDialog.is() ) + xDialog->setTitle( rChars ); + else if ( xButton.is() ) + mpWidget->setProperty( OUString::createFromAscii( "label" ), rChars ); + else + mpWidget->setProperty( OUString::createFromAscii( "text" ), rChars ); + } +} +// ---- ElementBase ---- + +ElementBase::ElementBase( sal_Int32 nUid, OUString const & rLocalName, + uno::Reference< xml::input::XAttributes > const & xAttributes, + ElementBase* pParent, + ImportContext* pImport ) +SAL_THROW(()) +: mpImport( pImport ) + , mpParent( pParent ) + , mnUid( nUid ) + , maLocalName( rLocalName ) + , mxAttributes( xAttributes ) +{ +} + +// ---- ImportContext ---- + +void ImportContext::startDocument( + uno::Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping ) + throw (xml::sax::SAXException, uno::RuntimeException) +{ + XMLNS_LAYOUT_UID = xNamespaceMapping->getUidByUri( + OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_LAYOUT_URI ) ) ); + XMLNS_CONTAINER_UID = xNamespaceMapping->getUidByUri( + OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_CONTAINER_URI ) ) ); +} + +ToplevelElement::ToplevelElement (OUString const &rName, + uno::Reference <xml::input::XAttributes> const &xAttributes, + ImportContext *pImport) +SAL_THROW(()) +: WidgetElement( 0, rName, xAttributes, NULL, pImport ) +{ +} + +ToplevelElement::~ToplevelElement() +{ +} + +uno::Reference< xml::input::XElement > ImportContext::startRootElement( + sal_Int32 nUid, OUString const & rLocalName, + uno::Reference< xml::input::XAttributes > const & xAttributes ) + throw (xml::sax::SAXException, uno::RuntimeException) +{ + if ( XMLNS_LAYOUT_UID != nUid ) + throw xml::sax::SAXException( + OUString( RTL_CONSTASCII_USTRINGPARAM( "invalid namespace!" ) ), + uno::Reference< uno::XInterface >(), uno::Any() ); + return new ToplevelElement( rLocalName, xAttributes, this ); +} + +RadioGroups::RadioGroups() +{ +} + +void RadioGroups::addItem( rtl::OUString id, uno::Reference< awt::XRadioButton > xRadio ) + throw (uno::RuntimeException) +{ + if ( ! xRadio.is() ) + throw uno::RuntimeException(); + + uno::Reference< RadioGroup > group; + RadioGroupsMap::iterator it = mxRadioGroups.find( id ); + if ( it == mxRadioGroups.end() ) + { + group = uno::Reference< RadioGroup > ( new RadioGroup() ); + mxRadioGroups [id] = group; + } + else + group = it->second; + group->addItem( xRadio ); +} + +RadioGroups::RadioGroup::RadioGroup() +{ +} + +void RadioGroups::RadioGroup::addItem( uno::Reference< awt::XRadioButton > xRadio ) +{ + if ( ! mxSelectedRadio.is() ) + { + xRadio->setState( true ); + mxSelectedRadio = xRadio; + } + else if ( xRadio->getState() ) + { +#if 1 + xRadio->setState( false ); +#else // huh, why select last added? + mxSelectedRadio->setState( false ); + mxSelectedRadio = xRadio; +#endif + } + + // TOO late: actionPerformed is called before itemStateChanged. + // If client code (wrongly?) uses actionPerformed, it will see + // the previous RadioButtons' state. + xRadio->addItemListener( this ); + + uno::Reference< awt::XButton > xButton = uno::Reference< awt::XButton > ( xRadio, uno::UNO_QUERY ); + xButton->addActionListener( this ); + + mxRadios.push_back (xRadio); +} + +void RadioGroups::RadioGroup::handleSelected () + throw (uno::RuntimeException) +{ + for ( RadioButtonsList::iterator it = mxRadios.begin(); + it != mxRadios.end(); it++ ) + if ( *it != mxSelectedRadio && (*it)->getState() ) + { + mxSelectedRadio->setState( false ); + mxSelectedRadio = *it; + break; + } +} + +// awt::XItemListener +void RadioGroups::RadioGroup::itemStateChanged( const awt::ItemEvent& e ) + throw (uno::RuntimeException) +{ + // TOO late: actionPerformed is called before itemStateChanged. + // If client code (wrongly?) uses actionPerformed, it will see + // the previous RadioButtons' state. + + // Need this for initialization, though. + if ( e.Selected ) + handleSelected (); +} + +// awt::XActionListener +void RadioGroups::RadioGroup::actionPerformed( const awt::ActionEvent& ) + throw (uno::RuntimeException) +{ + handleSelected (); +} + +// lang::XEventListener +void SAL_CALL RadioGroups::RadioGroup::disposing( const lang::EventObject& ) + throw (uno::RuntimeException) +{ +} + +} // namespace layoutimpl diff --git a/toolkit/source/layout/core/import.hxx b/toolkit/source/layout/core/import.hxx new file mode 100644 index 000000000000..7af8f16eb5d3 --- /dev/null +++ b/toolkit/source/layout/core/import.hxx @@ -0,0 +1,259 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_CORE_IMPORT_HXX +#define LAYOUT_CORE_IMPORT_HXX + +#include <map> +#include <list> +#define _BACKWARD_BACKWARD_WARNING_H 1 +#include <hash_map> + + +#include <com/sun/star/xml/input/XRoot.hpp> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/awt/XButton.hpp> +#include <com/sun/star/awt/XRadioButton.hpp> + +namespace layoutimpl +{ +class LayoutRoot; +class LayoutWidget; +namespace css = ::com::sun::star; + +class RadioGroups +{ +public: + RadioGroups(); + + void addItem( rtl::OUString id, css::uno::Reference< css::awt::XRadioButton > xRadio ) + throw (css::uno::RuntimeException); + +private: + class RadioGroup : public ::cppu::WeakImplHelper1< css::awt::XItemListener > + , public ::cppu::WeakImplHelper1< css::awt::XActionListener > + { + public: + RadioGroup(); + void addItem( css::uno::Reference< css::awt::XRadioButton > xRadio ); + + private: + typedef std::list< css::uno::Reference< css::awt::XRadioButton > > RadioButtonsList; + RadioButtonsList mxRadios; + css::uno::Reference< css::awt::XRadioButton > mxSelectedRadio; + + void handleSelected () + throw (css::uno::RuntimeException); + + // awt::XItemListener + void SAL_CALL itemStateChanged( const css::awt::ItemEvent& e ) + throw (css::uno::RuntimeException); + + // awt::XActionListener + void SAL_CALL actionPerformed( const css::awt::ActionEvent& e ) + throw (css::uno::RuntimeException); + + // lang::XEventListener + void SAL_CALL disposing( const css::lang::EventObject& ) + throw (css::uno::RuntimeException); + }; + + // each RadioGroup will stay alive after RadioGroups die with the ImportContext + // because they are referenced by every XRadioButton through the listener + typedef std::map< rtl::OUString, css::uno::Reference< RadioGroup > > RadioGroupsMap; + RadioGroupsMap mxRadioGroups; +}; + +#if 0 +// generator +class Widget +{ +public: + Widget( css::uno::Reference< css::awt::XToolkit > xToolkit, + css::uno::Reference< css::awt::XWindow > xToplevel, + rtl::OUString unoName, long attrbs ); + virtual ~Widget(); + + virtual void setProperties( const PropList &rProps ); + + virtual bool addChild( Widget *pChild ); + virtual void setChildProperties( Widget *pChild, const PropList &rProps ); + + inline css::uno::Reference< css::awt::XLayoutConstrains > getPeer() + { return mxWidget; } + + inline css::uno::Reference< css::awt::XLayoutConstrains > getContainer() + { return mxContainer; } + +protected: + css::uno::Reference< css::awt::XLayoutConstrains > mxWidget; + css::uno::Reference< css::awt::XLayoutContainer > mxContainer; +}; + +class Root +{ +public: + Root( css::uno::Reference< css::awt::XToolkit > xToolkit ) + : mxToolkit( xToolkit ) {} + ~Root(); + + virtual Widget *create( rtl::OUString id, const rtl::OUString unoName, long attrbs ); + + css::uno::Reference< css::awt::XLayoutConstrains > getById( rtl::OUString id ); + inline css::uno::Reference< css::awt::XLayoutConstrains > getToplevel(); + +protected: + css::uno::Reference< css::awt::XToolkit > mxToolkit; + Widget *mpToplevel; + + typedef std::hash_map< rtl::OUString, css::uno::Reference< css::awt::XLayoutConstrains >, + rtl::OUStringHash > ItemHash; + ItemHash maItems; +}; +#endif + +// parser +class ImportContext : public ::cppu::WeakImplHelper1< css::xml::input::XRoot > +{ +public: + sal_Int32 XMLNS_LAYOUT_UID, XMLNS_CONTAINER_UID; + LayoutRoot &mrRoot; // switch to XNameContainer ref ? + RadioGroups mxRadioGroups; + + inline ImportContext( LayoutRoot &rRoot ) SAL_THROW( () ) + : mrRoot( rRoot ) {} + virtual ~ImportContext() {} + + // XRoot + virtual void SAL_CALL startDocument( + css::uno::Reference< css::xml::input::XNamespaceMapping > + const & xNamespaceMapping ) + throw (css::xml::sax::SAXException, css::uno::RuntimeException); + virtual void SAL_CALL endDocument() + throw (css::xml::sax::SAXException, css::uno::RuntimeException) + { /* ignore */ } + virtual void SAL_CALL processingInstruction( + ::rtl::OUString const & /* rTarget */, ::rtl::OUString const & /* rData */ ) + throw (css::xml::sax::SAXException, css::uno::RuntimeException) + { /* ignore */ } + virtual void SAL_CALL setDocumentLocator( + css::uno::Reference< css::xml::sax::XLocator > const & /* xLocator */ ) + throw (css::xml::sax::SAXException, css::uno::RuntimeException) + { /* ignore */ } + virtual css::uno::Reference< css::xml::input::XElement > + SAL_CALL startRootElement( + sal_Int32 nUid, ::rtl::OUString const & rLocalName, + css::uno::Reference<css::xml::input::XAttributes > const & xAttributes ) + throw (css::xml::sax::SAXException, css::uno::RuntimeException); +}; + +class ElementBase : public ::cppu::WeakImplHelper1< css::xml::input::XElement > +{ +protected: + ImportContext *mpImport; +/* TODO: check if all this memebers are needed. */ + ElementBase *mpParent; + sal_Int32 mnUid; + + ::rtl::OUString maLocalName; + css::uno::Reference< css::xml::input::XAttributes > mxAttributes; +public: + ElementBase( + sal_Int32 nUid, ::rtl::OUString const & rLocalName, + css::uno::Reference< css::xml::input::XAttributes > const & xAttributes, + ElementBase * pParent, ImportContext * pImport ) + SAL_THROW( () ); + virtual ~ElementBase() SAL_THROW(()); + + // XElement + virtual css::uno::Reference<css::xml::input::XElement> SAL_CALL getParent() + throw (css::uno::RuntimeException) + { return static_cast< css::xml::input::XElement * >( mpParent ); } + virtual ::rtl::OUString SAL_CALL getLocalName() throw (css::uno::RuntimeException) + { return maLocalName; } + virtual sal_Int32 SAL_CALL getUid() throw (css::uno::RuntimeException) + { return mnUid; } + virtual css::uno::Reference< css::xml::input::XAttributes > + SAL_CALL getAttributes() throw (css::uno::RuntimeException) + { return mxAttributes; } + + virtual void SAL_CALL ignorableWhitespace( + ::rtl::OUString const & /* rWhitespaces */ ) + throw (css::xml::sax::SAXException, css::uno::RuntimeException) + { /* ignore */ } + virtual void SAL_CALL characters( ::rtl::OUString const & /* rChars */ ) + throw (css::xml::sax::SAXException, css::uno::RuntimeException) + { /* ignore */ } + virtual void SAL_CALL processingInstruction( + ::rtl::OUString const & /* Target */, ::rtl::OUString const & /* Data */ ) + throw (css::xml::sax::SAXException, css::uno::RuntimeException) + { /* ignore */ } + + virtual css::uno::Reference< css::xml::input::XElement > + SAL_CALL startChildElement( + sal_Int32 nUid, ::rtl::OUString const & rLocalName, + css::uno::Reference<css::xml::input::XAttributes > const & xAttributes ) + throw (css::xml::sax::SAXException, css::uno::RuntimeException) = 0; + virtual void SAL_CALL endElement() + throw (css::xml::sax::SAXException, css::uno::RuntimeException) + { /* ignore */ } +}; + +class WidgetElement : public ElementBase +{ +protected: + LayoutWidget *mpWidget; + +public: + WidgetElement( sal_Int32 nUid, rtl::OUString const &name, + css::uno::Reference< css::xml::input::XAttributes > const &attributes, + ElementBase *parent, ImportContext *import ) SAL_THROW (()); + + ~WidgetElement(); + + + virtual css::uno::Reference< css::xml::input::XElement> SAL_CALL + startChildElement (sal_Int32 id, rtl::OUString const &name, + css::uno::Reference< css::xml::input::XAttributes > const &attributes) + throw( css::xml::sax::SAXException, css::uno::RuntimeException ); + virtual void SAL_CALL characters( ::rtl::OUString const & /* rChars */ ) + throw (css::xml::sax::SAXException, css::uno::RuntimeException); +}; + +class ToplevelElement : public WidgetElement +{ +public: + ToplevelElement( rtl::OUString const &name, + css::uno::Reference< css::xml::input::XAttributes > const &attributes, + ImportContext *import ) SAL_THROW (()); + ~ToplevelElement(); +}; + + +} // namespace layoutimpl + +#endif /* LAYOUT_CORE_IMPORT_HXX */ diff --git a/toolkit/source/layout/core/localized-string.cxx b/toolkit/source/layout/core/localized-string.cxx new file mode 100644 index 000000000000..bbf067011f6b --- /dev/null +++ b/toolkit/source/layout/core/localized-string.cxx @@ -0,0 +1,79 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "localized-string.hxx" + +#include <toolkit/helper/property.hxx> +#include <vcl/window.hxx> + +namespace layoutimpl +{ + +namespace css = ::com::sun::star; +using namespace css; +using rtl::OUString; + +LocalizedString::LocalizedString() + : VCLXWindow() +{ +} + +void LocalizedString::ImplGetPropertyIds( std::list< sal_uInt16 > &ids ) +{ + PushPropertyIds( ids, BASEPROPERTY_TEXT, 0); + VCLXWindow::ImplGetPropertyIds( ids ); +} + +// XInterface +uno::Any LocalizedString::queryInterface( uno::Type const& rType ) + throw(uno::RuntimeException) +{ + uno::Any aRet = ::cppu::queryInterface( rType, + SAL_STATIC_CAST( awt::XFixedText*, this ) ); + return (aRet.hasValue() ? aRet : VCLXWindow::queryInterface( rType )); +} + +void LocalizedString::setText( OUString const& s ) + throw(uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( Window *w = GetWindow() ) + return w->SetText( s ); +} + +OUString LocalizedString::getText() + throw(uno::RuntimeException) +{ + ::vos::OGuard aGuard( GetMutex() ); + + if ( Window *w = GetWindow() ) + return w->GetText(); + return OUString(); +} + +} // namespace layoutimpl diff --git a/toolkit/source/layout/core/localized-string.hxx b/toolkit/source/layout/core/localized-string.hxx new file mode 100644 index 000000000000..a6310336ceb6 --- /dev/null +++ b/toolkit/source/layout/core/localized-string.hxx @@ -0,0 +1,76 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_CORE_LOCALIZED_STRING_HXX +#define LAYOUT_CORE_LOCALIZED_STRING_HXX + +#include <com/sun/star/awt/XFixedText.hpp> +#include <toolkit/awt/vclxwindow.hxx> + +namespace layoutimpl +{ +namespace css = ::com::sun::star; + +// FIXME: misuse XFixedText interface for simple string +class LocalizedString : public css::awt::XFixedText + , public VCLXWindow +{ +public: + LocalizedString(); + + // css::uno::XInterface + css::uno::Any SAL_CALL queryInterface( css::uno::Type const& rType ) + throw(css::uno::RuntimeException); + void SAL_CALL acquire() throw() { OWeakObject::acquire(); } + void SAL_CALL release() throw() { OWeakObject::release(); } + + // css::awt::XFixedText + void SAL_CALL setText( ::rtl::OUString const& s ) + throw(css::uno::RuntimeException); + ::rtl::OUString SAL_CALL getText() + throw(css::uno::RuntimeException); + void SAL_CALL setAlignment( sal_Int16 ) + throw(css::uno::RuntimeException) { } + sal_Int16 SAL_CALL getAlignment() + throw(css::uno::RuntimeException) { return 0; } + + // css::awt::XLayoutConstrains + virtual css::awt::Size SAL_CALL getMinimumSize() + throw(css::uno::RuntimeException) { return css::awt::Size( 0, 0 ); } + css::awt::Size SAL_CALL getPreferredSize() + throw(css::uno::RuntimeException) { return getMinimumSize(); } + css::awt::Size SAL_CALL calcAdjustedSize( css::awt::Size const& size ) + throw(css::uno::RuntimeException) { return size; } + + static void ImplGetPropertyIds( std::list< sal_uInt16 > &ids ); + virtual void GetPropertyIds( std::list< sal_uInt16 > &ids ) + { return ImplGetPropertyIds( ids ); } +}; + +} // namespace layoutimpl + +#endif /* LAYOUT_CORE_LOCALIZED_STRING_HXX */ diff --git a/toolkit/source/layout/core/makefile.mk b/toolkit/source/layout/core/makefile.mk new file mode 100644 index 000000000000..2c90921799af --- /dev/null +++ b/toolkit/source/layout/core/makefile.mk @@ -0,0 +1,65 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=../../.. +PRJNAME=toolkit +TARGET=layout-core +ENABLE_EXCEPTIONS=true + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/util$/makefile.pmk + +# --- Files -------------------------------------------------------- + +# FIXME: This is bad, hmkay +CFLAGS+= -I$(PRJ)/source + +SLOFILES= \ + $(SLO)$/bin.obj \ + $(SLO)$/box-base.obj \ + $(SLO)$/box.obj \ + $(SLO)$/byteseq.obj \ + $(SLO)$/container.obj \ + $(SLO)$/dialogbuttonhbox.obj \ + $(SLO)$/factory.obj \ + $(SLO)$/flow.obj \ + $(SLO)$/helper.obj \ + $(SLO)$/import.obj \ + $(SLO)$/localized-string.obj \ + $(SLO)$/proplist.obj \ + $(SLO)$/root.obj \ + $(SLO)$/table.obj \ + $(SLO)$/timer.obj \ + $(SLO)$/translate.obj\ + $(SLO)$/vcl.obj\ +# + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk diff --git a/toolkit/source/layout/core/precompiled_xmlscript.hxx b/toolkit/source/layout/core/precompiled_xmlscript.hxx new file mode 100644 index 000000000000..0fc538151348 --- /dev/null +++ b/toolkit/source/layout/core/precompiled_xmlscript.hxx @@ -0,0 +1,35 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +/* + xmlscript/source/xml_helper/xml_byteseq.cxx compile helper. + + Avoid introducing a toolkit dependency on xmlscript. + + It would be nice to modify xml_byteseq.cxx making it friendlier + to include. +*/ diff --git a/toolkit/source/layout/core/proplist.cxx b/toolkit/source/layout/core/proplist.cxx new file mode 100644 index 000000000000..7cd27473a8c7 --- /dev/null +++ b/toolkit/source/layout/core/proplist.cxx @@ -0,0 +1,454 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "proplist.hxx" + +#include <rtl/ustrbuf.hxx> +#include <toolkit/dllapi.h> +#include <com/sun/star/awt/WindowAttribute.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/awt/XVclWindowPeer.hpp> +#include <com/sun/star/awt/VclWindowPeerAttribute.hpp> +#include <tools/debug.hxx> + +#include "helper.hxx" + +#if TEST_LAYOUT && !defined( DBG_UTIL ) +#undef DBG_ERROR +#define DBG_ERROR OSL_TRACE +#undef DBG_ERROR1 +#define DBG_ERROR1 OSL_TRACE +#undef DBG_ERROR2 +#define DBG_ERROR2 OSL_TRACE +#endif /* TEST_LAYOUT && !DBG_UTIL */ + +namespace layoutimpl +{ + +using namespace com::sun::star; +using rtl::OString; +using rtl::OUString; +using rtl::OUStringBuffer; + +namespace prophlp +{ + +bool TOOLKIT_DLLPUBLIC +canHandleProps( const uno::Reference< uno::XInterface > &xPeer ) +{ + uno::Reference< beans::XPropertySet > xPropSet( xPeer, uno::UNO_QUERY ); + if ( xPropSet.is() ) + return true; + uno::Reference< beans::XPropertySetInfo > xInfo( xPeer, uno::UNO_QUERY ); + uno::Reference< awt::XVclWindowPeer> xVclPeer( xPeer, uno::UNO_QUERY ); + return xInfo.is() && xVclPeer.is(); +} + +uno::Reference< beans::XPropertySetInfo > TOOLKIT_DLLPUBLIC +queryPropertyInfo( + const uno::Reference< uno::XInterface > &xPeer ) +{ + uno::Reference< beans::XPropertySetInfo > xInfo( xPeer, uno::UNO_QUERY ); + if ( !xInfo.is() ) + { + uno::Reference< beans::XPropertySet > xPropSet( xPeer, uno::UNO_QUERY ); + if ( xPropSet.is() ) + xInfo = xPropSet->getPropertySetInfo(); + } + return xInfo; +} + +void TOOLKIT_DLLPUBLIC +setProperty( const uno::Reference< uno::XInterface > &xPeer, + const OUString &rName, uno::Any aValue ) +{ + uno::Reference< awt::XVclWindowPeer> xVclPeer( xPeer, uno::UNO_QUERY ); + if ( xVclPeer.is() ) + xVclPeer->setProperty( rName, aValue ); + else + { + uno::Reference< beans::XPropertySet > xPropSet( xPeer, uno::UNO_QUERY ); + xPropSet->setPropertyValue( rName, aValue ); + } +} + +uno::Any TOOLKIT_DLLPUBLIC +getProperty( const uno::Reference< uno::XInterface > &xPeer, + const OUString &rName ) +{ + uno::Reference< awt::XVclWindowPeer> xVclPeer( xPeer, uno::UNO_QUERY ); + if ( xVclPeer.is() ) + return xVclPeer->getProperty( rName ); + + uno::Reference< beans::XPropertySet > xPropSet( xPeer, uno::UNO_QUERY ); + return xPropSet->getPropertyValue( rName ); +} + +} // namespace prophlp + + +/* Given a string and a type, it converts the string to the type, and returns + it encapsulated in Any. */ +uno::Any anyFromString( OUString const& value, uno::Type const& type ) +{ + sal_Int16 radix = 10; + OUString intval = value; + if ( value.getLength() > 2 && value[0] == '0' && value[1] == 'x' ) + intval = value.copy( 2 ), radix = 16; + else if ( value.getLength() > 1 && value[0] == '#' ) + intval = value.copy( 1 ), radix = 16; + switch ( type.getTypeClass() ) + { + case uno::TypeClass_CHAR: + return uno::makeAny( value.toChar() ); + case uno::TypeClass_BOOLEAN: + if ( value == OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) ) ) + return uno::makeAny( true ); + else if ( value == OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) ) ) + return uno::makeAny( false ); + break; // ends switch, throws exception + case uno::TypeClass_BYTE: + return uno::makeAny( ( sal_uInt8 ) intval.toInt32( radix ) ); + case uno::TypeClass_SHORT: + return uno::makeAny( ( sal_Int16 ) intval.toInt32( radix ) ); + case uno::TypeClass_UNSIGNED_SHORT: + return uno::makeAny( ( sal_uInt16 ) intval.toInt32( radix ) ); + case uno::TypeClass_ENUM: + return uno::makeAny( ( sal_Int16 ) intval.toInt32( radix ) ); + case uno::TypeClass_LONG: + return uno::makeAny( ( sal_Int32 ) intval.toInt32( radix ) ); + case uno::TypeClass_UNSIGNED_LONG: + return uno::makeAny( ( sal_uInt32 ) intval.toInt32( radix ) ); + case uno::TypeClass_HYPER: + return uno::makeAny( ( sal_Int64 ) intval.toInt64( radix ) ); + case uno::TypeClass_UNSIGNED_HYPER: + return uno::makeAny( ( sal_uInt16 ) intval.toInt64( radix ) ); + case uno::TypeClass_FLOAT: + return uno::makeAny( value.toFloat() ); + case uno::TypeClass_DOUBLE: + return uno::makeAny( value.toDouble() ); + case uno::TypeClass_STRING: + return uno::makeAny( value ); + case uno::TypeClass_CONSTANT: + return uno::makeAny( intval.toInt32( radix ) ); + case uno::TypeClass_INTERFACE: + return uno::makeAny( loadGraphic( OUSTRING_CSTR( value ) ) ); + case uno::TypeClass_SEQUENCE: + { + sal_Int32 i = 0; + bool escaped = false, first = true; + OUString item, token; + std::list< OUString > values; + do + { + token = value.getToken( 0, ':', i ); + + if ( !token.getLength() && !escaped ) + { + escaped = true; + item += OUString( ':' ); + } + else if ( escaped ) + { + escaped = false; + item += token; + } + else + { + if ( !first ) + values.push_back( item ); + item = token; + } + first = false; + } + while ( i >= 0 ); + if ( item.getLength() ) + values.push_back( item ); + + uno::Sequence< OUString > seq( values.size() ); + i = 0; + for ( std::list< OUString >::const_iterator it = values.begin(); + it != values.end(); it++, i++ ) + seq[ i ] = *it; + + return uno::makeAny( seq ); + } + + default: + DBG_ERROR1( "ERROR: unknown property type of value: `%s'\n", OUSTRING_CSTR( value ) ); + break; + } + throw uno::RuntimeException(); +} + +/* Converts the XML naming scheme to UNO's, for legacy compatibility + (so, ergo, "one-two-three-four" -> "OneTwoThreeFour"). */ +static OUString toUnoNaming ( OUString const &string ) +{ + OUStringBuffer buffer( string.getLength() ); + sal_Unicode *str = string.pData->buffer; + bool capitalize = true; + + for ( int i = 0; i < string.getLength(); i++ ) + { + if ( i == 0 && str[0] == '_' ) + /* Skip translate-me prefix. */ + continue; + if ( str[i] == '-' ) + capitalize = true; + else + { + if ( capitalize && str[i] >= 'a' && str[i] <= 'z' ) + buffer.append( (sal_Unicode ) ( str[i] - 'a' + 'A' ) ); + else + buffer.append( (sal_Unicode ) str[i] ); + capitalize = false; + } + } + + return buffer.makeStringAndClear(); +} + +/* + * convert incoming XML style property names, to AWT style property names. + * convert the values based on introspection information. + * apply to either an XPropertySet or an XPropertySetInfo | XVclWindowPeer + * aggregate. + */ +void +setProperties( uno::Reference< uno::XInterface > const& xPeer, + PropList const& rProps ) +{ + if ( !prophlp::canHandleProps( xPeer ) ) + { + DBG_ERROR( "Error: setProperties - bad handle ignoring props:\n" ); + for ( PropList::const_iterator it = rProps.begin(); it != rProps.end(); + it++ ) + { + DBG_ERROR2( "%s=%s\n", OUSTRING_CSTR( it->first ), OUSTRING_CSTR( it->second ) ); + } + return; + } + + for ( PropList::const_iterator it = rProps.begin(); it != rProps.end(); + it++ ) + setProperty( xPeer, it->first, it->second ); +} + +void +setProperty( uno::Reference< uno::XInterface > const& xPeer, + OUString const& attr, OUString const& value ) +{ + OUString unoAttr = toUnoNaming( attr ); + + OSL_TRACE( "setting %s=%s", OUSTRING_CSTR( attr ), OUSTRING_CSTR( value ) ); + // get a Property object + beans::Property prop; + try + { + uno::Reference< beans::XPropertySetInfo > xInfo + = prophlp::queryPropertyInfo( xPeer ); + prop = xInfo->getPropertyByName( unoAttr ); + } + catch( beans::UnknownPropertyException & ) + { + DBG_ERROR1( "Warning: unknown attribute: `%s'\n", OUSTRING_CSTR( unoAttr ) ); + return; + } + + if ( prop.Name.getLength() <= 0 ) + { + DBG_ERROR1( "Warning: missing prop: `%s'\n", OUSTRING_CSTR( unoAttr ) ); + return; + } + + // encapsulates value in an uno::Any + uno::Any any; + try + { + any = anyFromString( value, prop.Type ); + } + catch( uno::RuntimeException & ) + { + DBG_ERROR5( "Warning: %s( %s )( %s ) attribute is of type %s( rejected: %s )\n", OUSTRING_CSTR( unoAttr ), OUSTRING_CSTR( value ), OUSTRING_CSTR( prop.Name ), OUSTRING_CSTR( prop.Type.getTypeName() ), OUSTRING_CSTR( value ) ); + return; + } + + // sets value on property + try + { + prophlp::setProperty( xPeer, unoAttr, any ); + } + catch( ... ) + { + DBG_ERROR2( "Warning: cannot set attribute %s to %s \n", OUSTRING_CSTR( unoAttr ), OUSTRING_CSTR( value ) ); + } +} + + + + +struct AttributesMap +{ + const char *name; + long value; + bool windowAttr; +}; +static const AttributesMap attribsMap[] = +{ + { "autohscroll", awt::VclWindowPeerAttribute::AUTOHSCROLL, false }, + { "autovscroll", awt::VclWindowPeerAttribute::AUTOVSCROLL, false }, + { "center", awt::VclWindowPeerAttribute::CENTER, false }, + { "clipchildren", awt::VclWindowPeerAttribute::CLIPCHILDREN, false }, + { "closeable", awt::WindowAttribute::CLOSEABLE, true }, + { "defbutton", awt::VclWindowPeerAttribute::DEFBUTTON, false }, + { "dropdown", awt::VclWindowPeerAttribute::DROPDOWN, false }, + { "fullsize", awt::WindowAttribute::FULLSIZE, true }, //FIXME? + { "group", awt::VclWindowPeerAttribute::GROUP, false }, + { "has_border", awt::WindowAttribute::BORDER, true }, + { "hscroll", awt::VclWindowPeerAttribute::HSCROLL, false }, + { "left", awt::VclWindowPeerAttribute::LEFT, false }, + { "moveable", awt::WindowAttribute::MOVEABLE, true }, + { "noborder", awt::VclWindowPeerAttribute::NOBORDER, false }, + { "nolabel", awt::VclWindowPeerAttribute::NOLABEL, false }, + { "optimumsize", awt::WindowAttribute::OPTIMUMSIZE, false }, + { "readonly", awt::VclWindowPeerAttribute::READONLY, false }, + { "right", awt::VclWindowPeerAttribute::RIGHT, false }, + { "show", awt::WindowAttribute::SHOW, true }, + { "sizeable", awt::WindowAttribute::SIZEABLE, true }, + { "sort", awt::VclWindowPeerAttribute::SORT, false }, + { "spin", awt::VclWindowPeerAttribute::SPIN, false }, + { "vscroll", awt::VclWindowPeerAttribute::VSCROLL, false }, + + // cutting on OK, YES_NO_CANCEL and related obsite attributes... +}; +static const int attribsMapLen = sizeof( attribsMap ) / sizeof( AttributesMap ); + +#if 0 +long getAttribute( const OUString &rName, bool bTopWindow ) +{ + + int min = 0, max = attribsMapLen - 1, mid, cmp; + do + { + mid = min +( max - min )/2; + cmp = rName.compareToAscii( attribsMap[ mid ].name ); + if ( cmp > 0 ) + min = mid+1; + else if ( cmp < 0 ) + max = mid-1; + else + { + if ( bTopWindow || attribsMap[ mid ].value ) + return attribsMap[ mid ].windowAttr; + return 0; + } + } + while ( min <= max ); + return 0; +} +#endif + +void propsFromAttributes( const uno::Reference<xml::input::XAttributes> & xAttributes, + PropList &rProps, sal_Int32 nNamespace ) +{ + sal_Int32 nAttrs = xAttributes->getLength(); + for ( sal_Int32 i = 0; i < nAttrs; i++ ) + { + if ( nNamespace != xAttributes->getUidByIndex( i ) ) + continue; + + std::pair< OUString, OUString > aElem + ( xAttributes->getLocalNameByIndex( i ), + xAttributes->getValueByIndex( i ) ); + + if ( aElem.first.getLength() > 0 ) // namespace bits .. + rProps.push_back( aElem ); + } +} + +bool +findAndRemove( const char *pAttr, PropList &rProps, OUString &rValue ) +{ + PropList::iterator it; + OUString aName = OUString::createFromAscii( pAttr ); + + for ( it = rProps.begin(); it != rProps.end(); it++ ) + { + if ( it->first.equalsIgnoreAsciiCase( aName ) + || it->first.equalsIgnoreAsciiCase( OUString::createFromAscii ("_") + aName ) ) + { + rValue = it->second; + rProps.erase( it ); + return true; + } + } + rValue = OUString(); + return false; +} + +long +getAttributeProps( PropList &rProps ) +{ + long nAttrs = 0; + OUString aValue; + + OUString trueStr( RTL_CONSTASCII_USTRINGPARAM( "true" ) ); + + if ( findAndRemove( "show", rProps, aValue ) && + aValue.equalsIgnoreAsciiCase( + OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) ) ) ) + ; + else + nAttrs |= awt::WindowAttribute::SHOW; + + for ( int i = 0; i < attribsMapLen; i++ ) + { + if ( findAndRemove( attribsMap[i].name, rProps, aValue ) ) + { + if ( aValue.equalsIgnoreAsciiCase( trueStr ) ) + nAttrs |= attribsMap[i].value; + } + } + + if ( findAndRemove( "align", rProps, aValue ) ) + { + sal_Int32 nVal = aValue.toInt32(); + + if ( nVal == 0 /* PROPERTY_ALIGN_LEFT */ ) + nAttrs |= awt::VclWindowPeerAttribute::LEFT; + else if ( nVal == 1 /* PROPERTY_ALIGN_CENTER */ ) + nAttrs |= awt::VclWindowPeerAttribute::CENTER; + else if ( nVal == 2 ) + nAttrs |= awt::VclWindowPeerAttribute::RIGHT; + } + + return nAttrs; +} + +} + diff --git a/toolkit/source/layout/core/proplist.hxx b/toolkit/source/layout/core/proplist.hxx new file mode 100644 index 000000000000..6a98cf449df3 --- /dev/null +++ b/toolkit/source/layout/core/proplist.hxx @@ -0,0 +1,91 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_CORE_PROPLIST_HXX +#define LAYOUT_CORE_PROPLIST_HXX + +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#include <com/sun/star/xml/input/XAttributes.hpp> +#include <list> +#include <rtl/ustring.hxx> +#include <toolkit/dllapi.h> +\ +namespace layoutimpl +{ + +namespace css = ::com::sun::star; + +typedef std::list< std::pair< rtl::OUString, rtl::OUString > > PropList; + +void propsFromAttributes( const css::uno::Reference<css::xml::input::XAttributes> & xAttributes, + PropList &rProps, sal_Int32 nNamespace ); + +void setProperties( css::uno::Reference< css::uno::XInterface > const& xPeer, + PropList const& rProps); + +void setProperty( css::uno::Reference< css::uno::XInterface > const& xPeer, + rtl::OUString const& attr, rtl::OUString const& value ); + +long getAttributeProps( PropList &rProps ); +bool findAndRemove( const char *pAttr, PropList &rProps, rtl::OUString &rValue); + +// Helpers - unfortunately VCLXWindows don't implement XPropertySet +// but containers do - these helpers help us to hide this +namespace prophlp +{ + +// can we set properties on this handle ? +bool TOOLKIT_DLLPUBLIC canHandleProps( const css::uno::Reference< css::uno::XInterface > &xRef ); +// if so which properties ? +css::uno::Reference< css::beans::XPropertySetInfo > TOOLKIT_DLLPUBLIC queryPropertyInfo( + const css::uno::Reference< css::uno::XInterface > &xRef ); +// set / get ... +void TOOLKIT_DLLPUBLIC setProperty( const css::uno::Reference< css::uno::XInterface > &xRef, + const rtl::OUString &rName, + css::uno::Any aValue ); +css::uno::Any TOOLKIT_DLLPUBLIC getProperty( const css::uno::Reference< css::uno::XInterface > &xRef, + const rtl::OUString &rName ); +} // namespace prophlp + +} // namespace layoutimpl + + +#if !OUSTRING_CSTR_PARANOIA +#define OUSTRING_CSTR( str ) \ + rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US ).getStr() +#else + +inline char const* OUSTRING_CSTR( rtl::OUString const& str ) +{ + rtl::OString *leak + = new rtl::OString (rtl::OUStringToOString (str, RTL_TEXTENCODING_ASCII_US)); + return leak->getStr(); +} + +#endif + +#endif /* LAYOUT_CORE_PROPLIST_HXX */ diff --git a/toolkit/source/layout/core/root.cxx b/toolkit/source/layout/core/root.cxx new file mode 100644 index 000000000000..af56e77f9aac --- /dev/null +++ b/toolkit/source/layout/core/root.cxx @@ -0,0 +1,409 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "root.hxx" + +#include <cassert> + +#include <com/sun/star/awt/WindowAttribute.hpp> +#include <com/sun/star/awt/XMessageBox.hpp> +#include <com/sun/star/awt/MessageBoxButtons.hpp> +#include <com/sun/star/frame/XDesktop.hpp> +#include <com/sun/star/awt/XMessageBoxFactory.hpp> +#include <com/sun/star/xml/sax/SAXParseException.hpp> +#include <com/sun/star/xml/sax/XParser.hpp> + +#include "helper.hxx" +#include "import.hxx" +#include "timer.hxx" +#include "translate.hxx" + +namespace layoutimpl +{ + +using namespace css; +using ::rtl::OUString; + +LayoutRoot::LayoutRoot( const uno::Reference< lang::XMultiServiceFactory >& xFactory ) + : mbDisposed( sal_False ) + , mxFactory( xFactory ) + , mpListeners( NULL ) + , mpToplevel( NULL ) +{ + if ( !xFactory.is() ) + throw uno::RuntimeException(); + mxLayoutUnit = uno::Reference< awt::XLayoutUnit >( new LayoutUnit() ); +} + +LayoutRoot::~LayoutRoot() +{ +// TODO: we want to delete the top level LayoutWidget... + ::osl::MutexGuard aGuard( maMutex ); + if ( !mbDisposed ) + { + try + { + m_refCount++; // inhibit multiple destruction + dispose(); + } + catch( uno::Exception& ) + { + } + } +} + +void ShowMessageBox( uno::Reference< lang::XMultiServiceFactory > const& xFactory, uno::Reference< awt::XToolkit > xToolkit, OUString const& aTitle, OUString const& aMessage ) +{ + uno::Reference< uno::XInterface > iDesktop = xFactory->createInstance + ( OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ); + uno::Reference< frame::XDesktop > xDesktop ( iDesktop, uno::UNO_QUERY ); + uno::Reference< frame::XFrame > xFrame ( xDesktop->getCurrentFrame() ); + uno::Reference< awt::XWindow > xContainerWindow( xFrame->getContainerWindow() ); + uno::Reference< awt::XWindowPeer > xWindowPeer( xContainerWindow, uno::UNO_QUERY_THROW ); + uno::Reference< awt::XMessageBoxFactory > xMessageBoxFactory( xToolkit, uno::UNO_QUERY ); + + awt::Rectangle aRectangle; + uno::Reference< awt::XMessageBox > xMessageBox + = xMessageBoxFactory->createMessageBox + ( xWindowPeer, aRectangle, OUString::createFromAscii( "errorbox" ), + awt::MessageBoxButtons::BUTTONS_OK, aTitle, aMessage ); + + if ( xMessageBox.is() ) + xMessageBox->execute(); + //FIXME: exceptions not caught and printed at top level?? + //else + //printf( "%s\n", OUSTRING_CSTR( aMessage ) ); +} + +void LayoutRoot::error( OUString const& message ) +{ + OSL_TRACE( "%s\n", OUSTRING_CSTR( message ) ); + ShowMessageBox( mxFactory, mxToolkit, + OUString::createFromAscii( "Fatal error" ), + message ); + throw uno::RuntimeException( message, uno::Reference< uno::XInterface >() ); +} + +// XInitialization +void SAL_CALL LayoutRoot::initialize( const uno::Sequence< uno::Any >& aArguments ) + throw ( uno::Exception, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( maMutex ); + + if ( mbDisposed ) + throw lang::DisposedException(); + + if ( mxContainer.is() ) // only 1 init ... + throw uno::Exception(); + + if ( !aArguments.getLength() ) + throw lang::IllegalArgumentException(); + + OSL_ENSURE( aArguments.getLength() == 1, "Wrong arg count\n" ); + + OUString aXMLName; + if ( !( aArguments[0] >>= aXMLName ) ) + throw lang::IllegalArgumentException(); + + uno::Reference< xml::sax::XParser > xParser + ( mxFactory->createInstance( + OUString::createFromAscii( "com.sun.star.xml.sax.Parser" ) ), + uno::UNO_QUERY ); + OSL_ASSERT( xParser.is() ); + if (! xParser.is()) + { + throw uno::RuntimeException( + OUString::createFromAscii( "cannot create sax-parser component" ), + uno::Reference< uno::XInterface >() ); + } + + // FIXME: quite possibly we want to pass this in ... + uno::Reference< awt::XToolkit > xToolkit; + + mxToolkit = uno::Reference< awt::XToolkit >( + mxFactory->createInstance( + OUString::createFromAscii( "com.sun.star.awt.Toolkit" ) ), + uno::UNO_QUERY ); + + if ( !mxToolkit.is() ) + throw uno::RuntimeException( + OUString::createFromAscii( "failed to create toolkit!" ), + uno::Reference< uno::XInterface >() ); + + OUString aXMLFile = readRightTranslation( aXMLName ); + uno::Reference< io::XInputStream > xStream = getFileAsStream( aXMLFile ); + if (! xStream.is() ) + error( OUString::createFromAscii( "Installation problem: cannot find XML file:" ) + aXMLName ); + + // error handler, entity resolver omitted + + ImportContext *pCtx = new ImportContext( *this ); + + uno::Reference< xml::input::XRoot > xRoot( pCtx ); + uno::Sequence < uno::Any > aArgs( 1 ); + aArgs[0] <<= xRoot; + uno::Reference< xml::sax::XDocumentHandler > xDocHandler + (mxFactory->createInstanceWithArguments + ( OUString::createFromAscii( "com.sun.star.xml.input.SaxDocumentHandler" ), + aArgs ), uno::UNO_QUERY ); + + if (! xDocHandler.is() ) + error( OUString::createFromAscii( "cannot find SAx handler for document type of:") + aXMLName ); + + xParser->setDocumentHandler( xDocHandler ); + + xml::sax::InputSource source; + source.aInputStream = xStream; + source.sSystemId = OUString::createFromAscii( "virtual file" ); + + try + { + xParser->parseStream( source ); + } + catch ( xml::sax::SAXParseException& e ) + { + OUString c = OUString::createFromAscii( ":" ); + error( aXMLName + + c + OUString::valueOf( e.LineNumber ) + + c + OUString::valueOf( e.ColumnNumber ) + + c + OUString::createFromAscii( "Sax parse error" ) ); + } +} + +// XLayoutContainer +uno::Reference< awt::XLayoutContainer > LayoutRoot::getLayoutContainer() throw (uno::RuntimeException) +{ + return uno::Reference< awt::XLayoutContainer >(); +} + +// local helper ... +void LayoutRoot::addItem( const OUString &rName, + const uno::Reference< awt::XLayoutConstrains > &xRef ) +{ + maItems[ rName ] = xRef; +} + +// XNameAccess +uno::Any SAL_CALL LayoutRoot::getByName( const OUString &rName ) + throw ( container::NoSuchElementException, + lang::WrappedTargetException, + uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( maMutex ); + if ( mbDisposed ) + throw lang::DisposedException(); + + uno::Reference< awt::XLayoutConstrains > xItem; + ItemHash::iterator i = maItems.find( rName ); + if ( i != maItems.end() ) + xItem = i->second; + return uno::makeAny( xItem ); +} + +sal_Bool SAL_CALL LayoutRoot::hasByName( const OUString &rName ) + throw (uno::RuntimeException) +{ + ::osl::MutexGuard aGuard( maMutex ); + if ( mbDisposed ) throw lang::DisposedException(); + + ItemHash::iterator i = maItems.find( rName ); + return i != maItems.end(); +} + +uno::Sequence< OUString > SAL_CALL LayoutRoot::getElementNames() + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( maMutex ); + if ( mbDisposed ) throw lang::DisposedException(); + + uno::Sequence< OUString > aNames( maItems.size() ); + sal_Int32 nPos = 0; + + for ( ItemHash::const_iterator it = maItems.begin(); + it != maItems.end(); it++ ) + aNames[ nPos++ ] = it->first; + + return aNames; +} + +uno::Type SAL_CALL LayoutRoot::getElementType() + throw ( uno::RuntimeException ) +{ + return getCppuType( ( const uno::Reference< awt::XLayoutConstrains >* )NULL ); +} + +sal_Bool SAL_CALL LayoutRoot::hasElements() + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( maMutex ); + + if ( mbDisposed ) throw lang::DisposedException(); + + return maItems.size() > 0; +} + +// XComponent +void SAL_CALL LayoutRoot::dispose() + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( maMutex ); + + if ( mbDisposed ) throw lang::DisposedException(); + + if ( mpListeners ) + { + + lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) ); + mpListeners->disposeAndClear( aSource ); + delete mpListeners; + mpListeners = NULL; + } + + maItems.clear(); + mbDisposed = sal_True; +} + +void SAL_CALL LayoutRoot::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( maMutex ); + + if ( mbDisposed ) throw lang::DisposedException(); + + if ( !mpListeners ) + mpListeners = new ::cppu::OInterfaceContainerHelper( maMutex ); + mpListeners->addInterface( xListener ); +} + +void SAL_CALL LayoutRoot::removeEventListener( const uno::Reference< lang::XEventListener >& xListener ) + throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( maMutex ); + + if ( mbDisposed ) throw lang::DisposedException(); + + if ( mpListeners ) + mpListeners->removeInterface( xListener ); +} + +// builder + +LayoutWidget *LayoutRoot::create( OUString id, const OUString unoName, long attrbs,uno::Reference< awt::XLayoutContainer > xParent ) +{ + LayoutWidget *pWidget = new LayoutWidget( mxToolkit, xParent, unoName, attrbs ); + if ( !mpToplevel ) + { + mpToplevel = pWidget; + mxWindow = uno::Reference< awt::XWindow >( pWidget->getPeer(), uno::UNO_QUERY ); + mxContainer = pWidget->mxContainer; + } + if ( pWidget->mxContainer.is() ) + pWidget->mxContainer->setLayoutUnit( mxLayoutUnit ); + if ( id.getLength() ) + maItems[ id ] = pWidget->getPeer(); + return pWidget; +} + +#if 0 +uno::Reference< awt::XLayoutConstrains > LayoutRoot::getToplevel() +{ + if ( mpToplevel ) + return mpToplevel->getPeer(); + return uno::Reference< awt::XLayoutConstrains > (); +} + +uno::Reference< awt::XLayoutConstrains > LayoutRoot::getById( OUString id ) +{ + uno::Reference< awt::XLayoutConstrains > rRef = 0; + ItemHash::iterator it = maItems.find( id ); + if ( it != maItems.end() ) + rRef = it->second; + return rRef; +} +#endif + +LayoutWidget::LayoutWidget( uno::Reference< awt::XToolkit > xToolkit, + uno::Reference< awt::XLayoutContainer > xParent, + OUString unoName, long attrbs ) +{ + while ( xParent.is() && !uno::Reference< awt::XWindow >( xParent, uno::UNO_QUERY ).is() ) + { + uno::Reference< awt::XLayoutContainer > xContainer( xParent, uno::UNO_QUERY ); + assert( xContainer.is() ); + xParent = uno::Reference< awt::XLayoutContainer >( xContainer->getParent(), uno::UNO_QUERY ); + } + + mxWidget = WidgetFactory::createWidget( xToolkit, xParent, unoName, attrbs ); + assert( mxWidget.is() ); + mxContainer = uno::Reference< awt::XLayoutContainer >( mxWidget, uno::UNO_QUERY ); +} + +LayoutWidget::~LayoutWidget() +{ + /* should we dispose of the references...? */ + // at least of its children... Or should root? +} + +bool LayoutWidget::addChild( LayoutWidget *pChild ) +{ + if ( !mxContainer.is() ) + return false; + + try + { + mxContainer->addChild( pChild->mxWidget ); + } + catch( awt::MaxChildrenException ex ) + { + return false; + } + return true; +} + +void LayoutWidget::setProperties( PropList const& rProps ) +{ + ::layoutimpl::setProperties( mxWidget, rProps ); +} + +void LayoutWidget::setProperty( OUString const& attr, OUString const& value ) +{ + ::layoutimpl::setProperty( mxWidget, attr, value ); +} + +void LayoutWidget::setChildProperties( LayoutWidget *pChild, + PropList const& rProps ) +{ + uno::Reference< beans::XPropertySet > xChildPeer; + xChildPeer = mxContainer->getChildProperties( pChild->mxWidget ); + + if ( xChildPeer.is() ) + ::layoutimpl::setProperties( xChildPeer, rProps ); +} + +} // namespace layoutimpl + diff --git a/toolkit/source/layout/core/root.hxx b/toolkit/source/layout/core/root.hxx new file mode 100644 index 000000000000..321c891bbe50 --- /dev/null +++ b/toolkit/source/layout/core/root.hxx @@ -0,0 +1,156 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_CORE_ROOT_HXX +#define LAYOUT_CORE_ROOT_HXX + +#define _BACKWARD_BACKWARD_WARNING_H 1 +#include <hash_map> + +#include <com/sun/star/awt/XLayoutRoot.hpp> +#include <com/sun/star/awt/XToolkit.hpp> +#include <com/sun/star/awt/XWindow.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <cppuhelper/implbase3.hxx> +#include <cppuhelper/interfacecontainer.h> +#include <toolkit/dllapi.h> + +#include <layout/core/proplist.hxx> + +namespace layoutimpl +{ + +namespace css = ::com::sun::star; + +css::uno::Reference< css::io::XInputStream > getFileAsStream( const rtl::OUString &rName ); + +/* Interface generation code -- to hook to a parser. */ + +/* + TODO: (ricardo) I think we should cut on LayoutRoot, stripping out its widget + proxy interface (just make it return the root widget). Would even make it easier + if there was interest to support multiple toplevel widgets in the same file. + + We also need to make sure the code gets diposed well... There is no need to keep + these objects around after initialization... +*/ + + +class LayoutWidget; + +class TOOLKIT_DLLPUBLIC LayoutRoot : public ::cppu::WeakImplHelper3< + css::awt::XLayoutRoot, + css::lang::XInitialization, + css::lang::XComponent> +{ +protected: + ::osl::Mutex maMutex; + + typedef std::hash_map< rtl::OUString, + css::uno::Reference< css::awt::XLayoutConstrains >, + ::rtl::OUStringHash > ItemHash; + ItemHash maItems; + + sal_Bool mbDisposed; + css::uno::Reference< css::lang::XMultiServiceFactory > mxFactory; + ::cppu::OInterfaceContainerHelper *mpListeners; + + css::uno::Reference< css::awt::XWindow > mxWindow; + css::uno::Reference< css::awt::XLayoutContainer > mxContainer; + + css::uno::Reference< css::awt::XToolkit > mxToolkit; + LayoutWidget *mpToplevel; + css::uno::Reference< css::awt::XLayoutUnit > mxLayoutUnit; + + void error( rtl::OUString const& message ); + +public: + LayoutRoot( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory ); + virtual ~LayoutRoot(); + + void addItem( const rtl::OUString &rName, + const css::uno::Reference< css::awt::XLayoutConstrains > &xRef ); + + void setWindow( css::uno::Reference< css::awt::XLayoutConstrains > xPeer ) + { + mxWindow = css::uno::Reference< css::awt::XWindow >( xPeer, css::uno::UNO_QUERY ); + } + + // get XLayoutContainer + virtual css::uno::Reference< css::awt::XLayoutContainer > SAL_CALL getLayoutContainer() throw (css::uno::RuntimeException); + + // XInitialization + virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) throw (css::uno::Exception, css::uno::RuntimeException); + + // XNameAccess + virtual css::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException); + virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames() throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (css::uno::RuntimeException); + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasElements() throw (css::uno::RuntimeException); + + // XComponent + virtual void SAL_CALL dispose() throw (css::uno::RuntimeException); + virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) throw (css::uno::RuntimeException); + virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) throw (css::uno::RuntimeException); + + // generator + virtual LayoutWidget *create( rtl::OUString id, const rtl::OUString unoName, long attrbs, css::uno::Reference< css::awt::XLayoutContainer > xParent ); +}; + +class TOOLKIT_DLLPUBLIC LayoutWidget +{ + friend class LayoutRoot; + +public: + LayoutWidget() {} + LayoutWidget( css::uno::Reference< css::awt::XToolkit > xToolkit, + css::uno::Reference< css::awt::XLayoutContainer > xToplevel, + rtl::OUString unoName, long attrbs ); + virtual ~LayoutWidget(); + + virtual void setProperties( const PropList &rProps ); + virtual void setProperty( rtl::OUString const& attr, rtl::OUString const& value ); + + virtual bool addChild( LayoutWidget *pChild ); + virtual void setChildProperties( LayoutWidget *pChild, const PropList &rProps ); + + inline css::uno::Reference< css::awt::XLayoutConstrains > getPeer() + { return mxWidget; } + inline css::uno::Reference< css::awt::XLayoutContainer > getContainer() + { return mxContainer; } + +protected: + css::uno::Reference< css::awt::XLayoutConstrains > mxWidget; + css::uno::Reference< css::awt::XLayoutContainer > mxContainer; +}; + +} // namespace layoutimpl + +#endif /* LAYOUT_CORE_ROOT_HXX */ diff --git a/toolkit/source/layout/core/table.cxx b/toolkit/source/layout/core/table.cxx new file mode 100644 index 000000000000..48156b1d730e --- /dev/null +++ b/toolkit/source/layout/core/table.cxx @@ -0,0 +1,311 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <table.hxx> + +#include <sal/macros.h> +#include <osl/mutex.hxx> +#include <cppuhelper/propshlp.hxx> +#include <cppuhelper/interfacecontainer.h> +#include <com/sun/star/awt/PosSize.hpp> +#include <tools/debug.hxx> + +// fixed point precision for distributing error +#define FIXED_PT 16 + +namespace layoutimpl +{ + +using namespace com::sun::star; + +Table::ChildProps::ChildProps( Table::ChildData *pData ) +{ + addProp( RTL_CONSTASCII_USTRINGPARAM( "XExpand" ), + ::getCppuType( static_cast< const sal_Bool* >( NULL ) ), + &( pData->mbExpand[ 0 ] ) ); + addProp( RTL_CONSTASCII_USTRINGPARAM( "YExpand" ), + ::getCppuType( static_cast< const sal_Bool* >( NULL ) ), + &( pData->mbExpand[ 1 ] ) ); + addProp( RTL_CONSTASCII_USTRINGPARAM( "ColSpan" ), + ::getCppuType( static_cast< const sal_Int32* >( NULL ) ), + &( pData->mnColSpan ) ); + addProp( RTL_CONSTASCII_USTRINGPARAM( "RowSpan" ), + ::getCppuType( static_cast< const sal_Int32* >( NULL ) ), + &( pData->mnRowSpan ) ); +} + +bool Table::ChildData::isVisible() +{ + return Box_Base::ChildData::isVisible() + && ( mnColSpan > 0 ) && ( mnRowSpan > 0 ); +} + +Table::Table() + : Box_Base() + , mnColsLen( 1 )// another default value could be 0xffff for infinite columns( = 1 row ) +{ + addProp( RTL_CONSTASCII_USTRINGPARAM( "Columns" ), + ::getCppuType( static_cast< const sal_Int32* >( NULL ) ), + &mnColsLen ); +} + +Table::ChildData::ChildData( uno::Reference< awt::XLayoutConstrains > const& xChild ) + : Box_Base::ChildData( xChild ) +// , mbExpand( { 1, 1 } ) + , mnColSpan( 1 ) + , mnRowSpan( 1 ) + , mnLeftCol( 0 ) + , mnRightCol( 0 ) + , mnTopRow( 0 ) + , mnBottomRow( 0 ) +{ + mbExpand[ 0 ] = 1; + mbExpand[ 1 ] = 1; +} + +Table::ChildData* +Table::createChild( uno::Reference< awt::XLayoutConstrains > const& xChild ) +{ + return new ChildData( xChild ); +} + +Table::ChildProps* +Table::createChildProps( Box_Base::ChildData *pData ) +{ + return new ChildProps( static_cast<Table::ChildData*> ( pData ) ); +} + +void SAL_CALL +Table::addChild( const uno::Reference< awt::XLayoutConstrains >& xChild ) + throw( uno::RuntimeException, awt::MaxChildrenException ) +{ + if ( xChild.is() ) + { + Box_Base::addChild( xChild ); + // cause of flicker + allocateChildAt( xChild, awt::Rectangle( 0,0,0,0 ) ); + } +} + +awt::Size SAL_CALL +Table::getMinimumSize() throw( uno::RuntimeException ) +{ + int nRowsLen = 0; + + // 1. layout the table -- adjust to cope with row-spans... + { + // temporary 1D representation of the table + std::vector< ChildData *> aTable; + + int col = 0; + int row = 0; + for ( std::list<Box_Base::ChildData *>::iterator it + = maChildren.begin(); it != maChildren.end(); it++ ) + { + ChildData *child = static_cast<Table::ChildData*> ( *it ); + if ( !child->isVisible() ) + continue; + + while ( col + SAL_MIN( child->mnColSpan, mnColsLen ) > mnColsLen ) + { + col = 0; + row++; + + unsigned int i = col +( row*mnColsLen ); + while ( aTable.size() > i && !aTable[ i ] ) + i++; + + col = i % mnColsLen; + row = i / mnColsLen; + } + + child->mnLeftCol = col; + child->mnRightCol = SAL_MIN( col + child->mnColSpan, mnColsLen ); + child->mnTopRow = row; + child->mnBottomRow = row + child->mnRowSpan; + + col += child->mnColSpan; + + unsigned int start = child->mnLeftCol +( child->mnTopRow*mnColsLen ); + unsigned int end =( child->mnRightCol-1 ) +( ( child->mnBottomRow-1 )*mnColsLen ); + if ( aTable.size() < end+1 ) + aTable.resize( end+1, NULL ); + for ( unsigned int i = start; i < end; i++ ) + aTable[ i ] = child; + + nRowsLen = SAL_MAX( nRowsLen, child->mnBottomRow ); + } + } + + // 2. calculate columns/rows sizes + for ( int g = 0; g < 2; g++ ) + { + std::vector< GroupData > &aGroup = g == 0 ? maCols : maRows; + + aGroup.clear(); + aGroup.resize( g == 0 ? mnColsLen : nRowsLen ); + + // 2.1 base sizes on one-column/row children + for ( std::list<Box_Base::ChildData *>::iterator it + = maChildren.begin(); it != maChildren.end(); it++ ) + { + ChildData *child = static_cast<Table::ChildData*> ( *it ); + if ( !child->isVisible() ) + continue; + const int nFirstAttach = g == 0 ? child->mnLeftCol : child->mnTopRow; + const int nLastAttach = g == 0 ? child->mnRightCol : child->mnBottomRow; + + if ( nFirstAttach == nLastAttach-1 ) + { + child->maRequisition = child->mxChild->getMinimumSize(); + int attach = nFirstAttach; + int child_size = g == 0 ? child->maRequisition.Width + : child->maRequisition.Height; + aGroup[ attach ].mnSize = SAL_MAX( aGroup[ attach ].mnSize, + child_size ); + if ( child->mbExpand[ g ] ) + aGroup[ attach ].mbExpand = true; + } + } + + // 2.2 make sure multiple-columns/rows children fit + for ( std::list<Box_Base::ChildData *>::iterator it + = maChildren.begin(); it != maChildren.end(); it++ ) + { + ChildData *child = static_cast<Table::ChildData*> ( *it ); + if ( !child->isVisible() ) + continue; + const int nFirstAttach = g == 0 ? child->mnLeftCol : child->mnTopRow; + const int nLastAttach = g == 0 ? child->mnRightCol : child->mnBottomRow; + + if ( nFirstAttach != nLastAttach-1 ) + { + child->maRequisition = child->mxChild->getMinimumSize(); + int size = 0; + int expandables = 0; + for ( int i = nFirstAttach; i < nLastAttach; i++ ) + { + size += aGroup[ i ].mnSize; + if ( aGroup[ i ].mbExpand ) + expandables++; + } + + int child_size = g == 0 ? child->maRequisition.Width + : child->maRequisition.Height; + int extra = child_size - size; + if ( extra > 0 ) + { + if ( expandables ) + extra /= expandables; + else + extra /= nLastAttach - nFirstAttach; + + for ( int i = nFirstAttach; i < nLastAttach; i++ ) + if ( expandables == 0 || aGroup[ i ].mbExpand ) + aGroup[ i ].mnSize += extra; + } + } + } + } + + // 3. Sum everything up + mnColExpandables =( mnRowExpandables = 0 ); + maRequisition.Width =( maRequisition.Height = 0 ); + for ( std::vector<GroupData>::iterator it = maCols.begin(); + it != maCols.end(); it++ ) + { + maRequisition.Width += it->mnSize; + if ( it->mbExpand ) + mnColExpandables++; + } + for ( std::vector<GroupData>::iterator it = maRows.begin(); + it != maRows.end(); it++ ) + { + maRequisition.Height += it->mnSize; + if ( it->mbExpand ) + mnRowExpandables++; + } + + return maRequisition; +} + +void SAL_CALL +Table::allocateArea( const awt::Rectangle &rArea ) + throw( uno::RuntimeException ) +{ + maAllocation = rArea; + if ( maCols.size() == 0 || maRows.size() == 0 ) + return; + + int nExtraSize[ 2 ] = { SAL_MAX( rArea.Width - maRequisition.Width, 0 ), + SAL_MAX( rArea.Height - maRequisition.Height, 0 ) }; + // split it + nExtraSize[ 0 ] /= mnColExpandables ? mnColExpandables : mnColsLen; + nExtraSize[ 1 ] /= mnRowExpandables ? mnRowExpandables : maRows.size(); + + for ( std::list<Box_Base::ChildData *>::const_iterator it + = maChildren.begin(); it != maChildren.end(); it++ ) + { + ChildData *child = static_cast<Table::ChildData*> ( *it ); + if ( !child->isVisible() ) + continue; + + awt::Rectangle rChildArea( rArea.X, rArea.Y, 0, 0 ); + + for ( int g = 0; g < 2; g++ ) + { + std::vector< GroupData > &aGroup = g == 0 ? maCols : maRows; + const int nFirstAttach = g == 0 ? child->mnLeftCol : child->mnTopRow; + const int nLastAttach = g == 0 ? child->mnRightCol : child->mnBottomRow; + + for ( int i = 0; i < nFirstAttach; i++ ) + { + int gSize = aGroup[ i ].mnSize; + if ( aGroup[ i ].mbExpand ) + gSize += nExtraSize[ g ]; + if ( g == 0 ) + rChildArea.X += gSize; + else + rChildArea.Y += gSize; + } + for ( int i = nFirstAttach; i < nLastAttach; i++ ) + { + int gSize = aGroup[ i ].mnSize; + if ( aGroup[ i ].mbExpand ) + gSize += nExtraSize[ g ]; + if ( g == 0 ) + rChildArea.Width += gSize; + else + rChildArea.Height += gSize; + } + } + + allocateChildAt( child->mxChild, rChildArea ); + } +} + +} // namespace layoutimpl diff --git a/toolkit/source/layout/core/table.hxx b/toolkit/source/layout/core/table.hxx new file mode 100644 index 000000000000..dd05eba38c41 --- /dev/null +++ b/toolkit/source/layout/core/table.hxx @@ -0,0 +1,102 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_CORE_TABLE_HXX +#define LAYOUT_CORE_TABLE_HXX + +#include <layout/core/box-base.hxx> + +namespace layoutimpl +{ + +class Table : public Box_Base +{ +public: + // Children properties + struct ChildData : public Box_Base::ChildData + { + sal_Bool mbExpand[ 2 ]; + sal_Int32 mnColSpan; + sal_Int32 mnRowSpan; + int mnLeftCol; + int mnRightCol; + int mnTopRow; + int mnBottomRow; + + ChildData( css::uno::Reference< css::awt::XLayoutConstrains > const& xChild ); + bool isVisible(); + }; + + struct ChildProps : public Box_Base::ChildProps + { + ChildProps( ChildData *pData ); + }; + +protected: + + // a group of children; either a column or a row + struct GroupData + { + sal_Bool mbExpand; + int mnSize; // request size (width or height) + GroupData() : mbExpand( false ), mnSize( 0 ) {} + }; + + // Table properties + sal_Int32 mnColsLen; + std::vector< GroupData > maCols; + std::vector< GroupData > maRows; + int mnColExpandables, mnRowExpandables; + + ChildData *createChild( css::uno::Reference< css::awt::XLayoutConstrains > const& xChild ); + ChildProps *createChildProps( Box_Base::ChildData* pData ); + +public: + Table(); + + // css::awt::XLayoutContainer + virtual void SAL_CALL addChild( const css::uno::Reference< css::awt::XLayoutConstrains >& Child ) + throw (css::uno::RuntimeException, css::awt::MaxChildrenException); + + virtual void SAL_CALL allocateArea( const css::awt::Rectangle &rArea ) + throw (css::uno::RuntimeException); + + virtual css::awt::Size SAL_CALL getMinimumSize() + throw(css::uno::RuntimeException); + + // unimplemented: + virtual sal_Bool SAL_CALL hasHeightForWidth() + throw(css::uno::RuntimeException) + { return false; } + virtual sal_Int32 SAL_CALL getHeightForWidth( sal_Int32 /*nWidth*/ ) + throw(css::uno::RuntimeException) + { return maRequisition.Height; } +}; + +} // namespace layoutimpl + +#endif /* LAYOUT_CORE_TABLE_HXX */ diff --git a/toolkit/source/layout/core/timer.cxx b/toolkit/source/layout/core/timer.cxx new file mode 100644 index 000000000000..f0975fd3f76b --- /dev/null +++ b/toolkit/source/layout/core/timer.cxx @@ -0,0 +1,148 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "timer.hxx" + +#include <vector> +#include <list> +#include <vcl/timer.hxx> +#include <com/sun/star/awt/XLayoutContainer.hpp> + +namespace layoutimpl +{ +using namespace ::com::sun::star; + +class AllocateTimer : public Timer +{ + typedef std::list< uno::Reference< awt::XLayoutContainer > > ContainerList; + ContainerList mxContainers; + uno::Reference< awt::XLayoutContainer > mxLastAdded; + +public: + AllocateTimer() + { + // timer set to 0 -- just process it as soon as it gets idle + SetTimeout( 0 ); + } + + static inline bool isParentOf( uno::Reference< awt::XLayoutContainer > xParent, + uno::Reference< awt::XLayoutContainer > xWidget ) + { + while ( xWidget.is() ) + { + if ( xWidget == xParent ) + return true; + xWidget = uno::Reference< awt::XLayoutContainer >( xWidget->getParent(), uno::UNO_QUERY ); + } + return false; + } + + static inline void eraseChildren( ContainerList::iterator &it, ContainerList &list ) + { + ContainerList::iterator jt = list.begin(); + while ( jt != list.end() ) + { + if ( it != jt && isParentOf( *it, *jt ) ) + jt = list.erase( jt ); + else + jt++; + } + } + + static inline bool isContainerDamaged( uno::Reference< awt::XLayoutContainer > xContainer ) + { + uno::Reference< awt::XLayoutConstrains > xConstrains( xContainer, uno::UNO_QUERY ); + awt::Size lastReq( xContainer->getRequestedSize() ); + awt::Size curReq( xConstrains->getMinimumSize() ); + return lastReq.Width != curReq.Width || lastReq.Height != curReq.Height; + } + + void add( const uno::Reference< awt::XLayoutContainer > &xContainer ) + { + // small optimization + if ( mxLastAdded == xContainer ) + return; + mxLastAdded = xContainer; + + mxContainers.push_back( xContainer ); + } + + virtual void Timeout() + { + mxLastAdded = uno::Reference< awt::XLayoutContainer >(); + + // 1. remove duplications and children + for ( ContainerList::iterator it = mxContainers.begin(); + it != mxContainers.end(); it++ ) + eraseChildren( it, mxContainers ); + + // 2. check damage extent + for ( ContainerList::iterator it = mxContainers.begin(); + it != mxContainers.end(); it++ ) + { + uno::Reference< awt::XLayoutContainer > xContainer = *it; + while ( xContainer->getParent().is() && isContainerDamaged( xContainer ) ) + { + xContainer = uno::Reference< awt::XLayoutContainer >( + xContainer->getParent(), uno::UNO_QUERY ); + } + + if ( *it != xContainer ) + { + // 2.2 replace it with parent + *it = xContainer; + + // 2.3 remove children of new parent + eraseChildren( it, mxContainers ); + } + } + + // 3. force re-calculations + for ( ContainerList::iterator it = mxContainers.begin(); + it != mxContainers.end(); it++ ) + (*it)->allocateArea( (*it)->getAllocatedArea() ); + } +}; + +static void AddResizeTimeout( const uno::Reference< awt::XLayoutContainer > &xCont ) +{ + static AllocateTimer timer; + timer.add( xCont ); + timer.Start(); +} + +LayoutUnit::LayoutUnit() : LayoutUnit_Base() +{ +} + +void SAL_CALL LayoutUnit::queueResize( const uno::Reference< awt::XLayoutContainer > &xContainer ) + throw( uno::RuntimeException ) +{ + AddResizeTimeout( xContainer ); +} + +} diff --git a/toolkit/source/layout/core/timer.hxx b/toolkit/source/layout/core/timer.hxx new file mode 100644 index 000000000000..f8432141c2f1 --- /dev/null +++ b/toolkit/source/layout/core/timer.hxx @@ -0,0 +1,49 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_CORE_TIMER_HXX +#define LAYOUT_CORE_TIMER_HXX + +#include <com/sun/star/awt/XLayoutUnit.hpp> +#include <cppuhelper/implbase1.hxx> + +namespace layoutimpl +{ + +typedef ::cppu::WeakImplHelper1< com::sun::star::awt::XLayoutUnit > LayoutUnit_Base; + +class LayoutUnit : public LayoutUnit_Base +{ +public: + LayoutUnit(); + void SAL_CALL queueResize( const com::sun::star::uno::Reference< com::sun::star::awt::XLayoutContainer > &xContainer ) + throw( com::sun::star::uno::RuntimeException ); +}; + +} + +#endif /* LAYOUT_CORE_TIMER_HXX */ diff --git a/toolkit/source/layout/core/translate.cxx b/toolkit/source/layout/core/translate.cxx new file mode 100644 index 000000000000..fa09d02190d2 --- /dev/null +++ b/toolkit/source/layout/core/translate.cxx @@ -0,0 +1,130 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "translate.hxx" + +#include <list> +#if TEST_LAYOUT +#include <cstdio> +#include "tools/getprocessworkingdir.hxx" +#endif + +#include <unotools/bootstrap.hxx> +#include <unotools/localfilehelper.hxx> +#include <unotools/ucbhelper.hxx> +#include <vcl/svapp.hxx> + +#include "proplist.hxx" + +namespace layoutimpl +{ +namespace css = ::com::sun::star; +using namespace css; +using ::rtl::OUString; +using ::utl::LocalFileHelper; +using ::utl::UCBContentHelper; +using ::utl::Bootstrap; + +static std::list<OUString> +getLocaleSubdirList( lang::Locale const& rLocale ) +{ + std::list<OUString> aSubdirs; + aSubdirs.push_front( OUString::createFromAscii( "." ) ); + aSubdirs.push_front( OUString::createFromAscii( "en-US" ) ); + if ( rLocale.Language.getLength() ) + aSubdirs.push_front( rLocale.Language ); + if ( rLocale.Country.getLength() ) + { + OUString aLocaleCountry = rLocale.Language + + OUString::createFromAscii( "-" ) + + rLocale.Country; + aSubdirs.push_front( aLocaleCountry ); + if ( rLocale.Variant.getLength() ) + aSubdirs.push_front( aLocaleCountry + + OUString::createFromAscii( "." ) + + rLocale.Variant ); + } + return aSubdirs; +} + +static bool +fileExists( String const& aFile ) +{ + String aUrl; + LocalFileHelper::ConvertPhysicalNameToURL( aFile, aUrl ); + return UCBContentHelper::Exists( aUrl ); +} + +static OUString +getFirstExisting( OUString const& aDir, std::list<OUString> const& aSubDirs, + OUString const& aXMLName ) +{ + static OUString const aSlash = OUString::createFromAscii( "/" ); + String aResult; + for ( std::list<OUString>::const_iterator i = aSubDirs.begin(); + i != aSubDirs.end(); i++ ) + { + String aFile = aDir + aSlash + *i + aSlash + aXMLName; + OSL_TRACE( "testing: %s", OUSTRING_CSTR( aFile ) ); + if ( fileExists( aFile ) ) + return aFile; + } + return OUString(); +} + +/* FIXME: IWBN to share code with impimagetree.cxx, also for reading + from zip files. */ +OUString +readRightTranslation( OUString const& aXMLName ) +{ + String aXMLFile; + std::list<OUString> aSubdirs + = getLocaleSubdirList( Application::GetSettings().GetUILocale() ); +#if TEST_LAYOUT // read from cwd first + OUString aCurrentWorkingUrl; + tools::getProcessWorkingDir( &aCurrentWorkingUrl ); + String aCurrentWorkingDir; + LocalFileHelper::ConvertURLToPhysicalName( aCurrentWorkingUrl, aCurrentWorkingDir ); + aXMLFile = getFirstExisting( aCurrentWorkingDir, aSubdirs, aXMLName ); + if ( aXMLFile.Len() ) + ; + else +#endif /* TEST_LAYOUT */ + { + OUString aShareUrl; + Bootstrap::locateSharedData( aShareUrl ); + OUString aXMLUrl = aShareUrl + OUString::createFromAscii( "/layout" ); + String aXMLDir; + LocalFileHelper::ConvertURLToPhysicalName( aXMLUrl, aXMLDir ); + aXMLFile = getFirstExisting( aXMLDir, aSubdirs, aXMLName ); + } + + OSL_TRACE( "FOUND:%s", OUSTRING_CSTR ( OUString (aXMLFile) ) ); + return aXMLFile; +} + +} // namespace layoutimpl diff --git a/toolkit/source/layout/core/translate.hxx b/toolkit/source/layout/core/translate.hxx new file mode 100644 index 000000000000..597b4a88530e --- /dev/null +++ b/toolkit/source/layout/core/translate.hxx @@ -0,0 +1,40 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_CORE_TRANSLATE_HXX +#define LAYOUT_CORE_TRANSLATE_HXX + +namespace rtl { +class OUString; +} // namespace rtl + +namespace layoutimpl +{ +::rtl::OUString readRightTranslation( ::rtl::OUString const& aXMLName ); +} // namespace layoutimpl + +#endif /* LAYOUT_CORE_TRANSLATE_HXX */ diff --git a/toolkit/source/layout/core/vcl.cxx b/toolkit/source/layout/core/vcl.cxx new file mode 100644 index 000000000000..2b8d910584e9 --- /dev/null +++ b/toolkit/source/layout/core/vcl.cxx @@ -0,0 +1,66 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <vcl.hxx> + +#include <sal/types.h> +#include <vcl/button.hxx> + +static PushButton* get_button (Dialog const* dialog, sal_uInt32 type) +{ + Window* child = dialog->GetWindow (WINDOW_FIRSTCHILD); + while (child) + { + if (child->GetType () == type) + return static_cast <PushButton*> (child); + child = child->GetWindow (WINDOW_NEXT); + } + + return 0; +} + +#define IMPLEMENT_CLOSING_DIALOG(cls)\ + Closing##cls::Closing##cls (Window* parent, WinBits bits)\ + : cls (parent, bits)\ + , mClosing (false)\ + {\ + }\ + BOOL Closing##cls::Close ()\ + {\ + if (mClosing)\ + EndDialog (false);\ + else if (PushButton *cancel = get_button (this, WINDOW_CANCELBUTTON))\ + cancel->Click ();\ + else if (PushButton *ok = get_button (this, WINDOW_OKBUTTON))\ + ok->Click ();\ + mClosing = true;\ + return false;\ + } + +IMPLEMENT_CLOSING_DIALOG (Dialog); +IMPLEMENT_CLOSING_DIALOG (ModelessDialog); +IMPLEMENT_CLOSING_DIALOG (ModalDialog); diff --git a/toolkit/source/layout/core/vcl.hxx b/toolkit/source/layout/core/vcl.hxx new file mode 100644 index 000000000000..20cc77dc7f82 --- /dev/null +++ b/toolkit/source/layout/core/vcl.hxx @@ -0,0 +1,48 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_CORE_VCL_HXX +#define LAYOUT_CORE_VCL_HXX + +#include <vcl/dialog.hxx> + +#define DECLARE_CLOSING_DIALOG(cls)\ + class Closing##cls : public cls\ + {\ + public:\ + bool mClosing;\ + Closing##cls (Window* parent, WinBits bits);\ + virtual BOOL Close ();\ + } + +DECLARE_CLOSING_DIALOG (Dialog); +DECLARE_CLOSING_DIALOG (ModalDialog); +DECLARE_CLOSING_DIALOG (ModelessDialog); + +#undef DECLARE_CLOSING_DIALOG + +#endif /* LAYOUT_CORE_VCL_HXX */ diff --git a/toolkit/source/layout/vcl/makefile.mk b/toolkit/source/layout/vcl/makefile.mk new file mode 100644 index 000000000000..529ddc31d97e --- /dev/null +++ b/toolkit/source/layout/vcl/makefile.mk @@ -0,0 +1,52 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=../../.. +PRJNAME=toolkit +TARGET=layout-vcl +ENABLE_EXCEPTIONS=true + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/util$/makefile.pmk + +.IF "$(COMNAME)" == "gcc3" +CFLAGS+=-Wall -fno-default-inline +.ENDIF + +# --- Files -------------------------------------------------------- + +SLOFILES= \ + $(SLO)$/wrapper.obj \ + $(SLO)$/wbutton.obj \ + $(SLO)$/wcontainer.obj \ + $(SLO)$/wfield.obj + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk diff --git a/toolkit/source/layout/vcl/wbutton.cxx b/toolkit/source/layout/vcl/wbutton.cxx new file mode 100644 index 000000000000..26d4410ccf9a --- /dev/null +++ b/toolkit/source/layout/vcl/wbutton.cxx @@ -0,0 +1,681 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "wrapper.hxx" + +#include <com/sun/star/awt/PosSize.hpp> +#include <com/sun/star/awt/XActionListener.hpp> +#include <com/sun/star/awt/XButton.hpp> +#include <com/sun/star/awt/XCheckBox.hpp> +#include <com/sun/star/awt/XRadioButton.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> +#include <cppuhelper/implbase1.hxx> +#include <toolkit/awt/vclxwindow.hxx> +#include <toolkit/awt/vclxwindows.hxx> +#include <toolkit/helper/convert.hxx> +#include <vcl/button.hxx> +#include <vcl/event.hxx> +#include <vcl/msgbox.hxx> +#include <vcl/svapp.hxx> +#include <vcl/window.hxx> + +#include <list> + +#include <layout/core/helper.hxx> + +using namespace ::com::sun::star; + +using rtl::OUString; + +namespace layout +{ + +class ImageImpl +{ + public: + uno::Reference< graphic::XGraphic > mxGraphic; + ImageImpl( const char *pName ) + : mxGraphic( layoutimpl::loadGraphic( pName ) ) + { + if ( !mxGraphic.is() ) + { + DBG_ERROR1( "ERROR: failed to load image: `%s'\n", pName ); + } + } +}; + +Image::Image( const char *pName ) + : pImpl( new ImageImpl( pName ) ) +{ +} + +Image::~Image() +{ + delete pImpl; +} + +class ButtonImpl : public ControlImpl + , public ::cppu::WeakImplHelper1< awt::XActionListener > +{ + Link maClickHdl; + +public: + uno::Reference< awt::XButton > mxButton; + ButtonImpl( Context *context, const PeerHandle &peer, Window *window ) + : ControlImpl( context, peer, window ) + , mxButton( peer, uno::UNO_QUERY ) + { + /* We have default action when clicked, always listen. */ + mxButton->addActionListener( this ); + } + + ~ButtonImpl() + { + } + + virtual void Click() { /* make me pure virtual? */ }; + + Link& GetClickHdl () + { + return maClickHdl; + } + + virtual void SetClickHdl( Link const& link ) + { + maClickHdl = link; + } + + void SAL_CALL disposing( lang::EventObject const& e ) + throw (uno::RuntimeException) + { + mxButton->removeActionListener( this ); + ControlImpl::disposing (e); + mxButton.clear (); + } + + virtual void SAL_CALL actionPerformed( const awt::ActionEvent& ) + throw (uno::RuntimeException) + { + if ( !maClickHdl ) + Click(); + else + maClickHdl.Call( static_cast<Window *>( mpWindow ) ); + } + + bool SetModeImage( uno::Reference< graphic::XGraphic > xGraph ) + { + setProperty( "Graphic", uno::Any( xGraph ) ); + return true; + } +}; + +Button::~Button () +{ +} + +String Button::GetStandardText (sal_uInt16 button_type) +{ + return ::Button::GetStandardText (button_type); +} + +void Button::SetText( OUString const& rStr ) +{ + if ( !getImpl().mxButton.is() ) + return; + getImpl().mxButton->setLabel( rStr ); +} + +void Button::SetClickHdl( const Link& link ) +{ + if (&getImpl () && getImpl().mxButton.is ()) + getImpl().SetClickHdl( link ); +} + +Link& Button::GetClickHdl () +{ + return getImpl().GetClickHdl (); +} + +bool Button::SetModeImage (Image const& image) +{ + return getImpl().SetModeImage (image.getImpl().mxGraphic); +} + +bool Button::SetModeImage (::Image const& image, BmpColorMode mode) +{ + return GetButton ()->SetModeImage (image, mode); +} + +void Button::SetImageAlign( ImageAlign eAlign ) +{ + getImpl().setProperty( "ImageAlign", uno::Any( (sal_Int16) eAlign ) ); +} + +void Button::Click() +{ +} + +IMPL_GET_IMPL( Button ); +IMPL_CONSTRUCTORS( Button, Control, "button" ); +IMPL_GET_WINDOW (Button); + +class PushButtonImpl : public ButtonImpl + , public ::cppu::WeakImplHelper1< awt::XItemListener > +{ + Link maToggleHdl; +public: + PushButtonImpl( Context *context, const PeerHandle &peer, Window *window ) + : ButtonImpl( context, peer, window ) + { + } + + void SetToggleHdl( const Link& link ) + { + // XButton doesn't have an explicit event for Toggle. Anyway, it is a + // superset of the clicks: all clicks, and explicit toggles + if (!link && !!maToggleHdl) + mxButton->removeActionListener( this ); + else if (!!link && !maToggleHdl) + mxButton->addActionListener( this ); + maToggleHdl = link; + } + void SAL_CALL disposing( lang::EventObject const& e ) + throw (uno::RuntimeException) + { + ButtonImpl::disposing (e); + } + virtual void SAL_CALL actionPerformed( awt::ActionEvent const& e ) + throw (uno::RuntimeException) + { + ButtonImpl::actionPerformed( e ); + fireToggle(); + } + virtual void SAL_CALL itemStateChanged( const awt::ItemEvent& ) + throw (uno::RuntimeException) + { + maToggleHdl.Call( static_cast<Window *>( mpWindow ) ); + } + void fireToggle() + { + maToggleHdl.Call( static_cast<Window *>( mpWindow ) ); + } + +}; + +PushButton::~PushButton () +{ + SetToggleHdl (Link ()); +} + +void PushButton::Check( bool bCheck ) +{ + getImpl().setProperty( "State", uno::Any( (sal_Int16) !!bCheck ) ); + // XButton doesn't have explicit toggle event + getImpl().fireToggle(); +} + +bool PushButton::IsChecked() const +{ + return !!( getImpl().getProperty( "State" ).get< sal_Int16 >() ); +} + +void PushButton::Toggle() +{ + Check( true ); +} + +void PushButton::SetToggleHdl( const Link& link ) +{ + if (&getImpl () && getImpl().mxButton.is ()) + getImpl().SetToggleHdl( link ); +} + +IMPL_GET_IMPL( PushButton ); +IMPL_CONSTRUCTORS( PushButton, Button, "pushbutton" ); +IMPL_GET_WINDOW (PushButton); + +class RadioButtonImpl : public ButtonImpl + , public ::cppu::WeakImplHelper1< awt::XItemListener > +{ + Link maToggleHdl; +public: + uno::Reference< awt::XRadioButton > mxRadioButton; + RadioButtonImpl( Context *context, const PeerHandle &peer, Window *window ) + : ButtonImpl( context, peer, window ) + , mxRadioButton( peer, uno::UNO_QUERY ) + { + } + + void Check( bool bCheck ) + { + if ( !mxRadioButton.is() ) + return; + +#if 1 + // Have setState fire item event for + // RadioGroups::RadioGroup::itemStateChanged () + ::RadioButton *r = static_cast<RadioButton*>(mpWindow)->GetRadioButton (); + bool state = r->IsRadioCheckEnabled (); + r->EnableRadioCheck(); + mxRadioButton->setState( !!bCheck ); + r->EnableRadioCheck (state); +#else + mxRadioButton->setState( !!bCheck ); +#endif + fireToggle(); + } + + bool IsChecked() + { + if ( !mxRadioButton.is() ) + return false; + return mxRadioButton->getState(); + } + + void SetToggleHdl( const Link& link ) + { + if (!link && !!maToggleHdl) + mxRadioButton->removeItemListener( this ); + else if (!!link && !maToggleHdl) + mxRadioButton->addItemListener( this ); + maToggleHdl = link; + } + + inline void fireToggle() + { + maToggleHdl.Call( static_cast<Window *>( mpWindow ) ); + } + + virtual void SetClickHdl( const Link& link ) + { + // Keep RadioGroups::RadioGroup's actionListener at HEAD + // of list. This way, it can handle RadioGroup's button + // states before all other callbacks and make sure the + // client code has the right state. + + // IWBN to add an XRadioButton2 and layout::VCLXRadioButton + // with {get,set}RadioGroup() (and a "radiogroup" property + // even) and handle the grouping here in RadioButtonImpl. + uno::Reference< uno::XInterface > x = static_cast<VCLXRadioButton*> (mpWindow->GetVCLXWindow ())->getFirstActionListener (); + uno::Reference< awt::XActionListener > a = uno::Reference< awt::XActionListener> (x ,uno::UNO_QUERY ); + mxButton->removeActionListener (a); + ButtonImpl::SetClickHdl (link); + mxButton->addActionListener (a); + } + + void SAL_CALL disposing( lang::EventObject const& e ) + throw (uno::RuntimeException) + { + ButtonImpl::disposing (e); + } + + virtual void SAL_CALL itemStateChanged( const awt::ItemEvent& ) + throw (uno::RuntimeException) + { + maToggleHdl.Call( static_cast<Window *>( mpWindow ) ); + } +}; + +RadioButton::~RadioButton () +{ + SetToggleHdl (Link ()); +} + +void RadioButton::Check( bool bCheck ) +{ + getImpl().Check( bCheck ); +} + +bool RadioButton::IsChecked() const +{ + return getImpl().IsChecked(); +} + +void RadioButton::SetToggleHdl( const Link& link ) +{ + if (&getImpl () && getImpl().mxRadioButton.is ()) + getImpl().SetToggleHdl( link ); +} + +IMPL_GET_IMPL( RadioButton ); +IMPL_GET_WINDOW( RadioButton ); +IMPL_GET_VCLXWINDOW( RadioButton ); +IMPL_CONSTRUCTORS( RadioButton, Button, "radiobutton" ); + +class CheckBoxImpl : public ButtonImpl + , public ::cppu::WeakImplHelper1< awt::XItemListener > +{ + Link maToggleHdl; + public: + uno::Reference< awt::XCheckBox > mxCheckBox; + CheckBoxImpl( Context *context, const PeerHandle &peer, Window *window ) + : ButtonImpl( context, peer, window ) + , mxCheckBox( peer, uno::UNO_QUERY ) + { + } + + void SetToggleHdl( const Link& link ) + { + if (!link && !!maToggleHdl) + mxCheckBox->removeItemListener( this ); + else if (!!link && !maToggleHdl) + mxCheckBox->addItemListener( this ); + maToggleHdl = link; + } + void SAL_CALL disposing( lang::EventObject const& e ) + throw (uno::RuntimeException) + { + ButtonImpl::disposing (e); + } + virtual void SAL_CALL itemStateChanged( const awt::ItemEvent& ) + throw (uno::RuntimeException) + { + maToggleHdl.Call( static_cast<Window *>( mpWindow ) ); + } +}; + +CheckBox::~CheckBox () +{ + SetToggleHdl (Link ()); +} + +void CheckBox::Check( bool bCheck ) +{ + if ( !getImpl().mxCheckBox.is() ) + return; + getImpl().mxCheckBox->setState( !!bCheck ); +} + +bool CheckBox::IsChecked() const +{ + if ( !getImpl().mxCheckBox.is() ) + return false; + return getImpl().mxCheckBox->getState() != 0; +} + +void CheckBox::SetToggleHdl( const Link& link ) +{ + if (&getImpl () && getImpl().mxCheckBox.is ()) + getImpl().SetToggleHdl( link ); +} + +IMPL_GET_IMPL( CheckBox ); +IMPL_CONSTRUCTORS( CheckBox, Button, "checkbox" ); + +#define BUTTON_IMPL(t, parent, response) \ + class t##Impl : public parent##Impl \ + { \ + public: \ + t##Impl( Context *context, PeerHandle const& peer, Window *window ) \ + : parent##Impl( context, peer, window ) \ + { \ + } \ + void Click() \ + { \ + if (Dialog *d = static_cast<Dialog *> (mpCtx)) \ + d->EndDialog( response ); \ + } \ + } + +/* Common button types currently unavailable in OOo: */ +/* mpReset */ +/* mpApply */ +/* mpAction */ +#define RET_RESET 6 +#define RET_APPLY 7 +#define BUTTONID_RESET RET_RESET +#define BUTTONID_APPLY RET_APPLY + +BUTTON_IMPL( OKButton, PushButton, BUTTONID_OK ); +BUTTON_IMPL( CancelButton, PushButton, BUTTONID_CANCEL ); +BUTTON_IMPL( YesButton, PushButton, BUTTONID_YES ); +BUTTON_IMPL( NoButton, PushButton, BUTTONID_NO ); +BUTTON_IMPL( RetryButton, PushButton, BUTTONID_RETRY ); +BUTTON_IMPL( IgnoreButton, PushButton, BUTTONID_IGNORE ); +BUTTON_IMPL( ResetButton, PushButton, BUTTONID_RESET ); +BUTTON_IMPL( ApplyButton, PushButton, BUTTONID_APPLY ); /* Deprecated? */ +BUTTON_IMPL( HelpButton, PushButton, BUTTONID_HELP ); + +IMPL_CONSTRUCTORS( OKButton, PushButton, "okbutton" ); +IMPL_CONSTRUCTORS( CancelButton, PushButton, "cancelbutton" ); +IMPL_CONSTRUCTORS( YesButton, PushButton, "yesbutton" ); +IMPL_CONSTRUCTORS( NoButton, PushButton, "nobutton" ); +IMPL_CONSTRUCTORS( RetryButton, PushButton, "retrybutton" ); +IMPL_CONSTRUCTORS( IgnoreButton, PushButton, "ignorebutton" ); +IMPL_CONSTRUCTORS( ResetButton, PushButton, "resetbutton" ); +IMPL_CONSTRUCTORS( ApplyButton, PushButton, "applybutton" ); /* Deprecated? */ +IMPL_CONSTRUCTORS( HelpButton, PushButton, "helpbutton" ); + +IMPL_IMPL (ImageButton, PushButton) + + +IMPL_CONSTRUCTORS( ImageButton, PushButton, "imagebutton" ); + +class AdvancedButtonImpl : public PushButtonImpl +{ +protected: + bool bAdvancedMode; + std::list< Window*> maAdvanced; + std::list< Window*> maSimple; + +public: + rtl::OUString mAdvancedLabel; + rtl::OUString mSimpleLabel; + +protected: + Window* Remove( std::list< Window*> lst, Window* w ) + { + for ( std::list< Window*>::iterator it = maAdvanced.begin(); + it != maAdvanced.end(); it++ ) + if ( *it == w ) + { + lst.erase( it ); + return *it; + } + return 0; + } + +public: + AdvancedButtonImpl( Context *context, PeerHandle const& peer, Window *window ) + : PushButtonImpl( context, peer, window ) + , bAdvancedMode( false ) + // TODO: i18n + // Button::GetStandardText( BUTTON_ADVANCED ); + // Button::GetStandardText( BUTTON_SIMPLE ); + , mAdvancedLabel( rtl::OUString::createFromAscii( "Advanced..." ) ) + , mSimpleLabel( rtl::OUString::createFromAscii( "Simple..." ) ) + { + } + void Click() + { + bAdvancedMode = !bAdvancedMode; + if ( bAdvancedMode ) + advancedMode(); + else + simpleMode(); + } + void setAlign () + { + ::PushButton *b = static_cast<PushButton*> (mpWindow)->GetPushButton (); + b->SetSymbolAlign (SYMBOLALIGN_RIGHT); + b->SetSmallSymbol (); + //mpWindow->SetStyle (mpWindow->GetStyle() | WB_CENTER); + } + void advancedMode() + { + ::PushButton *b = static_cast<PushButton*> (mpWindow)->GetPushButton (); + b->SetSymbol (SYMBOL_PAGEUP); + setAlign (); + if (mSimpleLabel.getLength ()) + b->SetText (mSimpleLabel); + for ( std::list< Window*>::iterator it = maAdvanced.begin(); + it != maAdvanced.end(); it++ ) + ( *it )->Show(); + for ( std::list< Window*>::iterator it = maSimple.begin(); + it != maSimple.end(); it++ ) + ( *it )->Hide(); + + redraw (); + } + void simpleMode() + { + //mxButton->setLabel( mSimpleLabel ); + ::PushButton *b = static_cast<PushButton*> (mpWindow)->GetPushButton (); + b->SetSymbol (SYMBOL_PAGEDOWN); + if (mAdvancedLabel.getLength ()) + b->SetText (mAdvancedLabel); + setAlign (); + for ( std::list< Window*>::iterator it = maAdvanced.begin(); + it != maAdvanced.end(); it++ ) + ( *it )->Hide(); + for ( std::list< Window*>::iterator it = maSimple.begin(); + it != maSimple.end(); it++ ) + ( *it )->Show(); + + redraw (true); + } + void AddAdvanced( Window* w ) + { + maAdvanced.push_back( w ); + if ( !bAdvancedMode ) + w->Hide(); + } + void AddSimple( Window* w ) + { + maSimple.push_back( w ); + if ( bAdvancedMode ) + w->Hide(); + } + void RemoveAdvanced( Window* w ) + { + Remove( maAdvanced, w ); + } + void RemoveSimple( Window* w ) + { + Remove( maSimple, w ); + } +}; + +void AdvancedButton::AddAdvanced( Window* w ) +{ + getImpl().AddAdvanced( w ); +} + +void AdvancedButton::AddSimple( Window* w ) +{ + getImpl().AddSimple( w ); +} + +void AdvancedButton::RemoveAdvanced( Window* w ) +{ + getImpl().RemoveAdvanced( w ); +} + +void AdvancedButton::RemoveSimple( Window* w ) +{ + getImpl().RemoveSimple( w ); +} + +void AdvancedButton::SetAdvancedText (rtl::OUString const& text) +{ + if (text.getLength ()) + getImpl ().mAdvancedLabel = text; +} + +void AdvancedButton::SetSimpleText (rtl::OUString const& text) +{ + if (text.getLength ()) + getImpl ().mSimpleLabel = text; +} + +rtl::OUString AdvancedButton::GetAdvancedText () const +{ + return getImpl ().mAdvancedLabel; +} + +rtl::OUString AdvancedButton::GetSimpleText () const +{ + return getImpl ().mSimpleLabel; +} + +void AdvancedButton::SetDelta (int) +{ +} + +IMPL_CONSTRUCTORS_BODY( AdvancedButton, PushButton, "advancedbutton", getImpl().simpleMode () ); +IMPL_GET_IMPL( AdvancedButton ); + + +class MoreButtonImpl : public AdvancedButtonImpl +{ +public: + MoreButtonImpl( Context *context, PeerHandle const& peer, Window *window ) + : AdvancedButtonImpl( context, peer, window) + { + mSimpleLabel = Button::GetStandardText( BUTTON_MORE ); + mAdvancedLabel = Button::GetStandardText( BUTTON_LESS ); + } + void AddWindow( Window* w ) { AddAdvanced( w ); } + void RemoveWindow( Window* w ) { RemoveAdvanced( w ); } +}; + +// TODO +//BUTTON_IMPL( MoreButton, PushButton, 0 ); +IMPL_CONSTRUCTORS_BODY( MoreButton, AdvancedButton, "morebutton", getImpl().simpleMode () ); +IMPL_GET_IMPL( MoreButton ); + +void MoreButton::AddWindow( Window* w ) +{ + getImpl().AddWindow( w ); +} + +void MoreButton::RemoveWindow( Window* w ) +{ + getImpl().RemoveWindow( w ); +} + +void MoreButton::SetMoreText (rtl::OUString const& text) +{ + SetAdvancedText (text); +} + +void MoreButton::SetLessText (rtl::OUString const& text) +{ + SetSimpleText (text); +} + +rtl::OUString MoreButton::GetMoreText () const +{ + return GetAdvancedText (); +} + +rtl::OUString MoreButton::GetLessText () const +{ + return GetSimpleText (); +} + +} // namespace layout diff --git a/toolkit/source/layout/vcl/wcontainer.cxx b/toolkit/source/layout/vcl/wcontainer.cxx new file mode 100644 index 000000000000..712aae19934d --- /dev/null +++ b/toolkit/source/layout/vcl/wcontainer.cxx @@ -0,0 +1,266 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "wrapper.hxx" + +#include <com/sun/star/awt/XLayoutRoot.hpp> +#include <com/sun/star/awt/XLayoutContainer.hpp> +#include <comphelper/processfactory.hxx> +#include <layout/core/helper.hxx> +#include <tools/debug.hxx> + +using namespace ::com::sun::star; + +namespace layout +{ + +Container::Container( Context const* context, char const* pId ) + : mxContainer( context->GetPeerHandle( pId ), uno::UNO_QUERY ) +{ + if ( !mxContainer.is() ) + { + DBG_ERROR1( "Error: failed to associate container with '%s'", pId ); + } +} + +Container::Container( rtl::OUString const& rName, sal_Int32 nBorder ) +{ + mxContainer = layoutimpl::WidgetFactory::createContainer( rName ); + + uno::Reference< beans::XPropertySet > xProps( mxContainer, uno::UNO_QUERY_THROW ); + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Border" ) ), + uno::Any( nBorder ) ); +} + +void Container::Add( Window *pChild ) +{ + if ( pChild ) + { + uno::Reference< awt::XLayoutConstrains > xChild( pChild->GetPeer(), uno::UNO_QUERY ); + mxContainer->addChild( xChild ); + } +} + +void Container::Add( Container *pChild ) +{ + if ( pChild ) + { + uno::Reference< awt::XLayoutConstrains > xChild( pChild->getImpl(), uno::UNO_QUERY ); + mxContainer->addChild( xChild ); + } +} + +void Container::Remove( Window *pChild ) +{ + if ( pChild ) + { + uno::Reference< awt::XLayoutConstrains > xChild( pChild->GetPeer(), uno::UNO_QUERY ); + mxContainer->removeChild( xChild ); + } +} + +void Container::Remove( Container *pChild ) +{ + if ( pChild ) + { + uno::Reference< awt::XLayoutConstrains > xChild( pChild->getImpl(), uno::UNO_QUERY ); + mxContainer->removeChild( xChild ); + } +} + +void Container::Clear() +{ + css::uno::Sequence< css::uno::Reference < css::awt::XLayoutConstrains > > children; + children = mxContainer->getChildren(); + for (int i = 0; i < children.getLength(); i++) + mxContainer->removeChild( children[i] ); +} + +void Container::ShowAll( bool bShow ) +{ + struct inner + { + static void setChildrenVisible( uno::Reference < awt::XLayoutContainer > xCont, + bool bVisible ) /* auxiliary */ + { + if ( xCont.is() ) + { + uno::Sequence< uno::Reference < awt::XLayoutConstrains > > aChildren; + aChildren = xCont->getChildren(); + for (int i = 0; i < aChildren.getLength(); i++) + { + uno::Reference < awt::XLayoutConstrains > xChild( aChildren[ i ] ); + + uno::Reference< awt::XWindow > xWin( xChild, uno::UNO_QUERY); + if ( xWin.is() ) + xWin->setVisible( bVisible ); + + uno::Reference < awt::XLayoutContainer > xChildCont( + xChild, uno::UNO_QUERY ); + setChildrenVisible( xChildCont, bVisible ); + } + } + } + }; + + inner::setChildrenVisible( mxContainer, bShow ); +} + +void Container::Show() +{ + ShowAll( true ); +} + +void Container::Hide() +{ + ShowAll( false ); +} + +Table::Table( sal_Int32 nBorder, sal_Int32 nColumns ) + : Container( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "table" ) ), nBorder ) +{ + uno::Reference< beans::XPropertySet > xProps( mxContainer, uno::UNO_QUERY_THROW ); + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Columns" ) ), + uno::Any( nColumns ) ); +} + +void Table::Add( Window *window, bool bXExpand, bool bYExpand, + sal_Int32 nXSpan, sal_Int32 nYSpan ) +{ + if ( !window ) + return; + WindowImpl &rImpl = window->getImpl(); + uno::Reference< awt::XLayoutConstrains > xChild( rImpl.mxWindow, + uno::UNO_QUERY ); + mxContainer->addChild( xChild ); + setProps( xChild, bXExpand, bYExpand, nXSpan, nYSpan ); +} + +void Table::Add( Container *pContainer, bool bXExpand, bool bYExpand, + sal_Int32 nXSpan, sal_Int32 nYSpan ) +{ + if ( !pContainer ) + return; + uno::Reference< awt::XLayoutConstrains > xChild( pContainer->getImpl(), + uno::UNO_QUERY ); + mxContainer->addChild( xChild ); + setProps( xChild, bXExpand, bYExpand, nXSpan, nYSpan ); +} + +void Table::setProps( uno::Reference< awt::XLayoutConstrains > xChild, + bool bXExpand, bool bYExpand, sal_Int32 nXSpan, sal_Int32 nYSpan ) +{ + uno::Reference< beans::XPropertySet > xProps + ( mxContainer->getChildProperties( xChild ), uno::UNO_QUERY_THROW ); + xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "XExpand" ) ), + uno::Any( bXExpand ) ); + xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "YExpand" ) ), + uno::Any( bYExpand ) ); + xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "ColSpan" ) ), + uno::Any( nXSpan ) ); + xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "RowSpan" ) ), + uno::Any( nYSpan ) ); +} + +Box::Box( rtl::OUString const& rName, sal_Int32 nBorder, bool bHomogeneous ) + : Container( rName, nBorder ) +{ + uno::Reference< beans::XPropertySet > xProps( mxContainer, uno::UNO_QUERY_THROW ); + xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "Homogeneous" ) ), + uno::Any( bHomogeneous ) ); +} + +void Box::Add( Window *window, bool bExpand, bool bFill, sal_Int32 nPadding) +{ + if ( !window ) + return; + WindowImpl &rImpl = window->getImpl(); + uno::Reference< awt::XLayoutConstrains > xChild( rImpl.mxWindow, + uno::UNO_QUERY ); + + mxContainer->addChild( xChild ); + setProps( xChild, bExpand, bFill, nPadding ); +} + +void Box::Add( Container *pContainer, bool bExpand, bool bFill, sal_Int32 nPadding) +{ + if ( !pContainer ) + return; + + uno::Reference< awt::XLayoutConstrains > xChild( pContainer->getImpl(), + uno::UNO_QUERY ); + mxContainer->addChild( xChild ); + setProps( xChild, bExpand, bFill, nPadding ); +} + +void Box::setProps( uno::Reference< awt::XLayoutConstrains > xChild, + bool bExpand, bool bFill, sal_Int32 nPadding ) +{ + uno::Reference< beans::XPropertySet > xProps + ( mxContainer->getChildProperties( xChild ), uno::UNO_QUERY_THROW ); + + xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "Expand" ) ), + uno::Any( bExpand ) ); + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Fill" ) ), + uno::Any( bFill ) ); + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Padding" ) ), + uno::Any( nPadding ) ); +} + +Table::Table( Context const* context, char const* pId ) + : Container( context, pId ) +{ +} + +Box::Box( Context const* context, char const* pId ) + : Container( context, pId ) +{ +} + +HBox::HBox( sal_Int32 nBorder, bool bHomogeneous ) + : Box( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "hbox" ) ), + nBorder, bHomogeneous ) +{ +} + +HBox::HBox( Context const* context, char const* pId ) + : Box( context, pId ) +{ +} + +VBox::VBox( sal_Int32 nBorder, bool bHomogeneous ) + : Box( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "vbox" ) ), + nBorder, bHomogeneous ) +{ +} + +VBox::VBox( Context const* context, char const* pId ) + : Box( context, pId ) +{ +} + +} // namespace layout diff --git a/toolkit/source/layout/vcl/wfield.cxx b/toolkit/source/layout/vcl/wfield.cxx new file mode 100644 index 000000000000..fb26d04a478b --- /dev/null +++ b/toolkit/source/layout/vcl/wfield.cxx @@ -0,0 +1,792 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "wrapper.hxx" + +#include <comphelper/processfactory.hxx> +#include <com/sun/star/awt/XMetricField.hpp> +#include <com/sun/star/awt/XNumericField.hpp> +#include <com/sun/star/awt/XTextComponent.hpp> +#include <com/sun/star/awt/XListBox.hpp> +#include <com/sun/star/awt/XComboBox.hpp> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/awt/XActionListener.hpp> +#include <com/sun/star/awt/XItemListener.hpp> +#include <com/sun/star/awt/XMouseListener.hpp> +#include <vcl/combobox.hxx> +#include <vcl/lstbox.hxx> + +#include <toolkit/awt/vclxwindows.hxx> + +using namespace ::com::sun::star; +using rtl::OUString; + +#define LAYOUT_API_CALLS_HANDLER 0 + +namespace layout +{ + +class EditImpl : public ControlImpl + , public ::cppu::WeakImplHelper1< awt::XTextListener > +{ +public: + Link maModifyHdl; + + uno::Reference< awt::XTextComponent > mxEdit; + EditImpl( Context *context, const PeerHandle &peer, Window *window ) + : ControlImpl( context, peer, window ) + , mxEdit( peer, uno::UNO_QUERY ) + { + } + + ~EditImpl (); + + virtual void SAL_CALL disposing( lang::EventObject const& e ) + throw (uno::RuntimeException); + + virtual void SetModifyHdl( Link const& link ); + + void SAL_CALL textChanged( const awt::TextEvent& /* rEvent */ ) + throw (uno::RuntimeException) + { + maModifyHdl.Call( mpWindow ); + } +}; + +EditImpl::~EditImpl () +{ +} + +void SAL_CALL EditImpl::disposing( lang::EventObject const& e ) + throw (uno::RuntimeException) +{ + ControlImpl::disposing (e); + mxEdit.clear (); +} + +void EditImpl::SetModifyHdl( Link const& link ) +{ + if (!link && !!maModifyHdl) + mxEdit->removeTextListener( this ); + else if (!!link && !maModifyHdl) + mxEdit->addTextListener( this ); + maModifyHdl = link; +} + +Edit::~Edit () +{ + SetModifyHdl (Link ()); +} + +void Edit::SetSelection( Selection const& rSelection ) +{ +#if LAYOUT_API_CALLS_HANDLER + if ( !getImpl().mxEdit.is() ) + getImpl().mxEdit->setSelection( awt::Selection( rSelection.Min(), rSelection.Max() ) ); +#else /* !LAYOUT_API_CALLS_HANDLER */ + GetEdit ()->SetSelection (rSelection); +#endif /* !LAYOUT_API_CALLS_HANDLER */ +} + +void Edit::SetText( OUString const& rStr ) +{ +#if LAYOUT_API_CALLS_HANDLER + if ( getImpl().mxEdit.is() ) + /// this calls handlers; endless loop in numfmt.cxx + getImpl().mxEdit->setText( rStr ); +#else /* !LAYOUT_API_CALLS_HANDLER */ + GetEdit ()->SetText (rStr); +#endif /* !LAYOUT_API_CALLS_HANDLER */ +} + +String Edit::GetText() const +{ + if ( !getImpl().mxEdit.is() ) + return getImpl().mxEdit->getText(); + return OUString(); +} + +void Edit::SetModifyHdl( const Link& link ) +{ + if (&getImpl () && getImpl().mxEdit.is ()) + getImpl().SetModifyHdl( link ); +} + +IMPL_CONSTRUCTORS( Edit, Control, "edit" ); +IMPL_GET_IMPL( Edit ); +IMPL_GET_WINDOW (Edit); + +class MultiLineEditImpl : public EditImpl +{ +public: + MultiLineEditImpl( Context *context, const PeerHandle &peer, Window *window ) + : EditImpl( context, peer, window ) + { + } +}; + +IMPL_CONSTRUCTORS( MultiLineEdit, Edit, "multilineedit" ); +IMPL_GET_IMPL( MultiLineEdit ); + +class SpinFieldImpl : public EditImpl +{ + public: + SpinFieldImpl( Context *context, const PeerHandle &peer, Window *window ) + : EditImpl( context, peer, window ) + { + } +}; + +IMPL_CONSTRUCTORS( SpinField, Edit, "spinfield" ); + +class NumericFieldImpl : public SpinFieldImpl +{ + public: + NumericFieldImpl( Context *context, const PeerHandle &peer, Window *window ) + : SpinFieldImpl( context, peer, window ) + { + } +}; + +class MetricFieldImpl : public SpinFieldImpl +{ + public: + MetricFieldImpl( Context *context, const PeerHandle &peer, Window *window ) + : SpinFieldImpl( context, peer, window ) + { + } +}; + +IMPL_GET_IMPL( SpinField ); +IMPL_GET_IMPL( NumericField ); +IMPL_GET_IMPL( MetricField ); + +class FormatterBaseImpl +{ + protected: + PeerHandle mpeer; + public: + explicit FormatterBaseImpl( const PeerHandle &peer ) + : mpeer( peer ) + { + }; +}; + +FormatterBase::FormatterBase( FormatterBaseImpl *pFormatImpl ) + : mpFormatImpl( pFormatImpl ) +{ +} + +class NumericFormatterImpl : public FormatterBaseImpl +{ + public: + uno::Reference< awt::XNumericField > mxField; + explicit NumericFormatterImpl( const PeerHandle &peer ) + : FormatterBaseImpl( peer ) + , mxField( peer, uno::UNO_QUERY ) + { + } + + // FIXME: burn that CPU ! cut/paste from vclxwindows.cxx + double valueToDouble( sal_Int64 nValue ) + { + sal_Int16 nDigits = mxField->getDecimalDigits(); + double n = (double)nValue; + for ( sal_uInt16 d = 0; d < nDigits; d++ ) + n /= 10; + return n; + } // FIXME: burn that CPU ! cut/paste from vclxwindows.cxx + sal_Int64 doubleToValue( double nValue ) + { + sal_Int16 nDigits = mxField->getDecimalDigits(); + double n = nValue; + for ( sal_uInt16 d = 0; d < nDigits; d++ ) + n *= 10; + return (sal_Int64) n; + } +}; + +class MetricFormatterImpl : public FormatterBaseImpl +{ + public: + uno::Reference< awt::XMetricField > mxField; + explicit MetricFormatterImpl( const PeerHandle &peer ) + : FormatterBaseImpl( peer ) + , mxField( peer, uno::UNO_QUERY ) + { + } +}; + +NumericFormatter::NumericFormatter( FormatterBaseImpl *pImpl ) + : FormatterBase( pImpl ) +{ +} + +NumericFormatterImpl& NumericFormatter::getFormatImpl() const +{ + return *( static_cast<NumericFormatterImpl *>( mpFormatImpl ) ); +} + +#define SET_IMPL(vclmethod, idlmethod) \ + void NumericFormatter::vclmethod( sal_Int64 nValue ) \ + { \ + if ( !getFormatImpl().mxField.is() ) \ + return; \ + getFormatImpl().mxField->idlmethod( getFormatImpl().valueToDouble( nValue ) ); \ + } + +SET_IMPL( SetMin, setMin ) +SET_IMPL( SetMax, setMax ) +SET_IMPL( SetLast, setLast ) +SET_IMPL( SetFirst, setFirst ) +SET_IMPL( SetValue, setValue ) +SET_IMPL( SetSpinSize, setSpinSize ) + +sal_Int64 NumericFormatter::GetValue() const +{ + if ( !getFormatImpl().mxField.is() ) + return 0; + return getFormatImpl().doubleToValue( getFormatImpl().mxField->getValue() ); +} + +#undef SET_IMPL + +IMPL_CONSTRUCTORS_2( NumericField, SpinField, NumericFormatter, "numericfield" ); + +MetricFormatter::MetricFormatter( FormatterBaseImpl *pImpl ) + : FormatterBase( pImpl ) +{ +} +MetricFormatterImpl& MetricFormatter::getFormatImpl() const +{ return *( static_cast<MetricFormatterImpl *>( mpFormatImpl ) ); } + +#define MetricUnitVclToUno(a) ((sal_uInt16)(a)) + +#define SET_IMPL(vclmethod, idlmethod) \ + void MetricFormatter::vclmethod( sal_Int64 nValue, FieldUnit nUnit ) \ + { \ + if ( !getFormatImpl().mxField.is() ) \ + return; \ + getFormatImpl().mxField->idlmethod( nValue, MetricUnitVclToUno( nUnit ) ); \ + } + +SET_IMPL( SetMin, setMin ) +SET_IMPL( SetMax, setMax ) +SET_IMPL( SetLast, setLast ) +SET_IMPL( SetFirst, setFirst ) +SET_IMPL( SetValue, setValue ) + +#undef SET_IMPL + +void MetricFormatter::SetSpinSize( sal_Int64 nValue ) +{ + if ( !getFormatImpl().mxField.is() ) + return; + getFormatImpl().mxField->setSpinSize( nValue ); +} + +sal_Int64 MetricFormatter::GetValue( FieldUnit nUnit ) const +{ + if ( !getFormatImpl().mxField.is() ) + return 0; + return getFormatImpl().mxField->getValue( MetricUnitVclToUno( nUnit ) ); +} + +IMPL_CONSTRUCTORS_2( MetricField, SpinField, MetricFormatter, "metricfield" ); + +class ComboBoxImpl : public EditImpl + , public ::cppu::WeakImplHelper1< awt::XActionListener > + , public ::cppu::WeakImplHelper1< awt::XItemListener > +{ +public: + uno::Reference< awt::XComboBox > mxComboBox; + + Link maClickHdl; + Link maSelectHdl; + + Window *parent; + + ComboBoxImpl( Context *context, const PeerHandle &peer, Window *window ) + : EditImpl( context, peer, window ) + , mxComboBox( peer, uno::UNO_QUERY ) + { + } + + ~ComboBoxImpl (); + + sal_uInt16 InsertEntry( OUString const& rStr, sal_uInt16 nPos ) + { + if ( nPos == COMBOBOX_APPEND ) + nPos = GetEntryCount(); + mxComboBox->addItem( rtl::OUString( rStr ), nPos ); + return nPos; + } + + void RemoveEntry( sal_uInt16 nPos ) + { + mxComboBox->removeItems( nPos, 1 ); + } + + sal_uInt16 GetEntryPos( String const& rStr ) const + { + uno::Sequence< rtl::OUString> aItems( mxComboBox->getItems() ); + rtl::OUString rKey( rStr ); + sal_uInt16 n = sal::static_int_cast< sal_uInt16 >(aItems.getLength()); + for (sal_uInt16 i = 0; i < n; i++) + { + if ( aItems[ i ] == rKey ) + return i; + } + return COMBOBOX_ENTRY_NOTFOUND; + } + + OUString GetEntry( sal_uInt16 nPos ) const + { + return OUString( mxComboBox->getItem( nPos ) ); + } + + sal_uInt16 GetEntryCount() const + { + return mxComboBox->getItemCount(); + } + + void SetClickHdl( Link const& link ) + { + if (!link && !!maClickHdl) + mxComboBox->removeActionListener( this ); + else if (!!link && !maClickHdl) + mxComboBox->addActionListener( this ); + maClickHdl = link; + } + + void SetSelectHdl( Link const& link ) + { + if (!link && !!maSelectHdl) + mxComboBox->removeItemListener( this ); + else if (!!link && !maSelectHdl) + mxComboBox->addItemListener( this ); + maSelectHdl = link; + } + + void SAL_CALL disposing( lang::EventObject const& e ) + throw (uno::RuntimeException); + + void SAL_CALL actionPerformed (const awt::ActionEvent&) + throw (uno::RuntimeException) + { + ComboBox* pComboBox = static_cast<ComboBox*>( mpWindow ); + if ( !pComboBox ) + return; + maClickHdl.Call( pComboBox ); + } + + void SAL_CALL itemStateChanged( awt::ItemEvent const&) + throw (uno::RuntimeException) + { + ComboBox* pComboBox = static_cast<ComboBox*>( mpWindow ); + if ( !pComboBox ) + return; + maSelectHdl.Call( pComboBox ); + } +}; + +ComboBox::~ComboBox () +{ +#ifndef __SUNPRO_CC + OSL_TRACE ("%s: deleting ComboBox for window: %p", __FUNCTION__, GetWindow ()); +#endif +} + +ComboBoxImpl::~ComboBoxImpl () +{ +#ifndef __SUNPRO_CC + OSL_TRACE ("%s: deleting ComboBoxImpl for window: %p", __FUNCTION__, mpWindow ? mpWindow->GetWindow () : 0); + OSL_TRACE ("%s: deleting ComboBoxImpl for listener: %p", __FUNCTION__, static_cast<XFocusListener*> (this)); +#endif +} + +void ComboBoxImpl::disposing( lang::EventObject const& e ) + throw (uno::RuntimeException) +{ + EditImpl::disposing (e); + mxComboBox.clear (); +} + +sal_uInt16 ComboBox::InsertEntry( String const& rStr, sal_uInt16 nPos ) +{ + return getImpl().InsertEntry( rStr, nPos ); +} + +void ComboBox::RemoveEntry( String const& rStr ) +{ + getImpl().RemoveEntry( GetEntryPos( rStr ) ); +} + +void ComboBox::RemoveEntry( sal_uInt16 nPos ) +{ + getImpl().RemoveEntry( nPos ); +} + +void ComboBox::Clear() +{ + uno::Sequence< rtl::OUString> aNoItems; + getImpl().setProperty( "StringItemList", uno::Any( aNoItems ) ); +} + +sal_uInt16 ComboBox::GetEntryPos( String const& rStr ) const +{ + return getImpl().GetEntryPos( rStr ); +} + +String ComboBox::GetEntry( sal_uInt16 nPos ) const +{ + rtl::OUString rItem = getImpl().mxComboBox->getItem( nPos ); + return OUString( rItem ); +} + +sal_uInt16 ComboBox::GetEntryCount() const +{ + return getImpl().GetEntryCount(); +} + +void ComboBox::SetClickHdl( const Link& link ) +{ + if (&getImpl () && getImpl().mxComboBox.is ()) + getImpl().SetClickHdl( link ); +} + +void ComboBox::SetSelectHdl( const Link& link ) +{ + if (&getImpl () && getImpl().mxComboBox.is ()) + getImpl().SetSelectHdl( link ); +} + +void ComboBox::EnableAutocomplete (bool enable, bool matchCase) +{ + GetComboBox ()->EnableAutocomplete (enable, matchCase); +} + +IMPL_CONSTRUCTORS_BODY( ComboBox, Edit, "combobox", getImpl().parent = parent; ); +IMPL_GET_WINDOW (ComboBox); +/// IMPL_GET_IMPL( ComboBox ); + +static ComboBoxImpl* null_combobox_impl = 0; + +ComboBoxImpl &ComboBox::getImpl () const +{ + if (ComboBoxImpl* c = static_cast<ComboBoxImpl *>(mpImpl)) + return *c; + return *null_combobox_impl; +} + +class ListBoxImpl : public ControlImpl + , public ::cppu::WeakImplHelper1< awt::XActionListener > + , public ::cppu::WeakImplHelper1< awt::XItemListener > + , public ::cppu::WeakImplHelper1< awt::XMouseListener > +{ + Link maClickHdl; + Link maSelectHdl; + Link maDoubleClickHdl; + +public: + uno::Reference< awt::XListBox > mxListBox; + ListBoxImpl( Context *context, const PeerHandle &peer, Window *window ) + : ControlImpl( context, peer, window ) + , mxListBox( peer, uno::UNO_QUERY ) + { + SelectEntryPos (0, true); + } + + sal_uInt16 InsertEntry (String const& rStr, sal_uInt16 nPos) + { + if ( nPos == LISTBOX_APPEND ) + nPos = mxListBox->getItemCount(); + mxListBox->addItem( rtl::OUString( rStr ), nPos ); + return nPos; + } + + void RemoveEntry( sal_uInt16 nPos ) + { + mxListBox->removeItems( nPos, 1 ); + } + + sal_uInt16 RemoveEntry( String const& rStr, sal_uInt16 nPos) + { + if ( nPos == LISTBOX_APPEND ) + nPos = mxListBox->getItemCount(); + mxListBox->addItem( rtl::OUString( rStr ), nPos ); + return nPos; + } + + sal_uInt16 GetEntryPos( String const& rStr ) const + { + uno::Sequence< rtl::OUString> aItems( mxListBox->getItems() ); + rtl::OUString rKey( rStr ); + sal_uInt16 n = sal::static_int_cast< sal_uInt16 >(aItems.getLength()); + for (sal_uInt16 i = 0; i < n; i++) + { + if ( aItems[ i ] == rKey ) + return i; + } + return LISTBOX_ENTRY_NOTFOUND; + } + + OUString GetEntry( sal_uInt16 nPos ) const + { + return mxListBox->getItem( nPos ); + } + + sal_uInt16 GetEntryCount() const + { + return mxListBox->getItemCount(); + } + + void SelectEntryPos( sal_uInt16 nPos, bool bSelect ) + { + mxListBox->selectItemPos( nPos, bSelect ); + } + + sal_uInt16 GetSelectEntryCount() const + { + return sal::static_int_cast< sal_uInt16 >( mxListBox->getSelectedItems().getLength() ); + } + + sal_uInt16 GetSelectEntryPos( sal_uInt16 nSelIndex ) const + { + sal_uInt16 nSelected = 0; + if ( mxListBox->isMutipleMode() ) + { + uno::Sequence< short > aItems( mxListBox->getSelectedItemsPos() ); + if ( nSelIndex < aItems.getLength() ) + nSelected = aItems[ nSelIndex ]; + } + else + nSelected = mxListBox->getSelectedItemPos(); + return nSelected; + } + + virtual void SAL_CALL disposing( lang::EventObject const& e ) + throw (uno::RuntimeException) + { + ControlImpl::disposing (e); + mxListBox.clear (); + } + + Link& GetClickHdl () + { + return maClickHdl; + } + + void SetClickHdl( Link const& link ) + { + if (!link && !!maClickHdl) + mxListBox->removeActionListener( this ); + else if (!!link && !maClickHdl) + mxListBox->addActionListener( this ); + maClickHdl = link; + } + + void SAL_CALL actionPerformed( const awt::ActionEvent& /* rEvent */ ) + throw (uno::RuntimeException) + { + maClickHdl.Call( mpWindow ); + } + + Link& GetSelectHdl () + { + return maSelectHdl; + } + + void SetSelectHdl( Link const& link ) + { + if (!link && !!maSelectHdl) + mxListBox->removeItemListener( this ); + else if (!!link && !maSelectHdl) + mxListBox->addItemListener( this ); + maSelectHdl = link; + } + + void SAL_CALL itemStateChanged (awt::ItemEvent const&) + throw (uno::RuntimeException) + { + maSelectHdl.Call (static_cast <ListBox*> (mpWindow)); + } + + Link& GetDoubleClickHdl () + { + return maDoubleClickHdl; + } + + void SetDoubleClickHdl (Link const& link) + { + if (!link && !!maDoubleClickHdl) + mxWindow->removeMouseListener (this); + else if (!!link && !maSelectHdl) + mxWindow->addMouseListener (this); + maDoubleClickHdl = link; + } + + void SAL_CALL mousePressed (awt::MouseEvent const&) throw (uno::RuntimeException) + { + } + void SAL_CALL mouseReleased (awt::MouseEvent const& e) throw (uno::RuntimeException) + { + if (e.ClickCount == 2) + maDoubleClickHdl.Call (mpWindow); + } + void SAL_CALL mouseEntered (awt::MouseEvent const&) throw (uno::RuntimeException) + { + } + void SAL_CALL mouseExited (awt::MouseEvent const&) throw (uno::RuntimeException) + { + } +}; + +ListBox::~ListBox () +{ +} + +sal_uInt16 ListBox::InsertEntry (String const& rStr, sal_uInt16 nPos) +{ + return getImpl().InsertEntry(rStr, nPos); +} + +void ListBox::RemoveEntry( sal_uInt16 nPos ) +{ + return getImpl().RemoveEntry( nPos ); +} + +void ListBox::RemoveEntry( String const& rStr ) +{ + return getImpl().RemoveEntry( GetEntryPos( rStr ) ); +} + +void ListBox::Clear() +{ + uno::Sequence< rtl::OUString> aNoItems; + getImpl().setProperty( "StringItemList", uno::Any( aNoItems ) ); +} + +sal_uInt16 ListBox::GetEntryPos( String const& rStr ) const +{ + return getImpl().GetEntryPos( rStr ); +} + +String ListBox::GetEntry( sal_uInt16 nPos ) const +{ + return getImpl().GetEntry( nPos ); +} + +sal_uInt16 ListBox::GetEntryCount() const +{ + return getImpl().GetEntryCount(); +} + +void ListBox::SelectEntryPos( sal_uInt16 nPos, bool bSelect ) +{ +#if LAYOUT_API_CALLS_HANDLER + getImpl().SelectEntryPos( nPos, bSelect ); +#else /* !LAYOUT_API_CALLS_HANDLER */ + GetListBox ()->SelectEntryPos (nPos, bSelect); +#endif /* !LAYOUT_API_CALLS_HANDLER */ +} + +void ListBox::SelectEntry( String const& rStr, bool bSelect ) +{ + SelectEntryPos( GetEntryPos( rStr ), bSelect ); +} + +sal_uInt16 ListBox::GetSelectEntryCount() const +{ + return getImpl().GetSelectEntryCount(); +} + +sal_uInt16 ListBox::GetSelectEntryPos( sal_uInt16 nSelIndex ) const +{ + return getImpl().GetSelectEntryPos( nSelIndex ); +} + +String ListBox::GetSelectEntry( sal_uInt16 nSelIndex ) const +{ + return GetEntry( GetSelectEntryPos( nSelIndex ) ); +} + +Link& ListBox::GetSelectHdl () +{ + return getImpl ().GetSelectHdl (); +} + +void ListBox::SetSelectHdl( Link const& link ) +{ + getImpl().SetSelectHdl( link ); +} + +Link& ListBox::GetClickHdl () +{ + return getImpl ().GetSelectHdl (); +} + +void ListBox::SetClickHdl( Link const& link ) +{ + if (&getImpl () && getImpl().mxListBox.is ()) + getImpl().SetClickHdl( link ); +} + +Link& ListBox::GetDoubleClickHdl () +{ + return getImpl ().GetSelectHdl (); +} + +void ListBox::SetDoubleClickHdl( Link const& link ) +{ + getImpl().SetDoubleClickHdl( link ); +} + +void ListBox::SetEntryData( sal_uInt16 pos, void* data) +{ + GetListBox ()->SetEntryData (pos, data); +} + +void* ListBox::GetEntryData( sal_uInt16 pos) const +{ + return GetListBox ()->GetEntryData (pos); +} + +void ListBox::SetNoSelection () +{ + GetListBox ()->SetNoSelection (); +} + +IMPL_CONSTRUCTORS (ListBox, Control, "listbox"); +IMPL_GET_IMPL (ListBox); +IMPL_GET_WINDOW (ListBox); + +IMPL_IMPL (MultiListBox, ListBox) +IMPL_CONSTRUCTORS_BODY( MultiListBox, ListBox, "multilistbox", GetMultiListBox()->EnableMultiSelection( true ); ); +IMPL_GET_IMPL( MultiListBox ); +IMPL_GET_WINDOW( MultiListBox ); +} // namespace layout diff --git a/toolkit/source/layout/vcl/wrapper.cxx b/toolkit/source/layout/vcl/wrapper.cxx new file mode 100644 index 000000000000..a8133250eb58 --- /dev/null +++ b/toolkit/source/layout/vcl/wrapper.cxx @@ -0,0 +1,1626 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <tools/rc.h> +//#define RESOURCE_PUBLISH_PROTECTED 1 +#if RESOURCE_PUBLISH_PROTECTED +// ugh, override non-helpful proctection +#define protected public +#endif /* RESOURCE_PUBLISH_PROTECTED */ +#include <tools/rc.hxx> +#undef protected + + +#include "wrapper.hxx" + +#include <awt/vclxplugin.hxx> +#include <awt/vclxtabcontrol.hxx> +#include <com/sun/star/awt/PosSize.hpp> +#include <com/sun/star/awt/VclWindowPeerAttribute.hpp> +#include <com/sun/star/awt/WindowAttribute.hpp> +#include <com/sun/star/awt/XDialog2.hpp> +#include <com/sun/star/awt/XProgressBar.hpp> +#include <com/sun/star/awt/XSimpleTabController.hpp> +#include <com/sun/star/awt/XTabListener.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> +#include <comphelper/processfactory.hxx> +#include <layout/core/factory.hxx> +#include <layout/core/localized-string.hxx> +#include <layout/core/root.hxx> +#include <toolkit/awt/vclxwindow.hxx> +#include <vcl/ctrl.hxx> +#include <vcl/dialog.hxx> +#include <vcl/image.hxx> +#include <vcl/tabctrl.hxx> +#include <vcl/tabpage.hxx> +#include <vcl/window.hxx> + +using namespace ::com::sun::star; +using rtl::OUString; + +namespace layout +{ + +// Context bits ... +class ContextImpl +{ + uno::Reference< awt::XLayoutRoot > mxRoot; + uno::Reference< container::XNameAccess > mxNameAccess; + PeerHandle mxTopLevel; + +public: + ContextImpl( char const *pPath ) + { + uno::Sequence< uno::Any > aParams( 1 ); + aParams[0] <<= OUString( pPath, strlen( pPath ), RTL_TEXTENCODING_UTF8 ); + + uno::Reference< lang::XSingleServiceFactory > xFactory( + comphelper::createProcessComponent( + OUString::createFromAscii( "com.sun.star.awt.Layout" ) ), + uno::UNO_QUERY ); + if ( !xFactory.is() ) + { + throw uno::RuntimeException( + OUString( RTL_CONSTASCII_USTRINGPARAM( "Layout engine not installed" ) ), + uno::Reference< uno::XInterface >() ); + } + mxRoot = uno::Reference< awt::XLayoutRoot >( + xFactory->createInstanceWithArguments( aParams ), + uno::UNO_QUERY ); + + mxNameAccess = uno::Reference< container::XNameAccess >( mxRoot, uno::UNO_QUERY ); + } + + ~ContextImpl() + { + } + + PeerHandle getByName( const OUString &rName ) + { + uno::Any val = mxNameAccess->getByName( rName ); + PeerHandle xRet; + val >>= xRet; + return xRet; + } + PeerHandle getTopLevel() + { + return mxTopLevel; + } + void setTopLevel( PeerHandle xToplevel ) + { + mxTopLevel = xToplevel; + } + PeerHandle getRoot() + { + return mxRoot; + } +}; + +Context::Context( const char *pPath ) + : pImpl( new ContextImpl( pPath ) ) +{ +} +Context::~Context() +{ + delete pImpl; + pImpl = NULL; +} + +void Context::setToplevel( PeerHandle xToplevel ) +{ + pImpl->setTopLevel( xToplevel ); +} + +PeerHandle Context::getToplevel() +{ + return pImpl->getTopLevel(); +} +PeerHandle Context::getRoot() +{ + return pImpl->getRoot(); +} + +PeerHandle Context::GetPeerHandle( const char *id, sal_uInt32 nId ) const +{ + PeerHandle xHandle; + xHandle = pImpl->getByName( OUString( id, strlen( id ), RTL_TEXTENCODING_UTF8 ) ); + if ( !xHandle.is() ) + { + DBG_ERROR1( "Failed to fetch widget '%s'", id ); + } + + if ( nId != 0 ) + { + rtl::OString aStr = rtl::OString::valueOf( (sal_Int32) nId ); + xHandle = GetPeerHandle( aStr, 0 ); + } + return xHandle; +} + +WindowImpl::WindowImpl (Context *context, const PeerHandle &peer, Window *window) + : mpWindow (window) + , mpCtx (context) + , mxWindow (peer, uno::UNO_QUERY) + , mxVclPeer (peer, uno::UNO_QUERY) + , mvclWindow (0) + , bFirstTimeVisible (true) +{ +} + +WindowImpl::~WindowImpl () +{ + if (mpWindow) + mpWindow->mpImpl = 0; + if (mvclWindow) + { + VCLXWindow *v = mvclWindow->GetWindowPeer (); + v->SetWindow (0); + mvclWindow->SetComponentInterface (uno::Reference <awt::XWindowPeer> ()); + mvclWindow->SetWindowPeer (uno::Reference <awt::XWindowPeer> (), 0); + delete mvclWindow; + mvclWindow = 0; + } +} + +void WindowImpl::wrapperGone () +{ + mvclWindow = 0; + mpWindow->mpImpl = 0; + mpWindow = 0; + mpCtx = 0; + if ( mxWindow.is() ) + { + uno::Reference< lang::XComponent > xComp( mxWindow, uno::UNO_QUERY ); + mxWindow.clear (); + if ( xComp.is() ) + xComp->dispose(); + } +} + +void SAL_CALL WindowImpl::disposing (lang::EventObject const&) + throw (uno::RuntimeException) +{ + if (mxWindow.is ()) + mxWindow.clear (); +} + +uno::Any WindowImpl::getProperty (char const* name) +{ + if ( !this || !mxVclPeer.is() ) + return css::uno::Any(); + return mxVclPeer->getProperty + ( rtl::OUString( name, strlen( name ), RTL_TEXTENCODING_ASCII_US ) ); +} + +void WindowImpl::setProperty (char const *name, uno::Any any) +{ + if ( !this || !mxVclPeer.is() ) + return; + mxVclPeer->setProperty + ( rtl::OUString( name, strlen( name ), RTL_TEXTENCODING_ASCII_US ), any ); +} + +void WindowImpl::redraw (bool resize) +{ + uno::Reference <awt::XWindow> ref (mxWindow, uno::UNO_QUERY); + ::Window* window = VCLXWindow::GetImplementation (ref)->GetWindow (); + ::Window* parent = window->GetParent(); + ::Rectangle r = Rectangle (parent->GetPosPixel (), + parent->GetSizePixel ()); + parent->Invalidate (r, INVALIDATE_CHILDREN | INVALIDATE_NOCHILDREN ); + if (resize) + parent->SetPosSizePixel (0, 0, 1, 1, awt::PosSize::SIZE); + else + parent->SetPosSizePixel (0, 0, r.nRight - r.nLeft, r.nBottom - r.nTop, + awt::PosSize::SIZE); +} + +Window::Window( WindowImpl *pImpl ) + : mpImpl( pImpl ) +{ + mpImpl->mvclWindow = GetVCLXWindow () ? GetWindow () : 0; +} + +Window::~Window() +{ + /* likely to be an UNO object - with floating references */ + if (mpImpl) + mpImpl->wrapperGone (); + mpImpl = 0; +} + +///IMPL_GET_IMPL( Control ); + +static ControlImpl* null_control_impl = 0; + +ControlImpl &Control::getImpl () const +{ + if (ControlImpl* c = static_cast<ControlImpl *>(mpImpl)) + return *c; + return *null_control_impl; +} + +Control::~Control () +{ + SetGetFocusHdl (Link ()); + SetLoseFocusHdl (Link ()); +} + +void Window::setRes (ResId const& res) +{ +#if RESOURCE_PUBLISH_PROTECTED + // Resources are shut-off from use. Is that really necessary? + Resource &r = *GetWindow (); + r.GetRes (res); +#else /* !RESOURCE_PUBLISH_PROTECTED */ + //We *must* derive. Is this also really necessary? + //Resource r (res); + + // ugh, I wonder which solution is cleaner... + class Resource_open_up : public Resource + { + public: + Resource_open_up (ResId const& r) + : Resource (r) + { + } + static sal_Int32 GetLongRes (void *p) + { + return Resource::GetLongRes (p); + } + void* GetClassRes () + { + return Resource::GetClassRes (); + } + sal_Int32 ReadLongRes () + { + return Resource::ReadLongRes (); + } + UniString ReadStringRes () + { + return Resource::ReadStringRes (); + } + }; + + Resource_open_up r (res); +#endif /* !RESOURCE_PUBLISH_PROTECTED */ + if (sal_uInt32 help_id = (sal_uInt32)r.GetLongRes (static_cast<char *> (r.GetClassRes ()) + 12)) + SetHelpId (help_id); + sal_uInt32 mask = r.ReadLongRes (); + if ( mask & WINDOW_TEXT ) + SetText( r.ReadStringRes ()); +} + +void Window::SetParent( ::Window *parent ) +{ + uno::Reference <awt::XWindow> ref( GetPeer(), uno::UNO_QUERY ); + if (VCLXWindow *vcl = VCLXWindow::GetImplementation( ref )) + if (::Window *window = vcl->GetWindow()) + window->SetParent( parent ); +} + +void Window::SetParent( Window *parent ) +{ + /* Let's hear it for C++: poor man's dynamic binding. */ + parent->ParentSet (this); +} + +void Window::ParentSet (Window *window) +{ + window->SetParent (GetWindow ()); +} + +Context *Window::getContext() +{ + return this && mpImpl ? mpImpl->mpCtx : NULL; +} + +PeerHandle Window::GetPeer() const +{ + if ( !mpImpl ) + return PeerHandle(); + return mpImpl->mxWindow; +} + +uno::Reference<awt::XWindow> Window::GetRef() const +{ + return uno::Reference <awt::XWindow> ( GetPeer(), uno::UNO_QUERY ); +} + +VCLXWindow* Window::GetVCLXWindow() const +{ + return VCLXWindow::GetImplementation( GetRef() ); +} + +::Window* Window::GetWindow() const +{ + return GetVCLXWindow()->GetWindow(); +} + +::Window* Window::GetParent() const +{ + return GetWindow()->GetParent(); +} + +void Window::SetHelpId( sal_uIntPtr id ) +{ + GetWindow()->SetHelpId( id ); +} + +sal_uIntPtr Window::GetHelpId() const +{ + return GetWindow()->GetHelpId(); +} + +void Window::SetSmartHelpId( SmartId const& id, SmartIdUpdateMode mode ) +{ + GetWindow()->SetSmartHelpId( id, mode ); +} + +SmartId Window::GetSmartHelpId() const +{ + return GetWindow()->GetSmartHelpId(); +} + +void Window::EnterWait () +{ + GetWindow()->EnterWait (); +} +void Window::LeaveWait () +{ + GetWindow()->LeaveWait (); +} +bool Window::IsWait () const +{ + return GetWindow()->IsWait (); +} + +bool Window::IsVisible () const +{ + if (GetWindow ()) + return GetWindow()->IsVisible (); + return false; +} + +bool Window::HasChildPathFocus (bool systemWindow) const +{ + return GetWindow()->HasChildPathFocus (systemWindow); +} + +void Window::SetPosPixel (Point const&) +{ +} + +Point Window::GetPosPixel () const +{ + return Point (); +} + +void Window::SetSizePixel (Size const&) +{ +} + +void Window::SetPosSizePixel (Point const&, Size const&) +{ +} + +Size Window::GetSizePixel () const +{ + return Size (); +} + +// void Window::Enable (bool enable, bool child); +// { +// GetWindow ()->Enable (enable, child); +// } + +// void Window::Disable (bool child) +// { +// GetWindow ()->Disable (child); +// } + +bool Window::IsEnabled () const +{ + return GetWindow ()->IsEnabled (); +// if (getImpl().mxWindow.is ()) +// return getImpl ().mxWindow->isEnabled (); +// return false; +} + +void Window::EnableInput (bool enable, bool child) +{ + GetWindow ()->EnableInput (enable, child); +} + +bool Window::IsInputEnabled () const +{ + return GetWindow ()->IsInputEnabled (); +} + +bool Window::HasFocus () const +{ + return GetWindow ()->HasFocus (); +} + +Font& Window::GetFont () const +{ + return const_cast <Font&> (GetWindow ()->GetFont ()); +} + +void Window::SetFont (Font const& font) +{ + GetWindow ()->SetFont (font); +} + +void Window::Invalidate (sal_uInt8 flags) +{ + GetWindow ()->Invalidate (flags); +} + +struct ToolkitVclPropsMap +{ + WinBits vclStyle; + long initAttr; + const char *propName; + + // the value to give the prop to enable/disable it -- not the most brilliant + // type declaration and storage, but does the work... properties are + // either a boolean or a short since they are either a directly wrappers for + // a WinBit, or aggregates related (like Align for WB_LEFT, _RIGHT and _CENTER). + bool isBoolean; + short enableProp, disableProp; +}; + +#define TYPE_BOOL true +#define TYPE_SHORT false +#define NOTYPE 0 +static const ToolkitVclPropsMap toolkitVclPropsMap[] = +{ + { WB_BORDER, awt::WindowAttribute::BORDER, "Border", TYPE_SHORT, 1, 0 }, + { WB_NOBORDER, awt::VclWindowPeerAttribute::NOBORDER, "Border", TYPE_SHORT, 0, 1 }, + { WB_SIZEABLE, awt::WindowAttribute::SIZEABLE, NULL, NOTYPE, 0, 0 }, + { WB_MOVEABLE, awt::WindowAttribute::MOVEABLE, NULL, NOTYPE, 0, 0 }, + { WB_CLOSEABLE, awt::WindowAttribute::CLOSEABLE, NULL, NOTYPE, 0, 0 }, + + { WB_HSCROLL, awt::VclWindowPeerAttribute::HSCROLL, NULL, NOTYPE, 0, 0 }, + { WB_VSCROLL, awt::VclWindowPeerAttribute::VSCROLL, NULL, NOTYPE, 0, 0 }, + { WB_LEFT, awt::VclWindowPeerAttribute::LEFT, "Align", TYPE_SHORT, 0, 0 }, + { WB_CENTER, awt::VclWindowPeerAttribute::CENTER, "Align", TYPE_SHORT, 1, 0 }, + { WB_RIGHT, awt::VclWindowPeerAttribute::RIGHT, "Align", TYPE_SHORT, 2, 0 }, + { WB_SPIN, awt::VclWindowPeerAttribute::SPIN, NULL, NOTYPE, 0, 0 }, + { WB_SORT, awt::VclWindowPeerAttribute::SORT, NULL, NOTYPE, 0, 0 }, + { WB_DROPDOWN, awt::VclWindowPeerAttribute::DROPDOWN, "Dropdown", TYPE_BOOL, 1, 0 }, + { WB_DEFBUTTON, awt::VclWindowPeerAttribute::DEFBUTTON, "DefaultButton", TYPE_BOOL, 1, 0 }, + { WB_READONLY, awt::VclWindowPeerAttribute::READONLY, NULL, NOTYPE, 0, 0 }, + { WB_CLIPCHILDREN, awt::VclWindowPeerAttribute::CLIPCHILDREN, NULL, NOTYPE, 0, 0 }, + { WB_GROUP, awt::VclWindowPeerAttribute::GROUP, NULL, NOTYPE, 0, 0 }, + + { WB_OK, awt::VclWindowPeerAttribute::OK, NULL, NOTYPE, 0, 0 }, + { WB_OK_CANCEL, awt::VclWindowPeerAttribute::OK_CANCEL, NULL, NOTYPE, 0, 0 }, + { WB_YES_NO, awt::VclWindowPeerAttribute::YES_NO, NULL, NOTYPE, 0, 0 }, + { WB_YES_NO_CANCEL, awt::VclWindowPeerAttribute::YES_NO_CANCEL, NULL, NOTYPE, 1, 0 }, + { WB_RETRY_CANCEL, awt::VclWindowPeerAttribute::RETRY_CANCEL, NULL, NOTYPE, 1, 0 }, + { WB_DEF_OK, awt::VclWindowPeerAttribute::DEF_OK, NULL, NOTYPE, 0, 0 }, + { WB_DEF_CANCEL, awt::VclWindowPeerAttribute::DEF_CANCEL, NULL, NOTYPE, 1, 0 }, + { WB_DEF_RETRY, awt::VclWindowPeerAttribute::DEF_RETRY, NULL, NOTYPE, 0, 0 }, + { WB_DEF_YES, awt::VclWindowPeerAttribute::DEF_YES, NULL, NOTYPE, 0, 0 }, + { WB_DEF_NO, awt::VclWindowPeerAttribute::DEF_NO, NULL, NOTYPE, 0, 0 }, + + { WB_AUTOHSCROLL, awt::VclWindowPeerAttribute::AUTOHSCROLL, "AutoHScroll", TYPE_BOOL, 1, 0 }, + { WB_AUTOVSCROLL, awt::VclWindowPeerAttribute::AUTOVSCROLL, "AutoVScroll", TYPE_BOOL, 1, 0 }, + + { WB_WORDBREAK, 0, "MultiLine", TYPE_BOOL, 1, 0 }, + { WB_NOPOINTERFOCUS, 0, "FocusOnClick", TYPE_BOOL, 1, 0 }, + { WB_TOGGLE, 0, "Toggle", TYPE_BOOL, 1, 0 }, + { WB_REPEAT, 0, "Repeat", TYPE_BOOL, 1, 0 }, + { WB_NOHIDESELECTION, 0, "HideInactiveSelection", TYPE_BOOL, 1, 0 }, +}; +#undef TYPE_BOOL +#undef TYPE_SHORT +#undef NOTYPE + +static const int toolkitVclPropsMapLen = + sizeof( toolkitVclPropsMap ) / sizeof( ToolkitVclPropsMap ); + +void Window::SetStyle( WinBits nStyle ) +{ + uno::Reference< awt::XVclWindowPeer > xPeer = mpImpl->mxVclPeer; + for (int i = 0; i < toolkitVclPropsMapLen; i++) + { + if ( toolkitVclPropsMap[ i ].propName ) + { + short nValue; + if ( nStyle & toolkitVclPropsMap[ i ].vclStyle ) + nValue = toolkitVclPropsMap[ i ].enableProp; + else + nValue = toolkitVclPropsMap[ i ].disableProp; + uno::Any aValue; + if ( toolkitVclPropsMap[ i ].isBoolean ) + aValue = uno::makeAny( (bool) nValue ); + else + aValue = uno::makeAny( (short) nValue ); + mpImpl->setProperty( toolkitVclPropsMap[ i ].propName, aValue ); + } + } +} + +WinBits Window::GetStyle() +{ + uno::Reference< awt::XVclWindowPeer > xPeer = mpImpl->mxVclPeer; + WinBits ret = 0; + for (int i = 0; i < toolkitVclPropsMapLen; i++) + { + if ( toolkitVclPropsMap[ i ].propName ) + { + short nValue = 0; + if ( toolkitVclPropsMap[ i ].isBoolean ) + { + bool bValue = false; + mpImpl->getProperty( toolkitVclPropsMap[ i ].propName ) >>= bValue; + nValue = bValue ? 1 : 0; + } + else + mpImpl->getProperty( toolkitVclPropsMap[ i ].propName ) >>= nValue; + if ( nValue == toolkitVclPropsMap[ i ].enableProp ) + ret |= toolkitVclPropsMap[i].vclStyle; + } + } + return ret; +} + +/* Unpleasant way to get an xToolkit pointer ... */ +uno::Reference< awt::XToolkit > getToolkit() +{ + static uno::Reference< awt::XToolkit > xToolkit; + if (!xToolkit.is()) + { + // Urgh ... + xToolkit = uno::Reference< awt::XToolkit >( + ::comphelper::getProcessServiceFactory()->createInstance( + OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" ) ) ), + uno::UNO_QUERY ); + if ( !xToolkit.is() ) + throw uno::RuntimeException( + OUString( RTL_CONSTASCII_USTRINGPARAM( "failed to create toolkit!") ), + uno::Reference< uno::XInterface >() ); + } + return xToolkit; +} + +PeerHandle Window::CreatePeer( Window *parent, WinBits nStyle, const char *pName) +{ + long nWinAttrbs = 0; + for (int i = 0; i < toolkitVclPropsMapLen; i++) + if ( nStyle & toolkitVclPropsMap[ i ].vclStyle ) + nWinAttrbs |= toolkitVclPropsMap[ i ].initAttr; + + return layoutimpl::WidgetFactory::createWidget (getToolkit(), parent->GetPeer(), OUString::createFromAscii( pName ), nWinAttrbs); +} + +void Window::Enable( bool bEnable ) +{ + if ( !getImpl().mxWindow.is() ) + return; + getImpl().mxWindow->setEnable( bEnable ); +} + +void Window::Show( bool bVisible ) +{ + if ( !getImpl().mxWindow.is() ) + return; + getImpl().mxWindow->setVisible( bVisible ); + if (!bVisible) + getImpl ().bFirstTimeVisible = true; + else if (GetParent() && getImpl().bFirstTimeVisible) + { + getImpl().redraw (); + getImpl().bFirstTimeVisible = false; + } +} + +void Window::GrabFocus() +{ + if ( !getImpl().mxWindow.is() ) + return; + getImpl().mxWindow->setFocus(); +} + +void Window::SetUpdateMode(bool mode) +{ + GetWindow()->SetUpdateMode( mode ); +} + +void Window::SetPointer( Pointer const& pointer ) +{ + GetWindow()->SetPointer( pointer ); +} + +Pointer const& Window::GetPointer() const +{ + return GetWindow()->GetPointer(); +} + +void Window::SetText( OUString const& str ) +{ + GetWindow()->SetText( str ); +} + +String Window::GetText() const +{ + return GetWindow()->GetText(); +} + +sal_Int32 Window::GetCtrlTextWidth (OUString const&) const +{ + return 0; +} + +sal_Int32 Window::GetTextHeight () const +{ + return 0; +} + +Size Window::LogicToPixel( Size const& size, MapMode const&) const +{ + return size; +} + +ControlImpl::ControlImpl (Context *context, const PeerHandle &peer, Window *window) + : WindowImpl( context, peer, window ) +{ +} + +ControlImpl::~ControlImpl () +{ + if ((!!mGetFocusHdl || !!mLoseFocusHdl) && mxWindow.is ()) + /* Disposing will be done @ VCLXWindow::dispose () maFocusListeners.disposeAndClear() + don't do it twice */ + mxWindow.clear (); +} + +void ControlImpl::SetGetFocusHdl (Link const& link) +{ + if (!mLoseFocusHdl || !link) + UpdateListening (link); + mGetFocusHdl = link; +} + +Link& ControlImpl::GetGetFocusHdl () +{ + return mGetFocusHdl; +} + +void ControlImpl::SetLoseFocusHdl (Link const& link) +{ + if (!mGetFocusHdl || !link) + UpdateListening (link); + mLoseFocusHdl = link; +} + +Link& ControlImpl::GetLoseFocusHdl () +{ + return mGetFocusHdl; +} + +void ControlImpl::UpdateListening (Link const& link) +{ + if (!link && (!!mGetFocusHdl || !!mLoseFocusHdl) + && (!mGetFocusHdl || !mLoseFocusHdl)) + mxWindow->removeFocusListener (this); + else if (!!link && !mGetFocusHdl && !mLoseFocusHdl) + mxWindow->addFocusListener (this); +} + +void SAL_CALL ControlImpl::disposing (lang::EventObject const&) + throw (uno::RuntimeException) +{ +/// mxWindow.clear (); +} + +void SAL_CALL ControlImpl::focusGained (awt::FocusEvent const&) + throw (uno::RuntimeException) +{ + mGetFocusHdl.Call (mpWindow); +} + +void SAL_CALL ControlImpl::focusLost (awt::FocusEvent const&) + throw (uno::RuntimeException) +{ + mLoseFocusHdl.Call (mpWindow); +} + +Link& Control::GetGetFocusHdl () +{ + return getImpl ().GetGetFocusHdl (); +} + +void Control::SetGetFocusHdl (Link const& link) +{ + if (&getImpl () && getImpl().mxWindow.is ()) + getImpl ().SetGetFocusHdl (link); +} + +Link& Control::GetLoseFocusHdl () +{ + return getImpl ().GetLoseFocusHdl (); +} + +void Control::SetLoseFocusHdl (Link const& link) +{ + if (&getImpl () && getImpl().mxWindow.is ()) + getImpl ().SetLoseFocusHdl (link); +} + +class DialogImpl : public WindowImpl +{ +public: + uno::Reference< awt::XDialog2 > mxDialog; + DialogImpl( Context *context, PeerHandle const &peer, Window *window ); +}; + +DialogImpl::DialogImpl( Context *context, const PeerHandle &peer, Window *window ) + : WindowImpl( context, peer, window ) + , mxDialog( peer, uno::UNO_QUERY ) +{ +} + +Dialog::Dialog( Window *parent, const char *xml_file, const char *id, sal_uInt32 nId ) + : Context( xml_file ) + , Window( new DialogImpl( this, Context::GetPeerHandle( id, nId ), this ) ) + , bConstruct (true) +{ + if ( parent ) + SetParent( parent ); +} + +Dialog::Dialog( ::Window *parent, const char *xml_file, const char *id, sal_uInt32 nId ) + : Context( xml_file ) + , Window( new DialogImpl( this, Context::GetPeerHandle( id, nId ), this ) ) +{ + if ( parent ) + SetParent( parent ); +} + +Dialog::~Dialog () +{ +} + +IMPL_GET_WINDOW (Dialog); +IMPL_GET_IMPL (Dialog); + +#define MX_DIALOG if (getImpl ().mxDialog.is ()) getImpl ().mxDialog +#define RETURN_MX_DIALOG if (getImpl ().mxDialog.is ()) return getImpl ().mxDialog + +short Dialog::Execute() +{ + RETURN_MX_DIALOG->execute (); + return -1; +} + +void Dialog::EndDialog( long result ) +{ + MX_DIALOG->endDialog (result); +} + +void Dialog::SetText( OUString const& str ) +{ + SetTitle (str); +} + +void Dialog::SetTitle( OUString const& str ) +{ + MX_DIALOG->setTitle (str); +} + +bool Dialog::Close () +{ + EndDialog (false); + return true; +} + +long Dialog::Notify (NotifyEvent& event) +{ + return GetDialog ()->Notify (event); +} + +void Dialog::Initialize (SfxChildWinInfo*) +{ +} + +#define MESSAGE_BOX_MEMBER_INIT\ + Dialog (parent, xml_file, id)\ + , imageError (this, "FI_ERROR")\ + , imageInfo (this, "FI_INFO")\ + , imageQuery (this, "FI_QUERY")\ + , imageWarning (this, "FI_WARNING")\ + , messageText (this, "FT_MESSAGE")\ + , cancelButton (this, "BTN_CANCEL")\ + , helpButton (this, "BTN_HELP")\ + , ignoreButton (this, "BTN_IGNORE")\ + , noButton (this, "BTN_NO")\ + , retryButton (this, "BTN_RETRY")\ + , yesButton (this, "BTN_YES") + +MessageBox::MessageBox (::Window *parent, char const* message, + char const* yes, char const* no, sal_uIntPtr help_id, + char const* xml_file, char const* id) + : MESSAGE_BOX_MEMBER_INIT +{ + ignoreButton.Hide (); + retryButton.Hide (); + init (message, yes, no, help_id); +} + +MessageBox::MessageBox (::Window *parent, OUString const& message, + OUString yes, OUString no, sal_uIntPtr help_id, + char const* xml_file, char const* id) + : MESSAGE_BOX_MEMBER_INIT +{ + ignoreButton.Hide (); + retryButton.Hide (); + init (message, yes, no, help_id); +} + +#if !defined (__GNUC__) +#define __PRETTY_FUNCTION__ __FUNCTION__ +#endif /* !__GNUC__ */ + +MessageBox::MessageBox (::Window *parent, WinBits bits, char const* message, + char const* yes, char const* no, sal_uIntPtr help_id, + char const* xml_file, char const* id) + : MESSAGE_BOX_MEMBER_INIT +{ + // HIG suggests using verbs instead of yes/no/retry etc. + // This constructor provides client-code compatibility: Client code should be fixed. +#ifndef __SUNPRO_CC + OSL_TRACE ("%s: warning, deprecated vcl/Messbox compatibility", __PRETTY_FUNCTION__); +#endif + bits_init (bits, OUString::createFromAscii (message), OUString::createFromAscii (yes), OUString::createFromAscii (no), help_id); +} + +MessageBox::MessageBox (::Window *parent, WinBits bits, OUString const& message, + OUString yes, OUString no, sal_uIntPtr help_id, + char const* xml_file, char const* id) + : MESSAGE_BOX_MEMBER_INIT +{ + // HIG suggests using verbs instead of yes/no/retry etc. + // This constructor provides client-code compatibility: Client code should be fixed. +#ifndef __SUNPRO_CC + OSL_TRACE ("%s: warning, deprecated vcl/Messbox compatibility", __PRETTY_FUNCTION__); +#endif + bits_init (bits, message, yes, no, help_id); +} + +void MessageBox::bits_init (WinBits bits, OUString const& message, + OUString yes, OUString no, sal_uIntPtr help_id) +{ + if ( bits & ( WB_OK_CANCEL | WB_OK )) + yes = Button::GetStandardText ( BUTTON_OK ); + if ( bits & (WB_YES_NO | WB_YES_NO_CANCEL )) + { + yes = Button::GetStandardText ( BUTTON_YES ); + no = Button::GetStandardText ( BUTTON_NO ); + } + if (! (bits & (WB_RETRY_CANCEL | WB_YES_NO_CANCEL | WB_ABORT_RETRY_IGNORE ))) + cancelButton.Hide (); + if (! (bits & (WB_RETRY_CANCEL | WB_ABORT_RETRY_IGNORE))) + retryButton.Hide (); + if ( bits & WB_ABORT_RETRY_IGNORE ) + cancelButton.SetText ( Button::GetStandardText (BUTTON_ABORT)); + else + ignoreButton.Hide (); + if ( !(bits & ( WB_OK | WB_OK_CANCEL | WB_YES_NO | WB_YES_NO_CANCEL))) + yesButton.Hide (); + if ( !(bits & ( WB_YES_NO | WB_YES_NO_CANCEL))) + noButton.Hide (); + + init (message, yes, no, help_id); +} + +void MessageBox::init (char const* message, char const* yes, char const* no, sal_uIntPtr help_id) +{ + init ( OUString::createFromAscii (message), OUString::createFromAscii (yes), OUString::createFromAscii (no), help_id); +} + +void MessageBox::init (OUString const& message, OUString const& yes, OUString const& no, sal_uIntPtr help_id) +{ + imageError.Hide (); + imageInfo.Hide (); + imageQuery.Hide (); + imageWarning.Hide (); + if (message.getLength ()) + messageText.SetText (message); + if (yes.getLength ()) + { + yesButton.SetText (yes); + if (yes != OUString (Button::GetStandardText (BUTTON_OK)) + && yes != OUString (Button::GetStandardText (BUTTON_YES))) + SetTitle (yes); + if (no.getLength ()) + noButton.SetText (no); + else + noButton.Hide (); + } + if (help_id) + SetHelpId (help_id); + else + helpButton.Hide (); +} + +#undef MESSAGE_BOX_IMPL +#define MESSAGE_BOX_IMPL(Name)\ + Name##Box::Name##Box (::Window *parent, char const* message,\ + char const* yes, char const* no, sal_uIntPtr help_id,\ + char const* xml_file, char const* id)\ + : MessageBox (parent, message, yes, no, help_id, xml_file, id)\ + {\ + image##Name.Show ();\ + }\ + Name##Box::Name##Box (::Window *parent, OUString const& message,\ + OUString yes, OUString no, sal_uIntPtr help_id,\ + char const* xml_file, char const* id)\ + : MessageBox (parent, message, yes, no, help_id, xml_file, id)\ + {\ + image##Name.Show ();\ + }\ + Name##Box::Name##Box (::Window *parent, WinBits bits, char const* message,\ + char const* yes, char const* no, sal_uIntPtr help_id,\ + char const* xml_file, char const* id)\ + : MessageBox (parent, bits, message, yes, no, help_id, xml_file, id)\ + {\ + image##Name.Show ();\ + }\ + Name##Box::Name##Box (::Window *parent, WinBits bits, OUString const& message,\ + OUString yes, OUString no, sal_uIntPtr help_id,\ + char const* xml_file, char const* id)\ + : MessageBox (parent, bits, message, yes, no, help_id, xml_file, id)\ + {\ + image##Name.Show ();\ + } + +MESSAGE_BOX_IMPL (Error); +MESSAGE_BOX_IMPL (Info); +MESSAGE_BOX_IMPL (Query); +MESSAGE_BOX_IMPL (Warning); + +class TabControlImpl + : public ControlImpl + , public ::cppu::WeakImplHelper1 <awt::XTabListener> +{ + Link mActivatePageHdl; + Link mDeactivatePageHdl; + +public: + uno::Reference <awt::XSimpleTabController> mxTabControl; + TabControlImpl (Context *context, const PeerHandle &peer, Window *window) + : ControlImpl (context, peer, window) + , mxTabControl (peer, uno::UNO_QUERY) + { + } + + virtual void SAL_CALL disposing (lang::EventObject const& e) + throw (uno::RuntimeException) + { + ControlImpl::disposing (e); + mxTabControl.clear (); + } + + Link& GetActivatePageHdl () + { + return mActivatePageHdl; + } + + void SetActivatePageHdl (Link const& link) + { + if (!mDeactivatePageHdl || !link) + UpdateListening (link); + mActivatePageHdl = link; + } + + Link& GetDeactivatePageHdl () + { + return mDeactivatePageHdl; + } + + void SetDeactivatePageHdl (Link const& link) + { + if (!mActivatePageHdl || !link) + UpdateListening (link); + mDeactivatePageHdl = link; + } + + void UpdateListening (Link const& link) + { + if (!link && (!!mActivatePageHdl || !!mDeactivatePageHdl)) + mxTabControl->removeTabListener (this); + else if (!!link && !mActivatePageHdl && !mDeactivatePageHdl) + mxTabControl->addTabListener (this); + } + + void SAL_CALL activated (sal_Int32) + throw (uno::RuntimeException) + { + mActivatePageHdl.Call (mpWindow); + } + + void SAL_CALL deactivated (sal_Int32) + throw (uno::RuntimeException) + { + mDeactivatePageHdl.Call (mpWindow); + } + + void SAL_CALL inserted (sal_Int32) + throw (uno::RuntimeException) + { + } + + void SAL_CALL removed (sal_Int32) + throw (uno::RuntimeException) + { + } + + void SAL_CALL changed (sal_Int32, uno::Sequence <beans::NamedValue> const&) + throw (uno::RuntimeException) + { + } +}; + +IMPL_GET_WINDOW (TabControl); +IMPL_GET_LAYOUT_VCLXWINDOW (TabControl); + +#define MX_TABCONTROL if (getImpl ().mxTabControl.is ()) getImpl ().mxTabControl +#define RETURN_MX_TABCONTROL if (getImpl ().mxTabControl.is ()) return getImpl ().mxTabControl + +TabControl::~TabControl () +{ + SetActivatePageHdl (Link ()); + SetDeactivatePageHdl (Link ()); +} + +void TabControl::InsertPage (sal_uInt16 id, OUString const& title, sal_uInt16 pos) +{ + (void) pos; +// GetTabControl ()->InsertPage (id, title, pos); +// GetTabControl ()->SetTabPage (id, new ::TabPage (GetTabControl ())); + + MX_TABCONTROL->insertTab (); + SetCurPageId (id); + +#if 1 // colour me loc productive -- NOT +#define ADD_PROP( seq, i, name, val )\ + { \ + beans::NamedValue value; \ + value.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( name ) ); \ + value.Value = uno::makeAny( val ); \ + seq[i] = value; \ + } + + uno::Sequence< beans::NamedValue > seq (1); + ADD_PROP ( seq, 0, "Title", OUString (title) ); + MX_TABCONTROL->setTabProps (id, seq); +#else + GetTabPage (id)->SetText (title); +#endif + +#if 0 + /// This so seems the right solution, but it makes the buttons of the + /// tabdialog move up + + ::TabPage *page = GetTabPage (id); + if (Window *w = dynamic_cast <Window*> (page)) + { + w->SetParent (this); + //GetVCLXTabControl ()->Box_Base::addChild (uno::Reference <awt::XLayoutConstrains> (w->GetPeer (), uno::UNO_QUERY)); + //GetVCLXTabControl ()->Box_Base::AddChild (uno::Reference <awt::XLayoutConstrains> (w->GetPeer (), uno::UNO_QUERY)); + //GetVCLXTabControl ()->AddChild (w); + //GetVCLXTabControl ()->AddChild (uno::Reference <awt::XLayoutConstrains> (w->GetPeer (), uno::UNO_QUERY)); + //uno::Reference <uno::XInterface> x (page->GetWindowPeer()); + //GetVCLXTabControl ()->AddChild (uno::Reference <awt::XLayoutConstrains> (page->::Window::GetWindowPeer (), uno::UNO_QUERY)); + //GetVCLXTabControl ()->AddChild (uno::Reference <awt::XLayoutConstrains> (page->GetComponentInterface (), uno::UNO_QUERY)); + } + getImpl ().redraw (); +#endif +} +void TabControl::RemovePage (sal_uInt16 id) +{ + GetTabControl ()->RemovePage (id); +} +sal_uInt16 TabControl::GetPageCount () const +{ + return GetTabControl ()->GetPageCount (); +} +sal_uInt16 TabControl::GetPageId (sal_uInt16 pos) const +{ + return GetTabControl ()->GetPageId (pos); +} +sal_uInt16 TabControl::GetPagePos (sal_uInt16 id) const +{ + getImpl ().redraw (); + return GetTabControl ()->GetPagePos (id); +} +void TabControl::SetCurPageId (sal_uInt16 id) +{ + getImpl ().redraw (); + GetTabControl ()->SetCurPageId (id); +} +sal_uInt16 TabControl::GetCurPageId () const +{ + return GetTabControl ()->GetCurPageId (); +} +void TabControl::SetTabPage (sal_uInt16 id, ::TabPage* page) +{ + GetTabControl ()->SetTabPage (id, page); + +#if 0 + /// This so seems the right solution, but it makes the buttons of the + /// tabdialog move up + if (Window *w = dynamic_cast <Window*> (page)) + { + w->SetParent (this); + //GetVCLXTabControl ()->Box_Base::addChild (uno::Reference <awt::XLayoutConstrains> (w->GetPeer (), uno::UNO_QUERY)); + //GetVCLXTabControl ()->Box_Base::AddChild (uno::Reference <awt::XLayoutConstrains> (w->GetPeer (), uno::UNO_QUERY)); + //GetVCLXTabControl ()->AddChild (w); + //GetVCLXTabControl ()->AddChild (uno::Reference <awt::XLayoutConstrains> (w->GetPeer (), uno::UNO_QUERY)); + //GetVCLXTabControl ()->AddChild (uno::Reference <awt::XLayoutConstrains> (page->GetWindowPeer (), uno::UNO_QUERY)); + //GetVCLXTabControl ()->AddChild (uno::Reference <awt::XLayoutConstrains> (page->GetComponentInterface (), uno::UNO_QUERY)); + } +#endif + getImpl ().redraw (); +} +::TabPage* TabControl::GetTabPage (sal_uInt16 id) const +{ + return GetTabControl ()->GetTabPage (id); +} +void TabControl::SetActivatePageHdl (Link const& link) +{ + if (&getImpl () && getImpl().mxTabControl.is ()) + getImpl ().SetActivatePageHdl (link); +} +Link& TabControl::GetActivatePageHdl () const +{ + return getImpl ().GetActivatePageHdl (); +} +void TabControl::SetDeactivatePageHdl (Link const& link) +{ + if (&getImpl () && getImpl().mxTabControl.is ()) + getImpl ().SetDeactivatePageHdl (link); +} +Link& TabControl::GetDeactivatePageHdl () const +{ + return getImpl ().GetDeactivatePageHdl (); +} +void TabControl::SetTabPageSizePixel (Size const& size) +{ + GetTabControl ()->SetTabPageSizePixel (size); +// GetParent()->SetSizePixel (size); +// GetWindow()->SetSizePixel (size); + //GetVCLXTabControl->SetTabSize (size); +} +Size TabControl::GetTabPageSizePixel () const +{ +#if 0 + //return GetTabControl ()->GetTabPageSizePixel (); + static size_t const tab_page_first_index = 1; + for (size_t i = 0; i < GetPageCount (); i++) + { + ::TabPage *p = GetTabPage (i + tab_page_first_index); + //if (dynamic_cast<Windowt*> (p)) + if (i) // URG + return p->GetOptimalSize (WINDOWSIZE_MINIMUM); + } +#endif + return GetTabControl ()->GetTabPageSizePixel (); +} + +IMPL_CONSTRUCTORS (TabControl, Control, "tabcontrol"); +IMPL_GET_IMPL (TabControl); + +class TabPageImpl : public WindowImpl +{ +public: + uno::Reference< awt::XWindow > mxTabPage; + TabPageImpl( Context *context, const PeerHandle &peer, Window *window ) + : WindowImpl( context, peer, window ) + , mxTabPage( peer, uno::UNO_QUERY ) + { + } +}; + +::Window* TabPage::global_parent = 0; +TabControl* TabPage::global_tabcontrol = 0; + +IMPL_GET_IMPL( TabPage ); + +TabPage::TabPage( Window *parent, const char *xml_file, const char *id, sal_uInt32 nId) + : Context( xml_file ) + , Window( new TabPageImpl( this, Context::GetPeerHandle( id, nId ), this ) ) +{ + if ( parent ) + SetParent( parent ); +} + +TabPage::TabPage( ::Window *parent, const char *xml_file, const char *id, sal_uInt32 nId) + : Context( xml_file ) + , Window( new TabPageImpl( this, Context::GetPeerHandle( id, nId ), this ) ) +{ + if ( parent ) + SetParent( parent ); +} + +TabPage::~TabPage() +{ + delete GetTabPage(); +} + +IMPL_GET_WINDOW( TabPage ); + +void TabPage::ActivatePage() +{ +} + +void TabPage::DeactivatePage() +{ +} + +class FixedLineImpl : public ControlImpl +{ +public: + FixedLineImpl( Context *context, const PeerHandle &peer, Window *window ) + : ControlImpl( context, peer, window ) + { + } +}; + +IMPL_CONSTRUCTORS( FixedLine, Control, "hfixedline" ); +IMPL_GET_IMPL( FixedLine ); + +bool FixedLine::IsEnabled() const +{ + //FIXME + return true; +} + +class FixedTextImpl : public ControlImpl +{ +public: + uno::Reference< awt::XFixedText > mxFixedText; + FixedTextImpl( Context *context, const PeerHandle &peer, Window *window ) + : ControlImpl( context, peer, window ) + , mxFixedText( peer, uno::UNO_QUERY ) + { + } + + ~FixedTextImpl (); + + virtual void SAL_CALL disposing( lang::EventObject const& e ) + throw (uno::RuntimeException); +}; + +FixedTextImpl::~FixedTextImpl () +{ +} + +void SAL_CALL FixedTextImpl::disposing( lang::EventObject const& e ) + throw (uno::RuntimeException) +{ + ControlImpl::disposing (e); + mxFixedText.clear (); +} + +FixedText::~FixedText () +{ +} + +IMPL_CONSTRUCTORS( FixedText, Control, "fixedtext" ); +IMPL_GET_IMPL( FixedText ); + +void FixedText::SetText( OUString const& rStr ) +{ + if ( !getImpl().mxFixedText.is() ) + return; + getImpl().mxFixedText->setText( rStr ); +} + +class FixedInfoImpl : public FixedTextImpl +{ +public: + FixedInfoImpl( Context *context, const PeerHandle &peer, Window *window ) + : FixedTextImpl( context, peer, window ) + { + } +}; + +IMPL_CONSTRUCTORS( FixedInfo, FixedText, "fixedinfo" ); +IMPL_GET_IMPL( FixedInfo ); + +class ProgressBarImpl : public ControlImpl +{ +public: + uno::Reference< awt::XProgressBar > mxProgressBar; + ProgressBarImpl( Context *context, const PeerHandle &peer, Window *window ) + : ControlImpl( context, peer, window ) + , mxProgressBar( peer, uno::UNO_QUERY ) + { + } + + virtual void SAL_CALL disposing( lang::EventObject const& e ) + throw (uno::RuntimeException) + { + ControlImpl::disposing (e); + mxProgressBar.clear (); + } +}; + + +class FixedImageImpl: public ControlImpl +{ +public: + uno::Reference< graphic::XGraphic > mxGraphic; + FixedImageImpl( Context *context, const PeerHandle &peer, Window *window) +// const char *pName ) + : ControlImpl( context, peer, window ) + //, mxGraphic( layoutimpl::loadGraphic( pName ) ) + , mxGraphic( peer, uno::UNO_QUERY ) + { + if ( !mxGraphic.is() ) + { + DBG_ERROR( "ERROR: failed to load image: `%s'" /*, pName*/ ); + } +#if 0 + else + getImpl().mxGraphic->...(); +#endif + } +}; + +IMPL_CONSTRUCTORS( FixedImage, Control, "fixedimage" ); +IMPL_GET_IMPL( FixedImage ) + +void FixedImage::setImage( ::Image const& i ) +{ + (void) i; + if ( !getImpl().mxGraphic.is() ) + return; + //FIXME: hack moved to proplist + //getImpl().mxGraphic = +} + +#if 0 + +FixedImage::FixedImage( const char *pName ) + : pImpl( new FixedImageImpl( pName ) ) +{ +} + +FixedImage::~FixedImage() +{ + delete pImpl; +} + +#endif + + +IMPL_CONSTRUCTORS( ProgressBar, Control, "ProgressBar" ); +IMPL_GET_IMPL( ProgressBar ); + +void ProgressBar::SetForegroundColor( util::Color color ) +{ + if ( !getImpl().mxProgressBar.is() ) + return; + getImpl().mxProgressBar->setForegroundColor( color ); +} + +void ProgressBar::SetBackgroundColor( util::Color color ) +{ + if ( !getImpl().mxProgressBar.is() ) + return; + getImpl().mxProgressBar->setBackgroundColor( color ); +} + +void ProgressBar::SetValue( sal_Int32 i ) +{ + if ( !getImpl().mxProgressBar.is() ) + return; + getImpl().mxProgressBar->setValue( i ); +} + +void ProgressBar::SetRange( sal_Int32 min, sal_Int32 max ) +{ + if ( !getImpl().mxProgressBar.is() ) + return; + getImpl().mxProgressBar->setRange( min, max ); +} + +sal_Int32 ProgressBar::GetValue() +{ + if ( !getImpl().mxProgressBar.is() ) + return 0; + return getImpl().mxProgressBar->getValue(); +} + +class PluginImpl: public ControlImpl +{ +public: + ::Control *mpPlugin; + + PluginImpl( Context *context, const PeerHandle &peer, Window *window, :: Control *plugin ) + : ControlImpl( context, peer, window ) + , mpPlugin( plugin ) + { + uno::Reference <awt::XWindow> ref( mxWindow, uno::UNO_QUERY ); + layoutimpl::VCLXPlugin *vcl + = static_cast<layoutimpl::VCLXPlugin*>( VCLXWindow::GetImplementation( ref ) ); + ::Window *parent = vcl->mpWindow->GetParent(); + vcl->SetWindow( plugin ); + vcl->SetPlugin( mpPlugin ); + plugin->SetParent( parent ); + plugin->SetStyle( vcl->mStyle ); + plugin->SetCreatedWithToolkit( true ); + plugin->SetComponentInterface( vcl ); + plugin->Show(); + } +}; + +Plugin::Plugin( Context *context, char const *id, ::Control *plugin ) + : Control( new PluginImpl( context, context->GetPeerHandle( id, 0 ), this, plugin ) ) + , mpPlugin( plugin ) +{ +} + +IMPL_GET_IMPL( Plugin ); + +class LocalizedStringImpl : public WindowImpl +{ +public: + layoutimpl::LocalizedString *mpString; + OUString maString; + LocalizedStringImpl( Context *context, const PeerHandle &peer, Window *window ) + : WindowImpl( context, peer, window ) + , mpString( static_cast<layoutimpl::LocalizedString*>( VCLXWindow::GetImplementation( uno::Reference <awt::XWindow> ( mxWindow, uno::UNO_QUERY ) ) ) ) + , maString () + { + } + OUString getText() + { + if (mpString) + maString = mpString->getText (); + return maString; + } + void setText( OUString const& s ) + { + if (mpString) + mpString->setText( s ); + } +}; + +IMPL_GET_IMPL( LocalizedString ); + +LocalizedString::LocalizedString( Context *context, char const* id ) + : Window( new LocalizedStringImpl( context, context->GetPeerHandle( id, 0 ), this ) ) +{ +} + +String LocalizedString::getString () +{ + return getImpl ().getText (); +} + +OUString LocalizedString::getOUString () +{ + return getImpl ().getText (); +} + +LocalizedString::operator OUString () +{ + return getOUString (); +} + +LocalizedString::operator OUString const& () +{ + getOUString (); + return getImpl ().maString; +} + +LocalizedString::operator String() +{ + getOUString (); + return getImpl ().maString; +} + +String LocalizedString::GetToken (USHORT i, sal_Char c) +{ + return getString ().GetToken (i, c); +} + +OUString LocalizedString::operator= (OUString const& s) +{ + getImpl().setText( s ); + return getImpl().getText(); +} + +OUString LocalizedString::operator+= (OUString const& b) +{ + OUString a = getImpl ().getText (); + a += b; + getImpl ().setText (a); + return getImpl ().getText (); +} + +OUString LocalizedString::operator+= (sal_Unicode const b) +{ + String a = getImpl ().getText (); + a += b; + getImpl ().setText (a); + return getImpl ().getText (); +} + +class InPlugImpl : public WindowImpl +{ +public: + InPlugImpl (Context *context, const PeerHandle &peer, Window *window) + : WindowImpl (context, peer, window) + { + } +}; + +IMPL_GET_IMPL (InPlug); + +static char const *FIXME_set_parent (::Window *parent, char const *xml_file) +{ + layout::TabPage::global_parent = parent; + return xml_file; +} + +InPlug::InPlug (Window *parent, char const* xml_file, char const* id, sal_uInt32 nId) + : Context (FIXME_set_parent (parent ? parent->GetWindow () : 0, xml_file)) + , layout::Window (new InPlugImpl (this, Context::GetPeerHandle (id, nId), this)) +{ + if (parent) + SetParent (parent); + if (::Window *w = dynamic_cast< ::Window* > (this)) + w->SetComponentInterface (GetVCLXWindow ()); +} + +InPlug::InPlug (::Window *parent, char const* xml_file, char const* id, sal_uInt32 nId) + : Context (FIXME_set_parent (parent, xml_file)) + , layout::Window (new InPlugImpl (this, Context::GetPeerHandle (id, nId), this)) +{ + if (parent) + layout::Window::SetParent (parent); + if (::Window *w = dynamic_cast< ::Window* > (this)) + w->SetComponentInterface (GetVCLXWindow ()); +} + +void InPlug::ParentSet (Window *window) +{ + window->SetParent (dynamic_cast< ::Window* > (this)); + + /// FIXME: for standalone run of layout::SfxTabDialog + SetParent (window->GetParent ()); +} + +} // namespace layout diff --git a/toolkit/source/layout/vcl/wrapper.hxx b/toolkit/source/layout/vcl/wrapper.hxx new file mode 100644 index 000000000000..2f7e24211150 --- /dev/null +++ b/toolkit/source/layout/vcl/wrapper.hxx @@ -0,0 +1,149 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef LAYOUT_VCL_WRAPPER_HXX +#define LAYOUT_VCL_WRAPPER_HXX + +#include <layout/layout.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/awt/XDialog2.hpp> +#include <com/sun/star/awt/XFocusListener.hpp> +#include <com/sun/star/awt/XWindow.hpp> +#include <com/sun/star/awt/XVclWindowPeer.hpp> +#include <cppuhelper/implbase1.hxx> + +#include <cstring> + +namespace layout +{ + +namespace css = com::sun::star; + +class WindowImpl +{ +public: + Window *mpWindow; + Context *mpCtx; + css::uno::Reference< css::awt::XWindow > mxWindow; + css::uno::Reference< css::awt::XVclWindowPeer > mxVclPeer; + ::Window *mvclWindow; + bool bFirstTimeVisible; + + WindowImpl (Context *context, PeerHandle const &peer, Window *window); + virtual ~WindowImpl (); + + void wrapperGone(); + css::uno::Any getProperty (char const *name); + void setProperty (char const *name, css::uno::Any any); + void redraw (bool resize=false); + + // XFocusListener + virtual void SAL_CALL disposing (css::lang::EventObject const&) throw (css::uno::RuntimeException); +}; + +class ControlImpl : public WindowImpl + , public ::cppu::WeakImplHelper1 <css::awt::XFocusListener> +{ +public: + Link mGetFocusHdl; + Link mLoseFocusHdl; + + ControlImpl( Context *context, PeerHandle const& peer, Window *window ); + ~ControlImpl (); + + virtual void SetGetFocusHdl (Link const& link); + Link& GetGetFocusHdl (); + virtual void SetLoseFocusHdl (Link const& link); + Link& GetLoseFocusHdl (); + virtual void UpdateListening (Link const& link); + + // XFocusListener + virtual void SAL_CALL disposing (css::lang::EventObject const&) throw (css::uno::RuntimeException); + void SAL_CALL focusGained (css::awt::FocusEvent const& e) throw (css::uno::RuntimeException); + void SAL_CALL focusLost (css::awt::FocusEvent const& e) throw (css::uno::RuntimeException); +}; + +inline WindowImpl &Window::getImpl() const{ return *(static_cast< WindowImpl * >( mpImpl )); } + +// Helpers for defining boiler-plate constructors ... +// Could in-line in top-level but not with safe static_casts. +#define IMPL_GET_IMPL(t) \ + inline t##Impl &t::getImpl() const \ + { \ + return *(static_cast<t##Impl *>(mpImpl)); \ + } +#define IMPL_CONSTRUCTORS_BODY(t,par,unoName,body) \ + t::t( Context *context, const char *pId, sal_uInt32 nId ) \ + : par( new t##Impl( context, context->GetPeerHandle( pId, nId ), this ) ) \ + { \ + Window *parent = dynamic_cast<Window*> (context);\ + body;\ + if (parent)\ + SetParent (parent);\ + } \ + t::t( Window *parent, WinBits bits) \ + : par( new t##Impl( parent->getContext(), Window::CreatePeer( parent, bits, unoName ), this ) ) \ + { \ + body;\ + if ( parent )\ + SetParent (parent);\ + } \ + t::t( Window *parent, ResId const& res) \ + : par( new t##Impl( parent->getContext(), Window::CreatePeer( parent, 0, unoName ), this ) ) \ + { \ + body;\ + setRes (res);\ + if (parent)\ + SetParent (parent);\ + } +#define IMPL_CONSTRUCTORS(t,par,unoName) IMPL_CONSTRUCTORS_BODY(t, par, unoName, ) +#define IMPL_CONSTRUCTORS_2(t,win_par,other_par,unoName) \ + t::t( Context *context, const char *pId, sal_uInt32 nId ) \ + : win_par( new t##Impl( context, context->GetPeerHandle( pId, nId ), this ) ) \ + , other_par( new other_par##Impl( Window::GetPeer() ) ) \ + { \ + } \ + t::t( Window *parent, WinBits bits) \ + : win_par( new t##Impl( parent->getContext(), Window::CreatePeer( parent, bits, unoName ), this ) ) \ + , other_par( new other_par##Impl( Window::GetPeer() ) ) \ + { \ + } + +#define IMPL_IMPL(t, parent) \ + class t##Impl : public parent##Impl \ + { \ + public: \ + t##Impl( Context *context, PeerHandle const& peer, Window *window ) \ + : parent##Impl( context, peer, window ) \ + { \ + } \ + }; + + +} // namespace layout + +#endif /* LAYOUT_VCL_WRAPPER_HXX */ |