Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef SVX_BORDERLINE_HXX
30 : : #define SVX_BORDERLINE_HXX
31 : :
32 : : #include <com/sun/star/table/BorderLineStyle.hpp>
33 : :
34 : : #include <tools/color.hxx>
35 : : #include <svl/poolitem.hxx>
36 : : #include <editeng/editengdllapi.h>
37 : : #include <svtools/ctrlbox.hxx>
38 : :
39 : : // Line defaults in twips (former Writer defaults):
40 : :
41 : : #define DEF_LINE_WIDTH_0 1
42 : : #define DEF_LINE_WIDTH_1 20
43 : : #define DEF_LINE_WIDTH_2 50
44 : : #define DEF_LINE_WIDTH_3 80
45 : : #define DEF_LINE_WIDTH_4 100
46 : : #define DEF_LINE_WIDTH_5 10
47 : :
48 : : // ============================================================================
49 : :
50 : : namespace editeng {
51 : :
52 : : // values from ::com::sun::star::table::BorderLineStyle
53 : : typedef sal_Int16 SvxBorderStyle;
54 : :
55 : : /// convert border width in twips between Word formats and LO
56 : : double EDITENG_DLLPUBLIC ConvertBorderWidthToWord(SvxBorderStyle, double);
57 : : double EDITENG_DLLPUBLIC ConvertBorderWidthFromWord(SvxBorderStyle, double);
58 : :
59 : : class EDITENG_DLLPUBLIC SvxBorderLine
60 : : {
61 : : protected:
62 : : Color aColor;
63 : :
64 : : long m_nWidth;
65 : : bool m_bMirrorWidths;
66 : : BorderWidthImpl m_aWidthImpl;
67 : : long m_nMult;
68 : : long m_nDiv;
69 : :
70 : : SvxBorderStyle m_nStyle;
71 : : sal_uInt16 nOutWidth;
72 : : sal_uInt16 nInWidth;
73 : : sal_uInt16 nDistance;
74 : :
75 : : bool m_bUseLeftTop;
76 : : Color (*m_pColorOutFn)( Color );
77 : : Color (*m_pColorInFn)( Color );
78 : : Color (*m_pColorGapFn)( Color );
79 : :
80 : : public:
81 : : SvxBorderLine( const Color *pCol = 0,
82 : : long nWidth = 0, SvxBorderStyle nStyle =
83 : : ::com::sun::star::table::BorderLineStyle::SOLID,
84 : : bool bUseLeftTop = false,
85 : : Color (*pColorOutFn)( Color ) = &darkColor,
86 : : Color (*pColorInFn)( Color ) = &darkColor,
87 : : Color (*pColorGapFn)( Color ) = NULL );
88 : : SvxBorderLine( const SvxBorderLine& r );
89 : :
90 : : SvxBorderLine& operator=( const SvxBorderLine& r );
91 : :
92 : 20754 : const Color& GetColor() const { return aColor; }
93 : : Color GetColorOut( bool bLeftOrTop = true ) const;
94 : : Color GetColorIn( bool bLeftOrTop = true ) const;
95 : 43367 : bool HasGapColor() const { return m_pColorGapFn != NULL; }
96 : : Color GetColorGap() const;
97 : :
98 : 4489 : void SetWidth( long nWidth = 0 ) { m_nWidth = nWidth; }
99 : : /** Guess the style and width from the three lines widths values.
100 : :
101 : : When the value of nStyle is SvxBorderLine::DOUBLE, the style set will be guessed
102 : : using the three values to match the best possible style among the following:
103 : : - SvxBorderLine::DOUBLE
104 : : - SvxBorderLine::THINTHICK_SMALLGAP
105 : : - SvxBorderLine::THINTHICK_MEDIUMGAP
106 : : - SvxBorderLine::THINTHICK_LARGEGAP
107 : : - SvxBorderLine::THICKTHIN_SMALLGAP
108 : : - SvxBorderLine::THICKTHIN_MEDIUMGAP
109 : : - SvxBorderLine::THICKTHIN_LARGEGAP
110 : :
111 : : If no styles matches the width, then the width is set to 0.
112 : :
113 : : There is one known case that could fit several styles: \a nIn = \a nDist = 0.75 pt,
114 : : \a nOut = 1.5 pt. This case fits SvxBorderLine::THINTHICK_SMALLGAP and
115 : : SvxBorderLine::THINTHICK_MEDIUMGAP with a 1.5 pt width and
116 : : SvxBorderLine::THINTHICK_LARGEGAP with a 0.75 pt width. The same case happens
117 : : also for thick-thin styles.
118 : :
119 : : \param nStyle the border style used to guess the width.
120 : : \param nIn the width of the inner line in 1th pt
121 : : \param nOut the width of the outer line in 1th pt
122 : : \param nDist the width of the gap between the lines in 1th pt
123 : : */
124 : : void GuessLinesWidths( SvxBorderStyle nStyle, sal_uInt16 nOut, sal_uInt16 nIn = 0, sal_uInt16 nDist = 0 );
125 : :
126 : : // TODO Hacky method to mirror lines in only a few cases
127 : 0 : void SetMirrorWidths( bool bMirror = true ) { m_bMirrorWidths = bMirror; }
128 : 2143 : long GetWidth( ) const { return m_nWidth; }
129 : : sal_uInt16 GetOutWidth() const;
130 : : sal_uInt16 GetInWidth() const;
131 : : sal_uInt16 GetDistance() const;
132 : :
133 : 93034 : SvxBorderStyle GetBorderLineStyle() const { return m_nStyle; }
134 : :
135 : 7199 : void SetColor( const Color &rColor ) { aColor = rColor; }
136 : : void SetColorOutFn( Color (*pColorOutFn)( Color ) ) { m_pColorOutFn = pColorOutFn; }
137 : : void SetColorInFn( Color (*pColorInFn)( Color ) ) { m_pColorInFn = pColorInFn; }
138 : : void SetColorGapFn( Color (*pColorGapFn)( Color ) ) { m_pColorGapFn = pColorGapFn; }
139 : : void SetUseLeftTop( bool bUseLeftTop ) { m_bUseLeftTop = bUseLeftTop; }
140 : : void SetBorderLineStyle( SvxBorderStyle nNew );
141 : : void ScaleMetrics( long nMult, long nDiv );
142 : :
143 : : sal_Bool operator==( const SvxBorderLine &rCmp ) const;
144 : :
145 : : String GetValueString( SfxMapUnit eSrcUnit, SfxMapUnit eDestUnit,
146 : : const IntlWrapper* pIntl,
147 : : sal_Bool bMetricStr = sal_False ) const;
148 : :
149 : : bool HasPriority( const SvxBorderLine& rOtherLine ) const;
150 : :
151 : 6156 : bool isEmpty() const {
152 : 6156 : return m_aWidthImpl.IsEmpty()
153 : : || m_nStyle == ::com::sun::star::table::BorderLineStyle::NONE
154 [ + - ][ + + ]: 6156 : || m_nWidth == 0;
[ + - ]
155 : : }
156 : 6 : bool isDouble() const { return m_aWidthImpl.IsDouble(); }
157 : 9056 : sal_uInt16 GetScaledWidth() const { return GetOutWidth() + GetInWidth() + GetDistance(); }
158 : :
159 : : static Color darkColor( Color aMain );
160 : : static Color lightColor( Color aMain );
161 : :
162 : : static Color threeDLightColor( Color aMain );
163 : : static Color threeDMediumColor( Color aMain );
164 : : static Color threeDDarkColor( Color aMain );
165 : :
166 : : static BorderWidthImpl getWidthImpl( SvxBorderStyle nStyle );
167 : : };
168 : :
169 : : // ============================================================================
170 : :
171 : : } // namespace editeng
172 : :
173 : : #endif
174 : :
175 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|