merge the formfield patch from ooo-build
[ooovba.git] / sw / source / core / layout / flyincnt.cxx
blob0efea0085ed3ee50cf83d4bcd4a0cf70bc7a99ff
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: flyincnt.cxx,v $
10 * $Revision: 1.20 $
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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #include "cntfrm.hxx"
35 #include "doc.hxx"
36 #include "flyfrm.hxx"
37 #include "frmtool.hxx"
38 #include "frmfmt.hxx"
39 #include "hints.hxx"
40 #include <fmtornt.hxx>
41 #include <fmtfsize.hxx>
42 #include "txtfrm.hxx" //fuer IsLocked()
43 #include "flyfrms.hxx"
44 // OD 2004-01-19 #110582#
45 #include <dflyobj.hxx>
47 //aus FlyCnt.cxx
48 void DeepCalc( const SwFrm *pFrm );
50 /*************************************************************************
52 |* SwFlyInCntFrm::SwFlyInCntFrm(), ~SwFlyInCntFrm()
54 |* Ersterstellung MA 01. Dec. 92
55 |* Letzte Aenderung MA 09. Apr. 99
57 |*************************************************************************/
58 SwFlyInCntFrm::SwFlyInCntFrm( SwFlyFrmFmt *pFmt, SwFrm *pAnch ) :
59 SwFlyFrm( pFmt, pAnch )
61 bInCnt = bInvalidLayout = bInvalidCntnt = TRUE;
62 SwTwips nRel = pFmt->GetVertOrient().GetPos();
63 // OD 2004-05-27 #i26791# - member <aRelPos> moved to <SwAnchoredObject>
64 Point aRelPos;
65 if( pAnch && pAnch->IsVertical() )
66 aRelPos.X() = pAnch->IsReverse() ? nRel : -nRel;
67 else
68 aRelPos.Y() = nRel;
69 SetCurrRelPos( aRelPos );
72 SwFlyInCntFrm::~SwFlyInCntFrm()
74 //und Tschuess.
75 if ( !GetFmt()->GetDoc()->IsInDtor() && GetAnchorFrm() )
77 SwRect aTmp( GetObjRectWithSpaces() );
78 SwFlyInCntFrm::NotifyBackground( FindPageFrm(), aTmp, PREP_FLY_LEAVE );
82 // --> OD 2004-06-29 #i28701#
83 TYPEINIT1(SwFlyInCntFrm,SwFlyFrm);
84 // <--
85 /*************************************************************************
87 |* SwFlyInCntFrm::SetRefPoint(),
89 |* Ersterstellung MA 01. Dec. 92
90 |* Letzte Aenderung MA 06. Aug. 95
92 |*************************************************************************/
93 void SwFlyInCntFrm::SetRefPoint( const Point& rPoint,
94 const Point& rRelAttr,
95 const Point& rRelPos )
97 // OD 2004-05-27 #i26791# - member <aRelPos> moved to <SwAnchoredObject>
98 ASSERT( rPoint != aRef || rRelAttr != GetCurrRelPos(), "SetRefPoint: no change" );
99 SwFlyNotify *pNotify = NULL;
100 // No notify at a locked fly frame, if a fly frame is locked, there's
101 // already a SwFlyNotify object on the stack (MakeAll).
102 if( !IsLocked() )
103 pNotify = new SwFlyNotify( this );
104 aRef = rPoint;
105 SetCurrRelPos( rRelAttr );
106 SWRECTFN( GetAnchorFrm() )
107 (Frm().*fnRect->fnSetPos)( rPoint + rRelPos );
108 // --> OD 2006-08-25 #i68520#
109 InvalidateObjRectWithSpaces();
110 // <--
111 if( pNotify )
113 InvalidatePage();
114 bValidPos = FALSE;
115 bInvalid = TRUE;
116 Calc();
117 delete pNotify;
121 /*************************************************************************
123 |* SwFlyInCntFrm::Modify()
125 |* Ersterstellung MA 16. Dec. 92
126 |* Letzte Aenderung MA 02. Sep. 93
128 |*************************************************************************/
129 void SwFlyInCntFrm::Modify( SfxPoolItem *pOld, SfxPoolItem *pNew )
131 BOOL bCallPrepare = FALSE;
132 USHORT nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
133 if( RES_ATTRSET_CHG == nWhich )
135 if( SFX_ITEM_SET == ((SwAttrSetChg*)pNew)->GetChgSet()->
136 GetItemState( RES_SURROUND, FALSE ) ||
137 SFX_ITEM_SET == ((SwAttrSetChg*)pNew)->GetChgSet()->
138 GetItemState( RES_FRMMACRO, FALSE ) )
140 SwAttrSetChg aOld( *(SwAttrSetChg*)pOld );
141 SwAttrSetChg aNew( *(SwAttrSetChg*)pNew );
143 aOld.ClearItem( RES_SURROUND );
144 aNew.ClearItem( RES_SURROUND );
145 aOld.ClearItem( RES_FRMMACRO );
146 aNew.ClearItem( RES_FRMMACRO );
147 if( aNew.Count() )
149 SwFlyFrm::Modify( &aOld, &aNew );
150 bCallPrepare = TRUE;
153 else if( ((SwAttrSetChg*)pNew)->GetChgSet()->Count())
155 SwFlyFrm::Modify( pOld, pNew );
156 bCallPrepare = TRUE;
159 else if( nWhich != RES_SURROUND && RES_FRMMACRO != nWhich )
161 SwFlyFrm::Modify( pOld, pNew );
162 bCallPrepare = TRUE;
165 if ( bCallPrepare && GetAnchorFrm() )
166 AnchorFrm()->Prepare( PREP_FLY_ATTR_CHG, GetFmt() );
168 /*************************************************************************
170 |* SwFlyInCntFrm::Format()
172 |* Beschreibung: Hier wird der Inhalt initial mit Formatiert.
173 |* Ersterstellung MA 16. Dec. 92
174 |* Letzte Aenderung MA 19. May. 93
176 |*************************************************************************/
177 void SwFlyInCntFrm::Format( const SwBorderAttrs *pAttrs )
179 if ( !Frm().Height() )
181 Lock(); //nicht hintenherum den Anker formatieren.
182 SwCntntFrm *pCntnt = ContainsCntnt();
183 while ( pCntnt )
184 { pCntnt->Calc();
185 pCntnt = pCntnt->GetNextCntntFrm();
187 Unlock();
189 SwFlyFrm::Format( pAttrs );
191 /*************************************************************************
193 |* SwFlyInCntFrm::MakeFlyPos()
195 |* Beschreibung Im Unterschied zu anderen Frms wird hier nur die
196 |* die RelPos berechnet. Die absolute Position wird ausschliesslich
197 |* per SetAbsPos errechnet.
198 |* Ersterstellung MA 03. Dec. 92
199 |* Letzte Aenderung MA 12. Apr. 96
201 |*************************************************************************/
202 // OD 2004-03-23 #i26791#
203 //void SwFlyInCntFrm::MakeFlyPos()
204 void SwFlyInCntFrm::MakeObjPos()
206 if ( !bValidPos )
208 bValidPos = TRUE;
209 SwFlyFrmFmt *pFmt = (SwFlyFrmFmt*)GetFmt();
210 const SwFmtVertOrient &rVert = pFmt->GetVertOrient();
211 //Und ggf. noch die aktuellen Werte im Format updaten, dabei darf
212 //zu diesem Zeitpunkt natuerlich kein Modify verschickt werden.
213 const bool bVert = GetAnchorFrm()->IsVertical();
214 const bool bRev = GetAnchorFrm()->IsReverse();
215 SwTwips nOld = rVert.GetPos();
216 SwTwips nAct = bVert ? -GetCurrRelPos().X() : GetCurrRelPos().Y();
217 if( bRev )
218 nAct = -nAct;
219 if( nAct != nOld )
221 SwFmtVertOrient aVert( rVert );
222 aVert.SetPos( nAct );
223 pFmt->LockModify();
224 pFmt->SetFmtAttr( aVert );
225 pFmt->UnlockModify();
230 // --> OD 2004-12-02 #115759#
231 void SwFlyInCntFrm::_ActionOnInvalidation( const InvalidationType _nInvalid )
233 if ( INVALID_POS == _nInvalid || INVALID_ALL == _nInvalid )
234 AnchorFrm()->Prepare( PREP_FLY_ATTR_CHG, &GetFrmFmt() );
236 // <--
237 /*************************************************************************
239 |* SwFlyInCntFrm::NotifyBackground()
241 |* Ersterstellung MA 03. Dec. 92
242 |* Letzte Aenderung MA 26. Aug. 93
244 |*************************************************************************/
245 void SwFlyInCntFrm::NotifyBackground( SwPageFrm *, const SwRect& rRect,
246 PrepareHint eHint)
248 if ( eHint == PREP_FLY_ATTR_CHG )
249 AnchorFrm()->Prepare( PREP_FLY_ATTR_CHG );
250 else
251 AnchorFrm()->Prepare( eHint, (void*)&rRect );
254 /*************************************************************************
256 |* SwFlyInCntFrm::GetRelPos()
258 |* Ersterstellung MA 04. Dec. 92
259 |* Letzte Aenderung MA 04. Dec. 92
261 |*************************************************************************/
262 const Point SwFlyInCntFrm::GetRelPos() const
264 Calc();
265 return GetCurrRelPos();
268 /*************************************************************************
270 |* SwFlyInCntFrm::RegistFlys()
272 |* Ersterstellung MA 26. Nov. 93
273 |* Letzte Aenderung MA 26. Nov. 93
275 |*************************************************************************/
276 void SwFlyInCntFrm::RegistFlys()
278 // vgl. SwRowFrm::RegistFlys()
279 SwPageFrm *pPage = FindPageFrm();
280 ASSERT( pPage, "Flys ohne Seite anmelden?" );
281 ::RegistFlys( pPage, this );
284 /*************************************************************************
286 |* SwFlyInCntFrm::MakeAll()
288 |* Ersterstellung MA 18. Feb. 94
289 |* Letzte Aenderung MA 13. Jun. 96
291 |*************************************************************************/
292 void SwFlyInCntFrm::MakeAll()
294 // OD 2004-01-19 #110582#
295 if ( !GetFmt()->GetDoc()->IsVisibleLayerId( GetVirtDrawObj()->GetLayer() ) )
297 return;
300 if ( !GetAnchorFrm() || IsLocked() || IsColLocked() || !FindPageFrm() )
301 return;
303 Lock(); //Der Vorhang faellt
305 //uebernimmt im DTor die Benachrichtigung
306 const SwFlyNotify aNotify( this );
307 SwBorderAttrAccess aAccess( SwFrm::GetCache(), this );
308 const SwBorderAttrs &rAttrs = *aAccess.Get();
310 if ( IsClipped() )
311 bValidSize = bHeightClipped = bWidthClipped = FALSE;
313 while ( !bValidPos || !bValidSize || !bValidPrtArea )
315 //Nur einstellen wenn das Flag gesetzt ist!!
316 if ( !bValidSize )
318 bValidPrtArea = FALSE;
320 // This is also done in the Format function, so I think
321 // this code is not necessary anymore:
322 long nOldWidth = aFrm.Width();
323 const Size aRelSize( CalcRel( rFrmSz ) );
324 aFrm.Width( aRelSize.Width() );
326 if ( aFrm.Width() > nOldWidth )
327 //Damit sich der Inhalt anpasst
328 aFrm.Height( aRelSize.Height() );
332 if ( !bValidPrtArea )
333 MakePrtArea( rAttrs );
335 if ( !bValidSize )
336 Format( &rAttrs );
338 if ( !bValidPos )
340 // OD 2004-03-23 #i26791#
341 //MakeFlyPos();
342 MakeObjPos();
345 // --> OD 2006-04-13 #b6402800#
346 // re-activate clipping of as-character anchored Writer fly frames
347 // depending on compatibility option <ClipAsCharacterAnchoredWriterFlyFrames>
348 if ( bValidPos && bValidSize &&
349 GetFmt()->getIDocumentSettingAccess()->get( IDocumentSettingAccess::CLIP_AS_CHARACTER_ANCHORED_WRITER_FLY_FRAME ) )
351 SwFrm* pFrm = AnchorFrm();
352 if ( Frm().Left() == (pFrm->Frm().Left()+pFrm->Prt().Left()) &&
353 Frm().Width() > pFrm->Prt().Width() )
355 Frm().Width( pFrm->Prt().Width() );
356 bValidPrtArea = FALSE;
357 bWidthClipped = TRUE;
360 // <--
362 Unlock();