diff options
author | Bjoern Michaelsen <bjoern.michaelsen@sun.com> | 2009-12-02 18:23:45 +0100 |
---|---|---|
committer | Bjoern Michaelsen <bjoern.michaelsen@sun.com> | 2009-12-02 18:23:45 +0100 |
commit | 4b8dcfb1c1aa01e0770631cc0d80f662513057c1 (patch) | |
tree | c2ac220b7e1600e0a569f8e115ed818a37164868 /sw/source/core/unocore/unobkm.cxx | |
parent | d7f8ab1fa9a6a51d2508dfa17144aea10ef8d3ff (diff) |
bosdo02: #i33737# implementing Fieldmark parameters as XNameContainer
Diffstat (limited to 'sw/source/core/unocore/unobkm.cxx')
-rw-r--r-- | sw/source/core/unocore/unobkm.cxx | 177 |
1 files changed, 111 insertions, 66 deletions
diff --git a/sw/source/core/unocore/unobkm.cxx b/sw/source/core/unocore/unobkm.cxx index 77241f815773..7b2230710311 100644 --- a/sw/source/core/unocore/unobkm.cxx +++ b/sw/source/core/unocore/unobkm.cxx @@ -353,90 +353,135 @@ void SwXBookmark::removeVetoableChangeListener(const OUString& /*PropertyName*/, throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException ) { } -SwXFieldmark::SwXFieldmark(bool _isReplacementObject, ::sw::mark::IMark* pBkm, SwDoc* pDc) - : SwXFieldmark_BASE(pBkm, pDc) - , isReplacementObject(_isReplacementObject) -{ } -void SwXFieldmark::attachToRange( const uno::Reference < text::XTextRange >& xTextRange ) - throw( lang::IllegalArgumentException, uno::RuntimeException ) +void SwXFieldmarkParameters::insertByName(const OUString& aName, const Any& aElement) + throw (IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException) { - attachToRangeEx( xTextRange, - ( isReplacementObject ? IDocumentMarkAccess::CHECKBOX_FIELDMARK : IDocumentMarkAccess::TEXT_FIELDMARK ) ); + vos::OGuard aGuard(Application::GetSolarMutex()); + IFieldmark::parameter_map_t* pParameters = getCoreParameters(); + if(pParameters->find(aName) != pParameters->end()) + throw ElementExistException(); + if(aElement.getValueType() != getElementType()) + throw IllegalArgumentException(); + (*pParameters)[aName] = aElement; } -::rtl::OUString SwXFieldmark::getFieldType( void ) - throw( ::com::sun::star::uno::RuntimeException ) +void SwXFieldmarkParameters::removeByName(const OUString& aName) + throw (NoSuchElementException, WrappedTargetException, RuntimeException) { - vos::OGuard aGuard( Application::GetSolarMutex( ) ); - IMark* pMark = const_cast< IMark* >( GetBookmark( ) ); - IFieldmark *pBkm = dynamic_cast< IFieldmark* > ( pMark ); - if ( pBkm ) - return pBkm->GetFieldname( ); - else - throw uno::RuntimeException( ); + vos::OGuard aGuard(Application::GetSolarMutex()); + if(!getCoreParameters()->erase(aName)) + throw NoSuchElementException(); } -void SwXFieldmark::setFieldType( const::rtl::OUString & fieldType ) - throw( ::com::sun::star::uno::RuntimeException ) +void SwXFieldmarkParameters::replaceByName(const OUString& aName, const Any& aElement) + throw (IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException) { - vos::OGuard aGuard( Application::GetSolarMutex( ) ); - IMark* pMark = const_cast< IMark* >( GetBookmark( ) ); - IFieldmark *pBkm = dynamic_cast< IFieldmark* >( pMark ); - if ( pBkm ) - pBkm->SetFieldname( fieldType ); - else - throw uno::RuntimeException( ); + vos::OGuard aGuard(Application::GetSolarMutex()); + IFieldmark::parameter_map_t* pParameters = getCoreParameters(); + IFieldmark::parameter_map_t::iterator pEntry = pParameters->find(aName); + if(pEntry == pParameters->end()) + throw NoSuchElementException(); + pEntry->second = aElement; } -sal_Int16 SwXFieldmark::getParamCount( ) - throw( ::com::sun::star::uno::RuntimeException ) +Any SwXFieldmarkParameters::getByName(const OUString& aName) + throw (NoSuchElementException, WrappedTargetException, RuntimeException) { - vos::OGuard aGuard( Application::GetSolarMutex( ) ); - IMark* pMark = const_cast< IMark* >( GetBookmark( ) ); - IFieldmark *pBkm = dynamic_cast< IFieldmark* >( pMark ); - if ( pBkm ) - return pBkm->getNumOfParams( ); - else - throw uno::RuntimeException( ); + vos::OGuard aGuard(Application::GetSolarMutex()); + IFieldmark::parameter_map_t* pParameters = getCoreParameters(); + IFieldmark::parameter_map_t::iterator pEntry = pParameters->find(aName); + if(pEntry == pParameters->end()) + throw NoSuchElementException(); + return makeAny(pEntry->second); } -rtl::OUString SwXFieldmark::getParamName( sal_Int16 i ) - throw( ::com::sun::star::uno::RuntimeException ) +Sequence<OUString> SwXFieldmarkParameters::getElementNames() + throw (RuntimeException) { - vos::OGuard aGuard( Application::GetSolarMutex( ) ); - IMark* pMark = const_cast< IMark* >( GetBookmark( ) ); - IFieldmark *pBkm = dynamic_cast< IFieldmark* >( pMark ); - if ( pBkm ) - return pBkm->getParam( i ).first; - else - throw uno::RuntimeException( ); + vos::OGuard aGuard(Application::GetSolarMutex()); + IFieldmark::parameter_map_t* pParameters = getCoreParameters(); + Sequence<OUString> vResult(pParameters->size()); + OUString* pOutEntry = vResult.getArray(); + for(IFieldmark::parameter_map_t::iterator pEntry = pParameters->begin(); pEntry!=pParameters->end(); ++pEntry, ++pOutEntry) + *pOutEntry = pEntry->first; + return vResult; } -::rtl::OUString SwXFieldmark::getParamValue( ::sal_Int16 i ) - throw( ::com::sun::star::uno::RuntimeException ) +::sal_Bool SwXFieldmarkParameters::hasByName(const OUString& aName) + throw (RuntimeException) { - vos::OGuard aGuard( Application::GetSolarMutex( ) ); - IMark* pMark = const_cast< IMark* >( GetBookmark( ) ); - IFieldmark *pBkm = dynamic_cast< IFieldmark* >( pMark ); - if ( pBkm ) - return pBkm->getParam( i ).second; - else - throw uno::RuntimeException( ); + vos::OGuard aGuard(Application::GetSolarMutex()); + IFieldmark::parameter_map_t* pParameters = getCoreParameters(); + return (pParameters->find(aName) != pParameters->end()); } -void SwXFieldmark::addParam( const ::rtl::OUString & name, - const ::rtl::OUString & value, - sal_Bool replaceExisting ) - throw( ::com::sun::star::uno::RuntimeException ) +Type SwXFieldmarkParameters::getElementType() + throw (RuntimeException) { - vos::OGuard aGuard( Application::GetSolarMutex( ) ); - IMark* pMark = const_cast< IMark* >( GetBookmark( ) ); - IFieldmark *pBkm = dynamic_cast< IFieldmark* >( pMark ); - if ( pBkm ) - pBkm->addParam( const_cast< rtl::OUString& >( name ), - const_cast< rtl::OUString& >( value ), - replaceExisting ); - else - throw uno::RuntimeException( ); + return ::cppu::UnoType<OUString>::get(); +} + +::sal_Bool SwXFieldmarkParameters::hasElements() + throw (RuntimeException) +{ + vos::OGuard aGuard(Application::GetSolarMutex()); + return !getCoreParameters()->empty(); +} + +void SwXFieldmarkParameters::Modify(SfxPoolItem *pOld, SfxPoolItem *pNew) +{ + ClientModify(this, pOld, pNew); +} + + +IFieldmark::parameter_map_t* SwXFieldmarkParameters::getCoreParameters() + throw (RuntimeException) +{ + const IFieldmark* pFieldmark = dynamic_cast< const IFieldmark* >(GetRegisteredIn()); + if(!pFieldmark) + throw RuntimeException(); + return const_cast< IFieldmark* >(pFieldmark)->GetParameters(); +} + +SwXFieldmark::SwXFieldmark(bool _isReplacementObject, ::sw::mark::IMark* pBkm, SwDoc* pDc) + : SwXFieldmark_BASE(pBkm, pDc) + , isReplacementObject(_isReplacementObject) +{ } + +void SwXFieldmark::attachToRange( const uno::Reference < text::XTextRange >& xTextRange ) + throw(IllegalArgumentException, RuntimeException) +{ + attachToRangeEx( xTextRange, + ( isReplacementObject ? IDocumentMarkAccess::CHECKBOX_FIELDMARK : IDocumentMarkAccess::TEXT_FIELDMARK ) ); +} + +::rtl::OUString SwXFieldmark::getFieldType(void) + throw(RuntimeException) +{ + vos::OGuard aGuard(Application::GetSolarMutex()); + const IFieldmark *pBkm = dynamic_cast<const IFieldmark*>(GetBookmark()); + if(!pBkm) + throw RuntimeException(); + return pBkm->GetFieldname(); +} + +void SwXFieldmark::setFieldType(const::rtl::OUString & fieldType) + throw(RuntimeException) +{ + vos::OGuard aGuard(Application::GetSolarMutex()); + IFieldmark *pBkm = dynamic_cast<IFieldmark*>(GetBookmark()); + if(!pBkm) + throw RuntimeException(); + pBkm->SetFieldname(fieldType); +} + +Reference<XNameContainer> SwXFieldmark::getParameters() + throw (RuntimeException) +{ + vos::OGuard aGuard(Application::GetSolarMutex()); + IFieldmark *pBkm = dynamic_cast<IFieldmark*>(GetBookmark()); + if(!pBkm) + throw uno::RuntimeException(); + return Reference<XNameContainer>(new SwXFieldmarkParameters(pBkm)); } |