1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23 #ifndef _NDHINTS_HXX
24 #define _NDHINTS_HXX
25
26
27 #include <svl/svarray.hxx>
28 #include <tools/mempool.hxx>
29
30 #include "swtypes.hxx"
31
32
33 class SwTxtNode;
34 class SwRegHistory; // steht im RolBck.hxx
35 class SwTxtAttr;
36 class SwTxtAttrNesting;
37
38 class SfxPoolItem;
39 class SfxItemSet;
40 class SwDoc;
41
42 typedef enum {
43 COPY = true,
44 NEW = false,
45 } CopyOrNew_t;
46
47 // if COPY then pTxtNode must be given!
48 SW_DLLPRIVATE SwTxtAttr * MakeTxtAttr(
49 SwDoc & rDoc,
50 SfxPoolItem & rNew,
51 xub_StrLen const nStt,
52 xub_StrLen const nEnd,
53 CopyOrNew_t const bIsCopy = NEW,
54 SwTxtNode *const pTxtNode = 0 );
55
56 SW_DLLPRIVATE SwTxtAttr * MakeTxtAttr(
57 SwDoc & rDoc,
58 const SfxItemSet & rSet,
59 xub_StrLen nStt,
60 xub_StrLen nEnd );
61
62 // create redline dummy text hint that must not be inserted into hints array
63 SW_DLLPRIVATE SwTxtAttr* MakeRedlineTxtAttr(
64 SwDoc & rDoc,
65 SfxPoolItem& rAttr );
66
67
68 /*
69 * Ableitung der Klasse SwpHints ueber den Umweg ueber SwpHts, da
70 * lediglich die Klasse SwTxtNode Attribute einfuegen und
71 * loeschen koennen soll. Anderen Klassen wie den Frames steht
72 * lediglich ein lesender Zugriff ueber den Index-Operator zur
73 * Verfuegung.
74 * Groesse beim Anlegen gleich 1, weil nur dann ein Array erzeug wird, wenn
75 * auch ein Hint eingefuegt wird.
76 */
77
78 /*************************************************************************
79 * class SwpHtStart/End
80 *************************************************************************/
81
82 SV_DECL_PTRARR_SORT(SwpHtStart,SwTxtAttr*,1,1)
83 SV_DECL_PTRARR_SORT(SwpHtEnd,SwTxtAttr*,1,1)
84
85 /*************************************************************************
86 * class SwpHintsArr
87 *************************************************************************/
88
89 /// the Hints array
90 class SwpHintsArray
91 {
92
93 protected:
94 SwpHtStart m_HintStarts;
95 SwpHtEnd m_HintEnds;
96
97 //FIXME: why are the non-const methods public?
98 public:
99 void Insert( const SwTxtAttr *pHt );
100 void DeleteAtPos( const sal_uInt16 nPosInStart );
101 bool Resort();
102 SwTxtAttr * Cut( const sal_uInt16 nPosInStart );
103
GetStart(const sal_uInt16 nPos) const104 inline const SwTxtAttr * GetStart( const sal_uInt16 nPos ) const
105 { return m_HintStarts[nPos]; }
GetEnd(const sal_uInt16 nPos) const106 inline const SwTxtAttr * GetEnd ( const sal_uInt16 nPos ) const
107 { return m_HintEnds [nPos]; }
GetStart(const sal_uInt16 nPos)108 inline SwTxtAttr * GetStart( const sal_uInt16 nPos )
109 { return m_HintStarts[nPos]; }
GetEnd(const sal_uInt16 nPos)110 inline SwTxtAttr * GetEnd ( const sal_uInt16 nPos )
111 { return m_HintEnds [nPos]; }
112
GetEndCount() const113 inline sal_uInt16 GetEndCount() const { return m_HintEnds .Count(); }
GetStartCount() const114 inline sal_uInt16 GetStartCount() const { return m_HintStarts.Count(); }
115
116 inline sal_uInt16 GetStartOf( const SwTxtAttr *pHt ) const;
GetPos(const SwTxtAttr * pHt) const117 inline sal_uInt16 GetPos( const SwTxtAttr *pHt ) const
118 { return m_HintStarts.GetPos( pHt ); }
119
GetTextHint(const sal_uInt16 nIdx)120 inline SwTxtAttr * GetTextHint( const sal_uInt16 nIdx )
121 { return GetStart(nIdx); }
operator [](const sal_uInt16 nIdx) const122 inline const SwTxtAttr * operator[]( const sal_uInt16 nIdx ) const
123 { return m_HintStarts[nIdx]; }
Count() const124 inline sal_uInt16 Count() const { return m_HintStarts.Count(); }
125
126 #ifdef DBG_UTIL
127 bool Check() const;
128 #endif
129 };
130
131 /*************************************************************************
132 * class SwpHints
133 *************************************************************************/
134
135 // public interface
136 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 sal_uInt16 nPos );
160 // Delete the given Hint. The Hint must actually be in the array!
161 void Delete( SwTxtAttr* pTxtHt );
162
SetInSplitNode(bool bInSplit)163 inline void SetInSplitNode(bool bInSplit) { m_bInSplitNode = bInSplit; }
SetCalcHiddenParaField()164 inline void SetCalcHiddenParaField() { m_bCalcHiddenParaField = true; }
SetHiddenParaField(const bool bNew)165 inline void SetHiddenParaField( const bool bNew )
166 { m_bHasHiddenParaField = bNew; }
HasHiddenParaField() const167 inline bool HasHiddenParaField() const
168 {
169 if ( m_bCalcHiddenParaField )
170 {
171 (const_cast<SwpHints*>(this))->CalcHiddenParaField();
172 }
173 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
CanBeDeleted() const185 inline bool CanBeDeleted() const { return !Count(); }
186
187 // register a History, which receives all attribute changes (for Undo)
Register(SwRegHistory * pHist)188 void Register( SwRegHistory* pHist ) { m_pHistory = pHist; }
189 // deregister the currently registered History
DeRegister()190 void DeRegister() { Register(0); }
GetHistory() const191 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
HasFtn() const198 inline bool HasFtn() const { return m_bFootnote; }
IsInSplitNode() const199 inline bool IsInSplitNode() const { return m_bInSplitNode; }
200
201 // calc current value of m_bHasHiddenParaField, returns true iff changed
202 bool CalcHiddenParaField();
203
204 DECL_FIXEDMEMPOOL_NEWDEL(SwpHints)
205 };
206
207 // Ausgabeoperator fuer die Texthints
208 SvStream &operator<<(SvStream &aS, const SwpHints &rHints); //$ ostream
209
210 /*************************************************************************
211 * Inline Implementations
212 *************************************************************************/
213
GetStartOf(const SwTxtAttr * pHt) const214 inline sal_uInt16 SwpHintsArray::GetStartOf( const SwTxtAttr *pHt ) const
215 {
216 sal_uInt16 nPos;
217 if ( !m_HintStarts.Seek_Entry( pHt, &nPos ) )
218 {
219 nPos = USHRT_MAX;
220 }
221 return nPos;
222 }
223
Cut(const sal_uInt16 nPosInStart)224 inline SwTxtAttr *SwpHintsArray::Cut( const sal_uInt16 nPosInStart )
225 {
226 SwTxtAttr *pHt = GetTextHint(nPosInStart);
227 DeleteAtPos( nPosInStart );
228 return pHt;
229 }
230
231
232 #endif
233