Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_VCL_TXTATTR_HXX
21 : #define INCLUDED_VCL_TXTATTR_HXX
22 :
23 : #include <rtl/ustring.hxx>
24 : #include <tools/color.hxx>
25 : #include <tools/debug.hxx>
26 : #include <vcl/vclenum.hxx>
27 : #include <vcl/dllapi.h>
28 :
29 : class Font;
30 :
31 : #define TEXTATTR_INVALID 0
32 : #define TEXTATTR_FONTCOLOR 1
33 : #define TEXTATTR_HYPERLINK 2
34 : #define TEXTATTR_FONTWEIGHT 3
35 :
36 : #define TEXTATTR_USER_START 1000 //start id for user defined text attributes
37 : #define TEXTATTR_PROTECTED 4
38 :
39 :
40 : class VCL_DLLPUBLIC TextAttrib
41 : {
42 : private:
43 : sal_uInt16 mnWhich;
44 :
45 : protected:
46 0 : TextAttrib( sal_uInt16 nWhich ) { mnWhich = nWhich; }
47 0 : TextAttrib( const TextAttrib& rAttr ) { mnWhich = rAttr.mnWhich; }
48 :
49 : public:
50 :
51 : virtual ~TextAttrib();
52 :
53 0 : sal_uInt16 Which() const { return mnWhich; }
54 : virtual void SetFont( Font& rFont ) const = 0;
55 : virtual TextAttrib* Clone() const = 0;
56 :
57 : virtual bool operator==( const TextAttrib& rAttr ) const = 0;
58 : bool operator!=( const TextAttrib& rAttr ) const
59 : { return !(*this == rAttr ); }
60 : };
61 :
62 :
63 :
64 : class VCL_DLLPUBLIC TextAttribFontColor : public TextAttrib
65 : {
66 : private:
67 : Color maColor;
68 :
69 : public:
70 : TextAttribFontColor( const Color& rColor );
71 : TextAttribFontColor( const TextAttribFontColor& rAttr );
72 : virtual ~TextAttribFontColor();
73 :
74 0 : const Color& GetColor() const { return maColor; }
75 :
76 : virtual void SetFont( Font& rFont ) const SAL_OVERRIDE;
77 : virtual TextAttrib* Clone() const SAL_OVERRIDE;
78 : virtual bool operator==( const TextAttrib& rAttr ) const SAL_OVERRIDE;
79 :
80 : };
81 :
82 : class VCL_DLLPUBLIC TextAttribFontWeight : public TextAttrib
83 : {
84 : private:
85 : FontWeight meWeight;
86 :
87 : public:
88 : TextAttribFontWeight( FontWeight eWeight );
89 : TextAttribFontWeight( const TextAttribFontWeight& rAttr );
90 : virtual ~TextAttribFontWeight();
91 :
92 : virtual void SetFont( Font& rFont ) const SAL_OVERRIDE;
93 : virtual TextAttrib* Clone() const SAL_OVERRIDE;
94 : virtual bool operator==( const TextAttrib& rAttr ) const SAL_OVERRIDE;
95 :
96 0 : inline FontWeight getFontWeight() const { return meWeight; }
97 : };
98 :
99 :
100 : class TextAttribHyperLink : public TextAttrib
101 : {
102 : private:
103 : OUString maURL;
104 : OUString maDescription;
105 : Color maColor;
106 :
107 : public:
108 : TextAttribHyperLink( const TextAttribHyperLink& rAttr );
109 : virtual ~TextAttribHyperLink();
110 :
111 : void SetURL( const OUString& rURL ) { maURL = rURL; }
112 0 : const OUString& GetURL() const { return maURL; }
113 :
114 : void SetDescription( const OUString& rDescr ) { maDescription = rDescr; }
115 : const OUString& GetDescription() const { return maDescription; }
116 :
117 : void SetColor( const Color& rColor ) { maColor = rColor; }
118 : const Color& GetColor() const { return maColor; }
119 :
120 : virtual void SetFont( Font& rFont ) const SAL_OVERRIDE;
121 : virtual TextAttrib* Clone() const SAL_OVERRIDE;
122 : virtual bool operator==( const TextAttrib& rAttr ) const SAL_OVERRIDE;
123 : };
124 :
125 : class VCL_DLLPUBLIC TextAttribProtect : public TextAttrib
126 : {
127 : public:
128 : TextAttribProtect();
129 : TextAttribProtect( const TextAttribProtect& rAttr );
130 : virtual ~TextAttribProtect();
131 :
132 : virtual void SetFont( Font& rFont ) const SAL_OVERRIDE;
133 : virtual TextAttrib* Clone() const SAL_OVERRIDE;
134 : virtual bool operator==( const TextAttrib& rAttr ) const SAL_OVERRIDE;
135 :
136 : };
137 :
138 :
139 : class TextCharAttrib
140 : {
141 : private:
142 : TextAttrib* mpAttr;
143 : sal_uInt16 mnStart;
144 : sal_uInt16 mnEnd;
145 :
146 : protected:
147 :
148 : public:
149 :
150 : TextCharAttrib( const TextAttrib& rAttr, sal_uInt16 nStart, sal_uInt16 nEnd );
151 : TextCharAttrib( const TextCharAttrib& rTextCharAttrib );
152 : ~TextCharAttrib();
153 :
154 0 : const TextAttrib& GetAttr() const { return *mpAttr; }
155 :
156 0 : sal_uInt16 Which() const { return mpAttr->Which(); }
157 :
158 0 : sal_uInt16 GetStart() const { return mnStart; }
159 0 : sal_uInt16& GetStart() { return mnStart; }
160 :
161 0 : sal_uInt16 GetEnd() const { return mnEnd; }
162 0 : sal_uInt16& GetEnd() { return mnEnd; }
163 :
164 : inline sal_uInt16 GetLen() const;
165 :
166 : inline void MoveForward( sal_uInt16 nDiff );
167 : inline void MoveBackward( sal_uInt16 nDiff );
168 :
169 : inline void Expand( sal_uInt16 nDiff );
170 : inline void Collaps( sal_uInt16 nDiff );
171 :
172 : inline bool IsIn( sal_uInt16 nIndex );
173 : inline bool IsInside( sal_uInt16 nIndex );
174 : inline bool IsEmpty();
175 :
176 : };
177 :
178 0 : inline sal_uInt16 TextCharAttrib::GetLen() const
179 : {
180 : DBG_ASSERT( mnEnd >= mnStart, "TextCharAttrib: nEnd < nStart!" );
181 0 : return mnEnd-mnStart;
182 : }
183 :
184 0 : inline void TextCharAttrib::MoveForward( sal_uInt16 nDiff )
185 : {
186 : DBG_ASSERT( ((long)mnEnd + nDiff) <= 0xFFFF, "TextCharAttrib: MoveForward?!" );
187 0 : mnStart = mnStart + nDiff;
188 0 : mnEnd = mnEnd + nDiff;
189 0 : }
190 :
191 0 : inline void TextCharAttrib::MoveBackward( sal_uInt16 nDiff )
192 : {
193 : DBG_ASSERT( ((long)mnStart - nDiff) >= 0, "TextCharAttrib: MoveBackward?!" );
194 0 : mnStart = mnStart - nDiff;
195 0 : mnEnd = mnEnd - nDiff;
196 0 : }
197 :
198 0 : inline void TextCharAttrib::Expand( sal_uInt16 nDiff )
199 : {
200 : DBG_ASSERT( ( ((long)mnEnd + nDiff) <= (long)0xFFFF ), "TextCharAttrib: Expand?!" );
201 0 : mnEnd = mnEnd + nDiff;
202 0 : }
203 :
204 0 : inline void TextCharAttrib::Collaps( sal_uInt16 nDiff )
205 : {
206 : DBG_ASSERT( (long)mnEnd - nDiff >= (long)mnStart, "TextCharAttrib: Collaps?!" );
207 0 : mnEnd = mnEnd - nDiff;
208 0 : }
209 :
210 0 : inline bool TextCharAttrib::IsIn( sal_uInt16 nIndex )
211 : {
212 0 : return ( ( mnStart <= nIndex ) && ( mnEnd >= nIndex ) );
213 : }
214 :
215 0 : inline bool TextCharAttrib::IsInside( sal_uInt16 nIndex )
216 : {
217 0 : return ( ( mnStart < nIndex ) && ( mnEnd > nIndex ) );
218 : }
219 :
220 0 : inline bool TextCharAttrib::IsEmpty()
221 : {
222 0 : return mnStart == mnEnd;
223 : }
224 :
225 : #endif // INCLUDED_VCL_TXTATTR_HXX
226 :
227 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|