[Libreoffice-commits] .: 12 commits - svtools/inc svtools/source vcl/source

Cédric Bosdonnat cbosdo at kemper.freedesktop.org
Sat Mar 19 10:19:10 PDT 2011


 svtools/inc/svtools/borderhelper.hxx |    5 
 svtools/inc/svtools/ctrlbox.hxx      |  147 +++++++---
 svtools/inc/svtools/rtfkeywd.hxx     |    3 
 svtools/inc/svtools/rtftoken.h       |    2 
 svtools/source/control/ctrlbox.cxx   |  509 +++++++++++++++++++++++++----------
 svtools/source/svrtf/rtfkeywd.cxx    |    2 
 vcl/source/control/field.cxx         |    1 
 7 files changed, 495 insertions(+), 174 deletions(-)

New commits:
commit 613c917c888230e16b04e8dd02ac7f7bbe6fc4e1
Author: Cédric Bosdonnat <cedricbosdo at openoffice.org>
Date:   Thu Feb 17 23:08:53 2011 +0100

    Fixed RTF import/export of new border lines

diff --git a/svtools/source/svrtf/rtfkeywd.cxx b/svtools/source/svrtf/rtfkeywd.cxx
index 0359242..c307950 100644
--- a/svtools/source/svrtf/rtfkeywd.cxx
+++ b/svtools/source/svrtf/rtfkeywd.cxx
@@ -777,6 +777,8 @@ static RTF_TokenEntry aRTFTokenTab[] = {
 {{OOO_STRING_SVTOOLS_RTF_BRDRDASHDD},	RTF_BRDRDASHDD},
 {{OOO_STRING_SVTOOLS_RTF_BRDRDASHDOTSTR},RTF_BRDRDASHDOTSTR},
 {{OOO_STRING_SVTOOLS_RTF_BRDRDASHSM},	RTF_BRDRDASHSM},
+{{OOO_STRING_SVTOOLS_RTF_BRDRINSET},	RTF_BRDRINSET},
+{{OOO_STRING_SVTOOLS_RTF_BRDROUTSET},	RTF_BRDROUTSET},
 {{OOO_STRING_SVTOOLS_RTF_BRDREMBOSS},	RTF_BRDREMBOSS},
 {{OOO_STRING_SVTOOLS_RTF_BRDRENGRAVE},	RTF_BRDRENGRAVE},
 {{OOO_STRING_SVTOOLS_RTF_BRDRFRAME},		RTF_BRDRFRAME},
commit d5d78662a3a7886ccbbd4dbab9e518e6f5834abf
Author: Cédric Bosdonnat <cedricbosdo at openoffice.org>
Date:   Tue Feb 15 15:43:26 2011 +0100

    Fixed some rebase problems

diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx
index 045ef7b..9305e18 100644
--- a/svtools/source/control/ctrlbox.cxx
+++ b/svtools/source/control/ctrlbox.cxx
@@ -482,8 +482,6 @@ sal_uInt16 ImpLineListData::GetStyle( )
     return m_nStyle;
 }
 
-DECLARE_LIST( ImpLineList, ImpLineListData* )
-
 // -----------------------------------------------------------------------
 
 void lclDrawPolygon( OutputDevice& rDev, const basegfx::B2DPolygon& rPolygon, long nWidth, sal_uInt16 nDashing )
@@ -718,10 +716,10 @@ sal_uInt16 LineListBox::GetStylePos( sal_uInt16 nListPos, long nWidth )
 
     sal_uInt16 i = 0;
     sal_uInt16 n = 0;
-    sal_uInt16 nCount = pLineList->Count( );
+    sal_uInt16 nCount = pLineList->size();
     while ( nPos == LISTBOX_ENTRY_NOTFOUND && i < nCount )
     {
-        ImpLineListData* pData = pLineList->GetObject( i );
+        ImpLineListData* pData = (*pLineList)[ i ];
         if ( pData && pData->GetMinWidth() <= nWidth )
         {
             if ( nListPos == n )
@@ -887,10 +885,10 @@ void LineListBox::UpdateEntries( long nOldWidth )
         ListBox::InsertEntry( m_sNone, LISTBOX_APPEND );
 
     sal_uInt16 n = 0;
-    sal_uInt16 nCount = pLineList->Count( );
+    sal_uInt16 nCount = pLineList->size( );
     while ( n < nCount )
     {
-        ImpLineListData* pData = pLineList->GetObject( n );
+        ImpLineListData* pData = (*pLineList)[ n ];
         if ( pData && pData->GetMinWidth() <= m_nWidth )
         {
             Bitmap      aBmp;
@@ -921,7 +919,7 @@ Color LineListBox::GetColorLine1( sal_uInt16 nPos )
     Color rResult = GetPaintColor( );
 
     sal_uInt16 nStyle = GetStylePos( nPos, m_nWidth );
-    ImpLineListData* pData = pLineList->GetObject( nStyle );
+    ImpLineListData* pData = (*pLineList)[ nStyle ];
     if ( pData )
         rResult = pData->GetColorLine1( GetColor( ) );
 
@@ -933,7 +931,7 @@ Color LineListBox::GetColorLine2( sal_uInt16 nPos )
     Color rResult = GetPaintColor( );
 
     sal_uInt16 nStyle = GetStylePos( nPos, m_nWidth );
-    ImpLineListData* pData = pLineList->GetObject( nStyle );
+    ImpLineListData* pData = (*pLineList)[ nStyle ];
     if ( pData )
         rResult = pData->GetColorLine2( GetColor( ) );
 
@@ -945,7 +943,7 @@ Color LineListBox::GetColorDist( sal_uInt16 nPos )
     Color rResult = GetSettings().GetStyleSettings().GetFieldColor();
 
     sal_uInt16 nStyle = GetStylePos( nPos, m_nWidth );
-    ImpLineListData* pData = pLineList->GetObject( nStyle );
+    ImpLineListData* pData = (*pLineList)[ nStyle ];
     if ( pData )
         rResult = pData->GetColorDist( GetColor( ), rResult );
 
commit 3b37e7addc56214a8c5799bb0c7df76df804d83f
Author: Cédric Bosdonnat <cedricbosdo at openoffice.org>
Date:   Thu Jan 20 15:22:49 2011 +0100

    Fixed lines width guessing: gap are no smaller than 1pt

diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx
index a75dbf5..045ef7b 100644
--- a/svtools/source/control/ctrlbox.cxx
+++ b/svtools/source/control/ctrlbox.cxx
@@ -329,9 +329,9 @@ long BorderWidthImpl::GetGap( long nWidth ) const
     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;
+    // Avoid having too small distances (less than 1pt)
+    if ( result < 20 && m_nRate1 > 0 && m_nRate2 > 0 )
+        result = 20;
 
     return result;
 }
@@ -371,7 +371,7 @@ long BorderWidthImpl::GuessWidth( long nLine1, long nLine2, long nGap )
 
     bool bGapChange = ( m_nFlags & CHANGE_DIST ) > 0;
     double nWidthGap = lcl_getGuessedWidth( nGap, m_nRateGap, bGapChange );
-    if ( bGapChange )
+    if ( bGapChange && nGap > 20 )
         aToCompare.push_back( nWidthGap );
     else if ( !bGapChange && nWidthGap < 0 )
         bInvalid = true;
commit 9279f86ee25c41dbe59b8ab81bcab795265063f8
Author: Cédric Bosdonnat <cedricbosdo at openoffice.org>
Date:   Thu Jan 20 15:20:41 2011 +0100

    Few fixes for RTF export and import of borders

diff --git a/svtools/inc/svtools/rtfkeywd.hxx b/svtools/inc/svtools/rtfkeywd.hxx
index b701c3a..5b54d87 100644
--- a/svtools/inc/svtools/rtfkeywd.hxx
+++ b/svtools/inc/svtools/rtfkeywd.hxx
@@ -747,6 +747,9 @@
 #define OOO_STRING_SVTOOLS_RTF_BRDRDASHSM "\\brdrdashsm"
 #define OOO_STRING_SVTOOLS_RTF_BRDREMBOSS "\\brdremboss"
 #define OOO_STRING_SVTOOLS_RTF_BRDRENGRAVE "\\brdrengrave"
+#define OOO_STRING_SVTOOLS_RTF_BRDROUTSET "\\brdroutset"
+#define OOO_STRING_SVTOOLS_RTF_BRDRINSET "\\brdrinset"
+#define OOO_STRING_SVTOOLS_RTF_BRDRNONE "\\brdrnone"
 #define OOO_STRING_SVTOOLS_RTF_BRDRFRAME "\\brdrframe"
 #define OOO_STRING_SVTOOLS_RTF_BRDRTHTNLG "\\brdrthtnlg"
 #define OOO_STRING_SVTOOLS_RTF_BRDRTHTNMG "\\brdrthtnmg"
commit 82b268432d1796f05fa448dc2bfd36283b7cf798
Author: Cédric Bosdonnat <cedricbosdo at openoffice.org>
Date:   Tue Jan 11 20:44:15 2011 +0100

    Remove the size in the LineListBox

diff --git a/svtools/inc/svtools/ctrlbox.hxx b/svtools/inc/svtools/ctrlbox.hxx
index 12455c5..267a104 100644
--- a/svtools/inc/svtools/ctrlbox.hxx
+++ b/svtools/inc/svtools/ctrlbox.hxx
@@ -315,7 +315,7 @@ class SVT_DLLPUBLIC LineListBox : public ListBox
 
     SVT_DLLPRIVATE void			ImpGetLine( long nLine1, long nLine2, long nDistance,
                                     Color nColor1, Color nColor2, Color nColorDist,
-                                    sal_uInt16 nStyle, Bitmap& rBmp, XubString& rStr );
+                                    sal_uInt16 nStyle, Bitmap& rBmp );
     using Window::ImplInit;
     SVT_DLLPRIVATE void			ImplInit();
     sal_Bool		UpdatePaintLineColor( void );		// returns sal_True if maPaintCol has changed
diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx
index bddc2fc..a75dbf5 100644
--- a/svtools/source/control/ctrlbox.cxx
+++ b/svtools/source/control/ctrlbox.cxx
@@ -600,7 +600,7 @@ namespace svtools
 
 void LineListBox::ImpGetLine( long nLine1, long nLine2, long nDistance,
                             Color aColor1, Color aColor2, Color aColorDist,
-                            sal_uInt16 nStyle, Bitmap& rBmp, XubString& rStr )
+                            sal_uInt16 nStyle, Bitmap& rBmp )
 {
     Size aSize = GetOutputSizePixel();
     aSize.Width() -= 20;
@@ -655,25 +655,13 @@ void LineListBox::ImpGetLine( long nLine1, long nLine2, long nDistance,
         }
         rBmp = aVirDev.GetBitmap( Point(), Size( aSize.Width(), n1+nDist+n2 ) );
     }
-
-    // Twips nach Unit
-    if ( eUnit == FUNIT_POINT )
-    {
-        nLine1      *= 5;
-        nLine2      *= 5;
-        nDistance   *= 5;
-        rStr.AssignAscii( " pt" );
-    }
-
-    String aNum( GetSettings().GetLocaleI18nHelper().GetNum( nLine1+nLine2+nDistance, 2 ) );
-    rStr.Insert( aNum, 0 );
 }
 
 // -----------------------------------------------------------------------
 
 void LineListBox::ImplInit()
 {
-    aTxtSize.Width()  = GetTextWidth( XubString( RTL_CONSTASCII_USTRINGPARAM( "99,99 mm" ) ) );
+    aTxtSize.Width()  = GetTextWidth( XubString( RTL_CONSTASCII_USTRINGPARAM( " " )  ) );
     aTxtSize.Height() = GetTextHeight();
     pLineList   = new ImpLineList();
     eUnit       = FUNIT_POINT;
@@ -905,7 +893,6 @@ void LineListBox::UpdateEntries( long nOldWidth )
         ImpLineListData* pData = pLineList->GetObject( n );
         if ( pData && pData->GetMinWidth() <= m_nWidth )
         {
-            XubString   aStr;
             Bitmap      aBmp;
             ImpGetLine( pData->GetLine1ForWidth( m_nWidth ),
                     pData->GetLine2ForWidth( m_nWidth ),
@@ -913,8 +900,8 @@ void LineListBox::UpdateEntries( long nOldWidth )
                     GetColorLine1( GetEntryCount( ) ),
                     GetColorLine2( GetEntryCount( ) ),
                     GetColorDist( GetEntryCount( ) ),
-                    pData->GetStyle(), aBmp, aStr );
-            ListBox::InsertEntry( aStr, aBmp, LISTBOX_APPEND );
+                    pData->GetStyle(), aBmp );
+            ListBox::InsertEntry( XubString( RTL_CONSTASCII_USTRINGPARAM( " " )  ), aBmp, LISTBOX_APPEND );
             if ( n == nTypePos )
                 SelectEntryPos( GetEntryCount() - 1 );
         }
