Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / sw / inc / ndhints.hxx
blobec712316751ed8a6d1e2c2a9c9a54a58248800ab
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_NDHINTS_HXX
20 #define INCLUDED_SW_INC_NDHINTS_HXX
22 #include <tools/mempool.hxx>
23 #include <o3tl/sorted_vector.hxx>
25 #include "swtypes.hxx"
27 class SwTextNode;
28 class SwRegHistory; // Is in RolBck.hxx.
29 class SwTextAttr;
30 class SwTextAttrNesting;
32 class SfxPoolItem;
33 class SfxItemSet;
34 class SwDoc;
36 enum class CopyOrNewType { Copy, New };
38 /// if COPY then pTextNode must be given!
39 SwTextAttr * MakeTextAttr(
40 SwDoc & rDoc,
41 SfxPoolItem & rNew,
42 sal_Int32 const nStt,
43 sal_Int32 const nEnd,
44 CopyOrNewType const bIsCopy = CopyOrNewType::New,
45 SwTextNode *const pTextNode = nullptr );
47 SwTextAttr * MakeTextAttr(
48 SwDoc & rDoc,
49 const SfxItemSet & rSet,
50 sal_Int32 nStt,
51 sal_Int32 nEnd );
53 /// create redline dummy text hint that must not be inserted into hints array
54 SwTextAttr* MakeRedlineTextAttr(
55 SwDoc & rDoc,
56 SfxPoolItem& rAttr );
59 /// SwTextAttr's, sorted by start
60 struct CompareSwpHtStart
62 bool operator()(SwTextAttr* const lhs, SwTextAttr* const rhs) const;
64 class SwpHtStart : public o3tl::sorted_vector<SwTextAttr*, CompareSwpHtStart,
65 o3tl::find_partialorder_ptrequals> {};
67 /// SwTextAttr's, sorted by end
68 struct CompareSwpHtEnd
70 bool operator()(SwTextAttr* const lhs, SwTextAttr* const rhs) const;
72 class SwpHtEnd : public o3tl::sorted_vector<SwTextAttr*, CompareSwpHtEnd,
73 o3tl::find_partialorder_ptrequals> {};
76 /// An SwTextAttr container, stores all directly formatted text portions for a text node.
77 class SwpHints
79 private:
80 // SAL_MAX_SIZE is used by GetStartOf to return
81 // failure, so just allow SAL_MAX_SIZE-1 hints
82 static const size_t MAX_HINTS = SAL_MAX_SIZE-1;
84 SwpHtStart m_HintsByStart;
85 SwpHtEnd m_HintsByEnd;
87 SwRegHistory* m_pHistory; ///< for Undo
89 /// true: the Node is in Split and Frames are moved
90 bool m_bInSplitNode : 1;
91 /// m_bHasHiddenParaField is invalid, call CalcHiddenParaField()
92 bool m_bCalcHiddenParaField : 1;
93 bool m_bHasHiddenParaField : 1; ///< HiddenParaField
94 bool m_bFootnote : 1; ///< footnotes
95 bool m_bDDEFields : 1; ///< the TextNode has DDE fields
97 /// records a new attribute in m_pHistory.
98 void NoteInHistory( SwTextAttr *pAttr, const bool bNew = false );
100 void CalcFlags( );
102 /** Delete methods may only be called by the TextNode!
103 Because the TextNode also guarantees removal of the Character for
104 attributes without an end. */
105 friend class SwTextNode;
106 void DeleteAtPos( size_t nPos );
107 /// Delete the given Hint. The Hint must actually be in the array!
108 void Delete( SwTextAttr* pTextHt );
110 void SetInSplitNode(bool bInSplit) { m_bInSplitNode = bInSplit; }
111 void SetCalcHiddenParaField() { m_bCalcHiddenParaField = true; }
112 void SetHiddenParaField( const bool bNew ) { m_bHasHiddenParaField = bNew; }
113 bool HasHiddenParaField() const
115 if ( m_bCalcHiddenParaField )
117 (const_cast<SwpHints*>(this))->CalcHiddenParaField();
119 return m_bHasHiddenParaField;
122 void InsertNesting(SwTextAttrNesting & rNewHint);
123 bool TryInsertNesting(SwTextNode & rNode, SwTextAttrNesting & rNewHint);
124 void BuildPortions( SwTextNode& rNode, SwTextAttr& rNewHint,
125 const SetAttrMode nMode );
126 bool MergePortions( SwTextNode& rNode );
128 void Insert( const SwTextAttr *pHt );
129 void Resort();
131 size_t GetIndexOf( const SwTextAttr *pHt ) const
133 SwpHtStart::const_iterator const it =
134 m_HintsByStart.find(const_cast<SwTextAttr*>(pHt));
135 if ( it == m_HintsByStart.end() )
137 return SAL_MAX_SIZE;
139 return it - m_HintsByStart.begin();
142 #ifdef DBG_UTIL
143 bool Check(bool) const;
144 #endif
146 public:
147 SwpHints();
149 size_t Count() const { return m_HintsByStart.size(); }
150 bool Contains( const SwTextAttr *pHt ) const;
151 SwTextAttr * Get( size_t nPos ) const
153 return m_HintsByStart[nPos];
155 SwTextAttr * GetSortedByEnd( size_t nPos ) const
157 return m_HintsByEnd[nPos];
159 SwTextAttr * Cut( const size_t nPosInStart )
161 SwTextAttr *pHt = m_HintsByStart[nPosInStart];
162 DeleteAtPos( nPosInStart );
163 return pHt;
166 bool CanBeDeleted() const { return m_HintsByStart.empty(); }
168 /// register a History, which receives all attribute changes (for Undo)
169 void Register( SwRegHistory* pHist ) { m_pHistory = pHist; }
170 /// deregister the currently registered History
171 void DeRegister() { Register(nullptr); }
172 SwRegHistory* GetHistory() const { return m_pHistory; }
174 /// try to insert the hint
175 /// @return true iff hint successfully inserted
176 bool TryInsertHint( SwTextAttr * const pHint, SwTextNode & rNode,
177 const SetAttrMode nMode = SetAttrMode::DEFAULT );
179 bool HasFootnote() const { return m_bFootnote; }
180 bool IsInSplitNode() const { return m_bInSplitNode; }
182 /// calc current value of m_bHasHiddenParaField, returns true iff changed
183 bool CalcHiddenParaField();
185 DECL_FIXEDMEMPOOL_NEWDEL(SwpHints)
188 #endif
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */