Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / vcl / txtattr.hxx
blob97fd9034160d2f9f0dab4f16c88abda2805c61c3
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>
28 #include <memory>
30 namespace vcl { class Font; }
32 #define TEXTATTR_FONTCOLOR 1
33 #define TEXTATTR_HYPERLINK 2
34 #define TEXTATTR_FONTWEIGHT 3
36 #define TEXTATTR_USER_START 1000 //start id for user defined text attributes
37 #define TEXTATTR_PROTECTED 4
40 class VCL_DLLPUBLIC TextAttrib
42 private:
43 sal_uInt16 mnWhich;
45 protected:
46 TextAttrib( sal_uInt16 nWhich ) { mnWhich = nWhich; }
47 TextAttrib( const TextAttrib& rAttr ) { mnWhich = rAttr.mnWhich; }
49 public:
51 virtual ~TextAttrib();
53 sal_uInt16 Which() const { return mnWhich; }
54 virtual void SetFont( vcl::Font& rFont ) const = 0;
55 virtual TextAttrib* Clone() const = 0;
57 virtual bool operator==( const TextAttrib& rAttr ) const = 0;
58 bool operator!=( const TextAttrib& rAttr ) const
59 { 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() override;
73 const Color& GetColor() const { return maColor; }
75 virtual void SetFont( vcl::Font& rFont ) const override;
76 virtual TextAttrib* Clone() const override;
77 virtual bool operator==( const TextAttrib& rAttr ) const 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() override;
91 virtual void SetFont( vcl::Font& rFont ) const override;
92 virtual TextAttrib* Clone() const override;
93 virtual bool operator==( const TextAttrib& rAttr ) const override;
95 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() override;
110 const OUString& GetURL() const { return maURL; }
111 virtual void SetFont( vcl::Font& rFont ) const override;
112 virtual TextAttrib* Clone() const override;
113 virtual bool operator==( const TextAttrib& rAttr ) const override;
116 class VCL_DLLPUBLIC TextAttribProtect : public TextAttrib
118 public:
119 TextAttribProtect();
120 TextAttribProtect( const TextAttribProtect& rAttr );
121 virtual ~TextAttribProtect() override;
123 virtual void SetFont( vcl::Font& rFont ) const override;
124 virtual TextAttrib* Clone() const override;
125 virtual bool operator==( const TextAttrib& rAttr ) const override;
130 class TextCharAttrib
132 private:
133 std::unique_ptr<TextAttrib>
134 mpAttr;
135 sal_Int32 mnStart;
136 sal_Int32 mnEnd;
138 protected:
140 public:
142 TextCharAttrib( const TextAttrib& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
143 TextCharAttrib( const TextCharAttrib& rTextCharAttrib );
144 ~TextCharAttrib();
146 const TextAttrib& GetAttr() const { return *mpAttr; }
148 sal_uInt16 Which() const { return mpAttr->Which(); }
150 sal_Int32 GetStart() const { return mnStart; }
151 sal_Int32& GetStart() { return mnStart; }
153 sal_Int32 GetEnd() const { return mnEnd; }
154 sal_Int32& GetEnd() { return mnEnd; }
156 inline sal_Int32 GetLen() const;
158 inline void MoveForward( sal_Int32 nDiff );
159 inline void MoveBackward( sal_Int32 nDiff );
161 inline void Expand( sal_Int32 nDiff );
162 inline void Collaps( sal_Int32 nDiff );
164 inline bool IsIn( sal_Int32 nIndex );
165 inline bool IsInside( sal_Int32 nIndex );
166 inline bool IsEmpty() const;
170 inline sal_Int32 TextCharAttrib::GetLen() const
172 DBG_ASSERT( mnEnd >= mnStart, "TextCharAttrib: nEnd < nStart!" );
173 return mnEnd-mnStart;
176 inline void TextCharAttrib::MoveForward( sal_Int32 nDiff )
178 DBG_ASSERT( nDiff <= SAL_MAX_INT32-mnEnd, "TextCharAttrib: MoveForward?!" );
179 mnStart = mnStart + nDiff;
180 mnEnd = mnEnd + nDiff;
183 inline void TextCharAttrib::MoveBackward( sal_Int32 nDiff )
185 DBG_ASSERT( mnStart >= nDiff, "TextCharAttrib: MoveBackward?!" );
186 mnStart = mnStart - nDiff;
187 mnEnd = mnEnd - nDiff;
190 inline void TextCharAttrib::Expand( sal_Int32 nDiff )
192 DBG_ASSERT( nDiff <= SAL_MAX_INT32-mnEnd, "TextCharAttrib: Expand?!" );
193 mnEnd = mnEnd + nDiff;
196 inline void TextCharAttrib::Collaps( sal_Int32 nDiff )
198 DBG_ASSERT( mnEnd-mnStart >= nDiff, "TextCharAttrib: Collaps?!" );
199 mnEnd = mnEnd - nDiff;
202 inline bool TextCharAttrib::IsIn( sal_Int32 nIndex )
204 return ( ( mnStart <= nIndex ) && ( mnEnd >= nIndex ) );
207 inline bool TextCharAttrib::IsInside( sal_Int32 nIndex )
209 return ( ( mnStart < nIndex ) && ( mnEnd > nIndex ) );
212 inline bool TextCharAttrib::IsEmpty() const
214 return mnStart == mnEnd;
217 #endif // INCLUDED_VCL_TXTATTR_HXX
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */