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