summaryrefslogtreecommitdiff
path: root/editeng
diff options
context:
space:
mode:
authorArmin Le Grand (Allotropia) <armin.le.grand@me.com>2021-06-10 17:07:10 +0200
committerArmin Le Grand <Armin.Le.Grand@me.com>2021-06-11 09:40:32 +0200
commit5c3ad59612697cf0afee0f836e9ee77f0920356b (patch)
treede89d2ec1996a944d42f7019a37d12a5d133e45e /editeng
parentd4a478af9cb3154ca1a2179240750865ee3ede91 (diff)
tdf#130428 remove unnecessary usage of SfxItemState::UNKNOWN
In this case SfxItemState::UNKNOWN was used as boolean state to decide to keep extracted value or replace. First method even throws an exception when SfxItemState::UNKNOWN should happen. I tried to be very careful in changing these methods, so another look/check from reviewers will be welcome. I think that code was unnecessarily complicated, too, butz hope to not have touched semantics (behaviour) at all Change-Id: Id213fedcafcfb655749caf2659f9a15b240ec27d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116999 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
Diffstat (limited to 'editeng')
-rw-r--r--editeng/source/uno/unotext.cxx106
1 files changed, 59 insertions, 47 deletions
diff --git a/editeng/source/uno/unotext.cxx b/editeng/source/uno/unotext.cxx
index 0c4a01c748d1..20d901e0d300 100644
--- a/editeng/source/uno/unotext.cxx
+++ b/editeng/source/uno/unotext.cxx
@@ -933,42 +933,41 @@ beans::PropertyState SvxUnoTextRangeBase::_getPropertyState(const SfxItemPropert
SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : nullptr;
if( pForwarder )
{
- SfxItemState eItemState = SfxItemState::UNKNOWN;
- sal_uInt16 nWID = 0;
+ SfxItemState eItemState(SfxItemState::DEFAULT);
+ bool bItemStateSet(false);
switch( pMap->nWID )
{
case WID_FONTDESC:
{
const sal_uInt16* pWhichId = aSvxUnoFontDescriptorWhichMap;
- SfxItemState eTempItemState = SfxItemState::UNKNOWN;
while( *pWhichId )
{
- if(nPara != -1)
- eTempItemState = pForwarder->GetItemState( nPara, *pWhichId );
- else
- eTempItemState = pForwarder->GetItemState( GetSelection(), *pWhichId );
+ const SfxItemState eTempItemState(nPara != -1
+ ? pForwarder->GetItemState( nPara, *pWhichId )
+ : pForwarder->GetItemState( GetSelection(), *pWhichId ));
switch( eTempItemState )
{
case SfxItemState::DISABLED:
case SfxItemState::DONTCARE:
eItemState = SfxItemState::DONTCARE;
+ bItemStateSet = true;
break;
case SfxItemState::DEFAULT:
- if( eItemState != SfxItemState::DEFAULT )
+ if( !bItemStateSet )
{
- if( eItemState == SfxItemState::UNKNOWN )
- eItemState = SfxItemState::DEFAULT;
+ eItemState = SfxItemState::DEFAULT;
+ bItemStateSet = true;
}
break;
case SfxItemState::SET:
- if( eItemState != SfxItemState::SET )
+ if( !bItemStateSet )
{
- if( eItemState == SfxItemState::UNKNOWN )
- eItemState = SfxItemState::SET;
+ eItemState = SfxItemState::SET;
+ bItemStateSet = true;
}
break;
default:
@@ -984,31 +983,35 @@ beans::PropertyState SvxUnoTextRangeBase::_getPropertyState(const SfxItemPropert
case WID_NUMBERINGSTARTVALUE:
case WID_PARAISNUMBERINGRESTART:
eItemState = SfxItemState::SET;
+ bItemStateSet = true;
break;
default:
- nWID = pMap->nWID;
- }
+ if(0 != pMap->nWID)
+ {
+ if( nPara != -1 )
+ eItemState = pForwarder->GetItemState( nPara, pMap->nWID );
+ else
+ eItemState = pForwarder->GetItemState( GetSelection(), pMap->nWID );
- if( nWID != 0 )
- {
- if( nPara != -1 )
- eItemState = pForwarder->GetItemState( nPara, nWID );
- else
- eItemState = pForwarder->GetItemState( GetSelection(), nWID );
+ bItemStateSet = true;
+ }
+ break;
}
- switch( eItemState )
+ if(bItemStateSet)
{
- case SfxItemState::DONTCARE:
- case SfxItemState::DISABLED:
- return beans::PropertyState_AMBIGUOUS_VALUE;
- case SfxItemState::SET:
- return beans::PropertyState_DIRECT_VALUE;
- case SfxItemState::DEFAULT:
- return beans::PropertyState_DEFAULT_VALUE;
- default: break;
-// case SfxItemState::UNKNOWN:
+ switch( eItemState )
+ {
+ case SfxItemState::DONTCARE:
+ case SfxItemState::DISABLED:
+ return beans::PropertyState_AMBIGUOUS_VALUE;
+ case SfxItemState::SET:
+ return beans::PropertyState_DIRECT_VALUE;
+ case SfxItemState::DEFAULT:
+ return beans::PropertyState_DEFAULT_VALUE;
+ default: break;
+ }
}
}
}
@@ -1065,39 +1068,39 @@ bool SvxUnoTextRangeBase::_getOnePropertyStates(const SfxItemSet* pSet, const Sf
bool bUnknownPropertyFound = false;
if(pSet && pMap)
{
- SfxItemState eItemState = SfxItemState::UNKNOWN;
- sal_uInt16 nWID = 0;
+ SfxItemState eItemState = SfxItemState::DEFAULT;
+ bool bItemStateSet(false);
switch( pMap->nWID )
{
case WID_FONTDESC:
{
const sal_uInt16* pWhichId = aSvxUnoFontDescriptorWhichMap;
- SfxItemState eTempItemState = SfxItemState::UNKNOWN;
while( *pWhichId )
{
- eTempItemState = pSet->GetItemState( *pWhichId );
+ const SfxItemState eTempItemState(pSet->GetItemState( *pWhichId ));
switch( eTempItemState )
{
case SfxItemState::DISABLED:
case SfxItemState::DONTCARE:
eItemState = SfxItemState::DONTCARE;
+ bItemStateSet = true;
break;
case SfxItemState::DEFAULT:
- if( eItemState != SfxItemState::DEFAULT )
+ if( !bItemStateSet )
{
- if( eItemState == SfxItemState::UNKNOWN )
- eItemState = SfxItemState::DEFAULT;
+ eItemState = SfxItemState::DEFAULT;
+ bItemStateSet = true;
}
break;
case SfxItemState::SET:
- if( eItemState != SfxItemState::SET )
+ if( !bItemStateSet )
{
- if( eItemState == SfxItemState::UNKNOWN )
- eItemState = SfxItemState::SET;
+ eItemState = SfxItemState::SET;
+ bItemStateSet = true;
}
break;
default:
@@ -1114,31 +1117,40 @@ bool SvxUnoTextRangeBase::_getOnePropertyStates(const SfxItemSet* pSet, const Sf
case WID_NUMBERINGSTARTVALUE:
case WID_PARAISNUMBERINGRESTART:
eItemState = SfxItemState::SET;
+ bItemStateSet = true;
break;
default:
- nWID = pMap->nWID;
+ if(0 != pMap->nWID)
+ {
+ eItemState = pSet->GetItemState( pMap->nWID, false );
+ bItemStateSet = true;
+ }
+ break;
}
if( bUnknownPropertyFound )
return false;
- if( nWID != 0 )
- eItemState = pSet->GetItemState( nWID, false );
-
- switch( eItemState )
+ if(bItemStateSet)
{
+ switch( eItemState )
+ {
case SfxItemState::SET:
rState = beans::PropertyState_DIRECT_VALUE;
break;
case SfxItemState::DEFAULT:
rState = beans::PropertyState_DEFAULT_VALUE;
break;
-// case SfxItemState::UNKNOWN:
// case SfxItemState::DONTCARE:
// case SfxItemState::DISABLED:
default:
rState = beans::PropertyState_AMBIGUOUS_VALUE;
+ }
+ }
+ else
+ {
+ rState = beans::PropertyState_AMBIGUOUS_VALUE;
}
}
return true;