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