LibreOffice Module vcl (master) 1
txtattr.hxx
Go to the documentation of this file.
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 <tools/color.hxx>
24#include <tools/debug.hxx>
25#include <tools/fontenum.hxx>
26#include <vcl/dllapi.h>
27#include <memory>
28
29namespace vcl { class Font; }
30
31#define TEXTATTR_FONTCOLOR 1
32#define TEXTATTR_FONTWEIGHT 3
33
34#define TEXTATTR_USER_START 1000 //start id for user defined text attributes
35#define TEXTATTR_PROTECTED 4
36
37
39{
40private:
41 sal_uInt16 const mnWhich;
42
43protected:
44 TextAttrib( sal_uInt16 nWhich ) : mnWhich(nWhich) {}
45 TextAttrib( const TextAttrib& ) = default;
46
47public:
48
49 virtual ~TextAttrib();
50
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;
54
55 virtual bool operator==( const TextAttrib& rAttr ) const = 0;
56 bool operator!=( const TextAttrib& rAttr ) const
57 { return !(*this == rAttr ); }
58};
59
60
62{
63private:
65
66public:
67 TextAttribFontColor( const Color& rColor );
68
69 const Color& GetColor() const { return maColor; }
70
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;
74
75};
76
78{
79private:
81
82public:
84
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;
88
89 FontWeight getFontWeight() const { return meWeight; }
90};
91
92class TextAttribProtect final : public TextAttrib
93{
94public:
96
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;
100
101};
102
103
105{
106private:
107 std::unique_ptr<TextAttrib>
109 sal_Int32 mnStart;
110 sal_Int32 mnEnd;
111
112public:
113 TextCharAttrib( const TextAttrib& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
114 TextCharAttrib( const TextCharAttrib& rTextCharAttrib );
115
116 const TextAttrib& GetAttr() const { return *mpAttr; }
117
118 sal_uInt16 Which() const { return mpAttr->Which(); }
119
120 sal_Int32 GetStart() const { return mnStart; }
121 void SetStart(sal_Int32 n) { mnStart = n; }
122
123 sal_Int32 GetEnd() const { return mnEnd; }
124 void SetEnd(sal_Int32 n) { mnEnd = n; }
125
126 inline sal_Int32 GetLen() const;
127
128 inline void MoveForward( sal_Int32 nDiff );
129 inline void MoveBackward( sal_Int32 nDiff );
130
131 inline void Expand( sal_Int32 nDiff );
132 inline void Collaps( sal_Int32 nDiff );
133
134 inline bool IsIn( sal_Int32 nIndex ) const;
135 inline bool IsInside( sal_Int32 nIndex ) const;
136 inline bool IsEmpty() const;
137
138};
139
140inline sal_Int32 TextCharAttrib::GetLen() const
141{
142 DBG_ASSERT( mnEnd >= mnStart, "TextCharAttrib: nEnd < nStart!" );
143 return mnEnd-mnStart;
144}
145
146inline void TextCharAttrib::MoveForward( sal_Int32 nDiff )
147{
148 DBG_ASSERT( nDiff <= SAL_MAX_INT32-mnEnd, "TextCharAttrib: MoveForward?!" );
149 mnStart = mnStart + nDiff;
150 mnEnd = mnEnd + nDiff;
151}
152
153inline void TextCharAttrib::MoveBackward( sal_Int32 nDiff )
154{
155 DBG_ASSERT( mnStart >= nDiff, "TextCharAttrib: MoveBackward?!" );
156 mnStart = mnStart - nDiff;
157 mnEnd = mnEnd - nDiff;
158}
159
160inline void TextCharAttrib::Expand( sal_Int32 nDiff )
161{
162 DBG_ASSERT( nDiff <= SAL_MAX_INT32-mnEnd, "TextCharAttrib: Expand?!" );
163 mnEnd = mnEnd + nDiff;
164}
165
166inline void TextCharAttrib::Collaps( sal_Int32 nDiff )
167{
168 DBG_ASSERT( mnEnd-mnStart >= nDiff, "TextCharAttrib: Collaps?!" );
169 mnEnd = mnEnd - nDiff;
170}
171
172inline bool TextCharAttrib::IsIn( sal_Int32 nIndex ) const
173{
174 return ( ( mnStart <= nIndex ) && ( mnEnd >= nIndex ) );
175}
176
177inline bool TextCharAttrib::IsInside( sal_Int32 nIndex ) const
178{
179 return ( ( mnStart < nIndex ) && ( mnEnd > nIndex ) );
180}
181
182inline bool TextCharAttrib::IsEmpty() const
183{
184 return mnStart == mnEnd;
185}
186
187#endif // INCLUDED_VCL_TXTATTR_HXX
188
189/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
basegfx::BColor maColor
const Color & GetColor() const
Definition: txtattr.hxx:69
FontWeight meWeight
Definition: txtattr.hxx:80
FontWeight getFontWeight() const
Definition: txtattr.hxx:89
virtual std::unique_ptr< TextAttrib > Clone() const override
Definition: txtattr.cxx:83
virtual bool operator==(const TextAttrib &rAttr) const override
Definition: txtattr.cxx:88
virtual void SetFont(vcl::Font &rFont) const override
Definition: txtattr.cxx:79
TextAttrib(sal_uInt16 nWhich)
Definition: txtattr.hxx:44
virtual std::unique_ptr< TextAttrib > Clone() const =0
sal_uInt16 Which() const
Definition: txtattr.hxx:51
virtual void SetFont(vcl::Font &rFont) const =0
bool operator!=(const TextAttrib &rAttr) const
Definition: txtattr.hxx:56
sal_uInt16 const mnWhich
Definition: txtattr.hxx:41
TextAttrib(const TextAttrib &)=default
bool IsEmpty() const
Definition: txtattr.hxx:182
void Expand(sal_Int32 nDiff)
Definition: txtattr.hxx:160
void MoveBackward(sal_Int32 nDiff)
Definition: txtattr.hxx:153
void Collaps(sal_Int32 nDiff)
Definition: txtattr.hxx:166
void SetStart(sal_Int32 n)
Definition: txtattr.hxx:121
const TextAttrib & GetAttr() const
Definition: txtattr.hxx:116
TextCharAttrib(const TextAttrib &rAttr, sal_Int32 nStart, sal_Int32 nEnd)
Definition: textdoc.cxx:33
sal_uInt16 Which() const
Definition: txtattr.hxx:118
bool IsIn(sal_Int32 nIndex) const
Definition: txtattr.hxx:172
sal_Int32 mnStart
Definition: txtattr.hxx:109
sal_Int32 GetLen() const
Definition: txtattr.hxx:140
void MoveForward(sal_Int32 nDiff)
Definition: txtattr.hxx:146
sal_Int32 GetStart() const
Definition: txtattr.hxx:120
sal_Int32 mnEnd
Definition: txtattr.hxx:110
bool IsInside(sal_Int32 nIndex) const
Definition: txtattr.hxx:177
sal_Int32 GetEnd() const
Definition: txtattr.hxx:123
void SetEnd(sal_Int32 n)
Definition: txtattr.hxx:124
std::unique_ptr< TextAttrib > mpAttr
Definition: txtattr.hxx:108
#define DBG_ASSERT(sCon, aError)
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
sal_Int32 nIndex
sal_Int64 n
css::uno::Reference< css::animations::XAnimationNode > Clone(const css::uno::Reference< css::animations::XAnimationNode > &xSourceNode, const SdPage *pSource=nullptr, const SdPage *pTarget=nullptr)
FontWeight
#define SAL_MAX_INT32
bool operator==(const ItalicMatrix &a, const ItalicMatrix &b)
Definition: vclenum.hxx:175