Kaydet (Commit) 39fe8aa1 authored tarafından Armin Le Grand's avatar Armin Le Grand

i115391 better support for MinTextSize settings for TextShapes and CustomShapes

üst 112710da
......@@ -49,6 +49,10 @@ namespace sdr
// react on Item change
virtual void ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem);
// Called after ItemChange() is done for all items. Allows local reactions on
// specific item changes
virtual void PostItemChange(const sal_uInt16 nWhich);
// clear single item
virtual void ClearObjectItem(const sal_uInt16 nWhich = 0);
......
......@@ -131,6 +131,10 @@ public:
static basegfx::B2DPolyPolygon GetLineGeometry( const SdrObjCustomShape* pCustomShape, const sal_Bool bBezierAllowed );
protected:
// #115391# new method for SdrObjCustomShape and SdrTextObj to correctly handle and set
// SdrTextMinFrameWidthItem and SdrTextMinFrameHeightItem based on all settings, necessities
// and object sizes
virtual void AdaptTextMinSize();
String aName;
......
......@@ -289,13 +289,16 @@ protected:
virtual void RestGeoData(const SdrObjGeoData& rGeo);
FASTBOOL NbcSetEckenradius(long nRad);
FASTBOOL NbcSetAutoGrowHeight(bool bAuto);
FASTBOOL NbcSetMinTextFrameHeight(long nHgt);
FASTBOOL NbcSetMaxTextFrameHeight(long nHgt);
FASTBOOL NbcSetAutoGrowWidth(bool bAuto);
FASTBOOL NbcSetMinTextFrameWidth(long nWdt);
FASTBOOL NbcSetMaxTextFrameWidth(long nWdt);
FASTBOOL NbcSetFitToSize(SdrFitToSizeType eFit);
// #115391# new method for SdrObjCustomShape and SdrTextObj to correctly handle and set
// SdrTextMinFrameWidthItem and SdrTextMinFrameHeightItem based on all settings, necessities
// and object sizes
virtual void AdaptTextMinSize();
// Konstruktoren fuer beschriftete Zeichenobjekte
SdrTextObj();
SdrTextObj(const Rectangle& rNewRect);
......
......@@ -41,13 +41,19 @@ namespace sdr
{
void CustomShapeProperties::UpdateTextFrameStatus()
{
SdrTextObj& rObj = (SdrTextObj&)GetSdrObject();
SdrTextAutoGrowHeightItem& rAutoGrowHeightItem =
(SdrTextAutoGrowHeightItem&)rObj.GetMergedItem( SDRATTR_TEXT_AUTOGROWHEIGHT );
rObj.bTextFrame = rAutoGrowHeightItem.GetValue() != 0;
SdrObjCustomShape& rObj = static_cast< SdrObjCustomShape& >(GetSdrObject());
const bool bOld(rObj.bTextFrame);
if ( rObj.bTextFrame )
rObj.NbcAdjustTextFrameWidthAndHeight();
rObj.bTextFrame = 0 != static_cast< const SdrTextAutoGrowHeightItem& >(GetObjectItemSet().Get(SDRATTR_TEXT_AUTOGROWHEIGHT)).GetValue();
if(rObj.bTextFrame != bOld)
{
rObj.InvalidateRenderGeometry();
// #115391# Potential recursuin, since it calls SetObjectItemSet again, but rObj.bTextFrame
// will not change again, thus it will be only one level and terminate
rObj.AdaptTextMinSize();
}
}
SfxItemSet& CustomShapeProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
......@@ -74,6 +80,7 @@ namespace sdr
// end
0, 0));
}
sal_Bool CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem ) const
{
sal_Bool bAllowItemChange = sal_True;
......@@ -86,6 +93,7 @@ namespace sdr
bAllowItemChange = TextProperties::AllowItemChange( nWhich, pNewItem );
return bAllowItemChange;
}
void CustomShapeProperties::ClearObjectItem(const sal_uInt16 nWhich)
{
if ( !nWhich )
......@@ -103,6 +111,7 @@ namespace sdr
else
TextProperties::ClearObjectItem( nWhich );
}
void CustomShapeProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
{
if ( !nWhich )
......@@ -118,66 +127,63 @@ namespace sdr
else
TextProperties::ClearObjectItemDirect( nWhich );
}
void CustomShapeProperties::ItemSetChanged(const SfxItemSet& rSet)
{
SdrObjCustomShape& rObj = (SdrObjCustomShape&)GetSdrObject();
// call parent
TextProperties::ItemSetChanged(rSet);
// update bTextFrame and RenderGeometry
UpdateTextFrameStatus();
}
if( SFX_ITEM_SET == rSet.GetItemState( SDRATTR_TEXT_AUTOGROWHEIGHT ) )
void CustomShapeProperties::PostItemChange(const sal_uInt16 nWhich)
{
switch(nWhich)
{
rObj.bTextFrame = ((SdrTextAutoGrowHeightItem&)rSet.Get( SDRATTR_TEXT_AUTOGROWHEIGHT )).GetValue() != 0;
case SDRATTR_TEXT_AUTOGROWHEIGHT:
{
// #115391# update bTextFrame and RenderGeometry using AdaptTextMinSize()
UpdateTextFrameStatus();
break;
}
default:
{
break;
}
}
// call parent
TextProperties::ItemSetChanged(rSet);
// local changes, removing cached objects
rObj.InvalidateRenderGeometry();
TextProperties::PostItemChange(nWhich);
}
void CustomShapeProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
{
SdrObjCustomShape& rObj = (SdrObjCustomShape&)GetSdrObject();
//OutlinerParaObject* pParaObj = rObj.GetOutlinerParaObject();
if( pNewItem && ( SDRATTR_TEXT_AUTOGROWHEIGHT == nWhich ) )
{
rObj.bTextFrame = ((SdrTextAutoGrowHeightItem*)pNewItem)->GetValue() != 0;
}
// call parent
TextProperties::ItemChange( nWhich, pNewItem );
rObj.InvalidateRenderGeometry();
// update bTextFrame and RenderGeometry
UpdateTextFrameStatus();
}
void CustomShapeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr)
{
// call parent
TextProperties::SetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr );
// update bTextFrame and RenderGeometry
UpdateTextFrameStatus();
}
void CustomShapeProperties::ForceDefaultAttributes()
{
// update bTextFrame and RenderGeometry
UpdateTextFrameStatus();
/* SJ: Following is no good if creating customshapes, leading to objects that are white after loading via xml
SdrTextObj& rObj = (SdrTextObj&)GetSdrObject();
sal_Bool bTextFrame(rObj.IsTextFrame());
// force ItemSet
GetObjectItemSet();
if(bTextFrame)
{
mpItemSet->Put(XLineStyleItem(XLINE_NONE));
mpItemSet->Put(XFillColorItem(String(), Color(COL_WHITE)));
mpItemSet->Put(XFillStyleItem(XFILL_NONE));
}
else
{
mpItemSet->Put(SvxAdjustItem(SVX_ADJUST_CENTER));
mpItemSet->Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_CENTER));
mpItemSet->Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
}
*/
// SJ: Following is no good if creating customshapes, leading to objects that are white after loading via xml
// This means: Do *not* call parent here is by purpose...
}
CustomShapeProperties::CustomShapeProperties(SdrObject& rObj)
: TextProperties(rObj)
{
......@@ -196,14 +202,15 @@ namespace sdr
{
return *(new CustomShapeProperties(*this, rObj));
}
void CustomShapeProperties::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
{
TextProperties::Notify( rBC, rHint );
sal_Bool bRemoveRenderGeometry = sal_False;
const SfxStyleSheetHint *pStyleHint = PTR_CAST( SfxStyleSheetHint, &rHint );
const SfxSimpleHint *pSimpleHint = PTR_CAST( SfxSimpleHint, &rHint );
if ( pStyleHint && pStyleHint->GetStyleSheet() == GetStyleSheet() )
{
switch( pStyleHint->GetHint() )
......@@ -218,15 +225,12 @@ namespace sdr
{
bRemoveRenderGeometry = sal_True;
}
if ( bRemoveRenderGeometry )
{
// update bTextFrame and RenderGeometry
UpdateTextFrameStatus();
// local changes, removing cached objects
SdrObjCustomShape& rObj = (SdrObjCustomShape&)GetSdrObject();
rObj.InvalidateRenderGeometry();
}
}
} // end of namespace properties
} // end of namespace sdr
......
......@@ -1719,27 +1719,61 @@ const Rectangle& SdrObjCustomShape::GetLogicRect() const
{
return SdrTextObj::GetLogicRect();
}
void SdrObjCustomShape::NbcSetSnapRect( const Rectangle& rRect )
// #115391# This implementation is based on the TextFrame size of the CustomShape and the
// state of the ResizeShapeToFitText flag to correctly set TextMinFrameWidth/Height
void SdrObjCustomShape::AdaptTextMinSize()
{
aRect=rRect;
ImpJustifyRect(aRect);
InvalidateRenderGeometry();
Rectangle aTextBound( aRect );
if ( GetTextBounds( aTextBound ) )
if(!pModel || !pModel->IsPasteResize())
{
if ( pModel==NULL || !pModel->IsPasteResize() )
const bool bResizeShapeToFitText(0 != static_cast< const SdrTextAutoGrowHeightItem& >(GetObjectItem(SDRATTR_TEXT_AUTOGROWHEIGHT)).GetValue());
SfxItemSet aSet(GetObjectItemSet());
bool bChanged(false);
if(bResizeShapeToFitText)
{
long nHDist=GetTextLeftDistance()+GetTextRightDistance();
long nVDist=GetTextUpperDistance()+GetTextLowerDistance();
long nTWdt=aTextBound.GetWidth ()-1-nHDist; if (nTWdt<0) nTWdt=0;
long nTHgt=aTextBound.GetHeight()-1-nVDist; if (nTHgt<0) nTHgt=0;
if ( IsAutoGrowWidth() )
NbcSetMinTextFrameWidth( nTWdt );
if ( IsAutoGrowHeight() )
NbcSetMinTextFrameHeight( nTHgt );
// always reset MinWidthHeight to zero to only rely on text size and frame size
// to allow resizing being completely dependent on text size only
aSet.Put(SdrTextMinFrameWidthItem(0));
aSet.Put(SdrTextMinFrameHeightItem(0));
bChanged = true;
}
else
{
// recreate from CustomShape-specific TextBounds
Rectangle aTextBound(aRect);
if(GetTextBounds(aTextBound))
{
const long nHDist(GetTextLeftDistance() + GetTextRightDistance());
const long nVDist(GetTextUpperDistance() + GetTextLowerDistance());
const long nTWdt(std::max(long(0), (long)(aTextBound.GetWidth() - 1 - nHDist)));
const long nTHgt(std::max(long(0), (long)(aTextBound.GetHeight() - 1 - nVDist)));
SfxItemSet aSet(GetObjectItemSet());
aSet.Put(SdrTextMinFrameWidthItem(nTWdt));
aSet.Put(SdrTextMinFrameHeightItem(nTHgt));
bChanged = true;
}
}
if(bChanged)
{
SetObjectItemSet(aSet);
NbcAdjustTextFrameWidthAndHeight();
}
}
}
void SdrObjCustomShape::NbcSetSnapRect( const Rectangle& rRect )
{
aRect=rRect;
ImpJustifyRect(aRect);
InvalidateRenderGeometry();
// #115391#
AdaptTextMinSize();
ImpCheckShear();
SetRectsDirty();
SetChanged();
......@@ -1758,20 +1792,10 @@ void SdrObjCustomShape::NbcSetLogicRect( const Rectangle& rRect )
aRect = rRect;
ImpJustifyRect( aRect );
InvalidateRenderGeometry();
Rectangle aTextBound( aRect );
if ( GetTextBounds( aTextBound ) )
{
long nHDist=GetTextLeftDistance()+GetTextRightDistance();
long nVDist=GetTextUpperDistance()+GetTextLowerDistance();
long nTWdt=aTextBound.GetWidth()-1-nHDist; if (nTWdt<0) nTWdt=0;
long nTHgt=aTextBound.GetHeight()-1-nVDist; if (nTHgt<0) nTHgt=0;
if ( IsAutoGrowWidth() )
NbcSetMinTextFrameWidth( nTWdt );
if ( IsAutoGrowHeight() )
NbcSetMinTextFrameHeight( nTHgt );
NbcAdjustTextFrameWidthAndHeight();
}
// #115391#
AdaptTextMinSize();
SetRectsDirty();
SetChanged();
}
......@@ -2487,25 +2511,9 @@ FASTBOOL SdrObjCustomShape::EndCreate( SdrDragStat& rStat, SdrCreateCmd eCmd )
{
DragCreateObject( rStat );
if ( bTextFrame )
{
if ( IsAutoGrowHeight() )
{
// MinTextHeight
long nHgt=aRect.GetHeight()-1;
if (nHgt==1) nHgt=0;
NbcSetMinTextFrameHeight( nHgt );
}
if ( IsAutoGrowWidth() )
{
// MinTextWidth
long nWdt=aRect.GetWidth()-1;
if (nWdt==1) nWdt=0;
NbcSetMinTextFrameWidth( nWdt );
}
// Textrahmen neu berechnen
NbcAdjustTextFrameWidthAndHeight();
}
// #115391#
AdaptTextMinSize();
SetRectsDirty();
return ( eCmd == SDRCREATE_FORCEEND || rStat.GetPointAnz() >= 2 );
}
......
......@@ -644,23 +644,51 @@ FASTBOOL SdrTextObj::NbcSetAutoGrowHeight(bool bAuto)
return sal_False;
}
FASTBOOL SdrTextObj::NbcSetMinTextFrameHeight(long nHgt)
// #115391# This implementation is based on the object size (aRect) and the
// states of IsAutoGrowWidth/Height to correctly set TextMinFrameWidth/Height
void SdrTextObj::AdaptTextMinSize()
{
if( bTextFrame && ( !pModel || !pModel->isLocked() ) ) // SJ: #i44922#
if(bTextFrame && (!pModel || !pModel->isLocked()))
{
SetObjectItem(SdrTextMinFrameHeightItem(nHgt));
const bool bW(IsAutoGrowWidth());
const bool bH(IsAutoGrowHeight());
// #84974# use bDisableAutoWidthOnDragging as
// bDisableAutoHeightOnDragging if vertical.
if(IsVerticalWriting() && bDisableAutoWidthOnDragging)
if(bW || bH)
{
bDisableAutoWidthOnDragging = sal_False;
SetObjectItem(SdrTextAutoGrowHeightItem(sal_False));
}
SfxItemSet aSet(GetObjectItemSet());
return sal_True;
if(bW)
{
const long nDist(GetTextLeftDistance() + GetTextRightDistance());
const long nW(std::max(long(0), (long)(aRect.GetWidth() - 1 - nDist)));
aSet.Put(SdrTextMinFrameWidthItem(nW));
if(!IsVerticalWriting() && bDisableAutoWidthOnDragging)
{
bDisableAutoWidthOnDragging = true;
aSet.Put(SdrTextAutoGrowWidthItem(false));
}
}
if(bH)
{
const long nDist(GetTextUpperDistance() + GetTextLowerDistance());
const long nH(std::max(long(0), (long)(aRect.GetHeight() - 1 - nDist)));
aSet.Put(SdrTextMinFrameHeightItem(nH));
if(IsVerticalWriting() && bDisableAutoWidthOnDragging)
{
bDisableAutoWidthOnDragging = false;
SetObjectItem(SdrTextAutoGrowHeightItem(false));
}
}
SetObjectItemSet(aSet);
NbcAdjustTextFrameWidthAndHeight();
}
}
return sal_False;
}
FASTBOOL SdrTextObj::NbcSetMaxTextFrameHeight(long nHgt)
......@@ -683,25 +711,6 @@ FASTBOOL SdrTextObj::NbcSetAutoGrowWidth(bool bAuto)
return sal_False;
}
FASTBOOL SdrTextObj::NbcSetMinTextFrameWidth(long nWdt)
{
if( bTextFrame && ( !pModel || !pModel->isLocked() ) ) // SJ: #i44922#
{
SetObjectItem(SdrTextMinFrameWidthItem(nWdt));
// #84974# use bDisableAutoWidthOnDragging only
// when not vertical.
if(!IsVerticalWriting() && bDisableAutoWidthOnDragging)
{
bDisableAutoWidthOnDragging = sal_False;
SetObjectItem(SdrTextAutoGrowWidthItem(sal_False));
}
return sal_True;
}
return sal_False;
}
FASTBOOL SdrTextObj::NbcSetMaxTextFrameWidth(long nWdt)
{
if(bTextFrame)
......
......@@ -229,22 +229,10 @@ FASTBOOL SdrTextObj::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
{
rStat.TakeCreateRect(aRect);
ImpJustifyRect(aRect);
if (bTextFrame) {
if (IsAutoGrowHeight()) {
// MinTextHeight
long nHgt=aRect.GetHeight()-1;
if (nHgt==1) nHgt=0;
NbcSetMinTextFrameHeight(nHgt);
}
if (IsAutoGrowWidth()) {
// MinTextWidth
long nWdt=aRect.GetWidth()-1;
if (nWdt==1) nWdt=0;
NbcSetMinTextFrameWidth(nWdt);
}
// Textrahmen neu berechnen
NbcAdjustTextFrameWidthAndHeight();
}
// #115391#
AdaptTextMinSize();
SetRectsDirty();
if (HAS_BASE(SdrRectObj,this)) {
((SdrRectObj*)this)->SetXPolyDirty();
......
......@@ -77,14 +77,20 @@ void SdrTextObj::NbcSetSnapRect(const Rectangle& rRect)
long nTHgt1=rRect.GetHeight()-1-nVDist; if (nTHgt1<0) nTHgt1=0;
aRect=rRect;
ImpJustifyRect(aRect);
if (bTextFrame && (pModel==NULL || !pModel->IsPasteResize())) { // #51139#
if (nTWdt0!=nTWdt1 && IsAutoGrowWidth() ) NbcSetMinTextFrameWidth(nTWdt1);
if (nTHgt0!=nTHgt1 && IsAutoGrowHeight()) NbcSetMinTextFrameHeight(nTHgt1);
if (GetFitToSize()==SDRTEXTFIT_RESIZEATTR) {
// #115391#
AdaptTextMinSize();
if (bTextFrame && (pModel==NULL || !pModel->IsPasteResize()))
{
if(SDRTEXTFIT_RESIZEATTR == GetFitToSize())
{
NbcResizeTextAttributes(Fraction(nTWdt1,nTWdt0),Fraction(nTHgt1,nTHgt0));
}
NbcAdjustTextFrameWidthAndHeight();
}
ImpCheckShear();
SetRectsDirty();
}
......@@ -105,14 +111,20 @@ void SdrTextObj::NbcSetLogicRect(const Rectangle& rRect)
long nTHgt1=rRect.GetHeight()-1-nVDist; if (nTHgt1<0) nTHgt1=0;
aRect=rRect;
ImpJustifyRect(aRect);
if (bTextFrame) {
if (nTWdt0!=nTWdt1 && IsAutoGrowWidth() ) NbcSetMinTextFrameWidth(nTWdt1);
if (nTHgt0!=nTHgt1 && IsAutoGrowHeight()) NbcSetMinTextFrameHeight(nTHgt1);
if (GetFitToSize()==SDRTEXTFIT_RESIZEATTR) {
// #115391#
AdaptTextMinSize();
if(bTextFrame)
{
if(SDRTEXTFIT_RESIZEATTR == GetFitToSize())
{
NbcResizeTextAttributes(Fraction(nTWdt1,nTWdt0),Fraction(nTHgt1,nTHgt0));
}
NbcAdjustTextFrameWidthAndHeight();
}
SetRectsDirty();
}
......@@ -219,16 +231,23 @@ void SdrTextObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fract
}
ImpJustifyRect(aRect);
long nTWdt1=aRect.GetWidth ()-1-nHDist; if (nTWdt1<0) nTWdt1=0;
long nTHgt1=aRect.GetHeight()-1-nVDist; if (nTHgt1<0) nTHgt1=0;
if (bTextFrame && (pModel==NULL || !pModel->IsPasteResize())) { // #51139#
if (nTWdt0!=nTWdt1 && IsAutoGrowWidth() ) NbcSetMinTextFrameWidth(nTWdt1);
if (nTHgt0!=nTHgt1 && IsAutoGrowHeight()) NbcSetMinTextFrameHeight(nTHgt1);
if (GetFitToSize()==SDRTEXTFIT_RESIZEATTR) {
// #115391#
AdaptTextMinSize();
if(bTextFrame && (!pModel || !pModel->IsPasteResize()))
{
if(SDRTEXTFIT_RESIZEATTR == GetFitToSize())
{
NbcResizeTextAttributes(Fraction(nTWdt1,nTWdt0),Fraction(nTHgt1,nTHgt0));
}
NbcAdjustTextFrameWidthAndHeight();
}
ImpCheckShear();
SetRectsDirty();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment