summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-06-11 12:07:44 +0200
committerMike Kaganski <mike.kaganski@collabora.com>2021-06-13 19:23:28 +0200
commit8aaa28ed43978a9a4a20d62368410a57ec05c23f (patch)
tree16706bd93e2af74db7220a099a1391bf7cdd1bd4 /svx
parentf7c7e4c63f5479de66d2fbed9db34972a5bd05aa (diff)
Assert on valid order of which ids in ranges on SfxItemSet creation
This allows to make sure we actually use sorted which ranges, and then it's safe to call SfxItemSet::MergeRange when needed. Also this change relaxes the previous requirement that ranges must be separated by at least one; this allows to have adjacent ranges, like in RES_FRMATR_BEGIN, RES_FRMATR_END-1, RES_GRFATR_BEGIN, RES_GRFATR_END-1, where RES_FRMATR_END is equal to RES_GRFATR_BEGIN. Allowing this makes possible to (1) self-document the ranges, so it's clear which ranges are included; and (2) be safe in case when these constants would change, so that the one merged range would not unexpectedly contain everything inserted between RES_FRMATR_END and RES_GRFATR_BEGIN. Change-Id: Iaad0f099b85059b3aa318a347aa7fbd3f6d455c7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116909 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/dialog/hdft.cxx57
-rw-r--r--svx/source/svdraw/svdedxv.cxx34
2 files changed, 42 insertions, 49 deletions
diff --git a/svx/source/dialog/hdft.cxx b/svx/source/dialog/hdft.cxx
index 1189cab8ae55..0cd7e9102abd 100644
--- a/svx/source/dialog/hdft.cxx
+++ b/svx/source/dialog/hdft.cxx
@@ -202,30 +202,25 @@ bool SvxHFPage::FillItemSet( SfxItemSet* rSet )
const sal_uInt16 nWBoxInfo = GetWhich(SID_ATTR_BORDER_INNER);
const sal_uInt16 nWShadow = GetWhich(SID_ATTR_BORDER_SHADOW);
- const sal_uInt16 aWhichTab[] = {
- nWSize, nWSize,
- nWLRSpace, nWLRSpace,
- nWULSpace, nWULSpace,
- nWOn, nWOn,
- nWDynamic, nWDynamic,
- nWShared, nWShared,
- nWSharedFirst, nWSharedFirst,
- nWBrush, nWBrush,
- nWBoxInfo, nWBoxInfo,
- nWBox, nWBox,
- nWShadow, nWShadow,
- nWDynSpacing, nWDynSpacing,
-
- // take over DrawingLayer FillStyles
- XATTR_FILL_FIRST, XATTR_FILL_LAST, // [1014
-
- 0, 0};
-
const SfxItemSet& rOldSet = GetItemSet();
SfxItemPool* pPool = rOldSet.GetPool();
DBG_ASSERT(pPool,"no pool :-(");
MapUnit eUnit = pPool->GetMetric(nWSize);
- SfxItemSet aSet(*pPool,aWhichTab);
+ // take over DrawingLayer FillStyles
+ SfxItemSet aSet(*pPool, svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{});
+ // Keep it valid
+ aSet.MergeRange(nWSize, nWSize);
+ aSet.MergeRange(nWLRSpace, nWLRSpace);
+ aSet.MergeRange(nWULSpace, nWULSpace);
+ aSet.MergeRange(nWOn, nWOn);
+ aSet.MergeRange(nWDynamic, nWDynamic);
+ aSet.MergeRange(nWShared, nWShared);
+ aSet.MergeRange(nWSharedFirst, nWSharedFirst);
+ aSet.MergeRange(nWBrush, nWBrush);
+ aSet.MergeRange(nWBoxInfo, nWBoxInfo);
+ aSet.MergeRange(nWBox, nWBox);
+ aSet.MergeRange(nWShadow, nWShadow);
+ aSet.MergeRange(nWDynSpacing, nWDynSpacing);
if(mbEnableDrawingLayerFillStyles)
{
@@ -540,11 +535,12 @@ IMPL_LINK_NOARG(SvxHFPage, BackgroundHdl, weld::Button&, void)
{
pBBSet.reset(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}}));
+ svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST, // DrawingLayer FillStyle definitions
+ SID_COLOR_TABLE, SID_PATTERN_LIST>{})); // XPropertyLists for Color, Gradient, Hatch and Graphic fills
+ // Keep it valid
+ pBBSet->MergeRange(nOuter, nOuter);
+ pBBSet->MergeRange(nInner, nInner);
+ pBBSet->MergeRange(nShadow, nShadow);
// copy items for XPropertyList entries from the DrawModel so that
// the Area TabPage can access them
@@ -577,11 +573,12 @@ IMPL_LINK_NOARG(SvxHFPage, BackgroundHdl, weld::Button&, void)
pBBSet.reset( new SfxItemSet(
*GetItemSet().GetPool(),
- {{XATTR_FILL_FIRST, XATTR_FILL_LAST},
- {nBrush, nBrush},
- {nOuter, nOuter},
- {nInner, nInner},
- {nShadow, nShadow}}) );
+ svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{}) );
+ // Keep it valid
+ pBBSet->MergeRange(nBrush, nBrush);
+ pBBSet->MergeRange(nOuter, nOuter);
+ pBBSet->MergeRange(nInner, nInner);
+ pBBSet->MergeRange(nShadow, nShadow);
}
const SfxPoolItem* pItem;
diff --git a/svx/source/svdraw/svdedxv.cxx b/svx/source/svdraw/svdedxv.cxx
index a8da538afbb4..50ac7499ee85 100644
--- a/svx/source/svdraw/svdedxv.cxx
+++ b/svx/source/svdraw/svdedxv.cxx
@@ -2628,25 +2628,21 @@ bool SdrObjEditView::SupportsFormatPaintbrush(SdrInventor nObjectInventor,
static const sal_uInt16* GetFormatRangeImpl(bool bTextOnly)
{
- static const sal_uInt16 gRanges[] = { SDRATTR_SHADOW_FIRST,
- SDRATTR_SHADOW_LAST,
- SDRATTR_GRAF_FIRST,
- SDRATTR_GRAF_LAST,
- SDRATTR_TABLE_FIRST,
- SDRATTR_TABLE_LAST,
- XATTR_LINE_FIRST,
- XATTR_LINE_LAST,
- XATTR_FILL_FIRST,
- XATTRSET_FILL,
- EE_PARA_START,
- EE_PARA_END, // text-only from here on
- EE_CHAR_START,
- EE_CHAR_END,
- SDRATTR_MISC_FIRST,
- SDRATTR_MISC_LAST, // table cell formats
- 0,
- 0 };
- return &gRanges[bTextOnly ? 10 : 0];
+ static constexpr auto gFull
+ = svl::ItemsArray({ { XATTR_LINE_FIRST, XATTR_LINE_LAST },
+ { XATTR_FILL_FIRST, XATTRSET_FILL },
+ { SDRATTR_SHADOW_FIRST, SDRATTR_SHADOW_LAST },
+ { SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST }, // table cell formats
+ { SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST },
+ { SDRATTR_TABLE_FIRST, SDRATTR_TABLE_LAST },
+ { EE_PARA_START, EE_PARA_END },
+ { EE_CHAR_START, EE_CHAR_END } });
+
+ static constexpr auto gTextOnly = svl::ItemsArray({ { SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST },
+ { EE_PARA_START, EE_PARA_END },
+ { EE_CHAR_START, EE_CHAR_END } });
+
+ return bTextOnly ? gTextOnly.data() : gFull.data();
}
void SdrObjEditView::TakeFormatPaintBrush(std::shared_ptr<SfxItemSet>& rFormatSet)