diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-05-21 17:44:32 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-05-21 21:09:57 +0200 |
commit | 2634bc59092b24217d984a5845365d703bdb08d2 (patch) | |
tree | a3b7324d54aefb57d5f012c7aeb1b80d07fce75b /sw/source/uibase | |
parent | c912c4b02b2dc4cd5aa62d77e92e1731c6cbde65 (diff) |
sw: replace most static_cast<sal_uInt16>() calls with o3tl::narrowing()
o3tl::narrowing() is a better way to handle this, as that way the
integer conversion is still implicit, which allows detecting integer
truncation at runtime (with suitable compiler flags).
Change-Id: I499abda3be6943e8c111c56df390e72939586221
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115948
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/source/uibase')
32 files changed, 97 insertions, 97 deletions
diff --git a/sw/source/uibase/app/appenv.cxx b/sw/source/uibase/app/appenv.cxx index 02ce718915ae..5e295b22a46a 100644 --- a/sw/source/uibase/app/appenv.cxx +++ b/sw/source/uibase/app/appenv.cxx @@ -334,8 +334,8 @@ void SwModule::InsertEnv( SfxRequest& rReq ) tools::Long lLeft = rItem.m_nShiftRight, lUpper = rItem.m_nShiftDown; - sal_uInt16 nPageW = static_cast<sal_uInt16>(std::max(rItem.m_nWidth, rItem.m_nHeight)), - nPageH = static_cast<sal_uInt16>(std::min(rItem.m_nWidth, rItem.m_nHeight)); + sal_uInt16 nPageW = o3tl::narrowing<sal_uInt16>(std::max(rItem.m_nWidth, rItem.m_nHeight)), + nPageH = o3tl::narrowing<sal_uInt16>(std::min(rItem.m_nWidth, rItem.m_nHeight)); switch (rItem.m_eAlign) { @@ -352,8 +352,8 @@ void SwModule::InsertEnv( SfxRequest& rReq ) } SvxLRSpaceItem aLRMargin( RES_LR_SPACE ); SvxULSpaceItem aULMargin( RES_UL_SPACE ); - aLRMargin.SetLeft (static_cast<sal_uInt16>(lLeft) ); - aULMargin.SetUpper(static_cast<sal_uInt16>(lUpper)); + aLRMargin.SetLeft (o3tl::narrowing<sal_uInt16>(lLeft) ); + aULMargin.SetUpper(o3tl::narrowing<sal_uInt16>(lUpper)); aLRMargin.SetRight(0); aULMargin.SetLower(0); rFormat.SetFormatAttr(aLRMargin); diff --git a/sw/source/uibase/app/applab.cxx b/sw/source/uibase/app/applab.cxx index 705bdee9e37a..1cb48c0f1135 100644 --- a/sw/source/uibase/app/applab.cxx +++ b/sw/source/uibase/app/applab.cxx @@ -224,8 +224,8 @@ void SwModule::InsertLab(SfxRequest& rReq, bool bLabel) // Borders SvxLRSpaceItem aLRMargin( RES_LR_SPACE ); SvxULSpaceItem aULMargin( RES_UL_SPACE ); - aLRMargin.SetLeft (static_cast<sal_uInt16>(rItem.m_lLeft) ); - aULMargin.SetUpper(static_cast<sal_uInt16>(rItem.m_lUpper)); + aLRMargin.SetLeft (o3tl::narrowing<sal_uInt16>(rItem.m_lLeft) ); + aULMargin.SetUpper(o3tl::narrowing<sal_uInt16>(rItem.m_lUpper)); aLRMargin.SetRight( 0 ); aULMargin.SetLower( 0 ); rFormat.SetFormatAttr(aLRMargin); diff --git a/sw/source/uibase/app/appopt.cxx b/sw/source/uibase/app/appopt.cxx index 1b22068ebe7f..ff3c5eb6da80 100644 --- a/sw/source/uibase/app/appopt.cxx +++ b/sw/source/uibase/app/appopt.cxx @@ -175,10 +175,10 @@ std::unique_ptr<SfxItemSet> SwModule::CreateItemSet( sal_uInt16 nId ) { const SvxTabStopItem& rDefTabs = pAppView->GetWrtShell().GetDefault(RES_PARATR_TABSTOP); - pRet->Put( SfxUInt16Item( SID_ATTR_DEFTABSTOP, static_cast<sal_uInt16>(::GetTabDist(rDefTabs)))); + pRet->Put( SfxUInt16Item( SID_ATTR_DEFTABSTOP, o3tl::narrowing<sal_uInt16>(::GetTabDist(rDefTabs)))); } else - pRet->Put(SfxUInt16Item( SID_ATTR_DEFTABSTOP, static_cast<sal_uInt16>(convertMm100ToTwip(pPref->GetDefTabInMm100())))); + pRet->Put(SfxUInt16Item( SID_ATTR_DEFTABSTOP, o3tl::narrowing<sal_uInt16>(convertMm100ToTwip(pPref->GetDefTabInMm100())))); } // Options for GridTabPage @@ -189,8 +189,8 @@ std::unique_ptr<SfxItemSet> SwModule::CreateItemSet( sal_uInt16 nId ) aGridItem.SetGridVisible( aViewOpt.IsGridVisible()); const Size& rSnapSize = aViewOpt.GetSnapSize(); - aGridItem.SetFieldDrawX( static_cast<sal_uInt16>(rSnapSize.Width() )); - aGridItem.SetFieldDrawY( static_cast<sal_uInt16>(rSnapSize.Height())); + aGridItem.SetFieldDrawX( o3tl::narrowing<sal_uInt16>(rSnapSize.Width() )); + aGridItem.SetFieldDrawY( o3tl::narrowing<sal_uInt16>(rSnapSize.Height())); aGridItem.SetFieldDivisionX( aViewOpt.GetDivisionX()); aGridItem.SetFieldDivisionY( aViewOpt.GetDivisionY()); diff --git a/sw/source/uibase/app/docsh2.cxx b/sw/source/uibase/app/docsh2.cxx index 893872b66118..54fa22ae795d 100644 --- a/sw/source/uibase/app/docsh2.cxx +++ b/sw/source/uibase/app/docsh2.cxx @@ -540,7 +540,7 @@ void SwDocShell::Execute(SfxRequest& rReq) aFileName = pTemplateItem->GetValue(); const SfxInt32Item* pFlagsItem = rReq.GetArg<SfxInt32Item>(SID_TEMPLATE_LOAD); if ( pFlagsItem ) - nFlags = static_cast<SfxTemplateFlags>(static_cast<sal_uInt16>(pFlagsItem->GetValue())); + nFlags = static_cast<SfxTemplateFlags>(o3tl::narrowing<sal_uInt16>(pFlagsItem->GetValue())); } } diff --git a/sw/source/uibase/app/swmodul1.cxx b/sw/source/uibase/app/swmodul1.cxx index 0e103f2282bc..c396d437fd0f 100644 --- a/sw/source/uibase/app/swmodul1.cxx +++ b/sw/source/uibase/app/swmodul1.cxx @@ -604,7 +604,7 @@ sal_uInt16 SwModule::GetLinkUpdMode() const { if(!m_pUsrPref) GetUsrPref(false); - return static_cast<sal_uInt16>(m_pUsrPref->GetUpdateLinkMode()); + return o3tl::narrowing<sal_uInt16>(m_pUsrPref->GetUpdateLinkMode()); } SwFieldUpdateFlags SwModule::GetFieldUpdateFlags() const diff --git a/sw/source/uibase/config/modcfg.cxx b/sw/source/uibase/config/modcfg.cxx index ef51d6e6ba95..4733727e7043 100644 --- a/sw/source/uibase/config/modcfg.cxx +++ b/sw/source/uibase/config/modcfg.cxx @@ -1139,10 +1139,10 @@ void SwTableConfig::Load() sal_Int32 nTemp = 0; switch (nProp) { - case 0 : pValues[nProp] >>= nTemp; m_nTableHMove = static_cast<sal_uInt16>(convertMm100ToTwip(nTemp)); break; //"Shift/Row", - case 1 : pValues[nProp] >>= nTemp; m_nTableVMove = static_cast<sal_uInt16>(convertMm100ToTwip(nTemp)); break; //"Shift/Column", - case 2 : pValues[nProp] >>= nTemp; m_nTableHInsert = static_cast<sal_uInt16>(convertMm100ToTwip(nTemp)); break; //"Insert/Row", - case 3 : pValues[nProp] >>= nTemp; m_nTableVInsert = static_cast<sal_uInt16>(convertMm100ToTwip(nTemp)); break; //"Insert/Column", + case 0 : pValues[nProp] >>= nTemp; m_nTableHMove = o3tl::narrowing<sal_uInt16>(convertMm100ToTwip(nTemp)); break; //"Shift/Row", + case 1 : pValues[nProp] >>= nTemp; m_nTableVMove = o3tl::narrowing<sal_uInt16>(convertMm100ToTwip(nTemp)); break; //"Shift/Column", + case 2 : pValues[nProp] >>= nTemp; m_nTableHInsert = o3tl::narrowing<sal_uInt16>(convertMm100ToTwip(nTemp)); break; //"Insert/Row", + case 3 : pValues[nProp] >>= nTemp; m_nTableVInsert = o3tl::narrowing<sal_uInt16>(convertMm100ToTwip(nTemp)); break; //"Insert/Column", case 4 : pValues[nProp] >>= nTemp; m_eTableChgMode = static_cast<TableChgMode>(nTemp); break; //"Change/Effect", case 5 : m_bInsTableFormatNum = *o3tl::doAccess<bool>(pValues[nProp]); break; //"Input/NumberRecognition", case 6 : m_bInsTableChangeNumFormat = *o3tl::doAccess<bool>(pValues[nProp]); break; //"Input/NumberFormatRecognition", diff --git a/sw/source/uibase/config/usrpref.cxx b/sw/source/uibase/config/usrpref.cxx index 2dbc4b74d966..7f85d5a78940 100644 --- a/sw/source/uibase/config/usrpref.cxx +++ b/sw/source/uibase/config/usrpref.cxx @@ -384,7 +384,7 @@ void SwLayoutViewConfig::Load() case 12: m_rParent.SetMetric(static_cast<FieldUnit>(nInt32Val), true); break;// "Other/MeasureUnit", case 13: m_rParent.SetDefTabInMm100(nInt32Val, true); break;// "Other/TabStop", case 14: m_rParent.SetVRulerRight(bSet); break;// "Window/IsVerticalRulerRight", - case 15: m_rParent.SetViewLayoutColumns( static_cast<sal_uInt16>(nInt32Val) ); break;// "ViewLayout/Columns", + case 15: m_rParent.SetViewLayoutColumns( o3tl::narrowing<sal_uInt16>(nInt32Val) ); break;// "ViewLayout/Columns", case 16: m_rParent.SetViewLayoutBookMode(bSet); break;// "ViewLayout/BookMode", case 17: m_rParent.SetDefaultPageMode(bSet,true); break;// "Other/IsSquaredPageMode", case 18: m_rParent.SetApplyCharUnit(bSet, true); break;// "Other/ApplyUserChar" diff --git a/sw/source/uibase/config/viewopt.cxx b/sw/source/uibase/config/viewopt.cxx index 77e65e1f6604..f36530c355ad 100644 --- a/sw/source/uibase/config/viewopt.cxx +++ b/sw/source/uibase/config/viewopt.cxx @@ -326,7 +326,7 @@ void SwViewOption::Init(const OutputDevice* pWin) { if( !s_nPixelTwips && pWin ) { - s_nPixelTwips = static_cast<sal_uInt16>(pWin->PixelToLogic( Size(1,1) ).Height()); + s_nPixelTwips = o3tl::narrowing<sal_uInt16>(pWin->PixelToLogic( Size(1,1) ).Height()); } } diff --git a/sw/source/uibase/dbui/mailmergehelper.cxx b/sw/source/uibase/dbui/mailmergehelper.cxx index 762956faba57..17abf70db7c4 100644 --- a/sw/source/uibase/dbui/mailmergehelper.cxx +++ b/sw/source/uibase/dbui/mailmergehelper.cxx @@ -360,7 +360,7 @@ void SwAddressPreview::UpdateScrollBar() { if (pImpl->nColumns) { - sal_uInt16 nResultingRows = static_cast<sal_uInt16>(pImpl->aAddresses.size() + pImpl->nColumns - 1) / pImpl->nColumns; + sal_uInt16 nResultingRows = o3tl::narrowing<sal_uInt16>(pImpl->aAddresses.size() + pImpl->nColumns - 1) / pImpl->nColumns; ++nResultingRows; auto nValue = m_xVScrollBar->vadjustment_get_value(); if (nValue > nResultingRows) @@ -397,7 +397,7 @@ void SwAddressPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Re aPartSize.AdjustHeight( -2 ); sal_uInt16 nAddress = nStartRow * pImpl->nColumns; - const sal_uInt16 nNumAddresses = static_cast<sal_uInt16>(pImpl->aAddresses.size()); + const sal_uInt16 nNumAddresses = o3tl::narrowing<sal_uInt16>(pImpl->aAddresses.size()); for (sal_uInt16 nRow = 0; nRow < pImpl->nRows ; ++nRow) { for (sal_uInt16 nCol = 0; nCol < pImpl->nColumns; ++nCol) @@ -435,9 +435,9 @@ bool SwAddressPreview::MouseButtonDown( const MouseEvent& rMEvt ) sal_uInt32 nSelect = nRow * pImpl->nColumns + nCol; if( nSelect < pImpl->aAddresses.size() && - pImpl->nSelectedAddress != static_cast<sal_uInt16>(nSelect)) + pImpl->nSelectedAddress != o3tl::narrowing<sal_uInt16>(nSelect)) { - pImpl->nSelectedAddress = static_cast<sal_uInt16>(nSelect); + pImpl->nSelectedAddress = o3tl::narrowing<sal_uInt16>(nSelect); m_aSelectHdl.Call(nullptr); } Invalidate(); @@ -479,9 +479,9 @@ bool SwAddressPreview::KeyInput( const KeyEvent& rKEvt ) } sal_uInt32 nSelect = nSelectedRow * pImpl->nColumns + nSelectedColumn; if( nSelect < pImpl->aAddresses.size() && - pImpl->nSelectedAddress != static_cast<sal_uInt16>(nSelect)) + pImpl->nSelectedAddress != o3tl::narrowing<sal_uInt16>(nSelect)) { - pImpl->nSelectedAddress = static_cast<sal_uInt16>(nSelect); + pImpl->nSelectedAddress = o3tl::narrowing<sal_uInt16>(nSelect); m_aSelectHdl.Call(nullptr); Invalidate(); } diff --git a/sw/source/uibase/dochdl/gloshdl.cxx b/sw/source/uibase/dochdl/gloshdl.cxx index 41f1aad97a79..1540d3e4207c 100644 --- a/sw/source/uibase/dochdl/gloshdl.cxx +++ b/sw/source/uibase/dochdl/gloshdl.cxx @@ -112,12 +112,12 @@ void SwGlossaryHdl::SetCurGroup(const OUString &rGrp, bool bApi, bool bAlwaysCre { if (sCurEntryPath == rPathArr[nPath]) { - nCurrentPath = static_cast<sal_uInt16>(nPath); + nCurrentPath = o3tl::narrowing<sal_uInt16>(nPath); break; } } const OUString sPath = sGroup.getToken(1, GLOS_DELIM); - sal_uInt16 nComparePath = static_cast<sal_uInt16>(sPath.toInt32()); + sal_uInt16 nComparePath = o3tl::narrowing<sal_uInt16>(sPath.toInt32()); if(nCurrentPath == nComparePath && sGroup.getToken(0, GLOS_DELIM) == sCurBase) bPathEqual = true; diff --git a/sw/source/uibase/docvw/srcedtw.cxx b/sw/source/uibase/docvw/srcedtw.cxx index a06b700b12f0..071ba6d64233 100644 --- a/sw/source/uibase/docvw/srcedtw.cxx +++ b/sw/source/uibase/docvw/srcedtw.cxx @@ -594,7 +594,7 @@ IMPL_LINK( SwSrcEditWindow, SyntaxTimerHdl, Timer*, pIdle, void ) sal_uInt16 nCount = 0; // at first the region around the cursor is processed TextSelection aSel = m_pTextView->GetSelection(); - sal_uInt16 nCur = static_cast<sal_uInt16>(aSel.GetStart().GetPara()); + sal_uInt16 nCur = o3tl::narrowing<sal_uInt16>(aSel.GetStart().GetPara()); if(nCur > 40) nCur -= 40; else @@ -745,7 +745,7 @@ void SwSrcEditWindow::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) case SfxHintId::TextParaContentChanged: if ( !m_bHighlighting ) { - m_aSyntaxLineTable.insert( static_cast<sal_uInt16>(pTextHint->GetValue()) ); + m_aSyntaxLineTable.insert( o3tl::narrowing<sal_uInt16>(pTextHint->GetValue()) ); m_aSyntaxIdle.Start(); } break; diff --git a/sw/source/uibase/fldui/fldmgr.cxx b/sw/source/uibase/fldui/fldmgr.cxx index 90b12e34c32d..df3bcf4a6ba3 100644 --- a/sw/source/uibase/fldui/fldmgr.cxx +++ b/sw/source/uibase/fldui/fldmgr.cxx @@ -769,7 +769,7 @@ OUString SwFieldMgr::GetFormatStr(SwFieldTypesEnum nTypeId, sal_uInt32 nFormatId // determine FormatId from Pseudo-ID sal_uInt16 SwFieldMgr::GetFormatId(SwFieldTypesEnum nTypeId, sal_uInt32 nFormatId) const { - sal_uInt16 nId = static_cast<sal_uInt16>(nFormatId); + sal_uInt16 nId = o3tl::narrowing<sal_uInt16>(nFormatId); switch( nTypeId ) { case SwFieldTypesEnum::DocumentInfo: @@ -983,7 +983,7 @@ bool SwFieldMgr::InsertField( case SwFieldTypesEnum::Chapter: { - sal_uInt16 nByte = static_cast<sal_uInt16>(rData.m_sPar2.toInt32()); + sal_uInt16 nByte = o3tl::narrowing<sal_uInt16>(rData.m_sPar2.toInt32()); SwChapterFieldType* pTyp = static_cast<SwChapterFieldType*>( pCurShell->GetFieldType(0, SwFieldIds::Chapter) ); pField.reset(new SwChapterField(pTyp, nFormatId)); @@ -1078,7 +1078,7 @@ bool SwFieldMgr::InsertField( { SwGetRefFieldType* pTyp = static_cast<SwGetRefFieldType*>( pCurShell->GetFieldType(0, SwFieldIds::GetRef) ); - sal_uInt16 nSeqNo = static_cast<sal_uInt16>(rData.m_sPar2.toInt32()); + sal_uInt16 nSeqNo = o3tl::narrowing<sal_uInt16>(rData.m_sPar2.toInt32()); OUString sReferenceLanguage; // handle language-variant formats if (nFormatId >= SAL_N_ELEMENTS(FMT_REF_ARY)) @@ -1564,7 +1564,7 @@ void SwFieldMgr::UpdateCurField(sal_uInt32 nFormat, case SwFieldTypesEnum::Chapter: { - sal_uInt16 nByte = static_cast<sal_uInt16>(rPar2.toInt32()); + sal_uInt16 nByte = o3tl::narrowing<sal_uInt16>(rPar2.toInt32()); nByte = std::max(sal_uInt16(1), nByte); nByte = std::min(nByte, sal_uInt16(MAXLEVEL)); nByte -= 1; @@ -1618,10 +1618,10 @@ void SwFieldMgr::UpdateCurField(sal_uInt32 nFormat, case SwFieldTypesEnum::GetRef: { bSetPar2 = false; - static_cast<SwGetRefField*>(pTmpField.get())->SetSubType( static_cast<sal_uInt16>(rPar2.toInt32()) ); + static_cast<SwGetRefField*>(pTmpField.get())->SetSubType( o3tl::narrowing<sal_uInt16>(rPar2.toInt32()) ); const sal_Int32 nPos = rPar2.indexOf( '|' ); if( nPos>=0 ) - static_cast<SwGetRefField*>(pTmpField.get())->SetSeqNo( static_cast<sal_uInt16>(rPar2.copy( nPos + 1 ).toInt32())); + static_cast<SwGetRefField*>(pTmpField.get())->SetSeqNo( o3tl::narrowing<sal_uInt16>(rPar2.copy( nPos + 1 ).toInt32())); } break; case SwFieldTypesEnum::Dropdown: diff --git a/sw/source/uibase/frmdlg/colex.cxx b/sw/source/uibase/frmdlg/colex.cxx index 479311332f75..7fee7182ebb1 100644 --- a/sw/source/uibase/frmdlg/colex.cxx +++ b/sw/source/uibase/frmdlg/colex.cxx @@ -325,7 +325,7 @@ void SwColExample::DrawPage(vcl::RenderContext& rRenderContext, const Point& rOr SwColumnOnlyExample::SwColumnOnlyExample() : m_aFrameSize(SvxPaperInfo::GetPaperSize(PAPER_A4)) // DIN A4 { - ::FitToActualSize(m_aCols, static_cast<sal_uInt16>(m_aFrameSize.Width())); + ::FitToActualSize(m_aCols, o3tl::narrowing<sal_uInt16>(m_aFrameSize.Width())); } void SwColumnOnlyExample::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/) @@ -440,15 +440,15 @@ void SwColumnOnlyExample::SetColumns(const SwFormatCol& rCol) tools::Long nWish = pCol->GetWishWidth(); nWish *= nFrameWidth; nWish /= nWishSum; - pCol->SetWishWidth(static_cast<sal_uInt16>(nWish)); + pCol->SetWishWidth(o3tl::narrowing<sal_uInt16>(nWish)); tools::Long nLeft = pCol->GetLeft(); nLeft *= nFrameWidth; nLeft /= nWishSum; - pCol->SetLeft(static_cast<sal_uInt16>(nLeft)); + pCol->SetLeft(o3tl::narrowing<sal_uInt16>(nLeft)); tools::Long nRight = pCol->GetRight(); nRight *= nFrameWidth; nRight /= nWishSum; - pCol->SetRight(static_cast<sal_uInt16>(nRight)); + pCol->SetRight(o3tl::narrowing<sal_uInt16>(nRight)); } // #97495# make sure that the automatic column width's are always equal if(!(nColCount && m_aCols.IsOrtho())) diff --git a/sw/source/uibase/frmdlg/colmgr.cxx b/sw/source/uibase/frmdlg/colmgr.cxx index 32d777713fda..928b01c357e6 100644 --- a/sw/source/uibase/frmdlg/colmgr.cxx +++ b/sw/source/uibase/frmdlg/colmgr.cxx @@ -137,12 +137,12 @@ void SwColMgr::SetActualWidth(sal_uInt16 nW) SwColMgr::SwColMgr(const SfxItemSet& rSet) : aFormatCol(rSet.Get(RES_COL)) { - nWidth = static_cast<sal_uInt16>(rSet.Get(RES_FRM_SIZE).GetWidth()); + nWidth = o3tl::narrowing<sal_uInt16>(rSet.Get(RES_FRM_SIZE).GetWidth()); if (nWidth < MINLAY) nWidth = USHRT_MAX; const SvxLRSpaceItem& rLR = rSet.Get(RES_LR_SPACE); - nWidth = nWidth - static_cast<sal_uInt16>(rLR.GetLeft()); - nWidth = nWidth - static_cast<sal_uInt16>(rLR.GetRight()); + nWidth = nWidth - o3tl::narrowing<sal_uInt16>(rLR.GetLeft()); + nWidth = nWidth - o3tl::narrowing<sal_uInt16>(rLR.GetRight()); ::FitToActualSize(aFormatCol, nWidth); } diff --git a/sw/source/uibase/lingu/hhcwrp.cxx b/sw/source/uibase/lingu/hhcwrp.cxx index 5e4a7ef35273..498fb484c472 100644 --- a/sw/source/uibase/lingu/hhcwrp.cxx +++ b/sw/source/uibase/lingu/hhcwrp.cxx @@ -180,10 +180,10 @@ void SwHHCWrapper::SelectNewUnit_impl( sal_Int32 nUnitStart, sal_Int32 nUnitEnd pCursor->DeleteMark(); m_rWrtShell.Right( CRSR_SKIP_CHARS, /*bExpand*/ false, - static_cast<sal_uInt16>(m_nUnitOffset + nUnitStart), true ); + o3tl::narrowing<sal_uInt16>(m_nUnitOffset + nUnitStart), true ); pCursor->SetMark(); m_rWrtShell.Right( CRSR_SKIP_CHARS, /*bExpand*/ true, - static_cast<sal_uInt16>(nUnitEnd - nUnitStart), true ); + o3tl::narrowing<sal_uInt16>(nUnitEnd - nUnitStart), true ); // end selection now. Otherwise SHIFT+HOME (extending the selection) // won't work when the dialog is closed without any replacement. // (see #116346#) @@ -438,7 +438,7 @@ void SwHHCWrapper::ReplaceUnit( m_rWrtShell.Left( 0, true, aNewOrigText.getLength(), true, true ); } - pRuby->SetPosition( static_cast<sal_uInt16>(bRubyBelow) ); + pRuby->SetPosition( o3tl::narrowing<sal_uInt16>(bRubyBelow) ); pRuby->SetAdjustment( RubyAdjust_CENTER ); m_rWrtShell.SetAttrItem(*pRuby); diff --git a/sw/source/uibase/misc/glosdoc.cxx b/sw/source/uibase/misc/glosdoc.cxx index 9d7b95aae140..12b082e94b27 100644 --- a/sw/source/uibase/misc/glosdoc.cxx +++ b/sw/source/uibase/misc/glosdoc.cxx @@ -175,7 +175,7 @@ std::unique_ptr<SwTextBlocks> SwGlossaries::GetGroupDoc(const OUString &rName, bool SwGlossaries::NewGroupDoc(OUString& rGroupName, const OUString& rTitle) { const OUString sNewPath(rGroupName.getToken(1, GLOS_DELIM)); - sal_uInt16 nNewPath = static_cast<sal_uInt16>(sNewPath.toInt32()); + sal_uInt16 nNewPath = o3tl::narrowing<sal_uInt16>(sNewPath.toInt32()); if (static_cast<size_t>(nNewPath) >= m_PathArr.size()) return false; const OUString sNewFilePath(m_PathArr[nNewPath]); @@ -195,7 +195,7 @@ bool SwGlossaries::NewGroupDoc(OUString& rGroupName, const OUString& rTitle) bool SwGlossaries::RenameGroupDoc( const OUString& rOldGroup, OUString& rNewGroup, const OUString& rNewTitle ) { - sal_uInt16 nOldPath = static_cast<sal_uInt16>(rOldGroup.getToken(1, GLOS_DELIM).toInt32()); + sal_uInt16 nOldPath = o3tl::narrowing<sal_uInt16>(rOldGroup.getToken(1, GLOS_DELIM).toInt32()); if (static_cast<size_t>(nOldPath) >= m_PathArr.size()) return false; @@ -208,7 +208,7 @@ bool SwGlossaries::RenameGroupDoc( return false; } - sal_uInt16 nNewPath = static_cast<sal_uInt16>(rNewGroup.getToken(1, GLOS_DELIM).toInt32()); + sal_uInt16 nNewPath = o3tl::narrowing<sal_uInt16>(rNewGroup.getToken(1, GLOS_DELIM).toInt32()); if (static_cast<size_t>(nNewPath) >= m_PathArr.size()) return false; @@ -246,7 +246,7 @@ bool SwGlossaries::RenameGroupDoc( // Deletes a text block group bool SwGlossaries::DelGroupDoc(const OUString &rName) { - sal_uInt16 nPath = static_cast<sal_uInt16>(rName.getToken(1, GLOS_DELIM).toInt32()); + sal_uInt16 nPath = o3tl::narrowing<sal_uInt16>(rName.getToken(1, GLOS_DELIM).toInt32()); if (static_cast<size_t>(nPath) >= m_PathArr.size()) return false; const OUString sBaseName(rName.getToken(0, GLOS_DELIM)); @@ -269,7 +269,7 @@ SwGlossaries::~SwGlossaries() // read a block document std::unique_ptr<SwTextBlocks> SwGlossaries::GetGlosDoc( const OUString &rName, bool bCreate ) const { - sal_uInt16 nPath = static_cast<sal_uInt16>(rName.getToken(1, GLOS_DELIM).toInt32()); + sal_uInt16 nPath = o3tl::narrowing<sal_uInt16>(rName.getToken(1, GLOS_DELIM).toInt32()); std::unique_ptr<SwTextBlocks> pTmp; if (static_cast<size_t>(nPath) < m_PathArr.size()) { diff --git a/sw/source/uibase/ribbar/inputwin.cxx b/sw/source/uibase/ribbar/inputwin.cxx index 5ba12dec0e76..1032f5e68072 100644 --- a/sw/source/uibase/ribbar/inputwin.cxx +++ b/sw/source/uibase/ribbar/inputwin.cxx @@ -515,11 +515,11 @@ void InputEdit::UpdateRange(std::u16string_view rBoxes, m_xWidget->get_selection_bounds(nSelStartPos, nSelEndPos); Selection aSelection(nSelStartPos, nSelEndPos); - sal_uInt16 nSel = static_cast<sal_uInt16>(aSelection.Len()); + sal_uInt16 nSel = o3tl::narrowing<sal_uInt16>(aSelection.Len()); // OS: The following expression ensures that in the overwrite mode, // the selected closing parenthesis will be not deleted. if( nSel && ( nSel > 1 || - m_xWidget->get_text()[ static_cast<sal_uInt16>(aSelection.Min()) ] != cClose )) + m_xWidget->get_text()[ o3tl::narrowing<sal_uInt16>(aSelection.Min()) ] != cClose )) m_xWidget->cut_clipboard(); else aSelection.Max() = aSelection.Min(); @@ -538,7 +538,7 @@ void InputEdit::UpdateRange(std::u16string_view rBoxes, { bool bFound = false; sal_Unicode cCh; - sal_uInt16 nPos, nEndPos = 0, nStartPos = static_cast<sal_uInt16>(aSelection.Min()); + sal_uInt16 nPos, nEndPos = 0, nStartPos = o3tl::narrowing<sal_uInt16>(aSelection.Min()); if( nStartPos-- ) { do { @@ -565,7 +565,7 @@ void InputEdit::UpdateRange(std::u16string_view rBoxes, } // Only if the current position lies in the range or right behind. if( bFound && ( nStartPos >= o3tl::make_unsigned(aSelection.Max()) || - static_cast<sal_uInt16>(aSelection.Max()) > nEndPos + 1 )) + o3tl::narrowing<sal_uInt16>(aSelection.Max()) > nEndPos + 1 )) bFound = false; } if( bFound ) @@ -577,7 +577,7 @@ void InputEdit::UpdateRange(std::u16string_view rBoxes, else { OUString aTmp = OUStringChar(cOpen) + aBoxes + OUStringChar(cClose); - nPos = static_cast<sal_uInt16>(aSelection.Min()); + nPos = o3tl::narrowing<sal_uInt16>(aSelection.Min()); aActText = aActText.replaceAt( nPos, 0, aTmp ); nPos = nPos + aTmp.getLength(); } diff --git a/sw/source/uibase/ribbar/workctrl.cxx b/sw/source/uibase/ribbar/workctrl.cxx index 9e7491db8de1..52c3a572dee2 100644 --- a/sw/source/uibase/ribbar/workctrl.cxx +++ b/sw/source/uibase/ribbar/workctrl.cxx @@ -98,7 +98,7 @@ void SwTbxAutoTextCtrl::CreatePopupWindow() const sal_uInt16 nBlockCount = pGlossaryList->GetBlockCount(i -1); if(nBlockCount) { - sal_uInt16 nIndex = static_cast<sal_uInt16>(100*i); + sal_uInt16 nIndex = o3tl::narrowing<sal_uInt16>(100*i); // but insert without extension pPopup->InsertItem( i, sTitle); VclPtrInstance<PopupMenu> pSub; @@ -410,7 +410,7 @@ void SwZoomBox_Impl::Select() { bNonNumeric = false; - sal_uInt16 nZoom = static_cast<sal_uInt16>(sEntry.toInt32()); + sal_uInt16 nZoom = o3tl::narrowing<sal_uInt16>(sEntry.toInt32()); if(nZoom < MINZOOM) nZoom = MINZOOM; if(nZoom > MAXZOOM) @@ -564,7 +564,7 @@ IMPL_LINK_NOARG(SwJumpToSpecificBox_Impl, SelectHdl, weld::Entry&, bool) { OUString sEntry(m_xWidget->get_text()); SfxUInt16Item aPageNum(nSlotId); - aPageNum.SetValue(static_cast<sal_uInt16>(sEntry.toInt32())); + aPageNum.SetValue(o3tl::narrowing<sal_uInt16>(sEntry.toInt32())); SfxObjectShell* pCurrentShell = SfxObjectShell::Current(); pCurrentShell->GetDispatcher()->ExecuteList(nSlotId, SfxCallMode::ASYNCHRON, { &aPageNum }); diff --git a/sw/source/uibase/shells/basesh.cxx b/sw/source/uibase/shells/basesh.cxx index b8e2cf281c67..760f32a59e53 100644 --- a/sw/source/uibase/shells/basesh.cxx +++ b/sw/source/uibase/shells/basesh.cxx @@ -972,7 +972,7 @@ void SwBaseShell::Execute(SfxRequest &rReq) // RepeatHeaderLines if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_4, true, &pItem)) aInsTableOpts.mnRowsToRepeat = - static_cast<sal_uInt16>(static_cast< const SfxInt16Item* >(pItem)->GetValue()); + o3tl::narrowing<sal_uInt16>(static_cast< const SfxInt16Item* >(pItem)->GetValue()); //WithBorder if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_5, true, &pItem) && static_cast< const SfxBoolItem* >(pItem)->GetValue()) diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx index 158ba5626915..905471f4e869 100644 --- a/sw/source/uibase/shells/textfld.cxx +++ b/sw/source/uibase/shells/textfld.cxx @@ -975,7 +975,7 @@ void SwTextShell::InsertHyperlink(const SvxHyperlinkItem& rHlnkItem) const OUString& rName = rHlnkItem.GetName(); const OUString& rURL = rHlnkItem.GetURL(); const OUString& rTarget = rHlnkItem.GetTargetFrame(); - sal_uInt16 nType = static_cast<sal_uInt16>(rHlnkItem.GetInsertMode()); + sal_uInt16 nType = o3tl::narrowing<sal_uInt16>(rHlnkItem.GetInsertMode()); nType &= ~HLINK_HTMLMODE; const SvxMacroTableDtor* pMacroTable = rHlnkItem.GetMacroTable(); diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx index 93a9bc35b522..010c8551c810 100644 --- a/sw/source/uibase/shells/textsh1.cxx +++ b/sw/source/uibase/shells/textsh1.cxx @@ -1013,7 +1013,7 @@ void SwTextShell::Execute(SfxRequest &rReq) const SvxTabStopItem& rDefTabs = GetPool().GetDefaultItem(RES_PARATR_TABSTOP); - const sal_uInt16 nDefDist = static_cast<sal_uInt16>(::GetTabDist( rDefTabs )); + const sal_uInt16 nDefDist = o3tl::narrowing<sal_uInt16>(::GetTabDist( rDefTabs )); SfxUInt16Item aDefDistItem( SID_ATTR_TABSTOP_DEFAULTS, nDefDist ); aCoreSet.Put( aDefDistItem ); diff --git a/sw/source/uibase/uiview/pview.cxx b/sw/source/uibase/uiview/pview.cxx index 04ff8a593306..9ca718e016f6 100644 --- a/sw/source/uibase/uiview/pview.cxx +++ b/sw/source/uibase/uiview/pview.cxx @@ -1434,7 +1434,7 @@ IMPL_LINK( SwPagePreview, EndScrollHdl, ScrollBar *, p, void ) if ( GetViewShell()->PagePreviewLayout()->DoesPreviewLayoutRowsFitIntoWindow() ) { // Scroll how many pages ?? - const sal_uInt16 nThmbPos = static_cast<sal_uInt16>(pScrollbar->GetThumbPos()); + const sal_uInt16 nThmbPos = o3tl::narrowing<sal_uInt16>(pScrollbar->GetThumbPos()); // adjust to new preview functionality if( nThmbPos != m_pViewWin->SelectedPage() ) { diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx index 56af6085b6af..2590b3afe94d 100644 --- a/sw/source/uibase/uiview/view.cxx +++ b/sw/source/uibase/uiview/view.cxx @@ -1215,7 +1215,7 @@ void SwView::ReadUserData( const OUString &rUserData, bool bBrowse ) sal_Int32 nOff = 0; SvxZoomType eZoom; if( !m_pWrtShell->GetViewOptions()->getBrowseMode() ) - eZoom = static_cast<SvxZoomType>(static_cast<sal_uInt16>(rUserData.getToken(nOff, ';', nPos ).toInt32())); + eZoom = static_cast<SvxZoomType>(o3tl::narrowing<sal_uInt16>(rUserData.getToken(nOff, ';', nPos ).toInt32())); else { eZoom = SvxZoomType::PERCENT; diff --git a/sw/source/uibase/uiview/viewmdi.cxx b/sw/source/uibase/uiview/viewmdi.cxx index f2d3c5747d9e..8d986a6d056d 100644 --- a/sw/source/uibase/uiview/viewmdi.cxx +++ b/sw/source/uibase/uiview/viewmdi.cxx @@ -155,7 +155,7 @@ void SwView::SetZoom_( const Size &rEditSize, SvxZoomType eZoomType, } nFac = std::max( tools::Long( MINZOOM ), nFac ); - const sal_uInt16 nZoomFac = static_cast<sal_uInt16>(nFac); + const sal_uInt16 nZoomFac = o3tl::narrowing<sal_uInt16>(nFac); SwViewOption aOpt( *pOpt ); if ( !GetViewFrame()->GetFrame().IsInPlace() ) diff --git a/sw/source/uibase/uiview/viewsrch.cxx b/sw/source/uibase/uiview/viewsrch.cxx index 3b4b4375a966..614c5606da7a 100644 --- a/sw/source/uibase/uiview/viewsrch.cxx +++ b/sw/source/uibase/uiview/viewsrch.cxx @@ -606,7 +606,7 @@ bool SwView::SearchAll() m_pWrtShell->StartOfSection(); } s_bExtra = false; - sal_uInt16 nFound = static_cast<sal_uInt16>(FUNC_Search( aOpts )); + sal_uInt16 nFound = o3tl::narrowing<sal_uInt16>(FUNC_Search( aOpts )); s_bFound = 0 != nFound; m_pWrtShell->EndAllAction(); diff --git a/sw/source/uibase/uiview/viewstat.cxx b/sw/source/uibase/uiview/viewstat.cxx index 06b740042bb0..e2606091bb72 100644 --- a/sw/source/uibase/uiview/viewstat.cxx +++ b/sw/source/uibase/uiview/viewstat.cxx @@ -305,7 +305,7 @@ void SwView::GetState(SfxItemSet &rSet) { const SvxTabStopItem& rDefTabs = m_pWrtShell->GetDefault(RES_PARATR_TABSTOP); rSet.Put( SfxUInt16Item( nWhich, - static_cast<sal_uInt16>(::GetTabDist(rDefTabs)))); + o3tl::narrowing<sal_uInt16>(::GetTabDist(rDefTabs)))); } break; case SID_ATTR_LANGUAGE: diff --git a/sw/source/uibase/uiview/viewtab.cxx b/sw/source/uibase/uiview/viewtab.cxx index 73da69f4f326..3a1bd7e2b1bd 100644 --- a/sw/source/uibase/uiview/viewtab.cxx +++ b/sw/source/uibase/uiview/viewtab.cxx @@ -125,7 +125,7 @@ static void lcl_ConvertToCols(const SvxColumnItem& rColItem, { OSL_ENSURE(rColItem[i+1].nStart >= rColItem[i].nEnd,"overlapping columns" ); const tools::Long nStart = std::max(rColItem[i+1].nStart, rColItem[i].nEnd); - const sal_uInt16 nRight = static_cast<sal_uInt16>((nStart - rColItem[i].nEnd) / 2); + const sal_uInt16 nRight = o3tl::narrowing<sal_uInt16>((nStart - rColItem[i].nEnd) / 2); const tools::Long nWidth = rColItem[i].nEnd - rColItem[i].nStart + nLeft + nRight; @@ -141,7 +141,7 @@ static void lcl_ConvertToCols(const SvxColumnItem& rColItem, // The difference between the total sum of the desired width and the so far // calculated columns and margins should result in the width of the last column. - rArr[rColItem.Count()-1].SetWishWidth( rCols.GetWishWidth() - static_cast<sal_uInt16>(nSumAll) ); + rArr[rColItem.Count()-1].SetWishWidth( rCols.GetWishWidth() - o3tl::narrowing<sal_uInt16>(nSumAll) ); rCols.SetOrtho(false, 0, 0 ); } @@ -204,23 +204,23 @@ static void ResizeFrameCols(SwFormatCol& rCol, SwColumn* pCol = &i; tools::Long nVal = pCol->GetWishWidth(); lcl_Scale(nVal, nScale); - pCol->SetWishWidth(static_cast<sal_uInt16>(nVal)); + pCol->SetWishWidth(o3tl::narrowing<sal_uInt16>(nVal)); nVal = pCol->GetLeft(); lcl_Scale(nVal, nScale); - pCol->SetLeft(static_cast<sal_uInt16>(nVal)); + pCol->SetLeft(o3tl::narrowing<sal_uInt16>(nVal)); nVal = pCol->GetRight(); lcl_Scale(nVal, nScale); - pCol->SetRight(static_cast<sal_uInt16>(nVal)); + pCol->SetRight(o3tl::narrowing<sal_uInt16>(nVal)); } lcl_Scale(nNewWishWidth, nScale); lcl_Scale(nWishDiff, nScale); } - rCol.SetWishWidth( static_cast<sal_uInt16>(nNewWishWidth) ); + rCol.SetWishWidth( o3tl::narrowing<sal_uInt16>(nNewWishWidth) ); if( nLeftDelta >= 2 || nLeftDelta <= -2) - rArr.front().SetWishWidth(rArr.front().GetWishWidth() + static_cast<sal_uInt16>(nWishDiff)); + rArr.front().SetWishWidth(rArr.front().GetWishWidth() + o3tl::narrowing<sal_uInt16>(nWishDiff)); else - rArr.back().SetWishWidth(rArr.back().GetWishWidth() + static_cast<sal_uInt16>(nWishDiff)); + rArr.back().SetWishWidth(rArr.back().GetWishWidth() + o3tl::narrowing<sal_uInt16>(nWishDiff)); // Reset auto width rCol.SetOrtho(false, 0, 0 ); } @@ -510,9 +510,9 @@ void SwView::ExecTabWin( SfxRequest const & rReq ) const bool bHead = bool(nFrameType & FrameTypeFlags::HEADER); SvxULSpaceItem aUL( rDesc.GetMaster().GetULSpace() ); if ( bHead ) - aUL.SetUpper( static_cast<sal_uInt16>(aLongULSpace.GetUpper()) ); + aUL.SetUpper( o3tl::narrowing<sal_uInt16>(aLongULSpace.GetUpper()) ); else - aUL.SetLower( static_cast<sal_uInt16>(aLongULSpace.GetLower()) ); + aUL.SetLower( o3tl::narrowing<sal_uInt16>(aLongULSpace.GetLower()) ); aDesc.GetMaster().SetFormatAttr( aUL ); if( (bHead && pHeaderFormat) || (!bHead && pFooterFormat) ) @@ -531,8 +531,8 @@ void SwView::ExecTabWin( SfxRequest const & rReq ) else { SvxULSpaceItem aUL(RES_UL_SPACE); - aUL.SetUpper(static_cast<sal_uInt16>(aLongULSpace.GetUpper())); - aUL.SetLower(static_cast<sal_uInt16>(aLongULSpace.GetLower())); + aUL.SetUpper(o3tl::narrowing<sal_uInt16>(aLongULSpace.GetUpper())); + aUL.SetLower(o3tl::narrowing<sal_uInt16>(aLongULSpace.GetLower())); aDesc.GetMaster().SetFormatAttr(aUL); } @@ -550,8 +550,8 @@ void SwView::ExecTabWin( SfxRequest const & rReq ) SwPageDesc aDesc( rDesc ); { SvxULSpaceItem aUL(RES_UL_SPACE); - aUL.SetUpper(static_cast<sal_uInt16>(aLongULSpace.GetUpper())); - aUL.SetLower(static_cast<sal_uInt16>(aLongULSpace.GetLower())); + aUL.SetUpper(o3tl::narrowing<sal_uInt16>(aLongULSpace.GetUpper())); + aUL.SetLower(o3tl::narrowing<sal_uInt16>(aLongULSpace.GetLower())); aDesc.GetMaster().SetFormatAttr(aUL); } rSh.ChgPageDesc( nDescId, aDesc ); @@ -1956,8 +1956,8 @@ void SwView::StateTabWin(SfxItemSet& rSet) aRect.Pos() += aTmpRect.Pos(); // make relative to page position: - aColItem.SetLeft (static_cast<sal_uInt16>( aRect.Left() - rPageRect.Left() )); - aColItem.SetRight(static_cast<sal_uInt16>( rPageRect.Right() - aRect.Right())); + aColItem.SetLeft (o3tl::narrowing<sal_uInt16>( aRect.Left() - rPageRect.Left() )); + aColItem.SetRight(o3tl::narrowing<sal_uInt16>( rPageRect.Right() - aRect.Right())); } aColItem.SetOrtho(aColItem.CalcOrtho()); @@ -2028,12 +2028,12 @@ void SwView::StateTabWin(SfxItemSet& rSet) { if (bVerticalWriting) { - aColItem.SetLeft(static_cast<sal_uInt16>(rPagePrtRect.Top())); + aColItem.SetLeft(o3tl::narrowing<sal_uInt16>(rPagePrtRect.Top())); aColItem.SetRight(sal_uInt16(nPageHeight - rPagePrtRect.Bottom())); } else { - aColItem.SetLeft(static_cast<sal_uInt16>(rPagePrtRect.Left())); + aColItem.SetLeft(o3tl::narrowing<sal_uInt16>(rPagePrtRect.Left())); aColItem.SetRight(sal_uInt16(nPageWidth - rPagePrtRect.Right())); } } @@ -2203,9 +2203,9 @@ void SwView::StateTabWin(SfxItemSet& rSet) : CurRectType::Page, pPt )); // The width of the frame or within the page margins. - const sal_uInt16 nTotalWidth = static_cast<sal_uInt16>(aRect.Width()); + const sal_uInt16 nTotalWidth = o3tl::narrowing<sal_uInt16>(aRect.Width()); // The entire frame width - The difference is twice the distance to the edge. - const sal_uInt16 nOuterWidth = static_cast<sal_uInt16>(aAbsRect.Width()); + const sal_uInt16 nOuterWidth = o3tl::narrowing<sal_uInt16>(aAbsRect.Width()); int nWidth = 0, nEnd = 0; aRectangle.SetLeft( 0 ); @@ -2325,7 +2325,7 @@ void SwView::StateTabWin(SfxItemSet& rSet) aRect.Pos() += rSh.GetAnyCurRect( CurRectType::FlyEmbedded, pPt ).Pos(); - const sal_uInt16 nTotalWidth = static_cast<sal_uInt16>(aRect.Width()); + const sal_uInt16 nTotalWidth = o3tl::narrowing<sal_uInt16>(aRect.Width()); // Initialize nStart and nEnd for nNum == 0 int nWidth = 0, nStart = 0, @@ -2341,7 +2341,7 @@ void SwView::StateTabWin(SfxItemSet& rSet) { const SwColumn* pCol = &rCols[i]; nStart = pCol->GetLeft() + nWidth; - nWidth += pCols->CalcColWidth( static_cast<sal_uInt16>(i), nTotalWidth ); + nWidth += pCols->CalcColWidth( o3tl::narrowing<sal_uInt16>(i), nTotalWidth ); nEnd = nWidth - pCol->GetRight(); } if( bFrame || bColSct ) diff --git a/sw/source/uibase/uno/unoatxt.cxx b/sw/source/uibase/uno/unoatxt.cxx index 754f4debef14..45f12f7b5b10 100644 --- a/sw/source/uibase/uno/unoatxt.cxx +++ b/sw/source/uibase/uno/unoatxt.cxx @@ -497,7 +497,7 @@ uno::Any SwXAutoTextGroup::getByIndex(sal_Int32 nIndex) const sal_uInt16 nCount = pGlosGroup->GetCount(); if (nIndex < 0 || nIndex >= static_cast<sal_Int32>(nCount)) throw lang::IndexOutOfBoundsException(); - return getByName(pGlosGroup->GetShortName(static_cast<sal_uInt16>(nIndex))); + return getByName(pGlosGroup->GetShortName(o3tl::narrowing<sal_uInt16>(nIndex))); } uno::Type SwXAutoTextGroup::getElementType() diff --git a/sw/source/uibase/uno/unomod.cxx b/sw/source/uibase/uno/unomod.cxx index e2662e00e342..fa1c432d7591 100644 --- a/sw/source/uibase/uno/unomod.cxx +++ b/sw/source/uibase/uno/unomod.cxx @@ -645,7 +645,7 @@ void SwXViewSettings::_setSingleValue( const comphelper::PropertyInfo & rInfo, c sal_Int16 nZoom = 0; if(!(rValue >>= nZoom) || nZoom > MAXZOOM || nZoom < MINZOOM) throw lang::IllegalArgumentException(); - mpViewOption->SetZoom(static_cast<sal_uInt16>(nZoom)); + mpViewOption->SetZoom(o3tl::narrowing<sal_uInt16>(nZoom)); mbApplyZoom = true; } break; diff --git a/sw/source/uibase/utlui/bookctrl.cxx b/sw/source/uibase/utlui/bookctrl.cxx index f47bfe735ec9..c82d40acfae8 100644 --- a/sw/source/uibase/utlui/bookctrl.cxx +++ b/sw/source/uibase/utlui/bookctrl.cxx @@ -93,7 +93,7 @@ void SwBookmarkControl::Command( const CommandEvent& rCEvt ) if(IDocumentMarkAccess::MarkType::BOOKMARK == IDocumentMarkAccess::GetType(**ppBookmark)) { xPopup->append(OUString::number(nPopupId), (*ppBookmark)->GetName()); - aBookmarkIdx[nPopupId] = static_cast<sal_uInt16>(ppBookmark - ppBookmarkStart); + aBookmarkIdx[nPopupId] = o3tl::narrowing<sal_uInt16>(ppBookmark - ppBookmarkStart); nPopupId++; } } diff --git a/sw/source/uibase/utlui/gloslst.cxx b/sw/source/uibase/utlui/gloslst.cxx index 46b44ecf567d..3bcc3ea299c9 100644 --- a/sw/source/uibase/utlui/gloslst.cxx +++ b/sw/source/uibase/utlui/gloslst.cxx @@ -287,7 +287,7 @@ void SwGlossaryList::Update() OUString sName( aTitle.copy( 0, aTitle.getLength() - sExt.getLength() )); aFoundGroupNames.push_back(sName); - sName += OUStringChar(GLOS_DELIM) + OUString::number( static_cast<sal_uInt16>(nPath) ); + sName += OUStringChar(GLOS_DELIM) + OUString::number( o3tl::narrowing<sal_uInt16>(nPath) ); AutoTextGroup* pFound = FindGroup( sName ); if( !pFound ) { diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx index 19b5945ccc5a..bb14ad2594ec 100644 --- a/sw/source/uibase/wrtsh/wrtsh1.cxx +++ b/sw/source/uibase/wrtsh/wrtsh1.cxx @@ -1111,7 +1111,7 @@ void SwWrtShell::NumOrBulletOn(bool bNum) OSL_ENSURE( pColl->IsAssignedToListLevelOfOutlineStyle(), "<SwWrtShell::NumOrBulletOn(..)> - paragraph style with outline rule, but no outline level" ); if ( pColl->IsAssignedToListLevelOfOutlineStyle() && - pCollRule->Get( static_cast<sal_uInt16>(nActivateOutlineLvl) ).GetNumberingType() + pCollRule->Get( o3tl::narrowing<sal_uInt16>(nActivateOutlineLvl) ).GetNumberingType() == SVX_NUM_NUMBER_NONE ) { // activate outline numbering @@ -1138,7 +1138,7 @@ void SwWrtShell::NumOrBulletOn(bool bNum) // Check, if corresponding list level of the outline numbering // has already a numbering format set. nActivateOutlineLvl = pColl->GetAssignedOutlineStyleLevel(); - if ( pCollRule->Get( static_cast<sal_uInt16>(nActivateOutlineLvl) ).GetNumberingType() + if ( pCollRule->Get( o3tl::narrowing<sal_uInt16>(nActivateOutlineLvl) ).GetNumberingType() == SVX_NUM_NUMBER_NONE ) { // activate outline numbering, because from the precondition @@ -1159,7 +1159,7 @@ void SwWrtShell::NumOrBulletOn(bool bNum) OSL_ENSURE( pColl->IsAssignedToListLevelOfOutlineStyle(), "<SwWrtShell::NumOrBulletOn(..)> - paragraph style with outline rule, but no outline level" ); if ( pColl->IsAssignedToListLevelOfOutlineStyle() && - pCollRule->Get( static_cast<sal_uInt16>(nActivateOutlineLvl) ).GetNumberingType() + pCollRule->Get( o3tl::narrowing<sal_uInt16>(nActivateOutlineLvl) ).GetNumberingType() == SVX_NUM_NUMBER_NONE ) { // activate outline numbering @@ -1224,7 +1224,7 @@ void SwWrtShell::NumOrBulletOn(bool bNum) if (nLevel >= MAXLEVEL) nLevel = MAXLEVEL - 1; - SwNumFormat aFormat(aNumRule.Get(static_cast<sal_uInt16>(nLevel))); + SwNumFormat aFormat(aNumRule.Get(o3tl::narrowing<sal_uInt16>(nLevel))); if (bNum) aFormat.SetNumberingType(SVX_NUM_ARABIC); @@ -1242,7 +1242,7 @@ void SwWrtShell::NumOrBulletOn(bool bNum) aFormat.SetPrefix(OUString()); aFormat.SetSuffix(OUString()); } - aNumRule.Set(static_cast<sal_uInt16>(nLevel), aFormat); + aNumRule.Set(o3tl::narrowing<sal_uInt16>(nLevel), aFormat); } } @@ -1396,7 +1396,7 @@ void SwWrtShell::NumOrBulletOff() if (nLevel >= MAXLEVEL) nLevel = MAXLEVEL - 1; - SwNumFormat aFormat(aNumRule.Get(static_cast<sal_uInt16>(nLevel))); + SwNumFormat aFormat(aNumRule.Get(o3tl::narrowing<sal_uInt16>(nLevel))); aFormat.SetNumberingType(SVX_NUM_NUMBER_NONE); aNumRule.Set(nLevel, aFormat); |