diff options
author | Armin Le Grand <Armin.Le.Grand@cib.de> | 2017-08-30 20:40:32 +0200 |
---|---|---|
committer | Armin Le Grand <Armin.Le.Grand@cib.de> | 2017-09-15 12:58:03 +0200 |
commit | a9c59cbfb9e16469b389db0b4d6befe196d0e2a0 (patch) | |
tree | a031682ae21ec46bb9c6e1e30b0110213e8e3dac /svx/source/dialog/framelink.cxx | |
parent | fe14ddf25003c0f79f9f8a249bc22d45f57a0068 (diff) |
borderline: Preparing further to use CellCoordinateSystem
Multiple cleanups, made svx::frame::Style a std::shared_ptr class,
preparing basing all border stuff on transformations, so it will
need a CellCoordinateSystem. Added stuff to get this Coordinate
System from the svx::frame::Cell using the Frame and knowledge
about ownerships
Change-Id: Ic2cb59cc92e648ac2fef72f22f8913479769d3e2
Diffstat (limited to 'svx/source/dialog/framelink.cxx')
-rw-r--r-- | svx/source/dialog/framelink.cxx | 153 |
1 files changed, 74 insertions, 79 deletions
diff --git a/svx/source/dialog/framelink.cxx b/svx/source/dialog/framelink.cxx index e5523fe5365e..cbabbcbc635b 100644 --- a/svx/source/dialog/framelink.cxx +++ b/svx/source/dialog/framelink.cxx @@ -41,64 +41,36 @@ using namespace editeng; namespace svx { namespace frame { - -namespace { - -/** Converts a width in twips to a width in another map unit (specified by fScale). */ -double lclScaleValue( double nValue, double fScale, sal_uInt16 nMaxWidth ) -{ - return std::min<double>(nValue * fScale, nMaxWidth); -} - -} // namespace - - // Classes - - -#define SCALEVALUE( value ) lclScaleValue( value, fScale, nMaxWidth ) - -Style::Style() : - meRefMode(RefMode::Centered), - mfPatternScale(1.0), - mnType(SvxBorderLineStyle::SOLID), - mpUsingCell(nullptr) +Style::Style() : maImplStyle(new implStyle()) { Clear(); } -Style::Style( double nP, double nD, double nS, SvxBorderLineStyle nType ) : - meRefMode(RefMode::Centered), - mfPatternScale(1.0), - mnType(nType), - mpUsingCell(nullptr) +Style::Style( double nP, double nD, double nS, SvxBorderLineStyle nType ) : maImplStyle(new implStyle()) { + maImplStyle->mnType = nType; Clear(); Set( nP, nD, nS ); } -Style::Style( const Color& rColorPrim, const Color& rColorSecn, const Color& rColorGap, bool bUseGapColor, - double nP, double nD, double nS, SvxBorderLineStyle nType ) : - meRefMode(RefMode::Centered), - mfPatternScale(1.0), - mnType(nType), - mpUsingCell(nullptr) +Style::Style( const Color& rColorPrim, const Color& rColorSecn, const Color& rColorGap, bool bUseGapColor, double nP, double nD, double nS, SvxBorderLineStyle nType ) : maImplStyle(new implStyle()) { + maImplStyle->mnType = nType; Set( rColorPrim, rColorSecn, rColorGap, bUseGapColor, nP, nD, nS ); } -Style::Style( const editeng::SvxBorderLine* pBorder, double fScale ) : - meRefMode(RefMode::Centered), - mfPatternScale(fScale), - mpUsingCell(nullptr) +Style::Style( const editeng::SvxBorderLine* pBorder, double fScale ) : maImplStyle(new implStyle()) { + maImplStyle->mfPatternScale = fScale; Set( pBorder, fScale ); } - -void Style::SetPatternScale( double fScale ) +double Style::GetWidth() const { - mfPatternScale = fScale; + implStyle* pTarget = maImplStyle.get(); + + return pTarget->mfPrim + pTarget->mfDist + pTarget->mfSecn; } void Style::Clear() @@ -115,66 +87,78 @@ void Style::Set( double nP, double nD, double nS ) >0 0 >0 nP 0 0 >0 >0 >0 nP nD nS */ - mfPrim = rtl::math::round(nP ? nP : nS, 2); - mfDist = rtl::math::round((nP && nS) ? nD : 0, 2); - mfSecn = rtl::math::round((nP && nD) ? nS : 0, 2); + implStyle* pTarget = maImplStyle.get(); + pTarget->mfPrim = rtl::math::round(nP ? nP : nS, 2); + pTarget->mfDist = rtl::math::round((nP && nS) ? nD : 0, 2); + pTarget->mfSecn = rtl::math::round((nP && nD) ? nS : 0, 2); } void Style::Set( const Color& rColorPrim, const Color& rColorSecn, const Color& rColorGap, bool bUseGapColor, double nP, double nD, double nS ) { - maColorPrim = rColorPrim; - maColorSecn = rColorSecn; - maColorGap = rColorGap; - mbUseGapColor = bUseGapColor; + implStyle* pTarget = maImplStyle.get(); + pTarget->maColorPrim = rColorPrim; + pTarget->maColorSecn = rColorSecn; + pTarget->maColorGap = rColorGap; + pTarget->mbUseGapColor = bUseGapColor; Set( nP, nD, nS ); } void Style::Set( const SvxBorderLine& rBorder, double fScale, sal_uInt16 nMaxWidth ) { - maColorPrim = rBorder.GetColorOut(); - maColorSecn = rBorder.GetColorIn(); - maColorGap = rBorder.GetColorGap(); - mbUseGapColor = rBorder.HasGapColor(); + implStyle* pTarget = maImplStyle.get(); + pTarget->maColorPrim = rBorder.GetColorOut(); + pTarget->maColorSecn = rBorder.GetColorIn(); + pTarget->maColorGap = rBorder.GetColorGap(); + pTarget->mbUseGapColor = rBorder.HasGapColor(); sal_uInt16 nPrim = rBorder.GetOutWidth(); sal_uInt16 nDist = rBorder.GetDistance(); sal_uInt16 nSecn = rBorder.GetInWidth(); - mnType = rBorder.GetBorderLineStyle(); + pTarget->mnType = rBorder.GetBorderLineStyle(); if( !nSecn ) // no or single frame border { - Set( SCALEVALUE( nPrim ), 0, 0 ); + Set( std::min<double>(nPrim * fScale, nMaxWidth), 0, 0 ); } else { - Set( SCALEVALUE( nPrim ), SCALEVALUE( nDist ), SCALEVALUE( nSecn ) ); + Set(std::min<double>(nPrim * fScale, nMaxWidth), std::min<double>(nDist * fScale, nMaxWidth), std::min<double>(nSecn * fScale, nMaxWidth)); // Enlarge the style if distance is too small due to rounding losses. - double nPixWidth = SCALEVALUE( nPrim + nDist + nSecn ); + double nPixWidth = std::min<double>((nPrim + nDist + nSecn) * fScale, nMaxWidth); + if( nPixWidth > GetWidth() ) - mfDist = nPixWidth - mfPrim - mfSecn; + { + pTarget->mfDist = nPixWidth - pTarget->mfPrim - pTarget->mfSecn; + } + // Shrink the style if it is too thick for the control. while( GetWidth() > nMaxWidth ) { // First decrease space between lines. - if (mfDist) - --mfDist; + if (pTarget->mfDist) + { + --(pTarget->mfDist); + continue; + } + // Still too thick? Decrease the line widths. - if( GetWidth() > nMaxWidth ) + if (pTarget->mfPrim != 0.0 && rtl::math::approxEqual(pTarget->mfPrim, pTarget->mfSecn)) { - if (mfPrim != 0.0 && rtl::math::approxEqual(mfPrim, mfSecn)) - { - // Both lines equal - decrease both to keep symmetry. - --mfPrim; - --mfSecn; - } - else - { - // Decrease each line for itself - if (mfPrim) - --mfPrim; - if ((GetWidth() > nMaxWidth) && mfSecn != 0.0) - --mfSecn; - } + // Both lines equal - decrease both to keep symmetry. + --(pTarget->mfPrim); + --(pTarget->mfSecn); + continue; + } + + // Decrease each line for itself + if (pTarget->mfPrim) + { + --(pTarget->mfPrim); + } + + if ((GetWidth() > nMaxWidth) && pTarget->mfSecn != 0.0) + { + --(pTarget->mfSecn); } } } @@ -183,23 +167,36 @@ void Style::Set( const SvxBorderLine& rBorder, double fScale, sal_uInt16 nMaxWid void Style::Set( const SvxBorderLine* pBorder, double fScale, sal_uInt16 nMaxWidth ) { if( pBorder ) + { Set( *pBorder, fScale, nMaxWidth ); + } else { Clear(); - mnType = SvxBorderLineStyle::SOLID; + maImplStyle->mnType = SvxBorderLineStyle::SOLID; } } Style& Style::MirrorSelf() { - if (mfSecn) - std::swap( mfPrim, mfSecn ); - if( meRefMode != RefMode::Centered ) - meRefMode = (meRefMode == RefMode::Begin) ? RefMode::End : RefMode::Begin; + implStyle* pTarget = maImplStyle.get(); + + if (pTarget->mfSecn) + { + std::swap( pTarget->mfPrim, pTarget->mfSecn ); + } + + if( pTarget->meRefMode != RefMode::Centered ) + { + pTarget->meRefMode = (pTarget->meRefMode == RefMode::Begin) ? RefMode::End : RefMode::Begin; + } + return *this; } +const Cell* Style::GetUsingCell() const { return maImplStyle->mpUsingCell; } +void Style::SetUsingCell(const Cell* pCell) { maImplStyle->mpUsingCell = pCell; } + bool operator==( const Style& rL, const Style& rR ) { return (rL.Prim() == rR.Prim()) && (rL.Dist() == rR.Dist()) && (rL.Secn() == rR.Secn()) && @@ -228,8 +225,6 @@ bool operator<( const Style& rL, const Style& rR ) return false; } -#undef SCALEVALUE - bool CheckFrameBorderConnectable( const Style& rLBorder, const Style& rRBorder, const Style& rTFromTL, const Style& rTFromT, const Style& rTFromTR, const Style& rBFromBL, const Style& rBFromB, const Style& rBFromBR ) |