xref: /AOO41X/main/svtools/inc/svtools/txtattr.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _TXTATTR_HXX
29 #define _TXTATTR_HXX
30 
31 #include "svtools/svtdllapi.h"
32 #include <tools/color.hxx>
33 #include <vcl/vclenum.hxx>
34 #include <tools/string.hxx>
35 #include <tools/debug.hxx>
36 
37 class Font;
38 
39 #define TEXTATTR_INVALID	0
40 #define TEXTATTR_FONTCOLOR	1
41 #define TEXTATTR_HYPERLINK	2
42 #define TEXTATTR_FONTWEIGHT	3
43 
44 #define TEXTATTR_USER_START 1000 //start id for user defined text attributes
45 #define TEXTATTR_PROTECTED  4
46 
47 
48 class SVT_DLLPUBLIC TextAttrib
49 {
50 private:
51 	sal_uInt16					mnWhich;
52 
53 protected:
54 							TextAttrib( sal_uInt16 nWhich ) { mnWhich = nWhich; }
55 							TextAttrib( const TextAttrib& rAttr ) { mnWhich = rAttr.mnWhich; }
56 
57 public:
58 
59 	virtual					~TextAttrib();
60 
61 	sal_uInt16					Which() const 	{ return mnWhich; }
62 
63 	virtual void 			SetFont( Font& rFont ) const = 0;
64 	virtual TextAttrib*		Clone() const = 0;
65 	virtual int				operator==( const TextAttrib& rAttr ) const = 0;
66 	int						operator!=( const TextAttrib& rAttr ) const
67 								{ return !(*this == rAttr ); }
68 };
69 
70 
71 
72 class SVT_DLLPUBLIC TextAttribFontColor : public TextAttrib
73 {
74 private:
75 	Color	maColor;
76 
77 public:
78 							TextAttribFontColor( const Color& rColor );
79 							TextAttribFontColor( const TextAttribFontColor& rAttr );
80 							~TextAttribFontColor();
81 
82     const Color&            GetColor() const { return maColor; }
83 
84 	virtual void 			SetFont( Font& rFont ) const;
85 	virtual TextAttrib*		Clone() const;
86 	virtual int				operator==( const TextAttrib& rAttr ) const;
87 
88 };
89 
90 class SVT_DLLPUBLIC TextAttribFontWeight : public TextAttrib
91 {
92 private:
93 	FontWeight	meWeight;
94 
95 public:
96 							TextAttribFontWeight( FontWeight eWeight );
97 							TextAttribFontWeight( const TextAttribFontWeight& rAttr );
98 							~TextAttribFontWeight();
99 
100 	virtual void 			SetFont( Font& rFont ) const;
101 	virtual TextAttrib*		Clone() const;
102 	virtual int				operator==( const TextAttrib& rAttr ) const;
103 
104     inline FontWeight getFontWeight() const { return meWeight; }
105 };
106 
107 
108 class TextAttribHyperLink : public TextAttrib
109 {
110 private:
111 	XubString	maURL;
112 	XubString	maDescription;
113 	Color		maColor;
114 
115 public:
116 							TextAttribHyperLink( const XubString& rURL );
117 							TextAttribHyperLink( const XubString& rURL, const XubString& rDescription );
118 							TextAttribHyperLink( const TextAttribHyperLink& rAttr );
119 							~TextAttribHyperLink();
120 
121 	void					SetURL( const XubString& rURL )				{ maURL = rURL; }
122 	const XubString&			GetURL() const 								{ return maURL; }
123 
124 	void					SetDescription( const XubString& rDescr )	{ maDescription = rDescr; }
125 	const XubString&			GetDescription() const						{ return maDescription; }
126 
127 	void					SetColor( const Color& rColor ) 			{ maColor = rColor; }
128 	const Color&			GetColor() const 							{ return maColor; }
129 
130 	virtual void 			SetFont( Font& rFont ) const;
131 	virtual TextAttrib*		Clone() const;
132 	virtual int				operator==( const TextAttrib& rAttr ) const;
133 };
134 
135 class SVT_DLLPUBLIC TextAttribProtect : public TextAttrib
136 {
137 public:
138                             TextAttribProtect();
139                             TextAttribProtect( const TextAttribProtect& rAttr );
140                             ~TextAttribProtect();
141 
142     virtual void            SetFont( Font& rFont ) const;
143     virtual TextAttrib*     Clone() const;
144     virtual int             operator==( const TextAttrib& rAttr ) const;
145 
146 };
147 
148 
149 class TextCharAttrib
150 {
151 private:
152 	TextAttrib*		mpAttr;
153 	sal_uInt16 			mnStart;
154 	sal_uInt16 			mnEnd;
155 
156 protected:
157 
158 public:
159 
160 					TextCharAttrib( const TextAttrib& rAttr, sal_uInt16 nStart, sal_uInt16 nEnd );
161 					TextCharAttrib( const TextCharAttrib& rTextCharAttrib );
162 					~TextCharAttrib();
163 
164 	const TextAttrib&	GetAttr() const 		{ return *mpAttr; }
165 
166 	sal_uInt16			Which() const 				{ return mpAttr->Which(); }
167 
168 	sal_uInt16			GetStart() const			{ return mnStart; }
169 	sal_uInt16&			GetStart()					{ return mnStart; }
170 
171 	sal_uInt16			GetEnd() const				{ return mnEnd; }
172 	sal_uInt16&			GetEnd()					{ return mnEnd; }
173 
174 	inline sal_uInt16	GetLen() const;
175 
176 	inline void		MoveForward( sal_uInt16 nDiff );
177 	inline void		MoveBackward( sal_uInt16 nDiff );
178 
179 	inline void		Expand( sal_uInt16 nDiff );
180 	inline void		Collaps( sal_uInt16 nDiff );
181 
182 	inline sal_Bool		IsIn( sal_uInt16 nIndex );
183 	inline sal_Bool		IsInside( sal_uInt16 nIndex );
184 	inline sal_Bool		IsEmpty();
185 
186 };
187 
188 inline sal_uInt16 TextCharAttrib::GetLen() const
189 {
190 	DBG_ASSERT( mnEnd >= mnStart, "TextCharAttrib: nEnd < nStart!" );
191 	return mnEnd-mnStart;
192 }
193 
194 inline void TextCharAttrib::MoveForward( sal_uInt16 nDiff )
195 {
196 	DBG_ASSERT( ((long)mnEnd + nDiff) <= 0xFFFF, "TextCharAttrib: MoveForward?!" );
197 	mnStart = mnStart + nDiff;
198 	mnEnd = mnEnd + nDiff;
199 }
200 
201 inline void TextCharAttrib::MoveBackward( sal_uInt16 nDiff )
202 {
203 	DBG_ASSERT( ((long)mnStart - nDiff) >= 0, "TextCharAttrib: MoveBackward?!" );
204 	mnStart = mnStart - nDiff;
205 	mnEnd = mnEnd - nDiff;
206 }
207 
208 inline void	TextCharAttrib::Expand( sal_uInt16 nDiff )
209 {
210 	DBG_ASSERT( ( ((long)mnEnd + nDiff) <= (long)0xFFFF ), "TextCharAttrib: Expand?!" );
211 	mnEnd = mnEnd + nDiff;
212 }
213 
214 inline void	TextCharAttrib::Collaps( sal_uInt16 nDiff )
215 {
216 	DBG_ASSERT( (long)mnEnd - nDiff >= (long)mnStart, "TextCharAttrib: Collaps?!" );
217 	mnEnd = mnEnd - nDiff;
218 }
219 
220 inline sal_Bool TextCharAttrib::IsIn( sal_uInt16 nIndex )
221 {
222 	return ( ( mnStart <= nIndex ) && ( mnEnd >= nIndex ) );
223 }
224 
225 inline sal_Bool TextCharAttrib::IsInside( sal_uInt16 nIndex )
226 {
227 	return ( ( mnStart < nIndex ) && ( mnEnd > nIndex ) );
228 }
229 
230 inline sal_Bool TextCharAttrib::IsEmpty()
231 {
232 	return mnStart == mnEnd;
233 }
234 
235 #endif // _TXTATTR_HXX
236