commit 6e3eaf8d5b1db10fa173c1c21cda987886543668
Author: Cédric Bosdonnat <cedricbosdo at openoffice.org>
Date:   Fri Jan 7 13:40:45 2011 +0100

    Switching the order of the SetLinesWidth arguments

diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx
index 61fd0eb..bddc2fc 100644
--- a/svtools/source/control/ctrlbox.cxx
+++ b/svtools/source/control/ctrlbox.cxx
@@ -338,15 +338,13 @@ long BorderWidthImpl::GetGap( long nWidth ) const
 
 double lcl_getGuessedWidth( long nTested, double nRate, bool nChanging )
 {
-    double nWidth = 0.0;
+    double nWidth = -1.0;
     if ( nChanging )
         nWidth = double( nTested ) / nRate;
     else
     {
         if ( double( nTested ) == nRate )
             nWidth = nRate;
-        else
-            nWidth = 0.0;
     }
 
     return nWidth;
@@ -361,21 +359,21 @@ long BorderWidthImpl::GuessWidth( long nLine1, long nLine2, long nGap )
     double nWidth1 = lcl_getGuessedWidth( nLine1, m_nRate1, bLine1Change );
     if ( bLine1Change )
         aToCompare.push_back( nWidth1 );
-    else if ( !bLine1Change && nWidth1 == 0 )
+    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 )
+    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 )
+    else if ( !bGapChange && nWidthGap < 0 )
         bInvalid = true;
 
     double nWidth = 0.0;
commit 1195561689688295dc39d8daa0a73c380ab62536
Author: Cédric Bosdonnat <cedricbosdo at openoffice.org>
Date:   Thu Jan 6 15:58:56 2011 +0100

    One LineListBox to rule them all: started improving column sep line

diff --git a/svtools/inc/svtools/ctrlbox.hxx b/svtools/inc/svtools/ctrlbox.hxx
index 0848392..12455c5 100644
--- a/svtools/inc/svtools/ctrlbox.hxx
+++ b/svtools/inc/svtools/ctrlbox.hxx
@@ -247,9 +247,65 @@ inline Color ColorListBox::GetSelectEntryColor( sal_uInt16 nSelIndex ) const
 // - LineListBox -
 // ---------------
 
+/**
+    Class computing border widths shared between Line style listbox and the
+    SvxBorderLine implementation.
+
+    This class doesn't know anything about units: it all depends on the different
+    values set. A border is composed of 2 lines separated by a gap. The computed
+    widths are the ones of each line and the gap and they can either be fix or vary.
+
+    The #m_nflags member will define which widths will vary (value 0 means that all
+    widths are fixed). The available flags are:
+     - CHANGE_LINE1
+     - CHANGE_LINE2
+     - CHANGE_DIST
+
+    For each line, the rate member is used as a multiplication factor is the width
+    isn't fixed. Otherwise it is the width in the unit expected by the client code.
+ */
+class SVT_DLLPUBLIC BorderWidthImpl
+{
+    sal_uInt16 m_nFlags;
+    double m_nRate1;
+    double m_nRate2;
+    double m_nRateGap;
+
+public:
+
+    BorderWidthImpl( sal_uInt16 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);  }
+};
+
+SVT_DLLPUBLIC inline Color sameColor( Color rMain )
+{
+    return rMain;
+}
+
+SVT_DLLPUBLIC inline Color sameDistColor( Color /*rMain*/, Color rDefault )
+{
+    return rDefault;
+}
+
+
 class SVT_DLLPUBLIC LineListBox : public ListBox
 {
     ImpLineList*	pLineList;
+    long            m_nWidth;
+    XubString       m_sNone;
+
     VirtualDevice	aVirDev;
     Size			aTxtSize;
     Color			aColor;
@@ -262,41 +318,49 @@ class SVT_DLLPUBLIC LineListBox : public ListBox
                                     sal_uInt16 nStyle, Bitmap& rBmp, XubString& rStr );
     using Window::ImplInit;
     SVT_DLLPRIVATE void			ImplInit();
-    void			UpdateLineColors( void );
     sal_Bool		UpdatePaintLineColor( void );		// returns sal_True if maPaintCol has changed
     virtual void	DataChanged( const DataChangedEvent& rDCEvt );
 
+    void            UpdateEntries( long nOldWidth );
+    sal_uInt16           GetStylePos( sal_uInt16 nListPos, long nWidth );
+
 public:
                     LineListBox( Window* pParent, WinBits nWinStyle = WB_BORDER );
                     LineListBox( Window* pParent, const ResId& rResId );
     virtual 		~LineListBox();
 
+    /** Set the width in Twips */
+    void            SetWidth( long nWidth );
+    void            SetNone( const XubString& sNone );
+
     using ListBox::InsertEntry;
     virtual sal_uInt16	InsertEntry( const XubString& rStr, sal_uInt16 nPos = LISTBOX_APPEND );
-    virtual sal_uInt16	InsertEntry( long nLine1, long nLine2 = 0, long nDistance = 0,
-                                sal_uInt16 nStyle = STYLE_SOLID, sal_uInt16 nPos = LISTBOX_APPEND );
+    /** Insert a listbox entry with all widths in Twips. */
+    void            InsertEntry( BorderWidthImpl aWidthImpl,
+                        sal_uInt16 nStyle, long nMinWidth = 0,
+                        Color (*pColor1Fn)(Color) = &sameColor,
+                        Color (*pColor2Fn)( Color ) = &sameColor,
+                        Color (*pColorDistFn)( Color, Color ) = &sameDistColor );
+
     using ListBox::RemoveEntry;
     virtual void	RemoveEntry( sal_uInt16 nPos );
     virtual void	Clear();
 
     using ListBox::GetEntryPos;
-    virtual sal_uInt16	GetEntryPos( long nLine1, long nLine2 = 0, long nDistance = 0,
-                                 sal_uInt16 nStyle = STYLE_SOLID ) const;
+    virtual sal_uInt16	GetEntryPos( sal_uInt16 nStyle = STYLE_SOLID ) const;
     long			GetEntryLine1( sal_uInt16 nPos ) const;
     long			GetEntryLine2( sal_uInt16 nPos ) const;
     long			GetEntryDistance( sal_uInt16 nPos ) const;
     sal_uInt16          GetEntryStyle( sal_uInt16 nPos ) const;
 
-    void		SelectEntry( const XubString& rStr, sal_Bool bSelect = sal_True ) { ListBox::SelectEntry( rStr, bSelect ); }
-    void			SelectEntry( long nLine1, long nLine2 = 0, long nDistance = 0,
-                                 sal_uInt16 nStyle = STYLE_SOLID, sal_Bool bSelect = sal_True );
+    void            SelectEntry( const XubString& rStr, sal_Bool bSelect = sal_True ) { ListBox::SelectEntry( rStr, bSelect ); }
+    void			SelectEntry( sal_uInt16 nStyle = STYLE_SOLID, sal_Bool bSelect = sal_True );
     long			GetSelectEntryLine1( sal_uInt16 nSelIndex = 0 ) const;
     long			GetSelectEntryLine2( sal_uInt16 nSelIndex = 0 ) const;
     long			GetSelectEntryDistance( sal_uInt16 nSelIndex = 0 ) const;
     sal_uInt16  		GetSelectEntryStyle( sal_uInt16 nSelIndex = 0 ) const;
     inline sal_Bool		IsEntrySelected( const XubString& rStr ) const { return ListBox::IsEntrySelected( rStr ); }
-    sal_Bool			IsEntrySelected( long nLine1, long nLine2 = 0, long nDistance = 0,
-                                     sal_uInt16 nStyle1 = STYLE_SOLID ) const;
+    sal_Bool			IsEntrySelected( sal_uInt16 nStyle1 = STYLE_SOLID ) const;
 
     inline void		SetUnit( FieldUnit eNewUnit ) { eUnit = eNewUnit; }
     inline FieldUnit	GetUnit() const { return eUnit; }
@@ -309,9 +373,9 @@ public:
 protected:
 
     inline const Color&	   GetPaintColor( void ) const;
-    virtual Color   GetColorLine1( sal_uInt16 nPos = 0 );
-    virtual Color   GetColorLine2( sal_uInt16 nPos = 0 );
-    virtual Color   GetColorDist( sal_uInt16 nPos = 0 );
+    Color   GetColorLine1( sal_uInt16 nPos = 0 );
+    Color   GetColorLine2( sal_uInt16 nPos = 0 );
+    Color   GetColorDist( sal_uInt16 nPos = 0 );
 
 private:
     // declared as private because some compilers would generate the default methods
@@ -348,19 +412,9 @@ inline long LineListBox::GetSelectEntryDistance( sal_uInt16 nSelIndex ) const
         return 0;
 }
 
-inline sal_uInt16 LineListBox::GetSelectEntryStyle( sal_uInt16 nSelIndex ) const
+inline sal_Bool LineListBox::IsEntrySelected( sal_uInt16 nStyle ) const
 {
-    sal_uInt16 nStyle = STYLE_SOLID;
-    sal_uInt16 nPos = GetSelectEntryPos( nSelIndex );
-    if ( nPos != LISTBOX_ENTRY_NOTFOUND )
-        nStyle = GetEntryStyle( nPos );
-
-    return nStyle;
-}
-
-inline sal_Bool LineListBox::IsEntrySelected( long nLine1, long nLine2, long nDistance, sal_uInt16 nStyle ) const
-{
-    sal_uInt16 nPos = GetEntryPos( nLine1, nLine2, nDistance, nStyle );
+    sal_uInt16 nPos = GetEntryPos( nStyle );
     if ( nPos != LISTBOX_ENTRY_NOTFOUND )
         return IsEntryPosSelected( nPos );
     else
@@ -371,7 +425,7 @@ inline void LineListBox::SetColor( const Color& rColor )
 {
     aColor = rColor;
 
-    UpdateLineColors();
+    UpdateEntries( m_nWidth );
 }
 
 inline Color LineListBox::GetColor( void ) const
@@ -384,107 +438,14 @@ const Color& LineListBox::GetPaintColor( void ) const
     return maPaintCol;
 }
 
-SVT_DLLPUBLIC inline Color sameColor( Color rMain )
-{
-    return rMain;
-}
-
-SVT_DLLPUBLIC inline Color sameDistColor( Color /*rMain*/, Color rDefault )
-{
-    return rDefault;
-}
-
-/**
-    Class computing border widths shared between Line style listbox and the
-    SvxBorderLine implementation.
-
-    This class doesn't know anything about units: it all depends on the different
-    values set. A border is composed of 2 lines separated by a gap. The computed
-    widths are the ones of each line and the gap and they can either be fix or vary.
-
-    The #m_nflags member will define which widths will vary (value 0 means that all
-    widths are fixed). The available flags are:
-     - CHANGE_LINE1
-     - CHANGE_LINE2
-     - CHANGE_DIST
-
-    For each line, the rate member is used as a multiplication factor is the width
-    isn't fixed. Otherwise it is the width in the unit expected by the client code.
- */
-class SVT_DLLPUBLIC BorderWidthImpl
-{
-    sal_uInt16 m_nFlags;
-    double m_nRate1;
-    double m_nRate2;
-    double m_nRateGap;
-
-public:
-
-    BorderWidthImpl( sal_uInt16 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
-{
-private:
-   ImpLineStyleList *     m_pStyleList;
-   long                   m_nWidth;
-   XubString              m_sNone;
-
-public:
-                    LineStyleListBox( Window* pParent, WinBits nWinStyle = WB_BORDER );
-                    LineStyleListBox( Window* pParent, const ResId& rResId );
-    virtual 		~LineStyleListBox();
-
-    /** Set the width in pt.
-      */
-    void            SetWidth( long nWidth );
-    void            SetNone( const XubString& sNone );
-
-    using LineListBox::InsertEntry;
-    /** Insert a listbox entry with all widths in Twips. */
-    void            InsertEntry( BorderWidthImpl aWidthImpl,
-                        sal_uInt16 nStyle, long nMinWidth = 0,
-                        Color (*pColor1Fn)(Color) = &sameColor,
-                        Color (*pColor2Fn)( Color ) = &sameColor,
-                        Color (*pColorDistFn)( Color, Color ) = &sameDistColor );
-
-    ULONG           GetSelectedStyle( );
-
-    virtual sal_uInt16	GetEntryPos( long nLine1, long nLine2 = 0, long nDistance = 0,
-                                 sal_uInt16 nStyle = STYLE_SOLID ) const;
-
-protected:
-
-    virtual Color   GetColorLine1( sal_uInt16 nPos = 0);
-    virtual Color   GetColorLine2( sal_uInt16 nPos = 0 );
-    virtual Color   GetColorDist( sal_uInt16 nPos = 0 );
-
-private:
-    void            UpdateEntries( long nOldWidth );
-    sal_uInt16      GetStylePos( sal_uInt16 nListPos, long nWidth );
-};
-
-inline void LineStyleListBox::SetWidth( long nWidth )
+inline void LineListBox::SetWidth( long nWidth )
 {
     long nOldWidth = m_nWidth;
     m_nWidth = nWidth;
     UpdateEntries( nOldWidth );
 }
 
-inline void LineStyleListBox::SetNone( const XubString& sNone )
+inline void LineListBox::SetNone( const XubString& sNone )
 {
     m_sNone = sNone;
 }
diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx
index 43b15db..61fd0eb 100644
--- a/svtools/source/control/ctrlbox.cxx
+++ b/svtools/source/control/ctrlbox.cxx
@@ -282,18 +282,210 @@ void ColorListBox::UserDraw( const UserDrawEvent& rUDEvt )
 // LineListBox
 // =======================================================================
 
-// -------------------
-// - ImpListListData -
-// -------------------
+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;
+}
+
+double lcl_getGuessedWidth( long nTested, double nRate, bool nChanging )
+{
+    double nWidth = 0.0;
+    if ( nChanging )
+        nWidth = double( nTested ) / nRate;
+    else
+    {
+        if ( double( nTested ) == nRate )
+            nWidth = nRate;
+        else
+            nWidth = 0.0;
+    }
 
-struct ImpLineListData
+    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 )
+    {
+        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 long( nWidth );
+}
+
+/** Utility class storing the border line width, style and colors. The widths
+    are defined in Twips.
+  */
+class ImpLineListData
 {
-    long    nLine1;
-    long    nLine2;
-    long    nDistance;
-    sal_uInt16  nStyle;
+private:
+    BorderWidthImpl m_aWidthImpl;
+
+    Color  ( *m_pColor1Fn )( Color );
+    Color  ( *m_pColor2Fn )( Color );
+    Color  ( *m_pColorDistFn )( Color, Color );
+
+    long   m_nMinWidth;
+    sal_uInt16 m_nStyle;
+
+public:
+    ImpLineListData( BorderWidthImpl aWidthImpl, sal_uInt16 nStyle,
+            long nMinWidth=0, Color ( *pColor1Fn ) ( Color ) = &sameColor,
+            Color ( *pColor2Fn ) ( Color ) = &sameColor, Color ( *pColorDistFn ) ( Color, Color ) = &sameDistColor );
+
+    /** Returns the computed width of the line 1 in twips. */
+    long GetLine1ForWidth( long nWidth ) { return m_aWidthImpl.GetLine1( nWidth ); }
+
+    /** Returns the computed width of the line 2 in twips. */
+    long GetLine2ForWidth( long nWidth ) { return m_aWidthImpl.GetLine2( nWidth ); }
+
+    /** Returns the computed width of the gap in twips. */
+    long GetDistForWidth( long nWidth ) { return m_aWidthImpl.GetGap( nWidth ); }
+
+    Color  GetColorLine1( const Color& aMain );
+    Color  GetColorLine2( const Color& aMain );
+    Color  GetColorDist( const Color& aMain, const Color& rDefault );
+
+    /** Returns the minimum width in twips */
+    long   GetMinWidth( );
+    sal_uInt16 GetStyle( );
 };
 
+ImpLineListData::ImpLineListData( BorderWidthImpl aWidthImpl,
+       sal_uInt16 nStyle, long nMinWidth, Color ( *pColor1Fn )( Color ),
+       Color ( *pColor2Fn )( Color ), Color ( *pColorDistFn )( Color, Color ) ) :
+    m_aWidthImpl( aWidthImpl ),
+    m_pColor1Fn( pColor1Fn ),
+    m_pColor2Fn( pColor2Fn ),
+    m_pColorDistFn( pColorDistFn ),
+    m_nMinWidth( nMinWidth ),
+    m_nStyle( nStyle )
+{
+}
+
+long ImpLineListData::GetMinWidth( )
+{
+    return m_nMinWidth;
+}
+
+Color ImpLineListData::GetColorLine1( const Color& rMain )
+{
+    return ( *m_pColor1Fn )( rMain );
+}
+
+Color ImpLineListData::GetColorLine2( const Color& rMain )
+{
+    return ( *m_pColor2Fn )( rMain );
+}
+
+Color ImpLineListData::GetColorDist( const Color& rMain, const Color& rDefault )
+{
+    return ( *m_pColorDistFn )( rMain, rDefault );
+}
+
+sal_uInt16 LineListBox::GetSelectEntryStyle( sal_uInt16 nSelIndex ) const
+{
+    sal_uInt16 nStyle = STYLE_SOLID;
+    sal_uInt16 nPos = GetSelectEntryPos( nSelIndex );
+    if ( nPos != LISTBOX_ENTRY_NOTFOUND )
+    {
+        if ( m_sNone.Len( ) > 0 )
+            nPos--;
+        nStyle = GetEntryStyle( nPos );
+    }
+
+    return nStyle;
+}
+
+sal_uInt16 ImpLineListData::GetStyle( )
+{
+    return m_nStyle;
+}
+
+DECLARE_LIST( ImpLineList, ImpLineListData* )
+
 // -----------------------------------------------------------------------
 
 void lclDrawPolygon( OutputDevice& rDev, const basegfx::B2DPolygon& rPolygon, long nWidth, sal_uInt16 nDashing )
@@ -420,26 +612,17 @@ void LineListBox::ImpGetLine( long nLine1, long nLine2, long nDistance,
     // SourceUnit nach Twips
     if ( eSourceUnit == FUNIT_POINT )
     {
-        nLine1      *= 20;
-        nLine2      *= 20;
-        nDistance   *= 20;
-    }
-    else if ( eSourceUnit == FUNIT_MM )
-    {
-        nLine1      *= 14440;
-        nLine1      /= 254;
-        nLine2      *= 14440;
-        nLine2      /= 254;
-        nDistance   *= 14440;
-        nDistance   /= 254;
+        nLine1      /= 5;
+        nLine2      /= 5;
+        nDistance   /= 5;
     }
 
     // Linien malen
     aSize = aVirDev.PixelToLogic( aSize );
     long nPix = aVirDev.PixelToLogic( Size( 0, 1 ) ).Height();
-    sal_uInt32 n1 = nLine1 / 100;
-    sal_uInt32 n2 = nLine2 / 100;
-    long nDist  = nDistance / 100;
+    sal_uInt32 n1 = nLine1;
+    sal_uInt32 n2 = nLine2;
+    long nDist  = nDistance;
     n1 += nPix-1;
     n1 -= n1%nPix;
     if ( n2 )
@@ -478,21 +661,11 @@ void LineListBox::ImpGetLine( long nLine1, long nLine2, long nDistance,
     // Twips nach Unit
     if ( eUnit == FUNIT_POINT )
     {
-        nLine1      /= 20;
-        nLine2      /= 20;
-        nDistance   /= 20;
+        nLine1      *= 5;
+        nLine2      *= 5;
+        nDistance   *= 5;
         rStr.AssignAscii( " pt" );
     }
-    else if ( eUnit == FUNIT_MM )
-    {
-        nLine1      *= 254;
-        nLine1      /= 14400;
-        nLine2      *= 254;
-        nLine2      /= 14400;
-        nDistance   *= 254;
-        nDistance   /= 14400;
-        rStr.AssignAscii( " mm" );
-    }
 
     String aNum( GetSettings().GetLocaleI18nHelper().GetNum( nLine1+nLine2+nDistance, 2 ) );
     rStr.Insert( aNum, 0 );
@@ -518,6 +691,8 @@ void LineListBox::ImplInit()
 
 LineListBox::LineListBox( Window* pParent, WinBits nWinStyle ) :
     ListBox( pParent, nWinStyle ),
+    m_nWidth( 5 ),
+    m_sNone( ),
     aColor( COL_BLACK ),
     maPaintCol( COL_BLACK )
 {
@@ -528,6 +703,8 @@ LineListBox::LineListBox( Window* pParent, WinBits nWinStyle ) :
 
 LineListBox::LineListBox( Window* pParent, const ResId& rResId ) :
     ListBox( pParent, rResId ),
+    m_nWidth( 5 ),
+    m_sNone( ),
     aColor( COL_BLACK ),
     maPaintCol( COL_BLACK )
 {
@@ -547,9 +724,34 @@ LineListBox::~LineListBox()
     delete pLineList;
 }
 
-void LineListBox::SelectEntry( long nLine1, long nLine2, long nDistance, sal_uInt16 nStyle, sal_Bool bSelect )
+sal_uInt16 LineListBox::GetStylePos( sal_uInt16 nListPos, long nWidth )
+{
+    sal_uInt16 nPos = LISTBOX_ENTRY_NOTFOUND;
+    if ( m_sNone.Len( ) > 0 )
+        nListPos--;
+
+    sal_uInt16 i = 0;
+    sal_uInt16 n = 0;
+    sal_uInt16 nCount = pLineList->Count( );
+    while ( nPos == LISTBOX_ENTRY_NOTFOUND && i < nCount )
+    {
+        ImpLineListData* pData = pLineList->GetObject( i );
+        if ( pData && pData->GetMinWidth() <= nWidth )
+        {
+            if ( nListPos == n )
+                nPos = i;
+            n++;
+        }
+        i++;
+    }
+
+    return nPos;
+}
+
+
+void LineListBox::SelectEntry( sal_uInt16 nStyle, sal_Bool bSelect )
 {
-    sal_uInt16 nPos = GetEntryPos( nLine1, nLine2, nDistance, nStyle );
+    sal_uInt16 nPos = GetEntryPos( nStyle );
     if ( nPos != LISTBOX_ENTRY_NOTFOUND )
         ListBox::SelectEntryPos( nPos, bSelect );
 }
@@ -573,34 +775,16 @@ sal_uInt16 LineListBox::InsertEntry( const XubString& rStr, sal_uInt16 nPos )
 
 // -----------------------------------------------------------------------
 
-sal_uInt16 LineListBox::InsertEntry( long nLine1, long nLine2, long nDistance,
-                                sal_uInt16 nStyle, sal_uInt16 nPos )
-{
-    XubString   aStr;
-    Bitmap      aBmp;
-    ImpGetLine( nLine1, nLine2, nDistance,
-            GetColorLine1( GetEntryCount( ) ),
-            GetColorLine2( GetEntryCount( ) ),
-            GetColorDist( GetEntryCount( ) ),
-            nStyle, aBmp, aStr );
-    nPos = ListBox::InsertEntry( aStr, aBmp, nPos );
-    if ( nPos != LISTBOX_ERROR )
-    {
-        ImpLineListData* pData = new ImpLineListData;
-        pData->nLine1    = nLine1;
-        pData->nLine2    = nLine2;
-        pData->nDistance = nDistance;
-        pData->nStyle    = nStyle;
-        if ( nPos < pLineList->size() ) {
-            ImpLineList::iterator it = pLineList->begin();
-            ::std::advance( it, nPos );
-            pLineList->insert( it, pData );
-        } else {
-            pLineList->push_back( pData );
-        }
-    }
-
-    return nPos;
+void LineListBox::InsertEntry(
+        BorderWidthImpl aWidthImpl,
+        sal_uInt16 nStyle, long nMinWidth,
+        Color ( *pColor1Fn )( Color ), Color ( *pColor2Fn )( Color ),
+        Color ( *pColorDistFn )( Color, Color ) )
+{
+    ImpLineListData* pData = new ImpLineListData(
+            aWidthImpl, nStyle, nMinWidth,
+           pColor1Fn, pColor2Fn, pColorDistFn );
+    pLineList->push_back( pData );
 }
 
 // -----------------------------------------------------------------------
@@ -633,19 +817,18 @@ void LineListBox::Clear()
 
 // -----------------------------------------------------------------------
 
-sal_uInt16 LineListBox::GetEntryPos( long nLine1, long nLine2,
-                                long nDistance, sal_uInt16 nStyle ) const
+sal_uInt16 LineListBox::GetEntryPos( sal_uInt16 nStyle ) const
 {
     for ( size_t i = 0, n = pLineList->size(); i < n; ++i ) {
         ImpLineListData* pData = (*pLineList)[ i ];
         if ( pData )
         {
-            if (  (pData->nLine1    == nLine1)
-               && (pData->nLine2    == nLine2)
-               && (pData->nDistance == nDistance)
-               && (pData->nStyle    == nStyle)
-            ) {
-                return (sal_uInt16)i;
+            if ( GetEntryStyle( i ) == nStyle )
+            {
+                size_t nPos = i;
+                if ( m_sNone.Len() > 0 )
+                    nPos ++;
+                return (sal_uInt16)nPos;
             }
         }
     }
@@ -657,7 +840,7 @@ sal_uInt16 LineListBox::GetEntryPos( long nLine1, long nLine2,
 long LineListBox::GetEntryLine1( sal_uInt16 nPos ) const
 {
     ImpLineListData* pData = (nPos < pLineList->size()) ? (*pLineList)[ nPos ] : NULL;
-    return ( pData ) ? pData->nLine1 : 0;
+    return ( pData ) ? pData->GetLine1ForWidth( m_nWidth ) : 0;
 }
 
 // -----------------------------------------------------------------------
@@ -665,7 +848,7 @@ long LineListBox::GetEntryLine1( sal_uInt16 nPos ) const
 long LineListBox::GetEntryLine2( sal_uInt16 nPos ) const
 {
     ImpLineListData* pData = (nPos < pLineList->size()) ? (*pLineList)[ nPos ] : NULL;
-    return ( pData ) ? pData->nLine2 : 0;
+    return ( pData ) ? pData->GetLine2ForWidth( m_nWidth ) : 0;
 }
 
 // -----------------------------------------------------------------------
@@ -673,7 +856,7 @@ long LineListBox::GetEntryLine2( sal_uInt16 nPos ) const
 long LineListBox::GetEntryDistance( sal_uInt16 nPos ) const
 {
     ImpLineListData* pData = (nPos < pLineList->size()) ? (*pLineList)[ nPos ] : NULL;
-    return ( pData ) ? pData->nDistance : 0;
+    return ( pData ) ? pData->GetDistForWidth( m_nWidth ) : 0;
 }
 
 // -----------------------------------------------------------------------
@@ -681,45 +864,7 @@ long LineListBox::GetEntryDistance( sal_uInt16 nPos ) const
 sal_uInt16 LineListBox::GetEntryStyle( sal_uInt16 nPos ) const
 {
     ImpLineListData* pData = (nPos < pLineList->size()) ? (*pLineList)[ nPos ] : NULL;
-    return ( pData ) ? pData->nStyle : STYLE_SOLID;
-}
-
-// -----------------------------------------------------------------------
-
-void LineListBox::UpdateLineColors( void )
-{
-    if( UpdatePaintLineColor() )
-    {
-        size_t nCount = pLineList->size();
-        if( !nCount )
-            return;
-
-        XubString	aStr;
-        Bitmap		aBmp;
-
-        // exchange entries which containing lines
-        SetUpdateMode( sal_False );
-
-        sal_uInt16 nSelEntry = GetSelectEntryPos();
-        for( size_t n = 0 ; n < nCount ; ++n )
-        {
-            ImpLineListData* pData = (*pLineList)[ n ];
-            if( pData )
-            {
-                // exchange listbox data
-                ListBox::RemoveEntry( sal_uInt16( n ) );
-                ImpGetLine( pData->nLine1, pData->nLine2, pData->nDistance,
-                        GetColorLine1( n ), GetColorLine2( n ), GetColorDist( n ),
-                        pData->nStyle, aBmp, aStr );
-            }
-        }
-
-        if( nSelEntry != LISTBOX_ENTRY_NOTFOUND )
-            SelectEntryPos( nSelEntry );
-
-        SetUpdateMode( sal_True );
-        Invalidate();
-    }
+    return ( pData ) ? pData->GetStyle() : STYLE_SOLID;
 }
 
 // -----------------------------------------------------------------------
@@ -738,398 +883,100 @@ sal_Bool LineListBox::UpdatePaintLineColor( void )
     return bRet;
 }
 
-Color LineListBox::GetColorLine1( sal_uInt16 )
-{
-    return GetPaintColor( );
-}
-
-Color LineListBox::GetColorLine2( sal_uInt16 )
-{
-    return GetPaintColor( );
-}
-
-Color LineListBox::GetColorDist( sal_uInt16 )
-{
-    return GetSettings().GetStyleSettings().GetFieldColor();
-}
-
-// -----------------------------------------------------------------------
-
-void LineListBox::DataChanged( const DataChangedEvent& rDCEvt )
-{
-    ListBox::DataChanged( rDCEvt );
-
-    if( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
-        UpdateLineColors();
-}
-
-// ===================================================================
-// 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;
-}
-
-double lcl_getGuessedWidth( long nTested, double nRate, bool nChanging )
-{
-    double nWidth = 0.0;
-    if ( nChanging )
-        nWidth = double( nTested ) / nRate;
-    else
-    {
-        if ( double( nTested ) == nRate )
-            nWidth = nRate;
-        else
-            nWidth = 0.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 )
-    {
-        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 long( nWidth );
-}
-
-/** Utility class storing the border line width, style and colors. The widths
-    are defined in Twips.
-  */
-class ImpLineStyleListData
-{
-private:
-    BorderWidthImpl m_aWidthImpl;
-
-    Color  ( *m_pColor1Fn )( Color );
-    Color  ( *m_pColor2Fn )( Color );
-    Color  ( *m_pColorDistFn )( Color, Color );
-
-    long   m_nMinWidth;
-    sal_uInt16 m_nStyle;
-
-public:
-    ImpLineStyleListData( BorderWidthImpl aWidthImpl, sal_uInt16 nStyle,
-            long nMinWidth=0, Color ( *pColor1Fn ) ( Color ) = &sameColor,
-            Color ( *pColor2Fn ) ( Color ) = &sameColor, Color ( *pColorDistFn ) ( Color, Color ) = &sameDistColor );
-
-    /** Returns the computed width of the line 1 in 100th of pt. */
-    long GetLine1ForWidth( long nWidth ) { return TWIPS_TO_PT100( m_aWidthImpl.GetLine1( nWidth ) ); }
-
-    /** Returns the computed width of the line 2 in 100th of pt. */
-    long GetLine2ForWidth( long nWidth ) { return TWIPS_TO_PT100( m_aWidthImpl.GetLine2( nWidth ) ); }
-
-    /** Returns the computed width of the gap in 100th of pt. */
-    long GetDistForWidth( long nWidth ) { return TWIPS_TO_PT100( m_aWidthImpl.GetGap( nWidth ) ); }
-
-    Color  GetColorLine1( const Color& aMain );
-    Color  GetColorLine2( const Color& aMain );
-    Color  GetColorDist( const Color& aMain, const Color& rDefault );
-
-    /** Returns the minimum width in 100th of pt */
-    long   GetMinWidth( );
-    sal_uInt16 GetStyle( );
-
-    /** Guess the width based on all the lines computed widths in 100th of pt.
-      The result value is expressed in Twips. */
-    long GuessWidth( long nLine1, long nLine2, long nDist )
-        { return m_aWidthImpl.GuessWidth( PT100_TO_TWIPS( nLine1 ),
-                PT100_TO_TWIPS( nLine2 ), PT100_TO_TWIPS( nDist ) ); }
-};
-
-ImpLineStyleListData::ImpLineStyleListData( BorderWidthImpl aWidthImpl,
-       sal_uInt16 nStyle, long nMinWidth, Color ( *pColor1Fn )( Color ),
-       Color ( *pColor2Fn )( Color ), Color ( *pColorDistFn )( Color, Color ) ) :
-    m_aWidthImpl( aWidthImpl ),
-    m_pColor1Fn( pColor1Fn ),
-    m_pColor2Fn( pColor2Fn ),
-    m_pColorDistFn( pColorDistFn ),
-    m_nMinWidth( nMinWidth ),
-    m_nStyle( nStyle )
-{
-}
-
-long ImpLineStyleListData::GetMinWidth( )
-{
-    return TWIPS_TO_PT100( m_nMinWidth );
-}
-
-Color ImpLineStyleListData::GetColorLine1( const Color& rMain )
-{
-    return ( *m_pColor1Fn )( rMain );
-}
-
-Color ImpLineStyleListData::GetColorLine2( const Color& rMain )
+void LineListBox::UpdateEntries( long nOldWidth )
 {
-    return ( *m_pColor2Fn )( rMain );
-}
-
-Color ImpLineStyleListData::GetColorDist( const Color& rMain, const Color& rDefault )
-{
-    return ( *m_pColorDistFn )( rMain, rDefault );
-}
+    SetUpdateMode( sal_False );
 
-sal_uInt16 ImpLineStyleListData::GetStyle( )
-{
-    return m_nStyle;
-}
+    UpdatePaintLineColor( );
 
-DECLARE_LIST( ImpLineStyleList, ImpLineStyleListData* )
+    sal_uInt16		nSelEntry = GetSelectEntryPos();
+    sal_uInt16       nTypePos = GetStylePos( nSelEntry, nOldWidth );
 
-LineStyleListBox::LineStyleListBox( Window* pParent, WinBits nWinStyle ) :
-    LineListBox( pParent, nWinStyle ),
-    m_nWidth( 5 ),
-    m_sNone( )
-{
-    m_pStyleList = new ImpLineStyleList;
-}
+    // Remove the old entries
+    while ( GetEntryCount( ) > 0 )
+        ListBox::RemoveEntry( 0 );
 
-LineStyleListBox::LineStyleListBox( Window* pParent, const ResId& rResId ) :
-    LineListBox( pParent, rResId ),
-    m_nWidth( 0 ),
-    m_sNone( )
-{
-    m_pStyleList = new ImpLineStyleList;
-}
+    // Add the new entries based on the defined width
+    if ( m_sNone.Len( ) > 0 )
+        ListBox::InsertEntry( m_sNone, LISTBOX_APPEND );
 
-LineStyleListBox::~LineStyleListBox( )
-{
     sal_uInt16 n = 0;
-    sal_uInt16 nCount = m_pStyleList->Count( );
+    sal_uInt16 nCount = pLineList->Count( );
     while ( n < nCount )
     {
-        ImpLineStyleListData* pData = m_pStyleList->GetObject( n );
-        if ( pData )
-            delete pData;
+        ImpLineListData* pData = pLineList->GetObject( n );
+        if ( pData && pData->GetMinWidth() <= m_nWidth )
+        {
+            XubString   aStr;
+            Bitmap      aBmp;
+            ImpGetLine( pData->GetLine1ForWidth( m_nWidth ),
+                    pData->GetLine2ForWidth( m_nWidth ),
+                    pData->GetDistForWidth( m_nWidth ),
+                    GetColorLine1( GetEntryCount( ) ),
+                    GetColorLine2( GetEntryCount( ) ),
+                    GetColorDist( GetEntryCount( ) ),
+                    pData->GetStyle(), aBmp, aStr );
+            ListBox::InsertEntry( aStr, aBmp, LISTBOX_APPEND );
+            if ( n == nTypePos )
+                SelectEntryPos( GetEntryCount() - 1 );
+        }
+        else if ( n == nTypePos )
+            SetNoSelection();
         n++;
     }
-    delete m_pStyleList;
-}
 
-void LineStyleListBox::InsertEntry(
-        BorderWidthImpl aWidthImpl,
-        sal_uInt16 nStyle, long nMinWidth,
-        Color ( *pColor1Fn )( Color ), Color ( *pColor2Fn )( Color ),
-        Color ( *pColorDistFn )( Color, Color ) )
-{
-    ImpLineStyleListData* pData = new ImpLineStyleListData(
-            aWidthImpl, nStyle, nMinWidth,
-           pColor1Fn, pColor2Fn, pColorDistFn );
-    m_pStyleList->Insert( pData, m_pStyleList->Count( ) );
+    SetUpdateMode( sal_True );
+    Invalidate();
 }
 
-Color LineStyleListBox::GetColorLine1( sal_uInt16 nPos )
+// -----------------------------------------------------------------------
+
+Color LineListBox::GetColorLine1( sal_uInt16 nPos )
 {
-    Color rResult = LineListBox::GetColorLine1( );
+    Color rResult = GetPaintColor( );
 
     sal_uInt16 nStyle = GetStylePos( nPos, m_nWidth );
-    ImpLineStyleListData* pData = m_pStyleList->GetObject( nStyle );
+    ImpLineListData* pData = pLineList->GetObject( nStyle );
     if ( pData )
         rResult = pData->GetColorLine1( GetColor( ) );
 
     return rResult;
 }
 
-Color LineStyleListBox::GetColorLine2( sal_uInt16 nPos )
+Color LineListBox::GetColorLine2( sal_uInt16 nPos )
 {
-    Color rResult = LineListBox::GetColorLine2( );
+    Color rResult = GetPaintColor( );
 
     sal_uInt16 nStyle = GetStylePos( nPos, m_nWidth );
-    ImpLineStyleListData* pData = m_pStyleList->GetObject( nStyle );
+    ImpLineListData* pData = pLineList->GetObject( nStyle );
     if ( pData )
         rResult = pData->GetColorLine2( GetColor( ) );
 
     return rResult;
 }
 
-Color LineStyleListBox::GetColorDist( sal_uInt16 nPos )
+Color LineListBox::GetColorDist( sal_uInt16 nPos )
 {
-    Color rResult = LineListBox::GetColorDist( );
+    Color rResult = GetSettings().GetStyleSettings().GetFieldColor();
 
     sal_uInt16 nStyle = GetStylePos( nPos, m_nWidth );
-    ImpLineStyleListData* pData = m_pStyleList->GetObject( nStyle );
+    ImpLineListData* pData = pLineList->GetObject( nStyle );
     if ( pData )
         rResult = pData->GetColorDist( GetColor( ), rResult );
 
     return rResult;
 }
 
-sal_uInt16 LineStyleListBox::GetSelectedStyle( )
-{
-    sal_uInt16 nSelEntry = GetSelectEntryPos();
-    if ( m_sNone.Len( ) > 0 )
-        nSelEntry--;
-    return GetStylePos( nSelEntry, m_nWidth );
-}
-
-sal_uInt16 LineStyleListBox::GetEntryPos( long /*nLine1*/, long /*nLine2*/,
-                                long /*nDistance*/, sal_uInt16 nStyle ) const
-{
-    sal_uInt16 nPos = LISTBOX_ENTRY_NOTFOUND;
-    sal_uInt16 n = 0;
-    sal_uInt16 nCount = this->GetEntryCount( );
-    while ( n < nCount )
-    {
-        if ( GetEntryStyle( n ) == nStyle )
-            nPos = (sal_uInt16)n;
-
-        n++;
-    }
-
-    return nPos;
-}
+// -----------------------------------------------------------------------
 
-sal_uInt16 LineStyleListBox::GetStylePos( sal_uInt16 nListPos, long nWidth )
+void LineListBox::DataChanged( const DataChangedEvent& rDCEvt )
 {
-    sal_uInt16 nPos = LISTBOX_ENTRY_NOTFOUND;
-    if ( m_sNone.Len( ) > 0 )
-        nListPos--;
-
-    sal_uInt16 i = 0;
-    sal_uInt16 n = 0;
-    sal_uInt16 nCount = m_pStyleList->Count( );
-    while ( nPos == LISTBOX_ENTRY_NOTFOUND && i < nCount )
-    {
-        ImpLineStyleListData* pData = m_pStyleList->GetObject( i );
-        if ( pData && pData->GetMinWidth() <= nWidth )
-        {
-            if ( nListPos == n )
-                nPos = i;
-            n++;
-        }
-        i++;
-    }
+    ListBox::DataChanged( rDCEvt );
 
-    return nPos;
+    if( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
+        UpdateEntries( m_nWidth );
 }
 
-void LineStyleListBox::UpdateEntries( long nOldWidth )
-{
-    SetUpdateMode( sal_False );
-
-    sal_uInt16		nSelEntry = GetSelectEntryPos();
-    sal_uInt16       nTypePos = GetStylePos( nSelEntry, nOldWidth );
-
-    // Remove the old entries
-    while ( GetEntryCount( ) > 0 )
-        RemoveEntry( 0 );
-
-    // Add the new entries based on the defined width
-    if ( m_sNone.Len( ) > 0 )
-        InsertEntry( m_sNone );
-
-    sal_uInt16 n = 0;
-    sal_uInt16 nCount = m_pStyleList->Count( );
-    while ( n < nCount )
-    {
-        ImpLineStyleListData* pData = m_pStyleList->GetObject( n );
-        if ( pData && pData->GetMinWidth() <= m_nWidth )
-        {
-            InsertEntry(
-                   pData->GetLine1ForWidth( m_nWidth ),
-                   pData->GetLine2ForWidth( m_nWidth ),
-                   pData->GetDistForWidth( m_nWidth ),
-                   pData->GetStyle( ) );
-            if ( n == nTypePos )
-                SelectEntryPos( GetEntryCount() - 1 );
-        }
-        else if ( n == nTypePos )
-            SetNoSelection();
-        n++;
-    }
-
-    SetColor( GetColor( ) );
-
-    SetUpdateMode( sal_True );
-    Invalidate();
-}
 
 // ===================================================================
 // FontNameBox
diff --git a/vcl/source/control/field.cxx b/vcl/source/control/field.cxx
index f94ab3e..7dba7bb 100644
--- a/vcl/source/control/field.cxx
+++ b/vcl/source/control/field.cxx
@@ -1431,7 +1431,6 @@ double MetricField::ConvertDoubleValue( double nValue, sal_uInt16 nDigits,
     {
         while ( nDecDigits )
         {
-            nValue += 5;
             nValue /= 10;
             nDecDigits--;
         }
commit f0cac16f43c2a5473410f4c4fa29d0a339de479d
Author: Cédric Bosdonnat <cedricbosdo at openoffice.org>
Date:   Tue Jan 4 13:41:04 2011 +0100

    Fixed units mess in SvxBorderLine and BorderLineImpl

diff --git a/svtools/inc/svtools/ctrlbox.hxx b/svtools/inc/svtools/ctrlbox.hxx
index ad389bc..0848392 100644
--- a/svtools/inc/svtools/ctrlbox.hxx
+++ b/svtools/inc/svtools/ctrlbox.hxx
@@ -394,16 +394,33 @@ SVT_DLLPUBLIC inline Color sameDistColor( Color /*rMain*/, Color rDefault )
     return rDefault;
 }
 
+/**
+    Class computing border widths shared between Line style listbox and the
+    SvxBorderLine implementation.
+
+    This class doesn't know anything about units: it all depends on the different
+    values set. A border is composed of 2 lines separated by a gap. The computed
+    widths are the ones of each line and the gap and they can either be fix or vary.
+
+    The #m_nflags member will define which widths will vary (value 0 means that all
+    widths are fixed). The available flags are:
+     - CHANGE_LINE1
+     - CHANGE_LINE2
+     - CHANGE_DIST
+
+    For each line, the rate member is used as a multiplication factor is the width
+    isn't fixed. Otherwise it is the width in the unit expected by the client code.
+ */
 class SVT_DLLPUBLIC BorderWidthImpl
 {
-    USHORT m_nFlags;
+    sal_uInt16 m_nFlags;
     double m_nRate1;
     double m_nRate2;
     double m_nRateGap;
 
 public:
 
-    BorderWidthImpl( USHORT nFlags = CHANGE_LINE1, double nRate1 = 0.0,
+    BorderWidthImpl( sal_uInt16 nFlags = CHANGE_LINE1, double nRate1 = 0.0,
             double nRate2 = 0.0, double nRateGap = 0.0 );
 
     BorderWidthImpl& operator= ( const BorderWidthImpl& r );
@@ -437,14 +454,14 @@ public:
     void            SetNone( const XubString& sNone );
 
     using LineListBox::InsertEntry;
+    /** Insert a listbox entry with all widths in Twips. */
     void            InsertEntry( BorderWidthImpl aWidthImpl,
                         sal_uInt16 nStyle, long nMinWidth = 0,
                         Color (*pColor1Fn)(Color) = &sameColor,
                         Color (*pColor2Fn)( Color ) = &sameColor,
                         Color (*pColorDistFn)( Color, Color ) = &sameDistColor );
 
-    sal_uInt16      GetSelectedStyle( );
-    long            GetWidthFromStyle( long nLine1, long nLine2, long nDistance, sal_uInt16 nStyle );
+    ULONG           GetSelectedStyle( );
 
     virtual sal_uInt16	GetEntryPos( long nLine1, long nLine2 = 0, long nDistance = 0,
                                  sal_uInt16 nStyle = STYLE_SOLID ) const;
diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx
index a21a733..43b15db 100644
--- a/svtools/source/control/ctrlbox.cxx
+++ b/svtools/source/control/ctrlbox.cxx
@@ -53,6 +53,9 @@
 #define EXTRAFONTSIZE 5
 #define MAXPREVIEWWIDTH 100
 
+#define TWIPS_TO_PT100(val) (val * 5)
+#define PT100_TO_TWIPS(val) (val / 5)
+
 using namespace ::com::sun::star;
 
 // ========================================================================
@@ -877,6 +880,9 @@ long BorderWidthImpl::GuessWidth( long nLine1, long nLine2, long nGap )
     return long( nWidth );
 }
 
+/** Utility class storing the border line width, style and colors. The widths
+    are defined in Twips.
+  */
 class ImpLineStyleListData
 {
 private:
@@ -894,21 +900,28 @@ public:
             long nMinWidth=0, Color ( *pColor1Fn ) ( Color ) = &sameColor,
             Color ( *pColor2Fn ) ( Color ) = &sameColor, Color ( *pColorDistFn ) ( Color, Color ) = &sameDistColor );
 
-    long GetLine1ForWidth( long nWidth ) { return m_aWidthImpl.GetLine1( nWidth ); }
-    long GetLine2ForWidth( long nWidth ) { return m_aWidthImpl.GetLine2( nWidth ); }
-    long GetDistForWidth( long nWidth ) { return m_aWidthImpl.GetGap( nWidth ); }
+    /** Returns the computed width of the line 1 in 100th of pt. */
+    long GetLine1ForWidth( long nWidth ) { return TWIPS_TO_PT100( m_aWidthImpl.GetLine1( nWidth ) ); }
+
+    /** Returns the computed width of the line 2 in 100th of pt. */
+    long GetLine2ForWidth( long nWidth ) { return TWIPS_TO_PT100( m_aWidthImpl.GetLine2( nWidth ) ); }
 
-    long   GetTotalWidth( long nWidth );
+    /** Returns the computed width of the gap in 100th of pt. */
+    long GetDistForWidth( long nWidth ) { return TWIPS_TO_PT100( m_aWidthImpl.GetGap( nWidth ) ); }
 
     Color  GetColorLine1( const Color& aMain );
     Color  GetColorLine2( const Color& aMain );
     Color  GetColorDist( const Color& aMain, const Color& rDefault );
 
+    /** Returns the minimum width in 100th of pt */
     long   GetMinWidth( );
     sal_uInt16 GetStyle( );
 
+    /** Guess the width based on all the lines computed widths in 100th of pt.
+      The result value is expressed in Twips. */
     long GuessWidth( long nLine1, long nLine2, long nDist )
-        { return m_aWidthImpl.GuessWidth( nLine1, nLine2, nDist ); }
+        { return m_aWidthImpl.GuessWidth( PT100_TO_TWIPS( nLine1 ),
+                PT100_TO_TWIPS( nLine2 ), PT100_TO_TWIPS( nDist ) ); }
 };
 
 ImpLineStyleListData::ImpLineStyleListData( BorderWidthImpl aWidthImpl,
@@ -925,7 +938,7 @@ ImpLineStyleListData::ImpLineStyleListData( BorderWidthImpl aWidthImpl,
 
 long ImpLineStyleListData::GetMinWidth( )
 {
-    return m_nMinWidth;
+    return TWIPS_TO_PT100( m_nMinWidth );
 }
 
 Color ImpLineStyleListData::GetColorLine1( const Color& rMain )
@@ -1036,17 +1049,6 @@ sal_uInt16 LineStyleListBox::GetSelectedStyle( )
     return GetStylePos( nSelEntry, m_nWidth );
 }
 
-long LineStyleListBox::GetWidthFromStyle( long nLine1, long nLine2, long nDistance, sal_uInt16 nStyle )
-{
-    long nResult = 0;
-    ImpLineStyleListData* pData = m_pStyleList->GetObject( nStyle );
-    if ( pData )
-    {
-        nResult = pData->GuessWidth( nLine1, nLine2, nDistance );
-    }
-    return nResult;
-}
-
 sal_uInt16 LineStyleListBox::GetEntryPos( long /*nLine1*/, long /*nLine2*/,
                                 long /*nDistance*/, sal_uInt16 nStyle ) const
 {
commit 1bf98565dccbc1907aa56290897f629b5b329635
Author: Cédric Bosdonnat <cedricbosdo at openoffice.org>
Date:   Fri Dec 24 09:58:37 2010 +0100

    Fixed BorderWidthImpl::GuessWidth()

diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx
index 6e2ec89..a21a733 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
commit 4ada7b3a852821476acff00ff9fa641ac561e1d4
Author: Cédric Bosdonnat <cedricbosdo at openoffice.org>
Date:   Thu Dec 16 17:15:33 2010 +0100

    Fixed the RTF import of borders to use new widths system

diff --git a/svtools/inc/svtools/rtftoken.h b/svtools/inc/svtools/rtftoken.h
index 9702e08..a65d60b 100644
--- a/svtools/inc/svtools/rtftoken.h
+++ b/svtools/inc/svtools/rtftoken.h
@@ -658,6 +658,8 @@ enum RTF_TOKEN_IDS {
     RTF_BRDRDOT,
     RTF_BRDRHAIR,
     RTF_BRDRDASH,
+    RTF_BRDRINSET,
+    RTF_BRDROUTSET,
     RTF_BRDRFRAME,
 
     // Swg-Border-Tokens
commit 99aa7050cfda23f8f8d81ca5553aefe92da889f3
Author: Cédric Bosdonnat <cedricbosdo at openoffice.org>
Date:   Mon Nov 8 16:29:04 2010 +0100

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

diff --git a/svtools/inc/svtools/ctrlbox.hxx b/svtools/inc/svtools/ctrlbox.hxx
index 2a67f48..ad389bc 100644
--- a/svtools/inc/svtools/ctrlbox.hxx
+++ b/svtools/inc/svtools/ctrlbox.hxx
@@ -394,6 +394,31 @@ SVT_DLLPUBLIC inline Color sameDistColor( Color /*rMain*/, Color 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
 {
 private:
@@ -412,8 +437,8 @@ public:
     void            SetNone( const XubString& sNone );
 
     using LineListBox::InsertEntry;
-    void            InsertEntry( double nLine1, double nLine2, double nDist,
-                        sal_uInt16 nChangeFlags, sal_uInt16 nStyle, long nMinWidth = 0,
+    void            InsertEntry( BorderWidthImpl aWidthImpl,
+                        sal_uInt16 nStyle, long nMinWidth = 0,
                         Color (*pColor1Fn)(Color) = &sameColor,
                         Color (*pColor2Fn)( Color ) = &sameColor,
                         Color (*pColorDistFn)( Color, Color ) = &sameDistColor );
diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx
index 9662ff2..6e2ec89 100644
--- a/svtools/source/control/ctrlbox.cxx
+++ b/svtools/source/control/ctrlbox.cxx
@@ -764,13 +764,91 @@ void LineListBox::DataChanged( const DataChangedEvent& rDCEvt )
 // 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
 {
 private:
-    double m_nLine1;
-    double m_nLine2;
-    double m_nDist;
-    sal_uInt16 m_nFlags;
+    BorderWidthImpl m_aWidthImpl;
 
     Color  ( *m_pColor1Fn )( Color );
     Color  ( *m_pColor2Fn )( Color );
@@ -780,15 +858,15 @@ private:
     sal_uInt16 m_nStyle;
 
 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,
             Color ( *pColor2Fn ) ( Color ) = &sameColor, Color ( *pColorDistFn ) ( Color, Color ) = &sameDistColor );
 
-    double GetLine1ForWidth( double nWidth );
-    double GetLine2ForWidth( double nWidth );
-    double GetDistForWidth( double nWidth );
+    long GetLine1ForWidth( long nWidth ) { return m_aWidthImpl.GetLine1( nWidth ); }
+    long GetLine2ForWidth( long nWidth ) { return m_aWidthImpl.GetLine2( nWidth ); }
+    long GetDistForWidth( long nWidth ) { return m_aWidthImpl.GetGap( nWidth ); }
 
-    long   GetTotalWidth( double nWidth );
+    long   GetTotalWidth( long nWidth );
 
     Color  GetColorLine1( const Color& aMain );
     Color  GetColorLine2( const Color& aMain );
@@ -797,16 +875,14 @@ public:
     long   GetMinWidth( );
     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 ),
        Color ( *pColor2Fn )( Color ), Color ( *pColorDistFn )( Color, Color ) ) :
-    m_nLine1( nLine1 ),
-    m_nLine2( nLine2 ),
-    m_nDist( nDist ),
-    m_nFlags( nFlags ),
+    m_aWidthImpl( aWidthImpl ),
     m_pColor1Fn( pColor1Fn ),
     m_pColor2Fn( pColor2Fn ),
     m_pColorDistFn( pColorDistFn ),
@@ -820,35 +896,6 @@ long ImpLineStyleListData::GetMinWidth( )
     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 )
 {
     return ( *m_pColor1Fn )( rMain );
@@ -869,33 +916,6 @@ sal_uInt16 ImpLineStyleListData::GetStyle( )
     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* )
 
 LineStyleListBox::LineStyleListBox( Window* pParent, WinBits nWinStyle ) :
@@ -928,13 +948,14 @@ LineStyleListBox::~LineStyleListBox( )
     delete m_pStyleList;
 }
 
-void LineStyleListBox::InsertEntry( double nLine1, double nLine2, double nDist,
-        sal_uInt16 nChangeFlags, sal_uInt16 nStyle, long nMinWidth,
+void LineStyleListBox::InsertEntry(
+        BorderWidthImpl aWidthImpl,
+        sal_uInt16 nStyle, long nMinWidth,
         Color ( *pColor1Fn )( Color ), Color ( *pColor2Fn )( Color ),
         Color ( *pColorDistFn )( Color, Color ) )
 {
-    ImpLineStyleListData* pData = new ImpLineStyleListData( nLine1, nLine2, nDist,
-           nChangeFlags, nStyle, nMinWidth,
+    ImpLineStyleListData* pData = new ImpLineStyleListData(
+            aWidthImpl, nStyle, nMinWidth,
            pColor1Fn, pColor2Fn, pColorDistFn );
     m_pStyleList->Insert( pData, m_pStyleList->Count( ) );
 }
@@ -986,7 +1007,6 @@ sal_uInt16 LineStyleListBox::GetSelectedStyle( )
 long LineStyleListBox::GetWidthFromStyle( long nLine1, long nLine2, long nDistance, sal_uInt16 nStyle )
 {
     long nResult = 0;
-//    sal_uInt16 nStyle = GetSelectedStyle();
     ImpLineStyleListData* pData = m_pStyleList->GetObject( nStyle );
     if ( pData )
     {
commit dae671a07ecf2e13d49ba1c254dc201921005a10
Author: Cédric Bosdonnat <cedricbosdo at openoffice.org>
Date:   Sat Nov 6 19:24:28 2010 +0100

    Nicely draw borders using drawinglayer

diff --git a/svtools/inc/svtools/borderhelper.hxx b/svtools/inc/svtools/borderhelper.hxx
index 18bad89..de24369 100644
--- a/svtools/inc/svtools/borderhelper.hxx
+++ b/svtools/inc/svtools/borderhelper.hxx
@@ -33,13 +33,18 @@
 
 #include <basegfx/polygon/b2dpolypolygon.hxx>
 #include <basegfx/polygon/b2dpolygon.hxx>
+#include <basegfx/point/b2dpoint.hxx>
 #include <vcl/outdev.hxx>
+#include <vector>
 
 namespace svtools
 {
     SVT_DLLPUBLIC basegfx::B2DPolyPolygon ApplyLineDashing( const basegfx::B2DPolygon& rPolygon,
             sal_uInt16 nDashing, MapUnit eUnit );
 
+    SVT_DLLPUBLIC void DrawLine( OutputDevice& rDev, const basegfx::B2DPoint& rBeg,
+            const basegfx::B2DPoint& rEnd, sal_uInt32 nWidth, sal_uInt16 nDashing );
+
     SVT_DLLPUBLIC void DrawLine( OutputDevice& rDev, const Point& rBeg,
             const Point& rEnd, sal_uInt32 nWidth, sal_uInt16 nDashing );
 }
diff --git a/svtools/inc/svtools/ctrlbox.hxx b/svtools/inc/svtools/ctrlbox.hxx
index b321e7f..2a67f48 100644
--- a/svtools/inc/svtools/ctrlbox.hxx
+++ b/svtools/inc/svtools/ctrlbox.hxx
@@ -47,9 +47,14 @@ typedef ::std::vector< ImplColorListData*    > ImpColorList;
 typedef ::std::vector< ImpLineListData*      > ImpLineList;
 typedef ::std::vector< ImplFontNameListData* > ImplFontList;
 
-#define STYLE_SOLID     ( ( sal_uInt16 ) 0 )
-#define STYLE_DOTTED    ( ( sal_uInt16 ) 1 )
-#define STYLE_DASHED    ( ( sal_uInt16 ) 2 )
+#define STYLE_SOLID                ( ( sal_uInt16 ) 0 )
+#define STYLE_DOTTED               ( ( sal_uInt16 ) 1 )
+#define STYLE_DASHED               ( ( sal_uInt16 ) 2 )
+
+#define CHANGE_LINE1               ( ( sal_uInt16 ) 1 )
+#define CHANGE_LINE2               ( ( sal_uInt16 ) 2 )
+#define CHANGE_DIST                ( ( sal_uInt16 ) 4 )
+#define ADAPT_DIST                 ( ( sal_uInt16 ) 8 )
 
 /*************************************************************************
 
@@ -253,12 +258,12 @@ class SVT_DLLPUBLIC LineListBox : public ListBox
     FieldUnit		eSourceUnit;
 
     SVT_DLLPRIVATE void			ImpGetLine( long nLine1, long nLine2, long nDistance,
+                                    Color nColor1, Color nColor2, Color nColorDist,
                                     sal_uInt16 nStyle, Bitmap& rBmp, XubString& rStr );
     using Window::ImplInit;
     SVT_DLLPRIVATE void			ImplInit();
     void			UpdateLineColors( void );
-    sal_Bool			UpdatePaintLineColor( void );		// returns sal_True if maPaintCol has changed
-    inline const Color&	GetPaintColor( void ) const;
+    sal_Bool		UpdatePaintLineColor( void );		// returns sal_True if maPaintCol has changed
     virtual void	DataChanged( const DataChangedEvent& rDCEvt );
 
 public:
@@ -275,14 +280,14 @@ public:
     virtual void	Clear();
 
     using ListBox::GetEntryPos;
-    sal_uInt16			GetEntryPos( long nLine1, long nLine2 = 0, long nDistance = 0,
+    virtual sal_uInt16	GetEntryPos( long nLine1, long nLine2 = 0, long nDistance = 0,
                                  sal_uInt16 nStyle = STYLE_SOLID ) const;
     long			GetEntryLine1( sal_uInt16 nPos ) const;
     long			GetEntryLine2( sal_uInt16 nPos ) const;
     long			GetEntryDistance( sal_uInt16 nPos ) const;
     sal_uInt16          GetEntryStyle( sal_uInt16 nPos ) const;
 
-    inline void		SelectEntry( const XubString& rStr, sal_Bool bSelect = sal_True ) { ListBox::SelectEntry( rStr, bSelect ); }
+    void		SelectEntry( const XubString& rStr, sal_Bool bSelect = sal_True ) { ListBox::SelectEntry( rStr, bSelect ); }
     void			SelectEntry( long nLine1, long nLine2 = 0, long nDistance = 0,
                                  sal_uInt16 nStyle = STYLE_SOLID, sal_Bool bSelect = sal_True );
     long			GetSelectEntryLine1( sal_uInt16 nSelIndex = 0 ) const;
@@ -301,6 +306,13 @@ public:
     void			SetColor( const Color& rColor );
     inline Color	GetColor( void ) const;
 
+protected:
+
+    inline const Color&	   GetPaintColor( void ) const;
+    virtual Color   GetColorLine1( sal_uInt16 nPos = 0 );
+    virtual Color   GetColorLine2( sal_uInt16 nPos = 0 );
+    virtual Color   GetColorDist( sal_uInt16 nPos = 0 );
+
 private:
     // declared as private because some compilers would generate the default methods
                     LineListBox( const LineListBox& );
@@ -309,13 +321,6 @@ private:
     void*			GetEntryData( sal_uInt16 nPos ) const;
 };
 
-inline void LineListBox::SelectEntry( long nLine1, long nLine2, long nDistance, sal_uInt16 nStyle, sal_Bool bSelect )
-{
-    sal_uInt16 nPos = GetEntryPos( nLine1, nLine2, nDistance, nStyle );
-    if ( nPos != LISTBOX_ENTRY_NOTFOUND )
-        ListBox::SelectEntryPos( nPos, bSelect );
-}
-
 inline long LineListBox::GetSelectEntryLine1( sal_uInt16 nSelIndex ) const
 {
     sal_uInt16 nPos = GetSelectEntryPos( nSelIndex );
@@ -374,6 +379,73 @@ inline Color LineListBox::GetColor( void ) const
     return aColor;
 }
 
+const Color& LineListBox::GetPaintColor( void ) const
+{
+    return maPaintCol;
+}
+
+SVT_DLLPUBLIC inline Color sameColor( Color rMain )
+{
+    return rMain;
+}
+
+SVT_DLLPUBLIC inline Color sameDistColor( Color /*rMain*/, Color rDefault )
+{
+    return rDefault;
+}
+
+class SVT_DLLPUBLIC LineStyleListBox : public LineListBox
+{
+private:
+   ImpLineStyleList *     m_pStyleList;
+   long                   m_nWidth;
+   XubString              m_sNone;
+
+public:
+                    LineStyleListBox( Window* pParent, WinBits nWinStyle = WB_BORDER );
+                    LineStyleListBox( Window* pParent, const ResId& rResId );
+    virtual 		~LineStyleListBox();
+
+    /** Set the width in pt.
+      */
+    void            SetWidth( long nWidth );
+    void            SetNone( const XubString& sNone );
+
+    using LineListBox::InsertEntry;
+    void            InsertEntry( double nLine1, double nLine2, double nDist,
+                        sal_uInt16 nChangeFlags, sal_uInt16 nStyle, long nMinWidth = 0,
+                        Color (*pColor1Fn)(Color) = &sameColor,
+                        Color (*pColor2Fn)( Color ) = &sameColor,
+                        Color (*pColorDistFn)( Color, Color ) = &sameDistColor );
+
+    sal_uInt16      GetSelectedStyle( );
+    long            GetWidthFromStyle( long nLine1, long nLine2, long nDistance, sal_uInt16 nStyle );
+
+    virtual sal_uInt16	GetEntryPos( long nLine1, long nLine2 = 0, long nDistance = 0,
+                                 sal_uInt16 nStyle = STYLE_SOLID ) const;
+
+protected:
+
+    virtual Color   GetColorLine1( sal_uInt16 nPos = 0);
+    virtual Color   GetColorLine2( sal_uInt16 nPos = 0 );
+    virtual Color   GetColorDist( sal_uInt16 nPos = 0 );
+
+private:
+    void            UpdateEntries( long nOldWidth );
+    sal_uInt16      GetStylePos( sal_uInt16 nListPos, long nWidth );
+};
+
+inline void LineStyleListBox::SetWidth( long nWidth )
+{
+    long nOldWidth = m_nWidth;
+    m_nWidth = nWidth;
+    UpdateEntries( nOldWidth );
+}
+
+inline void LineStyleListBox::SetNone( const XubString& sNone )
+{
+    m_sNone = sNone;
+}
 
 // ---------------
 // - FontNameBox -
diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx
index 083d73d..9662ff2 100644
--- a/svtools/source/control/ctrlbox.cxx
+++ b/svtools/source/control/ctrlbox.cxx
@@ -293,22 +293,11 @@ struct ImpLineListData
 
 // -----------------------------------------------------------------------
 
-inline const Color& LineListBox::GetPaintColor( void ) const
-{
-    return maPaintCol;
-}
-
-// -----------------------------------------------------------------------
-
-
-inline void lclDrawPolygon( OutputDevice& rDev, const basegfx::B2DPolygon& rPolygon, long nWidth, sal_uInt16 nDashing )
+void lclDrawPolygon( OutputDevice& rDev, const basegfx::B2DPolygon& rPolygon, long nWidth, sal_uInt16 nDashing )
 {
     sal_uInt16 nOldAA = rDev.GetAntialiasing();
     rDev.SetAntialiasing( nOldAA & !ANTIALIASING_ENABLE_B2DDRAW );
 
-    Color aOldColor = rDev.GetFillColor( );
-    rDev.SetFillColor( rDev.GetLineColor( ) );
-
     basegfx::B2DPolyPolygon aPolygons = svtools::ApplyLineDashing( rPolygon, nDashing, rDev.GetMapMode().GetMapUnit() );
     for ( sal_uInt32 i = 0; i < aPolygons.count( ); i++ )
     {
@@ -320,7 +309,12 @@ inline void lclDrawPolygon( OutputDevice& rDev, const basegfx::B2DPolygon& rPoly
         aVector.normalize( );
         const basegfx::B2DVector aPerpendicular(basegfx::getPerpendicular(aVector));
 
-        const basegfx::B2DVector aWidthOffset( nWidth / 2 * aPerpendicular);
+        // Handle problems of width 1px in Pixel mode: 0.5px gives a 1px line
+        long nPix = rDev.PixelToLogic( Size( 0, 1 ) ).Height();
+        if ( rDev.GetMapMode().GetMapUnit() == MAP_PIXEL && nWidth == nPix )
+            nWidth = 0;
+
+        const basegfx::B2DVector aWidthOffset( double( nWidth ) / 2 * aPerpendicular);
         basegfx::B2DPolygon aDashPolygon;
         aDashPolygon.append( aStart + aWidthOffset );
         aDashPolygon.append( aEnd + aWidthOffset );
@@ -331,13 +325,12 @@ inline void lclDrawPolygon( OutputDevice& rDev, const basegfx::B2DPolygon& rPoly
         rDev.DrawPolygon( aDashPolygon );
     }
 
-    rDev.SetFillColor( aOldColor );
     rDev.SetAntialiasing( nOldAA );
 }
 
 namespace svtools
 {
-    basegfx::B2DPolyPolygon ApplyLineDashing( const basegfx::B2DPolygon& rPolygon, sal_uInt16 nDashing, MapUnit eUnit )
+    std::vector < double > GetDashing( sal_uInt16 nDashing, MapUnit eUnit )
     {
         ::std::vector < double >aPattern;
         switch ( nDashing )
@@ -380,6 +373,12 @@ namespace svtools
                 break;
         }
 
+        return aPattern;
+    }
+
+    basegfx::B2DPolyPolygon ApplyLineDashing( const basegfx::B2DPolygon& rPolygon, sal_uInt16 nDashing, MapUnit eUnit )
+    {
+        std::vector< double > aPattern = GetDashing( nDashing, eUnit );
         basegfx::B2DPolyPolygon aPolygons;
         if ( ! aPattern.empty() )
             basegfx::tools::applyLineDashing( rPolygon, aPattern, &aPolygons );
@@ -392,14 +391,22 @@ namespace svtools
     void DrawLine( OutputDevice& rDev, const Point& rP1, const Point& rP2,
         sal_uInt32 nWidth, sal_uInt16 nDashing )
     {
+        DrawLine( rDev, basegfx::B2DPoint( rP1.X(), rP1.Y() ),
+                basegfx::B2DPoint( rP2.X(), rP2.Y( ) ), nWidth, nDashing );
+    }
+
+    void DrawLine( OutputDevice& rDev, const basegfx::B2DPoint& rP1, const basegfx::B2DPoint& rP2,
+        sal_uInt32 nWidth, sal_uInt16 nDashing )
+    {
         basegfx::B2DPolygon aPolygon;
-        aPolygon.append( basegfx::B2DPoint( rP1.X(), rP1.Y() ) );
-        aPolygon.append( basegfx::B2DPoint( rP2.X(), rP2.Y() ) );
+        aPolygon.append( rP1 );
+        aPolygon.append( rP2 );
         lclDrawPolygon( rDev, aPolygon, nWidth, nDashing );
     }
 }
 
 void LineListBox::ImpGetLine( long nLine1, long nLine2, long nDistance,
+                            Color aColor1, Color aColor2, Color aColorDist,
                             sal_uInt16 nStyle, Bitmap& rBmp, XubString& rStr )
 {
     Size aSize = GetOutputSizePixel();
@@ -448,23 +455,23 @@ void LineListBox::ImpGetLine( long nLine1, long nLine2, long nDistance,
         Size aVirSize = aVirDev.LogicToPixel( aSize );
         if ( aVirDev.GetOutputSizePixel() != aVirSize )
             aVirDev.SetOutputSizePixel( aVirSize );
-        aVirDev.SetFillColor( GetSettings().GetStyleSettings().GetFieldColor() );
+        aVirDev.SetFillColor( aColorDist );
         aVirDev.DrawRect( Rectangle( Point(), aSize ) );
 
-        Color oldColor = aVirDev.GetLineColor( );
-        aVirDev.SetLineColor( GetPaintColor( ) );
+        aVirDev.SetFillColor( aColor1 );
 
-        double y1 = n1 / 2;
-        svtools::DrawLine( aVirDev, Point( 0, y1 ), Point( aSize.Width( ), y1 ), n1, nStyle );
+        double y1 = double( n1 ) / 2;
+        svtools::DrawLine( aVirDev, basegfx::B2DPoint( 0, y1 ), basegfx::B2DPoint( aSize.Width( ), y1 ), n1, nStyle );
 
         if ( n2 )
         {
-            double y2 =  n1 + nDist + n2 / 2;
-            svtools::DrawLine( aVirDev, Point( 0, y2 ), Point( aSize.Width(), y2 ), n2, STYLE_SOLID );
+            double y2 =  n1 + nDist + double( n2 ) / 2;
+            aVirDev.SetFillColor( aColor2 );
+            svtools::DrawLine( aVirDev, basegfx::B2DPoint( 0, y2 ), basegfx::B2DPoint( aSize.Width(), y2 ), n2, STYLE_SOLID );
         }
-        aVirDev.SetLineColor( oldColor );
         rBmp = aVirDev.GetBitmap( Point(), Size( aSize.Width(), n1+nDist+n2 ) );
     }
+
     // Twips nach Unit
     if ( eUnit == FUNIT_POINT )
     {
@@ -537,6 +544,13 @@ LineListBox::~LineListBox()
     delete pLineList;
 }
 
+void LineListBox::SelectEntry( long nLine1, long nLine2, long nDistance, sal_uInt16 nStyle, sal_Bool bSelect )
+{
+    sal_uInt16 nPos = GetEntryPos( nLine1, nLine2, nDistance, nStyle );
+    if ( nPos != LISTBOX_ENTRY_NOTFOUND )
+        ListBox::SelectEntryPos( nPos, bSelect );
+}
+
 // -----------------------------------------------------------------------
 
 sal_uInt16 LineListBox::InsertEntry( const XubString& rStr, sal_uInt16 nPos )
@@ -561,7 +575,11 @@ sal_uInt16 LineListBox::InsertEntry( long nLine1, long nLine2, long nDistance,
 {
     XubString   aStr;
     Bitmap      aBmp;
-    ImpGetLine( nLine1, nLine2, nDistance, nStyle, aBmp, aStr );
+    ImpGetLine( nLine1, nLine2, nDistance,
+            GetColorLine1( GetEntryCount( ) ),
+            GetColorLine2( GetEntryCount( ) ),
+            GetColorDist( GetEntryCount( ) ),
+            nStyle, aBmp, aStr );
     nPos = ListBox::InsertEntry( aStr, aBmp, nPos );
     if ( nPos != LISTBOX_ERROR )
     {
@@ -688,6 +706,7 @@ void LineListBox::UpdateLineColors( void )
                 // exchange listbox data
                 ListBox::RemoveEntry( sal_uInt16( n ) );
                 ImpGetLine( pData->nLine1, pData->nLine2, pData->nDistance,
+                        GetColorLine1( n ), GetColorLine2( n ), GetColorDist( n ),
                         pData->nStyle, aBmp, aStr );
             }
         }
@@ -716,6 +735,21 @@ sal_Bool LineListBox::UpdatePaintLineColor( void )
     return bRet;
 }
 
+Color LineListBox::GetColorLine1( sal_uInt16 )
+{
+    return GetPaintColor( );
+}
+
+Color LineListBox::GetColorLine2( sal_uInt16 )
+{
+    return GetPaintColor( );
+}
+
+Color LineListBox::GetColorDist( sal_uInt16 )
+{
+    return GetSettings().GetStyleSettings().GetFieldColor();
+}
+
 // -----------------------------------------------------------------------
 
 void LineListBox::DataChanged( const DataChangedEvent& rDCEvt )
@@ -727,6 +761,323 @@ void LineListBox::DataChanged( const DataChangedEvent& rDCEvt )
 }
 
 // ===================================================================
+// LineStyleNameBox
+// ===================================================================
+
+class ImpLineStyleListData
+{
+private:
+    double m_nLine1;
+    double m_nLine2;
+    double m_nDist;
+    sal_uInt16 m_nFlags;
+
+    Color  ( *m_pColor1Fn )( Color );
+    Color  ( *m_pColor2Fn )( Color );
+    Color  ( *m_pColorDistFn )( Color, Color );
+
+    long   m_nMinWidth;
+    sal_uInt16 m_nStyle;
+
+public:
+    ImpLineStyleListData( double nLine1, double nLine2, double nDist, sal_uInt16 nFlags, sal_uInt16 nStyle,
+            long nMinWidth=0, Color ( *pColor1Fn ) ( Color ) = &sameColor,
+            Color ( *pColor2Fn ) ( Color ) = &sameColor, Color ( *pColorDistFn ) ( Color, Color ) = &sameDistColor );
+
+    double GetLine1ForWidth( double nWidth );
+    double GetLine2ForWidth( double nWidth );
+    double GetDistForWidth( double nWidth );
+
+    long   GetTotalWidth( double nWidth );
+
+    Color  GetColorLine1( const Color& aMain );
+    Color  GetColorLine2( const Color& aMain );
+    Color  GetColorDist( const Color& aMain, const Color& rDefault );
+
+    long   GetMinWidth( );
+    sal_uInt16 GetStyle( );
+
+    long GuessWidth( long nLine1, long nLine2, long nDist );
+};
+
+ImpLineStyleListData::ImpLineStyleListData( double nLine1, double nLine2, double nDist, sal_uInt16 nFlags,
+       sal_uInt16 nStyle, long nMinWidth, Color ( *pColor1Fn )( Color ),
+       Color ( *pColor2Fn )( Color ), Color ( *pColorDistFn )( Color, Color ) ) :
+    m_nLine1( nLine1 ),
+    m_nLine2( nLine2 ),
+    m_nDist( nDist ),
+    m_nFlags( nFlags ),
+    m_pColor1Fn( pColor1Fn ),
+    m_pColor2Fn( pColor2Fn ),
+    m_pColorDistFn( pColorDistFn ),
+    m_nMinWidth( nMinWidth ),
+    m_nStyle( nStyle )
+{
+}
+
+long ImpLineStyleListData::GetMinWidth( )
+{
+    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 )
+{
+    return ( *m_pColor1Fn )( rMain );
+}
+
+Color ImpLineStyleListData::GetColorLine2( const Color& rMain )
+{
+    return ( *m_pColor2Fn )( rMain );
+}
+
+Color ImpLineStyleListData::GetColorDist( const Color& rMain, const Color& rDefault )
+{
+    return ( *m_pColorDistFn )( rMain, rDefault );
+}
+
+sal_uInt16 ImpLineStyleListData::GetStyle( )
+{
+    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* )
+
+LineStyleListBox::LineStyleListBox( Window* pParent, WinBits nWinStyle ) :
+    LineListBox( pParent, nWinStyle ),
+    m_nWidth( 5 ),
+    m_sNone( )
+{
+    m_pStyleList = new ImpLineStyleList;
+}
+
+LineStyleListBox::LineStyleListBox( Window* pParent, const ResId& rResId ) :
+    LineListBox( pParent, rResId ),
+    m_nWidth( 0 ),
+    m_sNone( )
+{
+    m_pStyleList = new ImpLineStyleList;
+}
+
+LineStyleListBox::~LineStyleListBox( )
+{
+    sal_uInt16 n = 0;
+    sal_uInt16 nCount = m_pStyleList->Count( );
+    while ( n < nCount )
+    {
+        ImpLineStyleListData* pData = m_pStyleList->GetObject( n );
+        if ( pData )
+            delete pData;
+        n++;
+    }
+    delete m_pStyleList;
+}
+
+void LineStyleListBox::InsertEntry( double nLine1, double nLine2, double nDist,
+        sal_uInt16 nChangeFlags, sal_uInt16 nStyle, long nMinWidth,
+        Color ( *pColor1Fn )( Color ), Color ( *pColor2Fn )( Color ),
+        Color ( *pColorDistFn )( Color, Color ) )
+{
+    ImpLineStyleListData* pData = new ImpLineStyleListData( nLine1, nLine2, nDist,
+           nChangeFlags, nStyle, nMinWidth,
+           pColor1Fn, pColor2Fn, pColorDistFn );
+    m_pStyleList->Insert( pData, m_pStyleList->Count( ) );
+}
+
+Color LineStyleListBox::GetColorLine1( sal_uInt16 nPos )
+{
+    Color rResult = LineListBox::GetColorLine1( );
+
+    sal_uInt16 nStyle = GetStylePos( nPos, m_nWidth );
+    ImpLineStyleListData* pData = m_pStyleList->GetObject( nStyle );
+    if ( pData )
+        rResult = pData->GetColorLine1( GetColor( ) );
+
+    return rResult;
+}
+
+Color LineStyleListBox::GetColorLine2( sal_uInt16 nPos )
+{
+    Color rResult = LineListBox::GetColorLine2( );
+
+    sal_uInt16 nStyle = GetStylePos( nPos, m_nWidth );
+    ImpLineStyleListData* pData = m_pStyleList->GetObject( nStyle );
+    if ( pData )
+        rResult = pData->GetColorLine2( GetColor( ) );
+
+    return rResult;
+}
+
+Color LineStyleListBox::GetColorDist( sal_uInt16 nPos )
+{
+    Color rResult = LineListBox::GetColorDist( );
+
+    sal_uInt16 nStyle = GetStylePos( nPos, m_nWidth );
+    ImpLineStyleListData* pData = m_pStyleList->GetObject( nStyle );
+    if ( pData )
+        rResult = pData->GetColorDist( GetColor( ), rResult );
+
+    return rResult;
+}
+
+sal_uInt16 LineStyleListBox::GetSelectedStyle( )
+{
+    sal_uInt16 nSelEntry = GetSelectEntryPos();
+    if ( m_sNone.Len( ) > 0 )
+        nSelEntry--;
+    return GetStylePos( nSelEntry, m_nWidth );
+}
+
+long LineStyleListBox::GetWidthFromStyle( long nLine1, long nLine2, long nDistance, sal_uInt16 nStyle )
+{
+    long nResult = 0;
+//    sal_uInt16 nStyle = GetSelectedStyle();
+    ImpLineStyleListData* pData = m_pStyleList->GetObject( nStyle );
+    if ( pData )
+    {
+        nResult = pData->GuessWidth( nLine1, nLine2, nDistance );
+    }
+    return nResult;
+}
+
+sal_uInt16 LineStyleListBox::GetEntryPos( long /*nLine1*/, long /*nLine2*/,
+                                long /*nDistance*/, sal_uInt16 nStyle ) const
+{
+    sal_uInt16 nPos = LISTBOX_ENTRY_NOTFOUND;
+    sal_uInt16 n = 0;
+    sal_uInt16 nCount = this->GetEntryCount( );
+    while ( n < nCount )
+    {
+        if ( GetEntryStyle( n ) == nStyle )
+            nPos = (sal_uInt16)n;
+
+        n++;
+    }
+
+    return nPos;
+}
+
+sal_uInt16 LineStyleListBox::GetStylePos( sal_uInt16 nListPos, long nWidth )
+{
+    sal_uInt16 nPos = LISTBOX_ENTRY_NOTFOUND;
+    if ( m_sNone.Len( ) > 0 )
+        nListPos--;
+
+    sal_uInt16 i = 0;
+    sal_uInt16 n = 0;
+    sal_uInt16 nCount = m_pStyleList->Count( );
+    while ( nPos == LISTBOX_ENTRY_NOTFOUND && i < nCount )
+    {
+        ImpLineStyleListData* pData = m_pStyleList->GetObject( i );
+        if ( pData && pData->GetMinWidth() <= nWidth )
+        {
+            if ( nListPos == n )
+                nPos = i;
+            n++;
+        }
+        i++;
+    }
+
+    return nPos;
+}
+
+void LineStyleListBox::UpdateEntries( long nOldWidth )
+{
+    SetUpdateMode( sal_False );
+
+    sal_uInt16		nSelEntry = GetSelectEntryPos();
+    sal_uInt16       nTypePos = GetStylePos( nSelEntry, nOldWidth );
+
+    // Remove the old entries
+    while ( GetEntryCount( ) > 0 )
+        RemoveEntry( 0 );
+
+    // Add the new entries based on the defined width
+    if ( m_sNone.Len( ) > 0 )
+        InsertEntry( m_sNone );
+
+    sal_uInt16 n = 0;
+    sal_uInt16 nCount = m_pStyleList->Count( );
+    while ( n < nCount )
+    {
+        ImpLineStyleListData* pData = m_pStyleList->GetObject( n );
+        if ( pData && pData->GetMinWidth() <= m_nWidth )
+        {
+            InsertEntry(
+                   pData->GetLine1ForWidth( m_nWidth ),
+                   pData->GetLine2ForWidth( m_nWidth ),
+                   pData->GetDistForWidth( m_nWidth ),
+                   pData->GetStyle( ) );
+            if ( n == nTypePos )
+                SelectEntryPos( GetEntryCount() - 1 );
+        }
+        else if ( n == nTypePos )
+            SetNoSelection();
+        n++;
+    }
+
+    SetColor( GetColor( ) );
+
+    SetUpdateMode( sal_True );
+    Invalidate();
+}
+
+// ===================================================================
 // FontNameBox
 // ===================================================================
 


More information about the Libreoffice-commits mailing list