From 535c4c01b6d9e6341464d48077917fb7a5c242bb Mon Sep 17 00:00:00 2001 From: Maxim Monastirsky Date: Thu, 30 Jan 2014 11:02:53 +0200 Subject: Disable Increase/Decrease buttons when limits are reached MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit And simplify the code: - Use sal_uInt32 directly, without useless casting to SwTwips. - Check for slot id directly, without an additional variable. - Remove the redundant loop. Change-Id: Ica76a166c88213cdd39e44482ce834d3555afb60 Reviewed-on: https://gerrit.libreoffice.org/7654 Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- sw/source/ui/shells/txtattr.cxx | 71 ++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 40 deletions(-) (limited to 'sw') diff --git a/sw/source/ui/shells/txtattr.cxx b/sw/source/ui/shells/txtattr.cxx index 2059b5c253a5..14519822860c 100644 --- a/sw/source/ui/shells/txtattr.cxx +++ b/sw/source/ui/shells/txtattr.cxx @@ -55,8 +55,8 @@ #include #include "swabstdlg.hxx" #include "chrdlg.hrc" -const SwTwips lFontInc = 40; // 2pt -const SwTwips lFontMaxSz = 19998; // 999.9pt +const sal_uInt32 nFontInc = 40; // 2pt +const sal_uInt32 nFontMaxSz = 19998; // 999.9pt @@ -174,7 +174,6 @@ void SwTextShell::ExecCharAttrArgs(SfxRequest &rReq) sal_uInt16 nSlot = rReq.GetSlot(); const SfxItemSet* pArgs = rReq.GetArgs(); bool bArgs = pArgs != 0 && pArgs->Count() > 0; - int bGrow = sal_False; SwWrtShell& rWrtSh = GetShell(); SwTxtFmtColl* pColl = 0; @@ -220,49 +219,30 @@ void SwTextShell::ExecCharAttrArgs(SfxRequest &rReq) break; case FN_GROW_FONT_SIZE: - bGrow = sal_True; - // No break !! case FN_SHRINK_FONT_SIZE: { SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONTHEIGHT, rPool ); rWrtSh.GetCurAttr( aSetItem.GetItemSet() ); SfxItemSet aAttrSet( rPool, aSetItem.GetItemSet().GetRanges() ); - const SfxPoolItem* pI; - static const sal_uInt16 aScrTypes[] = { - SCRIPTTYPE_LATIN, SCRIPTTYPE_ASIAN, SCRIPTTYPE_COMPLEX, 0 }; - sal_uInt16 nScriptType = rWrtSh.GetScriptType(); - for( const sal_uInt16* pScrpTyp = aScrTypes; *pScrpTyp; ++pScrpTyp ) - if( ( nScriptType & *pScrpTyp ) && - 0 != ( pI = aSetItem.GetItemOfScript( *pScrpTyp ))) - { - SvxFontHeightItem aSize( *(const SvxFontHeightItem*)pI ); - SwTwips lSize = (SwTwips) aSize.GetHeight(); + sal_uInt16 nScriptTypes = rWrtSh.GetScriptType(); + SvxFontHeightItem aSize( *static_cast( aSetItem.GetItemOfScript( nScriptTypes ) ) ); + sal_uInt32 nSize = aSize.GetHeight(); + + if ( nSlot == FN_GROW_FONT_SIZE && ( nSize += nFontInc ) > nFontMaxSz ) + nSize = nFontMaxSz; + else if ( nSlot == FN_SHRINK_FONT_SIZE && ( nSize -= nFontInc ) < nFontInc ) + nSize = nFontInc; + + aSize.SetHeight( nSize ); + aSetItem.PutItemForScriptType( nScriptTypes, aSize ); + aAttrSet.Put( aSetItem.GetItemSet() ); + + if( pColl ) + pColl->SetFmtAttr( aAttrSet ); + else + rWrtSh.SetAttrSet( aAttrSet ); - if ( bGrow ) - { - if( lSize == lFontMaxSz ) - break; // That's all, further up is not possible - if( ( lSize += lFontInc ) > lFontMaxSz ) - lSize = lFontMaxSz; - } - else - { - if( lSize == lFontInc ) - break; - if( ( lSize -= lFontInc ) < lFontInc ) - lSize = lFontInc; - } - aSize.SetHeight( lSize ); - aAttrSet.Put( aSize ); - } - if( aAttrSet.Count() ) - { - if( pColl ) - pColl->SetFmtAttr( aAttrSet ); - else - rWrtSh.SetAttrSet( aAttrSet ); - } rReq.Done(); } break; @@ -618,8 +598,19 @@ void SwTextShell::GetAttrState(SfxItemSet &rSet) SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONTHEIGHT, *rSet.GetPool() ); aSetItem.GetItemSet().Put( aCoreSet, false ); - if( !aSetItem.GetItemOfScript( rSh.GetScriptType() )) + const SvxFontHeightItem* aSize( static_cast( + aSetItem.GetItemOfScript( rSh.GetScriptType() ) ) ); + + if( !aSize ) rSet.DisableItem( nSlot ); + else + { + sal_uInt32 nSize = aSize->GetHeight(); + if( nSize == nFontMaxSz ) + rSet.DisableItem( FN_GROW_FONT_SIZE ); + else if( nSize == nFontInc ) + rSet.DisableItem( FN_SHRINK_FONT_SIZE ); + } nSlot = 0; } break; -- cgit