SdrObjCustomShape::AdjustTextFrameWidthAndHeight: allow external text

So that in Writer, in case we're using Writer TextFrames to handle the
content of a shape, it's still possible to inform the custom shape about
the automatic size of the text, just like when native editeng text is
used.

Change-Id: I2534b942a9b2d62d7aa009ffbfa8d76feb011f92
This commit is contained in:
Miklos Vajna
2014-06-27 13:43:13 +02:00
parent f2ad42f97b
commit 4f33a0961d
2 changed files with 52 additions and 29 deletions

View File

@@ -136,6 +136,7 @@ protected:
virtual void AdaptTextMinSize() SAL_OVERRIDE;
OUString aName;
Size m_aSuggestedTextFrameSize;
public:
@@ -212,6 +213,12 @@ public:
virtual bool MovCreate(SdrDragStat& rStat) SAL_OVERRIDE; // #i37448#
virtual bool EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd) SAL_OVERRIDE;
/**
* Allows suggesting the text frame size: in case the application has its
* own text associated to the shape, instead of using the shape's editeng
* text.
*/
void SuggestTextFrameSize(Size aSuggestedTextFrameSize);
virtual bool AdjustTextFrameWidthAndHeight(Rectangle& rR, bool bHgt = true, bool bWdt = true) const SAL_OVERRIDE;
virtual bool NbcAdjustTextFrameWidthAndHeight(bool bHgt = true, bool bWdt = true) SAL_OVERRIDE;
virtual bool AdjustTextFrameWidthAndHeight(bool bHgt = true, bool bWdt = true) SAL_OVERRIDE;

View File

@@ -2312,9 +2312,17 @@ void SdrObjCustomShape::SetVerticalWriting( bool bVertical )
}
}
}
void SdrObjCustomShape::SuggestTextFrameSize(Size aSuggestedTextFrameSize)
{
m_aSuggestedTextFrameSize = aSuggestedTextFrameSize;
}
bool SdrObjCustomShape::AdjustTextFrameWidthAndHeight(Rectangle& rR, bool bHgt, bool bWdt) const
{
if ( pModel && HasText() && !rR.IsEmpty() )
// Either we have text or the application has native text and suggested its size to us.
bool bHasText = HasText() || (m_aSuggestedTextFrameSize.Width() != 0 && m_aSuggestedTextFrameSize.Height() != 0);
if ( pModel && bHasText && !rR.IsEmpty() )
{
bool bWdtGrow=bWdt && IsAutoGrowWidth();
bool bHgtGrow=bHgt && IsAutoGrowHeight();
@@ -2353,6 +2361,8 @@ bool SdrObjCustomShape::AdjustTextFrameWidthAndHeight(Rectangle& rR, bool bHgt,
if ( aSiz.Height() < 2 )
aSiz.Height() = 2; // minimum size=2
if (HasText())
{
if(pEdtOutl)
{
pEdtOutl->SetMaxAutoPaperSize( aSiz );
@@ -2389,6 +2399,12 @@ bool SdrObjCustomShape::AdjustTextFrameWidthAndHeight(Rectangle& rR, bool bHgt,
nHgt = rOutliner.GetTextHeight()+1; // a little more tolerance
rOutliner.Clear();
}
}
else
{
nHgt = m_aSuggestedTextFrameSize.Height();
nWdt = m_aSuggestedTextFrameSize.Width();
}
if ( nWdt < nMinWdt )
nWdt = nMinWdt;
if ( nWdt > nMaxWdt )