xref: /trunk/main/sw/inc/ndhints.hxx (revision 1d2dbeb0b7301723c6d13094e87a8714ef81a328)
1*1d2dbeb0SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*1d2dbeb0SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*1d2dbeb0SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*1d2dbeb0SAndrew Rist  * distributed with this work for additional information
6*1d2dbeb0SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*1d2dbeb0SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*1d2dbeb0SAndrew Rist  * "License"); you may not use this file except in compliance
9*1d2dbeb0SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*1d2dbeb0SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*1d2dbeb0SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*1d2dbeb0SAndrew Rist  * software distributed under the License is distributed on an
15*1d2dbeb0SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*1d2dbeb0SAndrew Rist  * KIND, either express or implied.  See the License for the
17*1d2dbeb0SAndrew Rist  * specific language governing permissions and limitations
18*1d2dbeb0SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*1d2dbeb0SAndrew Rist  *************************************************************/
21*1d2dbeb0SAndrew Rist 
22*1d2dbeb0SAndrew Rist 
23cdf0e10cSrcweir #ifndef _NDHINTS_HXX
24cdf0e10cSrcweir #define _NDHINTS_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <svl/svarray.hxx>
28cdf0e10cSrcweir #include <tools/mempool.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include "swtypes.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 
33cdf0e10cSrcweir class SwTxtNode;
34cdf0e10cSrcweir class SwRegHistory;                 // steht im RolBck.hxx
35cdf0e10cSrcweir class SwTxtAttr;
36cdf0e10cSrcweir class SwTxtAttrNesting;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir class SfxPoolItem;
39cdf0e10cSrcweir class SfxItemSet;
40cdf0e10cSrcweir class SwDoc;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir typedef enum {
43cdf0e10cSrcweir     COPY = true,
44cdf0e10cSrcweir     NEW  = false,
45cdf0e10cSrcweir } CopyOrNew_t;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir // if COPY then pTxtNode must be given!
48cdf0e10cSrcweir SW_DLLPRIVATE SwTxtAttr *
49cdf0e10cSrcweir MakeTxtAttr( SwDoc & rDoc, SfxPoolItem & rNew,
50cdf0e10cSrcweir         xub_StrLen const nStt, xub_StrLen const nEnd,
51cdf0e10cSrcweir         CopyOrNew_t const bIsCopy = NEW, SwTxtNode *const pTxtNode = 0);
52cdf0e10cSrcweir SW_DLLPRIVATE SwTxtAttr *
53cdf0e10cSrcweir MakeTxtAttr( SwDoc & rDoc, const SfxItemSet & rSet,
54cdf0e10cSrcweir         xub_StrLen nStt, xub_StrLen nEnd );
55cdf0e10cSrcweir 
56cdf0e10cSrcweir // create redline dummy text hint that must not be inserted into hints array
57cdf0e10cSrcweir SW_DLLPRIVATE SwTxtAttr*
58cdf0e10cSrcweir MakeRedlineTxtAttr( SwDoc & rDoc, SfxPoolItem& rAttr );
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
61cdf0e10cSrcweir /*
62cdf0e10cSrcweir  * Ableitung der Klasse SwpHints ueber den Umweg ueber SwpHts, da
63cdf0e10cSrcweir  * lediglich die Klasse SwTxtNode Attribute einfuegen und
64cdf0e10cSrcweir  * loeschen koennen soll. Anderen Klassen wie den Frames steht
65cdf0e10cSrcweir  * lediglich ein lesender Zugriff ueber den Index-Operator zur
66cdf0e10cSrcweir  * Verfuegung.
67cdf0e10cSrcweir  * Groesse beim Anlegen gleich 1, weil nur dann ein Array erzeug wird, wenn
68cdf0e10cSrcweir  * auch ein Hint eingefuegt wird.
69cdf0e10cSrcweir  */
70cdf0e10cSrcweir 
71cdf0e10cSrcweir /*************************************************************************
72cdf0e10cSrcweir  *                      class SwpHtStart/End
73cdf0e10cSrcweir  *************************************************************************/
74cdf0e10cSrcweir 
75cdf0e10cSrcweir SV_DECL_PTRARR_SORT(SwpHtStart,SwTxtAttr*,1,1)
76cdf0e10cSrcweir SV_DECL_PTRARR_SORT(SwpHtEnd,SwTxtAttr*,1,1)
77cdf0e10cSrcweir 
78cdf0e10cSrcweir /*************************************************************************
79cdf0e10cSrcweir  *                      class SwpHintsArr
80cdf0e10cSrcweir  *************************************************************************/
81cdf0e10cSrcweir 
82cdf0e10cSrcweir /// the Hints array
83cdf0e10cSrcweir class SwpHintsArray
84cdf0e10cSrcweir {
85cdf0e10cSrcweir 
86cdf0e10cSrcweir protected:
87cdf0e10cSrcweir     SwpHtStart m_HintStarts;
88cdf0e10cSrcweir     SwpHtEnd   m_HintEnds;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     //FIXME: why are the non-const methods public?
91cdf0e10cSrcweir public:
92cdf0e10cSrcweir     void Insert( const SwTxtAttr *pHt );
93cdf0e10cSrcweir     void DeleteAtPos( const sal_uInt16 nPosInStart );
94cdf0e10cSrcweir     bool Resort();
95cdf0e10cSrcweir     SwTxtAttr * Cut( const sal_uInt16 nPosInStart );
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     inline const SwTxtAttr * GetStart( const sal_uInt16 nPos ) const
98cdf0e10cSrcweir         { return m_HintStarts[nPos]; }
99cdf0e10cSrcweir     inline const SwTxtAttr * GetEnd  ( const sal_uInt16 nPos ) const
100cdf0e10cSrcweir         { return m_HintEnds  [nPos]; }
101cdf0e10cSrcweir     inline       SwTxtAttr * GetStart( const sal_uInt16 nPos )
102cdf0e10cSrcweir         { return m_HintStarts[nPos]; }
103cdf0e10cSrcweir     inline       SwTxtAttr * GetEnd  ( const sal_uInt16 nPos )
104cdf0e10cSrcweir         { return m_HintEnds  [nPos]; }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     inline sal_uInt16 GetEndCount()   const { return m_HintEnds  .Count(); }
107cdf0e10cSrcweir     inline sal_uInt16 GetStartCount() const { return m_HintStarts.Count(); }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     inline sal_uInt16 GetStartOf( const SwTxtAttr *pHt ) const;
110cdf0e10cSrcweir     inline sal_uInt16 GetPos( const SwTxtAttr *pHt ) const
111cdf0e10cSrcweir         { return m_HintStarts.GetPos( pHt ); }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     inline SwTxtAttr * GetTextHint( const sal_uInt16 nIdx )
114cdf0e10cSrcweir         { return GetStart(nIdx); }
115cdf0e10cSrcweir     inline const SwTxtAttr * operator[]( const sal_uInt16 nIdx ) const
116cdf0e10cSrcweir         { return m_HintStarts[nIdx]; }
117cdf0e10cSrcweir     inline sal_uInt16 Count() const { return m_HintStarts.Count(); }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir #ifdef DBG_UTIL
120cdf0e10cSrcweir     bool Check() const;
121cdf0e10cSrcweir #endif
122cdf0e10cSrcweir };
123cdf0e10cSrcweir 
124cdf0e10cSrcweir /*************************************************************************
125cdf0e10cSrcweir  *                      class SwpHints
126cdf0e10cSrcweir  *************************************************************************/
127cdf0e10cSrcweir 
128cdf0e10cSrcweir // public interface
129cdf0e10cSrcweir class SwpHints : public SwpHintsArray
130cdf0e10cSrcweir {
131cdf0e10cSrcweir private:
132cdf0e10cSrcweir     SwRegHistory* m_pHistory;   // for Undo
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     bool m_bFontChange          : 1;  // font change
135cdf0e10cSrcweir     // true: the Node is in Split and Frames are moved
136cdf0e10cSrcweir     bool m_bInSplitNode         : 1;
137cdf0e10cSrcweir     // m_bHasHiddenParaField is invalid, call CalcHiddenParaField()
138cdf0e10cSrcweir     bool m_bCalcHiddenParaField : 1;
139cdf0e10cSrcweir     bool m_bHasHiddenParaField  : 1;  // HiddenParaFld
140cdf0e10cSrcweir     bool m_bFootnote            : 1;  // footnotes
141cdf0e10cSrcweir     bool m_bDDEFields           : 1;  // the TextNode has DDE fields
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     // records a new attibute in m_pHistory.
144cdf0e10cSrcweir     void NoteInHistory( SwTxtAttr *pAttr, const bool bNew = false );
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     void CalcFlags( );
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     // Delete methods may only be called by the TextNode!
149cdf0e10cSrcweir     // Because the TextNode also guarantees removal of the Character for
150cdf0e10cSrcweir     // attributes without an end.
151cdf0e10cSrcweir     friend class SwTxtNode;
152cdf0e10cSrcweir     void DeleteAtPos( const sal_uInt16 nPos );
153cdf0e10cSrcweir     // Delete the given Hint. The Hint must actually be in the array!
154cdf0e10cSrcweir     void Delete( SwTxtAttr* pTxtHt );
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     inline void SetInSplitNode(bool bInSplit) { m_bInSplitNode = bInSplit; }
157cdf0e10cSrcweir     inline void SetCalcHiddenParaField() { m_bCalcHiddenParaField = true; }
158cdf0e10cSrcweir     inline void SetHiddenParaField( const bool bNew )
159cdf0e10cSrcweir         { m_bHasHiddenParaField = bNew; }
160cdf0e10cSrcweir     inline bool HasHiddenParaField() const
161cdf0e10cSrcweir     {
162cdf0e10cSrcweir         if ( m_bCalcHiddenParaField )
163cdf0e10cSrcweir         {
164cdf0e10cSrcweir             (const_cast<SwpHints*>(this))->CalcHiddenParaField();
165cdf0e10cSrcweir         }
166cdf0e10cSrcweir         return m_bHasHiddenParaField;
167cdf0e10cSrcweir     }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir     void InsertNesting(SwTxtAttrNesting & rNewHint);
170cdf0e10cSrcweir     bool TryInsertNesting(SwTxtNode & rNode, SwTxtAttrNesting & rNewHint);
171cdf0e10cSrcweir     void BuildPortions( SwTxtNode& rNode, SwTxtAttr& rNewHint,
172cdf0e10cSrcweir             const SetAttrMode nMode );
173cdf0e10cSrcweir     bool MergePortions( SwTxtNode& rNode );
174cdf0e10cSrcweir 
175cdf0e10cSrcweir public:
176cdf0e10cSrcweir     SwpHints();
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     inline bool CanBeDeleted() const    { return !Count(); }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     // register a History, which receives all attribute changes (for Undo)
181cdf0e10cSrcweir     void Register( SwRegHistory* pHist ) { m_pHistory = pHist; }
182cdf0e10cSrcweir     // deregister the currently registered History
183cdf0e10cSrcweir     void DeRegister() { Register(0); }
184cdf0e10cSrcweir     SwRegHistory* GetHistory() const    { return m_pHistory; }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     /// try to insert the hint
187cdf0e10cSrcweir     /// @return true iff hint successfully inserted
188cdf0e10cSrcweir     bool TryInsertHint( SwTxtAttr * const pHint, SwTxtNode & rNode,
189cdf0e10cSrcweir             const SetAttrMode nMode = nsSetAttrMode::SETATTR_DEFAULT );
190cdf0e10cSrcweir 
191cdf0e10cSrcweir     inline bool HasFtn() const          { return m_bFootnote; }
192cdf0e10cSrcweir     inline bool IsInSplitNode() const   { return m_bInSplitNode; }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir     // calc current value of m_bHasHiddenParaField, returns true iff changed
195cdf0e10cSrcweir     bool CalcHiddenParaField();
196cdf0e10cSrcweir 
197cdf0e10cSrcweir     DECL_FIXEDMEMPOOL_NEWDEL(SwpHints)
198cdf0e10cSrcweir };
199cdf0e10cSrcweir 
200cdf0e10cSrcweir // Ausgabeoperator fuer die Texthints
201cdf0e10cSrcweir SvStream &operator<<(SvStream &aS, const SwpHints &rHints); //$ ostream
202cdf0e10cSrcweir 
203cdf0e10cSrcweir /*************************************************************************
204cdf0e10cSrcweir  *                         Inline Implementations
205cdf0e10cSrcweir  *************************************************************************/
206cdf0e10cSrcweir 
207cdf0e10cSrcweir inline sal_uInt16 SwpHintsArray::GetStartOf( const SwTxtAttr *pHt ) const
208cdf0e10cSrcweir {
209cdf0e10cSrcweir     sal_uInt16 nPos;
210cdf0e10cSrcweir     if ( !m_HintStarts.Seek_Entry( pHt, &nPos ) )
211cdf0e10cSrcweir     {
212cdf0e10cSrcweir         nPos = USHRT_MAX;
213cdf0e10cSrcweir     }
214cdf0e10cSrcweir     return nPos;
215cdf0e10cSrcweir }
216cdf0e10cSrcweir 
217cdf0e10cSrcweir inline SwTxtAttr *SwpHintsArray::Cut( const sal_uInt16 nPosInStart )
218cdf0e10cSrcweir {
219cdf0e10cSrcweir     SwTxtAttr *pHt = GetTextHint(nPosInStart);
220cdf0e10cSrcweir     DeleteAtPos( nPosInStart );
221cdf0e10cSrcweir     return pHt;
222cdf0e10cSrcweir }
223cdf0e10cSrcweir 
224cdf0e10cSrcweir 
225cdf0e10cSrcweir #endif
226