summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArmin Le Grand <Armin.Le.Grand@me.com>2019-04-10 11:56:52 +0200
committerArmin Le Grand <Armin.Le.Grand@me.com>2019-05-05 18:45:18 +0200
commit253d84da26c39e502b2da3af971251877ee45ce5 (patch)
treecf56122d9612017eac3784270cae73880e09b261
parentWIP: Moved usage of SID_BASICIDE_ARG_SBX completely (diff)
downloadcore-253d84da26c39e502b2da3af971251877ee45ce5.tar.gz
core-253d84da26c39e502b2da3af971251877ee45ce5.zip
WIP: Replaced SID_ATTR_TRANSFORM_ANCHOR with Item
by implementing Item::TransformAnchor and using it type-safe. This is an example of a direct derive from an existing (simple) Item (CntInt16) and thus re-using the same ItemAdministrator. Slightly adapted implementations and tests Change-Id: I1a0222f04f59130bb51e29e3871d0bf7766b84ee
-rw-r--r--basctl/source/basicide/sbxitem.cxx7
-rw-r--r--cui/source/tabpages/swpossizetabpage.cxx8
-rw-r--r--include/item/base/ItemBase.hxx3
-rwxr-xr-xinclude/svx/item/TransformAnchor.hxx39
-rw-r--r--item/source/base/ItemBase.cxx13
-rw-r--r--item/source/simple/CntInt16.cxx7
-rw-r--r--item/source/simple/CntOUString.cxx6
-rw-r--r--item/test/ItemTest.cxx23
-rw-r--r--svx/Library_svxcore.mk2
-rwxr-xr-xsvx/source/items/TransformAnchor.cxx52
-rw-r--r--sw/source/uibase/shells/drwbassh.cxx11
11 files changed, 133 insertions, 38 deletions
diff --git a/basctl/source/basicide/sbxitem.cxx b/basctl/source/basicide/sbxitem.cxx
index bb5e518f72ce..33b3adca54e7 100644
--- a/basctl/source/basicide/sbxitem.cxx
+++ b/basctl/source/basicide/sbxitem.cxx
@@ -70,8 +70,13 @@ namespace Item
bool Sbx::operator==(const ItemBase& rCandidate) const
{
- assert(ItemBase::operator==(rCandidate));
+ if(ItemBase::operator==(rCandidate)) // compares ptrs
+ {
+ return true;
+ }
+
const Sbx& rCand(static_cast<const Sbx&>(rCandidate));
+
return (GetDocument() == rCand.GetDocument()
&& GetLibName() == rCand.GetLibName()
&& GetName() == rCand.GetName()
diff --git a/cui/source/tabpages/swpossizetabpage.cxx b/cui/source/tabpages/swpossizetabpage.cxx
index 6cfd5a568abb..f2691204e25c 100644
--- a/cui/source/tabpages/swpossizetabpage.cxx
+++ b/cui/source/tabpages/swpossizetabpage.cxx
@@ -37,7 +37,7 @@
#include <svtools/unitconv.hxx>
// I2TM
-#include <item/simple/CntInt16.hxx>
+#include <svx/item/TransformAnchor.hxx>
// ~I2TM
using namespace ::com::sun::star::text;
@@ -753,7 +753,7 @@ bool SvxSwPosSizeTabPage::FillItemSet( SfxItemSet* rSet)
if(bAnchorChanged)
{
// I2TM
- rSet->slotSet().SetSlot(SID_ATTR_TRANSFORM_ANCHOR, Item::CntInt16::Create(static_cast<sal_Int16>(nAnchor)));
+ rSet->itemSet().SetItem(Item::TransformAnchor::Create(nAnchor));
// ~I2TM
bModified = true;
}
@@ -902,9 +902,9 @@ void SvxSwPosSizeTabPage::Reset( const SfxItemSet* rSet)
RndStdIds nAnchorType = RndStdIds::FLY_AT_PARA;
// I2TM
- if(const auto Slot(rSet->slotSet().GetSlot<const Item::CntInt16>(SID_ATTR_TRANSFORM_ANCHOR)); Slot)
+ if(const auto Item(rSet->itemSet().GetStateAndItem<const Item::TransformAnchor>()); Item.HasItem())
{
- nAnchorType = static_cast<RndStdIds>(Slot->GetValue());
+ nAnchorType = Item.GetItem()->GetAnchorType();
// I2TM
switch(nAnchorType)
{
diff --git a/include/item/base/ItemBase.hxx b/include/item/base/ItemBase.hxx
index 6af2858e8d0a..f356d5edadc1 100644
--- a/include/item/base/ItemBase.hxx
+++ b/include/item/base/ItemBase.hxx
@@ -124,9 +124,6 @@ namespace Item
// to create instances
ItemBase();
- // basic RTTI TypeCheck to secure e.g. operator== and similar
- bool CheckSameType(const ItemBase& rCmp) const;
-
// PutValue/Any interface for automated instance creation from SfxType
// mechanism (UNO API and sfx2 stuff)
friend class ItemControlBlock;
diff --git a/include/svx/item/TransformAnchor.hxx b/include/svx/item/TransformAnchor.hxx
new file mode 100755
index 000000000000..d78c5e2a93c5
--- /dev/null
+++ b/include/svx/item/TransformAnchor.hxx
@@ -0,0 +1,39 @@
+/* -*- 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/.
+ */
+
+#ifndef INCLUDED_SVX_ITEM_TRANSFORMANCHOR_HXX
+#define INCLUDED_SVX_ITEM_TRANSFORMANCHOR_HXX
+
+#include <item/simple/CntInt16.hxx>
+#include <svx/swframetypes.hxx>
+
+///////////////////////////////////////////////////////////////////////////////
+
+namespace Item
+{
+ class SVX_DLLPUBLIC TransformAnchor : public CntInt16
+ {
+ public:
+ static ItemControlBlock& GetStaticItemControlBlock();
+ virtual ItemControlBlock& GetItemControlBlock() const override;
+
+ protected:
+ TransformAnchor(RndStdIds nValue = RndStdIds::UNKNOWN);
+
+ public:
+ static std::shared_ptr<const TransformAnchor> Create(RndStdIds nValue);
+ RndStdIds GetAnchorType() const { return static_cast<RndStdIds>(GetValue()); }
+ };
+} // end of namespace Item
+
+///////////////////////////////////////////////////////////////////////////////
+
+#endif // INCLUDED_SVX_ITEM_TRANSFORMANCHOR_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/item/source/base/ItemBase.cxx b/item/source/base/ItemBase.cxx
index 0124841e1c04..08dcc25ab8eb 100644
--- a/item/source/base/ItemBase.cxx
+++ b/item/source/base/ItemBase.cxx
@@ -25,7 +25,8 @@ class SbxItem : public SfxPoolItem
class SfxInt16Item
-> Item::CntInt16
--> SID_ATTR_TRANSFORM_ANCHOR -> need own type to replace in ItemSet ->
+-> SID_ATTR_TRANSFORM_ANCHOR -> need own type to replace in ItemSet -> Item::TransformAnchor
+-> replace using TransformAnchor and ItemSet -> done!
defs from sfx2\sdi\sfxitems.sdi may be a good hint which items to convert first (?)
these are:
@@ -230,11 +231,6 @@ namespace Item
{
}
- bool ItemBase::CheckSameType(const ItemBase& rCmp) const
- {
- return typeid(rCmp) == typeid(*this);
- }
-
void ItemBase::PutValues(const AnyIDArgs& rArgs)
{
for(const auto& arg : rArgs)
@@ -263,8 +259,8 @@ namespace Item
bool ItemBase::operator==(const ItemBase& rCmp) const
{
- // basic implementation compares type, no data available
- return CheckSameType(rCmp);
+ // basic implementation compares pointers, no data available
+ return this == &rCmp;
}
bool ItemBase::operator<(const ItemBase& rCmp) const
@@ -272,7 +268,6 @@ namespace Item
// basic implementation uses addresses of instances to
// deliver a consistent result, but should *not* be used in
// this form - it will not compare any data
- assert(CheckSameType(rCmp));
return this < &rCmp;
}
diff --git a/item/source/simple/CntInt16.cxx b/item/source/simple/CntInt16.cxx
index 14885387a979..a9fd7a0169f1 100644
--- a/item/source/simple/CntInt16.cxx
+++ b/item/source/simple/CntInt16.cxx
@@ -58,13 +58,16 @@ namespace Item
bool CntInt16::operator==(const ItemBase& rCandidate) const
{
- assert(ItemBase::operator==(rCandidate));
+ if(ItemBase::operator==(rCandidate)) // compares ptrs
+ {
+ return true;
+ }
+
return (GetValue() == static_cast<const CntInt16&>(rCandidate).GetValue());
}
bool CntInt16::operator<(const ItemBase& rCandidate) const
{
- assert(ItemBase::operator==(rCandidate));
return static_cast<const CntInt16*>(this)->GetValue() < static_cast<const CntInt16&>(rCandidate).GetValue();
}
diff --git a/item/source/simple/CntOUString.cxx b/item/source/simple/CntOUString.cxx
index bd77b934cb05..9f9eeb75372f 100644
--- a/item/source/simple/CntOUString.cxx
+++ b/item/source/simple/CntOUString.cxx
@@ -58,7 +58,11 @@ namespace Item
bool CntOUString::operator==(const ItemBase& rCandidate) const
{
- assert(ItemBase::operator==(rCandidate));
+ if(ItemBase::operator==(rCandidate)) // compares ptrs
+ {
+ return true;
+ }
+
return (GetValue() == static_cast<const CntOUString&>(rCandidate).GetValue());
}
diff --git a/item/test/ItemTest.cxx b/item/test/ItemTest.cxx
index 46816e7507c5..8c7b839b11c4 100644
--- a/item/test/ItemTest.cxx
+++ b/item/test/ItemTest.cxx
@@ -78,8 +78,13 @@ namespace Item
virtual bool operator==(const ItemBase& rCandidate) const override
{
- assert(ItemBase::operator==(rCandidate));
+ if(ItemBase::operator==(rCandidate)) // compares ptrs
+ {
+ return true;
+ }
+
const MultiValueAB& rCand(static_cast<const MultiValueAB&>(rCandidate));
+
return (GetValueA() == rCand.GetValueA()
&& GetValueB() == rCand.GetValueB());
}
@@ -96,7 +101,6 @@ namespace Item
// virtual bool operator<(const ItemBase& rCandidate) const override
// {
- // assert(ItemBase::operator==(rCandidate));
// return static_cast<const MultiValueAB*>(this)->GetValueA() < static_cast<const MultiValueAB&>(rCandidate).GetValueA()
// && static_cast<const MultiValueAB*>(this)->GetValueB() < static_cast<const MultiValueAB&>(rCandidate).GetValueB();
// }
@@ -159,8 +163,8 @@ namespace Item
virtual bool operator==(const ItemBase& rCandidate) const override
{
- assert(ItemBase::operator==(rCandidate));
const MultiValueABC& rCand(static_cast<const MultiValueABC&>(rCandidate));
+
return (MultiValueAB::operator==(rCandidate)
&& GetValueC() == rCand.GetValueC());
}
@@ -172,7 +176,6 @@ namespace Item
// virtual bool operator<(const ItemBase& rCandidate) const override
// {
- // assert(ItemBase::operator==(rCandidate));
// return MultiValueAB::operator<(rCandidate)
// && static_cast<const MultiValueABC*>(this)->GetValueC() < static_cast<const MultiValueABC&>(rCandidate).GetValueC();
// }
@@ -187,17 +190,17 @@ namespace Item
class MultiValueAB_Alternative : public MultiValueAB
{
public:
- static ItemControlBlock& MultiValueAB_Alternative::GetStaticItemControlBlock()
+ static ItemControlBlock& GetStaticItemControlBlock()
{
static ItemControlBlock aItemControlBlock(
- MultiValueABC::GetStaticItemControlBlock().GetItemAdministrator(),
+ MultiValueAB::GetStaticItemControlBlock().GetItemAdministrator(),
std::shared_ptr<const ItemBase>(new MultiValueAB_Alternative()),
[](){ return new MultiValueAB_Alternative(); });
return aItemControlBlock;
}
- virtual ItemControlBlock& MultiValueAB_Alternative::GetItemControlBlock() const override
+ virtual ItemControlBlock& GetItemControlBlock() const override
{
return MultiValueAB_Alternative::GetStaticItemControlBlock();
}
@@ -219,12 +222,6 @@ namespace Item
MultiValueAB_Alternative::GetStaticItemControlBlock().GetItemAdministrator()->Create(
new MultiValueAB_Alternative(nValueA, nValueB)));
}
-
- virtual bool operator==(const ItemBase& rCandidate) const override
- {
- assert(ItemBase::operator==(rCandidate));
- return (MultiValueAB::operator==(rCandidate));
- }
};
} // end of namespace Item
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk
index 1ca893e5eeab..0d04fbc18590 100644
--- a/svx/Library_svxcore.mk
+++ b/svx/Library_svxcore.mk
@@ -77,6 +77,7 @@ $(eval $(call gb_Library_use_libraries,svxcore,\
utl \
vcl \
xo \
+ item \
))
$(eval $(call gb_Library_use_externals,svxcore,\
@@ -163,6 +164,7 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\
svx/source/items/e3ditem \
svx/source/items/galleryitem \
svx/source/items/grfitem \
+ svx/source/items/TransformAnchor \
svx/source/sdr/animation/scheduler \
svx/source/sdr/animation/objectanimator \
svx/source/sdr/animation/animationstate \
diff --git a/svx/source/items/TransformAnchor.cxx b/svx/source/items/TransformAnchor.cxx
new file mode 100755
index 000000000000..d10d7d24bcaa
--- /dev/null
+++ b/svx/source/items/TransformAnchor.cxx
@@ -0,0 +1,52 @@
+/* -*- 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/.
+ */
+
+#include <cassert>
+#include <svx/item/TransformAnchor.hxx>
+#include <item/base/ItemAdministrator.hxx>
+
+///////////////////////////////////////////////////////////////////////////////
+
+namespace Item
+{
+ ItemControlBlock& TransformAnchor::GetStaticItemControlBlock()
+ {
+ static ItemControlBlock aItemControlBlock(
+ CntInt16::GetStaticItemControlBlock().GetItemAdministrator(),
+ std::shared_ptr<const ItemBase>(new TransformAnchor()),
+ [](){ return new TransformAnchor(); });
+
+ return aItemControlBlock;
+ }
+
+ ItemControlBlock& TransformAnchor::GetItemControlBlock() const
+ {
+ return TransformAnchor::GetStaticItemControlBlock();
+ }
+
+ TransformAnchor::TransformAnchor(RndStdIds nValue)
+ : CntInt16(static_cast<sal_Int16>(nValue))
+ {
+ }
+
+ std::shared_ptr<const TransformAnchor> TransformAnchor::Create(RndStdIds nValue)
+ {
+ // use ::Create(...) method with local incarnation, it will handle
+ // - detection of being default (will delete local incarnation)
+ // - detection of reuse (will delete local incarnation)
+ // - detectiomn of new use - will create shared_ptr for local incarnation and buffer
+ return std::static_pointer_cast<const TransformAnchor>(
+ TransformAnchor::GetStaticItemControlBlock().GetItemAdministrator()->Create(
+ new TransformAnchor(nValue)));
+ }
+} // end of namespace Item
+
+///////////////////////////////////////////////////////////////////////////////
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/shells/drwbassh.cxx b/sw/source/uibase/shells/drwbassh.cxx
index a354fd3b8c18..b236d48fcc7c 100644
--- a/sw/source/uibase/shells/drwbassh.cxx
+++ b/sw/source/uibase/shells/drwbassh.cxx
@@ -63,7 +63,7 @@
#include <fmtfollowtextflow.hxx>
// I2TM
-#include <item/simple/CntInt16.hxx>
+#include <svx/item/TransformAnchor.hxx>
// ~I2TM
using namespace ::com::sun::star;
@@ -218,8 +218,9 @@ void SwDrawBaseShell::Execute(SfxRequest const &rReq)
pSdrView->GetAttributes( aSet );
// I2TM
- aSet.slotSet().SetSlot(SID_ATTR_TRANSFORM_ANCHOR, Item::CntInt16::Create(static_cast<sal_Int16>(nAnchor)));
+ aSet.itemSet().SetItem(Item::TransformAnchor::Create(nAnchor));
// ~I2TM
+
bool bRTL;
bool bVertL2R;
aSet.Put(SfxBoolItem(SID_ATTR_TRANSFORM_IN_VERTICAL_TEXT, pSh->IsFrameVertical(true, bRTL, bVertL2R)));
@@ -268,16 +269,16 @@ void SwDrawBaseShell::Execute(SfxRequest const &rReq)
bool bSingleSelection = rMarkList.GetMarkCount() == 1;
// I2TM
- if(const auto Slot(pOutSet->slotSet().GetSlot<const Item::CntInt16>(SID_ATTR_TRANSFORM_ANCHOR)); Slot)
+ if(const auto Item(pOutSet->itemSet().GetStateAndItem<const Item::TransformAnchor>()); Item.HasItem())
{
if(!bSingleSelection)
{
- pSh->ChgAnchor(static_cast<RndStdIds>(Slot->GetValue()), false, bPosCorr);
+ pSh->ChgAnchor(Item.GetItem()->GetAnchorType(), false, bPosCorr);
}
else
{
SwFormatAnchor aAnchor(pFrameFormat->GetAnchor());
- aAnchor.SetType(static_cast<RndStdIds>(Slot->GetValue()));
+ aAnchor.SetType(Item.GetItem()->GetAnchorType());
aFrameAttrSet.Put( aAnchor );
}
}