workaround segfault in compiler on macos-clang-intel
[LibreOffice.git] / include / vcl / txtattr.hxx
blobe32fbc0b7cdec78c7396d3d93a96826d5bbffa2b
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 <config_options.h>
24 #include <tools/color.hxx>
25 #include <tools/debug.hxx>
26 #include <tools/fontenum.hxx>
27 #include <vcl/dllapi.h>
28 #include <memory>
30 namespace vcl { class Font; }
32 #define TEXTATTR_FONTCOLOR 1
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 const mnWhich;
44 protected:
45 TextAttrib( sal_uInt16 nWhich ) : mnWhich(nWhich) {}
46 TextAttrib( const TextAttrib& ) = default;
48 public:
50 virtual ~TextAttrib();
52 sal_uInt16 Which() const { return mnWhich; }
53 virtual void SetFont( vcl::Font& rFont ) const = 0;
54 virtual std::unique_ptr<TextAttrib> Clone() const = 0;
56 virtual bool operator==( const TextAttrib& rAttr ) const = 0;
57 bool operator!=( const TextAttrib& rAttr ) const
58 { return !(*this == rAttr ); }
62 class VCL_DLLPUBLIC TextAttribFontColor final : public TextAttrib
64 private:
65 Color maColor;
67 public:
68 TextAttribFontColor( const Color& rColor );
70 const Color& GetColor() const { return maColor; }
72 virtual void SetFont( vcl::Font& rFont ) const override;
73 virtual std::unique_ptr<TextAttrib> Clone() const override;
74 virtual bool operator==( const TextAttrib& rAttr ) const override;
78 class UNLESS_MERGELIBS_MORE(VCL_DLLPUBLIC) TextAttribFontWeight final : public TextAttrib
80 private:
81 FontWeight meWeight;
83 public:
84 TextAttribFontWeight( FontWeight eWeight );
86 virtual void SetFont( vcl::Font& rFont ) const override;
87 virtual std::unique_ptr<TextAttrib> Clone() const override;
88 virtual bool operator==( const TextAttrib& rAttr ) const override;
90 FontWeight getFontWeight() const { return meWeight; }
93 class TextAttribProtect final : public TextAttrib
95 public:
96 TextAttribProtect();
98 virtual void SetFont( vcl::Font& rFont ) const override;
99 virtual std::unique_ptr<TextAttrib> Clone() const override;
100 virtual bool operator==( const TextAttrib& rAttr ) const override;
105 class TextCharAttrib
107 private:
108 std::unique_ptr<TextAttrib>
109 mpAttr;
110 sal_Int32 mnStart;
111 sal_Int32 mnEnd;
113 public:
114 TextCharAttrib( const TextAttrib& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
115 TextCharAttrib( const TextCharAttrib& rTextCharAttrib );
117 const TextAttrib& GetAttr() const { return *mpAttr; }
119 sal_uInt16 Which() const { return mpAttr->Which(); }
121 sal_Int32 GetStart() const { return mnStart; }
122 void SetStart(sal_Int32 n) { mnStart = n; }
124 sal_Int32 GetEnd() const { return mnEnd; }
125 void SetEnd(sal_Int32 n) { mnEnd = n; }
127 inline sal_Int32 GetLen() const;
129 inline void MoveForward( sal_Int32 nDiff );
130 inline void MoveBackward( sal_Int32 nDiff );
132 inline void Expand( sal_Int32 nDiff );
133 inline void Collaps( sal_Int32 nDiff );
135 inline bool IsIn( sal_Int32 nIndex ) const;
136 inline bool IsInside( sal_Int32 nIndex ) const;
137 inline bool IsEmpty() const;
141 inline sal_Int32 TextCharAttrib::GetLen() const
143 DBG_ASSERT( mnEnd >= mnStart, "TextCharAttrib: nEnd < nStart!" );
144 return mnEnd-mnStart;
147 inline void TextCharAttrib::MoveForward( sal_Int32 nDiff )
149 DBG_ASSERT( nDiff <= SAL_MAX_INT32-mnEnd, "TextCharAttrib: MoveForward?!" );
150 mnStart = mnStart + nDiff;
151 mnEnd = mnEnd + nDiff;
154 inline void TextCharAttrib::MoveBackward( sal_Int32 nDiff )
156 DBG_ASSERT( mnStart >= nDiff, "TextCharAttrib: MoveBackward?!" );
157 mnStart = mnStart - nDiff;
158 mnEnd = mnEnd - nDiff;
161 inline void TextCharAttrib::Expand( sal_Int32 nDiff )
163 DBG_ASSERT( nDiff <= SAL_MAX_INT32-mnEnd, "TextCharAttrib: Expand?!" );
164 mnEnd = mnEnd + nDiff;
167 inline void TextCharAttrib::Collaps( sal_Int32 nDiff )
169 DBG_ASSERT( mnEnd-mnStart >= nDiff, "TextCharAttrib: Collaps?!" );
170 mnEnd = mnEnd - nDiff;
173 inline bool TextCharAttrib::IsIn( sal_Int32 nIndex ) const
175 return ( ( mnStart <= nIndex ) && ( mnEnd >= nIndex ) );
178 inline bool TextCharAttrib::IsInside( sal_Int32 nIndex ) const
180 return ( ( mnStart < nIndex ) && ( mnEnd > nIndex ) );
183 inline bool TextCharAttrib::IsEmpty() const
185 return mnStart == mnEnd;
188 #endif // INCLUDED_VCL_TXTATTR_HXX
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */