Update ooo320-m1
[ooovba.git] / sw / source / core / inc / frmtool.hxx
blob199be26f58102694fd5ab8469f88efb3570c3fcd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: frmtool.hxx,v $
10 * $Revision: 1.28 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _FRMTOOL_HXX
31 #define _FRMTOOL_HXX
32 #include "swtypes.hxx"
33 #include "layfrm.hxx"
34 #include "frmatr.hxx"
35 #include "swcache.hxx"
36 // --> OD 2008-12-04 #i96772#
37 #include <svx/lrspitem.hxx>
38 // <--
40 class SwPageFrm;
41 class SwFlyFrm;
42 class SwCntntFrm;
43 class SwDoc;
44 class SwAttrSet;
45 class SdrObject;
46 class BigInt;
47 class SvxBrushItem;
48 class SdrMarkList;
49 class SwNodeIndex;
50 class OutputDevice;
51 class SwPageDesc;
52 class SwTableBox;
53 struct SwFindRowSpanCacheObj;
55 #if defined(MSC)
56 #define MA_FASTCALL __fastcall
57 #else
58 #define MA_FASTCALL
59 #endif
61 #define WEIT_WECH LONG_MAX - 20000 //Initale Position der Flys.
62 #define BROWSE_HEIGHT 56700L * 10L //10 Meter
63 //#define BROWSE_HEIGHT 1440L * 45L // 45 inch, maximum size for pdf files
65 #define GRFNUM_NO 0
66 #define GRFNUM_YES 1
67 #define GRFNUM_REPLACE 2
69 //Painten des Hintergrunds. Mit Brush oder Graphic.
70 // OD 05.08.2002 #99657# - add 6th parameter to indicate that method should
71 // consider background transparency, saved in the color of the brush item
72 void MA_FASTCALL DrawGraphic( const SvxBrushItem *, OutputDevice *,
73 const SwRect &rOrg, const SwRect &rOut, const BYTE nGrfNum = GRFNUM_NO,
74 const sal_Bool bConsiderBackgroundTransparency = sal_False );
76 // OD 24.01.2003 #106593# - method to align rectangle
77 // Created declaration here to avoid <extern> declarations
78 void MA_FASTCALL SwAlignRect( SwRect &rRect, ViewShell *pSh );
80 // OD 24.01.2003 #106593# - method to align graphic rectangle
81 // Created declaration here to avoid <extern> declarations
82 void SwAlignGrfRect( SwRect *pGrfRect, const OutputDevice &rOut );
84 //Fly besorgen, wenn keine List hineingereicht wird, wir die der aktuellen
85 //Shell benutzt.
86 //Implementierung in feshview.cxx
87 SwFlyFrm *GetFlyFromMarked( const SdrMarkList *pLst, ViewShell *pSh );
89 //Nicht gleich die math.lib anziehen.
90 ULONG MA_FASTCALL SqRt( BigInt nX );
92 SwFrm *SaveCntnt( SwLayoutFrm *pLay, SwFrm *pStart );
93 void RestoreCntnt( SwFrm *pSav, SwLayoutFrm *pParent, SwFrm *pSibling, bool bGrow );
95 //CntntNodes besorgen, CntntFrms erzeugen und in den LayFrm haengen.
96 void MA_FASTCALL _InsertCnt( SwLayoutFrm *pLay, SwDoc *pDoc, ULONG nIndex,
97 BOOL bPages = FALSE, ULONG nEndIndex = 0,
98 SwFrm *pPrv = 0 );
100 //Erzeugen der Frames fuer einen bestimmten Bereich, verwendet _InsertCnt
101 void MakeFrms( SwDoc *pDoc, const SwNodeIndex &rSttIdx,
102 const SwNodeIndex &rEndIdx );
104 //Um z.B. fuer Tabelleheadlines das Erzeugen der Flys in _InsertCnt zu unterbinden.
105 extern BOOL bDontCreateObjects;
107 //Fuer FlyCnts, siehe SwFlyAtCntFrm::MakeAll()
108 extern BOOL bSetCompletePaintOnInvalidate;
110 //Fuer Tabelleneinstellung per Tastatur.
111 long MA_FASTCALL CalcRowRstHeight( SwLayoutFrm *pRow );
112 long MA_FASTCALL CalcHeightWidthFlys( const SwFrm *pFrm ); //MA_FLY_HEIGHT
114 //Neue Seite einsetzen
115 SwPageFrm * MA_FASTCALL InsertNewPage( SwPageDesc &rDesc, SwFrm *pUpper,
116 BOOL bOdd, BOOL bInsertEmpty, BOOL bFtn,
117 SwFrm *pSibling );
119 //Flys bei der Seite anmelden.
120 void RegistFlys( SwPageFrm*, const SwLayoutFrm* );
122 //Benachrichtung des Fly Hintergrundes wenn Notwendig.
123 void Notify( SwFlyFrm *pFly, SwPageFrm *pOld, const SwRect &rOld,
124 const SwRect* pOldRect = 0 );
126 void Notify_Background( const SdrObject* pObj,
127 SwPageFrm* pPage,
128 const SwRect& rRect,
129 const PrepareHint eHint,
130 const BOOL bInva );
132 const SwFrm* GetVirtualUpper( const SwFrm* pFrm, const Point& rPos );
134 BOOL Is_Lower_Of( const SwFrm *pCurrFrm, const SdrObject* pObj );
136 const SwFrm *FindKontext( const SwFrm *pFrm, USHORT nAdditionalKontextTyp );
138 BOOL IsFrmInSameKontext( const SwFrm *pInnerFrm, const SwFrm *pFrm );
140 const SwFrm * MA_FASTCALL FindPage( const SwRect &rRect, const SwFrm *pPage );
142 // JP 07.05.98: wird von SwCntntNode::GetFrm und von SwFlyFrm::GetFrm
143 // gerufen
144 SwFrm* GetFrmOfModify( SwModify&, USHORT nFrmType, const Point* = 0,
145 const SwPosition *pPos = 0,
146 const BOOL bCalcFrm = FALSE );
148 //Sollen ExtraDaten (Reline-Strich, Zeilennummern) gepaintet werden?
149 BOOL IsExtraData( const SwDoc *pDoc );
151 // OD 14.03.2003 #i11760# - method declaration <CalcCntnt(..)>
152 void CalcCntnt( SwLayoutFrm *pLay,
153 bool bNoColl = false,
154 bool bNoCalcFollow = false );
157 //Die Notify-Klassen merken sich im CTor die aktuellen Groessen und fuehren
158 //im DTor ggf. die notwendigen Benachrichtigungen durch.
160 class SwFrmNotify
162 protected:
163 SwFrm *pFrm;
164 const SwRect aFrm;
165 const SwRect aPrt;
166 SwTwips mnFlyAnchorOfst;
167 SwTwips mnFlyAnchorOfstNoWrap;
168 BOOL bHadFollow;
169 BOOL bInvaKeep;
170 BOOL bValidSize;
171 protected:
172 // --> OD 2005-07-29 #i49383#
173 bool mbFrmDeleted;
174 // <--
176 public:
177 SwFrmNotify( SwFrm *pFrm );
178 ~SwFrmNotify();
180 const SwRect &Frm() const { return aFrm; }
181 const SwRect &Prt() const { return aPrt; }
182 void SetInvaKeep() { bInvaKeep = TRUE; }
183 // --> OD 2005-07-29 #i49383#
184 void FrmDeleted()
186 mbFrmDeleted = true;
188 // <--
191 class SwLayNotify : public SwFrmNotify
193 BOOL bLowersComplete;
195 SwLayoutFrm *GetLay() { return (SwLayoutFrm*)pFrm; }
196 public:
197 SwLayNotify( SwLayoutFrm *pLayFrm );
198 ~SwLayNotify();
200 void SetLowersComplete( BOOL b ) { bLowersComplete = b; }
201 BOOL IsLowersComplete() { return bLowersComplete; }
204 class SwFlyNotify : public SwLayNotify
206 SwPageFrm *pOldPage;
207 const SwRect aFrmAndSpace;
208 SwFlyFrm *GetFly() { return (SwFlyFrm*)pFrm; }
209 public:
210 SwFlyNotify( SwFlyFrm *pFlyFrm );
211 ~SwFlyNotify();
213 SwPageFrm *GetOldPage() const { return pOldPage; }
216 class SwCntntNotify : public SwFrmNotify
218 private:
219 // OD 08.01.2004 #i11859#
220 bool mbChkHeightOfLastLine;
221 SwTwips mnHeightOfLastLine;
223 // OD 2004-02-26 #i25029#
224 bool mbInvalidatePrevPrtArea;
225 bool mbBordersJoinedWithPrev;
227 SwCntntFrm *GetCnt() { return (SwCntntFrm*)pFrm; }
229 public:
230 SwCntntNotify( SwCntntFrm *pCntFrm );
231 ~SwCntntNotify();
233 // OD 2004-02-26 #i25029#
234 void SetInvalidatePrevPrtArea()
236 mbInvalidatePrevPrtArea = true;
239 void SetBordersJoinedWithPrev()
241 mbBordersJoinedWithPrev = true;
245 //SwBorderAttrs kapselt die Berechnung fuer die Randattribute inclusive
246 //Umrandung. Die Attribute und die errechneten Werte werden gecached.
247 //Neu: Die gesammte Klasse wird gecached.
249 //!!!Achtung: Wenn weitere Attribute gecached werden muss unbedingt die
250 //Methode Modify::Modify mitgepflegt werden!!!
252 // OD 23.01.2003 #106895# - delete old method <SwBorderAttrs::CalcRight()> and
253 // the stuff that belongs to it.
254 class SwBorderAttrs : public SwCacheObj
256 const SwAttrSet &rAttrSet;
257 const SvxULSpaceItem &rUL;
258 // --> OD 2008-12-04 #i96772#
259 SvxLRSpaceItem rLR;
260 // <--
261 const SvxBoxItem &rBox;
262 const SvxShadowItem &rShadow;
263 const Size aFrmSize; //Die FrmSize
265 BOOL bBorderDist :1; //Ist's ein Frm der auch ohne Linie
266 //einen Abstand haben kann?
268 //Mit den Folgenden Bools werden die gecache'ten Werte fuer UNgueltig
269 //erklaert - bis sie einmal berechnet wurden.
270 BOOL bTopLine :1;
271 BOOL bBottomLine :1;
272 BOOL bLeftLine :1;
273 BOOL bRightLine :1;
274 BOOL bTop :1;
275 BOOL bBottom :1;
276 BOOL bLine :1;
278 BOOL bIsLine :1; //Umrandung an mind. einer Kante?
280 BOOL bCacheGetLine :1; //GetTopLine(), GetBottomLine() cachen?
281 BOOL bCachedGetTopLine :1; //GetTopLine() gecached?
282 BOOL bCachedGetBottomLine :1; //GetBottomLine() gecached?
283 // OD 21.05.2003 #108789# - booleans indicating, if values <bJoinedWithPrev>
284 // and <bJoinedWithNext> are cached and valid.
285 // Caching depends on value of <bCacheGetLine>.
286 mutable BOOL bCachedJoinedWithPrev :1;
287 mutable BOOL bCachedJoinedWithNext :1;
288 // OD 21.05.2003 #108789# - booleans indicating, if borders are joined
289 // with previous/next frame.
290 BOOL bJoinedWithPrev :1;
291 BOOL bJoinedWithNext :1;
293 //Die gecache'ten Werte, undefiniert bis sie einmal berechnet wurden.
294 USHORT nTopLine,
295 nBottomLine,
296 nLeftLine,
297 nRightLine,
298 nTop,
299 nBottom,
300 nGetTopLine,
301 nGetBottomLine;
303 //Nur die Lines + Shadow errechnen.
304 void _CalcTopLine();
305 void _CalcBottomLine();
306 void _CalcLeftLine();
307 void _CalcRightLine();
309 //Lines + Shadow + Abstaende
310 void _CalcTop();
311 void _CalcBottom();
313 void _IsLine();
315 // OD 2004-02-26 #i25029# - add optional 2nd parameter <_pPrevFrm>
316 // If set, its value is taken for testing, if borders/shadow have to joined
317 // with previous frame.
318 void _GetTopLine ( const SwFrm& _rFrm,
319 const SwFrm* _pPrevFrm = 0L );
320 void _GetBottomLine( const SwFrm& _rFrm );
322 // OD 21.05.2003 #108789# - private methods to calculate cached values
323 // <bJoinedWithPrev> and <bJoinedWithNext>.
324 // OD 2004-02-26 #i25029# - add optional 2nd parameter <_pPrevFrm>
325 // If set, its value is taken for testing, if borders/shadow have to joined
326 // with previous frame.
327 void _CalcJoinedWithPrev( const SwFrm& _rFrm,
328 const SwFrm* _pPrevFrm = 0L );
329 void _CalcJoinedWithNext( const SwFrm& _rFrm );
331 // OD 21.05.2003 #108789# - internal helper method for methods
332 // <_CalcJoinedWithPrev> and <_CalcJoinedWithNext>.
333 BOOL _JoinWithCmp( const SwFrm& _rCallerFrm,
334 const SwFrm& _rCmpFrm ) const;
336 //Rechte und linke Linie sowie LRSpace gleich?
337 // OD 21.05.2003 #108789# - change name of 1st parameter - "rAttrs" -> "rCmpAttrs".
338 BOOL CmpLeftRight( const SwBorderAttrs &rCmpAttrs,
339 const SwFrm *pCaller,
340 const SwFrm *pCmp ) const;
342 public:
343 DECL_FIXEDMEMPOOL_NEWDEL(SwBorderAttrs)
345 SwBorderAttrs( const SwModify *pOwner, const SwFrm *pConstructor );
346 ~SwBorderAttrs();
348 inline const SwAttrSet &GetAttrSet() const { return rAttrSet; }
349 inline const SvxULSpaceItem &GetULSpace() const { return rUL; }
350 inline const SvxLRSpaceItem &GetLRSpace() const { return rLR; }
351 inline const SvxBoxItem &GetBox() const { return rBox; }
352 inline const SvxShadowItem &GetShadow() const { return rShadow; }
354 inline USHORT CalcTopLine() const;
355 inline USHORT CalcBottomLine() const;
356 inline USHORT CalcLeftLine() const;
357 inline USHORT CalcRightLine() const;
358 inline USHORT CalcTop() const;
359 inline USHORT CalcBottom() const;
360 long CalcLeft( const SwFrm *pCaller ) const;
361 long CalcRight( const SwFrm *pCaller ) const;
363 inline BOOL IsLine() const;
365 inline const Size &GetSize() const { return aFrmSize; }
367 inline BOOL IsBorderDist() const { return bBorderDist; }
369 //Sollen obere bzw. untere Umrandung fuer den Frm ausgewertet werden?
370 // OD 2004-02-26 #i25029# - add optional 2nd parameter <_pPrevFrm>
371 // If set, its value is taken for testing, if borders/shadow have to joined
372 // with previous frame.
373 inline USHORT GetTopLine ( const SwFrm& _rFrm,
374 const SwFrm* _pPrevFrm = 0L ) const;
375 inline USHORT GetBottomLine( const SwFrm& _rFrm ) const;
376 inline void SetGetCacheLine( BOOL bNew ) const;
377 // OD 21.05.2003 #108789# - accessors for cached values <bJoinedWithPrev>
378 // and <bJoinedWithPrev>
379 // OD 2004-02-26 #i25029# - add optional 2nd parameter <_pPrevFrm>
380 // If set, its value is taken for testing, if borders/shadow have to joined
381 // with previous frame.
382 BOOL JoinedWithPrev( const SwFrm& _rFrm,
383 const SwFrm* _pPrevFrm = 0L ) const;
384 BOOL JoinedWithNext( const SwFrm& _rFrm ) const;
387 class SwBorderAttrAccess : public SwCacheAccess
389 const SwFrm *pConstructor; //opt: Zur weitergabe an SwBorderAttrs
390 protected:
391 virtual SwCacheObj *NewObj();
393 public:
394 SwBorderAttrAccess( SwCache &rCache, const SwFrm *pOwner );
396 SwBorderAttrs *Get();
399 //---------------------------------------------------------------------
400 //Iterator fuer die DrawObjecte einer Seite. Die Objecte werden Nach ihrer
401 //Z-Order iteriert.
402 //Das iterieren ist nicht eben billig, denn fuer alle Operationen muss jeweils
403 //ueber das gesamte SortArray iteriert werden.
404 class SwOrderIter
406 const SwPageFrm *pPage;
407 const SdrObject *pCurrent;
408 const BOOL bFlysOnly;
409 public:
410 SwOrderIter( const SwPageFrm *pPage, BOOL bFlysOnly = TRUE );
412 void Current( const SdrObject *pNew ) { pCurrent = pNew; }
413 const SdrObject *Current() const { return pCurrent; }
414 const SdrObject *operator()() const { return pCurrent; }
415 const SdrObject *Top();
416 const SdrObject *Bottom();
417 const SdrObject *Next();
418 const SdrObject *Prev();
422 class StackHack
424 static BYTE nCnt;
425 static BOOL bLocked;
426 public:
427 StackHack()
429 if ( ++StackHack::nCnt > 50 )
430 StackHack::bLocked = TRUE;
432 ~StackHack()
434 if ( --StackHack::nCnt < 5 )
435 StackHack::bLocked = FALSE;
438 static BOOL IsLocked() { return StackHack::bLocked; }
439 static BYTE Count() { return StackHack::nCnt; }
443 //Sollen obere bzw. untere Umrandung fuer den Frm ausgewertet werden?
444 // OD 2004-02-26 #i25029# - add optional 2nd parameter <_pPrevFrm>
445 // If set, its value is taken for testing, if borders/shadow have to joined
446 // with previous frame.
447 inline USHORT SwBorderAttrs::GetTopLine ( const SwFrm& _rFrm,
448 const SwFrm* _pPrevFrm ) const
450 if ( !bCachedGetTopLine || _pPrevFrm )
452 const_cast<SwBorderAttrs*>(this)->_GetTopLine( _rFrm, _pPrevFrm );
454 return nGetTopLine;
456 inline USHORT SwBorderAttrs::GetBottomLine( const SwFrm& _rFrm ) const
458 if ( !bCachedGetBottomLine )
459 const_cast<SwBorderAttrs*>(this)->_GetBottomLine( _rFrm );
460 return nGetBottomLine;
462 inline void SwBorderAttrs::SetGetCacheLine( BOOL bNew ) const
464 ((SwBorderAttrs*)this)->bCacheGetLine = bNew;
465 ((SwBorderAttrs*)this)->bCachedGetBottomLine =
466 ((SwBorderAttrs*)this)->bCachedGetTopLine = FALSE;
467 // OD 21.05.2003 #108789# - invalidate cache for values <bJoinedWithPrev>
468 // and <bJoinedWithNext>.
469 bCachedJoinedWithPrev = FALSE;
470 bCachedJoinedWithNext = FALSE;
473 inline USHORT SwBorderAttrs::CalcTopLine() const
475 if ( bTopLine )
476 ((SwBorderAttrs*)this)->_CalcTopLine();
477 return nTopLine;
479 inline USHORT SwBorderAttrs::CalcBottomLine() const
481 if ( bBottomLine )
482 ((SwBorderAttrs*)this)->_CalcBottomLine();
483 return nBottomLine;
485 inline USHORT SwBorderAttrs::CalcLeftLine() const
487 if ( bLeftLine )
488 ((SwBorderAttrs*)this)->_CalcLeftLine();
489 return nLeftLine;
491 inline USHORT SwBorderAttrs::CalcRightLine() const
493 if ( bRightLine )
494 ((SwBorderAttrs*)this)->_CalcRightLine();
495 return nRightLine;
497 inline USHORT SwBorderAttrs::CalcTop() const
499 if ( bTop )
500 ((SwBorderAttrs*)this)->_CalcTop();
501 return nTop;
503 inline USHORT SwBorderAttrs::CalcBottom() const
505 if ( bBottom )
506 ((SwBorderAttrs*)this)->_CalcBottom();
507 return nBottom;
509 inline BOOL SwBorderAttrs::IsLine() const
511 if ( bLine )
512 ((SwBorderAttrs*)this)->_IsLine();
513 return bIsLine;
516 /** method to determine the spacing values of a frame
518 OD 2004-03-10 #i28701#
519 Values only provided for flow frames (table, section or text frames)
520 Note: line spacing value is only determined for text frames
521 OD 2009-08-28 #i102458#
522 Add output parameter <obIsLineSpacingProportional>
524 @param rFrm
525 input parameter - frame, for which the spacing values are determined.
527 @param onPrevLowerSpacing
528 output parameter - lower spacing of the frame in SwTwips
530 @param onPrevLineSpacing
531 output parameter - line spacing of the frame in SwTwips
533 @param obIsLineSpacingProportional
535 @author OD
537 void GetSpacingValuesOfFrm( const SwFrm& rFrm,
538 SwTwips& onLowerSpacing,
539 SwTwips& onLineSpacing,
540 bool& obIsLineSpacingProportional );
542 /** method to get the content of the table cell
544 Content from any nested tables will be omitted.
545 Note: line spacing value is only determined for text frames
547 @param rCell_
548 input parameter - the cell which should be searched for content.
550 return
551 pointer to the found content frame or 0
554 const SwCntntFrm* GetCellCntnt( const SwLayoutFrm& rCell_ );
557 /** helper class to check if a frame has been deleted during an operation
558 * !!!WARNING!!! This should only be used as a last and desperate means
559 * to make the code robust.
562 class SwDeletionChecker
564 private:
566 const SwFrm* mpFrm;
567 const SwModify* mpRegIn;
569 public:
571 SwDeletionChecker( const SwFrm* pFrm )
572 : mpFrm( pFrm ),
573 mpRegIn( pFrm ? pFrm->GetRegisteredIn() : 0 )
578 * return
579 * true if mpFrm != 0 and mpFrm is not client of pRegIn
580 * false otherwise
582 bool HasBeenDeleted();
585 #endif //_FRMTOOL_HXX