Branch libreoffice-5-0-4
[LibreOffice.git] / sw / inc / docary.hxx
blob2d2871f37df5710aaddb0c8b713ba3f9139c06b4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
19 #ifndef INCLUDED_SW_INC_DOCARY_HXX
20 #define INCLUDED_SW_INC_DOCARY_HXX
22 #include <com/sun/star/i18n/ForbiddenCharacters.hpp>
23 #include <vector>
24 #include <set>
25 #include <algorithm>
26 #include <o3tl/sorted_vector.hxx>
28 class SwRangeRedline;
29 class SwExtraRedline;
30 class SwUnoCrsr;
31 class SwOLENode;
32 class SwTable;
33 class SwTableLine;
34 class SwTableBox;
36 namespace com { namespace sun { namespace star { namespace i18n {
37 struct ForbiddenCharacters; ///< comes from the I18N UNO interface
38 }}}}
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>
50 /** provides some methods for generic operations on lists that contain
51 SwFormat* subclasses. */
52 class SwFormatsBase
54 public:
55 virtual size_t GetFormatCount() const = 0;
56 virtual SwFormat* GetFormat(size_t idx) const = 0;
57 virtual ~SwFormatsBase() {};
60 template<typename Value>
61 class SwVectorModifyBase : public std::vector<Value>
63 public:
64 typedef typename std::vector<Value>::const_iterator const_iterator;
66 protected:
67 enum class DestructorPolicy {
68 KeepElements,
69 FreeElements,
72 private:
73 const DestructorPolicy mPolicy;
75 protected:
76 // default destructor deletes all contained elements
77 SwVectorModifyBase(DestructorPolicy policy = DestructorPolicy::FreeElements)
78 : mPolicy(policy) {}
80 public:
81 using std::vector<Value>::begin;
82 using std::vector<Value>::end;
84 // free any remaining child objects based on mPolicy
85 virtual ~SwVectorModifyBase()
87 if (mPolicy == DestructorPolicy::FreeElements)
88 for(const_iterator it = begin(); it != end(); ++it)
89 delete *it;
92 void DeleteAndDestroy(int aStartIdx, int aEndIdx)
94 if (aEndIdx < aStartIdx)
95 return;
96 for (const_iterator it = begin() + aStartIdx;
97 it != begin() + aEndIdx; ++it)
98 delete *it;
99 this->erase( begin() + aStartIdx, begin() + aEndIdx);
102 size_t GetPos(Value const& p) const
104 const_iterator const it = std::find(begin(), end(), p);
105 return it == end() ? SIZE_MAX : it - begin();
108 bool Contains(Value const& p) const
109 { return std::find(begin(), end(), p) != end(); }
111 static void dumpAsXml(struct _xmlTextWriter* /*pWriter*/) {};
114 template<typename Value>
115 class SwFormatsModifyBase : public SwVectorModifyBase<Value>, public SwFormatsBase
117 protected:
118 SwFormatsModifyBase(typename SwVectorModifyBase<Value>::DestructorPolicy
119 policy = SwVectorModifyBase<Value>::DestructorPolicy::FreeElements)
120 : SwVectorModifyBase<Value>(policy) {}
122 public:
123 virtual size_t GetFormatCount() const SAL_OVERRIDE
124 { return std::vector<Value>::size(); }
126 virtual Value GetFormat(size_t idx) const SAL_OVERRIDE
127 { return std::vector<Value>::operator[](idx); }
129 inline size_t GetPos(const SwFormat *p) const
130 { return SwVectorModifyBase<Value>::GetPos( static_cast<Value>( const_cast<SwFormat*>( p ) ) ); }
131 inline bool Contains(const SwFormat *p) const {
132 Value p2 = dynamic_cast<Value>(const_cast<SwFormat*>(p));
133 return p2 != nullptr && SwVectorModifyBase<Value>::Contains(p2);
137 class SwGrfFormatColls : public SwFormatsModifyBase<SwGrfFormatColl*>
139 public:
140 SwGrfFormatColls() : SwFormatsModifyBase( DestructorPolicy::KeepElements ) {}
143 /// Specific frame formats (frames, DrawObjects).
144 class SW_DLLPUBLIC SwFrameFormats : public SwFormatsModifyBase<SwFrameFormat*>
146 public:
147 void dumpAsXml(struct _xmlTextWriter* pWriter, const char* pName) const;
150 class SwCharFormats : public SwFormatsModifyBase<SwCharFormat*>
152 public:
153 void dumpAsXml(struct _xmlTextWriter* pWriter) const;
156 class SwTextFormatColls : public SwFormatsModifyBase<SwTextFormatColl*>
158 public:
159 SwTextFormatColls() : SwFormatsModifyBase( DestructorPolicy::KeepElements ) {}
160 void dumpAsXml(struct _xmlTextWriter* pWriter) const;
163 /// Array of Undo-history.
164 class SW_DLLPUBLIC SwSectionFormats : public SwFormatsModifyBase<SwSectionFormat*>
166 public:
167 void dumpAsXml(struct _xmlTextWriter* pWriter) const;
170 class SwFieldTypes : public SwVectorModifyBase<SwFieldType*> {
171 public:
172 void dumpAsXml(struct _xmlTextWriter* pWriter) const;
175 class SwTOXTypes : public SwVectorModifyBase<SwTOXType*> {};
177 class SW_DLLPUBLIC SwNumRuleTable : public SwVectorModifyBase<SwNumRule*> {
178 public:
179 void dumpAsXml(struct _xmlTextWriter* pWriter) const;
182 struct CompareSwRedlineTable
184 bool operator()(SwRangeRedline* const &lhs, SwRangeRedline* const &rhs) const;
186 class _SwRedlineTable
187 : public o3tl::sorted_vector<SwRangeRedline*, CompareSwRedlineTable,
188 o3tl::find_partialorder_ptrequals>
190 public:
191 ~_SwRedlineTable();
194 class SwRedlineTable : private _SwRedlineTable
196 public:
197 bool Contains(const SwRangeRedline* p) const { return find(const_cast<SwRangeRedline* const>(p)) != end(); }
198 sal_uInt16 GetPos(const SwRangeRedline* p) const;
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 );
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();
209 void dumpAsXml(struct _xmlTextWriter* pWriter) const;
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;
222 Find the redline at the given position.
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
228 const SwRangeRedline* FindAtPosition( const SwPosition& startPosition, sal_uInt16& tableIndex, bool next = true ) const;
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;
240 /// Table that holds 'extra' redlines, such as 'table row insert\delete', 'paragraph moves' etc...
241 class SwExtraRedlineTable
243 private:
244 std::vector<SwExtraRedline*> m_aExtraRedlines;
246 public:
247 ~SwExtraRedlineTable();
249 bool Insert( SwExtraRedline* p );
251 void DeleteAndDestroy( sal_uInt16 nPos, sal_uInt16 nLen = 1 );
252 void DeleteAndDestroyAll();
254 void dumpAsXml(struct _xmlTextWriter* pWriter) const;
256 sal_uInt16 GetSize() const { return m_aExtraRedlines.size(); }
257 SwExtraRedline* GetRedline( sal_uInt16 uIndex ) const { return m_aExtraRedlines.operator[]( uIndex ); }
258 bool IsEmpty() const { return m_aExtraRedlines.empty(); }
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 );
265 class SwUnoCrsrTable : public std::set<SwUnoCrsr*> {
266 public:
267 /// the destructor will free all objects still in the set
268 ~SwUnoCrsrTable();
271 typedef std::vector<SwOLENode*> SwOLENodes;
273 #endif // INCLUDED_SW_INC_DOCARY_HXX
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */