bump product version to 4.1.6.2
[LibreOffice.git] / sw / inc / ndhints.hxx
blobd8b611535cbc11058e0e8cb76f4cc5f0944f9985
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 _NDHINTS_HXX
20 #define _NDHINTS_HXX
23 #include <tools/mempool.hxx>
24 #include <o3tl/sorted_vector.hxx>
26 #include "swtypes.hxx"
28 class SwTxtNode;
29 class SwRegHistory; // Is in RolBck.hxx.
30 class SwTxtAttr;
31 class SwTxtAttrNesting;
33 class SfxPoolItem;
34 class SfxItemSet;
35 class SwDoc;
37 typedef enum {
38 COPY = true,
39 NEW = false,
40 } CopyOrNew_t;
42 /// if COPY then pTxtNode must be given!
43 SW_DLLPRIVATE SwTxtAttr *
44 MakeTxtAttr( SwDoc & rDoc, SfxPoolItem & rNew,
45 xub_StrLen const nStt, xub_StrLen const nEnd,
46 CopyOrNew_t const bIsCopy = NEW, SwTxtNode *const pTxtNode = 0);
47 SW_DLLPRIVATE SwTxtAttr *
48 MakeTxtAttr( SwDoc & rDoc, const SfxItemSet & rSet,
49 xub_StrLen nStt, xub_StrLen nEnd );
51 /// create redline dummy text hint that must not be inserted into hints array
52 SW_DLLPRIVATE SwTxtAttr*
53 MakeRedlineTxtAttr( SwDoc & rDoc, SfxPoolItem& rAttr );
56 /** Class SwpHints is derived indirectly via SwpHts, because only the
57 class SwTxtNode should be allowed to insert and remove attributes.
58 Other classes like the Frames are given only reading access via
59 the index-operator.
60 Size when created is 1 because an array is created only if
61 also a hint is inserted. */
63 /// Class SwpHtStart/End
65 struct CompareSwpHtStart
67 bool operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const;
69 class SwpHtStart : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtStart,
70 o3tl::find_partialorder_ptrequals> {};
72 struct CompareSwpHtEnd
74 bool operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const;
76 class SwpHtEnd : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtEnd,
77 o3tl::find_partialorder_ptrequals> {};
79 /// Class SwpHintsArr
82 /// the Hints array
83 class SwpHintsArray
86 protected:
87 SwpHtStart m_HintStarts;
88 SwpHtEnd m_HintEnds;
90 //FIXME: why are the non-const methods public?
91 public:
92 void Insert( const SwTxtAttr *pHt );
93 void DeleteAtPos( const sal_uInt16 nPosInStart );
94 void Resort();
95 SwTxtAttr * Cut( const sal_uInt16 nPosInStart );
97 inline const SwTxtAttr * GetStart( const sal_uInt16 nPos ) const
98 { return m_HintStarts[nPos]; }
99 inline const SwTxtAttr * GetEnd ( const sal_uInt16 nPos ) const
100 { return m_HintEnds [nPos]; }
101 inline SwTxtAttr * GetStart( const sal_uInt16 nPos )
102 { return m_HintStarts[nPos]; }
103 inline SwTxtAttr * GetEnd ( const sal_uInt16 nPos )
104 { return m_HintEnds [nPos]; }
106 inline sal_uInt16 GetEndCount() const { return m_HintEnds .size(); }
107 inline sal_uInt16 GetStartCount() const { return m_HintStarts.size(); }
109 inline sal_uInt16 GetStartOf( const SwTxtAttr *pHt ) const;
110 sal_uInt16 GetPos( const SwTxtAttr *pHt ) const;
112 inline SwTxtAttr * GetTextHint( const sal_uInt16 nIdx )
113 { return GetStart(nIdx); }
114 inline const SwTxtAttr * operator[]( const sal_uInt16 nIdx ) const
115 { return m_HintStarts[nIdx]; }
116 inline sal_uInt16 Count() const { return m_HintStarts.size(); }
118 #ifdef DBG_UTIL
119 bool Check(bool) const;
120 #endif
124 // Class SwpHints
127 /// public interface
128 class SwpHints : public SwpHintsArray
130 private:
131 SwRegHistory* m_pHistory; ///< for Undo
133 bool m_bFontChange : 1; ///< font change
134 /// true: the Node is in Split and Frames are moved
135 bool m_bInSplitNode : 1;
136 /// m_bHasHiddenParaField is invalid, call CalcHiddenParaField()
137 bool m_bCalcHiddenParaField : 1;
138 bool m_bHasHiddenParaField : 1; ///< HiddenParaFld
139 bool m_bFootnote : 1; ///< footnotes
140 bool m_bDDEFields : 1; ///< the TextNode has DDE fields
142 /// records a new attibute in m_pHistory.
143 void NoteInHistory( SwTxtAttr *pAttr, const bool bNew = false );
145 void CalcFlags( );
147 /** Delete methods may only be called by the TextNode!
148 Because the TextNode also guarantees removal of the Character for
149 attributes without an end. */
150 friend class SwTxtNode;
151 void DeleteAtPos( const sal_uInt16 nPos );
152 /// Delete the given Hint. The Hint must actually be in the array!
153 void Delete( SwTxtAttr* pTxtHt );
155 inline void SetInSplitNode(bool bInSplit) { m_bInSplitNode = bInSplit; }
156 inline void SetCalcHiddenParaField() { m_bCalcHiddenParaField = true; }
157 inline void SetHiddenParaField( const bool bNew )
158 { m_bHasHiddenParaField = bNew; }
159 inline bool HasHiddenParaField() const
161 if ( m_bCalcHiddenParaField )
163 (const_cast<SwpHints*>(this))->CalcHiddenParaField();
165 return m_bHasHiddenParaField;
168 void InsertNesting(SwTxtAttrNesting & rNewHint);
169 bool TryInsertNesting(SwTxtNode & rNode, SwTxtAttrNesting & rNewHint);
170 void BuildPortions( SwTxtNode& rNode, SwTxtAttr& rNewHint,
171 const SetAttrMode nMode );
172 bool MergePortions( SwTxtNode& rNode );
174 public:
175 SwpHints();
177 inline bool CanBeDeleted() const { return !Count(); }
179 /// register a History, which receives all attribute changes (for Undo)
180 void Register( SwRegHistory* pHist ) { m_pHistory = pHist; }
181 /// deregister the currently registered History
182 void DeRegister() { Register(0); }
183 SwRegHistory* GetHistory() const { return m_pHistory; }
185 /// try to insert the hint
186 /// @return true iff hint successfully inserted
187 bool TryInsertHint( SwTxtAttr * const pHint, SwTxtNode & rNode,
188 const SetAttrMode nMode = nsSetAttrMode::SETATTR_DEFAULT );
190 inline bool HasFtn() const { return m_bFootnote; }
191 inline bool IsInSplitNode() const { return m_bInSplitNode; }
193 /// calc current value of m_bHasHiddenParaField, returns true iff changed
194 bool CalcHiddenParaField();
196 DECL_FIXEDMEMPOOL_NEWDEL(SwpHints)
199 /// Output operator for text hints.
200 SvStream &operator<<(SvStream &aS, const SwpHints &rHints); //$ ostream
203 /// Inline Implementations
206 inline sal_uInt16 SwpHintsArray::GetStartOf( const SwTxtAttr *pHt ) const
208 SwpHtStart::const_iterator const it =
209 m_HintStarts.find(const_cast<SwTxtAttr*>(pHt));
210 if ( it == m_HintStarts.end() )
212 return USHRT_MAX;
214 return it - m_HintStarts.begin();
217 inline SwTxtAttr *SwpHintsArray::Cut( const sal_uInt16 nPosInStart )
219 SwTxtAttr *pHt = GetTextHint(nPosInStart);
220 DeleteAtPos( nPosInStart );
221 return pHt;
225 #endif
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */