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_VCL_TXTATTR_HXX
21 #define INCLUDED_VCL_TXTATTR_HXX
23 #include <config_options.h>
24 #include <tools/color.hxx>
25 #include <tools/debug.hxx>
26 #include <tools/fontenum.hxx>
27 #include <vcl/dllapi.h>
30 namespace vcl
{ class Font
; }
32 #define TEXTATTR_FONTCOLOR 1
33 #define TEXTATTR_FONTWEIGHT 3
35 #define TEXTATTR_USER_START 1000 //start id for user defined text attributes
36 #define TEXTATTR_PROTECTED 4
39 class VCL_DLLPUBLIC TextAttrib
42 sal_uInt16
const mnWhich
;
45 TextAttrib( sal_uInt16 nWhich
) : mnWhich(nWhich
) {}
46 TextAttrib( const TextAttrib
& ) = default;
50 virtual ~TextAttrib();
52 sal_uInt16
Which() const { return mnWhich
; }
53 virtual void SetFont( vcl::Font
& rFont
) const = 0;
54 virtual std::unique_ptr
<TextAttrib
> Clone() const = 0;
56 virtual bool operator==( const TextAttrib
& rAttr
) const = 0;
57 bool operator!=( const TextAttrib
& rAttr
) const
58 { return !(*this == rAttr
); }
62 class VCL_DLLPUBLIC TextAttribFontColor final
: public TextAttrib
68 TextAttribFontColor( const Color
& rColor
);
70 const Color
& GetColor() const { return maColor
; }
72 virtual void SetFont( vcl::Font
& rFont
) const override
;
73 virtual std::unique_ptr
<TextAttrib
> Clone() const override
;
74 virtual bool operator==( const TextAttrib
& rAttr
) const override
;
78 class UNLESS_MERGELIBS_MORE(VCL_DLLPUBLIC
) TextAttribFontWeight final
: public TextAttrib
84 TextAttribFontWeight( FontWeight eWeight
);
86 virtual void SetFont( vcl::Font
& rFont
) const override
;
87 virtual std::unique_ptr
<TextAttrib
> Clone() const override
;
88 virtual bool operator==( const TextAttrib
& rAttr
) const override
;
90 FontWeight
getFontWeight() const { return meWeight
; }
93 class TextAttribProtect final
: public TextAttrib
98 virtual void SetFont( vcl::Font
& rFont
) const override
;
99 virtual std::unique_ptr
<TextAttrib
> Clone() const override
;
100 virtual bool operator==( const TextAttrib
& rAttr
) const override
;
108 std::unique_ptr
<TextAttrib
>
114 TextCharAttrib( const TextAttrib
& rAttr
, sal_Int32 nStart
, sal_Int32 nEnd
);
115 TextCharAttrib( const TextCharAttrib
& rTextCharAttrib
);
117 const TextAttrib
& GetAttr() const { return *mpAttr
; }
119 sal_uInt16
Which() const { return mpAttr
->Which(); }
121 sal_Int32
GetStart() const { return mnStart
; }
122 void SetStart(sal_Int32 n
) { mnStart
= n
; }
124 sal_Int32
GetEnd() const { return mnEnd
; }
125 void SetEnd(sal_Int32 n
) { mnEnd
= n
; }
127 inline sal_Int32
GetLen() const;
129 inline void MoveForward( sal_Int32 nDiff
);
130 inline void MoveBackward( sal_Int32 nDiff
);
132 inline void Expand( sal_Int32 nDiff
);
133 inline void Collaps( sal_Int32 nDiff
);
135 inline bool IsIn( sal_Int32 nIndex
) const;
136 inline bool IsInside( sal_Int32 nIndex
) const;
137 inline bool IsEmpty() const;
141 inline sal_Int32
TextCharAttrib::GetLen() const
143 DBG_ASSERT( mnEnd
>= mnStart
, "TextCharAttrib: nEnd < nStart!" );
144 return mnEnd
-mnStart
;
147 inline void TextCharAttrib::MoveForward( sal_Int32 nDiff
)
149 DBG_ASSERT( nDiff
<= SAL_MAX_INT32
-mnEnd
, "TextCharAttrib: MoveForward?!" );
150 mnStart
= mnStart
+ nDiff
;
151 mnEnd
= mnEnd
+ nDiff
;
154 inline void TextCharAttrib::MoveBackward( sal_Int32 nDiff
)
156 DBG_ASSERT( mnStart
>= nDiff
, "TextCharAttrib: MoveBackward?!" );
157 mnStart
= mnStart
- nDiff
;
158 mnEnd
= mnEnd
- nDiff
;
161 inline void TextCharAttrib::Expand( sal_Int32 nDiff
)
163 DBG_ASSERT( nDiff
<= SAL_MAX_INT32
-mnEnd
, "TextCharAttrib: Expand?!" );
164 mnEnd
= mnEnd
+ nDiff
;
167 inline void TextCharAttrib::Collaps( sal_Int32 nDiff
)
169 DBG_ASSERT( mnEnd
-mnStart
>= nDiff
, "TextCharAttrib: Collaps?!" );
170 mnEnd
= mnEnd
- nDiff
;
173 inline bool TextCharAttrib::IsIn( sal_Int32 nIndex
) const
175 return ( ( mnStart
<= nIndex
) && ( mnEnd
>= nIndex
) );
178 inline bool TextCharAttrib::IsInside( sal_Int32 nIndex
) const
180 return ( ( mnStart
< nIndex
) && ( mnEnd
> nIndex
) );
183 inline bool TextCharAttrib::IsEmpty() const
185 return mnStart
== mnEnd
;
188 #endif // INCLUDED_VCL_TXTATTR_HXX
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */