summaryrefslogtreecommitdiff
path: root/editeng
diff options
context:
space:
mode:
authorCédric Bosdonnat <cedricbosdo@openoffice.org>2010-11-06 19:23:59 +0100
committerCédric Bosdonnat <cedricbosdo@openoffice.org>2011-03-19 17:57:15 +0100
commit55077bf762e058facd5692c83f5d2bce2d8c4ce4 (patch)
treee6080c2d7b46bbafb9e89d95d2979fbe4406ca04 /editeng
parent9061806bb3c4ca0acd391dd697f4757db6b7cdbc (diff)
Nicely draw borders using drawinglayer
Diffstat (limited to 'editeng')
-rwxr-xr-xediteng/inc/editeng/borderline.hxx42
-rw-r--r--editeng/source/items/frmitems.cxx175
2 files changed, 198 insertions, 19 deletions
diff --git a/editeng/inc/editeng/borderline.hxx b/editeng/inc/editeng/borderline.hxx
index 9acb60e24a..d4a5fcf27a 100755
--- a/editeng/inc/editeng/borderline.hxx
+++ b/editeng/inc/editeng/borderline.hxx
@@ -95,7 +95,18 @@ enum SvxBorderStyle
{
SOLID,
DOTTED,
- DASHED
+ DASHED,
+ DOUBLE,
+ THINTHICK_SMALLGAP,
+ THINTHICK_MEDIUMGAP,
+ THINTHICK_LARGEGAP,
+ THICKTHIN_SMALLGAP,
+ THICKTHIN_MEDIUMGAP,
+ THICKTHIN_LARGEGAP,
+ EMBOSSED,
+ ENGRAVED,
+ OUTSET,
+ INSET
};
class EDITENG_DLLPUBLIC SvxBorderLine
@@ -107,14 +118,25 @@ protected:
sal_uInt16 nInWidth;
sal_uInt16 nDistance;
+ bool m_bUseLeftTop;
+ Color (*m_pColorOutFn)( Color );
+ Color (*m_pColorInFn)( Color );
+ Color (*m_pColorGapFn)( Color );
+
public:
SvxBorderLine( const Color *pCol = 0, sal_uInt16 nOut = 0, sal_uInt16 nIn = 0, sal_uInt16 nDist = 0,
- SvxBorderStyle nStyle = SOLID );
+ SvxBorderStyle nStyle = SOLID, bool bUseLeftTop = false,
+ Color (*pColorOutFn)( Color ) = &darkColor, Color (*pColorInFn)( Color ) = &darkColor,
+ Color (*pColorGapFn)( Color ) = NULL );
SvxBorderLine( const SvxBorderLine& r );
SvxBorderLine& operator=( const SvxBorderLine& r );
- const Color& GetColor() const { return aColor; }
+ const Color& GetColor() const { return aColor; }
+ Color GetColorOut( bool bLeftOrTop = true ) const;
+ Color GetColorIn( bool bLeftOrTop = true ) const;
+ bool HasGapColor() const { return m_pColorGapFn != NULL; }
+ Color GetColorGap() const;
sal_uInt16 GetOutWidth() const { return nOutWidth; }
sal_uInt16 GetInWidth() const { return nInWidth; }
sal_uInt16 GetDistance() const { return nDistance; }
@@ -122,10 +144,14 @@ public:
SvxBorderStyle GetStyle() const { return m_nStyle; }
void SetColor( const Color &rColor ) { aColor = rColor; }
- void SetStyle( SvxBorderStyle nNew ) { m_nStyle = nNew; }
+ void SetColorOutFn( Color (*pColorOutFn)( Color ) ) { m_pColorOutFn = pColorOutFn; }
+ void SetColorInFn( Color (*pColorInFn)( Color ) ) { m_pColorInFn = pColorInFn; }
+ void SetColorGapFn( Color (*pColorGapFn)( Color ) ) { m_pColorGapFn = pColorGapFn; }
+ void SetUseLeftTop( bool bUseLeftTop ) { m_bUseLeftTop = bUseLeftTop; }
void SetOutWidth( sal_uInt16 nNew ) { nOutWidth = nNew; }
void SetInWidth( sal_uInt16 nNew ) { nInWidth = nNew; }
void SetDistance( sal_uInt16 nNew ) { nDistance = nNew; }
+ void SetStyle( SvxBorderStyle nNew );
void ScaleMetrics( long nMult, long nDiv );
sal_Bool operator==( const SvxBorderLine &rCmp ) const;
@@ -139,6 +165,14 @@ public:
bool isEmpty() const { return (0 == nOutWidth && 0 == nInWidth && 0 == nDistance); }
bool isDouble() const { return (0 != nOutWidth && 0 != nInWidth); }
sal_uInt16 getWidth() const { return nOutWidth + nInWidth + nDistance; }
+
+ static Color darkColor( Color aMain );
+ static Color lightColor( Color aMain );
+
+ static Color threeDLightColor( Color aMain );
+ static Color threeDMediumColor( Color aMain );
+ static Color threeDDarkColor( Color aMain );
+
};
// ============================================================================
diff --git a/editeng/source/items/frmitems.cxx b/editeng/source/items/frmitems.cxx
index 042dcca98c..e6981ba6a6 100644
--- a/editeng/source/items/frmitems.cxx
+++ b/editeng/source/items/frmitems.cxx
@@ -2,7 +2,7 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
@@ -63,6 +63,7 @@
#include <svl/memberid.hrc>
#include <svtools/wallitem.hxx>
#include <svl/cntwall.hxx>
+#include <svtools/borderhelper.hxx>
#include <rtl/ustring.hxx>
#include <rtl/ustrbuf.hxx>
#include <svtools/filter.hxx>
@@ -93,6 +94,9 @@
#include <editeng/memberids.hrc>
#include <editeng/editerr.hxx>
+#include <basegfx/color/bcolor.hxx>
+#include <basegfx/color/bcolortools.hxx>
+
using namespace ::rtl;
using namespace ::com::sun::star;
@@ -105,7 +109,6 @@ using namespace ::com::sun::star;
// STATIC DATA -----------------------------------------------------------
-
inline void SetValueProp( XubString& rStr, const sal_uInt16 nValue,
const sal_uInt16 nProp )
{
@@ -142,7 +145,6 @@ TYPEINIT1_FACTORY(SvxFmtKeepItem, SfxBoolItem, new SvxFmtKeepItem(sal_False, 0))
TYPEINIT1_FACTORY(SvxLineItem, SfxPoolItem, new SvxLineItem(0));
TYPEINIT1_FACTORY(SvxFrameDirectionItem, SfxUInt16Item, new SvxFrameDirectionItem(FRMDIR_HORI_LEFT_TOP, 0));
-
// class SvxPaperBinItem ------------------------------------------------
SfxPoolItem* SvxPaperBinItem::Clone( SfxItemPool* ) const
@@ -380,7 +382,6 @@ bool SvxSizeItem::HasMetrics() const
// -----------------------------------------------------------------------
-
SfxPoolItem* SvxSizeItem::Create( SvStream& rStrm, sal_uInt16 ) const
{
long nWidth, nHeight;
@@ -894,7 +895,6 @@ bool SvxULSpaceItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
}
break;
-
default:
OSL_FAIL("unknown MemberId");
return false;
@@ -1033,7 +1033,6 @@ bool SvxULSpaceItem::HasMetrics() const
return true;
}
-
// class SvxPrintItem ----------------------------------------------------
SfxPoolItem* SvxPrintItem::Clone( SfxItemPool* ) const
@@ -1547,12 +1546,73 @@ void SvxShadowItem::SetEnumValue( sal_uInt16 nVal )
// class SvxBorderLine --------------------------------------------------
+Color SvxBorderLine::darkColor( Color aMain )
+{
+ return aMain;
+}
+
+Color SvxBorderLine::lightColor( Color aMain )
+{
+
+ // Divide Luminance by 2
+ basegfx::BColor color = aMain.getBColor( );
+ basegfx::BColor hsl = basegfx::tools::rgb2hsl( color );
+ hsl.setZ( hsl.getZ() * 0.5 );
+ color = basegfx::tools::hsl2rgb( hsl );
+
+ return Color( color );
+}
+
+Color lcl_compute3DColor( Color aMain, int nLight, int nMedium, int nDark )
+{
+ basegfx::BColor color = aMain.getBColor( );
+ basegfx::BColor hsl = basegfx::tools::rgb2hsl( color );
+
+ int nCoef = 0;
+ if ( hsl.getZ( ) >= 0.5 )
+ nCoef = nLight;
+ else if ( 0.5 > hsl.getZ() && hsl.getZ() >= 0.25 )
+ nCoef = nMedium;
+ else
+ nCoef = nDark;
+
+ double L = hsl.getZ() * 255.0 + nCoef;
+ hsl.setZ( L / 255.0 );
+ color = basegfx::tools::hsl2rgb( hsl );
+
+ return Color( color );
+}
+
+Color SvxBorderLine::threeDLightColor( Color aMain )
+{
+ // These values have been defined in an empirical way
+ return lcl_compute3DColor( aMain, 3, 40, 83 );
+}
+
+Color SvxBorderLine::threeDDarkColor( Color aMain )
+{
+ // These values have been defined in an empirical way
+ return lcl_compute3DColor( aMain, -85, -43, -1 );
+}
+
+Color SvxBorderLine::threeDMediumColor( Color aMain )
+{
+ // These values have been defined in an empirical way
+ return lcl_compute3DColor( aMain, -42, -0, 42 );
+}
+
SvxBorderLine::SvxBorderLine( const Color *pCol, sal_uInt16 nOut, sal_uInt16 nIn, sal_uInt16 nDist,
- SvxBorderStyle nStyle )
+ SvxBorderStyle nStyle, bool bUseLeftTop,
+ Color (*pColorOutFn)( Color ), Color (*pColorInFn)( Color ),
+ Color (*pColorGapFn)( Color ) )
: m_nStyle( nStyle )
, nOutWidth( nOut )
, nInWidth ( nIn )
, nDistance( nDist )
+, m_bUseLeftTop( bUseLeftTop )
+, m_pColorOutFn( pColorOutFn )
+, m_pColorInFn( pColorInFn )
+, m_pColorGapFn( pColorGapFn )
{
if ( pCol )
aColor = *pCol;
@@ -1574,6 +1634,10 @@ SvxBorderLine& SvxBorderLine::operator=( const SvxBorderLine& r )
nInWidth = r.nInWidth;
nDistance = r.nDistance;
m_nStyle = r.m_nStyle;
+ m_bUseLeftTop = r.m_bUseLeftTop;
+ m_pColorOutFn = r.m_pColorOutFn;
+ m_pColorInFn = r.m_pColorInFn;
+ m_pColorGapFn = r.m_pColorGapFn;
return *this;
}
@@ -1590,11 +1654,95 @@ void SvxBorderLine::ScaleMetrics( long nMult, long nDiv )
sal_Bool SvxBorderLine::operator==( const SvxBorderLine& rCmp ) const
{
- return ( ( aColor == rCmp.GetColor() ) &&
- ( nInWidth == rCmp.GetInWidth() ) &&
- ( nOutWidth == rCmp.GetOutWidth() ) &&
- ( nDistance == rCmp.GetDistance() ) &&
- ( m_nStyle == rCmp.GetStyle() ) );
+ return ( ( aColor == rCmp.aColor ) &&
+ ( nInWidth == rCmp.GetInWidth() ) &&
+ ( nOutWidth == rCmp.GetOutWidth() ) &&
+ ( nDistance == rCmp.GetDistance() ) &&
+ ( m_nStyle == rCmp.GetStyle() ) &&
+ ( m_bUseLeftTop == rCmp.m_bUseLeftTop ) &&
+ ( m_pColorOutFn == rCmp.m_pColorOutFn ) &&
+ ( m_pColorInFn == rCmp.m_pColorInFn ) &&
+ ( m_pColorGapFn == rCmp.m_pColorGapFn ) );
+}
+
+void SvxBorderLine::SetStyle( SvxBorderStyle nNew )
+{
+ m_nStyle = nNew;
+ switch ( nNew )
+ {
+ case EMBOSSED:
+ m_pColorOutFn = threeDLightColor;
+ m_pColorInFn = threeDDarkColor;
+ m_pColorGapFn = threeDMediumColor;
+ m_bUseLeftTop = true;
+ break;
+ case ENGRAVED:
+ m_pColorOutFn = threeDDarkColor;
+ m_pColorInFn = threeDLightColor;
+ m_pColorGapFn = threeDMediumColor;
+ m_bUseLeftTop = true;
+ break;
+ case OUTSET:
+ m_pColorOutFn = lightColor;
+ m_pColorInFn = darkColor;
+ m_bUseLeftTop = true;
+ m_pColorGapFn = NULL;
+ break;
+ case INSET:
+ m_pColorOutFn = darkColor;
+ m_pColorInFn = lightColor;
+ m_bUseLeftTop = true;
+ m_pColorGapFn = NULL;
+ break;
+ default:
+ m_pColorOutFn = darkColor;
+ m_pColorInFn = darkColor;
+ m_bUseLeftTop = false;
+ m_pColorGapFn = NULL;
+ break;
+ }
+}
+
+Color SvxBorderLine::GetColorOut( bool bLeftOrTop ) const
+{
+ Color aResult = aColor;
+
+ if ( nInWidth > 0 && nOutWidth > 0 && m_pColorOutFn != NULL )
+ {
+ if ( !bLeftOrTop && m_bUseLeftTop )
+ aResult = (*m_pColorInFn)( aColor );
+ else
+ aResult = (*m_pColorOutFn)( aColor );
+ }
+
+ return aResult;
+}
+
+Color SvxBorderLine::GetColorIn( bool bLeftOrTop ) const
+{
+ Color aResult = aColor;
+
+ if ( nInWidth > 0 && nOutWidth > 0 && m_pColorInFn != NULL )
+ {
+ if ( !bLeftOrTop && m_bUseLeftTop )
+ aResult = (*m_pColorOutFn)( aColor );
+ else
+ aResult = (*m_pColorInFn)( aColor );
+ }
+
+ return aResult;
+}
+
+Color SvxBorderLine::GetColorGap( ) const
+{
+ Color aResult = aColor;
+
+ if ( nInWidth > 0 && nOutWidth > 0 && m_pColorGapFn != NULL )
+ {
+ aResult = (*m_pColorGapFn)( aColor );
+ }
+
+ return aResult;
}
// -----------------------------------------------------------------------
@@ -2640,7 +2788,6 @@ void SvxBoxInfoItem::SetLine( const SvxBorderLine* pNew, sal_uInt16 nLine )
}
}
-
// -----------------------------------------------------------------------
SfxPoolItem* SvxBoxInfoItem::Clone( SfxItemPool* ) const
@@ -3174,7 +3321,6 @@ SvxLineItem::SvxLineItem( const SvxLineItem& rCpy ) :
pLine = rCpy.GetLine() ? new SvxBorderLine( *rCpy.GetLine() ) : 0;
}
-
// -----------------------------------------------------------------------
SvxLineItem::~SvxLineItem()
@@ -4188,7 +4334,6 @@ WallpaperStyle SvxBrushItem::GraphicPos2WallpaperStyle( SvxGraphicPosition ePos
return eResult;
}
-
SvxBrushItem::SvxBrushItem( const CntWallpaperItem& rItem, sal_uInt16 _nWhich ) :
SfxPoolItem( _nWhich ),
pImpl( new SvxBrushItem_Impl( 0 ) ),