summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-11-10 12:48:21 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-11-15 08:24:29 +0100
commit3588a48a82d37f940595570758bc1d1179d18b84 (patch)
treedaa314ae437771157a53f8a5d5043a685f399ac3 /include
parenta8f31d5120c2ae9109d316db73b5adf9cb26c892 (diff)
TypedWhichId
use a strong-typedef template to give which IDs a type, which we can carry around to do a (a) little bit more convenience when Get()'ing them and (b) a little bit of enforcement of which PoolItem subclass each ID uses Fix a bug in casting EE_PARA_BULLETSTATE to the wrong subclass in AccessibleEditableTextPara::_correctValues Change-Id: I015ce8b3b0f6d21308af182afa3caf122c877a5b Reviewed-on: https://gerrit.libreoffice.org/44587 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include')
-rw-r--r--include/editeng/editeng.hxx6
-rw-r--r--include/editeng/eeitem.hxx31
-rw-r--r--include/editeng/unotext.hxx20
-rw-r--r--include/svl/itempool.hxx17
-rw-r--r--include/svl/itemset.hxx26
-rw-r--r--include/svl/poolitem.hxx9
-rw-r--r--include/svl/typedwhich.hxx61
-rw-r--r--include/svx/svdobj.hxx6
8 files changed, 155 insertions, 21 deletions
diff --git a/include/editeng/editeng.hxx b/include/editeng/editeng.hxx
index e7b33cfd5345..4f0be32b9dee 100644
--- a/include/editeng/editeng.hxx
+++ b/include/editeng/editeng.hxx
@@ -28,6 +28,7 @@
#include <com/sun/star/i18n/CharacterIteratorMode.hpp>
#include <svl/style.hxx>
+#include <svl/typedwhich.hxx>
#include <editeng/editdata.hxx>
#include <editeng/editstat.hxx>
#include <editeng/editengdllapi.h>
@@ -319,6 +320,11 @@ public:
bool HasParaAttrib( sal_Int32 nPara, sal_uInt16 nWhich ) const;
const SfxPoolItem& GetParaAttrib( sal_Int32 nPara, sal_uInt16 nWhich );
+ template<class T>
+ const T& GetParaAttrib( sal_Int32 nPara, TypedWhichId<T> nWhich )
+ {
+ return static_cast<const T&>(GetParaAttrib(nPara, nWhich.Which()));
+ }
vcl::Font GetStandardFont( sal_Int32 nPara );
SvxFont GetStandardSvxFont( sal_Int32 nPara );
diff --git a/include/editeng/eeitem.hxx b/include/editeng/eeitem.hxx
index 19393957e6bf..afc0eb8cd715 100644
--- a/include/editeng/eeitem.hxx
+++ b/include/editeng/eeitem.hxx
@@ -21,6 +21,15 @@
#define INCLUDED_EDITENG_EEITEM_HXX
#include <svl/solar.hrc>
+#include <svl/typedwhich.hxx>
+
+class SvxForbiddenRuleItem;
+class SvxFrameDirectionItem;
+class SvxHangingPunctuationItem;
+class SfxBoolItem;
+class SfxInt16Item;
+class SvxLRSpaceItem;
+class SvxScriptSpaceItem;
/*
* NOTE: Changes in this file will probably require
@@ -32,18 +41,18 @@
// Paragraph attributes:
#define EE_PARA_START (EE_ITEMS_START+0)
-#define EE_PARA_WRITINGDIR (EE_ITEMS_START+0)
+#define EE_PARA_WRITINGDIR TypedWhichId<SvxFrameDirectionItem>(EE_ITEMS_START+0)
#define EE_PARA_XMLATTRIBS (EE_ITEMS_START+1)
-#define EE_PARA_HANGINGPUNCTUATION (EE_ITEMS_START+2)
-#define EE_PARA_FORBIDDENRULES (EE_ITEMS_START+3)
-#define EE_PARA_ASIANCJKSPACING (EE_ITEMS_START+4)
-#define EE_PARA_NUMBULLET (EE_ITEMS_START+5)
-#define EE_PARA_HYPHENATE (EE_ITEMS_START+6)
-#define EE_PARA_BULLETSTATE (EE_ITEMS_START+7)
-#define EE_PARA_OUTLLRSPACE (EE_ITEMS_START+8)
-#define EE_PARA_OUTLLEVEL (EE_ITEMS_START+9)
-#define EE_PARA_BULLET (EE_ITEMS_START+10)
-#define EE_PARA_LRSPACE (EE_ITEMS_START+11)
+#define EE_PARA_HANGINGPUNCTUATION TypedWhichId<SvxHangingPunctuationItem>(EE_ITEMS_START+2)
+#define EE_PARA_FORBIDDENRULES TypedWhichId<SvxForbiddenRuleItem>(EE_ITEMS_START+3)
+#define EE_PARA_ASIANCJKSPACING TypedWhichId<SvxScriptSpaceItem>(EE_ITEMS_START+4)
+#define EE_PARA_NUMBULLET TypedWhichId<SvxNumBulletItem>(EE_ITEMS_START+5)
+#define EE_PARA_HYPHENATE TypedWhichId<SfxBoolItem>(EE_ITEMS_START+6)
+#define EE_PARA_BULLETSTATE TypedWhichId<SfxBoolItem>(EE_ITEMS_START+7)
+#define EE_PARA_OUTLLRSPACE TypedWhichId<SvxLRSpaceItem>(EE_ITEMS_START+8)
+#define EE_PARA_OUTLLEVEL TypedWhichId<SfxInt16Item>(EE_ITEMS_START+9)
+#define EE_PARA_BULLET TypedWhichId<SvxBulletItem>(EE_ITEMS_START+10)
+#define EE_PARA_LRSPACE TypedWhichId<SvxLRSpaceItem>(EE_ITEMS_START+11)
#define EE_PARA_ULSPACE (EE_ITEMS_START+12)
#define EE_PARA_SBL (EE_ITEMS_START+13)
#define EE_PARA_JUST (EE_ITEMS_START+14)
diff --git a/include/editeng/unotext.hxx b/include/editeng/unotext.hxx
index d2d29a8b0078..d55a5da31123 100644
--- a/include/editeng/unotext.hxx
+++ b/include/editeng/unotext.hxx
@@ -70,8 +70,8 @@ class SvxItemPropertySet;
#define WID_PARAISNUMBERINGRESTART OWN_ATTR_VALUE_START+4
#define SVX_UNOEDIT_NUMBERING_PROPERTIE \
- {OUString(UNO_NAME_NUMBERING_RULES), EE_PARA_NUMBULLET, cppu::UnoType<css::container::XIndexReplace>::get(), 0, 0 }, \
- {OUString(UNO_NAME_NUMBERING), EE_PARA_BULLETSTATE,cppu::UnoType<bool>::get(), 0, 0 }
+ {OUString(UNO_NAME_NUMBERING_RULES), EE_PARA_NUMBULLET.Which(), cppu::UnoType<css::container::XIndexReplace>::get(), 0, 0 }, \
+ {OUString(UNO_NAME_NUMBERING), EE_PARA_BULLETSTATE.Which(),cppu::UnoType<bool>::get(), 0, 0 }
#define SVX_UNOEDIT_OUTLINER_PROPERTIES \
SVX_UNOEDIT_NUMBERING_PROPERTIE, \
@@ -138,18 +138,18 @@ class SvxItemPropertySet;
#define SVX_UNOEDIT_PARA_PROPERTIES \
{OUString(UNO_NAME_EDIT_PARA_ADJUST), EE_PARA_JUST, ::cppu::UnoType<sal_Int16>::get(), 0, MID_PARA_ADJUST }, \
{OUString(UNO_NAME_EDIT_PARA_BMARGIN), EE_PARA_ULSPACE, ::cppu::UnoType<sal_Int32>::get(), 0, MID_LO_MARGIN|SFX_METRIC_ITEM }, \
- {OUString(UNO_NAME_EDIT_PARA_IS_HYPHEN), EE_PARA_HYPHENATE, cppu::UnoType<bool>::get(), 0, 0 }, \
+ {OUString(UNO_NAME_EDIT_PARA_IS_HYPHEN), EE_PARA_HYPHENATE.Which(), ::cppu::UnoType<bool>::get(), 0, 0 }, \
{OUString(UNO_NAME_EDIT_PARA_LASTLINEADJ), EE_PARA_JUST, ::cppu::UnoType<sal_Int16>::get(), 0, MID_LAST_LINE_ADJUST }, \
- {OUString(UNO_NAME_EDIT_PARA_LMARGIN), EE_PARA_LRSPACE, ::cppu::UnoType<sal_Int32>::get(), 0, MID_TXT_LMARGIN|SFX_METRIC_ITEM }, \
+ {OUString(UNO_NAME_EDIT_PARA_LMARGIN), EE_PARA_LRSPACE.Which(), ::cppu::UnoType<sal_Int32>::get(), 0, MID_TXT_LMARGIN|SFX_METRIC_ITEM }, \
{OUString(UNO_NAME_EDIT_PARA_LINESPACING), EE_PARA_SBL, cppu::UnoType<css::style::LineSpacing>::get(), 0, CONVERT_TWIPS}, \
- {OUString(UNO_NAME_EDIT_PARA_RMARGIN), EE_PARA_LRSPACE, ::cppu::UnoType<sal_Int32>::get(), 0, MID_R_MARGIN|SFX_METRIC_ITEM }, \
+ {OUString(UNO_NAME_EDIT_PARA_RMARGIN), EE_PARA_LRSPACE.Which(), ::cppu::UnoType<sal_Int32>::get(), 0, MID_R_MARGIN|SFX_METRIC_ITEM }, \
{OUString(UNO_NAME_EDIT_PARA_TAPSTOPS), EE_PARA_TABS, cppu::UnoType<css::uno::Sequence< css::style::TabStop >>::get(), 0, 0 }, \
{OUString(UNO_NAME_EDIT_PARA_TMARGIN), EE_PARA_ULSPACE, ::cppu::UnoType<sal_Int32>::get(), 0, MID_UP_MARGIN|SFX_METRIC_ITEM },\
- {OUString(UNO_NAME_EDIT_PARA_FIRST_LINE_INDENT), EE_PARA_LRSPACE, ::cppu::UnoType<sal_Int32>::get(), 0, MID_FIRST_LINE_INDENT|SFX_METRIC_ITEM}, \
- {OUString(UNO_NAME_EDIT_PARA_IS_HANGING_PUNCTUATION),EE_PARA_HANGINGPUNCTUATION, cppu::UnoType<bool>::get(), 0 ,0 }, \
- {OUString(UNO_NAME_EDIT_PARA_IS_CHARACTER_DISTANCE), EE_PARA_ASIANCJKSPACING, cppu::UnoType<bool>::get(), 0 ,0 }, \
- {OUString(UNO_NAME_EDIT_PARA_IS_FORBIDDEN_RULES), EE_PARA_FORBIDDENRULES, cppu::UnoType<bool>::get(), 0 ,0 },\
- {OUString("WritingMode"), EE_PARA_WRITINGDIR, ::cppu::UnoType<sal_Int16>::get(), 0, 0 }
+ {OUString(UNO_NAME_EDIT_PARA_FIRST_LINE_INDENT), EE_PARA_LRSPACE.Which(), ::cppu::UnoType<sal_Int32>::get(), 0, MID_FIRST_LINE_INDENT|SFX_METRIC_ITEM}, \
+ {OUString(UNO_NAME_EDIT_PARA_IS_HANGING_PUNCTUATION),EE_PARA_HANGINGPUNCTUATION.Which(), cppu::UnoType<bool>::get(), 0 ,0 }, \
+ {OUString(UNO_NAME_EDIT_PARA_IS_CHARACTER_DISTANCE), EE_PARA_ASIANCJKSPACING.Which(), cppu::UnoType<bool>::get(), 0 ,0 }, \
+ {OUString(UNO_NAME_EDIT_PARA_IS_FORBIDDEN_RULES), EE_PARA_FORBIDDENRULES.Which(), cppu::UnoType<bool>::get(), 0 ,0 },\
+ {OUString("WritingMode"), EE_PARA_WRITINGDIR.Which(), ::cppu::UnoType<sal_Int16>::get(), 0, 0 }
class SvxEditSource;
class SvxTextForwarder;
diff --git a/include/svl/itempool.hxx b/include/svl/itempool.hxx
index 0cd5bfc13342..22ea12cf4e24 100644
--- a/include/svl/itempool.hxx
+++ b/include/svl/itempool.hxx
@@ -23,6 +23,7 @@
#include <rtl/string.hxx>
#include <svl/poolitem.hxx>
#include <svl/svldllapi.h>
+#include <svl/typedwhich.hxx>
#include <tools/solar.h>
#include <memory>
#include <vector>
@@ -101,7 +102,11 @@ public:
SfxBroadcaster& BC();
void SetPoolDefaultItem( const SfxPoolItem& );
+
const SfxPoolItem* GetPoolDefaultItem( sal_uInt16 nWhich ) const;
+ template<class T> const T* GetPoolDefaultItem( TypedWhichId<T> nWhich ) const
+ { return static_cast<const T*>(GetPoolDefaultItem(nWhich.Which())); }
+
void ResetPoolDefaultItem( sal_uInt16 nWhich );
void SetDefaults(std::vector<SfxPoolItem*>* pDefaults);
@@ -147,11 +152,21 @@ public:
virtual const SfxPoolItem& Put( const SfxPoolItem&, sal_uInt16 nWhich = 0 );
void Remove( const SfxPoolItem& );
+
const SfxPoolItem& GetDefaultItem( sal_uInt16 nWhich ) const;
+ template<class T> const T& GetDefaultItem( TypedWhichId<T> nWhich ) const
+ { return static_cast<const T&>(GetDefaultItem(nWhich.Which())); }
bool CheckItemInPool(const SfxPoolItem *) const;
+
const SfxPoolItem * GetItem2(sal_uInt16 nWhich, sal_uInt32 nSurrogate) const;
+ template<class T> const T* GetItem2( TypedWhichId<T> nWhich, sal_uInt32 nSurrogate ) const
+ { return dynamic_cast<const T*>(GetItem2(nWhich.Which(), nSurrogate)); }
+
const SfxPoolItem * GetItem2Default(sal_uInt16 nWhich) const;
+ template<class T> const T* GetItem2Default( TypedWhichId<T> nWhich ) const
+ { return static_cast<const T*>(GetItem2Default(nWhich.Which())); }
+
sal_uInt32 GetItemCount2(sal_uInt16 nWhich) const;
sal_uInt16 GetFirstWhich() const;
@@ -169,6 +184,8 @@ public:
{ return IsItemPoolable( rItem.Which() ); }
void SetItemInfos( const SfxItemInfo *pInfos );
sal_uInt16 GetWhich( sal_uInt16 nSlot, bool bDeep = true ) const;
+ template<class T> sal_uInt16 GetWhich( TypedWhichId<T> nSlot, bool bDeep = true ) const
+ { return GetWhich(nSlot.Which(), bDeep); }
sal_uInt16 GetSlotId( sal_uInt16 nWhich ) const;
sal_uInt16 GetTrueWhich( sal_uInt16 nSlot, bool bDeep = true ) const;
sal_uInt16 GetTrueSlotId( sal_uInt16 nWhich ) const;
diff --git a/include/svl/itemset.hxx b/include/svl/itemset.hxx
index 89c6149f44a2..3254263c38ab 100644
--- a/include/svl/itemset.hxx
+++ b/include/svl/itemset.hxx
@@ -28,6 +28,7 @@
#include <svl/svldllapi.h>
#include <svl/poolitem.hxx>
+#include <svl/typedwhich.hxx>
class SfxItemPool;
class SfxPoolItem;
@@ -131,6 +132,11 @@ public:
sal_uInt16 TotalCount() const;
const SfxPoolItem& Get( sal_uInt16 nWhich, bool bSrchInParent = true ) const;
+ template<class T>
+ const T& Get( TypedWhichId<T> nWhich, bool bSrchInParent = true ) const
+ {
+ return static_cast<const T&>(Get(nWhich.Which(), bSrchInParent));
+ }
/** This method eases accessing single Items in the SfxItemSet.
@@ -149,6 +155,15 @@ public:
assert(!pItem || pCastedItem); // if it exists, must have the correct type
return pCastedItem;
}
+ template<class T> const T* GetItem( TypedWhichId<T> nWhich, bool bSearchInParent = true ) const
+ {
+ const SfxPoolItem* pItem = GetItem(nWhich.Which(), bSearchInParent);
+ const T* pCastedItem = dynamic_cast<const T*>(pItem);
+
+ assert(!pItem || pCastedItem); // if it exists, must have the correct type
+ return pCastedItem;
+ }
+
/// Templatized static version of GetItem() to directly return the correct type if the SfxItemSet is available.
template<class T> static const T* GetItem(const SfxItemSet* pItemSet, sal_uInt16 nWhich, bool bSearchInParent = true)
@@ -166,12 +181,23 @@ public:
SfxItemState GetItemState( sal_uInt16 nWhich,
bool bSrchInParent = true,
const SfxPoolItem **ppItem = nullptr ) const;
+ template<class T>
+ SfxItemState GetItemState( TypedWhichId<T> nWhich,
+ bool bSrchInParent = true,
+ const SfxPoolItem **ppItem = nullptr ) const
+ { return GetItemState(nWhich.Which(), bSrchInParent, ppItem); }
bool HasItem(sal_uInt16 nWhich, const SfxPoolItem** ppItem = nullptr) const;
void DisableItem(sal_uInt16 nWhich);
+ template<class T> void DisableItem( TypedWhichId<T> nWhich )
+ { DisableItem(nWhich.Which()); }
void InvalidateItem( sal_uInt16 nWhich );
+ template<class T> void InvalidateItem( TypedWhichId<T> nWhich )
+ { InvalidateItem(nWhich.Which()); }
sal_uInt16 ClearItem( sal_uInt16 nWhich = 0);
+ template<class T> sal_uInt16 ClearItem( TypedWhichId<T> nWhich )
+ { return ClearItem(nWhich.Which()); }
void ClearInvalidItems();
void InvalidateAllItems(); // HACK(via nWhich = 0) ???
diff --git a/include/svl/poolitem.hxx b/include/svl/poolitem.hxx
index 7f9540c166a2..2d5a6f567c0b 100644
--- a/include/svl/poolitem.hxx
+++ b/include/svl/poolitem.hxx
@@ -28,6 +28,7 @@
#include <com/sun/star/uno/Any.hxx>
#include <svl/hint.hxx>
#include <svl/svldllapi.h>
+#include <svl/typedwhich.hxx>
#include <tools/debug.hxx>
#include <tools/mapunit.hxx>
#include <tools/solar.h>
@@ -149,6 +150,10 @@ public:
assert(m_nRefCount==0);
m_nWhich = nId;
}
+ template<class T> void SetWhich( TypedWhichId<T> nId )
+ {
+ SetWhich(nId.Which());
+ }
sal_uInt16 Which() const { return m_nWhich; }
virtual bool operator==( const SfxPoolItem& ) const = 0;
bool operator!=( const SfxPoolItem& rItem ) const
@@ -173,6 +178,10 @@ public:
virtual SfxPoolItem* Clone( SfxItemPool *pPool = nullptr ) const = 0;
// clone and call SetWhich
SfxPoolItem* CloneSetWhich( sal_uInt16 nNewWhich ) const;
+ template<class T> T* CloneSetWhich( TypedWhichId<T> nId ) const
+ {
+ return static_cast<T*>(CloneSetWhich(nId.Which()));
+ }
sal_uInt32 GetRefCount() const { return m_nRefCount; }
SfxItemKind GetKind() const { return m_nKind; }
diff --git a/include/svl/typedwhich.hxx b/include/svl/typedwhich.hxx
new file mode 100644
index 000000000000..43318cc52303
--- /dev/null
+++ b/include/svl/typedwhich.hxx
@@ -0,0 +1,61 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#ifndef INCLUDED_SVL_TYPEDWHICH_HXX
+#define INCLUDED_SVL_TYPEDWHICH_HXX
+
+#include <sal/config.h>
+#include <sal/types.h>
+
+/**
+ * A very thin wrapper around the sal_uInt16 WhichId whose purpose is mostly to carry type information,
+ * so that we Put() and Get() the right subclasses of SfxPoolItem for each WhichId.
+ */
+template <class T> class TypedWhichId final
+{
+public:
+ constexpr TypedWhichId(sal_uInt16 nWhich)
+ : mnWhich(nWhich)
+ {
+ }
+ constexpr sal_uInt16 Which() const { return mnWhich; }
+ //constexpr operator sal_uInt16() const { return mnWhich; }
+private:
+ sal_uInt16 const mnWhich;
+};
+
+template <class T> constexpr bool operator==(sal_uInt16 lhs, TypedWhichId<T> const& rhs)
+{
+ return lhs == rhs.Which();
+}
+template <class T> constexpr bool operator!=(sal_uInt16 lhs, TypedWhichId<T> const& rhs)
+{
+ return lhs != rhs.Which();
+}
+template <class T> constexpr bool operator==(TypedWhichId<T> const& lhs, sal_uInt16 rhs)
+{
+ return lhs.Which() == rhs;
+}
+template <class T> constexpr bool operator!=(TypedWhichId<T> const& lhs, sal_uInt16 rhs)
+{
+ return lhs.Which() != rhs;
+}
+
+#endif // INCLUDED_SVL_TYPEDWHICH_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svx/svdobj.hxx b/include/svx/svdobj.hxx
index cd6953312565..af4f7ec72e21 100644
--- a/include/svx/svdobj.hxx
+++ b/include/svx/svdobj.hxx
@@ -27,6 +27,7 @@
#include <vcl/vclptr.hxx>
#include <svl/lstner.hxx>
#include <svl/poolitem.hxx>
+#include <svl/typedwhich.hxx>
#include <svx/svdtypes.hxx>
#include <svx/xenum.hxx>
#include <svx/svxdllapi.h>
@@ -581,6 +582,11 @@ public:
void ClearMergedItem(const sal_uInt16 nWhich = 0);
void SetMergedItemSet(const SfxItemSet& rSet, bool bClearAllItems = false);
const SfxPoolItem& GetMergedItem(const sal_uInt16 nWhich) const;
+ template<class T>
+ const T& GetMergedItem( TypedWhichId<T> nWhich ) const
+ {
+ return static_cast<const T&>(GetMergedItem(nWhich.Which()));
+ }
// syntactical sugar for ItemSet accesses
void SetMergedItemSetAndBroadcast(const SfxItemSet& rSet, bool bClearAllItems = false);