1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_toolkit.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #ifndef _TOOLKIT_ROADMAP_CONTROL_HXX 32*cdf0e10cSrcweir #include <toolkit/controls/roadmapcontrol.hxx> 33*cdf0e10cSrcweir #endif 34*cdf0e10cSrcweir #include <toolkit/helper/unopropertyarrayhelper.hxx> 35*cdf0e10cSrcweir #include <toolkit/helper/property.hxx> 36*cdf0e10cSrcweir #include <com/sun/star/awt/XVclWindowPeer.hpp> 37*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 38*cdf0e10cSrcweir #include <osl/diagnose.h> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir //........................................................................ 41*cdf0e10cSrcweir namespace toolkit 42*cdf0e10cSrcweir { 43*cdf0e10cSrcweir //........................................................................ 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 46*cdf0e10cSrcweir using namespace ::com::sun::star::awt; 47*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 48*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 49*cdf0e10cSrcweir using namespace ::com::sun::star::container; 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir // ---------------------------------------------------- 52*cdf0e10cSrcweir // helper 53*cdf0e10cSrcweir // ---------------------------------------------------- 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir static void lcl_throwIllegalArgumentException( ) 56*cdf0e10cSrcweir { // throwing is expensive (in terms of code size), thus we hope the compiler does not inline this .... 57*cdf0e10cSrcweir throw IllegalArgumentException(); 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir static void lcl_throwIndexOutOfBoundsException( ) 61*cdf0e10cSrcweir { // throwing is expensive (in terms of code size), thus we hope the compiler does not inline this .... 62*cdf0e10cSrcweir throw IndexOutOfBoundsException(); 63*cdf0e10cSrcweir } 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir // =================================================================== 66*cdf0e10cSrcweir // = UnoControlRoadmapModel 67*cdf0e10cSrcweir // =================================================================== 68*cdf0e10cSrcweir // ------------------------------------------------------------------- 69*cdf0e10cSrcweir UnoControlRoadmapModel::UnoControlRoadmapModel( const Reference< XMultiServiceFactory >& i_factory ) 70*cdf0e10cSrcweir :UnoControlRoadmapModel_Base( i_factory ) 71*cdf0e10cSrcweir ,maContainerListeners( *this ) 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR ); 74*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_BORDER ); 75*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR ); 76*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL ); 77*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR ); 78*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_HELPTEXT ); 79*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_HELPURL ); 80*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_IMAGEURL ); 81*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_GRAPHIC ); 82*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_PRINTABLE ); 83*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_COMPLETE ); 84*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_ACTIVATED ); 85*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_CURRENTITEMID ); 86*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_TABSTOP ); 87*cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_TEXT ); 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir // ------------------------------------------------------------------- 91*cdf0e10cSrcweir ::rtl::OUString UnoControlRoadmapModel::getServiceName() throw(RuntimeException) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( szServiceName_UnoControlRoadmapModel ); 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir // ------------------------------------------------------------------- 98*cdf0e10cSrcweir Any UnoControlRoadmapModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir Any aReturn; 101*cdf0e10cSrcweir switch (nPropId) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir case BASEPROPERTY_COMPLETE: 104*cdf0e10cSrcweir aReturn <<= (sal_Bool) sal_True; 105*cdf0e10cSrcweir break; 106*cdf0e10cSrcweir case BASEPROPERTY_ACTIVATED: 107*cdf0e10cSrcweir aReturn <<= (sal_Bool) sal_True; 108*cdf0e10cSrcweir break; 109*cdf0e10cSrcweir case BASEPROPERTY_CURRENTITEMID: 110*cdf0e10cSrcweir aReturn <<= (sal_Int16) -1; 111*cdf0e10cSrcweir break; 112*cdf0e10cSrcweir case BASEPROPERTY_TEXT: 113*cdf0e10cSrcweir break; 114*cdf0e10cSrcweir case BASEPROPERTY_BORDER: 115*cdf0e10cSrcweir aReturn <<= (sal_Int16) 2; // No Border 116*cdf0e10cSrcweir break; 117*cdf0e10cSrcweir case BASEPROPERTY_DEFAULTCONTROL: 118*cdf0e10cSrcweir aReturn <<= ::rtl::OUString( ::rtl::OUString::createFromAscii( szServiceName_UnoControlRoadmap ) ); 119*cdf0e10cSrcweir break; 120*cdf0e10cSrcweir default : aReturn = UnoControlRoadmapModel_Base::ImplGetDefaultValue( nPropId ); break; 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir return aReturn; 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir Reference< XInterface > SAL_CALL UnoControlRoadmapModel::createInstance( ) throw (Exception, ::com::sun::star::uno::RuntimeException) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir ORoadmapEntry* pRoadmapItem = new ORoadmapEntry(); 130*cdf0e10cSrcweir Reference< XInterface > xNewRoadmapItem = (::cppu::OWeakObject*)pRoadmapItem; 131*cdf0e10cSrcweir return xNewRoadmapItem; 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir Reference< XInterface > SAL_CALL UnoControlRoadmapModel::createInstanceWithArguments( const Sequence< Any >& /*aArguments*/ ) throw (Exception, RuntimeException) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir // Todo: implementation of the arguments handling 138*cdf0e10cSrcweir ORoadmapEntry* pRoadmapItem = new ORoadmapEntry(); 139*cdf0e10cSrcweir Reference< XInterface > xNewRoadmapItem = (::cppu::OWeakObject*)pRoadmapItem; 140*cdf0e10cSrcweir return xNewRoadmapItem; 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoControlRoadmapModel, UnoControlRoadmapModel_Base, UnoControlRoadmapModel_IBase ) 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir // ------------------------------------------------------------------- 148*cdf0e10cSrcweir ::com::sun::star::uno::Any SAL_CALL UnoControlRoadmapModel::queryAggregation( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir Any aRet = UnoControlRoadmapModel_Base::queryAggregation( rType ); 151*cdf0e10cSrcweir if ( !aRet.hasValue() ) 152*cdf0e10cSrcweir aRet = UnoControlRoadmapModel_IBase::queryInterface( rType ); 153*cdf0e10cSrcweir return aRet; 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir // ------------------------------------------------------------------- 158*cdf0e10cSrcweir ::cppu::IPropertyArrayHelper& UnoControlRoadmapModel::getInfoHelper() 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir static UnoPropertyArrayHelper* pHelper = NULL; 161*cdf0e10cSrcweir if ( !pHelper ) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); 164*cdf0e10cSrcweir pHelper = new UnoPropertyArrayHelper( aIDs ); 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir return *pHelper; 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir // beans::XMultiPropertySet 171*cdf0e10cSrcweir // ------------------------------------------------------------------- 172*cdf0e10cSrcweir Reference< XPropertySetInfo > UnoControlRoadmapModel::getPropertySetInfo( ) throw(RuntimeException) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 175*cdf0e10cSrcweir return xInfo; 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir sal_Int32 SAL_CALL UnoControlRoadmapModel::getCount() throw(RuntimeException) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir return maRoadmapItems.size(); 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir Any SAL_CALL UnoControlRoadmapModel::getByIndex( sal_Int32 Index ) throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException ) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir if (( Index >= (sal_Int32)maRoadmapItems.size()) || (Index < 0)) 187*cdf0e10cSrcweir lcl_throwIndexOutOfBoundsException( ); 188*cdf0e10cSrcweir Any aAny; 189*cdf0e10cSrcweir aAny = makeAny( maRoadmapItems.at( Index )); 190*cdf0e10cSrcweir return aAny; 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir void UnoControlRoadmapModel::MakeRMItemValidation( sal_Int32 Index, Reference< XInterface > xRoadmapItem ) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir if ((Index > (sal_Int32)maRoadmapItems.size()) || ( Index < 0 ) ) 198*cdf0e10cSrcweir lcl_throwIndexOutOfBoundsException( ); 199*cdf0e10cSrcweir if ( !xRoadmapItem.is() ) 200*cdf0e10cSrcweir lcl_throwIllegalArgumentException(); 201*cdf0e10cSrcweir Reference< XServiceInfo > xServiceInfo( xRoadmapItem, UNO_QUERY ); 202*cdf0e10cSrcweir sal_Bool bIsRoadmapItem = xServiceInfo->supportsService( ::rtl::OUString::createFromAscii( "com.sun.star.awt.RoadmapItem" ) ); 203*cdf0e10cSrcweir if ( !bIsRoadmapItem ) 204*cdf0e10cSrcweir lcl_throwIllegalArgumentException(); 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir void UnoControlRoadmapModel::SetRMItemDefaultProperties( const sal_Int32 , Reference< XInterface > xRoadmapItem) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir Any aAny; 211*cdf0e10cSrcweir Reference< XPropertySet > xPropertySet( xRoadmapItem, UNO_QUERY ); 212*cdf0e10cSrcweir Reference< XPropertySet > xProps( xRoadmapItem, UNO_QUERY ); 213*cdf0e10cSrcweir if ( xProps.is() ) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir sal_Int32 LocID = 0; 216*cdf0e10cSrcweir Any aValue = xPropertySet->getPropertyValue( ::rtl::OUString::createFromAscii( "ID" ) ); 217*cdf0e10cSrcweir aValue >>= LocID; 218*cdf0e10cSrcweir if (LocID < 0) // index may not be smaller than zero 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir aAny <<= GetUniqueID(); 221*cdf0e10cSrcweir xPropertySet->setPropertyValue( ::rtl::OUString::createFromAscii( "ID" ), aAny ); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir // The performance of this method could certainly be improved. 228*cdf0e10cSrcweir // As long as only vectors with up to 10 elements are 229*cdf0e10cSrcweir // involved it should be sufficient 230*cdf0e10cSrcweir sal_Int32 UnoControlRoadmapModel::GetUniqueID() 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir Any aAny; 233*cdf0e10cSrcweir sal_Bool bIncrement = sal_True; 234*cdf0e10cSrcweir sal_Int32 CurID = 0; 235*cdf0e10cSrcweir sal_Int32 n_CurItemID = 0; 236*cdf0e10cSrcweir Reference< XInterface > CurRoadmapItem; 237*cdf0e10cSrcweir while ( bIncrement ) 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir bIncrement = sal_False; 240*cdf0e10cSrcweir for ( RoadmapItemHolderList::iterator i = maRoadmapItems.begin(); i < maRoadmapItems.end(); i++ ) 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir CurRoadmapItem = *i; 243*cdf0e10cSrcweir Reference< XPropertySet > xPropertySet( CurRoadmapItem, UNO_QUERY ); 244*cdf0e10cSrcweir aAny = xPropertySet->getPropertyValue( ::rtl::OUString::createFromAscii( "ID" ) ); 245*cdf0e10cSrcweir aAny >>= n_CurItemID; 246*cdf0e10cSrcweir if (n_CurItemID == CurID) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir bIncrement = sal_True; 249*cdf0e10cSrcweir CurID++; 250*cdf0e10cSrcweir break; 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir return CurID; 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir ContainerEvent UnoControlRoadmapModel::GetContainerEvent(sal_Int32 Index, Reference< XInterface > xRoadmapItem) 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir ContainerEvent aEvent; 261*cdf0e10cSrcweir aEvent.Source = *this; 262*cdf0e10cSrcweir aEvent.Element <<= xRoadmapItem; 263*cdf0e10cSrcweir aEvent.Accessor = makeAny(Index); 264*cdf0e10cSrcweir return aEvent; 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir sal_Int16 UnoControlRoadmapModel::GetCurrentItemID( Reference< XPropertySet > xPropertySet ) 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir Any aAny = xPropertySet->getPropertyValue( GetPropertyName( BASEPROPERTY_CURRENTITEMID ) ); 271*cdf0e10cSrcweir sal_Int16 n_CurrentItemID = 0; 272*cdf0e10cSrcweir aAny >>= n_CurrentItemID; 273*cdf0e10cSrcweir return n_CurrentItemID; 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir void SAL_CALL UnoControlRoadmapModel::insertByIndex( const sal_Int32 Index, const Any& _Element) 278*cdf0e10cSrcweir throw (IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException ) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir if ( ( Index >= ( (sal_Int32)maRoadmapItems.size() + 1 ) ) || (Index < 0)) 281*cdf0e10cSrcweir lcl_throwIndexOutOfBoundsException( ); 282*cdf0e10cSrcweir Reference< XInterface > xRoadmapItem; 283*cdf0e10cSrcweir _Element >>= xRoadmapItem; 284*cdf0e10cSrcweir MakeRMItemValidation( Index, xRoadmapItem); 285*cdf0e10cSrcweir SetRMItemDefaultProperties( Index, xRoadmapItem ); 286*cdf0e10cSrcweir maRoadmapItems.insert( maRoadmapItems.begin() + Index, xRoadmapItem); 287*cdf0e10cSrcweir ContainerEvent aEvent = GetContainerEvent(Index, xRoadmapItem); 288*cdf0e10cSrcweir maContainerListeners.elementInserted( aEvent ); 289*cdf0e10cSrcweir Reference< XPropertySet > xPropertySet( (XAggregation*) (::cppu::OWeakAggObject*)this, UNO_QUERY ); 290*cdf0e10cSrcweir sal_Int16 n_CurrentItemID = GetCurrentItemID( xPropertySet ); 291*cdf0e10cSrcweir if ( Index <= n_CurrentItemID ) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir Any aAny; 294*cdf0e10cSrcweir aAny <<= ( sal_Int16 ) ( n_CurrentItemID + 1 ); 295*cdf0e10cSrcweir xPropertySet->setPropertyValue( GetPropertyName( BASEPROPERTY_CURRENTITEMID ), aAny ); 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir void SAL_CALL UnoControlRoadmapModel::removeByIndex( sal_Int32 Index) 302*cdf0e10cSrcweir throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException ) 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir if (( Index > (sal_Int32)maRoadmapItems.size()) || (Index < 0)) 305*cdf0e10cSrcweir lcl_throwIndexOutOfBoundsException( ); 306*cdf0e10cSrcweir Reference< XInterface > xRoadmapItem; 307*cdf0e10cSrcweir maRoadmapItems.erase( maRoadmapItems.begin() + Index ); 308*cdf0e10cSrcweir ContainerEvent aEvent = GetContainerEvent(Index, xRoadmapItem); 309*cdf0e10cSrcweir maContainerListeners.elementRemoved( aEvent ); 310*cdf0e10cSrcweir Reference< XPropertySet > xPropertySet( (XAggregation*) (::cppu::OWeakAggObject*)this, UNO_QUERY ); 311*cdf0e10cSrcweir sal_Int16 n_CurrentItemID = GetCurrentItemID( xPropertySet ); 312*cdf0e10cSrcweir Any aAny; 313*cdf0e10cSrcweir if ( Index <= n_CurrentItemID ) 314*cdf0e10cSrcweir { 315*cdf0e10cSrcweir if ( n_CurrentItemID >= (sal_Int32)maRoadmapItems.size() ) 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir n_CurrentItemID = sal::static_int_cast< sal_Int16 >( 318*cdf0e10cSrcweir maRoadmapItems.size()-1); 319*cdf0e10cSrcweir if ( n_CurrentItemID < 0 ) 320*cdf0e10cSrcweir return; 321*cdf0e10cSrcweir aAny <<= n_CurrentItemID; 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir else if (Index == n_CurrentItemID) 324*cdf0e10cSrcweir aAny <<= ( sal_Int16 ) -1; 325*cdf0e10cSrcweir else if( Index < n_CurrentItemID) 326*cdf0e10cSrcweir aAny <<= ( sal_Int16 ) ( n_CurrentItemID - 1 ); 327*cdf0e10cSrcweir xPropertySet->setPropertyValue( GetPropertyName( BASEPROPERTY_CURRENTITEMID ), aAny ); 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir void SAL_CALL UnoControlRoadmapModel::replaceByIndex( const sal_Int32 Index, const Any& _Element) 333*cdf0e10cSrcweir throw (IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException ) 334*cdf0e10cSrcweir { 335*cdf0e10cSrcweir Reference< XInterface > xRoadmapItem; 336*cdf0e10cSrcweir _Element >>= xRoadmapItem; 337*cdf0e10cSrcweir MakeRMItemValidation( Index, xRoadmapItem); 338*cdf0e10cSrcweir SetRMItemDefaultProperties( Index, xRoadmapItem ); 339*cdf0e10cSrcweir maRoadmapItems.erase( maRoadmapItems.begin() + Index ); 340*cdf0e10cSrcweir maRoadmapItems.insert( maRoadmapItems.begin() + Index, xRoadmapItem); //push_back( xRoadmapItem ); 341*cdf0e10cSrcweir ContainerEvent aEvent = GetContainerEvent(Index, xRoadmapItem); 342*cdf0e10cSrcweir maContainerListeners.elementReplaced( aEvent ); 343*cdf0e10cSrcweir } 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir Type SAL_CALL UnoControlRoadmapModel::getElementType() throw(RuntimeException) 347*cdf0e10cSrcweir { 348*cdf0e10cSrcweir Type aType = getCppuType( ( Reference< XPropertySet>* ) NULL ); 349*cdf0e10cSrcweir return aType; 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir sal_Bool SAL_CALL UnoControlRoadmapModel::hasElements() throw(RuntimeException) 354*cdf0e10cSrcweir { 355*cdf0e10cSrcweir return !maRoadmapItems.empty(); 356*cdf0e10cSrcweir } 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir void SAL_CALL UnoControlRoadmapModel::addContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw (::com::sun::star::uno::RuntimeException) 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir maContainerListeners.addInterface( xListener ); 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir void SAL_CALL UnoControlRoadmapModel::removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw (::com::sun::star::uno::RuntimeException) 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir maContainerListeners.removeInterface( xListener ); 367*cdf0e10cSrcweir } 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir // =================================================================== 370*cdf0e10cSrcweir // = UnoRoadmapControl 371*cdf0e10cSrcweir // =================================================================== 372*cdf0e10cSrcweir // ------------------------------------------------------------------- 373*cdf0e10cSrcweir UnoRoadmapControl::UnoRoadmapControl( const Reference< XMultiServiceFactory >& i_factory ) 374*cdf0e10cSrcweir :UnoControlRoadmap_Base( i_factory ) 375*cdf0e10cSrcweir ,maItemListeners( *this ) 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir } 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoRoadmapControl, UnoControlRoadmap_Base, UnoControlRoadmap_IBase ) 380*cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( UnoRoadmapControl, UnoControlRoadmap_Base, UnoControlRoadmap_IBase ) 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir sal_Bool SAL_CALL UnoRoadmapControl::setModel(const Reference< XControlModel >& _rModel) throw ( RuntimeException ) 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir Reference< XContainer > xC( getModel(), UNO_QUERY ); 388*cdf0e10cSrcweir if ( xC.is() ) 389*cdf0e10cSrcweir xC->removeContainerListener( this ); 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir sal_Bool bReturn = UnoControlBase::setModel( _rModel ); 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir xC = xC.query( getModel()); 394*cdf0e10cSrcweir if ( xC.is() ) 395*cdf0e10cSrcweir xC->addContainerListener( this ); 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir return bReturn; 398*cdf0e10cSrcweir } 399*cdf0e10cSrcweir 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir // ------------------------------------------------------------------- 402*cdf0e10cSrcweir ::rtl::OUString UnoRoadmapControl::GetComponentServiceName() 403*cdf0e10cSrcweir { 404*cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( "Roadmap" ); 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir void UnoRoadmapControl::dispose() throw(RuntimeException) 410*cdf0e10cSrcweir { 411*cdf0e10cSrcweir EventObject aEvt; 412*cdf0e10cSrcweir aEvt.Source = (::cppu::OWeakObject*)this; 413*cdf0e10cSrcweir maItemListeners.disposeAndClear( aEvt ); 414*cdf0e10cSrcweir UnoControl::dispose(); 415*cdf0e10cSrcweir } 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir 419*cdf0e10cSrcweir void UnoRoadmapControl::elementInserted( const ContainerEvent& rEvent )throw(RuntimeException) 420*cdf0e10cSrcweir { 421*cdf0e10cSrcweir Reference< XInterface > xRoadmapItem; 422*cdf0e10cSrcweir rEvent.Element >>= xRoadmapItem; 423*cdf0e10cSrcweir Reference< XPropertySet > xRoadmapPropertySet( xRoadmapItem, UNO_QUERY ); 424*cdf0e10cSrcweir if ( xRoadmapPropertySet.is() ) 425*cdf0e10cSrcweir xRoadmapPropertySet->addPropertyChangeListener( rtl::OUString(), this ); 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir Reference< XContainerListener > xPeer(getPeer(), UNO_QUERY); 428*cdf0e10cSrcweir if ( xPeer.is() ) 429*cdf0e10cSrcweir { 430*cdf0e10cSrcweir xPeer->elementInserted( rEvent ); 431*cdf0e10cSrcweir Reference < XPropertySet > xPropertySet( xPeer, UNO_QUERY ); 432*cdf0e10cSrcweir if ( xPropertySet.is() ) 433*cdf0e10cSrcweir xPropertySet->addPropertyChangeListener( rtl::OUString(), this ); 434*cdf0e10cSrcweir } 435*cdf0e10cSrcweir } 436*cdf0e10cSrcweir 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir void UnoRoadmapControl::elementRemoved( const ContainerEvent& rEvent )throw(RuntimeException) 439*cdf0e10cSrcweir { 440*cdf0e10cSrcweir Reference< XContainerListener > xPeer(getPeer(), UNO_QUERY); 441*cdf0e10cSrcweir if ( xPeer.is() ) 442*cdf0e10cSrcweir xPeer->elementRemoved( rEvent ); 443*cdf0e10cSrcweir Reference< XInterface > xRoadmapItem; 444*cdf0e10cSrcweir rEvent.Element >>= xRoadmapItem; 445*cdf0e10cSrcweir Reference< XPropertySet > xPropertySet( xRoadmapItem, UNO_QUERY ); 446*cdf0e10cSrcweir if ( xPropertySet.is() ) 447*cdf0e10cSrcweir xPropertySet->removePropertyChangeListener( rtl::OUString(), this ); 448*cdf0e10cSrcweir } 449*cdf0e10cSrcweir 450*cdf0e10cSrcweir 451*cdf0e10cSrcweir void UnoRoadmapControl::elementReplaced( const ContainerEvent& rEvent )throw(RuntimeException) 452*cdf0e10cSrcweir { 453*cdf0e10cSrcweir Reference< XContainerListener > xPeer(getPeer(), UNO_QUERY); 454*cdf0e10cSrcweir if ( xPeer.is() ) 455*cdf0e10cSrcweir xPeer->elementReplaced( rEvent ); 456*cdf0e10cSrcweir } 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir void SAL_CALL UnoRoadmapControl::itemStateChanged( const ItemEvent& rEvent ) throw (RuntimeException) 460*cdf0e10cSrcweir { 461*cdf0e10cSrcweir sal_Int16 CurItemIndex = sal::static_int_cast< sal_Int16 >(rEvent.ItemId); 462*cdf0e10cSrcweir Any aAny; 463*cdf0e10cSrcweir aAny <<= CurItemIndex; 464*cdf0e10cSrcweir Reference< XControlModel > xModel( getModel( ), UNO_QUERY ); 465*cdf0e10cSrcweir Reference< XPropertySet > xPropertySet( xModel, UNO_QUERY ); 466*cdf0e10cSrcweir xPropertySet->setPropertyValue( GetPropertyName( BASEPROPERTY_CURRENTITEMID ), aAny ); 467*cdf0e10cSrcweir if ( maItemListeners.getLength() ) 468*cdf0e10cSrcweir maItemListeners.itemStateChanged( rEvent ); 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir void SAL_CALL UnoRoadmapControl::addItemListener( const Reference< XItemListener >& l ) throw (RuntimeException) 473*cdf0e10cSrcweir { 474*cdf0e10cSrcweir maItemListeners.addInterface( l ); 475*cdf0e10cSrcweir if( getPeer().is() && maItemListeners.getLength() == 1 ) 476*cdf0e10cSrcweir { 477*cdf0e10cSrcweir Reference < XItemEventBroadcaster > xRoadmap( getPeer(), UNO_QUERY ); 478*cdf0e10cSrcweir xRoadmap->addItemListener( this ); 479*cdf0e10cSrcweir } 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir 483*cdf0e10cSrcweir void SAL_CALL UnoRoadmapControl::removeItemListener( const Reference< XItemListener >& l ) throw (RuntimeException) 484*cdf0e10cSrcweir { 485*cdf0e10cSrcweir if( getPeer().is() && maItemListeners.getLength() == 1 ) 486*cdf0e10cSrcweir { 487*cdf0e10cSrcweir Reference < XItemEventBroadcaster > xRoadmap( getPeer(), UNO_QUERY ); 488*cdf0e10cSrcweir xRoadmap->removeItemListener( this ); 489*cdf0e10cSrcweir } 490*cdf0e10cSrcweir 491*cdf0e10cSrcweir maItemListeners.removeInterface( l ); 492*cdf0e10cSrcweir } 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir 495*cdf0e10cSrcweir void SAL_CALL UnoRoadmapControl::propertyChange( const PropertyChangeEvent& evt ) throw (RuntimeException) 496*cdf0e10cSrcweir { 497*cdf0e10cSrcweir Reference< XPropertyChangeListener > xPeer(getPeer(), UNO_QUERY); 498*cdf0e10cSrcweir if ( xPeer.is() ) 499*cdf0e10cSrcweir xPeer->propertyChange( evt ); 500*cdf0e10cSrcweir } 501*cdf0e10cSrcweir 502*cdf0e10cSrcweir } 503*cdf0e10cSrcweir 504