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