summaryrefslogtreecommitdiff
path: root/svtools/source/control/ctrlbox.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'svtools/source/control/ctrlbox.cxx')
-rw-r--r--svtools/source/control/ctrlbox.cxx66
1 files changed, 49 insertions, 17 deletions
diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx
index 951f07dab8f7..f9f11afe1041 100644
--- a/svtools/source/control/ctrlbox.cxx
+++ b/svtools/source/control/ctrlbox.cxx
@@ -818,31 +818,63 @@ long BorderWidthImpl::GetGap( long nWidth ) const
return result;
}
-long BorderWidthImpl::GuessWidth( long nLine1, long nLine2, long nGap )
+double lcl_getGuessedWidth( long nTested, double nRate, bool nChanging )
{
- long nWidth = 0;
- if ( ( m_nFlags & CHANGE_LINE1 ) > 0 )
- nWidth = double( nLine1 ) / m_nRate1;
-
- if ( ( m_nFlags & CHANGE_LINE2 ) > 0 )
+ double nWidth = 0.0;
+ if ( nChanging )
+ nWidth = double( nTested ) / nRate;
+ else
{
- double nLine2Width = double( nLine2 ) / m_nRate2;
- if ( nWidth > 0 && nWidth != nLine2Width )
- nWidth = 0;
+ if ( double( nTested ) == nRate )
+ nWidth = nRate;
else
- nWidth = nLine2Width;
+ nWidth = 0.0;
}
- if ( ( m_nFlags & CHANGE_DIST ) > 0 )
+ return nWidth;
+}
+
+long BorderWidthImpl::GuessWidth( long nLine1, long nLine2, long nGap )
+{
+ std::vector< double > aToCompare;
+ bool bInvalid = false;
+
+ bool bLine1Change = ( m_nFlags & CHANGE_LINE1 ) > 0;
+ double nWidth1 = lcl_getGuessedWidth( nLine1, m_nRate1, bLine1Change );
+ if ( bLine1Change )
+ aToCompare.push_back( nWidth1 );
+ else if ( !bLine1Change && nWidth1 == 0 )
+ bInvalid = true;
+
+ bool bLine2Change = ( m_nFlags & CHANGE_LINE2 ) > 0;
+ double nWidth2 = lcl_getGuessedWidth( nLine2, m_nRate2, bLine2Change );
+ if ( bLine2Change )
+ aToCompare.push_back( nWidth2 );
+ else if ( !bLine2Change && nWidth2 == 0 )
+ bInvalid = true;
+
+ bool bGapChange = ( m_nFlags & CHANGE_DIST ) > 0;
+ double nWidthGap = lcl_getGuessedWidth( nGap, m_nRateGap, bGapChange );
+ if ( bGapChange )
+ aToCompare.push_back( nWidthGap );
+ else if ( !bGapChange && nWidthGap == 0 )
+ bInvalid = true;
+
+ double nWidth = 0.0;
+ if ( !bInvalid && aToCompare.size() > 0 )
{
- double nDistWidth = double( nGap ) / m_nRateGap;
- if ( nWidth > 0 && nWidth != nDistWidth )
- nWidth = 0;
- else
- nWidth = nDistWidth;
+ nWidth = *aToCompare.begin();
+ std::vector< double >::iterator pIt = aToCompare.begin();
+ while ( pIt != aToCompare.end() && !bInvalid )
+ {
+ bInvalid = ( nWidth != *pIt );
+ pIt++;
+ }
+ if ( bInvalid )
+ nWidth = 0.0;
}
- return nWidth;
+ return long( nWidth );
}
class ImpLineStyleListData