xref: /trunk/main/svtools/inc/svtools/txtattr.hxx (revision 01aa44aa)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _TXTATTR_HXX
25 #define _TXTATTR_HXX
26 
27 #include "svtools/svtdllapi.h"
28 #include <tools/color.hxx>
29 #include <vcl/vclenum.hxx>
30 #include <tools/string.hxx>
31 #include <tools/debug.hxx>
32 
33 class Font;
34 
35 #define TEXTATTR_INVALID	0
36 #define TEXTATTR_FONTCOLOR	1
37 #define TEXTATTR_HYPERLINK	2
38 #define TEXTATTR_FONTWEIGHT	3
39 
40 #define TEXTATTR_USER_START 1000 //start id for user defined text attributes
41 #define TEXTATTR_PROTECTED  4
42 
43 
44 class SVT_DLLPUBLIC TextAttrib
45 {
46 private:
47 	sal_uInt16					mnWhich;
48 
49 protected:
TextAttrib(sal_uInt16 nWhich)50 							TextAttrib( sal_uInt16 nWhich ) { mnWhich = nWhich; }
TextAttrib(const TextAttrib & rAttr)51 							TextAttrib( const TextAttrib& rAttr ) { mnWhich = rAttr.mnWhich; }
52 
53 public:
54 
55 	virtual					~TextAttrib();
56 
Which() const57 	sal_uInt16					Which() const 	{ return mnWhich; }
58 
59 	virtual void 			SetFont( Font& rFont ) const = 0;
60 	virtual TextAttrib*		Clone() const = 0;
61 	virtual int				operator==( const TextAttrib& rAttr ) const = 0;
operator !=(const TextAttrib & rAttr) const62 	int						operator!=( const TextAttrib& rAttr ) const
63 								{ return !(*this == rAttr ); }
64 };
65 
66 
67 
68 class SVT_DLLPUBLIC TextAttribFontColor : public TextAttrib
69 {
70 private:
71 	Color	maColor;
72 
73 public:
74 							TextAttribFontColor( const Color& rColor );
75 							TextAttribFontColor( const TextAttribFontColor& rAttr );
76 							~TextAttribFontColor();
77 
GetColor() const78     const Color&            GetColor() const { return maColor; }
79 
80 	virtual void 			SetFont( Font& rFont ) const;
81 	virtual TextAttrib*		Clone() const;
82 	virtual int				operator==( const TextAttrib& rAttr ) const;
83 
84 };
85 
86 class SVT_DLLPUBLIC TextAttribFontWeight : public TextAttrib
87 {
88 private:
89 	FontWeight	meWeight;
90 
91 public:
92 							TextAttribFontWeight( FontWeight eWeight );
93 							TextAttribFontWeight( const TextAttribFontWeight& rAttr );
94 							~TextAttribFontWeight();
95 
96 	virtual void 			SetFont( Font& rFont ) const;
97 	virtual TextAttrib*		Clone() const;
98 	virtual int				operator==( const TextAttrib& rAttr ) const;
99 
getFontWeight() const100     inline FontWeight getFontWeight() const { return meWeight; }
101 };
102 
103 
104 class TextAttribHyperLink : public TextAttrib
105 {
106 private:
107 	XubString	maURL;
108 	XubString	maDescription;
109 	Color		maColor;
110 
111 public:
112 							TextAttribHyperLink( const XubString& rURL );
113 							TextAttribHyperLink( const XubString& rURL, const XubString& rDescription );
114 							TextAttribHyperLink( const TextAttribHyperLink& rAttr );
115 							~TextAttribHyperLink();
116 
SetURL(const XubString & rURL)117 	void					SetURL( const XubString& rURL )				{ maURL = rURL; }
GetURL() const118 	const XubString&			GetURL() const 								{ return maURL; }
119 
SetDescription(const XubString & rDescr)120 	void					SetDescription( const XubString& rDescr )	{ maDescription = rDescr; }
GetDescription() const121 	const XubString&			GetDescription() const						{ return maDescription; }
122 
SetColor(const Color & rColor)123 	void					SetColor( const Color& rColor ) 			{ maColor = rColor; }
GetColor() const124 	const Color&			GetColor() const 							{ return maColor; }
125 
126 	virtual void 			SetFont( Font& rFont ) const;
127 	virtual TextAttrib*		Clone() const;
128 	virtual int				operator==( const TextAttrib& rAttr ) const;
129 };
130 
131 class SVT_DLLPUBLIC TextAttribProtect : public TextAttrib
132 {
133 public:
134                             TextAttribProtect();
135                             TextAttribProtect( const TextAttribProtect& rAttr );
136                             ~TextAttribProtect();
137 
138     virtual void            SetFont( Font& rFont ) const;
139     virtual TextAttrib*     Clone() const;
140     virtual int             operator==( const TextAttrib& rAttr ) const;
141 
142 };
143 
144 
145 class TextCharAttrib
146 {
147 private:
148 	TextAttrib*		mpAttr;
149 	sal_uInt16 			mnStart;
150 	sal_uInt16 			mnEnd;
151 
152 protected:
153 
154 public:
155 
156 					TextCharAttrib( const TextAttrib& rAttr, sal_uInt16 nStart, sal_uInt16 nEnd );
157 					TextCharAttrib( const TextCharAttrib& rTextCharAttrib );
158 					~TextCharAttrib();
159 
GetAttr() const160 	const TextAttrib&	GetAttr() const 		{ return *mpAttr; }
161 
Which() const162 	sal_uInt16			Which() const 				{ return mpAttr->Which(); }
163 
GetStart() const164 	sal_uInt16			GetStart() const			{ return mnStart; }
GetStart()165 	sal_uInt16&			GetStart()					{ return mnStart; }
166 
GetEnd() const167 	sal_uInt16			GetEnd() const				{ return mnEnd; }
GetEnd()168 	sal_uInt16&			GetEnd()					{ return mnEnd; }
169 
170 	inline sal_uInt16	GetLen() const;
171 
172 	inline void		MoveForward( sal_uInt16 nDiff );
173 	inline void		MoveBackward( sal_uInt16 nDiff );
174 
175 	inline void		Expand( sal_uInt16 nDiff );
176 	inline void		Collaps( sal_uInt16 nDiff );
177 
178 	inline sal_Bool		IsIn( sal_uInt16 nIndex );
179 	inline sal_Bool		IsInside( sal_uInt16 nIndex );
180 	inline sal_Bool		IsEmpty();
181 
182 };
183 
GetLen() const184 inline sal_uInt16 TextCharAttrib::GetLen() const
185 {
186 	DBG_ASSERT( mnEnd >= mnStart, "TextCharAttrib: nEnd < nStart!" );
187 	return mnEnd-mnStart;
188 }
189 
MoveForward(sal_uInt16 nDiff)190 inline void TextCharAttrib::MoveForward( sal_uInt16 nDiff )
191 {
192 	DBG_ASSERT( ((long)mnEnd + nDiff) <= 0xFFFF, "TextCharAttrib: MoveForward?!" );
193 	mnStart = mnStart + nDiff;
194 	mnEnd = mnEnd + nDiff;
195 }
196 
MoveBackward(sal_uInt16 nDiff)197 inline void TextCharAttrib::MoveBackward( sal_uInt16 nDiff )
198 {
199 	DBG_ASSERT( ((long)mnStart - nDiff) >= 0, "TextCharAttrib: MoveBackward?!" );
200 	mnStart = mnStart - nDiff;
201 	mnEnd = mnEnd - nDiff;
202 }
203 
Expand(sal_uInt16 nDiff)204 inline void	TextCharAttrib::Expand( sal_uInt16 nDiff )
205 {
206 	DBG_ASSERT( ( ((long)mnEnd + nDiff) <= (long)0xFFFF ), "TextCharAttrib: Expand?!" );
207 	mnEnd = mnEnd + nDiff;
208 }
209 
Collaps(sal_uInt16 nDiff)210 inline void	TextCharAttrib::Collaps( sal_uInt16 nDiff )
211 {
212 	DBG_ASSERT( (long)mnEnd - nDiff >= (long)mnStart, "TextCharAttrib: Collaps?!" );
213 	mnEnd = mnEnd - nDiff;
214 }
215 
IsIn(sal_uInt16 nIndex)216 inline sal_Bool TextCharAttrib::IsIn( sal_uInt16 nIndex )
217 {
218 	return ( ( mnStart <= nIndex ) && ( mnEnd >= nIndex ) );
219 }
220 
IsInside(sal_uInt16 nIndex)221 inline sal_Bool TextCharAttrib::IsInside( sal_uInt16 nIndex )
222 {
223 	return ( ( mnStart < nIndex ) && ( mnEnd > nIndex ) );
224 }
225 
IsEmpty()226 inline sal_Bool TextCharAttrib::IsEmpty()
227 {
228 	return mnStart == mnEnd;
229 }
230 
231 #endif // _TXTATTR_HXX
232