/src/libreoffice/editeng/inc/editdoc.hxx
Line | Count | Source |
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 | | #pragma once |
21 | | |
22 | | #include <config_collab.h> |
23 | | |
24 | | #include "editattr.hxx" |
25 | | #include <editeng/svxfont.hxx> |
26 | | #include <svl/itemset.hxx> |
27 | | #include <svl/itempool.hxx> |
28 | | #include <svl/languageoptions.hxx> |
29 | | #include <tools/lineend.hxx> |
30 | | #include "ContentNode.hxx" |
31 | | #include "EditPaM.hxx" |
32 | | |
33 | | #include <cstddef> |
34 | | #include <memory> |
35 | | #include <vector> |
36 | | |
37 | | enum class TextRotation; |
38 | | |
39 | | #if ENABLE_YRS |
40 | | #include "EditSelection.hxx" |
41 | | class ImpEditEngine; |
42 | | class IYrsTransactionSupplier; |
43 | | typedef struct TransactionInner YTransaction; |
44 | | typedef struct YTextEvent YTextEvent; |
45 | | typedef struct Branch Branch; |
46 | | typedef struct YOutput YOutput; |
47 | | #endif |
48 | | |
49 | | |
50 | 7.73M | #define CHARPOSGROW 16 |
51 | 3.10M | #define DEFTAB 720 |
52 | | |
53 | | void CreateFont( SvxFont& rFont, const SfxItemSet& rSet, bool bSearchInParent = true, SvtScriptType nScriptType = SvtScriptType::NONE ); |
54 | | sal_uInt16 GetScriptItemId( sal_uInt16 nItemId, SvtScriptType nScriptType ); |
55 | | bool IsScriptItemValid( sal_uInt16 nItemId, short nScriptType ); |
56 | | |
57 | | EditCharAttrib* MakeCharAttrib( SfxItemPool& rPool, const SfxPoolItem& rAttr, sal_Int32 nS, sal_Int32 nE ); |
58 | | |
59 | | class ContentAttribsInfo |
60 | | { |
61 | | private: |
62 | | typedef std::vector<std::unique_ptr<EditCharAttrib> > CharAttribsType; |
63 | | |
64 | | SfxItemSet aPrevParaAttribs; |
65 | | CharAttribsType aPrevCharAttribs; |
66 | | |
67 | | public: |
68 | | ContentAttribsInfo( SfxItemSet aParaAttribs ); |
69 | | |
70 | 0 | const SfxItemSet& GetPrevParaAttribs() const { return aPrevParaAttribs; } |
71 | 0 | const CharAttribsType& GetPrevCharAttribs() const { return aPrevCharAttribs; } |
72 | | |
73 | | void AppendCharAttrib(EditCharAttrib* pNew); |
74 | | }; |
75 | | |
76 | | typedef std::vector<Color> SvxColorList; |
77 | | |
78 | | enum class DeleteMode { |
79 | | Simple, RestOfWord, RestOfContent |
80 | | }; |
81 | | |
82 | | class DeletedNodeInfo |
83 | | { |
84 | | private: |
85 | | ContentNode* mpInvalidNode; |
86 | | sal_Int32 nInvalidParagraph; |
87 | | |
88 | | public: |
89 | | DeletedNodeInfo( ContentNode* pNode, sal_Int32 nPos ) |
90 | 115k | : mpInvalidNode(pNode) |
91 | 115k | , nInvalidParagraph(nPos) |
92 | 115k | { |
93 | 115k | } |
94 | | |
95 | 0 | ContentNode* GetNode() const { return mpInvalidNode; } |
96 | 0 | sal_Int32 GetPosition() const { return nInvalidParagraph; } |
97 | | }; |
98 | | |
99 | | |
100 | | /** Edit document |
101 | | * |
102 | | * Holder, responsible for the content nodes and the manipulation of those. |
103 | | */ |
104 | | class EditDoc |
105 | | { |
106 | | private: |
107 | | mutable sal_Int32 mnLastCache; |
108 | | std::vector<std::unique_ptr<ContentNode>> maContents; |
109 | | |
110 | | rtl::Reference<SfxItemPool> mpItemPool; |
111 | | Link<LinkParamNone*,void> maModifyHdl; |
112 | | |
113 | | SvxFont maDefFont; //faster than ever from the pool!! |
114 | | sal_uInt16 mnDefTab; |
115 | | bool mbIsVertical:1; |
116 | | TextRotation mnRotation; |
117 | | bool mbIsFixedCellHeight:1; |
118 | | |
119 | | bool mbModified:1; |
120 | | bool mbDisableAttributeExpanding:1; |
121 | | |
122 | | #if ENABLE_YRS |
123 | | OString m_CommentId; |
124 | | IYrsTransactionSupplier * m_pYrsSupplier{nullptr}; |
125 | | public: |
126 | | void SetYrsCommentId(IYrsTransactionSupplier *, OString const& rId); |
127 | | void YrsWriteEEState(); |
128 | | void YrsReadEEState(YTransaction *, ImpEditEngine & rIEE); |
129 | | void YrsApplyEEDelta(YTransaction *, YTextEvent const* pEvent, ImpEditEngine & rIEE); |
130 | | bool YrsWriteEECursor(YTransaction *, Branch const& rArray, YOutput const* pCurrent, EditSelection const& rSelection); |
131 | | ::std::optional<EditSelection> YrsReadEECursor(::std::pair<int64_t, int64_t> point, |
132 | | ::std::optional<::std::pair<int64_t, int64_t>> oMark); |
133 | | void YrsSetStyle(sal_Int32 nPara, ::std::u16string_view rStyle); |
134 | | void YrsSetParaAttr(sal_Int32 nPara, SfxPoolItem const& rItem); |
135 | | OString GetYrsCommentId() const; |
136 | | #endif |
137 | | |
138 | | public: |
139 | | EditDoc( SfxItemPool* pItemPool ); |
140 | | ~EditDoc(); |
141 | | |
142 | | void dumpAsXml(xmlTextWriterPtr pWriter) const; |
143 | | void ClearSpellErrors(); |
144 | | |
145 | 0 | bool IsModified() const { return mbModified; } |
146 | | void SetModified( bool b ); |
147 | | |
148 | 0 | void DisableAttributeExpanding() { mbDisableAttributeExpanding = true; } |
149 | | |
150 | | void SetModifyHdl(const Link<LinkParamNone*,void>& rLink) |
151 | 1.02M | { |
152 | 1.02M | maModifyHdl = rLink; |
153 | 1.02M | } |
154 | | |
155 | | void CreateDefFont( bool bUseStyles ); |
156 | 2.40M | const SvxFont& GetDefFont() const { return maDefFont; } |
157 | | |
158 | | void SetDefTab(sal_uInt16 nTab); |
159 | | |
160 | | sal_uInt16 GetDefTab() const |
161 | 0 | { |
162 | 0 | return mnDefTab; |
163 | 0 | } |
164 | | |
165 | | void SetVertical(bool bVertical); |
166 | | |
167 | | bool IsEffectivelyVertical() const; |
168 | | bool IsTopToBottom() const; |
169 | | bool GetVertical() const; |
170 | | void SetRotation(TextRotation nRotation); |
171 | 6.38M | TextRotation GetRotation() const { return mnRotation; } |
172 | | |
173 | | void SetFixedCellHeight( bool bUseFixedCellHeight ) |
174 | 469 | { |
175 | 469 | mbIsFixedCellHeight = bUseFixedCellHeight; |
176 | 469 | } |
177 | | bool IsFixedCellHeight() const |
178 | 16.9M | { |
179 | 16.9M | return mbIsFixedCellHeight; |
180 | 16.9M | } |
181 | | |
182 | | EditPaM Clear(); |
183 | | EditPaM RemoveText(); |
184 | | void RemoveChars( EditPaM aPaM, sal_Int32 nChars ); |
185 | | EditPaM InsertText( EditPaM aPaM, const OUString& rStr ); |
186 | | EditPaM InsertParaBreak( EditPaM aPaM, bool bKeepEndingAttribs ); |
187 | | EditPaM InsertFeature( EditPaM aPaM, const SfxPoolItem& rItem ); |
188 | | EditPaM ConnectParagraphs( ContentNode* pLeft, ContentNode* pRight ); |
189 | | |
190 | | OUString GetText( LineEnd eEnd ) const; |
191 | | sal_Int32 GetTextLen() const; |
192 | | |
193 | | OUString GetParaAsString( sal_Int32 nNode ) const; |
194 | | static OUString GetParaAsString(const ContentNode* pNode, sal_Int32 nStartPos = 0, sal_Int32 nEndPos = -1); |
195 | | |
196 | | EditPaM GetStartPaM() const; |
197 | | EditPaM GetEndPaM() const; |
198 | | |
199 | | SfxItemPool& GetItemPool() |
200 | 41.3M | { |
201 | 41.3M | return *mpItemPool; |
202 | 41.3M | } |
203 | | const SfxItemPool& GetItemPool() const |
204 | 202k | { |
205 | 202k | return *mpItemPool; |
206 | 202k | } |
207 | | void SetItemPool(SfxItemPool* pPool) |
208 | 411k | { |
209 | 411k | mpItemPool = pPool; |
210 | 411k | } |
211 | | |
212 | | void InsertAttrib( const SfxPoolItem& rItem, ContentNode* pNode, sal_Int32 nStart, sal_Int32 nEnd ); |
213 | | void InsertAttrib( ContentNode* pNode, sal_Int32 nStart, sal_Int32 nEnd, const SfxPoolItem& rPoolItem ); |
214 | | void InsertAttribInSelection( ContentNode* pNode, sal_Int32 nStart, sal_Int32 nEnd, const SfxPoolItem& rPoolItem ); |
215 | | bool RemoveAttribs( ContentNode* pNode, sal_Int32 nStart, sal_Int32 nEnd, sal_uInt16 nWhich ); |
216 | | bool RemoveAttribs( ContentNode* pNode, sal_Int32 nStart, sal_Int32 nEnd, EditCharAttrib*& rpStarting, EditCharAttrib*& rpEnding, sal_uInt16 nWhich ); |
217 | | static void FindAttribs( ContentNode* pNode, sal_Int32 nStartPos, sal_Int32 nEndPos, SfxItemSet& rCurSet ); |
218 | | |
219 | | sal_Int32 GetPos(const ContentNode* pNode) const; |
220 | | const ContentNode* GetObject(sal_Int32 nPos) const; |
221 | | ContentNode* GetObject(sal_Int32 nPos); |
222 | | sal_Int32 Count() const; |
223 | | void Insert(sal_Int32 nPos, std::unique_ptr<ContentNode> p); |
224 | | /// deletes |
225 | | void Remove(sal_Int32 nPos); |
226 | | /// does not delete |
227 | | std::unique_ptr<ContentNode> Release(sal_Int32 nPos); |
228 | | |
229 | | static OUString GetSepStr( LineEnd eEnd ); |
230 | | }; |
231 | | |
232 | | inline EditCharAttrib* GetAttrib(CharAttribList::AttribsType& rAttribs, std::size_t nAttr) |
233 | 277M | { |
234 | 277M | return (nAttr < rAttribs.size()) ? rAttribs[nAttr].get() : nullptr; |
235 | 277M | } |
236 | | |
237 | | #if OSL_DEBUG_LEVEL > 0 && !defined NDEBUG |
238 | | void CheckOrderedList(const CharAttribList::AttribsType& rAttribs); |
239 | | #endif |
240 | | |
241 | | class EDITENG_DLLPUBLIC EditEngineItemPool final : public SfxItemPool |
242 | | { |
243 | | public: |
244 | | EditEngineItemPool(); |
245 | | private: |
246 | | virtual ~EditEngineItemPool() override; |
247 | | }; |
248 | | |
249 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |