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