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 SwTxtNode;
28 : class SwRegHistory; // Is in RolBck.hxx.
29 : class SwTxtAttr;
30 : class SwTxtAttrNesting;
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 pTxtNode must be given!
42 : SwTxtAttr * MakeTxtAttr(
43 : SwDoc & rDoc,
44 : SfxPoolItem & rNew,
45 : sal_Int32 const nStt,
46 : sal_Int32 const nEnd,
47 : CopyOrNew_t const bIsCopy = NEW,
48 : SwTxtNode *const pTxtNode = 0 );
49 :
50 : SwTxtAttr * MakeTxtAttr(
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 : SwTxtAttr* MakeRedlineTxtAttr(
58 : SwDoc & rDoc,
59 : SfxPoolItem& rAttr );
60 :
61 : /** Class SwpHints is derived indirectly via SwpHts, because only the
62 : class SwTxtNode 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()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const;
73 : };
74 258440 : class SwpHtStart : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtStart,
75 : o3tl::find_partialorder_ptrequals> {};
76 :
77 : struct CompareSwpHtEnd
78 : {
79 : bool operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const;
80 : };
81 258440 : class SwpHtEnd : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtEnd,
82 : o3tl::find_partialorder_ptrequals> {};
83 :
84 : /// Class SwpHintsArr
85 :
86 : /// the Hints array
87 258440 : 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 SwTxtAttr *pHt );
101 : void DeleteAtPos( const size_t nPosInStart );
102 : void Resort();
103 : SwTxtAttr * Cut( const size_t nPosInStart );
104 :
105 149152 : inline const SwTxtAttr * GetStart( const size_t nPos ) const
106 149152 : { return m_HintStarts[nPos]; }
107 0 : inline const SwTxtAttr * GetEnd( const size_t nPos ) const
108 0 : { return m_HintEnds [nPos]; }
109 4899651 : inline SwTxtAttr * GetStart( const size_t nPos )
110 4899651 : { return m_HintStarts[nPos]; }
111 684313 : inline SwTxtAttr * GetEnd( const size_t nPos )
112 684313 : { return m_HintEnds [nPos]; }
113 :
114 718925 : inline size_t GetEndCount() const { return m_HintEnds.size(); }
115 666217 : inline size_t GetStartCount() const { return m_HintStarts.size(); }
116 :
117 : inline size_t GetStartOf( const SwTxtAttr *pHt ) const;
118 : bool Contains( const SwTxtAttr *pHt ) const;
119 :
120 0 : inline const SwTxtAttr * GetTextHint( const size_t nIdx ) const
121 0 : { return GetStart(nIdx); }
122 4497770 : inline SwTxtAttr * GetTextHint( const size_t nIdx )
123 4497770 : { return GetStart(nIdx); }
124 2628939 : inline const SwTxtAttr * operator[]( const size_t nIdx ) const
125 2628939 : { return m_HintStarts[nIdx]; }
126 5587070 : inline size_t Count() const { return m_HintStarts.size(); }
127 :
128 : #ifdef DBG_UTIL
129 : bool Check(bool) const;
130 : #endif
131 : };
132 :
133 : // Class SwpHints
134 :
135 : /// public interface
136 129210 : class SwpHints : public SwpHintsArray
137 : {
138 : private:
139 : SwRegHistory* m_pHistory; ///< for Undo
140 :
141 : bool m_bFontChange : 1; ///< font change
142 : /// true: the Node is in Split and Frames are moved
143 : bool m_bInSplitNode : 1;
144 : /// m_bHasHiddenParaField is invalid, call CalcHiddenParaField()
145 : bool m_bCalcHiddenParaField : 1;
146 : bool m_bHasHiddenParaField : 1; ///< HiddenParaFld
147 : bool m_bFootnote : 1; ///< footnotes
148 : bool m_bDDEFields : 1; ///< the TextNode has DDE fields
149 :
150 : /// records a new attibute in m_pHistory.
151 : void NoteInHistory( SwTxtAttr *pAttr, const bool bNew = false );
152 :
153 : void CalcFlags( );
154 :
155 : /** Delete methods may only be called by the TextNode!
156 : Because the TextNode also guarantees removal of the Character for
157 : attributes without an end. */
158 : friend class SwTxtNode;
159 : void DeleteAtPos( const size_t nPos );
160 : /// Delete the given Hint. The Hint must actually be in the array!
161 : void Delete( SwTxtAttr* pTxtHt );
162 :
163 4 : inline void SetInSplitNode(bool bInSplit) { m_bInSplitNode = bInSplit; }
164 0 : inline void SetCalcHiddenParaField() { m_bCalcHiddenParaField = true; }
165 1274 : inline void SetHiddenParaField( const bool bNew )
166 1274 : { m_bHasHiddenParaField = bNew; }
167 365081 : inline bool HasHiddenParaField() const
168 : {
169 365081 : if ( m_bCalcHiddenParaField )
170 : {
171 0 : (const_cast<SwpHints*>(this))->CalcHiddenParaField();
172 : }
173 365081 : return m_bHasHiddenParaField;
174 : }
175 :
176 : void InsertNesting(SwTxtAttrNesting & rNewHint);
177 : bool TryInsertNesting(SwTxtNode & rNode, SwTxtAttrNesting & rNewHint);
178 : void BuildPortions( SwTxtNode& rNode, SwTxtAttr& rNewHint,
179 : const SetAttrMode nMode );
180 : bool MergePortions( SwTxtNode& rNode );
181 :
182 : public:
183 : SwpHints();
184 :
185 348356 : inline bool CanBeDeleted() const { return !Count(); }
186 :
187 : /// register a History, which receives all attribute changes (for Undo)
188 11854 : void Register( SwRegHistory* pHist ) { m_pHistory = pHist; }
189 : /// deregister the currently registered History
190 6470 : void DeRegister() { Register(0); }
191 232 : SwRegHistory* GetHistory() const { return m_pHistory; }
192 :
193 : /// try to insert the hint
194 : /// @return true iff hint successfully inserted
195 : bool TryInsertHint( SwTxtAttr * const pHint, SwTxtNode & rNode,
196 : const SetAttrMode nMode = nsSetAttrMode::SETATTR_DEFAULT );
197 :
198 0 : inline bool HasFtn() const { return m_bFootnote; }
199 2190 : inline bool IsInSplitNode() const { return m_bInSplitNode; }
200 :
201 : /// calc current value of m_bHasHiddenParaField, returns true iff changed
202 : bool CalcHiddenParaField();
203 :
204 258440 : DECL_FIXEDMEMPOOL_NEWDEL(SwpHints)
205 : };
206 :
207 : /// Inline Implementations
208 :
209 77270 : inline size_t SwpHintsArray::GetStartOf( const SwTxtAttr *pHt ) const
210 : {
211 : SwpHtStart::const_iterator const it =
212 77270 : m_HintStarts.find(const_cast<SwTxtAttr*>(pHt));
213 77270 : if ( it == m_HintStarts.end() )
214 : {
215 0 : return SAL_MAX_SIZE;
216 : }
217 77270 : return it - m_HintStarts.begin();
218 : }
219 :
220 1078 : inline SwTxtAttr *SwpHintsArray::Cut( const size_t nPosInStart )
221 : {
222 1078 : SwTxtAttr *pHt = GetTextHint(nPosInStart);
223 1078 : DeleteAtPos( nPosInStart );
224 1078 : return pHt;
225 : }
226 :
227 : #endif
228 :
229 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|