Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #ifndef _NDHINTS_HXX
29 : : #define _NDHINTS_HXX
30 : :
31 : :
32 : : #include <tools/mempool.hxx>
33 : : #include <o3tl/sorted_vector.hxx>
34 : :
35 : : #include "swtypes.hxx"
36 : :
37 : : class SwTxtNode;
38 : : class SwRegHistory; // Is in RolBck.hxx.
39 : : class SwTxtAttr;
40 : : class SwTxtAttrNesting;
41 : :
42 : : class SfxPoolItem;
43 : : class SfxItemSet;
44 : : class SwDoc;
45 : :
46 : : typedef enum {
47 : : COPY = true,
48 : : NEW = false,
49 : : } CopyOrNew_t;
50 : :
51 : : // if COPY then pTxtNode must be given!
52 : : SW_DLLPRIVATE SwTxtAttr *
53 : : MakeTxtAttr( SwDoc & rDoc, SfxPoolItem & rNew,
54 : : xub_StrLen const nStt, xub_StrLen const nEnd,
55 : : CopyOrNew_t const bIsCopy = NEW, SwTxtNode *const pTxtNode = 0);
56 : : SW_DLLPRIVATE SwTxtAttr *
57 : : MakeTxtAttr( SwDoc & rDoc, const SfxItemSet & rSet,
58 : : xub_StrLen nStt, xub_StrLen nEnd );
59 : :
60 : : // create redline dummy text hint that must not be inserted into hints array
61 : : SW_DLLPRIVATE SwTxtAttr*
62 : : MakeRedlineTxtAttr( SwDoc & rDoc, SfxPoolItem& rAttr );
63 : :
64 : :
65 : : // Class SwpHints is derived indirectly via SwpHts, because only the
66 : : // class SwTxtNode should be allowed to insert and remove attributes.
67 : : // Other classes like the Frames are given only reading access via
68 : : // the index-operator.
69 : : // Size when created is 1 because an array is created only if
70 : : // also a hint is inserted.
71 : :
72 : : // Class SwpHtStart/End
73 : :
74 : : struct CompareSwpHtStart
75 : : {
76 : : bool operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const;
77 : : };
78 : 13143 : class SwpHtStart : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtStart,
79 : : o3tl::find_partialorder_ptrequals> {};
80 : :
81 : : struct CompareSwpHtEnd
82 : : {
83 : : bool operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const;
84 : : };
85 : 13143 : class SwpHtEnd : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtEnd,
86 : : o3tl::find_partialorder_ptrequals> {};
87 : :
88 : : // Class SwpHintsArr
89 : :
90 : :
91 : : /// the Hints array
92 [ + - ]: 13143 : class SwpHintsArray
93 : : {
94 : :
95 : : protected:
96 : : SwpHtStart m_HintStarts;
97 : : SwpHtEnd m_HintEnds;
98 : :
99 : : //FIXME: why are the non-const methods public?
100 : : public:
101 : : void Insert( const SwTxtAttr *pHt );
102 : : void DeleteAtPos( const sal_uInt16 nPosInStart );
103 : : bool Resort();
104 : : SwTxtAttr * Cut( const sal_uInt16 nPosInStart );
105 : :
106 : 9438 : inline const SwTxtAttr * GetStart( const sal_uInt16 nPos ) const
107 : 9438 : { return m_HintStarts[nPos]; }
108 : 0 : inline const SwTxtAttr * GetEnd ( const sal_uInt16 nPos ) const
109 : 0 : { return m_HintEnds [nPos]; }
110 : 956215 : inline SwTxtAttr * GetStart( const sal_uInt16 nPos )
111 : 956215 : { return m_HintStarts[nPos]; }
112 : 67686 : inline SwTxtAttr * GetEnd ( const sal_uInt16 nPos )
113 : 67686 : { return m_HintEnds [nPos]; }
114 : :
115 : 58307 : inline sal_uInt16 GetEndCount() const { return m_HintEnds .size(); }
116 : 61518 : inline sal_uInt16 GetStartCount() const { return m_HintStarts.size(); }
117 : :
118 : : inline sal_uInt16 GetStartOf( const SwTxtAttr *pHt ) const;
119 : : sal_uInt16 GetPos( const SwTxtAttr *pHt ) const;
120 : :
121 : 911304 : inline SwTxtAttr * GetTextHint( const sal_uInt16 nIdx )
122 : 911304 : { return GetStart(nIdx); }
123 : 1153365 : inline const SwTxtAttr * operator[]( const sal_uInt16 nIdx ) const
124 : 1153365 : { return m_HintStarts[nIdx]; }
125 : 1113721 : inline sal_uInt16 Count() const { return m_HintStarts.size(); }
126 : :
127 : : #ifdef DBG_UTIL
128 : : bool Check() const;
129 : : #endif
130 : : };
131 : :
132 : :
133 : : // Class SwpHints
134 : :
135 : :
136 : : // public interface
137 : 6522 : class SwpHints : public SwpHintsArray
138 : : {
139 : : private:
140 : : SwRegHistory* m_pHistory; // for Undo
141 : :
142 : : bool m_bFontChange : 1; // font change
143 : : // true: the Node is in Split and Frames are moved
144 : : bool m_bInSplitNode : 1;
145 : : // m_bHasHiddenParaField is invalid, call CalcHiddenParaField()
146 : : bool m_bCalcHiddenParaField : 1;
147 : : bool m_bHasHiddenParaField : 1; // HiddenParaFld
148 : : bool m_bFootnote : 1; // footnotes
149 : : bool m_bDDEFields : 1; // the TextNode has DDE fields
150 : :
151 : : // records a new attibute in m_pHistory.
152 : : void NoteInHistory( SwTxtAttr *pAttr, const bool bNew = false );
153 : :
154 : : void CalcFlags( );
155 : :
156 : : // Delete methods may only be called by the TextNode!
157 : : // Because the TextNode also guarantees removal of the Character for
158 : : // attributes without an end.
159 : : friend class SwTxtNode;
160 : : void DeleteAtPos( const sal_uInt16 nPos );
161 : : // Delete the given Hint. The Hint must actually be in the array!
162 : : void Delete( SwTxtAttr* pTxtHt );
163 : :
164 : 0 : inline void SetInSplitNode(bool bInSplit) { m_bInSplitNode = bInSplit; }
165 : 0 : inline void SetCalcHiddenParaField() { m_bCalcHiddenParaField = true; }
166 : 268 : inline void SetHiddenParaField( const bool bNew )
167 : 268 : { m_bHasHiddenParaField = bNew; }
168 : 43205 : inline bool HasHiddenParaField() const
169 : : {
170 [ - + ]: 43205 : if ( m_bCalcHiddenParaField )
171 : : {
172 : 0 : (const_cast<SwpHints*>(this))->CalcHiddenParaField();
173 : : }
174 : 43205 : return m_bHasHiddenParaField;
175 : : }
176 : :
177 : : void InsertNesting(SwTxtAttrNesting & rNewHint);
178 : : bool TryInsertNesting(SwTxtNode & rNode, SwTxtAttrNesting & rNewHint);
179 : : void BuildPortions( SwTxtNode& rNode, SwTxtAttr& rNewHint,
180 : : const SetAttrMode nMode );
181 : : bool MergePortions( SwTxtNode& rNode );
182 : :
183 : : public:
184 : : SwpHints();
185 : :
186 : 28002 : inline bool CanBeDeleted() const { return !Count(); }
187 : :
188 : : // register a History, which receives all attribute changes (for Undo)
189 : 3240 : void Register( SwRegHistory* pHist ) { m_pHistory = pHist; }
190 : : // deregister the currently registered History
191 : 1772 : void DeRegister() { Register(0); }
192 : 63 : SwRegHistory* GetHistory() const { return m_pHistory; }
193 : :
194 : : /// try to insert the hint
195 : : /// @return true iff hint successfully inserted
196 : : bool TryInsertHint( SwTxtAttr * const pHint, SwTxtNode & rNode,
197 : : const SetAttrMode nMode = nsSetAttrMode::SETATTR_DEFAULT );
198 : :
199 : 0 : inline bool HasFtn() const { return m_bFootnote; }
200 : 636 : inline bool IsInSplitNode() const { return m_bInSplitNode; }
201 : :
202 : : // calc current value of m_bHasHiddenParaField, returns true iff changed
203 : : bool CalcHiddenParaField();
204 : :
205 [ + - ][ + - ]: 13143 : DECL_FIXEDMEMPOOL_NEWDEL(SwpHints)
206 : : };
207 : :
208 : : // Output operator for text hints.
209 : : SvStream &operator<<(SvStream &aS, const SwpHints &rHints); //$ ostream
210 : :
211 : :
212 : : // Inline Implementations
213 : :
214 : :
215 : 11480 : inline sal_uInt16 SwpHintsArray::GetStartOf( const SwTxtAttr *pHt ) const
216 : : {
217 : : SwpHtStart::const_iterator const it =
218 [ + - ]: 11480 : m_HintStarts.find(const_cast<SwTxtAttr*>(pHt));
219 [ + - ][ - + ]: 11480 : if ( it == m_HintStarts.end() )
220 : : {
221 : 0 : return USHRT_MAX;
222 : : }
223 [ + - ]: 11480 : return it - m_HintStarts.begin();
224 : : }
225 : :
226 : 93 : inline SwTxtAttr *SwpHintsArray::Cut( const sal_uInt16 nPosInStart )
227 : : {
228 : 93 : SwTxtAttr *pHt = GetTextHint(nPosInStart);
229 : 93 : DeleteAtPos( nPosInStart );
230 : 93 : return pHt;
231 : : }
232 : :
233 : :
234 : : #endif
235 : :
236 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|