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 
29 namespace 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 {
40 private:
41  sal_uInt16 const mnWhich;
42 
43 protected:
44  TextAttrib( sal_uInt16 nWhich ) : mnWhich(nWhich) {}
45  TextAttrib( const TextAttrib& ) = default;
46 
47 public:
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 {
63 private:
64  Color const maColor;
65 
66 public:
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 {
79 private:
81 
82 public:
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 
92 class TextAttribProtect final : public TextAttrib
93 {
94 public:
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 {
106 private:
107  std::unique_ptr<TextAttrib>
109  sal_Int32 mnStart;
110  sal_Int32 mnEnd;
111 
112 public:
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 );
135  inline bool IsInside( sal_Int32 nIndex );
136  inline bool IsEmpty() const;
137 
138 };
139 
140 inline sal_Int32 TextCharAttrib::GetLen() const
141 {
142  DBG_ASSERT( mnEnd >= mnStart, "TextCharAttrib: nEnd < nStart!" );
143  return mnEnd-mnStart;
144 }
145 
146 inline 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 
153 inline void TextCharAttrib::MoveBackward( sal_Int32 nDiff )
154 {
155  DBG_ASSERT( mnStart >= nDiff, "TextCharAttrib: MoveBackward?!" );
156  mnStart = mnStart - nDiff;
157  mnEnd = mnEnd - nDiff;
158 }
159 
160 inline void TextCharAttrib::Expand( sal_Int32 nDiff )
161 {
162  DBG_ASSERT( nDiff <= SAL_MAX_INT32-mnEnd, "TextCharAttrib: Expand?!" );
163  mnEnd = mnEnd + nDiff;
164 }
165 
166 inline void TextCharAttrib::Collaps( sal_Int32 nDiff )
167 {
168  DBG_ASSERT( mnEnd-mnStart >= nDiff, "TextCharAttrib: Collaps?!" );
169  mnEnd = mnEnd - nDiff;
170 }
171 
172 inline bool TextCharAttrib::IsIn( sal_Int32 nIndex )
173 {
174  return ( ( mnStart <= nIndex ) && ( mnEnd >= nIndex ) );
175 }
176 
177 inline bool TextCharAttrib::IsInside( sal_Int32 nIndex )
178 {
179  return ( ( mnStart < nIndex ) && ( mnEnd > nIndex ) );
180 }
181 
182 inline 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: */
const Color & GetColor() const
Definition: txtattr.hxx:69
sal_Int32 GetLen() const
Definition: txtattr.hxx:140
FontWeight getFontWeight() const
Definition: txtattr.hxx:89
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
sal_Int32 GetStart() const
Definition: txtattr.hxx:120
sal_uInt16 Which() const
Definition: txtattr.hxx:51
void Collaps(sal_Int32 nDiff)
Definition: txtattr.hxx:166
FontWeight const meWeight
Definition: txtattr.hxx:80
sal_Int32 mnStart
Definition: txtattr.hxx:109
sal_Int32 mnEnd
Definition: txtattr.hxx:110
virtual bool operator==(const TextAttrib &rAttr) const override
Definition: txtattr.cxx:88
virtual void SetFont(vcl::Font &rFont) const =0
bool IsEmpty() const
Definition: txtattr.hxx:182
bool IsInside(sal_Int32 nIndex)
Definition: txtattr.hxx:177
bool operator==(const ItalicMatrix &a, const ItalicMatrix &b)
Definition: vclenum.hxx:203
Color const maColor
Definition: txtattr.hxx:64
virtual void SetFont(vcl::Font &rFont) const override
Definition: txtattr.cxx:79
#define SAL_MAX_INT32
#define DBG_ASSERT(sCon, aError)
Reference< XAnimationNode > Clone(const Reference< XAnimationNode > &xSourceNode, const SdPage *pSource, const SdPage *pTarget)
void SetEnd(sal_Int32 n)
Definition: txtattr.hxx:124
std::unique_ptr< TextAttrib > mpAttr
Definition: txtattr.hxx:108
sal_uInt16 Which() const
Definition: txtattr.hxx:118
virtual std::unique_ptr< TextAttrib > Clone() const =0
void MoveBackward(sal_Int32 nDiff)
Definition: txtattr.hxx:153
const TextAttrib & GetAttr() const
Definition: txtattr.hxx:116
TextAttrib(sal_uInt16 nWhich)
Definition: txtattr.hxx:44
void Expand(sal_Int32 nDiff)
Definition: txtattr.hxx:160
FontWeight
virtual bool operator==(const TextAttrib &rAttr) const =0
Definition: txtattr.cxx:27
sal_Int32 GetEnd() const
Definition: txtattr.hxx:123
TextCharAttrib(const TextAttrib &rAttr, sal_Int32 nStart, sal_Int32 nEnd)
Definition: textdoc.cxx:31
bool IsIn(sal_Int32 nIndex)
Definition: txtattr.hxx:172
sal_uInt16 const mnWhich
Definition: txtattr.hxx:41
virtual std::unique_ptr< TextAttrib > Clone() const override
Definition: txtattr.cxx:83
bool operator!=(const TextAttrib &rAttr) const
Definition: txtattr.hxx:56
void MoveForward(sal_Int32 nDiff)
Definition: txtattr.hxx:146
void SetStart(sal_Int32 n)
Definition: txtattr.hxx:121