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 0 : 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 0 : class SwpHtEnd : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtEnd,
82 : o3tl::find_partialorder_ptrequals> {};
83 :
84 : /// Class SwpHintsArr
85 :
86 : /// the Hints array
87 0 : class SwpHintsArray
88 : {
89 :
90 : protected:
91 : SwpHtStart m_HintStarts;
92 : SwpHtEnd m_HintEnds;
93 :
94 : //FIXME: why are the non-const methods public?
95 : public:
96 : void Insert( const SwTxtAttr *pHt );
97 : void DeleteAtPos( const sal_uInt16 nPosInStart );
98 : void Resort();
99 : SwTxtAttr * Cut( const sal_uInt16 nPosInStart );
100 :
101 0 : inline const SwTxtAttr * GetStart( const sal_uInt16 nPos ) const
102 0 : { return m_HintStarts[nPos]; }
103 0 : inline const SwTxtAttr * GetEnd ( const sal_uInt16 nPos ) const
104 0 : { return m_HintEnds [nPos]; }
105 0 : inline SwTxtAttr * GetStart( const sal_uInt16 nPos )
106 0 : { return m_HintStarts[nPos]; }
107 0 : inline SwTxtAttr * GetEnd ( const sal_uInt16 nPos )
108 0 : { return m_HintEnds [nPos]; }
109 :
110 0 : inline sal_uInt16 GetEndCount() const { return m_HintEnds .size(); }
111 0 : inline sal_uInt16 GetStartCount() const { return m_HintStarts.size(); }
112 :
113 : inline sal_uInt16 GetStartOf( const SwTxtAttr *pHt ) const;
114 : sal_uInt16 GetPos( const SwTxtAttr *pHt ) const;
115 :
116 0 : inline SwTxtAttr * GetTextHint( const sal_uInt16 nIdx )
117 0 : { return GetStart(nIdx); }
118 0 : inline const SwTxtAttr * operator[]( const sal_uInt16 nIdx ) const
119 0 : { return m_HintStarts[nIdx]; }
120 0 : inline sal_uInt16 Count() const { return m_HintStarts.size(); }
121 :
122 : #ifdef DBG_UTIL
123 : bool Check(bool) const;
124 : #endif
125 : };
126 :
127 : // Class SwpHints
128 :
129 : /// public interface
130 0 : class SwpHints : public SwpHintsArray
131 : {
132 : private:
133 : SwRegHistory* m_pHistory; ///< for Undo
134 :
135 : bool m_bFontChange : 1; ///< font change
136 : /// true: the Node is in Split and Frames are moved
137 : bool m_bInSplitNode : 1;
138 : /// m_bHasHiddenParaField is invalid, call CalcHiddenParaField()
139 : bool m_bCalcHiddenParaField : 1;
140 : bool m_bHasHiddenParaField : 1; ///< HiddenParaFld
141 : bool m_bFootnote : 1; ///< footnotes
142 : bool m_bDDEFields : 1; ///< the TextNode has DDE fields
143 :
144 : /// records a new attibute in m_pHistory.
145 : void NoteInHistory( SwTxtAttr *pAttr, const bool bNew = false );
146 :
147 : void CalcFlags( );
148 :
149 : /** Delete methods may only be called by the TextNode!
150 : Because the TextNode also guarantees removal of the Character for
151 : attributes without an end. */
152 : friend class SwTxtNode;
153 : void DeleteAtPos( const sal_uInt16 nPos );
154 : /// Delete the given Hint. The Hint must actually be in the array!
155 : void Delete( SwTxtAttr* pTxtHt );
156 :
157 0 : inline void SetInSplitNode(bool bInSplit) { m_bInSplitNode = bInSplit; }
158 0 : inline void SetCalcHiddenParaField() { m_bCalcHiddenParaField = true; }
159 0 : inline void SetHiddenParaField( const bool bNew )
160 0 : { m_bHasHiddenParaField = bNew; }
161 0 : inline bool HasHiddenParaField() const
162 : {
163 0 : if ( m_bCalcHiddenParaField )
164 : {
165 0 : (const_cast<SwpHints*>(this))->CalcHiddenParaField();
166 : }
167 0 : return m_bHasHiddenParaField;
168 : }
169 :
170 : void InsertNesting(SwTxtAttrNesting & rNewHint);
171 : bool TryInsertNesting(SwTxtNode & rNode, SwTxtAttrNesting & rNewHint);
172 : void BuildPortions( SwTxtNode& rNode, SwTxtAttr& rNewHint,
173 : const SetAttrMode nMode );
174 : bool MergePortions( SwTxtNode& rNode );
175 :
176 : public:
177 : SwpHints();
178 :
179 0 : inline bool CanBeDeleted() const { return !Count(); }
180 :
181 : /// register a History, which receives all attribute changes (for Undo)
182 0 : void Register( SwRegHistory* pHist ) { m_pHistory = pHist; }
183 : /// deregister the currently registered History
184 0 : void DeRegister() { Register(0); }
185 0 : SwRegHistory* GetHistory() const { return m_pHistory; }
186 :
187 : /// try to insert the hint
188 : /// @return true iff hint successfully inserted
189 : bool TryInsertHint( SwTxtAttr * const pHint, SwTxtNode & rNode,
190 : const SetAttrMode nMode = nsSetAttrMode::SETATTR_DEFAULT );
191 :
192 0 : inline bool HasFtn() const { return m_bFootnote; }
193 0 : inline bool IsInSplitNode() const { return m_bInSplitNode; }
194 :
195 : /// calc current value of m_bHasHiddenParaField, returns true iff changed
196 : bool CalcHiddenParaField();
197 :
198 0 : DECL_FIXEDMEMPOOL_NEWDEL(SwpHints)
199 : };
200 :
201 : /// Inline Implementations
202 :
203 0 : inline sal_uInt16 SwpHintsArray::GetStartOf( const SwTxtAttr *pHt ) const
204 : {
205 : SwpHtStart::const_iterator const it =
206 0 : m_HintStarts.find(const_cast<SwTxtAttr*>(pHt));
207 0 : if ( it == m_HintStarts.end() )
208 : {
209 0 : return USHRT_MAX;
210 : }
211 0 : return it - m_HintStarts.begin();
212 : }
213 :
214 0 : inline SwTxtAttr *SwpHintsArray::Cut( const sal_uInt16 nPosInStart )
215 : {
216 0 : SwTxtAttr *pHt = GetTextHint(nPosInStart);
217 0 : DeleteAtPos( nPosInStart );
218 0 : return pHt;
219 : }
220 :
221 : #endif
222 :
223 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|