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 _FRMTOOL_HXX 28 #define _FRMTOOL_HXX 29 #include "swtypes.hxx" 30 #include "layfrm.hxx" 31 #include "frmatr.hxx" 32 #include "swcache.hxx" 33 // --> OD 2008-12-04 #i96772# 34 #include <editeng/lrspitem.hxx> 35 // <-- 36 37 class SwPageFrm; 38 class SwFlyFrm; 39 class SwCntntFrm; 40 class SwRootFrm; 41 class SwDoc; 42 class SwAttrSet; 43 class SdrObject; 44 class BigInt; 45 class SvxBrushItem; 46 class SdrMarkList; 47 class SwNodeIndex; 48 class OutputDevice; 49 class SwPageDesc; 50 class SwTableBox; 51 struct SwFindRowSpanCacheObj; 52 53 #if defined(MSC) 54 #define MA_FASTCALL __fastcall 55 #else 56 #define MA_FASTCALL 57 #endif 58 59 #define WEIT_WECH LONG_MAX - 20000 //Initale Position der Flys. 60 #define BROWSE_HEIGHT 56700L * 10L //10 Meter 61 //#define BROWSE_HEIGHT 1440L * 45L // 45 inch, maximum size for pdf files 62 63 #define GRFNUM_NO 0 64 #define GRFNUM_YES 1 65 #define GRFNUM_REPLACE 2 66 67 //Painten des Hintergrunds. Mit Brush oder Graphic. 68 // OD 05.08.2002 #99657# - add 6th parameter to indicate that method should 69 // consider background transparency, saved in the color of the brush item 70 void MA_FASTCALL DrawGraphic( const SvxBrushItem *, OutputDevice *, 71 const SwRect &rOrg, const SwRect &rOut, const sal_uInt8 nGrfNum = GRFNUM_NO, 72 const sal_Bool bConsiderBackgroundTransparency = sal_False ); 73 74 // OD 24.01.2003 #106593# - method to align rectangle 75 // Created declaration here to avoid <extern> declarations 76 void MA_FASTCALL SwAlignRect( SwRect &rRect, ViewShell *pSh ); 77 78 // OD 24.01.2003 #106593# - method to align graphic rectangle 79 // Created declaration here to avoid <extern> declarations 80 void SwAlignGrfRect( SwRect *pGrfRect, const OutputDevice &rOut ); 81 82 //Fly besorgen, wenn keine List hineingereicht wird, wir die der aktuellen 83 //Shell benutzt. 84 //Implementierung in feshview.cxx 85 SwFlyFrm *GetFlyFromMarked( const SdrMarkList *pLst, ViewShell *pSh ); 86 87 //Nicht gleich die math.lib anziehen. 88 sal_uLong MA_FASTCALL SqRt( BigInt nX ); 89 90 SwFrm *SaveCntnt( SwLayoutFrm *pLay, SwFrm *pStart ); 91 void RestoreCntnt( SwFrm *pSav, SwLayoutFrm *pParent, SwFrm *pSibling, bool bGrow ); 92 93 //CntntNodes besorgen, CntntFrms erzeugen und in den LayFrm haengen. 94 void MA_FASTCALL _InsertCnt( SwLayoutFrm *pLay, SwDoc *pDoc, sal_uLong nIndex, 95 sal_Bool bPages = sal_False, sal_uLong nEndIndex = 0, 96 SwFrm *pPrv = 0 ); 97 98 //Erzeugen der Frames fuer einen bestimmten Bereich, verwendet _InsertCnt 99 void MakeFrms( SwDoc *pDoc, const SwNodeIndex &rSttIdx, 100 const SwNodeIndex &rEndIdx ); 101 102 //Um z.B. fuer Tabelleheadlines das Erzeugen der Flys in _InsertCnt zu unterbinden. 103 extern sal_Bool bDontCreateObjects; 104 105 //Fuer FlyCnts, siehe SwFlyAtCntFrm::MakeAll() 106 extern sal_Bool bSetCompletePaintOnInvalidate; 107 108 //Fuer Tabelleneinstellung per Tastatur. 109 long MA_FASTCALL CalcRowRstHeight( SwLayoutFrm *pRow ); 110 long MA_FASTCALL CalcHeightWidthFlys( const SwFrm *pFrm ); //MA_FLY_HEIGHT 111 112 //Neue Seite einsetzen 113 SwPageFrm * MA_FASTCALL InsertNewPage( SwPageDesc &rDesc, SwFrm *pUpper, 114 sal_Bool bOdd, sal_Bool bInsertEmpty, sal_Bool bFtn, 115 SwFrm *pSibling ); 116 117 //Flys bei der Seite anmelden. 118 void RegistFlys( SwPageFrm*, const SwLayoutFrm* ); 119 120 //Benachrichtung des Fly Hintergrundes wenn Notwendig. 121 void Notify( SwFlyFrm *pFly, SwPageFrm *pOld, const SwRect &rOld, 122 const SwRect* pOldRect = 0 ); 123 124 void Notify_Background( const SdrObject* pObj, 125 SwPageFrm* pPage, 126 const SwRect& rRect, 127 const PrepareHint eHint, 128 const sal_Bool bInva ); 129 130 const SwFrm* GetVirtualUpper( const SwFrm* pFrm, const Point& rPos ); 131 132 sal_Bool Is_Lower_Of( const SwFrm *pCurrFrm, const SdrObject* pObj ); 133 134 const SwFrm *FindKontext( const SwFrm *pFrm, sal_uInt16 nAdditionalKontextTyp ); 135 136 sal_Bool IsFrmInSameKontext( const SwFrm *pInnerFrm, const SwFrm *pFrm ); 137 138 const SwFrm * MA_FASTCALL FindPage( const SwRect &rRect, const SwFrm *pPage ); 139 140 // JP 07.05.98: wird von SwCntntNode::GetFrm und von SwFlyFrm::GetFrm 141 // gerufen 142 SwFrm* GetFrmOfModify( const SwRootFrm* pLayout, SwModify const&, sal_uInt16 const nFrmType, const Point* = 0, 143 const SwPosition *pPos = 0, 144 const sal_Bool bCalcFrm = sal_False ); 145 146 //Sollen ExtraDaten (Reline-Strich, Zeilennummern) gepaintet werden? 147 sal_Bool IsExtraData( const SwDoc *pDoc ); 148 149 // OD 14.03.2003 #i11760# - method declaration <CalcCntnt(..)> 150 void CalcCntnt( SwLayoutFrm *pLay, 151 bool bNoColl = false, 152 bool bNoCalcFollow = false ); 153 154 155 //Die Notify-Klassen merken sich im CTor die aktuellen Groessen und fuehren 156 //im DTor ggf. die notwendigen Benachrichtigungen durch. 157 158 class SwFrmNotify 159 { 160 protected: 161 SwFrm *pFrm; 162 const SwRect aFrm; 163 const SwRect aPrt; 164 SwTwips mnFlyAnchorOfst; 165 SwTwips mnFlyAnchorOfstNoWrap; 166 sal_Bool bHadFollow; 167 sal_Bool bInvaKeep; 168 sal_Bool bValidSize; 169 protected: 170 // --> OD 2005-07-29 #i49383# 171 bool mbFrmDeleted; 172 // <-- 173 174 public: 175 SwFrmNotify( SwFrm *pFrm ); 176 ~SwFrmNotify(); 177 178 const SwRect &Frm() const { return aFrm; } 179 const SwRect &Prt() const { return aPrt; } 180 void SetInvaKeep() { bInvaKeep = sal_True; } 181 // --> OD 2005-07-29 #i49383# 182 void FrmDeleted() 183 { 184 mbFrmDeleted = true; 185 } 186 // <-- 187 }; 188 189 class SwLayNotify : public SwFrmNotify 190 { 191 sal_Bool bLowersComplete; 192 193 SwLayoutFrm *GetLay() { return (SwLayoutFrm*)pFrm; } 194 public: 195 SwLayNotify( SwLayoutFrm *pLayFrm ); 196 ~SwLayNotify(); 197 198 void SetLowersComplete( sal_Bool b ) { bLowersComplete = b; } 199 sal_Bool IsLowersComplete() { return bLowersComplete; } 200 }; 201 202 class SwFlyNotify : public SwLayNotify 203 { 204 SwPageFrm *pOldPage; 205 const SwRect aFrmAndSpace; 206 SwFlyFrm *GetFly() { return (SwFlyFrm*)pFrm; } 207 public: 208 SwFlyNotify( SwFlyFrm *pFlyFrm ); 209 ~SwFlyNotify(); 210 211 SwPageFrm *GetOldPage() const { return pOldPage; } 212 }; 213 214 class SwCntntNotify : public SwFrmNotify 215 { 216 private: 217 // OD 08.01.2004 #i11859# 218 bool mbChkHeightOfLastLine; 219 SwTwips mnHeightOfLastLine; 220 221 // OD 2004-02-26 #i25029# 222 bool mbInvalidatePrevPrtArea; 223 bool mbBordersJoinedWithPrev; 224 225 SwCntntFrm *GetCnt() { return (SwCntntFrm*)pFrm; } 226 227 public: 228 SwCntntNotify( SwCntntFrm *pCntFrm ); 229 ~SwCntntNotify(); 230 231 // OD 2004-02-26 #i25029# 232 void SetInvalidatePrevPrtArea() 233 { 234 mbInvalidatePrevPrtArea = true; 235 } 236 237 void SetBordersJoinedWithPrev() 238 { 239 mbBordersJoinedWithPrev = true; 240 } 241 }; 242 243 //SwBorderAttrs kapselt die Berechnung fuer die Randattribute inclusive 244 //Umrandung. Die Attribute und die errechneten Werte werden gecached. 245 //Neu: Die gesammte Klasse wird gecached. 246 247 //!!!Achtung: Wenn weitere Attribute gecached werden muss unbedingt die 248 //Methode Modify::Modify mitgepflegt werden!!! 249 250 // OD 23.01.2003 #106895# - delete old method <SwBorderAttrs::CalcRight()> and 251 // the stuff that belongs to it. 252 class SwBorderAttrs : public SwCacheObj 253 { 254 const SwAttrSet &rAttrSet; 255 const SvxULSpaceItem &rUL; 256 // --> OD 2008-12-04 #i96772# 257 SvxLRSpaceItem rLR; 258 // <-- 259 const SvxBoxItem &rBox; 260 const SvxShadowItem &rShadow; 261 const Size aFrmSize; //Die FrmSize 262 263 sal_Bool bBorderDist :1; //Ist's ein Frm der auch ohne Linie 264 //einen Abstand haben kann? 265 266 //Mit den Folgenden Bools werden die gecache'ten Werte fuer UNgueltig 267 //erklaert - bis sie einmal berechnet wurden. 268 sal_Bool bTopLine :1; 269 sal_Bool bBottomLine :1; 270 sal_Bool bLeftLine :1; 271 sal_Bool bRightLine :1; 272 sal_Bool bTop :1; 273 sal_Bool bBottom :1; 274 sal_Bool bLine :1; 275 276 sal_Bool bIsLine :1; //Umrandung an mind. einer Kante? 277 278 sal_Bool bCacheGetLine :1; //GetTopLine(), GetBottomLine() cachen? 279 sal_Bool bCachedGetTopLine :1; //GetTopLine() gecached? 280 sal_Bool bCachedGetBottomLine :1; //GetBottomLine() gecached? 281 // OD 21.05.2003 #108789# - booleans indicating, if values <bJoinedWithPrev> 282 // and <bJoinedWithNext> are cached and valid. 283 // Caching depends on value of <bCacheGetLine>. 284 mutable sal_Bool bCachedJoinedWithPrev :1; 285 mutable sal_Bool bCachedJoinedWithNext :1; 286 // OD 21.05.2003 #108789# - booleans indicating, if borders are joined 287 // with previous/next frame. 288 sal_Bool bJoinedWithPrev :1; 289 sal_Bool bJoinedWithNext :1; 290 291 //Die gecache'ten Werte, undefiniert bis sie einmal berechnet wurden. 292 sal_uInt16 nTopLine, 293 nBottomLine, 294 nLeftLine, 295 nRightLine, 296 nTop, 297 nBottom, 298 nGetTopLine, 299 nGetBottomLine; 300 301 //Nur die Lines + Shadow errechnen. 302 void _CalcTopLine(); 303 void _CalcBottomLine(); 304 void _CalcLeftLine(); 305 void _CalcRightLine(); 306 307 //Lines + Shadow + Abstaende 308 void _CalcTop(); 309 void _CalcBottom(); 310 311 void _IsLine(); 312 313 // OD 2004-02-26 #i25029# - add optional 2nd parameter <_pPrevFrm> 314 // If set, its value is taken for testing, if borders/shadow have to joined 315 // with previous frame. 316 void _GetTopLine ( const SwFrm& _rFrm, 317 const SwFrm* _pPrevFrm = 0L ); 318 void _GetBottomLine( const SwFrm& _rFrm ); 319 320 // OD 21.05.2003 #108789# - private methods to calculate cached values 321 // <bJoinedWithPrev> and <bJoinedWithNext>. 322 // OD 2004-02-26 #i25029# - add optional 2nd parameter <_pPrevFrm> 323 // If set, its value is taken for testing, if borders/shadow have to joined 324 // with previous frame. 325 void _CalcJoinedWithPrev( const SwFrm& _rFrm, 326 const SwFrm* _pPrevFrm = 0L ); 327 void _CalcJoinedWithNext( const SwFrm& _rFrm ); 328 329 // OD 21.05.2003 #108789# - internal helper method for methods 330 // <_CalcJoinedWithPrev> and <_CalcJoinedWithNext>. 331 sal_Bool _JoinWithCmp( const SwFrm& _rCallerFrm, 332 const SwFrm& _rCmpFrm ) const; 333 334 //Rechte und linke Linie sowie LRSpace gleich? 335 // OD 21.05.2003 #108789# - change name of 1st parameter - "rAttrs" -> "rCmpAttrs". 336 sal_Bool CmpLeftRight( const SwBorderAttrs &rCmpAttrs, 337 const SwFrm *pCaller, 338 const SwFrm *pCmp ) const; 339 340 public: 341 DECL_FIXEDMEMPOOL_NEWDEL(SwBorderAttrs) 342 343 SwBorderAttrs( const SwModify *pOwner, const SwFrm *pConstructor ); 344 ~SwBorderAttrs(); 345 346 inline const SwAttrSet &GetAttrSet() const { return rAttrSet; } 347 inline const SvxULSpaceItem &GetULSpace() const { return rUL; } 348 inline const SvxLRSpaceItem &GetLRSpace() const { return rLR; } 349 inline const SvxBoxItem &GetBox() const { return rBox; } 350 inline const SvxShadowItem &GetShadow() const { return rShadow; } 351 352 inline sal_uInt16 CalcTopLine() const; 353 inline sal_uInt16 CalcBottomLine() const; 354 inline sal_uInt16 CalcLeftLine() const; 355 inline sal_uInt16 CalcRightLine() const; 356 inline sal_uInt16 CalcTop() const; 357 inline sal_uInt16 CalcBottom() const; 358 long CalcLeft( const SwFrm *pCaller ) const; 359 long CalcRight( const SwFrm *pCaller ) const; 360 361 inline sal_Bool IsLine() const; 362 363 inline const Size &GetSize() const { return aFrmSize; } 364 365 inline sal_Bool IsBorderDist() const { return bBorderDist; } 366 367 //Sollen obere bzw. untere Umrandung fuer den Frm ausgewertet werden? 368 // OD 2004-02-26 #i25029# - add optional 2nd parameter <_pPrevFrm> 369 // If set, its value is taken for testing, if borders/shadow have to joined 370 // with previous frame. 371 inline sal_uInt16 GetTopLine ( const SwFrm& _rFrm, 372 const SwFrm* _pPrevFrm = 0L ) const; 373 inline sal_uInt16 GetBottomLine( const SwFrm& _rFrm ) const; 374 inline void SetGetCacheLine( sal_Bool bNew ) const; 375 // OD 21.05.2003 #108789# - accessors for cached values <bJoinedWithPrev> 376 // and <bJoinedWithPrev> 377 // OD 2004-02-26 #i25029# - add optional 2nd parameter <_pPrevFrm> 378 // If set, its value is taken for testing, if borders/shadow have to joined 379 // with previous frame. 380 sal_Bool JoinedWithPrev( const SwFrm& _rFrm, 381 const SwFrm* _pPrevFrm = 0L ) const; 382 sal_Bool JoinedWithNext( const SwFrm& _rFrm ) const; 383 }; 384 385 class SwBorderAttrAccess : public SwCacheAccess 386 { 387 const SwFrm *pConstructor; //opt: Zur weitergabe an SwBorderAttrs 388 protected: 389 virtual SwCacheObj *NewObj(); 390 391 public: 392 SwBorderAttrAccess( SwCache &rCache, const SwFrm *pOwner ); 393 394 SwBorderAttrs *Get(); 395 }; 396 397 //--------------------------------------------------------------------- 398 //Iterator fuer die DrawObjecte einer Seite. Die Objecte werden Nach ihrer 399 //Z-Order iteriert. 400 //Das iterieren ist nicht eben billig, denn fuer alle Operationen muss jeweils 401 //ueber das gesamte SortArray iteriert werden. 402 class SwOrderIter 403 { 404 const SwPageFrm *pPage; 405 const SdrObject *pCurrent; 406 const sal_Bool bFlysOnly; 407 public: 408 SwOrderIter( const SwPageFrm *pPage, sal_Bool bFlysOnly = sal_True ); 409 410 void Current( const SdrObject *pNew ) { pCurrent = pNew; } 411 const SdrObject *Current() const { return pCurrent; } 412 const SdrObject *operator()() const { return pCurrent; } 413 const SdrObject *Top(); 414 const SdrObject *Bottom(); 415 const SdrObject *Next(); 416 const SdrObject *Prev(); 417 }; 418 419 420 class StackHack 421 { 422 static sal_uInt8 nCnt; 423 static sal_Bool bLocked; 424 public: 425 StackHack() 426 { 427 if ( ++StackHack::nCnt > 50 ) 428 StackHack::bLocked = sal_True; 429 } 430 ~StackHack() 431 { 432 if ( --StackHack::nCnt < 5 ) 433 StackHack::bLocked = sal_False; 434 } 435 436 static sal_Bool IsLocked() { return StackHack::bLocked; } 437 static sal_uInt8 Count() { return StackHack::nCnt; } 438 }; 439 440 441 //Sollen obere bzw. untere Umrandung fuer den Frm ausgewertet werden? 442 // OD 2004-02-26 #i25029# - add optional 2nd parameter <_pPrevFrm> 443 // If set, its value is taken for testing, if borders/shadow have to joined 444 // with previous frame. 445 inline sal_uInt16 SwBorderAttrs::GetTopLine ( const SwFrm& _rFrm, 446 const SwFrm* _pPrevFrm ) const 447 { 448 if ( !bCachedGetTopLine || _pPrevFrm ) 449 { 450 const_cast<SwBorderAttrs*>(this)->_GetTopLine( _rFrm, _pPrevFrm ); 451 } 452 return nGetTopLine; 453 } 454 inline sal_uInt16 SwBorderAttrs::GetBottomLine( const SwFrm& _rFrm ) const 455 { 456 if ( !bCachedGetBottomLine ) 457 const_cast<SwBorderAttrs*>(this)->_GetBottomLine( _rFrm ); 458 return nGetBottomLine; 459 } 460 inline void SwBorderAttrs::SetGetCacheLine( sal_Bool bNew ) const 461 { 462 ((SwBorderAttrs*)this)->bCacheGetLine = bNew; 463 ((SwBorderAttrs*)this)->bCachedGetBottomLine = 464 ((SwBorderAttrs*)this)->bCachedGetTopLine = sal_False; 465 // OD 21.05.2003 #108789# - invalidate cache for values <bJoinedWithPrev> 466 // and <bJoinedWithNext>. 467 bCachedJoinedWithPrev = sal_False; 468 bCachedJoinedWithNext = sal_False; 469 } 470 471 inline sal_uInt16 SwBorderAttrs::CalcTopLine() const 472 { 473 if ( bTopLine ) 474 ((SwBorderAttrs*)this)->_CalcTopLine(); 475 return nTopLine; 476 } 477 inline sal_uInt16 SwBorderAttrs::CalcBottomLine() const 478 { 479 if ( bBottomLine ) 480 ((SwBorderAttrs*)this)->_CalcBottomLine(); 481 return nBottomLine; 482 } 483 inline sal_uInt16 SwBorderAttrs::CalcLeftLine() const 484 { 485 if ( bLeftLine ) 486 ((SwBorderAttrs*)this)->_CalcLeftLine(); 487 return nLeftLine; 488 } 489 inline sal_uInt16 SwBorderAttrs::CalcRightLine() const 490 { 491 if ( bRightLine ) 492 ((SwBorderAttrs*)this)->_CalcRightLine(); 493 return nRightLine; 494 } 495 inline sal_uInt16 SwBorderAttrs::CalcTop() const 496 { 497 if ( bTop ) 498 ((SwBorderAttrs*)this)->_CalcTop(); 499 return nTop; 500 } 501 inline sal_uInt16 SwBorderAttrs::CalcBottom() const 502 { 503 if ( bBottom ) 504 ((SwBorderAttrs*)this)->_CalcBottom(); 505 return nBottom; 506 } 507 inline sal_Bool SwBorderAttrs::IsLine() const 508 { 509 if ( bLine ) 510 ((SwBorderAttrs*)this)->_IsLine(); 511 return bIsLine; 512 } 513 514 /** method to determine the spacing values of a frame 515 516 OD 2004-03-10 #i28701# 517 Values only provided for flow frames (table, section or text frames) 518 Note: line spacing value is only determined for text frames 519 OD 2009-08-28 #i102458# 520 Add output parameter <obIsLineSpacingProportional> 521 522 @param rFrm 523 input parameter - frame, for which the spacing values are determined. 524 525 @param onPrevLowerSpacing 526 output parameter - lower spacing of the frame in SwTwips 527 528 @param onPrevLineSpacing 529 output parameter - line spacing of the frame in SwTwips 530 531 @param obIsLineSpacingProportional 532 533 @author OD 534 */ 535 void GetSpacingValuesOfFrm( const SwFrm& rFrm, 536 SwTwips& onLowerSpacing, 537 SwTwips& onLineSpacing, 538 bool& obIsLineSpacingProportional ); 539 540 /** method to get the content of the table cell 541 542 Content from any nested tables will be omitted. 543 Note: line spacing value is only determined for text frames 544 545 @param rCell_ 546 input parameter - the cell which should be searched for content. 547 548 return 549 pointer to the found content frame or 0 550 */ 551 552 const SwCntntFrm* GetCellCntnt( const SwLayoutFrm& rCell_ ); 553 554 555 /** helper class to check if a frame has been deleted during an operation 556 * !!!WARNING!!! This should only be used as a last and desperate means 557 * to make the code robust. 558 */ 559 560 class SwDeletionChecker 561 { 562 private: 563 564 const SwFrm* mpFrm; 565 const SwModify* mpRegIn; 566 567 public: 568 569 SwDeletionChecker( const SwFrm* pFrm ) 570 : mpFrm( pFrm ), 571 mpRegIn( pFrm ? const_cast<SwFrm*>(pFrm)->GetRegisteredIn() : 0 ) 572 { 573 } 574 575 /** 576 * return 577 * true if mpFrm != 0 and mpFrm is not client of pRegIn 578 * false otherwise 579 */ 580 bool HasBeenDeleted(); 581 }; 582 583 #endif //_FRMTOOL_HXX 584