diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-07-23 08:44:14 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-08-10 03:02:52 +0200 |
commit | 9da7b1592e010928c26c43ee93b91cdd66403985 (patch) | |
tree | 213723545904c4c4549b7f635c4ac6182e0af06e | |
parent | eeeef98796df322d89912070c8e431c5f6d1283f (diff) |
sw: remove all uses of MM50 with (added) o3tl::toTwip
MM50 constant is the number of twips for 5mm. This is (ab)used as
a "shortcut" to set or compare various variables through the code
and also to set a multiplied value (like 1cm, 2cm, 4cm) or divided
value (2.5mm, 1.25mm). The problem with this is that converting the
5mm to twip doesn't round up exactly and multiplied and divided
values increase the error even more.
Instead of basing it from MM50 constant, it is just better to use
our o3tl::convert (or the added variant o3tl::toTwip), which can
actually calculate the conversion at compile time, so there is no
added complexity at runtime and we get a more readable code with
more exact result.
i.e.
o3tl::toTwip(4, o3tl::Length::cm)
instead of the more cryptic
MM50 * 8
In addition also sanitize and comment the values of the constants
in sw/inc/swtypes.hxx.
Change-Id: I85c306c36207d47ac3dc207094b68d0fb1ca5b70
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119397
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
27 files changed, 105 insertions, 60 deletions
diff --git a/include/o3tl/unit_conversion.hxx b/include/o3tl/unit_conversion.hxx index 4c76375737a2..cf293662e7b2 100644 --- a/include/o3tl/unit_conversion.hxx +++ b/include/o3tl/unit_conversion.hxx @@ -199,6 +199,12 @@ template <typename N, typename U> constexpr auto convert(N n, U from, U to) return convert(n, detail::md(from, to), detail::md(to, from)); } +// Convert to twips - for convenience as we do this a lot +template <typename N> constexpr auto toTwips(N number, Length from) +{ + return convert(number, from, Length::twip); +} + // Returns nDefault if intermediate multiplication overflows sal_Int64 (only for integral types). // On return, bOverflow indicates if overflow happened. nDefault is returned when overflow occurs. template <typename N, typename U> diff --git a/o3tl/qa/test-unit_conversion.cxx b/o3tl/qa/test-unit_conversion.cxx index 983c0845a4cd..80b01ea2bf2b 100644 --- a/o3tl/qa/test-unit_conversion.cxx +++ b/o3tl/qa/test-unit_conversion.cxx @@ -869,4 +869,11 @@ static_assert(o3tl::convert(100, o3tl::Length::line, o3tl::Length::line) == 100) static_assert(o3tl::convert(49, o3tl::Length::mm100, o3tl::Length::mm) == 0); static_assert(o3tl::convert(50, o3tl::Length::mm100, o3tl::Length::mm) == 1); +// Conversions used in the code - to make sure they produce the expected and unchanged result + +static_assert(o3tl::toTwips(25, o3tl::Length::in100) == 1440 / 4); +static_assert(o3tl::toTwips(15, o3tl::Length::in100) == 216); +// the following twip value used to the constant for 20mm +static_assert(o3tl::toTwips(20, o3tl::Length::mm) == 1134); + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sw/inc/swtypes.hxx b/sw/inc/swtypes.hxx index 81ad502b82be..ff79edb47d02 100644 --- a/sw/inc/swtypes.hxx +++ b/sw/inc/swtypes.hxx @@ -25,6 +25,7 @@ #include <com/sun/star/i18n/CollatorOptions.hpp> #include "swdllapi.h" #include <o3tl/typed_flags_set.hxx> +#include <o3tl/unit_conversion.hxx> #include <i18nlangtag/lang.h> #include <vcl/outdev.hxx> #include <svx/flagsdef.hxx> @@ -56,26 +57,26 @@ typedef tools::Long SwTwips; constexpr sal_Int32 COMPLETE_STRING = SAL_MAX_INT32; -constexpr SwTwips cMinHdFtHeight = 56; +constexpr SwTwips cMinHdFtHeight = 56; // ~1mm #define MINFLY 23 // Minimal size for FlyFrames. #define MINLAY 23 // Minimal size for other Frames. // Default column distance of two text columns corresponds to 0.3 cm. -constexpr SwTwips DEF_GUTTER_WIDTH = MM50 / 5 * 3; +constexpr SwTwips DEF_GUTTER_WIDTH = o3tl::toTwips(3, o3tl::Length::mm); // Minimal distance (distance to text) for border attribute // in order not to crock up aligned lines. -// 28 Twips == 0,4mm -constexpr SwTwips MIN_BORDER_DIST = 28; +// 28 Twips == 0,5mm +constexpr SwTwips MIN_BORDER_DIST = 28; // ~0.5mm // Minimal document border: 20mm. -constexpr SwTwips lMinBorder = 1134; +constexpr SwTwips lMinBorder = o3tl::toTwips(20, o3tl::Length::mm); // ~20mm // Margin left and above document. // Half of it is gap between the pages. //TODO: Replace with SwViewOption::defDocumentBorder -constexpr SwTwips DOCUMENTBORDER = 284; +constexpr SwTwips DOCUMENTBORDER = 284; // ~5mm // For inserting of captions (what and where to insert). // It's here because it is not big enough to justify its own hxx @@ -96,11 +97,11 @@ constexpr sal_uInt8 NO_NUMLEVEL = 0x20; // "or" with the levels. // (For more levels the values have to be multiplied with the levels+1; // levels 0 ..4!) -constexpr short lBulletIndent = 1440 / 4; +constexpr short lBulletIndent = o3tl::toTwips(25, o3tl::Length::in100); // 0.25 inch constexpr short lBulletFirstLineOffset = -lBulletIndent; -constexpr sal_uInt16 lNumberIndent = 1440 / 4; +constexpr sal_uInt16 lNumberIndent = o3tl::toTwips(25, o3tl::Length::in100); // 0.25 inch constexpr short lNumberFirstLineOffset = -lNumberIndent; -constexpr short lOutlineMinTextDistance = 216; // 0.15 inch = 0.38 cm +constexpr short lOutlineMinTextDistance = o3tl::toTwips(15, o3tl::Length::in100); // 0.15 inch = 0.38 cm // Count of SystemField-types of SwDoc. #define INIT_FLDTYPES 33 diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 91f6689f1d73..ad09174796af 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -597,7 +597,8 @@ void SwTiledRenderingTest::testInsertShape() IDocumentDrawModelAccess &rDrawModelAccess = pWrtShell->GetDoc()->getIDocumentDrawModelAccess(); SdrPage* pPage = rDrawModelAccess.GetDrawModel()->GetPage(0); SdrObject* pObject = pPage->GetObj(0); - CPPUNIT_ASSERT_EQUAL(tools::Rectangle(3302, 302, 6698, 3698), pObject->GetSnapRect()); + + CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(3299, 299), Size(3403, 3403)), pObject->GetSnapRect()); // check that it is in the foreground layer CPPUNIT_ASSERT_EQUAL(rDrawModelAccess.GetHeavenId().get(), pObject->GetLayer().get()); diff --git a/sw/source/core/doc/DocumentStylePoolManager.cxx b/sw/source/core/doc/DocumentStylePoolManager.cxx index c69df3adc003..e1c20bc0a377 100644 --- a/sw/source/core/doc/DocumentStylePoolManager.cxx +++ b/sw/source/core/doc/DocumentStylePoolManager.cxx @@ -1669,9 +1669,9 @@ SwFormat* DocumentStylePoolManager::GetFormatFromPool( sal_uInt16 nId ) aSet.Put( SwFormatVertOrient( 0, text::VertOrientation::TOP, text::RelOrientation::FRAME )); aSet.Put( SwFormatSurround( css::text::WrapTextMode_PARALLEL )); // Set the default width to 3.5 cm, use the minimum value for the height - aSet.Put( SwFormatFrameSize( SwFrameSize::Minimum, - o3tl::convert(35, o3tl::Length::mm, o3tl::Length::twip), - MM50 )); + aSet.Put(SwFormatFrameSize(SwFrameSize::Minimum, + o3tl::toTwips(35, o3tl::Length::mm), + o3tl::toTwips(5, o3tl::Length::mm))); } break; case RES_POOLFRM_WATERSIGN: diff --git a/sw/source/core/doc/lineinfo.cxx b/sw/source/core/doc/lineinfo.cxx index e77e14a174d8..628e90e32198 100644 --- a/sw/source/core/doc/lineinfo.cxx +++ b/sw/source/core/doc/lineinfo.cxx @@ -52,7 +52,7 @@ const SwLineNumberInfo& SwDoc::GetLineNumberInfo() const } SwLineNumberInfo::SwLineNumberInfo() : - m_nPosFromLeft( MM50 ), + m_nPosFromLeft(o3tl::toTwips(5, o3tl::Length::mm)), m_nCountBy( 5 ), m_nDividerCountBy( 3 ), m_ePos( LINENUMBER_POS_LEFT ), diff --git a/sw/source/core/edit/edattr.cxx b/sw/source/core/edit/edattr.cxx index 6ab5a3ae9ad8..2cb6f41b2484 100644 --- a/sw/source/core/edit/edattr.cxx +++ b/sw/source/core/edit/edattr.cxx @@ -501,8 +501,13 @@ bool SwEditShell::IsMoveLeftMargin( bool bRight, bool bModulus ) const { bool bRet = true; + constexpr sal_uInt16 constTwips_2cm = o3tl::toTwips(20, o3tl::Length::mm); + constexpr tools::Long constTwips_5mm = o3tl::toTwips(5, o3tl::Length::mm); + const SvxTabStopItem& rTabItem = GetDoc()->GetDefault( RES_PARATR_TABSTOP ); - sal_uInt16 nDefDist = o3tl::narrowing<sal_uInt16>(rTabItem.Count() ? rTabItem[0].GetTabPos() : 1134); + sal_uInt16 nDefDist = o3tl::narrowing<sal_uInt16>( + rTabItem.Count() ? rTabItem[0].GetTabPos() : constTwips_2cm); + if( !nDefDist ) return false; @@ -534,7 +539,7 @@ bool SwEditShell::IsMoveLeftMargin( bool bRight, bool bModulus ) const const sal_uInt32 nFrameWidth = o3tl::narrowing<sal_uInt32>( pFrame->IsVertical() ? pFrame->getFrameArea().Height() : pFrame->getFrameArea().Width() ); - bRet = o3tl::narrowing<SwTwips>(nFrameWidth) > ( nNext + MM50 ); + bRet = o3tl::narrowing<SwTwips>(nFrameWidth) > (nNext + constTwips_5mm); } else bRet = false; diff --git a/sw/source/core/frmedt/feshview.cxx b/sw/source/core/frmedt/feshview.cxx index cf9832887d33..5a6f85f0a163 100644 --- a/sw/source/core/frmedt/feshview.cxx +++ b/sw/source/core/frmedt/feshview.cxx @@ -1908,11 +1908,13 @@ bool SwFEShell::ImpEndCreate() // The crsr should not be too far away bCharBound = true; + constexpr tools::Long constTwips_1cm = o3tl::toTwips(1, o3tl::Length::cm); tools::Rectangle aRect( aTmp.SVRect() ); - aRect.AdjustLeft( -(MM50*2) ); - aRect.AdjustTop( -(MM50*2) ); - aRect.AdjustRight(MM50*2 ); - aRect.AdjustBottom(MM50*2 ); + // Extend by 1 cm in each direction + aRect.AdjustLeft(-constTwips_1cm); + aRect.AdjustTop(-constTwips_1cm); + aRect.AdjustRight(constTwips_1cm); + aRect.AdjustBottom(constTwips_1cm); if( !aRect.IsOver( rBound ) && !::GetHtmlMode( GetDoc()->GetDocShell() )) bCharBound = false; diff --git a/sw/source/core/layout/calcmove.cxx b/sw/source/core/layout/calcmove.cxx index 71a598c229bc..004fd4114d5c 100644 --- a/sw/source/core/layout/calcmove.cxx +++ b/sw/source/core/layout/calcmove.cxx @@ -860,7 +860,9 @@ void SwPageFrame::MakeAll(vcl::RenderContext* pRenderContext) if (nWidth < nDefWidth) nWidth = nDefWidth; nWidth += + 2 * aBorder.Width(); - nWidth = std::max( nWidth, 2L * aBorder.Width() + 4*MM50 ); + + constexpr tools::Long constTwips_2cm = o3tl::toTwips(2, o3tl::Length::cm); + nWidth = std::max(nWidth, 2L * aBorder.Width() + constTwips_2cm); { SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this); diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx index 69c726721745..74d366d9961d 100644 --- a/sw/source/core/unocore/unoframe.cxx +++ b/sw/source/core/unocore/unoframe.cxx @@ -879,9 +879,10 @@ bool BaseFrameProperties_Impl::FillBaseProperties(SfxItemSet& rToSet, const SfxI { rSizeFound = false; SwFormatFrameSize aFrameSz; + constexpr sal_Int32 constTwips_1cm = o3tl::toTwips(1, o3tl::Length::cm); awt::Size aSize; - aSize.Width = 2 * MM50; - aSize.Height = 2 * MM50; + aSize.Width = constTwips_1cm; + aSize.Height = constTwips_1cm; ::uno::Any aSizeVal; aSizeVal <<= aSize; static_cast<SfxPoolItem&>(aFrameSz).PutValue(aSizeVal, MID_FRMSIZE_SIZE|CONVERT_TWIPS); diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index f2f3f3e43b13..4ebbedcf72f2 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -2923,7 +2923,8 @@ void SwXPageStyle::SetPropertyValues_Impl(const uno::Sequence<OUString>& rProper aTempSet.SetParent(&GetDoc()->GetDfltFrameFormat()->GetAttrSet()); aTempSet.Put(SfxBoolItem(SID_ATTR_PAGE_ON, true)); - aTempSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(MM50, MM50))); + constexpr tools::Long constTwips_5mm = o3tl::toTwips(5, o3tl::Length::mm); + aTempSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(constTwips_5mm, constTwips_5mm))); aTempSet.Put(SvxLRSpaceItem(RES_LR_SPACE)); aTempSet.Put(SvxULSpaceItem(RES_UL_SPACE)); aTempSet.Put(SfxBoolItem(SID_ATTR_PAGE_SHARED, true)); diff --git a/sw/source/filter/html/htmlnum.hxx b/sw/source/filter/html/htmlnum.hxx index 2e7957996509..b73fd386e3f3 100644 --- a/sw/source/filter/html/htmlnum.hxx +++ b/sw/source/filter/html/htmlnum.hxx @@ -22,8 +22,8 @@ #include <swtypes.hxx> #include <string.h> -#define HTML_NUMBER_BULLET_MARGINLEFT (MM50*2 + MM50/2) -#define HTML_NUMBER_BULLET_INDENT (-MM50) +#define HTML_NUMBER_BULLET_MARGINLEFT (o3tl::toTwips(125, o3tl::Length::mm10)) +#define HTML_NUMBER_BULLET_INDENT (-o3tl::toTwips(5, o3tl::Length::mm)) class SwTextNode; class SwNumRule; diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx index 9ae5abc57095..e3cb057759d5 100644 --- a/sw/source/filter/html/htmlplug.cxx +++ b/sw/source/filter/html/htmlplug.cxx @@ -83,11 +83,12 @@ using namespace com::sun::star; -#define HTML_DFLT_EMBED_WIDTH ((MM50*5)/2) -#define HTML_DFLT_EMBED_HEIGHT ((MM50*5)/2) -#define HTML_DFLT_APPLET_WIDTH ((MM50*5)/2) -#define HTML_DFLT_APPLET_HEIGHT ((MM50*5)/2) +#define HTML_DFLT_EMBED_WIDTH (o3tl::toTwips(125, o3tl::Length::mm10)) +#define HTML_DFLT_EMBED_HEIGHT (o3tl::toTwips(125, o3tl::Length::mm10)) + +#define HTML_DFLT_APPLET_WIDTH (o3tl::toTwips(125, o3tl::Length::mm10)) +#define HTML_DFLT_APPLET_HEIGHT (o3tl::toTwips(125, o3tl::Length::mm10)) const HtmlFrmOpts HTML_FRMOPTS_EMBED_ALL = diff --git a/sw/source/filter/html/htmltab.cxx b/sw/source/filter/html/htmltab.cxx index e1cc324d73c2..ec1c6a03702f 100644 --- a/sw/source/filter/html/htmltab.cxx +++ b/sw/source/filter/html/htmltab.cxx @@ -3421,7 +3421,9 @@ void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions, true ); aFrameSet.Put( SwFormatSurround(eSurround) ); - SwFormatFrameSize aFrameSize( SwFrameSize::Variable, 20*MM50, MINLAY ); + constexpr tools::Long constTwips_100mm = o3tl::convert(tools::Long(100), o3tl::Length::mm, o3tl::Length::twip); + + SwFormatFrameSize aFrameSize( SwFrameSize::Variable, constTwips_100mm, MINLAY ); aFrameSize.SetWidthPercent( 100 ); aFrameSet.Put( aFrameSize ); diff --git a/sw/source/filter/html/svxcss1.hxx b/sw/source/filter/html/svxcss1.hxx index fd547a0e9d76..9a559d043e35 100644 --- a/sw/source/filter/html/svxcss1.hxx +++ b/sw/source/filter/html/svxcss1.hxx @@ -202,7 +202,8 @@ class SvxCSS1Parser : public CSS1Parser std::unique_ptr<SvxCSS1PropertyInfo> m_pSheetPropInfo; SvxCSS1PropertyInfo *m_pPropInfo; - static constexpr sal_uInt16 gnMinFixLineSpace = MM50/2; // minimum spacing for fixed line spacing + // minimum spacing for fixed line spacing + static constexpr sal_uInt16 gnMinFixLineSpace = o3tl::toTwips(25, o3tl::Length::mm10); rtl_TextEncoding m_eDefaultEnc; bool m_bIgnoreFontFamily; diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx index 3e3b693eb5a8..0a06c3fac05a 100644 --- a/sw/source/filter/html/swhtml.hxx +++ b/sw/source/filter/html/swhtml.hxx @@ -58,11 +58,11 @@ struct SwPending; class SvxCSS1PropertyInfo; struct ImplSVEvent; -#define HTML_CJK_PARSPACE (MM50/2) -#define HTML_CTL_PARSPACE (MM50/2) +constexpr tools::Long HTML_CJK_PARSPACE = o3tl::toTwips(25, o3tl::Length::mm10); // 2.5mm +constexpr tools::Long HTML_CTL_PARSPACE = o3tl::toTwips(25, o3tl::Length::mm10); // 2.5mm -#define HTML_DFLT_IMG_WIDTH (MM50*4) -#define HTML_DFLT_IMG_HEIGHT (MM50*2) +constexpr tools::Long HTML_DFLT_IMG_WIDTH = o3tl::toTwips(2, o3tl::Length::cm); // 2cm +constexpr tools::Long HTML_DFLT_IMG_HEIGHT = o3tl::toTwips(1, o3tl::Length::cm); // 1cm // some things you often need extern HTMLOptionEnum<SvxAdjust> const aHTMLPAlignTable[]; diff --git a/sw/source/filter/html/wrthtml.hxx b/sw/source/filter/html/wrthtml.hxx index 12f693a72872..fafe240182bb 100644 --- a/sw/source/filter/html/wrthtml.hxx +++ b/sw/source/filter/html/wrthtml.hxx @@ -66,7 +66,7 @@ namespace utl { class TempFile; } extern SwAttrFnTab aHTMLAttrFnTab; -#define HTML_PARSPACE (MM50) +#define HTML_PARSPACE (o3tl::toTwips(5, o3tl::Length::mm)) // flags for the output of any kind of frames // BORDER only possible if OutHTML_Image diff --git a/sw/source/ui/chrdlg/pardlg.cxx b/sw/source/ui/chrdlg/pardlg.cxx index aef94f46111a..5e66599ddb38 100644 --- a/sw/source/ui/chrdlg/pardlg.cxx +++ b/sw/source/ui/chrdlg/pardlg.cxx @@ -167,8 +167,9 @@ void SwParaDlg::PageCreated(const OString& rId, SfxTabPage& rPage) if (!bDrawParaDlg) { // See SvxStdParagraphTabPage::PageCreated: enable RegisterMode, AutoFirstLine, NegativeMode, ContextualMode + constexpr tools::Long constTwips_0_5mm = o3tl::toTwips(5, o3tl::Length::mm10); aSet.Put(SfxUInt32Item(SID_SVXSTDPARAGRAPHTABPAGE_FLAGSET,0x0002|0x0004|0x0008|0x0010)); - aSet.Put(SfxUInt32Item(SID_SVXSTDPARAGRAPHTABPAGE_ABSLINEDIST, MM50/10)); + aSet.Put(SfxUInt32Item(SID_SVXSTDPARAGRAPHTABPAGE_ABSLINEDIST, constTwips_0_5mm)); } rPage.PageCreated(aSet); diff --git a/sw/source/ui/dbui/mmlayoutpage.cxx b/sw/source/ui/dbui/mmlayoutpage.cxx index a6a32ddd76cb..df82f518e6aa 100644 --- a/sw/source/ui/dbui/mmlayoutpage.cxx +++ b/sw/source/ui/dbui/mmlayoutpage.cxx @@ -61,11 +61,11 @@ using namespace ::com::sun::star::frame; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::view; -#define DEFAULT_LEFT_DISTANCE (MM50*5) // 2,5 cm -#define DEFAULT_TOP_DISTANCE (MM50*11) // 5,5 cm -#define GREETING_TOP_DISTANCE (MM50*25) //12,5 cm -#define DEFAULT_ADDRESS_WIDTH (MM50*15)// 7,5 cm -#define DEFAULT_ADDRESS_HEIGHT (MM50*7) // 3,5cm +constexpr tools::Long DEFAULT_LEFT_DISTANCE = o3tl::toTwips(25, o3tl::Length::mm); // 2,5 cm +constexpr tools::Long DEFAULT_TOP_DISTANCE = o3tl::toTwips(55, o3tl::Length::mm); // 5,5 cm +constexpr tools::Long GREETING_TOP_DISTANCE = o3tl::toTwips(125, o3tl::Length::mm); //12,5 cm +constexpr tools::Long DEFAULT_ADDRESS_WIDTH = o3tl::toTwips(75, o3tl::Length::mm); // 7,5 cm +constexpr tools::Long DEFAULT_ADDRESS_HEIGHT = o3tl::toTwips(35, o3tl::Length::mm); // 3,5cm SwMailMergeLayoutPage::SwMailMergeLayoutPage(weld::Container* pPage, SwMailMergeWizard* pWizard) : vcl::OWizardPage(pPage, pWizard, "modules/swriter/ui/mmlayoutpage.ui", "MMLayoutPage") diff --git a/sw/source/ui/fmtui/tmpdlg.cxx b/sw/source/ui/fmtui/tmpdlg.cxx index 6e797e45a5a4..184401b134f8 100644 --- a/sw/source/ui/fmtui/tmpdlg.cxx +++ b/sw/source/ui/fmtui/tmpdlg.cxx @@ -489,7 +489,8 @@ void SwTemplateDlgController::PageCreated(const OString& rId, SfxTabPage &rPage { if( rPage.GetItemSet().GetParent() ) { - aSet.Put(SfxUInt32Item(SID_SVXSTDPARAGRAPHTABPAGE_ABSLINEDIST,MM50/10)); + constexpr tools::Long constTwips_0_5mm = o3tl::toTwips(5, o3tl::Length::mm10); + aSet.Put(SfxUInt32Item(SID_SVXSTDPARAGRAPHTABPAGE_ABSLINEDIST, constTwips_0_5mm)); aSet.Put(SfxUInt32Item(SID_SVXSTDPARAGRAPHTABPAGE_FLAGSET,0x000F)); rPage.PageCreated(aSet); } diff --git a/sw/source/ui/misc/pggrid.cxx b/sw/source/ui/misc/pggrid.cxx index 32186b8a8895..5b1b69b05b37 100644 --- a/sw/source/ui/misc/pggrid.cxx +++ b/sw/source/ui/misc/pggrid.cxx @@ -35,11 +35,13 @@ #include <swmodule.hxx> #include <view.hxx> +constexpr tools::Long constTwips_5mm = o3tl::toTwips(5, o3tl::Length::mm); + SwTextGridPage::SwTextGridPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet &rSet) : SfxTabPage(pPage, pController, "modules/swriter/ui/textgridpage.ui", "TextGridPage", &rSet) , m_nRubyUserValue(0) , m_bRubyUserValue(false) - , m_aPageSize(MM50, MM50) + , m_aPageSize(constTwips_5mm, constTwips_5mm) , m_bVertical(false) , m_bSquaredMode(false) , m_bHRulerChanged(false) diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx index bae05b03ac66..3dd384b64c9c 100644 --- a/sw/source/uibase/dochdl/swdtflvr.cxx +++ b/sw/source/uibase/dochdl/swdtflvr.cxx @@ -134,7 +134,10 @@ #include <memory> -#define OLESIZE 11905 - 2 * lMinBorder, 6 * MM50 +constexpr tools::Long constOleWidth = 11905 - 2 * lMinBorder; +constexpr tools::Long constOleHeight = o3tl::toTwips(3, o3tl::Length::cm); + +#define OLESIZE constOleWidth, constOleHeight constexpr sal_uInt32 SWTRANSFER_OBJECTTYPE_DRAWMODEL = 0x00000001; constexpr sal_uInt32 SWTRANSFER_OBJECTTYPE_HTML = 0x00000002; diff --git a/sw/source/uibase/inc/frmmgr.hxx b/sw/source/uibase/inc/frmmgr.hxx index 27ebc70a66d3..92e23853f139 100644 --- a/sw/source/uibase/inc/frmmgr.hxx +++ b/sw/source/uibase/inc/frmmgr.hxx @@ -35,8 +35,8 @@ struct SwPosition; class SwFormatCol; class SvGlobalName; -const SwTwips DFLT_WIDTH = MM50 * 4; -const SwTwips DFLT_HEIGHT = MM50; +constexpr SwTwips DFLT_WIDTH = o3tl::toTwips(20, o3tl::Length::mm); +constexpr SwTwips DFLT_HEIGHT = o3tl::toTwips(5, o3tl::Length::mm); enum class Frmmgr_Type { diff --git a/sw/source/uibase/ribbar/conform.cxx b/sw/source/uibase/ribbar/conform.cxx index f51e9123ca40..25cb8570d391 100644 --- a/sw/source/uibase/ribbar/conform.cxx +++ b/sw/source/uibase/ribbar/conform.cxx @@ -89,12 +89,15 @@ void ConstFormControl::Activate(const sal_uInt16 nSlotId) void ConstFormControl::CreateDefaultObject() { + constexpr tools::Long constTwips_5mm = o3tl::toTwips(5, o3tl::Length::mm); + constexpr tools::Long constTwips_10mm = o3tl::toTwips(10, o3tl::Length::mm); + Point aStartPos(GetDefaultCenterPos()); Point aEndPos(aStartPos); - aStartPos.AdjustX(-(2 * MM50)); - aStartPos.AdjustY(-MM50); - aEndPos.AdjustX(2 * MM50); - aEndPos.AdjustY(MM50); + aStartPos.AdjustX(-constTwips_10mm); + aStartPos.AdjustY(-constTwips_5mm); + aEndPos.AdjustX(constTwips_10mm); + aEndPos.AdjustY(constTwips_5mm); if(!m_pSh->HasDrawView()) m_pSh->MakeDrawView(); diff --git a/sw/source/uibase/ribbar/drawbase.cxx b/sw/source/uibase/ribbar/drawbase.cxx index b1ee706dfa5d..a5607aba014e 100644 --- a/sw/source/uibase/ribbar/drawbase.cxx +++ b/sw/source/uibase/ribbar/drawbase.cxx @@ -511,12 +511,14 @@ void SwDrawBase::EnterSelectMode(const MouseEvent& rMEvt) void SwDrawBase::CreateDefaultObject() { + constexpr tools::Long constTwips_3cm = o3tl::toTwips(3, o3tl::Length::cm); + Point aStartPos = GetDefaultCenterPos(); Point aEndPos(aStartPos); - aStartPos.AdjustX( -(6 * MM50) ); - aStartPos.AdjustY( -(6 * MM50) ); - aEndPos.AdjustX(6 * MM50 ); - aEndPos.AdjustY(6 * MM50 ); + aStartPos.AdjustX(-constTwips_3cm); + aStartPos.AdjustY(-constTwips_3cm); + aEndPos.AdjustX(constTwips_3cm); + aEndPos.AdjustY(constTwips_3cm); tools::Rectangle aRect(aStartPos, aEndPos); m_pSh->CreateDefaultShape(m_pWin->GetSdrDrawMode(), aRect, m_nSlotId); } diff --git a/sw/source/uibase/shells/textsh.cxx b/sw/source/uibase/shells/textsh.cxx index af3fc2e21494..114ce385e4d3 100644 --- a/sw/source/uibase/shells/textsh.cxx +++ b/sw/source/uibase/shells/textsh.cxx @@ -399,9 +399,11 @@ void SwTextShell::ExecInsert(SfxRequest &rReq) Size aWinSize = rEdtWin.GetSizePixel(); Point aStartPos(aWinSize.Width()/2, aWinSize.Height() / 2); aStartPos = rEdtWin.PixelToLogic(aStartPos); - aStartPos.AdjustX( -(8 * MM50) ); - aStartPos.AdjustY( -(4 * MM50) ); - Size aSize(16 * MM50, 8 * MM50); + constexpr tools::Long constTwips_2cm = o3tl::toTwips(2, o3tl::Length::cm); + constexpr tools::Long constTwips_4cm = o3tl::toTwips(4, o3tl::Length::cm); + aStartPos.AdjustX(-constTwips_4cm); + aStartPos.AdjustY(-constTwips_2cm); + Size aSize(2 * constTwips_4cm, 2 * constTwips_2cm); GetShell().LockPaint(); GetShell().StartAllAction(); SwFlyFrameAttrMgr aMgr( true, GetShellPtr(), Frmmgr_Type::TEXT, nullptr ); diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx index 41f71cd26462..d0ca5fa4b4a8 100644 --- a/sw/source/uibase/wrtsh/wrtsh1.cxx +++ b/sw/source/uibase/wrtsh/wrtsh1.cxx @@ -1896,7 +1896,8 @@ void SwWrtShell::ChangeHeaderOrFooter( rMaster.SetFormatAttr( SwFormatFooter( bOn )); if( bOn ) { - SvxULSpaceItem aUL(bHeader ? 0 : MM50, bHeader ? MM50 : 0, RES_UL_SPACE ); + constexpr tools::Long constTwips_5mm = o3tl::toTwips(5, o3tl::Length::mm); + SvxULSpaceItem aUL(bHeader ? 0 : constTwips_5mm, bHeader ? constTwips_5mm : 0, RES_UL_SPACE ); SwFrameFormat* pFormat = bHeader ? const_cast<SwFrameFormat*>(rMaster.GetHeader().GetHeaderFormat()) : const_cast<SwFrameFormat*>(rMaster.GetFooter().GetFooterFormat()); |