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 <rtl/ustring.hxx>
24 #include <tools/color.hxx>
25 #include <tools/debug.hxx>
26 #include <vcl/vclenum.hxx>
27 #include <vcl/dllapi.h>
30 namespace vcl
{ class Font
; }
32 #define TEXTATTR_FONTCOLOR 1
33 #define TEXTATTR_HYPERLINK 2
34 #define TEXTATTR_FONTWEIGHT 3
36 #define TEXTATTR_USER_START 1000 //start id for user defined text attributes
37 #define TEXTATTR_PROTECTED 4
40 class VCL_DLLPUBLIC TextAttrib
46 TextAttrib( sal_uInt16 nWhich
) { mnWhich
= nWhich
; }
47 TextAttrib( const TextAttrib
& rAttr
) { mnWhich
= rAttr
.mnWhich
; }
51 virtual ~TextAttrib();
53 sal_uInt16
Which() const { return mnWhich
; }
54 virtual void SetFont( vcl::Font
& rFont
) const = 0;
55 virtual TextAttrib
* Clone() const = 0;
57 virtual bool operator==( const TextAttrib
& rAttr
) const = 0;
58 bool operator!=( const TextAttrib
& rAttr
) const
59 { return !(*this == rAttr
); }
63 class VCL_DLLPUBLIC TextAttribFontColor
: public TextAttrib
69 TextAttribFontColor( const Color
& rColor
);
70 TextAttribFontColor( const TextAttribFontColor
& rAttr
);
71 virtual ~TextAttribFontColor() override
;
73 const Color
& GetColor() const { return maColor
; }
75 virtual void SetFont( vcl::Font
& rFont
) const override
;
76 virtual TextAttrib
* Clone() const override
;
77 virtual bool operator==( const TextAttrib
& rAttr
) const override
;
81 class VCL_DLLPUBLIC TextAttribFontWeight
: public TextAttrib
87 TextAttribFontWeight( FontWeight eWeight
);
88 TextAttribFontWeight( const TextAttribFontWeight
& rAttr
);
89 virtual ~TextAttribFontWeight() override
;
91 virtual void SetFont( vcl::Font
& rFont
) const override
;
92 virtual TextAttrib
* Clone() const override
;
93 virtual bool operator==( const TextAttrib
& rAttr
) const override
;
95 FontWeight
getFontWeight() const { return meWeight
; }
99 class TextAttribHyperLink
: public TextAttrib
103 OUString maDescription
;
107 TextAttribHyperLink( const TextAttribHyperLink
& rAttr
);
108 virtual ~TextAttribHyperLink() override
;
110 const OUString
& GetURL() const { return maURL
; }
111 virtual void SetFont( vcl::Font
& rFont
) const override
;
112 virtual TextAttrib
* Clone() const override
;
113 virtual bool operator==( const TextAttrib
& rAttr
) const override
;
116 class VCL_DLLPUBLIC TextAttribProtect
: public TextAttrib
120 TextAttribProtect( const TextAttribProtect
& rAttr
);
121 virtual ~TextAttribProtect() override
;
123 virtual void SetFont( vcl::Font
& rFont
) const override
;
124 virtual TextAttrib
* Clone() const override
;
125 virtual bool operator==( const TextAttrib
& rAttr
) const override
;
133 std::unique_ptr
<TextAttrib
>
142 TextCharAttrib( const TextAttrib
& rAttr
, sal_Int32 nStart
, sal_Int32 nEnd
);
143 TextCharAttrib( const TextCharAttrib
& rTextCharAttrib
);
146 const TextAttrib
& GetAttr() const { return *mpAttr
; }
148 sal_uInt16
Which() const { return mpAttr
->Which(); }
150 sal_Int32
GetStart() const { return mnStart
; }
151 sal_Int32
& GetStart() { return mnStart
; }
153 sal_Int32
GetEnd() const { return mnEnd
; }
154 sal_Int32
& GetEnd() { return mnEnd
; }
156 inline sal_Int32
GetLen() const;
158 inline void MoveForward( sal_Int32 nDiff
);
159 inline void MoveBackward( sal_Int32 nDiff
);
161 inline void Expand( sal_Int32 nDiff
);
162 inline void Collaps( sal_Int32 nDiff
);
164 inline bool IsIn( sal_Int32 nIndex
);
165 inline bool IsInside( sal_Int32 nIndex
);
166 inline bool IsEmpty() const;
170 inline sal_Int32
TextCharAttrib::GetLen() const
172 DBG_ASSERT( mnEnd
>= mnStart
, "TextCharAttrib: nEnd < nStart!" );
173 return mnEnd
-mnStart
;
176 inline void TextCharAttrib::MoveForward( sal_Int32 nDiff
)
178 DBG_ASSERT( nDiff
<= SAL_MAX_INT32
-mnEnd
, "TextCharAttrib: MoveForward?!" );
179 mnStart
= mnStart
+ nDiff
;
180 mnEnd
= mnEnd
+ nDiff
;
183 inline void TextCharAttrib::MoveBackward( sal_Int32 nDiff
)
185 DBG_ASSERT( mnStart
>= nDiff
, "TextCharAttrib: MoveBackward?!" );
186 mnStart
= mnStart
- nDiff
;
187 mnEnd
= mnEnd
- nDiff
;
190 inline void TextCharAttrib::Expand( sal_Int32 nDiff
)
192 DBG_ASSERT( nDiff
<= SAL_MAX_INT32
-mnEnd
, "TextCharAttrib: Expand?!" );
193 mnEnd
= mnEnd
+ nDiff
;
196 inline void TextCharAttrib::Collaps( sal_Int32 nDiff
)
198 DBG_ASSERT( mnEnd
-mnStart
>= nDiff
, "TextCharAttrib: Collaps?!" );
199 mnEnd
= mnEnd
- nDiff
;
202 inline bool TextCharAttrib::IsIn( sal_Int32 nIndex
)
204 return ( ( mnStart
<= nIndex
) && ( mnEnd
>= nIndex
) );
207 inline bool TextCharAttrib::IsInside( sal_Int32 nIndex
)
209 return ( ( mnStart
< nIndex
) && ( mnEnd
> nIndex
) );
212 inline bool TextCharAttrib::IsEmpty() const
214 return mnStart
== mnEnd
;
217 #endif // INCLUDED_VCL_TXTATTR_HXX
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */