Bump version to 6.4-15
[LibreOffice.git] / include / vcl / txtattr.hxx
bloba77ad3c786b6c69fc9b95d9721bc410f2af485c5
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 <tools/color.hxx>
24 #include <tools/debug.hxx>
25 #include <tools/fontenum.hxx>
26 #include <vcl/dllapi.h>
27 #include <memory>
29 namespace vcl { class Font; }
31 #define TEXTATTR_FONTCOLOR 1
32 #define TEXTATTR_FONTWEIGHT 3
34 #define TEXTATTR_USER_START 1000 //start id for user defined text attributes
35 #define TEXTATTR_PROTECTED 4
38 class VCL_DLLPUBLIC TextAttrib
40 private:
41 sal_uInt16 const mnWhich;
43 protected:
44 TextAttrib( sal_uInt16 nWhich ) : mnWhich(nWhich) {}
45 TextAttrib( const TextAttrib& ) = default;
47 public:
49 virtual ~TextAttrib();
51 sal_uInt16 Which() const { return mnWhich; }
52 virtual void SetFont( vcl::Font& rFont ) const = 0;
53 virtual std::unique_ptr<TextAttrib> Clone() const = 0;
55 virtual bool operator==( const TextAttrib& rAttr ) const = 0;
56 bool operator!=( const TextAttrib& rAttr ) const
57 { return !(*this == rAttr ); }
61 class VCL_DLLPUBLIC TextAttribFontColor final : public TextAttrib
63 private:
64 Color const maColor;
66 public:
67 TextAttribFontColor( const Color& rColor );
69 const Color& GetColor() const { return maColor; }
71 virtual void SetFont( vcl::Font& rFont ) const override;
72 virtual std::unique_ptr<TextAttrib> Clone() const override;
73 virtual bool operator==( const TextAttrib& rAttr ) const override;
77 class VCL_DLLPUBLIC TextAttribFontWeight final : public TextAttrib
79 private:
80 FontWeight const meWeight;
82 public:
83 TextAttribFontWeight( FontWeight eWeight );
85 virtual void SetFont( vcl::Font& rFont ) const override;
86 virtual std::unique_ptr<TextAttrib> Clone() const override;
87 virtual bool operator==( const TextAttrib& rAttr ) const override;
89 FontWeight getFontWeight() const { return meWeight; }
92 class TextAttribProtect final : public TextAttrib
94 public:
95 TextAttribProtect();
97 virtual void SetFont( vcl::Font& rFont ) const override;
98 virtual std::unique_ptr<TextAttrib> Clone() const override;
99 virtual bool operator==( const TextAttrib& rAttr ) const override;
104 class TextCharAttrib
106 private:
107 std::unique_ptr<TextAttrib>
108 mpAttr;
109 sal_Int32 mnStart;
110 sal_Int32 mnEnd;
112 public:
113 TextCharAttrib( const TextAttrib& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
114 TextCharAttrib( const TextCharAttrib& rTextCharAttrib );
116 const TextAttrib& GetAttr() const { return *mpAttr; }
118 sal_uInt16 Which() const { return mpAttr->Which(); }
120 sal_Int32 GetStart() const { return mnStart; }
121 void SetStart(sal_Int32 n) { mnStart = n; }
123 sal_Int32 GetEnd() const { return mnEnd; }
124 void SetEnd(sal_Int32 n) { mnEnd = n; }
126 inline sal_Int32 GetLen() const;
128 inline void MoveForward( sal_Int32 nDiff );
129 inline void MoveBackward( sal_Int32 nDiff );
131 inline void Expand( sal_Int32 nDiff );
132 inline void Collaps( sal_Int32 nDiff );
134 inline bool IsIn( sal_Int32 nIndex );
135 inline bool IsInside( sal_Int32 nIndex );
136 inline bool IsEmpty() const;
140 inline sal_Int32 TextCharAttrib::GetLen() const
142 DBG_ASSERT( mnEnd >= mnStart, "TextCharAttrib: nEnd < nStart!" );
143 return mnEnd-mnStart;
146 inline void TextCharAttrib::MoveForward( sal_Int32 nDiff )
148 DBG_ASSERT( nDiff <= SAL_MAX_INT32-mnEnd, "TextCharAttrib: MoveForward?!" );
149 mnStart = mnStart + nDiff;
150 mnEnd = mnEnd + nDiff;
153 inline void TextCharAttrib::MoveBackward( sal_Int32 nDiff )
155 DBG_ASSERT( mnStart >= nDiff, "TextCharAttrib: MoveBackward?!" );
156 mnStart = mnStart - nDiff;
157 mnEnd = mnEnd - nDiff;
160 inline void TextCharAttrib::Expand( sal_Int32 nDiff )
162 DBG_ASSERT( nDiff <= SAL_MAX_INT32-mnEnd, "TextCharAttrib: Expand?!" );
163 mnEnd = mnEnd + nDiff;
166 inline void TextCharAttrib::Collaps( sal_Int32 nDiff )
168 DBG_ASSERT( mnEnd-mnStart >= nDiff, "TextCharAttrib: Collaps?!" );
169 mnEnd = mnEnd - nDiff;
172 inline bool TextCharAttrib::IsIn( sal_Int32 nIndex )
174 return ( ( mnStart <= nIndex ) && ( mnEnd >= nIndex ) );
177 inline bool TextCharAttrib::IsInside( sal_Int32 nIndex )
179 return ( ( mnStart < nIndex ) && ( mnEnd > nIndex ) );
182 inline bool TextCharAttrib::IsEmpty() const
184 return mnStart == mnEnd;
187 #endif // INCLUDED_VCL_TXTATTR_HXX
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */