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