update dev300-m57
[ooovba.git] / svtools / inc / txtattr.hxx
blob992808f77675672445ffd8c3a29cd83f15c41a71
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: txtattr.hxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _TXTATTR_HXX
32 #define _TXTATTR_HXX
34 #include "svtools/svtdllapi.h"
35 #include <tools/color.hxx>
36 #include <vcl/vclenum.hxx>
37 #include <tools/string.hxx>
38 #include <tools/debug.hxx>
40 class Font;
42 #define TEXTATTR_INVALID 0
43 #define TEXTATTR_FONTCOLOR 1
44 #define TEXTATTR_HYPERLINK 2
45 #define TEXTATTR_FONTWEIGHT 3
47 #define TEXTATTR_USER_START 1000 //start id for user defined text attributes
48 #define TEXTATTR_PROTECTED 4
51 class SVT_DLLPUBLIC TextAttrib
53 private:
54 USHORT mnWhich;
56 protected:
57 TextAttrib( USHORT nWhich ) { mnWhich = nWhich; }
58 TextAttrib( const TextAttrib& rAttr ) { mnWhich = rAttr.mnWhich; }
60 public:
62 virtual ~TextAttrib();
64 USHORT Which() const { return mnWhich; }
66 virtual void SetFont( Font& rFont ) const = 0;
67 virtual TextAttrib* Clone() const = 0;
68 virtual int operator==( const TextAttrib& rAttr ) const = 0;
69 int operator!=( const TextAttrib& rAttr ) const
70 { return !(*this == rAttr ); }
75 class SVT_DLLPUBLIC TextAttribFontColor : public TextAttrib
77 private:
78 Color maColor;
80 public:
81 TextAttribFontColor( const Color& rColor );
82 TextAttribFontColor( const TextAttribFontColor& rAttr );
83 ~TextAttribFontColor();
85 const Color& GetColor() const { return maColor; }
87 virtual void SetFont( Font& rFont ) const;
88 virtual TextAttrib* Clone() const;
89 virtual int operator==( const TextAttrib& rAttr ) const;
93 class SVT_DLLPUBLIC TextAttribFontWeight : public TextAttrib
95 private:
96 FontWeight meWeight;
98 public:
99 TextAttribFontWeight( FontWeight eWeight );
100 TextAttribFontWeight( const TextAttribFontWeight& rAttr );
101 ~TextAttribFontWeight();
103 virtual void SetFont( Font& rFont ) const;
104 virtual TextAttrib* Clone() const;
105 virtual int operator==( const TextAttrib& rAttr ) const;
107 inline FontWeight getFontWeight() const { return meWeight; }
111 class TextAttribHyperLink : public TextAttrib
113 private:
114 XubString maURL;
115 XubString maDescription;
116 Color maColor;
118 public:
119 TextAttribHyperLink( const XubString& rURL );
120 TextAttribHyperLink( const XubString& rURL, const XubString& rDescription );
121 TextAttribHyperLink( const TextAttribHyperLink& rAttr );
122 ~TextAttribHyperLink();
124 void SetURL( const XubString& rURL ) { maURL = rURL; }
125 const XubString& GetURL() const { return maURL; }
127 void SetDescription( const XubString& rDescr ) { maDescription = rDescr; }
128 const XubString& GetDescription() const { return maDescription; }
130 void SetColor( const Color& rColor ) { maColor = rColor; }
131 const Color& GetColor() const { return maColor; }
133 virtual void SetFont( Font& rFont ) const;
134 virtual TextAttrib* Clone() const;
135 virtual int operator==( const TextAttrib& rAttr ) const;
138 class SVT_DLLPUBLIC TextAttribProtect : public TextAttrib
140 public:
141 TextAttribProtect();
142 TextAttribProtect( const TextAttribProtect& rAttr );
143 ~TextAttribProtect();
145 virtual void SetFont( Font& rFont ) const;
146 virtual TextAttrib* Clone() const;
147 virtual int operator==( const TextAttrib& rAttr ) const;
152 class TextCharAttrib
154 private:
155 TextAttrib* mpAttr;
156 USHORT mnStart;
157 USHORT mnEnd;
159 protected:
161 public:
163 TextCharAttrib( const TextAttrib& rAttr, USHORT nStart, USHORT nEnd );
164 TextCharAttrib( const TextCharAttrib& rTextCharAttrib );
165 ~TextCharAttrib();
167 const TextAttrib& GetAttr() const { return *mpAttr; }
169 USHORT Which() const { return mpAttr->Which(); }
171 USHORT GetStart() const { return mnStart; }
172 USHORT& GetStart() { return mnStart; }
174 USHORT GetEnd() const { return mnEnd; }
175 USHORT& GetEnd() { return mnEnd; }
177 inline USHORT GetLen() const;
179 inline void MoveForward( USHORT nDiff );
180 inline void MoveBackward( USHORT nDiff );
182 inline void Expand( USHORT nDiff );
183 inline void Collaps( USHORT nDiff );
185 inline BOOL IsIn( USHORT nIndex );
186 inline BOOL IsInside( USHORT nIndex );
187 inline BOOL IsEmpty();
191 inline USHORT TextCharAttrib::GetLen() const
193 DBG_ASSERT( mnEnd >= mnStart, "TextCharAttrib: nEnd < nStart!" );
194 return mnEnd-mnStart;
197 inline void TextCharAttrib::MoveForward( USHORT nDiff )
199 DBG_ASSERT( ((long)mnEnd + nDiff) <= 0xFFFF, "TextCharAttrib: MoveForward?!" );
200 mnStart = mnStart + nDiff;
201 mnEnd = mnEnd + nDiff;
204 inline void TextCharAttrib::MoveBackward( USHORT nDiff )
206 DBG_ASSERT( ((long)mnStart - nDiff) >= 0, "TextCharAttrib: MoveBackward?!" );
207 mnStart = mnStart - nDiff;
208 mnEnd = mnEnd - nDiff;
211 inline void TextCharAttrib::Expand( USHORT nDiff )
213 DBG_ASSERT( ( ((long)mnEnd + nDiff) <= (long)0xFFFF ), "TextCharAttrib: Expand?!" );
214 mnEnd = mnEnd + nDiff;
217 inline void TextCharAttrib::Collaps( USHORT nDiff )
219 DBG_ASSERT( (long)mnEnd - nDiff >= (long)mnStart, "TextCharAttrib: Collaps?!" );
220 mnEnd = mnEnd - nDiff;
223 inline BOOL TextCharAttrib::IsIn( USHORT nIndex )
225 return ( ( mnStart <= nIndex ) && ( mnEnd >= nIndex ) );
228 inline BOOL TextCharAttrib::IsInside( USHORT nIndex )
230 return ( ( mnStart < nIndex ) && ( mnEnd > nIndex ) );
233 inline BOOL TextCharAttrib::IsEmpty()
235 return mnStart == mnEnd;
238 #endif // _TXTATTR_HXX