diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2017-06-16 09:58:13 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2017-06-16 17:28:41 +0200 |
commit | 13bb5a4b09f5b2ad19dad1b55f45d0fe2b2fb908 (patch) | |
tree | d38ad18688a292ff6ccdfaa7c51080197ec95934 /svx/source/dialog | |
parent | f83d8ae84584c0967e2346566d21d65d6d7a432f (diff) |
Make SfxItemSet ranges correct by construction
This is a follow-up to 45a7f5b62d0b1b21763c1c94255ef2309ea4280b "Keep WID ranges
sorted, and join adjacent ones". While SfxItemSet::MergeRange relies on the
m_pWhichRanges being sorted (and, under DBG_UTIL, asserts if they are not), the
various SfxItemSet constructors curiously only check (via assert or DBG_ASSERT)
that each individual range has an upper bound not smaller than its lower bound.
Arguably, all SfxItemSet instances should fulfill the stronger guarantees
required and checked by MergeRange.
And in many cases the ranges are statically known, so that the checking can
happen at compile time. Therefore, replace the two SfxItemSet ctors taking
explicit ranges with two other ctors that actually do proper checking. The
(templated) overload taking an svl::Items struct should be used in all cases
where the range values are statically known at compile time, while the overload
taking a std::initializer_list<Pair> is for the remaining cases (that can only
do runtime checking via assert). Most of those latter cases are simple cases
with a single range covering a single item, but a few are more complex.
(At least some of the uses of the existing SfxItemSet overload taking a
const sal_uInt16* pWhichPairTable
can probably also be strengthened, but that is left for another day.)
This commit is the first in a series of two. Apart from the manual changes to
compilerplugins/clang/store/sfxitemsetrewrite.cxx, include/svl/itemset.hxx, and
svl/source/items/itemset.cxx, it only consists of automatic rewriting of the
relevant SfxItemSet ctor calls (plus a few required manual fixes, see next).
But it does not yet check that the individual ranges are properly sorted (see
the TODO in svl::detail::validGap). That check will be enabled, and the ensuing
manual fixes will be made in a follow-up commit, to reduce the likelyhood of
accidents.
There were three cases of necessary manual intervention:
* sw/source/core/unocore/unostyle.cxx uses eAtr of enum type RES_FRMATR in
braced-init-list syntax now, so needs explicit narrowing conversion to
sal_uInt16.
* In sw/source/uibase/uiview/formatclipboard.cxx, the trailiing comma in the
definition of macro FORMAT_PAINTBRUSH_FRAME_IDS needed to be removed manually.
* In svx/source/svdraw/svdoashp.cxx, svx/source/svdraw/svdotext.cxx,
sw/source/uibase/app/docstyle.cxx, sw/source/uibase/shells/frmsh.cxx,
sw/source/uibase/shells/grfsh.cxx, and sw/source/uibase/shells/textsh1.cxx,
some comments had to be put back (see "TODO: the replaced range can contain
relevant comments" in compilerplugins/clang/store/sfxitemsetrewrite.cxx).
A few uses of the variadic form erroneously used nullptr instead of 0 for
termination. But this should have been harmless even if promoted std::nullptr_t
is larger than promoted sal_uInt16, assuming that the part of the nullptr value
that was interpreted as sal_uInt16/promoted int was all-zero bits. Similarly,
some uses made the harmless error of using 0L instead of 0.
Change-Id: I2afea97282803cb311b9321a99bb627520ef5e35
Reviewed-on: https://gerrit.libreoffice.org/38861
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Tested-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'svx/source/dialog')
-rw-r--r-- | svx/source/dialog/databaseregistrationui.cxx | 2 | ||||
-rw-r--r-- | svx/source/dialog/dlgctl3d.cxx | 7 | ||||
-rw-r--r-- | svx/source/dialog/hdft.cxx | 28 | ||||
-rw-r--r-- | svx/source/dialog/imapwnd.cxx | 2 |
4 files changed, 18 insertions, 21 deletions
diff --git a/svx/source/dialog/databaseregistrationui.cxx b/svx/source/dialog/databaseregistrationui.cxx index 4827a7580361..68c8ffa6bf7c 100644 --- a/svx/source/dialog/databaseregistrationui.cxx +++ b/svx/source/dialog/databaseregistrationui.cxx @@ -33,7 +33,7 @@ namespace svx { sal_uInt16 nResult = RET_CANCEL; - SfxItemSet aRegistrationItems( SfxGetpApp()->GetPool(), SID_SB_DB_REGISTER, SID_SB_DB_REGISTER, 0 ); + SfxItemSet aRegistrationItems( SfxGetpApp()->GetPool(), svl::Items<SID_SB_DB_REGISTER, SID_SB_DB_REGISTER>{} ); SvxAbstractDialogFactory* pDialogFactory = SvxAbstractDialogFactory::Create(); ScopedVclPtr<SfxAbstractDialog> pDialog; diff --git a/svx/source/dialog/dlgctl3d.cxx b/svx/source/dialog/dlgctl3d.cxx index 17952278e00d..0fe4c3535fbd 100644 --- a/svx/source/dialog/dlgctl3d.cxx +++ b/svx/source/dialog/dlgctl3d.cxx @@ -131,9 +131,8 @@ void Svx3DPreviewControl::Construct() mpScene->SetRectsDirty(); SfxItemSet aSet( mpModel->GetItemPool(), - XATTR_LINESTYLE, XATTR_LINESTYLE, - XATTR_FILL_FIRST, XATTR_FILLBITMAP, - 0, 0 ); + svl::Items<XATTR_LINESTYLE, XATTR_LINESTYLE, + XATTR_FILL_FIRST, XATTR_FILLBITMAP>{} ); aSet.Put( XLineStyleItem( drawing::LineStyle_NONE ) ); aSet.Put( XFillStyleItem( drawing::FillStyle_SOLID ) ); aSet.Put( XFillColorItem( "", Color( COL_WHITE ) ) ); @@ -189,7 +188,7 @@ void Svx3DPreviewControl::SetObjectType(SvxPreviewObjectType nType) { if( mnObjectType != nType || !mp3DObj) { - SfxItemSet aSet(mpModel->GetItemPool(), SDRATTR_START, SDRATTR_END, 0, 0); + SfxItemSet aSet(mpModel->GetItemPool(), svl::Items<SDRATTR_START, SDRATTR_END>{}); mnObjectType = nType; if( mp3DObj ) diff --git a/svx/source/dialog/hdft.cxx b/svx/source/dialog/hdft.cxx index 044a1d9f7ddc..6a4d0bb2ece3 100644 --- a/svx/source/dialog/hdft.cxx +++ b/svx/source/dialog/hdft.cxx @@ -599,12 +599,11 @@ IMPL_LINK_NOARG(SvxHFPage, BackgroundHdl, Button*, void) { pBBSet = new SfxItemSet( *GetItemSet().GetPool(), - XATTR_FILL_FIRST, XATTR_FILL_LAST, // DrawingLayer FillStyle definitions - SID_COLOR_TABLE, SID_PATTERN_LIST, // XPropertyLists for Color, Gradient, Hatch and Graphic fills - nOuter, nOuter, - nInner, nInner, - nShadow, nShadow, - 0, 0); + {{XATTR_FILL_FIRST, XATTR_FILL_LAST}, // DrawingLayer FillStyle definitions + {SID_COLOR_TABLE, SID_PATTERN_LIST}, // XPropertyLists for Color, Gradient, Hatch and Graphic fills + {nOuter, nOuter}, + {nInner, nInner}, + {nShadow, nShadow}}); // copy items for XPropertyList entries from the DrawModel so that // the Area TabPage can access them @@ -637,11 +636,10 @@ IMPL_LINK_NOARG(SvxHFPage, BackgroundHdl, Button*, void) pBBSet = new SfxItemSet( *GetItemSet().GetPool(), - nBrush, nBrush, - nOuter, nOuter, - nInner, nInner, - nShadow, nShadow, - 0, 0); + {{nBrush, nBrush}, + {nOuter, nOuter}, + {nInner, nInner}, + {nShadow, nShadow}}); } const SfxPoolItem* pItem; @@ -713,7 +711,7 @@ IMPL_LINK_NOARG(SvxHFPage, BackgroundHdl, Button*, void) { // create FillAttributes from SvxBrushItem const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(pBBSet->Get(nWhich)); - SfxItemSet aTempSet(*pBBSet->GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST); + SfxItemSet aTempSet(*pBBSet->GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{}); setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet); aFillAttributes.reset(new drawinglayer::attribute::SdrAllFillAttributesHelper(aTempSet)); @@ -800,7 +798,7 @@ void SvxHFPage::ResetBackground_Impl( const SfxItemSet& rSet ) { // create FillAttributes from SvxBrushItem const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(rTmpSet.Get(nWhich)); - SfxItemSet aTempSet(*rTmpSet.GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST); + SfxItemSet aTempSet(*rTmpSet.GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{}); setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet); aHeaderFillAttributes.reset(new drawinglayer::attribute::SdrAllFillAttributesHelper(aTempSet)); @@ -844,7 +842,7 @@ void SvxHFPage::ResetBackground_Impl( const SfxItemSet& rSet ) { // create FillAttributes from SvxBrushItem const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(rTmpSet.Get(nWhich)); - SfxItemSet aTempSet(*rTmpSet.GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST); + SfxItemSet aTempSet(*rTmpSet.GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{}); setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet); aFooterFillAttributes.reset(new drawinglayer::attribute::SdrAllFillAttributesHelper(aTempSet)); @@ -877,7 +875,7 @@ void SvxHFPage::ResetBackground_Impl( const SfxItemSet& rSet ) { // create FillAttributes from SvxBrushItem const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(rSet.Get(nWhich)); - SfxItemSet aTempSet(*rSet.GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST); + SfxItemSet aTempSet(*rSet.GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{}); setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet); aPageFillAttributes.reset(new drawinglayer::attribute::SdrAllFillAttributesHelper(aTempSet)); diff --git a/svx/source/dialog/imapwnd.cxx b/svx/source/dialog/imapwnd.cxx index 44534a92627d..8b7456d585a9 100644 --- a/svx/source/dialog/imapwnd.cxx +++ b/svx/source/dialog/imapwnd.cxx @@ -635,7 +635,7 @@ void IMapWindow::DoMacroAssign() if ( pSdrObj ) { - SfxItemSet aSet( *pIMapPool, SID_ATTR_MACROITEM, SID_ATTR_MACROITEM, SID_EVENTCONFIG, SID_EVENTCONFIG, 0 ); + SfxItemSet aSet( *pIMapPool, svl::Items<SID_ATTR_MACROITEM, SID_ATTR_MACROITEM, SID_EVENTCONFIG, SID_EVENTCONFIG>{} ); SfxEventNamesItem aNamesItem(SID_EVENTCONFIG); aNamesItem.AddEvent( "MouseOver", "", SFX_EVENT_MOUSEOVER_OBJECT ); |