summaryrefslogtreecommitdiff
path: root/cui
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-06-16 09:58:13 +0200
committerStephan Bergmann <sbergman@redhat.com>2017-06-16 17:28:41 +0200
commit13bb5a4b09f5b2ad19dad1b55f45d0fe2b2fb908 (patch)
treed38ad18688a292ff6ccdfaa7c51080197ec95934 /cui
parentf83d8ae84584c0967e2346566d21d65d6d7a432f (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 'cui')
-rw-r--r--cui/source/dialogs/cuihyperdlg.cxx8
-rw-r--r--cui/source/dialogs/hltpbase.cxx4
-rw-r--r--cui/source/factory/dlgfact.cxx2
-rw-r--r--cui/source/options/treeopt.cxx29
-rw-r--r--cui/source/tabpages/bbdlg.cxx5
-rw-r--r--cui/source/tabpages/page.cxx10
6 files changed, 26 insertions, 32 deletions
diff --git a/cui/source/dialogs/cuihyperdlg.cxx b/cui/source/dialogs/cuihyperdlg.cxx
index eb8e9515b759..c5bd7a669c99 100644
--- a/cui/source/dialogs/cuihyperdlg.cxx
+++ b/cui/source/dialogs/cuihyperdlg.cxx
@@ -118,8 +118,8 @@ SvxHpLinkDlg::SvxHpLinkDlg (vcl::Window* pParent, SfxBindings* pBindings)
GetCancelButton().SetText ( CuiResId(RID_SVXSTR_HYPDLG_CLOSEBUT) );
// create itemset for tabpages
- mpItemSet = o3tl::make_unique<SfxItemSet>( SfxGetpApp()->GetPool(), SID_HYPERLINK_GETLINK,
- SID_HYPERLINK_SETLINK );
+ mpItemSet = o3tl::make_unique<SfxItemSet>( SfxGetpApp()->GetPool(), svl::Items<SID_HYPERLINK_GETLINK,
+ SID_HYPERLINK_SETLINK>{} );
SvxHyperlinkItem aItem(SID_HYPERLINK_GETLINK);
mpItemSet->Put(aItem);
@@ -191,8 +191,8 @@ bool SvxHpLinkDlg::Close()
void SvxHpLinkDlg::Apply()
{
- SfxItemSet aItemSet( SfxGetpApp()->GetPool(), SID_HYPERLINK_GETLINK,
- SID_HYPERLINK_SETLINK );
+ SfxItemSet aItemSet( SfxGetpApp()->GetPool(), svl::Items<SID_HYPERLINK_GETLINK,
+ SID_HYPERLINK_SETLINK>{} );
SvxHyperlinkTabPageBase* pCurrentPage = static_cast<SvxHyperlinkTabPageBase*>(
GetTabPage( GetCurPageId() ) );
diff --git a/cui/source/dialogs/hltpbase.cxx b/cui/source/dialogs/hltpbase.cxx
index 9c6d5c10f073..2a8fcbbf763b 100644
--- a/cui/source/dialogs/hltpbase.cxx
+++ b/cui/source/dialogs/hltpbase.cxx
@@ -323,8 +323,8 @@ IMPL_LINK_NOARG(SvxHyperlinkTabPageBase, ClickScriptHdl_Impl, Button*, void)
// create empty itemset for macro-dlg
std::unique_ptr<SfxItemSet> pItemSet( new SfxItemSet(SfxGetpApp()->GetPool(),
- SID_ATTR_MACROITEM,
- SID_ATTR_MACROITEM ) );
+ svl::Items<SID_ATTR_MACROITEM,
+ SID_ATTR_MACROITEM>{} ) );
pItemSet->Put ( aItem );
/* disable HyperLinkDlg for input while the MacroAssignDlg is working
diff --git a/cui/source/factory/dlgfact.cxx b/cui/source/factory/dlgfact.cxx
index a6e5d5f68004..4d07d9f9e5f8 100644
--- a/cui/source/factory/dlgfact.cxx
+++ b/cui/source/factory/dlgfact.cxx
@@ -1285,7 +1285,7 @@ class SvxMacroAssignDialog : public VclAbstractDialog
public:
SvxMacroAssignDialog( vcl::Window* _pParent, const Reference< XFrame >& _rxDocumentFrame, const bool _bUnoDialogMode,
const Reference< XNameReplace >& _rxEvents, const sal_uInt16 _nInitiallySelectedEvent )
- :m_aItems( SfxGetpApp()->GetPool(), SID_ATTR_MACROITEM, SID_ATTR_MACROITEM )
+ :m_aItems( SfxGetpApp()->GetPool(), svl::Items<SID_ATTR_MACROITEM, SID_ATTR_MACROITEM>{} )
{
m_aItems.Put( SfxBoolItem( SID_ATTR_MACROITEM, _bUnoDialogMode ) );
m_pDialog.reset( VclPtr<SvxMacroAssignDlg>::Create( _pParent, _rxDocumentFrame, m_aItems, _rxEvents, _nInitiallySelectedEvent ) );
diff --git a/cui/source/options/treeopt.cxx b/cui/source/options/treeopt.cxx
index 72721304337b..b82a2a948442 100644
--- a/cui/source/options/treeopt.cxx
+++ b/cui/source/options/treeopt.cxx
@@ -1124,14 +1124,13 @@ std::unique_ptr<SfxItemSet> OfaTreeOptionsDialog::CreateItemSet( sal_uInt16 nId
{
pRet = o3tl::make_unique<SfxItemSet>(
SfxGetpApp()->GetPool(),
- SID_ATTR_METRIC, SID_ATTR_SPELL,
+ svl::Items<SID_ATTR_METRIC, SID_ATTR_SPELL,
SID_AUTOSPELL_CHECK, SID_AUTOSPELL_CHECK,
SID_ATTR_QUICKLAUNCHER, SID_ATTR_QUICKLAUNCHER,
SID_ATTR_YEAR2000, SID_ATTR_YEAR2000,
- SID_HTML_MODE, SID_HTML_MODE,
- 0 );
+ SID_HTML_MODE, SID_HTML_MODE>{} );
- SfxItemSet aOptSet( SfxGetpApp()->GetPool(), SID_ATTR_QUICKLAUNCHER, SID_ATTR_QUICKLAUNCHER );
+ SfxItemSet aOptSet( SfxGetpApp()->GetPool(), svl::Items<SID_ATTR_QUICKLAUNCHER, SID_ATTR_QUICKLAUNCHER>{} );
SfxGetpApp()->GetOptions(aOptSet);
pRet->Put(aOptSet);
@@ -1164,11 +1163,10 @@ std::unique_ptr<SfxItemSet> OfaTreeOptionsDialog::CreateItemSet( sal_uInt16 nId
case SID_LANGUAGE_OPTIONS :
{
pRet = o3tl::make_unique<SfxItemSet>(SfxGetpApp()->GetPool(),
- SID_ATTR_LANGUAGE, SID_AUTOSPELL_CHECK,
+ svl::Items<SID_ATTR_LANGUAGE, SID_AUTOSPELL_CHECK,
SID_ATTR_CHAR_CJK_LANGUAGE, SID_ATTR_CHAR_CTL_LANGUAGE,
SID_OPT_LOCALE_CHANGED, SID_OPT_LOCALE_CHANGED,
- SID_SET_DOCUMENT_LANGUAGE, SID_SET_DOCUMENT_LANGUAGE,
- 0 );
+ SID_SET_DOCUMENT_LANGUAGE, SID_SET_DOCUMENT_LANGUAGE>{} );
// for linguistic
@@ -1233,28 +1231,25 @@ std::unique_ptr<SfxItemSet> OfaTreeOptionsDialog::CreateItemSet( sal_uInt16 nId
break;
case SID_INET_DLG :
pRet = o3tl::make_unique<SfxItemSet>( SfxGetpApp()->GetPool(),
- SID_BASIC_ENABLED, SID_BASIC_ENABLED,
+ svl::Items<SID_BASIC_ENABLED, SID_BASIC_ENABLED,
//SID_OPTIONS_START - ..END
SID_SAVEREL_INET, SID_SAVEREL_FSYS,
SID_INET_NOPROXY, SID_INET_FTP_PROXY_PORT,
- SID_SECURE_URL, SID_SECURE_URL,
- 0L );
+ SID_SECURE_URL, SID_SECURE_URL>{} );
SfxGetpApp()->GetOptions(*pRet);
break;
case SID_FILTER_DLG:
pRet = o3tl::make_unique<SfxItemSet>( SfxGetpApp()->GetPool(),
- SID_ATTR_DOCINFO, SID_ATTR_AUTOSAVEMINUTE,
+ svl::Items<SID_ATTR_DOCINFO, SID_ATTR_AUTOSAVEMINUTE,
SID_SAVEREL_INET, SID_SAVEREL_FSYS,
SID_ATTR_PRETTYPRINTING, SID_ATTR_PRETTYPRINTING,
- SID_ATTR_WARNALIENFORMAT, SID_ATTR_WARNALIENFORMAT,
- 0 );
+ SID_ATTR_WARNALIENFORMAT, SID_ATTR_WARNALIENFORMAT>{} );
SfxGetpApp()->GetOptions(*pRet);
break;
case SID_SB_STARBASEOPTIONS:
pRet = o3tl::make_unique<SfxItemSet>( SfxGetpApp()->GetPool(),
- SID_SB_POOLING_ENABLED, SID_SB_DB_REGISTER,
- 0 );
+ svl::Items<SID_SB_POOLING_ENABLED, SID_SB_DB_REGISTER>{} );
::offapp::ConnectionPoolConfig::GetOptions(*pRet);
svx::DbRegisteredNamesConfig::GetOptions(*pRet);
break;
@@ -1262,7 +1257,7 @@ std::unique_ptr<SfxItemSet> OfaTreeOptionsDialog::CreateItemSet( sal_uInt16 nId
case SID_SCH_EDITOPTIONS:
{
SvxChartOptions aChartOpt;
- pRet = o3tl::make_unique<SfxItemSet>( SfxGetpApp()->GetPool(), SID_SCH_EDITOPTIONS, SID_SCH_EDITOPTIONS );
+ pRet = o3tl::make_unique<SfxItemSet>( SfxGetpApp()->GetPool(), svl::Items<SID_SCH_EDITOPTIONS, SID_SCH_EDITOPTIONS>{} );
pRet->Put( SvxChartColorTableItem( SID_SCH_EDITOPTIONS, aChartOpt.GetDefaultColors() ) );
break;
}
@@ -1278,7 +1273,7 @@ void OfaTreeOptionsDialog::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet
{
utl::MiscCfg aMisc;
const SfxPoolItem* pItem = nullptr;
- SfxItemSet aOptSet(SfxGetpApp()->GetPool(), SID_ATTR_QUICKLAUNCHER, SID_ATTR_QUICKLAUNCHER );
+ SfxItemSet aOptSet(SfxGetpApp()->GetPool(), svl::Items<SID_ATTR_QUICKLAUNCHER, SID_ATTR_QUICKLAUNCHER>{} );
aOptSet.Put(rSet);
if(aOptSet.Count())
SfxGetpApp()->SetOptions( aOptSet );
diff --git a/cui/source/tabpages/bbdlg.cxx b/cui/source/tabpages/bbdlg.cxx
index 0cef97d9ce1b..114f7dd28269 100644
--- a/cui/source/tabpages/bbdlg.cxx
+++ b/cui/source/tabpages/bbdlg.cxx
@@ -74,9 +74,8 @@ void SvxBorderBackgroundDlg::PageCreated( sal_uInt16 nPageId, SfxTabPage& rTabPa
{
SfxItemSet aNew(
*GetInputSetImpl()->GetPool(),
- SID_COLOR_TABLE, SID_BITMAP_LIST,
- SID_OFFER_IMPORT, SID_OFFER_IMPORT,
- 0, 0);
+ svl::Items<SID_COLOR_TABLE, SID_BITMAP_LIST,
+ SID_OFFER_IMPORT, SID_OFFER_IMPORT>{});
aNew.Put(*GetInputSetImpl());
diff --git a/cui/source/tabpages/page.cxx b/cui/source/tabpages/page.cxx
index 16100cc46413..437cdb41a0e5 100644
--- a/cui/source/tabpages/page.cxx
+++ b/cui/source/tabpages/page.cxx
@@ -1155,7 +1155,7 @@ void SvxPageDescPage::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));
@@ -1199,7 +1199,7 @@ void SvxPageDescPage::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));
@@ -1233,7 +1233,7 @@ void SvxPageDescPage::ResetBackground_Impl(const SfxItemSet& rSet)
{
// create FillAttributes from SvxBrushItem
const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(*pItem);
- 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));
@@ -1303,7 +1303,7 @@ void SvxPageDescPage::InitHeadFoot_Impl( const SfxItemSet& rSet )
{
// aBspWin.SetHdColor(rItem.GetColor());
const SvxBrushItem& rItem = static_cast< const SvxBrushItem& >(rHeaderSet.Get(nWhich));
- SfxItemSet aTempSet(*rHeaderSet.GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST);
+ SfxItemSet aTempSet(*rHeaderSet.GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{});
setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
aHeaderFillAttributes.reset(new drawinglayer::attribute::SdrAllFillAttributesHelper(aTempSet));
@@ -1365,7 +1365,7 @@ void SvxPageDescPage::InitHeadFoot_Impl( const SfxItemSet& rSet )
{
// aBspWin.SetFtColor(rItem.GetColor());
const SvxBrushItem& rItem = static_cast<const SvxBrushItem&>(rFooterSet.Get(nWhich));
- SfxItemSet aTempSet(*rFooterSet.GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST);
+ SfxItemSet aTempSet(*rFooterSet.GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{});
setSvxBrushItemAsFillAttributesToTargetSet(rItem, aTempSet);
aFooterFillAttributes.reset(new drawinglayer::attribute::SdrAllFillAttributesHelper(aTempSet));