Kaydet (Commit) f2c22965 authored tarafından Cédric Bosdonnat's avatar Cédric Bosdonnat

Borders: expose the width computation logic for SvxBorderLine to use it

üst a99b2131
...@@ -394,6 +394,31 @@ SVT_DLLPUBLIC inline Color sameDistColor( Color /*rMain*/, Color rDefault ) ...@@ -394,6 +394,31 @@ SVT_DLLPUBLIC inline Color sameDistColor( Color /*rMain*/, Color rDefault )
return rDefault; return rDefault;
} }
class SVT_DLLPUBLIC BorderWidthImpl
{
USHORT m_nFlags;
double m_nRate1;
double m_nRate2;
double m_nRateGap;
public:
BorderWidthImpl( USHORT nFlags = CHANGE_LINE1, double nRate1 = 0.0,
double nRate2 = 0.0, double nRateGap = 0.0 );
BorderWidthImpl& operator= ( const BorderWidthImpl& r );
bool operator== ( const BorderWidthImpl& r ) const;
long GetLine1 ( long nWidth ) const;
long GetLine2( long nWidth ) const;
long GetGap( long nWidth ) const;
long GuessWidth( long nLine1, long nLine2, long nGap );
bool IsEmpty( ) const { return (0 == m_nRate1) && (0 == m_nRate2); }
bool IsDouble( ) const { return (0 != m_nRate1) && (0 != m_nRate2); }
};
class SVT_DLLPUBLIC LineStyleListBox : public LineListBox class SVT_DLLPUBLIC LineStyleListBox : public LineListBox
{ {
private: private:
...@@ -412,8 +437,8 @@ public: ...@@ -412,8 +437,8 @@ public:
void SetNone( const XubString& sNone ); void SetNone( const XubString& sNone );
using LineListBox::InsertEntry; using LineListBox::InsertEntry;
void InsertEntry( double nLine1, double nLine2, double nDist, void InsertEntry( BorderWidthImpl aWidthImpl,
sal_uInt16 nChangeFlags, sal_uInt16 nStyle, long nMinWidth = 0, sal_uInt16 nStyle, long nMinWidth = 0,
Color (*pColor1Fn)(Color) = &sameColor, Color (*pColor1Fn)(Color) = &sameColor,
Color (*pColor2Fn)( Color ) = &sameColor, Color (*pColor2Fn)( Color ) = &sameColor,
Color (*pColorDistFn)( Color, Color ) = &sameDistColor ); Color (*pColorDistFn)( Color, Color ) = &sameDistColor );
......
...@@ -764,13 +764,91 @@ void LineListBox::DataChanged( const DataChangedEvent& rDCEvt ) ...@@ -764,13 +764,91 @@ void LineListBox::DataChanged( const DataChangedEvent& rDCEvt )
// LineStyleNameBox // LineStyleNameBox
// =================================================================== // ===================================================================
BorderWidthImpl::BorderWidthImpl( sal_uInt16 nFlags, double nRate1, double nRate2, double nRateGap ):
m_nFlags( nFlags ),
m_nRate1( nRate1 ),
m_nRate2( nRate2 ),
m_nRateGap( nRateGap )
{
}
BorderWidthImpl& BorderWidthImpl::operator= ( const BorderWidthImpl& r )
{
m_nFlags = r.m_nFlags;
m_nRate1 = r.m_nRate1;
m_nRate2 = r.m_nRate2;
m_nRateGap = r.m_nRateGap;
return *this;
}
bool BorderWidthImpl::operator== ( const BorderWidthImpl& r ) const
{
return ( m_nFlags == r.m_nFlags ) &&
( m_nRate1 == r.m_nRate1 ) &&
( m_nRate2 == r.m_nRate2 ) &&
( m_nRateGap == r.m_nRateGap );
}
long BorderWidthImpl::GetLine1( long nWidth ) const
{
long result = m_nRate1;
if ( ( m_nFlags & CHANGE_LINE1 ) > 0 )
result = m_nRate1 * nWidth;
return result;
}
long BorderWidthImpl::GetLine2( long nWidth ) const
{
long result = m_nRate2;
if ( ( m_nFlags & CHANGE_LINE2 ) > 0 )
result = m_nRate2 * nWidth;
return result;
}
long BorderWidthImpl::GetGap( long nWidth ) const
{
long result = m_nRateGap;
if ( ( m_nFlags & CHANGE_DIST ) > 0 )
result = m_nRateGap * nWidth;
// Avoid having too small distances
if ( result < 100 && m_nRate1 > 0 && m_nRate2 > 0 )
result = 100;
return result;
}
long BorderWidthImpl::GuessWidth( long nLine1, long nLine2, long nGap )
{
long nWidth = 0;
if ( ( m_nFlags & CHANGE_LINE1 ) > 0 )
nWidth = double( nLine1 ) / m_nRate1;
if ( ( m_nFlags & CHANGE_LINE2 ) > 0 )
{
double nLine2Width = double( nLine2 ) / m_nRate2;
if ( nWidth > 0 && nWidth != nLine2Width )
nWidth = 0;
else
nWidth = nLine2Width;
}
if ( ( m_nFlags & CHANGE_DIST ) > 0 )
{
double nDistWidth = double( nGap ) / m_nRateGap;
if ( nWidth > 0 && nWidth != nDistWidth )
nWidth = 0;
else
nWidth = nDistWidth;
}
return nWidth;
}
class ImpLineStyleListData class ImpLineStyleListData
{ {
private: private:
double m_nLine1; BorderWidthImpl m_aWidthImpl;
double m_nLine2;
double m_nDist;
sal_uInt16 m_nFlags;
Color ( *m_pColor1Fn )( Color ); Color ( *m_pColor1Fn )( Color );
Color ( *m_pColor2Fn )( Color ); Color ( *m_pColor2Fn )( Color );
...@@ -780,15 +858,15 @@ private: ...@@ -780,15 +858,15 @@ private:
sal_uInt16 m_nStyle; sal_uInt16 m_nStyle;
public: public:
ImpLineStyleListData( double nLine1, double nLine2, double nDist, sal_uInt16 nFlags, sal_uInt16 nStyle, ImpLineStyleListData( BorderWidthImpl aWidthImpl, sal_uInt16 nStyle,
long nMinWidth=0, Color ( *pColor1Fn ) ( Color ) = &sameColor, long nMinWidth=0, Color ( *pColor1Fn ) ( Color ) = &sameColor,
Color ( *pColor2Fn ) ( Color ) = &sameColor, Color ( *pColorDistFn ) ( Color, Color ) = &sameDistColor ); Color ( *pColor2Fn ) ( Color ) = &sameColor, Color ( *pColorDistFn ) ( Color, Color ) = &sameDistColor );
double GetLine1ForWidth( double nWidth ); long GetLine1ForWidth( long nWidth ) { return m_aWidthImpl.GetLine1( nWidth ); }
double GetLine2ForWidth( double nWidth ); long GetLine2ForWidth( long nWidth ) { return m_aWidthImpl.GetLine2( nWidth ); }
double GetDistForWidth( double nWidth ); long GetDistForWidth( long nWidth ) { return m_aWidthImpl.GetGap( nWidth ); }
long GetTotalWidth( double nWidth ); long GetTotalWidth( long nWidth );
Color GetColorLine1( const Color& aMain ); Color GetColorLine1( const Color& aMain );
Color GetColorLine2( const Color& aMain ); Color GetColorLine2( const Color& aMain );
...@@ -797,16 +875,14 @@ public: ...@@ -797,16 +875,14 @@ public:
long GetMinWidth( ); long GetMinWidth( );
sal_uInt16 GetStyle( ); sal_uInt16 GetStyle( );
long GuessWidth( long nLine1, long nLine2, long nDist ); long GuessWidth( long nLine1, long nLine2, long nDist )
{ return m_aWidthImpl.GuessWidth( nLine1, nLine2, nDist ); }
}; };
ImpLineStyleListData::ImpLineStyleListData( double nLine1, double nLine2, double nDist, sal_uInt16 nFlags, ImpLineStyleListData::ImpLineStyleListData( BorderWidthImpl aWidthImpl,
sal_uInt16 nStyle, long nMinWidth, Color ( *pColor1Fn )( Color ), sal_uInt16 nStyle, long nMinWidth, Color ( *pColor1Fn )( Color ),
Color ( *pColor2Fn )( Color ), Color ( *pColorDistFn )( Color, Color ) ) : Color ( *pColor2Fn )( Color ), Color ( *pColorDistFn )( Color, Color ) ) :
m_nLine1( nLine1 ), m_aWidthImpl( aWidthImpl ),
m_nLine2( nLine2 ),
m_nDist( nDist ),
m_nFlags( nFlags ),
m_pColor1Fn( pColor1Fn ), m_pColor1Fn( pColor1Fn ),
m_pColor2Fn( pColor2Fn ), m_pColor2Fn( pColor2Fn ),
m_pColorDistFn( pColorDistFn ), m_pColorDistFn( pColorDistFn ),
...@@ -820,35 +896,6 @@ long ImpLineStyleListData::GetMinWidth( ) ...@@ -820,35 +896,6 @@ long ImpLineStyleListData::GetMinWidth( )
return m_nMinWidth; return m_nMinWidth;
} }
double ImpLineStyleListData::GetLine1ForWidth( double nWidth )
{
double result = m_nLine1;
if ( ( m_nFlags & CHANGE_LINE1 ) > 0 )
result = m_nLine1 * nWidth;
return result;
}
double ImpLineStyleListData::GetLine2ForWidth( double nWidth )
{
double result = m_nLine2;
if ( ( m_nFlags & CHANGE_LINE2 ) > 0 )
result = m_nLine2 * nWidth;
return result;
}
double ImpLineStyleListData::GetDistForWidth( double nWidth )
{
double result = m_nDist;
if ( ( m_nFlags & CHANGE_DIST ) > 0 )
result = m_nDist * nWidth;
// Avoid having too small distances
if ( result < 100 && m_nLine1 > 0 && m_nLine2 > 0 )
result = 100;
return result;
}
Color ImpLineStyleListData::GetColorLine1( const Color& rMain ) Color ImpLineStyleListData::GetColorLine1( const Color& rMain )
{ {
return ( *m_pColor1Fn )( rMain ); return ( *m_pColor1Fn )( rMain );
...@@ -869,33 +916,6 @@ sal_uInt16 ImpLineStyleListData::GetStyle( ) ...@@ -869,33 +916,6 @@ sal_uInt16 ImpLineStyleListData::GetStyle( )
return m_nStyle; return m_nStyle;
} }
long ImpLineStyleListData::GuessWidth( long nLine1, long nLine2, long nDist )
{
double nWidth = 0;
if ( ( m_nFlags & CHANGE_LINE1 ) > 0 )
nWidth = double( nLine1 ) / m_nLine1;
if ( ( m_nFlags & CHANGE_LINE2 ) > 0 )
{
double nLine2Width = double( nLine2 ) / m_nLine2;
if ( nWidth > 0 && nWidth != nLine2Width )
nWidth = 0;
else
nWidth = nLine2Width;
}
if ( ( m_nFlags & CHANGE_DIST ) > 0 )
{
double nDistWidth = double( nDist ) / m_nDist;
if ( nWidth > 0 && nWidth != nDistWidth )
nWidth = 0;
else
nWidth = nDistWidth;
}
return nWidth;
}
DECLARE_LIST( ImpLineStyleList, ImpLineStyleListData* ) DECLARE_LIST( ImpLineStyleList, ImpLineStyleListData* )
LineStyleListBox::LineStyleListBox( Window* pParent, WinBits nWinStyle ) : LineStyleListBox::LineStyleListBox( Window* pParent, WinBits nWinStyle ) :
...@@ -928,13 +948,14 @@ LineStyleListBox::~LineStyleListBox( ) ...@@ -928,13 +948,14 @@ LineStyleListBox::~LineStyleListBox( )
delete m_pStyleList; delete m_pStyleList;
} }
void LineStyleListBox::InsertEntry( double nLine1, double nLine2, double nDist, void LineStyleListBox::InsertEntry(
sal_uInt16 nChangeFlags, sal_uInt16 nStyle, long nMinWidth, BorderWidthImpl aWidthImpl,
sal_uInt16 nStyle, long nMinWidth,
Color ( *pColor1Fn )( Color ), Color ( *pColor2Fn )( Color ), Color ( *pColor1Fn )( Color ), Color ( *pColor2Fn )( Color ),
Color ( *pColorDistFn )( Color, Color ) ) Color ( *pColorDistFn )( Color, Color ) )
{ {
ImpLineStyleListData* pData = new ImpLineStyleListData( nLine1, nLine2, nDist, ImpLineStyleListData* pData = new ImpLineStyleListData(
nChangeFlags, nStyle, nMinWidth, aWidthImpl, nStyle, nMinWidth,
pColor1Fn, pColor2Fn, pColorDistFn ); pColor1Fn, pColor2Fn, pColorDistFn );
m_pStyleList->Insert( pData, m_pStyleList->Count( ) ); m_pStyleList->Insert( pData, m_pStyleList->Count( ) );
} }
...@@ -986,7 +1007,6 @@ sal_uInt16 LineStyleListBox::GetSelectedStyle( ) ...@@ -986,7 +1007,6 @@ sal_uInt16 LineStyleListBox::GetSelectedStyle( )
long LineStyleListBox::GetWidthFromStyle( long nLine1, long nLine2, long nDistance, sal_uInt16 nStyle ) long LineStyleListBox::GetWidthFromStyle( long nLine1, long nLine2, long nDistance, sal_uInt16 nStyle )
{ {
long nResult = 0; long nResult = 0;
// sal_uInt16 nStyle = GetSelectedStyle();
ImpLineStyleListData* pData = m_pStyleList->GetObject( nStyle ); ImpLineStyleListData* pData = m_pStyleList->GetObject( nStyle );
if ( pData ) if ( pData )
{ {
......
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