tdf#124953: Use rangelist's combined range top-left address...
[LibreOffice.git] / include / svx / framelink.hxx
blobfa629fc24ad2afd3064c1ffa7e0b5134394b10c4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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_SVX_FRAMELINK_HXX
21 #define INCLUDED_SVX_FRAMELINK_HXX
23 #include <algorithm>
24 #include <sal/types.h>
25 #include <tools/color.hxx>
26 #include <svx/svxdllapi.h>
27 #include <vcl/outdev.hxx>
28 #include <editeng/borderline.hxx>
30 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
32 class Point;
33 namespace tools { class Rectangle; }
34 class OutputDevice;
35 namespace svx { namespace frame { class Cell; }}
37 namespace svx {
38 namespace frame {
41 // Enums
44 /** Specifies how the reference points for frame borders are used.
46 enum class RefMode
48 /** Frame borders are drawn centered to the reference points. */
49 Centered,
51 /** The reference points specify the begin of the frame border width.
53 The result is that horizontal lines are drawn below, and vertical lines
54 are drawn right of the reference points.
56 Begin,
58 /** The reference points specify the end of the frame border width.
60 The result is that horizontal lines are drawn above, and vertical lines
61 are drawn left of the reference points.
63 End
67 // Classes
70 /** Contains the widths of primary and secondary line of a frame style.
72 In the following, "frame style" is a complete style of one frame border,
73 i.e. the double line at the left side of the frame. A "line" is always a
74 trivial single line, i.e. the first line of a double frame style.
76 The following states of the members of this struct are valid:
78 mnPrim mnDist mnSecn frame style
79 -------------------------------------------------
80 0 0 0 invisible
81 >0 0 0 single
82 >0 >0 >0 double
84 The behaviour of the member functions for other states is not defined.
86 Per definition the primary line in double frame styles is:
87 - The top line for horizontal frame borders.
88 - The left line for vertical frame borders.
89 - The bottom-left line for top-left to bottom-right diagonal frame borders.
90 - The top-left line for bottom-left to top-right diagonal frame borders.
92 The following picture shows the upper end of a vertical double frame
93 border.
95 |<---------------- GetWidth() ----------------->|
96 | |
97 |<----- mnPrim ----->||<- mnDist ->||<- mnSecn >|
98 | || || |
99 ###################### #############
100 ###################### #############
101 ###################### #############
102 ###################### #############
103 ###################### | #############
104 ###################### | #############
106 |<- middle of the frame border
108 class SAL_WARN_UNUSED SVX_DLLPUBLIC Style
110 private:
111 class implStyle
113 private:
114 friend class Style;
116 Color maColorPrim;
117 Color maColorSecn;
118 Color maColorGap;
119 bool mbUseGapColor;
120 RefMode meRefMode; /// Reference point handling for this frame border.
121 double mfPrim; /// Width of primary (single, left, or top) line.
122 double mfDist; /// Distance between primary and secondary line.
123 double mfSecn; /// Width of secondary (right or bottom) line.
124 double mfPatternScale; /// Scale used for line pattern spacing.
125 SvxBorderLineStyle mnType;
127 public:
128 /** Constructs an invisible frame style. */
129 explicit implStyle() :
130 maColorPrim(),
131 maColorSecn(),
132 maColorGap(),
133 mbUseGapColor(false),
134 meRefMode(RefMode::Centered),
135 mfPrim(0.0),
136 mfDist(0.0),
137 mfSecn(0.0),
138 mfPatternScale(1.0),
139 mnType(SvxBorderLineStyle::SOLID)
143 /// the impl class holding the data
144 std::shared_ptr< implStyle > maImplStyle;
146 /// call to set maImplStyle on demand
147 void implEnsureImplStyle();
149 public:
150 /** Constructs an invisible frame style. */
151 explicit Style();
152 /** Constructs a frame style with passed line widths. */
153 explicit Style( double nP, double nD, double nS, SvxBorderLineStyle nType, double fScale );
154 /** Constructs a frame style with passed color and line widths. */
155 explicit Style( const Color& rColorPrim, const Color& rColorSecn, const Color& rColorGap, bool bUseGapColor, double nP, double nD, double nS, SvxBorderLineStyle nType, double fScale );
156 /** Constructs a frame style from the passed SvxBorderLine struct. */
157 explicit Style( const editeng::SvxBorderLine* pBorder, double fScale );
159 RefMode GetRefMode() const { if(!maImplStyle) return RefMode::Centered; return maImplStyle->meRefMode; }
160 const Color GetColorPrim() const { if(!maImplStyle) return Color(); return maImplStyle->maColorPrim; }
161 const Color GetColorSecn() const { if(!maImplStyle) return Color(); return maImplStyle->maColorSecn; }
162 const Color GetColorGap() const { if(!maImplStyle) return Color(); return maImplStyle->maColorGap; }
163 bool UseGapColor() const { if(!maImplStyle) return false; return maImplStyle->mbUseGapColor; }
164 double Prim() const { if(!maImplStyle) return 0.0; return maImplStyle->mfPrim; }
165 double Dist() const { if(!maImplStyle) return 0.0; return maImplStyle->mfDist; }
166 double Secn() const { if(!maImplStyle) return 0.0; return maImplStyle->mfSecn; }
167 double PatternScale() const { if(!maImplStyle) return 1.0; return maImplStyle->mfPatternScale;}
168 SvxBorderLineStyle Type() const { if(!maImplStyle) return SvxBorderLineStyle::SOLID; return maImplStyle->mnType; }
170 /// Check if this style is used - this depends on it having any width definition.
171 /// As can be seen in the definition comment above, Prim() *must* be non zero to have a width
172 bool IsUsed() const { if(!maImplStyle) return false; return 0.0 != maImplStyle->mfPrim; }
174 /** Returns the total width of this frame style. */
175 double GetWidth() const { if(!maImplStyle) return 0.0; implStyle* pTarget = maImplStyle.get(); return pTarget->mfPrim + pTarget->mfDist + pTarget->mfSecn; }
177 /** Sets the frame style to invisible state. */
178 void Clear();
179 /** Sets the frame style to the passed line widths. */
180 void Set( double nP, double nD, double nS );
181 /** Sets the frame style to the passed line widths. */
182 void Set( const Color& rColorPrim, const Color& rColorSecn, const Color& rColorGap, bool bUseGapColor, double nP, double nD, double nS );
183 /** Sets the frame style to the passed SvxBorderLine struct. If nullptr, resets the style */
184 void Set( const editeng::SvxBorderLine* pBorder, double fScale, sal_uInt16 nMaxWidth = SAL_MAX_UINT16 );
186 /** Sets a new reference point handling mode, does not modify other settings. */
187 void SetRefMode( RefMode eRefMode );
188 /** Sets a new color, does not modify other settings. */
189 void SetColorPrim( const Color& rColor );
190 void SetColorSecn( const Color& rColor );
191 /** Sets whether to use dotted style for single hair lines. */
192 void SetType( SvxBorderLineStyle nType );
194 /** Mirrors this style (exchanges primary and secondary), if it is a double frame style. */
195 Style& MirrorSelf();
197 bool operator==( const Style& rOther) const;
198 bool operator<( const Style& rOther) const;
201 inline bool operator>( const Style& rL, const Style& rR ) { return rR.operator<(rL); }
206 #endif
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */