xref: /trunk/main/sw/inc/ndhints.hxx (revision 1d2dbeb0)
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 *
49 MakeTxtAttr( SwDoc & rDoc, SfxPoolItem & rNew,
50         xub_StrLen const nStt, xub_StrLen const nEnd,
51         CopyOrNew_t const bIsCopy = NEW, SwTxtNode *const pTxtNode = 0);
52 SW_DLLPRIVATE SwTxtAttr *
53 MakeTxtAttr( SwDoc & rDoc, const SfxItemSet & rSet,
54         xub_StrLen nStt, xub_StrLen nEnd );
55 
56 // create redline dummy text hint that must not be inserted into hints array
57 SW_DLLPRIVATE SwTxtAttr*
58 MakeRedlineTxtAttr( SwDoc & rDoc, SfxPoolItem& rAttr );
59 
60 
61 /*
62  * Ableitung der Klasse SwpHints ueber den Umweg ueber SwpHts, da
63  * lediglich die Klasse SwTxtNode Attribute einfuegen und
64  * loeschen koennen soll. Anderen Klassen wie den Frames steht
65  * lediglich ein lesender Zugriff ueber den Index-Operator zur
66  * Verfuegung.
67  * Groesse beim Anlegen gleich 1, weil nur dann ein Array erzeug wird, wenn
68  * auch ein Hint eingefuegt wird.
69  */
70 
71 /*************************************************************************
72  *                      class SwpHtStart/End
73  *************************************************************************/
74 
75 SV_DECL_PTRARR_SORT(SwpHtStart,SwTxtAttr*,1,1)
76 SV_DECL_PTRARR_SORT(SwpHtEnd,SwTxtAttr*,1,1)
77 
78 /*************************************************************************
79  *                      class SwpHintsArr
80  *************************************************************************/
81 
82 /// the Hints array
83 class SwpHintsArray
84 {
85 
86 protected:
87     SwpHtStart m_HintStarts;
88     SwpHtEnd   m_HintEnds;
89 
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     bool Resort();
95     SwTxtAttr * Cut( const sal_uInt16 nPosInStart );
96 
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]; }
105 
106     inline sal_uInt16 GetEndCount()   const { return m_HintEnds  .Count(); }
107     inline sal_uInt16 GetStartCount() const { return m_HintStarts.Count(); }
108 
109     inline sal_uInt16 GetStartOf( const SwTxtAttr *pHt ) const;
110     inline sal_uInt16 GetPos( const SwTxtAttr *pHt ) const
111         { return m_HintStarts.GetPos( pHt ); }
112 
113     inline SwTxtAttr * GetTextHint( const sal_uInt16 nIdx )
114         { return GetStart(nIdx); }
115     inline const SwTxtAttr * operator[]( const sal_uInt16 nIdx ) const
116         { return m_HintStarts[nIdx]; }
117     inline sal_uInt16 Count() const { return m_HintStarts.Count(); }
118 
119 #ifdef DBG_UTIL
120     bool Check() const;
121 #endif
122 };
123 
124 /*************************************************************************
125  *                      class SwpHints
126  *************************************************************************/
127 
128 // public interface
129 class SwpHints : public SwpHintsArray
130 {
131 private:
132     SwRegHistory* m_pHistory;   // for Undo
133 
134     bool m_bFontChange          : 1;  // font change
135     // true: the Node is in Split and Frames are moved
136     bool m_bInSplitNode         : 1;
137     // m_bHasHiddenParaField is invalid, call CalcHiddenParaField()
138     bool m_bCalcHiddenParaField : 1;
139     bool m_bHasHiddenParaField  : 1;  // HiddenParaFld
140     bool m_bFootnote            : 1;  // footnotes
141     bool m_bDDEFields           : 1;  // the TextNode has DDE fields
142 
143     // records a new attibute in m_pHistory.
144     void NoteInHistory( SwTxtAttr *pAttr, const bool bNew = false );
145 
146     void CalcFlags( );
147 
148     // Delete methods may only be called by the TextNode!
149     // Because the TextNode also guarantees removal of the Character for
150     // attributes without an end.
151     friend class SwTxtNode;
152     void DeleteAtPos( const sal_uInt16 nPos );
153     // Delete the given Hint. The Hint must actually be in the array!
154     void Delete( SwTxtAttr* pTxtHt );
155 
156     inline void SetInSplitNode(bool bInSplit) { m_bInSplitNode = bInSplit; }
157     inline void SetCalcHiddenParaField() { m_bCalcHiddenParaField = true; }
158     inline void SetHiddenParaField( const bool bNew )
159         { m_bHasHiddenParaField = bNew; }
160     inline bool HasHiddenParaField() const
161     {
162         if ( m_bCalcHiddenParaField )
163         {
164             (const_cast<SwpHints*>(this))->CalcHiddenParaField();
165         }
166         return m_bHasHiddenParaField;
167     }
168 
169     void InsertNesting(SwTxtAttrNesting & rNewHint);
170     bool TryInsertNesting(SwTxtNode & rNode, SwTxtAttrNesting & rNewHint);
171     void BuildPortions( SwTxtNode& rNode, SwTxtAttr& rNewHint,
172             const SetAttrMode nMode );
173     bool MergePortions( SwTxtNode& rNode );
174 
175 public:
176     SwpHints();
177 
178     inline bool CanBeDeleted() const    { return !Count(); }
179 
180     // register a History, which receives all attribute changes (for Undo)
181     void Register( SwRegHistory* pHist ) { m_pHistory = pHist; }
182     // deregister the currently registered History
183     void DeRegister() { Register(0); }
184     SwRegHistory* GetHistory() const    { return m_pHistory; }
185 
186     /// try to insert the hint
187     /// @return true iff hint successfully inserted
188     bool TryInsertHint( SwTxtAttr * const pHint, SwTxtNode & rNode,
189             const SetAttrMode nMode = nsSetAttrMode::SETATTR_DEFAULT );
190 
191     inline bool HasFtn() const          { return m_bFootnote; }
192     inline bool IsInSplitNode() const   { return m_bInSplitNode; }
193 
194     // calc current value of m_bHasHiddenParaField, returns true iff changed
195     bool CalcHiddenParaField();
196 
197     DECL_FIXEDMEMPOOL_NEWDEL(SwpHints)
198 };
199 
200 // Ausgabeoperator fuer die Texthints
201 SvStream &operator<<(SvStream &aS, const SwpHints &rHints); //$ ostream
202 
203 /*************************************************************************
204  *                         Inline Implementations
205  *************************************************************************/
206 
207 inline sal_uInt16 SwpHintsArray::GetStartOf( const SwTxtAttr *pHt ) const
208 {
209     sal_uInt16 nPos;
210     if ( !m_HintStarts.Seek_Entry( pHt, &nPos ) )
211     {
212         nPos = USHRT_MAX;
213     }
214     return nPos;
215 }
216 
217 inline SwTxtAttr *SwpHintsArray::Cut( const sal_uInt16 nPosInStart )
218 {
219     SwTxtAttr *pHt = GetTextHint(nPosInStart);
220     DeleteAtPos( nPosInStart );
221     return pHt;
222 }
223 
224 
225 #endif
226