Line data Source code
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 : #ifndef INCLUDED_SW_INC_DOCARY_HXX
20 : #define INCLUDED_SW_INC_DOCARY_HXX
21 :
22 : #include <com/sun/star/i18n/ForbiddenCharacters.hpp>
23 : #include <vector>
24 : #include <set>
25 : #include <algorithm>
26 : #include <o3tl/sorted_vector.hxx>
27 :
28 : class SwRangeRedline;
29 : class SwExtraRedline;
30 : class SwUnoCrsr;
31 : class SwOLENode;
32 : class SwTable;
33 : class SwTableLine;
34 : class SwTableBox;
35 :
36 : namespace com { namespace sun { namespace star { namespace i18n {
37 : struct ForbiddenCharacters; ///< comes from the I18N UNO interface
38 : }}}}
39 :
40 : #include <swtypes.hxx>
41 : #include <ndarr.hxx>
42 : #include <charfmt.hxx>
43 : #include <fmtcol.hxx>
44 : #include <frmfmt.hxx>
45 : #include <section.hxx>
46 : #include <fldbas.hxx>
47 : #include <tox.hxx>
48 : #include <numrule.hxx>
49 :
50 : /** provides some methods for generic operations on lists that contain
51 : SwFormat* subclasses. */
52 21652 : class SwFormatsBase
53 : {
54 : public:
55 : virtual size_t GetFormatCount() const = 0;
56 : virtual SwFormat* GetFormat(size_t idx) const = 0;
57 21589 : virtual ~SwFormatsBase() {};
58 : };
59 :
60 : template<typename Value>
61 0 : class SwVectorModifyBase : public std::vector<Value>
62 : {
63 : public:
64 : typedef typename std::vector<Value>::const_iterator const_iterator;
65 :
66 : protected:
67 : enum class DestructorPolicy {
68 : KeepElements,
69 : FreeElements,
70 : };
71 :
72 : private:
73 : const DestructorPolicy mPolicy;
74 :
75 : protected:
76 : // default destructor deletes all contained elements
77 30738 : SwVectorModifyBase(DestructorPolicy policy = DestructorPolicy::FreeElements)
78 30738 : : mPolicy(policy) {}
79 :
80 : public:
81 : using std::vector<Value>::begin;
82 : using std::vector<Value>::end;
83 :
84 : // free any remaining child objects based on mPolicy
85 30572 : virtual ~SwVectorModifyBase()
86 : {
87 30572 : if (mPolicy == DestructorPolicy::FreeElements)
88 158754 : for(const_iterator it = begin(); it != end(); ++it)
89 134080 : delete *it;
90 61144 : }
91 :
92 11880 : void DeleteAndDestroy(int aStartIdx, int aEndIdx)
93 : {
94 11880 : if (aEndIdx < aStartIdx)
95 11880 : return;
96 153015 : for (const_iterator it = begin() + aStartIdx;
97 102010 : it != begin() + aEndIdx; ++it)
98 39125 : delete *it;
99 11880 : this->erase( begin() + aStartIdx, begin() + aEndIdx);
100 : }
101 :
102 1726 : size_t GetPos(Value const& p) const
103 : {
104 1726 : const_iterator const it = std::find(begin(), end(), p);
105 1726 : return it == end() ? SIZE_MAX : it - begin();
106 : }
107 :
108 114 : bool Contains(Value const& p) const
109 114 : { return std::find(begin(), end(), p) != end(); }
110 :
111 : static void dumpAsXml(struct _xmlTextWriter* /*pWriter*/) {};
112 : };
113 :
114 : template<typename Value>
115 21589 : class SwFormatsModifyBase : public SwVectorModifyBase<Value>, public SwFormatsBase
116 : {
117 : protected:
118 21652 : SwFormatsModifyBase(typename SwVectorModifyBase<Value>::DestructorPolicy
119 : policy = SwVectorModifyBase<Value>::DestructorPolicy::FreeElements)
120 21652 : : SwVectorModifyBase<Value>(policy) {}
121 :
122 : public:
123 77453847 : virtual size_t GetFormatCount() const SAL_OVERRIDE
124 77453847 : { return std::vector<Value>::size(); }
125 :
126 74233249 : virtual Value GetFormat(size_t idx) const SAL_OVERRIDE
127 74233249 : { return std::vector<Value>::operator[](idx); }
128 :
129 181 : inline size_t GetPos(const SwFormat *p) const
130 181 : { return SwVectorModifyBase<Value>::GetPos( static_cast<Value>( const_cast<SwFormat*>( p ) ) ); }
131 206 : inline bool Contains(const SwFormat *p) const {
132 206 : Value p2 = dynamic_cast<Value>(const_cast<SwFormat*>(p));
133 206 : return p2 != nullptr && SwVectorModifyBase<Value>::Contains(p2);
134 : }
135 : };
136 :
137 5898 : class SwGrfFormatColls : public SwFormatsModifyBase<SwGrfFormatColl*>
138 : {
139 : public:
140 2958 : SwGrfFormatColls() : SwFormatsModifyBase( DestructorPolicy::KeepElements ) {}
141 : };
142 :
143 : /// Specific frame formats (frames, DrawObjects).
144 28372 : class SW_DLLPUBLIC SwFrameFormats : public SwFormatsModifyBase<SwFrameFormat*>
145 : {
146 : public:
147 : void dumpAsXml(struct _xmlTextWriter* pWriter, const char* pName) const;
148 : };
149 :
150 8856 : class SwCharFormats : public SwFormatsModifyBase<SwCharFormat*>
151 : {
152 : public:
153 : void dumpAsXml(struct _xmlTextWriter* pWriter) const;
154 : };
155 :
156 5898 : class SwTextFormatColls : public SwFormatsModifyBase<SwTextFormatColl*>
157 : {
158 : public:
159 2958 : SwTextFormatColls() : SwFormatsModifyBase( DestructorPolicy::KeepElements ) {}
160 : void dumpAsXml(struct _xmlTextWriter* pWriter) const;
161 : };
162 :
163 : /// Array of Undo-history.
164 8944 : class SW_DLLPUBLIC SwSectionFormats : public SwFormatsModifyBase<SwSectionFormat*>
165 : {
166 : public:
167 : void dumpAsXml(struct _xmlTextWriter* pWriter) const;
168 : };
169 :
170 8856 : class SwFieldTypes : public SwVectorModifyBase<SwFieldType*> {
171 : public:
172 : void dumpAsXml(struct _xmlTextWriter* pWriter) const;
173 : };
174 :
175 8856 : class SwTOXTypes : public SwVectorModifyBase<SwTOXType*> {};
176 :
177 9340 : class SW_DLLPUBLIC SwNumRuleTable : public SwVectorModifyBase<SwNumRule*> {
178 : public:
179 : void dumpAsXml(struct _xmlTextWriter* pWriter) const;
180 : };
181 :
182 : struct CompareSwRedlineTable
183 : {
184 : bool operator()(SwRangeRedline* const &lhs, SwRangeRedline* const &rhs) const;
185 : };
186 2958 : class _SwRedlineTable
187 : : public o3tl::sorted_vector<SwRangeRedline*, CompareSwRedlineTable,
188 : o3tl::find_partialorder_ptrequals>
189 : {
190 : public:
191 : ~_SwRedlineTable();
192 : };
193 :
194 5907 : class SwRedlineTable : private _SwRedlineTable
195 : {
196 : public:
197 0 : bool Contains(const SwRangeRedline* p) const { return find(const_cast<SwRangeRedline* const>(p)) != end(); }
198 : sal_uInt16 GetPos(const SwRangeRedline* p) const;
199 :
200 : bool Insert( SwRangeRedline* p, bool bIns = true );
201 : bool Insert( SwRangeRedline* p, sal_uInt16& rInsPos, bool bIns = true );
202 : bool InsertWithValidRanges( SwRangeRedline* p, sal_uInt16* pInsPos = 0 );
203 :
204 : void Remove( sal_uInt16 nPos );
205 : bool Remove( const SwRangeRedline* p );
206 : void DeleteAndDestroy( sal_uInt16 nPos, sal_uInt16 nLen = 1 );
207 : void DeleteAndDestroyAll();
208 :
209 : void dumpAsXml(struct _xmlTextWriter* pWriter) const;
210 :
211 : sal_uInt16 FindNextOfSeqNo( sal_uInt16 nSttPos ) const;
212 : sal_uInt16 FindPrevOfSeqNo( sal_uInt16 nSttPos ) const;
213 : /** Search next or previous Redline with the same Seq. No.
214 : Search can be restricted via Lookahead.
215 : Using 0 makes search the whole array. */
216 : sal_uInt16 FindNextSeqNo( sal_uInt16 nSeqNo, sal_uInt16 nSttPos,
217 : sal_uInt16 nLookahead = 20 ) const;
218 : sal_uInt16 FindPrevSeqNo( sal_uInt16 nSeqNo, sal_uInt16 nSttPos,
219 : sal_uInt16 nLookahead = 20 ) const;
220 :
221 : /**
222 : Find the redline at the given position.
223 :
224 : @param tableIndex position in SwRedlineTable to start searching at, will be updated with the index of the returned
225 : redline (or the next redline after the given position if not found)
226 : @param next true: redline starts at position and ends after, false: redline starts before position and ends at or after
227 : */
228 : const SwRangeRedline* FindAtPosition( const SwPosition& startPosition, sal_uInt16& tableIndex, bool next = true ) const;
229 :
230 : using _SwRedlineTable::const_iterator;
231 : using _SwRedlineTable::begin;
232 : using _SwRedlineTable::end;
233 : using _SwRedlineTable::size;
234 : using _SwRedlineTable::size_type;
235 : using _SwRedlineTable::operator[];
236 : using _SwRedlineTable::empty;
237 : using _SwRedlineTable::Resort;
238 : };
239 :
240 : /// Table that holds 'extra' redlines, such as 'table row insert\delete', 'paragraph moves' etc...
241 2958 : class SwExtraRedlineTable
242 : {
243 : private:
244 : std::vector<SwExtraRedline*> m_aExtraRedlines;
245 :
246 : public:
247 : ~SwExtraRedlineTable();
248 :
249 : bool Insert( SwExtraRedline* p );
250 :
251 : void DeleteAndDestroy( sal_uInt16 nPos, sal_uInt16 nLen = 1 );
252 : void DeleteAndDestroyAll();
253 :
254 : void dumpAsXml(struct _xmlTextWriter* pWriter) const;
255 :
256 3939 : sal_uInt16 GetSize() const { return m_aExtraRedlines.size(); }
257 36 : SwExtraRedline* GetRedline( sal_uInt16 uIndex ) const { return m_aExtraRedlines.operator[]( uIndex ); }
258 : bool IsEmpty() const { return m_aExtraRedlines.empty(); }
259 :
260 : bool DeleteAllTableRedlines( SwDoc* pDoc, const SwTable& rTable, bool bSaveInUndo, sal_uInt16 nRedlineTypeToDelete );
261 : bool DeleteTableRowRedline ( SwDoc* pDoc, const SwTableLine& rTableLine, bool bSaveInUndo, sal_uInt16 nRedlineTypeToDelete );
262 : bool DeleteTableCellRedline( SwDoc* pDoc, const SwTableBox& rTableBox, bool bSaveInUndo, sal_uInt16 nRedlineTypeToDelete );
263 : };
264 :
265 : typedef std::vector<SwOLENode*> SwOLENodes;
266 :
267 : #endif // INCLUDED_SW_INC_DOCARY_HXX
268 :
269 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|