summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2018-02-13 18:57:46 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-02-14 11:21:51 +0100
commite2372907c991833a8bbe13f84460783d8d8fdfdb (patch)
treeaf8e58ad8ffb73a4352de578496f006839763ad2
parent532576461654eaf43120d2f693172c07a41275fa (diff)
Make SwFormatFrameSize derive from SvxSizeItem
...as seen in UBSan builds when, on an image in Writer, selecting context menu's "Properties..." to open the "Image" dialog, there'll be failure > cui/source/tabpages/grfpage.cxx:206:21: runtime error: downcast of address 0x00001293f5c0 which does not point to an object of type 'const SvxSizeItem' > 0x00001293f5c0: note: object is of type 'SwFormatFrameSize' 00 00 00 00 68 d5 ea aa 8f 7f 00 00 01 00 00 00 43 27 00 00 81 2e 00 00 00 00 00 00 c5 41 00 00 > ^~~~~~~~~~~~~~~~~~~~~~~ > vptr for 'SwFormatFrameSize' > #0 0x7f8f1ec29a34 in SvxGrfCropPage::Reset(SfxItemSet const*) cui/source/tabpages/grfpage.cxx:206:21 > #1 0x7f9036000d98 in SfxTabDialog::ActivatePageHdl(TabControl*) sfx2/source/dialog/tabdlg.cxx:1115:19 Moved the {Get,Set}{Width,Height} convenience functions down from SwFormatFrameSize to SvxSizeItem. And "reverted" the SvxSizeItem {Has,Scale}Metrics overrides in SwFormatFrameSize, "just in case." Renamed SvxSizeItem::aSize to m_aSize to avoid GCC -Werror=shadow in SwFormatFrameSize::dumpAsXml (sw/source/core/layout/atrfrm.cxx), which has a local variable named aSize. Change-Id: I9a2e0b19f21c1468ecba87a5bdafa40c8c424ae4 Reviewed-on: https://gerrit.libreoffice.org/49678 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
-rw-r--r--editeng/source/items/frmitems.cxx24
-rw-r--r--include/editeng/sizeitem.hxx13
-rw-r--r--sw/inc/fmtfsize.hxx18
-rw-r--r--sw/source/core/layout/atrfrm.cxx37
-rw-r--r--sw/source/uibase/uiview/viewtab.cxx4
5 files changed, 55 insertions, 41 deletions
diff --git a/editeng/source/items/frmitems.cxx b/editeng/source/items/frmitems.cxx
index 0ed13e1088af..f39dc856fb3d 100644
--- a/editeng/source/items/frmitems.cxx
+++ b/editeng/source/items/frmitems.cxx
@@ -201,7 +201,7 @@ SvxSizeItem::SvxSizeItem( const sal_uInt16 nId, const Size& rSize ) :
SfxPoolItem( nId ),
- aSize( rSize )
+ m_aSize( rSize )
{
}
@@ -211,7 +211,7 @@ bool SvxSizeItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
- awt::Size aTmp(aSize.Width(), aSize.Height());
+ awt::Size aTmp(m_aSize.Width(), m_aSize.Height());
if( bConvert )
{
aTmp.Height = convertTwipToMm100(aTmp.Height);
@@ -247,7 +247,7 @@ bool SvxSizeItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
aTmp.Height = convertMm100ToTwip(aTmp.Height);
aTmp.Width = convertMm100ToTwip(aTmp.Width);
}
- aSize = Size( aTmp.Width, aTmp.Height );
+ m_aSize = Size( aTmp.Width, aTmp.Height );
}
else
{
@@ -261,7 +261,7 @@ bool SvxSizeItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
if(!(rVal >>= nVal ))
return false;
- aSize.setWidth( bConvert ? convertMm100ToTwip(nVal) : nVal );
+ m_aSize.setWidth( bConvert ? convertMm100ToTwip(nVal) : nVal );
}
break;
case MID_SIZE_HEIGHT:
@@ -270,7 +270,7 @@ bool SvxSizeItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
if(!(rVal >>= nVal))
return true;
- aSize.setHeight( bConvert ? convertMm100ToTwip(nVal) : nVal );
+ m_aSize.setHeight( bConvert ? convertMm100ToTwip(nVal) : nVal );
}
break;
default: OSL_FAIL("Wrong MemberId!");
@@ -291,7 +291,7 @@ bool SvxSizeItem::operator==( const SfxPoolItem& rAttr ) const
{
assert(SfxPoolItem::operator==(rAttr));
- return ( aSize == static_cast<const SvxSizeItem&>( rAttr ).GetSize() );
+ return ( m_aSize == static_cast<const SvxSizeItem&>( rAttr ).GetSize() );
}
@@ -313,18 +313,18 @@ bool SvxSizeItem::GetPresentation
switch ( ePres )
{
case SfxItemPresentation::Nameless:
- rText = GetMetricText( aSize.Width(), eCoreUnit, ePresUnit, &rIntl ) +
+ rText = GetMetricText( m_aSize.Width(), eCoreUnit, ePresUnit, &rIntl ) +
cpDelimTmp +
- GetMetricText( aSize.Height(), eCoreUnit, ePresUnit, &rIntl );
+ GetMetricText( m_aSize.Height(), eCoreUnit, ePresUnit, &rIntl );
return true;
case SfxItemPresentation::Complete:
rText = EditResId(RID_SVXITEMS_SIZE_WIDTH) +
- GetMetricText( aSize.Width(), eCoreUnit, ePresUnit, &rIntl ) +
+ GetMetricText( m_aSize.Width(), eCoreUnit, ePresUnit, &rIntl ) +
" " + EditResId(GetMetricId(ePresUnit)) +
cpDelimTmp +
EditResId(RID_SVXITEMS_SIZE_HEIGHT) +
- GetMetricText( aSize.Height(), eCoreUnit, ePresUnit, &rIntl ) +
+ GetMetricText( m_aSize.Height(), eCoreUnit, ePresUnit, &rIntl ) +
" " + EditResId(GetMetricId(ePresUnit));
return true;
// no break necessary
@@ -337,8 +337,8 @@ bool SvxSizeItem::GetPresentation
void SvxSizeItem::ScaleMetrics( long nMult, long nDiv )
{
- aSize.setWidth( Scale( aSize.Width(), nMult, nDiv ) );
- aSize.setHeight( Scale( aSize.Height(), nMult, nDiv ) );
+ m_aSize.setWidth( Scale( m_aSize.Width(), nMult, nDiv ) );
+ m_aSize.setHeight( Scale( m_aSize.Height(), nMult, nDiv ) );
}
diff --git a/include/editeng/sizeitem.hxx b/include/editeng/sizeitem.hxx
index 89398307c34c..9e2bdc6efabf 100644
--- a/include/editeng/sizeitem.hxx
+++ b/include/editeng/sizeitem.hxx
@@ -33,7 +33,7 @@
class EDITENG_DLLPUBLIC SvxSizeItem : public SfxPoolItem
{
- Size aSize;
+ Size m_aSize;
public:
static SfxPoolItem* CreateDefault();
@@ -57,13 +57,18 @@ public:
virtual void ScaleMetrics( long nMult, long nDiv ) override;
virtual bool HasMetrics() const override;
- const Size& GetSize() const { return aSize; }
- void SetSize(const Size& rSize) { aSize = rSize; }
+ const Size& GetSize() const { return m_aSize; }
+ void SetSize(const Size& rSize) { m_aSize = rSize; }
+
+ long GetWidth() const { return m_aSize.getWidth(); }
+ long GetHeight() const { return m_aSize.getHeight(); }
+ void SetWidth(long n) { m_aSize.setWidth(n); }
+ void SetHeight(long n) { m_aSize.setHeight(n); }
};
inline SvxSizeItem& SvxSizeItem::operator=( const SvxSizeItem &rCpy )
{
- aSize = rCpy.aSize;
+ m_aSize = rCpy.m_aSize;
return *this;
}
diff --git a/sw/inc/fmtfsize.hxx b/sw/inc/fmtfsize.hxx
index 9cbfb2078198..c70706431833 100644
--- a/sw/inc/fmtfsize.hxx
+++ b/sw/inc/fmtfsize.hxx
@@ -19,6 +19,9 @@
#ifndef INCLUDED_SW_INC_FMTFSIZE_HXX
#define INCLUDED_SW_INC_FMTFSIZE_HXX
+#include <sal/config.h>
+
+#include <editeng/sizeitem.hxx>
#include <tools/gen.hxx>
#include <svl/poolitem.hxx>
#include "swdllapi.h"
@@ -38,9 +41,8 @@ enum SwFrameSize
(can be exceeded but not be less). */
};
-class SW_DLLPUBLIC SwFormatFrameSize: public SfxPoolItem
+class SW_DLLPUBLIC SwFormatFrameSize: public SvxSizeItem
{
- Size m_aSize;
SwFrameSize m_eFrameHeightType;
SwFrameSize m_eFrameWidthType;
sal_uInt8 m_nWidthPercent;
@@ -59,12 +61,14 @@ class SW_DLLPUBLIC SwFormatFrameSize: public SfxPoolItem
// the object is placed (PrtArea) and to the screen width
// minus borders in BrowseView if the environment is the page.
+ void ScaleMetrics(long lMult, long lDiv) override;
+ bool HasMetrics() const override;
+
public:
SwFormatFrameSize( SwFrameSize eSize = ATT_VAR_SIZE,
SwTwips nWidth = 0, SwTwips nHeight = 0 );
SwFormatFrameSize& operator=( const SwFormatFrameSize& rCpy );
- /// "Pure virtual methods" of SfxPoolItem.
virtual bool operator==( const SfxPoolItem& ) const override;
virtual SfxPoolItem* Clone( SfxItemPool *pPool = nullptr ) const override;
virtual bool GetPresentation( SfxItemPresentation ePres,
@@ -81,14 +85,6 @@ public:
SwFrameSize GetWidthSizeType() const { return m_eFrameWidthType; }
void SetWidthSizeType( SwFrameSize eSize ) { m_eFrameWidthType = eSize; }
- const Size& GetSize() const { return m_aSize; }
- void SetSize( const Size &rNew ) { m_aSize = rNew; }
-
- SwTwips GetHeight() const { return m_aSize.Height(); }
- SwTwips GetWidth() const { return m_aSize.Width(); }
- void SetHeight( const SwTwips nNew ) { m_aSize.Height() = nNew; }
- void SetWidth ( const SwTwips nNew ) { m_aSize.Width() = nNew; }
-
enum PercentFlags { SYNCED = 0xff };
//0xff is reserved to indicate height is synced to width
sal_uInt8 GetHeightPercent() const{ return m_nHeightPercent; }
diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx
index 7ca5544be310..1d0aebd450d8 100644
--- a/sw/source/core/layout/atrfrm.cxx
+++ b/sw/source/core/layout/atrfrm.cxx
@@ -171,10 +171,23 @@ static void lcl_DelHFFormat( SwClient *pToRemove, SwFrameFormat *pFormat )
}
}
+void SwFormatFrameSize::ScaleMetrics(long lMult, long lDiv) {
+ // Don't inherit the SvxSizeItem override (might or might not be relevant; added "just in case"
+ // when changing SwFormatFrameSize to derive from SvxSizeItem instead of directly from
+ // SfxPoolItem):
+ return SfxPoolItem::ScaleMetrics(lMult, lDiv);
+}
+
+bool SwFormatFrameSize::HasMetrics() const {
+ // Don't inherit the SvxSizeItem override (might or might not be relevant; added "just in case"
+ // when changing SwFormatFrameSize to derive from SvxSizeItem instead of directly from
+ // SfxPoolItem):
+ return SfxPoolItem::HasMetrics();
+}
+
// Partially implemented inline in hxx
SwFormatFrameSize::SwFormatFrameSize( SwFrameSize eSize, SwTwips nWidth, SwTwips nHeight )
- : SfxPoolItem( RES_FRM_SIZE ),
- m_aSize( nWidth, nHeight ),
+ : SvxSizeItem( RES_FRM_SIZE, {nWidth, nHeight} ),
m_eFrameHeightType( eSize ),
m_eFrameWidthType( ATT_FIX_SIZE )
{
@@ -183,7 +196,7 @@ SwFormatFrameSize::SwFormatFrameSize( SwFrameSize eSize, SwTwips nWidth, SwTwips
SwFormatFrameSize& SwFormatFrameSize::operator=( const SwFormatFrameSize& rCpy )
{
- m_aSize = rCpy.GetSize();
+ SvxSizeItem::operator=(rCpy);
m_eFrameHeightType = rCpy.GetHeightSizeType();
m_eFrameWidthType = rCpy.GetWidthSizeType();
m_nHeightPercent = rCpy.GetHeightPercent();
@@ -198,7 +211,7 @@ bool SwFormatFrameSize::operator==( const SfxPoolItem& rAttr ) const
assert(SfxPoolItem::operator==(rAttr));
return( m_eFrameHeightType == static_cast<const SwFormatFrameSize&>(rAttr).m_eFrameHeightType &&
m_eFrameWidthType == static_cast<const SwFormatFrameSize&>(rAttr).m_eFrameWidthType &&
- m_aSize == static_cast<const SwFormatFrameSize&>(rAttr).GetSize()&&
+ SvxSizeItem::operator==(rAttr)&&
m_nWidthPercent == static_cast<const SwFormatFrameSize&>(rAttr).GetWidthPercent() &&
m_eWidthPercentRelation == static_cast<const SwFormatFrameSize&>(rAttr).GetWidthPercentRelation() &&
m_nHeightPercent == static_cast<const SwFormatFrameSize&>(rAttr).GetHeightPercent() &&
@@ -219,8 +232,8 @@ bool SwFormatFrameSize::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
case MID_FRMSIZE_SIZE:
{
awt::Size aTmp;
- aTmp.Height = convertTwipToMm100(m_aSize.Height());
- aTmp.Width = convertTwipToMm100(m_aSize.Width());
+ aTmp.Height = convertTwipToMm100(GetHeight());
+ aTmp.Width = convertTwipToMm100(GetWidth());
rVal <<= aTmp;
}
break;
@@ -243,14 +256,14 @@ bool SwFormatFrameSize::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
rVal <<= SwFormatFrameSize::SYNCED == GetWidthPercent();
break;
case MID_FRMSIZE_WIDTH :
- rVal <<= static_cast<sal_Int32>(convertTwipToMm100(m_aSize.Width()));
+ rVal <<= static_cast<sal_Int32>(convertTwipToMm100(GetWidth()));
break;
case MID_FRMSIZE_HEIGHT:
// #95848# returned size should never be zero.
// (there was a bug that allowed for setting height to 0.
// Thus there some documents existing with that not allowed
// attribute value which may cause problems on import.)
- rVal <<= static_cast<sal_Int32>(convertTwipToMm100(m_aSize.Height() < MINLAY ? MINLAY : m_aSize.Height() ));
+ rVal <<= static_cast<sal_Int32>(convertTwipToMm100(GetHeight() < MINLAY ? MINLAY : GetHeight() ));
break;
case MID_FRMSIZE_SIZE_TYPE:
rVal <<= static_cast<sal_Int16>(GetHeightSizeType());
@@ -285,7 +298,7 @@ bool SwFormatFrameSize::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
aTmp.Height() = convertMm100ToTwip(aTmp.Height());
aTmp.Width() = convertMm100ToTwip(aTmp.Width());
}
- m_aSize = aTmp;
+ SetSize(aTmp);
}
}
break;
@@ -350,7 +363,7 @@ bool SwFormatFrameSize::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
nWd = convertMm100ToTwip(nWd);
if(nWd < MINLAY)
nWd = MINLAY;
- m_aSize.Width() = nWd;
+ SetWidth(nWd);
}
else
bRet = false;
@@ -365,7 +378,7 @@ bool SwFormatFrameSize::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
nHg = convertMm100ToTwip(nHg);
if(nHg < MINLAY)
nHg = MINLAY;
- m_aSize.Height() = nHg;
+ SetHeight(nHg);
}
else
bRet = false;
@@ -411,7 +424,7 @@ void SwFormatFrameSize::dumpAsXml(xmlTextWriterPtr pWriter) const
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
std::stringstream aSize;
- aSize << m_aSize;
+ aSize << GetSize();
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("size"), BAD_CAST(aSize.str().c_str()));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("eFrameHeightType"), BAD_CAST(OString::number(m_eFrameHeightType).getStr()));
diff --git a/sw/source/uibase/uiview/viewtab.cxx b/sw/source/uibase/uiview/viewtab.cxx
index 2434e42a80d5..145a17cb8088 100644
--- a/sw/source/uibase/uiview/viewtab.cxx
+++ b/sw/source/uibase/uiview/viewtab.cxx
@@ -300,7 +300,7 @@ void SwView::ExecTabWin( SfxRequest const & rReq )
}
SwFormatFrameSize aSize( pFormat->GetFrameSize() );
- long nOldWidth = static_cast<long>(aSize.GetWidth());
+ long nOldWidth = aSize.GetWidth();
if(aSize.GetWidthPercent())
{
@@ -317,7 +317,7 @@ void SwView::ExecTabWin( SfxRequest const & rReq )
{
SwFormatCol aCol(pFormat->GetCol());
- ::ResizeFrameCols(aCol, nOldWidth, static_cast<long>(aSize.GetWidth()), nDeltaX );
+ ::ResizeFrameCols(aCol, nOldWidth, aSize.GetWidth(), nDeltaX );
aSet.Put(aCol);
}