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 SfxItemSet 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 EditCharAttrib
* FindAttribRightOpen(sal_uInt16 nWhich
, sal_Int32 nPos
);
81 const EditCharAttrib
* FindNextAttrib(sal_uInt16 nWhich
, sal_Int32 nFromPos
) const;
82 EditCharAttrib
* FindEmptyAttrib(sal_uInt16 nWhich
, sal_Int32 nPos
);
83 const EditCharAttrib
* FindFeature(sal_Int32 nPos
) const;
86 void OptimizeRanges();
88 sal_Int32
Count() const;
90 void InsertAttrib(EditCharAttrib
* pAttrib
);
92 SvxFont
& GetDefFont() { return maDefFont
; }
94 bool HasEmptyAttribs() const { return mbHasEmptyAttribs
; }
95 void SetHasEmptyAttribs(bool b
);
96 bool HasBoundingAttrib(sal_Int32 nBound
) const;
97 bool HasAttrib(sal_Int32 nStartPos
, sal_Int32 nEndPos
) const;
99 AttribsType
& GetAttribs() { return maAttribs
; }
100 const AttribsType
& GetAttribs() const { return maAttribs
; }
102 void Remove(const EditCharAttrib
* p
);
103 void Remove(sal_Int32 nPos
);
105 #if OSL_DEBUG_LEVEL > 0 && !defined NDEBUG
106 static void DbgCheckAttribs(CharAttribList
const& rAttribs
);
114 ContentAttribs maContentAttribs
;
115 CharAttribList maCharAttribList
;
116 std::unique_ptr
<WrongList
> mpWrongList
;
118 void UnExpandPosition(sal_Int32
& rStartPos
, bool bBiasStart
);
121 ContentNode(SfxItemPool
& rItemPool
);
122 ContentNode(const OUString
& rStr
, const ContentAttribs
& rContentAttribs
);
124 ContentNode(const ContentNode
&) = delete;
125 ContentNode
& operator=(const ContentNode
&) = delete;
127 void dumpAsXml(xmlTextWriterPtr pWriter
) const;
129 ContentAttribs
& GetContentAttribs() { return maContentAttribs
; }
130 const ContentAttribs
& GetContentAttribs() const { return maContentAttribs
; }
131 CharAttribList
& GetCharAttribs() { return maCharAttribList
; }
132 const CharAttribList
& GetCharAttribs() const { return maCharAttribList
; }
134 void ExpandAttribs(sal_Int32 nIndex
, sal_Int32 nNewChars
);
135 void CollapseAttribs(sal_Int32 nIndex
, sal_Int32 nDelChars
);
136 void AppendAttribs(ContentNode
* pNextNode
);
137 void CopyAndCutAttribs(ContentNode
* pPrevNode
, SfxItemPool
& rPool
, bool bKeepEndingAttribs
);
139 void SetStyleSheet(SfxStyleSheet
* pS
, bool bRecalcFont
= true);
140 void SetStyleSheet(SfxStyleSheet
* pS
, const SvxFont
& rFontFromStyle
);
141 SfxStyleSheet
* GetStyleSheet() { return maContentAttribs
.GetStyleSheet(); }
143 void CreateDefFont();
145 void EnsureWrongList();
146 WrongList
* GetWrongList();
147 const WrongList
* GetWrongList() const;
148 void SetWrongList(WrongList
* p
);
150 void CreateWrongList();
151 void DestroyWrongList();
153 bool IsFeature(sal_Int32 nPos
) const;
155 sal_Int32
Len() const;
156 const OUString
& GetString() const { return maString
; }
158 /// return length including expanded fields
159 sal_Int32
GetExpandedLen() const;
160 /// return content including expanded fields
161 OUString
GetExpandedText(sal_Int32 nStartPos
= 0, sal_Int32 nEndPos
= -1) const;
162 /// re-write offsets in the expanded text to string offsets
163 void UnExpandPositions(sal_Int32
& rStartPos
, sal_Int32
& rEndPos
);
165 void SetChar(sal_Int32 nPos
, sal_Unicode c
);
166 void Insert(const OUString
& rStr
, sal_Int32 nPos
);
167 void Append(std::u16string_view rStr
);
168 void Erase(sal_Int32 nPos
);
169 void Erase(sal_Int32 nPos
, sal_Int32 nCount
);
170 OUString
Copy(sal_Int32 nPos
) const;
171 OUString
Copy(sal_Int32 nPos
, sal_Int32 nCount
) const;
172 sal_Unicode
GetChar(sal_Int32 nPos
) const;
174 void checkAndDeleteEmptyAttribs() const;
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */