From 120e469d176026ceb59abbf74d2ad255323cbc9a Mon Sep 17 00:00:00 2001 From: Armin Le Grand Date: Thu, 19 Sep 2013 10:11:03 +0000 Subject: i#115391 better support for MinTextSize settings ... for TextShapes and CustomShapes Conflicts: include/svx/svdotext.hxx svx/source/sdr/properties/customshapeproperties.cxx svx/source/svdraw/svdoashp.cxx svx/source/svdraw/svdotext.cxx svx/source/svdraw/svdotxdr.cxx svx/source/svdraw/svdotxtr.cxx Change-Id: Ie6f490801b6887568135ed5f83c8bbe7ab6daa08 --- .../sdr/properties/customshapeproperties.cxx | 100 ++++++++++---------- svx/source/svdraw/svdoashp.cxx | 101 +++++++++++---------- svx/source/svdraw/svdotext.cxx | 97 ++++++++++++++++---- svx/source/svdraw/svdotxdr.cxx | 20 +--- svx/source/svdraw/svdotxtr.cxx | 31 +++++-- 5 files changed, 210 insertions(+), 139 deletions(-) (limited to 'svx') diff --git a/svx/source/sdr/properties/customshapeproperties.cxx b/svx/source/sdr/properties/customshapeproperties.cxx index 13f167cf2a2d..35b4d07ec087 100644 --- a/svx/source/sdr/properties/customshapeproperties.cxx +++ b/svx/source/sdr/properties/customshapeproperties.cxx @@ -34,13 +34,19 @@ namespace sdr { void CustomShapeProperties::UpdateTextFrameStatus() { - SdrTextObj& rObj = (SdrTextObj&)GetSdrObject(); - SdrTextAutoGrowHeightItem& rAutoGrowHeightItem = - (SdrTextAutoGrowHeightItem&)rObj.GetMergedItem( SDRATTR_TEXT_AUTOGROWHEIGHT ); - rObj.bTextFrame = rAutoGrowHeightItem.GetValue(); + 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 recursion, 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) @@ -67,6 +73,7 @@ namespace sdr // end 0, 0)); } + bool CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem ) const { sal_Bool bAllowItemChange = sal_True; @@ -79,6 +86,7 @@ namespace sdr bAllowItemChange = TextProperties::AllowItemChange( nWhich, pNewItem ); return bAllowItemChange; } + void CustomShapeProperties::ClearObjectItem(const sal_uInt16 nWhich) { if ( !nWhich ) @@ -96,6 +104,7 @@ namespace sdr else TextProperties::ClearObjectItem( nWhich ); } + void CustomShapeProperties::ClearObjectItemDirect(const sal_uInt16 nWhich) { if ( !nWhich ) @@ -111,66 +120,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(); + 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(); - } // call parent TextProperties::ItemChange( nWhich, pNewItem ); - rObj.InvalidateRenderGeometry(); + // update bTextFrame and RenderGeometry + UpdateTextFrameStatus(); } + void CustomShapeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, 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) { @@ -189,14 +195,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() ) @@ -211,15 +218,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 diff --git a/svx/source/svdraw/svdoashp.cxx b/svx/source/svdraw/svdoashp.cxx index dee596023efa..6ced8d646ac1 100644 --- a/svx/source/svdraw/svdoashp.cxx +++ b/svx/source/svdraw/svdoashp.cxx @@ -1443,27 +1443,60 @@ 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))); + + 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(); @@ -1482,20 +1515,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(); } @@ -2197,25 +2220,9 @@ bool 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 ); - } - // re-calculate text frame - NbcAdjustTextFrameWidthAndHeight(); - } + // #115391# + AdaptTextMinSize(); + SetRectsDirty(); return ( eCmd == SDRCREATE_FORCEEND || rStat.GetPointAnz() >= 2 ); } diff --git a/svx/source/svdraw/svdotext.cxx b/svx/source/svdraw/svdotext.cxx index 214f22af597f..5c24ec0848ea 100644 --- a/svx/source/svdraw/svdotext.cxx +++ b/svx/source/svdraw/svdotext.cxx @@ -542,39 +542,98 @@ bool SdrTextObj::NbcSetEckenradius(long nRad) return true; } -bool SdrTextObj::NbcSetMinTextFrameHeight(long nHgt) +bool SdrTextObj::NbcSetAutoGrowHeight(bool bAuto) { - if( bTextFrame && ( !pModel || !pModel->isLocked() ) ) // #i44922# + if(bTextFrame) { - SetObjectItem(SdrTextMinFrameHeightItem(nHgt)); - - // use bDisableAutoWidthOnDragging as - // bDisableAutoHeightOnDragging if vertical. - if(IsVerticalWriting() && bDisableAutoWidthOnDragging) - { - bDisableAutoWidthOnDragging = false; - SetObjectItem(SdrTextAutoGrowHeightItem(false)); - } + SetObjectItem(SdrTextAutoGrowHeightItem(bAuto)); + return true; + } + return false; +} +bool SdrTextObj::NbcSetMaxTextFrameHeight(long nHgt) +{ + if(bTextFrame) + { + SetObjectItem(SdrTextMaxFrameHeightItem(nHgt)); return true; } return false; } -bool SdrTextObj::NbcSetMinTextFrameWidth(long nWdt) +// #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() ) ) // #i44922# + if(bTextFrame && (!pModel || !pModel->isLocked())) { - SetObjectItem(SdrTextMinFrameWidthItem(nWdt)); + const bool bW(IsAutoGrowWidth()); + const bool bH(IsAutoGrowHeight()); - // use bDisableAutoWidthOnDragging only - // when not vertical. - if(!IsVerticalWriting() && bDisableAutoWidthOnDragging) + if(bW || bH) { - bDisableAutoWidthOnDragging = false; - SetObjectItem(SdrTextAutoGrowWidthItem(false)); + SfxItemSet aSet(GetObjectItemSet()); + + 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(); } + } +} +bool SdrTextObj::NbcSetAutoGrowWidth(bool bAuto) +{ + if(bTextFrame) + { + SetObjectItem(SdrTextAutoGrowWidthItem(bAuto)); + return true; + } + return false; +} + +bool SdrTextObj::NbcSetMaxTextFrameWidth(long nWdt) +{ + if(bTextFrame) + { + SetObjectItem(SdrTextMaxFrameWidthItem(nWdt)); + return true; + } + return false; +} + +bool SdrTextObj::NbcSetFitToSize(SdrFitToSizeType eFit) +{ + if(bTextFrame) + { + SetObjectItem(SdrTextFitToSizeTypeItem(eFit)); return true; } return false; diff --git a/svx/source/svdraw/svdotxdr.cxx b/svx/source/svdraw/svdotxdr.cxx index 7e81766c2e90..cd9868553c09 100644 --- a/svx/source/svdraw/svdotxdr.cxx +++ b/svx/source/svdraw/svdotxdr.cxx @@ -210,22 +210,10 @@ bool 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); - } - // re-calculate text frame - NbcAdjustTextFrameWidthAndHeight(); - } + + // #115391# + AdaptTextMinSize(); + SetRectsDirty(); if (HAS_BASE(SdrRectObj,this)) { ((SdrRectObj*)this)->SetXPolyDirty(); diff --git a/svx/source/svdraw/svdotxtr.cxx b/svx/source/svdraw/svdotxtr.cxx index 409af9f24c07..a0267ddae4ca 100644 --- a/svx/source/svdraw/svdotxtr.cxx +++ b/svx/source/svdraw/svdotxtr.cxx @@ -58,11 +58,15 @@ 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())) { - if (nTWdt0!=nTWdt1 && IsAutoGrowWidth() ) NbcSetMinTextFrameWidth(nTWdt1); - if (nTHgt0!=nTHgt1 && IsAutoGrowHeight()) NbcSetMinTextFrameHeight(nTHgt1); + + // #115391# + AdaptTextMinSize(); + + if (bTextFrame && (pModel==NULL || !pModel->IsPasteResize())) + { NbcAdjustTextFrameWidthAndHeight(); } + ImpCheckShear(); SetRectsDirty(); } @@ -83,11 +87,15 @@ 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); + + // #115391# + AdaptTextMinSize(); + + if(bTextFrame) + { NbcAdjustTextFrameWidthAndHeight(); } + SetRectsDirty(); } @@ -185,13 +193,18 @@ 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())) { - if (nTWdt0!=nTWdt1 && IsAutoGrowWidth() ) NbcSetMinTextFrameWidth(nTWdt1); - if (nTHgt0!=nTHgt1 && IsAutoGrowHeight()) NbcSetMinTextFrameHeight(nTHgt1); + + // #115391# + AdaptTextMinSize(); + + if(bTextFrame && (!pModel || !pModel->IsPasteResize())) + { NbcAdjustTextFrameWidthAndHeight(); } + ImpCheckShear(); SetRectsDirty(); } -- cgit