1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_EDITENG_BORDERLINE_HXX
21 #define INCLUDED_EDITENG_BORDERLINE_HXX
23 #include <com/sun/star/table/BorderLineStyle.hpp>
25 #include <tools/color.hxx>
26 #include <svl/poolitem.hxx>
27 #include <editeng/editengdllapi.h>
28 #include <svtools/ctrlbox.hxx>
30 // Line defaults in twips (former Writer defaults):
32 #define DEF_LINE_WIDTH_0 1
33 #define DEF_LINE_WIDTH_1 20
34 #define DEF_LINE_WIDTH_2 50
35 #define DEF_LINE_WIDTH_3 80
36 #define DEF_LINE_WIDTH_4 100
37 #define DEF_LINE_WIDTH_5 10
43 // values from ::com::sun::star::table::BorderLineStyle
44 typedef sal_Int16 SvxBorderStyle
;
46 // convert border style between Word formats and LO
47 SvxBorderStyle EDITENG_DLLPUBLIC
ConvertBorderStyleFromWord(int);
48 /// convert border width in twips between Word formats and LO
49 double EDITENG_DLLPUBLIC
ConvertBorderWidthToWord(SvxBorderStyle
, double);
50 double EDITENG_DLLPUBLIC
ConvertBorderWidthFromWord(SvxBorderStyle
,
53 class EDITENG_DLLPUBLIC SvxBorderLine
60 BorderWidthImpl m_aWidthImpl
;
64 SvxBorderStyle m_nStyle
;
67 Color (*m_pColorOutFn
)( Color
);
68 Color (*m_pColorInFn
)( Color
);
69 Color (*m_pColorGapFn
)( Color
);
72 SvxBorderLine( const Color
*pCol
= 0,
73 long nWidth
= 0, SvxBorderStyle nStyle
=
74 ::com::sun::star::table::BorderLineStyle::SOLID
,
75 bool bUseLeftTop
= false,
76 Color (*pColorOutFn
)( Color
) = &darkColor
,
77 Color (*pColorInFn
)( Color
) = &darkColor
,
78 Color (*pColorGapFn
)( Color
) = NULL
);
79 SvxBorderLine( const SvxBorderLine
& r
);
81 SvxBorderLine
& operator=( const SvxBorderLine
& r
);
83 const Color
& GetColor() const { return aColor
; }
84 Color
GetColorOut( bool bLeftOrTop
= true ) const;
85 Color
GetColorIn( bool bLeftOrTop
= true ) const;
86 bool HasGapColor() const { return m_pColorGapFn
!= NULL
; }
87 Color
GetColorGap() const;
89 void SetWidth( long nWidth
= 0 );
90 /** Guess the style and width from the three lines widths values.
92 When the value of nStyle is SvxBorderLine::DOUBLE, the style set will be guessed
93 using the three values to match the best possible style among the following:
94 - SvxBorderLine::DOUBLE
95 - SvxBorderLine::THINTHICK_SMALLGAP
96 - SvxBorderLine::THINTHICK_MEDIUMGAP
97 - SvxBorderLine::THINTHICK_LARGEGAP
98 - SvxBorderLine::THICKTHIN_SMALLGAP
99 - SvxBorderLine::THICKTHIN_MEDIUMGAP
100 - SvxBorderLine::THICKTHIN_LARGEGAP
102 If no styles matches the width, then the width is set to 0.
104 There is one known case that could fit several styles: \a nIn = \a nDist = 0.75 pt,
105 \a nOut = 1.5 pt. This case fits SvxBorderLine::THINTHICK_SMALLGAP and
106 SvxBorderLine::THINTHICK_MEDIUMGAP with a 1.5 pt width and
107 SvxBorderLine::THINTHICK_LARGEGAP with a 0.75 pt width. The same case happens
108 also for thick-thin styles.
110 \param nStyle the border style used to guess the width.
111 \param nIn the width of the inner line in 1th pt
112 \param nOut the width of the outer line in 1th pt
113 \param nDist the width of the gap between the lines in 1th pt
115 void GuessLinesWidths( SvxBorderStyle nStyle
, sal_uInt16 nOut
, sal_uInt16 nIn
= 0, sal_uInt16 nDist
= 0 );
117 // TODO Hacky method to mirror lines in only a few cases
118 void SetMirrorWidths( bool bMirror
= true ) { m_bMirrorWidths
= bMirror
; }
119 long GetWidth( ) const { return m_nWidth
; }
120 sal_uInt16
GetOutWidth() const;
121 sal_uInt16
GetInWidth() const;
122 sal_uInt16
GetDistance() const;
124 SvxBorderStyle
GetBorderLineStyle() const { return m_nStyle
; }
126 void SetColor( const Color
&rColor
) { aColor
= rColor
; }
127 void SetColorOutFn( Color (*pColorOutFn
)( Color
) ) { m_pColorOutFn
= pColorOutFn
; }
128 void SetColorInFn( Color (*pColorInFn
)( Color
) ) { m_pColorInFn
= pColorInFn
; }
129 void SetColorGapFn( Color (*pColorGapFn
)( Color
) ) { m_pColorGapFn
= pColorGapFn
; }
130 void SetUseLeftTop( bool bUseLeftTop
) { m_bUseLeftTop
= bUseLeftTop
; }
131 void SetBorderLineStyle( SvxBorderStyle nNew
);
132 void ScaleMetrics( long nMult
, long nDiv
);
134 bool operator==( const SvxBorderLine
&rCmp
) const;
136 OUString
GetValueString( SfxMapUnit eSrcUnit
, SfxMapUnit eDestUnit
,
137 const IntlWrapper
* pIntl
,
138 bool bMetricStr
= false ) const;
140 bool HasPriority( const SvxBorderLine
& rOtherLine
) const;
142 bool isEmpty() const {
143 return m_aWidthImpl
.IsEmpty()
144 || m_nStyle
== ::com::sun::star::table::BorderLineStyle::NONE
147 bool isDouble() const { return m_aWidthImpl
.IsDouble(); }
148 sal_uInt16
GetScaledWidth() const { return GetOutWidth() + GetInWidth() + GetDistance(); }
150 static Color
darkColor( Color aMain
);
151 static Color
lightColor( Color aMain
);
153 static Color
threeDLightColor( Color aMain
);
154 static Color
threeDMediumColor( Color aMain
);
155 static Color
threeDDarkColor( Color aMain
);
157 static BorderWidthImpl
getWidthImpl( SvxBorderStyle nStyle
);
160 EDITENG_DLLPUBLIC
bool operator!=( const SvxBorderLine
& rLeft
, const SvxBorderLine
& rRight
);
162 } // namespace editeng
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */