1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sw.hxx" 26 27 #include "cntfrm.hxx" 28 #include "doc.hxx" 29 #include "flyfrm.hxx" 30 #include "frmtool.hxx" 31 #include "frmfmt.hxx" 32 #include "hints.hxx" 33 #include <fmtornt.hxx> 34 #include <fmtfsize.hxx> 35 #include "txtfrm.hxx" //fuer IsLocked() 36 #include "flyfrms.hxx" 37 // OD 2004-01-19 #110582# 38 #include <dflyobj.hxx> 39 40 //aus FlyCnt.cxx 41 void DeepCalc( const SwFrm *pFrm ); 42 43 /************************************************************************* 44 |* 45 |* SwFlyInCntFrm::SwFlyInCntFrm(), ~SwFlyInCntFrm() 46 |* 47 |* Ersterstellung MA 01. Dec. 92 48 |* Letzte Aenderung MA 09. Apr. 99 49 |* 50 |*************************************************************************/ 51 SwFlyInCntFrm::SwFlyInCntFrm( SwFlyFrmFmt *pFmt, SwFrm* pSib, SwFrm *pAnch ) : 52 SwFlyFrm( pFmt, pSib, pAnch ) 53 { 54 bInCnt = bInvalidLayout = bInvalidCntnt = sal_True; 55 SwTwips nRel = pFmt->GetVertOrient().GetPos(); 56 // OD 2004-05-27 #i26791# - member <aRelPos> moved to <SwAnchoredObject> 57 Point aRelPos; 58 if( pAnch && pAnch->IsVertical() ) 59 aRelPos.X() = pAnch->IsReverse() ? nRel : -nRel; 60 else 61 aRelPos.Y() = nRel; 62 SetCurrRelPos( aRelPos ); 63 } 64 65 SwFlyInCntFrm::~SwFlyInCntFrm() 66 { 67 //und Tschuess. 68 if ( !GetFmt()->GetDoc()->IsInDtor() && GetAnchorFrm() ) 69 { 70 SwRect aTmp( GetObjRectWithSpaces() ); 71 SwFlyInCntFrm::NotifyBackground( FindPageFrm(), aTmp, PREP_FLY_LEAVE ); 72 } 73 } 74 75 // --> OD 2004-06-29 #i28701# 76 TYPEINIT1(SwFlyInCntFrm,SwFlyFrm); 77 // <-- 78 /************************************************************************* 79 |* 80 |* SwFlyInCntFrm::SetRefPoint(), 81 |* 82 |* Ersterstellung MA 01. Dec. 92 83 |* Letzte Aenderung MA 06. Aug. 95 84 |* 85 |*************************************************************************/ 86 void SwFlyInCntFrm::SetRefPoint( const Point& rPoint, 87 const Point& rRelAttr, 88 const Point& rRelPos ) 89 { 90 // OD 2004-05-27 #i26791# - member <aRelPos> moved to <SwAnchoredObject> 91 ASSERT( rPoint != aRef || rRelAttr != GetCurrRelPos(), "SetRefPoint: no change" ); 92 SwFlyNotify *pNotify = NULL; 93 // No notify at a locked fly frame, if a fly frame is locked, there's 94 // already a SwFlyNotify object on the stack (MakeAll). 95 if( !IsLocked() ) 96 pNotify = new SwFlyNotify( this ); 97 aRef = rPoint; 98 SetCurrRelPos( rRelAttr ); 99 SWRECTFN( GetAnchorFrm() ) 100 (Frm().*fnRect->fnSetPos)( rPoint + rRelPos ); 101 // --> OD 2006-08-25 #i68520# 102 InvalidateObjRectWithSpaces(); 103 // <-- 104 if( pNotify ) 105 { 106 InvalidatePage(); 107 bValidPos = sal_False; 108 bInvalid = sal_True; 109 Calc(); 110 delete pNotify; 111 } 112 } 113 114 /************************************************************************* 115 |* 116 |* SwFlyInCntFrm::Modify() 117 |* 118 |* Ersterstellung MA 16. Dec. 92 119 |* Letzte Aenderung MA 02. Sep. 93 120 |* 121 |*************************************************************************/ 122 void SwFlyInCntFrm::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) 123 { 124 sal_Bool bCallPrepare = sal_False; 125 sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0; 126 if( RES_ATTRSET_CHG == nWhich ) 127 { 128 if( SFX_ITEM_SET == ((SwAttrSetChg*)pNew)->GetChgSet()-> 129 GetItemState( RES_SURROUND, sal_False ) || 130 SFX_ITEM_SET == ((SwAttrSetChg*)pNew)->GetChgSet()-> 131 GetItemState( RES_FRMMACRO, sal_False ) ) 132 { 133 SwAttrSetChg aOld( *(SwAttrSetChg*)pOld ); 134 SwAttrSetChg aNew( *(SwAttrSetChg*)pNew ); 135 136 aOld.ClearItem( RES_SURROUND ); 137 aNew.ClearItem( RES_SURROUND ); 138 aOld.ClearItem( RES_FRMMACRO ); 139 aNew.ClearItem( RES_FRMMACRO ); 140 if( aNew.Count() ) 141 { 142 SwFlyFrm::Modify( &aOld, &aNew ); 143 bCallPrepare = sal_True; 144 } 145 } 146 else if( ((SwAttrSetChg*)pNew)->GetChgSet()->Count()) 147 { 148 SwFlyFrm::Modify( pOld, pNew ); 149 bCallPrepare = sal_True; 150 } 151 } 152 else if( nWhich != RES_SURROUND && RES_FRMMACRO != nWhich ) 153 { 154 SwFlyFrm::Modify( pOld, pNew ); 155 bCallPrepare = sal_True; 156 } 157 158 if ( bCallPrepare && GetAnchorFrm() ) 159 AnchorFrm()->Prepare( PREP_FLY_ATTR_CHG, GetFmt() ); 160 } 161 /************************************************************************* 162 |* 163 |* SwFlyInCntFrm::Format() 164 |* 165 |* Beschreibung: Hier wird der Inhalt initial mit Formatiert. 166 |* Ersterstellung MA 16. Dec. 92 167 |* Letzte Aenderung MA 19. May. 93 168 |* 169 |*************************************************************************/ 170 void SwFlyInCntFrm::Format( const SwBorderAttrs *pAttrs ) 171 { 172 if ( !Frm().Height() ) 173 { 174 Lock(); //nicht hintenherum den Anker formatieren. 175 SwCntntFrm *pCntnt = ContainsCntnt(); 176 while ( pCntnt ) 177 { pCntnt->Calc(); 178 pCntnt = pCntnt->GetNextCntntFrm(); 179 } 180 Unlock(); 181 } 182 SwFlyFrm::Format( pAttrs ); 183 } 184 /************************************************************************* 185 |* 186 |* SwFlyInCntFrm::MakeFlyPos() 187 |* 188 |* Beschreibung Im Unterschied zu anderen Frms wird hier nur die 189 |* die RelPos berechnet. Die absolute Position wird ausschliesslich 190 |* per SetAbsPos errechnet. 191 |* Ersterstellung MA 03. Dec. 92 192 |* Letzte Aenderung MA 12. Apr. 96 193 |* 194 |*************************************************************************/ 195 // OD 2004-03-23 #i26791# 196 //void SwFlyInCntFrm::MakeFlyPos() 197 void SwFlyInCntFrm::MakeObjPos() 198 { 199 if ( !bValidPos ) 200 { 201 bValidPos = sal_True; 202 SwFlyFrmFmt *pFmt = (SwFlyFrmFmt*)GetFmt(); 203 const SwFmtVertOrient &rVert = pFmt->GetVertOrient(); 204 //Und ggf. noch die aktuellen Werte im Format updaten, dabei darf 205 //zu diesem Zeitpunkt natuerlich kein Modify verschickt werden. 206 const bool bVert = GetAnchorFrm()->IsVertical(); 207 const bool bRev = GetAnchorFrm()->IsReverse(); 208 SwTwips nOld = rVert.GetPos(); 209 SwTwips nAct = bVert ? -GetCurrRelPos().X() : GetCurrRelPos().Y(); 210 if( bRev ) 211 nAct = -nAct; 212 if( nAct != nOld ) 213 { 214 SwFmtVertOrient aVert( rVert ); 215 aVert.SetPos( nAct ); 216 pFmt->LockModify(); 217 pFmt->SetFmtAttr( aVert ); 218 pFmt->UnlockModify(); 219 } 220 } 221 } 222 223 // --> OD 2004-12-02 #115759# 224 void SwFlyInCntFrm::_ActionOnInvalidation( const InvalidationType _nInvalid ) 225 { 226 if ( INVALID_POS == _nInvalid || INVALID_ALL == _nInvalid ) 227 AnchorFrm()->Prepare( PREP_FLY_ATTR_CHG, &GetFrmFmt() ); 228 } 229 // <-- 230 /************************************************************************* 231 |* 232 |* SwFlyInCntFrm::NotifyBackground() 233 |* 234 |* Ersterstellung MA 03. Dec. 92 235 |* Letzte Aenderung MA 26. Aug. 93 236 |* 237 |*************************************************************************/ 238 void SwFlyInCntFrm::NotifyBackground( SwPageFrm *, const SwRect& rRect, 239 PrepareHint eHint) 240 { 241 if ( eHint == PREP_FLY_ATTR_CHG ) 242 AnchorFrm()->Prepare( PREP_FLY_ATTR_CHG ); 243 else 244 AnchorFrm()->Prepare( eHint, (void*)&rRect ); 245 } 246 247 /************************************************************************* 248 |* 249 |* SwFlyInCntFrm::GetRelPos() 250 |* 251 |* Ersterstellung MA 04. Dec. 92 252 |* Letzte Aenderung MA 04. Dec. 92 253 |* 254 |*************************************************************************/ 255 const Point SwFlyInCntFrm::GetRelPos() const 256 { 257 Calc(); 258 return GetCurrRelPos(); 259 } 260 261 /************************************************************************* 262 |* 263 |* SwFlyInCntFrm::RegistFlys() 264 |* 265 |* Ersterstellung MA 26. Nov. 93 266 |* Letzte Aenderung MA 26. Nov. 93 267 |* 268 |*************************************************************************/ 269 void SwFlyInCntFrm::RegistFlys() 270 { 271 // vgl. SwRowFrm::RegistFlys() 272 SwPageFrm *pPage = FindPageFrm(); 273 ASSERT( pPage, "Flys ohne Seite anmelden?" ); 274 ::RegistFlys( pPage, this ); 275 } 276 277 /************************************************************************* 278 |* 279 |* SwFlyInCntFrm::MakeAll() 280 |* 281 |* Ersterstellung MA 18. Feb. 94 282 |* Letzte Aenderung MA 13. Jun. 96 283 |* 284 |*************************************************************************/ 285 void SwFlyInCntFrm::MakeAll() 286 { 287 // OD 2004-01-19 #110582# 288 if ( !GetFmt()->GetDoc()->IsVisibleLayerId( GetVirtDrawObj()->GetLayer() ) ) 289 { 290 return; 291 } 292 293 if ( !GetAnchorFrm() || IsLocked() || IsColLocked() || !FindPageFrm() ) 294 return; 295 296 Lock(); //Der Vorhang faellt 297 298 //uebernimmt im DTor die Benachrichtigung 299 const SwFlyNotify aNotify( this ); 300 SwBorderAttrAccess aAccess( SwFrm::GetCache(), this ); 301 const SwBorderAttrs &rAttrs = *aAccess.Get(); 302 303 if ( IsClipped() ) 304 bValidSize = bHeightClipped = bWidthClipped = sal_False; 305 306 while ( !bValidPos || !bValidSize || !bValidPrtArea ) 307 { 308 //Nur einstellen wenn das Flag gesetzt ist!! 309 if ( !bValidSize ) 310 { 311 bValidPrtArea = sal_False; 312 /* 313 // This is also done in the Format function, so I think 314 // this code is not necessary anymore: 315 long nOldWidth = aFrm.Width(); 316 const Size aRelSize( CalcRel( rFrmSz ) ); 317 aFrm.Width( aRelSize.Width() ); 318 319 if ( aFrm.Width() > nOldWidth ) 320 //Damit sich der Inhalt anpasst 321 aFrm.Height( aRelSize.Height() ); 322 */ 323 } 324 325 if ( !bValidPrtArea ) 326 MakePrtArea( rAttrs ); 327 328 if ( !bValidSize ) 329 Format( &rAttrs ); 330 331 if ( !bValidPos ) 332 { 333 // OD 2004-03-23 #i26791# 334 //MakeFlyPos(); 335 MakeObjPos(); 336 } 337 338 // --> OD 2006-04-13 #b6402800# 339 // re-activate clipping of as-character anchored Writer fly frames 340 // depending on compatibility option <ClipAsCharacterAnchoredWriterFlyFrames> 341 if ( bValidPos && bValidSize && 342 GetFmt()->getIDocumentSettingAccess()->get( IDocumentSettingAccess::CLIP_AS_CHARACTER_ANCHORED_WRITER_FLY_FRAME ) ) 343 { 344 SwFrm* pFrm = AnchorFrm(); 345 if ( Frm().Left() == (pFrm->Frm().Left()+pFrm->Prt().Left()) && 346 Frm().Width() > pFrm->Prt().Width() ) 347 { 348 Frm().Width( pFrm->Prt().Width() ); 349 bValidPrtArea = sal_False; 350 bWidthClipped = sal_True; 351 } 352 } 353 // <-- 354 } 355 Unlock(); 356 } 357 358