diff options
Diffstat (limited to 'editeng/source/uno')
-rw-r--r-- | editeng/source/uno/UnoForbiddenCharsTable.cxx | 145 | ||||
-rw-r--r-- | editeng/source/uno/unoedhlp.cxx | 197 | ||||
-rw-r--r-- | editeng/source/uno/unoedprx.cxx | 1316 | ||||
-rw-r--r-- | editeng/source/uno/unoedsrc.cxx | 90 | ||||
-rw-r--r-- | editeng/source/uno/unofdesc.cxx | 266 | ||||
-rw-r--r-- | editeng/source/uno/unofield.cxx | 1180 | ||||
-rw-r--r-- | editeng/source/uno/unofored.cxx | 557 | ||||
-rw-r--r-- | editeng/source/uno/unoforou.cxx | 615 | ||||
-rw-r--r-- | editeng/source/uno/unoipset.cxx | 394 | ||||
-rw-r--r-- | editeng/source/uno/unonrule.cxx | 615 | ||||
-rw-r--r-- | editeng/source/uno/unopracc.cxx | 171 | ||||
-rw-r--r-- | editeng/source/uno/unotext.cxx | 2724 | ||||
-rw-r--r-- | editeng/source/uno/unotext2.cxx | 711 | ||||
-rw-r--r-- | editeng/source/uno/unoviwed.cxx | 137 | ||||
-rw-r--r-- | editeng/source/uno/unoviwou.cxx | 173 |
15 files changed, 9291 insertions, 0 deletions
diff --git a/editeng/source/uno/UnoForbiddenCharsTable.cxx b/editeng/source/uno/UnoForbiddenCharsTable.cxx new file mode 100644 index 000000000000..cf3cce7b9adb --- /dev/null +++ b/editeng/source/uno/UnoForbiddenCharsTable.cxx @@ -0,0 +1,145 @@ +/************************************************************************* + * + * 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_editeng.hxx" +#include <editeng/UnoForbiddenCharsTable.hxx> +#include <editeng/forbiddencharacterstable.hxx> +#include <vos/mutex.hxx> +#include <vcl/svapp.hxx> +#include <editeng/unolingu.hxx> // LocalToLanguage, LanguageToLocale + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::i18n; +using namespace ::rtl; +using namespace ::vos; +using namespace ::cppu; + +SvxUnoForbiddenCharsTable::SvxUnoForbiddenCharsTable(ORef<SvxForbiddenCharactersTable> xForbiddenChars) : + mxForbiddenChars( xForbiddenChars ) +{ +} + +SvxUnoForbiddenCharsTable::~SvxUnoForbiddenCharsTable() +{ +} + +void SvxUnoForbiddenCharsTable::onChange() +{ +} + +ForbiddenCharacters SvxUnoForbiddenCharsTable::getForbiddenCharacters( const Locale& rLocale ) + throw(NoSuchElementException, RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + if(!mxForbiddenChars.isValid()) + throw RuntimeException(); + + const LanguageType eLang = SvxLocaleToLanguage( rLocale ); + const ForbiddenCharacters* pForbidden = mxForbiddenChars->GetForbiddenCharacters( eLang, sal_False ); + if(!pForbidden) + throw NoSuchElementException(); + + return *pForbidden; +} + +sal_Bool SvxUnoForbiddenCharsTable::hasForbiddenCharacters( const Locale& rLocale ) + throw(RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + if(!mxForbiddenChars.isValid()) + return sal_False; + + const LanguageType eLang = SvxLocaleToLanguage( rLocale ); + const ForbiddenCharacters* pForbidden = mxForbiddenChars->GetForbiddenCharacters( eLang, sal_False ); + + return NULL != pForbidden; +} + +void SvxUnoForbiddenCharsTable::setForbiddenCharacters(const Locale& rLocale, const ForbiddenCharacters& rForbiddenCharacters ) + throw(RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + if(!mxForbiddenChars.isValid()) + throw RuntimeException(); + + const LanguageType eLang = SvxLocaleToLanguage( rLocale ); + mxForbiddenChars->SetForbiddenCharacters( eLang, rForbiddenCharacters ); + + onChange(); +} + +void SvxUnoForbiddenCharsTable::removeForbiddenCharacters( const Locale& rLocale ) + throw(RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + if(!mxForbiddenChars.isValid()) + throw RuntimeException(); + + const LanguageType eLang = SvxLocaleToLanguage( rLocale ); + mxForbiddenChars->ClearForbiddenCharacters( eLang ); + + onChange(); +} + +// XSupportedLocales +Sequence< Locale > SAL_CALL SvxUnoForbiddenCharsTable::getLocales() + throw(RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + const sal_Int32 nCount = mxForbiddenChars.isValid() ? mxForbiddenChars->Count() : 0; + + Sequence< Locale > aLocales( nCount ); + if( nCount ) + { + Locale* pLocales = aLocales.getArray(); + + for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ ) + { + const sal_uLong nLanguage = mxForbiddenChars->GetObjectKey( nIndex ); + SvxLanguageToLocale ( *pLocales++, static_cast < LanguageType > (nLanguage) ); + } + } + + return aLocales; +} + +sal_Bool SAL_CALL SvxUnoForbiddenCharsTable::hasLocale( const Locale& aLocale ) + throw(RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + return hasForbiddenCharacters( aLocale ); +} diff --git a/editeng/source/uno/unoedhlp.cxx b/editeng/source/uno/unoedhlp.cxx new file mode 100644 index 000000000000..e8cd841e3157 --- /dev/null +++ b/editeng/source/uno/unoedhlp.cxx @@ -0,0 +1,197 @@ +/************************************************************************* + * + * 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_editeng.hxx" +#include <tools/debug.hxx> + +#include <editeng/unoedhlp.hxx> +#include <editeng/editdata.hxx> +#include <editeng/editeng.hxx> + +//------------------------------------------------------------------------ + +TYPEINIT1( SvxEditSourceHint, TextHint ); + +SvxEditSourceHint::SvxEditSourceHint( sal_uLong _nId ) : + TextHint( _nId ), + mnStart( 0 ), + mnEnd( 0 ) +{ +} + +SvxEditSourceHint::SvxEditSourceHint( sal_uLong _nId, sal_uLong nValue, sal_uLong nStart, sal_uLong nEnd ) : + TextHint( _nId, nValue ), + mnStart( nStart), + mnEnd( nEnd ) +{ +} + +sal_uLong SvxEditSourceHint::GetValue() const +{ + return TextHint::GetValue(); +} + +sal_uLong SvxEditSourceHint::GetStartValue() const +{ + return mnStart; +} + +sal_uLong SvxEditSourceHint::GetEndValue() const +{ + return mnEnd; +} + +void SvxEditSourceHint::SetValue( sal_uLong n ) +{ + TextHint::SetValue( n ); +} + +void SvxEditSourceHint::SetStartValue( sal_uLong n ) +{ + mnStart = n; +} + +void SvxEditSourceHint::SetEndValue( sal_uLong n ) +{ + mnEnd = n; +} + +//------------------------------------------------------------------------ + +::std::auto_ptr<SfxHint> SvxEditSourceHelper::EENotification2Hint( EENotify* aNotify ) +{ + if( aNotify ) + { + switch( aNotify->eNotificationType ) + { + case EE_NOTIFY_TEXTMODIFIED: + return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_MODIFIED, aNotify->nParagraph ) ); + + case EE_NOTIFY_PARAGRAPHINSERTED: + return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_PARAINSERTED, aNotify->nParagraph ) ); + + case EE_NOTIFY_PARAGRAPHREMOVED: + return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_PARAREMOVED, aNotify->nParagraph ) ); + + case EE_NOTIFY_PARAGRAPHSMOVED: + return ::std::auto_ptr<SfxHint>( new SvxEditSourceHint( EDITSOURCE_HINT_PARASMOVED, aNotify->nParagraph, aNotify->nParam1, aNotify->nParam2 ) ); + + case EE_NOTIFY_TEXTHEIGHTCHANGED: + return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_TEXTHEIGHTCHANGED, aNotify->nParagraph ) ); + + case EE_NOTIFY_TEXTVIEWSCROLLED: + return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_VIEWSCROLLED ) ); + + case EE_NOTIFY_TEXTVIEWSELECTIONCHANGED: + return ::std::auto_ptr<SfxHint>( new SvxEditSourceHint( EDITSOURCE_HINT_SELECTIONCHANGED ) ); + + case EE_NOTIFY_BLOCKNOTIFICATION_START: + return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_START, 0 ) ); + + case EE_NOTIFY_BLOCKNOTIFICATION_END: + return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_END, 0 ) ); + + case EE_NOTIFY_INPUT_START: + return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_INPUT_START, 0 ) ); + + case EE_NOTIFY_INPUT_END: + return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_INPUT_END, 0 ) ); + + default: + DBG_ERROR( "SvxEditSourceHelper::EENotification2Hint unknown notification" ); + break; + } + } + + return ::std::auto_ptr<SfxHint>( new SfxHint() ); +} + +sal_Bool SvxEditSourceHelper::GetAttributeRun( sal_uInt16& nStartIndex, sal_uInt16& nEndIndex, const EditEngine& rEE, sal_uInt16 nPara, sal_uInt16 nIndex ) +{ + EECharAttribArray aCharAttribs; + + rEE.GetCharAttribs( nPara, aCharAttribs ); + + // find closest index in front of nIndex + sal_uInt16 nAttr, nCurrIndex; + sal_Int32 nClosestStartIndex; + for( nAttr=0, nClosestStartIndex=0; nAttr<aCharAttribs.Count(); ++nAttr ) + { + nCurrIndex = aCharAttribs[nAttr].nStart; + + if( nCurrIndex > nIndex ) + break; // aCharAttribs array is sorted in increasing order for nStart values + + if( nCurrIndex > nClosestStartIndex ) + { + nClosestStartIndex = nCurrIndex; + } + } + + // find closest index behind of nIndex + sal_Int32 nClosestEndIndex; + for( nAttr=0, nClosestEndIndex=rEE.GetTextLen(nPara); nAttr<aCharAttribs.Count(); ++nAttr ) + { + nCurrIndex = aCharAttribs[nAttr].nEnd; + + if( nCurrIndex > nIndex && + nCurrIndex < nClosestEndIndex ) + { + nClosestEndIndex = nCurrIndex; + } + } + + nStartIndex = static_cast<sal_uInt16>( nClosestStartIndex ); + nEndIndex = static_cast<sal_uInt16>( nClosestEndIndex ); + + return sal_True; +} + +Point SvxEditSourceHelper::EEToUserSpace( const Point& rPoint, const Size& rEESize, bool bIsVertical ) +{ + return bIsVertical ? Point( -rPoint.Y() + rEESize.Height(), rPoint.X() ) : rPoint; +} + +Point SvxEditSourceHelper::UserSpaceToEE( const Point& rPoint, const Size& rEESize, bool bIsVertical ) +{ + return bIsVertical ? Point( rPoint.Y(), -rPoint.X() + rEESize.Height() ) : rPoint; +} + +Rectangle SvxEditSourceHelper::EEToUserSpace( const Rectangle& rRect, const Size& rEESize, bool bIsVertical ) +{ + // #106775# Don't touch rect if not vertical + return bIsVertical ? Rectangle( EEToUserSpace(rRect.BottomLeft(), rEESize, bIsVertical), + EEToUserSpace(rRect.TopRight(), rEESize, bIsVertical) ) : rRect; +} + +Rectangle SvxEditSourceHelper::UserSpaceToEE( const Rectangle& rRect, const Size& rEESize, bool bIsVertical ) +{ + // #106775# Don't touch rect if not vertical + return bIsVertical ? Rectangle( UserSpaceToEE(rRect.TopRight(), rEESize, bIsVertical), + UserSpaceToEE(rRect.BottomLeft(), rEESize, bIsVertical) ) : rRect; +} diff --git a/editeng/source/uno/unoedprx.cxx b/editeng/source/uno/unoedprx.cxx new file mode 100644 index 000000000000..01c62014de7c --- /dev/null +++ b/editeng/source/uno/unoedprx.cxx @@ -0,0 +1,1316 @@ +/************************************************************************* + * + * 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_editeng.hxx" + +//------------------------------------------------------------------------ +// +// Global header +// +//------------------------------------------------------------------------ + +#include <limits.h> +#include <vector> +#include <algorithm> +#include <vos/mutex.hxx> +#include <vcl/window.hxx> +#include <vcl/svapp.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +//------------------------------------------------------------------------ +// +// Project-local header +// +//------------------------------------------------------------------------ +#include "editeng/unoedprx.hxx" +#include <editeng/unotext.hxx> +#include <editeng/unoedhlp.hxx> +#include <editeng/editdata.hxx> +#include <editeng/editeng.hxx> +#include <editeng/editview.hxx> +#include <editeng/AccessibleStringWrap.hxx> +#include <editeng/outliner.hxx> + +using namespace ::com::sun::star; + + +class SvxAccessibleTextIndex +{ +public: + SvxAccessibleTextIndex() : + mnPara(0), + mnIndex(0), + mnEEIndex(0), + mnFieldOffset(0), + mnFieldLen(0), + mbInField(sal_False), + mnBulletOffset(0), + mnBulletLen(0), + mbInBullet(sal_False) {}; + ~SvxAccessibleTextIndex() {}; + + // Get/Set current paragraph + void SetParagraph( sal_uInt16 nPara ) + { + mnPara = nPara; + } + sal_uInt16 GetParagraph() const { return mnPara; } + + /** Set the index in the UAA semantic + + @param nIndex + The index from the UA API (fields and bullets are expanded) + + @param rTF + The text forwarder to use in the calculations + */ + void SetIndex( sal_Int32 nIndex, const SvxTextForwarder& rTF ); + void SetIndex( sal_uInt16 nPara, sal_Int32 nIndex, const SvxTextForwarder& rTF ) { SetParagraph(nPara); SetIndex(nIndex, rTF); } + sal_Int32 GetIndex() const { return mnIndex; } + + /** Set the index in the edit engine semantic + + Update the object state to reflect the given index position in + EditEngine/Outliner index values + + @param nEEIndex + The index from the edit engine (fields span exactly one index increment) + + @param rTF + The text forwarder to use in the calculations + */ + void SetEEIndex( sal_uInt16 nEEIndex, const SvxTextForwarder& rTF ); + void SetEEIndex( sal_uInt16 nPara, sal_uInt16 nEEIndex, const SvxTextForwarder& rTF ) { SetParagraph(nPara); SetEEIndex(nEEIndex, rTF); } + sal_uInt16 GetEEIndex() const; + + void SetFieldOffset( sal_Int32 nOffset, sal_Int32 nLen ) { mnFieldOffset = nOffset; mnFieldLen = nLen; } + sal_Int32 GetFieldOffset() const { return mnFieldOffset; } + sal_Int32 GetFieldLen() const { return mnFieldLen; } + void AreInField( sal_Bool bInField = sal_True ) { mbInField = bInField; } + sal_Bool InField() const { return mbInField; } + + void SetBulletOffset( sal_Int32 nOffset, sal_Int32 nLen ) { mnBulletOffset = nOffset; mnBulletLen = nLen; } + sal_Int32 GetBulletOffset() const { return mnBulletOffset; } + sal_Int32 GetBulletLen() const { return mnBulletLen; } + void AreInBullet( sal_Bool bInBullet = sal_True ) { mbInBullet = bInBullet; } + sal_Bool InBullet() const { return mbInBullet; } + + /// returns false if the current index contains non-editable text (e.g. bullets) + sal_Bool IsEditable() const; + + /// returns false if the given range is non-editable (e.g. contains bullets or _parts_ of fields) + sal_Bool IsEditableRange( const SvxAccessibleTextIndex& rEnd ) const; + +private: + sal_uInt16 mnPara; + sal_Int32 mnIndex; + sal_Int32 mnEEIndex; + sal_Int32 mnFieldOffset; + sal_Int32 mnFieldLen; + sal_Bool mbInField; + sal_Int32 mnBulletOffset; + sal_Int32 mnBulletLen; + sal_Bool mbInBullet; +}; + +ESelection MakeEESelection( const SvxAccessibleTextIndex& rStart, const SvxAccessibleTextIndex& rEnd ) +{ + // deal with field special case: to really get a field contained + // within a selection, the start index must be before or on the + // field, the end index after it. + + // The SvxAccessibleTextIndex.GetEEIndex method gives the index on + // the field, as long the input index is on the field. Thus, + // correction necessary for the end index + + // Therefore, for _ranges_, if part of the field is touched, all + // of the field must be selected + if( rStart.GetParagraph() <= rEnd.GetParagraph() || + (rStart.GetParagraph() == rEnd.GetParagraph() && + rStart.GetEEIndex() <= rEnd.GetEEIndex()) ) + { + if( rEnd.InField() && rEnd.GetFieldOffset() ) + return ESelection( rStart.GetParagraph(), rStart.GetEEIndex(), + rEnd.GetParagraph(), rEnd.GetEEIndex()+1 ); + } + else if( rStart.GetParagraph() > rEnd.GetParagraph() || + (rStart.GetParagraph() == rEnd.GetParagraph() && + rStart.GetEEIndex() > rEnd.GetEEIndex()) ) + { + if( rStart.InField() && rStart.GetFieldOffset() ) + return ESelection( rStart.GetParagraph(), rStart.GetEEIndex()+1, + rEnd.GetParagraph(), rEnd.GetEEIndex() ); + } + + return ESelection( rStart.GetParagraph(), rStart.GetEEIndex(), + rEnd.GetParagraph(), rEnd.GetEEIndex() ); +} + +ESelection MakeEESelection( const SvxAccessibleTextIndex& rIndex ) +{ + return ESelection( rIndex.GetParagraph(), rIndex.GetEEIndex(), + rIndex.GetParagraph(), rIndex.GetEEIndex() + 1 ); +} + +sal_uInt16 SvxAccessibleTextIndex::GetEEIndex() const +{ + DBG_ASSERT(mnEEIndex >= 0 && mnEEIndex <= USHRT_MAX, + "SvxAccessibleTextIndex::GetEEIndex: index value overflow"); + + return static_cast< sal_uInt16 > (mnEEIndex); +} + +void SvxAccessibleTextIndex::SetEEIndex( sal_uInt16 nEEIndex, const SvxTextForwarder& rTF ) +{ + // reset + mnFieldOffset = 0; + mbInField = sal_False; + mnFieldLen = 0; + mnBulletOffset = 0; + mbInBullet = sal_False; + mnBulletLen = 0; + + // set known values + mnEEIndex = nEEIndex; + + // calculate unknowns + sal_uInt16 nCurrField, nFieldCount = rTF.GetFieldCount( GetParagraph() ); + + mnIndex = nEEIndex; + + EBulletInfo aBulletInfo = rTF.GetBulletInfo( GetParagraph() ); + + // any text bullets? + if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && + aBulletInfo.bVisible && + aBulletInfo.nType != SVX_NUM_BITMAP ) + { + mnIndex += aBulletInfo.aText.Len(); + } + + for( nCurrField=0; nCurrField < nFieldCount; ++nCurrField ) + { + EFieldInfo aFieldInfo( rTF.GetFieldInfo( GetParagraph(), nCurrField ) ); + + if( aFieldInfo.aPosition.nIndex > nEEIndex ) + break; + + if( aFieldInfo.aPosition.nIndex == nEEIndex ) + { + AreInField(); + break; + } + + // #106010# + mnIndex += ::std::max(aFieldInfo.aCurrentText.Len()-1, 0); + } +} + +void SvxAccessibleTextIndex::SetIndex( sal_Int32 nIndex, const SvxTextForwarder& rTF ) +{ + // reset + mnFieldOffset = 0; + mbInField = sal_False; + mnFieldLen = 0; + mnBulletOffset = 0; + mbInBullet = sal_False; + mnBulletLen = 0; + + // set known values + mnIndex = nIndex; + + // calculate unknowns + sal_uInt16 nCurrField, nFieldCount = rTF.GetFieldCount( GetParagraph() ); + + DBG_ASSERT(nIndex >= 0 && nIndex <= USHRT_MAX, + "SvxAccessibleTextIndex::SetIndex: index value overflow"); + + mnEEIndex = nIndex; + + EBulletInfo aBulletInfo = rTF.GetBulletInfo( GetParagraph() ); + + // any text bullets? + if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && + aBulletInfo.bVisible && + aBulletInfo.nType != SVX_NUM_BITMAP ) + { + sal_Int32 nBulletLen = aBulletInfo.aText.Len(); + + if( nIndex < nBulletLen ) + { + AreInBullet(); + SetBulletOffset( nIndex, nBulletLen ); + mnEEIndex = 0; + return; + } + + mnEEIndex = mnEEIndex - nBulletLen; + } + + for( nCurrField=0; nCurrField < nFieldCount; ++nCurrField ) + { + EFieldInfo aFieldInfo( rTF.GetFieldInfo( GetParagraph(), nCurrField ) ); + + // we're before a field + if( aFieldInfo.aPosition.nIndex > mnEEIndex ) + break; + + // #106010# + mnEEIndex -= ::std::max(aFieldInfo.aCurrentText.Len()-1, 0); + + // we're within a field + if( aFieldInfo.aPosition.nIndex >= mnEEIndex ) + { + AreInField(); + SetFieldOffset( ::std::max(aFieldInfo.aCurrentText.Len()-1, 0) - (aFieldInfo.aPosition.nIndex - mnEEIndex), + aFieldInfo.aCurrentText.Len() ); + mnEEIndex = aFieldInfo.aPosition.nIndex ; + break; + } + } +} + +sal_Bool SvxAccessibleTextIndex::IsEditable() const +{ + if( InBullet() || InField() ) + return sal_False; + + return sal_True; +} + +sal_Bool SvxAccessibleTextIndex::IsEditableRange( const SvxAccessibleTextIndex& rEnd ) const +{ + if( GetIndex() > rEnd.GetIndex() ) + return rEnd.IsEditableRange( *this ); + + if( InBullet() || rEnd.InBullet() ) + return sal_False; + + if( InField() && GetFieldOffset() ) + return sal_False; // within field + + if( rEnd.InField() && rEnd.GetFieldOffset() >= rEnd.GetFieldLen() - 1 ) + return sal_False; // within field + + return sal_True; +} + +//--------------------------------------------------------------------------------- + +SvxEditSourceAdapter::SvxEditSourceAdapter() : mbEditSourceValid( sal_False ) +{ +} + +SvxEditSourceAdapter::~SvxEditSourceAdapter() +{ +} + +SvxEditSource* SvxEditSourceAdapter::Clone() const +{ + if( mbEditSourceValid && mpAdaptee.get() ) + { + ::std::auto_ptr< SvxEditSource > pClonedAdaptee( mpAdaptee->Clone() ); + + if( pClonedAdaptee.get() ) + { + SvxEditSourceAdapter* pClone = new SvxEditSourceAdapter(); + + if( pClone ) + { + pClone->SetEditSource( pClonedAdaptee ); + return pClone; + } + } + } + + return NULL; +} + +SvxAccessibleTextAdapter* SvxEditSourceAdapter::GetTextForwarderAdapter() +{ + if( mbEditSourceValid && mpAdaptee.get() ) + { + SvxTextForwarder* pTextForwarder = mpAdaptee->GetTextForwarder(); + + if( pTextForwarder ) + { + maTextAdapter.SetForwarder(*pTextForwarder); + + return &maTextAdapter; + } + } + + return NULL; +} + +SvxTextForwarder* SvxEditSourceAdapter::GetTextForwarder() +{ + return GetTextForwarderAdapter(); +} + +SvxViewForwarder* SvxEditSourceAdapter::GetViewForwarder() +{ + if( mbEditSourceValid && mpAdaptee.get() ) + return mpAdaptee->GetViewForwarder(); + + return NULL; +} + +SvxAccessibleTextEditViewAdapter* SvxEditSourceAdapter::GetEditViewForwarderAdapter( sal_Bool bCreate ) +{ + if( mbEditSourceValid && mpAdaptee.get() ) + { + SvxEditViewForwarder* pEditViewForwarder = mpAdaptee->GetEditViewForwarder(bCreate); + + if( pEditViewForwarder ) + { + SvxAccessibleTextAdapter* pTextAdapter = GetTextForwarderAdapter(); + + if( pTextAdapter ) + { + maEditViewAdapter.SetForwarder(*pEditViewForwarder, *pTextAdapter); + + return &maEditViewAdapter; + } + } + } + + return NULL; +} + +SvxEditViewForwarder* SvxEditSourceAdapter::GetEditViewForwarder( sal_Bool bCreate ) +{ + return GetEditViewForwarderAdapter( bCreate ); +} + +void SvxEditSourceAdapter::UpdateData() +{ + if( mbEditSourceValid && mpAdaptee.get() ) + mpAdaptee->UpdateData(); +} + +SfxBroadcaster& SvxEditSourceAdapter::GetBroadcaster() const +{ + if( mbEditSourceValid && mpAdaptee.get() ) + return mpAdaptee->GetBroadcaster(); + + return maDummyBroadcaster; +} + +void SvxEditSourceAdapter::SetEditSource( ::std::auto_ptr< SvxEditSource > pAdaptee ) +{ + if( pAdaptee.get() ) + { + mpAdaptee = pAdaptee; + mbEditSourceValid = sal_True; + } + else + { + // do a lazy delete (prevents us from deleting the broadcaster + // from within a broadcast in + // AccessibleTextHelper_Impl::Notify) + mbEditSourceValid = sal_False; + } +} + +sal_Bool SvxEditSourceAdapter::IsValid() const +{ + return mbEditSourceValid; +} + + +//-------------------------------------------------------------------------------------- + +SvxAccessibleTextAdapter::SvxAccessibleTextAdapter() : mrTextForwarder( NULL ) +{ +} + +SvxAccessibleTextAdapter::~SvxAccessibleTextAdapter() +{ +} + +sal_uInt16 SvxAccessibleTextAdapter::GetParagraphCount() const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + return mrTextForwarder->GetParagraphCount(); +} + +sal_uInt16 SvxAccessibleTextAdapter::GetTextLen( sal_uInt16 nParagraph ) const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + SvxAccessibleTextIndex aIndex; + aIndex.SetEEIndex( nParagraph, mrTextForwarder->GetTextLen( nParagraph ), *this ); + + return static_cast< sal_uInt16 >(aIndex.GetIndex()); +} + +String SvxAccessibleTextAdapter::GetText( const ESelection& rSel ) const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + SvxAccessibleTextIndex aStartIndex; + SvxAccessibleTextIndex aEndIndex; + + aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *this ); + aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *this ); + + // normalize selection + if( rSel.nStartPara > rSel.nEndPara || + (rSel.nStartPara == rSel.nEndPara && rSel.nStartPos > rSel.nEndPos) ) + { + ::std::swap( aStartIndex, aEndIndex ); + } + + String sStr = mrTextForwarder->GetText( MakeEESelection(aStartIndex, aEndIndex) ); + + // trim field text, if necessary + if( aStartIndex.InField() ) + { + DBG_ASSERT(aStartIndex.GetFieldOffset() >= 0 && + aStartIndex.GetFieldOffset() <= USHRT_MAX, + "SvxAccessibleTextIndex::GetText: index value overflow"); + + sStr.Erase(0, static_cast< sal_uInt16 > (aStartIndex.GetFieldOffset()) ); + } + if( aEndIndex.InField() && aEndIndex.GetFieldOffset() ) + { + DBG_ASSERT(sStr.Len() - (aEndIndex.GetFieldLen() - aEndIndex.GetFieldOffset()) >= 0 && + sStr.Len() - (aEndIndex.GetFieldLen() - aEndIndex.GetFieldOffset()) <= USHRT_MAX, + "SvxAccessibleTextIndex::GetText: index value overflow"); + + sStr = sStr.Copy(0, static_cast< sal_uInt16 > (sStr.Len() - (aEndIndex.GetFieldLen() - aEndIndex.GetFieldOffset())) ); + } + + EBulletInfo aBulletInfo1 = GetBulletInfo( static_cast< sal_uInt16 >(aStartIndex.GetParagraph()) ); + EBulletInfo aBulletInfo2 = GetBulletInfo( static_cast< sal_uInt16 >(aEndIndex.GetParagraph()) ); + + if( aStartIndex.InBullet() ) + { + // prepend leading bullet + String sBullet = aBulletInfo1.aText; + + DBG_ASSERT(aStartIndex.GetBulletOffset() >= 0 && + aStartIndex.GetBulletOffset() <= USHRT_MAX, + "SvxAccessibleTextIndex::GetText: index value overflow"); + + sBullet.Erase(0, static_cast< sal_uInt16 > (aStartIndex.GetBulletOffset()) ); + + sBullet += sStr; + sStr = sBullet; + } + + if( aEndIndex.InBullet() ) + { + // append trailing bullet + sStr += aBulletInfo2.aText;; + + DBG_ASSERT(sStr.Len() - (aEndIndex.GetBulletLen() - aEndIndex.GetBulletOffset()) >= 0 && + sStr.Len() - (aEndIndex.GetBulletLen() - aEndIndex.GetBulletOffset()) <= USHRT_MAX, + "SvxAccessibleTextIndex::GetText: index value overflow"); + + sStr = sStr.Copy(0, static_cast< sal_uInt16 > (sStr.Len() - (aEndIndex.GetBulletLen() - aEndIndex.GetBulletOffset())) ); + } + else if( aStartIndex.GetParagraph() != aEndIndex.GetParagraph() && + HaveTextBullet( aEndIndex.GetParagraph() ) ) + { + String sBullet = aBulletInfo2.aText; + + DBG_ASSERT(sBullet.Len() - (aEndIndex.GetBulletLen() - aEndIndex.GetBulletOffset()) >= 0 && + sBullet.Len() - (aEndIndex.GetBulletLen() - aEndIndex.GetBulletOffset()) <= USHRT_MAX, + "SvxAccessibleTextIndex::GetText: index value overflow"); + + sBullet = sBullet.Copy(0, static_cast< sal_uInt16 > (sBullet.Len() - (aEndIndex.GetBulletLen() - aEndIndex.GetBulletOffset())) ); + + // insert bullet + sStr.Insert( sBullet, + static_cast< sal_uInt16 > (GetTextLen(aStartIndex.GetParagraph()) - aStartIndex.GetIndex()) ); + } + + return sStr; +} + +SfxItemSet SvxAccessibleTextAdapter::GetAttribs( const ESelection& rSel, sal_Bool bOnlyHardAttrib ) const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + SvxAccessibleTextIndex aStartIndex; + SvxAccessibleTextIndex aEndIndex; + + aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *this ); + aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *this ); + + return mrTextForwarder->GetAttribs( MakeEESelection(aStartIndex, aEndIndex), + bOnlyHardAttrib ); +} + +SfxItemSet SvxAccessibleTextAdapter::GetParaAttribs( sal_uInt16 nPara ) const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + return mrTextForwarder->GetParaAttribs( nPara ); +} + +void SvxAccessibleTextAdapter::SetParaAttribs( sal_uInt16 nPara, const SfxItemSet& rSet ) +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + mrTextForwarder->SetParaAttribs( nPara, rSet ); +} + +void SvxAccessibleTextAdapter::RemoveAttribs( const ESelection& , sal_Bool , sal_uInt16 ) +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); +} + +void SvxAccessibleTextAdapter::GetPortions( sal_uInt16 nPara, SvUShorts& rList ) const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + mrTextForwarder->GetPortions( nPara, rList ); +} + +sal_uInt16 SvxAccessibleTextAdapter::GetItemState( const ESelection& rSel, sal_uInt16 nWhich ) const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + SvxAccessibleTextIndex aStartIndex; + SvxAccessibleTextIndex aEndIndex; + + aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *this ); + aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *this ); + + return mrTextForwarder->GetItemState( MakeEESelection(aStartIndex, aEndIndex), + nWhich ); +} + +sal_uInt16 SvxAccessibleTextAdapter::GetItemState( sal_uInt16 nPara, sal_uInt16 nWhich ) const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + return mrTextForwarder->GetItemState( nPara, nWhich ); +} + +void SvxAccessibleTextAdapter::QuickInsertText( const String& rText, const ESelection& rSel ) +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + SvxAccessibleTextIndex aStartIndex; + SvxAccessibleTextIndex aEndIndex; + + aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *this ); + aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *this ); + + mrTextForwarder->QuickInsertText( rText, + MakeEESelection(aStartIndex, aEndIndex) ); +} + +void SvxAccessibleTextAdapter::QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel ) +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + SvxAccessibleTextIndex aStartIndex; + SvxAccessibleTextIndex aEndIndex; + + aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *this ); + aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *this ); + + mrTextForwarder->QuickInsertField( rFld, + MakeEESelection(aStartIndex, aEndIndex) ); +} + +void SvxAccessibleTextAdapter::QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel ) +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + SvxAccessibleTextIndex aStartIndex; + SvxAccessibleTextIndex aEndIndex; + + aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *this ); + aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *this ); + + mrTextForwarder->QuickSetAttribs( rSet, + MakeEESelection(aStartIndex, aEndIndex) ); +} + +void SvxAccessibleTextAdapter::QuickInsertLineBreak( const ESelection& rSel ) +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + SvxAccessibleTextIndex aStartIndex; + SvxAccessibleTextIndex aEndIndex; + + aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *this ); + aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *this ); + + mrTextForwarder->QuickInsertLineBreak( MakeEESelection(aStartIndex, aEndIndex) ); +} + +SfxItemPool* SvxAccessibleTextAdapter::GetPool() const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + return mrTextForwarder->GetPool(); +} + +XubString SvxAccessibleTextAdapter::CalcFieldValue( const SvxFieldItem& rField, sal_uInt16 nPara, sal_uInt16 nPos, Color*& rpTxtColor, Color*& rpFldColor ) +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + return mrTextForwarder->CalcFieldValue( rField, nPara, nPos, rpTxtColor, rpFldColor ); +} + +void SvxAccessibleTextAdapter::FieldClicked( const SvxFieldItem& rField, sal_uInt16 nPara, xub_StrLen nPos ) +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + mrTextForwarder->FieldClicked( rField, nPara, nPos ); +} + +sal_Int32 SvxAccessibleTextAdapter::CalcLogicalIndex( sal_uInt16 nPara, sal_uInt16 nEEIndex ) +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + SvxAccessibleTextIndex aIndex; + aIndex.SetEEIndex(nPara, nEEIndex, *mrTextForwarder); + return aIndex.GetIndex(); +} + +sal_uInt16 SvxAccessibleTextAdapter::CalcEditEngineIndex( sal_uInt16 nPara, sal_Int32 nLogicalIndex ) +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + SvxAccessibleTextIndex aIndex; + aIndex.SetIndex(nPara, nLogicalIndex, *mrTextForwarder); + return aIndex.GetEEIndex(); +} + + + +sal_Bool SvxAccessibleTextAdapter::IsValid() const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + if( mrTextForwarder ) + return mrTextForwarder->IsValid(); + else + return sal_False; +} + +LanguageType SvxAccessibleTextAdapter::GetLanguage( sal_uInt16 nPara, sal_uInt16 nPos ) const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + SvxAccessibleTextIndex aIndex; + + aIndex.SetIndex( nPara, nPos, *this ); + + return mrTextForwarder->GetLanguage( nPara, aIndex.GetEEIndex() ); +} + +sal_uInt16 SvxAccessibleTextAdapter::GetFieldCount( sal_uInt16 nPara ) const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + return mrTextForwarder->GetFieldCount( nPara ); +} + +EFieldInfo SvxAccessibleTextAdapter::GetFieldInfo( sal_uInt16 nPara, sal_uInt16 nField ) const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + return mrTextForwarder->GetFieldInfo( nPara, nField ); +} + +EBulletInfo SvxAccessibleTextAdapter::GetBulletInfo( sal_uInt16 nPara ) const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + return mrTextForwarder->GetBulletInfo( nPara ); +} + +Rectangle SvxAccessibleTextAdapter::GetCharBounds( sal_uInt16 nPara, sal_uInt16 nIndex ) const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + SvxAccessibleTextIndex aIndex; + aIndex.SetIndex( nPara, nIndex, *this ); + + // preset if anything goes wrong below + // n-th char in GetParagraphIndex's paragraph + Rectangle aRect = mrTextForwarder->GetCharBounds( nPara, static_cast< sal_uInt16 >( aIndex.GetEEIndex() ) ); + + if( aIndex.InBullet() ) + { + EBulletInfo aBulletInfo = GetBulletInfo( nPara ); + + OutputDevice* pOutDev = GetRefDevice(); + + DBG_ASSERT(pOutDev!=NULL, "SvxAccessibleTextAdapter::GetCharBounds: No ref device"); + + // preset if anything goes wrong below + aRect = aBulletInfo.aBounds; // better than nothing + if( pOutDev ) + { + AccessibleStringWrap aStringWrap( *pOutDev, aBulletInfo.aFont, aBulletInfo.aText ); + + if( aStringWrap.GetCharacterBounds( aIndex.GetBulletOffset(), aRect ) ) + aRect.Move( aBulletInfo.aBounds.Left(), aBulletInfo.aBounds.Top() ); + } + } + else + { + // handle field content manually + if( aIndex.InField() ) + { + OutputDevice* pOutDev = GetRefDevice(); + + DBG_ASSERT(pOutDev!=NULL, "SvxAccessibleTextAdapter::GetCharBounds: No ref device"); + + if( pOutDev ) + { + ESelection aSel = MakeEESelection( aIndex ); + + SvxFont aFont = EditEngine::CreateSvxFontFromItemSet( mrTextForwarder->GetAttribs( aSel ) ); + AccessibleStringWrap aStringWrap( *pOutDev, + aFont, + mrTextForwarder->GetText( aSel ) ); + + Rectangle aStartRect = mrTextForwarder->GetCharBounds( nPara, static_cast< sal_uInt16 >( aIndex.GetEEIndex() ) ); + + if( !aStringWrap.GetCharacterBounds( aIndex.GetFieldOffset(), aRect ) ) + aRect = aStartRect; + else + aRect.Move( aStartRect.Left(), aStartRect.Top() ); + } + } + } + + return aRect; +} + +Rectangle SvxAccessibleTextAdapter::GetParaBounds( sal_uInt16 nPara ) const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + EBulletInfo aBulletInfo = GetBulletInfo( nPara ); + + if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && + aBulletInfo.bVisible && + aBulletInfo.nType != SVX_NUM_BITMAP ) + { + // include bullet in para bounding box + Rectangle aRect( mrTextForwarder->GetParaBounds( nPara ) ); + + aRect.Union( aBulletInfo.aBounds ); + + return aRect; + } + + return mrTextForwarder->GetParaBounds( nPara ); +} + +MapMode SvxAccessibleTextAdapter::GetMapMode() const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + return mrTextForwarder->GetMapMode(); +} + +OutputDevice* SvxAccessibleTextAdapter::GetRefDevice() const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + return mrTextForwarder->GetRefDevice(); +} + +sal_Bool SvxAccessibleTextAdapter::GetIndexAtPoint( const Point& rPoint, sal_uInt16& nPara, sal_uInt16& nIndex ) const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + if( !mrTextForwarder->GetIndexAtPoint( rPoint, nPara, nIndex ) ) + return sal_False; + + SvxAccessibleTextIndex aIndex; + aIndex.SetEEIndex(nPara, nIndex, *this); + + DBG_ASSERT(aIndex.GetIndex() >= 0 && aIndex.GetIndex() <= USHRT_MAX, + "SvxAccessibleTextIndex::SetIndex: index value overflow"); + + nIndex = static_cast< sal_uInt16 > (aIndex.GetIndex()); + + EBulletInfo aBulletInfo = GetBulletInfo( nPara ); + + // any text bullets? + if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && + aBulletInfo.bVisible && + aBulletInfo.nType != SVX_NUM_BITMAP ) + { + if( aBulletInfo.aBounds.IsInside( rPoint) ) + { + OutputDevice* pOutDev = GetRefDevice(); + + DBG_ASSERT(pOutDev!=NULL, "SvxAccessibleTextAdapter::GetIndexAtPoint: No ref device"); + + if( !pOutDev ) + return sal_False; + + AccessibleStringWrap aStringWrap( *pOutDev, aBulletInfo.aFont, aBulletInfo.aText ); + + Point aPoint = rPoint; + aPoint.Move( -aBulletInfo.aBounds.Left(), -aBulletInfo.aBounds.Top() ); + + DBG_ASSERT(aStringWrap.GetIndexAtPoint( aPoint ) >= 0 && + aStringWrap.GetIndexAtPoint( aPoint ) <= USHRT_MAX, + "SvxAccessibleTextIndex::SetIndex: index value overflow"); + + nIndex = static_cast< sal_uInt16 > (aStringWrap.GetIndexAtPoint( aPoint )); + return sal_True; + } + } + + if( aIndex.InField() ) + { + OutputDevice* pOutDev = GetRefDevice(); + + DBG_ASSERT(pOutDev!=NULL, "SvxAccessibleTextAdapter::GetIndexAtPoint: No ref device"); + + if( !pOutDev ) + return sal_False; + + ESelection aSelection = MakeEESelection( aIndex ); + SvxFont aFont = EditEngine::CreateSvxFontFromItemSet( mrTextForwarder->GetAttribs( aSelection ) ); + AccessibleStringWrap aStringWrap( *pOutDev, + aFont, + mrTextForwarder->GetText( aSelection ) ); + + Rectangle aRect = mrTextForwarder->GetCharBounds( nPara, aIndex.GetEEIndex() ); + Point aPoint = rPoint; + aPoint.Move( -aRect.Left(), -aRect.Top() ); + + DBG_ASSERT(aIndex.GetIndex() + aStringWrap.GetIndexAtPoint( rPoint ) >= 0 && + aIndex.GetIndex() + aStringWrap.GetIndexAtPoint( rPoint ) <= USHRT_MAX, + "SvxAccessibleTextIndex::SetIndex: index value overflow"); + + nIndex = static_cast< sal_uInt16 >(aIndex.GetIndex() + aStringWrap.GetIndexAtPoint( aPoint )); + return sal_True; + } + + return sal_True; +} + +sal_Bool SvxAccessibleTextAdapter::GetWordIndices( sal_uInt16 nPara, sal_uInt16 nIndex, sal_uInt16& nStart, sal_uInt16& nEnd ) const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + SvxAccessibleTextIndex aIndex; + aIndex.SetIndex(nPara, nIndex, *this); + nIndex = aIndex.GetEEIndex(); + + if( aIndex.InBullet() ) + { + DBG_ASSERT(aIndex.GetBulletLen() >= 0 && + aIndex.GetBulletLen() <= USHRT_MAX, + "SvxAccessibleTextIndex::SetIndex: index value overflow"); + + // always treat bullet as separate word + nStart = 0; + nEnd = static_cast< sal_uInt16 > (aIndex.GetBulletLen()); + + return sal_True; + } + + if( aIndex.InField() ) + { + DBG_ASSERT(aIndex.GetIndex() - aIndex.GetFieldOffset() >= 0 && + aIndex.GetIndex() - aIndex.GetFieldOffset() <= USHRT_MAX && + nStart + aIndex.GetFieldLen() >= 0 && + nStart + aIndex.GetFieldLen() <= USHRT_MAX, + "SvxAccessibleTextIndex::SetIndex: index value overflow"); + + // always treat field as separate word + // TODO: to circumvent this, _we_ would have to do the break iterator stuff! + nStart = static_cast< sal_uInt16 > (aIndex.GetIndex() - aIndex.GetFieldOffset()); + nEnd = static_cast< sal_uInt16 > (nStart + aIndex.GetFieldLen()); + + return sal_True; + } + + if( !mrTextForwarder->GetWordIndices( nPara, nIndex, nStart, nEnd ) ) + return sal_False; + + aIndex.SetEEIndex( nPara, nStart, *this ); + DBG_ASSERT(aIndex.GetIndex() >= 0 && + aIndex.GetIndex() <= USHRT_MAX, + "SvxAccessibleTextIndex::SetIndex: index value overflow"); + nStart = static_cast< sal_uInt16 > (aIndex.GetIndex()); + + aIndex.SetEEIndex( nPara, nEnd, *this ); + DBG_ASSERT(aIndex.GetIndex() >= 0 && + aIndex.GetIndex() <= USHRT_MAX, + "SvxAccessibleTextIndex::SetIndex: index value overflow"); + nEnd = static_cast< sal_uInt16 > (aIndex.GetIndex()); + + return sal_True; +} + +sal_Bool SvxAccessibleTextAdapter::GetAttributeRun( sal_uInt16& nStartIndex, sal_uInt16& nEndIndex, sal_uInt16 nPara, sal_uInt16 nIndex ) const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + SvxAccessibleTextIndex aIndex; + aIndex.SetIndex(nPara, nIndex, *this); + nIndex = aIndex.GetEEIndex(); + + if( aIndex.InBullet() ) + { + DBG_ASSERT(aIndex.GetBulletLen() >= 0 && + aIndex.GetBulletLen() <= USHRT_MAX, + "SvxAccessibleTextIndex::SetIndex: index value overflow"); + + // always treat bullet as distinct attribute + nStartIndex = 0; + nEndIndex = static_cast< sal_uInt16 > (aIndex.GetBulletLen()); + + return sal_True; + } + + if( aIndex.InField() ) + { + DBG_ASSERT(aIndex.GetIndex() - aIndex.GetFieldOffset() >= 0 && + aIndex.GetIndex() - aIndex.GetFieldOffset() <= USHRT_MAX, + "SvxAccessibleTextIndex::SetIndex: index value overflow"); + + // always treat field as distinct attribute + nStartIndex = static_cast< sal_uInt16 > (aIndex.GetIndex() - aIndex.GetFieldOffset()); + nEndIndex = static_cast< sal_uInt16 > (nStartIndex + aIndex.GetFieldLen()); + + return sal_True; + } + + if( !mrTextForwarder->GetAttributeRun( nStartIndex, nEndIndex, nPara, nIndex ) ) + return sal_False; + + aIndex.SetEEIndex( nPara, nStartIndex, *this ); + DBG_ASSERT(aIndex.GetIndex() >= 0 && + aIndex.GetIndex() <= USHRT_MAX, + "SvxAccessibleTextIndex::SetIndex: index value overflow"); + nStartIndex = static_cast< sal_uInt16 > (aIndex.GetIndex()); + + aIndex.SetEEIndex( nPara, nEndIndex, *this ); + DBG_ASSERT(aIndex.GetIndex() >= 0 && + aIndex.GetIndex() <= USHRT_MAX, + "SvxAccessibleTextIndex::SetIndex: index value overflow"); + nEndIndex = static_cast< sal_uInt16 > (aIndex.GetIndex()); + + return sal_True; +} + +sal_uInt16 SvxAccessibleTextAdapter::GetLineCount( sal_uInt16 nPara ) const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + return mrTextForwarder->GetLineCount( nPara ); +} + +sal_uInt16 SvxAccessibleTextAdapter::GetLineLen( sal_uInt16 nPara, sal_uInt16 nLine ) const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + SvxAccessibleTextIndex aStartIndex; + SvxAccessibleTextIndex aEndIndex; + sal_uInt16 nCurrLine; + sal_uInt16 nCurrIndex, nLastIndex; + for( nCurrLine=0, nCurrIndex=0, nLastIndex=0; nCurrLine<=nLine; ++nCurrLine ) + { + nLastIndex = nCurrIndex; + nCurrIndex = + nCurrIndex + mrTextForwarder->GetLineLen( nPara, nCurrLine ); + } + + aEndIndex.SetEEIndex( nPara, nCurrIndex, *this ); + if( nLine > 0 ) + { + aStartIndex.SetEEIndex( nPara, nLastIndex, *this ); + + return static_cast< sal_uInt16 >(aEndIndex.GetIndex() - aStartIndex.GetIndex()); + } + else + return static_cast< sal_uInt16 >(aEndIndex.GetIndex()); +} + +void SvxAccessibleTextAdapter::GetLineBoundaries( /*out*/sal_uInt16 &rStart, /*out*/sal_uInt16 &rEnd, sal_uInt16 nParagraph, sal_uInt16 nLine ) const +{ + mrTextForwarder->GetLineBoundaries( rStart, rEnd, nParagraph, nLine ); +} + +sal_uInt16 SvxAccessibleTextAdapter::GetLineNumberAtIndex( sal_uInt16 nPara, sal_uInt16 nIndex ) const +{ + return mrTextForwarder->GetLineNumberAtIndex( nPara, nIndex ); +} + +sal_Bool SvxAccessibleTextAdapter::Delete( const ESelection& rSel ) +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + SvxAccessibleTextIndex aStartIndex; + SvxAccessibleTextIndex aEndIndex; + + aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *this ); + aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *this ); + + return mrTextForwarder->Delete( MakeEESelection(aStartIndex, aEndIndex ) ); +} + +sal_Bool SvxAccessibleTextAdapter::InsertText( const String& rStr, const ESelection& rSel ) +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + SvxAccessibleTextIndex aStartIndex; + SvxAccessibleTextIndex aEndIndex; + + aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *this ); + aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *this ); + + return mrTextForwarder->InsertText( rStr, MakeEESelection(aStartIndex, aEndIndex) ); +} + +sal_Bool SvxAccessibleTextAdapter::QuickFormatDoc( sal_Bool bFull ) +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + return mrTextForwarder->QuickFormatDoc( bFull ); +} + +sal_Int16 SvxAccessibleTextAdapter::GetDepth( sal_uInt16 nPara ) const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + return mrTextForwarder->GetDepth( nPara ); +} + +sal_Bool SvxAccessibleTextAdapter::SetDepth( sal_uInt16 nPara, sal_Int16 nNewDepth ) +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + return mrTextForwarder->SetDepth( nPara, nNewDepth ); +} + +void SvxAccessibleTextAdapter::SetForwarder( SvxTextForwarder& rForwarder ) +{ + mrTextForwarder = &rForwarder; +} + +sal_Bool SvxAccessibleTextAdapter::HaveImageBullet( sal_uInt16 nPara ) const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + EBulletInfo aBulletInfo = GetBulletInfo( nPara ); + + if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && + aBulletInfo.bVisible && + aBulletInfo.nType == SVX_NUM_BITMAP ) + { + return sal_True; + } + else + { + return sal_False; + } +} + +sal_Bool SvxAccessibleTextAdapter::HaveTextBullet( sal_uInt16 nPara ) const +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + EBulletInfo aBulletInfo = GetBulletInfo( nPara ); + + if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && + aBulletInfo.bVisible && + aBulletInfo.nType != SVX_NUM_BITMAP ) + { + return sal_True; + } + else + { + return sal_False; + } +} + +sal_Bool SvxAccessibleTextAdapter::IsEditable( const ESelection& rSel ) +{ + DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder"); + + SvxAccessibleTextIndex aStartIndex; + SvxAccessibleTextIndex aEndIndex; + + aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *this ); + aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *this ); + + // normalize selection + if( rSel.nStartPara > rSel.nEndPara || + (rSel.nStartPara == rSel.nEndPara && rSel.nStartPos > rSel.nEndPos) ) + { + ::std::swap( aStartIndex, aEndIndex ); + } + + return aStartIndex.IsEditableRange( aEndIndex ); +} + +const SfxItemSet * SvxAccessibleTextAdapter::GetEmptyItemSetPtr() +{ + DBG_ERROR( "not implemented" ); + return 0; +} + +void SvxAccessibleTextAdapter::AppendParagraph() +{ + DBG_ERROR( "not implemented" ); +} + +xub_StrLen SvxAccessibleTextAdapter::AppendTextPortion( sal_uInt16, const String &, const SfxItemSet & ) +{ + DBG_ERROR( "not implemented" ); + return 0; +} +void SvxAccessibleTextAdapter::CopyText(const SvxTextForwarder&) +{ + DBG_ERROR( "not implemented" ); +} + + + +//--------------------------------------------------------------------------------------- + +SvxAccessibleTextEditViewAdapter::SvxAccessibleTextEditViewAdapter() +{ +} + +SvxAccessibleTextEditViewAdapter::~SvxAccessibleTextEditViewAdapter() +{ +} + +sal_Bool SvxAccessibleTextEditViewAdapter::IsValid() const +{ + DBG_ASSERT(mrViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder"); + + if( mrViewForwarder ) + return mrViewForwarder->IsValid(); + else + return sal_False; +} + +Rectangle SvxAccessibleTextEditViewAdapter::GetVisArea() const +{ + DBG_ASSERT(mrViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder"); + + return mrViewForwarder->GetVisArea(); +} + +Point SvxAccessibleTextEditViewAdapter::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const +{ + DBG_ASSERT(mrViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder"); + + return mrViewForwarder->LogicToPixel(rPoint, rMapMode); +} + +Point SvxAccessibleTextEditViewAdapter::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const +{ + DBG_ASSERT(mrViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder"); + + return mrViewForwarder->PixelToLogic(rPoint, rMapMode); +} + +sal_Bool SvxAccessibleTextEditViewAdapter::GetSelection( ESelection& rSel ) const +{ + DBG_ASSERT(mrViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder"); + + ESelection aSelection; + + if( !mrViewForwarder->GetSelection( aSelection ) ) + return sal_False; + + SvxAccessibleTextIndex aStartIndex; + SvxAccessibleTextIndex aEndIndex; + + aStartIndex.SetEEIndex( aSelection.nStartPara, aSelection.nStartPos, *mrTextForwarder ); + aEndIndex.SetEEIndex( aSelection.nEndPara, aSelection.nEndPos, *mrTextForwarder ); + + DBG_ASSERT(aStartIndex.GetIndex() >= 0 && aStartIndex.GetIndex() <= USHRT_MAX && + aEndIndex.GetIndex() >= 0 && aEndIndex.GetIndex() <= USHRT_MAX, + "SvxAccessibleTextEditViewAdapter::GetSelection: index value overflow"); + + rSel = ESelection( aStartIndex.GetParagraph(), static_cast< sal_uInt16 > (aStartIndex.GetIndex()), + aEndIndex.GetParagraph(), static_cast< sal_uInt16 > (aEndIndex.GetIndex()) ); + + return sal_True; +} + +sal_Bool SvxAccessibleTextEditViewAdapter::SetSelection( const ESelection& rSel ) +{ + DBG_ASSERT(mrViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder"); + + SvxAccessibleTextIndex aStartIndex; + SvxAccessibleTextIndex aEndIndex; + + aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *mrTextForwarder ); + aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *mrTextForwarder ); + + return mrViewForwarder->SetSelection( MakeEESelection(aStartIndex, aEndIndex) ); +} + +sal_Bool SvxAccessibleTextEditViewAdapter::Copy() +{ + DBG_ASSERT(mrViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder"); + + return mrViewForwarder->Copy(); +} + +sal_Bool SvxAccessibleTextEditViewAdapter::Cut() +{ + DBG_ASSERT(mrViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder"); + + return mrViewForwarder->Cut(); +} + +sal_Bool SvxAccessibleTextEditViewAdapter::Paste() +{ + DBG_ASSERT(mrViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder"); + + return mrViewForwarder->Paste(); +} + +void SvxAccessibleTextEditViewAdapter::SetForwarder( SvxEditViewForwarder& rForwarder, + SvxAccessibleTextAdapter& rTextForwarder ) +{ + mrViewForwarder = &rForwarder; + mrTextForwarder = &rTextForwarder; +} + diff --git a/editeng/source/uno/unoedsrc.cxx b/editeng/source/uno/unoedsrc.cxx new file mode 100644 index 000000000000..06e0d7ac21c9 --- /dev/null +++ b/editeng/source/uno/unoedsrc.cxx @@ -0,0 +1,90 @@ +/************************************************************************* + * + * 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_editeng.hxx" +#include <svl/brdcst.hxx> + +#include <editeng/unoedsrc.hxx> + + +//------------------------------------------------------------------------ + +void SvxEditSource::addRange( SvxUnoTextRangeBase* ) +{ +} + +//------------------------------------------------------------------------ + +void SvxEditSource::removeRange( SvxUnoTextRangeBase* ) +{ +} + +//------------------------------------------------------------------------ + +const SvxUnoTextRangeBaseList& SvxEditSource::getRanges() const +{ + static SvxUnoTextRangeBaseList gList; + return gList; +} + +//------------------------------------------------------------------------ + +SvxTextForwarder::~SvxTextForwarder() +{ +} + +//------------------------------------------------------------------------ + +SvxViewForwarder::~SvxViewForwarder() +{ +} + +//------------------------------------------------------------------------ + +SvxEditSource::~SvxEditSource() +{ +} + +SvxViewForwarder* SvxEditSource::GetViewForwarder() +{ + return NULL; +} + +SvxEditViewForwarder* SvxEditSource::GetEditViewForwarder( sal_Bool ) +{ + return NULL; +} + +SfxBroadcaster& SvxEditSource::GetBroadcaster() const +{ + DBG_ERROR("SvxEditSource::GetBroadcaster called for implementation missing this feature!"); + + static SfxBroadcaster aBroadcaster; + + return aBroadcaster; +} diff --git a/editeng/source/uno/unofdesc.cxx b/editeng/source/uno/unofdesc.cxx new file mode 100644 index 000000000000..d81af6ccff0c --- /dev/null +++ b/editeng/source/uno/unofdesc.cxx @@ -0,0 +1,266 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_editeng.hxx" + +#include <editeng/eeitem.hxx> +#include <com/sun/star/uno/Any.hxx> + +#ifndef _TOOLKIT_HELPRE_VCLUNOHELPER_HXX_ +#include <toolkit/helper/vclunohelper.hxx> +#endif +#include <editeng/fontitem.hxx> +#include <editeng/fhgtitem.hxx> +#include <editeng/postitem.hxx> +#include <editeng/udlnitem.hxx> +#include <editeng/wghtitem.hxx> +#include <editeng/crsditem.hxx> +#include <editeng/wrlmitem.hxx> +#include <editeng/memberids.hrc> +#include <svl/itempool.hxx> + +#include <editeng/unofdesc.hxx> + +using namespace ::rtl; +using namespace ::com::sun::star; + + +void SvxUnoFontDescriptor::ConvertToFont( const awt::FontDescriptor& rDesc, Font& rFont ) +{ + rFont.SetName( rDesc.Name ); + rFont.SetStyleName( rDesc.StyleName ); + rFont.SetSize( Size( rDesc.Width, rDesc.Height ) ); + rFont.SetFamily( (FontFamily)rDesc.Family ); + rFont.SetCharSet( (CharSet)rDesc.CharSet ); + rFont.SetPitch( (FontPitch)rDesc.Pitch ); + rFont.SetOrientation( (short)(rDesc.Orientation*10) ); + rFont.SetKerning( rDesc.Kerning ); + rFont.SetWeight( VCLUnoHelper::ConvertFontWeight(rDesc.Weight) ); + rFont.SetItalic( (FontItalic)rDesc.Slant ); + rFont.SetUnderline( (FontUnderline)rDesc.Underline ); + rFont.SetStrikeout( (FontStrikeout)rDesc.Strikeout ); + rFont.SetWordLineMode( rDesc.WordLineMode ); +} + +void SvxUnoFontDescriptor::ConvertFromFont( const Font& rFont, awt::FontDescriptor& rDesc ) +{ + rDesc.Name = rFont.GetName(); + rDesc.StyleName = rFont.GetStyleName(); + rDesc.Width = sal::static_int_cast< sal_Int16 >(rFont.GetSize().Width()); + rDesc.Height = sal::static_int_cast< sal_Int16 >(rFont.GetSize().Height()); + rDesc.Family = sal::static_int_cast< sal_Int16 >(rFont.GetFamily()); + rDesc.CharSet = rFont.GetCharSet(); + rDesc.Pitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch()); + rDesc.Orientation = static_cast< float >(rFont.GetOrientation() / 10); + rDesc.Kerning = rFont.IsKerning(); + rDesc.Weight = VCLUnoHelper::ConvertFontWeight( rFont.GetWeight() ); + rDesc.Slant = (awt::FontSlant)rFont.GetItalic(); + rDesc.Underline = sal::static_int_cast< sal_Int16 >(rFont.GetUnderline()); + rDesc.Strikeout = sal::static_int_cast< sal_Int16 >(rFont.GetStrikeout()); + rDesc.WordLineMode = rFont.IsWordLineMode(); +} + +void SvxUnoFontDescriptor::FillItemSet( const awt::FontDescriptor& rDesc, SfxItemSet& rSet ) +{ + uno::Any aTemp; + + { + SvxFontItem aFontItem( EE_CHAR_FONTINFO ); + aFontItem.GetFamilyName()= rDesc.Name; + aFontItem.GetStyleName() = rDesc.StyleName; + aFontItem.GetFamily() = (FontFamily)rDesc.Family; + aFontItem.GetCharSet() = rDesc.CharSet; + aFontItem.GetPitch() = (FontPitch)rDesc.Pitch; + rSet.Put(aFontItem); + } + + { + SvxFontHeightItem aFontHeightItem( 0, 100, EE_CHAR_FONTHEIGHT ); + aTemp <<= (float)rDesc.Height; + ((SfxPoolItem*)&aFontHeightItem)->PutValue( aTemp, MID_FONTHEIGHT|CONVERT_TWIPS ); + rSet.Put(aFontHeightItem); + } + + { + SvxPostureItem aPostureItem( (FontItalic)0, EE_CHAR_ITALIC ); + aTemp <<= rDesc.Slant; + ((SfxPoolItem*)&aPostureItem)->PutValue( aTemp, MID_POSTURE ); + rSet.Put(aPostureItem); + } + + { + SvxUnderlineItem aUnderlineItem( (FontUnderline)0, EE_CHAR_UNDERLINE ); + aTemp <<= (sal_Int16)rDesc.Underline; + ((SfxPoolItem*)&aUnderlineItem)->PutValue( aTemp, MID_TL_STYLE ); + rSet.Put( aUnderlineItem ); + } + + { + SvxWeightItem aWeightItem( (FontWeight)0, EE_CHAR_WEIGHT ); + aTemp <<= rDesc.Weight; + ((SfxPoolItem*)&aWeightItem)->PutValue( aTemp, MID_WEIGHT ); + rSet.Put( aWeightItem ); + } + + { + SvxCrossedOutItem aCrossedOutItem( (FontStrikeout)0, EE_CHAR_STRIKEOUT ); + aTemp <<= rDesc.Strikeout; + ((SfxPoolItem*)&aCrossedOutItem)->PutValue( aTemp, MID_CROSS_OUT ); + rSet.Put( aCrossedOutItem ); + } + + { + SvxWordLineModeItem aWLMItem( rDesc.WordLineMode, EE_CHAR_WLM ); + rSet.Put( aWLMItem ); + } +} + +void SvxUnoFontDescriptor::FillFromItemSet( const SfxItemSet& rSet, awt::FontDescriptor& rDesc ) +{ + const SfxPoolItem* pItem = NULL; + { + SvxFontItem* pFontItem = (SvxFontItem*)&rSet.Get( EE_CHAR_FONTINFO, sal_True ); + rDesc.Name = pFontItem->GetFamilyName(); + rDesc.StyleName = pFontItem->GetStyleName(); + rDesc.Family = sal::static_int_cast< sal_Int16 >( + pFontItem->GetFamily()); + rDesc.CharSet = pFontItem->GetCharSet(); + rDesc.Pitch = sal::static_int_cast< sal_Int16 >( + pFontItem->GetPitch()); + } + { + pItem = &rSet.Get( EE_CHAR_FONTHEIGHT, sal_True ); + uno::Any aHeight; + if( pItem->QueryValue( aHeight, MID_FONTHEIGHT ) ) + aHeight >>= rDesc.Height; + } + { + pItem = &rSet.Get( EE_CHAR_ITALIC, sal_True ); + uno::Any aFontSlant; + if(pItem->QueryValue( aFontSlant, MID_POSTURE )) + aFontSlant >>= rDesc.Slant; + } + { + pItem = &rSet.Get( EE_CHAR_UNDERLINE, sal_True ); + uno::Any aUnderline; + if(pItem->QueryValue( aUnderline, MID_TL_STYLE )) + aUnderline >>= rDesc.Underline; + } + { + pItem = &rSet.Get( EE_CHAR_WEIGHT, sal_True ); + uno::Any aWeight; + if(pItem->QueryValue( aWeight, MID_WEIGHT )) + aWeight >>= rDesc.Weight; + } + { + pItem = &rSet.Get( EE_CHAR_STRIKEOUT, sal_True ); + uno::Any aStrikeOut; + if(pItem->QueryValue( aStrikeOut, MID_CROSS_OUT )) + aStrikeOut >>= rDesc.Strikeout; + } + { + SvxWordLineModeItem* pWLMItem = (SvxWordLineModeItem*)&rSet.Get( EE_CHAR_WLM, sal_True ); + rDesc.WordLineMode = pWLMItem->GetValue(); + } +} + +#define CheckState( state ) \ + switch( state ) \ + { \ + case SFX_ITEM_DONTCARE: \ + case SFX_ITEM_DISABLED: \ + return beans::PropertyState_AMBIGUOUS_VALUE; \ + case SFX_ITEM_READONLY: \ + case SFX_ITEM_SET: \ + return beans::PropertyState_DIRECT_VALUE; \ + } + +beans::PropertyState SvxUnoFontDescriptor::getPropertyState( const SfxItemSet& rSet ) +{ + CheckState(rSet.GetItemState( EE_CHAR_FONTINFO, sal_False )); + CheckState(rSet.GetItemState( EE_CHAR_FONTHEIGHT, sal_False )); + CheckState(rSet.GetItemState( EE_CHAR_ITALIC, sal_False )); + CheckState(rSet.GetItemState( EE_CHAR_UNDERLINE, sal_False )); + CheckState(rSet.GetItemState( EE_CHAR_WEIGHT, sal_False )); + CheckState(rSet.GetItemState( EE_CHAR_STRIKEOUT, sal_False )); + CheckState(rSet.GetItemState( EE_CHAR_WLM, sal_False )); + + return beans::PropertyState_DEFAULT_VALUE; +} + +void SvxUnoFontDescriptor::setPropertyToDefault( SfxItemSet& rSet ) +{ + rSet.InvalidateItem( EE_CHAR_FONTINFO ); + rSet.InvalidateItem( EE_CHAR_FONTHEIGHT ); + rSet.InvalidateItem( EE_CHAR_ITALIC ); + rSet.InvalidateItem( EE_CHAR_UNDERLINE ); + rSet.InvalidateItem( EE_CHAR_WEIGHT ); + rSet.InvalidateItem( EE_CHAR_STRIKEOUT ); + rSet.InvalidateItem( EE_CHAR_WLM ); +} + +uno::Any SvxUnoFontDescriptor::getPropertyDefault( SfxItemPool* pPool ) +{ + SfxItemSet aSet( *pPool, EE_CHAR_FONTINFO, EE_CHAR_FONTINFO, + EE_CHAR_FONTHEIGHT, EE_CHAR_FONTHEIGHT, + EE_CHAR_ITALIC, EE_CHAR_ITALIC, + EE_CHAR_UNDERLINE, EE_CHAR_UNDERLINE, + EE_CHAR_WEIGHT, EE_CHAR_WEIGHT, + EE_CHAR_STRIKEOUT, EE_CHAR_STRIKEOUT, + EE_CHAR_WLM, EE_CHAR_WLM, 0 ); + + uno::Any aAny; + + if(!pPool->IsWhich(EE_CHAR_FONTINFO)|| + !pPool->IsWhich(EE_CHAR_FONTHEIGHT)|| + !pPool->IsWhich(EE_CHAR_ITALIC)|| + !pPool->IsWhich(EE_CHAR_UNDERLINE)|| + !pPool->IsWhich(EE_CHAR_WEIGHT)|| + !pPool->IsWhich(EE_CHAR_STRIKEOUT)|| + !pPool->IsWhich(EE_CHAR_WLM)) + return aAny; + + aSet.Put(pPool->GetDefaultItem(EE_CHAR_FONTINFO)); + aSet.Put(pPool->GetDefaultItem(EE_CHAR_FONTHEIGHT)); + aSet.Put(pPool->GetDefaultItem(EE_CHAR_ITALIC)); + aSet.Put(pPool->GetDefaultItem(EE_CHAR_UNDERLINE)); + aSet.Put(pPool->GetDefaultItem(EE_CHAR_WEIGHT)); + aSet.Put(pPool->GetDefaultItem(EE_CHAR_STRIKEOUT)); + aSet.Put(pPool->GetDefaultItem(EE_CHAR_WLM)); + + awt::FontDescriptor aDesc; + + FillFromItemSet( aSet, aDesc ); + + aAny <<= aDesc; + + return aAny; +} + + + diff --git a/editeng/source/uno/unofield.cxx b/editeng/source/uno/unofield.cxx new file mode 100644 index 000000000000..dbf52dddc757 --- /dev/null +++ b/editeng/source/uno/unofield.cxx @@ -0,0 +1,1180 @@ +/************************************************************************* + * + * 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_editeng.hxx" +#include <com/sun/star/util/DateTime.hpp> +#include <com/sun/star/text/FilenameDisplayFormat.hpp> +#include <com/sun/star/lang/NoSupportException.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <vcl/svapp.hxx> +#include <vos/mutex.hxx> + +#include <rtl/uuid.h> +#include <rtl/memory.h> + +#include <editeng/eeitem.hxx> +#include <editeng/flditem.hxx> +#include <editeng/measfld.hxx> +#include <editeng/unofield.hxx> +#include <editeng/unotext.hxx> +#include <comphelper/serviceinfohelper.hxx> + +using namespace ::rtl; +using namespace ::vos; +using namespace ::cppu; +using namespace ::com::sun::star; + +#define QUERYINT( xint ) \ + if( rType == ::getCppuType((const uno::Reference< xint >*)0) ) \ + aAny <<= uno::Reference< xint >(this) + + +#define WID_DATE 0 +#define WID_BOOL1 1 +#define WID_BOOL2 2 +#define WID_INT32 3 +#define WID_INT16 4 +#define WID_STRING1 5 +#define WID_STRING2 6 +#define WID_STRING3 7 + +class SvxUnoFieldData_Impl +{ +public: + sal_Bool mbBoolean1; + sal_Bool mbBoolean2; + sal_Int32 mnInt32; + sal_Int16 mnInt16; + OUString msString1; + OUString msString2; + OUString msString3; + util::DateTime maDateTime; + + OUString msPresentation; +}; + +const SfxItemPropertySet* ImplGetFieldItemPropertySet( sal_Int32 mnId ) +{ + static SfxItemPropertyMapEntry aExDateTimeFieldPropertyMap_Impl[] = + { + { MAP_CHAR_LEN("DateTime"), WID_DATE, &::getCppuType((const util::DateTime*)0), 0, 0 }, + { MAP_CHAR_LEN("IsFixed"), WID_BOOL1, &::getBooleanCppuType(), 0, 0 }, + { MAP_CHAR_LEN("IsDate"), WID_BOOL2, &::getBooleanCppuType(), 0, 0 }, + { MAP_CHAR_LEN("NumberFormat"), WID_INT32, &::getCppuType((const sal_Int16*)0), 0, 0 }, + {0,0,0,0,0,0} + }; + static SfxItemPropertySet aExDateTimeFieldPropertySet_Impl(aExDateTimeFieldPropertyMap_Impl); + + static SfxItemPropertyMapEntry aDateTimeFieldPropertyMap_Impl[] = + { + { MAP_CHAR_LEN("IsDate"), WID_BOOL2, &::getBooleanCppuType(), 0, 0 }, + {0,0,0,0,0,0} + }; + static SfxItemPropertySet aDateTimeFieldPropertySet_Impl(aDateTimeFieldPropertyMap_Impl); + + static SfxItemPropertyMapEntry aUrlFieldPropertyMap_Impl[] = + { + + { MAP_CHAR_LEN("Format"), WID_INT16, &::getCppuType((const sal_Int16*)0), 0, 0 }, + { MAP_CHAR_LEN("Representation"), WID_STRING1, &::getCppuType((const OUString*)0), 0, 0 }, + { MAP_CHAR_LEN("TargetFrame"), WID_STRING2, &::getCppuType((const OUString*)0), 0, 0 }, + { MAP_CHAR_LEN("URL"), WID_STRING3, &::getCppuType((const OUString*)0), 0, 0 }, + {0,0,0,0,0,0} + }; + static SfxItemPropertySet aUrlFieldPropertySet_Impl(aUrlFieldPropertyMap_Impl); + + static SfxItemPropertyMapEntry aEmptyPropertyMap_Impl[] = + { + {0,0,0,0,0,0} + }; + static SfxItemPropertySet aEmptyPropertySet_Impl(aEmptyPropertyMap_Impl); + + static SfxItemPropertyMapEntry aExtFileFieldPropertyMap_Impl[] = + { + { MAP_CHAR_LEN("IsFixed"), WID_BOOL1, &::getBooleanCppuType(), 0, 0 }, + { MAP_CHAR_LEN("FileFormat"), WID_INT16, &::getCppuType((const sal_Int16*)0), 0, 0 }, + { MAP_CHAR_LEN("CurrentPresentation"), WID_STRING1,&::getCppuType((const OUString*)0), 0, 0 }, + {0,0,0,0,0,0} + }; + static SfxItemPropertySet aExtFileFieldPropertySet_Impl(aExtFileFieldPropertyMap_Impl); + + static SfxItemPropertyMapEntry aAuthorFieldPropertyMap_Impl[] = + { + { MAP_CHAR_LEN("IsFixed"), WID_BOOL1, &::getBooleanCppuType(), 0, 0 }, + { MAP_CHAR_LEN("CurrentPresentation"), WID_STRING1,&::getCppuType((const OUString*)0), 0, 0 }, + { MAP_CHAR_LEN("Content"), WID_STRING2,&::getCppuType((const OUString*)0), 0, 0 }, + { MAP_CHAR_LEN("AuthorFormat"), WID_INT16, &::getCppuType((const sal_Int16*)0), 0, 0 }, + { MAP_CHAR_LEN("FullName"), WID_BOOL2, &::getBooleanCppuType(), 0, 0 }, + {0,0,0,0,0,0} + }; + static SfxItemPropertySet aAuthorFieldPropertySet_Impl(aAuthorFieldPropertyMap_Impl); + + static SfxItemPropertyMapEntry aMeasureFieldPropertyMap_Impl[] = + { + { MAP_CHAR_LEN("Kind"), WID_INT16, &::getCppuType((const sal_Int16*)0), 0, 0 }, + {0,0,0,0,0,0} + }; + static SfxItemPropertySet aMeasureFieldPropertySet_Impl(aMeasureFieldPropertyMap_Impl); + + switch( mnId ) + { + case ID_EXT_DATEFIELD: + case ID_EXT_TIMEFIELD: + return &aExDateTimeFieldPropertySet_Impl; + case ID_URLFIELD: + return &aUrlFieldPropertySet_Impl; + case ID_DATEFIELD: + case ID_TIMEFIELD: + return &aDateTimeFieldPropertySet_Impl; + case ID_EXT_FILEFIELD: + return &aExtFileFieldPropertySet_Impl; + case ID_AUTHORFIELD: + return &aAuthorFieldPropertySet_Impl; + case ID_MEASUREFIELD: + return &aMeasureFieldPropertySet_Impl; +// case ID_PAGEFIELD: +// case ID_PAGESFIELD: +// case ID_FILEFIELD: +// case ID_TABLEFIELD: +// case ID_HEADERFIELD: +// case ID_FOOTERFIELD: +// case ID_DATETIMEFIELD:: + default: + return &aEmptyPropertySet_Impl; + } +} + +static sal_Char const* aFieldItemNameMap_Impl[] = +{ + "Date", + "URL", + "Page", + "Pages", + "Time", + "File", + "Table", + "ExtTime", + "ExtFile", + "Author", + "Measure", + "ExtDate", + "Header", + "Footer", + "DateTime", + "Unknown" +}; + +/* conversion routines */ + +static sal_Int16 getFileNameDisplayFormat( SvxFileFormat nFormat ) +{ + switch( nFormat ) + { + case SVXFILEFORMAT_NAME_EXT: return text::FilenameDisplayFormat::NAME_AND_EXT; + case SVXFILEFORMAT_FULLPATH: return text::FilenameDisplayFormat::FULL; + case SVXFILEFORMAT_PATH: return text::FilenameDisplayFormat::PATH; +// case SVXFILEFORMAT_NAME: + default: return text::FilenameDisplayFormat::NAME; + } +} + +static SvxFileFormat setFileNameDisplayFormat( sal_Int16 nFormat ) +{ + switch( nFormat ) + { + case text::FilenameDisplayFormat::FULL: return SVXFILEFORMAT_FULLPATH; + case text::FilenameDisplayFormat::PATH: return SVXFILEFORMAT_PATH; + case text::FilenameDisplayFormat::NAME: return SVXFILEFORMAT_NAME; +// case text::FilenameDisplayFormat::NAME_AND_EXT: + default: + return SVXFILEFORMAT_NAME_EXT; + } +} + +static util::DateTime getDate( sal_uLong nDate ) +{ + util::DateTime aDate; + memset( &aDate, 0, sizeof( util::DateTime ) ); + + Date aTempDate( nDate ); + + aDate.Day = aTempDate.GetDay(); + aDate.Month = aTempDate.GetMonth(); + aDate.Year = aTempDate.GetYear(); + + return aDate; +} + +inline Date setDate( util::DateTime& rDate ) +{ + return Date( rDate.Day, rDate.Month, rDate.Year ); +} + +static util::DateTime getTime( long nTime ) +{ + util::DateTime aTime; + memset( &aTime, 0, sizeof( util::DateTime ) ); + + Time aTempTime( nTime ); + + aTime.HundredthSeconds = aTempTime.Get100Sec(); + aTime.Seconds = aTempTime.GetSec(); + aTime.Minutes = aTempTime.GetMin(); + aTime.Hours = aTempTime.GetHour(); + + return aTime; +} + +inline Time setTime( util::DateTime& rDate ) +{ + return Time( rDate.Hours, rDate.Minutes, rDate.Seconds, rDate.HundredthSeconds ); +} + +// ==================================================================== +// class SvxUnoTextField +// ==================================================================== +UNO3_GETIMPLEMENTATION_IMPL( SvxUnoTextField ); + +SvxUnoTextField::SvxUnoTextField( sal_Int32 nServiceId ) throw() +: OComponentHelper( getMutex() ) +, mpPropSet(NULL) +, mnServiceId(nServiceId) +, mpImpl( new SvxUnoFieldData_Impl ) +{ + mpPropSet = ImplGetFieldItemPropertySet(mnServiceId); + + memset( &(mpImpl->maDateTime), 0, sizeof( util::DateTime ) ); + + switch( nServiceId ) + { + case ID_EXT_DATEFIELD: + case ID_DATEFIELD: + mpImpl->mbBoolean2 = sal_True; + mpImpl->mnInt32 = SVXDATEFORMAT_STDSMALL; + mpImpl->mbBoolean1 = sal_False; + break; + + case ID_EXT_TIMEFIELD: + case ID_TIMEFIELD: + mpImpl->mbBoolean2 = sal_False; + mpImpl->mbBoolean1 = sal_False; + mpImpl->mnInt32 = SVXTIMEFORMAT_STANDARD; + break; + + case ID_URLFIELD: + mpImpl->mnInt16 = SVXURLFORMAT_REPR; + break; + + case ID_EXT_FILEFIELD: + mpImpl->mbBoolean1 = sal_False; + mpImpl->mnInt16 = text::FilenameDisplayFormat::FULL; + break; + + case ID_AUTHORFIELD: + mpImpl->mnInt16 = SVXAUTHORFORMAT_FULLNAME; + mpImpl->mbBoolean1 = sal_False; + mpImpl->mbBoolean2 = sal_True; + break; + + case ID_MEASUREFIELD: + mpImpl->mnInt16 = SDRMEASUREFIELD_VALUE; + break; + + default: + mpImpl->mbBoolean1 = sal_False; + mpImpl->mbBoolean2 = sal_False; + mpImpl->mnInt32 = 0; + mpImpl->mnInt16 = 0; + + } +} + +SvxUnoTextField::SvxUnoTextField( uno::Reference< text::XTextRange > xAnchor, const OUString& rPresentation, const SvxFieldData* pData ) throw() +: OComponentHelper( getMutex() ) +, mxAnchor( xAnchor ) +, mpPropSet(NULL) +, mnServiceId(ID_UNKNOWN) +, mpImpl( new SvxUnoFieldData_Impl ) +{ + DBG_ASSERT(pData, "pFieldData == NULL! [CL]" ); + + mpImpl->msPresentation = rPresentation; + + if(pData) + { + mnServiceId = GetFieldId(pData); + DBG_ASSERT(mnServiceId != ID_UNKNOWN, "unknown SvxFieldData! [CL]"); + if(mnServiceId != ID_UNKNOWN) + { + // extract field properties from data class + switch( mnServiceId ) + { + case ID_DATEFIELD: + case ID_EXT_DATEFIELD: + { + mpImpl->mbBoolean2 = sal_True; + // #i35416# for variable date field, don't use invalid "0000-00-00" date, + // use current date instead + sal_Bool bFixed = ((SvxDateField*)pData)->GetType() == SVXDATETYPE_FIX; + mpImpl->maDateTime = getDate( bFixed ? + ((SvxDateField*)pData)->GetFixDate() : + Date().GetDate() ); + mpImpl->mnInt32 = ((SvxDateField*)pData)->GetFormat(); + mpImpl->mbBoolean1 = bFixed; + } + break; + + case ID_TIMEFIELD: + mpImpl->mbBoolean2 = sal_False; + mpImpl->mbBoolean1 = sal_False; + mpImpl->mnInt32 = SVXTIMEFORMAT_STANDARD; + break; + + case ID_EXT_TIMEFIELD: + mpImpl->mbBoolean2 = sal_False; + mpImpl->maDateTime = getTime( ((SvxExtTimeField*)pData)->GetFixTime() ); + mpImpl->mbBoolean1 = ((SvxExtTimeField*)pData)->GetType() == SVXTIMETYPE_FIX; + mpImpl->mnInt32 = ((SvxExtTimeField*)pData)->GetFormat(); + break; + + case ID_URLFIELD: + mpImpl->msString1 = ((SvxURLField*)pData)->GetRepresentation(); + mpImpl->msString2 = ((SvxURLField*)pData)->GetTargetFrame(); + mpImpl->msString3 = ((SvxURLField*)pData)->GetURL(); + mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >( + ((SvxURLField*)pData)->GetFormat()); + break; + + case ID_EXT_FILEFIELD: + mpImpl->msString1 = ((SvxExtFileField*)pData)->GetFile(); + mpImpl->mbBoolean1 = ((SvxExtFileField*)pData)->GetType() == SVXFILETYPE_FIX; + mpImpl->mnInt16 = getFileNameDisplayFormat(((SvxExtFileField*)pData)->GetFormat()); + break; + + case ID_AUTHORFIELD: + mpImpl->msString1 = ((SvxAuthorField*)pData)->GetFormatted(); + mpImpl->msString2 = ((SvxAuthorField*)pData)->GetFormatted(); + mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >( + ((SvxAuthorField*)pData)->GetFormat()); + mpImpl->mbBoolean1 = ((SvxAuthorField*)pData)->GetType() == SVXAUTHORTYPE_FIX; + mpImpl->mbBoolean2 = ((SvxAuthorField*)pData)->GetFormat() != SVXAUTHORFORMAT_SHORTNAME; + break; + + case ID_MEASUREFIELD: + mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(((SdrMeasureField*)pData)->GetMeasureFieldKind()); + break; + } + } + } + + mpPropSet = ImplGetFieldItemPropertySet(mnServiceId); +} + +SvxUnoTextField::~SvxUnoTextField() throw() +{ + delete mpImpl; +} + +SvxFieldData* SvxUnoTextField::CreateFieldData() const throw() +{ + SvxFieldData* pData = NULL; + + switch( mnServiceId ) + { + case ID_TIMEFIELD: + case ID_EXT_TIMEFIELD: + case ID_DATEFIELD: + case ID_EXT_DATEFIELD: + { + if( mpImpl->mbBoolean2 ) // IsDate? + { + Date aDate( setDate( mpImpl->maDateTime ) ); + pData = new SvxDateField( aDate, mpImpl->mbBoolean1?SVXDATETYPE_FIX:SVXDATETYPE_VAR ); + if( mpImpl->mnInt32 >= SVXDATEFORMAT_APPDEFAULT && mpImpl->mnInt32 <= SVXDATEFORMAT_F ) + ((SvxDateField*)pData)->SetFormat( (SvxDateFormat)mpImpl->mnInt32 ); + } + else + { + if( mnServiceId != ID_TIMEFIELD && mnServiceId != ID_DATEFIELD ) + { + Time aTime( setTime( mpImpl->maDateTime ) ); + pData = new SvxExtTimeField( aTime, mpImpl->mbBoolean1?SVXTIMETYPE_FIX:SVXTIMETYPE_VAR ); + + if( mpImpl->mnInt32 >= SVXTIMEFORMAT_APPDEFAULT && mpImpl->mnInt32 <= SVXTIMEFORMAT_AM_HMSH ) + ((SvxExtTimeField*)pData)->SetFormat( (SvxTimeFormat)mpImpl->mnInt32 ); + } + else + { + pData = new SvxTimeField(); + } + } + + } + break; + + case ID_URLFIELD: + pData = new SvxURLField( mpImpl->msString3, mpImpl->msString1, mpImpl->msString1.getLength() ? SVXURLFORMAT_REPR : SVXURLFORMAT_URL ); + ((SvxURLField*)pData)->SetTargetFrame( mpImpl->msString2 ); + if( mpImpl->mnInt16 >= SVXURLFORMAT_APPDEFAULT && mpImpl->mnInt16 <= SVXURLFORMAT_REPR ) + ((SvxURLField*)pData)->SetFormat( (SvxURLFormat)mpImpl->mnInt16 ); + break; + + case ID_PAGEFIELD: + pData = new SvxPageField(); + break; + + case ID_PAGESFIELD: + pData = new SvxPagesField(); + break; + + case ID_FILEFIELD: + pData = new SvxFileField(); + break; + + case ID_TABLEFIELD: + pData = new SvxTableField(); + break; + + case ID_EXT_FILEFIELD: + { + // #92009# pass fixed attribute to constructor + pData = new SvxExtFileField( mpImpl->msString1, + mpImpl->mbBoolean1 ? SVXFILETYPE_FIX : SVXFILETYPE_VAR, + setFileNameDisplayFormat(mpImpl->mnInt16 ) ); + break; + } + + case ID_AUTHORFIELD: + { + ::rtl::OUString aContent; + String aFirstName; + String aLastName; + String aEmpty; + + // do we have CurrentPresentation given? + // mimic behaviour of writer, which means: + // prefer CurrentPresentation over Content + // if both are given. + if( mpImpl->msString1.getLength() ) + aContent = mpImpl->msString1; + else + aContent = mpImpl->msString2; + + sal_Int32 nPos = aContent.lastIndexOf( sal_Char(' '), 0 ); + if( nPos > 0 ) + { + aFirstName = aContent.copy( 0, nPos ); + aLastName = aContent.copy( nPos + 1 ); + } + else + { + aLastName = aContent; + } + + // #92009# pass fixed attribute to constructor + pData = new SvxAuthorField( aFirstName, aLastName, aEmpty, + mpImpl->mbBoolean1 ? SVXAUTHORTYPE_FIX : SVXAUTHORTYPE_VAR ); + + if( !mpImpl->mbBoolean2 ) + { + ((SvxAuthorField*)pData)->SetFormat( SVXAUTHORFORMAT_SHORTNAME ); + } + else if( mpImpl->mnInt16 >= SVXAUTHORFORMAT_FULLNAME || mpImpl->mnInt16 <= SVXAUTHORFORMAT_SHORTNAME ) + { + ((SvxAuthorField*)pData)->SetFormat( (SvxAuthorFormat) mpImpl->mnInt16 ); + } + + break; + } + + case ID_MEASUREFIELD: + { + SdrMeasureFieldKind eKind = SDRMEASUREFIELD_VALUE; + if( mpImpl->mnInt16 == (sal_Int16)SDRMEASUREFIELD_UNIT || mpImpl->mnInt16 == (sal_Int16)SDRMEASUREFIELD_ROTA90BLANCS ) + eKind = (SdrMeasureFieldKind) mpImpl->mnInt16; + pData = new SdrMeasureField( eKind); + break; + } + case ID_HEADERFIELD: + pData = new SvxHeaderField(); + break; + case ID_FOOTERFIELD: + pData = new SvxFooterField(); + break; + case ID_DATETIMEFIELD: + pData = new SvxDateTimeField(); + break; + }; + + return pData; +} + +// uno::XInterface +uno::Any SAL_CALL SvxUnoTextField::queryAggregation( const uno::Type & rType ) + throw(uno::RuntimeException) +{ + uno::Any aAny; + + QUERYINT( beans::XPropertySet ); + else QUERYINT( text::XTextContent ); + else QUERYINT( text::XTextField ); + else QUERYINT( lang::XServiceInfo ); + else QUERYINT( lang::XUnoTunnel ); + else + return OComponentHelper::queryAggregation( rType ); + + return aAny; +} + +// XTypeProvider + +uno::Sequence< uno::Type > SAL_CALL SvxUnoTextField::getTypes() + throw (uno::RuntimeException) +{ + if( maTypeSequence.getLength() == 0 ) + { + maTypeSequence = OComponentHelper::getTypes(); + sal_Int32 nOldCount = maTypeSequence.getLength(); + + maTypeSequence.realloc( nOldCount + 4 ); // !DANGER! keep this updated + uno::Type* pTypes = &maTypeSequence.getArray()[nOldCount]; + + *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextField >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< beans::XPropertySet >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< lang::XServiceInfo >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< lang::XUnoTunnel >*)0); + } + return maTypeSequence; +} + +uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextField::getImplementationId() + throw (uno::RuntimeException) +{ + static uno::Sequence< sal_Int8 > aId; + if( aId.getLength() == 0 ) + { + aId.realloc( 16 ); + rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); + } + return aId; +} + +uno::Any SAL_CALL SvxUnoTextField::queryInterface( const uno::Type & rType ) + throw(uno::RuntimeException) +{ + return OComponentHelper::queryInterface(rType); +} + +void SAL_CALL SvxUnoTextField::acquire() throw( ) +{ + OComponentHelper::acquire(); +} + +void SAL_CALL SvxUnoTextField::release() throw( ) +{ + OComponentHelper::release(); +} + +// Interface text::XTextField +OUString SAL_CALL SvxUnoTextField::getPresentation( sal_Bool bShowCommand ) + throw(uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + if(bShowCommand) + { + DBG_ASSERT( ((sal_uInt32)mnServiceId) < ID_UNKNOWN, "Unknown field type" ); + return OUString::createFromAscii( aFieldItemNameMap_Impl[(((sal_uInt32)mnServiceId) > ID_UNKNOWN)? ID_UNKNOWN : mnServiceId ] ); + } + else + { + return mpImpl->msPresentation; + } +} + +// Interface text::XTextContent +void SAL_CALL SvxUnoTextField::attach( const uno::Reference< text::XTextRange >& xTextRange ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + SvxUnoTextRangeBase* pRange = SvxUnoTextRange::getImplementation( xTextRange ); + if(pRange == NULL) + throw lang::IllegalArgumentException(); + + SvxFieldData* pData = CreateFieldData(); + if( pData ) + pRange->attachField( pData ); + + delete pData; +} + +uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextField::getAnchor() + throw(uno::RuntimeException) +{ + return mxAnchor; +} + +// lang::XComponent +void SAL_CALL SvxUnoTextField::dispose() + throw(uno::RuntimeException) +{ + OComponentHelper::dispose(); +} + +void SAL_CALL SvxUnoTextField::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) + throw(uno::RuntimeException) +{ + OComponentHelper::addEventListener(xListener); +} + +void SAL_CALL SvxUnoTextField::removeEventListener( const uno::Reference< lang::XEventListener >& aListener ) + throw(uno::RuntimeException) +{ + OComponentHelper::removeEventListener(aListener); +} + + +// Interface beans::XPropertySet +uno::Reference< beans::XPropertySetInfo > SAL_CALL SvxUnoTextField::getPropertySetInfo( ) + throw(uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + return mpPropSet->getPropertySetInfo(); +} + +void SAL_CALL SvxUnoTextField::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + if( mpImpl == NULL ) + throw uno::RuntimeException(); + + const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap()->getByName( aPropertyName ); + if ( !pMap ) + throw beans::UnknownPropertyException(); + + switch( pMap->nWID ) + { + case WID_DATE: + if(aValue >>= mpImpl->maDateTime) + return; + break; + case WID_BOOL1: + if(aValue >>= mpImpl->mbBoolean1) + return; + break; + case WID_BOOL2: + if(aValue >>= mpImpl->mbBoolean2) + return; + break; + case WID_INT16: + if(aValue >>= mpImpl->mnInt16) + return; + break; + case WID_INT32: + if(aValue >>= mpImpl->mnInt32) + return; + break; + case WID_STRING1: + if(aValue >>= mpImpl->msString1) + return; + break; + case WID_STRING2: + if(aValue >>= mpImpl->msString2) + return; + break; + case WID_STRING3: + if(aValue >>= mpImpl->msString3) + return; + break; + } + + throw lang::IllegalArgumentException(); + +/* + case WID_FORMAT: + { + sal_Int32 nFormat; + + switch( mnId ) + { + case ID_DATEFIELD: + { + SvxDateField* pDate = PTR_CAST( SvxDateField, aFieldItem.GetField() ); + if(pDate) + pDate->SetFormat( (SvxDateFormat)nFormat ); + break; + } + case ID_URLFIELD: + { + SvxURLField* pURL = PTR_CAST( SvxURLField, aFieldItem.GetField() ); + if(pURL) + pURL->SetFormat( (SvxURLFormat)nFormat ); + break; + } + case ID_EXT_TIMEFIELD: + { + SvxExtTimeField* pTime = PTR_CAST( SvxExtTimeField, aFieldItem.GetField() ); + if(pTime) + pTime->SetFormat( (SvxTimeFormat)nFormat ); + break; + } + case ID_EXT_FILEFIELD: + { + SvxExtFileField* pFile = PTR_CAST( SvxExtFileField, aFieldItem.GetField() ); + if(pFile) + pFile->SetFormat( (SvxFileFormat)nFormat ); + break; + } + case ID_AUTHORFIELD: + { + SvxAuthorField* pAuthor = PTR_CAST( SvxAuthorField, aFieldItem.GetField() ); + if(pAuthor) + pAuthor->SetFormat( (SvxAuthorFormat)nFormat ); + break; + } + default: + throw beans::UnknownPropertyException(); + } + } + break; + case WID_FIX: + { + if( aValue.hasValue() || aValue.getValueType() != ::getCppuBooleanType() ) + throw lang::IllegalArgumentException(); + sal_Bool bFix( *(sal_Bool*)aValue.getValue() ); + switch( mnId ) + { + case ID_EXT_TIMEFIELD: + { + SvxExtTimeField* pTime = PTR_CAST( SvxExtTimeField, aFieldItem.GetField() ); + if(pTime) + pTime->SetType( (SvxTimeType)bFix?SVXTIMETYPE_FIX:SVXTIMETYPE_VAR ); + break; + } + case ID_DATEFIELD: + { + SvxDateField* pDate = PTR_CAST( SvxDateField, aFieldItem.GetField() ); + if(pDate) + pDate->SetType( (SvxDateType)bFix?SVXDATETYPE_FIX:SVXDATETYPE_VAR ); + break; + } + case ID_EXT_FILEFIELD: + { + SvxExtFileField* pFile = PTR_CAST( SvxExtFileField, aFieldItem.GetField() ); + if(pFile) + pFile->SetType( (SvxFileType)bFix?SVXFILETYPE_FIX:SVXFILETYPE_VAR ); + break; + } + case ID_AUTHORFIELD: + { + SvxAuthorField* pAuthor = PTR_CAST( SvxAuthorField, aFieldItem.GetField() ); + if(pAuthor) + pAuthor->SetType( (SvxAuthorType)bFix?SVXAUTHORTYPE_FIX:SVXAUTHORTYPE_VAR ); + break; + } + default: + throw beans::UnknownPropertyException(); + } + } + break; + case WID_PRES: + case WID_URL: + case WID_TARGET: + { + SvxURLField* pURL = PTR_CAST( SvxURLField, aFieldItem.GetField() ); + if(pURL) + { + OUString aUnoStr; + if(!(aValue >>= aUnoStr)) + throw lang::IllegalArgumentException(); + + switch( pMap->nWID ) + { + case WID_PRES: + pURL->SetRepresentation( aUnoStr ); + break; + case WID_URL: + pURL->SetURL( aUnoStr ); + break; + case WID_TARGET: + pURL->SetTargetFrame( aUnoStr ); + break; + } + } + break; + } + } + + SfxItemSet aSet = pForwarder->GetAttribs( GetSelection() ); + aSet.Put( aFieldItem ); +*/ +} + +uno::Any SAL_CALL SvxUnoTextField::getPropertyValue( const OUString& PropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + uno::Any aValue; + + const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap()->getByName( PropertyName ); + if ( !pMap ) + throw beans::UnknownPropertyException(); + + switch( pMap->nWID ) + { + case WID_DATE: + aValue <<= mpImpl->maDateTime; + break; + case WID_BOOL1: + aValue <<= mpImpl->mbBoolean1; + break; + case WID_BOOL2: + aValue <<= mpImpl->mbBoolean2; + break; + case WID_INT16: + aValue <<= mpImpl->mnInt16; + break; + case WID_INT32: + aValue <<= mpImpl->mnInt32; + break; + case WID_STRING1: + aValue <<= mpImpl->msString1; + break; + case WID_STRING2: + aValue <<= mpImpl->msString2; + break; + case WID_STRING3: + aValue <<= mpImpl->msString3; + break; + } + + return aValue; + +/* + switch(pMap->nWID) + { + case WID_FORMAT: + switch( mnId ) + { + case ID_DATEFIELD: + { + SvxDateField* pDate = PTR_CAST( SvxDateField, pFieldItem->GetField() ); + if(pDate) + aValue <<= (sal_Int32)pDate->GetFormat(); + break; + } + case ID_URLFIELD: + { + SvxURLField* pURL = PTR_CAST( SvxURLField, pFieldItem->GetField() ); + if(pURL) + aValue <<= (sal_Int32)pURL->GetFormat(); + break; + } + case ID_EXT_TIMEFIELD: + { + SvxExtTimeField* pTime = PTR_CAST( SvxExtTimeField, pFieldItem->GetField() ); + if(pTime) + aValue <<= (sal_Int32)pTime->GetFormat(); + break; + } + case ID_EXT_FILEFIELD: + { + SvxExtFileField* pFile = PTR_CAST( SvxExtFileField, pFieldItem->GetField() ); + if(pFile) + aValue <<= (sal_Int32)pFile->GetFormat(); + break; + } + case ID_AUTHORFIELD: + { + SvxAuthorField* pAuthor = PTR_CAST( SvxAuthorField, pFieldItem->GetField() ); + if(pAuthor) + aValue <<= (sal_Int32)pAuthor->GetFormat(); + break; + } + default: + throw beans::UnknownPropertyException(); + } + break; + case WID_FIX: + { + sal_Bool bFix = sal_False; + switch( mnId ) + { + case ID_EXT_TIMEFIELD: + { + SvxExtTimeField* pTime = PTR_CAST( SvxExtTimeField, pFieldItem->GetField() ); + if(pTime) + bFix = pTime->GetType() == SVXTIMETYPE_FIX; + break; + } + case ID_DATEFIELD: + { + SvxDateField* pDate = PTR_CAST( SvxDateField, pFieldItem->GetField() ); + if(pDate) + bFix = pDate->GetType() == SVXDATETYPE_FIX; + break; + } + case ID_EXT_FILEFIELD: + { + SvxExtFileField* pFile = PTR_CAST( SvxExtFileField, pFieldItem->GetField() ); + if(pFile) + bFix = pFile->GetType() == SVXFILETYPE_FIX; + break; + } + case ID_AUTHORFIELD: + { + SvxAuthorField* pAuthor = PTR_CAST( SvxAuthorField, pFieldItem->GetField() ); + if(pAuthor) + bFix = pAuthor->GetType() == SVXAUTHORTYPE_FIX; + break; + } + default: + throw beans::UnknownPropertyException(); + } + aValue.setValue( &bFix, ::getCppuBooleanType() ); + } + break; + case WID_PRES: + case WID_URL: + case WID_TARGET: + { + SvxURLField* pURL = PTR_CAST( SvxURLField, pFieldItem->GetField() ); + if(pURL) + { + OUString aStr; + switch( pMap->nWID ) + { + case WID_PRES: + aStr = pURL->GetRepresentation(); + break; + case WID_URL: + aStr = pURL->GetURL(); + break; + case WID_TARGET: + aStr = pURL->GetTargetFrame(); + break; + } + aValue <<= aStr; + } + break; + } + case WID_FCOLOR: + case WID_TCOLOR: + { + Color* pFColor = NULL; + Color* pTColor = NULL; + const ESelection aSel = GetSelection(); + + pForwarder->CalcFieldValue( *pFieldItem, aSel.nStartPara, aSel.nStartPos, pTColor, pFColor ); + + if( pMap->nWID == WID_FCOLOR ) + aValue <<= (sal_Int32)pFColor->GetColor(); + else + aValue <<= (sal_Int32)pTColor->GetColor(); + break; + + delete pTColor; + delete pFColor; + } + } + return aValue; +*/ +} + +void SAL_CALL SvxUnoTextField::addPropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) throw(::com::sun::star::beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {} +void SAL_CALL SvxUnoTextField::removePropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) throw(::com::sun::star::beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {} +void SAL_CALL SvxUnoTextField::addVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) throw(::com::sun::star::beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {} +void SAL_CALL SvxUnoTextField::removeVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) throw(::com::sun::star::beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {} + +// OComponentHelper +void SvxUnoTextField::disposing() +{ + // nothing to do +} + +sal_Int32 SvxUnoTextField::GetFieldId( const SvxFieldData* pFieldData ) const throw() +{ + if( pFieldData->ISA( SvxURLField ) ) + return ID_URLFIELD; + else if( pFieldData->ISA( SvxPageField ) ) + return ID_PAGEFIELD; + else if( pFieldData->ISA( SvxPagesField ) ) + return ID_PAGESFIELD; + else if( pFieldData->ISA( SvxTimeField ) ) + return ID_TIMEFIELD; + else if( pFieldData->ISA( SvxFileField ) ) + return ID_FILEFIELD; + else if( pFieldData->ISA( SvxTableField ) ) + return ID_TABLEFIELD; + else if( pFieldData->ISA( SvxExtTimeField ) ) + return ID_EXT_TIMEFIELD; + else if( pFieldData->ISA( SvxExtFileField ) ) + return ID_EXT_FILEFIELD; + else if( pFieldData->ISA( SvxAuthorField ) ) + return ID_AUTHORFIELD; + else if( pFieldData->ISA( SvxDateField ) ) + return ID_EXT_DATEFIELD; + else if( pFieldData->ISA( SdrMeasureField ) ) + return ID_MEASUREFIELD; + else if( pFieldData->ISA( SvxHeaderField ) ) + return ID_HEADERFIELD; + else if( pFieldData->ISA( SvxFooterField ) ) + return ID_FOOTERFIELD; + else if( pFieldData->ISA( SvxDateTimeField ) ) + return ID_DATETIMEFIELD; + + return ID_UNKNOWN; +} + +// lang::XServiceInfo +OUString SAL_CALL SvxUnoTextField::getImplementationName() throw(uno::RuntimeException) +{ + return OUString(RTL_CONSTASCII_USTRINGPARAM("SvxUnoTextField")); +} + +static const sal_Char* pOldServiceNames[] = +{ + "com.sun.star.text.TextField.DateTime", + "com.sun.star.text.TextField.URL", + "com.sun.star.text.TextField.PageNumber", + "com.sun.star.text.TextField.PageCount", + "com.sun.star.text.TextField.DateTime", + "com.sun.star.text.TextField.DocInfo.Title", // SvxFileField is used for title + "com.sun.star.text.TextField.SheetName", + "com.sun.star.text.TextField.DateTime", + "com.sun.star.text.TextField.FileName", + "com.sun.star.text.TextField.Author", + "com.sun.star.text.TextField.Measure", + "com.sun.star.text.TextField.DateTime", + "com.sun.star.presentation.TextField.Header", + "com.sun.star.presentation.TextField.Footer", + "com.sun.star.presentation.TextField.DateTime" +}; + +static const sal_Char* pNewServiceNames[] = +{ + "com.sun.star.text.textfield.DateTime", + "com.sun.star.text.textfield.URL", + "com.sun.star.text.textfield.PageNumber", + "com.sun.star.text.textfield.PageCount", + "com.sun.star.text.textfield.DateTime", + "com.sun.star.text.textfield.docinfo.Title", // SvxFileField is used for title + "com.sun.star.text.textfield.SheetName", + "com.sun.star.text.textfield.DateTime", + "com.sun.star.text.textfield.FileName", + "com.sun.star.text.textfield.Author", + "com.sun.star.text.textfield.Measure", + "com.sun.star.text.textfield.DateTime", + "com.sun.star.presentation.textfield.Header", + "com.sun.star.presentation.textfield.Footer", + "com.sun.star.presentation.textfield.DateTime" +}; + +uno::Sequence< OUString > SAL_CALL SvxUnoTextField::getSupportedServiceNames() + throw(uno::RuntimeException) +{ + uno::Sequence< OUString > aSeq( 4 ); + OUString* pServices = aSeq.getArray(); + pServices[0] = OUString::createFromAscii( pNewServiceNames[mnServiceId] ); + pServices[1] = OUString::createFromAscii( pOldServiceNames[mnServiceId] ); + pServices[2] = OUString::createFromAscii( "com.sun.star.text.TextContent" ), + pServices[3] = OUString::createFromAscii( "com.sun.star.text.TextField" ); + + return aSeq; +} + +sal_Bool SAL_CALL SvxUnoTextField::supportsService( const OUString& ServiceName ) throw( uno::RuntimeException ) +{ + return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() ); +} + +uno::Reference< uno::XInterface > SAL_CALL SvxUnoTextCreateTextField( const ::rtl::OUString& ServiceSpecifier ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) +{ + uno::Reference< uno::XInterface > xRet; + + const OUString aTextFieldPrexit( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.textfield.") ); + + // #i93308# up to OOo 3.2 we used this wrong namespace name with the capital T & F. This is + // fixed since OOo 3.2 but for compatibility we will still provide support for the wrong notation. + const OUString aTextFieldPrexit2( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextField.") ); + + if( (ServiceSpecifier.compareTo( aTextFieldPrexit, aTextFieldPrexit.getLength() ) == 0) || + (ServiceSpecifier.compareTo( aTextFieldPrexit2, aTextFieldPrexit2.getLength() ) == 0) ) + { + OUString aFieldType( ServiceSpecifier.copy( aTextFieldPrexit.getLength() ) ); + + sal_Int32 nId = ID_UNKNOWN; + + if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("DateTime") ) ) + { + nId = ID_DATEFIELD; + } + else if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("URL") ) ) + { + nId = ID_URLFIELD; + } + else if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("PageNumber") ) ) + { + nId = ID_PAGEFIELD; + } + else if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("PageCount") ) ) + { + nId = ID_PAGESFIELD; + } + else if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("SheetName") ) ) + { + nId = ID_TABLEFIELD; + } + else if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("FileName") ) ) + { + nId = ID_EXT_FILEFIELD; + } + else if (aFieldType.equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM("docinfo.Title") ) || + aFieldType.equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM("DocInfo.Title") ) ) + { + nId = ID_FILEFIELD; + } + else if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Author") ) ) + { + nId = ID_AUTHORFIELD; + } + else if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Measure") ) ) + { + nId = ID_MEASUREFIELD; + } + + if( nId != ID_UNKNOWN ) + xRet = (::cppu::OWeakObject * )new SvxUnoTextField( nId ); + } + + return xRet; +} diff --git a/editeng/source/uno/unofored.cxx b/editeng/source/uno/unofored.cxx new file mode 100644 index 000000000000..f7d7401d6a3f --- /dev/null +++ b/editeng/source/uno/unofored.cxx @@ -0,0 +1,557 @@ +/************************************************************************* + * + * 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_editeng.hxx" + +#include <algorithm> +#include <editeng/eeitem.hxx> +#include <com/sun/star/i18n/WordType.hpp> + +#include <svl/itemset.hxx> +#include <editeng/editeng.hxx> +#include <editeng/editview.hxx> +#include <editeng/unoedhlp.hxx> +#include <editeng/editdata.hxx> +#include <editeng/outliner.hxx> +#include <editeng/editobj.hxx> // nur fuer die GetText-Kruecke + +#include <editeng/unofored.hxx> + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------ + +SvxEditEngineForwarder::SvxEditEngineForwarder( EditEngine& rEngine ) : + rEditEngine( rEngine ) +{ +} + +SvxEditEngineForwarder::~SvxEditEngineForwarder() +{ + // die EditEngine muss ggf. von aussen geloescht werden +} + +sal_uInt16 SvxEditEngineForwarder::GetParagraphCount() const +{ + return rEditEngine.GetParagraphCount(); +} + +sal_uInt16 SvxEditEngineForwarder::GetTextLen( sal_uInt16 nParagraph ) const +{ + return rEditEngine.GetTextLen( nParagraph ); +} + +String SvxEditEngineForwarder::GetText( const ESelection& rSel ) const +{ + String aRet = rEditEngine.GetText( rSel, LINEEND_LF ); + aRet.ConvertLineEnd(); + return aRet; +} + +SfxItemSet SvxEditEngineForwarder::GetAttribs( const ESelection& rSel, sal_Bool bOnlyHardAttrib ) const +{ + if( rSel.nStartPara == rSel.nEndPara ) + { + sal_uInt8 nFlags = 0; + switch( bOnlyHardAttrib ) + { + case EditEngineAttribs_All: + nFlags = GETATTRIBS_ALL; + break; + case EditEngineAttribs_HardAndPara: + nFlags = GETATTRIBS_PARAATTRIBS|GETATTRIBS_CHARATTRIBS; + break; + case EditEngineAttribs_OnlyHard: + nFlags = GETATTRIBS_CHARATTRIBS; + break; + default: + DBG_ERROR("unknown flags for SvxOutlinerForwarder::GetAttribs"); + } + + return rEditEngine.GetAttribs( rSel.nStartPara, rSel.nStartPos, rSel.nEndPos, nFlags ); + } + else + { + return rEditEngine.GetAttribs( rSel, bOnlyHardAttrib ); + } +} + +SfxItemSet SvxEditEngineForwarder::GetParaAttribs( sal_uInt16 nPara ) const +{ + SfxItemSet aSet( rEditEngine.GetParaAttribs( nPara ) ); + + sal_uInt16 nWhich = EE_PARA_START; + while( nWhich <= EE_PARA_END ) + { + if( aSet.GetItemState( nWhich, sal_True ) != SFX_ITEM_ON ) + { + if( rEditEngine.HasParaAttrib( nPara, nWhich ) ) + aSet.Put( rEditEngine.GetParaAttrib( nPara, nWhich ) ); + } + nWhich++; + } + + return aSet; +} + +void SvxEditEngineForwarder::SetParaAttribs( sal_uInt16 nPara, const SfxItemSet& rSet ) +{ + rEditEngine.SetParaAttribs( nPara, rSet ); +} + +void SvxEditEngineForwarder::RemoveAttribs( const ESelection& rSelection, sal_Bool bRemoveParaAttribs, sal_uInt16 nWhich ) +{ + rEditEngine.RemoveAttribs( rSelection, bRemoveParaAttribs, nWhich ); +} + +SfxItemPool* SvxEditEngineForwarder::GetPool() const +{ + return rEditEngine.GetEmptyItemSet().GetPool(); +} + +void SvxEditEngineForwarder::GetPortions( sal_uInt16 nPara, SvUShorts& rList ) const +{ + rEditEngine.GetPortions( nPara, rList ); +} + +void SvxEditEngineForwarder::QuickInsertText( const String& rText, const ESelection& rSel ) +{ + rEditEngine.QuickInsertText( rText, rSel ); +} + +void SvxEditEngineForwarder::QuickInsertLineBreak( const ESelection& rSel ) +{ + rEditEngine.QuickInsertLineBreak( rSel ); +} + +void SvxEditEngineForwarder::QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel ) +{ + rEditEngine.QuickInsertField( rFld, rSel ); +} + +void SvxEditEngineForwarder::QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel ) +{ + rEditEngine.QuickSetAttribs( rSet, rSel ); +} + +sal_Bool SvxEditEngineForwarder::IsValid() const +{ + // cannot reliably query EditEngine state + // while in the middle of an update + return rEditEngine.GetUpdateMode(); +} + +XubString SvxEditEngineForwarder::CalcFieldValue( const SvxFieldItem& rField, sal_uInt16 nPara, sal_uInt16 nPos, Color*& rpTxtColor, Color*& rpFldColor ) +{ + return rEditEngine.CalcFieldValue( rField, nPara, nPos, rpTxtColor, rpFldColor ); +} + +void SvxEditEngineForwarder::FieldClicked( const SvxFieldItem& rField, sal_uInt16 nPara, xub_StrLen nPos ) +{ + rEditEngine.FieldClicked( rField, nPara, nPos ); +} + +sal_uInt16 GetSvxEditEngineItemState( EditEngine& rEditEngine, const ESelection& rSel, sal_uInt16 nWhich ) +{ + EECharAttribArray aAttribs; + + const SfxPoolItem* pLastItem = NULL; + + SfxItemState eState = SFX_ITEM_DEFAULT; + + // check all paragraphs inside the selection + for( sal_uInt16 nPara = rSel.nStartPara; nPara <= rSel.nEndPara; nPara++ ) + { + SfxItemState eParaState = SFX_ITEM_DEFAULT; + + // calculate start and endpos for this paragraph + sal_uInt16 nPos = 0; + if( rSel.nStartPara == nPara ) + nPos = rSel.nStartPos; + + sal_uInt16 nEndPos = rSel.nEndPos; + if( rSel.nEndPara != nPara ) + nEndPos = rEditEngine.GetTextLen( nPara ); + + + // get list of char attribs + rEditEngine.GetCharAttribs( nPara, aAttribs ); + + sal_Bool bEmpty = sal_True; // we found no item inside the selektion of this paragraph + sal_Bool bGaps = sal_False; // we found items but theire gaps between them + sal_uInt16 nLastEnd = nPos; + + const SfxPoolItem* pParaItem = NULL; + + for( sal_uInt16 nAttrib = 0; nAttrib < aAttribs.Count(); nAttrib++ ) + { + struct EECharAttrib aAttrib = aAttribs.GetObject( nAttrib ); + DBG_ASSERT( aAttrib.pAttr, "GetCharAttribs gives corrupt data" ); + + const sal_Bool bEmptyPortion = aAttrib.nStart == aAttrib.nEnd; + if( (!bEmptyPortion && (aAttrib.nStart >= nEndPos)) || (bEmptyPortion && (aAttrib.nStart > nEndPos)) ) + break; // break if we are already behind our selektion + + if( (!bEmptyPortion && (aAttrib.nEnd <= nPos)) || (bEmptyPortion && (aAttrib.nEnd < nPos)) ) + continue; // or if the attribute ends before our selektion + + if( aAttrib.pAttr->Which() != nWhich ) + continue; // skip if is not the searched item + + // if we already found an item + if( pParaItem ) + { + // ... and its different to this one than the state is dont care + if( *pParaItem != *aAttrib.pAttr ) + return SFX_ITEM_DONTCARE; + } + else + { + pParaItem = aAttrib.pAttr; + } + + if( bEmpty ) + bEmpty = sal_False; + + if( !bGaps && aAttrib.nStart > nLastEnd ) + bGaps = sal_True; + + nLastEnd = aAttrib.nEnd; + } + + if( !bEmpty && !bGaps && nLastEnd < ( nEndPos - 1 ) ) + bGaps = sal_True; +/* + // since we have no portion with our item or if there were gaps + if( bEmpty || bGaps ) + { + // we need to check the paragraph item + const SfxItemSet& rParaSet = rEditEngine.GetParaAttribs( nPara ); + if( rParaSet.GetItemState( nWhich ) == SFX_ITEM_SET ) + { + eState = SFX_ITEM_SET; + // get item from the paragraph + const SfxPoolItem* pTempItem = rParaSet.GetItem( nWhich ); + if( pParaItem ) + { + if( *pParaItem != *pTempItem ) + return SFX_ITEM_DONTCARE; + } + else + { + pParaItem = pTempItem; + } + + // set if theres no last item or if its the same + eParaState = SFX_ITEM_SET; + } + else if( bEmpty ) + { + eParaState = SFX_ITEM_DEFAULT; + } + else if( bGaps ) + { + // gaps and item not set in paragraph, thats a dont care + return SFX_ITEM_DONTCARE; + } + } + else + { + eParaState = SFX_ITEM_SET; + } +*/ + if( bEmpty ) + eParaState = SFX_ITEM_DEFAULT; + else if( bGaps ) + eParaState = SFX_ITEM_DONTCARE; + else + eParaState = SFX_ITEM_SET; + + // if we already found an item check if we found the same + if( pLastItem ) + { + if( (pParaItem == NULL) || (*pLastItem != *pParaItem) ) + return SFX_ITEM_DONTCARE; + } + else + { + pLastItem = pParaItem; + eState = eParaState; + } + } + + return eState; +} + +sal_uInt16 SvxEditEngineForwarder::GetItemState( const ESelection& rSel, sal_uInt16 nWhich ) const +{ + return GetSvxEditEngineItemState( rEditEngine, rSel, nWhich ); +} + +sal_uInt16 SvxEditEngineForwarder::GetItemState( sal_uInt16 nPara, sal_uInt16 nWhich ) const +{ + const SfxItemSet& rSet = rEditEngine.GetParaAttribs( nPara ); + return rSet.GetItemState( nWhich ); +} + +LanguageType SvxEditEngineForwarder::GetLanguage( sal_uInt16 nPara, sal_uInt16 nIndex ) const +{ + return rEditEngine.GetLanguage(nPara, nIndex); +} + +sal_uInt16 SvxEditEngineForwarder::GetFieldCount( sal_uInt16 nPara ) const +{ + return rEditEngine.GetFieldCount(nPara); +} + +EFieldInfo SvxEditEngineForwarder::GetFieldInfo( sal_uInt16 nPara, sal_uInt16 nField ) const +{ + return rEditEngine.GetFieldInfo( nPara, nField ); +} + +EBulletInfo SvxEditEngineForwarder::GetBulletInfo( sal_uInt16 ) const +{ + return EBulletInfo(); +} + +Rectangle SvxEditEngineForwarder::GetCharBounds( sal_uInt16 nPara, sal_uInt16 nIndex ) const +{ + // #101701# + // EditEngine's 'internal' methods like GetCharacterBounds() + // don't rotate for vertical text. + Size aSize( rEditEngine.CalcTextWidth(), rEditEngine.GetTextHeight() ); + ::std::swap( aSize.Width(), aSize.Height() ); + bool bIsVertical( rEditEngine.IsVertical() == sal_True ); + + // #108900# Handle virtual position one-past-the end of the string + if( nIndex >= rEditEngine.GetTextLen(nPara) ) + { + Rectangle aLast; + + if( nIndex ) + { + // use last character, if possible + aLast = rEditEngine.GetCharacterBounds( EPosition(nPara, nIndex-1) ); + + // move at end of this last character, make one pixel wide + aLast.Move( aLast.Right() - aLast.Left(), 0 ); + aLast.SetSize( Size(1, aLast.GetHeight()) ); + + // take care for CTL + aLast = SvxEditSourceHelper::EEToUserSpace( aLast, aSize, bIsVertical ); + } + else + { + // #109864# Bounds must lie within the paragraph + aLast = GetParaBounds( nPara ); + + // #109151# Don't use paragraph height, but line height + // instead. aLast is already CTL-correct + if( bIsVertical) + aLast.SetSize( Size( rEditEngine.GetLineHeight(nPara,0), 1 ) ); + else + aLast.SetSize( Size( 1, rEditEngine.GetLineHeight(nPara,0) ) ); + } + + return aLast; + } + else + { + return SvxEditSourceHelper::EEToUserSpace( rEditEngine.GetCharacterBounds( EPosition(nPara, nIndex) ), + aSize, bIsVertical ); + } +} + +Rectangle SvxEditEngineForwarder::GetParaBounds( sal_uInt16 nPara ) const +{ + const Point aPnt = rEditEngine.GetDocPosTopLeft( nPara ); + sal_uLong nWidth; + sal_uLong nHeight; + sal_uLong nTextWidth; + + if( rEditEngine.IsVertical() ) + { + // #101701# + // Hargl. EditEngine's 'external' methods return the rotated + // dimensions, 'internal' methods like GetTextHeight( n ) + // don't rotate. + nWidth = rEditEngine.GetTextHeight( nPara ); + nHeight = rEditEngine.GetTextHeight(); + nTextWidth = rEditEngine.GetTextHeight(); + + return Rectangle( nTextWidth - aPnt.Y() - nWidth, 0, nTextWidth - aPnt.Y(), nHeight ); + } + else + { + nWidth = rEditEngine.CalcTextWidth(); + nHeight = rEditEngine.GetTextHeight( nPara ); + + return Rectangle( 0, aPnt.Y(), nWidth, aPnt.Y() + nHeight ); + } +} + +MapMode SvxEditEngineForwarder::GetMapMode() const +{ + return rEditEngine.GetRefMapMode(); +} + +OutputDevice* SvxEditEngineForwarder::GetRefDevice() const +{ + return rEditEngine.GetRefDevice(); +} + +sal_Bool SvxEditEngineForwarder::GetIndexAtPoint( const Point& rPos, sal_uInt16& nPara, sal_uInt16& nIndex ) const +{ + // #101701# + Size aSize( rEditEngine.CalcTextWidth(), rEditEngine.GetTextHeight() ); + ::std::swap( aSize.Width(), aSize.Height() ); + Point aEEPos( SvxEditSourceHelper::UserSpaceToEE( rPos, + aSize, + rEditEngine.IsVertical() == sal_True )); + + EPosition aDocPos = rEditEngine.FindDocPosition( aEEPos ); + + nPara = aDocPos.nPara; + nIndex = aDocPos.nIndex; + + return sal_True; +} + +sal_Bool SvxEditEngineForwarder::GetWordIndices( sal_uInt16 nPara, sal_uInt16 nIndex, sal_uInt16& nStart, sal_uInt16& nEnd ) const +{ + ESelection aRes = rEditEngine.GetWord( ESelection(nPara, nIndex, nPara, nIndex), com::sun::star::i18n::WordType::DICTIONARY_WORD ); + + if( aRes.nStartPara == nPara && + aRes.nStartPara == aRes.nEndPara ) + { + nStart = aRes.nStartPos; + nEnd = aRes.nEndPos; + + return sal_True; + } + + return sal_False; +} + +sal_Bool SvxEditEngineForwarder::GetAttributeRun( sal_uInt16& nStartIndex, sal_uInt16& nEndIndex, sal_uInt16 nPara, sal_uInt16 nIndex ) const +{ + return SvxEditSourceHelper::GetAttributeRun( nStartIndex, nEndIndex, rEditEngine, nPara, nIndex ); +} + +sal_uInt16 SvxEditEngineForwarder::GetLineCount( sal_uInt16 nPara ) const +{ + return rEditEngine.GetLineCount(nPara); +} + +sal_uInt16 SvxEditEngineForwarder::GetLineLen( sal_uInt16 nPara, sal_uInt16 nLine ) const +{ + return rEditEngine.GetLineLen(nPara, nLine); +} + +void SvxEditEngineForwarder::GetLineBoundaries( /*out*/sal_uInt16 &rStart, /*out*/sal_uInt16 &rEnd, sal_uInt16 nPara, sal_uInt16 nLine ) const +{ + rEditEngine.GetLineBoundaries(rStart, rEnd, nPara, nLine); +} + +sal_uInt16 SvxEditEngineForwarder::GetLineNumberAtIndex( sal_uInt16 nPara, sal_uInt16 nIndex ) const +{ + return rEditEngine.GetLineNumberAtIndex(nPara, nIndex); +} + + +sal_Bool SvxEditEngineForwarder::QuickFormatDoc( sal_Bool ) +{ + rEditEngine.QuickFormatDoc(); + + return sal_True; +} + +sal_Bool SvxEditEngineForwarder::Delete( const ESelection& rSelection ) +{ + rEditEngine.QuickDelete( rSelection ); + rEditEngine.QuickFormatDoc(); + + return sal_True; +} + +sal_Bool SvxEditEngineForwarder::InsertText( const String& rStr, const ESelection& rSelection ) +{ + rEditEngine.QuickInsertText( rStr, rSelection ); + rEditEngine.QuickFormatDoc(); + + return sal_True; +} + +sal_Int16 SvxEditEngineForwarder::GetDepth( sal_uInt16 ) const +{ + // EditEngine does not support outline depth + return -1; +} + +sal_Bool SvxEditEngineForwarder::SetDepth( sal_uInt16, sal_Int16 nNewDepth ) +{ + // EditEngine does not support outline depth + return nNewDepth == -1 ? sal_True : sal_False; +} + +const SfxItemSet * SvxEditEngineForwarder::GetEmptyItemSetPtr() +{ + return &rEditEngine.GetEmptyItemSet(); +} + +void SvxEditEngineForwarder::AppendParagraph() +{ + rEditEngine.InsertParagraph( rEditEngine.GetParagraphCount(), String::EmptyString() ); +} + +xub_StrLen SvxEditEngineForwarder::AppendTextPortion( sal_uInt16 nPara, const String &rText, const SfxItemSet & /*rSet*/ ) +{ + xub_StrLen nLen = 0; + + sal_uInt16 nParaCount = rEditEngine.GetParagraphCount(); + DBG_ASSERT( nPara < nParaCount, "paragraph index out of bounds" ); + if (/*0 <= nPara && */nPara < nParaCount) + { + nLen = rEditEngine.GetTextLen( nPara ); + rEditEngine.QuickInsertText( rText, ESelection( nPara, nLen, nPara, nLen ) ); + } + + return nLen; +} + +void SvxEditEngineForwarder::CopyText(const SvxTextForwarder& rSource) +{ + const SvxEditEngineForwarder* pSourceForwarder = dynamic_cast< const SvxEditEngineForwarder* >( &rSource ); + if( !pSourceForwarder ) + return; + EditTextObject* pNewTextObject = pSourceForwarder->rEditEngine.CreateTextObject(); + rEditEngine.SetText( *pNewTextObject ); + delete pNewTextObject; +} + +//------------------------------------------------------------------------ diff --git a/editeng/source/uno/unoforou.cxx b/editeng/source/uno/unoforou.cxx new file mode 100644 index 000000000000..550e9d9482a1 --- /dev/null +++ b/editeng/source/uno/unoforou.cxx @@ -0,0 +1,615 @@ +/************************************************************************* + * + * 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_editeng.hxx" + +#include <algorithm> +#include <svl/style.hxx> +#include <com/sun/star/i18n/WordType.hpp> + +#include <svl/itemset.hxx> +#include <editeng/editeng.hxx> +#include <editeng/editdata.hxx> +#include <editeng/outliner.hxx> +#include <editeng/unoedhlp.hxx> +#include <svl/poolitem.hxx> +#include <vcl/wrkwin.hxx> +#include <editeng/eeitem.hxx> + +#include <editeng/unoforou.hxx> +#include <editeng/unofored.hxx> +#include <editeng/outlobj.hxx> + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------ + +SvxOutlinerForwarder::SvxOutlinerForwarder( Outliner& rOutl, sal_Bool bOutlText /* = sal_False */ ) : + rOutliner( rOutl ), + bOutlinerText( bOutlText ), + mpAttribsCache( NULL ), + mpParaAttribsCache( NULL ), + mnParaAttribsCache( 0 ) +{ +} + +SvxOutlinerForwarder::~SvxOutlinerForwarder() +{ + flushCache(); +} + +sal_uInt16 SvxOutlinerForwarder::GetParagraphCount() const +{ + return (sal_uInt16)rOutliner.GetParagraphCount(); +} + +sal_uInt16 SvxOutlinerForwarder::GetTextLen( sal_uInt16 nParagraph ) const +{ + return rOutliner.GetEditEngine().GetTextLen( nParagraph ); +} + +String SvxOutlinerForwarder::GetText( const ESelection& rSel ) const +{ + //! GetText(ESelection) sollte es wohl auch mal am Outliner geben + // solange den Hack fuer die EditEngine uebernehmen: + EditEngine* pEditEngine = (EditEngine*)&rOutliner.GetEditEngine(); + return pEditEngine->GetText( rSel, LINEEND_LF ); +} + +static SfxItemSet ImplOutlinerForwarderGetAttribs( const ESelection& rSel, sal_Bool bOnlyHardAttrib, EditEngine& rEditEngine ) +{ + if( rSel.nStartPara == rSel.nEndPara ) + { + sal_uInt8 nFlags = 0; + + switch( bOnlyHardAttrib ) + { + case EditEngineAttribs_All: + nFlags = GETATTRIBS_ALL; + break; + case EditEngineAttribs_HardAndPara: + nFlags = GETATTRIBS_PARAATTRIBS|GETATTRIBS_CHARATTRIBS; + break; + case EditEngineAttribs_OnlyHard: + nFlags = GETATTRIBS_CHARATTRIBS; + break; + default: + DBG_ERROR("unknown flags for SvxOutlinerForwarder::GetAttribs"); + } + return rEditEngine.GetAttribs( rSel.nStartPara, rSel.nStartPos, rSel.nEndPos, nFlags ); + } + else + { + return rEditEngine.GetAttribs( rSel, bOnlyHardAttrib ); + } +} + +SfxItemSet SvxOutlinerForwarder::GetAttribs( const ESelection& rSel, sal_Bool bOnlyHardAttrib ) const +{ + if( mpAttribsCache && ( 0 == bOnlyHardAttrib ) ) + { + // have we the correct set in cache? + if( ((SvxOutlinerForwarder*)this)->maAttribCacheSelection.IsEqual(rSel) ) + { + // yes! just return the cache + return *mpAttribsCache; + } + else + { + // no, we need delete the old cache + delete mpAttribsCache; + mpAttribsCache = NULL; + } + } + + //! gibt's das nicht am Outliner ??? + //! und warum ist GetAttribs an der EditEngine nicht const? + EditEngine& rEditEngine = (EditEngine&)rOutliner.GetEditEngine(); + + SfxItemSet aSet( ImplOutlinerForwarderGetAttribs( rSel, bOnlyHardAttrib, rEditEngine ) ); + + if( 0 == bOnlyHardAttrib ) + { + mpAttribsCache = new SfxItemSet( aSet ); + maAttribCacheSelection = rSel; + } + + SfxStyleSheet* pStyle = rEditEngine.GetStyleSheet( rSel.nStartPara ); + if( pStyle ) + aSet.SetParent( &(pStyle->GetItemSet() ) ); + + return aSet; +} + +SfxItemSet SvxOutlinerForwarder::GetParaAttribs( sal_uInt16 nPara ) const +{ + if( mpParaAttribsCache ) + { + // have we the correct set in cache? + if( nPara == mnParaAttribsCache ) + { + // yes! just return the cache + return *mpParaAttribsCache; + } + else + { + // no, we need delete the old cache + delete mpParaAttribsCache; + mpParaAttribsCache = NULL; + } + } + + mpParaAttribsCache = new SfxItemSet( rOutliner.GetParaAttribs( nPara ) ); + mnParaAttribsCache = nPara; + + EditEngine& rEditEngine = (EditEngine&)rOutliner.GetEditEngine(); + + SfxStyleSheet* pStyle = rEditEngine.GetStyleSheet( nPara ); + if( pStyle ) + mpParaAttribsCache->SetParent( &(pStyle->GetItemSet() ) ); + + return *mpParaAttribsCache; +} + +void SvxOutlinerForwarder::SetParaAttribs( sal_uInt16 nPara, const SfxItemSet& rSet ) +{ + flushCache(); + + const SfxItemSet* pOldParent = rSet.GetParent(); + if( pOldParent ) + ((SfxItemSet*)&rSet)->SetParent( NULL ); + + rOutliner.SetParaAttribs( nPara, rSet ); + + if( pOldParent ) + ((SfxItemSet*)&rSet)->SetParent( pOldParent ); +} + +void SvxOutlinerForwarder::RemoveAttribs( const ESelection& rSelection, sal_Bool bRemoveParaAttribs, sal_uInt16 nWhich ) +{ + rOutliner.RemoveAttribs( rSelection, bRemoveParaAttribs, nWhich ); +} + +SfxItemPool* SvxOutlinerForwarder::GetPool() const +{ + return rOutliner.GetEmptyItemSet().GetPool(); +} + +void SvxOutlinerForwarder::GetPortions( sal_uInt16 nPara, SvUShorts& rList ) const +{ + ((EditEngine&)rOutliner.GetEditEngine()).GetPortions( nPara, rList ); +} + +void SvxOutlinerForwarder::QuickInsertText( const String& rText, const ESelection& rSel ) +{ + flushCache(); + if( rText.Len() == 0 ) + { + rOutliner.QuickDelete( rSel ); + } + else + { + rOutliner.QuickInsertText( rText, rSel ); + } +} + +void SvxOutlinerForwarder::QuickInsertLineBreak( const ESelection& rSel ) +{ + flushCache(); + rOutliner.QuickInsertLineBreak( rSel ); +} + +void SvxOutlinerForwarder::QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel ) +{ + flushCache(); + rOutliner.QuickInsertField( rFld, rSel ); +} + +void SvxOutlinerForwarder::QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel ) +{ + flushCache(); + rOutliner.QuickSetAttribs( rSet, rSel ); +} + +XubString SvxOutlinerForwarder::CalcFieldValue( const SvxFieldItem& rField, sal_uInt16 nPara, sal_uInt16 nPos, Color*& rpTxtColor, Color*& rpFldColor ) +{ + return rOutliner.CalcFieldValue( rField, nPara, nPos, rpTxtColor, rpFldColor ); +} + +void SvxOutlinerForwarder::FieldClicked( const SvxFieldItem& rField, sal_uInt16 nPara, xub_StrLen nPos ) +{ + rOutliner.FieldClicked( rField, nPara, nPos ); +} + +sal_Bool SvxOutlinerForwarder::IsValid() const +{ + // cannot reliably query outliner state + // while in the middle of an update + return rOutliner.GetUpdateMode(); +} + +extern sal_uInt16 GetSvxEditEngineItemState( EditEngine& rEditEngine, const ESelection& rSel, sal_uInt16 nWhich ); + +sal_uInt16 SvxOutlinerForwarder::GetItemState( const ESelection& rSel, sal_uInt16 nWhich ) const +{ + return GetSvxEditEngineItemState( (EditEngine&)rOutliner.GetEditEngine(), rSel, nWhich ); +} + +sal_uInt16 SvxOutlinerForwarder::GetItemState( sal_uInt16 nPara, sal_uInt16 nWhich ) const +{ + const SfxItemSet& rSet = rOutliner.GetParaAttribs( nPara ); + return rSet.GetItemState( nWhich ); +} + + +void SvxOutlinerForwarder::flushCache() +{ + if( mpAttribsCache ) + { + delete mpAttribsCache; + mpAttribsCache = NULL; + } + + if( mpParaAttribsCache ) + { + delete mpParaAttribsCache; + mpParaAttribsCache = NULL; + } +} + +LanguageType SvxOutlinerForwarder::GetLanguage( sal_uInt16 nPara, sal_uInt16 nIndex ) const +{ + return rOutliner.GetLanguage(nPara, nIndex); +} + +sal_uInt16 SvxOutlinerForwarder::GetFieldCount( sal_uInt16 nPara ) const +{ + return rOutliner.GetEditEngine().GetFieldCount(nPara); +} + +EFieldInfo SvxOutlinerForwarder::GetFieldInfo( sal_uInt16 nPara, sal_uInt16 nField ) const +{ + return rOutliner.GetEditEngine().GetFieldInfo( nPara, nField ); +} + +EBulletInfo SvxOutlinerForwarder::GetBulletInfo( sal_uInt16 nPara ) const +{ + return rOutliner.GetBulletInfo( nPara ); +} + +Rectangle SvxOutlinerForwarder::GetCharBounds( sal_uInt16 nPara, sal_uInt16 nIndex ) const +{ + // #101701# + // EditEngine's 'internal' methods like GetCharacterBounds() + // don't rotate for vertical text. + Size aSize( rOutliner.CalcTextSize() ); + ::std::swap( aSize.Width(), aSize.Height() ); + bool bIsVertical( rOutliner.IsVertical() == sal_True ); + + // #108900# Handle virtual position one-past-the end of the string + if( nIndex >= GetTextLen(nPara) ) + { + Rectangle aLast; + + if( nIndex ) + { + // use last character, if possible + aLast = rOutliner.GetEditEngine().GetCharacterBounds( EPosition(nPara, nIndex-1) ); + + // move at end of this last character, make one pixel wide + aLast.Move( aLast.Right() - aLast.Left(), 0 ); + aLast.SetSize( Size(1, aLast.GetHeight()) ); + + // take care for CTL + aLast = SvxEditSourceHelper::EEToUserSpace( aLast, aSize, bIsVertical ); + } + else + { + // #109864# Bounds must lie within the paragraph + aLast = GetParaBounds( nPara ); + + // #109151# Don't use paragraph height, but line height + // instead. aLast is already CTL-correct + if( bIsVertical) + aLast.SetSize( Size( rOutliner.GetLineHeight(nPara,0), 1 ) ); + else + aLast.SetSize( Size( 1, rOutliner.GetLineHeight(nPara,0) ) ); + } + + return aLast; + } + else + { + return SvxEditSourceHelper::EEToUserSpace( rOutliner.GetEditEngine().GetCharacterBounds( EPosition(nPara, nIndex) ), + aSize, bIsVertical ); + } +} + +Rectangle SvxOutlinerForwarder::GetParaBounds( sal_uInt16 nPara ) const +{ + Point aPnt = rOutliner.GetDocPosTopLeft( nPara ); + Size aSize = rOutliner.CalcTextSize(); + + if( rOutliner.IsVertical() ) + { + // #101701# + // Hargl. Outliner's 'external' methods return the rotated + // dimensions, 'internal' methods like GetTextHeight( n ) + // don't rotate. + sal_uLong nWidth = rOutliner.GetTextHeight( nPara ); + + return Rectangle( aSize.Width() - aPnt.Y() - nWidth, 0, aSize.Width() - aPnt.Y(), aSize.Height() ); + } + else + { + sal_uLong nHeight = rOutliner.GetTextHeight( nPara ); + + return Rectangle( 0, aPnt.Y(), aSize.Width(), aPnt.Y() + nHeight ); + } +} + +MapMode SvxOutlinerForwarder::GetMapMode() const +{ + return rOutliner.GetRefMapMode(); +} + +OutputDevice* SvxOutlinerForwarder::GetRefDevice() const +{ + return rOutliner.GetRefDevice(); +} + +sal_Bool SvxOutlinerForwarder::GetIndexAtPoint( const Point& rPos, sal_uInt16& nPara, sal_uInt16& nIndex ) const +{ + // #101701# + Size aSize( rOutliner.CalcTextSize() ); + ::std::swap( aSize.Width(), aSize.Height() ); + Point aEEPos( SvxEditSourceHelper::UserSpaceToEE( rPos, + aSize, + rOutliner.IsVertical() == sal_True )); + + EPosition aDocPos = rOutliner.GetEditEngine().FindDocPosition( aEEPos ); + + nPara = aDocPos.nPara; + nIndex = aDocPos.nIndex; + + return sal_True; +} + +sal_Bool SvxOutlinerForwarder::GetWordIndices( sal_uInt16 nPara, sal_uInt16 nIndex, sal_uInt16& nStart, sal_uInt16& nEnd ) const +{ + ESelection aRes = rOutliner.GetEditEngine().GetWord( ESelection(nPara, nIndex, nPara, nIndex), com::sun::star::i18n::WordType::DICTIONARY_WORD ); + + if( aRes.nStartPara == nPara && + aRes.nStartPara == aRes.nEndPara ) + { + nStart = aRes.nStartPos; + nEnd = aRes.nEndPos; + + return sal_True; + } + + return sal_False; +} + +sal_Bool SvxOutlinerForwarder::GetAttributeRun( sal_uInt16& nStartIndex, sal_uInt16& nEndIndex, sal_uInt16 nPara, sal_uInt16 nIndex ) const +{ + return SvxEditSourceHelper::GetAttributeRun( nStartIndex, nEndIndex, rOutliner.GetEditEngine(), nPara, nIndex ); +} + +sal_uInt16 SvxOutlinerForwarder::GetLineCount( sal_uInt16 nPara ) const +{ + return static_cast < sal_uInt16 >( rOutliner.GetLineCount(nPara) ); +} + +sal_uInt16 SvxOutlinerForwarder::GetLineLen( sal_uInt16 nPara, sal_uInt16 nLine ) const +{ + return rOutliner.GetLineLen(nPara, nLine); +} + +void SvxOutlinerForwarder::GetLineBoundaries( /*out*/sal_uInt16 &rStart, /*out*/sal_uInt16 &rEnd, sal_uInt16 nPara, sal_uInt16 nLine ) const +{ + return rOutliner.GetEditEngine().GetLineBoundaries( rStart, rEnd, nPara, nLine ); +} + +sal_uInt16 SvxOutlinerForwarder::GetLineNumberAtIndex( sal_uInt16 nPara, sal_uInt16 nIndex ) const +{ + return rOutliner.GetEditEngine().GetLineNumberAtIndex( nPara, nIndex ); +} + +sal_Bool SvxOutlinerForwarder::QuickFormatDoc( sal_Bool ) +{ + rOutliner.QuickFormatDoc(); + + return sal_True; +} + +sal_Bool SvxOutlinerForwarder::Delete( const ESelection& rSelection ) +{ + flushCache(); + rOutliner.QuickDelete( rSelection ); + rOutliner.QuickFormatDoc(); + + return sal_True; +} + +sal_Bool SvxOutlinerForwarder::InsertText( const String& rStr, const ESelection& rSelection ) +{ + flushCache(); + rOutliner.QuickInsertText( rStr, rSelection ); + rOutliner.QuickFormatDoc(); + + return sal_True; +} + +sal_Int16 SvxOutlinerForwarder::GetDepth( sal_uInt16 nPara ) const +{ + DBG_ASSERT( nPara < GetParagraphCount(), "SvxOutlinerForwarder::GetDepth: Invalid paragraph index"); + + Paragraph* pPara = rOutliner.GetParagraph( nPara ); + + sal_Int16 nLevel = -1; + + if( pPara ) + nLevel = rOutliner.GetDepth( nPara ); + + return nLevel; +} + +sal_Bool SvxOutlinerForwarder::SetDepth( sal_uInt16 nPara, sal_Int16 nNewDepth ) +{ + DBG_ASSERT( nPara < GetParagraphCount(), "SvxOutlinerForwarder::SetDepth: Invalid paragraph index"); + + if( (nNewDepth >= -1) && (nNewDepth <= 9) && (nPara < GetParagraphCount()) ) + { + Paragraph* pPara = rOutliner.GetParagraph( nPara ); + if( pPara ) + { + rOutliner.SetDepth( pPara, nNewDepth ); + +// const bool bOutlinerText = pSdrObject && (pSdrObject->GetObjInventor() == SdrInventor) && (pSdrObject->GetObjIdentifier() == OBJ_OUTLINETEXT); + if( bOutlinerText ) + rOutliner.SetLevelDependendStyleSheet( nPara ); + + return sal_True; + } + } + + return sal_False; +} + +sal_Int16 SvxOutlinerForwarder::GetNumberingStartValue( sal_uInt16 nPara ) +{ + if( nPara < GetParagraphCount() ) + { + return rOutliner.GetNumberingStartValue( nPara ); + } + else + { + DBG_ERROR( "SvxOutlinerForwarder::GetNumberingStartValue)(), Invalid paragraph index"); + return -1; + } +} + +void SvxOutlinerForwarder::SetNumberingStartValue( sal_uInt16 nPara, sal_Int16 nNumberingStartValue ) +{ + if( nPara < GetParagraphCount() ) + { + rOutliner.SetNumberingStartValue( nPara, nNumberingStartValue ); + } + else + { + DBG_ERROR( "SvxOutlinerForwarder::SetNumberingStartValue)(), Invalid paragraph index"); + } +} + +sal_Bool SvxOutlinerForwarder::IsParaIsNumberingRestart( sal_uInt16 nPara ) +{ + if( nPara < GetParagraphCount() ) + { + return rOutliner.IsParaIsNumberingRestart( nPara ); + } + else + { + DBG_ERROR( "SvxOutlinerForwarder::IsParaIsNumberingRestart)(), Invalid paragraph index"); + return sal_False; + } +} + +void SvxOutlinerForwarder::SetParaIsNumberingRestart( sal_uInt16 nPara, sal_Bool bParaIsNumberingRestart ) +{ + if( nPara < GetParagraphCount() ) + { + rOutliner.SetParaIsNumberingRestart( nPara, bParaIsNumberingRestart ); + } + else + { + DBG_ERROR( "SvxOutlinerForwarder::SetParaIsNumberingRestart)(), Invalid paragraph index"); + } +} + +const SfxItemSet * SvxOutlinerForwarder::GetEmptyItemSetPtr() +{ + EditEngine& rEditEngine = const_cast< EditEngine& >( rOutliner.GetEditEngine() ); + return &rEditEngine.GetEmptyItemSet(); +} + +void SvxOutlinerForwarder::AppendParagraph() +{ + EditEngine& rEditEngine = const_cast< EditEngine& >( rOutliner.GetEditEngine() ); + rEditEngine.InsertParagraph( rEditEngine.GetParagraphCount(), String::EmptyString() ); +} + +xub_StrLen SvxOutlinerForwarder::AppendTextPortion( sal_uInt16 nPara, const String &rText, const SfxItemSet & /*rSet*/ ) +{ + xub_StrLen nLen = 0; + + EditEngine& rEditEngine = const_cast< EditEngine& >( rOutliner.GetEditEngine() ); + sal_uInt16 nParaCount = rEditEngine.GetParagraphCount(); + DBG_ASSERT( nPara < nParaCount, "paragraph index out of bounds" ); + if (/*0 <= nPara && */nPara < nParaCount) + { + nLen = rEditEngine.GetTextLen( nPara ); + rEditEngine.QuickInsertText( rText, ESelection( nPara, nLen, nPara, nLen ) ); + } + + return nLen; +} + +void SvxOutlinerForwarder::CopyText(const SvxTextForwarder& rSource) +{ + const SvxOutlinerForwarder* pSourceForwarder = dynamic_cast< const SvxOutlinerForwarder* >( &rSource ); + if( !pSourceForwarder ) + return; + OutlinerParaObject* pNewOutlinerParaObject = pSourceForwarder->rOutliner.CreateParaObject(); + rOutliner.SetText( *pNewOutlinerParaObject ); + delete pNewOutlinerParaObject; +} + +//------------------------------------------------------------------------ + + +sal_Int16 SvxTextForwarder::GetNumberingStartValue( sal_uInt16 ) +{ + return -1; +} + +void SvxTextForwarder::SetNumberingStartValue( sal_uInt16, sal_Int16 ) +{ +} + +sal_Bool SvxTextForwarder::IsParaIsNumberingRestart( sal_uInt16 ) +{ + return sal_False; +} + +void SvxTextForwarder::SetParaIsNumberingRestart( sal_uInt16, sal_Bool ) +{ +} + +//------------------------------------------------------------------------ + diff --git a/editeng/source/uno/unoipset.cxx b/editeng/source/uno/unoipset.cxx new file mode 100644 index 000000000000..a1b276153d64 --- /dev/null +++ b/editeng/source/uno/unoipset.cxx @@ -0,0 +1,394 @@ +/************************************************************************* + * + * 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_editeng.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <svl/eitem.hxx> +#include <tools/list.hxx> + +#include <hash_map> +#include <vector> +#include <svl/itemprop.hxx> + +#include <editeng/unoipset.hxx> +#include <editeng/editids.hrc> +#include <editeng/editeng.hxx> +#include <svl/itempool.hxx> +#include <algorithm> + +using namespace ::com::sun::star; +using namespace ::rtl; + +//---------------------------------------------------------------------- + +struct SfxItemPropertyMapEntryHash +{ + size_t operator()(const SfxItemPropertyMapEntry* pMap) const { return (size_t)pMap; } +}; + +//---------------------------------------------------------------------- + +struct SvxIDPropertyCombine +{ + sal_uInt16 nWID; + uno::Any aAny; +}; + +DECLARE_LIST( SvxIDPropertyCombineList, SvxIDPropertyCombine * ) + +SvxItemPropertySet::SvxItemPropertySet( const SfxItemPropertyMapEntry* pMap, SfxItemPool& rItemPool, sal_Bool bConvertTwips ) +: m_aPropertyMap( pMap ), + _pMap(pMap), mbConvertTwips(bConvertTwips), mrItemPool( rItemPool ) +{ + pCombiList = NULL; +} + +//---------------------------------------------------------------------- +SvxItemPropertySet::~SvxItemPropertySet() +{ + ClearAllUsrAny(); +} + +//---------------------------------------------------------------------- +uno::Any* SvxItemPropertySet::GetUsrAnyForID(sal_uInt16 nWID) const +{ + if(pCombiList && pCombiList->Count()) + { + SvxIDPropertyCombine* pActual = pCombiList->First(); + while(pActual) + { + if(pActual->nWID == nWID) + return &pActual->aAny; + pActual = pCombiList->Next(); + + } + } + return NULL; +} + +//---------------------------------------------------------------------- +void SvxItemPropertySet::AddUsrAnyForID(const uno::Any& rAny, sal_uInt16 nWID) +{ + if(!pCombiList) + pCombiList = new SvxIDPropertyCombineList(); + + SvxIDPropertyCombine* pNew = new SvxIDPropertyCombine; + pNew->nWID = nWID; + pNew->aAny = rAny; + pCombiList->Insert(pNew); +} + +//---------------------------------------------------------------------- + +void SvxItemPropertySet::ClearAllUsrAny() +{ + if(pCombiList) + delete pCombiList; + pCombiList = NULL; +} + +//---------------------------------------------------------------------- + +sal_Bool SvxUnoCheckForPositiveValue( const uno::Any& rVal ) +{ + sal_Bool bConvert = sal_True; // the default is that all metric items must be converted + sal_Int32 nValue = 0; + if( rVal >>= nValue ) + bConvert = (nValue > 0); + return bConvert; +} + + +//---------------------------------------------------------------------- +uno::Any SvxItemPropertySet::getPropertyValue( const SfxItemPropertySimpleEntry* pMap, const SfxItemSet& rSet, bool bSearchInParent, bool bDontConvertNegativeValues ) const +{ + uno::Any aVal; + if(!pMap || !pMap->nWID) + return aVal; + + const SfxPoolItem* pItem = 0; + SfxItemPool* pPool = rSet.GetPool(); + rSet.GetItemState( pMap->nWID, bSearchInParent, &pItem ); + if( NULL == pItem && pPool ) + pItem = &(pPool->GetDefaultItem( pMap->nWID )); + + const SfxMapUnit eMapUnit = pPool ? pPool->GetMetric((sal_uInt16)pMap->nWID) : SFX_MAPUNIT_100TH_MM; + sal_uInt8 nMemberId = pMap->nMemberId & (~SFX_METRIC_ITEM); + if( eMapUnit == SFX_MAPUNIT_100TH_MM ) + nMemberId &= (~CONVERT_TWIPS); + + if(pItem) + { + pItem->QueryValue( aVal, nMemberId ); + if( pMap->nMemberId & SFX_METRIC_ITEM ) + { + if( eMapUnit != SFX_MAPUNIT_100TH_MM ) + { + if ( !bDontConvertNegativeValues || SvxUnoCheckForPositiveValue( aVal ) ) + SvxUnoConvertToMM( eMapUnit, aVal ); + } + } + else if ( pMap->pType->getTypeClass() == uno::TypeClass_ENUM && + aVal.getValueType() == ::getCppuType((const sal_Int32*)0) ) + { + // convert typeless SfxEnumItem to enum type + sal_Int32 nEnum; + aVal >>= nEnum; + aVal.setValue( &nEnum, *pMap->pType ); + } + } + else + { + DBG_ERROR( "No SfxPoolItem found for property!" ); + } + + return aVal; +} + +//---------------------------------------------------------------------- +void SvxItemPropertySet::setPropertyValue( const SfxItemPropertySimpleEntry* pMap, const uno::Any& rVal, SfxItemSet& rSet, bool bDontConvertNegativeValues ) const +{ + if(!pMap || !pMap->nWID) + return; + + // item holen + const SfxPoolItem* pItem = 0; + SfxPoolItem *pNewItem = 0; + SfxItemState eState = rSet.GetItemState( pMap->nWID, sal_True, &pItem ); + SfxItemPool* pPool = rSet.GetPool(); + + // UnoAny in item-Wert stecken + if(eState < SFX_ITEM_DEFAULT || pItem == NULL) + { + if( pPool == NULL ) + { + DBG_ERROR( "No default item and no pool?" ); + return; + } + + pItem = &pPool->GetDefaultItem( pMap->nWID ); + } + + DBG_ASSERT( pItem, "Got no default for item!" ); + if( pItem ) + { + uno::Any aValue( rVal ); + + const SfxMapUnit eMapUnit = pPool ? pPool->GetMetric((sal_uInt16)pMap->nWID) : SFX_MAPUNIT_100TH_MM; + + // check for needed metric translation + if( (pMap->nMemberId & SFX_METRIC_ITEM) && eMapUnit != SFX_MAPUNIT_100TH_MM ) + { + if ( !bDontConvertNegativeValues || SvxUnoCheckForPositiveValue( aValue ) ) + SvxUnoConvertFromMM( eMapUnit, aValue ); + } + + pNewItem = pItem->Clone(); + + sal_uInt8 nMemberId = pMap->nMemberId & (~SFX_METRIC_ITEM); + if( eMapUnit == SFX_MAPUNIT_100TH_MM ) + nMemberId &= (~CONVERT_TWIPS); + + if( pNewItem->PutValue( aValue, nMemberId ) ) + { + // neues item in itemset setzen + rSet.Put( *pNewItem, pMap->nWID ); + } + delete pNewItem; + } +} + +//---------------------------------------------------------------------- +uno::Any SvxItemPropertySet::getPropertyValue( const SfxItemPropertySimpleEntry* pMap ) const +{ + // Schon ein Wert eingetragen? Dann schnell fertig + uno::Any* pUsrAny = GetUsrAnyForID(pMap->nWID); + if(pUsrAny) + return *pUsrAny; + + // Noch kein UsrAny gemerkt, generiere Default-Eintrag und gib + // diesen zurueck + + const SfxMapUnit eMapUnit = mrItemPool.GetMetric((sal_uInt16)pMap->nWID); + sal_uInt8 nMemberId = pMap->nMemberId & (~SFX_METRIC_ITEM); + if( eMapUnit == SFX_MAPUNIT_100TH_MM ) + nMemberId &= (~CONVERT_TWIPS); + + uno::Any aVal; + SfxItemSet aSet( mrItemPool, pMap->nWID, pMap->nWID); + + if( (pMap->nWID < OWN_ATTR_VALUE_START) && (pMap->nWID > OWN_ATTR_VALUE_END ) ) + { + // Default aus ItemPool holen + if(mrItemPool.IsWhich(pMap->nWID)) + aSet.Put(mrItemPool.GetDefaultItem(pMap->nWID)); + } + + if(aSet.Count()) + { + const SfxPoolItem* pItem = NULL; + SfxItemState eState = aSet.GetItemState( pMap->nWID, sal_True, &pItem ); + if(eState >= SFX_ITEM_DEFAULT && pItem) + { + pItem->QueryValue( aVal, nMemberId ); + ((SvxItemPropertySet*)this)->AddUsrAnyForID(aVal, pMap->nWID); + } + } + + if( pMap->nMemberId & SFX_METRIC_ITEM ) + { + // check for needed metric translation + if(pMap->nMemberId & SFX_METRIC_ITEM && eMapUnit != SFX_MAPUNIT_100TH_MM) + { + SvxUnoConvertToMM( eMapUnit, aVal ); + } + } + + if ( pMap->pType->getTypeClass() == uno::TypeClass_ENUM && + aVal.getValueType() == ::getCppuType((const sal_Int32*)0) ) + { + sal_Int32 nEnum; + aVal >>= nEnum; + + aVal.setValue( &nEnum, *pMap->pType ); + } + + return aVal; +} + +//---------------------------------------------------------------------- + +void SvxItemPropertySet::setPropertyValue( const SfxItemPropertySimpleEntry* pMap, const uno::Any& rVal ) const +{ + uno::Any* pUsrAny = GetUsrAnyForID(pMap->nWID); + if(!pUsrAny) + ((SvxItemPropertySet*)this)->AddUsrAnyForID(rVal, pMap->nWID); + else + *pUsrAny = rVal; +} + +//---------------------------------------------------------------------- + +const SfxItemPropertySimpleEntry* SvxItemPropertySet::getPropertyMapEntry(const OUString &rName) const +{ + return m_aPropertyMap.getByName( rName ); + } + +//---------------------------------------------------------------------- + +uno::Reference< beans::XPropertySetInfo > SvxItemPropertySet::getPropertySetInfo() const +{ + if( !m_xInfo.is() ) + m_xInfo = new SfxItemPropertySetInfo( &m_aPropertyMap ); + return m_xInfo; +} + +//---------------------------------------------------------------------- + +#ifndef TWIPS_TO_MM +#define TWIPS_TO_MM(val) ((val * 127 + 36) / 72) +#endif +#ifndef MM_TO_TWIPS +#define MM_TO_TWIPS(val) ((val * 72 + 63) / 127) +#endif + +/** converts the given any with a metric to 100th/mm if needed */ +void SvxUnoConvertToMM( const SfxMapUnit eSourceMapUnit, uno::Any & rMetric ) throw() +{ + // map the metric of the itempool to 100th mm + switch(eSourceMapUnit) + { + case SFX_MAPUNIT_TWIP : + { + switch( rMetric.getValueTypeClass() ) + { + case uno::TypeClass_BYTE: + rMetric <<= (sal_Int8)(TWIPS_TO_MM(*(sal_Int8*)rMetric.getValue())); + break; + case uno::TypeClass_SHORT: + rMetric <<= (sal_Int16)(TWIPS_TO_MM(*(sal_Int16*)rMetric.getValue())); + break; + case uno::TypeClass_UNSIGNED_SHORT: + rMetric <<= (sal_uInt16)(TWIPS_TO_MM(*(sal_uInt16*)rMetric.getValue())); + break; + case uno::TypeClass_LONG: + rMetric <<= (sal_Int32)(TWIPS_TO_MM(*(sal_Int32*)rMetric.getValue())); + break; + case uno::TypeClass_UNSIGNED_LONG: + rMetric <<= (sal_uInt32)(TWIPS_TO_MM(*(sal_uInt32*)rMetric.getValue())); + break; + default: + DBG_ERROR("AW: Missing unit translation to 100th mm!"); + } + break; + } + default: + { + DBG_ERROR("AW: Missing unit translation to 100th mm!"); + } + } +} + +//---------------------------------------------------------------------- + +/** converts the given any with a metric from 100th/mm to the given metric if needed */ +void SvxUnoConvertFromMM( const SfxMapUnit eDestinationMapUnit, uno::Any & rMetric ) throw() +{ + switch(eDestinationMapUnit) + { + case SFX_MAPUNIT_TWIP : + { + switch( rMetric.getValueTypeClass() ) + { + case uno::TypeClass_BYTE: + rMetric <<= (sal_Int8)(MM_TO_TWIPS(*(sal_Int8*)rMetric.getValue())); + break; + case uno::TypeClass_SHORT: + rMetric <<= (sal_Int16)(MM_TO_TWIPS(*(sal_Int16*)rMetric.getValue())); + break; + case uno::TypeClass_UNSIGNED_SHORT: + rMetric <<= (sal_uInt16)(MM_TO_TWIPS(*(sal_uInt16*)rMetric.getValue())); + break; + case uno::TypeClass_LONG: + rMetric <<= (sal_Int32)(MM_TO_TWIPS(*(sal_Int32*)rMetric.getValue())); + break; + case uno::TypeClass_UNSIGNED_LONG: + rMetric <<= (sal_uInt32)(MM_TO_TWIPS(*(sal_uInt32*)rMetric.getValue())); + break; + default: + DBG_ERROR("AW: Missing unit translation to 100th mm!"); + } + break; + } + default: + { + DBG_ERROR("AW: Missing unit translation to PoolMetrics!"); + } + } +} + diff --git a/editeng/source/uno/unonrule.cxx b/editeng/source/uno/unonrule.cxx new file mode 100644 index 000000000000..28a0eb64c570 --- /dev/null +++ b/editeng/source/uno/unonrule.cxx @@ -0,0 +1,615 @@ +/************************************************************************* + * + * 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_editeng.hxx" + +#define PROPERTY_NONE 0 + +#include <com/sun/star/text/HoriOrientation.hpp> +#include <com/sun/star/awt/XBitmap.hpp> + +#include <vcl/svapp.hxx> +#include <vos/mutex.hxx> +#include <vcl/graph.hxx> +#include <svtools/grfmgr.hxx> +#include <toolkit/unohlp.hxx> +#include <rtl/uuid.h> +#include <rtl/memory.h> + +#include <editeng/brshitem.hxx> +#include <editeng/unoprnms.hxx> +#include <editeng/numitem.hxx> +#include <editeng/eeitem.hxx> +#include <editeng/unotext.hxx> +#include <editeng/numitem.hxx> +#include <editeng/unofdesc.hxx> +#include <editeng/unonrule.hxx> +#include <editeng/editids.hrc> + +using ::rtl::OUString; +using ::com::sun::star::util::XCloneable; +using ::com::sun::star::ucb::XAnyCompare; + + +using namespace ::vos; +using namespace ::std; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::container; + +const SvxAdjust aUnoToSvxAdjust[] = +{ + SVX_ADJUST_LEFT, + SVX_ADJUST_RIGHT, + SVX_ADJUST_CENTER, + SVX_ADJUST_LEFT, + SVX_ADJUST_LEFT, + SVX_ADJUST_LEFT, + SVX_ADJUST_BLOCK +}; + +const unsigned short aSvxToUnoAdjust[] = +{ + text::HoriOrientation::LEFT, + text::HoriOrientation::RIGHT, + text::HoriOrientation::FULL, + text::HoriOrientation::CENTER, + text::HoriOrientation::FULL, + text::HoriOrientation::LEFT +}; + +SvxAdjust ConvertUnoAdjust( unsigned short nAdjust ) +{ + DBG_ASSERT( nAdjust <= 7, "Enum hat sich geaendert! [CL]" ); + return aUnoToSvxAdjust[nAdjust]; +} + +unsigned short ConvertUnoAdjust( SvxAdjust eAdjust ) +{ + DBG_ASSERT( eAdjust <= 6, "Enum hat sich geaendert! [CL]" ); + return aSvxToUnoAdjust[eAdjust]; +} + +/****************************************************************** + * SvxUnoNumberingRules + ******************************************************************/ + +UNO3_GETIMPLEMENTATION_IMPL( SvxUnoNumberingRules ); + +SvxUnoNumberingRules::SvxUnoNumberingRules( const SvxNumRule& rRule ) throw() +: maRule( rRule ) +{ +} + +SvxUnoNumberingRules::~SvxUnoNumberingRules() throw() +{ +} + +//XIndexReplace +void SAL_CALL SvxUnoNumberingRules::replaceByIndex( sal_Int32 Index, const uno::Any& Element ) + throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException ) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + if( Index < 0 || Index >= maRule.GetLevelCount() ) + throw IndexOutOfBoundsException(); + + Sequence< beans::PropertyValue > aSeq; + + if( !( Element >>= aSeq) ) + throw IllegalArgumentException(); + setNumberingRuleByIndex( aSeq, Index ); +} + +// XIndexAccess +sal_Int32 SAL_CALL SvxUnoNumberingRules::getCount() throw( RuntimeException ) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + return maRule.GetLevelCount(); +} + +Any SAL_CALL SvxUnoNumberingRules::getByIndex( sal_Int32 Index ) + throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException ) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + if( Index < 0 || Index >= maRule.GetLevelCount() ) + throw IndexOutOfBoundsException(); + + return Any( getNumberingRuleByIndex(Index) ); +} + +//XElementAccess +Type SAL_CALL SvxUnoNumberingRules::getElementType() + throw( RuntimeException ) +{ + return ::getCppuType(( const Sequence< beans::PropertyValue >*)0); +} + +sal_Bool SAL_CALL SvxUnoNumberingRules::hasElements() throw( RuntimeException ) +{ + return sal_True; +} + +// XAnyCompare +sal_Int16 SAL_CALL SvxUnoNumberingRules::compare( const Any& rAny1, const Any& rAny2 ) throw(RuntimeException) +{ + return SvxUnoNumberingRules::Compare( rAny1, rAny2 ); +} + +// XCloneable +Reference< XCloneable > SAL_CALL SvxUnoNumberingRules::createClone( ) throw (RuntimeException) +{ + return new SvxUnoNumberingRules(maRule); +} + +// XServiceInfo +sal_Char pSvxUnoNumberingRulesService[sizeof("com.sun.star.text.NumberingRules")] = "com.sun.star.text.NumberingRules"; + +OUString SAL_CALL SvxUnoNumberingRules::getImplementationName( ) throw(RuntimeException) +{ + return OUString( RTL_CONSTASCII_USTRINGPARAM( "SvxUnoNumberingRules" ) ); +} + +sal_Bool SAL_CALL SvxUnoNumberingRules::supportsService( const OUString& ServiceName ) throw(RuntimeException) +{ + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( pSvxUnoNumberingRulesService ) ); +} + +Sequence< OUString > SAL_CALL SvxUnoNumberingRules::getSupportedServiceNames( ) throw(RuntimeException) +{ + OUString aService( RTL_CONSTASCII_USTRINGPARAM( pSvxUnoNumberingRulesService ) ); + Sequence< OUString > aSeq( &aService, 1 ); + return aSeq; +} + +Sequence<beans::PropertyValue> SvxUnoNumberingRules::getNumberingRuleByIndex( sal_Int32 nIndex) const throw() +{ + // NumberingRule aRule; + const SvxNumberFormat& rFmt = maRule.GetLevel((sal_uInt16) nIndex); + sal_uInt16 nIdx = 0; + + const int nProps = 15; + beans::PropertyValue* pArray = new beans::PropertyValue[nProps]; + + Any aVal; + { + aVal <<= rFmt.GetNumberingType(); + beans::PropertyValue aAlignProp( OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_NUMBERINGTYPE)), -1, aVal, beans::PropertyState_DIRECT_VALUE); + pArray[nIdx++] = aAlignProp; + } + + { + SvxAdjust eAdj = rFmt.GetNumAdjust(); + aVal <<= ConvertUnoAdjust(eAdj); + pArray[nIdx++] = beans::PropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_ADJUST)), -1, aVal, beans::PropertyState_DIRECT_VALUE); + } + + { + aVal <<= OUString(rFmt.GetPrefix()); + beans::PropertyValue aPrefixProp( OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_PREFIX)), -1, aVal, beans::PropertyState_DIRECT_VALUE); + pArray[nIdx++] = aPrefixProp; + } + + { + aVal <<= OUString(rFmt.GetSuffix()); + beans::PropertyValue aSuffixProp( OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_SUFFIX)), -1, aVal, beans::PropertyState_DIRECT_VALUE); + pArray[nIdx++] = aSuffixProp; + } + + { + sal_Unicode nCode = rFmt.GetBulletChar(); + OUString aStr( &nCode, 1 ); + aVal <<= aStr; + beans::PropertyValue aBulletProp( OUString(RTL_CONSTASCII_USTRINGPARAM("BulletChar")), -1, aVal, beans::PropertyState_DIRECT_VALUE); + pArray[nIdx++] = aBulletProp; + } + + if( rFmt.GetBulletFont() ) + { + awt::FontDescriptor aDesc; + SvxUnoFontDescriptor::ConvertFromFont( *rFmt.GetBulletFont(), aDesc ); + aVal.setValue(&aDesc, ::getCppuType((const awt::FontDescriptor*)0)); + pArray[nIdx++] = beans::PropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_BULLET_FONT)), -1, aVal, beans::PropertyState_DIRECT_VALUE); + } + + { + const SvxBrushItem* pBrush = rFmt.GetBrush(); + if(pBrush && pBrush->GetGraphicObject()) + { + const GraphicObject* pGrafObj = pBrush->GetGraphicObject(); + OUString aURL( RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_GRAPHOBJ_URLPREFIX)); + aURL += OUString::createFromAscii( pGrafObj->GetUniqueID().GetBuffer() ); + + aVal <<= aURL; + const beans::PropertyValue aGraphicProp( OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicURL")), -1, aVal, beans::PropertyState_DIRECT_VALUE); + pArray[nIdx++] = aGraphicProp; + } + } + + { + const Size aSize( rFmt.GetGraphicSize() ); + const awt::Size aUnoSize( aSize.Width(), aSize.Height() ); + aVal <<= aUnoSize; + const beans::PropertyValue aGraphicSizeProp(OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicSize")), -1, aVal, beans::PropertyState_DIRECT_VALUE ); + pArray[nIdx++] = aGraphicSizeProp; + } + + aVal <<= (sal_Int16)rFmt.GetStart(); + pArray[nIdx++] = beans::PropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_START_WITH)), -1, aVal, beans::PropertyState_DIRECT_VALUE); + + aVal <<= (sal_Int32)rFmt.GetAbsLSpace(); + pArray[nIdx++] = beans::PropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_LEFT_MARGIN)), -1, aVal, beans::PropertyState_DIRECT_VALUE); + + aVal <<= (sal_Int32)rFmt.GetFirstLineOffset(); + pArray[nIdx++] = beans::PropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_FIRST_LINE_OFFSET)), -1, aVal, beans::PropertyState_DIRECT_VALUE); + + pArray[nIdx++] = beans::PropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("SymbolTextDistance")), -1, aVal, beans::PropertyState_DIRECT_VALUE); + + aVal <<= (sal_Int32)rFmt.GetBulletColor().GetColor(); + pArray[nIdx++] = beans::PropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_BULLET_COLOR)), -1, aVal, beans::PropertyState_DIRECT_VALUE); + + aVal <<= (sal_Int16)rFmt.GetBulletRelSize(); + pArray[nIdx++] = beans::PropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_BULLET_RELSIZE)), -1, aVal, beans::PropertyState_DIRECT_VALUE); + + DBG_ASSERT( nIdx <= nProps, "FixMe: Array uebergelaufen!!!! [CL]" ); + Sequence< beans::PropertyValue> aSeq(pArray, nIdx); + + delete [] pArray; + return aSeq; +} + +void SvxUnoNumberingRules::setNumberingRuleByIndex( const Sequence< beans::PropertyValue >& rProperties, sal_Int32 nIndex) + throw( RuntimeException, IllegalArgumentException ) +{ + SvxNumberFormat aFmt(maRule.GetLevel( (sal_uInt16)nIndex )); + const beans::PropertyValue* pPropArray = rProperties.getConstArray(); + for(int i = 0; i < rProperties.getLength(); i++) + { + const beans::PropertyValue& rProp = pPropArray[i]; + const OUString& rPropName = rProp.Name; + const Any& aVal = rProp.Value; + + if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_NUMBERINGTYPE))) + { + sal_Int16 nSet = sal_Int16(); + aVal >>= nSet; + + switch(nSet) + { + case SVX_NUM_BITMAP: + case SVX_NUM_CHAR_SPECIAL: + case SVX_NUM_ROMAN_UPPER: + case SVX_NUM_ROMAN_LOWER: + case SVX_NUM_CHARS_UPPER_LETTER: + case SVX_NUM_CHARS_LOWER_LETTER: + case SVX_NUM_ARABIC: + case SVX_NUM_NUMBER_NONE: + case SVX_NUM_CHARS_UPPER_LETTER_N: + case SVX_NUM_CHARS_LOWER_LETTER_N: + aFmt.SetNumberingType(nSet); + continue; + } + } + else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_PREFIX))) + { + OUString aPrefix; + if( aVal >>= aPrefix ) + { + aFmt.SetPrefix(aPrefix); + continue; + } + } + else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_SUFFIX))) + { + OUString aSuffix; + if( aVal >>= aSuffix ) + { + aFmt.SetSuffix(aSuffix); + continue; + } + } + else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_BULLETID))) + { + sal_Int16 nSet = sal_Int16(); + if( aVal >>= nSet ) + { + if(nSet < 0x100) + { + aFmt.SetBulletChar(nSet); + continue; + } + } + } + else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("BulletChar"))) + { + OUString aStr; + if( aVal >>= aStr ) + { + if(aStr.getLength()) + { + aFmt.SetBulletChar(aStr[0]); + } + else + { + aFmt.SetBulletChar(0); + } + continue; + } + } + else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_ADJUST))) + { + sal_Int16 nAdjust = sal_Int16(); + if( aVal >>= nAdjust ) + { + aFmt.SetNumAdjust(ConvertUnoAdjust( (unsigned short)nAdjust )); + continue; + } + } + else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_BULLET_FONT))) + { + awt::FontDescriptor aDesc; + if( aVal >>= aDesc ) + { + Font aFont; + SvxUnoFontDescriptor::ConvertToFont( aDesc, aFont ); + aFmt.SetBulletFont(&aFont); + continue; + } + } + else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Graphic"))) + { + Reference< awt::XBitmap > xBmp; + if( aVal >>= xBmp ) + { + Graphic aGraf( VCLUnoHelper::GetBitmap( xBmp ) ); + SvxBrushItem aBrushItem(aGraf, GPOS_AREA, SID_ATTR_BRUSH); + aFmt.SetGraphicBrush( &aBrushItem ); + continue; + } + } + else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("GraphicURL"))) + { + OUString aURL; + if( aVal >>= aURL ) + { + GraphicObject aGrafObj( GraphicObject::CreateGraphicObjectFromURL( aURL ) ); + SvxBrushItem aBrushItem( aGrafObj, GPOS_AREA, SID_ATTR_BRUSH ); + aFmt.SetGraphicBrush( &aBrushItem ); + continue; + } + } + else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("GraphicSize"))) + { + awt::Size aUnoSize; + if( aVal >>= aUnoSize ) + { + aFmt.SetGraphicSize( Size( aUnoSize.Width, aUnoSize.Height ) ); + continue; + } + } + else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_START_WITH))) + { + sal_Int16 nStart = sal_Int16(); + if( aVal >>= nStart ) + { + aFmt.SetStart( nStart ); + continue; + } + } + else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_LEFT_MARGIN))) + { + sal_Int32 nMargin = 0; + if( aVal >>= nMargin ) + { + aFmt.SetAbsLSpace((sal_uInt16)nMargin); + continue; + } + } + else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_FIRST_LINE_OFFSET))) + { + sal_Int32 nMargin = 0; + if( aVal >>= nMargin ) + { + aFmt.SetFirstLineOffset((sal_uInt16)nMargin); + continue; + } + } + else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("SymbolTextDistance"))) + { + sal_Int32 nTextDistance = 0; + if( aVal >>= nTextDistance ) + { + aFmt.SetCharTextDistance((sal_uInt16)nTextDistance); + continue; + } + } + else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_BULLET_COLOR))) + { + sal_Int32 nColor = 0; + if( aVal >>= nColor ) + { + aFmt.SetBulletColor( (Color) nColor ); + continue; + } + } + else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_BULLET_RELSIZE))) + { + sal_Int16 nSize = sal_Int16(); + if( aVal >>= nSize ) + { + aFmt.SetBulletRelSize( (short)nSize ); + continue; + } + } + else + { + continue; + } + + throw IllegalArgumentException(); + } + + // check that we always have a brush item for bitmap numbering + if( aFmt.GetNumberingType() == SVX_NUM_BITMAP ) + { + if( NULL == aFmt.GetBrush() ) + { + GraphicObject aGrafObj; + SvxBrushItem aBrushItem( aGrafObj, GPOS_AREA, SID_ATTR_BRUSH ); + aFmt.SetGraphicBrush( &aBrushItem ); + } + } + maRule.SetLevel( (sal_uInt16)nIndex, aFmt ); +} + +/////////////////////////////////////////////////////////////////////// + +const SvxNumRule& SvxGetNumRule( Reference< XIndexReplace > xRule ) throw( IllegalArgumentException ) +{ + SvxUnoNumberingRules* pRule = SvxUnoNumberingRules::getImplementation( xRule ); + if( pRule == NULL ) + throw IllegalArgumentException(); + + return pRule->getNumRule(); +} + +bool SvxGetNumRule( Reference< XIndexReplace > xRule, SvxNumRule& rNumRule ) +{ + SvxUnoNumberingRules* pRule = SvxUnoNumberingRules::getImplementation( xRule ); + if( pRule ) + { + rNumRule = pRule->getNumRule(); + } + else if( xRule.is() ) + { + try + { + pRule = new SvxUnoNumberingRules( rNumRule ); + + Reference< XIndexReplace > xDestRule( pRule ); + + const sal_Int32 nCount = min( xRule->getCount(), xDestRule->getCount() ); + sal_Int32 nLevel; + for( nLevel = 0; nLevel < nCount; nLevel++ ) + { + xDestRule->replaceByIndex( nLevel, xRule->getByIndex( nLevel ) ); + } + + rNumRule = pRule->getNumRule(); + } + catch( Exception& ) + { + return false; + } + } + else + { + return false; + } + + return true; +} + +/////////////////////////////////////////////////////////////////////// +com::sun::star::uno::Reference< com::sun::star::container::XIndexReplace > SvxCreateNumRule( const SvxNumRule* pRule ) throw() +{ + DBG_ASSERT( pRule, "No default SvxNumRule!" ); + if( pRule ) + { + return new SvxUnoNumberingRules( *pRule ); + } + else + { + SvxNumRule aDefaultRule( NUM_BULLET_REL_SIZE|NUM_BULLET_COLOR|NUM_CHAR_TEXT_DISTANCE, 10 , sal_False); + return new SvxUnoNumberingRules( aDefaultRule ); + } +} + + +/////////////////////////////////////////////////////////////////////// + +class SvxUnoNumberingRulesCompare : public ::cppu::WeakAggImplHelper1< XAnyCompare > +{ +public: + virtual sal_Int16 SAL_CALL compare( const Any& Any1, const Any& Any2 ) throw(RuntimeException); +}; + +sal_Int16 SAL_CALL SvxUnoNumberingRulesCompare::compare( const Any& Any1, const Any& Any2 ) throw(RuntimeException) +{ + return SvxUnoNumberingRules::Compare( Any1, Any2 ); +} + +sal_Int16 SvxUnoNumberingRules::Compare( const Any& Any1, const Any& Any2 ) +{ + Reference< XIndexReplace > x1( Any1, UNO_QUERY ), x2( Any2, UNO_QUERY ); + if( x1.is() && x2.is() ) + { + if( x1.get() == x2.get() ) + return 0; + + SvxUnoNumberingRules* pRule1 = SvxUnoNumberingRules::getImplementation( x1 ); + if( pRule1 ) + { + SvxUnoNumberingRules* pRule2 = SvxUnoNumberingRules::getImplementation( x2 ); + if( pRule2 ) + { + const SvxNumRule& rRule1 = pRule1->getNumRule(); + const SvxNumRule& rRule2 = pRule2->getNumRule(); + + const sal_uInt16 nLevelCount1 = rRule1.GetLevelCount(); + const sal_uInt16 nLevelCount2 = rRule2.GetLevelCount(); + + if( nLevelCount1 == 0 || nLevelCount2 == 0 ) + return -1; + + for( sal_uInt16 i = 0; (i < nLevelCount1) && (i < nLevelCount2); i++ ) + { + if( rRule1.GetLevel(i) != rRule2.GetLevel(i) ) + return -1; + } + return 0; + } + } + } + + return -1; +} + +Reference< XAnyCompare > SvxCreateNumRuleCompare() throw() +{ + return new SvxUnoNumberingRulesCompare(); +} + +::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexReplace > SvxCreateNumRule() throw() +{ + SvxNumRule aTempRule( 0, 10, false ); + return SvxCreateNumRule( &aTempRule ); +} diff --git a/editeng/source/uno/unopracc.cxx b/editeng/source/uno/unopracc.cxx new file mode 100644 index 000000000000..93acde6de73b --- /dev/null +++ b/editeng/source/uno/unopracc.cxx @@ -0,0 +1,171 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_editeng.hxx" + +//------------------------------------------------------------------------ +// +// Global header +// +//------------------------------------------------------------------------ +#include <vos/mutex.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <cppuhelper/weakref.hxx> +#include <com/sun/star/lang/XComponent.hpp> +#include <cppuhelper/typeprovider.hxx> + + +//------------------------------------------------------------------------ +// +// Project-local header +// +//------------------------------------------------------------------------ + +#include <editeng/unopracc.hxx> +#include <editeng/unoedsrc.hxx> + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------ +// +// SvxAccessibleTextPropertySet implementation +// +//------------------------------------------------------------------------ + +SvxAccessibleTextPropertySet::SvxAccessibleTextPropertySet( const SvxEditSource* pEditSrc, const SvxItemPropertySet* pPropSet ) + : SvxUnoTextRangeBase( pEditSrc, pPropSet ) +{ +} + +SvxAccessibleTextPropertySet::~SvxAccessibleTextPropertySet() throw() +{ +} + +uno::Reference< text::XText > SAL_CALL SvxAccessibleTextPropertySet::getText() throw (uno::RuntimeException) +{ + // TODO (empty?) + return uno::Reference< text::XText > (); +} + +uno::Any SAL_CALL SvxAccessibleTextPropertySet::queryAggregation( const uno::Type & ) throw(uno::RuntimeException) +{ + // TODO (empty?) + return uno::Any(); +} + +uno::Any SAL_CALL SvxAccessibleTextPropertySet::queryInterface( const uno::Type & rType ) + throw(uno::RuntimeException) +{ + return OWeakObject::queryInterface(rType); +} + +void SAL_CALL SvxAccessibleTextPropertySet::acquire() + throw() +{ + OWeakObject::acquire(); +} + +void SAL_CALL SvxAccessibleTextPropertySet::release() + throw() +{ + OWeakObject::release(); +} + +// XTypeProvider +uno::Sequence< uno::Type > SAL_CALL SvxAccessibleTextPropertySet::getTypes() throw ( uno::RuntimeException ) +{ + static ::cppu::OTypeCollection* pTypeCollection = NULL ; + + // double-checked locking pattern. + if ( pTypeCollection == NULL ) + { + osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ; + + // Control these pointer again ... it can be, that another instance will be faster then these! + if ( pTypeCollection == NULL ) + { + // Create a static typecollection ... + static ::cppu::OTypeCollection aTypeCollection( + ::getCppuType( static_cast< const uno::Reference< beans::XPropertySet >* > (0) ), + ::getCppuType( static_cast< const uno::Reference< beans::XMultiPropertySet >* > (0) ), + ::getCppuType( static_cast< const uno::Reference< beans::XPropertyState >* > (0) ), + ::getCppuType( static_cast< const uno::Reference< lang::XServiceInfo >* > (0) ), + ::getCppuType( static_cast< const uno::Reference< lang::XTypeProvider >* > (0) ) ); + + // ... and set his address to static pointer! + pTypeCollection = &aTypeCollection ; + } + } + + return pTypeCollection->getTypes() ; +} + +uno::Sequence< sal_Int8 > SAL_CALL SvxAccessibleTextPropertySet::getImplementationId() + throw (uno::RuntimeException) +{ + static uno::Sequence< sal_Int8 > aId; + if( aId.getLength() == 0 ) + { + aId.realloc( 16 ); + rtl_createUuid( reinterpret_cast< sal_uInt8* > (aId.getArray()), 0, sal_True ); + } + return aId; +} + +// XServiceInfo +::rtl::OUString SAL_CALL SAL_CALL SvxAccessibleTextPropertySet::getImplementationName (void) throw (uno::RuntimeException) +{ + return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("SvxAccessibleTextPropertySet")); +} + +sal_Bool SAL_CALL SvxAccessibleTextPropertySet::supportsService (const ::rtl::OUString& sServiceName) throw (uno::RuntimeException) +{ + // Iterate over all supported service names and return true if on of them + // matches the given name. + uno::Sequence< ::rtl::OUString> aSupportedServices ( + getSupportedServiceNames ()); + for (int i=0; i<aSupportedServices.getLength(); i++) + if (sServiceName == aSupportedServices[i]) + return sal_True; + return sal_False; +} + +uno::Sequence< ::rtl::OUString> SAL_CALL SvxAccessibleTextPropertySet::getSupportedServiceNames (void) throw (uno::RuntimeException) +{ + // TODO + return SvxUnoTextRangeBase::getSupportedServiceNames(); +} + +// XServiceName +::rtl::OUString SAL_CALL SvxAccessibleTextPropertySet::getServiceName() throw (uno::RuntimeException) +{ + return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.beans.PropertyValue")); +} + + diff --git a/editeng/source/uno/unotext.cxx b/editeng/source/uno/unotext.cxx new file mode 100644 index 000000000000..f62000e0d0f8 --- /dev/null +++ b/editeng/source/uno/unotext.cxx @@ -0,0 +1,2724 @@ +/************************************************************************* + * + * 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_editeng.hxx" +#include <vcl/svapp.hxx> +#include <com/sun/star/style/LineSpacing.hpp> +#include <com/sun/star/text/ControlCharacter.hpp> +#include <com/sun/star/text/ControlCharacter.hpp> +#include <com/sun/star/text/XTextField.hdl> +#include <vos/mutex.hxx> +#include <svl/itemset.hxx> +#include <svl/itempool.hxx> +#include <svl/intitem.hxx> +#include <svl/eitem.hxx> +#include <rtl/uuid.h> +#include <rtl/memory.h> + +#include <editeng/fontitem.hxx> +#include <editeng/tstpitem.hxx> +#include <editeng/unoprnms.hxx> +#include <editeng/unotext.hxx> +#include <editeng/unoedsrc.hxx> +#include <editeng/unonrule.hxx> +#include <editeng/unofdesc.hxx> +#include <editeng/unofield.hxx> +#include <editeng/flditem.hxx> +#include <editeng/numitem.hxx> +#include <editeng/editeng.hxx> +#include <editeng/outliner.hxx> +#include <editeng/unoipset.hxx> +#include <comphelper/serviceinfohelper.hxx> + +using namespace ::rtl; +using namespace ::vos; +using namespace ::cppu; +using namespace ::com::sun::star; + +#define QUERYINT( xint ) \ + if( rType == ::getCppuType((const uno::Reference< xint >*)0) ) \ + return uno::makeAny(uno::Reference< xint >(this)) + +const SvxItemPropertySet* ImplGetSvxUnoOutlinerTextCursorSvxPropertySet() +{ + static SvxItemPropertySet aTextCursorSvxPropertySet( ImplGetSvxUnoOutlinerTextCursorPropertyMap(), EditEngine::GetGlobalItemPool() ); + return &aTextCursorSvxPropertySet; +} + +const SfxItemPropertyMapEntry* ImplGetSvxTextPortionPropertyMap() +{ + // Propertymap fuer einen Outliner Text + static const SfxItemPropertyMapEntry aSvxTextPortionPropertyMap[] = + { + SVX_UNOEDIT_CHAR_PROPERTIES, + SVX_UNOEDIT_FONT_PROPERTIES, + SVX_UNOEDIT_OUTLINER_PROPERTIES, + SVX_UNOEDIT_PARA_PROPERTIES, + {MAP_CHAR_LEN("TextField"), EE_FEATURE_FIELD, &::getCppuType((const uno::Reference< text::XTextField >*)0), beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN("TextPortionType"), WID_PORTIONTYPE, &::getCppuType((const ::rtl::OUString*)0), beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS, &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0) , 0, 0}, + {MAP_CHAR_LEN("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS, &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0) , 0, 0}, + {0,0,0,0,0,0} + }; + return aSvxTextPortionPropertyMap; +} +const SvxItemPropertySet* ImplGetSvxTextPortionSvxPropertySet() +{ + static SvxItemPropertySet aSvxTextPortionPropertySet( ImplGetSvxTextPortionPropertyMap(), EditEngine::GetGlobalItemPool() ); + return &aSvxTextPortionPropertySet; +} + +const SfxItemPropertySet* ImplGetSvxTextPortionSfxPropertySet() +{ + static SfxItemPropertySet aSvxTextPortionSfxPropertySet( ImplGetSvxTextPortionPropertyMap() ); + return &aSvxTextPortionSfxPropertySet; +} + +const SfxItemPropertyMapEntry* ImplGetSvxUnoOutlinerTextCursorPropertyMap() +{ + // Propertymap fuer einen Outliner Text + static const SfxItemPropertyMapEntry aSvxUnoOutlinerTextCursorPropertyMap[] = + { + SVX_UNOEDIT_CHAR_PROPERTIES, + SVX_UNOEDIT_FONT_PROPERTIES, + SVX_UNOEDIT_OUTLINER_PROPERTIES, + SVX_UNOEDIT_PARA_PROPERTIES, + {MAP_CHAR_LEN("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS, &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0) , 0, 0}, + {MAP_CHAR_LEN("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS, &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0) , 0, 0}, + {0,0,0,0,0,0} + }; + + return aSvxUnoOutlinerTextCursorPropertyMap; +} +const SfxItemPropertySet* ImplGetSvxUnoOutlinerTextCursorSfxPropertySet() +{ + static SfxItemPropertySet aTextCursorSfxPropertySet( ImplGetSvxUnoOutlinerTextCursorPropertyMap() ); + return &aTextCursorSfxPropertySet; +} + +// ==================================================================== +// helper fuer Item/Property Konvertierung +// ==================================================================== + +void GetSelection( struct ESelection& rSel, SvxTextForwarder* pForwarder ) throw() +{ + DBG_ASSERT( pForwarder, "I need a valid SvxTextForwarder!" ); + if( pForwarder ) + { + sal_Int16 nParaCount = pForwarder->GetParagraphCount(); + if(nParaCount>0) + nParaCount--; + + rSel = ESelection( 0,0, nParaCount, pForwarder->GetTextLen( nParaCount )); + } +} + +void CheckSelection( struct ESelection& rSel, SvxTextForwarder* pForwarder ) throw() +{ + DBG_ASSERT( pForwarder, "I need a valid SvxTextForwarder!" ); + if( pForwarder ) + { + if( rSel.nStartPara == 0xffff ) + { + ::GetSelection( rSel, pForwarder ); + } + else + { + ESelection aMaxSelection; + GetSelection( aMaxSelection, pForwarder ); + + // check start position + if( rSel.nStartPara < aMaxSelection.nStartPara ) + { + rSel.nStartPara = aMaxSelection.nStartPara; + rSel.nStartPos = aMaxSelection.nStartPos; + } + else if( rSel.nStartPara > aMaxSelection.nEndPara ) + { + rSel.nStartPara = aMaxSelection.nEndPara; + rSel.nStartPos = aMaxSelection.nEndPos; + } + else if( rSel.nStartPos > pForwarder->GetTextLen( rSel.nStartPara ) ) + { + rSel.nStartPos = pForwarder->GetTextLen( rSel.nStartPara ); + } + + // check end position + if( rSel.nEndPara < aMaxSelection.nStartPara ) + { + rSel.nEndPara = aMaxSelection.nStartPara; + rSel.nEndPos = aMaxSelection.nStartPos; + } + else if( rSel.nEndPara > aMaxSelection.nEndPara ) + { + rSel.nEndPara = aMaxSelection.nEndPara; + rSel.nEndPos = aMaxSelection.nEndPos; + } + else if( rSel.nEndPos > pForwarder->GetTextLen( rSel.nEndPara ) ) + { + rSel.nEndPos = pForwarder->GetTextLen( rSel.nEndPara ); + } + } + } +} + +// ==================================================================== +// class SvxUnoTextRangeBase +// ==================================================================== + +#ifdef DEBUG +class check_me +{ +public: + check_me() : mnAllocNum(0) {}; + ~check_me(); + + void add( SvxUnoTextRangeBase* pRange ); + void remove( SvxUnoTextRangeBase* pRange ); + + std::list< std::pair< sal_uInt32, SvxUnoTextRangeBase* > > maRanges; + sal_uInt32 mnAllocNum; +}; + +void check_me::add( SvxUnoTextRangeBase* pRange ) +{ + maRanges.push_back( std::pair< sal_uInt32, SvxUnoTextRangeBase* >( mnAllocNum++, pRange ) ); +} + +void check_me::remove( SvxUnoTextRangeBase* pRange ) +{ + std::list< std::pair< sal_uInt32, SvxUnoTextRangeBase* > >::iterator aIter; + for( aIter = maRanges.begin(); aIter != maRanges.end(); aIter++ ) + { + if( pRange == (*aIter).second ) + { + maRanges.erase( aIter ); + break; + } + } +} + +check_me::~check_me() +{ + if( !maRanges.empty() ) + { + DBG_ERROR("living text range detected!"); + std::list< std::pair< sal_uInt32, SvxUnoTextRangeBase* > >::iterator aIter; + for( aIter = maRanges.begin(); aIter != maRanges.end(); aIter++ ) + { + sal_Int32 nAllocNum; + SvxUnoTextRangeBase* pRange; + nAllocNum = (*aIter).first; + pRange = (*aIter).second; + } + } +} + +static check_me gNumRanges; +#endif + +UNO3_GETIMPLEMENTATION_IMPL( SvxUnoTextRangeBase ); + +SvxUnoTextRangeBase::SvxUnoTextRangeBase( const SvxItemPropertySet* _pSet ) throw() +: mpEditSource(NULL) , mpPropSet(_pSet) +{ +#ifdef DEBUG + gNumRanges.add(this); +#endif +} + +SvxUnoTextRangeBase::SvxUnoTextRangeBase( const SvxEditSource* pSource, const SvxItemPropertySet* _pSet ) throw() +: mpPropSet(_pSet) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + DBG_ASSERT(pSource,"SvxUnoTextRangeBase: I need a valid SvxEditSource!"); + + mpEditSource = pSource->Clone(); + if (mpEditSource != NULL) + { + ESelection aSelection; + ::GetSelection( aSelection, mpEditSource->GetTextForwarder() ); + SetSelection( aSelection ); + + mpEditSource->addRange( this ); + } +#ifdef DEBUG + gNumRanges.add(this); +#endif +} + +SvxUnoTextRangeBase::SvxUnoTextRangeBase( const SvxUnoTextRangeBase& rRange ) throw() +: text::XTextRange() +, beans::XPropertySet() +, beans::XMultiPropertySet() +, beans::XMultiPropertyStates() +, beans::XPropertyState() +, lang::XServiceInfo() +, text::XTextRangeCompare() +, lang::XUnoTunnel() +, mpPropSet(rRange.getPropertySet()) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + mpEditSource = rRange.mpEditSource ? rRange.mpEditSource->Clone() : NULL; + + SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL; + if( pForwarder ) + { + maSelection = rRange.maSelection; + CheckSelection( maSelection, pForwarder ); + } + + if( mpEditSource ) + mpEditSource->addRange( this ); + +#ifdef DEBUG + gNumRanges.add(this); +#endif +} + +SvxUnoTextRangeBase::~SvxUnoTextRangeBase() throw() +{ +#ifdef DEBUG + gNumRanges.remove(this); +#endif + + if( mpEditSource ) + mpEditSource->removeRange( this ); + + delete mpEditSource; +} + +void SvxUnoTextRangeBase::SetEditSource( SvxEditSource* pSource ) throw() +{ + DBG_ASSERT(pSource,"SvxUnoTextRangeBase: I need a valid SvxEditSource!"); + DBG_ASSERT(mpEditSource==NULL,"SvxUnoTextRangeBase::SetEditSource called while SvxEditSource already set" ); + + mpEditSource = pSource; + + maSelection.nStartPara = 0xffff; + + if( mpEditSource ) + mpEditSource->addRange( this ); +} + +/** puts a field item with a copy of the given FieldData into the itemset + corresponding with this range */ +void SvxUnoTextRangeBase::attachField( const SvxFieldData* pData ) throw() +{ + OGuard aGuard( Application::GetSolarMutex() ); + + if( pData ) + { + SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL; + if( pForwarder ) + { + SvxFieldItem aField( *pData, EE_FEATURE_FIELD ); + pForwarder->QuickInsertField( aField, maSelection ); + } + } +} + +void SvxUnoTextRangeBase::SetSelection( const ESelection& rSelection ) throw() +{ + OGuard aGuard( Application::GetSolarMutex() ); + + maSelection = rSelection; + if (mpEditSource != NULL) + CheckSelection( maSelection, mpEditSource->GetTextForwarder() ); +} + +// Interface XTextRange ( XText ) + +uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextRangeBase::getStart(void) + throw( uno::RuntimeException ) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + uno::Reference< text::XTextRange > xRange; + + SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL; + if( pForwarder ) + { + + CheckSelection( maSelection, pForwarder ); + + SvxUnoTextBase* pText = SvxUnoTextBase::getImplementation( getText() ); + + if(pText == NULL) + throw uno::RuntimeException(); + + SvxUnoTextRange* pRange = new SvxUnoTextRange( *pText ); + xRange = pRange; + + ESelection aNewSel = maSelection; + aNewSel.nEndPara = aNewSel.nStartPara; + aNewSel.nEndPos = aNewSel.nStartPos; + pRange->SetSelection( aNewSel ); + } + + return xRange; +} + +uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextRangeBase::getEnd(void) + throw( uno::RuntimeException ) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + uno::Reference< text::XTextRange > xRet; + + SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL; + if( pForwarder ) + { + CheckSelection( maSelection, pForwarder ); + + SvxUnoTextBase* pText = SvxUnoTextBase::getImplementation( getText() ); + + if(pText == NULL) + throw uno::RuntimeException(); + + SvxUnoTextRange* pNew = new SvxUnoTextRange( *pText ); + xRet = pNew; + + ESelection aNewSel = maSelection; + aNewSel.nStartPara = aNewSel.nEndPara; + aNewSel.nStartPos = aNewSel.nEndPos; + pNew->SetSelection( aNewSel ); + } + return xRet; +} + +OUString SAL_CALL SvxUnoTextRangeBase::getString(void) + throw( uno::RuntimeException ) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL; + if( pForwarder ) + { + CheckSelection( maSelection, pForwarder ); + + return pForwarder->GetText( maSelection ); + } + else + { + const OUString aEmpty; + return aEmpty; + } +} + +void SAL_CALL SvxUnoTextRangeBase::setString(const OUString& aString) + throw( uno::RuntimeException ) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL; + if( pForwarder ) + { + CheckSelection( maSelection, pForwarder ); + + String aConverted( aString ); + aConverted.ConvertLineEnd( LINEEND_LF ); // Zeilenenden nur einfach zaehlen + + pForwarder->QuickInsertText( aConverted, maSelection ); + mpEditSource->UpdateData(); + + // Selektion anpassen + //! Wenn die EditEngine bei QuickInsertText die Selektion zurueckgeben wuerde, + //! waer's einfacher... + CollapseToStart(); + + sal_uInt16 nLen = aConverted.Len(); + if (nLen) + GoRight( nLen, sal_True ); + } +} + +// Interface beans::XPropertySet +uno::Reference< beans::XPropertySetInfo > SAL_CALL SvxUnoTextRangeBase::getPropertySetInfo(void) + throw( uno::RuntimeException ) +{ + return mpPropSet->getPropertySetInfo(); +} + +void SAL_CALL SvxUnoTextRangeBase::setPropertyValue(const OUString& PropertyName, const uno::Any& aValue) + throw( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException ) +{ + _setPropertyValue( PropertyName, aValue, -1 ); +} + +void SAL_CALL SvxUnoTextRangeBase::_setPropertyValue( const OUString& PropertyName, const uno::Any& aValue, sal_Int32 nPara ) + throw( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException ) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL; + if( pForwarder ) + { + + CheckSelection( maSelection, pForwarder ); + + const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName ); + if ( pMap ) + { + ESelection aSel( GetSelection() ); + sal_Bool bParaAttrib = (pMap->nWID >= EE_PARA_START) && ( pMap->nWID <= EE_PARA_END ); + + if( nPara == -1 && !bParaAttrib ) + { + SfxItemSet aOldSet( pForwarder->GetAttribs( aSel ) ); + // we have a selection and no para attribute + SfxItemSet aNewSet( *aOldSet.GetPool(), aOldSet.GetRanges() ); + + setPropertyValue( pMap, aValue, maSelection, aOldSet, aNewSet ); + + + pForwarder->QuickSetAttribs( aNewSet, GetSelection() ); + } + else + { + sal_Int32 nEndPara; + + if( nPara == -1 ) + { + nPara = aSel.nStartPara; + nEndPara = aSel.nEndPara; + } + else + { + // only one paragraph + nEndPara = nPara; + } + + while( nPara <= nEndPara ) + { + // we have a paragraph + SfxItemSet aSet( pForwarder->GetParaAttribs( (sal_uInt16)nPara ) ); + setPropertyValue( pMap, aValue, maSelection, aSet, aSet ); + pForwarder->SetParaAttribs( (sal_uInt16)nPara, aSet ); + nPara++; + } + } + + GetEditSource()->UpdateData(); + return; + } + } + + throw beans::UnknownPropertyException(); +} + +void SvxUnoTextRangeBase::setPropertyValue( const SfxItemPropertySimpleEntry* pMap, const uno::Any& rValue, const ESelection& rSelection, const SfxItemSet& rOldSet, SfxItemSet& rNewSet ) throw( beans::UnknownPropertyException, lang::IllegalArgumentException ) +{ + if(!SetPropertyValueHelper( rOldSet, pMap, rValue, rNewSet, &rSelection, GetEditSource() )) + { + // Fuer Teile von zusammengesetzten Items mit mehreren Properties (z.B. Hintergrund) + // muss vorher das alte Item aus dem Dokument geholt werden + rNewSet.Put(rOldSet.Get(pMap->nWID)); // altes Item in neuen Set + mpPropSet->setPropertyValue(pMap, rValue, rNewSet, false ); + } +} + +sal_Bool SvxUnoTextRangeBase::SetPropertyValueHelper( const SfxItemSet&, const SfxItemPropertySimpleEntry* pMap, const uno::Any& aValue, SfxItemSet& rNewSet, const ESelection* pSelection /* = NULL */, SvxEditSource* pEditSource /* = NULL*/ ) throw( uno::RuntimeException ) +{ + switch( pMap->nWID ) + { + case WID_FONTDESC: + { + awt::FontDescriptor aDesc; + if(aValue >>= aDesc) + { + SvxUnoFontDescriptor::FillItemSet( aDesc, rNewSet ); + return sal_True; + } + } + break; + + case EE_PARA_NUMBULLET: + { + uno::Reference< container::XIndexReplace > xRule; + if( !aValue.hasValue() || ((aValue >>= xRule) && !xRule.is()) ) + return sal_True; + + return sal_False; + } + + case WID_NUMLEVEL: + { + SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL; + if(pForwarder && pSelection) + { + sal_Int16 nLevel = sal_Int16(); + if( aValue >>= nLevel ) + { + // #101004# Call interface method instead of unsafe cast + if(! pForwarder->SetDepth( pSelection->nStartPara, nLevel ) ) + throw lang::IllegalArgumentException(); + + return sal_True; + } + } + } + break; + case WID_NUMBERINGSTARTVALUE: + { + SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL; + if(pForwarder && pSelection) + { + sal_Int16 nStartValue = -1; + if( aValue >>= nStartValue ) + { + pForwarder->SetNumberingStartValue( pSelection->nStartPara, nStartValue ); + return sal_True; + } + } + } + break; + case WID_PARAISNUMBERINGRESTART: + { + SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL; + if(pForwarder && pSelection) + { + sal_Bool bParaIsNumberingRestart = sal_False; + if( aValue >>= bParaIsNumberingRestart ) + { + pForwarder->SetParaIsNumberingRestart( pSelection->nStartPara, bParaIsNumberingRestart ); + return sal_True; + } + } + } + break; + case EE_PARA_BULLETSTATE: + { + sal_Bool bBullet = sal_True; + if( aValue >>= bBullet ) + { + SfxBoolItem aItem( EE_PARA_BULLETSTATE, bBullet ); + rNewSet.Put(aItem); + return sal_True; + } + } + break; + + default: + return sal_False; + } + + throw lang::IllegalArgumentException(); +} + +uno::Any SAL_CALL SvxUnoTextRangeBase::getPropertyValue(const OUString& PropertyName) + throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException ) +{ + return _getPropertyValue( PropertyName, -1 ); +} + +uno::Any SAL_CALL SvxUnoTextRangeBase::_getPropertyValue(const OUString& PropertyName, sal_Int32 nPara ) + throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException ) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + uno::Any aAny; + + SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL; + if( pForwarder ) + { + const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName ); + if( pMap ) + { + SfxItemSet* pAttribs = NULL; + if( nPara != -1 ) + pAttribs = pForwarder->GetParaAttribs( (sal_uInt16)nPara ).Clone(); + else + pAttribs = pForwarder->GetAttribs( GetSelection() ).Clone(); + + // Dontcare durch Default ersetzen, damit man immer eine Reflection hat + pAttribs->ClearInvalidItems(); + + getPropertyValue( pMap, aAny, *pAttribs ); + + delete pAttribs; + return aAny; + } + } + + throw beans::UnknownPropertyException(); +} + +void SvxUnoTextRangeBase::getPropertyValue( const SfxItemPropertySimpleEntry* pMap, uno::Any& rAny, const SfxItemSet& rSet ) throw( beans::UnknownPropertyException ) +{ + switch( pMap->nWID ) + { + case EE_FEATURE_FIELD: + if ( rSet.GetItemState( EE_FEATURE_FIELD, sal_False ) == SFX_ITEM_SET ) + { + SvxFieldItem* pItem = (SvxFieldItem*)rSet.GetItem( EE_FEATURE_FIELD ); + const SvxFieldData* pData = pItem->GetField(); + uno::Reference< text::XTextRange > xAnchor( this ); + + // get presentation string for field + Color* pTColor = NULL; + Color* pFColor = NULL; + + SvxTextForwarder* pForwarder = mpEditSource->GetTextForwarder(); + OUString aPresentation( pForwarder->CalcFieldValue( SvxFieldItem(*pData, EE_FEATURE_FIELD), maSelection.nStartPara, maSelection.nStartPos, pTColor, pFColor ) ); + + delete pTColor; + delete pFColor; + + uno::Reference< text::XTextField > xField( new SvxUnoTextField( xAnchor, aPresentation, pData ) ); + rAny <<= xField; + } + break; + + case WID_PORTIONTYPE: + if ( rSet.GetItemState( EE_FEATURE_FIELD, sal_False ) == SFX_ITEM_SET ) + { + OUString aType( RTL_CONSTASCII_USTRINGPARAM("TextField") ); + rAny <<= aType; + } + else + { + OUString aType( RTL_CONSTASCII_USTRINGPARAM("Text") ); + rAny <<= aType; + } + break; + + default: + if(!GetPropertyValueHelper( *((SfxItemSet*)(&rSet)), pMap, rAny, &maSelection, GetEditSource() )) + rAny = mpPropSet->getPropertyValue(pMap, rSet, true, false ); + } +} + +sal_Bool SvxUnoTextRangeBase::GetPropertyValueHelper( SfxItemSet& rSet, const SfxItemPropertySimpleEntry* pMap, uno::Any& aAny, const ESelection* pSelection /* = NULL */, SvxEditSource* pEditSource /* = NULL */ ) + throw( uno::RuntimeException ) +{ + switch( pMap->nWID ) + { + case WID_FONTDESC: + { + awt::FontDescriptor aDesc; + SvxUnoFontDescriptor::FillFromItemSet( rSet, aDesc ); + aAny <<= aDesc; + } + break; + + case EE_PARA_NUMBULLET: + { + if((rSet.GetItemState( EE_PARA_NUMBULLET, sal_True ) & (SFX_ITEM_SET|SFX_ITEM_DEFAULT)) == 0) + throw uno::RuntimeException(); + + SvxNumBulletItem* pBulletItem = (SvxNumBulletItem*)rSet.GetItem( EE_PARA_NUMBULLET, sal_True ); + + if( pBulletItem == NULL ) + throw uno::RuntimeException(); + + aAny <<= SvxCreateNumRule( pBulletItem->GetNumRule() ); + } + break; + + case WID_NUMLEVEL: + { + SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL; + if(pForwarder && pSelection) + { + sal_Int16 nLevel = pForwarder->GetDepth( pSelection->nStartPara ); + if( nLevel >= 0 ) + aAny <<= nLevel; + } + } + break; + case WID_NUMBERINGSTARTVALUE: + { + SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL; + if(pForwarder && pSelection) + aAny <<= pForwarder->GetNumberingStartValue( pSelection->nStartPara ); + } + break; + case WID_PARAISNUMBERINGRESTART: + { + SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL; + if(pForwarder && pSelection) + aAny <<= pForwarder->IsParaIsNumberingRestart( pSelection->nStartPara ); + } + break; + + case EE_PARA_BULLETSTATE: + { + sal_Bool bState = sal_False; + if( rSet.GetItemState( EE_PARA_BULLETSTATE, sal_True ) & (SFX_ITEM_SET|SFX_ITEM_DEFAULT)) + { + SfxBoolItem* pItem = (SfxBoolItem*)rSet.GetItem( EE_PARA_BULLETSTATE, sal_True ); + bState = pItem->GetValue() ? sal_True : sal_False; + } + + aAny <<= bState; + } + break; + default: + + return sal_False; + } + + return sal_True; +} + +// wird (noch) nicht unterstuetzt +void SAL_CALL SvxUnoTextRangeBase::addPropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {} +void SAL_CALL SvxUnoTextRangeBase::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {} +void SAL_CALL SvxUnoTextRangeBase::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {} +void SAL_CALL SvxUnoTextRangeBase::removeVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {} + +// XMultiPropertySet +void SAL_CALL SvxUnoTextRangeBase::setPropertyValues( const uno::Sequence< ::rtl::OUString >& aPropertyNames, const uno::Sequence< uno::Any >& aValues ) throw (beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException) +{ + _setPropertyValues( aPropertyNames, aValues, -1 ); +} + +void SAL_CALL SvxUnoTextRangeBase::_setPropertyValues( const uno::Sequence< ::rtl::OUString >& aPropertyNames, const uno::Sequence< uno::Any >& aValues, sal_Int32 nPara ) throw (beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL; + if( pForwarder ) + { + CheckSelection( maSelection, pForwarder ); + + ESelection aSel( GetSelection() ); + + const OUString* pPropertyNames = aPropertyNames.getConstArray(); + const uno::Any* pValues = aValues.getConstArray(); + sal_Int32 nCount = aPropertyNames.getLength(); + + sal_Int32 nEndPara = nPara; + sal_Int32 nTempPara = nPara; + + if( nTempPara == -1 ) + { + nTempPara = aSel.nStartPara; + nEndPara = aSel.nEndPara; + } + + SfxItemSet* pOldAttrSet = NULL; + SfxItemSet* pNewAttrSet = NULL; + + SfxItemSet* pOldParaSet = NULL; + SfxItemSet* pNewParaSet = NULL; + + for( ; nCount; nCount--, pPropertyNames++, pValues++ ) + { + const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( *pPropertyNames ); + + if( pMap ) + { + sal_Bool bParaAttrib = (pMap->nWID >= EE_PARA_START) && ( pMap->nWID <= EE_PARA_END ); + + if( (nPara == -1) && !bParaAttrib ) + { + if( NULL == pNewAttrSet ) + { + const SfxItemSet aSet( pForwarder->GetAttribs( aSel ) ); + pOldAttrSet = new SfxItemSet( aSet ); + pNewAttrSet = new SfxItemSet( *pOldAttrSet->GetPool(), pOldAttrSet->GetRanges() ); + } + + setPropertyValue( pMap, *pValues, GetSelection(), *pOldAttrSet, *pNewAttrSet ); + + if( pMap->nWID >= EE_ITEMS_START && pMap->nWID <= EE_ITEMS_END ) + { + const SfxPoolItem* pItem; + if( pNewAttrSet->GetItemState( pMap->nWID, sal_True, &pItem ) == SFX_ITEM_SET ) + { + pOldAttrSet->Put( *pItem ); + } + } + } + else + { + if( NULL == pNewParaSet ) + { + const SfxItemSet aSet( pForwarder->GetParaAttribs( (sal_uInt16)nTempPara ) ); + pOldParaSet = new SfxItemSet( aSet ); + pNewParaSet = new SfxItemSet( *pOldParaSet->GetPool(), pOldParaSet->GetRanges() ); + } + + setPropertyValue( pMap, *pValues, GetSelection(), *pOldParaSet, *pNewParaSet ); + + if( pMap->nWID >= EE_ITEMS_START && pMap->nWID <= EE_ITEMS_END ) + { + const SfxPoolItem* pItem; + if( pNewParaSet->GetItemState( pMap->nWID, sal_True, &pItem ) == SFX_ITEM_SET ) + { + pOldParaSet->Put( *pItem ); + } + } + + } + } + } + + sal_Bool bNeedsUpdate = sal_False; + + if( pNewParaSet ) + { + if( pNewParaSet->Count() ) + { + while( nTempPara <= nEndPara ) + { + SfxItemSet aSet( pForwarder->GetParaAttribs( (sal_uInt16)nTempPara ) ); + aSet.Put( *pNewParaSet ); + pForwarder->SetParaAttribs( (sal_uInt16)nTempPara, aSet ); + nTempPara++; + } + bNeedsUpdate = sal_True; + } + + delete pNewParaSet; + delete pOldParaSet; + } + + if( pNewAttrSet ) + { + if( pNewAttrSet->Count() ) + { + pForwarder->QuickSetAttribs( *pNewAttrSet, GetSelection() ); + bNeedsUpdate = sal_True; + } + delete pNewAttrSet; + delete pOldAttrSet; + + } + + if( bNeedsUpdate ) + GetEditSource()->UpdateData(); + } +} + +uno::Sequence< uno::Any > SAL_CALL SvxUnoTextRangeBase::getPropertyValues( const uno::Sequence< ::rtl::OUString >& aPropertyNames ) throw (uno::RuntimeException) +{ + return _getPropertyValues( aPropertyNames, -1 ); +} + +uno::Sequence< uno::Any > SAL_CALL SvxUnoTextRangeBase::_getPropertyValues( const uno::Sequence< ::rtl::OUString >& aPropertyNames, sal_Int32 nPara ) throw (uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + sal_Int32 nCount = aPropertyNames.getLength(); + + + uno::Sequence< uno::Any > aValues( nCount ); + + SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL; + if( pForwarder ) + { + SfxItemSet* pAttribs = NULL; + if( nPara != -1 ) + pAttribs = pForwarder->GetParaAttribs( (sal_uInt16)nPara ).Clone(); + else + pAttribs = pForwarder->GetAttribs( GetSelection() ).Clone(); + + pAttribs->ClearInvalidItems(); + + const OUString* pPropertyNames = aPropertyNames.getConstArray(); + uno::Any* pValues = aValues.getArray(); + + for( ; nCount; nCount--, pPropertyNames++, pValues++ ) + { + const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( *pPropertyNames ); + if( pMap ) + { + getPropertyValue( pMap, *pValues, *pAttribs ); + } + } + + delete pAttribs; + + } + + return aValues; +} + +void SAL_CALL SvxUnoTextRangeBase::addPropertiesChangeListener( const uno::Sequence< ::rtl::OUString >& , const uno::Reference< beans::XPropertiesChangeListener >& ) throw (uno::RuntimeException) +{ +} + +void SAL_CALL SvxUnoTextRangeBase::removePropertiesChangeListener( const uno::Reference< beans::XPropertiesChangeListener >& ) throw (uno::RuntimeException) +{ +} + +void SAL_CALL SvxUnoTextRangeBase::firePropertiesChangeEvent( const uno::Sequence< ::rtl::OUString >& , const uno::Reference< beans::XPropertiesChangeListener >& ) throw (uno::RuntimeException) +{ +} + +// beans::XPropertyState +beans::PropertyState SAL_CALL SvxUnoTextRangeBase::getPropertyState( const OUString& PropertyName ) + throw(beans::UnknownPropertyException, uno::RuntimeException) +{ + return _getPropertyState( PropertyName, -1 ); +} + +static sal_uInt16 aSvxUnoFontDescriptorWhichMap[] = { EE_CHAR_FONTINFO, EE_CHAR_FONTHEIGHT, EE_CHAR_ITALIC, + EE_CHAR_UNDERLINE, EE_CHAR_WEIGHT, EE_CHAR_STRIKEOUT, + EE_CHAR_WLM, 0 }; + +beans::PropertyState SAL_CALL SvxUnoTextRangeBase::_getPropertyState(const SfxItemPropertySimpleEntry* pMap, sal_Int32 nPara) + throw( beans::UnknownPropertyException, uno::RuntimeException ) +{ + if ( pMap ) + { + SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL; + if( pForwarder ) + { + SfxItemState eItemState = SFX_ITEM_UNKNOWN; + sal_uInt16 nWID = 0; + + switch( pMap->nWID ) + { + case WID_FONTDESC: + { + sal_uInt16* pWhichId = aSvxUnoFontDescriptorWhichMap; + SfxItemState eTempItemState; + while( *pWhichId ) + { + if(nPara != -1) + eTempItemState = pForwarder->GetItemState( (sal_uInt16)nPara, *pWhichId ); + else + eTempItemState = pForwarder->GetItemState( GetSelection(), *pWhichId ); + + switch( eTempItemState ) + { + case SFX_ITEM_DISABLED: + case SFX_ITEM_DONTCARE: + eItemState = SFX_ITEM_DONTCARE; + break; + + case SFX_ITEM_DEFAULT: + if( eItemState != SFX_ITEM_DEFAULT ) + { + if( eItemState == SFX_ITEM_UNKNOWN ) + eItemState = SFX_ITEM_DEFAULT; + } + break; + + case SFX_ITEM_READONLY: + case SFX_ITEM_SET: + if( eItemState != SFX_ITEM_SET ) + { + if( eItemState == SFX_ITEM_UNKNOWN ) + eItemState = SFX_ITEM_SET; + } + break; + default: + throw beans::UnknownPropertyException(); + } + + pWhichId++; + } + } + break; + + case WID_NUMLEVEL: + case WID_NUMBERINGSTARTVALUE: + case WID_PARAISNUMBERINGRESTART: + eItemState = SFX_ITEM_SET; + break; + + default: + nWID = pMap->nWID; + } + + if( nWID != 0 ) + { + if( nPara != -1 ) + eItemState = pForwarder->GetItemState( (sal_uInt16)nPara, nWID ); + else + eItemState = pForwarder->GetItemState( GetSelection(), nWID ); + } + + switch( eItemState ) + { + case SFX_ITEM_DONTCARE: + case SFX_ITEM_DISABLED: + return beans::PropertyState_AMBIGUOUS_VALUE; + case SFX_ITEM_READONLY: + case SFX_ITEM_SET: + return beans::PropertyState_DIRECT_VALUE; + case SFX_ITEM_DEFAULT: + return beans::PropertyState_DEFAULT_VALUE; +// case SFX_ITEM_UNKNOWN: + } + } + } + throw beans::UnknownPropertyException(); +} + +beans::PropertyState SAL_CALL SvxUnoTextRangeBase::_getPropertyState(const OUString& PropertyName, sal_Int32 nPara /* = -1 */) + throw( beans::UnknownPropertyException, uno::RuntimeException ) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + return _getPropertyState( mpPropSet->getPropertyMapEntry( PropertyName ), nPara); +} + +uno::Sequence< beans::PropertyState > SAL_CALL SvxUnoTextRangeBase::getPropertyStates( const uno::Sequence< OUString >& aPropertyName ) + throw(beans::UnknownPropertyException, uno::RuntimeException) +{ + return _getPropertyStates( aPropertyName, -1 ); +} + +uno::Sequence< beans::PropertyState > SvxUnoTextRangeBase::_getPropertyStates(const uno::Sequence< OUString >& PropertyName, sal_Int32 nPara /* = -1 */) + throw( beans::UnknownPropertyException, uno::RuntimeException ) +{ + const sal_Int32 nCount = PropertyName.getLength(); + const OUString* pNames = PropertyName.getConstArray(); + + uno::Sequence< beans::PropertyState > aRet( nCount ); + beans::PropertyState* pState = aRet.getArray(); + + SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL; + if( pForwarder ) + { + SfxItemSet* pSet = NULL; + if( nPara != -1 ) + { + pSet = new SfxItemSet( pForwarder->GetParaAttribs( (sal_uInt16)nPara ) ); + } + else + { + ESelection aSel( GetSelection() ); + CheckSelection( aSel, pForwarder ); + pSet = new SfxItemSet( pForwarder->GetAttribs( aSel, EditEngineAttribs_OnlyHard ) ); + } + + sal_Bool bUnknownPropertyFound = sal_False; + for( sal_Int32 nIdx = 0; nIdx < nCount; nIdx++ ) + { + const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( *pNames++ ); + if( NULL == pMap ) + { + bUnknownPropertyFound = sal_True; + break; + } + bUnknownPropertyFound = !_getOnePropertyStates(pSet, pMap, *pState++); + } + + delete pSet; + + if( bUnknownPropertyFound ) + throw beans::UnknownPropertyException(); + } + + return aRet; +} + +sal_Bool SvxUnoTextRangeBase::_getOnePropertyStates(const SfxItemSet* pSet, const SfxItemPropertySimpleEntry* pMap, beans::PropertyState& rState) +{ + sal_Bool bUnknownPropertyFound = sal_False; + if(pSet && pMap) + { + SfxItemState eItemState = SFX_ITEM_UNKNOWN; + sal_uInt16 nWID = 0; + + switch( pMap->nWID ) + { + case WID_FONTDESC: + { + sal_uInt16* pWhichId = aSvxUnoFontDescriptorWhichMap; + SfxItemState eTempItemState; + while( *pWhichId ) + { + eTempItemState = pSet->GetItemState( *pWhichId ); + + switch( eTempItemState ) + { + case SFX_ITEM_DISABLED: + case SFX_ITEM_DONTCARE: + eItemState = SFX_ITEM_DONTCARE; + break; + + case SFX_ITEM_DEFAULT: + if( eItemState != SFX_ITEM_DEFAULT ) + { + if( eItemState == SFX_ITEM_UNKNOWN ) + eItemState = SFX_ITEM_DEFAULT; + } + break; + + case SFX_ITEM_READONLY: + case SFX_ITEM_SET: + if( eItemState != SFX_ITEM_SET ) + { + if( eItemState == SFX_ITEM_UNKNOWN ) + eItemState = SFX_ITEM_SET; + } + break; + default: + bUnknownPropertyFound = sal_True; + break; + } + + pWhichId++; + } + } + break; + + case WID_NUMLEVEL: + case WID_NUMBERINGSTARTVALUE: + case WID_PARAISNUMBERINGRESTART: + eItemState = SFX_ITEM_SET; + break; + + default: + nWID = pMap->nWID; + } + + if( bUnknownPropertyFound ) + return !bUnknownPropertyFound; + + if( nWID != 0 ) + eItemState = pSet->GetItemState( nWID, sal_False ); + + switch( eItemState ) + { + case SFX_ITEM_READONLY: + case SFX_ITEM_SET: + rState = beans::PropertyState_DIRECT_VALUE; + break; + case SFX_ITEM_DEFAULT: + rState = beans::PropertyState_DEFAULT_VALUE; + break; +// case SFX_ITEM_UNKNOWN: +// case SFX_ITEM_DONTCARE: +// case SFX_ITEM_DISABLED: + default: + rState = beans::PropertyState_AMBIGUOUS_VALUE; + } + } + return !bUnknownPropertyFound; +} + +void SAL_CALL SvxUnoTextRangeBase::setPropertyToDefault( const OUString& PropertyName ) + throw(beans::UnknownPropertyException, uno::RuntimeException) +{ + _setPropertyToDefault( PropertyName, -1 ); +} + +void SvxUnoTextRangeBase::_setPropertyToDefault(const OUString& PropertyName, sal_Int32 nPara /* = -1 */) + throw( beans::UnknownPropertyException, uno::RuntimeException ) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL; + + if( pForwarder ) + { + const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( PropertyName ); + if ( pMap ) + { + CheckSelection( maSelection, mpEditSource->GetTextForwarder() ); + _setPropertyToDefault( pForwarder, pMap, nPara ); + return; + } + } + + throw beans::UnknownPropertyException(); +} + +void SvxUnoTextRangeBase::_setPropertyToDefault(SvxTextForwarder* pForwarder, const SfxItemPropertySimpleEntry* pMap, sal_Int32 nPara ) + throw( beans::UnknownPropertyException, uno::RuntimeException ) +{ + do + { + SfxItemSet aSet( *pForwarder->GetPool(), sal_True ); + + if( pMap->nWID == WID_FONTDESC ) + { + SvxUnoFontDescriptor::setPropertyToDefault( aSet ); + } + else if( pMap->nWID == WID_NUMLEVEL ) + { + // #101004# Call interface method instead of unsafe cast + pForwarder->SetDepth( maSelection.nStartPara, -1 ); + return; + } + else if( pMap->nWID == WID_NUMBERINGSTARTVALUE ) + { + pForwarder->SetNumberingStartValue( maSelection.nStartPara, -1 ); + } + else if( pMap->nWID == WID_PARAISNUMBERINGRESTART ) + { + pForwarder->SetParaIsNumberingRestart( maSelection.nStartPara, sal_False ); + } + else + { + aSet.InvalidateItem( pMap->nWID ); + } + + if(nPara != -1) + pForwarder->SetParaAttribs( (sal_uInt16)nPara, aSet ); + else + pForwarder->QuickSetAttribs( aSet, GetSelection() ); + + GetEditSource()->UpdateData(); + + return; + } + while(0); +} + +uno::Any SAL_CALL SvxUnoTextRangeBase::getPropertyDefault( const OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL; + if( pForwarder ) + { + const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( aPropertyName ); + if( pMap ) + { + SfxItemPool* pPool = pForwarder->GetPool(); + + switch( pMap->nWID ) + { + case WID_FONTDESC: + return SvxUnoFontDescriptor::getPropertyDefault( pPool ); + + case WID_NUMLEVEL: + { + uno::Any aAny; + return aAny; + } + + case WID_NUMBERINGSTARTVALUE: + return uno::Any( (sal_Int16)-1 ); + + case WID_PARAISNUMBERINGRESTART: + return uno::Any( (sal_Bool)sal_False ); + + default: + { + // Default aus ItemPool holen + if(pPool->IsWhich(pMap->nWID)) + { + SfxItemSet aSet( *pPool, pMap->nWID, pMap->nWID); + aSet.Put(pPool->GetDefaultItem(pMap->nWID)); + return mpPropSet->getPropertyValue(pMap, aSet, true, false ); + } + } + } + } + } + throw beans::UnknownPropertyException(); +} + +// beans::XMultiPropertyStates +void SAL_CALL SvxUnoTextRangeBase::setAllPropertiesToDefault( ) throw (uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL; + + if( pForwarder ) + { + PropertyEntryVector_t aEntries = mpPropSet->getPropertyMap()->getPropertyEntries(); + PropertyEntryVector_t::const_iterator aIt = aEntries.begin(); + while( aIt != aEntries.end() ) + { + _setPropertyToDefault( pForwarder, &(*aIt), -1 ); + ++aIt; + } + } +} + +void SAL_CALL SvxUnoTextRangeBase::setPropertiesToDefault( const uno::Sequence< OUString >& aPropertyNames ) throw (beans::UnknownPropertyException, uno::RuntimeException) +{ + sal_Int32 nCount = aPropertyNames.getLength(); + for( const OUString* pName = aPropertyNames.getConstArray(); nCount; pName++, nCount-- ) + { + setPropertyToDefault( *pName ); + } +} + +uno::Sequence< uno::Any > SAL_CALL SvxUnoTextRangeBase::getPropertyDefaults( const uno::Sequence< OUString >& aPropertyNames ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) +{ + sal_Int32 nCount = aPropertyNames.getLength(); + uno::Sequence< uno::Any > ret( nCount ); + uno::Any* pDefaults = ret.getArray(); + + for( const OUString* pName = aPropertyNames.getConstArray(); nCount; pName++, nCount--, pDefaults++ ) + { + *pDefaults = getPropertyDefault( *pName ); + } + + return ret; +} + +// internal +void SvxUnoTextRangeBase::CollapseToStart(void) throw() +{ + CheckSelection( maSelection, mpEditSource->GetTextForwarder() ); + + maSelection.nEndPara = maSelection.nStartPara; + maSelection.nEndPos = maSelection.nStartPos; +} + +void SvxUnoTextRangeBase::CollapseToEnd(void) throw() +{ + CheckSelection( maSelection, mpEditSource->GetTextForwarder() ); + + maSelection.nStartPara = maSelection.nEndPara; + maSelection.nStartPos = maSelection.nEndPos; +} + +sal_Bool SvxUnoTextRangeBase::IsCollapsed(void) throw() +{ + CheckSelection( maSelection, mpEditSource->GetTextForwarder() ); + + return ( maSelection.nStartPara == maSelection.nEndPara && + maSelection.nStartPos == maSelection.nEndPos ); +} + +sal_Bool SvxUnoTextRangeBase::GoLeft(sal_Int16 nCount, sal_Bool Expand) throw() +{ + CheckSelection( maSelection, mpEditSource->GetTextForwarder() ); + + // #75098# use end position, as in Writer (start is anchor, end is cursor) + sal_uInt16 nNewPos = maSelection.nEndPos; + sal_uInt16 nNewPar = maSelection.nEndPara; + + sal_Bool bOk = sal_True; + SvxTextForwarder* pForwarder = NULL; + while ( nCount > nNewPos && bOk ) + { + if ( nNewPar == 0 ) + bOk = sal_False; + else + { + if ( !pForwarder ) + pForwarder = mpEditSource->GetTextForwarder(); // erst hier, wenn's noetig ist... + + --nNewPar; + nCount -= nNewPos + 1; + nNewPos = pForwarder->GetTextLen( nNewPar ); + } + } + + if ( bOk ) + { + nNewPos = nNewPos - nCount; + maSelection.nStartPara = nNewPar; + maSelection.nStartPos = nNewPos; + } + + if (!Expand) + CollapseToStart(); + + return bOk; +} + +sal_Bool SvxUnoTextRangeBase::GoRight(sal_Int16 nCount, sal_Bool Expand) throw() +{ + SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL; + if( pForwarder ) + { + CheckSelection( maSelection, pForwarder ); + + + sal_uInt16 nNewPos = maSelection.nEndPos + nCount; //! Ueberlauf ??? + sal_uInt16 nNewPar = maSelection.nEndPara; + + sal_Bool bOk = sal_True; + sal_uInt16 nParCount = pForwarder->GetParagraphCount(); + sal_uInt16 nThisLen = pForwarder->GetTextLen( nNewPar ); + while ( nNewPos > nThisLen && bOk ) + { + if ( nNewPar + 1 >= nParCount ) + bOk = sal_False; + else + { + nNewPos -= nThisLen+1; + ++nNewPar; + nThisLen = pForwarder->GetTextLen( nNewPar ); + } + } + + if (bOk) + { + maSelection.nEndPara = nNewPar; + maSelection.nEndPos = nNewPos; + } + + if (!Expand) + CollapseToEnd(); + + return bOk; + } + return sal_False; +} + +void SvxUnoTextRangeBase::GotoStart(sal_Bool Expand) throw() +{ + maSelection.nStartPara = 0; + maSelection.nStartPos = 0; + + if (!Expand) + CollapseToStart(); +} + +void SvxUnoTextRangeBase::GotoEnd(sal_Bool Expand) throw() +{ + CheckSelection( maSelection, mpEditSource->GetTextForwarder() ); + + SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL; + if( pForwarder ) + { + + sal_uInt16 nPar = pForwarder->GetParagraphCount(); + if (nPar) + --nPar; + + maSelection.nEndPara = nPar; + maSelection.nEndPos = pForwarder->GetTextLen( nPar ); + + if (!Expand) + CollapseToEnd(); + } +} + +// lang::XServiceInfo +sal_Bool SAL_CALL SvxUnoTextRangeBase::supportsService( const OUString& ServiceName ) + throw(uno::RuntimeException) +{ + return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() ); +} + +uno::Sequence< OUString > SAL_CALL SvxUnoTextRangeBase::getSupportedServiceNames() + throw(uno::RuntimeException) +{ + return getSupportedServiceNames_Static(); +} + +uno::Sequence< OUString > SAL_CALL SvxUnoTextRangeBase::getSupportedServiceNames_Static() + SAL_THROW(()) +{ + uno::Sequence< OUString > aSeq; + comphelper::ServiceInfoHelper::addToSequence( aSeq, 3, "com.sun.star.style.CharacterProperties", + "com.sun.star.style.CharacterPropertiesComplex", + "com.sun.star.style.CharacterPropertiesAsian"); + return aSeq; +} + +// XTextRangeCompare +sal_Int16 SAL_CALL SvxUnoTextRangeBase::compareRegionStarts( const uno::Reference< text::XTextRange >& xR1, const uno::Reference< text::XTextRange >& xR2 ) throw (lang::IllegalArgumentException, uno::RuntimeException) +{ + SvxUnoTextRangeBase* pR1 = SvxUnoTextRangeBase::getImplementation( xR1 ); + SvxUnoTextRangeBase* pR2 = SvxUnoTextRangeBase::getImplementation( xR2 ); + + if( (pR1 == 0) || (pR2 == 0) ) + throw lang::IllegalArgumentException(); + + const ESelection& r1 = pR1->maSelection; + const ESelection& r2 = pR2->maSelection; + + if( r1.nStartPara == r2.nStartPara ) + { + if( r1.nStartPos == r2.nStartPos ) + return 0; + else + return r1.nStartPos < r2.nStartPos ? 1 : -1; + } + else + { + return r1.nStartPara < r2.nStartPara ? 1 : -1; + } +} + +sal_Int16 SAL_CALL SvxUnoTextRangeBase::compareRegionEnds( const uno::Reference< text::XTextRange >& xR1, const uno::Reference< text::XTextRange >& xR2 ) throw (lang::IllegalArgumentException, uno::RuntimeException) +{ + SvxUnoTextRangeBase* pR1 = SvxUnoTextRangeBase::getImplementation( xR1 ); + SvxUnoTextRangeBase* pR2 = SvxUnoTextRangeBase::getImplementation( xR2 ); + + if( (pR1 == 0) || (pR2 == 0) ) + throw lang::IllegalArgumentException(); + + const ESelection& r1 = pR1->maSelection; + const ESelection& r2 = pR2->maSelection; + + if( r1.nEndPara == r2.nEndPara ) + { + if( r1.nEndPos == r2.nEndPos ) + return 0; + else + return r1.nEndPos < r2.nEndPos ? 1 : -1; + } + else + { + return r1.nEndPara < r2.nEndPara ? 1 : -1; + } +} + +// ==================================================================== +// class SvxUnoTextRange +// ==================================================================== + +uno::Sequence< uno::Type > SvxUnoTextRange::maTypeSequence; + +uno::Reference< uno::XInterface > SvxUnoTextRange_NewInstance() +{ + SvxUnoText aText; + uno::Reference< text::XTextRange > xRange( new SvxUnoTextRange( aText ) ); +#if (_MSC_VER < 1300) + return xRange; +#else + return (uno::Reference< uno::XInterface >)xRange; +#endif +} + +SvxUnoTextRange::SvxUnoTextRange( const SvxUnoTextBase& rParent, sal_Bool bPortion /* = sal_False */ ) throw() +:SvxUnoTextRangeBase( rParent.GetEditSource(), bPortion ? ImplGetSvxTextPortionSvxPropertySet() : rParent.getPropertySet() ), + mbPortion( bPortion ) +{ + xParentText = (text::XText*)&rParent; +} + +SvxUnoTextRange::~SvxUnoTextRange() throw() +{ +} + +uno::Any SAL_CALL SvxUnoTextRange::queryAggregation( const uno::Type & rType ) + throw(uno::RuntimeException) +{ + QUERYINT( text::XTextRange ); + else if( rType == ::getCppuType((const uno::Reference< beans::XMultiPropertyStates >*)0) ) + return uno::makeAny(uno::Reference< beans::XMultiPropertyStates >(this)); + else if( rType == ::getCppuType((const uno::Reference< beans::XPropertySet >*)0) ) + return uno::makeAny(uno::Reference< beans::XPropertySet >(this)); + else QUERYINT( beans::XPropertyState ); + else QUERYINT( text::XTextRangeCompare ); + else if( rType == ::getCppuType((const uno::Reference< beans::XMultiPropertySet >*)0) ) + return uno::makeAny(uno::Reference< beans::XMultiPropertySet >(this)); + else QUERYINT( lang::XServiceInfo ); + else QUERYINT( lang::XTypeProvider ); + else QUERYINT( lang::XUnoTunnel ); + else + return OWeakAggObject::queryAggregation( rType ); +} + +uno::Any SAL_CALL SvxUnoTextRange::queryInterface( const uno::Type & rType ) + throw(uno::RuntimeException) +{ + return OWeakAggObject::queryInterface(rType); +} + +void SAL_CALL SvxUnoTextRange::acquire() + throw( ) +{ + OWeakAggObject::acquire(); +} + +void SAL_CALL SvxUnoTextRange::release() + throw( ) +{ + OWeakAggObject::release(); +} + +// XTypeProvider + +uno::Sequence< uno::Type > SAL_CALL SvxUnoTextRange::getTypes() + throw (uno::RuntimeException) +{ + if( maTypeSequence.getLength() == 0 ) + { + maTypeSequence.realloc( 9 ); // !DANGER! keep this updated + uno::Type* pTypes = maTypeSequence.getArray(); + + *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextRange >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< beans::XPropertySet >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< beans::XMultiPropertySet >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< beans::XMultiPropertyStates >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< beans::XPropertyState >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< lang::XServiceInfo >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< lang::XTypeProvider >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< lang::XUnoTunnel >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextRangeCompare >*)0); + } + return maTypeSequence; +} + +uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextRange::getImplementationId() + throw (uno::RuntimeException) +{ + static uno::Sequence< sal_Int8 > aId; + if( aId.getLength() == 0 ) + { + aId.realloc( 16 ); + rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); + } + return aId; +} + +// XTextRange +uno::Reference< text::XText > SAL_CALL SvxUnoTextRange::getText() + throw(uno::RuntimeException) +{ + return xParentText; +} + +// lang::XServiceInfo +OUString SAL_CALL SvxUnoTextRange::getImplementationName() + throw(uno::RuntimeException) +{ + return OUString(RTL_CONSTASCII_USTRINGPARAM("SvxUnoTextRange")); +} + +// ==================================================================== +// class SvxUnoText +// ==================================================================== + +// UNO3_GETIMPLEMENTATION2_IMPL( SvxUnoText, SvxUnoTextRangeBase ); + +uno::Sequence< uno::Type > SvxUnoTextBase::maTypeSequence; + +SvxUnoTextBase::SvxUnoTextBase() throw() +: SvxUnoTextRangeBase( NULL ) +{ + +} + +SvxUnoTextBase::SvxUnoTextBase( const SvxItemPropertySet* _pSet ) throw() +: SvxUnoTextRangeBase( _pSet ) +{ +} + +SvxUnoTextBase::SvxUnoTextBase( const SvxEditSource* pSource, const SvxItemPropertySet* _pSet ) throw() +: SvxUnoTextRangeBase( pSource, _pSet ) +{ + ESelection aSelection; + ::GetSelection( aSelection, GetEditSource()->GetTextForwarder() ); + SetSelection( aSelection ); +} + +SvxUnoTextBase::SvxUnoTextBase( const SvxEditSource* pSource, const SvxItemPropertySet* _pSet, uno::Reference < text::XText > xParent ) throw() +: SvxUnoTextRangeBase( pSource, _pSet ) +{ + xParentText = xParent; + ESelection aSelection; + ::GetSelection( aSelection, GetEditSource()->GetTextForwarder() ); + SetSelection( aSelection ); +} + +SvxUnoTextBase::SvxUnoTextBase( const SvxUnoTextBase& rText ) throw() +: SvxUnoTextRangeBase( rText ) +, text::XTextAppend() +, text::XTextCopy() +, container::XEnumerationAccess() +, text::XTextRangeMover() +, lang::XTypeProvider() +{ + xParentText = rText.xParentText; +} + +SvxUnoTextBase::~SvxUnoTextBase() throw() +{ +} + +// Internal +ESelection SvxUnoTextBase::InsertField( const SvxFieldItem& rField ) throw() +{ + SvxTextForwarder* pForwarder = GetEditSource() ? GetEditSource()->GetTextForwarder() : NULL; + if( pForwarder ) + { + pForwarder->QuickInsertField( rField, GetSelection() ); + GetEditSource()->UpdateData(); + + // Selektion anpassen + //! Wenn die EditEngine bei QuickInsertText die Selektion zurueckgeben wuerde, + //! waer's einfacher... + + CollapseToStart(); + GoRight( 1, sal_True ); // Feld ist immer 1 Zeichen + } + + return GetSelection(); // Selektion mit dem Feld +} + +// XInterface +uno::Any SAL_CALL SvxUnoTextBase::queryAggregation( const uno::Type & rType ) + throw(uno::RuntimeException) +{ + QUERYINT( text::XText ); + QUERYINT( text::XSimpleText ); + if( rType == ::getCppuType((const uno::Reference< text::XTextRange >*)0) ) + return uno::makeAny(uno::Reference< text::XTextRange >((text::XText*)(this))); + QUERYINT(container::XEnumerationAccess ); + QUERYINT( container::XElementAccess ); + QUERYINT( beans::XMultiPropertyStates ); + QUERYINT( beans::XPropertySet ); + QUERYINT( beans::XMultiPropertySet ); + QUERYINT( beans::XPropertyState ); + QUERYINT( text::XTextRangeCompare ); + QUERYINT( lang::XServiceInfo ); + QUERYINT( text::XTextRangeMover ); + QUERYINT( text::XTextCopy ); + QUERYINT( text::XTextAppend ); + QUERYINT( text::XParagraphAppend ); + QUERYINT( text::XTextPortionAppend ); + QUERYINT( lang::XTypeProvider ); + QUERYINT( lang::XUnoTunnel ); + + return uno::Any(); +} + +// XTypeProvider + +uno::Sequence< uno::Type > SAL_CALL SvxUnoTextBase::getStaticTypes() throw() +{ + if( maTypeSequence.getLength() == 0 ) + { + maTypeSequence.realloc( 15 ); // !DANGER! keep this updated + uno::Type* pTypes = maTypeSequence.getArray(); + + *pTypes++ = ::getCppuType(( const uno::Reference< text::XText >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< container::XEnumerationAccess >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< beans::XPropertySet >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< beans::XMultiPropertySet >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< beans::XMultiPropertyStates >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< beans::XPropertyState >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextRangeMover >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextAppend >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextCopy >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< text::XParagraphAppend >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextPortionAppend >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< lang::XServiceInfo >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< lang::XTypeProvider >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< lang::XUnoTunnel >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextRangeCompare >*)0); + } + return maTypeSequence; +} + +uno::Sequence< uno::Type > SAL_CALL SvxUnoTextBase::getTypes() + throw (uno::RuntimeException) +{ + return getStaticTypes(); +} + +uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextBase::getImplementationId() + throw (uno::RuntimeException) +{ + static uno::Sequence< sal_Int8 > aId; + if( aId.getLength() == 0 ) + { + aId.realloc( 16 ); + rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); + } + return aId; +} + +uno::Reference< text::XTextCursor > SvxUnoTextBase::createTextCursorBySelection( const ESelection& rSel ) +{ + SvxUnoTextCursor* pCursor = new SvxUnoTextCursor( *this ); + uno::Reference< text::XTextCursor > xCursor( pCursor ); + pCursor->SetSelection( rSel ); + return xCursor; +} + +// XSimpleText + +uno::Reference< text::XTextCursor > SAL_CALL SvxUnoTextBase::createTextCursor() + throw(uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + return new SvxUnoTextCursor( *this ); +} + +uno::Reference< text::XTextCursor > SAL_CALL SvxUnoTextBase::createTextCursorByRange( const uno::Reference< text::XTextRange >& aTextPosition ) + throw(uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + uno::Reference< text::XTextCursor > xCursor; + + if( aTextPosition.is() ) + { + SvxUnoTextRangeBase* pRange = SvxUnoTextRangeBase::getImplementation( aTextPosition ); + if(pRange) + xCursor = createTextCursorBySelection( pRange->GetSelection() ); + } + + return xCursor; +} + +void SAL_CALL SvxUnoTextBase::insertString( const uno::Reference< text::XTextRange >& xRange, const OUString& aString, sal_Bool bAbsorb ) + throw(uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + if( !xRange.is() ) + return; + + ESelection aSelection; + ::GetSelection( aSelection, GetEditSource()->GetTextForwarder() ); + SetSelection( aSelection ); + + SvxUnoTextRangeBase* pRange = SvxUnoTextRange::getImplementation( xRange ); + if(pRange) + { + // setString am SvxUnoTextRangeBase statt selber QuickInsertText und UpdateData, + // damit die Selektion am SvxUnoTextRangeBase angepasst wird. + //! Eigentlich muessten alle Cursor-Objekte dieses Textes angepasst werden! + + if (!bAbsorb) // nicht ersetzen -> hinten anhaengen + pRange->CollapseToEnd(); + + pRange->setString( aString ); + + pRange->CollapseToEnd(); + } +} + +void SAL_CALL SvxUnoTextBase::insertControlCharacter( const uno::Reference< text::XTextRange >& xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + SvxTextForwarder* pForwarder = GetEditSource() ? GetEditSource()->GetTextForwarder() : NULL; + + if( pForwarder ) + { + ESelection aSelection; + ::GetSelection( aSelection, pForwarder ); + SetSelection( aSelection ); + + switch( nControlCharacter ) + { + case text::ControlCharacter::PARAGRAPH_BREAK: + { + const String aText( (sal_Unicode)13 ); // '\r' geht auf'm Mac nicht + insertString( xRange, aText, bAbsorb ); + + return; + } + case text::ControlCharacter::LINE_BREAK: + { + SvxUnoTextRangeBase* pRange = SvxUnoTextRange::getImplementation( xRange ); + if(pRange) + { + ESelection aRange = pRange->GetSelection(); + + if( bAbsorb ) + { + const String aEmpty; + pForwarder->QuickInsertText( aEmpty, aRange ); + + aRange.nEndPos = aRange.nStartPos; + aRange.nEndPara = aRange.nStartPara; + } + else + { + aRange.nStartPos = aRange.nEndPos; + aRange.nStartPara = aRange.nStartPara; + } + + pForwarder->QuickInsertLineBreak( aRange ); + GetEditSource()->UpdateData(); + + aRange.nEndPos += 1; + if( !bAbsorb ) + aRange.nStartPos += 1; + + pRange->SetSelection( aRange ); + } + return; + } + case text::ControlCharacter::APPEND_PARAGRAPH: + { + SvxUnoTextRangeBase* pRange = SvxUnoTextRange::getImplementation( xRange ); + if(pRange) + { + ESelection aRange = pRange->GetSelection(); +// ESelection aOldSelection = aRange; + + aRange.nStartPos = pForwarder->GetTextLen( aRange.nStartPara ); + + aRange.nEndPara = aRange.nStartPara; + aRange.nEndPos = aRange.nStartPos; + + pRange->SetSelection( aRange ); + const String aText( (sal_Unicode)13 ); // '\r' geht auf'm Mac nicht + pRange->setString( aText ); + + aRange.nStartPos = 0; + aRange.nStartPara += 1; + aRange.nEndPos = 0; + aRange.nEndPara += 1; + + pRange->SetSelection( aRange ); + + return; + } + } + } + } + + throw lang::IllegalArgumentException(); +} + +// XText +void SAL_CALL SvxUnoTextBase::insertTextContent( const uno::Reference< text::XTextRange >& xRange, const uno::Reference< text::XTextContent >& xContent, sal_Bool bAbsorb ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + SvxTextForwarder* pForwarder = GetEditSource() ? GetEditSource()->GetTextForwarder() : NULL; + if( pForwarder ) + { + + SvxUnoTextRangeBase* pRange = SvxUnoTextRange::getImplementation( xRange ); + SvxUnoTextField* pField = SvxUnoTextField::getImplementation( xContent ); + + if( pRange == NULL || pField == NULL ) + throw lang::IllegalArgumentException(); + + ESelection aSelection = pRange->GetSelection(); + if( !bAbsorb ) + { + aSelection.nStartPara = aSelection.nEndPara; + aSelection.nStartPos = aSelection.nEndPos; + } + + SvxFieldData* pFieldData = pField->CreateFieldData(); + if( pFieldData == NULL ) + throw lang::IllegalArgumentException(); + + SvxFieldItem aField( *pFieldData, EE_FEATURE_FIELD ); + pForwarder->QuickInsertField( aField, aSelection ); + GetEditSource()->UpdateData(); + + pField->SetAnchor( uno::Reference< text::XTextRange >::query( (cppu::OWeakObject*)this ) ); + + aSelection.nEndPos += 1; + aSelection.nStartPos = aSelection.nEndPos; + //maSelection = aSelection; //??? + pRange->SetSelection( aSelection ); + + delete pFieldData; + } +} + +void SAL_CALL SvxUnoTextBase::removeTextContent( const uno::Reference< text::XTextContent >& ) throw(container::NoSuchElementException, uno::RuntimeException) +{ +} + +// XTextRange + +uno::Reference< text::XText > SAL_CALL SvxUnoTextBase::getText() + throw(uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + if (GetEditSource()) + { + ESelection aSelection; + ::GetSelection( aSelection, GetEditSource()->GetTextForwarder() ); + ((SvxUnoTextBase*)this)->SetSelection( aSelection ); + } + + return (text::XText*)this; +} + +uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::getStart() + throw(uno::RuntimeException) +{ + return SvxUnoTextRangeBase::getStart(); +} + +uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::getEnd() + throw(uno::RuntimeException) +{ + return SvxUnoTextRangeBase::getEnd(); +} + +OUString SAL_CALL SvxUnoTextBase::getString() throw( uno::RuntimeException ) +{ + return SvxUnoTextRangeBase::getString(); +} + +void SAL_CALL SvxUnoTextBase::setString( const OUString& aString ) throw(uno::RuntimeException) +{ + SvxUnoTextRangeBase::setString(aString); +} + + +// XEnumerationAccess +uno::Reference< container::XEnumeration > SAL_CALL SvxUnoTextBase::createEnumeration() + throw(uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + ESelection aSelection; + ::GetSelection( aSelection, GetEditSource()->GetTextForwarder() ); + SetSelection( aSelection ); + + uno::Reference< container::XEnumeration > xEnum( (container::XEnumeration*) new SvxUnoTextContentEnumeration( *this ) ); + return xEnum; +} + +// XElementAccess ( container::XEnumerationAccess ) +uno::Type SAL_CALL SvxUnoTextBase::getElementType( ) throw(uno::RuntimeException) +{ + return ::getCppuType((const uno::Reference< text::XTextRange >*)0 ); +} + +sal_Bool SAL_CALL SvxUnoTextBase::hasElements( ) throw(uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + if(GetEditSource()) + { + SvxTextForwarder* pForwarder = GetEditSource()->GetTextForwarder(); + if(pForwarder) + return pForwarder->GetParagraphCount() != 0; + } + + return sal_False; +} + +// text::XTextRangeMover +void SAL_CALL SvxUnoTextBase::moveTextRange( const uno::Reference< text::XTextRange >&, sal_Int16 ) + throw(uno::RuntimeException) +{ +} + +void SvxPropertyValuesToItemSet( + SfxItemSet &rItemSet, + const uno::Sequence< beans::PropertyValue > rPropertyVaules, + const SfxItemPropertySet *pPropSet, + SvxTextForwarder *pForwarder /*needed for WID_NUMLEVEL*/, + sal_uInt16 nPara /*needed for WID_NUMLEVEL*/) + throw(lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException) +{ + sal_Int32 nProps = rPropertyVaules.getLength(); + const beans::PropertyValue *pProps = rPropertyVaules.getConstArray(); + for (sal_Int32 i = 0; i < nProps; ++i) + { + const SfxItemPropertySimpleEntry *pEntry = pPropSet->getPropertyMap()->getByName( pProps[i].Name ); + if (pEntry) + { + // Note: there is no need to take special care of the properties + // TextField (EE_FEATURE_FIELD) and + // TextPortionType (WID_PORTIONTYPE) + // since they are read-only and thus are already taken care of below. + + if (pEntry->nFlags & beans::PropertyAttribute::READONLY) + // should be PropertyVetoException which is not yet defined for the new import API's functions + throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + pProps[i].Name, static_cast < cppu::OWeakObject * > ( 0 ) ); + //throw PropertyVetoException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + pProps[i].Name, static_cast < cppu::OWeakObject * > ( 0 ) ); + + if (pEntry->nWID == WID_FONTDESC) + { + awt::FontDescriptor aDesc; + if (pProps[i].Value >>= aDesc) + SvxUnoFontDescriptor::FillItemSet( aDesc, rItemSet ); + } + else if (pEntry->nWID == WID_NUMLEVEL) + { + if (pForwarder) + { + sal_Int16 nLevel = -1; + pProps[i].Value >>= nLevel; + + // #101004# Call interface method instead of unsafe cast + if (!pForwarder->SetDepth( nPara, nLevel )) + throw lang::IllegalArgumentException(); + } + } + else if (pEntry->nWID == WID_NUMBERINGSTARTVALUE ) + { + if( pForwarder ) + { + sal_Int16 nStartValue = -1; + if( !(pProps[i].Value >>= nStartValue) ) + throw lang::IllegalArgumentException(); + + pForwarder->SetNumberingStartValue( nPara, nStartValue ); + } + } + else if (pEntry->nWID == WID_PARAISNUMBERINGRESTART ) + { + if( pForwarder ) + { + sal_Bool bParaIsNumberingRestart = sal_False; + if( !(pProps[i].Value >>= bParaIsNumberingRestart) ) + throw lang::IllegalArgumentException(); + + pForwarder->SetParaIsNumberingRestart( nPara, bParaIsNumberingRestart ); + } + } + else + pPropSet->setPropertyValue( pProps[i].Name, pProps[i].Value, rItemSet ); + } + else + throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + pProps[i].Name, static_cast < cppu::OWeakObject * > ( 0 ) ); + } +} + +// com::sun::star::text::XParagraphAppend (new import API) +uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::appendParagraph( + const uno::Sequence< beans::PropertyValue >& rCharAndParaProps ) + throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + uno::Reference< text::XTextRange > xRet; + SvxEditSource *pEditSource = GetEditSource(); + SvxTextForwarder *pTextForwarder = pEditSource ? pEditSource->GetTextForwarder() : 0; + if (pTextForwarder) + { + sal_uInt16 nParaCount = pTextForwarder->GetParagraphCount(); + DBG_ASSERT( nParaCount > 0, "paragraph count is 0 or negative" ); + pTextForwarder->AppendParagraph(); + + // set properties for new appended (now last) paragraph + ESelection aSel( nParaCount, 0, nParaCount, 0 ); + SfxItemSet aItemSet( *pTextForwarder->GetEmptyItemSetPtr() ); + SvxPropertyValuesToItemSet( aItemSet, rCharAndParaProps, + ImplGetSvxUnoOutlinerTextCursorSfxPropertySet(), + pTextForwarder, + nParaCount ); + pTextForwarder->QuickSetAttribs( aItemSet, aSel ); + pEditSource->UpdateData(); + SvxUnoTextRange* pRange = new SvxUnoTextRange( *this ); + xRet = pRange; + pRange->SetSelection( aSel ); + } + return xRet; +} + +uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::finishParagraph( + const uno::Sequence< beans::PropertyValue >& rCharAndParaProps ) + throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + uno::Reference< text::XTextRange > xRet; + SvxEditSource *pEditSource = GetEditSource(); + SvxTextForwarder *pTextForwarder = pEditSource ? pEditSource->GetTextForwarder() : 0; + if (pTextForwarder) + { + sal_uInt16 nParaCount = pTextForwarder->GetParagraphCount(); + DBG_ASSERT( nParaCount > 0, "paragraph count is 0 or negative" ); + pTextForwarder->AppendParagraph(); + + // set properties for the previously last paragraph + sal_uInt16 nPara = nParaCount - 1; + ESelection aSel( nPara, 0, nPara, 0 ); + SfxItemSet aItemSet( *pTextForwarder->GetEmptyItemSetPtr() ); + SvxPropertyValuesToItemSet( aItemSet, rCharAndParaProps, + ImplGetSvxUnoOutlinerTextCursorSfxPropertySet(), pTextForwarder, nPara ); + pTextForwarder->QuickSetAttribs( aItemSet, aSel ); + pEditSource->UpdateData(); + SvxUnoTextRange* pRange = new SvxUnoTextRange( *this ); + xRet = pRange; + pRange->SetSelection( aSel ); + } + return xRet; +} + +// com::sun::star::text::XTextPortionAppend (new import API) +uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::appendTextPortion( + const ::rtl::OUString& rText, + const uno::Sequence< beans::PropertyValue >& rCharAndParaProps ) + throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + SvxEditSource *pEditSource = GetEditSource(); + SvxTextForwarder *pTextForwarder = pEditSource ? pEditSource->GetTextForwarder() : 0; + uno::Reference< text::XTextRange > xRet; + if (pTextForwarder) + { + sal_uInt16 nParaCount = pTextForwarder->GetParagraphCount(); + DBG_ASSERT( nParaCount > 0, "paragraph count is 0 or negative" ); + sal_uInt16 nPara = nParaCount - 1; + SfxItemSet aSet( pTextForwarder->GetParaAttribs( nPara ) ); + xub_StrLen nStart = pTextForwarder->AppendTextPortion( nPara, rText, aSet ); + pEditSource->UpdateData(); + xub_StrLen nEnd = pTextForwarder->GetTextLen( nPara ); + + // set properties for the new text portion + ESelection aSel( nPara, nStart, nPara, nEnd ); + pTextForwarder->RemoveAttribs( aSel, sal_False, 0 ); + pEditSource->UpdateData(); + + SfxItemSet aItemSet( *pTextForwarder->GetEmptyItemSetPtr() ); + SvxPropertyValuesToItemSet( aItemSet, rCharAndParaProps, + ImplGetSvxTextPortionSfxPropertySet(), pTextForwarder, nPara ); + pTextForwarder->QuickSetAttribs( aItemSet, aSel ); + SvxUnoTextRange* pRange = new SvxUnoTextRange( *this ); + xRet = pRange; + pRange->SetSelection( aSel ); + const beans::PropertyValue* pProps = rCharAndParaProps.getConstArray(); + for( sal_Int32 nProp = 0; nProp < rCharAndParaProps.getLength(); ++nProp ) + pRange->setPropertyValue( pProps[nProp].Name, pProps[nProp].Value ); + } + return xRet; +} +/*-- 25.03.2008 08:16:09--------------------------------------------------- + + -----------------------------------------------------------------------*/ +void SvxUnoTextBase::copyText( + const uno::Reference< text::XTextCopy >& xSource ) throw ( uno::RuntimeException ) +{ + OGuard aGuard( Application::GetSolarMutex() ); + uno::Reference< lang::XUnoTunnel > xUT( xSource, uno::UNO_QUERY ); + SvxEditSource *pEditSource = GetEditSource(); + SvxTextForwarder *pTextForwarder = pEditSource ? pEditSource->GetTextForwarder() : 0; + if( !pTextForwarder ) + return; + if( xUT.is() ) + { + SvxUnoTextBase* pSource = reinterpret_cast<SvxUnoTextBase*>(sal::static_int_cast<sal_uIntPtr>( + xUT->getSomething( SvxUnoTextBase::getUnoTunnelId()))); + SvxEditSource *pSourceEditSource = pSource->GetEditSource(); + SvxTextForwarder *pSourceTextForwarder = pSourceEditSource ? pSourceEditSource->GetTextForwarder() : 0; + if( pSourceTextForwarder ) + { + pTextForwarder->CopyText( *pSourceTextForwarder ); + pEditSource->UpdateData(); + } + } + else + { + uno::Reference< text::XText > xSourceText( xSource, uno::UNO_QUERY ); + if( xSourceText.is() ) + { + setString( xSourceText->getString() ); + } + } +} + +// lang::XServiceInfo +OUString SAL_CALL SvxUnoTextBase::getImplementationName() + throw(uno::RuntimeException) +{ + return OUString(RTL_CONSTASCII_USTRINGPARAM("SvxUnoTextBase")); +} + +uno::Sequence< OUString > SAL_CALL SvxUnoTextBase::getSupportedServiceNames( ) + throw(uno::RuntimeException) +{ + return getSupportedServiceNames_Static(); +} + +uno::Sequence< OUString > SAL_CALL SvxUnoTextBase::getSupportedServiceNames_Static( ) + SAL_THROW(()) +{ + uno::Sequence< OUString > aSeq( SvxUnoTextRangeBase::getSupportedServiceNames_Static() ); + comphelper::ServiceInfoHelper::addToSequence( aSeq, 1, "com.sun.star.text.Text" ); + return aSeq; +} + +const uno::Sequence< sal_Int8 > & SvxUnoTextBase::getUnoTunnelId() throw() +{ + static uno::Sequence< sal_Int8 > * pSeq = 0; + if( !pSeq ) + { + ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !pSeq ) + { + static uno::Sequence< sal_Int8 > aSeq( 16 ); + rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); + pSeq = &aSeq; + } + } + return *pSeq; +} + +SvxUnoTextBase* SvxUnoTextBase::getImplementation( const uno::Reference< uno::XInterface >& xInt ) +{ + uno::Reference< lang::XUnoTunnel > xUT( xInt, uno::UNO_QUERY ); + if( xUT.is() ) + return reinterpret_cast<SvxUnoTextBase*>(sal::static_int_cast<sal_uIntPtr>(xUT->getSomething( SvxUnoTextBase::getUnoTunnelId()))); + else + return NULL; +} + +sal_Int64 SAL_CALL SvxUnoTextBase::getSomething( const uno::Sequence< sal_Int8 >& rId ) throw(uno::RuntimeException) \ +{ + if( rId.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), + rId.getConstArray(), 16 ) ) + { + return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this)); + } + else + { + return SvxUnoTextRangeBase::getSomething( rId ); + } +} + +// -------------------------------------------------------------------- + +SvxUnoText::SvxUnoText( ) throw() +{ +} + +SvxUnoText::SvxUnoText( const SvxItemPropertySet* _pSet ) throw() +: SvxUnoTextBase( _pSet ) +{ +} + +SvxUnoText::SvxUnoText( const SvxEditSource* pSource, const SvxItemPropertySet* _pSet, uno::Reference < text::XText > xParent ) throw() +: SvxUnoTextBase( pSource, _pSet, xParent ) +{ +} + +SvxUnoText::SvxUnoText( const SvxUnoText& rText ) throw() +: SvxUnoTextBase( rText ) +, cppu::OWeakAggObject() +{ +} + +SvxUnoText::~SvxUnoText() throw() +{ +} + +uno::Sequence< uno::Type > SAL_CALL getStaticTypes() throw() +{ + return SvxUnoTextBase::getStaticTypes(); +} + +// uno::XInterface +uno::Any SAL_CALL SvxUnoText::queryAggregation( const uno::Type & rType ) throw( uno::RuntimeException ) +{ + uno::Any aAny( SvxUnoTextBase::queryAggregation( rType ) ); + if( !aAny.hasValue() ) + aAny = OWeakAggObject::queryAggregation( rType ); + + return aAny; +} + +uno::Any SAL_CALL SvxUnoText::queryInterface( const uno::Type & rType ) throw( uno::RuntimeException ) +{ + return OWeakAggObject::queryInterface( rType ); +} + +void SAL_CALL SvxUnoText::acquire() throw( ) +{ + OWeakAggObject::acquire(); +} + +void SAL_CALL SvxUnoText::release() throw( ) +{ + OWeakAggObject::release(); +} + +// lang::XTypeProvider +uno::Sequence< uno::Type > SAL_CALL SvxUnoText::getTypes( ) throw( uno::RuntimeException ) +{ + return SvxUnoTextBase::getTypes(); +} + +uno::Sequence< sal_Int8 > SAL_CALL SvxUnoText::getImplementationId( ) throw( uno::RuntimeException ) +{ + static uno::Sequence< sal_Int8 > aId; + if( aId.getLength() == 0 ) + { + aId.realloc( 16 ); + rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); + } + return aId; +} + +SvxUnoText* SvxUnoText::getImplementation( const uno::Reference< uno::XInterface >& xInt ) +{ + uno::Reference< lang::XUnoTunnel > xUT( xInt, uno::UNO_QUERY ); + if( xUT.is() ) + return reinterpret_cast<SvxUnoText*>(sal::static_int_cast<sal_uIntPtr>(xUT->getSomething( SvxUnoText::getUnoTunnelId()))); + else + return NULL; +} + +const uno::Sequence< sal_Int8 > & SvxUnoText::getUnoTunnelId() throw() +{ + static uno::Sequence< sal_Int8 > * pSeq = 0; + if( !pSeq ) + { + ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !pSeq ) + { + static uno::Sequence< sal_Int8 > aSeq( 16 ); + rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); + pSeq = &aSeq; + } + } + return *pSeq; +} + +sal_Int64 SAL_CALL SvxUnoText::getSomething( const uno::Sequence< sal_Int8 >& rId ) throw(uno::RuntimeException) \ +{ + if( rId.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), + rId.getConstArray(), 16 ) ) + { + return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this)); + } + else + { + return SvxUnoTextBase::getSomething( rId ); + } +} + + +// -------------------------------------------------------------------- + +SvxDummyTextSource::~SvxDummyTextSource() +{ +}; + +SvxEditSource* SvxDummyTextSource::Clone() const +{ + return new SvxDummyTextSource(); +} + +SvxTextForwarder* SvxDummyTextSource::GetTextForwarder() +{ + return this; +} + +void SvxDummyTextSource::UpdateData() +{ +} + +sal_uInt16 SvxDummyTextSource::GetParagraphCount() const +{ + return 0; +} + +sal_uInt16 SvxDummyTextSource::GetTextLen( sal_uInt16 ) const +{ + return 0; +} + +String SvxDummyTextSource::GetText( const ESelection& ) const +{ + return String(); +} + +SfxItemSet SvxDummyTextSource::GetAttribs( const ESelection&, sal_Bool ) const +{ + // AW: Very dangerous: The former implementation used a SfxItemPool created on the + // fly which of course was deleted again ASAP. Thus, the returned SfxItemSet was using + // a deleted Pool by design. + return SfxItemSet(EditEngine::GetGlobalItemPool()); +} + +SfxItemSet SvxDummyTextSource::GetParaAttribs( sal_uInt16 ) const +{ + return GetAttribs(ESelection()); +} + +void SvxDummyTextSource::SetParaAttribs( sal_uInt16, const SfxItemSet& ) +{ +} + +void SvxDummyTextSource::RemoveAttribs( const ESelection& , sal_Bool , sal_uInt16 ) +{ +} + +void SvxDummyTextSource::GetPortions( sal_uInt16, SvUShorts& ) const +{ +} + +sal_uInt16 SvxDummyTextSource::GetItemState( const ESelection&, sal_uInt16 ) const +{ + return 0; +} + +sal_uInt16 SvxDummyTextSource::GetItemState( sal_uInt16, sal_uInt16 ) const +{ + return 0; +} + +SfxItemPool* SvxDummyTextSource::GetPool() const +{ + return NULL; +} + +void SvxDummyTextSource::QuickInsertText( const String&, const ESelection& ) +{ +} + +void SvxDummyTextSource::QuickInsertField( const SvxFieldItem&, const ESelection& ) +{ +} + +void SvxDummyTextSource::QuickSetAttribs( const SfxItemSet&, const ESelection& ) +{ +} + +void SvxDummyTextSource::QuickInsertLineBreak( const ESelection& ) +{ +}; + +XubString SvxDummyTextSource::CalcFieldValue( const SvxFieldItem&, sal_uInt16, sal_uInt16, Color*&, Color*& ) +{ + return XubString(); +} + +void SvxDummyTextSource::FieldClicked( const SvxFieldItem&, sal_uInt16, xub_StrLen ) +{ +} + +sal_Bool SvxDummyTextSource::IsValid() const +{ + return sal_False; +} + +void SvxDummyTextSource::SetNotifyHdl( const Link& ) +{ +} + +LanguageType SvxDummyTextSource::GetLanguage( sal_uInt16, sal_uInt16 ) const +{ + return LANGUAGE_DONTKNOW; +} + +sal_uInt16 SvxDummyTextSource::GetFieldCount( sal_uInt16 ) const +{ + return 0; +} + +EFieldInfo SvxDummyTextSource::GetFieldInfo( sal_uInt16, sal_uInt16 ) const +{ + return EFieldInfo(); +} + +EBulletInfo SvxDummyTextSource::GetBulletInfo( sal_uInt16 ) const +{ + return EBulletInfo(); +} + +Rectangle SvxDummyTextSource::GetCharBounds( sal_uInt16, sal_uInt16 ) const +{ + return Rectangle(); +} + +Rectangle SvxDummyTextSource::GetParaBounds( sal_uInt16 ) const +{ + return Rectangle(); +} + +MapMode SvxDummyTextSource::GetMapMode() const +{ + return MapMode(); +} + +OutputDevice* SvxDummyTextSource::GetRefDevice() const +{ + return NULL; +} + +sal_Bool SvxDummyTextSource::GetIndexAtPoint( const Point&, sal_uInt16&, sal_uInt16& ) const +{ + return sal_False; +} + +sal_Bool SvxDummyTextSource::GetWordIndices( sal_uInt16, sal_uInt16, sal_uInt16&, sal_uInt16& ) const +{ + return sal_False; +} + +sal_Bool SvxDummyTextSource::GetAttributeRun( sal_uInt16&, sal_uInt16&, sal_uInt16, sal_uInt16 ) const +{ + return sal_False; +} + +sal_uInt16 SvxDummyTextSource::GetLineCount( sal_uInt16 ) const +{ + return 0; +} + +sal_uInt16 SvxDummyTextSource::GetLineLen( sal_uInt16, sal_uInt16 ) const +{ + return 0; +} + +void SvxDummyTextSource::GetLineBoundaries( /*out*/sal_uInt16 &rStart, /*out*/sal_uInt16 &rEnd, sal_uInt16 /*nParagraph*/, sal_uInt16 /*nLine*/ ) const +{ + rStart = rEnd = 0; +} + +sal_uInt16 SvxDummyTextSource::GetLineNumberAtIndex( sal_uInt16 /*nPara*/, sal_uInt16 /*nIndex*/ ) const +{ + return 0; +} + +sal_Bool SvxDummyTextSource::QuickFormatDoc( sal_Bool ) +{ + return sal_False; +} + +sal_Int16 SvxDummyTextSource::GetDepth( sal_uInt16 ) const +{ + return -1; +} + +sal_Bool SvxDummyTextSource::SetDepth( sal_uInt16, sal_Int16 nNewDepth ) +{ + return nNewDepth == 0 ? sal_True : sal_False; +} + +sal_Bool SvxDummyTextSource::Delete( const ESelection& ) +{ + return sal_False; +} + +sal_Bool SvxDummyTextSource::InsertText( const String&, const ESelection& ) +{ + return sal_False; +} + +const SfxItemSet * SvxDummyTextSource::GetEmptyItemSetPtr() +{ + return 0; +} + +void SvxDummyTextSource::AppendParagraph() +{ +} + +xub_StrLen SvxDummyTextSource::AppendTextPortion( sal_uInt16, const String &, const SfxItemSet & ) +{ + return 0; +} + +void SvxDummyTextSource::CopyText(const SvxTextForwarder& ) +{ +} + diff --git a/editeng/source/uno/unotext2.cxx b/editeng/source/uno/unotext2.cxx new file mode 100644 index 000000000000..97895848b798 --- /dev/null +++ b/editeng/source/uno/unotext2.cxx @@ -0,0 +1,711 @@ +/************************************************************************* + * + * 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_editeng.hxx" +#include <vcl/svapp.hxx> +#include <vos/mutex.hxx> + +#define _SVSTDARR_sal_uIt16S +#include <svl/svstdarr.hxx> + +#include <rtl/uuid.h> +#include <rtl/memory.h> + +#include <editeng/eeitem.hxx> +#include <editeng/flditem.hxx> +#include <editeng/unofield.hxx> +#include <editeng/unotext.hxx> +#include <comphelper/serviceinfohelper.hxx> + +using namespace ::rtl; +using namespace ::vos; +using namespace ::cppu; +using namespace ::com::sun::star; + +#define QUERYINT( xint ) \ + if( rType == ::getCppuType((const uno::Reference< xint >*)0) ) \ + return uno::makeAny(uno::Reference< xint >(this)) + +// ==================================================================== +// SvxUnoTextContentEnumeration +// ==================================================================== + +SvxUnoTextContentEnumeration::SvxUnoTextContentEnumeration( const SvxUnoTextBase& _rText ) throw() +: mrText( _rText ) +{ + mxParentText = const_cast<SvxUnoTextBase*>(&_rText); + if( mrText.GetEditSource() ) + mpEditSource = mrText.GetEditSource()->Clone(); + else + mpEditSource = NULL; + mnNextParagraph = 0; +} + +SvxUnoTextContentEnumeration::~SvxUnoTextContentEnumeration() throw() +{ + delete mpEditSource; +} + +// container::XEnumeration +sal_Bool SAL_CALL SvxUnoTextContentEnumeration::hasMoreElements(void) + throw( uno::RuntimeException ) +{ + OGuard aGuard( Application::GetSolarMutex() ); + if( mpEditSource && mpEditSource->GetTextForwarder() ) + return mnNextParagraph < mpEditSource->GetTextForwarder()->GetParagraphCount(); + else + return sal_False; +} + +uno::Any SvxUnoTextContentEnumeration::nextElement(void) throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException ) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + if(!hasMoreElements()) + throw container::NoSuchElementException(); + + SvxUnoTextContent* pContent = 0; + + const SvxUnoTextRangeBaseList& rRanges( mpEditSource->getRanges() ); + SvxUnoTextRangeBaseList::const_iterator aIter; + for( aIter = rRanges.begin(); (aIter != rRanges.end()) && (pContent == 0); aIter++ ) + { + SvxUnoTextContent* pIterContent = dynamic_cast< SvxUnoTextContent* >( (*aIter ) ); + if( pIterContent && (pIterContent->mnParagraph == mnNextParagraph) ) + pContent = pIterContent; + } + + if( pContent == 0 ) + pContent = new SvxUnoTextContent( mrText, mnNextParagraph ); + + mnNextParagraph++; + + uno::Reference< text::XTextContent > xRef( pContent ); + return uno::makeAny( xRef ); +} + +// ==================================================================== +// class SvxUnoTextContent +// ==================================================================== +uno::Reference< text::XText > xDummyText; +uno::Sequence< uno::Type > SvxUnoTextContent::maTypeSequence; + +static SvxUnoText* getDummyText() throw() +{ + if(!xDummyText.is()) + xDummyText = new SvxUnoText(); + + return SvxUnoText::getImplementation( xDummyText ); +} + +SvxUnoTextContent::SvxUnoTextContent() throw() +: SvxUnoTextRangeBase(*getDummyText()) +, mnParagraph(0) +, mrParentText(*getDummyText()) +, maDisposeListeners(maDisposeContainerMutex) +, mbDisposing( false ) +{ +} + +SvxUnoTextContent::SvxUnoTextContent( const SvxUnoTextBase& rText, sal_uInt16 nPara ) throw() +: SvxUnoTextRangeBase(rText) +, mnParagraph(nPara) +, mrParentText(rText) +, maDisposeListeners(maDisposeContainerMutex) +, mbDisposing( false ) +{ + mxParentText = const_cast<SvxUnoTextBase*>(&rText); + if( GetEditSource() && GetEditSource()->GetTextForwarder() ) + SetSelection( ESelection( mnParagraph,0, mnParagraph, GetEditSource()->GetTextForwarder()->GetTextLen( mnParagraph ) ) ); +} + +SvxUnoTextContent::SvxUnoTextContent( const SvxUnoTextContent& rContent ) throw() +: SvxUnoTextRangeBase(rContent) +, text::XTextContent() +, container::XEnumerationAccess() +, lang::XTypeProvider() +, cppu::OWeakAggObject() +, mrParentText(rContent.mrParentText) +, maDisposeListeners(maDisposeContainerMutex) +, mbDisposing( false ) +{ + mxParentText = rContent.mxParentText; + mnParagraph = rContent.mnParagraph; + SetSelection( rContent.GetSelection() ); +} + +SvxUnoTextContent::~SvxUnoTextContent() throw() +{ +} + +// uno::XInterface +uno::Any SAL_CALL SvxUnoTextContent::queryAggregation( const uno::Type & rType ) throw( uno::RuntimeException ) +{ + QUERYINT( text::XTextRange ); + else QUERYINT( beans::XMultiPropertyStates ); + else QUERYINT( beans::XPropertySet ); + else QUERYINT( beans::XMultiPropertySet ); + else QUERYINT( beans::XPropertyState ); + else QUERYINT( text::XTextContent ); + else QUERYINT( text::XTextRangeCompare ); + else QUERYINT( lang::XComponent ); + else QUERYINT( container::XEnumerationAccess ); + else QUERYINT( container::XElementAccess ); + else QUERYINT( lang::XServiceInfo ); + else QUERYINT( lang::XTypeProvider ); + else QUERYINT( lang::XUnoTunnel ); + else + return OWeakAggObject::queryAggregation( rType ); +} + +uno::Any SAL_CALL SvxUnoTextContent::queryInterface( const uno::Type & rType ) throw( uno::RuntimeException ) +{ + return OWeakAggObject::queryInterface(rType); +} + +void SAL_CALL SvxUnoTextContent::acquire() throw( ) +{ + OWeakAggObject::acquire(); +} + +void SAL_CALL SvxUnoTextContent::release() throw( ) +{ + OWeakAggObject::release(); +} + +// XTypeProvider + +uno::Sequence< uno::Type > SAL_CALL SvxUnoTextContent::getTypes() + throw (uno::RuntimeException) +{ + if( maTypeSequence.getLength() == 0 ) + { + maTypeSequence.realloc( 11 ); // !DANGER! keep this updated + uno::Type* pTypes = maTypeSequence.getArray(); + + *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextRange >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< beans::XPropertySet >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< beans::XMultiPropertySet >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< beans::XMultiPropertyStates >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< beans::XPropertyState >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextRangeCompare >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextContent >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< container::XEnumerationAccess >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< lang::XServiceInfo >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< lang::XTypeProvider >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< lang::XUnoTunnel >*)0); + } + return maTypeSequence; +} + +uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextContent::getImplementationId() + throw (uno::RuntimeException) +{ + static uno::Sequence< sal_Int8 > aId; + if( aId.getLength() == 0 ) + { + aId.realloc( 16 ); + rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); + } + return aId; +} + +// text::XTextRange + +uno::Reference< text::XText > SAL_CALL SvxUnoTextContent::getText() + throw(uno::RuntimeException) +{ + return mxParentText; +} + +// text::XTextContent +void SAL_CALL SvxUnoTextContent::attach( const uno::Reference< text::XTextRange >& ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ +} + +uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextContent::getAnchor() throw( uno::RuntimeException ) +{ + return uno::Reference< text::XTextRange >::query( mxParentText ); +} + +// XComponent + +void SAL_CALL SvxUnoTextContent::dispose() + throw(uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + if( mbDisposing ) + return; // catched a recursion + + mbDisposing = true; + + lang::EventObject aEvt; + aEvt.Source = *(OWeakAggObject*) this; + maDisposeListeners.disposeAndClear(aEvt); + + if( mxParentText.is() ) + mxParentText->removeTextContent( this ); +} + +void SAL_CALL SvxUnoTextContent::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) + throw(uno::RuntimeException) +{ + maDisposeListeners.addInterface(xListener); +} + +void SAL_CALL SvxUnoTextContent::removeEventListener( const uno::Reference< lang::XEventListener >& aListener ) + throw(uno::RuntimeException) +{ + maDisposeListeners.removeInterface(aListener); +} + +// XEnumerationAccess + +uno::Reference< container::XEnumeration > SAL_CALL SvxUnoTextContent::createEnumeration( ) + throw(uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + return new SvxUnoTextRangeEnumeration( mrParentText, mnParagraph ); +} + +// XElementAccess ( container::XEnumerationAccess ) + +uno::Type SAL_CALL SvxUnoTextContent::getElementType() + throw(uno::RuntimeException) +{ + return ::getCppuType((const uno::Reference< text::XTextRange >*)0); +} + +sal_Bool SAL_CALL SvxUnoTextContent::hasElements() + throw(uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + SvxTextForwarder* pForwarder = GetEditSource() ? GetEditSource()->GetTextForwarder() : NULL; + if( pForwarder ) + { + SvUShorts aPortions; + pForwarder->GetPortions( mnParagraph, aPortions ); + return aPortions.Count() > 0; + } + else + { + return 0; + } +} + +// XPropertySet + +void SAL_CALL SvxUnoTextContent::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException) +{ + _setPropertyValue( aPropertyName, aValue, mnParagraph ); +} + +uno::Any SAL_CALL SvxUnoTextContent::getPropertyValue( const OUString& PropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) +{ + return _getPropertyValue( PropertyName, mnParagraph ); +} + +// XMultiPropertySet +void SAL_CALL SvxUnoTextContent::setPropertyValues( const uno::Sequence< ::rtl::OUString >& aPropertyNames, const uno::Sequence< uno::Any >& aValues ) throw (beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException) +{ + _setPropertyValues( aPropertyNames, aValues, mnParagraph ); +} + +uno::Sequence< uno::Any > SAL_CALL SvxUnoTextContent::getPropertyValues( const uno::Sequence< ::rtl::OUString >& aPropertyNames ) throw (uno::RuntimeException) +{ + return _getPropertyValues( aPropertyNames, mnParagraph ); +} + +/*// XTolerantMultiPropertySet +uno::Sequence< beans::SetPropertyTolerantFailed > SAL_CALL SvxUnoTextContent::setPropertyValuesTolerant( const uno::Sequence< ::rtl::OUString >& aPropertyNames, const uno::Sequence< uno::Any >& aValues ) throw (lang::IllegalArgumentException, uno::RuntimeException) +{ + return _setPropertyValuesTolerant(aPropertyNames, aValues, mnParagraph); +} + +uno::Sequence< beans::GetPropertyTolerantResult > SAL_CALL SvxUnoTextContent::getPropertyValuesTolerant( const uno::Sequence< ::rtl::OUString >& aPropertyNames ) throw (uno::RuntimeException) +{ + return _getPropertyValuesTolerant(aPropertyNames, mnParagraph); +} + +uno::Sequence< beans::GetDirectPropertyTolerantResult > SAL_CALL SvxUnoTextContent::getDirectPropertyValuesTolerant( const uno::Sequence< ::rtl::OUString >& aPropertyNames ) + throw (uno::RuntimeException) +{ + return _getDirectPropertyValuesTolerant(aPropertyNames, mnParagraph); +}*/ + +// beans::XPropertyState +beans::PropertyState SAL_CALL SvxUnoTextContent::getPropertyState( const OUString& PropertyName ) + throw(beans::UnknownPropertyException, uno::RuntimeException) +{ + return _getPropertyState( PropertyName, mnParagraph ); +} + +uno::Sequence< beans::PropertyState > SAL_CALL SvxUnoTextContent::getPropertyStates( const uno::Sequence< OUString >& aPropertyName ) + throw(beans::UnknownPropertyException, uno::RuntimeException) +{ + return _getPropertyStates( aPropertyName, mnParagraph ); +} + +void SAL_CALL SvxUnoTextContent::setPropertyToDefault( const OUString& PropertyName ) + throw(beans::UnknownPropertyException, uno::RuntimeException) +{ + _setPropertyToDefault( PropertyName, mnParagraph ); +} + +// lang::XServiceInfo + +OUString SAL_CALL SvxUnoTextContent::getImplementationName() + throw(uno::RuntimeException) +{ + return OUString( RTL_CONSTASCII_USTRINGPARAM("SvxUnoTextContent") ); +} + +uno::Sequence< OUString > SAL_CALL SvxUnoTextContent::getSupportedServiceNames() + throw(uno::RuntimeException) +{ + uno::Sequence< OUString > aSeq( SvxUnoTextRangeBase::getSupportedServiceNames() ); + comphelper::ServiceInfoHelper::addToSequence( aSeq, 5, "com.sun.star.style.ParagraphProperties", + "com.sun.star.style.ParagraphPropertiesComplex", + "com.sun.star.style.ParagraphPropertiesAsian", + "com.sun.star.text.TextContent", + "com.sun.star.text.Paragraph"); + return aSeq; +} + +// ==================================================================== +// class SvxUnoTextRangeEnumeration +// ==================================================================== + +SvxUnoTextRangeEnumeration::SvxUnoTextRangeEnumeration( const SvxUnoTextBase& rText, sal_uInt16 nPara ) throw() +: mxParentText( const_cast<SvxUnoTextBase*>(&rText) ), + mrParentText( rText ), + mnParagraph( nPara ), + mnNextPortion( 0 ) +{ + mpEditSource = rText.GetEditSource() ? rText.GetEditSource()->Clone() : NULL; + + if( mpEditSource && mpEditSource->GetTextForwarder() ) + { + mpPortions = new SvUShorts; + mpEditSource->GetTextForwarder()->GetPortions( nPara, *mpPortions ); + } + else + { + mpPortions = NULL; + } +} + +SvxUnoTextRangeEnumeration::~SvxUnoTextRangeEnumeration() throw() +{ + delete mpEditSource; + delete mpPortions; +} + +// container::XEnumeration + +sal_Bool SAL_CALL SvxUnoTextRangeEnumeration::hasMoreElements() + throw(uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + return mpPortions && mnNextPortion < mpPortions->Count(); +} + +uno::Any SAL_CALL SvxUnoTextRangeEnumeration::nextElement() + throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + + if( mpPortions == NULL || mnNextPortion >= mpPortions->Count() ) + throw container::NoSuchElementException(); + + sal_uInt16 nStartPos = 0; + if (mnNextPortion > 0) + nStartPos = mpPortions->GetObject(mnNextPortion-1); + sal_uInt16 nEndPos = mpPortions->GetObject(mnNextPortion); + ESelection aSel( mnParagraph, nStartPos, mnParagraph, nEndPos ); + + uno::Reference< text::XTextRange > xRange; + + const SvxUnoTextRangeBaseList& rRanges( mpEditSource->getRanges() ); + + SvxUnoTextRange* pRange = 0; + + SvxUnoTextRangeBaseList::const_iterator aIter; + for( aIter = rRanges.begin(); (aIter != rRanges.end()) && (pRange == 0); aIter++ ) + { + SvxUnoTextRange* pIterRange = dynamic_cast< SvxUnoTextRange* >( (*aIter ) ); + if( pIterRange && pIterRange->mbPortion && (aSel.IsEqual( pIterRange->maSelection ) ) ) + pRange = pIterRange; + } + + if( pRange == 0 ) + { + pRange = new SvxUnoTextRange( mrParentText, sal_True ); + pRange->SetSelection(aSel); + } + + xRange = pRange; + + mnNextPortion++; + + return uno::makeAny( xRange ); +} + +// ==================================================================== +// class SvxUnoTextCursor +// ==================================================================== + +uno::Sequence< uno::Type > SvxUnoTextCursor::maTypeSequence; + +uno::Reference< uno::XInterface > SvxUnoTextCursor_NewInstance() +{ + SvxUnoText aText; + uno::Reference< text::XText > xText( (text::XText*)new SvxUnoTextCursor( aText ) ); + uno::Reference< uno::XInterface > xInt( xText, uno::UNO_QUERY ); + return xInt; +} + +SvxUnoTextCursor::SvxUnoTextCursor( const SvxUnoTextBase& rText ) throw() +: SvxUnoTextRangeBase(rText), + mxParentText( const_cast<SvxUnoTextBase*>(&rText) ) +{ +} + +SvxUnoTextCursor::SvxUnoTextCursor( const SvxUnoTextCursor& rCursor ) throw() +: SvxUnoTextRangeBase(rCursor) +, text::XTextCursor() +, lang::XTypeProvider() +, cppu::OWeakAggObject() +, mxParentText(rCursor.mxParentText) +{ +} + +SvxUnoTextCursor::~SvxUnoTextCursor() throw() +{ +} + +// automatisch auskommentiert - [getIdlClass(es) or queryInterface] - Bitte XTypeProvider benutzen! +//sal_Bool SvxUnoTextCursor::queryInterface( uno::Uik aUIK, Reference< uno::XInterface > & xRef) +uno::Any SAL_CALL SvxUnoTextCursor::queryAggregation( const uno::Type & rType ) + throw(uno::RuntimeException) +{ + if( rType == ::getCppuType((const uno::Reference< text::XTextRange >*)0) ) + return uno::makeAny(uno::Reference< text::XTextRange >((text::XText*)(this))); + else QUERYINT( text::XTextCursor ); + else QUERYINT( beans::XMultiPropertyStates ); + else QUERYINT( beans::XPropertySet ); + else QUERYINT( beans::XMultiPropertySet ); + else QUERYINT( beans::XPropertyState ); + else QUERYINT( text::XTextRangeCompare ); + else QUERYINT( lang::XServiceInfo ); + else QUERYINT( lang::XTypeProvider ); + else QUERYINT( lang::XUnoTunnel ); + else + return OWeakAggObject::queryAggregation( rType ); +} + +uno::Any SAL_CALL SvxUnoTextCursor::queryInterface( const uno::Type & rType ) + throw(uno::RuntimeException) +{ + return OWeakAggObject::queryInterface(rType); +} + +void SAL_CALL SvxUnoTextCursor::acquire() throw ( ) +{ + OWeakAggObject::acquire(); +} + +void SAL_CALL SvxUnoTextCursor::release() throw ( ) +{ + OWeakAggObject::release(); +} + +// XTypeProvider +uno::Sequence< uno::Type > SAL_CALL SvxUnoTextCursor::getTypes() + throw(uno::RuntimeException) +{ + if( maTypeSequence.getLength() == 0 ) + { + maTypeSequence.realloc( 10 ); // !DANGER! keep this updated + uno::Type* pTypes = maTypeSequence.getArray(); + + *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextRange >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextCursor >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< beans::XPropertySet >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< beans::XMultiPropertySet >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< beans::XMultiPropertyStates >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< beans::XPropertyState >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextRangeCompare >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< lang::XServiceInfo >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< lang::XTypeProvider >*)0); + *pTypes++ = ::getCppuType(( const uno::Reference< lang::XUnoTunnel >*)0); + } + return maTypeSequence; +} + +uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextCursor::getImplementationId() + throw (uno::RuntimeException) +{ + static uno::Sequence< sal_Int8 > aId; + if( aId.getLength() == 0 ) + { + aId.realloc( 16 ); + rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); + } + return aId; +} + +// text::XTextCursor +void SAL_CALL SvxUnoTextCursor::collapseToStart() + throw(uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + CollapseToStart(); +} + +void SAL_CALL SvxUnoTextCursor::collapseToEnd() + throw(uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + CollapseToEnd(); +} + +sal_Bool SAL_CALL SvxUnoTextCursor::isCollapsed() + throw(uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + return IsCollapsed(); +} + +sal_Bool SAL_CALL SvxUnoTextCursor::goLeft( sal_Int16 nCount, sal_Bool bExpand ) + throw(uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + return GoLeft( nCount, bExpand ); +} + +sal_Bool SAL_CALL SvxUnoTextCursor::goRight( sal_Int16 nCount, sal_Bool bExpand ) + throw(uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + return GoRight( nCount, bExpand ); +} + +void SAL_CALL SvxUnoTextCursor::gotoStart( sal_Bool bExpand ) + throw(uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + GotoStart( bExpand ); +} + +void SAL_CALL SvxUnoTextCursor::gotoEnd( sal_Bool bExpand ) + throw(uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + GotoEnd( bExpand ); +} + +void SAL_CALL SvxUnoTextCursor::gotoRange( const uno::Reference< text::XTextRange >& xRange, sal_Bool bExpand ) + throw(uno::RuntimeException) +{ + if( !xRange.is() ) + return; + + SvxUnoTextRangeBase* pRange = SvxUnoTextRangeBase::getImplementation( xRange ); + + if( pRange ) + { + ESelection aNewSel = pRange->GetSelection(); + + if( bExpand ) + { + const ESelection& rOldSel = GetSelection(); + aNewSel.nStartPara = rOldSel.nStartPara; + aNewSel.nStartPos = rOldSel.nStartPos; + } + + SetSelection( aNewSel ); + } +} + +// text::XTextRange (rest in SvxTextRange) +uno::Reference< text::XText > SAL_CALL SvxUnoTextCursor::getText(void) throw( uno::RuntimeException ) +{ + return mxParentText; +} + +uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextCursor::getStart() + throw(uno::RuntimeException) +{ + return SvxUnoTextRangeBase::getStart(); +} + +uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextCursor::getEnd() + throw(uno::RuntimeException) +{ + return SvxUnoTextRangeBase::getEnd(); +} + +OUString SAL_CALL SvxUnoTextCursor::getString() throw( uno::RuntimeException ) +{ + return SvxUnoTextRangeBase::getString(); +} + +void SAL_CALL SvxUnoTextCursor::setString( const OUString& aString ) throw(uno::RuntimeException) +{ + SvxUnoTextRangeBase::setString(aString); +} +// lang::XServiceInfo +OUString SAL_CALL SvxUnoTextCursor::getImplementationName() throw(uno::RuntimeException) +{ + return OUString(RTL_CONSTASCII_USTRINGPARAM("SvxUnoTextCursor")); +} + +sal_Bool SAL_CALL SvxUnoTextCursor::supportsService( const OUString& ServiceName ) throw(uno::RuntimeException) +{ + return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() ); +} + +uno::Sequence< OUString > SAL_CALL SvxUnoTextCursor::getSupportedServiceNames() throw(uno::RuntimeException) +{ + uno::Sequence< OUString > aSeq( SvxUnoTextRangeBase::getSupportedServiceNames() ); + comphelper::ServiceInfoHelper::addToSequence( aSeq, 4,"com.sun.star.style.ParagraphProperties", + "com.sun.star.style.ParagraphPropertiesComplex", + "com.sun.star.style.ParagraphPropertiesAsian", + "com.sun.star.text.TextCursor"); + return aSeq; +} + + diff --git a/editeng/source/uno/unoviwed.cxx b/editeng/source/uno/unoviwed.cxx new file mode 100644 index 000000000000..5a31863ff9cd --- /dev/null +++ b/editeng/source/uno/unoviwed.cxx @@ -0,0 +1,137 @@ +/************************************************************************* + * + * 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_editeng.hxx" +#include <vcl/outdev.hxx> +#include <vcl/window.hxx> + +#include <editeng/unoviwed.hxx> +#include <editeng/editview.hxx> +#include <editeng/editeng.hxx> + +SvxEditEngineViewForwarder::SvxEditEngineViewForwarder( EditView& rView ) : + mrView( rView ) +{ +} + +SvxEditEngineViewForwarder::~SvxEditEngineViewForwarder() +{ +} + +sal_Bool SvxEditEngineViewForwarder::IsValid() const +{ + return sal_True; +} + +Rectangle SvxEditEngineViewForwarder::GetVisArea() const +{ + OutputDevice* pOutDev = mrView.GetWindow(); + + if( pOutDev ) + { + Rectangle aVisArea = mrView.GetVisArea(); + + // figure out map mode from edit engine + EditEngine* pEditEngine = mrView.GetEditEngine(); + + if( pEditEngine ) + { + MapMode aMapMode(pOutDev->GetMapMode()); + aVisArea = OutputDevice::LogicToLogic( aVisArea, + pEditEngine->GetRefMapMode(), + aMapMode.GetMapUnit() ); + aMapMode.SetOrigin(Point()); + return pOutDev->LogicToPixel( aVisArea, aMapMode ); + } + } + + return Rectangle(); +} + +Point SvxEditEngineViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const +{ + OutputDevice* pOutDev = mrView.GetWindow(); + + if( pOutDev ) + { + MapMode aMapMode(pOutDev->GetMapMode()); + Point aPoint( OutputDevice::LogicToLogic( rPoint, rMapMode, + aMapMode.GetMapUnit() ) ); + aMapMode.SetOrigin(Point()); + return pOutDev->LogicToPixel( aPoint, aMapMode ); + } + + return Point(); +} + +Point SvxEditEngineViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const +{ + OutputDevice* pOutDev = mrView.GetWindow(); + + if( pOutDev ) + { + MapMode aMapMode(pOutDev->GetMapMode()); + aMapMode.SetOrigin(Point()); + Point aPoint( pOutDev->PixelToLogic( rPoint, aMapMode ) ); + return OutputDevice::LogicToLogic( aPoint, + aMapMode.GetMapUnit(), + rMapMode ); + } + + return Point(); +} + +sal_Bool SvxEditEngineViewForwarder::GetSelection( ESelection& rSelection ) const +{ + rSelection = mrView.GetSelection(); + return sal_True; +} + +sal_Bool SvxEditEngineViewForwarder::SetSelection( const ESelection& rSelection ) +{ + mrView.SetSelection( rSelection ); + return sal_True; +} + +sal_Bool SvxEditEngineViewForwarder::Copy() +{ + mrView.Copy(); + return sal_True; +} + +sal_Bool SvxEditEngineViewForwarder::Cut() +{ + mrView.Cut(); + return sal_True; +} + +sal_Bool SvxEditEngineViewForwarder::Paste() +{ + mrView.Paste(); + return sal_True; +} diff --git a/editeng/source/uno/unoviwou.cxx b/editeng/source/uno/unoviwou.cxx new file mode 100644 index 000000000000..e70273d32290 --- /dev/null +++ b/editeng/source/uno/unoviwou.cxx @@ -0,0 +1,173 @@ +/************************************************************************* + * + * 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_editeng.hxx" +#include <vcl/outdev.hxx> +#include <vcl/window.hxx> + +#include <editeng/unoviwou.hxx> +#include <editeng/outliner.hxx> +#include <editeng/editeng.hxx> + +SvxDrawOutlinerViewForwarder::SvxDrawOutlinerViewForwarder( OutlinerView& rOutl ) : + mrOutlinerView ( rOutl ), maTextShapeTopLeft() +{ +} + +SvxDrawOutlinerViewForwarder::SvxDrawOutlinerViewForwarder( OutlinerView& rOutl, const Point& rShapePosTopLeft ) : + mrOutlinerView ( rOutl ), maTextShapeTopLeft( rShapePosTopLeft ) +{ +} + +SvxDrawOutlinerViewForwarder::~SvxDrawOutlinerViewForwarder() +{ +} + +Point SvxDrawOutlinerViewForwarder::GetTextOffset() const +{ + // #101029# calc text offset from shape anchor + Rectangle aOutputRect( mrOutlinerView.GetOutputArea() ); + + return aOutputRect.TopLeft() - maTextShapeTopLeft; +} + +sal_Bool SvxDrawOutlinerViewForwarder::IsValid() const +{ + return sal_True; +} + +Rectangle SvxDrawOutlinerViewForwarder::GetVisArea() const +{ + OutputDevice* pOutDev = mrOutlinerView.GetWindow(); + + if( pOutDev ) + { + Rectangle aVisArea = mrOutlinerView.GetVisArea(); + + // #101029# + Point aTextOffset( GetTextOffset() ); + aVisArea.Move( aTextOffset.X(), aTextOffset.Y() ); + + // figure out map mode from edit engine + Outliner* pOutliner = mrOutlinerView.GetOutliner(); + + if( pOutliner ) + { + MapMode aMapMode(pOutDev->GetMapMode()); + aVisArea = OutputDevice::LogicToLogic( aVisArea, + pOutliner->GetRefMapMode(), + aMapMode.GetMapUnit() ); + aMapMode.SetOrigin(Point()); + return pOutDev->LogicToPixel( aVisArea, aMapMode ); + } + } + + return Rectangle(); +} + +Point SvxDrawOutlinerViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const +{ + OutputDevice* pOutDev = mrOutlinerView.GetWindow(); + + if( pOutDev ) + { + Point aPoint1( rPoint ); + Point aTextOffset( GetTextOffset() ); + + // #101029# + aPoint1.X() += aTextOffset.X(); + aPoint1.Y() += aTextOffset.Y(); + + MapMode aMapMode(pOutDev->GetMapMode()); + Point aPoint2( OutputDevice::LogicToLogic( aPoint1, rMapMode, + aMapMode.GetMapUnit() ) ); + aMapMode.SetOrigin(Point()); + return pOutDev->LogicToPixel( aPoint2, aMapMode ); + } + + return Point(); +} + +Point SvxDrawOutlinerViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const +{ + OutputDevice* pOutDev = mrOutlinerView.GetWindow(); + + if( pOutDev ) + { + MapMode aMapMode(pOutDev->GetMapMode()); + aMapMode.SetOrigin(Point()); + Point aPoint1( pOutDev->PixelToLogic( rPoint, aMapMode ) ); + Point aPoint2( OutputDevice::LogicToLogic( aPoint1, + aMapMode.GetMapUnit(), + rMapMode ) ); + // #101029# + Point aTextOffset( GetTextOffset() ); + + aPoint2.X() -= aTextOffset.X(); + aPoint2.Y() -= aTextOffset.Y(); + + return aPoint2; + } + + return Point(); +} + +sal_Bool SvxDrawOutlinerViewForwarder::GetSelection( ESelection& rSelection ) const +{ + rSelection = mrOutlinerView.GetSelection(); + return sal_True; +} + +sal_Bool SvxDrawOutlinerViewForwarder::SetSelection( const ESelection& rSelection ) +{ + mrOutlinerView.SetSelection( rSelection ); + return sal_True; +} + +sal_Bool SvxDrawOutlinerViewForwarder::Copy() +{ + mrOutlinerView.Copy(); + return sal_True; +} + +sal_Bool SvxDrawOutlinerViewForwarder::Cut() +{ + mrOutlinerView.Cut(); + return sal_True; +} + +sal_Bool SvxDrawOutlinerViewForwarder::Paste() +{ + mrOutlinerView.Paste(); + return sal_True; +} + +void SvxDrawOutlinerViewForwarder::SetShapePos( const Point& rShapePosTopLeft ) +{ + maTextShapeTopLeft = rShapePosTopLeft; +} |