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 .
23 #include <vcl/dllapi.h>
24 #include <tools/color.hxx>
25 #include <vcl/vclenum.hxx>
26 #include <tools/string.hxx>
27 #include <tools/debug.hxx>
31 #define TEXTATTR_INVALID 0
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( Font
& rFont
) const = 0;
55 virtual TextAttrib
* Clone() const = 0;
57 virtual int operator==( const TextAttrib
& rAttr
) const = 0;
58 int operator!=( const TextAttrib
& rAttr
) const
59 { return !(*this == rAttr
); }
64 class VCL_DLLPUBLIC TextAttribFontColor
: public TextAttrib
70 TextAttribFontColor( const Color
& rColor
);
71 TextAttribFontColor( const TextAttribFontColor
& rAttr
);
72 ~TextAttribFontColor();
74 const Color
& GetColor() const { return maColor
; }
76 virtual void SetFont( Font
& rFont
) const;
77 virtual TextAttrib
* Clone() const;
78 virtual int operator==( const TextAttrib
& rAttr
) const;
82 class VCL_DLLPUBLIC TextAttribFontWeight
: public TextAttrib
88 TextAttribFontWeight( FontWeight eWeight
);
89 TextAttribFontWeight( const TextAttribFontWeight
& rAttr
);
90 ~TextAttribFontWeight();
92 virtual void SetFont( Font
& rFont
) const;
93 virtual TextAttrib
* Clone() const;
94 virtual int operator==( const TextAttrib
& rAttr
) const;
96 inline FontWeight
getFontWeight() const { return meWeight
; }
100 class TextAttribHyperLink
: public TextAttrib
104 XubString maDescription
;
108 TextAttribHyperLink( const TextAttribHyperLink
& rAttr
);
109 ~TextAttribHyperLink();
111 void SetURL( const XubString
& rURL
) { maURL
= rURL
; }
112 const XubString
& GetURL() const { return maURL
; }
114 void SetDescription( const XubString
& rDescr
) { maDescription
= rDescr
; }
115 const XubString
& GetDescription() const { return maDescription
; }
117 void SetColor( const Color
& rColor
) { maColor
= rColor
; }
118 const Color
& GetColor() const { return maColor
; }
120 virtual void SetFont( Font
& rFont
) const;
121 virtual TextAttrib
* Clone() const;
122 virtual int operator==( const TextAttrib
& rAttr
) const;
125 class VCL_DLLPUBLIC TextAttribProtect
: public TextAttrib
129 TextAttribProtect( const TextAttribProtect
& rAttr
);
130 ~TextAttribProtect();
132 virtual void SetFont( Font
& rFont
) const;
133 virtual TextAttrib
* Clone() const;
134 virtual int operator==( const TextAttrib
& rAttr
) const;
150 TextCharAttrib( const TextAttrib
& rAttr
, sal_uInt16 nStart
, sal_uInt16 nEnd
);
151 TextCharAttrib( const TextCharAttrib
& rTextCharAttrib
);
154 const TextAttrib
& GetAttr() const { return *mpAttr
; }
156 sal_uInt16
Which() const { return mpAttr
->Which(); }
158 sal_uInt16
GetStart() const { return mnStart
; }
159 sal_uInt16
& GetStart() { return mnStart
; }
161 sal_uInt16
GetEnd() const { return mnEnd
; }
162 sal_uInt16
& GetEnd() { return mnEnd
; }
164 inline sal_uInt16
GetLen() const;
166 inline void MoveForward( sal_uInt16 nDiff
);
167 inline void MoveBackward( sal_uInt16 nDiff
);
169 inline void Expand( sal_uInt16 nDiff
);
170 inline void Collaps( sal_uInt16 nDiff
);
172 inline sal_Bool
IsIn( sal_uInt16 nIndex
);
173 inline sal_Bool
IsInside( sal_uInt16 nIndex
);
174 inline sal_Bool
IsEmpty();
178 inline sal_uInt16
TextCharAttrib::GetLen() const
180 DBG_ASSERT( mnEnd
>= mnStart
, "TextCharAttrib: nEnd < nStart!" );
181 return mnEnd
-mnStart
;
184 inline void TextCharAttrib::MoveForward( sal_uInt16 nDiff
)
186 DBG_ASSERT( ((long)mnEnd
+ nDiff
) <= 0xFFFF, "TextCharAttrib: MoveForward?!" );
187 mnStart
= mnStart
+ nDiff
;
188 mnEnd
= mnEnd
+ nDiff
;
191 inline void TextCharAttrib::MoveBackward( sal_uInt16 nDiff
)
193 DBG_ASSERT( ((long)mnStart
- nDiff
) >= 0, "TextCharAttrib: MoveBackward?!" );
194 mnStart
= mnStart
- nDiff
;
195 mnEnd
= mnEnd
- nDiff
;
198 inline void TextCharAttrib::Expand( sal_uInt16 nDiff
)
200 DBG_ASSERT( ( ((long)mnEnd
+ nDiff
) <= (long)0xFFFF ), "TextCharAttrib: Expand?!" );
201 mnEnd
= mnEnd
+ nDiff
;
204 inline void TextCharAttrib::Collaps( sal_uInt16 nDiff
)
206 DBG_ASSERT( (long)mnEnd
- nDiff
>= (long)mnStart
, "TextCharAttrib: Collaps?!" );
207 mnEnd
= mnEnd
- nDiff
;
210 inline sal_Bool
TextCharAttrib::IsIn( sal_uInt16 nIndex
)
212 return ( ( mnStart
<= nIndex
) && ( mnEnd
>= nIndex
) );
215 inline sal_Bool
TextCharAttrib::IsInside( sal_uInt16 nIndex
)
217 return ( ( mnStart
< nIndex
) && ( mnEnd
> nIndex
) );
220 inline sal_Bool
TextCharAttrib::IsEmpty()
222 return mnStart
== mnEnd
;
225 #endif // _TXTATTR_HXX
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */