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