Branch libreoffice-5-0-4
[LibreOffice.git] / include / vcl / txtattr.hxx
blob825f2ae54fe68c43d0a31ad2d48e82d80b38184d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_TXTATTR_HXX
21 #define INCLUDED_VCL_TXTATTR_HXX
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>
29 namespace vcl { class Font; }
31 #define TEXTATTR_FONTCOLOR 1
32 #define TEXTATTR_HYPERLINK 2
33 #define TEXTATTR_FONTWEIGHT 3
35 #define TEXTATTR_USER_START 1000 //start id for user defined text attributes
36 #define TEXTATTR_PROTECTED 4
39 class VCL_DLLPUBLIC TextAttrib
41 private:
42 sal_uInt16 mnWhich;
44 protected:
45 TextAttrib( sal_uInt16 nWhich ) { mnWhich = nWhich; }
46 TextAttrib( const TextAttrib& rAttr ) { mnWhich = rAttr.mnWhich; }
48 public:
50 virtual ~TextAttrib();
52 sal_uInt16 Which() const { return mnWhich; }
53 virtual void SetFont( vcl::Font& rFont ) const = 0;
54 virtual TextAttrib* Clone() const = 0;
56 virtual bool operator==( const TextAttrib& rAttr ) const = 0;
57 bool operator!=( const TextAttrib& rAttr ) const
58 { return !(*this == rAttr ); }
63 class VCL_DLLPUBLIC TextAttribFontColor : public TextAttrib
65 private:
66 Color maColor;
68 public:
69 TextAttribFontColor( const Color& rColor );
70 TextAttribFontColor( const TextAttribFontColor& rAttr );
71 virtual ~TextAttribFontColor();
73 const Color& GetColor() const { return maColor; }
75 virtual void SetFont( vcl::Font& rFont ) const SAL_OVERRIDE;
76 virtual TextAttrib* Clone() const SAL_OVERRIDE;
77 virtual bool operator==( const TextAttrib& rAttr ) const SAL_OVERRIDE;
81 class VCL_DLLPUBLIC TextAttribFontWeight : public TextAttrib
83 private:
84 FontWeight meWeight;
86 public:
87 TextAttribFontWeight( FontWeight eWeight );
88 TextAttribFontWeight( const TextAttribFontWeight& rAttr );
89 virtual ~TextAttribFontWeight();
91 virtual void SetFont( vcl::Font& rFont ) const SAL_OVERRIDE;
92 virtual TextAttrib* Clone() const SAL_OVERRIDE;
93 virtual bool operator==( const TextAttrib& rAttr ) const SAL_OVERRIDE;
95 inline FontWeight getFontWeight() const { return meWeight; }
99 class TextAttribHyperLink : public TextAttrib
101 private:
102 OUString maURL;
103 OUString maDescription;
104 Color maColor;
106 public:
107 TextAttribHyperLink( const TextAttribHyperLink& rAttr );
108 virtual ~TextAttribHyperLink();
110 void SetURL( const OUString& rURL ) { maURL = rURL; }
111 const OUString& GetURL() const { return maURL; }
113 void SetDescription( const OUString& rDescr ) { maDescription = rDescr; }
114 const OUString& GetDescription() const { return maDescription; }
116 void SetColor( const Color& rColor ) { maColor = rColor; }
117 const Color& GetColor() const { return maColor; }
119 virtual void SetFont( vcl::Font& rFont ) const SAL_OVERRIDE;
120 virtual TextAttrib* Clone() const SAL_OVERRIDE;
121 virtual bool operator==( const TextAttrib& rAttr ) const SAL_OVERRIDE;
124 class VCL_DLLPUBLIC TextAttribProtect : public TextAttrib
126 public:
127 TextAttribProtect();
128 TextAttribProtect( const TextAttribProtect& rAttr );
129 virtual ~TextAttribProtect();
131 virtual void SetFont( vcl::Font& rFont ) const SAL_OVERRIDE;
132 virtual TextAttrib* Clone() const SAL_OVERRIDE;
133 virtual bool operator==( const TextAttrib& rAttr ) const SAL_OVERRIDE;
138 class TextCharAttrib
140 private:
141 TextAttrib* mpAttr;
142 sal_uInt16 mnStart;
143 sal_uInt16 mnEnd;
145 protected:
147 public:
149 TextCharAttrib( const TextAttrib& rAttr, sal_uInt16 nStart, sal_uInt16 nEnd );
150 TextCharAttrib( const TextCharAttrib& rTextCharAttrib );
151 ~TextCharAttrib();
153 const TextAttrib& GetAttr() const { return *mpAttr; }
155 sal_uInt16 Which() const { return mpAttr->Which(); }
157 sal_uInt16 GetStart() const { return mnStart; }
158 sal_uInt16& GetStart() { return mnStart; }
160 sal_uInt16 GetEnd() const { return mnEnd; }
161 sal_uInt16& GetEnd() { return mnEnd; }
163 inline sal_uInt16 GetLen() const;
165 inline void MoveForward( sal_uInt16 nDiff );
166 inline void MoveBackward( sal_uInt16 nDiff );
168 inline void Expand( sal_uInt16 nDiff );
169 inline void Collaps( sal_uInt16 nDiff );
171 inline bool IsIn( sal_uInt16 nIndex );
172 inline bool IsInside( sal_uInt16 nIndex );
173 inline bool IsEmpty() const;
177 inline sal_uInt16 TextCharAttrib::GetLen() const
179 DBG_ASSERT( mnEnd >= mnStart, "TextCharAttrib: nEnd < nStart!" );
180 return mnEnd-mnStart;
183 inline void TextCharAttrib::MoveForward( sal_uInt16 nDiff )
185 DBG_ASSERT( ((long)mnEnd + nDiff) <= 0xFFFF, "TextCharAttrib: MoveForward?!" );
186 mnStart = mnStart + nDiff;
187 mnEnd = mnEnd + nDiff;
190 inline void TextCharAttrib::MoveBackward( sal_uInt16 nDiff )
192 DBG_ASSERT( ((long)mnStart - nDiff) >= 0, "TextCharAttrib: MoveBackward?!" );
193 mnStart = mnStart - nDiff;
194 mnEnd = mnEnd - nDiff;
197 inline void TextCharAttrib::Expand( sal_uInt16 nDiff )
199 DBG_ASSERT( ( ((long)mnEnd + nDiff) <= (long)0xFFFF ), "TextCharAttrib: Expand?!" );
200 mnEnd = mnEnd + nDiff;
203 inline void TextCharAttrib::Collaps( sal_uInt16 nDiff )
205 DBG_ASSERT( (long)mnEnd - nDiff >= (long)mnStart, "TextCharAttrib: Collaps?!" );
206 mnEnd = mnEnd - nDiff;
209 inline bool TextCharAttrib::IsIn( sal_uInt16 nIndex )
211 return ( ( mnStart <= nIndex ) && ( mnEnd >= nIndex ) );
214 inline bool TextCharAttrib::IsInside( sal_uInt16 nIndex )
216 return ( ( mnStart < nIndex ) && ( mnEnd > nIndex ) );
219 inline bool TextCharAttrib::IsEmpty() const
221 return mnStart == mnEnd;
224 #endif // INCLUDED_VCL_TXTATTR_HXX
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */