1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include "editattr.hxx"
23 #include "edtspell.hxx"
24 #include <editeng/svxfont.hxx>
25 #include <svl/itemset.hxx>
26 #include <svl/style.hxx>
27 #include <svl/itempool.hxx>
28 #include <svl/languageoptions.hxx>
29 #include <tools/lineend.hxx>
32 #include <string_view>
40 SfxStyleSheet
* mpStyle
= nullptr;
41 SfxItemSetFixed
<EE_PARA_START
, EE_CHAR_END
> maAttribSet
;
44 ContentAttribs(SfxItemPool
& rItemPool
);
46 void dumpAsXml(xmlTextWriterPtr pWriter
) const;
48 SvxTabStop
FindTabStop(sal_Int32 nCurPos
, sal_uInt16 nDefTab
);
49 SfxItemSet
& GetItems() { return maAttribSet
; }
50 const SfxItemSet
& GetItems() const { return maAttribSet
; }
51 const SfxStyleSheet
* GetStyleSheet() const { return mpStyle
; }
52 SfxStyleSheet
* GetStyleSheet() { return mpStyle
; }
53 void SetStyleSheet(SfxStyleSheet
* pS
);
55 const SfxPoolItem
& GetItem(sal_uInt16 nWhich
) const;
56 template <class T
> const T
& GetItem(TypedWhichId
<T
> nWhich
) const
58 return static_cast<const T
&>(GetItem(sal_uInt16(nWhich
)));
60 bool HasItem(sal_uInt16 nWhich
) const;
66 typedef std::vector
<std::unique_ptr
<EditCharAttrib
>> AttribsType
;
69 AttribsType maAttribs
;
70 SvxFont maDefFont
; // faster than ever from the pool!
71 bool mbHasEmptyAttribs
= false;
74 void dumpAsXml(xmlTextWriterPtr pWriter
) const;
76 void DeleteEmptyAttribs();
78 const EditCharAttrib
* FindAttrib(sal_uInt16 nWhich
, sal_Int32 nPos
) const;
79 EditCharAttrib
* FindAttrib(sal_uInt16 nWhich
, sal_Int32 nPos
);
80 const EditCharAttrib
* FindNextAttrib(sal_uInt16 nWhich
, sal_Int32 nFromPos
) const;
81 EditCharAttrib
* FindEmptyAttrib(sal_uInt16 nWhich
, sal_Int32 nPos
);
82 const EditCharAttrib
* FindFeature(sal_Int32 nPos
) const;
85 void OptimizeRanges();
87 sal_Int32
Count() const;
89 void InsertAttrib(EditCharAttrib
* pAttrib
);
91 SvxFont
& GetDefFont() { return maDefFont
; }
93 bool HasEmptyAttribs() const { return mbHasEmptyAttribs
; }
94 void SetHasEmptyAttribs(bool b
);
95 bool HasBoundingAttrib(sal_Int32 nBound
) const;
96 bool HasAttrib(sal_Int32 nStartPos
, sal_Int32 nEndPos
) const;
98 AttribsType
& GetAttribs() { return maAttribs
; }
99 const AttribsType
& GetAttribs() const { return maAttribs
; }
101 void Remove(const EditCharAttrib
* p
);
102 void Remove(sal_Int32 nPos
);
104 #if OSL_DEBUG_LEVEL > 0 && !defined NDEBUG
105 static void DbgCheckAttribs(CharAttribList
const& rAttribs
);
113 ContentAttribs maContentAttribs
;
114 CharAttribList maCharAttribList
;
115 std::unique_ptr
<WrongList
> mpWrongList
;
117 void UnExpandPosition(sal_Int32
& rStartPos
, bool bBiasStart
);
120 ContentNode(SfxItemPool
& rItemPool
);
121 ContentNode(const OUString
& rStr
, const ContentAttribs
& rContentAttribs
);
123 ContentNode(const ContentNode
&) = delete;
124 ContentNode
& operator=(const ContentNode
&) = delete;
126 void dumpAsXml(xmlTextWriterPtr pWriter
) const;
128 ContentAttribs
& GetContentAttribs() { return maContentAttribs
; }
129 const ContentAttribs
& GetContentAttribs() const { return maContentAttribs
; }
130 CharAttribList
& GetCharAttribs() { return maCharAttribList
; }
131 const CharAttribList
& GetCharAttribs() const { return maCharAttribList
; }
133 void ExpandAttribs(sal_Int32 nIndex
, sal_Int32 nNewChars
);
134 void CollapseAttribs(sal_Int32 nIndex
, sal_Int32 nDelChars
);
135 void AppendAttribs(ContentNode
* pNextNode
);
136 void CopyAndCutAttribs(ContentNode
* pPrevNode
, SfxItemPool
& rPool
, bool bKeepEndingAttribs
);
138 void SetStyleSheet(SfxStyleSheet
* pS
, bool bRecalcFont
= true);
139 void SetStyleSheet(SfxStyleSheet
* pS
, const SvxFont
& rFontFromStyle
);
140 SfxStyleSheet
* GetStyleSheet() { return maContentAttribs
.GetStyleSheet(); }
142 void CreateDefFont();
144 void EnsureWrongList();
145 WrongList
* GetWrongList();
146 const WrongList
* GetWrongList() const;
147 void SetWrongList(WrongList
* p
);
149 void CreateWrongList();
150 void DestroyWrongList();
152 bool IsFeature(sal_Int32 nPos
) const;
154 sal_Int32
Len() const;
155 const OUString
& GetString() const { return maString
; }
157 /// return length including expanded fields
158 sal_Int32
GetExpandedLen() const;
159 /// return content including expanded fields
160 OUString
GetExpandedText(sal_Int32 nStartPos
= 0, sal_Int32 nEndPos
= -1) const;
161 /// re-write offsets in the expanded text to string offsets
162 void UnExpandPositions(sal_Int32
& rStartPos
, sal_Int32
& rEndPos
);
164 void SetChar(sal_Int32 nPos
, sal_Unicode c
);
165 void Insert(std::u16string_view rStr
, sal_Int32 nPos
);
166 void Append(std::u16string_view rStr
);
167 void Erase(sal_Int32 nPos
);
168 void Erase(sal_Int32 nPos
, sal_Int32 nCount
);
169 OUString
Copy(sal_Int32 nPos
) const;
170 OUString
Copy(sal_Int32 nPos
, sal_Int32 nCount
) const;
171 sal_Unicode
GetChar(sal_Int32 nPos
) const;
173 void checkAndDeleteEmptyAttribs() const;
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */