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