diff options
186 files changed, 641 insertions, 638 deletions
diff --git a/sw/inc/calc.hxx b/sw/inc/calc.hxx index 7590680d72c5..4121cc7f0e72 100644 --- a/sw/inc/calc.hxx +++ b/sw/inc/calc.hxx @@ -27,6 +27,7 @@ #include <rtl/ustrbuf.hxx> #include <tools/solar.h> #include <tools/long.hxx> +#include <o3tl/safeint.hxx> #include "swdllapi.h" class CharClass; @@ -167,7 +168,7 @@ public: ii %= nTableSize; if( pPos ) - *pPos = static_cast<sal_uInt16>(ii); + *pPos = o3tl::narrowing<sal_uInt16>(ii); for( T* pEntry = m_aData[ii].get(); pEntry; pEntry = static_cast<T*>(pEntry->pNext.get()) ) { diff --git a/sw/inc/swtable.hxx b/sw/inc/swtable.hxx index 6696c94d6cfc..6b27c9ea21e4 100644 --- a/sw/inc/swtable.hxx +++ b/sw/inc/swtable.hxx @@ -192,7 +192,7 @@ public: /// Set the new table style name for this table. void SetTableStyleName(const OUString& rName) { maTableStyleName = rName; } - sal_uInt16 GetRowsToRepeat() const { return std::min( static_cast<sal_uInt16>(GetTabLines().size()), m_nRowsToRepeat ); } + sal_uInt16 GetRowsToRepeat() const { return std::min( o3tl::narrowing<sal_uInt16>(GetTabLines().size()), m_nRowsToRepeat ); } void SetRowsToRepeat( sal_uInt16 nNumOfRows ) { m_nRowsToRepeat = nNumOfRows; } bool IsHeadline( const SwTableLine& rLine ) const; diff --git a/sw/qa/core/doc/doc.cxx b/sw/qa/core/doc/doc.cxx index 68d5992b05be..00b8df8a3c41 100644 --- a/sw/qa/core/doc/doc.cxx +++ b/sw/qa/core/doc/doc.cxx @@ -66,8 +66,8 @@ CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testTextboxTextRotateAngle) SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "textbox-textrotateangle.odt"); SwFrameFormats& rFrameFormats = *pDoc->GetSpzFrameFormats(); CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rFrameFormats.size()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(RES_DRAWFRMFMT), rFrameFormats[0]->Which()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(RES_FLYFRMFMT), rFrameFormats[1]->Which()); + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(RES_DRAWFRMFMT), rFrameFormats[0]->Which()); + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(RES_FLYFRMFMT), rFrameFormats[1]->Which()); SvxFrameDirection eActual = rFrameFormats[1]->GetAttrSet().GetItem(RES_FRAMEDIR)->GetValue(); // Without the accompanying fix in place, this test would have failed with: diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx index d5efe8a29677..13ace3b1a1fa 100644 --- a/sw/qa/extras/odfexport/odfexport.cxx +++ b/sw/qa/extras/odfexport/odfexport.cxx @@ -2951,7 +2951,7 @@ DECLARE_ODFEXPORT_TEST(testArabicZeroNumbering, "arabic-zero-numbering.odt") // - Expected: 64 // - Actual : 4 // i.e. numbering type was ARABIC, not ARABIC_ZERO. - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(style::NumberingType::ARABIC_ZERO), + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(style::NumberingType::ARABIC_ZERO), aMap["NumberingType"].get<sal_uInt16>()); } @@ -2965,7 +2965,7 @@ DECLARE_ODFEXPORT_TEST(testArabicZero3Numbering, "arabic-zero3-numbering.odt") // - Expected: 65 // - Actual : 4 // i.e. numbering type was ARABIC, not ARABIC_ZERO3. - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(style::NumberingType::ARABIC_ZERO3), + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(style::NumberingType::ARABIC_ZERO3), aMap["NumberingType"].get<sal_uInt16>()); } @@ -2979,7 +2979,7 @@ DECLARE_ODFEXPORT_TEST(testArabicZero4Numbering, "arabic-zero4-numbering.odt") // - Expected: 66 // - Actual : 4 // i.e. numbering type was ARABIC, not ARABIC_ZERO4. - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(style::NumberingType::ARABIC_ZERO4), + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(style::NumberingType::ARABIC_ZERO4), aMap["NumberingType"].get<sal_uInt16>()); } @@ -2993,7 +2993,7 @@ DECLARE_ODFEXPORT_TEST(testArabicZero5Numbering, "arabic-zero5-numbering.odt") // - Expected: 67 // - Actual : 4 // i.e. numbering type was ARABIC, not ARABIC_ZERO5. - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(style::NumberingType::ARABIC_ZERO5), + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(style::NumberingType::ARABIC_ZERO5), aMap["NumberingType"].get<sal_uInt16>()); } @@ -3007,7 +3007,7 @@ DECLARE_ODFEXPORT_TEST(testRovasNumbering, "rovas-numbering.odt") // - Expected: 68 // - Actual : 4 // i.e. numbering type was ARABIC, not SZEKELY_ROVAS. - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(style::NumberingType::SZEKELY_ROVAS), + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(style::NumberingType::SZEKELY_ROVAS), aMap["NumberingType"].get<sal_uInt16>()); } diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx index 5f3fc94cd8e4..40bcaaa5875b 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx @@ -339,8 +339,8 @@ DECLARE_OOXMLEXPORT_TEST(testBtlrShape, "btlr-textbox.docx") SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc(); const SwFrameFormats& rFormats = *pDoc->GetSpzFrameFormats(); CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rFormats.size()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(RES_DRAWFRMFMT), rFormats[0]->Which()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(RES_FLYFRMFMT), rFormats[1]->Which()); + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(RES_DRAWFRMFMT), rFormats[0]->Which()); + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(RES_FLYFRMFMT), rFormats[1]->Which()); // Without the accompanying fix in place, this test would have failed with 'Expected: 5, Actual: // 4', i.e. the textbox inherited its writing direction instead of having an explicit btlr // value. diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx index 24f51850e4ff..293f82ed9c87 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx @@ -363,7 +363,7 @@ DECLARE_ODFEXPORT_TEST(testArabicZeroNumbering, "arabic-zero-numbering.docx") // - Expected: 64 // - Actual : 4 // i.e. numbering type was ARABIC, not ARABIC_ZERO. - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(style::NumberingType::ARABIC_ZERO), + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(style::NumberingType::ARABIC_ZERO), aMap["NumberingType"].get<sal_uInt16>()); } @@ -376,7 +376,7 @@ DECLARE_ODFEXPORT_TEST(testArabicZero3Numbering, "arabic-zero3-numbering.docx") // - Expected: 65 // - Actual : 4 // i.e. numbering type was ARABIC, not ARABIC_ZERO3. - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(style::NumberingType::ARABIC_ZERO3), + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(style::NumberingType::ARABIC_ZERO3), aMap["NumberingType"].get<sal_uInt16>()); } @@ -389,7 +389,7 @@ DECLARE_ODFEXPORT_TEST(testArabicZero4Numbering, "arabic-zero4-numbering.docx") // - Expected: 66 // - Actual : 4 // i.e. numbering type was ARABIC, not ARABIC_ZERO4. - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(style::NumberingType::ARABIC_ZERO4), + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(style::NumberingType::ARABIC_ZERO4), aMap["NumberingType"].get<sal_uInt16>()); } @@ -402,7 +402,7 @@ DECLARE_ODFEXPORT_TEST(testArabicZero5Numbering, "arabic-zero5-numbering.docx") // - Expected: 67 // - Actual : 4 // i.e. numbering type was ARABIC, not ARABIC_ZERO5. - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(style::NumberingType::ARABIC_ZERO5), + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(style::NumberingType::ARABIC_ZERO5), aMap["NumberingType"].get<sal_uInt16>()); } diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx index 049c78bd7f6b..75c4382324e5 100644 --- a/sw/qa/extras/rtfexport/rtfexport.cxx +++ b/sw/qa/extras/rtfexport/rtfexport.cxx @@ -1135,8 +1135,8 @@ DECLARE_RTFEXPORT_TEST(testCustomDocProps, "custom-doc-props.rtf") // Test roundtrip of date in general, and year/month/day in particular. util::DateTime aDate = getProperty<util::DateTime>(xUserDefinedProperties, "d"); CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(2016), aDate.Year); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(1), aDate.Month); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(30), aDate.Day); + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(1), aDate.Month); + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(30), aDate.Day); // Test real number. CPPUNIT_ASSERT_EQUAL(3.14, getProperty<double>(xUserDefinedProperties, "pi")); diff --git a/sw/qa/extras/rtfexport/rtfexport3.cxx b/sw/qa/extras/rtfexport/rtfexport3.cxx index 4468a97650b5..efbb7c806477 100644 --- a/sw/qa/extras/rtfexport/rtfexport3.cxx +++ b/sw/qa/extras/rtfexport/rtfexport3.cxx @@ -187,7 +187,7 @@ DECLARE_ODFEXPORT_TEST(testArabicZeroNumbering, "arabic-zero-numbering.rtf") // - Expected: 64 // - Actual : 4 // i.e. numbering type was ARABIC, not ARABIC_ZERO. - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(style::NumberingType::ARABIC_ZERO), + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(style::NumberingType::ARABIC_ZERO), aMap["NumberingType"].get<sal_uInt16>()); } diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index aab2a4cc71e8..854fe65c95ca 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -1488,7 +1488,7 @@ void SwTiledRenderingTest::testTrackChanges() // Reject the change by id, while the cursor does not cover the tracked change. uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence( { - {"RejectTrackedChange", uno::makeAny(static_cast<sal_uInt16>(pRedline->GetId()))} + {"RejectTrackedChange", uno::makeAny(o3tl::narrowing<sal_uInt16>(pRedline->GetId()))} })); comphelper::dispatchCommand(".uno:RejectTrackedChange", aPropertyValues); Scheduler::ProcessEventsToIdle(); diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 8ef3de9d6a60..c47e5402304e 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -2404,7 +2404,7 @@ void SwUiWriterTest::testDeleteTableRedlines() IDocumentRedlineAccess& rIDRA = pDoc->getIDocumentRedlineAccess(); SwExtraRedlineTable& rExtras = rIDRA.GetExtraRedlineTable(); rExtras.DeleteAllTableRedlines(*pDoc, rTable, false, RedlineType::Any); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(0), rExtras.GetSize()); + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(0), rExtras.GetSize()); } void SwUiWriterTest::testXFlatParagraph() @@ -5966,7 +5966,7 @@ void SwUiWriterTest::testRedlineParam() pWrtShell->StartOfSection(); uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence( { - {"NextTrackedChange", uno::makeAny(static_cast<sal_uInt16>(rTable[0]->GetId()))} + {"NextTrackedChange", uno::makeAny(o3tl::narrowing<sal_uInt16>(rTable[0]->GetId()))} })); dispatchCommand(mxComponent, ".uno:NextTrackedChange", aPropertyValues); Scheduler::ProcessEventsToIdle(); @@ -5979,7 +5979,7 @@ void SwUiWriterTest::testRedlineParam() pWrtShell->StartOfSection(); aPropertyValues = comphelper::InitPropertySequence( { - {"NextTrackedChange", uno::makeAny(static_cast<sal_uInt16>(rTable[1]->GetId()))} + {"NextTrackedChange", uno::makeAny(o3tl::narrowing<sal_uInt16>(rTable[1]->GetId()))} }); dispatchCommand(mxComponent, ".uno:NextTrackedChange", aPropertyValues); Scheduler::ProcessEventsToIdle(); @@ -5990,7 +5990,7 @@ void SwUiWriterTest::testRedlineParam() pWrtShell->StartOfSection(); aPropertyValues = comphelper::InitPropertySequence( { - {"RejectTrackedChange", uno::makeAny(static_cast<sal_uInt16>(rTable[1]->GetId()))} + {"RejectTrackedChange", uno::makeAny(o3tl::narrowing<sal_uInt16>(rTable[1]->GetId()))} }); dispatchCommand(mxComponent, ".uno:RejectTrackedChange", aPropertyValues); Scheduler::ProcessEventsToIdle(); diff --git a/sw/qa/extras/ww8export/ww8export3.cxx b/sw/qa/extras/ww8export/ww8export3.cxx index 4d982dbdb982..691a562ec434 100644 --- a/sw/qa/extras/ww8export/ww8export3.cxx +++ b/sw/qa/extras/ww8export/ww8export3.cxx @@ -139,7 +139,7 @@ DECLARE_WW8EXPORT_TEST(testArabicZeroNumbering, "arabic-zero-numbering.doc") // - Expected: 64 // - Actual : 4 // i.e. numbering type was ARABIC, not ARABIC_ZERO. - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(style::NumberingType::ARABIC_ZERO), + CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(style::NumberingType::ARABIC_ZERO), aMap["NumberingType"].get<sal_uInt16>()); } diff --git a/sw/source/core/SwNumberTree/SwNodeNum.cxx b/sw/source/core/SwNumberTree/SwNodeNum.cxx index 6bf92d3eb73a..af92fe21ddc8 100644 --- a/sw/source/core/SwNumberTree/SwNodeNum.cxx +++ b/sw/source/core/SwNumberTree/SwNodeNum.cxx @@ -273,7 +273,7 @@ SwNumberTree::tSwNumTreeNumber SwNodeNum::GetStartValue() const if (nLevel >= 0 && nLevel < MAXLEVEL) { - const SwNumFormat * pFormat = pRule->GetNumFormat( static_cast<sal_uInt16>(nLevel)); + const SwNumFormat * pFormat = pRule->GetNumFormat( o3tl::narrowing<sal_uInt16>(nLevel)); if (pFormat) aResult = pFormat->GetStart(); diff --git a/sw/source/core/access/accportions.cxx b/sw/source/core/access/accportions.cxx index 9310a290a184..b1da888d5af7 100644 --- a/sw/source/core/access/accportions.cxx +++ b/sw/source/core/access/accportions.cxx @@ -615,7 +615,7 @@ TextFrameIndex SwAccessiblePortionData::FillSpecialPos( // (if necessary) size_t nRefLine = FindBreak( m_aLineBreaks, nRefPos ); size_t nMyLine = FindBreak( m_aLineBreaks, nPos ); - sal_uInt16 nLineOffset = static_cast<sal_uInt16>( nMyLine - nRefLine ); + sal_uInt16 nLineOffset = o3tl::narrowing<sal_uInt16>( nMyLine - nRefLine ); if( nLineOffset != 0 ) nRefPos = m_aLineBreaks[ nMyLine ]; diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx index a7d4d2474613..6f5516d69c1f 100644 --- a/sw/source/core/crsr/crsrsh.cxx +++ b/sw/source/core/crsr/crsrsh.cxx @@ -523,7 +523,7 @@ bool SwCursorShell::UpDown( bool bUp, sal_uInt16 nCnt ) if( !bTableMode ) eUpdateMode = static_cast<CursorFlag>(eUpdateMode | SwCursorShell::UPDOWN | SwCursorShell::CHKRANGE); - UpdateCursor( static_cast<sal_uInt16>(eUpdateMode) ); + UpdateCursor( o3tl::narrowing<sal_uInt16>(eUpdateMode) ); } } return bRet; @@ -2435,7 +2435,7 @@ void SwCursorShell::ShellGetFocus() m_bHasFocus = true; if( !m_bBasicHideCursor && VisArea().Width() ) { - UpdateCursor( static_cast<sal_uInt16>( SwCursorShell::CHKRANGE ) ); + UpdateCursor( o3tl::narrowing<sal_uInt16>( SwCursorShell::CHKRANGE ) ); ShowCursors( m_bSVCursorVis ); } } diff --git a/sw/source/core/crsr/swcrsr.cxx b/sw/source/core/crsr/swcrsr.cxx index 847a019cf1b9..5ae9e5c78e76 100644 --- a/sw/source/core/crsr/swcrsr.cxx +++ b/sw/source/core/crsr/swcrsr.cxx @@ -1891,7 +1891,7 @@ bool SwCursor::LeftRight( bool bLeft, sal_uInt16 nCnt, sal_uInt16 nMode, { pTableBox = & pTableBox->FindEndOfRowSpan( pOldTabSttNode->GetTable(), - static_cast<sal_uInt16>(pTableBox->getRowSpan() + m_nRowSpanOffset)); + o3tl::narrowing<sal_uInt16>(pTableBox->getRowSpan() + m_nRowSpanOffset)); SwNodeIndex& rPtIdx = GetPoint()->nNode; SwNodeIndex aNewIdx( *pTableBox->GetSttNd() ); rPtIdx = aNewIdx; @@ -2212,7 +2212,7 @@ bool SwCursor::GoPrevNextCell( bool bNext, sal_uInt16 nCnt ) if ( pTableBox && pTableBox->getRowSpan() > 1 ) { pTableBox = & pTableBox->FindEndOfRowSpan( pTableNd->GetTable(), - static_cast<sal_uInt16>(pTableBox->getRowSpan() + m_nRowSpanOffset)); + o3tl::narrowing<sal_uInt16>(pTableBox->getRowSpan() + m_nRowSpanOffset)); SwNodeIndex aNewIdx( *pTableBox->GetSttNd() ); rPtIdx = aNewIdx; pTableBoxStartNode = rPtIdx.GetNode().FindTableBoxStartNode(); diff --git a/sw/source/core/crsr/trvltbl.cxx b/sw/source/core/crsr/trvltbl.cxx index 5f26c9f23788..8bffbe3505fb 100644 --- a/sw/source/core/crsr/trvltbl.cxx +++ b/sw/source/core/crsr/trvltbl.cxx @@ -61,7 +61,7 @@ bool SwCursorShell::GoNextCell( bool bAppendLine ) pTableNd = IsCursorInTable(); assert (pTableNd); pTableBox = & pTableBox->FindEndOfRowSpan( pTableNd->GetTable(), - static_cast<sal_uInt16>(pTableBox->getRowSpan() + pCursor->GetCursorRowSpanOffset() ) ); + o3tl::narrowing<sal_uInt16>(pTableBox->getRowSpan() + pCursor->GetCursorRowSpanOffset() ) ); pTableBoxStartNode = pTableBox->GetSttNd(); } } diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx index 88fd7872a41b..254d0fc00085 100644 --- a/sw/source/core/doc/DocumentContentOperationsManager.cxx +++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx @@ -1348,7 +1348,7 @@ namespace //local functions originally from docfmt.cxx if (nLevel >= MAXLEVEL) nLevel = MAXLEVEL - 1; - SwNumFormat aNumFormat = pNumRule->Get(static_cast<sal_uInt16>(nLevel)); + SwNumFormat aNumFormat = pNumRule->Get(o3tl::narrowing<sal_uInt16>(nLevel)); SwCharFormat * pCharFormat = rDoc.FindCharFormatByName(aNumFormat.GetCharFormatName()); diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx b/sw/source/core/doc/DocumentFieldsManager.cxx index b187e709e9b0..aa52a22be144 100644 --- a/sw/source/core/doc/DocumentFieldsManager.cxx +++ b/sw/source/core/doc/DocumentFieldsManager.cxx @@ -929,7 +929,7 @@ void DocumentFieldsManager::UpdateExpFieldsImpl( // Hash table for all string replacements is filled on-the-fly. // Try to fabricate an uneven number. const SwFieldTypes::size_type nHashSize {(( mpFieldTypes->size() / 7 ) + 1 ) * 7}; - const sal_uInt16 nStrFormatCnt = static_cast<sal_uInt16>(nHashSize); + const sal_uInt16 nStrFormatCnt = o3tl::narrowing<sal_uInt16>(nHashSize); OSL_ENSURE( nStrFormatCnt == nHashSize, "Downcasting to sal_uInt16 lost information!" ); SwHashTable<HashStr> aHashStrTable(nStrFormatCnt); diff --git a/sw/source/core/doc/DocumentLayoutManager.cxx b/sw/source/core/doc/DocumentLayoutManager.cxx index d4a92a09a69c..1266e3ea719f 100644 --- a/sw/source/core/doc/DocumentLayoutManager.cxx +++ b/sw/source/core/doc/DocumentLayoutManager.cxx @@ -135,7 +135,7 @@ SwFrameFormat *DocumentLayoutManager::MakeLayoutFormat( RndStdIds eRequest, cons m_rDoc.GetNodes().MakeTextSection ( aTmpIdx, bHeader ? SwHeaderStartNode : SwFooterStartNode, - m_rDoc.getIDocumentStylePoolAccess().GetTextCollFromPool(static_cast<sal_uInt16>( bHeader + m_rDoc.getIDocumentStylePoolAccess().GetTextCollFromPool(o3tl::narrowing<sal_uInt16>( bHeader ? ( eRequest == RndStdIds::HEADERL ? RES_POOLCOLL_HEADERL : eRequest == RndStdIds::HEADERR diff --git a/sw/source/core/doc/DocumentStylePoolManager.cxx b/sw/source/core/doc/DocumentStylePoolManager.cxx index 5df33094c073..ff0657aaff48 100644 --- a/sw/source/core/doc/DocumentStylePoolManager.cxx +++ b/sw/source/core/doc/DocumentStylePoolManager.cxx @@ -1753,8 +1753,8 @@ SwPageDesc* DocumentStylePoolManager::GetPageDescFromPool( sal_uInt16 nId, bool } SvxULSpaceItem aUL( RES_UL_SPACE ); { - aUL.SetUpper( static_cast<sal_uInt16>(aLR.GetLeft()) ); - aUL.SetLower( static_cast<sal_uInt16>(aLR.GetLeft()) ); + aUL.SetUpper( o3tl::narrowing<sal_uInt16>(aLR.GetLeft()) ); + aUL.SetLower( o3tl::narrowing<sal_uInt16>(aLR.GetLeft()) ); } SwAttrSet aSet( m_rDoc.GetAttrPool(), aPgFrameFormatSetRange ); @@ -1824,8 +1824,8 @@ SwPageDesc* DocumentStylePoolManager::GetPageDescFromPool( sal_uInt16 nId, bool { lcl_PutStdPageSizeIntoItemSet( m_rDoc, aSet ); aLR.SetRight(o3tl::convert(1, o3tl::Length::cm, o3tl::Length::twip)); - aUL.SetUpper( static_cast<sal_uInt16>(aLR.GetRight()) ); - aUL.SetLower( static_cast<sal_uInt16>(aLR.GetRight()) ); + aUL.SetUpper( o3tl::narrowing<sal_uInt16>(aLR.GetRight()) ); + aUL.SetLower( o3tl::narrowing<sal_uInt16>(aLR.GetRight()) ); aSet.Put( aLR ); aSet.Put( aUL ); diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx index 9b3b3bb70991..8fb7040348e2 100644 --- a/sw/source/core/doc/doc.cxx +++ b/sw/source/core/doc/doc.cxx @@ -503,7 +503,7 @@ sal_uInt16 PostItField_::GetPageNo( sal_uInt16 nPgNo = pFrame->GetPhyPageNum(); if( rRangeEnum.hasValue( nPgNo, &rPossiblePages )) { - rLineNo = static_cast<sal_uInt16>(pFrame->GetLineCount( nPos ) + + rLineNo = o3tl::narrowing<sal_uInt16>(pFrame->GetLineCount( nPos ) + pFrame->GetAllLines() - pFrame->GetThisLines()); rVirtPgNo = pFrame->GetVirtPageNum(); return nPgNo; @@ -1271,7 +1271,7 @@ void SwDoc::Summary(SwDoc& rExtDoc, sal_uInt8 nLevel, sal_uInt8 nPara, bool bImp { SwTextFormatColl* pMyColl = pNd->GetTextColl(); - const sal_uInt16 nHeadLine = static_cast<sal_uInt16>( + const sal_uInt16 nHeadLine = o3tl::narrowing<sal_uInt16>( !pMyColl->IsAssignedToListLevelOfOutlineStyle() ? RES_POOLCOLL_HEADLINE2 : RES_POOLCOLL_HEADLINE1 ); diff --git a/sw/source/core/doc/docdesc.cxx b/sw/source/core/doc/docdesc.cxx index b417ab0add9a..6b63e7a300c3 100644 --- a/sw/source/core/doc/docdesc.cxx +++ b/sw/source/core/doc/docdesc.cxx @@ -107,8 +107,8 @@ static void lcl_DefaultPageFormat( sal_uInt16 nPoolFormatId, SvxLRSpaceItem aLR( RES_LR_SPACE ); SvxULSpaceItem aUL( RES_UL_SPACE ); - aUL.SetUpper( static_cast<sal_uInt16>(nMinTop) ); - aUL.SetLower( static_cast<sal_uInt16>(nMinBottom) ); + aUL.SetUpper( o3tl::narrowing<sal_uInt16>(nMinTop) ); + aUL.SetLower( o3tl::narrowing<sal_uInt16>(nMinBottom) ); aLR.SetRight( nMinRight ); aLR.SetLeft( nMinLeft ); diff --git a/sw/source/core/doc/docdraw.cxx b/sw/source/core/doc/docdraw.cxx index c450f4213dc3..edc3a145c11c 100644 --- a/sw/source/core/doc/docdraw.cxx +++ b/sw/source/core/doc/docdraw.cxx @@ -199,7 +199,7 @@ SwDrawContact* SwDoc::GroupSelection( SdrView& rDrawView ) std::unique_ptr<SwUndoDrawGroup> pUndo; if (GetIDocumentUndoRedo().DoesUndo()) - pUndo.reset(new SwUndoDrawGroup( static_cast<sal_uInt16>(rMrkList.GetMarkCount()), *this)); + pUndo.reset(new SwUndoDrawGroup( o3tl::narrowing<sal_uInt16>(rMrkList.GetMarkCount()), *this)); // #i53320# bool bGroupMembersNotPositioned( false ); @@ -335,7 +335,7 @@ void SwDoc::UnGroupSelection( SdrView& rDrawView ) pFormatsAndObjs[i].emplace_back( pFormat, pSubObj ); if( bUndo ) - pUndo->AddObj( static_cast<sal_uInt16>(i2), pFormat ); + pUndo->AddObj( o3tl::narrowing<sal_uInt16>(i2), pFormat ); } } } @@ -419,7 +419,7 @@ bool SwDoc::DeleteSelection( SwDrawView& rDrawView ) { std::unique_ptr<SwUndoDrawDelete> pUndo; if (GetIDocumentUndoRedo().DoesUndo()) - pUndo.reset(new SwUndoDrawDelete( static_cast<sal_uInt16>(rMrkList.GetMarkCount()), *this )); + pUndo.reset(new SwUndoDrawDelete( o3tl::narrowing<sal_uInt16>(rMrkList.GetMarkCount()), *this )); // Destroy ContactObjects, save formats. for( size_t i = 0; i < rMrkList.GetMarkCount(); ++i ) diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx index 8b1b4b2a9bc0..bd0fb7dff196 100644 --- a/sw/source/core/doc/docfmt.cxx +++ b/sw/source/core/doc/docfmt.cxx @@ -1675,7 +1675,7 @@ void SwDoc::MoveLeftMargin(const SwPaM& rPam, bool bRight, bool bModulus, const int nListLevel = pTNd->GetActualListLevel(); if ( nListLevel >= 0 ) { - const SwNumFormat& rFormat = pRule->Get(static_cast<sal_uInt16>(nListLevel)); + const SwNumFormat& rFormat = pRule->Get(o3tl::narrowing<sal_uInt16>(nListLevel)); if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT ) { aLS.SetTextLeft( rFormat.GetIndentAt() ); diff --git a/sw/source/core/doc/docftn.cxx b/sw/source/core/doc/docftn.cxx index 286f0b4ad47f..7f2b30ddc615 100644 --- a/sw/source/core/doc/docftn.cxx +++ b/sw/source/core/doc/docftn.cxx @@ -106,7 +106,7 @@ SwPageDesc* SwEndNoteInfo::GetPageDesc(SwDoc& rDoc) const { if(!m_pPageDesc) { - m_pPageDesc = rDoc.getIDocumentStylePoolAccess().GetPageDescFromPool( static_cast<sal_uInt16>( + m_pPageDesc = rDoc.getIDocumentStylePoolAccess().GetPageDescFromPool( o3tl::narrowing<sal_uInt16>( m_bEndNote ? RES_POOLPAGE_ENDNOTE : RES_POOLPAGE_FOOTNOTE ) ); m_aDepends.StartListening(m_pPageDesc); } @@ -139,7 +139,7 @@ void SwEndNoteInfo::SetFootnoteTextColl(SwTextFormatColl& rFormat) SwCharFormat* SwEndNoteInfo::GetCharFormat(SwDoc& rDoc) const { - auto pCharFormatFromDoc = rDoc.getIDocumentStylePoolAccess().GetCharFormatFromPool( static_cast<sal_uInt16>( + auto pCharFormatFromDoc = rDoc.getIDocumentStylePoolAccess().GetCharFormatFromPool( o3tl::narrowing<sal_uInt16>( m_bEndNote ? RES_POOLCHR_ENDNOTE : RES_POOLCHR_FOOTNOTE ) ); if (m_pCharFormat != pCharFormatFromDoc) { @@ -172,7 +172,7 @@ namespace void SwEndNoteInfo::SetCharFormat(SwCharFormat* pFormat) { lcl_ResetPoolIdForDocAndSync( - static_cast<sal_uInt16>(m_bEndNote + o3tl::narrowing<sal_uInt16>(m_bEndNote ? RES_POOLCHR_ENDNOTE : RES_POOLCHR_FOOTNOTE), pFormat, @@ -181,7 +181,7 @@ void SwEndNoteInfo::SetCharFormat(SwCharFormat* pFormat) SwCharFormat* SwEndNoteInfo::GetAnchorCharFormat(SwDoc& rDoc) const { - auto pAnchorFormatFromDoc = rDoc.getIDocumentStylePoolAccess().GetCharFormatFromPool( static_cast<sal_uInt16>( + auto pAnchorFormatFromDoc = rDoc.getIDocumentStylePoolAccess().GetCharFormatFromPool( o3tl::narrowing<sal_uInt16>( m_bEndNote ? RES_POOLCHR_ENDNOTE_ANCHOR : RES_POOLCHR_FOOTNOTE_ANCHOR ) ); if(m_pAnchorFormat != pAnchorFormatFromDoc) { @@ -195,7 +195,7 @@ SwCharFormat* SwEndNoteInfo::GetAnchorCharFormat(SwDoc& rDoc) const void SwEndNoteInfo::SetAnchorCharFormat(SwCharFormat* pFormat) { lcl_ResetPoolIdForDocAndSync( - static_cast<sal_uInt16>(m_bEndNote + o3tl::narrowing<sal_uInt16>(m_bEndNote ? RES_POOLCHR_ENDNOTE_ANCHOR : RES_POOLCHR_FOOTNOTE_ANCHOR), pFormat, diff --git a/sw/source/core/doc/doclay.cxx b/sw/source/core/doc/doclay.cxx index 2da94ef4699c..43b4408ec080 100644 --- a/sw/source/core/doc/doclay.cxx +++ b/sw/source/core/doc/doclay.cxx @@ -311,7 +311,7 @@ SwFlyFrameFormat* SwDoc::MakeFlySection( RndStdIds eAnchorType, if( !pFrameFormat ) pFrameFormat = getIDocumentStylePoolAccess().GetFrameFormatFromPool( RES_POOLFRM_FRAME ); - sal_uInt16 nCollId = static_cast<sal_uInt16>( + sal_uInt16 nCollId = o3tl::narrowing<sal_uInt16>( GetDocumentSettingManager().get(DocumentSettingId::HTML_MODE) ? RES_POOLCOLL_TEXT : RES_POOLCOLL_FRAME ); /* If there is no adjust item in the paragraph style for the content node of the new fly section diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx index 5e287e84f19d..2420532c5bee 100644 --- a/sw/source/core/doc/docnum.cxx +++ b/sw/source/core/doc/docnum.cxx @@ -246,7 +246,7 @@ bool SwDoc::OutlineUpDown(const SwPaM& rPam, short nOffset, n++; SwTextFormatColl *aTmpColl = - getIDocumentStylePoolAccess().GetTextCollFromPool(static_cast<sal_uInt16>(RES_POOLCOLL_HEADLINE1 + n)); + getIDocumentStylePoolAccess().GetTextCollFromPool(o3tl::narrowing<sal_uInt16>(RES_POOLCOLL_HEADLINE1 + n)); if( aTmpColl->IsAssignedToListLevelOfOutlineStyle() && aTmpColl->GetAssignedOutlineStyleLevel() == n ) @@ -275,7 +275,7 @@ bool SwDoc::OutlineUpDown(const SwPaM& rPam, short nOffset, n--; SwTextFormatColl *aTmpColl = - getIDocumentStylePoolAccess().GetTextCollFromPool(static_cast<sal_uInt16>(RES_POOLCOLL_HEADLINE1 + n)); + getIDocumentStylePoolAccess().GetTextCollFromPool(o3tl::narrowing<sal_uInt16>(RES_POOLCOLL_HEADLINE1 + n)); if( aTmpColl->IsAssignedToListLevelOfOutlineStyle() && aTmpColl->GetAssignedOutlineStyleLevel() == n ) @@ -2556,7 +2556,7 @@ OUString SwDoc::GetUniqueNumRuleName( const OUString* pChkStr, bool bAutoNum ) c if( sNm.startsWith( aName ) ) { // Determine Number and set the Flag - nNum = static_cast<sal_uInt16>(sNm.copy( nNmLen ).toInt32()); + nNum = o3tl::narrowing<sal_uInt16>(sNm.copy( nNmLen ).toInt32()); if( nNum-- && nNum < mpNumRuleTable->size() ) pSetFlags[ nNum / 8 ] |= (0x01 << ( nNum & 0x07 )); } diff --git a/sw/source/core/doc/docsort.cxx b/sw/source/core/doc/docsort.cxx index 25a664d17bf8..3c2f8c1f019c 100644 --- a/sw/source/core/doc/docsort.cxx +++ b/sw/source/core/doc/docsort.cxx @@ -555,7 +555,7 @@ bool SwDoc::SortTable(const SwSelBoxes& rBoxes, const SwSortOptions& rOpt) std::multiset<SwSortBoxElement> aSortList; // When sorting, do not include the first row if the HeaderLine is repeated - for( sal_uInt16 i = static_cast<sal_uInt16>(nStart); i < nCount; ++i) + for( sal_uInt16 i = o3tl::narrowing<sal_uInt16>(nStart); i < nCount; ++i) { aSortList.insert(SwSortBoxElement(i)); } diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx index d8e7d30e80e1..2c3ed6902f13 100644 --- a/sw/source/core/doc/doctxm.cxx +++ b/sw/source/core/doc/doctxm.cxx @@ -1520,7 +1520,7 @@ void SwTOXBaseSection::UpdateContent( SwTOXElement eMyType, std::unique_ptr<SwTOXPara> pNew( MakeSwTOXSortTabBase<SwTOXPara>( pLayout, *pCNd, eMyType, ( USHRT_MAX != nSetLevel ) - ? static_cast<sal_uInt16>(nSetLevel) + ? o3tl::narrowing<sal_uInt16>(nSetLevel) : FORM_ALPHA_DELIMITER ) ); InsertSorted( std::move(pNew) ); } @@ -1570,7 +1570,7 @@ void SwTOXBaseSection::UpdateTable(const SwTextNode* pOwnChapterNode, if( pOutlNd->GetTextColl()->IsAssignedToListLevelOfOutlineStyle()) { const int nTmp = pOutlNd->GetTextColl()->GetAttrOutlineLevel(); - pNew->SetLevel(static_cast<sal_uInt16>(nTmp)); + pNew->SetLevel(o3tl::narrowing<sal_uInt16>(nTmp)); } } } diff --git a/sw/source/core/doc/fmtcol.cxx b/sw/source/core/doc/fmtcol.cxx index 6a91ac469294..a0dcda5cff88 100644 --- a/sw/source/core/doc/fmtcol.cxx +++ b/sw/source/core/doc/fmtcol.cxx @@ -588,7 +588,7 @@ void SwTextFormatColl::SetAttrOutlineLevel( int nLevel) { OSL_ENSURE( 0 <= nLevel && nLevel <= MAXLEVEL ,"SwTextFormatColl: Level Out Of Range" ); SetFormatAttr( SfxUInt16Item( RES_PARATR_OUTLINELEVEL, - static_cast<sal_uInt16>(nLevel) ) ); + o3tl::narrowing<sal_uInt16>(nLevel) ) ); } int SwTextFormatColl::GetAttrOutlineLevel() const diff --git a/sw/source/core/doc/htmltbl.cxx b/sw/source/core/doc/htmltbl.cxx index 67dc9b9c56b5..41a10d34c10b 100644 --- a/sw/source/core/doc/htmltbl.cxx +++ b/sw/source/core/doc/htmltbl.cxx @@ -314,7 +314,7 @@ sal_uInt16 SwHTMLTableLayout::GetBrowseWidthByVisArea( const SwDoc& rDoc ) SwViewShell const *pVSh = rDoc.getIDocumentLayoutAccess().GetCurrentViewShell(); if( pVSh ) { - return static_cast<sal_uInt16>(pVSh->GetBrowseWidth()); + return o3tl::narrowing<sal_uInt16>(pVSh->GetBrowseWidth()); } return 0; @@ -328,7 +328,7 @@ sal_uInt16 SwHTMLTableLayout::GetBrowseWidth( const SwDoc& rDoc ) { const SwFrame *pPageFrame = pRootFrame->GetLower(); if( pPageFrame ) - return static_cast<sal_uInt16>(pPageFrame->getFramePrintArea().Width()); + return o3tl::narrowing<sal_uInt16>(pPageFrame->getFramePrintArea().Width()); } // #i91658# @@ -367,7 +367,7 @@ sal_uInt16 SwHTMLTableLayout::GetBrowseWidthByTabFrame( rTabFrame.CalcFlyOffsets( nUpperDummy, nLeftOffset, nRightOffset ); nWidth -= (nLeftOffset + nRightOffset); - return static_cast<sal_uInt16>(std::min(nWidth, SwTwips(SAL_MAX_UINT16))); + return o3tl::narrowing<sal_uInt16>(std::min(nWidth, SwTwips(SAL_MAX_UINT16))); } sal_uInt16 SwHTMLTableLayout::GetBrowseWidthByTable( const SwDoc& rDoc ) const @@ -985,7 +985,7 @@ void SwHTMLTableLayout::AutoLayoutPass1() { // the next column gets the rest sal_uInt16 nColWidth = - static_cast<sal_uInt16>((pColumn->GetMax() * nRelLeft) / nFixMax); + o3tl::narrowing<sal_uInt16>((pColumn->GetMax() * nRelLeft) / nFixMax); pColumn->SetWidthOption( nColWidth ); } } @@ -1112,8 +1112,8 @@ void SwHTMLTableLayout::AutoLayoutPass2( sal_uInt16 nAbsAvail, sal_uInt16 nRelAv { sal_uLong nAbsLeftFillL = nAbsLeftFill, nAbsRightFillL = nAbsRightFill; - m_nRelLeftFill = static_cast<sal_uInt16>((nAbsLeftFillL * nRelAvail) / nAbsAvail); - m_nRelRightFill = static_cast<sal_uInt16>((nAbsRightFillL * nRelAvail) / nAbsAvail); + m_nRelLeftFill = o3tl::narrowing<sal_uInt16>((nAbsLeftFillL * nRelAvail) / nAbsAvail); + m_nRelRightFill = o3tl::narrowing<sal_uInt16>((nAbsRightFillL * nRelAvail) / nAbsAvail); nAbsAvail -= (nAbsLeftFill + nAbsRightFill); if( nRelAvail ) @@ -1145,7 +1145,7 @@ void SwHTMLTableLayout::AutoLayoutPass2( sal_uInt16 nAbsAvail, sal_uInt16 nRelAv // Let's play such games now anyway. We had a graphic in a 1% wide // table and it didn't fit in of course. - nAbsTabWidth = static_cast<sal_uInt16>( (static_cast<sal_uLong>(nAbsAvail) * m_nWidthOption) / 100 ); + nAbsTabWidth = o3tl::narrowing<sal_uInt16>( (static_cast<sal_uLong>(nAbsAvail) * m_nWidthOption) / 100 ); if( IsTopTable() && ( /*MayBeInFlyFrame() ||*/ static_cast<sal_uLong>(nAbsTabWidth) > m_nMin ) ) { @@ -1214,17 +1214,17 @@ void SwHTMLTableLayout::AutoLayoutPass2( sal_uInt16 nAbsAvail, sal_uInt16 nRelAv if( nColMin <= USHRT_MAX ) { pColumn->SetAbsColWidth( - static_cast<sal_uInt16>((nColMin * nAbsTabWidth) / m_nMin) ); + o3tl::narrowing<sal_uInt16>((nColMin * nAbsTabWidth) / m_nMin) ); pColumn->SetRelColWidth( - static_cast<sal_uInt16>((nColMin * m_nRelTabWidth) / m_nMin) ); + o3tl::narrowing<sal_uInt16>((nColMin * m_nRelTabWidth) / m_nMin) ); } else { double nColMinD = nColMin; pColumn->SetAbsColWidth( - static_cast<sal_uInt16>((nColMinD * nAbsTabWidth) / m_nMin) ); + o3tl::narrowing<sal_uInt16>((nColMinD * nAbsTabWidth) / m_nMin) ); pColumn->SetRelColWidth( - static_cast<sal_uInt16>((nColMinD * m_nRelTabWidth) / m_nMin) ); + o3tl::narrowing<sal_uInt16>((nColMinD * m_nRelTabWidth) / m_nMin) ); } nAbs = nAbs + pColumn->GetAbsColWidth(); @@ -1251,17 +1251,17 @@ void SwHTMLTableLayout::AutoLayoutPass2( sal_uInt16 nAbsAvail, sal_uInt16 nRelAv if( nColMin <= USHRT_MAX ) { pColumn->SetAbsColWidth( - static_cast<sal_uInt16>((((nColMin-nRealColMin) * nDistAbs) / nDistMin) + nRealColMin) ); + o3tl::narrowing<sal_uInt16>((((nColMin-nRealColMin) * nDistAbs) / nDistMin) + nRealColMin) ); pColumn->SetRelColWidth( - static_cast<sal_uInt16>((((nColMin-nRealColMin) * nDistRel) / nDistMin) + nRealColMin) ); + o3tl::narrowing<sal_uInt16>((((nColMin-nRealColMin) * nDistRel) / nDistMin) + nRealColMin) ); } else { double nColMinD = nColMin; pColumn->SetAbsColWidth( - static_cast<sal_uInt16>((((nColMinD-nRealColMin) * nDistAbs) / nDistMin) + nRealColMin) ); + o3tl::narrowing<sal_uInt16>((((nColMinD-nRealColMin) * nDistAbs) / nDistMin) + nRealColMin) ); pColumn->SetRelColWidth( - static_cast<sal_uInt16>((((nColMinD-nRealColMin) * nDistRel) / nDistMin) + nRealColMin) ); + o3tl::narrowing<sal_uInt16>((((nColMinD-nRealColMin) * nDistRel) / nDistMin) + nRealColMin) ); } nAbs = nAbs + pColumn->GetAbsColWidth(); @@ -1284,7 +1284,7 @@ void SwHTMLTableLayout::AutoLayoutPass2( sal_uInt16 nAbsAvail, sal_uInt16 nRelAv // No fixed width, use the maximum. if( !nAbsTabWidth ) - nAbsTabWidth = static_cast<sal_uInt16>(m_nMax); + nAbsTabWidth = o3tl::narrowing<sal_uInt16>(m_nMax); // A top table may also get wider then the available space. if( nAbsTabWidth > nAbsAvail ) @@ -1301,7 +1301,7 @@ void SwHTMLTableLayout::AutoLayoutPass2( sal_uInt16 nAbsAvail, sal_uInt16 nRelAv { if (nAbsAvail == 0) throw o3tl::divide_by_zero(); - m_nRelTabWidth = static_cast<sal_uInt16>((nAbsTabWidthL * nRelAvail) / nAbsAvail); + m_nRelTabWidth = o3tl::narrowing<sal_uInt16>((nAbsTabWidthL * nRelAvail) / nAbsAvail); } else m_nRelTabWidth = nAbsTabWidth; @@ -1339,7 +1339,7 @@ void SwHTMLTableLayout::AutoLayoutPass2( sal_uInt16 nAbsAvail, sal_uInt16 nRelAv // The column keeps its width. nFixedCols++; sal_uLong nColMax = pColumn->GetMax(); - pColumn->SetAbsColWidth( static_cast<sal_uInt16>(nColMax) ); + pColumn->SetAbsColWidth( o3tl::narrowing<sal_uInt16>(nColMax) ); sal_uLong nRelColWidth = (nColMax * m_nRelTabWidth) / nAbsTabWidth; @@ -1349,10 +1349,10 @@ void SwHTMLTableLayout::AutoLayoutPass2( sal_uInt16 nAbsAvail, sal_uInt16 nRelAv nRelColWidth++; else if( nChkWidth > nColMax ) nRelColWidth--; - pColumn->SetRelColWidth( static_cast<sal_uInt16>(nRelColWidth) ); + pColumn->SetRelColWidth( o3tl::narrowing<sal_uInt16>(nRelColWidth) ); - nAbs = nAbs + static_cast<sal_uInt16>(nColMax); - nRel = nRel + static_cast<sal_uInt16>(nRelColWidth); + nAbs = nAbs + o3tl::narrowing<sal_uInt16>(nColMax); + nRel = nRel + o3tl::narrowing<sal_uInt16>(nRelColWidth); } } @@ -1381,9 +1381,9 @@ void SwHTMLTableLayout::AutoLayoutPass2( sal_uInt16 nAbsAvail, sal_uInt16 nRelAv { sal_uLong nColMax = pColumn->GetMax(); pColumn->SetAbsColWidth( - static_cast<sal_uInt16>((nColMax * nDistAbsTabWidth) / nDistMax) ); + o3tl::narrowing<sal_uInt16>((nColMax * nDistAbsTabWidth) / nDistMax) ); pColumn->SetRelColWidth( - static_cast<sal_uInt16>((nColMax * nDistRelTabWidth) / nDistMax) ); + o3tl::narrowing<sal_uInt16>((nColMax * nDistRelTabWidth) / nDistMax) ); } nAbs = nAbs + pColumn->GetAbsColWidth(); nRel = nRel + pColumn->GetRelColWidth(); @@ -1400,9 +1400,9 @@ void SwHTMLTableLayout::AutoLayoutPass2( sal_uInt16 nAbsAvail, sal_uInt16 nRelAv { sal_uLong nColMax = GetColumn( i )->GetMax(); GetColumn( i )->SetAbsColWidth( - static_cast<sal_uInt16>((nColMax * nAbsTabWidth) / m_nMax) ); + o3tl::narrowing<sal_uInt16>((nColMax * nAbsTabWidth) / m_nMax) ); GetColumn( i )->SetRelColWidth( - static_cast<sal_uInt16>((nColMax * m_nRelTabWidth) / m_nMax) ); + o3tl::narrowing<sal_uInt16>((nColMax * m_nRelTabWidth) / m_nMax) ); } } } @@ -1413,7 +1413,7 @@ void SwHTMLTableLayout::AutoLayoutPass2( sal_uInt16 nAbsAvail, sal_uInt16 nRelAv if( !nAbsTabWidth ) nAbsTabWidth = nAbsAvail; if( nAbsTabWidth < m_nMin ) - nAbsTabWidth = static_cast<sal_uInt16>(m_nMin); + nAbsTabWidth = o3tl::narrowing<sal_uInt16>(m_nMin); if( nAbsTabWidth > nAbsAvail ) { @@ -1427,7 +1427,7 @@ void SwHTMLTableLayout::AutoLayoutPass2( sal_uInt16 nAbsAvail, sal_uInt16 nRelAv { if (nAbsAvail == 0) throw o3tl::divide_by_zero(); - m_nRelTabWidth = static_cast<sal_uInt16>((nAbsTabWidthL * nRelAvail) / nAbsAvail); + m_nRelTabWidth = o3tl::narrowing<sal_uInt16>((nAbsTabWidthL * nRelAvail) / nAbsAvail); } else m_nRelTabWidth = nAbsTabWidth; @@ -1442,10 +1442,10 @@ void SwHTMLTableLayout::AutoLayoutPass2( sal_uInt16 nAbsAvail, sal_uInt16 nRelAv ? (nAbsColWidth * m_nRelTabWidth) / nAbsTabWidth : nAbsColWidth; - GetColumn( i )->SetAbsColWidth( static_cast<sal_uInt16>(nAbsColWidth) ); - GetColumn( i )->SetRelColWidth( static_cast<sal_uInt16>(nRelColWidth) ); - nAbs = nAbs + static_cast<sal_uInt16>(nAbsColWidth); - nRel = nRel + static_cast<sal_uInt16>(nRelColWidth); + GetColumn( i )->SetAbsColWidth( o3tl::narrowing<sal_uInt16>(nAbsColWidth) ); + GetColumn( i )->SetRelColWidth( o3tl::narrowing<sal_uInt16>(nRelColWidth) ); + nAbs = nAbs + o3tl::narrowing<sal_uInt16>(nAbsColWidth); + nRel = nRel + o3tl::narrowing<sal_uInt16>(nRelColWidth); } GetColumn( m_nCols-1 )->SetAbsColWidth( nAbsTabWidth - nAbs ); GetColumn( m_nCols-1 )->SetRelColWidth( m_nRelTabWidth - nRel ); @@ -1462,8 +1462,8 @@ void SwHTMLTableLayout::AutoLayoutPass2( sal_uInt16 nAbsAvail, sal_uInt16 nRelAv // Calculate the width of additional cells we use for // aligning inner tables. - sal_uInt16 nAbsDist = static_cast<sal_uInt16>(nAbsAvail-nAbsTabWidth); - sal_uInt16 nRelDist = static_cast<sal_uInt16>(nRelAvail-m_nRelTabWidth); + sal_uInt16 nAbsDist = o3tl::narrowing<sal_uInt16>(nAbsAvail-nAbsTabWidth); + sal_uInt16 nRelDist = o3tl::narrowing<sal_uInt16>(nRelAvail-m_nRelTabWidth); sal_uInt16 nParentInhAbsLeftSpace = 0, nParentInhAbsRightSpace = 0; // Calculate the size and position of the additional cells. diff --git a/sw/source/core/doc/notxtfrm.cxx b/sw/source/core/doc/notxtfrm.cxx index 76fe94181f0f..e4f2e071afba 100644 --- a/sw/source/core/doc/notxtfrm.cxx +++ b/sw/source/core/doc/notxtfrm.cxx @@ -131,7 +131,7 @@ static void lcl_PaintReplacement( const SwRect &rRect, const OUString &rText, else if ( !rURL.GetURL().isEmpty() ) bVisited = rSh.GetDoc()->IsVisitedURL( rURL.GetURL() ); - SwFormat *pFormat = rSh.GetDoc()->getIDocumentStylePoolAccess().GetFormatFromPool( static_cast<sal_uInt16> + SwFormat *pFormat = rSh.GetDoc()->getIDocumentStylePoolAccess().GetFormatFromPool( o3tl::narrowing<sal_uInt16> (bVisited ? RES_POOLCHR_INET_VISIT : RES_POOLCHR_INET_NORMAL ) ); aCol = pFormat->GetColor().GetValue(); eUnderline = pFormat->GetUnderline().GetLineStyle(); diff --git a/sw/source/core/doc/number.cxx b/sw/source/core/doc/number.cxx index ecd1b119b95e..eb84b1b63a68 100644 --- a/sw/source/core/doc/number.cxx +++ b/sw/source/core/doc/number.cxx @@ -659,7 +659,7 @@ OUString SwNumRule::MakeNumString( const SwNumberTree::tNumberVector & rNumVecto if (nLevel < MAXLEVEL) { - const SwNumFormat& rMyNFormat = Get( static_cast<sal_uInt16>(nLevel) ); + const SwNumFormat& rMyNFormat = Get( o3tl::narrowing<sal_uInt16>(nLevel) ); { css::lang::Locale aLocale( LanguageTag::convertToLocale(nLang)); @@ -789,7 +789,7 @@ OUString SwNumRule::MakeRefNumString( const SwNodeNum& rNodeNum, if (nListLevel >= MAXLEVEL) nListLevel = MAXLEVEL - 1; - SwNumFormat aFormat( Get( static_cast<sal_uInt16>(nListLevel) ) ); + SwNumFormat aFormat( Get( o3tl::narrowing<sal_uInt16>(nListLevel) ) ); bMakeNumStringForPhantom = aFormat.IsEnumeration() && SVX_NUM_NUMBER_NONE != aFormat.GetNumberingType(); @@ -834,7 +834,7 @@ OUString SwNumRule::MakeRefNumString( const SwNodeNum& rNodeNum, if ( bInclSuperiorNumLabels && pWorkingNodeNum->GetLevelInListTree() > 0 ) { - sal_uInt8 n = Get( static_cast<sal_uInt16>(pWorkingNodeNum->GetLevelInListTree()) ).GetIncludeUpperLevels(); + sal_uInt8 n = Get( o3tl::narrowing<sal_uInt16>(pWorkingNodeNum->GetLevelInListTree()) ).GetIncludeUpperLevels(); pWorkingNodeNum = dynamic_cast<SwNodeNum*>(pWorkingNodeNum->GetParent()); // skip parents, whose list label is already contained in the actual list label. while ( pWorkingNodeNum && n > 1 ) diff --git a/sw/source/core/doc/tblcpy.cxx b/sw/source/core/doc/tblcpy.cxx index 6bc270801873..337c7bcef619 100644 --- a/sw/source/core/doc/tblcpy.cxx +++ b/sw/source/core/doc/tblcpy.cxx @@ -225,7 +225,7 @@ namespace } if( bNoSelection && mnStartCol < USHRT_MAX ) { - sal_uInt16 nIdx = std::min(mnStartCol, static_cast<sal_uInt16>(maLines[0].size())); + sal_uInt16 nIdx = std::min(mnStartCol, o3tl::narrowing<sal_uInt16>(maLines[0].size())); mnStartCol = std::accumulate(maLines[0].begin(), maLines[0].begin() + nIdx, sal_uInt16(0), [](sal_uInt16 sum, const BoxSpanInfo& rInfo) { return sum + rInfo.mnColSpan; }); } @@ -298,7 +298,7 @@ namespace aInfo.mbSelected = true; if( mnStartCol == USHRT_MAX ) { - mnStartCol = static_cast<sal_uInt16>(maLines[nLine].size()); + mnStartCol = o3tl::narrowing<sal_uInt16>(maLines[nLine].size()); if( pSelBoxes->size() < 2 ) { pSelBoxes = nullptr; @@ -352,7 +352,7 @@ namespace const sal_uInt16 nLineCount = rLines.size(); if( nLineCount < mnAddLine ) mnAddLine = nLineCount; - sal_uInt16 nLine = static_cast<sal_uInt16>(maLines.size()); + sal_uInt16 nLine = o3tl::narrowing<sal_uInt16>(maLines.size()); maLines.resize( nLine + mnAddLine ); while( mnAddLine ) { @@ -591,7 +591,7 @@ static void lcl_CpyBox( const SwTable& rCpyTable, const SwTableBox* pCpyBox, : RES_POOLCOLL_TABLE_HDLN == nPoolId ) ) { SwTextFormatColl* pColl = pDoc->getIDocumentStylePoolAccess().GetTextCollFromPool( - static_cast<sal_uInt16>( + o3tl::narrowing<sal_uInt16>( RES_POOLCOLL_TABLE == nPoolId ? RES_POOLCOLL_TABLE_HDLN : RES_POOLCOLL_TABLE ) ); diff --git a/sw/source/core/doc/tblrwcl.cxx b/sw/source/core/doc/tblrwcl.cxx index 818782a5ff1b..18eab679a289 100644 --- a/sw/source/core/doc/tblrwcl.cxx +++ b/sw/source/core/doc/tblrwcl.cxx @@ -672,7 +672,7 @@ void DeleteBox_( SwTable& rTable, SwTableBox* pBox, SwUndo* pUndo, // JP 02.04.97: 1st part for Bug 36271 // First the left/right edges - if( nDelPos + 1 < static_cast<sal_uInt16>(rTableBoxes.size()) ) + if( nDelPos + 1 < o3tl::narrowing<sal_uInt16>(rTableBoxes.size()) ) { SwTableBox* pNxtBox = rTableBoxes[ nDelPos + 1 ]; const SvxBoxItem& rNxtBoxItem = pNxtBox->GetFrameFormat()->GetBox(); @@ -698,7 +698,7 @@ void DeleteBox_( SwTable& rTable, SwTableBox* pBox, SwUndo* pUndo, SwTableBox* pPrvBox = rTableBoxes[ nDelPos - 1 ]; const SvxBoxItem& rPrvBoxItem = pPrvBox->GetFrameFormat()->GetBox(); - SwTableBox* pNxtBox = nDelPos + 1 < static_cast<sal_uInt16>(rTableBoxes.size()) + SwTableBox* pNxtBox = nDelPos + 1 < o3tl::narrowing<sal_uInt16>(rTableBoxes.size()) ? rTableBoxes[ nDelPos + 1 ] : nullptr; if( pPrvBox->GetSttNd() && !rPrvBoxItem.GetRight() && @@ -854,7 +854,7 @@ lcl_FndNxtPrvDelBox( const SwTableLines& rTableLns, --*pCurPos; pAllDelBoxes->erase( pAllDelBoxes->begin() + nFndPos ); } - } while( bNxt ? ( nLinePos + 1 < static_cast<sal_uInt16>(rTableLns.size()) ) : nLinePos != 0 ); + } while( bNxt ? ( nLinePos + 1 < o3tl::narrowing<sal_uInt16>(rTableLns.size()) ) : nLinePos != 0 ); return pFndBox; } @@ -897,7 +897,7 @@ lcl_SaveUpperLowerBorder( SwTable& rTable, const SwTableBox& rBox, pPrvBox = ::lcl_FndNxtPrvDelBox( *pTableLns, nBoxStt, nBoxWidth, nLnPos, false, pAllDelBoxes, pCurPos ); - if( nLnPos + 1 < static_cast<sal_uInt16>(pTableLns->size()) ) // Successor? + if( nLnPos + 1 < o3tl::narrowing<sal_uInt16>(pTableLns->size()) ) // Successor? pNxtBox = ::lcl_FndNxtPrvDelBox( *pTableLns, nBoxStt, nBoxWidth, nLnPos, true, pAllDelBoxes, pCurPos ); @@ -1371,7 +1371,7 @@ static void lcl_Merge_MoveBox(FndBox_ & rFndBox, InsULPara *const pULPara) { // if there are Boxes behind it, move them nPos = pFndTableBox->GetUpper()->GetBoxPos( pFndTableBox ); - if( nPos +1 < static_cast<sal_uInt16>(pBoxes->size()) ) + if( nPos +1 < o3tl::narrowing<sal_uInt16>(pBoxes->size()) ) { nInsPos = pULPara->pInsLine->GetTabBoxes().size(); lcl_CpyBoxes( nPos+1, pBoxes->size(), @@ -1444,7 +1444,7 @@ static void lcl_Merge_MoveLine(FndLine_& rFndLine, InsULPara *const pULPara) } else // If there are Lines after it, move them - if( (nPos = pLines->GetPos( pFndLn )) + 1 < static_cast<sal_uInt16>(pLines->size()) ) + if( (nPos = pLines->GetPos( pFndLn )) + 1 < o3tl::narrowing<sal_uInt16>(pLines->size()) ) { nInsPos = pULPara->pInsBox->GetTabLines().size(); lcl_CpyLines( nPos+1, pLines->size(), *pLines, @@ -1479,7 +1479,7 @@ static void lcl_Merge_MoveLine(FndLine_& rFndLine, InsULPara *const pULPara) } else // If there are Lines after it, move them - if( (nPos = pLines->GetPos( pFndLn )) + 1 < static_cast<sal_uInt16>(pLines->size()) ) + if( (nPos = pLines->GetPos( pFndLn )) + 1 < o3tl::narrowing<sal_uInt16>(pLines->size()) ) lcl_CpyLines( nPos+1, pLines->size(), *pLines, pLMBox ); lcl_CalcWidth( pLMBox ); // calculate the Box's width @@ -1678,7 +1678,7 @@ static sal_uInt16 lcl_GetBoxOffset( const FndBox_& rBox ) { if (pBox==pCmp) break; - nRet = nRet + static_cast<sal_uInt16>(pCmp->GetFrameFormat()->GetFrameSize().GetWidth()); + nRet = nRet + o3tl::narrowing<sal_uInt16>(pCmp->GetFrameFormat()->GetFrameSize().GetWidth()); } pBox = pBox->GetUpper()->GetUpper(); } while( pBox ); @@ -1690,7 +1690,7 @@ static sal_uInt16 lcl_GetLineWidth( const FndLine_& rLine ) sal_uInt16 nRet = 0; for( auto n = rLine.GetBoxes().size(); n; ) { - nRet = nRet + static_cast<sal_uInt16>(rLine.GetBoxes()[--n]->GetBox() + nRet = nRet + o3tl::narrowing<sal_uInt16>(rLine.GetBoxes()[--n]->GetBox() ->GetFrameFormat()->GetFrameSize().GetWidth()); } return nRet; @@ -2202,7 +2202,7 @@ SwTableBox* SwTableLine::FindNextBox( const SwTable& rTable, { nFndPos = GetBoxPos( pSrchBox ); if( USHRT_MAX != nFndPos && - nFndPos + 1 != static_cast<sal_uInt16>(GetTabBoxes().size()) ) + nFndPos + 1 != o3tl::narrowing<sal_uInt16>(GetTabBoxes().size()) ) { pBox = GetTabBoxes()[ nFndPos + 1 ]; while( !pBox->GetTabLines().empty() ) @@ -2216,7 +2216,7 @@ SwTableBox* SwTableLine::FindNextBox( const SwTable& rTable, nFndPos = GetUpper()->GetTabLines().GetPos( pLine ); OSL_ENSURE( USHRT_MAX != nFndPos, "Line is not in the Table" ); // Is there another Line? - if( nFndPos+1 >= static_cast<sal_uInt16>(GetUpper()->GetTabLines().size()) ) + if( nFndPos+1 >= o3tl::narrowing<sal_uInt16>(GetUpper()->GetTabLines().size()) ) return GetUpper()->GetUpper()->FindNextBox( rTable, GetUpper(), bOvrTableLns ); pLine = GetUpper()->GetTabLines()[nFndPos+1]; } @@ -2224,7 +2224,7 @@ SwTableBox* SwTableLine::FindNextBox( const SwTable& rTable, { // Search for the next Line in the Table nFndPos = rTable.GetTabLines().GetPos( pLine ); - if( nFndPos + 1 >= static_cast<sal_uInt16>(rTable.GetTabLines().size()) ) + if( nFndPos + 1 >= o3tl::narrowing<sal_uInt16>(rTable.GetTabLines().size()) ) return nullptr; // there are no more Boxes pLine = rTable.GetTabLines()[ nFndPos+1 ]; diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx index 9ad8d8c33d57..cba67e1bf74d 100644 --- a/sw/source/core/doc/textboxhelper.cxx +++ b/sw/source/core/doc/textboxhelper.cxx @@ -575,7 +575,7 @@ void SwTextBoxHelper::getProperty(SwFrameFormat const* pShape, sal_uInt16 nWID, break; default: SAL_WARN("sw.core", "SwTextBoxHelper::getProperty: unhandled member-id: " - << static_cast<sal_uInt16>(nMemberID)); + << o3tl::narrowing<sal_uInt16>(nMemberID)); break; } } @@ -633,7 +633,7 @@ void SwTextBoxHelper::syncProperty(SwFrameFormat* pShape, sal_uInt16 nWID, sal_u break; default: SAL_WARN("sw.core", "SwTextBoxHelper::syncProperty: unhandled member-id: " - << static_cast<sal_uInt16>(nMemberID) + << o3tl::narrowing<sal_uInt16>(nMemberID) << " (which-id: " << nWID << ")"); break; } @@ -650,7 +650,7 @@ void SwTextBoxHelper::syncProperty(SwFrameFormat* pShape, sal_uInt16 nWID, sal_u break; default: SAL_WARN("sw.core", "SwTextBoxHelper::syncProperty: unhandled member-id: " - << static_cast<sal_uInt16>(nMemberID) + << o3tl::narrowing<sal_uInt16>(nMemberID) << " (which-id: " << nWID << ")"); break; } @@ -674,7 +674,7 @@ void SwTextBoxHelper::syncProperty(SwFrameFormat* pShape, sal_uInt16 nWID, sal_u break; default: SAL_WARN("sw.core", "SwTextBoxHelper::syncProperty: unhandled member-id: " - << static_cast<sal_uInt16>(nMemberID) + << o3tl::narrowing<sal_uInt16>(nMemberID) << " (which-id: " << nWID << ")"); break; } @@ -714,7 +714,7 @@ void SwTextBoxHelper::syncProperty(SwFrameFormat* pShape, sal_uInt16 nWID, sal_u break; default: SAL_WARN("sw.core", "SwTextBoxHelper::syncProperty: unhandled member-id: " - << static_cast<sal_uInt16>(nMemberID) + << o3tl::narrowing<sal_uInt16>(nMemberID) << " (which-id: " << nWID << ")"); break; } @@ -743,7 +743,7 @@ void SwTextBoxHelper::syncProperty(SwFrameFormat* pShape, sal_uInt16 nWID, sal_u break; default: SAL_WARN("sw.core", "SwTextBoxHelper::syncProperty: unhandled member-id: " - << static_cast<sal_uInt16>(nMemberID) + << o3tl::narrowing<sal_uInt16>(nMemberID) << " (which-id: " << nWID << ")"); break; } @@ -768,7 +768,7 @@ void SwTextBoxHelper::syncProperty(SwFrameFormat* pShape, sal_uInt16 nWID, sal_u break; default: SAL_WARN("sw.core", "SwTextBoxHelper::syncProperty: unhandled member-id: " - << static_cast<sal_uInt16>(nMemberID) + << o3tl::narrowing<sal_uInt16>(nMemberID) << " (which-id: " << nWID << ")"); break; } @@ -787,15 +787,15 @@ void SwTextBoxHelper::syncProperty(SwFrameFormat* pShape, sal_uInt16 nWID, sal_u break; default: SAL_WARN("sw.core", "SwTextBoxHelper::syncProperty: unhandled member-id: " - << static_cast<sal_uInt16>(nMemberID) + << o3tl::narrowing<sal_uInt16>(nMemberID) << " (which-id: " << nWID << ")"); break; } break; default: SAL_WARN("sw.core", "SwTextBoxHelper::syncProperty: unhandled which-id: " - << nWID << " (member-id: " << static_cast<sal_uInt16>(nMemberID) - << ")"); + << nWID << " (member-id: " + << o3tl::narrowing<sal_uInt16>(nMemberID) << ")"); break; } diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx index 389923d6f415..d11f09ecf69a 100644 --- a/sw/source/core/docnode/ndtbl.cxx +++ b/sw/source/core/docnode/ndtbl.cxx @@ -362,7 +362,7 @@ const SwTable* SwDoc::InsertTable( const SwInsertTableOptions& rInsTableOpts, if( GetIDocumentUndoRedo().DoesUndo() ) { GetIDocumentUndoRedo().AppendUndo( - std::make_unique<SwUndoInsTable>( rPos, nCols, nRows, static_cast<sal_uInt16>(eAdjust), + std::make_unique<SwUndoInsTable>( rPos, nCols, nRows, o3tl::narrowing<sal_uInt16>(eAdjust), rInsTableOpts, pTAFormat, pColArr, aTableName)); } @@ -651,7 +651,7 @@ const SwTable* SwDoc::TextToTable( const SwInsertTableOptions& rInsTableOpts, { GetIDocumentUndoRedo().StartUndo( SwUndoId::TEXTTOTABLE, nullptr ); pUndo = new SwUndoTextToTable( aOriginal, rInsTableOpts, cCh, - static_cast<sal_uInt16>(eAdjust), pTAFormat ); + o3tl::narrowing<sal_uInt16>(eAdjust), pTAFormat ); GetIDocumentUndoRedo().AppendUndo( std::unique_ptr<SwUndo>(pUndo) ); // Do not add splitting the TextNode to the Undo history @@ -1041,13 +1041,13 @@ SwTableNode* SwNodes::TextToTable( const SwNodeRange& rRange, sal_Unicode cCh, { // sw_redlinehide: no idea if this makes any sense... TextFrameIndex const nPos(aFInfo.GetFrame()->MapModelToView(pTextNd, nChPos)); - aPosArr.push_back( static_cast<sal_uInt16>( + aPosArr.push_back( o3tl::narrowing<sal_uInt16>( aFInfo.GetCharPos(nPos+TextFrameIndex(1), false)) ); } } aPosArr.push_back( - static_cast<sal_uInt16>(aFInfo.GetFrame()->IsVertical() ? + o3tl::narrowing<sal_uInt16>(aFInfo.GetFrame()->IsVertical() ? aFInfo.GetFrame()->getFramePrintArea().Bottom() : aFInfo.GetFrame()->getFramePrintArea().Right()) ); @@ -2921,7 +2921,7 @@ void SwCollectTableLineBoxes::AddBox( const SwTableBox& rBox ) m_aPositionArr.push_back(m_nWidth); SwTableBox* p = const_cast<SwTableBox*>(&rBox); m_Boxes.push_back(p); - m_nWidth = m_nWidth + static_cast<sal_uInt16>(rBox.GetFrameFormat()->GetFrameSize().GetWidth()); + m_nWidth = m_nWidth + o3tl::narrowing<sal_uInt16>(rBox.GetFrameFormat()->GetFrameSize().GetWidth()); } const SwTableBox* SwCollectTableLineBoxes::GetBoxOfPos( const SwTableBox& rBox ) @@ -2944,7 +2944,7 @@ const SwTableBox* SwCollectTableLineBoxes::GetBoxOfPos( const SwTableBox& rBox ) if( n >= m_aPositionArr.size() ) --n; - m_nWidth = m_nWidth + static_cast<sal_uInt16>(rBox.GetFrameFormat()->GetFrameSize().GetWidth()); + m_nWidth = m_nWidth + o3tl::narrowing<sal_uInt16>(rBox.GetFrameFormat()->GetFrameSize().GetWidth()); pRet = m_Boxes[ n ]; } return pRet; diff --git a/sw/source/core/docnode/ndtbl1.cxx b/sw/source/core/docnode/ndtbl1.cxx index 9a4f80ee995a..3df6b3272cee 100644 --- a/sw/source/core/docnode/ndtbl1.cxx +++ b/sw/source/core/docnode/ndtbl1.cxx @@ -1303,7 +1303,7 @@ sal_uInt16 SwDoc::GetBoxAlign( const SwCursor& rCursor ) const SwFormatVertOrient &rOri = aBoxes[i]->GetFrameFormat()->GetVertOrient(); if( USHRT_MAX == nAlign ) - nAlign = static_cast<sal_uInt16>(rOri.GetVertOrient()); + nAlign = o3tl::narrowing<sal_uInt16>(rOri.GetVertOrient()); else if( rOri.GetVertOrient() != nAlign ) { nAlign = USHRT_MAX; @@ -1339,7 +1339,7 @@ static sal_uInt16 lcl_CalcCellFit( const SwLayoutFrame *pCell ) // To compensate for the accuracy of calculation later on in SwTable::SetTabCols // we keep adding up a little. nRet += COLFUZZY; - return static_cast<sal_uInt16>(std::max( SwTwips(MINLAY), nRet )); + return o3tl::narrowing<sal_uInt16>(std::max( SwTwips(MINLAY), nRet )); } /* The Line is within the Selection but not outlined by the TabCols. diff --git a/sw/source/core/docnode/section.cxx b/sw/source/core/docnode/section.cxx index c65afd1e5749..9d300621da0e 100644 --- a/sw/source/core/docnode/section.cxx +++ b/sw/source/core/docnode/section.cxx @@ -947,7 +947,7 @@ void SwSectionFormat::UpdateParent() if(bIsHidden == pSection->IsHiddenFlag()) { - SwMsgPoolItem aMsgItem(static_cast<sal_uInt16>(bIsHidden + SwMsgPoolItem aMsgItem(o3tl::narrowing<sal_uInt16>(bIsHidden ? RES_SECTION_HIDDEN : RES_SECTION_NOT_HIDDEN)); CallSwClientNotify(sw::LegacyModifyHint(&aMsgItem, &aMsgItem)); diff --git a/sw/source/core/edit/autofmt.cxx b/sw/source/core/edit/autofmt.cxx index 637f507734a4..b9b4d8480a7a 100644 --- a/sw/source/core/edit/autofmt.cxx +++ b/sw/source/core/edit/autofmt.cxx @@ -639,7 +639,7 @@ bool SwAutoFormat::DoTable() case '+': case '|': - aPosArr.push_back( static_cast<sal_uInt16>(aInfo.GetCharPos(n)) ); + aPosArr.push_back( o3tl::narrowing<sal_uInt16>(aInfo.GetCharPos(n)) ); break; default: @@ -665,7 +665,7 @@ bool SwAutoFormat::DoTable() { eHori = text::HoriOrientation::NONE; // then - as last - we need to add the current frame width into the array - aPosArr.push_back( static_cast<sal_uInt16>(m_pCurTextFrame->getFrameArea().Width()) ); + aPosArr.push_back( o3tl::narrowing<sal_uInt16>(m_pCurTextFrame->getFrameArea().Width()) ); } else eHori = text::HoriOrientation::LEFT; @@ -908,7 +908,7 @@ CHECK_ROMAN_1: if( nMod5 == ((3 * nVal) + n10 ) || nMod5 == ((4 * nVal) + n10 ) || nLast == n10 ) - nStart = static_cast<sal_uInt16>(nStart + (n10 * 8)); + nStart = o3tl::narrowing<sal_uInt16>(nStart + (n10 * 8)); else if( nMod5 == 0 || nMod5 == (1 * nVal) || nMod5 == (2 * nVal) ) @@ -927,7 +927,7 @@ CHECK_ROMAN_5: int nMod = nStart % nVal; int n10 = nVal / 5; if( n10 == nMod ) - nStart = static_cast<sal_uInt16>(nStart + (3 * n10)); + nStart = o3tl::narrowing<sal_uInt16>(nStart + (3 * n10)); else if( 0 == nMod ) nStart = nStart + nVal; else @@ -1590,7 +1590,7 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, sal_uInt16 nDigitLevel ) else { bChgBullet = true; - SetColl( static_cast<sal_uInt16>(RES_POOLCOLL_BULLET_LEVEL1 + ( std::min( nLvl, cnNumBullColls ) * 4 )) ); + SetColl( o3tl::narrowing<sal_uInt16>(RES_POOLCOLL_BULLET_LEVEL1 + ( std::min( nLvl, cnNumBullColls ) * 4 )) ); } } else @@ -1627,7 +1627,7 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, sal_uInt16 nDigitLevel ) { SwNumFormat aFormat( aRule.Get( nLvl ) ); aFormat.SetPrefix( aPrefix.getToken( 0, u'\x0001', nPrefixIdx )); - aFormat.SetStart( static_cast<sal_uInt16>(aPrefix.getToken( 0, u'\x0001', nPrefixIdx ).toInt32())); + aFormat.SetStart( o3tl::narrowing<sal_uInt16>(aPrefix.getToken( 0, u'\x0001', nPrefixIdx ).toInt32())); aFormat.SetSuffix( aPostfix.getToken( 0, u'\x0001' )); aFormat.SetIncludeUpperLevels( 0 ); @@ -1652,7 +1652,7 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, sal_uInt16 nDigitLevel ) if( !n ) aFormat.SetPrefix( aPrefix.getToken( 0, u'\x0001', nPrefixIdx )); // token 0, read only on first loop - aFormat.SetStart( static_cast<sal_uInt16>(aPrefix.getToken( 0, u'\x0001', nPrefixIdx ).toInt32() )); + aFormat.SetStart( o3tl::narrowing<sal_uInt16>(aPrefix.getToken( 0, u'\x0001', nPrefixIdx ).toInt32() )); aFormat.SetSuffix( aPostfix.getToken( 0, u'\x0001', nPostfixIdx )); aFormat.SetIncludeUpperLevels( MAXLEVEL ); if( n < aNumTypes.getLength() ) @@ -1687,7 +1687,7 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, sal_uInt16 nDigitLevel ) } } else if( !m_aFlags.bAFormatByInput ) - SetColl( static_cast<sal_uInt16>(RES_POOLCOLL_NUM_LEVEL1 + ( std::min( nLvl, cnNumBullColls ) * 4 ) )); + SetColl( o3tl::narrowing<sal_uInt16>(RES_POOLCOLL_NUM_LEVEL1 + ( std::min( nLvl, cnNumBullColls ) * 4 ) )); else bChgEnum = false; } @@ -1811,7 +1811,7 @@ void SwAutoFormat::BuildNegIndent( SwTwips nSpaces ) || (!nTextPos && IsBlanksInString(*m_pCurTextFrame)) || IsSentenceAtEnd(*m_pCurTextFrame); - SetColl( static_cast<sal_uInt16>( nTextPos + SetColl( o3tl::narrowing<sal_uInt16>( nTextPos ? RES_POOLCOLL_CONFRONTATION : RES_POOLCOLL_TEXT_NEGIDENT ) ); @@ -1889,7 +1889,7 @@ void SwAutoFormat::BuildHeadLine( sal_uInt16 nLvl ) m_pDoc->GetDocumentRedlineManager().SetAutoFormatRedlineComment( &sText ); } - SetColl( static_cast<sal_uInt16>(RES_POOLCOLL_HEADLINE1 + nLvl ), true ); + SetColl( o3tl::narrowing<sal_uInt16>(RES_POOLCOLL_HEADLINE1 + nLvl ), true ); if( m_aFlags.bAFormatByInput ) { SwTextFormatColl& rNxtColl = m_pCurTextFrame->GetTextNodeForParaProps()->GetTextColl()->GetNextTextFormatColl(); diff --git a/sw/source/core/edit/edattr.cxx b/sw/source/core/edit/edattr.cxx index dc8769f2a61a..4df2c7db6e47 100644 --- a/sw/source/core/edit/edattr.cxx +++ b/sw/source/core/edit/edattr.cxx @@ -93,7 +93,7 @@ bool SwEditShell::GetPaMAttr( SwPaM* pPaM, SfxItemSet& rSet, nListLevel = MAXLEVEL - 1; const OUString & aCharFormatName = - pNumRule->Get(static_cast<sal_uInt16>(nListLevel)).GetCharFormatName(); + pNumRule->Get(o3tl::narrowing<sal_uInt16>(nListLevel)).GetCharFormatName(); SwCharFormat * pCharFormat = GetDoc()->FindCharFormatByName(aCharFormatName); @@ -504,7 +504,7 @@ bool SwEditShell::IsMoveLeftMargin( bool bRight, bool bModulus ) const bool bRet = true; const SvxTabStopItem& rTabItem = GetDoc()->GetDefault( RES_PARATR_TABSTOP ); - sal_uInt16 nDefDist = static_cast<sal_uInt16>(rTabItem.Count() ? rTabItem[0].GetTabPos() : 1134); + sal_uInt16 nDefDist = o3tl::narrowing<sal_uInt16>(rTabItem.Count() ? rTabItem[0].GetTabPos() : 1134); if( !nDefDist ) return false; @@ -533,7 +533,7 @@ bool SwEditShell::IsMoveLeftMargin( bool bRight, bool bModulus ) const SwFrame* pFrame = pCNd->getLayoutFrame( GetLayout() ); if ( pFrame ) { - const sal_uInt16 nFrameWidth = static_cast<sal_uInt16>( pFrame->IsVertical() ? + const sal_uInt16 nFrameWidth = o3tl::narrowing<sal_uInt16>( pFrame->IsVertical() ? pFrame->getFrameArea().Height() : pFrame->getFrameArea().Width() ); bRet = nFrameWidth > ( nNext + MM50 ); @@ -614,7 +614,7 @@ static bool lcl_IsNoEndTextAttrAtPos(SwRootFrame const& rLayout, if (nListLevel >= MAXLEVEL) nListLevel = MAXLEVEL - 1; - const SwNumFormat &rNumFormat = pNumRule->Get( static_cast<sal_uInt16>(nListLevel) ); + const SwNumFormat &rNumFormat = pNumRule->Get( o3tl::narrowing<sal_uInt16>(nListLevel) ); if( SVX_NUM_BITMAP != rNumFormat.GetNumberingType() ) { if ( SVX_NUM_CHAR_SPECIAL == rNumFormat.GetNumberingType() ) diff --git a/sw/source/core/edit/edfld.cxx b/sw/source/core/edit/edfld.cxx index 837f37b94e20..b6bb9055f23d 100644 --- a/sw/source/core/edit/edfld.cxx +++ b/sw/source/core/edit/edfld.cxx @@ -46,7 +46,7 @@ size_t SwEditShell::GetFieldTypeCount(SwFieldIds nResId ) const if(nResId == SwFieldIds::Unknown) { - return static_cast<sal_uInt16>(pFieldTypes->size()); + return o3tl::narrowing<sal_uInt16>(pFieldTypes->size()); } // all types with the same ResId diff --git a/sw/source/core/edit/editsh.cxx b/sw/source/core/edit/editsh.cxx index 9be63fb05251..eea6cd397b86 100644 --- a/sw/source/core/edit/editsh.cxx +++ b/sw/source/core/edit/editsh.cxx @@ -812,7 +812,7 @@ void SwEditShell::SetNumberingRestart() nListLevel = MAXLEVEL - 1; bIsNodeNum = pTextNd->GetNum()->GetNumber() == - pNumRule->Get( static_cast<sal_uInt16>(nListLevel) ).GetStart(); + pNumRule->Get( o3tl::narrowing<sal_uInt16>(nListLevel) ).GetStart(); } if (bIsNodeNum) { diff --git a/sw/source/core/edit/ednumber.cxx b/sw/source/core/edit/ednumber.cxx index af7ec8178e41..cd4458c276dd 100644 --- a/sw/source/core/edit/ednumber.cxx +++ b/sw/source/core/edit/ednumber.cxx @@ -900,7 +900,7 @@ sal_uInt16 SwEditShell::GetNodeNumStart( SwPaM* pPaM ) const // return USHRT_MAX, if no list restart value is found. if ( pTextNd && pTextNd->HasAttrListRestartValue() ) { - return static_cast<sal_uInt16>(pTextNd->GetAttrListRestartValue()); + return o3tl::narrowing<sal_uInt16>(pTextNd->GetAttrListRestartValue()); } return USHRT_MAX; } diff --git a/sw/source/core/fields/dbfld.cxx b/sw/source/core/fields/dbfld.cxx index b93c30d8f8f4..cb849d8f6230 100644 --- a/sw/source/core/fields/dbfld.cxx +++ b/sw/source/core/fields/dbfld.cxx @@ -665,7 +665,7 @@ void SwDBNumSetField::Evaluate(const SwDoc& rDoc) if( m_bCondValid && pMgr && pMgr->IsInMerge() && pMgr->IsDataSourceOpen(aTmpData.sDataSource, aTmpData.sCommand, true)) { // condition OK -> adjust current Set - pMgr->ToRecordId(std::max(static_cast<sal_uInt16>(m_aPar2.toInt32()), sal_uInt16(1))-1); + pMgr->ToRecordId(std::max(o3tl::narrowing<sal_uInt16>(m_aPar2.toInt32()), sal_uInt16(1))-1); } } diff --git a/sw/source/core/fields/expfld.cxx b/sw/source/core/fields/expfld.cxx index ceea88941ddb..6ee39cf4d8a0 100644 --- a/sw/source/core/fields/expfld.cxx +++ b/sw/source/core/fields/expfld.cxx @@ -472,7 +472,7 @@ bool SwGetExpField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) break; case FIELD_PROP_USHORT1: rAny >>= nTmp; - m_nSubType = static_cast<sal_uInt16>(nTmp); + m_nSubType = o3tl::narrowing<sal_uInt16>(nTmp); break; case FIELD_PROP_PAR1: { @@ -484,7 +484,7 @@ bool SwGetExpField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) case FIELD_PROP_SUBTYPE: nTmp = lcl_APIToSubType(rAny); if( nTmp >=0 ) - SetSubType( static_cast<sal_uInt16>((GetSubType() & 0xff00) | nTmp)); + SetSubType( o3tl::narrowing<sal_uInt16>((GetSubType() & 0xff00) | nTmp)); break; case FIELD_PROP_BOOL2: if(*o3tl::doAccess<bool>(rAny)) @@ -697,7 +697,7 @@ void SwSetExpFieldType::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) { sal_Int32 nSet = lcl_APIToSubType(rAny); if(nSet >=0) - SetType(static_cast<sal_uInt16>(nSet)); + SetType(o3tl::narrowing<sal_uInt16>(nSet)); } break; case FIELD_PROP_PAR2: @@ -1109,7 +1109,7 @@ bool SwSetExpField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) case FIELD_PROP_SUBTYPE: nTmp32 = lcl_APIToSubType(rAny); if(nTmp32 >= 0) - SetSubType(static_cast<sal_uInt16>((GetSubType() & 0xff00) | nTmp32)); + SetSubType(o3tl::narrowing<sal_uInt16>((GetSubType() & 0xff00) | nTmp32)); break; case FIELD_PROP_PAR3: rAny >>= maPText; diff --git a/sw/source/core/frmedt/fetab.cxx b/sw/source/core/frmedt/fetab.cxx index bf7f1d2d618e..bd82d5deee2c 100644 --- a/sw/source/core/frmedt/fetab.cxx +++ b/sw/source/core/frmedt/fetab.cxx @@ -564,10 +564,10 @@ void SwFEShell::GetTabCols_(SwTabCols &rToFill, const SwFrame *pBox) const } if ( !bDel && - m_pColumnCache->pLastCols->GetLeftMin () == static_cast<sal_uInt16>(nLeftMin) && - m_pColumnCache->pLastCols->GetLeft () == static_cast<sal_uInt16>(aRectFnSet.GetLeft(pTab->getFramePrintArea())) && - m_pColumnCache->pLastCols->GetRight () == static_cast<sal_uInt16>(aRectFnSet.GetRight(pTab->getFramePrintArea()))&& - m_pColumnCache->pLastCols->GetRightMax() == static_cast<sal_uInt16>(nRightMax) - m_pColumnCache->pLastCols->GetLeftMin() ) + m_pColumnCache->pLastCols->GetLeftMin () == o3tl::narrowing<sal_uInt16>(nLeftMin) && + m_pColumnCache->pLastCols->GetLeft () == o3tl::narrowing<sal_uInt16>(aRectFnSet.GetLeft(pTab->getFramePrintArea())) && + m_pColumnCache->pLastCols->GetRight () == o3tl::narrowing<sal_uInt16>(aRectFnSet.GetRight(pTab->getFramePrintArea()))&& + m_pColumnCache->pLastCols->GetRightMax() == o3tl::narrowing<sal_uInt16>(nRightMax) - m_pColumnCache->pLastCols->GetLeftMin() ) { if (m_pColumnCache->pLastCellFrame != pBox) { diff --git a/sw/source/core/frmedt/tblsel.cxx b/sw/source/core/frmedt/tblsel.cxx index 067786a6c2a2..e5aae5f1a945 100644 --- a/sw/source/core/frmedt/tblsel.cxx +++ b/sw/source/core/frmedt/tblsel.cxx @@ -2364,7 +2364,7 @@ void FndBox_::MakeFrames( SwTable &rTable ) i >= 0 && !pSibling; --i ) { SwTableLine *pLine = m_pLineBehind ? m_pLineBehind : - rTable.GetTabLines()[static_cast<sal_uInt16>(i)]; + rTable.GetTabLines()[o3tl::narrowing<sal_uInt16>(i)]; SwIterator<SwRowFrame,SwFormat> aIter( *pLine->GetFrameFormat() ); pSibling = aIter.First(); while ( pSibling && ( diff --git a/sw/source/core/graphic/grfatr.cxx b/sw/source/core/graphic/grfatr.cxx index 703a06d69d3d..b267a55c19d2 100644 --- a/sw/source/core/graphic/grfatr.cxx +++ b/sw/source/core/graphic/grfatr.cxx @@ -332,7 +332,7 @@ bool SwDrawModeGrf::PutValue( const uno::Any& rVal, sal_Int32 eVal = SWUnoHelper::GetEnumAsInt32( rVal ); if(eVal >= 0 && eVal <= sal_uInt16(GraphicDrawMode::Watermark)) { - SetEnumValue(static_cast<sal_uInt16>(eVal)); + SetEnumValue(o3tl::narrowing<sal_uInt16>(eVal)); return true; } return false; diff --git a/sw/source/core/inc/tblrwcl.hxx b/sw/source/core/inc/tblrwcl.hxx index cc1f0a514769..addc40804f74 100644 --- a/sw/source/core/inc/tblrwcl.hxx +++ b/sw/source/core/inc/tblrwcl.hxx @@ -126,7 +126,7 @@ struct SwGCLineBorder SwGCLineBorder( const SwTableBox& rBox ) : pLines( &rBox.GetTabLines() ), pShareFormats(nullptr), nLinePos( 0 ) {} - bool IsLastLine() const { return nLinePos + 1 >= static_cast<sal_uInt16>(pLines->size()); } + bool IsLastLine() const { return nLinePos + 1 >= o3tl::narrowing<sal_uInt16>(pLines->size()); } }; class SwGCBorder_BoxBrd diff --git a/sw/source/core/inc/wrong.hxx b/sw/source/core/inc/wrong.hxx index dcd8503ef6aa..3d32eae81e2f 100644 --- a/sw/source/core/inc/wrong.hxx +++ b/sw/source/core/inc/wrong.hxx @@ -320,7 +320,7 @@ public: return nIdx < maList.size() ? maList[nIdx].mnPos : 0; } - sal_uInt16 Count() const { return static_cast<sal_uInt16>(maList.size()); } + sal_uInt16 Count() const { return o3tl::narrowing<sal_uInt16>(maList.size()); } void Insert( const OUString& rType, css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag, diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx index fe29ecfe2faa..dd434fb6d90c 100644 --- a/sw/source/core/layout/atrfrm.cxx +++ b/sw/source/core/layout/atrfrm.cxx @@ -1098,7 +1098,7 @@ bool SwFormatCol::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) const text::TextColumn* pArray = aSetColumns.getConstArray(); m_aColumns.clear(); //max count is 64k here - this is something the array can't do - sal_uInt16 nCount = std::min( static_cast<sal_uInt16>(aSetColumns.getLength()), + sal_uInt16 nCount = std::min( o3tl::narrowing<sal_uInt16>(aSetColumns.getLength()), sal_uInt16(0x3fff) ); sal_uInt16 nWidthSum = 0; // #101224# one column is no column @@ -2269,7 +2269,7 @@ bool SwTextGridItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) sal_Int16 nTmp = 0; bRet = (rVal >>= nTmp); if( bRet && (nTmp >= 0) ) - SetLines( static_cast<sal_uInt16>(nTmp) ); + SetLines( o3tl::narrowing<sal_uInt16>(nTmp) ); else bRet = false; } @@ -2301,15 +2301,15 @@ bool SwTextGridItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) if( (nMemberId & ~CONVERT_TWIPS) == MID_GRID_BASEHEIGHT ) { nTmp = std::max<sal_Int32>(nTmp, MIN_TEXTGRID_SIZE); - SetBaseHeight( static_cast<sal_uInt16>(nTmp) ); + SetBaseHeight( o3tl::narrowing<sal_uInt16>(nTmp) ); } else if( (nMemberId & ~CONVERT_TWIPS) == MID_GRID_BASEWIDTH ) { nTmp = std::max<sal_Int32>(nTmp, MIN_TEXTGRID_SIZE); - SetBaseWidth( static_cast<sal_uInt16>(nTmp) ); + SetBaseWidth( o3tl::narrowing<sal_uInt16>(nTmp) ); } else - SetRubyHeight( static_cast<sal_uInt16>(nTmp) ); + SetRubyHeight( o3tl::narrowing<sal_uInt16>(nTmp) ); } else bRet = false; diff --git a/sw/source/core/layout/dbg_lay.cxx b/sw/source/core/layout/dbg_lay.cxx index 4f1bc42ecc18..6391f97343d8 100644 --- a/sw/source/core/layout/dbg_lay.cxx +++ b/sw/source/core/layout/dbg_lay.cxx @@ -409,7 +409,7 @@ void SwImplProtocol::CheckLine( OString& rLine ) } break; case 5: - m_nMaxLines = static_cast<sal_uInt16>(nVal); + m_nMaxLines = o3tl::narrowing<sal_uInt16>(nVal); break; case 6: m_aVars.push_back(nVal); diff --git a/sw/source/core/layout/wsfrm.cxx b/sw/source/core/layout/wsfrm.cxx index ca8cc3c8ef9b..600125e48b9c 100644 --- a/sw/source/core/layout/wsfrm.cxx +++ b/sw/source/core/layout/wsfrm.cxx @@ -3412,10 +3412,10 @@ void SwLayoutFrame::Format( vcl::RenderContext* /*pRenderContext*/, const SwBord } } - const sal_uInt16 nLeft = static_cast<sal_uInt16>(pAttrs->CalcLeft(this)); + const sal_uInt16 nLeft = o3tl::narrowing<sal_uInt16>(pAttrs->CalcLeft(this)); const sal_uInt16 nUpper = bHideWhitespace ? 0 : pAttrs->CalcTop(); - const sal_uInt16 nRight = static_cast<sal_uInt16>(pAttrs->CalcRight(this)); + const sal_uInt16 nRight = o3tl::narrowing<sal_uInt16>(pAttrs->CalcRight(this)); const sal_uInt16 nLower = bHideWhitespace ? 0 : pAttrs->CalcBottom(); const bool bVert = IsVertical() && !IsPageFrame(); diff --git a/sw/source/core/table/swnewtable.cxx b/sw/source/core/table/swnewtable.cxx index 85592b9a7458..a2506f59bd7c 100644 --- a/sw/source/core/table/swnewtable.cxx +++ b/sw/source/core/table/swnewtable.cxx @@ -1062,7 +1062,7 @@ SwTableBox& SwTableBox::FindEndOfRowSpan( const SwTable& rTable, sal_uInt16 nMax return *this; if( nMaxStep > --nAbsSpan ) - nMaxStep = static_cast<sal_uInt16>(nAbsSpan); + nMaxStep = o3tl::narrowing<sal_uInt16>(nAbsSpan); const SwTableLine* pMyUpper = GetUpper(); sal_uInt16 nLine = rTable.GetTabLines().GetPos( pMyUpper ); nMaxStep = nLine + nMaxStep; @@ -1388,7 +1388,7 @@ static sal_uInt16 lcl_LineIndex( const SwTable& rTable, const SwSelBoxes& rBoxes nSpan = 0; else if( nSpan ) { - sal_uInt16 nEndOfRowSpan = static_cast<sal_uInt16>(nPos + nRowSpan - 1); + sal_uInt16 nEndOfRowSpan = o3tl::narrowing<sal_uInt16>(nPos + nRowSpan - 1); if( nEndOfRowSpan > nSpan || nSpan == USHRT_MAX ) nSpan = nEndOfRowSpan; } @@ -2101,7 +2101,7 @@ void SwTable::CleanUpBottomRowSpan( sal_uInt16 nDelLines ) if( nRowSp > 1 ) { lcl_ChangeRowSpan( *this, -static_cast<tools::Long>(nDelLines), - static_cast<sal_uInt16>(nLastLine), false ); + o3tl::narrowing<sal_uInt16>(nLastLine), false ); break; } } diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx index fda4da0b85d9..64632d69e583 100644 --- a/sw/source/core/table/swtable.cxx +++ b/sw/source/core/table/swtable.cxx @@ -717,7 +717,7 @@ static void lcl_ProcessBoxSet( SwTableBox *pBox, Parm &rParm ) SwTableBoxes& rTableBoxes = pBox->GetUpper()->GetTabBoxes(); if( nPos && rTableBoxes[ nPos - 1 ]->getRowSpan() != 1 ) nLeftDiff = 0; - if( nPos + 1 < static_cast<sal_uInt16>(rTableBoxes.size()) && + if( nPos + 1 < o3tl::narrowing<sal_uInt16>(rTableBoxes.size()) && rTableBoxes[ nPos + 1 ]->getRowSpan() != 1 ) nRightDiff = 0; } @@ -1177,7 +1177,7 @@ void SwTable::NewSetTabCols( Parm &rParm, const SwTabCols &rNew, nOldPos = lcl_MulDiv64<tools::Long>(nOldPos, rParm.nOldWish, nOldWidth); if( nOldPos != nNewPos && nNewPos > 0 && nOldPos > 0 ) { - ColChange aChg( static_cast<sal_uInt16>(nOldPos), static_cast<sal_uInt16>(nNewPos) ); + ColChange aChg( o3tl::narrowing<sal_uInt16>(nOldPos), o3tl::narrowing<sal_uInt16>(nNewPos) ); aOldNew.push_back( aChg ); } } @@ -1218,7 +1218,7 @@ void SwTable::NewSetTabCols( Parm &rParm, const SwTabCols &rNew, } aRowSpanPos.clear(); } - if( nCurr+1 < static_cast<sal_uInt16>(rLines.size()) ) + if( nCurr+1 < o3tl::narrowing<sal_uInt16>(rLines.size()) ) { ChangeList aCopy; sal_uInt16 nPos = 0; @@ -1236,7 +1236,7 @@ void SwTable::NewSetTabCols( Parm &rParm, const SwTabCols &rNew, lcl_CalcNewWidths( aRowSpanPos, aCopy, rLines[++j], rParm.nOldWish, nOldWidth, false ); lcl_AdjustWidthsInLine( rLines[j], aCopy, rParm, 0 ); - bGoOn = !aRowSpanPos.empty() && j+1 < static_cast<sal_uInt16>(rLines.size()); + bGoOn = !aRowSpanPos.empty() && j+1 < o3tl::narrowing<sal_uInt16>(rLines.size()); } } ::lcl_AdjustWidthsInLine( rLines[nCurr], aOldNew, rParm, COLFUZZY ); @@ -1305,7 +1305,7 @@ sal_uInt16 SwTable::GetBoxNum( OUString& rStr, bool bFirstPart, nRet = 0; if ( !bPerformValidCheck || lcl_IsValidRowName( rStr ) ) { - nRet = static_cast<sal_uInt16>(rStr.toInt32()); + nRet = o3tl::narrowing<sal_uInt16>(rStr.toInt32()); } rStr.clear(); } @@ -1315,7 +1315,7 @@ sal_uInt16 SwTable::GetBoxNum( OUString& rStr, bool bFirstPart, const OUString aText( rStr.copy( 0, nPos ) ); if ( !bPerformValidCheck || lcl_IsValidRowName( aText ) ) { - nRet = static_cast<sal_uInt16>(aText.toInt32()); + nRet = o3tl::narrowing<sal_uInt16>(aText.toInt32()); } rStr = rStr.copy( nPos+1 ); } diff --git a/sw/source/core/text/EnhancedPDFExportHelper.cxx b/sw/source/core/text/EnhancedPDFExportHelper.cxx index 088f21c00b10..ba2f0ad9333f 100644 --- a/sw/source/core/text/EnhancedPDFExportHelper.cxx +++ b/sw/source/core/text/EnhancedPDFExportHelper.cxx @@ -424,7 +424,7 @@ void SwTaggedPDFHelper::BeginTag( vcl::PDFWriter::StructElement eType, const OUS ++m_nEndStructureElement; #if OSL_DEBUG_LEVEL > 1 - aStructStack.push_back( static_cast<sal_uInt16>(eType) ); + aStructStack.push_back( o3tl::narrowing<sal_uInt16>(eType) ); #endif // Store the id of the current structure element if @@ -1117,7 +1117,7 @@ void SwTaggedPDFHelper::BeginBlockStructureElements() int nRealLevel = pTextNd->GetAttrOutlineLevel()-1; nRealLevel = std::min(nRealLevel, 5); - nPDFType = static_cast<sal_uInt16>(vcl::PDFWriter::H1 + nRealLevel); + nPDFType = o3tl::narrowing<sal_uInt16>(vcl::PDFWriter::H1 + nRealLevel); switch(nRealLevel) { case 0 : diff --git a/sw/source/core/text/frmcrsr.cxx b/sw/source/core/text/frmcrsr.cxx index ce29c020fa4a..5f3045f0504b 100644 --- a/sw/source/core/text/frmcrsr.cxx +++ b/sw/source/core/text/frmcrsr.cxx @@ -1418,7 +1418,7 @@ void SwTextFrame::FillCursorPos( SwFillData& rFill ) const if( nDiff > 0 ) { nDiff /= nDist; - rFill.Fill().nParaCnt = static_cast<sal_uInt16>(nDiff + 1); + rFill.Fill().nParaCnt = o3tl::narrowing<sal_uInt16>(nDiff + 1); rFill.nLineWidth = 0; rFill.bInner = false; rFill.bEmpty = true; diff --git a/sw/source/core/text/inftxt.cxx b/sw/source/core/text/inftxt.cxx index 344ccede8962..c399ac758a24 100644 --- a/sw/source/core/text/inftxt.cxx +++ b/sw/source/core/text/inftxt.cxx @@ -426,7 +426,7 @@ void SwTextSizeInfo::GetTextSize( const SwScriptInfo* pSI, const TextFrameIndex aDrawInf.SetSnapToGrid( SnapToGrid() ); aDrawInf.SetKanaComp( nComp ); SwPosSize aSize( m_pFnt->GetTextSize_( aDrawInf ) ); - nMaxSizeDiff = static_cast<sal_uInt16>(aDrawInf.GetKanaDiff()); + nMaxSizeDiff = o3tl::narrowing<sal_uInt16>(aDrawInf.GetKanaDiff()); nMinSize = aSize.Width(); } @@ -955,7 +955,7 @@ static void lcl_DrawSpecial( const SwTextPaintInfo& rTextPaintInfo, const SwLine Point aTmpPos( nX, nY ); rNonConstTextPaintInfo.SetPos( aTmpPos ); sal_uInt16 nOldWidth = rPor.Width(); - const_cast<SwLinePortion&>(rPor).Width( static_cast<sal_uInt16>(aFontSize.Width()) ); + const_cast<SwLinePortion&>(rPor).Width( o3tl::narrowing<sal_uInt16>(aFontSize.Width()) ); rTextPaintInfo.DrawText( aTmp, rPor ); const_cast<SwLinePortion&>(rPor).Width( nOldWidth ); rNonConstTextPaintInfo.SetFont( const_cast<SwFont*>(pOldFnt) ); diff --git a/sw/source/core/text/itradj.cxx b/sw/source/core/text/itradj.cxx index a5944e49e357..8e7514cf9be3 100644 --- a/sw/source/core/text/itradj.cxx +++ b/sw/source/core/text/itradj.cxx @@ -488,7 +488,7 @@ SwTwips SwTextAdjuster::CalcKanaAdj( SwLineLayout* pCurrent ) else nCompress = 10000 - nCompress; - ( pCurrent->GetKanaComp() )[ nKanaIdx ] = static_cast<sal_uInt16>(nCompress); + ( pCurrent->GetKanaComp() )[ nKanaIdx ] = o3tl::narrowing<sal_uInt16>(nCompress); nKanaDiffSum = 0; } @@ -524,7 +524,7 @@ SwTwips SwTextAdjuster::CalcKanaAdj( SwLineLayout* pCurrent ) } else if( pPos->InGlueGrp() && pPos->InFixMargGrp() ) { - pPos->Width( static_cast<sal_uInt16>(pPos->Width() - nDecompress) ); + pPos->Width( o3tl::narrowing<sal_uInt16>(pPos->Width() - nDecompress) ); if ( pPos->InTabGrp() ) // set fix width to width diff --git a/sw/source/core/text/itratr.cxx b/sw/source/core/text/itratr.cxx index f6e298b2d3e0..9571324f8dbe 100644 --- a/sw/source/core/text/itratr.cxx +++ b/sw/source/core/text/itratr.cxx @@ -1432,7 +1432,7 @@ sal_uInt16 SwTextFrame::GetScalingOfSelectedText( SwTextIter aLine(this, &aInf); aLine.CharToLine( nStart ); pOut->SetMapMode( aOldMap ); - return static_cast<sal_uInt16>( nWidth ? + return o3tl::narrowing<sal_uInt16>( nWidth ? ( ( 100 * aLine.GetCurr()->Height() ) / nWidth ) : 0 ); } // no frame or no paragraph, we take the height of the character @@ -1442,7 +1442,7 @@ sal_uInt16 SwTextFrame::GetScalingOfSelectedText( pOut->SetMapMode( aOldMap ); SwDrawTextInfo aDrawInf(pSh, *pOut, GetText(), sal_Int32(nStart), 1); - return static_cast<sal_uInt16>( nWidth ? ((100 * aIter.GetFnt()->GetTextSize_( aDrawInf ).Height()) / nWidth ) : 0 ); + return o3tl::narrowing<sal_uInt16>( nWidth ? ((100 * aIter.GetFnt()->GetTextSize_( aDrawInf ).Height()) / nWidth ) : 0 ); } SwTwips SwTextNode::GetWidthOfLeadingTabs() const diff --git a/sw/source/core/text/itrcrsr.cxx b/sw/source/core/text/itrcrsr.cxx index b728a6ce98ff..f42a84237643 100644 --- a/sw/source/core/text/itrcrsr.cxx +++ b/sw/source/core/text/itrcrsr.cxx @@ -142,7 +142,7 @@ namespace { nListLevel = MAXLEVEL - 1; const SwNumFormat& rNumFormat = - rTextNode.GetNumRule()->Get( static_cast<sal_uInt16>(nListLevel) ); + rTextNode.GetNumRule()->Get( o3tl::narrowing<sal_uInt16>(nListLevel) ); if ( rNumFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT ) { bRet = true; @@ -1625,7 +1625,7 @@ TextFrameIndex SwTextCursor::GetModelPositionForViewPoint( SwPosition *pPos, con nTmpY = pPor->Height() - nTmpY; if( nTmpY < 0 ) nTmpY = 0; - nX = static_cast<sal_uInt16>(nTmpY); + nX = o3tl::narrowing<sal_uInt16>(nTmpY); } if( static_cast<SwMultiPortion*>(pPor)->HasBrackets() ) diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx index c61e05ea0ab9..e672eabb3fce 100644 --- a/sw/source/core/text/itrform2.cxx +++ b/sw/source/core/text/itrform2.cxx @@ -235,7 +235,7 @@ SwLinePortion *SwTextFormatter::Underflow( SwTextFormatInfo &rInf ) // line width is adjusted, so that pPor does not fit to current // line anymore - rInf.Width( static_cast<sal_uInt16>(rInf.X() + (pPor->Width() ? pPor->Width() - 1 : 0)) ); + rInf.Width( o3tl::narrowing<sal_uInt16>(rInf.X() + (pPor->Width() ? pPor->Width() - 1 : 0)) ); rInf.SetLen( pPor->GetLen() ); rInf.SetFull( false ); if( pFly ) @@ -424,7 +424,7 @@ void SwTextFormatter::BuildPortions( SwTextFormatInfo &rInf ) { SwFontScript nNxtActual = rInf.GetFont()->GetActual(); SwFontScript nLstActual = nNxtActual; - sal_uInt16 nLstHeight = static_cast<sal_uInt16>(rInf.GetFont()->GetHeight()); + sal_uInt16 nLstHeight = o3tl::narrowing<sal_uInt16>(rInf.GetFont()->GetHeight()); bool bAllowBehind = false; const CharClass& rCC = GetAppCharClass(); @@ -467,7 +467,7 @@ void SwTextFormatter::BuildPortions( SwTextFormatInfo &rInf ) if ( pTmpFnt ) { nLstActual = pTmpFnt->GetActual(); - nLstHeight = static_cast<sal_uInt16>(pTmpFnt->GetHeight()); + nLstHeight = o3tl::narrowing<sal_uInt16>(pTmpFnt->GetHeight()); } } } @@ -528,7 +528,7 @@ void SwTextFormatter::BuildPortions( SwTextFormatInfo &rInf ) const SwTwips nRestWidth = rInf.Width() - rInf.X(); if ( nKernWidth <= nRestWidth ) - pGridKernPortion->Width( static_cast<sal_uInt16>(nKernWidth) ); + pGridKernPortion->Width( o3tl::narrowing<sal_uInt16>(nKernWidth) ); } if ( pGridKernPortion != pPor ) @@ -615,7 +615,7 @@ void SwTextFormatter::BuildPortions( SwTextFormatInfo &rInf ) (m_pScriptInfo->ScriptType(nTmp - TextFrameIndex(1)) == css::i18n::ScriptType::ASIAN || m_pScriptInfo->ScriptType(nTmp) == css::i18n::ScriptType::ASIAN) ) { - const sal_uInt16 nDist = static_cast<sal_uInt16>(rInf.GetFont()->GetHeight()/5); + const sal_uInt16 nDist = o3tl::narrowing<sal_uInt16>(rInf.GetFont()->GetHeight()/5); if( nDist ) { @@ -670,7 +670,7 @@ void SwTextFormatter::BuildPortions( SwTextFormatInfo &rInf ) 0; const SwTwips nTmpWidth = i * nGridWidth; const SwTwips nKernWidth = std::min(nTmpWidth - nSumWidth, nRestWidth); - const sal_uInt16 nKernWidth_1 = static_cast<sal_uInt16>(nKernWidth / 2); + const sal_uInt16 nKernWidth_1 = o3tl::narrowing<sal_uInt16>(nKernWidth / 2); OSL_ENSURE( nKernWidth <= nRestWidth, "Not enough space left for adjusting non-asian text in grid mode" ); @@ -1431,7 +1431,7 @@ SwLinePortion *SwTextFormatter::NewPortion( SwTextFormatInfo &rInf ) PortionType::TabDecimal == pLastTabPortion->GetWhichPor() ) { OSL_ENSURE( rInf.X() >= pLastTabPortion->GetFix(), "Decimal tab stop position cannot be calculated" ); - const sal_uInt16 nWidthOfPortionsUpToDecimalPosition = static_cast<sal_uInt16>(rInf.X() - pLastTabPortion->GetFix() ); + const sal_uInt16 nWidthOfPortionsUpToDecimalPosition = o3tl::narrowing<sal_uInt16>(rInf.X() - pLastTabPortion->GetFix() ); static_cast<SwTabDecimalPortion*>(pLastTabPortion)->SetWidthOfPortionsUpToDecimalPosition( nWidthOfPortionsUpToDecimalPosition ); rInf.SetTabDecimal( 0 ); } @@ -1806,7 +1806,7 @@ void SwTextFormatter::CalcRealHeight( bool bNewLine ) nTmp = 100; nTmp *= nLineHeight; - nLineHeight = static_cast<sal_uInt16>(nTmp / 100); + nLineHeight = o3tl::narrowing<sal_uInt16>(nTmp / 100); } m_pCurr->SetRealHeight( nLineHeight ); @@ -1841,7 +1841,7 @@ void SwTextFormatter::CalcRealHeight( bool bNewLine ) nTmp /= 100; if( !nTmp ) ++nTmp; - nLineHeight = static_cast<sal_uInt16>(nTmp); + nLineHeight = o3tl::narrowing<sal_uInt16>(nTmp); sal_uInt16 nAsc = ( 4 * nLineHeight ) / 5; // 80% #if 0 // could do clipping here (like Word does) @@ -1899,7 +1899,7 @@ void SwTextFormatter::CalcRealHeight( bool bNewLine ) nTmp += nLineHeight; if (nTmp < 1) nTmp = 1; - nLineHeight = static_cast<sal_uInt16>(nTmp); + nLineHeight = o3tl::narrowing<sal_uInt16>(nTmp); break; } case SvxInterLineSpaceRule::Fix: @@ -2465,7 +2465,7 @@ void SwTextFormatter::CalcFlyWidth( SwTextFormatInfo &rInf ) if( bForced ) { m_pCurr->SetForcedLeftMargin(); - rInf.ForcedLeftMargin( static_cast<sal_uInt16>(aInter.Width()) ); + rInf.ForcedLeftMargin( o3tl::narrowing<sal_uInt16>(aInter.Width()) ); } if( bFullLine ) @@ -2555,7 +2555,7 @@ void SwTextFormatter::CalcFlyWidth( SwTextFormatInfo &rInf ) const tools::Long nNewWidth = ( i - 1 ) * nGridWidth - nOfst; if ( nNewWidth > 0 ) - rInf.Width( static_cast<sal_uInt16>(nNewWidth) ); + rInf.Width( o3tl::narrowing<sal_uInt16>(nNewWidth) ); else rInf.Width( 0 ); diff --git a/sw/source/core/text/porfld.cxx b/sw/source/core/text/porfld.cxx index 26f3dcf56c98..4d589427850c 100644 --- a/sw/source/core/text/porfld.cxx +++ b/sw/source/core/text/porfld.cxx @@ -785,7 +785,7 @@ SwGrfNumPortion::SwGrfNumPortion( m_nYPos = 0; m_eOrient = text::VertOrientation::TOP; } - Width( static_cast<sal_uInt16>(rGrfSize.Width() + 2 * GRFNUM_SECURE) ); + Width( o3tl::narrowing<sal_uInt16>(rGrfSize.Width() + 2 * GRFNUM_SECURE) ); m_nFixWidth = Width(); m_nGrfHeight = rGrfSize.Height() + 2 * GRFNUM_SECURE; Height( sal_uInt16(m_nGrfHeight) ); @@ -834,7 +834,7 @@ bool SwGrfNumPortion::Format( SwTextFormatInfo &rInf ) if( bFull ) { - Width( rInf.Width() - static_cast<sal_uInt16>(rInf.X()) ); + Width( rInf.Width() - o3tl::narrowing<sal_uInt16>(rInf.X()) ); if( bFly ) { SetLen(TextFrameIndex(0)); @@ -1170,7 +1170,7 @@ bool SwCombinedPortion::Format( SwTextFormatInfo &rInf ) { rInf.GetOut()->SetFont( rInf.GetFont()->GetFnt( m_aScrType[i] ) ); m_aWidth[ m_aScrType[i] ] = - static_cast<sal_uInt16>(2 * rInf.GetOut()->GetFontMetric().GetFontSize().Width() / 3); + o3tl::narrowing<sal_uInt16>(2 * rInf.GetOut()->GetFontMetric().GetFontSize().Width() / 3); } } } @@ -1217,7 +1217,7 @@ bool SwCombinedPortion::Format( SwTextFormatInfo &rInf ) SwDrawTextInfo aDrawInf(pSh, *rInf.GetOut(), m_aExpand, i, 1); Size aSize = aTmpFont.GetTextSize_( aDrawInf ); const sal_uInt16 nAsc = aTmpFont.GetAscent( pSh, *rInf.GetOut() ); - m_aPos[ i ] = static_cast<sal_uInt16>(aSize.Width()); + m_aPos[ i ] = o3tl::narrowing<sal_uInt16>(aSize.Width()); if( i == nTop ) // enter the second line { m_nLowPos = nMaxDescent; @@ -1232,7 +1232,7 @@ bool SwCombinedPortion::Format( SwTextFormatInfo &rInf ) if( nAsc > nMaxAscent ) nMaxAscent = nAsc; if( aSize.Height() - nAsc > nMaxDescent ) - nMaxDescent = static_cast<sal_uInt16>(aSize.Height() - nAsc); + nMaxDescent = o3tl::narrowing<sal_uInt16>(aSize.Height() - nAsc); } // for one or two characters we double the width of the portion if( nCount < 3 ) @@ -1295,7 +1295,7 @@ bool SwCombinedPortion::Format( SwTextFormatInfo &rInf ) { if( rInf.GetLineStart() == rInf.GetIdx() && (!rInf.GetLast()->InFieldGrp() || !static_cast<SwFieldPortion*>(rInf.GetLast())->IsFollow() ) ) - Width( static_cast<sal_uInt16>( rInf.Width() - rInf.X() ) ); + Width( o3tl::narrowing<sal_uInt16>( rInf.Width() - rInf.X() ) ); else { Truncate(); diff --git a/sw/source/core/text/porfly.cxx b/sw/source/core/text/porfly.cxx index 8fd2bc4c9d3c..71a7021aa6ff 100644 --- a/sw/source/core/text/porfly.cxx +++ b/sw/source/core/text/porfly.cxx @@ -57,7 +57,7 @@ bool SwFlyPortion::Format( SwTextFormatInfo &rInf ) rInf.GetLastTab()->FormatEOL( rInf ); rInf.GetLast()->FormatEOL( rInf ); - PrtWidth( static_cast<sal_uInt16>(GetFix() - rInf.X() + PrtWidth()) ); + PrtWidth( o3tl::narrowing<sal_uInt16>(GetFix() - rInf.X() + PrtWidth()) ); if( !Width() ) { OSL_ENSURE( Width(), "+SwFlyPortion::Format: a fly is a fly is a fly" ); @@ -81,7 +81,7 @@ bool SwFlyPortion::Format( SwTextFormatInfo &rInf ) SetLen(TextFrameIndex(1)); } - const sal_uInt16 nNewWidth = static_cast<sal_uInt16>(rInf.X() + PrtWidth()); + const sal_uInt16 nNewWidth = o3tl::narrowing<sal_uInt16>(rInf.X() + PrtWidth()); if( rInf.Width() <= nNewWidth ) { Truncate(); @@ -428,7 +428,7 @@ void SwFlyCntPortion::SetBase( const SwTextFrame& rFrame, const Point &rBase, else { mnAscent = 0; - Height( Height() + static_cast<sal_uInt16>(nRelPos) ); + Height( Height() + o3tl::narrowing<sal_uInt16>(nRelPos) ); } } else diff --git a/sw/source/core/text/porlin.cxx b/sw/source/core/text/porlin.cxx index 035f670d464b..e0a157d9d579 100644 --- a/sw/source/core/text/porlin.cxx +++ b/sw/source/core/text/porlin.cxx @@ -88,7 +88,7 @@ void SwLinePortion::PrePaint( const SwTextPaintInfo& rInf, sal_uInt16 nLastWidth = pLast->Width(); if ( pLast->InSpaceGrp() && rInf.GetSpaceAdd() ) - nLastWidth = nLastWidth + static_cast<sal_uInt16>(pLast->CalcSpacing( rInf.GetSpaceAdd(), rInf )); + nLastWidth = nLastWidth + o3tl::narrowing<sal_uInt16>(pLast->CalcSpacing( rInf.GetSpaceAdd(), rInf )); sal_uInt16 nPos; SwTextPaintInfo aInf( rInf ); @@ -246,7 +246,7 @@ bool SwLinePortion::Format( SwTextFormatInfo &rInf ) const SwLinePortion *pLast = rInf.GetLast(); Height( pLast->Height() ); SetAscent( pLast->GetAscent() ); - const sal_uInt16 nNewWidth = static_cast<sal_uInt16>(rInf.X() + PrtWidth()); + const sal_uInt16 nNewWidth = o3tl::narrowing<sal_uInt16>(rInf.X() + PrtWidth()); // Only portions with true width can return true // Notes for example never set bFull==true if( rInf.Width() <= nNewWidth && PrtWidth() && ! IsKernPortion() ) diff --git a/sw/source/core/text/pormulti.cxx b/sw/source/core/text/pormulti.cxx index 0a6bd2b596dc..0c3297e57207 100644 --- a/sw/source/core/text/pormulti.cxx +++ b/sw/source/core/text/pormulti.cxx @@ -654,9 +654,9 @@ void SwRubyPortion::Adjust_( SwTextFormatInfo &rInf ) TextFrameIndex nSub(0); switch ( m_nAdjustment ) { - case css::text::RubyAdjust_CENTER: nRight = static_cast<sal_uInt16>(nLineDiff / 2); + case css::text::RubyAdjust_CENTER: nRight = o3tl::narrowing<sal_uInt16>(nLineDiff / 2); [[fallthrough]]; - case css::text::RubyAdjust_RIGHT: nLeft = static_cast<sal_uInt16>(nLineDiff - nRight); break; + case css::text::RubyAdjust_RIGHT: nLeft = o3tl::narrowing<sal_uInt16>(nLineDiff - nRight); break; case css::text::RubyAdjust_BLOCK: nSub = TextFrameIndex(1); [[fallthrough]]; case css::text::RubyAdjust_INDENT_BLOCK: @@ -683,8 +683,8 @@ void SwRubyPortion::Adjust_( SwTextFormatInfo &rInf ) } if( nLineDiff > 1 ) { - nRight = static_cast<sal_uInt16>(nLineDiff / 2); - nLeft = static_cast<sal_uInt16>(nLineDiff - nRight); + nRight = o3tl::narrowing<sal_uInt16>(nLineDiff / 2); + nLeft = o3tl::narrowing<sal_uInt16>(nLineDiff - nRight); } break; } @@ -2544,7 +2544,7 @@ SwTextCursorSave::SwTextCursorSave( SwTextCursor* pCursor, } if( nSpaceAdd > 0 && !pMulti->HasTabulator() ) - pCursor->m_pCurr->Width( static_cast<sal_uInt16>(nWidth + nSpaceAdd * sal_Int32(nSpaceCnt) / SPACING_PRECISION_FACTOR) ); + pCursor->m_pCurr->Width( o3tl::narrowing<sal_uInt16>(nWidth + nSpaceAdd * sal_Int32(nSpaceCnt) / SPACING_PRECISION_FACTOR) ); // For a BidiPortion we have to calculate the offset from the // end of the portion diff --git a/sw/source/core/text/porrst.cxx b/sw/source/core/text/porrst.cxx index 21a51e135b85..23f837d63051 100644 --- a/sw/source/core/text/porrst.cxx +++ b/sw/source/core/text/porrst.cxx @@ -243,7 +243,7 @@ SwArrowPortion::SwArrowPortion( const SwLinePortion &rPortion ) : SwArrowPortion::SwArrowPortion( const SwTextPaintInfo &rInf ) : m_bLeft( false ) { - Height( static_cast<sal_uInt16>(rInf.GetTextFrame()->getFramePrintArea().Height()) ); + Height( o3tl::narrowing<sal_uInt16>(rInf.GetTextFrame()->getFramePrintArea().Height()) ); m_aPos.setX( rInf.GetTextFrame()->getFrameArea().Left() + rInf.GetTextFrame()->getFramePrintArea().Right() ); m_aPos.setY( rInf.GetTextFrame()->getFrameArea().Top() + @@ -493,7 +493,7 @@ bool SwTextFrame::FillRegister( SwTwips& rRegStart, sal_uInt16& rRegDiff ) nTmp /= 100; if( !nTmp ) ++nTmp; - rRegDiff = static_cast<sal_uInt16>(nTmp); + rRegDiff = o3tl::narrowing<sal_uInt16>(nTmp); nNetHeight = rRegDiff; break; } diff --git a/sw/source/core/text/portxt.cxx b/sw/source/core/text/portxt.cxx index ed9d3c517bb5..c1fa69bcfc68 100644 --- a/sw/source/core/text/portxt.cxx +++ b/sw/source/core/text/portxt.cxx @@ -221,7 +221,7 @@ void SwTextPortion::BreakCut( SwTextFormatInfo &rInf, const SwTextGuess &rGuess // The word/char is larger than the line // Special case 1: The word is larger than the line // We truncate ... - const sal_uInt16 nLineWidth = static_cast<sal_uInt16>(rInf.Width() - rInf.X()); + const sal_uInt16 nLineWidth = o3tl::narrowing<sal_uInt16>(rInf.Width() - rInf.X()); TextFrameIndex nLen = rGuess.CutPos() - rInf.GetIdx(); if (nLen > TextFrameIndex(0)) { diff --git a/sw/source/core/text/txtdrop.cxx b/sw/source/core/text/txtdrop.cxx index e5ac47c692f7..ce39a3e9e1dc 100644 --- a/sw/source/core/text/txtdrop.cxx +++ b/sw/source/core/text/txtdrop.cxx @@ -775,7 +775,7 @@ void SwDropCapCache::CalcFontSize( SwDropPortion* pDrop, SwTextFormatInfo &rInf m_aText[ nTmpIdx ] = aStr; m_aWishedHeight[ nTmpIdx ] = sal_uInt16(nWishedHeight); // save initial scaling factor - m_aFactor[ nTmpIdx ] = static_cast<sal_uInt16>(nFactor); + m_aFactor[ nTmpIdx ] = o3tl::narrowing<sal_uInt16>(nFactor); } bool bGrow = (pDrop->GetLen() != TextFrameIndex(0)); @@ -925,7 +925,7 @@ void SwDropCapCache::CalcFontSize( SwDropPortion* pDrop, SwTextFormatInfo &rInf else { if ( bUseCache ) - m_aFactor[ nTmpIdx ] = static_cast<sal_uInt16>(nFactor); + m_aFactor[ nTmpIdx ] = o3tl::narrowing<sal_uInt16>(nFactor); nMin = nFactor; } @@ -982,7 +982,7 @@ void SwDropCapCache::CalcFontSize( SwDropPortion* pDrop, SwTextFormatInfo &rInf bool SwDropPortion::Format( SwTextFormatInfo &rInf ) { bool bFull = false; - m_nFix = static_cast<sal_uInt16>(rInf.X()); + m_nFix = o3tl::narrowing<sal_uInt16>(rInf.X()); SwLayoutModeModifier aLayoutModeModifier( *rInf.GetOut() ); aLayoutModeModifier.SetAuto(); @@ -1020,7 +1020,7 @@ bool SwDropPortion::Format( SwTextFormatInfo &rInf ) Width(); // set values - pCurrPart->SetWidth( static_cast<sal_uInt16>(nTmpWidth) ); + pCurrPart->SetWidth( o3tl::narrowing<sal_uInt16>(nTmpWidth) ); // Move rInf.SetIdx( rInf.GetIdx() + pCurrPart->GetLen() ); @@ -1029,7 +1029,7 @@ bool SwDropPortion::Format( SwTextFormatInfo &rInf ) } SetJoinBorderWithNext(false); SetJoinBorderWithPrev(false); - Width( static_cast<sal_uInt16>(rInf.X() - nOldX) ); + Width( o3tl::narrowing<sal_uInt16>(rInf.X() - nOldX) ); } // reset my length @@ -1066,7 +1066,7 @@ bool SwDropPortion::Format( SwTextFormatInfo &rInf ) else { const sal_uInt16 nWant = Width() + GetDistance(); - const sal_uInt16 nRest = static_cast<sal_uInt16>(rInf.Width() - rInf.X()); + const sal_uInt16 nRest = o3tl::narrowing<sal_uInt16>(rInf.Width() - rInf.X()); if( ( nWant > nRest ) || lcl_IsDropFlyInter( rInf, Width() + GetDistance(), m_nDropHeight ) ) m_nDistance = 0; diff --git a/sw/source/core/text/txtfly.cxx b/sw/source/core/text/txtfly.cxx index 28ffea4116ab..d91d41ae4a01 100644 --- a/sw/source/core/text/txtfly.cxx +++ b/sw/source/core/text/txtfly.cxx @@ -244,7 +244,7 @@ SwRect SwContourCache::ContourRect( const SwFormat* pFormat, CacheItem item { pObj, // due to #37347 the Object must be entered only after GetContour() std::make_unique<TextRanger>( aPolyPolygon, pPolyPolygon.get(), 20, - static_cast<sal_uInt16>(rLRSpace.GetLeft()), static_cast<sal_uInt16>(rLRSpace.GetRight()), + o3tl::narrowing<sal_uInt16>(rLRSpace.GetLeft()), o3tl::narrowing<sal_uInt16>(rLRSpace.GetRight()), pFormat->GetSurround().IsOutside(), false, pFrame->IsVertical() ) }; mvItems.insert(mvItems.begin(), std::move(item)); diff --git a/sw/source/core/text/txtfrm.cxx b/sw/source/core/text/txtfrm.cxx index d640737b773d..9d7aa1efdec1 100644 --- a/sw/source/core/text/txtfrm.cxx +++ b/sw/source/core/text/txtfrm.cxx @@ -3330,11 +3330,11 @@ sal_uInt32 SwTextFrame::GetParHeight() const if( !HasPara() ) { // For non-empty paragraphs this is a special case // For UnderSized we can simply just ask 1 Twip more - sal_uInt16 nRet = static_cast<sal_uInt16>(getFramePrintArea().SSize().Height()); + sal_uInt16 nRet = o3tl::narrowing<sal_uInt16>(getFramePrintArea().SSize().Height()); if( IsUndersized() ) { if( IsEmpty() || GetText().isEmpty() ) - nRet = static_cast<sal_uInt16>(EmptyHeight()); + nRet = o3tl::narrowing<sal_uInt16>(EmptyHeight()); else ++nRet; } @@ -3485,7 +3485,7 @@ void SwTextFrame::CalcAdditionalFirstLineOffset() nListLevel = MAXLEVEL - 1; const SwNumFormat& rNumFormat = - pTextNode->GetNumRule()->Get( static_cast<sal_uInt16>(nListLevel) ); + pTextNode->GetNumRule()->Get( o3tl::narrowing<sal_uInt16>(nListLevel) ); if ( rNumFormat.GetPositionAndSpaceMode() != SvxNumberFormat::LABEL_ALIGNMENT ) return; @@ -3732,7 +3732,7 @@ sal_uInt16 SwTextFrame::FirstLineHeight() const if ( !HasPara() ) { if( IsEmpty() && isFrameAreaDefinitionValid() ) - return IsVertical() ? static_cast<sal_uInt16>(getFramePrintArea().Width()) : static_cast<sal_uInt16>(getFramePrintArea().Height()); + return IsVertical() ? o3tl::narrowing<sal_uInt16>(getFramePrintArea().Width()) : o3tl::narrowing<sal_uInt16>(getFramePrintArea().Height()); return USHRT_MAX; } const SwParaPortion *pPara = GetPara(); diff --git a/sw/source/core/text/txtftn.cxx b/sw/source/core/text/txtftn.cxx index 5b4b9f7492e0..c35388bccb24 100644 --- a/sw/source/core/text/txtftn.cxx +++ b/sw/source/core/text/txtftn.cxx @@ -1181,7 +1181,7 @@ TextFrameIndex SwTextFormatter::FormatQuoVadis(TextFrameIndex const nOffset) if( nDiff < 0 ) { nLastLeft = pQuo->GetAscent(); - nQuoWidth = static_cast<sal_uInt16>(-nDiff + nLastLeft); + nQuoWidth = o3tl::narrowing<sal_uInt16>(-nDiff + nLastLeft); } else { diff --git a/sw/source/core/text/txttab.cxx b/sw/source/core/text/txttab.cxx index 8e8203c72270..ae8b69ba3bf9 100644 --- a/sw/source/core/text/txttab.cxx +++ b/sw/source/core/text/txttab.cxx @@ -154,7 +154,7 @@ SwTabPortion *SwTextFormatter::NewTabPortion( SwTextFormatInfo &rInf, bool bAuto const SvxTabStopItem& rTab = m_pFrame->GetAttrSet()->GetPool()->GetDefaultItem( RES_PARATR_TABSTOP ); if( rTab.Count() ) - nDefTabDist = static_cast<sal_uInt16>(rTab[0].GetTabPos()); + nDefTabDist = o3tl::narrowing<sal_uInt16>(rTab[0].GetTabPos()); else nDefTabDist = SVX_TAB_DEFDIST; m_aLineInf.SetDefTabStop( nDefTabDist ); @@ -323,7 +323,7 @@ bool SwTabPortion::PreFormat( SwTextFormatInfo &rInf ) OSL_ENSURE( rInf.X() <= GetTabPos(), "SwTabPortion::PreFormat: rush hour" ); // Here we settle down ... - SetFix( static_cast<sal_uInt16>(rInf.X()) ); + SetFix( o3tl::narrowing<sal_uInt16>(rInf.X()) ); IDocumentSettingAccess const& rIDSA(rInf.GetTextFrame()->GetDoc().getIDocumentSettingAccess()); const bool bTabCompat = rIDSA.get(DocumentSettingId::TAB_COMPAT); @@ -387,7 +387,7 @@ bool SwTabPortion::PreFormat( SwTextFormatInfo &rInf ) break; } - PrtWidth( static_cast<sal_uInt16>(GetTabPos() - rInf.X()) ); + PrtWidth( o3tl::narrowing<sal_uInt16>(GetTabPos() - rInf.X()) ); bFull = rInf.Width() <= rInf.X() + PrtWidth(); // In tabulator compatibility mode, we reset the bFull flag @@ -417,7 +417,7 @@ bool SwTabPortion::PreFormat( SwTextFormatInfo &rInf ) // line if there is a fly reducing the line width: !rInf.GetFly() ) { - PrtWidth( static_cast<sal_uInt16>(rInf.Width() - rInf.X()) ); + PrtWidth( o3tl::narrowing<sal_uInt16>(rInf.Width() - rInf.X()) ); SetFixWidth( PrtWidth() ); } else diff --git a/sw/source/core/text/wrong.cxx b/sw/source/core/text/wrong.cxx index 5a70c7be9507..0022f4e453ea 100644 --- a/sw/source/core/text/wrong.cxx +++ b/sw/source/core/text/wrong.cxx @@ -203,7 +203,7 @@ sal_uInt16 SwWrongList::GetWrongPos( sal_Int32 nValue ) const return (rST.mnPos <= nValue && nValue < rST.mnPos + rST.mnLen) || (rST.mnPos > nValue); }); - return static_cast<sal_uInt16>(std::distance(maList.begin(), aIter)); + return o3tl::narrowing<sal_uInt16>(std::distance(maList.begin(), aIter)); } --nMax; @@ -559,7 +559,7 @@ void SwWrongList::Remove(sal_uInt16 nIdx, sal_uInt16 nLen ) i1 += nIdx; std::vector<SwWrongArea>::iterator i2 = i1; - if ( nIdx + nLen >= static_cast<sal_uInt16>(maList.size()) ) + if ( nIdx + nLen >= o3tl::narrowing<sal_uInt16>(maList.size()) ) i2 = maList.end(); // robust else i2 += nLen; @@ -602,10 +602,10 @@ void SwWrongList::RemoveEntry( sal_Int32 nBegin, sal_Int32 nEnd ) { return (rST.mnPos != nBegin) || ((rST.mnPos + rST.mnLen) != nEnd); }); } - auto nDel = static_cast<sal_uInt16>(std::distance(aDelIter, aIter)); + auto nDel = o3tl::narrowing<sal_uInt16>(std::distance(aDelIter, aIter)); if( nDel ) { - auto nDelPos = static_cast<sal_uInt16>(std::distance(maList.cbegin(), aDelIter)); + auto nDelPos = o3tl::narrowing<sal_uInt16>(std::distance(maList.cbegin(), aDelIter)); Remove( nDelPos, nDel ); } } diff --git a/sw/source/core/tox/ToxTextGenerator.cxx b/sw/source/core/tox/ToxTextGenerator.cxx index df37f294796b..199e30256475 100644 --- a/sw/source/core/tox/ToxTextGenerator.cxx +++ b/sw/source/core/tox/ToxTextGenerator.cxx @@ -265,7 +265,7 @@ ToxTextGenerator::GenerateText(SwDoc* pDoc, aCharStyleName = SwResId(STR_POOLCHR_INET_NORMAL); mLinkProcessor->StartNewLink(rText.getLength(), aCharStyleName); } - rBase.FillText( *pTOXNd, aIdx, static_cast<sal_uInt16>(eField), pLayout ); + rBase.FillText( *pTOXNd, aIdx, o3tl::narrowing<sal_uInt16>(eField), pLayout ); if (eField == ToxAuthorityField::AUTH_FIELD_URL) { // Get the absolute URL, the text may be a relative one. diff --git a/sw/source/core/tox/tox.cxx b/sw/source/core/tox/tox.cxx index 466b7d6acdd9..021da63a54e3 100644 --- a/sw/source/core/tox/tox.cxx +++ b/sw/source/core/tox/tox.cxx @@ -860,7 +860,7 @@ lcl_BuildToken(const OUString & sPattern, sal_Int32 & nCurPatternPos) eRet.sCharStyleName = sToken.getToken( 0, ',', nIdx ); OUString sTmp( sToken.getToken( 0, ',', nIdx )); if( !sTmp.isEmpty() ) - eRet.nPoolId = static_cast<sal_uInt16>(sTmp.toInt32()); + eRet.nPoolId = o3tl::narrowing<sal_uInt16>(sTmp.toInt32()); switch( eTokenType ) { @@ -870,10 +870,10 @@ lcl_BuildToken(const OUString & sPattern, sal_Int32 & nCurPatternPos) case TOKEN_ENTRY_NO: sTmp = sToken.getToken( 0, ',', nIdx ); // token 2 if( !sTmp.isEmpty() ) - eRet.nChapterFormat = static_cast<sal_uInt16>(sTmp.toInt32()); + eRet.nChapterFormat = o3tl::narrowing<sal_uInt16>(sTmp.toInt32()); sTmp = sToken.getToken( 0, ',', nIdx ); // token 3 if( !sTmp.isEmpty() ) - eRet.nOutlineLevel = static_cast<sal_uInt16>(sTmp.toInt32()); //the maximum outline level to examine + eRet.nOutlineLevel = o3tl::narrowing<sal_uInt16>(sTmp.toInt32()); //the maximum outline level to examine break; case TOKEN_TEXT: @@ -911,7 +911,7 @@ lcl_BuildToken(const OUString & sPattern, sal_Int32 & nCurPatternPos) break; case TOKEN_AUTHORITY: - eRet.nAuthorityField = static_cast<sal_uInt16>(sAuthFieldEnum.toInt32()); + eRet.nAuthorityField = o3tl::narrowing<sal_uInt16>(sAuthFieldEnum.toInt32()); break; default: break; } diff --git a/sw/source/core/tox/txmsrt.cxx b/sw/source/core/tox/txmsrt.cxx index e0ffc1922701..a67906d0e4ad 100644 --- a/sw/source/core/tox/txmsrt.cxx +++ b/sw/source/core/tox/txmsrt.cxx @@ -136,7 +136,7 @@ SwTOXSortTabBase::SwTOXSortTabBase( TOXSortType nTyp, const SwContentNode* pNd, const SwTOXInternational* pInter, const lang::Locale* pLocale ) : pTOXNd( nullptr ), pTextMark( pMark ), pTOXIntl( pInter ), - nPos( 0 ), nCntPos( 0 ), nType( static_cast<sal_uInt16>(nTyp) ) + nPos( 0 ), nCntPos( 0 ), nType( o3tl::narrowing<sal_uInt16>(nTyp) ) , m_bValidText( false ) { if ( pLocale ) @@ -668,7 +668,7 @@ sal_uInt16 SwTOXPara::GetLevel() const { const int nTmp = static_cast<const SwTextNode*>(pNd)->GetAttrOutlineLevel(); if(nTmp != 0 ) - nRet = static_cast<sal_uInt16>(nTmp); + nRet = o3tl::narrowing<sal_uInt16>(nTmp); } return nRet; } diff --git a/sw/source/core/txtnode/atrftn.cxx b/sw/source/core/txtnode/atrftn.cxx index 884883d10515..2376ca3169c2 100644 --- a/sw/source/core/txtnode/atrftn.cxx +++ b/sw/source/core/txtnode/atrftn.cxx @@ -234,8 +234,8 @@ OUString SwFormatFootnote::GetViewNumStr(const SwDoc& rDoc, const SwFormatFootnoteEndAtTextEnd& rFootnoteEnd = static_cast<const SwFormatFootnoteEndAtTextEnd&>( pSectNd->GetSection().GetFormat()->GetFormatAttr( IsEndNote() ? - static_cast<sal_uInt16>(RES_END_AT_TXTEND) : - static_cast<sal_uInt16>(RES_FTN_AT_TXTEND) ) ); + o3tl::narrowing<sal_uInt16>(RES_END_AT_TXTEND) : + o3tl::narrowing<sal_uInt16>(RES_FTN_AT_TXTEND) ) ); if( FTNEND_ATTXTEND_OWNNUMANDFMT == rFootnoteEnd.GetValue() ) { diff --git a/sw/source/core/txtnode/fntcache.cxx b/sw/source/core/txtnode/fntcache.cxx index 5e3afe0fce96..1da7a73acdee 100644 --- a/sw/source/core/txtnode/fntcache.cxx +++ b/sw/source/core/txtnode/fntcache.cxx @@ -412,7 +412,7 @@ sal_uInt16 SwFntObj::GetFontAscent( const SwViewShell *pSh, const OutputDevice& const vcl::Font aOldFnt( rRefDev.GetFont() ); const_cast<OutputDevice&>(rRefDev).SetFont( *m_pPrtFont ); const FontMetric aOutMet( rRefDev.GetFontMetric() ); - m_nPrtAscent = static_cast<sal_uInt16>(aOutMet.GetAscent()); + m_nPrtAscent = o3tl::narrowing<sal_uInt16>(aOutMet.GetAscent()); const_cast<OutputDevice&>(rRefDev).SetFont( aOldFnt ); } @@ -448,12 +448,12 @@ sal_uInt16 SwFntObj::GetFontHeight( const SwViewShell* pSh, const OutputDevice& CreatePrtFont( rOut ); const vcl::Font aOldFnt( rRefDev.GetFont() ); const_cast<OutputDevice&>(rRefDev).SetFont( *m_pPrtFont ); - m_nPrtHeight = static_cast<sal_uInt16>(rRefDev.GetTextHeight()); + m_nPrtHeight = o3tl::narrowing<sal_uInt16>(rRefDev.GetTextHeight()); #if OSL_DEBUG_LEVEL > 0 // Check if vcl did not change the meaning of GetTextHeight const FontMetric aOutMet( rRefDev.GetFontMetric() ); - tools::Long nTmpPrtHeight = static_cast<sal_uInt16>(aOutMet.GetAscent()) + aOutMet.GetDescent(); + tools::Long nTmpPrtHeight = o3tl::narrowing<sal_uInt16>(aOutMet.GetAscent()) + aOutMet.GetDescent(); // #i106098#: do not compare with == here due to rounding error OSL_ENSURE( std::abs(nTmpPrtHeight - m_nPrtHeight) < 3, "GetTextHeight != Ascent + Descent" ); @@ -485,7 +485,7 @@ sal_uInt16 SwFntObj::GetFontLeading( const SwViewShell *pSh, const OutputDevice& const_cast<OutputDevice&>(rOut).SetFont( aOldFnt ); m_bSymbol = RTL_TEXTENCODING_SYMBOL == aMet.GetCharSet(); GuessLeading( *pSh, aMet ); - m_nExtLeading = static_cast<sal_uInt16>(aMet.GetExternalLeading()); + m_nExtLeading = o3tl::narrowing<sal_uInt16>(aMet.GetExternalLeading()); /* HACK: FIXME There is something wrong with Writer's bullet rendering, causing lines with bullets to be higher than they should be. I think this is because Writer uses font's external leading incorrect, as the vertical distance @@ -569,7 +569,7 @@ void SwFntObj::CreateScrFont( const SwViewShell& rSh, const OutputDevice& rOut ) GuessLeading( rSh, aMet ); if ( USHRT_MAX == m_nExtLeading ) - m_nExtLeading = static_cast<sal_uInt16>(aMet.GetExternalLeading()); + m_nExtLeading = o3tl::narrowing<sal_uInt16>(aMet.GetExternalLeading()); // reset the original reference device font pPrt->SetFont( aOldPrtFnt ); @@ -587,9 +587,9 @@ void SwFntObj::CreateScrFont( const SwViewShell& rSh, const OutputDevice& rOut ) m_pScrFont = m_pPrtFont; } - m_nScrAscent = static_cast<sal_uInt16>(pOut->GetFontMetric().GetAscent()); + m_nScrAscent = o3tl::narrowing<sal_uInt16>(pOut->GetFontMetric().GetAscent()); if ( USHRT_MAX == m_nScrHeight ) - m_nScrHeight = static_cast<sal_uInt16>(pOut->GetTextHeight()); + m_nScrHeight = o3tl::narrowing<sal_uInt16>(pOut->GetTextHeight()); // reset original output device font pOut->SetFont( aOldOutFont ); @@ -653,7 +653,7 @@ void SwFntObj::GuessLeading( const SwViewShell& { OSL_ENSURE( m_nPrtAscent < USHRT_MAX, "GuessLeading: PrtAscent-Fault" ); if ( m_nPrtAscent < USHRT_MAX ) - m_nPrtAscent = m_nPrtAscent + static_cast<sal_uInt16>(( 2 * nDiff ) / 5); + m_nPrtAscent = m_nPrtAscent + o3tl::narrowing<sal_uInt16>(( 2 * nDiff ) / 5); } } } @@ -1175,7 +1175,7 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) lcl_IsMonoSpaceFont( *(rInf.GetpOut()) ) ) { pSI->Compress( pKernArray.get(), rInf.GetIdx(), rInf.GetLen(), - rInf.GetKanaComp(), static_cast<sal_uInt16>(m_aFont.GetFontSize().Height()), lcl_IsFullstopCentered( rInf.GetOut() ) , &aTextOriginPos ); + rInf.GetKanaComp(), o3tl::narrowing<sal_uInt16>(m_aFont.GetFontSize().Height()), lcl_IsFullstopCentered( rInf.GetOut() ) , &aTextOriginPos ); bSpecialJust = true; } ///Asian Justification @@ -1342,7 +1342,7 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) { pSI->Compress( pKernArray.get(), rInf.GetIdx(), rInf.GetLen(), rInf.GetKanaComp(), - static_cast<sal_uInt16>(m_aFont.GetFontSize().Height()), lcl_IsFullstopCentered( rInf.GetOut() ), &aTextOriginPos ); + o3tl::narrowing<sal_uInt16>(m_aFont.GetFontSize().Height()), lcl_IsFullstopCentered( rInf.GetOut() ), &aTextOriginPos ); bSpecialJust = true; } @@ -1551,10 +1551,10 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) Point aTmpPos( aTextOriginPos ); pSI->Compress( pScrArray.get(), rInf.GetIdx(), rInf.GetLen(), rInf.GetKanaComp(), - static_cast<sal_uInt16>(m_aFont.GetFontSize().Height()), lcl_IsFullstopCentered( rInf.GetOut() ), &aTmpPos ); + o3tl::narrowing<sal_uInt16>(m_aFont.GetFontSize().Height()), lcl_IsFullstopCentered( rInf.GetOut() ), &aTmpPos ); pSI->Compress( pKernArray.get(), rInf.GetIdx(), rInf.GetLen(), rInf.GetKanaComp(), - static_cast<sal_uInt16>(m_aFont.GetFontSize().Height()), lcl_IsFullstopCentered( rInf.GetOut() ), &aTextOriginPos ); + o3tl::narrowing<sal_uInt16>(m_aFont.GetFontSize().Height()), lcl_IsFullstopCentered( rInf.GetOut() ), &aTextOriginPos ); } // Asian Justification @@ -2029,7 +2029,7 @@ Size SwFntObj::GetTextSize( SwDrawTextInfo& rInf ) if( bCompress ) rInf.SetKanaDiff( rInf.GetScriptInfo()->Compress( pKernArray.get(), rInf.GetIdx(), nLn, rInf.GetKanaComp(), - static_cast<sal_uInt16>(m_aFont.GetFontSize().Height()) ,lcl_IsFullstopCentered( rInf.GetOut() ) ) ); + o3tl::narrowing<sal_uInt16>(m_aFont.GetFontSize().Height()) ,lcl_IsFullstopCentered( rInf.GetOut() ) ) ); else rInf.SetKanaDiff( 0 ); @@ -2091,7 +2091,7 @@ Size SwFntObj::GetTextSize( SwDrawTextInfo& rInf ) sal_Int32(rInf.GetIdx()), sal_Int32(nLn)); rInf.SetKanaDiff( rInf.GetScriptInfo()->Compress( pKernArray.get(), rInf.GetIdx(), nLn, rInf.GetKanaComp(), - static_cast<sal_uInt16>(m_aFont.GetFontSize().Height()) ,lcl_IsFullstopCentered( rInf.GetOut() ) ) ); + o3tl::narrowing<sal_uInt16>(m_aFont.GetFontSize().Height()) ,lcl_IsFullstopCentered( rInf.GetOut() ) ) ); aTextSize.setWidth( pKernArray[sal_Int32(nLn) - 1] ); } else @@ -2151,7 +2151,7 @@ TextFrameIndex SwFntObj::GetModelPositionForViewPoint(SwDrawTextInfo &rInf) { pSI->Compress( pKernArray.get(), rInf.GetIdx(), rInf.GetLen(), rInf.GetKanaComp(), - static_cast<sal_uInt16>(m_aFont.GetFontSize().Height()), + o3tl::narrowing<sal_uInt16>(m_aFont.GetFontSize().Height()), lcl_IsFullstopCentered( rInf.GetOut() ) ); } @@ -2590,7 +2590,7 @@ TextFrameIndex SwFont::GetTextBreak(SwDrawTextInfo const & rInf, tools::Long nTe rInf.GetOut().GetTextArray( rInf.GetText(), pKernArray.get(), sal_Int32(rInf.GetIdx()), sal_Int32(nLn)); if( rInf.GetScriptInfo()->Compress( pKernArray.get(), rInf.GetIdx(), nLn, - rInf.GetKanaComp(), static_cast<sal_uInt16>(GetHeight( m_nActual )), + rInf.GetKanaComp(), o3tl::narrowing<sal_uInt16>(GetHeight( m_nActual )), lcl_IsFullstopCentered( rInf.GetOut() ) ) ) { tools::Long nKernAdd = nKern; diff --git a/sw/source/core/txtnode/fntcap.cxx b/sw/source/core/txtnode/fntcap.cxx index 66e8014dc183..16b054102c53 100644 --- a/sw/source/core/txtnode/fntcap.cxx +++ b/sw/source/core/txtnode/fntcap.cxx @@ -482,7 +482,7 @@ void SwSubFont::DrawStretchCapital( SwDrawTextInfo &rInf ) rInf.SetLen(TextFrameIndex(rInf.GetText().getLength())); const Point aOldPos = rInf.GetPos(); - const sal_uInt16 nCapWidth = static_cast<sal_uInt16>( GetCapitalSize( rInf ).Width() ); + const sal_uInt16 nCapWidth = o3tl::narrowing<sal_uInt16>( GetCapitalSize( rInf ).Width() ); rInf.SetPos(aOldPos); rInf.SetDrawSpace( GetUnderline() != LINESTYLE_NONE || diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx index 161c22ea2ea0..93b11b1be028 100644 --- a/sw/source/core/txtnode/ndtxt.cxx +++ b/sw/source/core/txtnode/ndtxt.cxx @@ -923,7 +923,7 @@ bool HasNumberingWhichNeedsLayoutUpdate(const SwTextNode& rTextNode) } const SwNumFormat* pFormat - = pNumRule->GetNumFormat(static_cast<sal_uInt16>(rTextNode.GetAttrListLevel())); + = pNumRule->GetNumFormat(o3tl::narrowing<sal_uInt16>(rTextNode.GetAttrListLevel())); if (!pFormat) { return false; @@ -3077,7 +3077,7 @@ namespace sal_uInt16 lcl_BoundListLevel(const int nActualLevel) { - return static_cast<sal_uInt16>( std::clamp( nActualLevel, 0, MAXLEVEL-1 ) ); + return o3tl::narrowing<sal_uInt16>( std::clamp( nActualLevel, 0, MAXLEVEL-1 ) ); } } @@ -4030,7 +4030,7 @@ void SwTextNode::SetAttrOutlineLevel(int nLevel) if ( 0 <= nLevel && nLevel <= MAXLEVEL ) { SetAttr( SfxUInt16Item( RES_PARATR_OUTLINELEVEL, - static_cast<sal_uInt16>(nLevel) ) ); + o3tl::narrowing<sal_uInt16>(nLevel) ) ); } } @@ -4204,7 +4204,7 @@ SwNumberTree::tSwNumTreeNumber SwTextNode::GetActualListStartValue() const if ( pRule ) { const SwNumFormat* pFormat = - pRule->GetNumFormat( static_cast<sal_uInt16>(GetAttrListLevel()) ); + pRule->GetNumFormat( o3tl::narrowing<sal_uInt16>(GetAttrListLevel()) ); if ( pFormat ) { nListRestartValue = pFormat->GetStart(); @@ -4483,7 +4483,7 @@ bool SwTextNode::GetListTabStopPosition( tools::Long& nListTabStopPosition ) con const SwNumRule* pNumRule = GetNum() ? GetNum()->GetNumRule() : nullptr; if ( pNumRule && HasVisibleNumberingOrBullet() && GetActualListLevel() >= 0 ) { - const SwNumFormat& rFormat = pNumRule->Get( static_cast<sal_uInt16>(GetActualListLevel()) ); + const SwNumFormat& rFormat = pNumRule->Get( o3tl::narrowing<sal_uInt16>(GetActualListLevel()) ); if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT && rFormat.GetLabelFollowedBy() == SvxNumberFormat::LISTTAB ) { @@ -4515,7 +4515,7 @@ OUString SwTextNode::GetLabelFollowedBy() const const SwNumRule* pNumRule = GetNum() ? GetNum()->GetNumRule() : nullptr; if ( pNumRule && HasVisibleNumberingOrBullet() && GetActualListLevel() >= 0 ) { - const SwNumFormat& rFormat = pNumRule->Get( static_cast<sal_uInt16>(GetActualListLevel()) ); + const SwNumFormat& rFormat = pNumRule->Get( o3tl::narrowing<sal_uInt16>(GetActualListLevel()) ); if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT ) { switch ( rFormat.GetLabelFollowedBy() ) diff --git a/sw/source/core/txtnode/swfont.cxx b/sw/source/core/txtnode/swfont.cxx index 967f6336186d..620c0d67682a 100644 --- a/sw/source/core/txtnode/swfont.cxx +++ b/sw/source/core/txtnode/swfont.cxx @@ -1081,7 +1081,7 @@ Size SwSubFont::GetTextSize_( SwDrawTextInfo& rInf ) const sal_uInt16 nAscent = pLastFont->GetFontAscent( rInf.GetShell(), rInf.GetOut() ); aTextSize.setHeight( - static_cast<tools::Long>(CalcEscHeight( static_cast<sal_uInt16>(aTextSize.Height()), nAscent)) ); + static_cast<tools::Long>(CalcEscHeight( o3tl::narrowing<sal_uInt16>(aTextSize.Height()), nAscent)) ); } } diff --git a/sw/source/core/txtnode/thints.cxx b/sw/source/core/txtnode/thints.cxx index 41e9adefd9d5..2a97d9017e79 100644 --- a/sw/source/core/txtnode/thints.cxx +++ b/sw/source/core/txtnode/thints.cxx @@ -1863,7 +1863,7 @@ void SwTextNode::TryCharSetExpandToNum(const SfxItemSet& aCharSet) if (!(nLevel != -1 && pCurrNum)) return; - const SwNumFormat* pCurrNumFormat = pCurrNum->GetNumFormat(static_cast<sal_uInt16>(nLevel)); + const SwNumFormat* pCurrNumFormat = pCurrNum->GetNumFormat(o3tl::narrowing<sal_uInt16>(nLevel)); if (!pCurrNumFormat) return; @@ -2101,7 +2101,7 @@ static void lcl_MergeListLevelIndentAsLRSpaceItem( const SwTextNode& rTextNode, const SwNumRule* pRule = rTextNode.GetNumRule(); if ( pRule && rTextNode.GetActualListLevel() >= 0 ) { - const SwNumFormat& rFormat = pRule->Get(static_cast<sal_uInt16>(rTextNode.GetActualListLevel())); + const SwNumFormat& rFormat = pRule->Get(o3tl::narrowing<sal_uInt16>(rTextNode.GetActualListLevel())); if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT ) { SvxLRSpaceItem aLR( RES_LR_SPACE ); @@ -2303,7 +2303,7 @@ bool SwTextNode::GetParaAttr(SfxItemSet& rSet, sal_Int32 nStt, sal_Int32 nEnd, if( rItemPair.mpItem && !IsInvalidItem(rItemPair.mpItem) ) { const sal_uInt16 nWh = - static_cast<sal_uInt16>(n + RES_CHRATR_BEGIN); + o3tl::narrowing<sal_uInt16>(n + RES_CHRATR_BEGIN); if (nEnd <= rItemPair.mnEndPos) // behind or exactly end { diff --git a/sw/source/core/txtnode/txtatr2.cxx b/sw/source/core/txtnode/txtatr2.cxx index f9d23617ece3..71cbb16e2be7 100644 --- a/sw/source/core/txtnode/txtatr2.cxx +++ b/sw/source/core/txtnode/txtatr2.cxx @@ -231,7 +231,7 @@ SwCharFormat* SwTextRuby::GetCharFormat() const SwDoc& rDoc = GetTextNode().GetDoc(); const OUString& rStr = rFormat.GetCharFormatName(); const sal_uInt16 nId = rStr.isEmpty() - ? static_cast<sal_uInt16>(RES_POOLCHR_RUBYTEXT) + ? o3tl::narrowing<sal_uInt16>(RES_POOLCHR_RUBYTEXT) : rFormat.GetCharFormatId(); // JP 10.02.2000, Bug 72806: don't modify the doc for getting the diff --git a/sw/source/core/undo/undobj1.cxx b/sw/source/core/undo/undobj1.cxx index 40ca36552139..aa2d2d624fd2 100644 --- a/sw/source/core/undo/undobj1.cxx +++ b/sw/source/core/undo/undobj1.cxx @@ -102,7 +102,7 @@ void SwUndoFlyBase::InsFly(::sw::UndoRedoContext & rContext, bool bShowSelFrame) if (RndStdIds::FLY_AT_PAGE == m_nRndId) { - aAnchor.SetPageNum( static_cast<sal_uInt16>(m_nNodePagePos) ); + aAnchor.SetPageNum( o3tl::narrowing<sal_uInt16>(m_nNodePagePos) ); } else { diff --git a/sw/source/core/undo/undraw.cxx b/sw/source/core/undo/undraw.cxx index c29e4a9a7713..fc7efcdfec70 100644 --- a/sw/source/core/undo/undraw.cxx +++ b/sw/source/core/undo/undraw.cxx @@ -298,7 +298,7 @@ void SwUndoDrawGroup::SetGroupFormat( SwDrawFrameFormat* pFormat ) SwUndoDrawUnGroup::SwUndoDrawUnGroup( SdrObjGroup* pObj, const SwDoc& rDoc ) : SwUndo( SwUndoId::DRAWUNGROUP, &rDoc ), m_bDeleteFormat( false ) { - m_nSize = static_cast<sal_uInt16>(pObj->GetSubList()->GetObjCount()) + 1; + m_nSize = o3tl::narrowing<sal_uInt16>(pObj->GetSubList()->GetObjCount()) + 1; m_pObjArray.reset( new SwUndoGroupObjImpl[ m_nSize ] ); SwDrawContact *pContact = static_cast<SwDrawContact*>(GetUserCall(pObj)); diff --git a/sw/source/core/undo/unnum.cxx b/sw/source/core/undo/unnum.cxx index aed2397937c7..cf09ad827d82 100644 --- a/sw/source/core/undo/unnum.cxx +++ b/sw/source/core/undo/unnum.cxx @@ -342,7 +342,7 @@ SwUndoNumRuleStart::SwUndoNumRuleStart( const SwPosition& rPos, sal_uInt16 nStt { if ( pTextNd->HasAttrListRestartValue() ) { - m_nOldStart = static_cast<sal_uInt16>(pTextNd->GetAttrListRestartValue()); + m_nOldStart = o3tl::narrowing<sal_uInt16>(pTextNd->GetAttrListRestartValue()); } else { diff --git a/sw/source/core/undo/untbl.cxx b/sw/source/core/undo/untbl.cxx index 0b806e476f6d..28f54bcd7277 100644 --- a/sw/source/core/undo/untbl.cxx +++ b/sw/source/core/undo/untbl.cxx @@ -929,7 +929,7 @@ sal_uInt16 SaveTable::AddFormat( SwFrameFormat* pFormat, bool bIsLine ) m_aSets.push_back(pSet); m_aFrameFormats.insert(m_aFrameFormats.begin() + nRet, pFormat); } - return static_cast<sal_uInt16>(nRet); + return o3tl::narrowing<sal_uInt16>(nRet); } void SaveTable::RestoreAttr( SwTable& rTable, bool bMdfyBox ) diff --git a/sw/source/core/unocore/unocoll.cxx b/sw/source/core/unocore/unocoll.cxx index 9eaefe985b6f..50f0aa61cf38 100644 --- a/sw/source/core/unocore/unocoll.cxx +++ b/sw/source/core/unocore/unocoll.cxx @@ -1860,7 +1860,7 @@ uno::Any SwXReferenceMarks::getByIndex(sal_Int32 nIndex) if(0 <= nIndex && nIndex < SAL_MAX_UINT16) { SwFormatRefMark *const pMark = const_cast<SwFormatRefMark*>( - GetDoc()->GetRefMark(static_cast<sal_uInt16>(nIndex))); + GetDoc()->GetRefMark(o3tl::narrowing<sal_uInt16>(nIndex))); if(pMark) { xRef = SwXReferenceMark::CreateXReferenceMark(*GetDoc(), pMark); diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx index 894e4db8733b..e5c8fb7e1515 100644 --- a/sw/source/core/unocore/unoframe.cxx +++ b/sw/source/core/unocore/unoframe.cxx @@ -1409,7 +1409,7 @@ void SwXFrame::setPropertyValue(const OUString& rPropertyName, const ::uno::Any& } else if(IsDescriptor()) { - m_pProps->SetProperty(static_cast<sal_uInt16>(RES_FRAMEDIR), 0, _rValue); + m_pProps->SetProperty(o3tl::narrowing<sal_uInt16>(RES_FRAMEDIR), 0, _rValue); } return; } @@ -1476,16 +1476,16 @@ void SwXFrame::setPropertyValue(const OUString& rPropertyName, const ::uno::Any& pNoText->SetContour(nullptr); else if(aValue >>= aParam) { - tools::PolyPolygon aPoly(static_cast<sal_uInt16>(aParam.getLength())); + tools::PolyPolygon aPoly(o3tl::narrowing<sal_uInt16>(aParam.getLength())); for(const ::drawing::PointSequence& rPointSeq : std::as_const(aParam)) { sal_Int32 nPoints = rPointSeq.getLength(); const ::awt::Point* pPoints = rPointSeq.getConstArray(); - tools::Polygon aSet( static_cast<sal_uInt16>(nPoints) ); + tools::Polygon aSet( o3tl::narrowing<sal_uInt16>(nPoints) ); for(sal_Int32 j = 0; j < nPoints; j++) { Point aPoint(pPoints[j].X, pPoints[j].Y); - aSet.SetPoint(aPoint, static_cast<sal_uInt16>(j)); + aSet.SetPoint(aPoint, o3tl::narrowing<sal_uInt16>(j)); } // Close polygon if it isn't closed already. aSet.Optimize( PolyOptimizeFlags::CLOSE ); diff --git a/sw/source/core/unocore/unoidx.cxx b/sw/source/core/unocore/unoidx.cxx index c4f5ddf17980..418dfce96797 100644 --- a/sw/source/core/unocore/unoidx.cxx +++ b/sw/source/core/unocore/unoidx.cxx @@ -2557,7 +2557,7 @@ SwXDocumentIndex::StyleAccess_Impl::replaceByIndex( SwGetPoolIdFromName::TxtColl); sSetStyles.append(aString); } - rTOXBase.SetStyleNames(sSetStyles.makeStringAndClear(), static_cast<sal_uInt16>(nIndex)); + rTOXBase.SetStyleNames(sSetStyles.makeStringAndClear(), o3tl::narrowing<sal_uInt16>(nIndex)); } sal_Int32 SAL_CALL @@ -2579,7 +2579,7 @@ SwXDocumentIndex::StyleAccess_Impl::getByIndex(sal_Int32 nIndex) SwTOXBase & rTOXBase( m_xParent->m_pImpl->GetTOXSectionOrThrow() ); const OUString& rStyles = - rTOXBase.GetStyleNames(static_cast<sal_uInt16>(nIndex)); + rTOXBase.GetStyleNames(o3tl::narrowing<sal_uInt16>(nIndex)); const sal_Int32 nStyles = comphelper::string::getTokenCount(rStyles, TOX_STYLE_DELIMITER); uno::Sequence<OUString> aStyles(nStyles); OUString* pStyles = aStyles.getArray(); @@ -2842,7 +2842,7 @@ SwXDocumentIndex::TokenAccess_Impl::replaceByIndex( sPattern.append(aToken.GetString()); } SwForm aForm(rTOXBase.GetTOXForm()); - aForm.SetPattern(static_cast<sal_uInt16>(nIndex), sPattern.makeStringAndClear()); + aForm.SetPattern(o3tl::narrowing<sal_uInt16>(nIndex), sPattern.makeStringAndClear()); rTOXBase.SetTOXForm(aForm); } @@ -2869,7 +2869,7 @@ SwXDocumentIndex::TokenAccess_Impl::getByIndex(sal_Int32 nIndex) // #i21237# SwFormTokens aPattern = rTOXBase.GetTOXForm(). - GetPattern(static_cast<sal_uInt16>(nIndex)); + GetPattern(o3tl::narrowing<sal_uInt16>(nIndex)); sal_Int32 nTokenCount = 0; uno::Sequence< beans::PropertyValues > aRetSeq; diff --git a/sw/source/core/unocore/unoobj.cxx b/sw/source/core/unocore/unoobj.cxx index 079e69ba2abc..c96e8ea28ca1 100644 --- a/sw/source/core/unocore/unoobj.cxx +++ b/sw/source/core/unocore/unoobj.cxx @@ -310,7 +310,7 @@ lcl_SetNodeNumStart(SwPaM & rCursor, uno::Any const& rValue) { sal_Int16 nTmp = 1; rValue >>= nTmp; - sal_uInt16 nStt = (nTmp < 0 ? USHRT_MAX : static_cast<sal_uInt16>(nTmp)); + sal_uInt16 nStt = (nTmp < 0 ? USHRT_MAX : o3tl::narrowing<sal_uInt16>(nTmp)); SwDoc& rDoc = rCursor.GetDoc(); UnoActionContext aAction(&rDoc); @@ -2787,7 +2787,7 @@ bool SwUnoCursorHelper::ConvertSortProperties( LanguageTag::convertToLanguageType( pFields[i].CollatorLocale ); aKeys[i]->sSortType = pFields[i].CollatorAlgorithm; aKeys[i]->nColumnId = - static_cast<sal_uInt16>(pFields[i].Field); + o3tl::narrowing<sal_uInt16>(pFields[i].Field); aKeys[i]->bIsNumeric = (pFields[i].FieldType == table::TableSortFieldType_NUMERIC); aKeys[i]->eSortOrder = (pFields[i].IsAscending) diff --git a/sw/source/core/unocore/unosett.cxx b/sw/source/core/unocore/unosett.cxx index af6633e05222..eedb0fdbaa2d 100644 --- a/sw/source/core/unocore/unosett.cxx +++ b/sw/source/core/unocore/unosett.cxx @@ -1251,7 +1251,7 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetNumberingRuleByIndex( SolarMutexGuard aGuard; OSL_ENSURE( 0 <= nIndex && nIndex < MAXLEVEL, "index out of range" ); - const SwNumFormat& rFormat = rNumRule.Get( static_cast<sal_uInt16>(nIndex) ); + const SwNumFormat& rFormat = rNumRule.Get( o3tl::narrowing<sal_uInt16>(nIndex) ); SwCharFormat* pCharFormat = rFormat.GetCharFormat(); OUString CharStyleName; @@ -1479,7 +1479,7 @@ void SwXNumberingRules::SetNumberingRuleByIndex( SolarMutexGuard aGuard; OSL_ENSURE( 0 <= nIndex && nIndex < MAXLEVEL, "index out of range" ); - SwNumFormat aFormat(rNumRule.Get( static_cast<sal_uInt16>(nIndex) )); + SwNumFormat aFormat(rNumRule.Get( o3tl::narrowing<sal_uInt16>(nIndex) )); OUString sHeadingStyleName; OUString sParagraphStyleName; @@ -1525,7 +1525,7 @@ void SwXNumberingRules::SetNumberingRuleByIndex( } } - rNumRule.Set(static_cast<sal_uInt16>(nIndex), aFormat); + rNumRule.Set(o3tl::narrowing<sal_uInt16>(nIndex), aFormat); } void SwXNumberingRules::SetPropertiesToNumFormat( diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx index 0e2cff68a5b5..ee6c41b11911 100644 --- a/sw/source/core/unocore/unotbl.cxx +++ b/sw/source/core/unocore/unotbl.cxx @@ -204,7 +204,7 @@ static void lcl_SetSpecialProperty(SwFrameFormat* pFormat, sal_Int32 nRepeat = 0; aValue >>= nRepeat; if( nRepeat >= 0 && nRepeat < SAL_MAX_UINT16 ) - pFormat->GetDoc()->SetRowsToRepeat( *pTable, static_cast<sal_uInt16>(nRepeat) ); + pFormat->GetDoc()->SetRowsToRepeat( *pTable, o3tl::narrowing<sal_uInt16>(nRepeat) ); } } break; @@ -2031,8 +2031,8 @@ void SwXTextTable::initialize(sal_Int32 nR, sal_Int32 nC) { if (!m_pImpl->IsDescriptor() || nR <= 0 || nC <= 0 || nR >= SAL_MAX_UINT16 || nC >= SAL_MAX_UINT16) throw uno::RuntimeException(); - m_pImpl->m_nRows = static_cast<sal_uInt16>(nR); - m_pImpl->m_nColumns = static_cast<sal_uInt16>(nC); + m_pImpl->m_nRows = o3tl::narrowing<sal_uInt16>(nR); + m_pImpl->m_nColumns = o3tl::narrowing<sal_uInt16>(nC); } uno::Reference<table::XTableRows> SAL_CALL SwXTextTable::getRows() @@ -2636,7 +2636,7 @@ void SwXTextTable::setPropertyValue(const OUString& rPropertyName, const uno::An aBoxInfo.SetLine(aVertLine.isEmpty() ? nullptr : &aVertLine, SvxBoxInfoItemLine::VERT); aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::VERT, aBorder.IsVerticalLineValid); - aBox.SetAllDistances(static_cast<sal_uInt16>(convertMm100ToTwip(aBorder.Distance))); + aBox.SetAllDistances(o3tl::narrowing<sal_uInt16>(convertMm100ToTwip(aBorder.Distance))); aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::DISTANCE, aBorder.IsDistanceValid); aSet.Put(aBox); @@ -3973,7 +3973,7 @@ void SwXTableRows::insertByIndex(sal_Int32 nIndex, sal_Int32 nCount) // remove actions - TODO: why? UnoActionRemoveContext aRemoveContext(&pUnoCursor->GetDoc()); } - pFrameFormat->GetDoc()->InsertRow(*pUnoCursor, static_cast<sal_uInt16>(nCount), bAppend); + pFrameFormat->GetDoc()->InsertRow(*pUnoCursor, o3tl::narrowing<sal_uInt16>(nCount), bAppend); } void SwXTableRows::removeByIndex(sal_Int32 nIndex, sal_Int32 nCount) @@ -4129,7 +4129,7 @@ void SwXTableColumns::insertByIndex(sal_Int32 nIndex, sal_Int32 nCount) UnoActionRemoveContext aRemoveContext(&pUnoCursor->GetDoc()); } - pFrameFormat->GetDoc()->InsertCol(*pUnoCursor, static_cast<sal_uInt16>(nCount), bAppend); + pFrameFormat->GetDoc()->InsertCol(*pUnoCursor, o3tl::narrowing<sal_uInt16>(nCount), bAppend); } ///@see SwXTableRows::removeByIndex (TODO: seems to be copy and paste programming here) diff --git a/sw/source/core/view/pagepreviewlayout.cxx b/sw/source/core/view/pagepreviewlayout.cxx index ac91694845fe..3c37ba2ced2b 100644 --- a/sw/source/core/view/pagepreviewlayout.cxx +++ b/sw/source/core/view/pagepreviewlayout.cxx @@ -362,9 +362,9 @@ bool SwPagePreviewLayout::Prepare( const sal_uInt16 _nProposedStartPageNum, // determine column and row of proposed start position. // Note: paint starts at point (0,0) const sal_uInt16 nColOfProposed = - static_cast<sal_uInt16>(rProposedStartPos.X() / mnColWidth) + 1; + o3tl::narrowing<sal_uInt16>(rProposedStartPos.X() / mnColWidth) + 1; const sal_uInt16 nRowOfProposed = - static_cast<sal_uInt16>(rProposedStartPos.Y() / mnRowHeight) + 1; + o3tl::narrowing<sal_uInt16>(rProposedStartPos.Y() / mnRowHeight) + 1; // determine start page == page at proposed start position // leaving left-top-corner blank is // controlled by <mbBookPreview>. diff --git a/sw/source/filter/basflt/fltini.cxx b/sw/source/filter/basflt/fltini.cxx index 57e66b9a5e8e..27e7f1e7ba55 100644 --- a/sw/source/filter/basflt/fltini.cxx +++ b/sw/source/filter/basflt/fltini.cxx @@ -354,9 +354,9 @@ void CalculateFlySize(SfxItemSet& rFlySet, const SwNodeIndex& rAnchor, if( nMaxFrame < MINLAY ) nMaxFrame = MINLAY; - if( nWidth > static_cast<sal_uInt16>(nMaxFrame) ) + if( nWidth > o3tl::narrowing<sal_uInt16>(nMaxFrame) ) nWidth = nMaxFrame; - else if( nWidth > static_cast<sal_uInt16>(nMinFrame) ) + else if( nWidth > o3tl::narrowing<sal_uInt16>(nMinFrame) ) nWidth = nMinFrame; } } diff --git a/sw/source/filter/html/css1atr.cxx b/sw/source/filter/html/css1atr.cxx index a5b6deeca699..f8fd83cf47aa 100644 --- a/sw/source/filter/html/css1atr.cxx +++ b/sw/source/filter/html/css1atr.cxx @@ -1927,7 +1927,7 @@ void SwHTMLWriter::OutCSS1_FrameFormatOptions( const SwFrameFormat& rFrameFormat nYPos -= aULItem.GetUpper(); if( nYPos < 0 ) { - aULItem.SetUpper( static_cast<sal_uInt16>(aULItem.GetUpper() + nYPos) ); + aULItem.SetUpper( o3tl::narrowing<sal_uInt16>(aULItem.GetUpper() + nYPos) ); nYPos = 0; } } @@ -1943,7 +1943,7 @@ void SwHTMLWriter::OutCSS1_FrameFormatOptions( const SwFrameFormat& rFrameFormat nXPos -= aLRItem.GetLeft(); if( nXPos < 0 ) { - aLRItem.SetLeft( static_cast<sal_uInt16>(aLRItem.GetLeft() + nXPos) ); + aLRItem.SetLeft( o3tl::narrowing<sal_uInt16>(aLRItem.GetLeft() + nXPos) ); nXPos = 0; } } diff --git a/sw/source/filter/html/htmlatr.cxx b/sw/source/filter/html/htmlatr.cxx index bff41ee81471..f6a169d36fa9 100644 --- a/sw/source/filter/html/htmlatr.cxx +++ b/sw/source/filter/html/htmlatr.cxx @@ -106,12 +106,12 @@ sal_uInt16 SwHTMLWriter::GetDefListLvl( const OUString& rNm, sal_uInt16 nPoolId OUString sDTDD = OOO_STRING_SVTOOLS_HTML_dt " "; if( rNm.startsWith(sDTDD) ) // DefinitionList - term - return static_cast<sal_uInt16>(rNm.copy( sDTDD.getLength() ).toInt32()) | HTML_DLCOLL_DT; + return o3tl::narrowing<sal_uInt16>(rNm.copy( sDTDD.getLength() ).toInt32()) | HTML_DLCOLL_DT; sDTDD = OOO_STRING_SVTOOLS_HTML_dd " "; if( rNm.startsWith(sDTDD) ) // DefinitionList - definition - return static_cast<sal_uInt16>(rNm.copy( sDTDD.getLength() ).toInt32()) | HTML_DLCOLL_DD; + return o3tl::narrowing<sal_uInt16>(rNm.copy( sDTDD.getLength() ).toInt32()) | HTML_DLCOLL_DD; return 0; } diff --git a/sw/source/filter/html/htmldrawreader.cxx b/sw/source/filter/html/htmldrawreader.cxx index 90ac85467903..61ab1d493982 100644 --- a/sw/source/filter/html/htmldrawreader.cxx +++ b/sw/source/filter/html/htmldrawreader.cxx @@ -94,8 +94,8 @@ void SwHTMLParser::InsertDrawObject( SdrObject* pNewDrawObj, aTwipSpc = Application::GetDefaultDevice()->PixelToLogic( aTwipSpc, MapMode(MapUnit::MapTwip) ); - nLeftSpace = nRightSpace = static_cast<sal_uInt16>(aTwipSpc.Width()); - nUpperSpace = nLowerSpace = static_cast<sal_uInt16>(aTwipSpc.Height()); + nLeftSpace = nRightSpace = o3tl::narrowing<sal_uInt16>(aTwipSpc.Width()); + nUpperSpace = nLowerSpace = o3tl::narrowing<sal_uInt16>(aTwipSpc.Height()); } // set left/right border @@ -307,7 +307,7 @@ void SwHTMLParser::NewMarquee( HTMLTable *pCurTable ) break; case HtmlOptionId::SCROLLDELAY: - nDelay = static_cast<sal_uInt16>(rOption.GetNumber()); + nDelay = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); break; case HtmlOptionId::WIDTH: diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx index 50a5a648efae..725ec85f8393 100644 --- a/sw/source/filter/html/htmlflywriter.cxx +++ b/sw/source/filter/html/htmlflywriter.cxx @@ -615,7 +615,7 @@ OString SwHTMLWriter::OutFrameFormatOptions( const SwFrameFormat &rFrameFormat, aTwipSpc.setHeight( ( static_cast<const SvxULSpaceItem*>(pItem)->GetUpper() + static_cast<const SvxULSpaceItem*>(pItem)->GetLower() ) / 2 ); - m_nDfltTopMargin = m_nDfltBottomMargin = static_cast<sal_uInt16>(aTwipSpc.Height()); + m_nDfltTopMargin = m_nDfltBottomMargin = o3tl::narrowing<sal_uInt16>(aTwipSpc.Height()); } if( (nFrameOpts & HtmlFrmOpts::Space) && @@ -880,7 +880,7 @@ void SwHTMLWriter::writeFrameFormatOptions(HtmlWriter& aHtml, const SwFrameForma aTwipSpc.setHeight( ( static_cast<const SvxULSpaceItem*>(pItem)->GetUpper() + static_cast<const SvxULSpaceItem*>(pItem)->GetLower() ) / 2 ); - m_nDfltTopMargin = m_nDfltBottomMargin = static_cast<sal_uInt16>(aTwipSpc.Height()); + m_nDfltTopMargin = m_nDfltBottomMargin = o3tl::narrowing<sal_uInt16>(aTwipSpc.Height()); } if( (nFrameOptions & HtmlFrmOpts::Space) && @@ -1344,7 +1344,7 @@ Writer& OutHTML_Image( Writer& rWrt, const SwFrameFormat &rFrameFormat, aPixelBorder.setHeight( 0 ); nBorderWidth = - static_cast<sal_uInt16>(aPixelBorder.Width() + aPixelBorder.Height()); + o3tl::narrowing<sal_uInt16>(aPixelBorder.Width() + aPixelBorder.Height()); } if( pColBorderLine ) @@ -1596,7 +1596,7 @@ static Writer & OutHTML_FrameFormatAsMulticol( Writer& rWrt, { if( nGutter && Application::GetDefaultDevice() ) { - nGutter = static_cast<sal_uInt16>(Application::GetDefaultDevice() + nGutter = o3tl::narrowing<sal_uInt16>(Application::GetDefaultDevice() ->LogicToPixel( Size(nGutter,0), MapMode(MapUnit::MapTwip) ).Width()); } diff --git a/sw/source/filter/html/htmlform.cxx b/sw/source/filter/html/htmlform.cxx index 3c064d600bee..4466602c5ca3 100644 --- a/sw/source/filter/html/htmlform.cxx +++ b/sw/source/filter/html/htmlform.cxx @@ -1448,7 +1448,7 @@ void SwHTMLParser::InsertInput() nMaxLen = static_cast<sal_Int16>(rOption.GetNumber()); break; case HtmlOptionId::SIZE: - nSize = static_cast<sal_uInt16>(rOption.GetNumber()); + nSize = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); break; case HtmlOptionId::SRC: sImgSrc = rOption.GetString(); @@ -1907,10 +1907,10 @@ void SwHTMLParser::NewTextArea() bDisabled = true; break; case HtmlOptionId::ROWS: - nRows = static_cast<sal_uInt16>(rOption.GetNumber()); + nRows = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); break; case HtmlOptionId::COLS: - nCols = static_cast<sal_uInt16>(rOption.GetNumber()); + nCols = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); break; case HtmlOptionId::WRAP: nWrap = rOption.GetEnum( aHTMLTextAreaWrapTable, nWrap ); @@ -2188,7 +2188,7 @@ void SwHTMLParser::NewSelect() bDisabled = true; break; case HtmlOptionId::SIZE: - m_nSelectEntryCnt = static_cast<sal_uInt16>(rOption.GetNumber()); + m_nSelectEntryCnt = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); break; case HtmlOptionId::TABINDEX: diff --git a/sw/source/filter/html/htmlftn.cxx b/sw/source/filter/html/htmlftn.cxx index 0f0a0098e1a8..ebd80a589d07 100644 --- a/sw/source/filter/html/htmlftn.cxx +++ b/sw/source/filter/html/htmlftn.cxx @@ -95,7 +95,7 @@ static sal_Int32 lcl_html_getEndNoteInfo( SwEndNoteInfo& rInfo, break; case 1: - rInfo.m_nFootnoteOffset = aPart.isEmpty() ? 0 : static_cast<sal_uInt16>(aPart.toInt32()); + rInfo.m_nFootnoteOffset = aPart.isEmpty() ? 0 : o3tl::narrowing<sal_uInt16>(aPart.toInt32()); break; case 2: diff --git a/sw/source/filter/html/htmlgrin.cxx b/sw/source/filter/html/htmlgrin.cxx index 7b0c49cc3f3a..e52da66d701f 100644 --- a/sw/source/filter/html/htmlgrin.cxx +++ b/sw/source/filter/html/htmlgrin.cxx @@ -402,7 +402,7 @@ void SwHTMLParser::InsertImage() sAltNm = rOption.GetString(); break; case HtmlOptionId::BORDER: - nBorder = static_cast<sal_uInt16>(rOption.GetNumber()); + nBorder = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); break; case HtmlOptionId::ISMAP: bIsMap = true; diff --git a/sw/source/filter/html/htmlnum.cxx b/sw/source/filter/html/htmlnum.cxx index 345645a240c8..2fdb68e7ae58 100644 --- a/sw/source/filter/html/htmlnum.cxx +++ b/sw/source/filter/html/htmlnum.cxx @@ -27,7 +27,7 @@ void SwHTMLNumRuleInfo::Set(const SwTextNode& rTextNd) if (pTextNdNumRule && pTextNdNumRule != rTextNd.GetDoc().GetOutlineNumRule()) { pNumRule = const_cast<SwNumRule*>(pTextNdNumRule); - nDeep = static_cast<sal_uInt16>(pNumRule ? rTextNd.GetActualListLevel() + 1 : 0); + nDeep = o3tl::narrowing<sal_uInt16>(pNumRule ? rTextNd.GetActualListLevel() + 1 : 0); bNumbered = rTextNd.IsCountedInList(); // #i57919# - correction of refactoring done by cws swnumtree: // <bRestart> has to be set to <true>, if numbering is restarted at this diff --git a/sw/source/filter/html/htmlnumreader.cxx b/sw/source/filter/html/htmlnumreader.cxx index feaee46f4cb3..3c25dacdb3e0 100644 --- a/sw/source/filter/html/htmlnumreader.cxx +++ b/sw/source/filter/html/htmlnumreader.cxx @@ -165,7 +165,7 @@ void SwHTMLParser::NewNumberBulletList( HtmlTokenId nToken ) break; case HtmlOptionId::START: { - sal_uInt16 nStart = static_cast<sal_uInt16>(rOption.GetNumber()); + sal_uInt16 nStart = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); if( bNewNumFormat ) { aNumFormat.SetStart( nStart ); @@ -198,10 +198,10 @@ void SwHTMLParser::NewNumberBulletList( HtmlTokenId nToken ) } break; case HtmlOptionId::WIDTH: - nWidth = static_cast<sal_uInt16>(rOption.GetNumber()); + nWidth = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); break; case HtmlOptionId::HEIGHT: - nHeight = static_cast<sal_uInt16>(rOption.GetNumber()); + nHeight = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); break; case HtmlOptionId::ALIGN: eVertOri = rOption.GetEnum( aHTMLImgVAlignTable, eVertOri ); @@ -441,7 +441,7 @@ void SwHTMLParser::NewNumberBulletListItem( HtmlTokenId nToken ) switch( rOption.GetToken() ) { case HtmlOptionId::VALUE: - nStart = static_cast<sal_uInt16>(rOption.GetNumber()); + nStart = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); break; case HtmlOptionId::ID: aId = rOption.GetString(); diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx index b18b695d27e8..5ce2ab50d90b 100644 --- a/sw/source/filter/html/htmlplug.cxx +++ b/sw/source/filter/html/htmlplug.cxx @@ -252,7 +252,7 @@ void SwHTMLParser::SetSpace( const Size& rPixSpace, Application::GetDefaultDevice()->PixelToLogic( aTwipSpc, MapMode(MapUnit::MapTwip) ); nLeftSpace = nRightSpace = aTwipSpc.Width(); - nUpperSpace = nLowerSpace = static_cast<sal_uInt16>(aTwipSpc.Height()); + nUpperSpace = nLowerSpace = o3tl::narrowing<sal_uInt16>(aTwipSpc.Height()); } // set left/right margin diff --git a/sw/source/filter/html/htmlsect.cxx b/sw/source/filter/html/htmlsect.cxx index d68a22e2e389..9d71125cc6f1 100644 --- a/sw/source/filter/html/htmlsect.cxx +++ b/sw/source/filter/html/htmlsect.cxx @@ -579,7 +579,7 @@ void SwHTMLParser::NewMultiCol( sal_uInt16 columnsFromCss ) aDir = rOption.GetString(); break; case HtmlOptionId::COLS: - nCols = static_cast<sal_uInt16>(rOption.GetNumber()); + nCols = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); break; case HtmlOptionId::WIDTH: nWidth = rOption.GetNumber(); @@ -588,7 +588,7 @@ void SwHTMLParser::NewMultiCol( sal_uInt16 columnsFromCss ) nWidth = 100; break; case HtmlOptionId::GUTTER: - nGutter = static_cast<sal_uInt16>(rOption.GetNumber()); + nGutter = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); break; default: break; } @@ -707,7 +707,7 @@ void SwHTMLParser::NewMultiCol( sal_uInt16 columnsFromCss ) if( nGutter && Application::GetDefaultDevice() ) { - nGutter = static_cast<sal_uInt16>(Application::GetDefaultDevice() + nGutter = o3tl::narrowing<sal_uInt16>(Application::GetDefaultDevice() ->PixelToLogic( Size(nGutter, 0), MapMode(MapUnit::MapTwip) ).Width()); } diff --git a/sw/source/filter/html/htmltab.cxx b/sw/source/filter/html/htmltab.cxx index 5149640c6bdd..8969248fee90 100644 --- a/sw/source/filter/html/htmltab.cxx +++ b/sw/source/filter/html/htmltab.cxx @@ -945,7 +945,7 @@ void HTMLTable::InitCtor(const HTMLTableOptions& rOptions) // nBorder tells the width of the border as it's used in the width calculation of NetScape // If pOption->nBorder == USHRT_MAX, there wasn't a BORDER option given // Nonetheless, a 1 pixel wide border will be used for width calculation - m_nBorder = static_cast<sal_uInt16>(nPWidth); + m_nBorder = o3tl::narrowing<sal_uInt16>(nPWidth); if( nBorderOpt==USHRT_MAX ) nPWidth = 0; @@ -1004,8 +1004,8 @@ void HTMLTable::InitCtor(const HTMLTableOptions& rOptions) nPWidth = rOptions.nHSpace; nPHeight = rOptions.nVSpace; SvxCSS1Parser::PixelToTwip( nPWidth, nPHeight ); - m_nHSpace = static_cast<sal_uInt16>(nPWidth); - m_nVSpace = static_cast<sal_uInt16>(nPHeight); + m_nHSpace = o3tl::narrowing<sal_uInt16>(nPWidth); + m_nVSpace = o3tl::narrowing<sal_uInt16>(nPHeight); m_bColSpec = false; @@ -2022,14 +2022,14 @@ void HTMLTable::InsertCell( std::shared_ptr<HTMLTableCnts> const& rCnts, // Only set width on the first cell! if( nCellWidth ) { - sal_uInt16 nTmp = bRelWidth ? nCellWidth : static_cast<sal_uInt16>(aTwipSz.Width()); + sal_uInt16 nTmp = bRelWidth ? nCellWidth : o3tl::narrowing<sal_uInt16>(aTwipSz.Width()); GetCell( m_nCurrentRow, m_nCurrentColumn ).SetWidth( nTmp, bRelWidth ); } // Remember height if( nCellHeight && 1==nRowSpan ) { - m_aRows[m_nCurrentRow].SetHeight(static_cast<sal_uInt16>(aTwipSz.Height())); + m_aRows[m_nCurrentRow].SetHeight(o3tl::narrowing<sal_uInt16>(aTwipSz.Height())); } // Set the column counter behind the new cells @@ -2156,7 +2156,7 @@ void HTMLTable::InsertCol( sal_uInt16 nSpan, sal_uInt16 nColWidth, bool bRelWidt for( i=m_nCurrentColumn; i<nColsReq; i++ ) { HTMLTableColumn& rCol = m_aColumns[i]; - sal_uInt16 nTmp = bRelWidth ? nColWidth : static_cast<sal_uInt16>(aTwipSz.Width()); + sal_uInt16 nTmp = bRelWidth ? nColWidth : o3tl::narrowing<sal_uInt16>(aTwipSz.Width()); rCol.SetWidth( nTmp, bRelWidth ); rCol.SetAdjust( eAdjust ); rCol.SetVertOri( eVertOrient ); @@ -2481,7 +2481,7 @@ void HTMLTable::RegisterDrawObject( SdrObject *pObj, sal_uInt8 nPercentWidth ) m_pDrawObjectPercentWidths.reset(new std::vector<sal_uInt16>); m_pDrawObjectPercentWidths->push_back( m_nCurrentRow ); m_pDrawObjectPercentWidths->push_back( m_nCurrentColumn ); - m_pDrawObjectPercentWidths->push_back( static_cast<sal_uInt16>(nPercentWidth) ); + m_pDrawObjectPercentWidths->push_back( o3tl::narrowing<sal_uInt16>(nPercentWidth) ); } void HTMLTable::MakeParentContents() @@ -2891,7 +2891,7 @@ CellSaveStruct::CellSaveStruct( SwHTMLParser& rParser, HTMLTable const *pCurTabl m_aId = rOption.GetString(); break; case HtmlOptionId::COLSPAN: - m_nColSpan = static_cast<sal_uInt16>(rOption.GetNumber()); + m_nColSpan = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); if (m_nColSpan > 256) { SAL_INFO("sw.html", "ignoring huge COLSPAN " << m_nColSpan); @@ -2899,7 +2899,7 @@ CellSaveStruct::CellSaveStruct( SwHTMLParser& rParser, HTMLTable const *pCurTabl } break; case HtmlOptionId::ROWSPAN: - m_nRowSpan = static_cast<sal_uInt16>(rOption.GetNumber()); + m_nRowSpan = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); if (m_nRowSpan > 8192 || (m_nRowSpan > 256 && utl::ConfigManager::IsFuzzing())) { SAL_INFO("sw.html", "ignoring huge ROWSPAN " << m_nRowSpan); @@ -2913,13 +2913,13 @@ CellSaveStruct::CellSaveStruct( SwHTMLParser& rParser, HTMLTable const *pCurTabl m_eVertOri = rOption.GetEnum( aHTMLTableVAlignTable, m_eVertOri ); break; case HtmlOptionId::WIDTH: - m_nWidth = static_cast<sal_uInt16>(rOption.GetNumber()); // Just for Netscape + m_nWidth = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); // Just for Netscape m_bPercentWidth = (rOption.GetString().indexOf('%') != -1); if( m_bPercentWidth && m_nWidth>100 ) m_nWidth = 100; break; case HtmlOptionId::HEIGHT: - m_nHeight = static_cast<sal_uInt16>(rOption.GetNumber()); // Just for Netscape + m_nHeight = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); // Just for Netscape if( rOption.GetString().indexOf('%') != -1) m_nHeight = 0; // don't consider % attributes break; @@ -4308,7 +4308,7 @@ void SwHTMLParser::BuildTableColGroup( HTMLTable *pCurTable, InsertBookmark( rOption.GetString() ); break; case HtmlOptionId::SPAN: - pSaveStruct->nColGrpSpan = static_cast<sal_uInt16>(rOption.GetNumber()); + pSaveStruct->nColGrpSpan = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); if (pSaveStruct->nColGrpSpan > 256) { SAL_INFO("sw.html", "ignoring huge SPAN " << pSaveStruct->nColGrpSpan); @@ -4316,7 +4316,7 @@ void SwHTMLParser::BuildTableColGroup( HTMLTable *pCurTable, } break; case HtmlOptionId::WIDTH: - pSaveStruct->nColGrpWidth = static_cast<sal_uInt16>(rOption.GetNumber()); + pSaveStruct->nColGrpWidth = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); pSaveStruct->bRelColGrpWidth = (rOption.GetString().indexOf('*') != -1); break; @@ -4395,7 +4395,7 @@ void SwHTMLParser::BuildTableColGroup( HTMLTable *pCurTable, InsertBookmark( rOption.GetString() ); break; case HtmlOptionId::SPAN: - nColSpan = static_cast<sal_uInt16>(rOption.GetNumber()); + nColSpan = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); if (nColSpan > 256) { SAL_INFO("sw.html", "ignoring huge SPAN " << nColSpan); @@ -4403,7 +4403,7 @@ void SwHTMLParser::BuildTableColGroup( HTMLTable *pCurTable, } break; case HtmlOptionId::WIDTH: - nColWidth = static_cast<sal_uInt16>(rOption.GetNumber()); + nColWidth = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); bRelColWidth = (rOption.GetString().indexOf('*') != -1); break; @@ -4754,24 +4754,24 @@ HTMLTableOptions::HTMLTableOptions( const HTMLOptions& rOptions, aId = rOption.GetString(); break; case HtmlOptionId::COLS: - nCols = static_cast<sal_uInt16>(rOption.GetNumber()); + nCols = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); break; case HtmlOptionId::WIDTH: - nWidth = static_cast<sal_uInt16>(rOption.GetNumber()); + nWidth = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); bPercentWidth = (rOption.GetString().indexOf('%') != -1); if( bPercentWidth && nWidth>100 ) nWidth = 100; break; case HtmlOptionId::HEIGHT: - nHeight = static_cast<sal_uInt16>(rOption.GetNumber()); + nHeight = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); if( rOption.GetString().indexOf('%') != -1 ) nHeight = 0; // don't use % attributes break; case HtmlOptionId::CELLPADDING: - nCellPadding = static_cast<sal_uInt16>(rOption.GetNumber()); + nCellPadding = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); break; case HtmlOptionId::CELLSPACING: - nCellSpacing = static_cast<sal_uInt16>(rOption.GetNumber()); + nCellSpacing = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); break; case HtmlOptionId::ALIGN: { @@ -4790,7 +4790,7 @@ HTMLTableOptions::HTMLTableOptions( const HTMLOptions& rOptions, !rOption.GetString().equalsIgnoreAsciiCase( OOO_STRING_SVTOOLS_HTML_O_border)) { - nBorder = static_cast<sal_uInt16>(rOption.GetNumber()); + nBorder = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); } else nBorder = 1; @@ -4838,10 +4838,10 @@ HTMLTableOptions::HTMLTableOptions( const HTMLOptions& rOptions, aDir = rOption.GetString(); break; case HtmlOptionId::HSPACE: - nHSpace = static_cast<sal_uInt16>(rOption.GetNumber()); + nHSpace = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); break; case HtmlOptionId::VSPACE: - nVSpace = static_cast<sal_uInt16>(rOption.GetNumber()); + nVSpace = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); break; default: break; } @@ -5170,7 +5170,7 @@ std::shared_ptr<HTMLTable> SwHTMLParser::BuildTable(SvxAdjust eParentAdjust, } // Process SwTable - sal_uInt16 nBrowseWidth = static_cast<sal_uInt16>(GetCurrentBrowseWidth()); + sal_uInt16 nBrowseWidth = o3tl::narrowing<sal_uInt16>(GetCurrentBrowseWidth()); xSaveStruct->MakeTable(nBrowseWidth, *m_pPam->GetPoint(), m_xDoc.get()); } diff --git a/sw/source/filter/html/htmltabw.cxx b/sw/source/filter/html/htmltabw.cxx index af5f67922bed..5657b2fe1eb5 100644 --- a/sw/source/filter/html/htmltabw.cxx +++ b/sw/source/filter/html/htmltabw.cxx @@ -118,7 +118,7 @@ void SwHTMLWrtTable::Pixelize( sal_uInt16& rValue ) if( !aSz.Width() ) aSz.setWidth( 1 ); aSz = Application::GetDefaultDevice()->PixelToLogic( aSz, MapMode(MapUnit::MapTwip) ); - rValue = static_cast<sal_uInt16>(aSz.Width()); + rValue = o3tl::narrowing<sal_uInt16>(aSz.Width()); } } @@ -915,7 +915,7 @@ Writer& OutHTML_SwTableNode( Writer& rWrt, SwTableNode & rNode, const SwFormatFrameSize& rFrameSize = pFormat->GetFrameSize(); tools::Long nWidth = rFrameSize.GetSize().Width(); sal_uInt8 nPercentWidth = rFrameSize.GetWidthPercent(); - sal_uInt16 nBaseWidth = static_cast<sal_uInt16>(nWidth); + sal_uInt16 nBaseWidth = o3tl::narrowing<sal_uInt16>(nWidth); sal_Int16 eTabHoriOri = pFormat->GetHoriOrient().GetHoriOrient(); diff --git a/sw/source/filter/html/svxcss1.cxx b/sw/source/filter/html/svxcss1.cxx index 9ff8244ca50b..ecb8729de900 100644 --- a/sw/source/filter/html/svxcss1.cxx +++ b/sw/source/filter/html/svxcss1.cxx @@ -1013,7 +1013,7 @@ static void ParseCSS1_font_size( const CSS1Expression *pExpr, break; case CSS1_PERCENTAGE: // only for drop caps! - nPropHeight = static_cast<sal_uInt16>(pExpr->GetNumber()); + nPropHeight = o3tl::narrowing<sal_uInt16>(pExpr->GetNumber()); break; case CSS1_IDENT: { @@ -1139,7 +1139,7 @@ static void ParseCSS1_font_weight( const CSS1Expression *pExpr, break; case CSS1_NUMBER: { - sal_uInt16 nWeight = static_cast<sal_uInt16>(pExpr->GetNumber()); + sal_uInt16 nWeight = o3tl::narrowing<sal_uInt16>(pExpr->GetNumber()); SvxWeightItem aWeight( nWeight>400 ? WEIGHT_BOLD : WEIGHT_NORMAL, aItemIds.nWeight ); rItemSet.Put( aWeight ); @@ -1448,7 +1448,7 @@ static void ParseCSS1_background( const CSS1Expression *pExpr, { // the percentage is converted to an enum - sal_uInt16 nPerc = static_cast<sal_uInt16>(pExpr->GetNumber()); + sal_uInt16 nPerc = o3tl::narrowing<sal_uInt16>(pExpr->GetNumber()); if( !bHori ) { ePos = nPerc < 25 ? GPOS_LT @@ -1594,7 +1594,7 @@ static void ParseCSS1_line_height( const CSS1Expression *pExpr, switch( pExpr->GetType() ) { case CSS1_LENGTH: - nHeight = static_cast<sal_uInt16>(pExpr->GetULength()); + nHeight = o3tl::narrowing<sal_uInt16>(pExpr->GetULength()); break; case CSS1_PIXLENGTH: { @@ -1604,18 +1604,18 @@ static void ParseCSS1_line_height( const CSS1Expression *pExpr, tools::Long nPHeight = static_cast<tools::Long>(fHeight); tools::Long nPWidth = 0; SvxCSS1Parser::PixelToTwip(nPWidth, nPHeight); - nHeight = static_cast<sal_uInt16>(nPHeight); + nHeight = o3tl::narrowing<sal_uInt16>(nPHeight); } } break; case CSS1_PERCENTAGE: { - nPropHeight = static_cast<sal_uInt16>(pExpr->GetNumber()); + nPropHeight = o3tl::narrowing<sal_uInt16>(pExpr->GetNumber()); } break; case CSS1_NUMBER: { - nPropHeight = static_cast<sal_uInt16>(pExpr->GetNumber() * 100); + nPropHeight = o3tl::narrowing<sal_uInt16>(pExpr->GetNumber() * 100); } break; default: @@ -1711,7 +1711,7 @@ static void ParseCSS1_font( const CSS1Expression *pExpr, } else { - eWeight = static_cast<sal_uInt16>(pExpr->GetNumber()) > 400 ? WEIGHT_BOLD + eWeight = o3tl::narrowing<sal_uInt16>(pExpr->GetNumber()) > 400 ? WEIGHT_BOLD : WEIGHT_NORMAL; } @@ -2045,13 +2045,13 @@ static void ParseCSS1_margin_left( const CSS1Expression *pExpr, &pItem ) ) { SvxLRSpaceItem aLRItem( *static_cast<const SvxLRSpaceItem*>(pItem) ); - aLRItem.SetTextLeft( static_cast<sal_uInt16>(nLeft) ); + aLRItem.SetTextLeft( o3tl::narrowing<sal_uInt16>(nLeft) ); rItemSet.Put( aLRItem ); } else { SvxLRSpaceItem aLRItem( aItemIds.nLRSpace ); - aLRItem.SetTextLeft( static_cast<sal_uInt16>(nLeft) ); + aLRItem.SetTextLeft( o3tl::narrowing<sal_uInt16>(nLeft) ); rItemSet.Put( aLRItem ); } rPropInfo.m_bLeftMargin = true; @@ -2104,13 +2104,13 @@ static void ParseCSS1_margin_right( const CSS1Expression *pExpr, &pItem ) ) { SvxLRSpaceItem aLRItem( *static_cast<const SvxLRSpaceItem*>(pItem) ); - aLRItem.SetRight( static_cast<sal_uInt16>(nRight) ); + aLRItem.SetRight( o3tl::narrowing<sal_uInt16>(nRight) ); rItemSet.Put( aLRItem ); } else { SvxLRSpaceItem aLRItem( aItemIds.nLRSpace ); - aLRItem.SetRight( static_cast<sal_uInt16>(nRight) ); + aLRItem.SetRight( o3tl::narrowing<sal_uInt16>(nRight) ); rItemSet.Put( aLRItem ); } rPropInfo.m_bRightMargin = true; @@ -2132,7 +2132,7 @@ static void ParseCSS1_margin_top( const CSS1Expression *pExpr, tools::Long nTmp = pExpr->GetSLength(); if( nTmp < 0 ) nTmp = 0; - nUpper = static_cast<sal_uInt16>(nTmp); + nUpper = o3tl::narrowing<sal_uInt16>(nTmp); bSet = true; } break; @@ -2146,7 +2146,7 @@ static void ParseCSS1_margin_top( const CSS1Expression *pExpr, if( nPHeight < 0 ) nPHeight = 0; SvxCSS1Parser::PixelToTwip( nPWidth, nPHeight ); - nUpper = static_cast<sal_uInt16>(nPHeight); + nUpper = o3tl::narrowing<sal_uInt16>(nPHeight); bSet = true; } } @@ -2194,7 +2194,7 @@ static void ParseCSS1_margin_bottom( const CSS1Expression *pExpr, tools::Long nTmp = pExpr->GetSLength(); if( nTmp < 0 ) nTmp = 0; - nLower = static_cast<sal_uInt16>(nTmp); + nLower = o3tl::narrowing<sal_uInt16>(nTmp); bSet = true; } break; @@ -2208,7 +2208,7 @@ static void ParseCSS1_margin_bottom( const CSS1Expression *pExpr, if( nPHeight < 0 ) nPHeight = 0; SvxCSS1Parser::PixelToTwip( nPWidth, nPHeight ); - nLower = static_cast<sal_uInt16>(nPHeight); + nLower = o3tl::narrowing<sal_uInt16>(nPHeight); bSet = true; } } @@ -2339,18 +2339,18 @@ static void ParseCSS1_margin( const CSS1Expression *pExpr, { SvxLRSpaceItem aLRItem( *static_cast<const SvxLRSpaceItem*>(pItem) ); if( bSetMargins[3] ) - aLRItem.SetLeft( static_cast<sal_uInt16>(nMargins[3]) ); + aLRItem.SetLeft( o3tl::narrowing<sal_uInt16>(nMargins[3]) ); if( bSetMargins[1] ) - aLRItem.SetRight( static_cast<sal_uInt16>(nMargins[1]) ); + aLRItem.SetRight( o3tl::narrowing<sal_uInt16>(nMargins[1]) ); rItemSet.Put( aLRItem ); } else { SvxLRSpaceItem aLRItem( aItemIds.nLRSpace ); if( bSetMargins[3] ) - aLRItem.SetLeft( static_cast<sal_uInt16>(nMargins[3]) ); + aLRItem.SetLeft( o3tl::narrowing<sal_uInt16>(nMargins[3]) ); if( bSetMargins[1] ) - aLRItem.SetRight( static_cast<sal_uInt16>(nMargins[1]) ); + aLRItem.SetRight( o3tl::narrowing<sal_uInt16>(nMargins[1]) ); rItemSet.Put( aLRItem ); } } @@ -2369,18 +2369,18 @@ static void ParseCSS1_margin( const CSS1Expression *pExpr, { SvxULSpaceItem aULItem( *static_cast<const SvxULSpaceItem*>(pItem) ); if( bSetMargins[0] ) - aULItem.SetUpper( static_cast<sal_uInt16>(nMargins[0]) ); + aULItem.SetUpper( o3tl::narrowing<sal_uInt16>(nMargins[0]) ); if( bSetMargins[2] ) - aULItem.SetLower( static_cast<sal_uInt16>(nMargins[2]) ); + aULItem.SetLower( o3tl::narrowing<sal_uInt16>(nMargins[2]) ); rItemSet.Put( aULItem ); } else { SvxULSpaceItem aULItem( aItemIds.nULSpace ); if( bSetMargins[0] ) - aULItem.SetUpper( static_cast<sal_uInt16>(nMargins[0]) ); + aULItem.SetUpper( o3tl::narrowing<sal_uInt16>(nMargins[0]) ); if( bSetMargins[2] ) - aULItem.SetLower( static_cast<sal_uInt16>(nMargins[2]) ); + aULItem.SetLower( o3tl::narrowing<sal_uInt16>(nMargins[2]) ); rItemSet.Put( aULItem ); } @@ -2406,7 +2406,7 @@ static bool ParseCSS1_padding_xxx( const CSS1Expression *pExpr, nTmp = 0; else if( nTmp > SvxCSS1PropertyInfo::UNSET_BORDER_DISTANCE-1 ) nTmp = SvxCSS1PropertyInfo::UNSET_BORDER_DISTANCE-1; - nDist = static_cast<sal_uInt16>(nTmp); + nDist = o3tl::narrowing<sal_uInt16>(nTmp); bSet = true; } break; @@ -2422,7 +2422,7 @@ static bool ParseCSS1_padding_xxx( const CSS1Expression *pExpr, SvxCSS1Parser::PixelToTwip( nPWidth, nPHeight ); if( nPWidth > SvxCSS1PropertyInfo::UNSET_BORDER_DISTANCE-1 ) nPWidth = SvxCSS1PropertyInfo::UNSET_BORDER_DISTANCE-1; - nDist = static_cast<sal_uInt16>(nPWidth); + nDist = o3tl::narrowing<sal_uInt16>(nPWidth); bSet = true; } } @@ -2549,7 +2549,7 @@ static void ParseCSS1_border_xxx( const CSS1Expression *pExpr, break; case CSS1_LENGTH: - nWidth = static_cast<sal_uInt16>(pExpr->GetULength()); + nWidth = o3tl::narrowing<sal_uInt16>(pExpr->GetULength()); break; case CSS1_PIXLENGTH: @@ -2564,7 +2564,7 @@ static void ParseCSS1_border_xxx( const CSS1Expression *pExpr, tools::Long nPWidth = bHori ? 0 : fWidth; tools::Long nPHeight = bHori ? fWidth : 0; SvxCSS1Parser::PixelToTwip( nPWidth, nPHeight ); - nWidth = static_cast<sal_uInt16>(bHori ? nPHeight : nPWidth); + nWidth = o3tl::narrowing<sal_uInt16>(bHori ? nPHeight : nPWidth); } else nWidth = 1; @@ -2625,7 +2625,7 @@ static void ParseCSS1_border_xxx_width( const CSS1Expression *pExpr, break; case CSS1_LENGTH: - nWidth = static_cast<sal_uInt16>(pExpr->GetULength()); + nWidth = o3tl::narrowing<sal_uInt16>(pExpr->GetULength()); break; case CSS1_PIXLENGTH: @@ -2641,7 +2641,7 @@ static void ParseCSS1_border_xxx_width( const CSS1Expression *pExpr, tools::Long nPWidth = bHori ? 0 : nWidthL; tools::Long nPHeight = bHori ? nWidthL : 0; SvxCSS1Parser::PixelToTwip( nPWidth, nPHeight ); - nWidth = static_cast<sal_uInt16>(bHori ? nPHeight : nPWidth); + nWidth = o3tl::narrowing<sal_uInt16>(bHori ? nPHeight : nPWidth); } } break; diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx index 078dae27f0ac..baa98996e308 100644 --- a/sw/source/filter/html/swhtml.cxx +++ b/sw/source/filter/html/swhtml.cxx @@ -3605,7 +3605,7 @@ void SwHTMLParser::NewBasefontAttr() switch( rOption.GetToken() ) { case HtmlOptionId::SIZE: - nSize = static_cast<sal_uInt16>(rOption.GetNumber()); + nSize = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); break; case HtmlOptionId::ID: aId = rOption.GetString(); @@ -3721,7 +3721,7 @@ void SwHTMLParser::NewFontAttr( HtmlTokenId nToken ) else if( nSSize > 7 ) nSSize = 7; - nSize = static_cast<sal_uInt16>(nSSize); + nSize = o3tl::narrowing<sal_uInt16>(nSSize); nFontHeight = m_aFontHeights[nSize-1]; } break; @@ -4974,12 +4974,12 @@ void SwHTMLParser::InsertSpacer() { SvxULSpaceItem aULSpace( static_cast<const SvxULSpaceItem&>(pTextNode ->SwContentNode::GetAttr( RES_UL_SPACE )) ); - aULSpace.SetLower( aULSpace.GetLower() + static_cast<sal_uInt16>(nSize) ); + aULSpace.SetLower( aULSpace.GetLower() + o3tl::narrowing<sal_uInt16>(nSize) ); pTextNode->SetAttr( aULSpace ); } else { - NewAttr(m_xAttrTab, &m_xAttrTab->pULSpace, SvxULSpaceItem(0, static_cast<sal_uInt16>(nSize), RES_UL_SPACE)); + NewAttr(m_xAttrTab, &m_xAttrTab->pULSpace, SvxULSpaceItem(0, o3tl::narrowing<sal_uInt16>(nSize), RES_UL_SPACE)); EndAttr( m_xAttrTab->pULSpace, false ); AppendTextNode(); // Don't change spacing! @@ -5031,7 +5031,7 @@ sal_uInt16 SwHTMLParser::ToTwips( sal_uInt16 nPixel ) { SwTwips nTwips = Application::GetDefaultDevice()->PixelToLogic( Size( nPixel, nPixel ), MapMode( MapUnit::MapTwip ) ).Width(); - return static_cast<sal_uInt16>(std::min(nTwips, SwTwips(SAL_MAX_UINT16))); + return o3tl::narrowing<sal_uInt16>(std::min(nTwips, SwTwips(SAL_MAX_UINT16))); } else return nPixel; @@ -5255,11 +5255,11 @@ void SwHTMLParser::InsertHorzRule() aId = rOption.GetString(); break; case HtmlOptionId::SIZE: - nSize = static_cast<sal_uInt16>(rOption.GetNumber()); + nSize = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); break; case HtmlOptionId::WIDTH: bPercentWidth = (rOption.GetString().indexOf('%') != -1); - nWidth = static_cast<sal_uInt16>(rOption.GetNumber()); + nWidth = o3tl::narrowing<sal_uInt16>(rOption.GetNumber()); if( bPercentWidth && nWidth>=100 ) { // the default case are 100% lines (no attributes necessary) @@ -5343,8 +5343,8 @@ void SwHTMLParser::InsertHorzRule() { // fake length and alignment of line above paragraph indents tools::Long nBrowseWidth = GetCurrentBrowseWidth(); - nWidth = bPercentWidth ? static_cast<sal_uInt16>((nWidth*nBrowseWidth) / 100) - : ToTwips( static_cast<sal_uInt16>(nBrowseWidth) ); + nWidth = bPercentWidth ? o3tl::narrowing<sal_uInt16>((nWidth*nBrowseWidth) / 100) + : ToTwips( o3tl::narrowing<sal_uInt16>(nBrowseWidth) ); if( nWidth < MINLAY ) nWidth = MINLAY; @@ -5357,16 +5357,16 @@ void SwHTMLParser::InsertHorzRule() switch( eAdjust ) { case SvxAdjust::Right: - aLRItem.SetTextLeft( static_cast<sal_uInt16>(nDist) ); + aLRItem.SetTextLeft( o3tl::narrowing<sal_uInt16>(nDist) ); break; case SvxAdjust::Left: - aLRItem.SetRight( static_cast<sal_uInt16>(nDist) ); + aLRItem.SetRight( o3tl::narrowing<sal_uInt16>(nDist) ); break; case SvxAdjust::Center: default: nDist /= 2; - aLRItem.SetTextLeft( static_cast<sal_uInt16>(nDist) ); - aLRItem.SetRight( static_cast<sal_uInt16>(nDist) ); + aLRItem.SetTextLeft( o3tl::narrowing<sal_uInt16>(nDist) ); + aLRItem.SetRight( o3tl::narrowing<sal_uInt16>(nDist) ); break; } diff --git a/sw/source/filter/html/wrthtml.cxx b/sw/source/filter/html/wrthtml.cxx index ca438b5894b1..c8b97d7850a0 100644 --- a/sw/source/filter/html/wrthtml.cxx +++ b/sw/source/filter/html/wrthtml.cxx @@ -684,7 +684,7 @@ static void lcl_html_OutSectionStartTag( SwHTMLWriter& rHTMLWrt, { if( nGutter && Application::GetDefaultDevice() ) { - nGutter = static_cast<sal_uInt16>(Application::GetDefaultDevice() + nGutter = o3tl::narrowing<sal_uInt16>(Application::GetDefaultDevice() ->LogicToPixel( Size(nGutter, 0), MapMode(MapUnit::MapTwip) ).Width()); } sOut.append(" " OOO_STRING_SVTOOLS_HTML_O_gutter "=\"" + OString::number(nGutter) + "\""); diff --git a/sw/source/filter/writer/wrtswtbl.cxx b/sw/source/filter/writer/wrtswtbl.cxx index 6c16d3c139ef..a504111c55f6 100644 --- a/sw/source/filter/writer/wrtswtbl.cxx +++ b/sw/source/filter/writer/wrtswtbl.cxx @@ -336,14 +336,14 @@ sal_uInt16 SwWriteTable::GetAbsWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) con nWidth -= GetLeftSpace( nCol ) + GetRightSpace( nCol, nColSpan ); OSL_ENSURE( nWidth > 0, "Column Width <= 0. OK?" ); - return nWidth > 0 ? static_cast<sal_uInt16>(nWidth) : 0; + return nWidth > 0 ? o3tl::narrowing<sal_uInt16>(nWidth) : 0; } sal_uInt16 SwWriteTable::GetRelWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const { tools::Long nWidth = GetRawWidth( nCol, nColSpan ); - return static_cast<sal_uInt16>(static_cast<tools::Long>(Fraction( nWidth*256 + GetBaseWidth()/2, + return o3tl::narrowing<sal_uInt16>(static_cast<tools::Long>(Fraction( nWidth*256 + GetBaseWidth()/2, GetBaseWidth() ))); } @@ -353,7 +353,7 @@ sal_uInt16 SwWriteTable::GetPercentWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) // Looks funny, but is nothing more than // [(100 * nWidth) + .5] without rounding errors - return static_cast<sal_uInt16>(static_cast<tools::Long>(Fraction( nWidth*100 + GetBaseWidth()/2, + return o3tl::narrowing<sal_uInt16>(static_cast<tools::Long>(Fraction( nWidth*100 + GetBaseWidth()/2, GetBaseWidth() ))); } @@ -659,7 +659,7 @@ void SwWriteTable::FillTableRowsCols( tools::Long nStartRPos, sal_uInt16 nStartR // The new table model may have true row span attributes const sal_Int32 nAttrRowSpan = pBox->getRowSpan(); if ( 1 < nAttrRowSpan ) - nRowSpan = static_cast<sal_uInt16>(nAttrRowSpan); + nRowSpan = o3tl::narrowing<sal_uInt16>(nAttrRowSpan); else if ( nAttrRowSpan < 1 ) nRowSpan = 0; diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 09772ab2ccb3..1690e567fd7e 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -9445,7 +9445,7 @@ void DocxAttributeOutput::FormatColumns_Impl( sal_uInt16 nCols, const SwFormatCo for ( sal_uInt16 n = 0; n < nCols; ++n ) { rtl::Reference<FastAttributeList> pColAttrList = FastSerializerHelper::createAttrList(); - sal_uInt16 nWidth = rCol.CalcPrtColWidth( n, static_cast<sal_uInt16>(nPageSize) ); + sal_uInt16 nWidth = rCol.CalcPrtColWidth( n, o3tl::narrowing<sal_uInt16>(nPageSize) ); pColAttrList->add( FSNS( XML_w, XML_w ), OString::number( nWidth ).getStr( ) ); diff --git a/sw/source/filter/ww8/writerhelper.cxx b/sw/source/filter/ww8/writerhelper.cxx index 7dc276264569..2a5182f63c26 100644 --- a/sw/source/filter/ww8/writerhelper.cxx +++ b/sw/source/filter/ww8/writerhelper.cxx @@ -628,7 +628,7 @@ namespace sw nPointCount = 0x0000ffff; } - tools::Polygon aRetval(static_cast<sal_uInt16>(nPointCount)); + tools::Polygon aRetval(o3tl::narrowing<sal_uInt16>(nPointCount)); sal_uInt32 nAppendIndex(0); for(a = 0; a < rPolyPoly.Count(); a++) @@ -637,7 +637,7 @@ namespace sw for(sal_uInt16 b(0); nAppendIndex <= nPointCount && b < rCandidate.GetSize(); b++) { - aRetval[static_cast<sal_uInt16>(nAppendIndex++)] = rCandidate[b]; + aRetval[o3tl::narrowing<sal_uInt16>(nAppendIndex++)] = rCandidate[b]; } } diff --git a/sw/source/filter/ww8/wrtw8num.cxx b/sw/source/filter/ww8/wrtw8num.cxx index c3f8eabe9fd9..85a4fa8cac23 100644 --- a/sw/source/filter/ww8/wrtw8num.cxx +++ b/sw/source/filter/ww8/wrtw8num.cxx @@ -140,7 +140,7 @@ sal_uInt16 MSWordExportBase::GetNumberingId( const SwNumRule& rNumRule ) } } SwNumRule* p = const_cast<SwNumRule*>(&rNumRule); - sal_uInt16 nRet = static_cast<sal_uInt16>(m_pUsedNumTable->GetPos(p)); + sal_uInt16 nRet = o3tl::narrowing<sal_uInt16>(m_pUsedNumTable->GetPos(p)); return nRet; } diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx index 08e54ab628cf..d6a09917715c 100644 --- a/sw/source/filter/ww8/wrtw8sty.cxx +++ b/sw/source/filter/ww8/wrtw8sty.cxx @@ -1379,7 +1379,7 @@ void WW8AttributeOutput::SectionLineNumbering( sal_uLong nRestartNo, const SwLin if ( nRestartNo ) { SwWW8Writer::InsUInt16( *m_rWW8Export.pO, NS_sprm::SLnnMin::val ); - SwWW8Writer::InsUInt16( *m_rWW8Export.pO, static_cast<sal_uInt16>(nRestartNo) - 1 ); + SwWW8Writer::InsUInt16( *m_rWW8Export.pO, o3tl::narrowing<sal_uInt16>(nRestartNo) - 1 ); } } diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx index d8e4241422c8..bd6a633bb670 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -462,7 +462,7 @@ static void WriteDop( WW8Export& rWrt ) // write default TabStop const SvxTabStopItem& rTabStop = DefaultItemGet<SvxTabStopItem>(rWrt.m_rDoc, RES_PARATR_TABSTOP); - rDop.dxaTab = static_cast<sal_uInt16>(rTabStop[0].GetTabPos()); + rDop.dxaTab = o3tl::narrowing<sal_uInt16>(rTabStop[0].GetTabPos()); // Zoom factor and type SwViewShell *pViewShell(rWrt.m_rDoc.getIDocumentLayoutAccess().GetCurrentViewShell()); @@ -1029,7 +1029,7 @@ void WW8_WrPlcPn::AppendFkpEntry(WW8_FC nEndFc,short nVarLen,const sal_uInt8* pS void WW8_WrPlcPn::WriteFkps() { - nFkpStartPage = static_cast<sal_uInt16>( SwWW8Writer::FillUntil( rWrt.Strm() ) >> 9 ); + nFkpStartPage = o3tl::narrowing<sal_uInt16>( SwWW8Writer::FillUntil( rWrt.Strm() ) >> 9 ); for(const std::unique_ptr<WW8_WrFkp> & rp : m_Fkps) { @@ -1116,10 +1116,10 @@ sal_uInt8 WW8_WrFkp::SearchSameSprm( sal_uInt16 nVarLen, const sal_uInt8* pSprms sal_uInt8 nStart = pOfs[i * nItemSize]; if( nStart ) { // has Sprms - const sal_uInt8* p = pFkp + ( static_cast<sal_uInt16>(nStart) << 1 ); + const sal_uInt8* p = pFkp + ( o3tl::narrowing<sal_uInt16>(nStart) << 1 ); if( ( CHP == ePlc ? (*p++ == nVarLen) - : ((static_cast<sal_uInt16>(*p++) << 1 ) == (( nVarLen+1) & 0xfffe)) ) + : ((o3tl::narrowing<sal_uInt16>(*p++) << 1 ) == (( nVarLen+1) & 0xfffe)) ) && !memcmp( p, pSprms, nVarLen ) ) return nStart; // found it } @@ -1139,7 +1139,7 @@ sal_uInt8 *WW8_WrFkp::CopyLastSprms(sal_uInt8 &rLen) sal_uInt8 nStart = *(pStart + (nIMax-1) * nItemSize); - const sal_uInt8* p = pFkp + ( static_cast<sal_uInt16>(nStart) << 1 ); + const sal_uInt8* p = pFkp + ( o3tl::narrowing<sal_uInt16>(nStart) << 1 ); if (!*p) p++; @@ -1273,7 +1273,7 @@ void WW8_WrFkp::MergeToNew( short& rVarLen, sal_uInt8 *& rpNewSprms ) return; // has Sprms - sal_uInt8* p = pFkp + ( static_cast<sal_uInt16>(nStart) << 1 ); + sal_uInt8* p = pFkp + ( o3tl::narrowing<sal_uInt16>(nStart) << 1 ); // old and new equal? Then copy only one into the new sprms if( nOldVarLen == rVarLen && !memcmp( p+1, rpNewSprms, nOldVarLen )) @@ -2193,7 +2193,7 @@ void WW8AttributeOutput::TableHeight( ww8::WW8TableNodeInfoInner::Pointer_t pTab if ( nHeight ) { m_rWW8Export.InsUInt16( NS_sprm::TDyaRowHeight::val ); - m_rWW8Export.InsUInt16( static_cast<sal_uInt16>(nHeight) ); + m_rWW8Export.InsUInt16( o3tl::narrowing<sal_uInt16>(nHeight) ); } } @@ -2379,7 +2379,7 @@ void WW8AttributeOutput::TableDefinition( ww8::WW8TableNodeInfoInner::Pointer_t ww8::GridColsPtr pGridCols = GetGridCols( pTableTextNodeInfoInner ); for ( const auto nCol : *pGridCols ) { - m_rWW8Export.InsUInt16( static_cast<sal_uInt16>(nCol) + nTableOffset ); + m_rWW8Export.InsUInt16( o3tl::narrowing<sal_uInt16>(nCol) + nTableOffset ); } /* TCs */ @@ -2420,7 +2420,7 @@ void WW8AttributeOutput::TableDefinition( ww8::WW8TableNodeInfoInner::Pointer_t { m_rWW8Export.InsUInt16( NS_sprm::TTableWidth::val ); m_rWW8Export.pO->push_back( sal_uInt8/*ftsPercent*/ (2) ); - m_rWW8Export.InsUInt16( static_cast<sal_uInt16>(nWidthPercent) * 50 ); + m_rWW8Export.InsUInt16( o3tl::narrowing<sal_uInt16>(nWidthPercent) * 50 ); } } diff --git a/sw/source/filter/ww8/wrtww8gr.cxx b/sw/source/filter/ww8/wrtww8gr.cxx index b79641c5372a..2b72b52edfab 100644 --- a/sw/source/filter/ww8/wrtww8gr.cxx +++ b/sw/source/filter/ww8/wrtww8gr.cxx @@ -589,7 +589,7 @@ void SwWW8WrGrf::WritePICFHeader(SvStream& rStrm, const ww8::Frame &rFly, if ( !bIsSubstitutedSize ) { const double fVal = nWidth * 1000.0 / (aGrTwipSz.Width() + nXSizeAdd ); - Set_UInt16( pArr, static_cast<sal_uInt16>(::rtl::math::round(fVal)) ); + Set_UInt16( pArr, o3tl::narrowing<sal_uInt16>(::rtl::math::round(fVal)) ); } else { @@ -606,7 +606,7 @@ void SwWW8WrGrf::WritePICFHeader(SvStream& rStrm, const ww8::Frame &rFly, if ( !bIsSubstitutedSize ) { const double fVal = nHeight * 1000.0 / (aGrTwipSz.Height() + nYSizeAdd); - Set_UInt16( pArr, static_cast<sal_uInt16>(::rtl::math::round(fVal)) ); + Set_UInt16( pArr, o3tl::narrowing<sal_uInt16>(::rtl::math::round(fVal)) ); } else { @@ -720,7 +720,7 @@ void SwWW8WrGrf::WritePICBulletFHeader(SvStream& rStrm, const Graphic &rGrf, if( aGrTwipSz.Width() + nXSizeAdd ) // set mx { double fVal = nWidth * 1000.0 / (aGrTwipSz.Width() + nXSizeAdd); - Set_UInt16( pArr, static_cast<sal_uInt16>(::rtl::math::round(fVal)) ); + Set_UInt16( pArr, o3tl::narrowing<sal_uInt16>(::rtl::math::round(fVal)) ); } else pArr += 2; @@ -728,7 +728,7 @@ void SwWW8WrGrf::WritePICBulletFHeader(SvStream& rStrm, const Graphic &rGrf, if( aGrTwipSz.Height() + nYSizeAdd ) // set my { double fVal = nHeight * 1000.0 / (aGrTwipSz.Height() + nYSizeAdd); - Set_UInt16( pArr, static_cast<sal_uInt16>(::rtl::math::round(fVal)) ); + Set_UInt16( pArr, o3tl::narrowing<sal_uInt16>(::rtl::math::round(fVal)) ); } else pArr += 2; diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx index 5d120613e4d5..90696900a8d3 100644 --- a/sw/source/filter/ww8/ww8atr.cxx +++ b/sw/source/filter/ww8/ww8atr.cxx @@ -816,7 +816,7 @@ void MSWordExportBase::OutputFormat( const SwFormat& rFormat, bool bPapFormat, b { //if outline numbered // if Write StyleDefinition then write the OutlineRule - const SwNumFormat& rNFormat = m_rDoc.GetOutlineNumRule()->Get( static_cast<sal_uInt16>( nLvl ) ); + const SwNumFormat& rNFormat = m_rDoc.GetOutlineNumRule()->Get( o3tl::narrowing<sal_uInt16>( nLvl ) ); if ( m_bStyDef ) AttrOutput().OutlineNumbering(static_cast<sal_uInt8>(nLvl)); @@ -1479,7 +1479,7 @@ void WW8AttributeOutput::CharFontSize( const SvxFontHeightItem& rHeight ) { m_rWW8Export.InsUInt16( nId ); - m_rWW8Export.InsUInt16( static_cast<sal_uInt16>(( rHeight.GetHeight() + 5 ) / 10 ) ); + m_rWW8Export.InsUInt16( o3tl::narrowing<sal_uInt16>(( rHeight.GetHeight() + 5 ) / 10 ) ); } } @@ -3741,7 +3741,7 @@ void WW8AttributeOutput::FormatFrameSize( const SwFormatFrameSize& rSize ) { //"sprmPDxaWidth" m_rWW8Export.InsUInt16( NS_sprm::PDxaWidth::val ); - m_rWW8Export.InsUInt16( static_cast<sal_uInt16>(rSize.GetWidth()) ); + m_rWW8Export.InsUInt16( o3tl::narrowing<sal_uInt16>(rSize.GetWidth()) ); } if ( rSize.GetHeight() ) @@ -3753,8 +3753,8 @@ void WW8AttributeOutput::FormatFrameSize( const SwFormatFrameSize& rSize ) switch ( rSize.GetHeightSizeType() ) { case SwFrameSize::Variable: break; - case SwFrameSize::Fixed: nH = static_cast<sal_uInt16>(rSize.GetHeight()) & 0x7fff; break; - default: nH = static_cast<sal_uInt16>(rSize.GetHeight()) | 0x8000; break; + case SwFrameSize::Fixed: nH = o3tl::narrowing<sal_uInt16>(rSize.GetHeight()) & 0x7fff; break; + default: nH = o3tl::narrowing<sal_uInt16>(rSize.GetHeight()) | 0x8000; break; } m_rWW8Export.InsUInt16( nH ); } @@ -4080,7 +4080,7 @@ void WW8AttributeOutput::FormatLRSpace( const SvxLRSpaceItem& rLR ) // sprmPDxaFromText10 m_rWW8Export.InsUInt16( NS_sprm::LN_PDxaFromText10 ); // use average, since WW only knows one value - m_rWW8Export.InsUInt16( static_cast<sal_uInt16>( ( rLR.GetLeft() + rLR.GetRight() ) / 2 ) ); + m_rWW8Export.InsUInt16( o3tl::narrowing<sal_uInt16>( ( rLR.GetLeft() + rLR.GetRight() ) / 2 ) ); } else if ( m_rWW8Export.m_bOutPageDescs ) // PageDescs { @@ -4116,11 +4116,11 @@ void WW8AttributeOutput::FormatLRSpace( const SvxLRSpaceItem& rLR ) { // normal paragraphs // sprmPDxaLeft m_rWW8Export.InsUInt16( 0x845E ); //asian version ? - m_rWW8Export.InsUInt16( static_cast<sal_uInt16>(rLR.GetTextLeft()) ); + m_rWW8Export.InsUInt16( o3tl::narrowing<sal_uInt16>(rLR.GetTextLeft()) ); // sprmPDxaRight m_rWW8Export.InsUInt16( 0x845D ); //asian version ? - m_rWW8Export.InsUInt16( static_cast<sal_uInt16>(rLR.GetRight()) ); + m_rWW8Export.InsUInt16( o3tl::narrowing<sal_uInt16>(rLR.GetRight()) ); // sprmPDxaLeft1 m_rWW8Export.InsUInt16( 0x8460 ); //asian version ? @@ -4149,7 +4149,7 @@ void WW8AttributeOutput::FormatULSpace( const SvxULSpaceItem& rUL ) // sprmPDyaFromText m_rWW8Export.InsUInt16( NS_sprm::PDyaFromText::val ); // use average, since WW only knows one value - m_rWW8Export.InsUInt16( static_cast<sal_uInt16>( ( rUL.GetUpper() + rUL.GetLower() ) / 2 ) ); + m_rWW8Export.InsUInt16( o3tl::narrowing<sal_uInt16>( ( rUL.GetUpper() + rUL.GetLower() ) / 2 ) ); } else if ( m_rWW8Export.m_bOutPageDescs ) // Page-UL { @@ -4694,7 +4694,7 @@ void WW8AttributeOutput::FormatColumns_Impl( sal_uInt16 nCols, const SwFormatCol m_rWW8Export.pO->push_back( static_cast<sal_uInt8>(n) ); m_rWW8Export.InsUInt16( rCol. CalcPrtColWidth( n, - static_cast<sal_uInt16>(nPageSize) ) ); + o3tl::narrowing<sal_uInt16>(nPageSize) ) ); if ( n + 1 != nCols ) { @@ -4761,11 +4761,11 @@ void AttributeOutputBase::FormatColumns( const SwFormatCol& rCol ) { bEven = true; sal_uInt16 n; - sal_uInt16 nColWidth = rCol.CalcPrtColWidth( 0, static_cast<sal_uInt16>(nPageSize) ); + sal_uInt16 nColWidth = rCol.CalcPrtColWidth( 0, o3tl::narrowing<sal_uInt16>(nPageSize) ); for ( n = 1; n < nCols; n++ ) { short nDiff = nColWidth - - rCol.CalcPrtColWidth( n, static_cast<sal_uInt16>(nPageSize) ); + rCol.CalcPrtColWidth( n, o3tl::narrowing<sal_uInt16>(nPageSize) ); if ( nDiff > 10 || nDiff < -10 ) // Tolerance: 10 tw { diff --git a/sw/source/filter/ww8/ww8graf.cxx b/sw/source/filter/ww8/ww8graf.cxx index 912293c668cb..a97b985b058f 100644 --- a/sw/source/filter/ww8/ww8graf.cxx +++ b/sw/source/filter/ww8/ww8graf.cxx @@ -1744,13 +1744,13 @@ void SwWW8ImplReader::MatchSdrItemsIntoFlySet( SdrObject const * pSdrObj, // set distances from box's border to text contained within the box if( 0 < rInnerDist.Left() ) - aBox.SetDistance( static_cast<sal_uInt16>(rInnerDist.Left()), SvxBoxItemLine::LEFT ); + aBox.SetDistance( o3tl::narrowing<sal_uInt16>(rInnerDist.Left()), SvxBoxItemLine::LEFT ); if( 0 < rInnerDist.Top() ) - aBox.SetDistance( static_cast<sal_uInt16>(rInnerDist.Top()), SvxBoxItemLine::TOP ); + aBox.SetDistance( o3tl::narrowing<sal_uInt16>(rInnerDist.Top()), SvxBoxItemLine::TOP ); if( 0 < rInnerDist.Right() ) - aBox.SetDistance( static_cast<sal_uInt16>(rInnerDist.Right()), SvxBoxItemLine::RIGHT ); + aBox.SetDistance( o3tl::narrowing<sal_uInt16>(rInnerDist.Right()), SvxBoxItemLine::RIGHT ); if( 0 < rInnerDist.Bottom() ) - aBox.SetDistance( static_cast<sal_uInt16>(rInnerDist.Bottom()), SvxBoxItemLine::BOTTOM ); + aBox.SetDistance( o3tl::narrowing<sal_uInt16>(rInnerDist.Bottom()), SvxBoxItemLine::BOTTOM ); bool bFixSize = !(WW8ITEMVALUE(rOldSet, SDRATTR_TEXT_AUTOGROWHEIGHT, SdrOnOffItem)); diff --git a/sw/source/filter/ww8/ww8graf2.cxx b/sw/source/filter/ww8/ww8graf2.cxx index cf1572f35ede..e5289fa8d4dc 100644 --- a/sw/source/filter/ww8/ww8graf2.cxx +++ b/sw/source/filter/ww8/ww8graf2.cxx @@ -356,7 +356,7 @@ SwFlyFrameFormat* SwWW8ImplReader::MakeGrafNotInContent(const WW8PicDesc& rPD, sal_Int32 nNetHeight = nHeight + rPD.nCT + rPD.nCB; if (m_xSFlyPara->nLineSpace && m_xSFlyPara->nLineSpace > nNetHeight) m_xSFlyPara->nYPos = - static_cast<sal_uInt16>( m_xSFlyPara->nYPos + m_xSFlyPara->nLineSpace - nNetHeight ); + o3tl::narrowing<sal_uInt16>( m_xSFlyPara->nYPos + m_xSFlyPara->nLineSpace - nNetHeight ); WW8FlySet aFlySet(*this, m_xWFlyPara.get(), m_xSFlyPara.get(), true); diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index 83995b2d5ffc..574d7dd5356d 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -1000,8 +1000,8 @@ SdrObject* SwMSDffManager::ProcessObj(SvStream& rSt, if ( nTextId ) { - pImpRec->aTextId.nTxBxS = static_cast<sal_uInt16>( nTextId >> 16 ); - pImpRec->aTextId.nSequence = static_cast<sal_uInt16>(nTextId); + pImpRec->aTextId.nTxBxS = o3tl::narrowing<sal_uInt16>( nTextId >> 16 ); + pImpRec->aTextId.nSequence = o3tl::narrowing<sal_uInt16>(nTextId); } pImpRec->nDxWrapDistLeft = o3tl::convert(GetPropertyValue(DFF_Prop_dxWrapDistLeft, 114935), @@ -4207,9 +4207,9 @@ bool SwWW8ImplReader::ReadText(WW8_CP nStartCp, WW8_CP nTextLen, ManTypes nType) if ((nCrCount++ & 0x40) == 0 && nType == MAN_MAINTEXT && l <= nTextLen) { if (nTextLen < WW8_CP_MAX/100) - m_nProgress = static_cast<sal_uInt16>(l * 100 / nTextLen); + m_nProgress = o3tl::narrowing<sal_uInt16>(l * 100 / nTextLen); else - m_nProgress = static_cast<sal_uInt16>(l / nTextLen * 100); + m_nProgress = o3tl::narrowing<sal_uInt16>(l / nTextLen * 100); m_xProgress->Update(m_nProgress); // Update } } @@ -6558,8 +6558,8 @@ bool SwMSDffManager::GetOLEStorageName(sal_uInt32 nOLEId, OUString& rStorageName // Note: Ask MM about assertions in method <rReader.GetTxbxTextSttEndCp(..)>. WW8_CP nStartCp, nEndCp; if ( rReader.m_bDrawCpOValid && rReader.GetTxbxTextSttEndCp(nStartCp, nEndCp, - static_cast<sal_uInt16>((nOLEId >> 16) & 0xFFFF), - static_cast<sal_uInt16>(nOLEId & 0xFFFF)) ) + o3tl::narrowing<sal_uInt16>((nOLEId >> 16) & 0xFFFF), + o3tl::narrowing<sal_uInt16>(nOLEId & 0xFFFF)) ) { WW8PLCFxSaveAll aSave; rReader.m_xPlcxMan->SaveAllPLCFx( aSave ); diff --git a/sw/source/filter/ww8/ww8par2.cxx b/sw/source/filter/ww8/ww8par2.cxx index facee87ec980..5d96a44e9196 100644 --- a/sw/source/filter/ww8/ww8par2.cxx +++ b/sw/source/filter/ww8/ww8par2.cxx @@ -2553,7 +2553,7 @@ void WW8TabDesc::UseSwTable() OSL_ENSURE( m_pTableNd, "Where is my table node" ); // #i69519# - Restrict rows to repeat to a decent value - if ( m_nRowsToRepeat == static_cast<sal_uInt16>(m_nRows) ) + if ( m_nRowsToRepeat == o3tl::narrowing<sal_uInt16>(m_nRows) ) m_nRowsToRepeat = 1; m_pTableNd->GetTable().SetRowsToRepeat( m_nRowsToRepeat ); @@ -2588,9 +2588,9 @@ void WW8TabDesc::MergeCells() // start a new merge group if appropriate - OSL_ENSURE(nRow < static_cast<sal_uInt16>(m_pTabLines->size()), + OSL_ENSURE(nRow < o3tl::narrowing<sal_uInt16>(m_pTabLines->size()), "Too few lines, table ended early"); - if (nRow >= static_cast<sal_uInt16>(m_pTabLines->size())) + if (nRow >= o3tl::narrowing<sal_uInt16>(m_pTabLines->size())) return; m_pTabLine = (*m_pTabLines)[ nRow ]; m_pTabBoxes = &m_pTabLine->GetTabBoxes(); @@ -2711,7 +2711,7 @@ void WW8TabDesc::ParkPaM() { SwTableBox *pTabBox2 = nullptr; short nRow = m_nCurrentRow + 1; - if (nRow < static_cast<sal_uInt16>(m_pTabLines->size())) + if (nRow < o3tl::narrowing<sal_uInt16>(m_pTabLines->size())) { if (SwTableLine *pLine = (*m_pTabLines)[nRow]) { @@ -3159,7 +3159,7 @@ void WW8TabDesc::AdjustNewBand() InsertCells( m_pActBand->nSwCols - m_nDefaultSwCols ); SetPamInCell( 0, false); - OSL_ENSURE( m_pTabBoxes && m_pTabBoxes->size() == static_cast<sal_uInt16>(m_pActBand->nSwCols), + OSL_ENSURE( m_pTabBoxes && m_pTabBoxes->size() == o3tl::narrowing<sal_uInt16>(m_pActBand->nSwCols), "Wrong column count in table" ); if( m_bClaimLineFormat ) diff --git a/sw/source/filter/ww8/ww8par3.cxx b/sw/source/filter/ww8/ww8par3.cxx index 678b9bb40183..02dd2f139d0b 100644 --- a/sw/source/filter/ww8/ww8par3.cxx +++ b/sw/source/filter/ww8/ww8par3.cxx @@ -678,8 +678,8 @@ bool WW8ListManager::ReadLVL(SwNumFormat& rNumFormat, std::unique_ptr<SfxItemSet for(int i=0;i<4;++i) rParaSprms.push_back(*pBegin++); short nDxaLeft = SVBT16ToUInt16(aSprm.pSprm); - aLVL.nDxaLeft = (0 < nDxaLeft) ? static_cast<sal_uInt16>(nDxaLeft) - : static_cast<sal_uInt16>(-nDxaLeft); + aLVL.nDxaLeft = (0 < nDxaLeft) ? o3tl::narrowing<sal_uInt16>(nDxaLeft) + : o3tl::narrowing<sal_uInt16>(-nDxaLeft); } // "sprmPDxaLeft1" pap.dxaLeft1;dxa;word; @@ -749,8 +749,8 @@ bool WW8ListManager::ReadLVL(SwNumFormat& rNumFormat, std::unique_ptr<SfxItemSet if (bDoAdjust) { aLVL.nDxaLeft = (0 < nTabPos) - ? static_cast<sal_uInt16>(nTabPos) - : static_cast<sal_uInt16>(-nTabPos); + ? o3tl::narrowing<sal_uInt16>(nTabPos) + : o3tl::narrowing<sal_uInt16>(-nTabPos); aLVL.nDxaLeft1 = nDesired - aLVL.nDxaLeft; } @@ -866,7 +866,7 @@ bool WW8ListManager::ReadLVL(SwNumFormat& rNumFormat, std::unique_ptr<SfxItemSet // 6. Configure NumFormat if( bSetStartNo && 0 <= aLVL.nStartAt) - rNumFormat.SetStart(static_cast<sal_uInt16>(aLVL.nStartAt)); + rNumFormat.SetStart(o3tl::narrowing<sal_uInt16>(aLVL.nStartAt)); rNumFormat.SetNumberingType( nType ); rNumFormat.SetNumAdjust( eAdj ); @@ -1978,7 +1978,7 @@ void SwWW8ImplReader::Read_LFOPosition(sal_uInt16, const sal_uInt8* pData, } else // nData in (0..0x7FFF] { - m_nLFOPosition = static_cast<sal_uInt16>(nData)-1; // m_nLFOPosition in [0..0x7FFF) + m_nLFOPosition = o3tl::narrowing<sal_uInt16>(nData)-1; // m_nLFOPosition in [0..0x7FFF) /* If we are a ww8+ style with ww7- style lists then there is a bizarre broken word bug where when the list is removed from a para diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx index 3aa79d63e707..cb9a66db152b 100644 --- a/sw/source/filter/ww8/ww8par5.cxx +++ b/sw/source/filter/ww8/ww8par5.cxx @@ -889,7 +889,7 @@ tools::Long SwWW8ImplReader::Read_Field(WW8PLCFManResult* pRes) if (bNested) return 0; - sal_uInt16 n = (aF.nId <= eMax) ? aF.nId : static_cast<sal_uInt16>(eMax); + sal_uInt16 n = (aF.nId <= eMax) ? aF.nId : o3tl::narrowing<sal_uInt16>(eMax); sal_uInt16 nI = n / 32; // # of sal_uInt32 sal_uInt32 nMask = 1 << ( n % 32 ); // Mask for bits @@ -2675,7 +2675,7 @@ void SwWW8ImplReader::Read_SubF_Ruby( WW8ReadFieldParams& rReadParam) if( sTemp.startsWithIgnoreAsciiCase( "jc" ) ) { sTemp = sTemp.copy(2); - nJustificationCode = static_cast<sal_uInt16>(sTemp.toInt32()); + nJustificationCode = o3tl::narrowing<sal_uInt16>(sTemp.toInt32()); } else if( sTemp.startsWithIgnoreAsciiCase( "hps" ) ) { @@ -2887,12 +2887,12 @@ static void lcl_toxMatchTSwitch(SwWW8ImplReader const & rReader, SwTOXBase& rBas else while( -1 != nIndex ) { sal_Int32 nOldIndex=nIndex; - sal_uInt16 nLevel = static_cast<sal_uInt16>( + sal_uInt16 nLevel = o3tl::narrowing<sal_uInt16>( sParams.getToken(0, ';', nIndex).toInt32()); if( -1 == nIndex ) { nIndex = nOldIndex; - nLevel = static_cast<sal_uInt16>( + nLevel = o3tl::narrowing<sal_uInt16>( sParams.getToken(0, ',', nIndex).toInt32()); } @@ -3023,7 +3023,7 @@ eF_ResT SwWW8ImplReader::Read_F_Tox( WW8FieldDesc* pF, OUString& rStr ) // if NO OUString just ignore the \c if( !sParams.isEmpty() ) { - nIndexCols = static_cast<sal_uInt16>(sParams.toInt32()); + nIndexCols = o3tl::narrowing<sal_uInt16>(sParams.toInt32()); } } break; @@ -3616,7 +3616,7 @@ static void lcl_ImportTox(SwDoc &rDoc, SwPaM const &rPaM, const OUString &rStr, // if NO String just ignore the \l if( !sParams.isEmpty() && sParams[0]>'0' && sParams[0]<='9' ) { - nLevel = static_cast<sal_uInt16>(sParams.toInt32()); + nLevel = o3tl::narrowing<sal_uInt16>(sParams.toInt32()); } } break; diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx index 16572f2905cb..96b1203f46e8 100644 --- a/sw/source/filter/ww8/ww8par6.cxx +++ b/sw/source/filter/ww8/ww8par6.cxx @@ -4373,15 +4373,15 @@ void SwWW8ImplReader::Read_LineSpace( sal_uInt16, const sal_uInt8* pData, short tools::Long n = nSpace * 10 / 24; // WW: 240 = 100%, SW: 100 = 100% // here n is in [0..13653] - aLSpc.SetPropLineSpace( static_cast<sal_uInt16>(n) ); + aLSpc.SetPropLineSpace( o3tl::narrowing<sal_uInt16>(n) ); const SvxFontHeightItem* pH = static_cast<const SvxFontHeightItem*>( GetFormatAttr( RES_CHRATR_FONTSIZE )); - nSpaceTw = static_cast<sal_uInt16>( n * pH->GetHeight() / 100 ); + nSpaceTw = o3tl::narrowing<sal_uInt16>( n * pH->GetHeight() / 100 ); } else // Fixed / Minimum { // for negative space, the distance is "exact", otherwise "at least" - nSpaceTw = static_cast<sal_uInt16>(nSpace); + nSpaceTw = o3tl::narrowing<sal_uInt16>(nSpace); aLSpc.SetLineHeight( nSpaceTw ); aLSpc.SetLineSpaceRule( eLnSpc); } @@ -5047,16 +5047,16 @@ void SwWW8ImplReader::Read_Border(sal_uInt16 , const sal_uInt8*, short nLen) GetBorderDistance( aBrcs, aInnerDist ); if (nBorder & (1 << WW8_LEFT)) - aBox->SetDistance( static_cast<sal_uInt16>(aInnerDist.Left()), SvxBoxItemLine::LEFT ); + aBox->SetDistance( o3tl::narrowing<sal_uInt16>(aInnerDist.Left()), SvxBoxItemLine::LEFT ); if (nBorder & (1 << WW8_TOP)) - aBox->SetDistance( static_cast<sal_uInt16>(aInnerDist.Top()), SvxBoxItemLine::TOP ); + aBox->SetDistance( o3tl::narrowing<sal_uInt16>(aInnerDist.Top()), SvxBoxItemLine::TOP ); if (nBorder & (1 << WW8_RIGHT)) - aBox->SetDistance( static_cast<sal_uInt16>(aInnerDist.Right()), SvxBoxItemLine::RIGHT ); + aBox->SetDistance( o3tl::narrowing<sal_uInt16>(aInnerDist.Right()), SvxBoxItemLine::RIGHT ); if (nBorder & (1 << WW8_BOT)) - aBox->SetDistance( static_cast<sal_uInt16>(aInnerDist.Bottom()), SvxBoxItemLine::BOTTOM ); + aBox->SetDistance( o3tl::narrowing<sal_uInt16>(aInnerDist.Bottom()), SvxBoxItemLine::BOTTOM ); NewAttr( *aBox ); diff --git a/sw/source/filter/ww8/ww8scan.cxx b/sw/source/filter/ww8/ww8scan.cxx index c37ccf2d1470..8f24ccac97c8 100644 --- a/sw/source/filter/ww8/ww8scan.cxx +++ b/sw/source/filter/ww8/ww8scan.cxx @@ -2448,7 +2448,7 @@ void WW8PLCF::GeneratePLCF(SvStream& rSt, sal_Int32 nPN, sal_Int32 ncpN) for (sal_Int32 i = 0; i < ncpN; ++i) // construct PNs { - ShortToSVBT16(static_cast<sal_uInt16>(nPN + i), p); + ShortToSVBT16(o3tl::narrowing<sal_uInt16>(nPN + i), p); p += nStru; } } @@ -4236,7 +4236,7 @@ void WW8ReadSTTBF(bool bVer8, SvStream& rStrm, sal_uInt32 nStart, sal_Int32 nLen nLen = SAL_MAX_UINT16; else if (nLen < 2 ) nLen = 2; - nLen2 = static_cast<sal_uInt16>(nLen); + nLen2 = o3tl::narrowing<sal_uInt16>(nLen); } sal_uLong nRead = 0; for( nLen2 -= 2; nRead < nLen2; ) @@ -4327,7 +4327,7 @@ void WW8PLCFx_Book::SetIdx2(sal_uInt32 nI) if( nIMax ) { pBook[1]->SetIdx( nI & 0x7fffffff ); - nIsEnd = static_cast<sal_uInt16>( ( nI >> 31 ) & 1 ); // 0 or 1 + nIsEnd = o3tl::narrowing<sal_uInt16>( ( nI >> 31 ) & 1 ); // 0 or 1 } } @@ -6554,10 +6554,10 @@ void WW8Fib::Write(SvStream& rStrm) if( !bVer8 ) { pData += 1*sizeof( sal_Int16); - Set_UInt16( pData, static_cast<sal_uInt16>(m_pnChpFirst) ); - Set_UInt16( pData, static_cast<sal_uInt16>(m_pnPapFirst) ); - Set_UInt16( pData, static_cast<sal_uInt16>(m_cpnBteChp) ); - Set_UInt16( pData, static_cast<sal_uInt16>(m_cpnBtePap) ); + Set_UInt16( pData, o3tl::narrowing<sal_uInt16>(m_pnChpFirst) ); + Set_UInt16( pData, o3tl::narrowing<sal_uInt16>(m_pnPapFirst) ); + Set_UInt16( pData, o3tl::narrowing<sal_uInt16>(m_cpnBteChp) ); + Set_UInt16( pData, o3tl::narrowing<sal_uInt16>(m_cpnBtePap) ); } Set_UInt32( pData, m_fcPlcfdoaMom ); // only at Ver67, in Ver8 unused diff --git a/sw/source/filter/xml/xmlimpit.cxx b/sw/source/filter/xml/xmlimpit.cxx index bfb29a7af264..4d849810afb1 100644 --- a/sw/source/filter/xml/xmlimpit.cxx +++ b/sw/source/filter/xml/xmlimpit.cxx @@ -123,7 +123,7 @@ void SvXMLImportItemMapper::importXML( SfxItemSet& rSet, if( 0 == (pEntry->nMemberId&MID_SW_FLAG_SPECIAL_ITEM_IMPORT) ) { bPut = PutXMLValue( *pNewItem, sValue, - static_cast<sal_uInt16>( pEntry->nMemberId & MID_SW_FLAG_MASK ), + o3tl::narrowing<sal_uInt16>( pEntry->nMemberId & MID_SW_FLAG_MASK ), rUnitConverter ); } @@ -339,10 +339,10 @@ bool SvXMLImportItemMapper::PutXMLValue( switch( nMemberId ) { case MID_L_MARGIN: - rLRSpace.SetTextLeft( nAbs, static_cast<sal_uInt16>(nProp) ); + rLRSpace.SetTextLeft( nAbs, o3tl::narrowing<sal_uInt16>(nProp) ); break; case MID_R_MARGIN: - rLRSpace.SetRight( nAbs, static_cast<sal_uInt16>(nProp) ); + rLRSpace.SetRight( nAbs, o3tl::narrowing<sal_uInt16>(nProp) ); break; } } @@ -360,7 +360,7 @@ bool SvXMLImportItemMapper::PutXMLValue( bOk = rUnitConverter.convertMeasureToCore(nAbs, rValue, -0x7fff, 0x7fff ); - rLRSpace.SetTextFirstLineOffset( static_cast<short>(nAbs), static_cast<sal_uInt16>(nProp) ); + rLRSpace.SetTextFirstLineOffset( static_cast<short>(nAbs), o3tl::narrowing<sal_uInt16>(nProp) ); } break; @@ -394,10 +394,10 @@ bool SvXMLImportItemMapper::PutXMLValue( switch( nMemberId ) { case MID_UP_MARGIN: - rULSpace.SetUpper( static_cast<sal_uInt16>(nAbs), static_cast<sal_uInt16>(nProp) ); + rULSpace.SetUpper( o3tl::narrowing<sal_uInt16>(nAbs), o3tl::narrowing<sal_uInt16>(nProp) ); break; case MID_LO_MARGIN: - rULSpace.SetLower( static_cast<sal_uInt16>(nAbs), static_cast<sal_uInt16>(nProp) ); + rULSpace.SetLower( o3tl::narrowing<sal_uInt16>(nAbs), o3tl::narrowing<sal_uInt16>(nProp) ); break; default: OSL_FAIL("unknown MemberId"); @@ -507,16 +507,16 @@ bool SvXMLImportItemMapper::PutXMLValue( if( nMemberId == LEFT_BORDER_PADDING || nMemberId == ALL_BORDER_PADDING ) - rBox.SetDistance( static_cast<sal_uInt16>(nTemp), SvxBoxItemLine::LEFT ); + rBox.SetDistance( o3tl::narrowing<sal_uInt16>(nTemp), SvxBoxItemLine::LEFT ); if( nMemberId == RIGHT_BORDER_PADDING || nMemberId == ALL_BORDER_PADDING ) - rBox.SetDistance( static_cast<sal_uInt16>(nTemp), SvxBoxItemLine::RIGHT ); + rBox.SetDistance( o3tl::narrowing<sal_uInt16>(nTemp), SvxBoxItemLine::RIGHT ); if( nMemberId == TOP_BORDER_PADDING || nMemberId == ALL_BORDER_PADDING ) - rBox.SetDistance( static_cast<sal_uInt16>(nTemp), SvxBoxItemLine::TOP ); + rBox.SetDistance( o3tl::narrowing<sal_uInt16>(nTemp), SvxBoxItemLine::TOP ); if( nMemberId == BOTTOM_BORDER_PADDING || nMemberId == ALL_BORDER_PADDING ) - rBox.SetDistance( static_cast<sal_uInt16>(nTemp), SvxBoxItemLine::BOTTOM); + rBox.SetDistance( o3tl::narrowing<sal_uInt16>(nTemp), SvxBoxItemLine::BOTTOM); break; case ALL_BORDER: @@ -831,7 +831,7 @@ bool SvXMLImportItemMapper::PutXMLValue( // "auto" as "0" for tables - now that we support a real offset // 0, this fake "0" MUST NOT be imported as offset 0! if( bOk && nVal > 0 ) - rPageDesc.SetNumOffset( static_cast<sal_uInt16>(nVal) ); + rPageDesc.SetNumOffset( o3tl::narrowing<sal_uInt16>(nVal) ); } } break; @@ -944,7 +944,7 @@ bool SvXMLImportItemMapper::PutXMLValue( else if( nValue > SAL_MAX_UINT16 ) nValue = SAL_MAX_UINT16; - rFrameSize.SetWidth( static_cast<sal_uInt16>(nValue) ); + rFrameSize.SetWidth( o3tl::narrowing<sal_uInt16>(nValue) ); rFrameSize.SetHeightSizeType( SwFrameSize::Variable ); bOk = true; } @@ -960,9 +960,9 @@ bool SvXMLImportItemMapper::PutXMLValue( if( bOk ) { if( bSetWidth ) - rFrameSize.SetWidth( static_cast<sal_uInt16>(nValue) ); + rFrameSize.SetWidth( o3tl::narrowing<sal_uInt16>(nValue) ); if( bSetHeight ) - rFrameSize.SetHeight( static_cast<sal_uInt16>(nValue) ); + rFrameSize.SetHeight( o3tl::narrowing<sal_uInt16>(nValue) ); if( bSetSizeType ) rFrameSize.SetHeightSizeType( eSizeType ); } diff --git a/sw/source/filter/xml/xmliteme.cxx b/sw/source/filter/xml/xmliteme.cxx index eb5f74ced41d..8594c75bf4df 100644 --- a/sw/source/filter/xml/xmliteme.cxx +++ b/sw/source/filter/xml/xmliteme.cxx @@ -116,7 +116,7 @@ void SwXMLTableItemMapper_Impl::handleSpecialItem( static_cast<const SwFormatHoriOrient *>(pItem)->GetHoriOrient(); bool bExport = false; sal_uInt16 nMemberId = - static_cast<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK ); + o3tl::narrowing<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK ); switch( nMemberId ) { case MID_L_MARGIN: @@ -141,7 +141,7 @@ void SwXMLTableItemMapper_Impl::handleSpecialItem( case RES_FRM_SIZE: { sal_uInt16 nMemberId = - static_cast<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK ); + o3tl::narrowing<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK ); switch( nMemberId ) { case MID_FRMSIZE_WIDTH: diff --git a/sw/source/filter/xml/xmlitemm.cxx b/sw/source/filter/xml/xmlitemm.cxx index 95462b8ac7b9..66001b1de5fb 100644 --- a/sw/source/filter/xml/xmlitemm.cxx +++ b/sw/source/filter/xml/xmlitemm.cxx @@ -23,19 +23,20 @@ #include <xmloff/xmlnamespace.hxx> #include "xmlitmap.hxx" #include <xmloff/xmltoken.hxx> +#include <o3tl/safeint.hxx> #include <unomid.h> using namespace ::xmloff::token; #define MAP_ENTRY( p, l, w, m ) \ - { XML_NAMESPACE_##p, XML_##l, static_cast<sal_uInt16>(w), m } + { XML_NAMESPACE_##p, XML_##l, o3tl::narrowing<sal_uInt16>(w), m } #define M_E_SI( p, l, w, m ) \ - { XML_NAMESPACE_##p, XML_##l, static_cast<sal_uInt16>(w), MID_SW_FLAG_SPECIAL_ITEM_IMPORT|m } + { XML_NAMESPACE_##p, XML_##l, o3tl::narrowing<sal_uInt16>(w), MID_SW_FLAG_SPECIAL_ITEM_IMPORT|m } #define M_E_SE( p, l, w, m ) \ - { XML_NAMESPACE_##p, XML_##l, static_cast<sal_uInt16>(w), MID_SW_FLAG_SPECIAL_ITEM_EXPORT|m } + { XML_NAMESPACE_##p, XML_##l, o3tl::narrowing<sal_uInt16>(w), MID_SW_FLAG_SPECIAL_ITEM_EXPORT|m } #define M_E_SIE( p, l, w, m ) \ - { XML_NAMESPACE_##p, XML_##l, static_cast<sal_uInt16>(w), MID_SW_FLAG_SPECIAL_ITEM_EXPORT|MID_SW_FLAG_SPECIAL_ITEM_IMPORT|m } + { XML_NAMESPACE_##p, XML_##l, o3tl::narrowing<sal_uInt16>(w), MID_SW_FLAG_SPECIAL_ITEM_EXPORT|MID_SW_FLAG_SPECIAL_ITEM_IMPORT|m } #define M_END { 0, XML_TOKEN_INVALID, 0, 0 } diff --git a/sw/source/filter/xml/xmlithlp.cxx b/sw/source/filter/xml/xmlithlp.cxx index 552170949d91..57f845e206f8 100644 --- a/sw/source/filter/xml/xmlithlp.cxx +++ b/sw/source/filter/xml/xmlithlp.cxx @@ -26,6 +26,7 @@ #include <xmloff/xmluconv.hxx> #include <osl/diagnose.h> +#include <o3tl/safeint.hxx> #include <com/sun/star/table/BorderLineStyle.hpp> #include <com/sun/star/text/HoriOrientation.hpp> @@ -114,7 +115,7 @@ bool sw_frmitems_parseXMLBorder( std::u16string_view rValue, else if( !rHasWidth && rUnitConverter.convertMeasureToCore(nTemp, aToken, 0, USHRT_MAX)) { - rWidth = static_cast<sal_uInt16>(nTemp); + rWidth = o3tl::narrowing<sal_uInt16>(nTemp); rHasWidth = true; } else diff --git a/sw/source/filter/xml/xmlmeta.cxx b/sw/source/filter/xml/xmlmeta.cxx index 4efa7d21bea9..69d07702aa8f 100644 --- a/sw/source/filter/xml/xmlmeta.cxx +++ b/sw/source/filter/xml/xmlmeta.cxx @@ -122,7 +122,7 @@ void SwXMLImport::SetStatistics( if (rStat.Value >>= val) { if (pStat->target16 != nullptr) { aDocStat.*(pStat->target16) - = static_cast<sal_uInt16> (val); + = o3tl::narrowing<sal_uInt16> (val); } else { aDocStat.*(pStat->target32) = static_cast<sal_uInt32> (val); diff --git a/sw/source/filter/xml/xmltble.cxx b/sw/source/filter/xml/xmltble.cxx index fb3674c955d0..b4ba4c9a8c85 100644 --- a/sw/source/filter/xml/xmltble.cxx +++ b/sw/source/filter/xml/xmltble.cxx @@ -298,7 +298,7 @@ static OUString lcl_xmltble_appendBoxPrefix(std::u16string_view rNamePrefix, if( bTop ) { OUString sTmp; - sw_GetTableBoxColStr( static_cast<sal_uInt16>(nCol), sTmp ); + sw_GetTableBoxColStr( o3tl::narrowing<sal_uInt16>(nCol), sTmp ); return OUString::Concat(rNamePrefix) + "." + sTmp + OUString::number(nRow + 1); } return OUString::Concat(rNamePrefix) diff --git a/sw/source/filter/xml/xmltbli.cxx b/sw/source/filter/xml/xmltbli.cxx index 041784f15ef7..db83fcda984c 100644 --- a/sw/source/filter/xml/xmltbli.cxx +++ b/sw/source/filter/xml/xmltbli.cxx @@ -2324,7 +2324,7 @@ void SwXMLTableContext::MakeTable_( SwTableBox *pBox ) for( colIter = m_aColumnWidths.begin(); colIter < m_aColumnWidths.end() - 1; ++colIter) { sal_Int32 nW = static_cast<sal_Int32>( colIter->width * n); - colIter->width = static_cast<sal_uInt16>(nW); + colIter->width = o3tl::narrowing<sal_uInt16>(nW); nRelWidth += nW; } m_aColumnWidths.back().width = (m_nWidth-nRelWidth); diff --git a/sw/source/ui/chrdlg/break.cxx b/sw/source/ui/chrdlg/break.cxx index 4a0a20f11759..7bc1210ef34d 100644 --- a/sw/source/ui/chrdlg/break.cxx +++ b/sw/source/ui/chrdlg/break.cxx @@ -49,7 +49,7 @@ void SwBreakDlg::rememberResult() oPgNum.reset(); if (m_xPageNumBox->get_active()) { - oPgNum = static_cast<sal_uInt16>(m_xPageNumEdit->get_value()); + oPgNum = o3tl::narrowing<sal_uInt16>(m_xPageNumEdit->get_value()); } } } diff --git a/sw/source/ui/chrdlg/drpcps.cxx b/sw/source/ui/chrdlg/drpcps.cxx index 5f0731b12810..c1ef7c489846 100644 --- a/sw/source/ui/chrdlg/drpcps.cxx +++ b/sw/source/ui/chrdlg/drpcps.cxx @@ -669,7 +669,7 @@ void SwDropCapsPage::ModifyEntry(weld::Entry& rEdit) else if (&rEdit == m_xLinesField.get()) m_aPict.SetLines(static_cast<sal_uInt8>(m_xLinesField->get_value())); else - m_aPict.SetDistance(static_cast<sal_uInt16>(m_xDistanceField->denormalize(m_xDistanceField->get_value(FieldUnit::TWIP)))); + m_aPict.SetDistance(o3tl::narrowing<sal_uInt16>(m_xDistanceField->denormalize(m_xDistanceField->get_value(FieldUnit::TWIP)))); bModified = true; } @@ -708,7 +708,7 @@ void SwDropCapsPage::FillSet( SfxItemSet &rSet ) // quantity, lines, gap aFormat.GetChars() = static_cast<sal_uInt8>(m_xDropCapsField->get_value()); aFormat.GetLines() = static_cast<sal_uInt8>(m_xLinesField->get_value()); - aFormat.GetDistance() = static_cast<sal_uInt16>(m_xDistanceField->denormalize(m_xDistanceField->get_value(FieldUnit::TWIP))); + aFormat.GetDistance() = o3tl::narrowing<sal_uInt16>(m_xDistanceField->denormalize(m_xDistanceField->get_value(FieldUnit::TWIP))); aFormat.GetWholeWord() = m_xWholeWordCB->get_active(); // template diff --git a/sw/source/ui/chrdlg/numpara.cxx b/sw/source/ui/chrdlg/numpara.cxx index 4f1cbdcc0135..c4d1de17a62a 100644 --- a/sw/source/ui/chrdlg/numpara.cxx +++ b/sw/source/ui/chrdlg/numpara.cxx @@ -131,7 +131,7 @@ bool SwParagraphNumTabPage::FillItemSet( SfxItemSet* rSet ) bool bNumberNewStartChecked = TRISTATE_TRUE == m_xNewStartNumberCB->get_state(); rSet->Put(SfxBoolItem(FN_NUMBER_NEWSTART, bNewStartChecked)); rSet->Put(SfxUInt16Item(FN_NUMBER_NEWSTART_AT, - bNumberNewStartChecked && bNewStartChecked ? static_cast<sal_uInt16>(m_xNewStartNF->get_value()) : USHRT_MAX)); + bNumberNewStartChecked && bNewStartChecked ? o3tl::narrowing<sal_uInt16>(m_xNewStartNF->get_value()) : USHRT_MAX)); } if (m_xCountParaCB->get_state_changed_from_saved()|| diff --git a/sw/source/ui/config/optload.cxx b/sw/source/ui/config/optload.cxx index af0765ab11d3..6d2aa0b40856 100644 --- a/sw/source/ui/config/optload.cxx +++ b/sw/source/ui/config/optload.cxx @@ -198,7 +198,7 @@ bool SwLoadOptPage::FillItemSet( SfxItemSet* rSet ) if (m_xTabMF->get_visible() && m_xTabMF->get_value_changed_from_saved()) { rSet->Put(SfxUInt16Item(SID_ATTR_DEFTABSTOP, - static_cast<sal_uInt16>(m_xTabMF->denormalize(m_xTabMF->get_value(FieldUnit::TWIP))))); + o3tl::narrowing<sal_uInt16>(m_xTabMF->denormalize(m_xTabMF->get_value(FieldUnit::TWIP))))); bRet = true; } @@ -477,7 +477,7 @@ SwCaptionOptPage::SwCaptionOptPage(weld::Container* pPage, weld::DialogControlle if (!pFieldType->GetName().isEmpty() && pFieldType->GetName() == m_xCategoryBox->get_active_text()) { - nSelFormat = static_cast<sal_uInt16>(static_cast<SwSetExpFieldType*>(pFieldType)->GetSeqFormat()); + nSelFormat = o3tl::narrowing<sal_uInt16>(static_cast<SwSetExpFieldType*>(pFieldType)->GetSeqFormat()); break; } } diff --git a/sw/source/ui/config/optpage.cxx b/sw/source/ui/config/optpage.cxx index 95eaf4acf213..3868c8b76246 100644 --- a/sw/source/ui/config/optpage.cxx +++ b/sw/source/ui/config/optpage.cxx @@ -1050,16 +1050,16 @@ bool SwTableOptionsTabPage::FillItemSet( SfxItemSet* ) SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig(); if (m_xRowMoveMF->get_value_changed_from_saved()) - pModOpt->SetTableHMove( static_cast<sal_uInt16>(m_xRowMoveMF->denormalize( m_xRowMoveMF->get_value(FieldUnit::TWIP)))); + pModOpt->SetTableHMove( o3tl::narrowing<sal_uInt16>(m_xRowMoveMF->denormalize( m_xRowMoveMF->get_value(FieldUnit::TWIP)))); if (m_xColMoveMF->get_value_changed_from_saved()) - pModOpt->SetTableVMove( static_cast<sal_uInt16>(m_xColMoveMF->denormalize( m_xColMoveMF->get_value(FieldUnit::TWIP)))); + pModOpt->SetTableVMove( o3tl::narrowing<sal_uInt16>(m_xColMoveMF->denormalize( m_xColMoveMF->get_value(FieldUnit::TWIP)))); if (m_xRowInsertMF->get_value_changed_from_saved()) - pModOpt->SetTableHInsert(static_cast<sal_uInt16>(m_xRowInsertMF->denormalize( m_xRowInsertMF->get_value(FieldUnit::TWIP)))); + pModOpt->SetTableHInsert(o3tl::narrowing<sal_uInt16>(m_xRowInsertMF->denormalize( m_xRowInsertMF->get_value(FieldUnit::TWIP)))); if (m_xColInsertMF->get_value_changed_from_saved()) - pModOpt->SetTableVInsert(static_cast<sal_uInt16>(m_xColInsertMF->denormalize( m_xColInsertMF->get_value(FieldUnit::TWIP)))); + pModOpt->SetTableVInsert(o3tl::narrowing<sal_uInt16>(m_xColInsertMF->denormalize( m_xColInsertMF->get_value(FieldUnit::TWIP)))); TableChgMode eMode; if (m_xFixRB->get_active()) diff --git a/sw/source/ui/dbui/dbinsdlg.cxx b/sw/source/ui/dbui/dbinsdlg.cxx index 6e4d47ca9190..5f30ef971191 100644 --- a/sw/source/ui/dbui/dbinsdlg.cxx +++ b/sw/source/ui/dbui/dbinsdlg.cxx @@ -664,7 +664,7 @@ IMPL_LINK_NOARG(SwInsertDBColAutoPilot, TableFormatHdl, weld::Button&, void) { const SwColumn* pCol = &rCols[i]; nStart1 = pCol->GetLeft() + nWidth1; - nWidth1 += static_cast<tools::Long>(rCol.CalcColWidth( i, static_cast<sal_uInt16>(nWidth) )); + nWidth1 += static_cast<tools::Long>(rCol.CalcColWidth( i, o3tl::narrowing<sal_uInt16>(nWidth) )); nEnd1 = nWidth1 - pCol->GetRight(); } if(nStart1 || nEnd1 != nWidth) diff --git a/sw/source/ui/dbui/mmaddressblockpage.cxx b/sw/source/ui/dbui/mmaddressblockpage.cxx index 3217a01147d5..e62f18352f1c 100644 --- a/sw/source/ui/dbui/mmaddressblockpage.cxx +++ b/sw/source/ui/dbui/mmaddressblockpage.cxx @@ -139,7 +139,7 @@ void SwMailMergeAddressBlockPage::Activate() m_pWizard->GetConfigItem().GetAddressBlocks(); for(const auto& rAddress : aBlocks) m_xSettings->AddAddress(rAddress); - m_xSettings->SelectAddress(static_cast<sal_uInt16>(rConfigItem.GetCurrentAddressBlockIndex())); + m_xSettings->SelectAddress(o3tl::narrowing<sal_uInt16>(rConfigItem.GetCurrentAddressBlockIndex())); m_xAddressCB->set_active(rConfigItem.IsAddressBlock()); AddressBlockHdl_Impl(*m_xAddressCB); m_xSettings->SetLayout(1, 2); @@ -430,7 +430,7 @@ IMPL_LINK(SwSelectAddressBlockDialog, NewCustomizeHdl_Impl, weld::Button&, rButt m_aAddressBlocks.realloc(m_aAddressBlocks.getLength() + 1); const sal_Int32 nSelect = m_aAddressBlocks.getLength() - 1; m_aAddressBlocks[nSelect] = sNew; - m_xPreview->SelectAddress(static_cast<sal_uInt16>(nSelect)); + m_xPreview->SelectAddress(o3tl::narrowing<sal_uInt16>(nSelect)); } m_xDeletePB->set_sensitive(m_aAddressBlocks.getLength() > 1); } diff --git a/sw/source/ui/envelp/envfmt.cxx b/sw/source/ui/envelp/envfmt.cxx index b3b57a923011..f29d4f49ab99 100644 --- a/sw/source/ui/envelp/envfmt.cxx +++ b/sw/source/ui/envelp/envfmt.cxx @@ -197,7 +197,7 @@ IMPL_LINK( SwEnvFormatPage, ModifyHdl, weld::MetricSpinButton&, rEdit, void ) Paper ePaper = SvxPaperInfo::GetSvxPaper( Size(nRotatedWidth, nRotatedHeight), MapUnit::MapTwip); for (size_t i = 0; i < m_aIDs.size(); ++i) - if (m_aIDs[i] == static_cast<sal_uInt16>(ePaper)) + if (m_aIDs[i] == o3tl::narrowing<sal_uInt16>(ePaper)) m_xSizeFormatBox->set_active(i); // remember user size @@ -266,7 +266,7 @@ void SwEnvFormatPage::Edit(const OString& rIdent, bool bSender) const SvxTabStopItem& rDefTabs = pSh->GetView().GetCurShell()->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 ); aTmpSet.Put( aDefDistItem ); @@ -463,7 +463,7 @@ void SwEnvFormatPage::Reset(const SfxItemSet* rSet) Size( std::min(rItem.m_nWidth, rItem.m_nHeight), std::max(rItem.m_nWidth, rItem.m_nHeight)), MapUnit::MapTwip); for (size_t i = 0; i < m_aIDs.size(); ++i) - if (m_aIDs[i] == static_cast<sal_uInt16>(ePaper)) + if (m_aIDs[i] == o3tl::narrowing<sal_uInt16>(ePaper)) m_xSizeFormatBox->set_active(i); // Metric fields diff --git a/sw/source/ui/fldui/flddb.cxx b/sw/source/ui/fldui/flddb.cxx index 14492377629b..3764a5145d85 100644 --- a/sw/source/ui/fldui/flddb.cxx +++ b/sw/source/ui/fldui/flddb.cxx @@ -149,7 +149,7 @@ void SwFieldDBPage::Reset(const SfxItemSet*) sal_Int32 nIdx{ 0 }; if (sUserData.getToken(0, ';', nIdx).equalsIgnoreAsciiCase(USER_DATA_VERSION_1)) { - const sal_uInt16 nVal = static_cast<sal_uInt16>(sUserData.getToken(0, ';', nIdx).toInt32()); + const sal_uInt16 nVal = o3tl::narrowing<sal_uInt16>(sUserData.getToken(0, ';', nIdx).toInt32()); if (nVal != USHRT_MAX) { for (sal_Int32 i = 0, nEntryCount = m_xTypeLB->n_children(); i < nEntryCount; ++i) diff --git a/sw/source/ui/fldui/fldvar.cxx b/sw/source/ui/fldui/fldvar.cxx index b26b52ef1993..9cf9602cdade 100644 --- a/sw/source/ui/fldui/fldvar.cxx +++ b/sw/source/ui/fldui/fldvar.cxx @@ -151,7 +151,7 @@ void SwFieldVarPage::Reset(const SfxItemSet* ) if(!IsRefresh() && sUserData.getToken(0, ';', nIdx).equalsIgnoreAsciiCase(USER_DATA_VERSION_1)) { OUString sVal = sUserData.getToken(0, ';', nIdx); - sal_uInt16 nVal = static_cast<sal_uInt16>(sVal.toInt32()); + sal_uInt16 nVal = o3tl::narrowing<sal_uInt16>(sVal.toInt32()); if (USHRT_MAX != nVal) { for (sal_Int32 i = 0, nEntryCount = m_xTypeLB->n_children(); i < nEntryCount; i++) diff --git a/sw/source/ui/frmdlg/column.cxx b/sw/source/ui/frmdlg/column.cxx index 80a290a9bcc9..7a2baccac79d 100644 --- a/sw/source/ui/frmdlg/column.cxx +++ b/sw/source/ui/frmdlg/column.cxx @@ -553,7 +553,7 @@ void SwColumnPage::Reset(const SfxItemSet *rSet) m_xColMgr.reset(new SwColMgr(*rSet)); m_nCols = m_xColMgr->GetCount() ; - m_xCLNrEdt->set_max(std::max(static_cast<sal_uInt16>(m_xCLNrEdt->get_max()), m_nCols)); + m_xCLNrEdt->set_max(std::max(o3tl::narrowing<sal_uInt16>(m_xCLNrEdt->get_max()), m_nCols)); if(m_bFrame) { @@ -563,7 +563,7 @@ void SwColumnPage::Reset(const SfxItemSet *rSet) { const SwFormatFrameSize& rSize = rSet->Get(RES_FRM_SIZE); const SvxBoxItem& rBox = rSet->Get(RES_BOX); - m_xColMgr->SetActualWidth(static_cast<sal_uInt16>(rSize.GetSize().Width()) - rBox.GetSmallestDistance()); + m_xColMgr->SetActualWidth(o3tl::narrowing<sal_uInt16>(rSize.GetSize().Width()) - rBox.GetSmallestDistance()); } } if (m_xBalanceColsCB->get_visible()) @@ -911,7 +911,7 @@ IMPL_LINK_NOARG(SwColumnPage, ColModify, weld::SpinButton&, void) void SwColumnPage::ColModify(bool bForceColReset) { - m_nCols = static_cast<sal_uInt16>(m_xCLNrEdt->get_value()); + m_nCols = o3tl::narrowing<sal_uInt16>(m_xCLNrEdt->get_value()); //#107890# the handler is also called from LoseFocus() //then no change has been made and thus no action should be taken // #i17816# changing the displayed types within the ValueSet @@ -923,7 +923,7 @@ void SwColumnPage::ColModify(bool bForceColReset) if (!bForceColReset) m_aDefaultVS.SetNoSelection(); tools::Long nDist = static_cast< tools::Long >(m_xDistEd1->DenormalizePercent(m_xDistEd1->get_value(FieldUnit::TWIP))); - m_xColMgr->SetCount(m_nCols, static_cast<sal_uInt16>(nDist)); + m_xColMgr->SetCount(m_nCols, o3tl::narrowing<sal_uInt16>(nDist)); for(sal_uInt16 i = 0; i < m_nCols; i++) m_nColDist[i] = nDist; m_nFirstVis = 0; @@ -955,7 +955,7 @@ IMPL_LINK(SwColumnPage, GapModify, weld::MetricSpinButton&, rMetricField, void) nActValue = nMaxGap; m_xDistEd1->set_value(m_xDistEd1->NormalizePercent(nMaxGap), FieldUnit::TWIP); } - m_xColMgr->SetGutterWidth(static_cast<sal_uInt16>(nActValue)); + m_xColMgr->SetGutterWidth(o3tl::narrowing<sal_uInt16>(nActValue)); for(sal_uInt16 i = 0; i < m_nCols; i++) m_nColDist[i] = nActValue; @@ -1018,7 +1018,7 @@ IMPL_LINK(SwColumnPage, EdModify, weld::MetricSpinButton&, rEdit, void) IMPL_LINK(SwColumnPage, AutoWidthHdl, weld::Toggleable&, rBox, void) { tools::Long nDist = static_cast< tools::Long >(m_xDistEd1->DenormalizePercent(m_xDistEd1->get_value(FieldUnit::TWIP))); - m_xColMgr->SetCount(m_nCols, static_cast<sal_uInt16>(nDist)); + m_xColMgr->SetCount(m_nCols, o3tl::narrowing<sal_uInt16>(nDist)); for(sal_uInt16 i = 0; i < m_nCols; i++) m_nColDist[i] = nDist; if (rBox.get_active()) diff --git a/sw/source/ui/frmdlg/cption.cxx b/sw/source/ui/frmdlg/cption.cxx index 6f4f8208b7ee..867e16fa56dc 100644 --- a/sw/source/ui/frmdlg/cption.cxx +++ b/sw/source/ui/frmdlg/cption.cxx @@ -216,7 +216,7 @@ SwCaptionDialog::SwCaptionDialog(weld::Window *pParent, SwView &rV) SwFieldType* pFieldType = pMgr->GetFieldType(SwFieldIds::Unknown, --i); if (pFieldType->GetName() == m_xCategoryBox->get_active_text()) { - nSelFormat = static_cast<sal_uInt16>(static_cast<SwSetExpFieldType*>(pFieldType)->GetSeqFormat()); + nSelFormat = o3tl::narrowing<sal_uInt16>(static_cast<SwSetExpFieldType*>(pFieldType)->GetSeqFormat()); break; } } diff --git a/sw/source/ui/frmdlg/frmpage.cxx b/sw/source/ui/frmdlg/frmpage.cxx index 0708a639e6c7..00dbc8c0e03e 100644 --- a/sw/source/ui/frmdlg/frmpage.cxx +++ b/sw/source/ui/frmdlg/frmpage.cxx @@ -2197,7 +2197,7 @@ void SwFramePage::Init(const SfxItemSet& rSet) // columns SwFormatCol aCol( rSet.Get(RES_COL) ); - ::FitToActualSize( aCol, static_cast<sal_uInt16>(rSize.GetWidth()) ); + ::FitToActualSize( aCol, o3tl::narrowing<sal_uInt16>(rSize.GetWidth()) ); RndStdIds eAnchorId = GetAnchor(); diff --git a/sw/source/ui/frmdlg/wrap.cxx b/sw/source/ui/frmdlg/wrap.cxx index 95df8eeb85d0..ad9e0aad185e 100644 --- a/sw/source/ui/frmdlg/wrap.cxx +++ b/sw/source/ui/frmdlg/wrap.cxx @@ -321,8 +321,8 @@ bool SwWrapTabPage::FillItemSet(SfxItemSet *rSet) bool bBottomMod = m_xBottomMarginED->get_value_changed_from_saved(); SvxULSpaceItem aUL( RES_UL_SPACE ); - aUL.SetUpper(static_cast<sal_uInt16>(m_xTopMarginED->denormalize(m_xTopMarginED->get_value(FieldUnit::TWIP)))); - aUL.SetLower(static_cast<sal_uInt16>(m_xBottomMarginED->denormalize(m_xBottomMarginED->get_value(FieldUnit::TWIP)))); + aUL.SetUpper(o3tl::narrowing<sal_uInt16>(m_xTopMarginED->denormalize(m_xTopMarginED->get_value(FieldUnit::TWIP)))); + aUL.SetLower(o3tl::narrowing<sal_uInt16>(m_xBottomMarginED->denormalize(m_xBottomMarginED->get_value(FieldUnit::TWIP)))); if ( bTopMod || bBottomMod ) { @@ -338,8 +338,8 @@ bool SwWrapTabPage::FillItemSet(SfxItemSet *rSet) bool bRightMod = m_xRightMarginED->get_value_changed_from_saved(); SvxLRSpaceItem aLR( RES_LR_SPACE ); - aLR.SetLeft(static_cast<sal_uInt16>(m_xLeftMarginED->denormalize(m_xLeftMarginED->get_value(FieldUnit::TWIP)))); - aLR.SetRight(static_cast<sal_uInt16>(m_xRightMarginED->denormalize(m_xRightMarginED->get_value(FieldUnit::TWIP)))); + aLR.SetLeft(o3tl::narrowing<sal_uInt16>(m_xLeftMarginED->denormalize(m_xLeftMarginED->get_value(FieldUnit::TWIP)))); + aLR.SetRight(o3tl::narrowing<sal_uInt16>(m_xRightMarginED->denormalize(m_xRightMarginED->get_value(FieldUnit::TWIP)))); if ( bLeftMod || bRightMod ) { diff --git a/sw/source/ui/misc/linenum.cxx b/sw/source/ui/misc/linenum.cxx index f04efd98bfe6..72adb140b219 100644 --- a/sw/source/ui/misc/linenum.cxx +++ b/sw/source/ui/misc/linenum.cxx @@ -208,16 +208,16 @@ IMPL_LINK_NOARG(SwLineNumberingDlg, OKHdl, weld::Button&, void) aInf.SetPos(static_cast<LineNumberPosition>(m_xPosLB->get_active())); // offset - aInf.SetPosFromLeft(static_cast<sal_uInt16>(m_xOffsetMF->denormalize(m_xOffsetMF->get_value(FieldUnit::TWIP)))); + aInf.SetPosFromLeft(o3tl::narrowing<sal_uInt16>(m_xOffsetMF->denormalize(m_xOffsetMF->get_value(FieldUnit::TWIP)))); // numbering offset - aInf.SetCountBy(static_cast<sal_uInt16>(m_xNumIntervalNF->get_value())); + aInf.SetCountBy(o3tl::narrowing<sal_uInt16>(m_xNumIntervalNF->get_value())); // divider aInf.SetDivider(m_xDivisorED->get_text()); // divider offset - aInf.SetDividerCountBy(static_cast<sal_uInt16>(m_xDivIntervalNF->get_value())); + aInf.SetDividerCountBy(o3tl::narrowing<sal_uInt16>(m_xDivIntervalNF->get_value())); // count aInf.SetCountBlankLines(m_xCountEmptyLinesCB->get_active()); diff --git a/sw/source/ui/misc/outline.cxx b/sw/source/ui/misc/outline.cxx index 8c03aef47a4e..f01b6386901e 100644 --- a/sw/source/ui/misc/outline.cxx +++ b/sw/source/ui/misc/outline.cxx @@ -92,7 +92,7 @@ void SwNumNamesDlg::SetUserNames(const OUString *pList[]) nSelect++; } } - m_xFormBox->select(std::min(nSelect, static_cast<sal_uInt16>(m_xFormBox->n_children() - 1))); + m_xFormBox->select(std::min(nSelect, o3tl::narrowing<sal_uInt16>(m_xFormBox->n_children() - 1))); SelectHdl(*m_xFormBox); } @@ -666,7 +666,7 @@ IMPL_LINK( SwOutlineSettingsTabPage, StartModified, weld::SpinButton&, rEdit, vo if(nActLevel & nMask) { SwNumFormat aNumFormat(pNumRule->Get(i)); - aNumFormat.SetStart(static_cast<sal_uInt16>(rEdit.get_value())); + aNumFormat.SetStart(o3tl::narrowing<sal_uInt16>(rEdit.get_value())); pNumRule->Set(i, aNumFormat); } nMask <<= 1; @@ -767,7 +767,7 @@ void SwOutlineSettingsTabPage::SetWrtShell(SwWrtShell* pShell) int nTmp = 0; if(nOutlinePos != SwOutlineNodes::npos) { - nTmp = static_cast<sal_uInt16>(pSh->getIDocumentOutlineNodesAccess()->getOutlineLevel(nOutlinePos)); + nTmp = o3tl::narrowing<sal_uInt16>(pSh->getIDocumentOutlineNodesAccess()->getOutlineLevel(nOutlinePos)); } m_xLevelLB->select(nTmp-1); diff --git a/sw/source/ui/table/colwd.cxx b/sw/source/ui/table/colwd.cxx index 435b4ee10dc2..2440d8696fac 100644 --- a/sw/source/ui/table/colwd.cxx +++ b/sw/source/ui/table/colwd.cxx @@ -28,7 +28,7 @@ IMPL_LINK_NOARG(SwTableWidthDlg, LoseFocusHdl, weld::SpinButton&, void) { - sal_uInt16 nId = static_cast<sal_uInt16>(m_xColNF->get_value()) - 1; + sal_uInt16 nId = o3tl::narrowing<sal_uInt16>(m_xColNF->get_value()) - 1; const SwTwips lWidth = m_rFnc.GetColWidth(nId); m_xWidthMF->set_max(m_xWidthMF->normalize(m_rFnc.GetMaxColWidth(nId)), FieldUnit::TWIP); m_xWidthMF->set_value(m_xWidthMF->normalize(lWidth), FieldUnit::TWIP); @@ -60,8 +60,8 @@ SwTableWidthDlg::SwTableWidthDlg(weld::Window *pParent, SwTableFUNC &rTableFnc) void SwTableWidthDlg::Apply() { m_rFnc.InitTabCols(); - m_rFnc.SetColWidth(static_cast<sal_uInt16>(m_xColNF->get_value() - 1), - static_cast<sal_uInt16>(m_xWidthMF->denormalize(m_xWidthMF->get_value(FieldUnit::TWIP)))); + m_rFnc.SetColWidth(o3tl::narrowing<sal_uInt16>(m_xColNF->get_value() - 1), + o3tl::narrowing<sal_uInt16>(m_xWidthMF->denormalize(m_xWidthMF->get_value(FieldUnit::TWIP)))); } short SwTableWidthDlg::run() diff --git a/sw/source/ui/table/tabledlg.cxx b/sw/source/ui/table/tabledlg.cxx index 836a3499f50e..36964d4f10fe 100644 --- a/sw/source/ui/table/tabledlg.cxx +++ b/sw/source/ui/table/tabledlg.cxx @@ -1349,7 +1349,7 @@ bool SwTextFlowPage::FillItemSet( SfxItemSet* rSet ) { sPage = m_xPageCollLB->get_active_text(); } - sal_uInt16 nPgNum = static_cast<sal_uInt16>(m_xPageNoNF->get_value()); + sal_uInt16 nPgNum = o3tl::narrowing<sal_uInt16>(m_xPageNoNF->get_value()); bool const usePageNo(bState && m_xPageNoCB->get_active()); std::optional<sal_uInt16> const oPageNum( usePageNo ? nPgNum : std::optional<sal_Int16>()); 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); |