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