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 _ITRTXT_HXX 28 #define _ITRTXT_HXX 29 #include "swtypes.hxx" 30 #include "itratr.hxx" 31 #include "inftxt.hxx" 32 33 class SwTxtFrm; 34 struct SwPosition; 35 struct SwCrsrMoveState; 36 class SwMarginPortion; 37 class SwFlyPortion; 38 39 /************************************************************************* 40 * class SwTxtIter 41 *************************************************************************/ 42 43 class SwTxtIter : public SwAttrIter 44 { 45 protected: 46 SwLineInfo aLineInf; 47 SwTxtFrm *pFrm; 48 SwTxtInfo *pInf; 49 SwLineLayout *pCurr; 50 SwLineLayout *pPrev; 51 SwTwips nFrameStart; 52 SwTwips nY; 53 SwTwips nRegStart; // Anfangsposition (Y) des Registers 54 xub_StrLen nStart; // Start im Textstring, Ende = pCurr->GetLen() 55 KSHORT nRegDiff; // Zeilenabstand des Registers 56 MSHORT nLineNr; // Zeilennummer 57 sal_Bool bPrev : 1; 58 sal_Bool bRegisterOn : 1; // Registerhaltigkeit 59 sal_Bool bOneBlock : 1; // Blocksatz: Einzelwoerter austreiben 60 sal_Bool bLastBlock : 1; // Blocksatz: Auch die letzte Zeile 61 sal_Bool bLastCenter : 1; // Blocksatz: Letzte Zeile zentrieren 62 63 SwLineLayout *_GetPrev(); 64 65 // Zuruecksetzen in die erste Zeile. 66 void Init(); 67 void CtorInitTxtIter( SwTxtFrm *pFrm, SwTxtInfo *pInf ); 68 inline SwTxtIter(SwTxtNode* pTxtNode) : SwAttrIter(pTxtNode) { } 69 70 public: 71 inline SwTxtIter( SwTxtFrm *pTxtFrm, SwTxtInfo *pTxtInf ) : SwAttrIter(pTxtFrm!=NULL?pTxtFrm->GetTxtNode():NULL) 72 { CtorInitTxtIter( pTxtFrm, pTxtInf ); } 73 inline const SwLineLayout *GetCurr() const { return pCurr; } // niemals 0! 74 inline const SwLineLayout *GetNext() const { return pCurr->GetNext(); } 75 const SwLineLayout *GetPrev(); 76 inline xub_StrLen GetLength() const { return pCurr->GetLen(); } 77 inline MSHORT GetLineNr() const { return nLineNr; } 78 inline xub_StrLen GetStart() const { return nStart; } 79 inline xub_StrLen GetEnd() const { return GetStart() + GetLength(); } 80 inline SwTwips Y() const { return nY; } 81 82 inline SwTwips RegStart() const { return nRegStart; } 83 inline KSHORT RegDiff() const { return nRegDiff; } 84 inline sal_Bool IsRegisterOn() const { return bRegisterOn; } 85 86 inline SwTxtInfo &GetInfo() { return *pInf; } 87 inline const SwTxtInfo &GetInfo() const { return *pInf; } 88 89 inline void Top() { Init(); } 90 void Bottom(); 91 const SwLineLayout *Next(); 92 const SwLineLayout *Prev(); 93 94 // Ueberspringt die Dummyzeilen der FlyFrms 95 const SwLineLayout *NextLine(); 96 const SwLineLayout *PrevLine(); 97 const SwLineLayout *GetNextLine() const; 98 const SwLineLayout *GetPrevLine(); 99 100 void CharToLine( const xub_StrLen ); 101 const SwLineLayout *TwipsToLine(const SwTwips); 102 103 // schneidet ab pCurr alle ab. 104 void TruncLines( sal_Bool bNoteFollow = sal_False ); 105 106 inline KSHORT GetLineHeight() const { return pCurr->GetRealHeight(); } 107 void CalcAscentAndHeight( KSHORT &rAscent, KSHORT &rHeight ) const; 108 109 // 5298, viel Aerger durch die Abfrage auf pCurr == pPara 110 inline sal_Bool IsFirstTxtLine() const 111 { return nStart == GetInfo().GetTxtStart() && 112 !( pCurr->IsDummy() && GetNextLine() ); } 113 114 // Als Ersatz fuer das alte IsFirstLine() 115 inline sal_Bool IsParaLine() const 116 { return pCurr == pInf->GetParaPortion(); } 117 118 const SwLineInfo &GetLineInfo() const { return aLineInf; } 119 inline SwTwips GetFirstPos() const { return nFrameStart; } 120 inline sal_Bool SeekAndChg( SwTxtSizeInfo &rInf ); 121 inline sal_Bool SeekAndChgBefore( SwTxtSizeInfo &rInf ); 122 inline sal_Bool SeekStartAndChg( SwTxtSizeInfo &rInf, const sal_Bool bPara=sal_False ); 123 124 inline SwTxtFrm *GetTxtFrm() { return pFrm; } 125 inline const SwTxtFrm *GetTxtFrm() const { return pFrm; } 126 127 // zaehlt aufeinanderfolgende Trennungen, um MaxHyphens einzuhalten 128 void CntHyphens( sal_uInt8 &nEndCnt, sal_uInt8 &nMidCnt) const; 129 }; 130 131 /************************************************************************* 132 * class SwTxtMargin 133 *************************************************************************/ 134 135 class SwTxtMargin : public SwTxtIter 136 { 137 private: 138 SwTwips nLeft; 139 SwTwips nRight; 140 SwTwips nFirst; 141 KSHORT nDropLeft; 142 KSHORT nDropHeight; 143 KSHORT nDropDescent; 144 MSHORT nDropLines; 145 MSHORT nAdjust; 146 // --> OD 2008-06-30 #i91133# 147 SwTwips mnTabLeft; 148 // <-- 149 150 protected: 151 // fuer FormatQuoVadis 152 inline void Right( const SwTwips nNew ) { nRight = nNew; } 153 // fuer CalcFlyAdjust 154 inline void SetDropLeft( const KSHORT nNew ) { nDropLeft = nNew; } 155 156 void CtorInitTxtMargin( SwTxtFrm *pFrm, SwTxtSizeInfo *pInf ); 157 inline SwTxtMargin(SwTxtNode* pTxtNode) : SwTxtIter(pTxtNode) { } 158 public: 159 inline SwTxtMargin( SwTxtFrm *pTxtFrm, SwTxtSizeInfo *pTxtSizeInf ) : SwTxtIter(pTxtFrm!=NULL?pTxtFrm->GetTxtNode():NULL) 160 { CtorInitTxtMargin( pTxtFrm, pTxtSizeInf ); } 161 inline SwTwips GetLeftMargin() const; 162 inline SwTwips Left() const; 163 inline SwTwips Right() const { return nRight; } 164 inline SwTwips FirstLeft() const { return nFirst; } 165 inline SwTwips CurrWidth() const { return pCurr->PrtWidth(); } 166 SwTwips GetLineStart() const; 167 inline SwTwips GetLineEnd() const { return GetLineStart() + CurrWidth(); } 168 inline Point GetTopLeft() const { return Point( GetLineStart(), Y() ); } 169 inline sal_Bool IsOneBlock() const { return bOneBlock; } 170 inline sal_Bool IsLastBlock() const { return bLastBlock; } 171 inline sal_Bool IsLastCenter() const { return bLastCenter; } 172 inline MSHORT GetAdjust() const { return nAdjust; } 173 inline KSHORT GetLineWidth() const 174 { return KSHORT( Right() - GetLeftMargin() + 1 ); } 175 inline SwTwips GetLeftMin() const { return nFirst < nLeft ? nFirst : nLeft; } 176 inline sal_Bool HasNegFirst() const { return nFirst < nLeft; } 177 178 // --> OD 2008-06-30 #i91133# 179 inline SwTwips GetTabLeft() const 180 { 181 return mnTabLeft; 182 } 183 // <-- 184 // DropCaps 185 inline MSHORT GetDropLines() const { return nDropLines; } 186 inline void SetDropLines( const MSHORT nNew ) { nDropLines = nNew; } 187 inline KSHORT GetDropLeft() const { return nDropLeft; } 188 inline KSHORT GetDropHeight() const { return nDropHeight; } 189 inline void SetDropHeight( const KSHORT nNew ) { nDropHeight = nNew; } 190 inline KSHORT GetDropDescent() const { return nDropDescent; } 191 inline void SetDropDescent( const KSHORT nNew ) { nDropDescent = nNew; } 192 void DropInit(); 193 194 // liefert TxtPos fuer Start und Ende der aktuellen Zeile ohne whitespaces 195 // In frminf.cxx implementiert. 196 xub_StrLen GetTxtStart() const; 197 xub_StrLen GetTxtEnd() const; 198 199 inline SwTxtSizeInfo &GetInfo() 200 { return (SwTxtSizeInfo&)SwTxtIter::GetInfo(); } 201 inline const SwTxtSizeInfo &GetInfo() const 202 { return (const SwTxtSizeInfo&)SwTxtIter::GetInfo(); } 203 204 }; 205 206 207 /************************************************************************* 208 * class SwTxtAdjuster 209 *************************************************************************/ 210 211 class SwTxtAdjuster : public SwTxtMargin 212 { 213 // Gleicht die Portions aus, wenn Adjustment und FlyFrms vorliegen. 214 void CalcFlyAdjust( SwLineLayout *pCurr ); 215 216 // ruft SplitGlues und CalcBlockAdjust 217 void FormatBlock( ); 218 219 // Erstellt bei kurzen Zeilen die Glue-Kette. 220 SwMarginPortion* CalcRightMargin( SwLineLayout *pCurr, SwTwips nReal = 0 ); 221 222 // Berechnung des Adjustments (FlyPortions) 223 SwFlyPortion *CalcFlyPortion( const long nRealWidth, 224 const SwRect &rCurrRect ); 225 226 protected: 227 inline SwTxtAdjuster(SwTxtNode* pTxtNode) : SwTxtMargin(pTxtNode) { } 228 // spannt beim Blocksatz die Glues auf. 229 void CalcNewBlock( SwLineLayout *pCurr, const SwLinePortion *pStopAt, 230 SwTwips nReal = 0, bool bSkipKashida = false ); 231 SwTwips CalcKanaAdj( SwLineLayout *pCurr ); 232 public: 233 inline SwTxtAdjuster( SwTxtFrm *pTxtFrm, SwTxtSizeInfo *pTxtSizeInf ) : SwTxtMargin(pTxtFrm!=NULL?pTxtFrm->GetTxtNode():NULL) 234 { CtorInitTxtMargin( pTxtFrm, pTxtSizeInf ); } 235 236 // wird von SwTxtFormatter wegen UpdatePos ueberladen 237 void CalcAdjLine( SwLineLayout *pCurr ); 238 239 // sorgt fuer das nachtraegliche adjustieren 240 inline void GetAdjusted() const 241 { 242 if( pCurr->IsFormatAdj() ) 243 ((SwTxtAdjuster*)this)->CalcAdjLine( pCurr ); 244 } 245 246 // DropCaps-Extrawurst 247 void CalcDropAdjust(); 248 void CalcDropRepaint(); 249 }; 250 251 /************************************************************************* 252 * class SwTxtCursor 253 *************************************************************************/ 254 255 class SwTxtCursor : public SwTxtAdjuster 256 { 257 // A small helper-class to save SwTxtCursor member, manipulate them 258 // and to restore them 259 friend class SwTxtCursorSave; 260 261 // 1170: Mehrdeutigkeiten 262 static sal_Bool bRightMargin; 263 void _GetCharRect(SwRect *, const xub_StrLen, SwCrsrMoveState* ); 264 protected: 265 void CtorInitTxtCursor( SwTxtFrm *pFrm, SwTxtSizeInfo *pInf ); 266 inline SwTxtCursor(SwTxtNode* pTxtNode) : SwTxtAdjuster(pTxtNode) { } 267 public: 268 inline SwTxtCursor( SwTxtFrm *pTxtFrm, SwTxtSizeInfo *pTxtSizeInf ) : SwTxtAdjuster(pTxtFrm!=NULL?pTxtFrm->GetTxtNode():NULL) 269 { CtorInitTxtCursor( pTxtFrm, pTxtSizeInf ); } 270 sal_Bool GetCharRect(SwRect *, const xub_StrLen, SwCrsrMoveState* = 0, 271 const long nMax = 0 ); 272 sal_Bool GetEndCharRect(SwRect *, const xub_StrLen, SwCrsrMoveState* = 0, 273 const long nMax = 0 ); 274 xub_StrLen GetCrsrOfst( SwPosition *pPos, const Point &rPoint, 275 const MSHORT nChgNode, SwCrsrMoveState* = 0 ) const; 276 // 1170: beruecksichtigt Mehrdeutigkeiten; Implementierung s.u. 277 const SwLineLayout *CharCrsrToLine( const xub_StrLen nPos ); 278 279 // calculates baseline for portion rPor 280 // bAutoToCentered indicates, if AUTOMATIC mode means CENTERED or BASELINE 281 sal_uInt16 AdjustBaseLine( const SwLineLayout& rLine, const SwLinePortion* pPor, 282 sal_uInt16 nPorHeight = 0, sal_uInt16 nAscent = 0, 283 const sal_Bool bAutoToCentered = sal_False ) const; 284 285 static inline void SetRightMargin( const sal_Bool bNew ){ bRightMargin = bNew; } 286 static inline sal_Bool IsRightMargin() { return bRightMargin; } 287 }; 288 289 /************************************************************************* 290 * SwHookOut 291 * 292 * Change current output device to printer, this has to be done before 293 * formatting. 294 *************************************************************************/ 295 296 class SwHookOut 297 { 298 SwTxtSizeInfo* pInf; 299 OutputDevice* pOut; 300 sal_Bool bOnWin; 301 public: 302 SwHookOut( SwTxtSizeInfo& rInfo ); 303 ~SwHookOut(); 304 }; 305 306 /************************************************************************* 307 * Inline-Implementierungen 308 *************************************************************************/ 309 310 inline sal_Bool SwTxtIter::SeekAndChg( SwTxtSizeInfo &rInf ) 311 { 312 return SeekAndChgAttrIter( rInf.GetIdx(), rInf.GetOut() ); 313 } 314 315 inline sal_Bool SwTxtIter::SeekAndChgBefore( SwTxtSizeInfo &rInf ) 316 { 317 if ( rInf.GetIdx() ) 318 return SeekAndChgAttrIter( rInf.GetIdx()-1, rInf.GetOut() ); 319 else 320 return SeekAndChgAttrIter( rInf.GetIdx(), rInf.GetOut() ); 321 } 322 323 inline sal_Bool SwTxtIter::SeekStartAndChg( SwTxtSizeInfo &rInf, const sal_Bool bPara ) 324 { 325 return SeekStartAndChgAttrIter( rInf.GetOut(), bPara ); 326 } 327 328 inline SwTwips SwTxtMargin::GetLeftMargin() const 329 { 330 return IsFirstTxtLine() ? nFirst : Left(); 331 } 332 333 inline SwTwips SwTxtMargin::Left() const 334 { 335 return (nDropLines >= nLineNr && 1 != nLineNr) ? nFirst + nDropLeft : nLeft; 336 } 337 338 339 340 #endif 341