Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "cntfrm.hxx"
31 : : #include "doc.hxx"
32 : : #include "flyfrm.hxx"
33 : : #include "frmtool.hxx"
34 : : #include "frmfmt.hxx"
35 : : #include "hints.hxx"
36 : : #include <fmtornt.hxx>
37 : : #include <fmtfsize.hxx>
38 : : #include "txtfrm.hxx" //fuer IsLocked()
39 : : #include "flyfrms.hxx"
40 : : // OD 2004-01-19 #110582#
41 : : #include <dflyobj.hxx>
42 : :
43 : : //from FlyCnt.cxx
44 : : void DeepCalc( const SwFrm *pFrm );
45 : :
46 : : /*************************************************************************
47 : : |*
48 : : |* SwFlyInCntFrm::SwFlyInCntFrm(), ~SwFlyInCntFrm()
49 : : |*
50 : : |*************************************************************************/
51 : 464 : SwFlyInCntFrm::SwFlyInCntFrm( SwFlyFrmFmt *pFmt, SwFrm* pSib, SwFrm *pAnch ) :
52 : 464 : SwFlyFrm( pFmt, pSib, pAnch )
53 : : {
54 : 464 : bInCnt = bInvalidLayout = bInvalidCntnt = sal_True;
55 [ + - ]: 464 : SwTwips nRel = pFmt->GetVertOrient().GetPos();
56 : : // OD 2004-05-27 #i26791# - member <aRelPos> moved to <SwAnchoredObject>
57 : 464 : Point aRelPos;
58 [ + - ][ - + ]: 464 : if( pAnch && pAnch->IsVertical() )
[ - + ][ + - ]
59 [ # # ]: 0 : aRelPos.X() = pAnch->IsReverse() ? nRel : -nRel;
60 : : else
61 : 464 : aRelPos.Y() = nRel;
62 [ + - ]: 464 : SetCurrRelPos( aRelPos );
63 : 464 : }
64 : :
65 : 377 : SwFlyInCntFrm::~SwFlyInCntFrm()
66 : : {
67 : : //good bye
68 [ + - ][ + - ]: 377 : if ( !GetFmt()->GetDoc()->IsInDtor() && GetAnchorFrm() )
[ + - ][ + - ]
[ + - ]
69 : : {
70 [ + - ]: 377 : SwRect aTmp( GetObjRectWithSpaces() );
71 [ + - ][ + - ]: 377 : SwFlyInCntFrm::NotifyBackground( FindPageFrm(), aTmp, PREP_FLY_LEAVE );
72 : : }
73 [ - + ]: 754 : }
74 : :
75 : : // #i28701#
76 [ - + ][ + + ]: 20034 : TYPEINIT1(SwFlyInCntFrm,SwFlyFrm);
77 : : /*************************************************************************
78 : : |*
79 : : |* SwFlyInCntFrm::SetRefPoint(),
80 : : |*
81 : : |*************************************************************************/
82 : 787 : void SwFlyInCntFrm::SetRefPoint( const Point& rPoint,
83 : : const Point& rRelAttr,
84 : : const Point& rRelPos )
85 : : {
86 : : // OD 2004-05-27 #i26791# - member <aRelPos> moved to <SwAnchoredObject>
87 : : OSL_ENSURE( rPoint != aRef || rRelAttr != GetCurrRelPos(), "SetRefPoint: no change" );
88 : 787 : SwFlyNotify *pNotify = NULL;
89 : : // No notify at a locked fly frame, if a fly frame is locked, there's
90 : : // already a SwFlyNotify object on the stack (MakeAll).
91 [ + - ]: 787 : if( !IsLocked() )
92 [ + - ]: 787 : pNotify = new SwFlyNotify( this );
93 : 787 : aRef = rPoint;
94 : 787 : SetCurrRelPos( rRelAttr );
95 [ # # ][ # # ]: 787 : SWRECTFN( GetAnchorFrm() )
[ - + ][ - + ]
96 [ + - ][ + - ]: 787 : (Frm().*fnRect->fnSetPos)( rPoint + rRelPos );
97 : : // #i68520#
98 : 787 : InvalidateObjRectWithSpaces();
99 [ + - ]: 787 : if( pNotify )
100 : : {
101 : 787 : InvalidatePage();
102 : 787 : bValidPos = sal_False;
103 : 787 : bInvalid = sal_True;
104 : 787 : Calc();
105 [ + - ]: 787 : delete pNotify;
106 : : }
107 : 787 : }
108 : :
109 : : /*************************************************************************
110 : : |*
111 : : |* SwFlyInCntFrm::Modify()
112 : : |*
113 : : |*************************************************************************/
114 : 50 : void SwFlyInCntFrm::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
115 : : {
116 : 50 : sal_Bool bCallPrepare = sal_False;
117 [ + - ][ # # ]: 50 : sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
118 [ + + ]: 50 : if( RES_ATTRSET_CHG == nWhich )
119 : : {
120 [ + + - + ]: 56 : if( SFX_ITEM_SET == ((SwAttrSetChg*)pNew)->GetChgSet()->
[ + + ]
121 : 20 : GetItemState( RES_SURROUND, sal_False ) ||
122 : 16 : SFX_ITEM_SET == ((SwAttrSetChg*)pNew)->GetChgSet()->
123 : 16 : GetItemState( RES_FRMMACRO, sal_False ) )
124 : : {
125 [ + - ]: 4 : SwAttrSetChg aOld( *(SwAttrSetChg*)pOld );
126 [ + - ]: 4 : SwAttrSetChg aNew( *(SwAttrSetChg*)pNew );
127 : :
128 [ + - ]: 4 : aOld.ClearItem( RES_SURROUND );
129 [ + - ]: 4 : aNew.ClearItem( RES_SURROUND );
130 [ + - ]: 4 : aOld.ClearItem( RES_FRMMACRO );
131 [ + - ]: 4 : aNew.ClearItem( RES_FRMMACRO );
132 [ - + ]: 4 : if( aNew.Count() )
133 : : {
134 [ # # ]: 0 : SwFlyFrm::Modify( &aOld, &aNew );
135 : 0 : bCallPrepare = sal_True;
136 [ + - ][ + - ]: 4 : }
137 : : }
138 [ + - ]: 16 : else if( ((SwAttrSetChg*)pNew)->GetChgSet()->Count())
139 : : {
140 : 16 : SwFlyFrm::Modify( pOld, pNew );
141 : 16 : bCallPrepare = sal_True;
142 : : }
143 : : }
144 [ + - ][ + - ]: 30 : else if( nWhich != RES_SURROUND && RES_FRMMACRO != nWhich )
145 : : {
146 : 30 : SwFlyFrm::Modify( pOld, pNew );
147 : 30 : bCallPrepare = sal_True;
148 : : }
149 : :
150 [ + + ][ + - ]: 50 : if ( bCallPrepare && GetAnchorFrm() )
[ + + ]
151 : 46 : AnchorFrm()->Prepare( PREP_FLY_ATTR_CHG, GetFmt() );
152 : 50 : }
153 : : /*************************************************************************
154 : : |*
155 : : |* SwFlyInCntFrm::Format()
156 : : |*
157 : : |* Here the content gets formatted initially.
158 : : |*
159 : : |*************************************************************************/
160 : 963 : void SwFlyInCntFrm::Format( const SwBorderAttrs *pAttrs )
161 : : {
162 [ - + ]: 963 : if ( !Frm().Height() )
163 : : {
164 : 0 : Lock(); //don't format the anchor on the crook.
165 : 0 : SwCntntFrm *pCntnt = ContainsCntnt();
166 [ # # ]: 0 : while ( pCntnt )
167 : 0 : { pCntnt->Calc();
168 : 0 : pCntnt = pCntnt->GetNextCntntFrm();
169 : : }
170 : 0 : Unlock();
171 : : }
172 : 963 : SwFlyFrm::Format( pAttrs );
173 : 963 : }
174 : : /*************************************************************************
175 : : |*
176 : : |* SwFlyInCntFrm::MakeFlyPos()
177 : : |*
178 : : |* Description In contrast to other Frms we only calculate the RelPos
179 : : |* here. The absolute position is only calculated using SetAbsPos.
180 : : |*************************************************************************/
181 : : // OD 2004-03-23 #i26791#
182 : : //void SwFlyInCntFrm::MakeFlyPos()
183 : 1259 : void SwFlyInCntFrm::MakeObjPos()
184 : : {
185 [ + - ]: 1259 : if ( !bValidPos )
186 : : {
187 : 1259 : bValidPos = sal_True;
188 : 1259 : SwFlyFrmFmt *pFmt = (SwFlyFrmFmt*)GetFmt();
189 : 1259 : const SwFmtVertOrient &rVert = pFmt->GetVertOrient();
190 : : //Update the current values in the format if needed, during this we of
191 : : //course must not send any Modify.
192 : 1259 : const bool bVert = GetAnchorFrm()->IsVertical();
193 : 1259 : const bool bRev = GetAnchorFrm()->IsReverse();
194 : 1259 : SwTwips nOld = rVert.GetPos();
195 [ # # ][ + - ]: 1259 : SwTwips nAct = bVert ? -GetCurrRelPos().X() : GetCurrRelPos().Y();
[ + - ][ - + ]
[ # # # # ]
[ - + ]
196 [ - + ]: 1259 : if( bRev )
197 : 0 : nAct = -nAct;
198 [ + + ]: 1259 : if( nAct != nOld )
199 : : {
200 [ + - ]: 588 : SwFmtVertOrient aVert( rVert );
201 : 588 : aVert.SetPos( nAct );
202 : 588 : pFmt->LockModify();
203 [ + - ]: 588 : pFmt->SetFmtAttr( aVert );
204 [ + - ]: 588 : pFmt->UnlockModify();
205 : : }
206 : : }
207 : 1259 : }
208 : :
209 : : // #115759#
210 : 544 : void SwFlyInCntFrm::_ActionOnInvalidation( const InvalidationType _nInvalid )
211 : : {
212 [ + + ][ - + ]: 544 : if ( INVALID_POS == _nInvalid || INVALID_ALL == _nInvalid )
213 : 36 : AnchorFrm()->Prepare( PREP_FLY_ATTR_CHG, &GetFrmFmt() );
214 : 544 : }
215 : : /*************************************************************************
216 : : |*
217 : : |* SwFlyInCntFrm::NotifyBackground()
218 : : |*
219 : : |*************************************************************************/
220 : 897 : void SwFlyInCntFrm::NotifyBackground( SwPageFrm *, const SwRect& rRect,
221 : : PrepareHint eHint)
222 : : {
223 [ - + ]: 897 : if ( eHint == PREP_FLY_ATTR_CHG )
224 : 0 : AnchorFrm()->Prepare( PREP_FLY_ATTR_CHG );
225 : : else
226 : 897 : AnchorFrm()->Prepare( eHint, (void*)&rRect );
227 : 897 : }
228 : :
229 : : /*************************************************************************
230 : : |*
231 : : |* SwFlyInCntFrm::GetRelPos()
232 : : |*
233 : : |*************************************************************************/
234 : 92 : const Point SwFlyInCntFrm::GetRelPos() const
235 : : {
236 : 92 : Calc();
237 : 92 : return GetCurrRelPos();
238 : : }
239 : :
240 : : /*************************************************************************
241 : : |*
242 : : |* SwFlyInCntFrm::RegistFlys()
243 : : |*
244 : : |*************************************************************************/
245 : 438 : void SwFlyInCntFrm::RegistFlys()
246 : : {
247 : : // vgl. SwRowFrm::RegistFlys()
248 : 438 : SwPageFrm *pPage = FindPageFrm();
249 : : OSL_ENSURE( pPage, "Register Flys without pages?" );
250 : 438 : ::RegistFlys( pPage, this );
251 : 438 : }
252 : :
253 : : /*************************************************************************
254 : : |*
255 : : |* SwFlyInCntFrm::MakeAll()
256 : : |*
257 : : |*************************************************************************/
258 : 1725 : void SwFlyInCntFrm::MakeAll()
259 : : {
260 : : // OD 2004-01-19 #110582#
261 [ + - ][ + - ]: 1725 : if ( !GetFmt()->GetDoc()->IsVisibleLayerId( GetVirtDrawObj()->GetLayer() ) )
[ + - ][ + - ]
[ + - ]
262 : : {
263 : : return;
264 : : }
265 : :
266 [ + - ][ + - ]: 1725 : if ( !GetAnchorFrm() || IsLocked() || IsColLocked() || !FindPageFrm() )
[ + - ][ + - ]
[ + - ][ - + ]
[ + - ]
267 : : return;
268 : :
269 : 1725 : Lock(); // The curtain falls
270 : :
271 : : //does the notification in the DTor
272 [ + - ]: 1725 : const SwFlyNotify aNotify( this );
273 [ + - ]: 1725 : SwBorderAttrAccess aAccess( SwFrm::GetCache(), this );
274 [ + - ]: 1725 : const SwBorderAttrs &rAttrs = *aAccess.Get();
275 : :
276 [ - + ]: 1725 : if ( IsClipped() )
277 : 0 : bValidSize = bHeightClipped = bWidthClipped = sal_False;
278 : :
279 [ + + ][ + + ]: 3450 : while ( !bValidPos || !bValidSize || !bValidPrtArea )
[ - + ][ + + ]
280 : : {
281 : : //Only stop, if the flag is set!!
282 [ + + ]: 1725 : if ( !bValidSize )
283 : : {
284 : 963 : bValidPrtArea = sal_False;
285 : : }
286 : :
287 [ + + ]: 1725 : if ( !bValidPrtArea )
288 [ + - ]: 963 : MakePrtArea( rAttrs );
289 : :
290 [ + + ]: 1725 : if ( !bValidSize )
291 [ + - ]: 963 : Format( &rAttrs );
292 : :
293 [ + + ]: 1725 : if ( !bValidPos )
294 : : {
295 : : // OD 2004-03-23 #i26791#
296 : : //MakeFlyPos();
297 [ + - ]: 1259 : MakeObjPos();
298 : : }
299 : :
300 : : //
301 : : // re-activate clipping of as-character anchored Writer fly frames
302 : : // depending on compatibility option <ClipAsCharacterAnchoredWriterFlyFrames>
303 [ + - ][ + - ]: 3450 : if ( bValidPos && bValidSize &&
[ - + ][ - + ]
304 [ + - ][ + - ]: 1725 : GetFmt()->getIDocumentSettingAccess()->get( IDocumentSettingAccess::CLIP_AS_CHARACTER_ANCHORED_WRITER_FLY_FRAME ) )
[ + - ]
305 : : {
306 [ # # ]: 0 : SwFrm* pFrm = AnchorFrm();
307 [ # # # # ]: 0 : if ( Frm().Left() == (pFrm->Frm().Left()+pFrm->Prt().Left()) &&
[ # # ]
308 : 0 : Frm().Width() > pFrm->Prt().Width() )
309 : : {
310 : 0 : Frm().Width( pFrm->Prt().Width() );
311 : 0 : bValidPrtArea = sal_False;
312 : 0 : bWidthClipped = sal_True;
313 : : }
314 : : }
315 : : }
316 [ + - ][ + - ]: 1725 : Unlock();
317 : : }
318 : :
319 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|