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_NDHINTS_HXX
20 : #define INCLUDED_SW_INC_NDHINTS_HXX
21 :
22 : #include <tools/mempool.hxx>
23 : #include <o3tl/sorted_vector.hxx>
24 :
25 : #include "swtypes.hxx"
26 :
27 : class SwTextNode;
28 : class SwRegHistory; // Is in RolBck.hxx.
29 : class SwTextAttr;
30 : class SwTextAttrNesting;
31 :
32 : class SfxPoolItem;
33 : class SfxItemSet;
34 : class SwDoc;
35 :
36 : typedef enum {
37 : COPY = int(true),
38 : NEW = int(false),
39 : } CopyOrNew_t;
40 :
41 : /// if COPY then pTextNode must be given!
42 : SwTextAttr * MakeTextAttr(
43 : SwDoc & rDoc,
44 : SfxPoolItem & rNew,
45 : sal_Int32 const nStt,
46 : sal_Int32 const nEnd,
47 : CopyOrNew_t const bIsCopy = NEW,
48 : SwTextNode *const pTextNode = 0 );
49 :
50 : SwTextAttr * MakeTextAttr(
51 : SwDoc & rDoc,
52 : const SfxItemSet & rSet,
53 : sal_Int32 nStt,
54 : sal_Int32 nEnd );
55 :
56 : /// create redline dummy text hint that must not be inserted into hints array
57 : SwTextAttr* MakeRedlineTextAttr(
58 : SwDoc & rDoc,
59 : SfxPoolItem& rAttr );
60 :
61 : /** Class SwpHints is derived indirectly via SwpHts, because only the
62 : class SwTextNode should be allowed to insert and remove attributes.
63 : Other classes like the Frames are given only reading access via
64 : the index-operator.
65 : Size when created is 1 because an array is created only if
66 : also a hint is inserted. */
67 :
68 : /// Class SwpHtStart/End
69 :
70 : struct CompareSwpHtStart
71 : {
72 : bool operator()(SwTextAttr* const lhs, SwTextAttr* const rhs) const;
73 : };
74 145674 : class SwpHtStart : public o3tl::sorted_vector<SwTextAttr*, CompareSwpHtStart,
75 : o3tl::find_partialorder_ptrequals> {};
76 :
77 : struct CompareSwpHtEnd
78 : {
79 : bool operator()(SwTextAttr* const lhs, SwTextAttr* const rhs) const;
80 : };
81 145674 : class SwpHtEnd : public o3tl::sorted_vector<SwTextAttr*, CompareSwpHtEnd,
82 : o3tl::find_partialorder_ptrequals> {};
83 :
84 : /// Class SwpHintsArr
85 :
86 : /// the Hints array
87 145674 : class SwpHintsArray
88 : {
89 :
90 : protected:
91 : SwpHtStart m_HintStarts;
92 : SwpHtEnd m_HintEnds;
93 :
94 : // SAL_MAX_SIZE is used by GetStartOf to return
95 : // failure, so just allow SAL_MAX_SIZE-1 hints
96 : static const size_t MAX_HINTS = SAL_MAX_SIZE-1;
97 :
98 : //FIXME: why are the non-const methods public?
99 : public:
100 : void Insert( const SwTextAttr *pHt );
101 : void DeleteAtPos( const size_t nPosInStart );
102 : void Resort();
103 536 : SwTextAttr * Cut( const size_t nPosInStart )
104 : {
105 536 : SwTextAttr *pHt = GetTextHint(nPosInStart);
106 536 : DeleteAtPos( nPosInStart );
107 536 : return pHt;
108 : }
109 33977999 : const SwTextAttr * GetStart( const size_t nPos ) const
110 : {
111 : assert(nPos < m_HintStarts.size());
112 33977999 : return m_HintStarts[nPos];
113 : }
114 0 : const SwTextAttr * GetEnd( const size_t nPos ) const
115 : {
116 : assert(nPos < m_HintEnds.size());
117 0 : return m_HintEnds[nPos];
118 : }
119 2733879 : SwTextAttr * GetStart( const size_t nPos )
120 : {
121 : assert(nPos < m_HintStarts.size());
122 2733879 : return m_HintStarts[nPos];
123 : }
124 573086 : SwTextAttr * GetEnd( const size_t nPos )
125 : {
126 : assert(nPos < m_HintEnds.size());
127 573086 : return m_HintEnds[nPos];
128 : }
129 :
130 474035 : size_t GetEndCount() const { return m_HintEnds.size(); }
131 32980908 : size_t GetStartCount() const { return m_HintStarts.size(); }
132 :
133 41267 : size_t GetStartOf( const SwTextAttr *pHt ) const
134 : {
135 : SwpHtStart::const_iterator const it =
136 41267 : m_HintStarts.find(const_cast<SwTextAttr*>(pHt));
137 41267 : if ( it == m_HintStarts.end() )
138 : {
139 0 : return SAL_MAX_SIZE;
140 : }
141 41267 : return it - m_HintStarts.begin();
142 : }
143 :
144 : bool Contains( const SwTextAttr *pHt ) const;
145 :
146 0 : const SwTextAttr * GetTextHint( const size_t nIdx ) const
147 0 : { return GetStart(nIdx); }
148 2381474 : SwTextAttr * GetTextHint( const size_t nIdx )
149 2381474 : { return GetStart(nIdx); }
150 33898861 : const SwTextAttr * operator[]( const size_t nIdx ) const
151 33898861 : { return GetStart(nIdx); }
152 32527146 : size_t Count() const { return GetStartCount(); }
153 :
154 : #ifdef DBG_UTIL
155 : bool Check(bool) const;
156 : #endif
157 : };
158 :
159 : // Class SwpHints
160 :
161 : /// public interface
162 72830 : class SwpHints : public SwpHintsArray
163 : {
164 : private:
165 : SwRegHistory* m_pHistory; ///< for Undo
166 :
167 : bool m_bFontChange : 1; ///< font change
168 : /// true: the Node is in Split and Frames are moved
169 : bool m_bInSplitNode : 1;
170 : /// m_bHasHiddenParaField is invalid, call CalcHiddenParaField()
171 : bool m_bCalcHiddenParaField : 1;
172 : bool m_bHasHiddenParaField : 1; ///< HiddenParaField
173 : bool m_bFootnote : 1; ///< footnotes
174 : bool m_bDDEFields : 1; ///< the TextNode has DDE fields
175 :
176 : /// records a new attibute in m_pHistory.
177 : void NoteInHistory( SwTextAttr *pAttr, const bool bNew = false );
178 :
179 : void CalcFlags( );
180 :
181 : /** Delete methods may only be called by the TextNode!
182 : Because the TextNode also guarantees removal of the Character for
183 : attributes without an end. */
184 : friend class SwTextNode;
185 : void DeleteAtPos( const size_t nPos );
186 : /// Delete the given Hint. The Hint must actually be in the array!
187 : void Delete( SwTextAttr* pTextHt );
188 :
189 5 : void SetInSplitNode(bool bInSplit) { m_bInSplitNode = bInSplit; }
190 0 : void SetCalcHiddenParaField() { m_bCalcHiddenParaField = true; }
191 1239 : void SetHiddenParaField( const bool bNew ) { m_bHasHiddenParaField = bNew; }
192 199133 : bool HasHiddenParaField() const
193 : {
194 199133 : if ( m_bCalcHiddenParaField )
195 : {
196 0 : (const_cast<SwpHints*>(this))->CalcHiddenParaField();
197 : }
198 199133 : return m_bHasHiddenParaField;
199 : }
200 :
201 : void InsertNesting(SwTextAttrNesting & rNewHint);
202 : bool TryInsertNesting(SwTextNode & rNode, SwTextAttrNesting & rNewHint);
203 : void BuildPortions( SwTextNode& rNode, SwTextAttr& rNewHint,
204 : const SetAttrMode nMode );
205 : bool MergePortions( SwTextNode& rNode );
206 :
207 : public:
208 : SwpHints();
209 :
210 185617 : bool CanBeDeleted() const { return !Count(); }
211 :
212 : /// register a History, which receives all attribute changes (for Undo)
213 5859 : void Register( SwRegHistory* pHist ) { m_pHistory = pHist; }
214 : /// deregister the currently registered History
215 3201 : void DeRegister() { Register(0); }
216 120 : SwRegHistory* GetHistory() const { return m_pHistory; }
217 :
218 : /// try to insert the hint
219 : /// @return true iff hint successfully inserted
220 : bool TryInsertHint( SwTextAttr * const pHint, SwTextNode & rNode,
221 : const SetAttrMode nMode = SetAttrMode::DEFAULT );
222 :
223 0 : bool HasFootnote() const { return m_bFootnote; }
224 1153 : bool IsInSplitNode() const { return m_bInSplitNode; }
225 :
226 : /// calc current value of m_bHasHiddenParaField, returns true iff changed
227 : bool CalcHiddenParaField();
228 :
229 145674 : DECL_FIXEDMEMPOOL_NEWDEL(SwpHints)
230 : };
231 :
232 : #endif
233 :
234 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|