diff options
Diffstat (limited to 'forms/source/solar')
-rw-r--r-- | forms/source/solar/component/makefile.mk | 51 | ||||
-rw-r--r-- | forms/source/solar/component/navbarcontrol.cxx | 564 | ||||
-rw-r--r-- | forms/source/solar/component/navbarcontrol.hxx | 158 | ||||
-rw-r--r-- | forms/source/solar/control/makefile.mk | 53 | ||||
-rw-r--r-- | forms/source/solar/control/navtoolbar.cxx | 736 | ||||
-rw-r--r-- | forms/source/solar/inc/navtoolbar.hxx | 194 |
6 files changed, 1756 insertions, 0 deletions
diff --git a/forms/source/solar/component/makefile.mk b/forms/source/solar/component/makefile.mk new file mode 100644 index 000000000000..06471405a3e2 --- /dev/null +++ b/forms/source/solar/component/makefile.mk @@ -0,0 +1,51 @@ +#************************************************************************* +# +# 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=..$/..$/.. +PRJINC=$(PRJ)$/source +PRJNAME=forms +TARGET=solarcomponent + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk +.INCLUDE: $(PRJ)$/makefile.pmk + +# --- Types ------------------------------------- + +INCPRE+=$(SOLARINCDIR)$/offuh + +# --- Files ------------------------------------- + +SLOFILES= $(SLO)$/navbarcontrol.obj + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/forms/source/solar/component/navbarcontrol.cxx b/forms/source/solar/component/navbarcontrol.cxx new file mode 100644 index 000000000000..622df5783715 --- /dev/null +++ b/forms/source/solar/component/navbarcontrol.cxx @@ -0,0 +1,564 @@ +/************************************************************************* + * + * 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_forms.hxx" + +#include "navbarcontrol.hxx" +#include "frm_strings.hxx" +#include "frm_module.hxx" +#include "FormComponent.hxx" +#include "componenttools.hxx" +#include "navtoolbar.hxx" +#include "commandimageprovider.hxx" +#include "commanddescriptionprovider.hxx" + +/** === begin UNO includes === **/ +#include <com/sun/star/awt/XView.hpp> +#include <com/sun/star/awt/PosSize.hpp> +#include <com/sun/star/form/runtime/FormFeature.hpp> +#include <com/sun/star/awt/XControlModel.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> +/** === end UNO includes === **/ + +#include <tools/debug.hxx> +#include <tools/diagnose_ex.h> +#include <vcl/svapp.hxx> + +//-------------------------------------------------------------------------- +extern "C" void SAL_CALL createRegistryInfo_ONavigationBarControl() +{ + static ::frm::OMultiInstanceAutoRegistration< ::frm::ONavigationBarControl > aAutoRegistration; +} + +//......................................................................... +namespace frm +{ +//......................................................................... + + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::beans; + using namespace ::com::sun::star::awt; + using namespace ::com::sun::star::lang; + using namespace ::com::sun::star::frame; + using namespace ::com::sun::star::graphic; + namespace FormFeature = ::com::sun::star::form::runtime::FormFeature; + +#define FORWARD_TO_PEER_1( unoInterface, method, param1 ) \ + Reference< unoInterface > xTypedPeer( getPeer(), UNO_QUERY ); \ + if ( xTypedPeer.is() ) \ + { \ + xTypedPeer->method( param1 ); \ + } + +#define FORWARD_TO_PEER_1_RET( returnType, unoInterface, method, param1 ) \ + returnType aReturn; \ + Reference< unoInterface > xTypedPeer( getPeer(), UNO_QUERY ); \ + if ( xTypedPeer.is() ) \ + { \ + aReturn = xTypedPeer->method( param1 ); \ + } \ + return aReturn; + +#define FORWARD_TO_PEER_3( unoInterface, method, param1, param2, param3 ) \ + Reference< unoInterface > xTypedPeer( getPeer(), UNO_QUERY ); \ + if ( xTypedPeer.is() ) \ + { \ + xTypedPeer->method( param1, param2, param3 ); \ + } + +#define FORWARD_TO_PEER_3_RET( returnType, unoInterface, method, param1, param2, param3 ) \ + returnType aReturn; \ + Reference< unoInterface > xTypedPeer( getPeer(), UNO_QUERY ); \ + if ( xTypedPeer.is() ) \ + { \ + aReturn = xTypedPeer->method( param1, param2, param3 ); \ + } \ + return aReturn; + + //================================================================== + // ONavigationBarControl + //================================================================== + DBG_NAME( ONavigationBarControl ) + //------------------------------------------------------------------ + ONavigationBarControl::ONavigationBarControl( const Reference< XMultiServiceFactory >& _rxORB ) + :UnoControl( _rxORB ) + { + DBG_CTOR( ONavigationBarControl, NULL ); + } + + //------------------------------------------------------------------ + ONavigationBarControl::~ONavigationBarControl() + { + DBG_DTOR( ONavigationBarControl, NULL ); + } + + //------------------------------------------------------------------ + IMPLEMENT_FORWARD_XTYPEPROVIDER2( ONavigationBarControl, UnoControl, ONavigationBarControl_Base ) + + //------------------------------------------------------------------ + Any SAL_CALL ONavigationBarControl::queryAggregation( const Type& _rType ) throw ( RuntimeException ) + { + Any aReturn = UnoControl::queryAggregation( _rType ); + + if ( !aReturn.hasValue() ) + aReturn = ONavigationBarControl_Base::queryInterface( _rType ); + + return aReturn; + } + + //------------------------------------------------------------------ + namespace + { + //.............................................................. + static WinBits lcl_getWinBits_nothrow( const Reference< XControlModel >& _rxModel ) + { + WinBits nBits = 0; + try + { + Reference< XPropertySet > xProps( _rxModel, UNO_QUERY ); + if ( xProps.is() ) + { + sal_Int16 nBorder = 0; + xProps->getPropertyValue( PROPERTY_BORDER ) >>= nBorder; + if ( nBorder ) + nBits |= WB_BORDER; + + sal_Bool bTabStop = sal_False; + if ( xProps->getPropertyValue( PROPERTY_TABSTOP ) >>= bTabStop ) + nBits |= ( bTabStop ? WB_TABSTOP : WB_NOTABSTOP ); + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return nBits; + } + } + + //------------------------------------------------------------------ + void SAL_CALL ONavigationBarControl::createPeer( const Reference< XToolkit >& /*_rToolkit*/, const Reference< XWindowPeer >& _rParentPeer ) throw( RuntimeException ) + { + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + if (!getPeer().is()) + { + mbCreatingPeer = sal_True; + + // determine the VLC window for the parent + Window* pParentWin = NULL; + if ( _rParentPeer.is() ) + { + VCLXWindow* pParentXWin = VCLXWindow::GetImplementation( _rParentPeer ); + if ( pParentXWin ) + pParentWin = pParentXWin->GetWindow(); + DBG_ASSERT( pParentWin, "ONavigationBarControl::createPeer: could not obtain the VCL-level parent window!" ); + } + + // create the peer + ONavigationBarPeer* pPeer = ONavigationBarPeer::Create( maContext.getLegacyServiceFactory(), pParentWin, getModel() ); + DBG_ASSERT( pPeer, "ONavigationBarControl::createPeer: invalid peer returned!" ); + if ( pPeer ) + // by definition, the returned component is aquired once + pPeer->release(); + + // announce the peer to the base class + setPeer( pPeer ); + + // initialize ourself (and thus the peer) with the model properties + updateFromModel(); + + Reference< XView > xPeerView( getPeer(), UNO_QUERY ); + if ( xPeerView.is() ) + { + xPeerView->setZoom( maComponentInfos.nZoomX, maComponentInfos.nZoomY ); + xPeerView->setGraphics( mxGraphics ); + } + + // a lot of initial settings from our component infos + setPosSize( maComponentInfos.nX, maComponentInfos.nY, maComponentInfos.nWidth, maComponentInfos.nHeight, PosSize::POSSIZE ); + + pPeer->setVisible ( maComponentInfos.bVisible && !mbDesignMode ); + pPeer->setEnable ( maComponentInfos.bEnable ); + pPeer->setDesignMode( mbDesignMode ); + + peerCreated(); + + mbCreatingPeer = sal_False; + + OControl::initFormControlPeer( getPeer() ); + } + } + + //------------------------------------------------------------------ + ::rtl::OUString SAL_CALL ONavigationBarControl::getImplementationName() throw( RuntimeException ) + { + return getImplementationName_Static(); + } + + //------------------------------------------------------------------ + Sequence< ::rtl::OUString > SAL_CALL ONavigationBarControl::getSupportedServiceNames() throw( RuntimeException ) + { + return getSupportedServiceNames_Static(); + } + + //------------------------------------------------------------------ + ::rtl::OUString SAL_CALL ONavigationBarControl::getImplementationName_Static() + { + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.form.ONavigationBarControl" ) ); + } + + //------------------------------------------------------------------ + Sequence< ::rtl::OUString > SAL_CALL ONavigationBarControl::getSupportedServiceNames_Static() + { + Sequence< ::rtl::OUString > aServices( 2 ); + aServices[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControl" ) ); + aServices[ 1 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.control.NavigationToolBar" ) ); + return aServices; + } + + //------------------------------------------------------------------ + Reference< XInterface > SAL_CALL ONavigationBarControl::Create( const Reference< XMultiServiceFactory >& _rxFactory ) + { + return *( new ONavigationBarControl( _rxFactory ) ); + } + + //------------------------------------------------------------------ + void SAL_CALL ONavigationBarControl::registerDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException) + { + FORWARD_TO_PEER_1( XDispatchProviderInterception, registerDispatchProviderInterceptor, _rxInterceptor ); + } + + //------------------------------------------------------------------ + void SAL_CALL ONavigationBarControl::releaseDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException) + { + FORWARD_TO_PEER_1( XDispatchProviderInterception, releaseDispatchProviderInterceptor, _rxInterceptor ); + } + + //------------------------------------------------------------------ + void SAL_CALL ONavigationBarControl::setDesignMode( sal_Bool _bOn ) throw( RuntimeException ) + { + UnoControl::setDesignMode( _bOn ); + FORWARD_TO_PEER_1( XVclWindowPeer, setDesignMode, _bOn ); + } + + //================================================================== + // ONavigationBarPeer + //================================================================== + DBG_NAME( ONavigationBarPeer ) + //------------------------------------------------------------------ + ONavigationBarPeer* ONavigationBarPeer::Create( const Reference< XMultiServiceFactory >& _rxORB, + Window* _pParentWindow, const Reference< XControlModel >& _rxModel ) + { + DBG_TESTSOLARMUTEX(); + + // the peer itself + ONavigationBarPeer* pPeer = new ONavigationBarPeer( _rxORB ); + pPeer->acquire(); // by definition, the returned object is aquired once + + // the VCL control for the peer + Reference< XModel > xContextDocument( getXModel( _rxModel ) ); + NavigationToolBar* pNavBar = new NavigationToolBar( + _pParentWindow, + lcl_getWinBits_nothrow( _rxModel ), + createDocumentCommandImageProvider( _rxORB, xContextDocument ), + createDocumentCommandDescriptionProvider( _rxORB, xContextDocument ) + ); + + // some knittings + pNavBar->setDispatcher( pPeer ); + pNavBar->SetComponentInterface( pPeer ); + + // we want a faster repeating rate for the slots in this + // toolbox + AllSettings aSettings = pNavBar->GetSettings(); + MouseSettings aMouseSettings = aSettings.GetMouseSettings(); + aMouseSettings.SetButtonRepeat( 10 ); + aSettings.SetMouseSettings( aMouseSettings ); + pNavBar->SetSettings( aSettings, sal_True ); + + // outta here + return pPeer; + } + + //------------------------------------------------------------------ + ONavigationBarPeer::ONavigationBarPeer( const Reference< XMultiServiceFactory >& _rxORB ) + :OFormNavigationHelper( _rxORB ) + { + DBG_CTOR( ONavigationBarPeer, NULL ); + } + + //------------------------------------------------------------------ + ONavigationBarPeer::~ONavigationBarPeer() + { + DBG_DTOR( ONavigationBarPeer, NULL ); + } + + //------------------------------------------------------------------ + IMPLEMENT_FORWARD_XINTERFACE2( ONavigationBarPeer, VCLXWindow, OFormNavigationHelper ) + + //------------------------------------------------------------------ + IMPLEMENT_FORWARD_XTYPEPROVIDER2( ONavigationBarPeer, VCLXWindow, OFormNavigationHelper ) + + //------------------------------------------------------------------ + void SAL_CALL ONavigationBarPeer::dispose( ) throw( RuntimeException ) + { + VCLXWindow::dispose(); + OFormNavigationHelper::dispose(); + } + + //------------------------------------------------------------------ + void SAL_CALL ONavigationBarPeer::setProperty( const ::rtl::OUString& _rPropertyName, const Any& _rValue ) throw( RuntimeException ) + { + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + NavigationToolBar* pNavBar = static_cast< NavigationToolBar* >( GetWindow() ); + if ( !pNavBar ) + { + VCLXWindow::setProperty( _rPropertyName, _rValue ); + return; + } + + bool bVoid = !_rValue.hasValue(); + + sal_Bool bBoolValue = sal_False; + sal_Int32 nColor = COL_TRANSPARENT; + + // TODO: more generic mechanisms for this (the grid control implementation, + // when used herein, will do the same stuff for lot of these) + + if ( _rPropertyName.equals( PROPERTY_BACKGROUNDCOLOR ) ) + { + Wallpaper aTest = pNavBar->GetBackground(); + if ( bVoid ) + { + pNavBar->SetBackground( pNavBar->GetSettings().GetStyleSettings().GetFaceColor() ); + pNavBar->SetControlBackground(); + } + else + { + OSL_VERIFY( _rValue >>= nColor ); + Color aColor( nColor ); + pNavBar->SetBackground( aColor ); + pNavBar->SetControlBackground( aColor ); + } + } + else if ( _rPropertyName.equals( PROPERTY_TEXTLINECOLOR ) ) + { + if ( bVoid ) + { + pNavBar->SetTextLineColor(); + } + else + { + OSL_VERIFY( _rValue >>= nColor ); + Color aColor( nColor ); + pNavBar->SetTextLineColor( nColor ); + } + } + else if ( _rPropertyName.equals( PROPERTY_ICONSIZE ) ) + { + sal_Int16 nInt16Value = 0; + OSL_VERIFY( _rValue >>= nInt16Value ); + pNavBar->SetImageSize( nInt16Value ? NavigationToolBar::eLarge : NavigationToolBar::eSmall ); + } + else if ( _rPropertyName.equals( PROPERTY_SHOW_POSITION ) ) + { + OSL_VERIFY( _rValue >>= bBoolValue ); + pNavBar->ShowFunctionGroup( NavigationToolBar::ePosition, bBoolValue ); + } + else if ( _rPropertyName.equals( PROPERTY_SHOW_NAVIGATION ) ) + { + OSL_VERIFY( _rValue >>= bBoolValue ); + pNavBar->ShowFunctionGroup( NavigationToolBar::eNavigation, bBoolValue ); + } + else if ( _rPropertyName.equals( PROPERTY_SHOW_RECORDACTIONS ) ) + { + OSL_VERIFY( _rValue >>= bBoolValue ); + pNavBar->ShowFunctionGroup( NavigationToolBar::eRecordActions, bBoolValue ); + } + else if ( _rPropertyName.equals( PROPERTY_SHOW_FILTERSORT ) ) + { + OSL_VERIFY( _rValue >>= bBoolValue ); + pNavBar->ShowFunctionGroup( NavigationToolBar::eFilterSort, bBoolValue ); + } + else + { + VCLXWindow::setProperty( _rPropertyName, _rValue ); + } + } + + //------------------------------------------------------------------ + Any SAL_CALL ONavigationBarPeer::getProperty( const ::rtl::OUString& _rPropertyName ) throw( RuntimeException ) + { + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + Any aReturn; + NavigationToolBar* pNavBar = static_cast< NavigationToolBar* >( GetWindow() ); + + if ( _rPropertyName.equals( PROPERTY_BACKGROUNDCOLOR ) ) + { + aReturn <<= (sal_Int32)pNavBar->GetControlBackground().GetColor(); + } + else if ( _rPropertyName.equals( PROPERTY_TEXTLINECOLOR ) ) + { + aReturn <<= (sal_Int32)pNavBar->GetTextLineColor().GetColor(); + } + else if ( _rPropertyName.equals( PROPERTY_ICONSIZE ) ) + { + sal_Int16 nIconType = ( NavigationToolBar::eLarge == pNavBar->GetImageSize() ) + ? 1 : 0; + aReturn <<= nIconType; + } + else if ( _rPropertyName.equals( PROPERTY_SHOW_POSITION ) ) + { + aReturn <<= (sal_Bool)( pNavBar->IsFunctionGroupVisible( NavigationToolBar::ePosition ) ); + } + else if ( _rPropertyName.equals( PROPERTY_SHOW_NAVIGATION ) ) + { + aReturn <<= (sal_Bool)( pNavBar->IsFunctionGroupVisible( NavigationToolBar::eNavigation ) ); + } + else if ( _rPropertyName.equals( PROPERTY_SHOW_RECORDACTIONS ) ) + { + aReturn <<= (sal_Bool)( pNavBar->IsFunctionGroupVisible( NavigationToolBar::eRecordActions ) ); + } + else if ( _rPropertyName.equals( PROPERTY_SHOW_FILTERSORT ) ) + { + aReturn <<= (sal_Bool)( pNavBar->IsFunctionGroupVisible( NavigationToolBar::eFilterSort ) ); + } + else + aReturn = VCLXWindow::getProperty( _rPropertyName ); + + return aReturn; + } + + //------------------------------------------------------------------ + void ONavigationBarPeer::interceptorsChanged( ) + { + if ( isDesignMode() ) + // not interested in if we're in design mode + return; + + OFormNavigationHelper::interceptorsChanged(); + } + + //------------------------------------------------------------------ + void ONavigationBarPeer::featureStateChanged( sal_Int16 _nFeatureId, sal_Bool _bEnabled ) + { + // enable this button on the toolbox + NavigationToolBar* pNavBar = static_cast< NavigationToolBar* >( GetWindow() ); + if ( pNavBar ) + { + pNavBar->enableFeature( _nFeatureId, _bEnabled ); + + // is it a feature with additional state information? + if ( _nFeatureId == FormFeature::ToggleApplyFilter ) + { // additional boolean state + pNavBar->checkFeature( _nFeatureId, getBooleanState( _nFeatureId ) ); + } + else if ( _nFeatureId == FormFeature::TotalRecords ) + { + pNavBar->setFeatureText( _nFeatureId, getStringState( _nFeatureId ) ); + } + else if ( _nFeatureId == FormFeature::MoveAbsolute ) + { + pNavBar->setFeatureText( _nFeatureId, String::CreateFromInt32( getIntegerState( _nFeatureId ) ) ); + } + } + + // base class + OFormNavigationHelper::featureStateChanged( _nFeatureId, _bEnabled ); + } + + //------------------------------------------------------------------ + void ONavigationBarPeer::allFeatureStatesChanged( ) + { + // force the control to update it's states + NavigationToolBar* pNavBar = static_cast< NavigationToolBar* >( GetWindow() ); + if ( pNavBar ) + pNavBar->setDispatcher( this ); + + // base class + OFormNavigationHelper::allFeatureStatesChanged( ); + } + + //------------------------------------------------------------------ + bool ONavigationBarPeer::isEnabled( sal_Int16 _nFeatureId ) const + { + if ( const_cast< ONavigationBarPeer* >( this )->isDesignMode() ) + return false; + + return OFormNavigationHelper::isEnabled( _nFeatureId ); + } + + //------------------------------------------------------------------ + void SAL_CALL ONavigationBarPeer::setDesignMode( sal_Bool _bOn ) throw( RuntimeException ) + { + VCLXWindow::setDesignMode( _bOn ); + + if ( _bOn ) + disconnectDispatchers(); + else + connectDispatchers(); + // this will connect if not already connected and just update else + } + + //------------------------------------------------------------------ + void SAL_CALL ONavigationBarPeer::disposing( const EventObject& _rSource ) throw (RuntimeException) + { + VCLXWindow::disposing( _rSource ); + OFormNavigationHelper::disposing( _rSource ); + } + + //------------------------------------------------------------------ + void ONavigationBarPeer::getSupportedFeatures( ::std::vector< sal_Int16 >& _rFeatureIds ) + { + _rFeatureIds.push_back( FormFeature::MoveAbsolute ); + _rFeatureIds.push_back( FormFeature::TotalRecords ); + _rFeatureIds.push_back( FormFeature::MoveToFirst ); + _rFeatureIds.push_back( FormFeature::MoveToPrevious ); + _rFeatureIds.push_back( FormFeature::MoveToNext ); + _rFeatureIds.push_back( FormFeature::MoveToLast ); + _rFeatureIds.push_back( FormFeature::SaveRecordChanges ); + _rFeatureIds.push_back( FormFeature::UndoRecordChanges ); + _rFeatureIds.push_back( FormFeature::MoveToInsertRow ); + _rFeatureIds.push_back( FormFeature::DeleteRecord ); + _rFeatureIds.push_back( FormFeature::ReloadForm ); + _rFeatureIds.push_back( FormFeature::RefreshCurrentControl ); + _rFeatureIds.push_back( FormFeature::SortAscending ); + _rFeatureIds.push_back( FormFeature::SortDescending ); + _rFeatureIds.push_back( FormFeature::InteractiveSort ); + _rFeatureIds.push_back( FormFeature::AutoFilter ); + _rFeatureIds.push_back( FormFeature::InteractiveFilter ); + _rFeatureIds.push_back( FormFeature::ToggleApplyFilter ); + _rFeatureIds.push_back( FormFeature::RemoveFilterAndSort ); + } + +//......................................................................... +} // namespace frm +//......................................................................... diff --git a/forms/source/solar/component/navbarcontrol.hxx b/forms/source/solar/component/navbarcontrol.hxx new file mode 100644 index 000000000000..877aa55aaba2 --- /dev/null +++ b/forms/source/solar/component/navbarcontrol.hxx @@ -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. + * + ************************************************************************/ + +#ifndef FORMS_NAVBARCONTROL_HXX +#define FORMS_NAVBARCONTROL_HXX + +#include "formnavigation.hxx" + +/** === begin UNO includes === **/ +#include <com/sun/star/frame/XDispatchProviderInterception.hpp> +#include <com/sun/star/frame/XStatusListener.hpp> +/** === end UNO includes === **/ + +#include <toolkit/controls/unocontrol.hxx> +#include <toolkit/awt/vclxwindow.hxx> +#include <comphelper/uno3.hxx> +#include <cppuhelper/implbase1.hxx> +#include <tools/wintypes.hxx> + +//......................................................................... +namespace frm +{ +//......................................................................... + + //================================================================== + // ONavigationBarControl + //================================================================== + typedef ::cppu::ImplHelper1 < ::com::sun::star::frame::XDispatchProviderInterception + > ONavigationBarControl_Base; + + class ONavigationBarControl + :public UnoControl + ,public ONavigationBarControl_Base + { + public: + ONavigationBarControl( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB + ); + + protected: + ~ONavigationBarControl(); + + public: + // XServiceInfo - static version + static ::rtl::OUString SAL_CALL getImplementationName_Static(); + static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_Static(); + static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL Create( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory ); + + protected: + // UNO + DECLARE_UNO3_AGG_DEFAULTS( ONavigationBarControl, UnoControl ); + virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw ( ::com::sun::star::uno::RuntimeException ); + + // XControl + virtual void SAL_CALL createPeer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit >& _rToolkit, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& _rParent ) throw( ::com::sun::star::uno::RuntimeException ); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException); + + // XTypeProvider + DECLARE_XTYPEPROVIDER() + + // XVclWindowPeer + virtual void SAL_CALL setDesignMode( sal_Bool _bOn ) throw( ::com::sun::star::uno::RuntimeException ); + + // XDispatchProviderInterception + virtual void SAL_CALL registerDispatchProviderInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& Interceptor ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL releaseDispatchProviderInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& Interceptor ) throw (::com::sun::star::uno::RuntimeException); + }; + + //================================================================== + // ONavigationBarPeer + //================================================================== + class ONavigationBarPeer + :public VCLXWindow + ,public OFormNavigationHelper + { + public: + /** factory method + @return + a new ONavigationBarPeer instance, which has been aquired once! + */ + static ONavigationBarPeer* Create( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, + Window* _pParentWindow, + const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& _rxModel + ); + + protected: + ONavigationBarPeer( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB + ); + ~ONavigationBarPeer(); + + public: + // XInterface + DECLARE_XINTERFACE( ) + + // XVclWindowPeer + virtual void SAL_CALL setDesignMode( sal_Bool _bOn ) throw( ::com::sun::star::uno::RuntimeException ); + + // XWindow2 + using VCLXWindow::isEnabled; + + protected: + // XTypeProvider + DECLARE_XTYPEPROVIDER( ) + + // XComponent + void SAL_CALL dispose( ) throw( ::com::sun::star::uno::RuntimeException ); + + // XVclWindowPeer + void SAL_CALL setProperty( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Any& _rValue ) throw( ::com::sun::star::uno::RuntimeException ); + ::com::sun::star::uno::Any SAL_CALL getProperty( const ::rtl::OUString& _rPropertyName ) throw(::com::sun::star::uno::RuntimeException); + + // XEventListener + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); + + // OFormNavigationHelper overriables + virtual void interceptorsChanged( ); + virtual void featureStateChanged( sal_Int16 _nFeatureId, sal_Bool _bEnabled ); + virtual void allFeatureStatesChanged( ); + virtual void getSupportedFeatures( ::std::vector< sal_Int16 >& /* [out] */ _rFeatureIds ); + + // IFeatureDispatcher overriables + virtual bool isEnabled( sal_Int16 _nFeatureId ) const; + }; + +//......................................................................... +} // namespace frm +//......................................................................... + +#endif // FORMS_NAVBARCONTROL_HXX diff --git a/forms/source/solar/control/makefile.mk b/forms/source/solar/control/makefile.mk new file mode 100644 index 000000000000..906f5938d596 --- /dev/null +++ b/forms/source/solar/control/makefile.mk @@ -0,0 +1,53 @@ +#************************************************************************* +# +# 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=..$/..$/.. +PRJINC=$(PRJ)$/source +PRJNAME=forms +TARGET=solarcontrol + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk +.INCLUDE: $(PRJ)$/makefile.pmk + +# --- Types ------------------------------------- + +INCPRE+=$(SOLARINCDIR)$/offuh + +# --- Files ------------------------------------- + +CXXFILES= navtoolbar.cxx \ + +SLOFILES= $(SLO)$/navtoolbar.obj \ + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/forms/source/solar/control/navtoolbar.cxx b/forms/source/solar/control/navtoolbar.cxx new file mode 100644 index 000000000000..a24d07e28ba5 --- /dev/null +++ b/forms/source/solar/control/navtoolbar.cxx @@ -0,0 +1,736 @@ +/************************************************************************* + * + * 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_forms.hxx" + +#include "navtoolbar.hxx" +#include "frm_resource.hxx" +#include "featuredispatcher.hxx" +#include "frm_resource.hrc" +#include "commandimageprovider.hxx" +#include "commanddescriptionprovider.hxx" + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/form/runtime/FormFeature.hpp> + +#include <sfx2/imgmgr.hxx> +#include <vcl/fixed.hxx> + +#include <memory> + +#define LID_RECORD_LABEL 1000 +#define LID_RECORD_FILLER 1001 + +//......................................................................... +namespace frm +{ +//......................................................................... + + using ::com::sun::star::uno::makeAny; + namespace FormFeature = ::com::sun::star::form::runtime::FormFeature; + + //===================================================================== + //..................................................................... + namespace + { + static bool isArtificialItem( sal_Int16 _nFeatureId ) + { + return ( _nFeatureId == LID_RECORD_LABEL ) + || ( _nFeatureId == LID_RECORD_FILLER ); + } + + static String getLabelString( sal_uInt16 _nResId ) + { + String sLabel = String::CreateFromAscii( " " ); + sLabel += String( FRM_RES_STRING( _nResId ) ); + sLabel += String::CreateFromAscii( " " ); + return sLabel; + } + + ::rtl::OUString lcl_getCommandURL( const sal_Int16 _nFormFeature ) + { + const sal_Char* pAsciiCommandName = NULL; + switch ( _nFormFeature ) + { + case FormFeature::MoveAbsolute : pAsciiCommandName = "AbsoluteRecord"; break; + case FormFeature::TotalRecords : pAsciiCommandName = "RecTotal"; break; + case FormFeature::MoveToFirst : pAsciiCommandName = "FirstRecord"; break; + case FormFeature::MoveToPrevious : pAsciiCommandName = "PrevRecord"; break; + case FormFeature::MoveToNext : pAsciiCommandName = "NextRecord"; break; + case FormFeature::MoveToLast : pAsciiCommandName = "LastRecord"; break; + case FormFeature::SaveRecordChanges : pAsciiCommandName = "RecSave"; break; + case FormFeature::UndoRecordChanges : pAsciiCommandName = "RecUndo"; break; + case FormFeature::MoveToInsertRow : pAsciiCommandName = "NewRecord"; break; + case FormFeature::DeleteRecord : pAsciiCommandName = "DeleteRecord"; break; + case FormFeature::ReloadForm : pAsciiCommandName = "Refresh"; break; + case FormFeature::RefreshCurrentControl : pAsciiCommandName = "RefreshFormControl"; break; + case FormFeature::SortAscending : pAsciiCommandName = "Sortup"; break; + case FormFeature::SortDescending : pAsciiCommandName = "SortDown"; break; + case FormFeature::InteractiveSort : pAsciiCommandName = "OrderCrit"; break; + case FormFeature::AutoFilter : pAsciiCommandName = "AutoFilter"; break; + case FormFeature::InteractiveFilter : pAsciiCommandName = "FilterCrit"; break; + case FormFeature::ToggleApplyFilter : pAsciiCommandName = "FormFiltered"; break; + case FormFeature::RemoveFilterAndSort : pAsciiCommandName = "RemoveFilterSort"; break; + } + if ( pAsciiCommandName != NULL ) + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ) ) + ::rtl::OUString::createFromAscii( pAsciiCommandName ); + + OSL_ENSURE( false, "lcl_getCommandURL: unknown FormFeature!" ); + return ::rtl::OUString(); + } + } + + //===================================================================== + //= ImplNavToolBar + //===================================================================== + class ImplNavToolBar : public ToolBox + { + protected: + const IFeatureDispatcher* m_pDispatcher; + + public: + ImplNavToolBar( Window* _pParent ) + :ToolBox( _pParent, WB_3DLOOK ) + ,m_pDispatcher( NULL ) + { + } + + void setDispatcher( const IFeatureDispatcher* _pDispatcher ) + { + m_pDispatcher = _pDispatcher; + } + + protected: + // ToolBox overridables + virtual void Select(); + + }; + + //--------------------------------------------------------------------- + void ImplNavToolBar::Select() + { + if ( m_pDispatcher ) + { + if ( !m_pDispatcher->isEnabled( GetCurItemId() ) ) + // the toolbox is a little bit buggy: With TIB_REPEAT, it sometimes + // happens that a select is reported, even though the respective + // item has just been disabled. + return; + m_pDispatcher->dispatch( GetCurItemId() ); + } + } + + //===================================================================== + //= NavigationToolBar + //===================================================================== + DBG_NAME( NavigationToolBar ) + //--------------------------------------------------------------------- + NavigationToolBar::NavigationToolBar( Window* _pParent, WinBits _nStyle, const PCommandImageProvider& _pImageProvider, + const PCommandDescriptionProvider& _pDescriptionProvider ) + :Window( _pParent, _nStyle ) + ,m_pDispatcher( NULL ) + ,m_pImageProvider( _pImageProvider ) + ,m_pDescriptionProvider( _pDescriptionProvider ) + ,m_eImageSize( eSmall ) + ,m_pToolbar( NULL ) + { + DBG_CTOR( NavigationToolBar, NULL ); + implInit( ); + } + + //--------------------------------------------------------------------- + NavigationToolBar::~NavigationToolBar( ) + { + for ( ::std::vector< Window* >::iterator loopChildWins = m_aChildWins.begin(); + loopChildWins != m_aChildWins.end(); + ++loopChildWins + ) + { + delete *loopChildWins; + } + delete m_pToolbar; + DBG_DTOR( NavigationToolBar, NULL ); + } + + //--------------------------------------------------------------------- + void NavigationToolBar::setDispatcher( const IFeatureDispatcher* _pDispatcher ) + { + m_pDispatcher = _pDispatcher; + + m_pToolbar->setDispatcher( _pDispatcher ); + + RecordPositionInput* pPositionWindow = static_cast< RecordPositionInput* >( m_pToolbar->GetItemWindow( FormFeature::MoveAbsolute ) ); + OSL_ENSURE( pPositionWindow, "NavigationToolBar::setDispatcher: can't forward the dispatcher to the position window!" ); + if ( pPositionWindow ) + pPositionWindow->setDispatcher( _pDispatcher ); + + updateFeatureStates( ); + } + + //--------------------------------------------------------------------- + void NavigationToolBar::updateFeatureStates( ) + { + for ( sal_uInt16 nPos = 0; nPos < m_pToolbar->GetItemCount(); ++nPos ) + { + sal_uInt16 nItemId = m_pToolbar->GetItemId( nPos ); + + if ( ( nItemId == LID_RECORD_LABEL ) || ( nItemId == LID_RECORD_FILLER ) ) + continue; + + // is this item enabled? + bool bEnabled = m_pDispatcher ? m_pDispatcher->isEnabled( nItemId ) : false; + implEnableItem( nItemId, bEnabled ); + } + } + + //--------------------------------------------------------------------- + void NavigationToolBar::implEnableItem( sal_uInt16 _nItemId, bool _bEnabled ) + { + m_pToolbar->EnableItem( _nItemId, _bEnabled ); + + if ( _nItemId == FormFeature::MoveAbsolute ) + m_pToolbar->EnableItem( LID_RECORD_LABEL, _bEnabled ); + + if ( _nItemId == FormFeature::TotalRecords ) + m_pToolbar->EnableItem( LID_RECORD_FILLER, _bEnabled ); + } + + //--------------------------------------------------------------------- + void NavigationToolBar::enableFeature( sal_Int16 _nFeatureId, bool _bEnabled ) + { + DBG_ASSERT( m_pToolbar->GetItemPos( (sal_uInt16)_nFeatureId ) != TOOLBOX_ITEM_NOTFOUND, + "NavigationToolBar::enableFeature: invalid id!" ); + + implEnableItem( (sal_uInt16)_nFeatureId, _bEnabled ); + } + + //--------------------------------------------------------------------- + void NavigationToolBar::checkFeature( sal_Int16 _nFeatureId, bool _bEnabled ) + { + DBG_ASSERT( m_pToolbar->GetItemPos( (sal_uInt16)_nFeatureId ) != TOOLBOX_ITEM_NOTFOUND, + "NavigationToolBar::checkFeature: invalid id!" ); + + m_pToolbar->CheckItem( (sal_uInt16)_nFeatureId, _bEnabled ); + } + + //--------------------------------------------------------------------- + void NavigationToolBar::setFeatureText( sal_Int16 _nFeatureId, const ::rtl::OUString& _rText ) + { + DBG_ASSERT( m_pToolbar->GetItemPos( (sal_uInt16)_nFeatureId ) != TOOLBOX_ITEM_NOTFOUND, + "NavigationToolBar::checkFeature: invalid id!" ); + + Window* pItemWindow = m_pToolbar->GetItemWindow( (sal_uInt16)_nFeatureId ); + if ( pItemWindow ) + pItemWindow->SetText( _rText ); + else + m_pToolbar->SetItemText( (sal_uInt16)_nFeatureId, _rText ); + } + + //--------------------------------------------------------------------- + void NavigationToolBar::implInit( ) + { + m_pToolbar = new ImplNavToolBar( this ); + m_pToolbar->SetOutStyle( TOOLBOX_STYLE_FLAT ); + m_pToolbar->Show(); + + // need the SfxApplication for retrieving informations about our + // items. We could duplicate all the information here in our lib + // (such as the item text and the image), but why should we? + + struct FeatureDescription + { + sal_uInt16 nId; + bool bRepeat; + bool bItemWindow; + } aSupportedFeatures[] = + { + { LID_RECORD_LABEL, false, true }, + { FormFeature::MoveAbsolute, false, true }, + { LID_RECORD_FILLER, false, true }, + { FormFeature::TotalRecords, false, true }, + { FormFeature::MoveToFirst, true, false }, + { FormFeature::MoveToPrevious, true, false }, + { FormFeature::MoveToNext, true, false }, + { FormFeature::MoveToLast, true, false }, + { FormFeature::MoveToInsertRow, false, false }, + { 0, false, false }, + { FormFeature::SaveRecordChanges, false, false }, + { FormFeature::UndoRecordChanges, false, false }, + { FormFeature::DeleteRecord, false, false }, + { FormFeature::ReloadForm, false, false }, + { FormFeature::RefreshCurrentControl, false, false }, + { 0, false, false }, + { FormFeature::SortAscending, false, false }, + { FormFeature::SortDescending, false, false }, + { FormFeature::InteractiveSort, false, false }, + { FormFeature::AutoFilter, false, false }, + { FormFeature::InteractiveFilter, false, false }, + { FormFeature::ToggleApplyFilter, false, false }, + { FormFeature::RemoveFilterAndSort, false, false }, + }; + + size_t nSupportedFeatures = sizeof( aSupportedFeatures ) / sizeof( aSupportedFeatures[0] ); + FeatureDescription* pSupportedFeatures = aSupportedFeatures; + FeatureDescription* pSupportedFeaturesEnd = aSupportedFeatures + nSupportedFeatures; + for ( ; pSupportedFeatures < pSupportedFeaturesEnd; ++pSupportedFeatures ) + { + if ( pSupportedFeatures->nId ) + { // it's _not_ a separator + + // insert the entry + m_pToolbar->InsertItem( pSupportedFeatures->nId, String(), pSupportedFeatures->bRepeat ? TIB_REPEAT : 0 ); + m_pToolbar->SetQuickHelpText( pSupportedFeatures->nId, String() ); // TODO + + if ( !isArtificialItem( pSupportedFeatures->nId ) ) + { + ::rtl::OUString sCommandURL( lcl_getCommandURL( pSupportedFeatures->nId ) ); + m_pToolbar->SetItemCommand( pSupportedFeatures->nId, sCommandURL ); + if ( m_pDescriptionProvider ) + m_pToolbar->SetQuickHelpText( pSupportedFeatures->nId, m_pDescriptionProvider->getCommandDescription( sCommandURL ) ); + } + + if ( pSupportedFeatures->bItemWindow ) + { + Window* pItemWindow = NULL; + if ( FormFeature::MoveAbsolute == pSupportedFeatures->nId ) + { + pItemWindow = new RecordPositionInput( m_pToolbar ); + static_cast< RecordPositionInput* >( pItemWindow )->setDispatcher( m_pDispatcher ); + } + else if ( LID_RECORD_FILLER == pSupportedFeatures->nId ) + { + pItemWindow = new FixedText( m_pToolbar, WB_CENTER | WB_VCENTER ); + pItemWindow->SetBackground(Wallpaper(Color(COL_TRANSPARENT))); + } + else + { + pItemWindow = new FixedText( m_pToolbar, WB_VCENTER ); + pItemWindow->SetBackground(); + pItemWindow->SetPaintTransparent(sal_True); + } + m_aChildWins.push_back( pItemWindow ); + + switch ( pSupportedFeatures->nId ) + { + case LID_RECORD_LABEL: + pItemWindow->SetText( getLabelString( RID_STR_LABEL_RECORD ) ); + break; + + case LID_RECORD_FILLER: + pItemWindow->SetText( getLabelString( RID_STR_LABEL_OF ) ); + break; + } + + m_pToolbar->SetItemWindow( pSupportedFeatures->nId, pItemWindow ); + } + } + else + { // a separator + m_pToolbar->InsertSeparator( ); + } + } + + forEachItemWindow( &NavigationToolBar::adjustItemWindowWidth, NULL ); + + implUpdateImages(); + } + + //--------------------------------------------------------------------- + void NavigationToolBar::implUpdateImages() + { + OSL_ENSURE( m_pImageProvider, "NavigationToolBar::implUpdateImages: no image provider => no images!" ); + if ( !m_pImageProvider ) + return; + + const bool bIsHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode(); + + const sal_uInt16 nItemCount = m_pToolbar->GetItemCount(); + + // collect the FormFeatures in the toolbar + typedef ::std::vector< sal_Int16 > FormFeatures; + FormFeatures aFormFeatures; + aFormFeatures.reserve( nItemCount ); + + for ( sal_uInt16 i=0; i<nItemCount; ++i ) + { + sal_uInt16 nId = m_pToolbar->GetItemId( i ); + if ( ( TOOLBOXITEM_BUTTON == m_pToolbar->GetItemType( i ) ) && !isArtificialItem( nId ) ) + aFormFeatures.push_back( nId ); + } + + // translate them into command URLs + CommandURLs aCommandURLs( aFormFeatures.size() ); + for ( FormFeatures::const_iterator formFeature = aFormFeatures.begin(); + formFeature != aFormFeatures.end(); + ++formFeature + ) + { + aCommandURLs[ formFeature - aFormFeatures.begin() ] = lcl_getCommandURL( *formFeature ); + } + + // retrieve the images for the command URLs + CommandImages aCommandImages = m_pImageProvider->getCommandImages( aCommandURLs, m_eImageSize == eLarge, bIsHighContrast ); + + // and set them at the toolbar + CommandImages::const_iterator commandImage = aCommandImages.begin(); + for ( FormFeatures::const_iterator formFeature = aFormFeatures.begin(); + formFeature != aFormFeatures.end(); + ++formFeature, ++commandImage + ) + { + m_pToolbar->SetItemImage( *formFeature, *commandImage ); + } + + // parts of our layout is dependent on the size of our icons + Resize(); + } + + //--------------------------------------------------------------------- + void NavigationToolBar::implSetImageSize( ImageSize _eSize ) + { + if ( _eSize != m_eImageSize ) + { + m_eImageSize = _eSize; + implUpdateImages(); + } + } + + //--------------------------------------------------------------------- + void NavigationToolBar::SetImageSize( ImageSize _eSize ) + { + implSetImageSize( _eSize ); + } + + //--------------------------------------------------------------------- + void NavigationToolBar::ShowFunctionGroup( FunctionGroup _eGroup, bool _bShow ) + { + const sal_uInt16* pGroupIds = NULL; + + switch ( _eGroup ) + { + case ePosition: + { + static const sal_uInt16 aPositionIds[] = { + LID_RECORD_LABEL, FormFeature::MoveAbsolute, LID_RECORD_FILLER, FormFeature::TotalRecords, 0 + }; + pGroupIds = aPositionIds; + } + break; + case eNavigation: + { + static const sal_uInt16 aNavigationIds[] = { + FormFeature::MoveToFirst, FormFeature::MoveToPrevious, FormFeature::MoveToNext, FormFeature::MoveToLast, FormFeature::MoveToInsertRow, 0 + }; + pGroupIds = aNavigationIds; + } + break; + case eRecordActions: + { + static const sal_uInt16 aActionIds[] = { + FormFeature::SaveRecordChanges, FormFeature::UndoRecordChanges, FormFeature::DeleteRecord, FormFeature::ReloadForm, FormFeature::RefreshCurrentControl, 0 + }; + pGroupIds = aActionIds; + } + break; + case eFilterSort: + { + static const sal_uInt16 aFilterSortIds[] = { + FormFeature::SortAscending, FormFeature::SortDescending, FormFeature::InteractiveSort, FormFeature::AutoFilter, FormFeature::InteractiveFilter, FormFeature::ToggleApplyFilter, FormFeature::RemoveFilterAndSort, 0 + }; + pGroupIds = aFilterSortIds; + } + break; + default: + OSL_ENSURE( sal_False, "NavigationToolBar::ShowFunctionGroup: invalid group id!" ); + } + + if ( pGroupIds ) + while ( *pGroupIds ) + m_pToolbar->ShowItem( *pGroupIds++, _bShow ); + } + + //--------------------------------------------------------------------- + bool NavigationToolBar::IsFunctionGroupVisible( FunctionGroup _eGroup ) + { + sal_uInt16 nIndicatorItem = 0; + switch ( _eGroup ) + { + case ePosition : nIndicatorItem = LID_RECORD_LABEL; break; + case eNavigation : nIndicatorItem = FormFeature::MoveToFirst; break; + case eRecordActions : nIndicatorItem = FormFeature::SaveRecordChanges; break; + case eFilterSort : nIndicatorItem = FormFeature::SortAscending; break; + default: + OSL_ENSURE( sal_False, "NavigationToolBar::IsFunctionGroupVisible: invalid group id!" ); + } + + return m_pToolbar->IsItemVisible( nIndicatorItem ); + } + + //------------------------------------------------------------------------------ + void NavigationToolBar::StateChanged( StateChangedType nType ) + { + Window::StateChanged( nType ); + + switch ( nType ) + { + case STATE_CHANGE_ZOOM: +// m_pToolbar->SetZoom( GetZoom() ); +// forEachItemWindow( setItemWindowZoom, NULL ); + // the ToolBox class is not zoomable at the moment, so + // we better have no zoom at all instead of only half a zoom ... + break; + + case STATE_CHANGE_CONTROLFONT: + forEachItemWindow( &NavigationToolBar::setItemControlFont, NULL ); + forEachItemWindow( &NavigationToolBar::adjustItemWindowWidth, NULL ); + break; + + case STATE_CHANGE_CONTROLFOREGROUND: + forEachItemWindow( &NavigationToolBar::setItemControlForeground, NULL ); + break; + + case STATE_CHANGE_MIRRORING: + { + sal_Bool bIsRTLEnabled( IsRTLEnabled() ); + m_pToolbar->EnableRTL( bIsRTLEnabled ); + forEachItemWindow( &NavigationToolBar::enableItemRTL, &bIsRTLEnabled ); + Resize(); + } + break; + } + } + + //--------------------------------------------------------------------- + void NavigationToolBar::Resize() + { + // resize/position the toolbox as a whole + sal_Int32 nToolbarHeight = m_pToolbar->CalcWindowSizePixel().Height(); + + sal_Int32 nMyHeight = GetOutputSizePixel().Height(); + m_pToolbar->SetPosSizePixel( Point( 0, ( nMyHeight - nToolbarHeight ) / 2 ), + Size( GetSizePixel().Width(), nToolbarHeight ) ); + + Window::Resize(); + } + + //--------------------------------------------------------------------- + void NavigationToolBar::SetControlBackground() + { + Window::SetControlBackground(); + m_pToolbar->SetControlBackground(); + forEachItemWindow( &NavigationToolBar::setItemBackground, NULL ); + + // the contrast of the background color may have changed, so force + // the images to be rebuild (high contrast requires a possibly different + // image set) + implUpdateImages(); + } + + //--------------------------------------------------------------------- + void NavigationToolBar::SetControlBackground( const Color& _rColor ) + { + Window::SetControlBackground( _rColor ); + m_pToolbar->SetControlBackground( _rColor ); + forEachItemWindow( &NavigationToolBar::setItemBackground, &_rColor ); + + // the contrast of the background color may have changed, so force + // the images to be rebuild (high contrast requires a possibly different + // image set) + implUpdateImages(); + } + + //--------------------------------------------------------------------- + void NavigationToolBar::SetTextLineColor( ) + { + Window::SetTextLineColor( ); + m_pToolbar->SetTextLineColor( ); + forEachItemWindow( &NavigationToolBar::setTextLineColor, NULL ); + } + + //--------------------------------------------------------------------- + void NavigationToolBar::SetTextLineColor( const Color& _rColor ) + { + Window::SetTextLineColor( _rColor ); + m_pToolbar->SetTextLineColor( _rColor ); + forEachItemWindow( &NavigationToolBar::setTextLineColor, &_rColor ); + } + + //--------------------------------------------------------------------- + void NavigationToolBar::forEachItemWindow( ItemWindowHandler _handler, const void* _pParam ) + { + for ( sal_uInt16 item = 0; item < m_pToolbar->GetItemCount(); ++item ) + { + sal_uInt16 nItemId = m_pToolbar->GetItemId( item ); + Window* pItemWindow = m_pToolbar->GetItemWindow( nItemId ); + if ( pItemWindow ) + (this->*_handler)( nItemId, pItemWindow, _pParam ); + } + } + + //--------------------------------------------------------------------- + void NavigationToolBar::setItemBackground( sal_uInt16 /* _nItemId */, Window* _pItemWindow, const void* _pColor ) const + { + if ( _pColor ) + _pItemWindow->SetControlBackground( *static_cast< const Color* >( _pColor ) ); + else + _pItemWindow->SetControlBackground(); + } + + //--------------------------------------------------------------------- + void NavigationToolBar::setTextLineColor( sal_uInt16 /* _nItemId */, Window* _pItemWindow, const void* _pColor ) const + { + if ( _pColor ) + _pItemWindow->SetTextLineColor( *static_cast< const Color* >( _pColor ) ); + else + _pItemWindow->SetTextLineColor(); + } +#if 0 + //--------------------------------------------------------------------- + void NavigationToolBar::setItemWindowZoom( sal_uInt16 /* _nItemId */, Window* _pItemWindow, const void* /* _pParam */ ) const + { + _pItemWindow->SetZoom( GetZoom() ); + _pItemWindow->SetZoomedPointFont( IsControlFont() ? GetControlFont() : GetPointFont() ); + } +#endif + //--------------------------------------------------------------------- + void NavigationToolBar::setItemControlFont( sal_uInt16 /* _nItemId */, Window* _pItemWindow, const void* /* _pParam */ ) const + { + if ( IsControlFont() ) + _pItemWindow->SetControlFont( GetControlFont() ); + else + _pItemWindow->SetControlFont( ); + } + + //--------------------------------------------------------------------- + void NavigationToolBar::setItemControlForeground( sal_uInt16 /* _nItemId */, Window* _pItemWindow, const void* /* _pParam */ ) const + { + if ( IsControlForeground() ) + _pItemWindow->SetControlForeground( GetControlForeground() ); + else + _pItemWindow->SetControlForeground( ); + _pItemWindow->SetTextColor( GetTextColor() ); + } + + //--------------------------------------------------------------------- + void NavigationToolBar::adjustItemWindowWidth( sal_uInt16 _nItemId, Window* _pItemWindow, const void* /* _pParam */ ) const + { + String sItemText; + switch ( _nItemId ) + { + case LID_RECORD_LABEL: + sItemText = getLabelString( RID_STR_LABEL_RECORD ); + break; + + case LID_RECORD_FILLER: + sItemText = getLabelString( RID_STR_LABEL_OF ); + break; + + case FormFeature::MoveAbsolute: + sItemText = String::CreateFromAscii( "12345678" ); + break; + + case FormFeature::TotalRecords: + sItemText = String::CreateFromAscii( "123456" ); + break; + } + + Size aSize( _pItemWindow->GetTextWidth( sItemText ), /* _pItemWindow->GetSizePixel( ).Height() */ _pItemWindow->GetTextHeight() + 4 ); + aSize.Width() += 6; + _pItemWindow->SetSizePixel( aSize ); + + m_pToolbar->SetItemWindow( _nItemId, _pItemWindow ); + } + + //--------------------------------------------------------------------- + void NavigationToolBar::enableItemRTL( sal_uInt16 /*_nItemId*/, Window* _pItemWindow, const void* _pIsRTLEnabled ) const + { + _pItemWindow->EnableRTL( *static_cast< const sal_Bool* >( _pIsRTLEnabled ) ); + } + + //===================================================================== + //= RecordPositionInput + //===================================================================== + //--------------------------------------------------------------------- + RecordPositionInput::RecordPositionInput( Window* _pParent ) + :NumericField( _pParent, WB_BORDER | WB_VCENTER ) + ,m_pDispatcher( NULL ) + { + SetMin( 1 ); + SetFirst( 1 ); + SetSpinSize( 1 ); + SetDecimalDigits( 0 ); + SetStrictFormat( sal_True ); + SetBorderStyle( WINDOW_BORDER_MONO ); + } + + //--------------------------------------------------------------------- + RecordPositionInput::~RecordPositionInput() + { + } + + //--------------------------------------------------------------------- + void RecordPositionInput::setDispatcher( const IFeatureDispatcher* _pDispatcher ) + { + m_pDispatcher = _pDispatcher; + } + + //--------------------------------------------------------------------- + void RecordPositionInput::FirePosition( sal_Bool _bForce ) + { + if ( _bForce || ( GetText() != GetSavedValue() ) ) + { + sal_Int64 nRecord = GetValue(); + if ( nRecord < GetMin() || nRecord > GetMax() ) + return; + + if ( m_pDispatcher ) + m_pDispatcher->dispatchWithArgument( FormFeature::MoveAbsolute, "Position", makeAny( (sal_Int32)nRecord ) ); + + SaveValue(); + } + } + + //--------------------------------------------------------------------- + void RecordPositionInput::LoseFocus() + { + FirePosition( sal_False ); + } + + //--------------------------------------------------------------------- + void RecordPositionInput::KeyInput( const KeyEvent& rKeyEvent ) + { + if( rKeyEvent.GetKeyCode() == KEY_RETURN && GetText().Len() ) + FirePosition( sal_True ); + else + NumericField::KeyInput( rKeyEvent ); + } + + +//......................................................................... +} // namespace frm +//......................................................................... diff --git a/forms/source/solar/inc/navtoolbar.hxx b/forms/source/solar/inc/navtoolbar.hxx new file mode 100644 index 000000000000..a6147a60b0e4 --- /dev/null +++ b/forms/source/solar/inc/navtoolbar.hxx @@ -0,0 +1,194 @@ +/************************************************************************* + * + * 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 FORMS_SOLAR_CONTROL_NAVTOOLBAR_HXX +#define FORMS_SOLAR_CONTROL_NAVTOOLBAR_HXX + +#include <vcl/toolbox.hxx> +#include <vcl/field.hxx> + +#include <boost/shared_ptr.hpp> + +//......................................................................... +namespace frm +{ +//......................................................................... + + class IFeatureDispatcher; + class ICommandImageProvider; + class ICommandDescriptionProvider; + + class ImplNavToolBar; + + //===================================================================== + //= NavigationToolBar + //===================================================================== + class NavigationToolBar : public Window + { + public: + enum ImageSize + { + eSmall, + eLarge + }; + + enum FunctionGroup + { + ePosition, + eNavigation, + eRecordActions, + eFilterSort + }; + + private: + const IFeatureDispatcher* m_pDispatcher; + const ::boost::shared_ptr< const ICommandImageProvider > + m_pImageProvider; + const ::boost::shared_ptr< const ICommandDescriptionProvider > + m_pDescriptionProvider; + ImageSize m_eImageSize; + ImplNavToolBar* m_pToolbar; + ::std::vector< Window* > m_aChildWins; + + public: + NavigationToolBar( + Window* _pParent, + WinBits _nStyle, + const ::boost::shared_ptr< const ICommandImageProvider >& _pImageProvider, + const ::boost::shared_ptr< const ICommandDescriptionProvider >& _pDescriptionProvider + ); + ~NavigationToolBar( ); + + /** sets the dispatcher which is to be used for the features + + If the dispatcher is the same as the one which is currently set, + then the states of the features are updated + + @param _pDispatcher + the new (or old) dispatcher. The caller is reponsible for + ensuring the life time of the object does exceed the life time + of the tool bar instance. + */ + void setDispatcher( const IFeatureDispatcher* _pDispatcher ); + + /// enables or disables a given feature + void enableFeature( sal_Int16 _nFeatureId, bool _bEnabled ); + + /// checks or unchecks a given feature + void checkFeature( sal_Int16 _nFeatureId, bool _bEnabled ); + + /// sets the text of a given feature + void setFeatureText( sal_Int16 _nFeatureId, const ::rtl::OUString& _rText ); + + /** retrieves the current image size + */ + inline ImageSize GetImageSize( ) const { return m_eImageSize; } + + /** sets the size of the images + */ + void SetImageSize( ImageSize _eSize ); + + /** shows or hides a function group + */ + void ShowFunctionGroup( FunctionGroup _eGroup, bool _bShow ); + + /** determines whether or not a given function group is currently visible + */ + bool IsFunctionGroupVisible( FunctionGroup _eGroup ); + + // Window "overridables" (hiding the respective Window methods) + void SetControlBackground(); + void SetControlBackground( const Color& rColor ); + void SetTextLineColor( ); + void SetTextLineColor( const Color& rColor ); + + protected: + // Window overridables + virtual void Resize(); + virtual void StateChanged( StateChangedType nType ); + + /// ctor implementation + void implInit( ); + + /// impl version of SetImageSize + void implSetImageSize( ImageSize _eSize ); + + /// updates the images of our items + void implUpdateImages(); + + /// enables or disables an item, plus possible dependent items + void implEnableItem( sal_uInt16 _nItemId, bool _bEnabled ); + + /** update the states of all features, using the callback + */ + void updateFeatureStates( ); + + // iterating through item windows + typedef void (NavigationToolBar::*ItemWindowHandler) (sal_uInt16, Window*, const void*) const; + void forEachItemWindow( ItemWindowHandler _handler, const void* _pParam ); + + void setItemBackground( sal_uInt16 /* _nItemId */, Window* _pItemWindow, const void* _pColor ) const; + void setTextLineColor( sal_uInt16 /* _nItemId */, Window* _pItemWindow, const void* _pColor ) const; +#if 0 + void setItemWindowZoom( sal_uInt16 /* _nItemId */, Window* _pItemWindow, const void* /* _pParam */ ) const; +#endif + void setItemControlFont( sal_uInt16 /* _nItemId */, Window* _pItemWindow, const void* /* _pParam */ ) const; + void setItemControlForeground( sal_uInt16 /* _nItemId */, Window* _pItemWindow, const void* /* _pParam */ ) const; + void adjustItemWindowWidth( sal_uInt16 _nItemId, Window* _pItemWindow, const void* /* _pParam */ ) const; + void enableItemRTL( sal_uInt16 /*_nItemId*/, Window* _pItemWindow, const void* _pIsRTLEnabled ) const; + }; + + //===================================================================== + //= RecordPositionInput + //===================================================================== + class RecordPositionInput : public NumericField + { + private: + const IFeatureDispatcher* m_pDispatcher; + + public: + RecordPositionInput( Window* _pParent ); + ~RecordPositionInput(); + + /** sets the dispatcher which is to be used for the features + */ + void setDispatcher( const IFeatureDispatcher* _pDispatcher ); + + protected: + // Window overridables + virtual void LoseFocus(); + virtual void KeyInput( const KeyEvent& rKeyEvent ); + + private: + void FirePosition( sal_Bool _bForce ); + }; + +//......................................................................... +} // namespace frm +//......................................................................... + +#endif // FORMS_SOLAR_CONTROL_NAVTOOLBAR_HXX |