xref: /aoo42x/main/sw/source/core/text/txtfly.hxx (revision cdf0e10c)
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 _TXTFLY_HXX
28 #define _TXTFLY_HXX
29 #include <svl/svarray.hxx>
30 
31 #include "swtypes.hxx"
32 #include "swrect.hxx"
33 
34 class OutputDevice;
35 class SwCntntFrm;
36 class SwPageFrm;
37 class SwTxtFly;
38 class SdrObject;
39 class SwTxtPaintInfo;
40 class SwFmt;
41 class TextRanger;
42 class Color;
43 // --> OD 2004-10-06 #i26945#
44 class SwAnchoredObject;
45 // <--
46 
47 // --> OD 2006-08-15 #i68520# - refactoring
48 //typedef MSHORT _FlyCntnt;
49 #include <fmtsrndenum.hxx>
50 // <--
51 
52 // --> OD 2006-08-15 #i68520#
53 //SV_DECL_PTRARR( SwFlyList, SdrObject*, 10, 10 )
54 #include <vector>
55 typedef std::vector< SwAnchoredObject* > SwAnchoredObjList;
56 // <--
57 
58 /*************************************************************************
59  *						class SwFlyIter
60  *************************************************************************/
61 enum PAGESIDE { LEFT_SIDE, RIGHT_SIDE, DONTKNOW_SIDE };
62 
63 /*************************************************************************
64  *						class SwContourCache
65  *************************************************************************/
66 
67 class SwDrawTextInfo;
68 // Contour-Cache, globale Variable, in txtinit.cxx initialisiert/zerstoert
69 // und in txtfly.cxx benutzt bei Konturumfluss
70 class SwContourCache;
71 extern SwContourCache *pContourCache;
72 class SwTxtFrm;
73 
74 #define POLY_CNT 20
75 #define POLY_MIN 5
76 #define POLY_MAX 4000
77 
78 class SwContourCache
79 {
80 	friend void ClrContourCache();
81 	const SdrObject *pSdrObj[ POLY_CNT ];
82 	TextRanger *pTextRanger[ POLY_CNT ];
83 	long nPntCnt;
84 	MSHORT nObjCnt;
85     const SwRect ContourRect( const SwFmt* pFmt, const SdrObject* pObj,
86         const SwTxtFrm* pFrm, const SwRect &rLine, const long nXPos,
87         const sal_Bool bRight );
88 
89 public:
90 	SwContourCache();
91 	~SwContourCache();
92 	const SdrObject* GetObject( MSHORT nPos ){ return pSdrObj[ nPos ]; }
93 	MSHORT GetCount() const { return nObjCnt; }
94 	void ClrObject( MSHORT nPos );
95     // --> OD 2006-08-15 #i68520#
96     static const SwRect CalcBoundRect( const SwAnchoredObject* pAnchoredObj,
97                                        const SwRect &rLine,
98                                        const SwTxtFrm* pFrm,
99                                        const long nXPos,
100                                        const sal_Bool bRight );
101     // <--
102 #ifdef DBG_UTIL
103 	void ShowContour( OutputDevice* pOut, const SdrObject* pObj,
104 					  const Color& rClosedColor, const Color& rOpenColor );
105 #endif
106 };
107 
108 /*************************************************************************
109  *						class SwTxtFly
110  *************************************************************************/
111 
112 class SwTxtFly
113 {
114 	const SwPageFrm		*pPage;
115     // --> OD 2006-08-15 #i68520#
116     const SwAnchoredObject* mpCurrAnchoredObj;
117     // <--
118 
119     const SwTxtFrm      *pCurrFrm;
120 
121 	const SwCntntFrm	*pMaster;
122     // --> OD 2006-08-15 #i68520#
123     SwAnchoredObjList* mpAnchoredObjList;
124     // <--
125 
126 	long nMinBottom;
127 	long nNextTop; // Hier wird die Oberkante des "naechsten" Rahmens gespeichert
128 	sal_uLong nIndex;
129 	sal_Bool bOn : 1;
130 	sal_Bool bLeftSide : 1;
131 	sal_Bool bTopRule: 1;
132     sal_Bool mbIgnoreCurrentFrame: 1;
133     sal_Bool mbIgnoreContour: 1;
134     // --> OD 2004-12-17 #118809# - boolean, indicating if objects in page
135     // header|footer are considered for text frames not in page header|footer.
136     sal_Bool mbIgnoreObjsInHeaderFooter: 1;
137     // <--
138 	SwRect _GetFrm( const SwRect &rPortion, sal_Bool bTop ) const;
139     // --> OD 2006-08-15 #i68520#
140     SwAnchoredObjList* InitAnchoredObjList();
141     inline SwAnchoredObjList* GetAnchoredObjList() const
142     {
143         return mpAnchoredObjList
144                ? mpAnchoredObjList
145                : const_cast<SwTxtFly*>(this)->InitAnchoredObjList();
146     }
147     // iterates over the anchored object list <mpAnchoredObjList>
148 	sal_Bool ForEach( const SwRect &rRect, SwRect* pRect, sal_Bool bAvoid ) const;
149     SwSurround _GetSurroundForTextWrap( const SwAnchoredObject* pAnchoredObj ) const;
150     void CalcRightMargin( SwRect &rFly,
151                           SwAnchoredObjList::size_type nPos,
152                           const SwRect &rLine ) const;
153     void CalcLeftMargin( SwRect &rFly,
154                          SwAnchoredObjList::size_type nPos,
155                          const SwRect &rLine ) const;
156     SwAnchoredObjList::size_type GetPos( const SwAnchoredObject* pAnchoredObj ) const;
157     // <--
158     // --> OD 2004-10-06 #i26945# - change first parameter:
159     // Now it's the <SwAnchoredObject> instance of the floating screen object
160     sal_Bool GetTop( const SwAnchoredObject* _pAnchoredObj,
161                      const sal_Bool bInFtn,
162                      const sal_Bool bInFooterOrHeader );
163     // <--
164 	SwTwips CalcMinBottom() const;
165 	const SwCntntFrm* _GetMaster();
166 
167 public:
168     inline SwTxtFly()
169     {
170         mbIgnoreCurrentFrame = sal_False;
171         mbIgnoreCurrentFrame = sal_False;
172         // --> OD 2004-12-17 #118809#
173         mbIgnoreObjsInHeaderFooter = sal_False;
174         // <--
175         // --> OD 2006-08-15 #i68520#
176         mpCurrAnchoredObj = 0;
177         mpAnchoredObjList = 0;
178         // <--
179         pMaster = 0;
180     }
181     inline SwTxtFly( const SwTxtFrm *pFrm )
182         { CtorInitTxtFly( pFrm ); }
183 
184 	SwTxtFly( const SwTxtFly& rTxtFly );
185     // --> OD 2006-08-15 #i68520#
186     inline ~SwTxtFly() { delete mpAnchoredObjList; }
187     // <--
188     void CtorInitTxtFly( const SwTxtFrm *pFrm );
189 	void SetTopRule(){ bTopRule = sal_False; }
190 
191 	inline SwRect GetFrm( const SwRect &rPortion, sal_Bool bTop = sal_True ) const;
192 	inline sal_Bool IsOn() const { return bOn; }
193 	inline sal_Bool Relax( const SwRect &rRect );
194 	inline sal_Bool Relax();
195 	inline SwTwips GetMinBottom() const
196         // --> OD 2006-08-15 #i68520#
197         { return mpAnchoredObjList ? nMinBottom : CalcMinBottom(); }
198         // <--
199 	inline const SwCntntFrm* GetMaster() const
200 		{ return pMaster ? pMaster : ((SwTxtFly*)this)->_GetMaster(); }
201 	inline long GetNextTop() const { return nNextTop; }
202 	// Diese temporaere Variable darf auch in const-Methoden manipuliert werden
203 	inline void SetNextTop( long nNew ) const
204 		{ ((SwTxtFly*)this)->nNextTop = nNew;	}
205 
206     // --> OD 2006-08-15 #i68520#
207     // determines the demanded rectangle for an anchored object,
208     // considering its surround for text wrapping.
209     SwRect AnchoredObjToRect( const SwAnchoredObject* pAnchoredObj,
210                               const SwRect& rRect ) const;
211     // <--
212 
213 	// Die Drawmethoden stellen sicher, dass ueberlappende Frames
214 	// (ausser bei transparenten Frames) nicht uebergepinselt werden.
215 	sal_Bool DrawTextOpaque( SwDrawTextInfo &rInf );
216 
217     void DrawFlyRect( OutputDevice* pOut, const SwRect &rRect,
218 					  const SwTxtPaintInfo &rInf, sal_Bool bNoGraphic = sal_False );
219 
220 	// Liefert zurueck, ob die Zeile von einem Frame ueberlappt wird.
221 	sal_Bool IsAnyFrm( const SwRect &rLine ) const;
222 	sal_Bool IsAnyFrm() const;
223 	//Das Rechteck kann leer sein, es gilt dann der Frm.
224 	sal_Bool IsAnyObj( const SwRect& ) const;
225 
226     void SetIgnoreCurrentFrame( sal_Bool bNew ) { mbIgnoreCurrentFrame = bNew; }
227     void SetIgnoreContour( sal_Bool bNew ) { mbIgnoreContour = bNew; }
228     // --> OD 2004-12-17 #118809#
229     inline void SetIgnoreObjsInHeaderFooter( const sal_Bool _bNew )
230     {
231         mbIgnoreObjsInHeaderFooter = _bNew;
232     }
233     // <--
234 
235 #ifdef DBG_UTIL
236 	void ShowContour( OutputDevice* pOut );
237 #endif
238 };
239 
240 // Wenn in das rRect (meist die aktuelle Zeile) kein freifliegender
241 // Frame ragt, dann schalten wir uns ab.
242 // rRect ist dokumentglobal !
243 inline sal_Bool SwTxtFly::Relax( const SwRect &rRect )
244 {
245 	return 0 != (bOn = bOn && IsAnyFrm( rRect ));
246 }
247 
248 inline sal_Bool SwTxtFly::Relax()
249 {
250 	return 0 != (bOn = bOn && IsAnyFrm());
251 }
252 
253 inline SwRect SwTxtFly::GetFrm( const SwRect &rRect, sal_Bool bTop ) const
254 {
255 	return bOn ? _GetFrm( rRect, bTop ) : SwRect();
256 }
257 
258 
259 #endif
260