merge the formfield patch from ooo-build
[ooovba.git] / sw / source / core / frmedt / fefly1.cxx
blob640a49f13decb2d475b9f2df2459b5199e2b5761
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: fefly1.cxx,v $
10 * $Revision: 1.45 $
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"
33 #include <hintids.hxx>
34 #include <svtools/itemiter.hxx>
35 #include <svtools/imapobj.hxx>
36 #include <svtools/soerr.hxx>
37 #include <svx/protitem.hxx>
38 #include <svx/svdogrp.hxx>
39 #include <svx/svdouno.hxx>
40 #include <svx/fmglob.hxx>
41 #include <com/sun/star/form/FormButtonType.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <fmtanchr.hxx>
44 #include <txtflcnt.hxx>
45 #include <fmtcntnt.hxx>
46 #include <fmtornt.hxx>
47 #include <fmtflcnt.hxx>
48 #include <fmturl.hxx>
49 #include <fmtclds.hxx>
50 #include <fmtfsize.hxx>
51 #include <docary.hxx>
52 #include <fesh.hxx>
53 #include <rootfrm.hxx>
54 #include <pagefrm.hxx>
55 #include <cntfrm.hxx>
56 #include <txtfrm.hxx>
57 #include <viewimp.hxx>
58 #include <viscrs.hxx>
59 #include <doc.hxx>
60 #include <dview.hxx>
61 #include <dflyobj.hxx>
62 #include <dcontact.hxx>
63 #include <frmfmt.hxx>
64 #include <flyfrm.hxx>
65 #include <ndtxt.hxx>
66 #include <edimp.hxx>
67 #include <swtable.hxx>
68 #include <mvsave.hxx> // Strukturen zum Sichern beim Move/Delete
69 #include <ndgrf.hxx>
70 #include <flyfrms.hxx>
71 #include <flypos.hxx>
72 #include <fldbas.hxx>
73 #include <fmtfld.hxx>
74 #include <swundo.hxx>
75 // --> OD 2006-03-06 #125892#
76 #include <HandleAnchorNodeChg.hxx>
77 // <--
79 #include <frmatr.hxx>
82 using ::rtl::OUString;
83 using namespace ::com::sun::star;
85 //Zum anmelden von Flys in Flys in ...
86 //definiert in layout/frmtool.cxx
87 void RegistFlys( SwPageFrm*, const SwLayoutFrm* );
89 /***********************************************************************
90 #* Class : SwDoc
91 #* Methode : UseSpzLayoutFmt
92 #* Beschreibung: Anhand des Request werden zu dem Format entsprechende
93 #* Aenderungen an den Spezifischen Layouts vorgenommen.
94 #* Datum : MA 23. Sep. 92
95 #* Update : JP 09.03.98
96 #***********************************************************************/
98 sal_Bool lcl_SetNewFlyPos( const SwNode& rNode, SwFmtAnchor& rAnchor,
99 const Point& rPt )
101 sal_Bool bRet = sal_False;
102 const SwStartNode* pStNode = rNode.FindFlyStartNode();
103 if( pStNode )
105 SwPosition aPos( *pStNode );
106 rAnchor.SetAnchor( &aPos );
107 bRet = sal_True;
109 else
111 const SwCntntNode *pCntNd = rNode.GetCntntNode();
112 const SwCntntFrm* pCFrm = pCntNd ? pCntNd->GetFrm( &rPt, 0, sal_False ) : 0;
113 const SwPageFrm *pPg = pCFrm ? pCFrm->FindPageFrm() : 0;
115 rAnchor.SetPageNum( pPg ? pPg->GetPhyPageNum() : 1 );
116 rAnchor.SetType( FLY_PAGE );
118 return bRet;
121 BOOL lcl_FindAnchorPos( SwDoc& rDoc, const Point& rPt, const SwFrm& rFrm,
122 SfxItemSet& rSet )
124 BOOL bRet = TRUE;
125 SwFmtAnchor aNewAnch( (SwFmtAnchor&)rSet.Get( RES_ANCHOR ) );
126 RndStdIds nNew = aNewAnch.GetAnchorId();
127 const SwFrm *pNewAnch;
129 //Neuen Anker ermitteln
130 Point aTmpPnt( rPt );
131 switch( nNew )
133 case FLY_IN_CNTNT: // sollte der nicht auch mit hinein?
134 case FLY_AT_CNTNT:
135 case FLY_AUTO_CNTNT: // LAYER_IMPL
137 //Ausgehend von der linken oberen Ecke des Fly den
138 //dichtesten CntntFrm suchen.
139 const SwFrm* pFrm = rFrm.IsFlyFrm() ? ((SwFlyFrm&)rFrm).GetAnchorFrm()
140 : &rFrm;
141 pNewAnch = ::FindAnchor( pFrm, aTmpPnt );
142 if( pNewAnch->IsProtected() )
144 bRet = FALSE;
145 break;
148 SwPosition aPos( *((SwCntntFrm*)pNewAnch)->GetNode() );
149 if( FLY_AUTO_CNTNT == nNew || FLY_IN_CNTNT == nNew )
151 // es muss ein TextNode gefunden werden, denn nur in diesen
152 // ist ein Inhaltsgebundene Frames zu verankern
153 SwCrsrMoveState aState( MV_SETONLYTEXT );
154 aTmpPnt.X() -= 1; //nicht im Fly landen!!
155 if( !pNewAnch->GetCrsrOfst( &aPos, aTmpPnt, &aState ) )
157 SwCntntNode* pCNd = ((SwCntntFrm*)pNewAnch)->GetNode();
158 if( pNewAnch->Frm().Bottom() < aTmpPnt.Y() )
159 pCNd->MakeStartIndex( &aPos.nContent );
160 else
161 pCNd->MakeEndIndex( &aPos.nContent );
164 aNewAnch.SetAnchor( &aPos );
166 break;
168 case FLY_AT_FLY: // LAYER_IMPL
170 //Ausgehend von der linken oberen Ecke des Fly den
171 //dichtesten SwFlyFrm suchen.
172 SwCrsrMoveState aState( MV_SETONLYTEXT );
173 SwPosition aPos( rDoc.GetNodes() );
174 aTmpPnt.X() -= 1; //nicht im Fly landen!!
175 rDoc.GetRootFrm()->GetCrsrOfst( &aPos, aTmpPnt, &aState );
176 pNewAnch = ::FindAnchor(
177 aPos.nNode.GetNode().GetCntntNode()->GetFrm( 0, 0, sal_False ),
178 aTmpPnt )->FindFlyFrm();
180 if( pNewAnch && &rFrm != pNewAnch && !pNewAnch->IsProtected() )
182 aPos.nNode = *((SwFlyFrm*)pNewAnch)->GetFmt()->GetCntnt().
183 GetCntntIdx();
184 aNewAnch.SetAnchor( &aPos );
185 break;
189 aNewAnch.SetType( nNew = FLY_PAGE );
190 // no break
192 case FLY_PAGE:
193 pNewAnch = rFrm.FindPageFrm();
194 aNewAnch.SetPageNum( pNewAnch->GetPhyPageNum() );
195 break;
197 default:
198 ASSERT( !&rDoc, "Falsche ID fuer neuen Anker." );
201 rSet.Put( aNewAnch );
202 return bRet;
206 //! also used in unoframe.cxx
208 sal_Bool lcl_ChkAndSetNewAnchor( const SwFlyFrm& rFly, SfxItemSet& rSet )
210 const SwFrmFmt& rFmt = *rFly.GetFmt();
211 const SwFmtAnchor &rOldAnch = rFmt.GetAnchor();
212 const RndStdIds nOld = rOldAnch.GetAnchorId();
214 RndStdIds nNew = ((SwFmtAnchor&)rSet.Get( RES_ANCHOR )).GetAnchorId();
216 if( nOld == nNew )
217 return sal_False;
219 SwDoc* pDoc = (SwDoc*)rFmt.GetDoc();
221 #ifndef PRODUCT
222 ASSERT( !(nNew == FLY_PAGE &&
223 (FLY_AT_CNTNT==nOld || FLY_AUTO_CNTNT==nOld || FLY_IN_CNTNT==nOld ) &&
224 pDoc->IsInHeaderFooter( rOldAnch.GetCntntAnchor()->nNode )),
225 "Unerlaubter Ankerwechsel in Head/Foot." );
226 #endif
228 return ::lcl_FindAnchorPos( *pDoc, rFly.Frm().Pos(), rFly, rSet );
231 void SwFEShell::SelectFlyFrm( SwFlyFrm& rFrm, sal_Bool bNew )
233 SET_CURR_SHELL( this );
235 // Wenn es ein neuer Rahmen ist, so soll er selektiert sein.
236 // !!Rahmen immer selektieren, wenn sie nicht selektiert sind.
237 // - Es kann ein neuer 'alter' sein weil der Anker gewechselt wurde.
238 // - 'alte' Rahmen sind vorher immer selektiert denn sonst wird nix
239 // an ihnen veraendert.
240 // Der Rahmen darf nicht per Dokumentposition selektiert werden, weil er
241 // auf jedenfall selektiert sein muss!
242 SwViewImp *pImpl = Imp();
243 if( GetWin() && (bNew || !pImpl->GetDrawView()->AreObjectsMarked()) )
245 ASSERT( rFrm.IsFlyFrm(), "SelectFlyFrm will einen Fly" );
247 //Wenn der Fly bereits selektiert ist gibt es hier ja wohl nichts
248 //zu tun.
249 if ( FindFlyFrm() == &rFrm )
250 return;
252 //Damit der Anker ueberhaupt noch gepaintet wird.
253 if( rFrm.IsFlyInCntFrm() && rFrm.GetAnchorFrm() )
254 rFrm.GetAnchorFrm()->SetCompletePaint();
256 // --> OD 2004-06-11 #i28701# - no format at all.
257 // //Hier wurde immer kalkuliert. Leider ist der Sonderfall Fly in Fly mit
258 // //Spalten u.U. sehr kritisch wenn der innenliegende zuerst formatiert
259 // //wird. Um kein Risiko einzugehen entschaerfen wir nur diesen Sonderfall.
260 // if( !rFrm.GetAnchorFrm()->IsInFly() )
261 // rFrm.Calc();
263 if( pImpl->GetDrawView()->AreObjectsMarked() )
264 pImpl->GetDrawView()->UnmarkAll();
266 pImpl->GetDrawView()->MarkObj( rFrm.GetVirtDrawObj(),
267 pImpl->GetPageView(), sal_False, sal_False );
268 KillPams();
269 ClearMark();
270 SelFlyGrabCrsr();
274 /*************************************************************************
276 |* SwFEShell::FindFlyFrm()
278 |* Beschreibung Liefert den Fly wenn einer Selektiert ist.
279 |* Ersterstellung MA 03. Nov. 92
280 |* Letzte Aenderung MA 05. Mar. 96
282 *************************************************************************/
284 SwFlyFrm *SwFEShell::FindFlyFrm() const
286 if ( Imp()->HasDrawView() )
288 // Ein Fly ist genau dann erreichbar, wenn er selektiert ist.
289 const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
290 if( rMrkList.GetMarkCount() != 1 )
291 return 0;
293 SdrObject *pO = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
294 return pO->ISA(SwVirtFlyDrawObj) ? ((SwVirtFlyDrawObj*)pO)->GetFlyFrm() : 0;
296 return 0;
299 /*************************************************************************
301 |* SwFEShell::IsFlyInFly()
303 |* Beschreibung Liefert sal_True, wenn der aktuelle Fly an einem anderen
304 |* verankert werden koennte (also innerhalb ist)
305 |* Ersterstellung AMA 11. Sep. 97
306 |* Letzte Aenderung AMA 14. Jan. 98
308 *************************************************************************/
310 const SwFrmFmt* SwFEShell::IsFlyInFly()
312 SET_CURR_SHELL( this );
314 if ( !Imp()->HasDrawView() )
315 return NULL;
317 const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
318 if ( !rMrkList.GetMarkCount() )
320 SwCntntFrm *pCntnt = GetCurrFrm( sal_False );
321 if( !pCntnt )
322 return NULL;
323 SwFlyFrm *pFly = pCntnt->FindFlyFrm();
324 if ( !pFly )
325 return NULL;
326 return pFly->GetFmt();
328 else if ( rMrkList.GetMarkCount() != 1 ||
329 !GetUserCall(rMrkList.GetMark( 0 )->GetMarkedSdrObj()) )
330 return NULL;
332 SdrObject *pObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
334 SwFrmFmt *pFmt = FindFrmFmt( pObj );
335 if( pFmt && FLY_AT_FLY == pFmt->GetAnchor().GetAnchorId() )
337 const SwFrm* pFly = pObj->ISA(SwVirtFlyDrawObj) ?
338 ((SwVirtFlyDrawObj*)pObj)->GetFlyFrm()->GetAnchorFrm() :
339 ((SwDrawContact*)GetUserCall(pObj))->GetAnchorFrm( pObj );
340 ASSERT( pFly, "IsFlyInFly: Where's my anchor?" );
341 ASSERT( pFly->IsFlyFrm(), "IsFlyInFly: Funny anchor!" );
342 return ((SwFlyFrm*)pFly)->GetFmt();
345 Point aTmpPos = pObj->GetCurrentBoundRect().TopLeft();
347 SwFrm *pTxtFrm;
349 SwCrsrMoveState aState( MV_SETONLYTEXT );
350 SwNodeIndex aSwNodeIndex( GetDoc()->GetNodes() );
351 SwPosition aPos( aSwNodeIndex );
352 Point aPoint( aTmpPos );
353 aPoint.X() -= 1; //nicht im Fly landen!!
354 GetLayout()->GetCrsrOfst( &aPos, aPoint, &aState );
355 // OD 01.07.2003 #108784# - determine text frame by left-top-corner
356 // of object
357 //pTxtFrm = aPos.nNode.GetNode().GetCntntNode()->GetFrm( 0, 0, sal_False );
358 pTxtFrm = aPos.nNode.GetNode().GetCntntNode()->GetFrm( &aTmpPos, 0, sal_False );
360 const SwFrm *pTmp = ::FindAnchor( pTxtFrm, aTmpPos );
361 const SwFlyFrm *pFly = pTmp->FindFlyFrm();
362 if( pFly )
363 return pFly->GetFmt();
364 return NULL;
367 /*************************************************************************
369 |* SwFEShell::SetFlyPos
371 |* Ersterstellung MA 14. Jan. 93
372 |* Letzte Aenderung MA 14. Feb. 95
374 *************************************************************************/
376 void SwFEShell::SetFlyPos( const Point& rAbsPos )
378 SET_CURR_SHELL( this );
380 //Bezugspunkt in Dokumentkoordinaten bestimmen
381 SwCntntFrm *pCntnt = GetCurrFrm( sal_False );
382 if( !pCntnt )
383 return;
384 SwFlyFrm *pFly = pCntnt->FindFlyFrm();
385 if ( !pFly )
386 return;
388 //SwSaveHdl aSaveX( Imp() );
390 //Bei Absatzgebundenen Flys muss ausgehend von der absoluten
391 //Position ein neuer Anker gesetzt werden. Anker und neue RelPos werden
392 //vom Fly selbst berechnet und gesetzt.
393 if ( pFly->IsFlyAtCntFrm() )
394 ((SwFlyAtCntFrm*)pFly)->SetAbsPos( rAbsPos );
395 else
397 const SwFrm *pAnch = pFly->GetAnchorFrm();
398 // --> OD 2004-06-11 #i28701# - no format here
399 // pAnch->Calc();
400 Point aOrient( pAnch->Frm().Pos() );
402 if ( pFly->IsFlyInCntFrm() )
403 aOrient.X() = rAbsPos.X();
405 //RelPos errechnen.
406 aOrient.X() = rAbsPos.X() - aOrient.X();
407 aOrient.Y() = rAbsPos.Y() - aOrient.Y();
408 pFly->ChgRelPos( aOrient );
410 // --> OD 2004-06-11 #i28701# - no format here
411 // pFly->Calc();
412 CallChgLnk(); // rufe das AttrChangeNotify auf der UI-Seite.
415 /*************************************************************************
417 |* SwFEShell::FindAnchorPos
419 |* Ersterstellung AMA 24. Sep. 97
420 |* Letzte Aenderung AMA 24. Sep. 97
422 *************************************************************************/
424 Point SwFEShell::FindAnchorPos( const Point& rAbsPos, sal_Bool bMoveIt )
426 Point aRet;
428 SET_CURR_SHELL( this );
430 if ( !Imp()->HasDrawView() )
431 return aRet;
433 const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
434 if ( rMrkList.GetMarkCount() != 1 ||
435 !GetUserCall(rMrkList.GetMark( 0 )->GetMarkedSdrObj()) )
436 return aRet;
438 SdrObject* pObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
439 // --> OD 2004-07-16 #i28701#
440 SwAnchoredObject* pAnchoredObj = ::GetUserCall( pObj )->GetAnchoredObj( pObj );
441 SwFrmFmt& rFmt = pAnchoredObj->GetFrmFmt();
442 RndStdIds nAnchorId = rFmt.GetAnchor().GetAnchorId();
444 if ( FLY_IN_CNTNT == nAnchorId )
445 return aRet;
447 sal_Bool bFlyFrame = pObj->ISA(SwVirtFlyDrawObj);
449 SwFlyFrm* pFly = 0L;
450 const SwFrm* pOldAnch;
451 const SwFrm* pFooterOrHeader = NULL;
453 if( bFlyFrame )
455 //Bezugspunkt in Dokumentkoordinaten bestimmen
456 SwCntntFrm *pCntnt = GetCurrFrm( sal_False );
457 if( !pCntnt )
458 return aRet;
459 pFly = pCntnt->FindFlyFrm();
460 if ( !pFly )
461 return aRet;
462 pOldAnch = pFly->GetAnchorFrm();
463 if( !pOldAnch )
464 return aRet;
465 if( FLY_PAGE != nAnchorId )
466 pFooterOrHeader = pCntnt->FindFooterOrHeader();
468 // OD 26.06.2003 #108784# - set <pFooterOrHeader> also for drawing
469 // objects, but not for control objects.
470 // Necessary for moving 'anchor symbol' at the user interface inside header/footer.
471 else if ( !::CheckControlLayer( pObj ) )
473 SwCntntFrm *pCntnt = GetCurrFrm( sal_False );
474 if( !pCntnt )
475 return aRet;
476 pFooterOrHeader = pCntnt->FindFooterOrHeader();
479 //Ausgehend von der linken oberen Ecke des Fly den
480 //dichtesten SwFlyFrm suchen.
481 SwCntntFrm *pTxtFrm;
483 SwCrsrMoveState aState( MV_SETONLYTEXT );
484 SwPosition aPos( GetDoc()->GetNodes().GetEndOfExtras() );
485 Point aTmpPnt( rAbsPos );
486 GetLayout()->GetCrsrOfst( &aPos, aTmpPnt, &aState );
487 pTxtFrm = aPos.nNode.GetNode().GetCntntNode()->GetFrm(0,&aPos,FALSE );
489 const SwFrm *pNewAnch;
490 if( pTxtFrm )
492 if( FLY_PAGE == nAnchorId )
493 pNewAnch = pTxtFrm->FindPageFrm();
494 else
496 pNewAnch = ::FindAnchor( pTxtFrm, rAbsPos );
498 if( FLY_AT_FLY == nAnchorId ) // LAYER_IMPL
499 pNewAnch = pNewAnch->FindFlyFrm();
502 else
503 pNewAnch = 0;
505 if( pNewAnch && !pNewAnch->IsProtected() )
507 const SwFlyFrm* pCheck = bFlyFrame ? pNewAnch->FindFlyFrm() : 0;
508 // Falls wir innerhalb eines Rahmens landen, muss sichergestellt werden,
509 // dass der Rahmen nicht in seinem eigenen Inhalt landet!
510 while( pCheck )
512 if( pCheck == pFly )
513 break;
514 const SwFrm *pTmp = pCheck->GetAnchorFrm();
515 pCheck = pTmp ? pTmp->FindFlyFrm() : NULL;
517 // Es darf nicht aus einer Kopf-/Fusszeile in einen anderen Bereich
518 // gewechselt werden, es darf nicht in eine Kopf-/Fusszeile hinein-
519 // gewechselt werden.
520 if( !pCheck &&
521 pFooterOrHeader == pNewAnch->FindFooterOrHeader() )
523 aRet = pNewAnch->GetFrmAnchorPos( ::HasWrap( pObj ) );
525 if( bMoveIt || nAnchorId == FLY_AUTO_CNTNT )
527 SwFmtAnchor aAnch( rFmt.GetAnchor() );
528 switch ( nAnchorId )
530 case FLY_AT_CNTNT:
532 SwPosition *pPos = (SwPosition*)aAnch.GetCntntAnchor();
533 pPos->nNode = *pTxtFrm->GetNode();
534 pPos->nContent.Assign(0,0);
535 break;
537 case FLY_PAGE:
539 aAnch.SetPageNum( ((const SwPageFrm*)pNewAnch)->
540 GetPhyPageNum() );
541 break;
543 case FLY_AT_FLY:
545 SwPosition aPos( *((SwFlyFrm*)pNewAnch)->GetFmt()->
546 GetCntnt().GetCntntIdx() );
547 aAnch.SetAnchor( &aPos );
548 break;
550 case FLY_AUTO_CNTNT:
552 SwPosition *pPos = (SwPosition*)aAnch.GetCntntAnchor();
553 Point aTmpPnt( rAbsPos );
554 if( pTxtFrm->GetCrsrOfst( pPos, aTmpPnt, NULL ) )
556 SwRect aTmpRect;
557 pTxtFrm->GetCharRect( aTmpRect, *pPos );
558 aRet = aTmpRect.Pos();
560 else
562 pPos->nNode = *pTxtFrm->GetNode();
563 pPos->nContent.Assign(0,0);
565 break;
567 default:
568 break;
570 if( bMoveIt )
572 StartAllAction();
573 // --> OD 2006-02-28 #125892#
574 // handle change of anchor node:
575 // if count of the anchor frame also change, the fly frames have to be
576 // re-created. Thus, delete all fly frames except the <this> before the
577 // anchor attribute is change and re-create them afterwards.
579 SwHandleAnchorNodeChg* pHandleAnchorNodeChg( 0L );
580 SwFlyFrmFmt* pFlyFrmFmt( dynamic_cast<SwFlyFrmFmt*>(&rFmt) );
581 if ( pFlyFrmFmt )
583 pHandleAnchorNodeChg =
584 new SwHandleAnchorNodeChg( *pFlyFrmFmt, aAnch );
586 rFmt.GetDoc()->SetAttr( aAnch, rFmt );
587 delete pHandleAnchorNodeChg;
589 // <--
590 // --> OD 2004-06-24 #i28701# - no call of method
591 // <CheckCharRectAndTopOfLine()> for to-character anchored
592 // Writer fly frame needed. This method call can cause a
593 // format of the anchor frame, which is no longer intended.
594 // Instead clear the anchor character rectangle and
595 // the top of line values for all to-character anchored objects.
596 pAnchoredObj->ClearCharRectAndTopOfLine();
597 // <--
598 EndAllAction();
602 SwRect aTmpRect( aRet, rAbsPos );
603 if( aTmpRect.HasArea() )
604 MakeVisible( aTmpRect );
605 #ifndef PRODUCT
606 //TODO: That doesn't seem to be intended
607 if( Color(COL_TRANSPARENT) != GetOut()->GetLineColor() )
609 ASSERT( FALSE, "Hey, Joe: Where's my Null Pen?" );
610 GetOut()->SetLineColor( Color(COL_TRANSPARENT) );
612 #endif
616 return aRet;
619 /***********************************************************************
620 #* Class : SwFEShell
621 #* Methode : NewFlyFrm
622 #* Beschreibung:
623 #* Datum : MA 03. Nov. 92
624 #* Update : JP 11. Aug. 93
625 #***********************************************************************/
627 const SwFrmFmt *SwFEShell::NewFlyFrm( const SfxItemSet& rSet, sal_Bool bAnchValid,
628 SwFrmFmt *pParent )
630 SET_CURR_SHELL( this );
631 StartAllAction();
633 SwPaM* pCrsr = GetCrsr();
634 const Point aPt( GetCrsrDocPos() );
636 SwSelBoxes aBoxes;
637 sal_Bool bMoveCntnt = sal_True;
638 if( IsTableMode() )
640 GetTblSel( *this, aBoxes );
641 if( aBoxes.Count() )
643 // die Crsr muessen noch aus dem Loeschbereich entfernt
644 // werden. Setze sie immer hinter/auf die Tabelle; ueber die
645 // Dokument-Position werden sie dann immer an die alte
646 // Position gesetzt.
647 ParkCrsr( SwNodeIndex( *aBoxes[0]->GetSttNd() ));
649 // --> FME 2005-12-01 #i127787# pCurCrsr will be deleted in ParkCrsr,
650 // we better get the current pCurCrsr instead of working with the
651 // deleted one:
652 pCrsr = GetCrsr();
653 // <--
655 // KillPams();
657 else
658 bMoveCntnt = sal_False;
660 else if( !pCrsr->HasMark() && pCrsr->GetNext() == pCrsr )
661 bMoveCntnt = sal_False;
663 const SwPosition& rPos = *pCrsr->Start();
665 SwFmtAnchor& rAnch = (SwFmtAnchor&)rSet.Get( RES_ANCHOR );
666 RndStdIds eRndId = rAnch.GetAnchorId();
667 switch( eRndId )
669 case FLY_PAGE:
670 if( !rAnch.GetPageNum() ) //HotFix: Bug in UpdateByExample
671 rAnch.SetPageNum( 1 );
672 break;
674 case FLY_AT_FLY:
675 case FLY_AT_CNTNT:
676 case FLY_AUTO_CNTNT:
677 case FLY_IN_CNTNT:
678 if( !bAnchValid )
680 if( FLY_AT_FLY != eRndId )
681 rAnch.SetAnchor( &rPos );
682 else if( lcl_SetNewFlyPos( rPos.nNode.GetNode(), rAnch, aPt ) )
683 eRndId = FLY_PAGE;
685 break;
687 default:
688 ASSERT( !this, "Was sollte das fuer ein Fly werden?" )
689 break;
692 SwFlyFrmFmt *pRet;
693 if( bMoveCntnt )
695 GetDoc()->StartUndo( UNDO_INSLAYFMT, NULL );
696 SwFmtAnchor* pOldAnchor = 0;
697 sal_Bool bHOriChgd = sal_False, bVOriChgd = sal_False;
698 SwFmtVertOrient aOldV;
699 SwFmtHoriOrient aOldH;
701 if( FLY_PAGE != eRndId )
703 // erstmal als mit Seitenbindung, Absatz/Zeichenbindung erst wenn
704 // alles verschoben ist. Dann ist die Position gueltig!
705 // JP 13.05.98: ggfs. auch noch die Hori/Vert-Orientierung
706 // umsetzen, damit diese beim Umanker NICHT
707 // korrigiert wird
708 pOldAnchor = new SwFmtAnchor( rAnch );
709 ((SfxItemSet&)rSet).Put( SwFmtAnchor( FLY_PAGE, 1 ) );
711 const SfxPoolItem* pItem;
712 if( SFX_ITEM_SET == rSet.GetItemState( RES_HORI_ORIENT, sal_False, &pItem )
713 && text::HoriOrientation::NONE == ((SwFmtHoriOrient*)pItem)->GetHoriOrient() )
715 bHOriChgd = sal_True;
716 aOldH = *((SwFmtHoriOrient*)pItem);
717 ((SfxItemSet&)rSet).Put( SwFmtHoriOrient( 0, text::HoriOrientation::LEFT ) );
719 if( SFX_ITEM_SET == rSet.GetItemState( RES_VERT_ORIENT, sal_False, &pItem )
720 && text::VertOrientation::NONE == ((SwFmtVertOrient*)pItem)->GetVertOrient() )
722 bVOriChgd = sal_True;
723 aOldV = *((SwFmtVertOrient*)pItem);
724 ((SfxItemSet&)rSet).Put( SwFmtVertOrient( 0, text::VertOrientation::TOP ) );
728 pRet = GetDoc()->MakeFlyAndMove( *pCrsr, rSet, &aBoxes, pParent );
730 KillPams();
732 if( pOldAnchor )
734 if( pRet )
736 // neue Position bestimmen
737 //JP 24.03.97: immer ueber die Seitenbindung gehen - der
738 // chaos::Anchor darf nie im verschobenen Bereich
739 // liegen
740 pRet->DelFrms();
742 const SwFrm* pAnch = ::FindAnchor( GetLayout(), aPt, sal_False );
743 SwPosition aPos( *((SwCntntFrm*)pAnch)->GetNode() );
744 if( FLY_IN_CNTNT == eRndId )
745 aPos.nContent.Assign( ((SwCntntFrm*)pAnch)->GetNode(), 0 );
746 pOldAnchor->SetAnchor( &aPos );
748 // das verschieben von TabelleSelektion ist noch nicht
749 // Undofaehig - also darf das UmAnkern auch nicht
750 // aufgezeichnet werden.
751 sal_Bool bDoesUndo = GetDoc()->DoesUndo();
752 if( bDoesUndo && UNDO_INSLAYFMT == GetDoc()->GetUndoIds(NULL, NULL) )
753 GetDoc()->DoUndo( sal_False );
755 ((SfxItemSet&)rSet).Put( *pOldAnchor );
757 if( bHOriChgd )
758 ((SfxItemSet&)rSet).Put( aOldH );
759 if( bVOriChgd )
760 ((SfxItemSet&)rSet).Put( aOldV );
762 GetDoc()->SetFlyFrmAttr( *pRet, (SfxItemSet&)rSet );
763 GetDoc()->DoUndo( bDoesUndo );
765 delete pOldAnchor;
767 GetDoc()->EndUndo( UNDO_INSLAYFMT, NULL );
769 else
770 /* #109161# If called from a shell try to propagate an
771 existing adjust item from rPos to the content node of the
772 new frame. */
773 pRet = GetDoc()->MakeFlySection( eRndId, &rPos, &rSet, pParent, TRUE );
775 if( pRet )
777 SwFlyFrm* pFrm = pRet->GetFrm( &aPt );
778 if( pFrm )
779 SelectFlyFrm( *pFrm, sal_True );
780 else
782 GetLayout()->SetAssertFlyPages();
783 pRet = 0;
786 EndAllActionAndCall();
788 return pRet;
791 /***********************************************************************
792 #* Class : SwFEShell
793 #* Methode : Insert
794 #* Datum : ??
795 #* Update : MA 12. Sep. 94
796 #***********************************************************************/
798 void SwFEShell::Insert( const String& rGrfName, const String& rFltName,
799 const Graphic* pGraphic,
800 const SfxItemSet* pFlyAttrSet,
801 const SfxItemSet* pGrfAttrSet,
802 SwFrmFmt* pFrmFmt )
804 SwFlyFrmFmt* pFmt = 0;
805 SET_CURR_SHELL( this );
806 StartAllAction();
807 SwShellCrsr *pStartCursor = dynamic_cast<SwShellCrsr*>(this->GetSwCrsr());
808 SwShellCrsr *pCursor = pStartCursor;
809 do {
811 // Anker noch nicht oder unvollstaendig gesetzt ?
812 if( pFlyAttrSet )
814 const SfxPoolItem* pItem;
815 if( SFX_ITEM_SET == pFlyAttrSet->GetItemState( RES_ANCHOR, sal_False,
816 &pItem ) )
818 SwFmtAnchor* pAnchor = (SwFmtAnchor*)pItem;
819 switch( pAnchor->GetAnchorId())
821 case FLY_AT_CNTNT:
822 case FLY_AUTO_CNTNT: // LAYER_IMPL
823 case FLY_IN_CNTNT:
824 if( !pAnchor->GetCntntAnchor() )
826 pAnchor->SetAnchor( pCursor->GetPoint() );
828 break;
829 case FLY_AT_FLY:
830 if( !pAnchor->GetCntntAnchor() )
832 lcl_SetNewFlyPos( *pCursor->GetNode(),
833 *pAnchor, GetCrsrDocPos() );
835 break;
836 case FLY_PAGE:
837 if( !pAnchor->GetPageNum() )
839 pAnchor->SetPageNum( pCursor->GetPageNum(
840 sal_True, &pCursor->GetPtPos() ) );
842 break;
843 default :
844 break;
848 pFmt = GetDoc()->Insert(*pCursor, rGrfName,
849 rFltName, pGraphic,
850 pFlyAttrSet,
851 pGrfAttrSet, pFrmFmt );
852 ASSERT( pFmt, "Doc->Insert(notxt) failed." );
854 } while( (pCursor = dynamic_cast<SwShellCrsr*>(pCursor->GetNext()))
855 != pStartCursor );
857 EndAllAction();
859 if( pFmt )
861 const Point aPt( GetCrsrDocPos() );
862 SwFlyFrm* pFrm = pFmt->GetFrm( &aPt );
864 if( pFrm )
865 SelectFlyFrm( *pFrm, sal_True );
866 else
867 GetLayout()->SetAssertFlyPages();
871 SwFlyFrmFmt* SwFEShell::InsertObject( const svt::EmbeddedObjectRef& xObj,
872 const SfxItemSet* pFlyAttrSet,
873 const SfxItemSet* pGrfAttrSet,
874 SwFrmFmt* pFrmFmt )
876 SwFlyFrmFmt* pFmt = 0;
877 SET_CURR_SHELL( this );
878 StartAllAction();
879 FOREACHPAM_START( this )
880 pFmt = GetDoc()->Insert(*PCURCRSR, xObj,
881 pFlyAttrSet, pGrfAttrSet, pFrmFmt );
882 ASSERT( pFmt, "Doc->Insert(notxt) failed." );
884 FOREACHPAM_END()
885 EndAllAction();
887 if( pFmt )
889 const Point aPt( GetCrsrDocPos() );
890 SwFlyFrm* pFrm = pFmt->GetFrm( &aPt );
892 if( pFrm )
893 SelectFlyFrm( *pFrm, sal_True );
894 else
895 GetLayout()->SetAssertFlyPages();
898 return pFmt;
902 void SwFEShell::Insert( SdrObject& rDrawObj,
903 const SfxItemSet* pFlyAttrSet,
904 SwFrmFmt* pFrmFmt, const Point* pPt )
906 SwDrawFrmFmt* pFmt = 0;
907 SET_CURR_SHELL( this );
909 if( pPt )
911 SfxItemSet* pSet = 0;
912 const SfxPoolItem* pItem;
913 if( !pFlyAttrSet ||
914 !pFlyAttrSet->GetItemState( RES_ANCHOR, sal_False, &pItem ) ||
915 FLY_PAGE != ((SwFmtAnchor*)pItem)->GetAnchorId() )
917 pSet = new SfxItemSet( GetDoc()->GetAttrPool(), aFrmFmtSetRange );
918 pSet->Put( SwFmtAnchor( FLY_AT_CNTNT ));
919 pFlyAttrSet = pSet;
922 SwCrsrMoveState aState( MV_SETONLYTEXT );
923 SwPaM aPam( pDoc->GetNodes() );
924 Point aTmpPt( *pPt );
925 getIDocumentLayoutAccess()->GetRootFrm()->GetCrsrOfst( aPam.GetPoint(), aTmpPt, &aState );
926 SwFrm* pFrm = aPam.GetCntntNode()->GetFrm( 0, 0, sal_False );
927 const Point aRelPos( pPt->X() - pFrm->Frm().Left(),
928 pPt->Y() - pFrm->Frm().Top() );
929 // OD 2004-04-05 #i26791# - direct object positioning for <SwDoc::Insert(..)>
930 rDrawObj.SetRelativePos( aRelPos );
931 ::lcl_FindAnchorPos( *GetDoc(), *pPt, *pFrm, *(SfxItemSet*)pFlyAttrSet );
932 pFmt = GetDoc()->Insert( aPam, rDrawObj, pFlyAttrSet, pFrmFmt );
933 if( pSet )
934 delete pSet;
936 else
938 StartAllAction();
939 FOREACHPAM_START( this )
940 pFmt = GetDoc()->Insert(*PCURCRSR, rDrawObj,
941 pFlyAttrSet, pFrmFmt );
942 ASSERT( pFmt, "Doc->Insert(sdrobj) failed." );
944 FOREACHPAM_END()
945 EndAllAction();
948 // --> OD 2005-01-07 #i40085# - follow-up of #i35635#
949 // move object to visible layer
950 SwContact* pContact = static_cast<SwContact*>(rDrawObj.GetUserCall());
951 if ( pContact )
953 pContact->MoveObjToVisibleLayer( &rDrawObj );
955 // <--
957 if( pFmt )
958 // das DrawObject selektieren
959 Imp()->GetDrawView()->MarkObj( &rDrawObj, Imp()->GetPageView(),
960 sal_False, sal_False );
961 else
962 GetLayout()->SetAssertFlyPages();
965 /***********************************************************************
966 #* Class : SwFEShell
967 #* Methode : GetPageObjs
968 #* Datum : ??
969 #* Update : MA 11. Jan. 95
970 #***********************************************************************/
972 void SwFEShell::GetPageObjs( SvPtrarr& rFillArr )
974 if( rFillArr.Count() )
975 rFillArr.Remove( 0, rFillArr.Count() );
977 const SwFrmFmt* pFmt;
978 for( sal_uInt16 n = 0; n < pDoc->GetSpzFrmFmts()->Count(); ++n )
980 pFmt = (const SwFrmFmt*)(*pDoc->GetSpzFrmFmts())[n];
981 if( FLY_PAGE == pFmt->GetAnchor().GetAnchorId() )
982 rFillArr.Insert( (VoidPtr)pFmt, rFillArr.Count() );
986 /***********************************************************************
987 #* Class : SwFEShell
988 #* Methode : SetPageFlysNewPage
989 #* Datum : ??
990 #* Update : MA 14. Feb. 95
991 #***********************************************************************/
993 void SwFEShell::SetPageObjsNewPage( SvPtrarr& rFillArr, int nOffset )
995 if( !rFillArr.Count() || !nOffset )
996 return;
998 StartAllAction();
999 StartUndo();
1001 SwFrmFmt* pFmt;
1002 long nNewPage;
1003 SwRootFrm* pTmpRootFrm = getIDocumentLayoutAccess()->GetRootFrm();
1004 sal_uInt16 nMaxPage = pTmpRootFrm->GetPageNum();
1005 sal_Bool bTmpAssert = sal_False;
1006 for( sal_uInt16 n = 0; n < rFillArr.Count(); ++n )
1008 pFmt = (SwFrmFmt*)rFillArr[n];
1009 if( USHRT_MAX != pDoc->GetSpzFrmFmts()->GetPos( pFmt ))
1011 // FlyFmt ist noch gueltig, also behandeln
1012 SwFmtAnchor aNewAnchor( pFmt->GetAnchor() );
1013 if( FLY_PAGE != aNewAnchor.GetAnchorId() ||
1014 0 >= ( nNewPage = aNewAnchor.GetPageNum() + nOffset ) )
1015 // chaos::Anchor wurde veraendert oder ungueltige SeitenNummer,
1016 // also nicht veraendern !!
1017 continue;
1019 if( sal_uInt16(nNewPage) > nMaxPage )
1021 if ( RES_DRAWFRMFMT == pFmt->Which() )
1023 SwContact *pCon = pFmt->FindContactObj();
1024 if( pCon )
1025 ((SwDrawContact*)pCon)->DisconnectFromLayout();
1027 else
1028 pFmt->DelFrms();
1029 bTmpAssert = sal_True;
1031 aNewAnchor.SetPageNum( sal_uInt16(nNewPage) );
1032 pDoc->SetAttr( aNewAnchor, *pFmt );
1036 if( bTmpAssert )
1037 pTmpRootFrm->SetAssertFlyPages();
1039 EndUndo();
1040 EndAllAction();
1043 /***********************************************************************
1044 #* Class : SwFEShell
1045 #* Methode : GetFlyFrmAttr
1046 #* Beschreibung: Alle Attribute in dem 'Koerbchen' werden mit den
1047 #* Attributen des aktuellen FlyFrms gefuellt.
1048 #* Sind Attribute nicht zu fuellen weil fehl am Platz oder
1049 #* uneindeutig (Mehrfachtselektionen) so werden sie entfernt.
1050 #* Datum : MA 03. Nov. 92
1051 #* Update : MA 03. Feb. 94
1052 #***********************************************************************/
1054 sal_Bool SwFEShell::GetFlyFrmAttr( SfxItemSet &rSet ) const
1056 SwFlyFrm *pFly = FindFlyFrm();
1057 if ( !pFly )
1059 // --> OD 2006-11-08 #139670# - make code robust
1060 SwFrm* pCurrFrm( GetCurrFrm() );
1061 if ( !pCurrFrm )
1063 ASSERT( false,
1064 "<SwFEShell::GetFlyFrmAttr(..)> - missing current frame. This is a serious defect, please inform OD." );
1065 return sal_False;
1067 // <--
1068 pFly = GetCurrFrm()->FindFlyFrm();
1069 if ( !pFly )
1071 ASSERT( !this, "GetFlyFrmAttr, no Fly selected." );
1072 return sal_False;
1076 SET_CURR_SHELL( (ViewShell*)this );
1078 if( !rSet.Set( pFly->GetFmt()->GetAttrSet(), sal_True ) )
1079 return sal_False;
1081 //Und die Attribute durchschaufeln. Unerlaubte Attribute entfernen, dann
1082 //alle restlichen Attribute besorgen und eintragen.
1083 const SfxPoolItem* pItem;
1084 if( SFX_ITEM_SET == rSet.GetItemState( RES_ANCHOR, sal_False, &pItem ) )
1086 SwFmtAnchor* pAnchor = (SwFmtAnchor*)pItem;
1087 RndStdIds eType = pAnchor->GetAnchorId();
1089 if( FLY_PAGE != eType )
1091 // OD 12.11.2003 #i22341# - content anchor of anchor item is needed.
1092 // Thus, don't overwrite anchor item by default contructed anchor item.
1093 //rSet.Put( SwFmtAnchor( eType ) );
1094 if( FLY_IN_CNTNT == eType )
1096 rSet.ClearItem( RES_OPAQUE );
1097 rSet.ClearItem( RES_SURROUND );
1101 rSet.SetParent( pFly->GetFmt()->GetAttrSet().GetParent() );
1102 //JP 11.02.97: Bug #35894#: die Attribute MUESSEN entfern werden!
1103 rSet.ClearItem( RES_FILL_ORDER );
1104 rSet.ClearItem( RES_CNTNT );
1105 //MA: Ersteinmal entfernen (Template by example usw.)
1106 rSet.ClearItem( RES_CHAIN );
1107 return sal_True;
1109 /***********************************************************************
1110 #* Class : SwFEShell
1111 #* Methode : SetFlyFrmAttr
1112 #* Beschreibung: Die Attribute des aktuellen Flys aendern sich.
1113 #* Datum : MA 03. Nov. 92
1114 #* Update : MA 01. Aug. 95
1115 #***********************************************************************/
1117 sal_Bool SwFEShell::SetFlyFrmAttr( SfxItemSet& rSet )
1119 SET_CURR_SHELL( this );
1120 sal_Bool bRet = sal_False;
1122 if( rSet.Count() )
1124 SwFlyFrm *pFly = FindFlyFrm();
1125 if( !pFly )
1127 ASSERT( GetCurrFrm(), "Crsr in parking zone" );
1128 pFly = GetCurrFrm()->FindFlyFrm();
1129 ASSERT( pFly, "SetFlyFrmAttr, no Fly selected." );
1131 if( pFly )
1133 StartAllAction();
1134 const Point aPt( pFly->Frm().Pos() );
1136 if( SFX_ITEM_SET == rSet.GetItemState( RES_ANCHOR, sal_False ))
1137 ::lcl_ChkAndSetNewAnchor( *pFly, rSet );
1138 SwFlyFrmFmt* pFlyFmt = (SwFlyFrmFmt*)pFly->GetFmt();
1140 if( GetDoc()->SetFlyFrmAttr( *pFlyFmt, rSet ))
1142 bRet = sal_True;
1143 SwFlyFrm* pFrm = pFlyFmt->GetFrm( &aPt );
1144 if( pFrm )
1145 SelectFlyFrm( *pFrm, sal_True );
1146 else
1147 GetLayout()->SetAssertFlyPages();
1150 EndAllActionAndCall();
1153 return bRet;
1155 /*-- 30.03.2004 15:05:07---------------------------------------------------
1157 -----------------------------------------------------------------------*/
1158 sal_Bool SwFEShell::SetDrawingAttr( SfxItemSet& rSet )
1160 sal_Bool bRet = sal_False;
1161 SET_CURR_SHELL( this );
1162 if ( !rSet.Count() ||
1163 !Imp()->HasDrawView() )
1164 return bRet;
1166 const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
1167 if ( rMrkList.GetMarkCount() != 1 )
1168 return bRet;
1170 StartUndo();
1171 SdrObject *pObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
1172 SwFrmFmt *pFmt = FindFrmFmt( pObj );
1173 StartAllAction();
1174 if( SFX_ITEM_SET == rSet.GetItemState( RES_ANCHOR, sal_False ))
1176 RndStdIds nNew = ((SwFmtAnchor&)rSet.Get( RES_ANCHOR )).GetAnchorId();
1177 if ( nNew != pFmt->GetAnchor().GetAnchorId() )
1179 ChgAnchor( nNew );
1180 // --> OD 2004-06-17 #i26791# - clear anchor attribute in item set,
1181 // because method <ChgAnchor(..)> takes care of it.
1182 rSet.ClearItem( RES_ANCHOR );
1186 if( GetDoc()->SetFlyFrmAttr( *pFmt, rSet ))
1188 bRet = sal_True;
1189 Point aTmp;
1190 SelectObj( aTmp, 0, pObj );
1192 EndAllActionAndCall();
1193 EndUndo();
1194 return bRet;
1198 /***********************************************************************
1199 #* Class : SwFEShell
1200 #* Methode : ResetFlyFrmAttr
1201 #* Beschreibung: Das gewuenschte Attribut oder die im Set befindlichen
1202 #* werden zurueckgesetzt.
1203 #* Datum : MA 14. Mar. 97
1204 #* Update : MA 14. Mar. 97
1205 #***********************************************************************/
1207 sal_Bool SwFEShell::ResetFlyFrmAttr( sal_uInt16 nWhich, const SfxItemSet* pSet )
1209 sal_Bool bRet = sal_False;
1211 if( RES_ANCHOR != nWhich && RES_CHAIN != nWhich && RES_CNTNT != nWhich )
1213 SET_CURR_SHELL( this );
1215 SwFlyFrm *pFly = FindFlyFrm();
1216 if( !pFly )
1218 ASSERT( GetCurrFrm(), "Crsr in parking zone" );
1219 pFly = GetCurrFrm()->FindFlyFrm();
1220 ASSERT( pFly, "SetFlyFrmAttr, no Fly selected." );
1223 if( pFly )
1225 StartAllAction();
1227 if( pSet )
1229 SfxItemIter aIter( *pSet );
1230 const SfxPoolItem* pItem = aIter.FirstItem();
1231 while( pItem )
1233 if( !IsInvalidItem( pItem ) &&
1234 RES_ANCHOR != ( nWhich = pItem->Which() ) &&
1235 RES_CHAIN != nWhich && RES_CNTNT != nWhich )
1236 pFly->GetFmt()->ResetFmtAttr( nWhich );
1237 pItem = aIter.NextItem();
1240 else
1241 pFly->GetFmt()->ResetFmtAttr( nWhich );
1243 bRet = sal_True;
1244 EndAllActionAndCall();
1245 GetDoc()->SetModified();
1248 return bRet;
1251 /***********************************************************************
1252 #* Class : SwFEShell
1253 #* Methode : GetCurFrmFmt
1254 #* Beschreibung: liefert wenn Rahmen, dann Rahmenvorlage, sonst 0
1255 #* Datum : ST 04. Jun. 93
1256 #* Update :
1257 #***********************************************************************/
1259 SwFrmFmt* SwFEShell::GetCurFrmFmt() const
1261 SwFrmFmt* pRet = 0;
1262 SwLayoutFrm *pFly = FindFlyFrm();
1263 if( pFly && ( pRet = (SwFrmFmt*)pFly->GetFmt()->DerivedFrom() ) ==
1264 GetDoc()->GetDfltFrmFmt() )
1265 pRet = 0;
1266 return pRet;
1269 /******************************************************************************
1270 * Methode : void SwFEShell::SetFrmFmt(SwFrmFmt *pNewFmt)
1271 * Beschreibung:
1272 * Erstellt : OK 14.04.94 15:40
1273 * Aenderung : MA 23. Apr. 97
1274 ******************************************************************************/
1276 void SwFEShell::SetFrmFmt( SwFrmFmt *pNewFmt, sal_Bool bKeepOrient, Point* pDocPos )
1278 SwFlyFrm *pFly = 0;
1279 if(pDocPos)
1281 const SwFrmFmt* pFmt = GetFmtFromObj( *pDocPos );
1283 if(PTR_CAST(SwFlyFrmFmt, pFmt))
1284 pFly = ((SwFlyFrmFmt*)pFmt)->GetFrm();
1286 else
1287 pFly = FindFlyFrm();
1288 ASSERT( pFly, "SetFrmFmt: kein Frame" );
1289 if( pFly )
1291 StartAllAction();
1292 SET_CURR_SHELL( this );
1294 SwFlyFrmFmt* pFlyFmt = (SwFlyFrmFmt*)pFly->GetFmt();
1295 const Point aPt( pFly->Frm().Pos() );
1297 SfxItemSet* pSet = 0;
1298 const SfxPoolItem* pItem;
1299 if( SFX_ITEM_SET == pNewFmt->GetItemState( RES_ANCHOR, sal_False, &pItem ))
1301 pSet = new SfxItemSet( GetDoc()->GetAttrPool(), aFrmFmtSetRange );
1302 pSet->Put( *pItem );
1303 if( !::lcl_ChkAndSetNewAnchor( *pFly, *pSet ))
1304 delete pSet, pSet = 0;
1307 if( GetDoc()->SetFrmFmtToFly( *pFlyFmt, *pNewFmt, pSet, bKeepOrient ))
1309 SwFlyFrm* pFrm = pFlyFmt->GetFrm( &aPt );
1310 if( pFrm )
1311 SelectFlyFrm( *pFrm, sal_True );
1312 else
1313 GetLayout()->SetAssertFlyPages();
1315 if( pSet )
1316 delete pSet;
1318 EndAllActionAndCall();
1322 /*************************************************************************
1324 |* SwFEShell::GetFlyFrmFmt()
1326 |* Ersterstellung OK 23.06.93 13:15
1327 |* Letzte Aenderung OK 23.06.93 13:15
1329 *************************************************************************/
1331 const SwFrmFmt* SwFEShell::GetFlyFrmFmt() const
1333 const SwFlyFrm* pFly = FindFlyFrm();
1334 if ( !pFly )
1336 SwFrm* pCurrFrm = GetCurrFrm();
1337 pFly = pCurrFrm ? pCurrFrm->FindFlyFrm() : 0;
1339 if( pFly )
1340 return pFly->GetFmt();
1341 return 0;
1344 SwFrmFmt* SwFEShell::GetFlyFrmFmt()
1346 SwFlyFrm* pFly = FindFlyFrm();
1347 if ( !pFly )
1349 SwFrm* pCurrFrm = GetCurrFrm();
1350 pFly = pCurrFrm ? pCurrFrm->FindFlyFrm() : 0;
1352 if( pFly )
1353 return pFly->GetFmt();
1354 return 0;
1357 /*************************************************************************
1359 |* SwFEShell::GetFlyRect()
1361 |* Ersterstellung AMA 6. Mae. 97
1362 |* Letzte Aenderung AMA 6. Mae. 97
1364 *************************************************************************/
1366 SwRect SwFEShell::GetFlyRect() const
1368 SwCntntFrm *pCntnt = GetCurrFrm( sal_False );
1369 SwFlyFrm *pFly = pCntnt ? pCntnt->FindFlyFrm() : 0;
1370 if ( !pFly )
1372 SwRect aRect;
1373 return aRect;
1375 else
1376 return pFly->Frm();
1379 /*************************************************************************
1381 |* SwFEShell::GetObjRect()
1383 |* Ersterstellung MA 22. Aug. 93
1384 |* Letzte Aenderung MA 11. Jan. 95
1386 *************************************************************************/
1388 SwRect SwFEShell::GetObjRect() const
1390 if( Imp()->HasDrawView() )
1391 return Imp()->GetDrawView()->GetAllMarkedRect();
1392 else
1394 SwRect aRect;
1395 return aRect;
1399 void SwFEShell::SetObjRect( const SwRect& rRect )
1401 if ( Imp()->HasDrawView() )
1403 Imp()->GetDrawView()->SetAllMarkedRect( rRect.SVRect() );
1404 CallChgLnk(); // rufe das AttrChangeNotify auf der UI-Seite.
1408 /***********************************************************************
1409 #* Class : SwFEShell
1410 #* Methode : RequestObjectResize()
1411 #* Datum : MA 10. Feb. 95
1412 #* Update : MA 13. Jul. 95
1413 #***********************************************************************/
1415 Size SwFEShell::RequestObjectResize( const SwRect &rRect, const uno::Reference < embed::XEmbeddedObject >& xObj )
1417 Size aResult;
1419 SwFlyFrm *pFly = FindFlyFrm( xObj );
1420 if ( !pFly )
1422 aResult = rRect.SSize();
1423 return aResult;
1426 aResult = pFly->Prt().SSize();
1428 sal_Bool bPosProt = pFly->GetFmt()->GetProtect().IsPosProtected();
1429 sal_Bool bSizeProt = pFly->GetFmt()->GetProtect().IsSizeProtected();
1431 StartAllAction();
1433 //MA wir lassen den Fly nicht Clippen, damit die Ole-Server mit
1434 //beliebigen Wuenschen kommen koennen. Die Formatierung uebernimmt das
1435 //Clippen. Die richtige Darstellung wird per Scalierung erledigt.
1436 //Die Scalierung wird von SwNoTxtFrm::Format durch einen Aufruf von
1437 //SwWrtShell::CalcAndSetScale() erledigt.
1438 if ( rRect.SSize() != pFly->Prt().SSize() && !bSizeProt )
1440 Size aSz( rRect.SSize() );
1442 //JP 28.02.2001: Task 74707 - ask for fly in fly with automatic size
1444 const SwFrm* pAnchor;
1445 const SwTxtNode* pTNd;
1446 const SwpHints* pHts;
1447 const SwFmtFrmSize& rFrmSz = pFly->GetFmt()->GetFrmSize();
1448 if( bCheckForOLEInCaption &&
1449 0 != rFrmSz.GetWidthPercent() &&
1450 0 != (pAnchor = pFly->GetAnchorFrm()) &&
1451 pAnchor->IsTxtFrm() &&
1452 !pAnchor->GetNext() && !pAnchor->GetPrev() &&
1453 pAnchor->GetUpper()->IsFlyFrm() &&
1454 0 != ( pTNd = ((SwTxtFrm*)pAnchor)->GetNode()->GetTxtNode()) &&
1455 0 != ( pHts = pTNd->GetpSwpHints() ))
1457 // search for a sequence field:
1458 const SfxPoolItem* pItem;
1459 for( USHORT n = 0, nEnd = pHts->Count(); n < nEnd; ++n )
1460 if( RES_TXTATR_FIELD == ( pItem =
1461 &(*pHts)[ n ]->GetAttr())->Which() &&
1462 TYP_SEQFLD == ((SwFmtFld*)pItem)->GetFld()->GetTypeId() )
1464 // sequence field found
1465 SwFlyFrm* pChgFly = (SwFlyFrm*)pAnchor->GetUpper();
1466 // calculate the changed size:
1467 // width must change, height can change
1468 Size aNewSz( aSz.Width() + pChgFly->Frm().Width() -
1469 pFly->Prt().Width(), aSz.Height() );
1471 SwFrmFmt *pFmt = pChgFly->GetFmt();
1472 SwFmtFrmSize aFrmSz( pFmt->GetFrmSize() );
1473 aFrmSz.SetWidth( aNewSz.Width() );
1474 if( ATT_MIN_SIZE != aFrmSz.GetHeightSizeType() )
1476 aNewSz.Height() += pChgFly->Frm().Height() -
1477 pFly->Prt().Height();
1478 if( Abs( aNewSz.Height() - pChgFly->Frm().Height()) > 1 )
1479 aFrmSz.SetHeight( aNewSz.Height() );
1481 // uebers Doc fuers Undo!
1482 pFmt->GetDoc()->SetAttr( aFrmSz, *pFmt );
1483 break;
1487 // set the new Size at the fly themself
1488 if ( pFly->Prt().Height() > 0 && pFly->Prt().Width() > 0 )
1490 aSz.Width() += pFly->Frm().Width() - pFly->Prt().Width();
1491 aSz.Height()+= pFly->Frm().Height()- pFly->Prt().Height();
1493 aResult = pFly->ChgSize( aSz );
1495 //Wenn sich das Objekt aendert ist die Kontur hoechstwahrscheinlich daneben.
1496 ASSERT( pFly->Lower()->IsNoTxtFrm(), "Request ohne NoTxt" );
1497 SwNoTxtNode *pNd = ((SwCntntFrm*)pFly->Lower())->GetNode()->GetNoTxtNode();
1498 ASSERT( pNd, "Request ohne Node" );
1499 pNd->SetContour( 0 );
1500 ClrContourCache();
1503 //Wenn nur die Size angepasst werden soll, so wird eine Pos mit
1504 //ausgezeichneten Werten transportiert.
1505 Point aPt( pFly->Prt().Pos() );
1506 aPt += pFly->Frm().Pos();
1507 if ( rRect.Top() != LONG_MIN && rRect.Pos() != aPt && !bPosProt )
1509 aPt = rRect.Pos();
1510 aPt.X() -= pFly->Prt().Left();
1511 aPt.Y() -= pFly->Prt().Top();
1512 //Bei Absatzgebundenen Flys muss ausgehend von der neuen Position ein
1513 //neuer Anker gesetzt werden. Anker und neue RelPos werden vom Fly
1514 //selbst berechnet und gesetzt.
1515 if( pFly->IsFlyAtCntFrm() )
1516 ((SwFlyAtCntFrm*)pFly)->SetAbsPos( aPt );
1517 else
1519 const SwFrmFmt *pFmt = pFly->GetFmt();
1520 const SwFmtVertOrient &rVert = pFmt->GetVertOrient();
1521 const SwFmtHoriOrient &rHori = pFmt->GetHoriOrient();
1522 const long lXDiff = aPt.X() - pFly->Frm().Left();
1523 const long lYDiff = aPt.Y() - pFly->Frm().Top();
1524 const Point aTmp( rHori.GetPos() + lXDiff,
1525 rVert.GetPos() + lYDiff );
1526 pFly->ChgRelPos( aTmp );
1529 EndAllAction();
1531 return aResult;
1535 /***********************************************************************
1536 #* Class : SwFEShell
1537 #* Methode : WizzardFindCurFrmFmt
1538 #* Datum : JP 31.07.95
1539 #* Update : JP 31.07.95
1540 #***********************************************************************/
1542 SwFrmFmt* SwFEShell::WizzardGetFly()
1544 // mal nicht uebers Layout den Fly suchen. Dann kann auch ohne gueltiges
1545 // Layout ein Rahmen geloescht werden. ( z.B.: fuer die Wizard's )
1546 SwSpzFrmFmts& rSpzArr = *pDoc->GetSpzFrmFmts();
1547 sal_uInt16 nCnt = rSpzArr.Count();
1548 if( nCnt )
1550 SwNodeIndex& rCrsrNd = GetCrsr()->GetPoint()->nNode;
1551 if( rCrsrNd.GetIndex() > pDoc->GetNodes().GetEndOfExtras().GetIndex() )
1552 // Cusor steht im Body-Bereich!
1553 return 0;
1555 for( sal_uInt16 n = 0; n < nCnt; ++n )
1557 SwFrmFmt* pFmt = rSpzArr[ n ];
1558 const SwNodeIndex* pIdx = pFmt->GetCntnt( sal_False ).GetCntntIdx();
1559 SwStartNode* pSttNd;
1560 if( pIdx &&
1561 0 != ( pSttNd = pIdx->GetNode().GetStartNode() ) &&
1562 pSttNd->GetIndex() < rCrsrNd.GetIndex() &&
1563 rCrsrNd.GetIndex() < pSttNd->EndOfSectionIndex() )
1565 // gefunden: also raus damit
1566 return pFmt;
1570 return 0;
1573 void SwFEShell::SetFlyName( const String& rName )
1575 SwLayoutFrm *pFly = FindFlyFrm();
1576 if( pFly )
1577 GetDoc()->SetFlyName( *(SwFlyFrmFmt*)pFly->GetFmt(), rName );
1578 else {
1579 ASSERT( !this, "kein FlyFrame selektiert" )
1583 const String& SwFEShell::GetFlyName() const
1585 SwLayoutFrm *pFly = FindFlyFrm();
1586 if( pFly )
1587 return pFly->GetFmt()->GetName();
1589 ASSERT( !this, "kein FlyFrame selektiert" )
1590 return aEmptyStr;
1594 String SwFEShell::GetUniqueGrfName() const
1596 return GetDoc()->GetUniqueGrfName();
1599 const SwFrmFmt* SwFEShell::IsURLGrfAtPos( const Point& rPt, String* pURL,
1600 String *pTargetFrameName,
1601 String *pDescription ) const
1603 if( !Imp()->HasDrawView() )
1604 return 0;
1606 SdrObject* pObj;
1607 SdrPageView* pPV;
1608 const SwFrmFmt* pRet = 0;
1609 SwDrawView *pDView = (SwDrawView*)Imp()->GetDrawView();
1611 sal_uInt16 nOld = pDView->GetHitTolerancePixel();
1612 pDView->SetHitTolerancePixel( 2 );
1614 if( pDView->PickObj( rPt, pDView->getHitTolLog(), pObj, pPV,SDRSEARCH_PICKMACRO ) &&
1615 pObj->ISA(SwVirtFlyDrawObj) )
1617 SwFlyFrm *pFly = ((SwVirtFlyDrawObj*)pObj)->GetFlyFrm();
1618 const SwFmtURL &rURL = pFly->GetFmt()->GetURL();
1619 if( rURL.GetURL().Len() || rURL.GetMap() )
1621 BOOL bSetTargetFrameName = pTargetFrameName != 0;
1622 BOOL bSetDescription = pDescription != 0;
1623 if ( rURL.GetMap() )
1625 IMapObject *pObject = pFly->GetFmt()->GetIMapObject( rPt, pFly );
1626 if ( pObject && pObject->GetURL().Len() )
1628 if( pURL )
1629 *pURL = pObject->GetURL();
1630 if ( bSetTargetFrameName && pObject->GetTarget().Len() )
1632 bSetTargetFrameName = sal_False;
1633 *pTargetFrameName = pObject->GetTarget();
1635 if ( bSetDescription )
1637 bSetDescription = sal_False;
1638 *pDescription = pObject->GetAltText();
1640 pRet = pFly->GetFmt();
1643 else
1645 if( pURL )
1647 *pURL = rURL.GetURL();
1648 if( rURL.IsServerMap() )
1650 // dann die rel. Pixel Position anhaengen !!
1651 Point aPt( rPt );
1652 aPt -= pFly->Frm().Pos();
1653 // ohne MapMode-Offset, ohne Offset, o ... !!!!!
1654 aPt = GetOut()->LogicToPixel(
1655 aPt, MapMode( MAP_TWIP ) );
1656 ((( *pURL += '?' ) += String::CreateFromInt32( aPt.X() ))
1657 += ',' ) += String::CreateFromInt32(aPt.Y() );
1660 pRet = pFly->GetFmt();
1662 if ( bSetTargetFrameName )
1663 *pTargetFrameName = rURL.GetTargetFrameName();
1664 if ( bSetDescription )
1665 *pDescription = pFly->GetFmt()->GetName();
1668 pDView->SetHitTolerancePixel( nOld );
1669 return pRet;
1672 const Graphic *SwFEShell::GetGrfAtPos( const Point &rPt,
1673 String &rName, sal_Bool &rbLink ) const
1675 if( !Imp()->HasDrawView() )
1676 return 0;
1678 SdrObject* pObj;
1679 SdrPageView* pPV;
1680 SwDrawView *pDView = (SwDrawView*)Imp()->GetDrawView();
1682 if( pDView->PickObj( rPt, pDView->getHitTolLog(), pObj, pPV ) && pObj->ISA(SwVirtFlyDrawObj) )
1684 SwFlyFrm *pFly = ((SwVirtFlyDrawObj*)pObj)->GetFlyFrm();
1685 if ( pFly->Lower() && pFly->Lower()->IsNoTxtFrm() )
1687 SwGrfNode *pNd = ((SwCntntFrm*)pFly->Lower())->GetNode()->GetGrfNode();
1688 if ( pNd )
1690 if ( pNd->IsGrfLink() )
1692 //Halbfertige Grafik?
1693 ::sfx2::SvLinkSource* pLnkObj = pNd->GetLink()->GetObj();
1694 if( pLnkObj && pLnkObj->IsPending() )
1695 return 0;
1696 rbLink = sal_True;
1699 pNd->GetFileFilterNms( &rName, 0 );
1700 if ( !rName.Len() )
1701 rName = pFly->GetFmt()->GetName();
1702 pNd->SwapIn( sal_True );
1703 return &pNd->GetGrf();
1707 return 0;
1711 const SwFrmFmt* SwFEShell::GetFmtFromObj( const Point& rPt, SwRect** pRectToFill ) const
1713 SwFrmFmt* pRet = 0;
1715 if( Imp()->HasDrawView() )
1717 SdrObject* pObj;
1718 SdrPageView* pPView;
1720 SwDrawView *pDView = (SwDrawView*)Imp()->GetDrawView();
1722 sal_uInt16 nOld = pDView->GetHitTolerancePixel();
1723 // Tattergrenze fuer Drawing-SS
1724 pDView->SetHitTolerancePixel( pDView->GetMarkHdlSizePixel()/2 );
1726 if( pDView->PickObj( rPt, pDView->getHitTolLog(), pObj, pPView, SDRSEARCH_PICKMARKABLE ) )
1728 // dann teste mal was es ist:
1729 if ( pObj->ISA(SwVirtFlyDrawObj) )
1730 pRet = ((SwVirtFlyDrawObj*)pObj)->GetFmt();
1731 else if ( pObj->GetUserCall() ) //nicht fuer Gruppenobjekte
1732 pRet = ((SwDrawContact*)pObj->GetUserCall())->GetFmt();
1733 if(pRet && pRectToFill)
1734 **pRectToFill = pObj->GetCurrentBoundRect();
1736 pDView->SetHitTolerancePixel( nOld );
1738 return pRet;
1741 // returns a format too, if the point is over the text of any fly
1742 const SwFrmFmt* SwFEShell::GetFmtFromAnyObj( const Point& rPt ) const
1744 const SwFrmFmt* pRet = GetFmtFromObj( rPt );
1745 if( !pRet || RES_FLYFRMFMT == pRet->Which() )
1747 SwPosition aPos( *GetCrsr()->GetPoint() );
1748 Point aPt( rPt );
1749 GetLayout()->GetCrsrOfst( &aPos, aPt );
1750 SwCntntNode *pNd = aPos.nNode.GetNode().GetCntntNode();
1751 SwFrm* pFrm = pNd->GetFrm( &rPt )->FindFlyFrm();
1752 pRet = pFrm ? ((SwLayoutFrm*)pFrm)->GetFmt() : 0;
1754 return pRet;
1757 ObjCntType SwFEShell::GetObjCntType( const SdrObject& rObj ) const
1759 ObjCntType eType = OBJCNT_NONE;
1761 // OD 23.06.2003 #108784# - investigate 'master' drawing object, if method
1762 // is called for a 'virtual' drawing object.
1763 const SdrObject* pInvestigatedObj;
1764 if ( rObj.ISA(SwDrawVirtObj) )
1766 const SwDrawVirtObj* pDrawVirtObj = static_cast<const SwDrawVirtObj*>(&rObj);
1767 pInvestigatedObj = &(pDrawVirtObj->GetReferencedObj());
1769 else
1771 pInvestigatedObj = &rObj;
1774 if( FmFormInventor == pInvestigatedObj->GetObjInventor() )
1776 eType = OBJCNT_CONTROL;
1777 uno::Reference< awt::XControlModel > xModel =
1778 ((SdrUnoObj&)(*pInvestigatedObj)).GetUnoControlModel();
1779 if( xModel.is() )
1781 uno::Any aVal;
1782 OUString sName = OUString::createFromAscii("ButtonType");
1783 uno::Reference< beans::XPropertySet > xSet(xModel, uno::UNO_QUERY);
1785 uno::Reference< beans::XPropertySetInfo > xInfo = xSet->getPropertySetInfo();
1786 if(xInfo->hasPropertyByName( sName ))
1788 beans::Property xProperty = xInfo->getPropertyByName( sName );
1789 aVal = xSet->getPropertyValue( sName );
1790 if( aVal.getValue() && form::FormButtonType_URL == *((form::FormButtonType*)aVal.getValue()) )
1791 eType = OBJCNT_URLBUTTON;
1795 else if( pInvestigatedObj->ISA(SwVirtFlyDrawObj) )
1797 SwFlyFrm *pFly = ((SwVirtFlyDrawObj&)(*pInvestigatedObj)).GetFlyFrm();
1798 if ( pFly->Lower() && pFly->Lower()->IsNoTxtFrm() )
1800 if ( ((SwCntntFrm*)pFly->Lower())->GetNode()->GetGrfNode() )
1801 eType = OBJCNT_GRF;
1802 else
1803 eType = OBJCNT_OLE;
1805 else
1806 eType = OBJCNT_FLY;
1808 // --> OD 2006-11-06 #130889# - make code robust
1809 // else if( pInvestigatedObj->ISA( SdrObjGroup ) &&
1810 // FLY_IN_CNTNT !=
1811 // ((SwDrawContact*)GetUserCall(pInvestigatedObj))->GetFmt()->GetAnchor().GetAnchorId() )
1812 // eType = OBJCNT_GROUPOBJ;
1813 else if ( pInvestigatedObj->ISA( SdrObjGroup ) )
1815 SwDrawContact* pDrawContact( dynamic_cast<SwDrawContact*>(GetUserCall( pInvestigatedObj ) ) );
1816 if ( !pDrawContact )
1818 ASSERT( false,
1819 "<SwFEShell::GetObjCntType(..)> - missing draw contact object" );
1820 eType = OBJCNT_NONE;
1822 else
1824 SwFrmFmt* pFrmFmt( pDrawContact->GetFmt() );
1825 if ( !pFrmFmt )
1827 ASSERT( false,
1828 "<SwFEShell::GetObjCntType(..)> - missing frame format" );
1829 eType = OBJCNT_NONE;
1831 else if ( FLY_IN_CNTNT != pFrmFmt->GetAnchor().GetAnchorId() )
1833 eType = OBJCNT_GROUPOBJ;
1837 // <--
1838 else
1839 eType = OBJCNT_SIMPLE;
1840 return eType;
1843 ObjCntType SwFEShell::GetObjCntType( const Point &rPt, SdrObject *&rpObj ) const
1845 ObjCntType eType = OBJCNT_NONE;
1847 if( Imp()->HasDrawView() )
1849 SdrObject* pObj;
1850 SdrPageView* pPView;
1852 SwDrawView *pDView = (SwDrawView*)Imp()->GetDrawView();
1854 sal_uInt16 nOld = pDView->GetHitTolerancePixel();
1855 // Tattergrenze fuer Drawing-SS
1856 pDView->SetHitTolerancePixel( pDView->GetMarkHdlSizePixel()/2 );
1858 if( pDView->PickObj( rPt, pDView->getHitTolLog(), pObj, pPView, SDRSEARCH_PICKMARKABLE ) )
1859 eType = GetObjCntType( *(rpObj = pObj) );
1861 pDView->SetHitTolerancePixel( nOld );
1863 return eType;
1866 ObjCntType SwFEShell::GetObjCntTypeOfSelection( SdrObject** ppObj ) const
1868 ObjCntType eType = OBJCNT_NONE;
1870 if( Imp()->HasDrawView() )
1872 const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
1873 for( sal_uInt32 i = 0, nE = rMrkList.GetMarkCount(); i < nE; ++i )
1875 SdrObject* pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
1876 ObjCntType eTmp = GetObjCntType( *pObj );
1877 if( !i )
1879 eType = eTmp;
1880 if( ppObj ) *ppObj = pObj;
1882 else if( eTmp != eType )
1884 eType = OBJCNT_DONTCARE;
1885 // einmal DontCare, immer DontCare!
1886 break;
1890 return eType;
1894 sal_Bool SwFEShell::ReplaceSdrObj( const String& rGrfName, const String& rFltName,
1895 const Graphic* pGrf )
1897 SET_CURR_SHELL( this );
1899 sal_Bool bRet = sal_False;
1900 const SdrMarkList *pMrkList;
1901 if( Imp()->HasDrawView() && 1 ==
1902 ( pMrkList = &Imp()->GetDrawView()->GetMarkedObjectList())->GetMarkCount() )
1904 SdrObject* pObj = pMrkList->GetMark( 0 )->GetMarkedSdrObj();
1905 SwFrmFmt *pFmt = FindFrmFmt( pObj );
1907 // Attribute sichern und dann an der Grafik setzen
1908 SfxItemSet aFrmSet( pDoc->GetAttrPool(),
1909 pFmt->GetAttrSet().GetRanges() );
1910 aFrmSet.Set( pFmt->GetAttrSet() );
1912 // Groesse und Position setzen ??
1913 if( !pObj->ISA(SwVirtFlyDrawObj) )
1915 // dann mal los:
1916 const Rectangle &rBound = pObj->GetSnapRect();
1917 Point aRelPos( pObj->GetRelativePos() );
1919 const long nWidth = rBound.Right() - rBound.Left();
1920 const long nHeight= rBound.Bottom() - rBound.Top();
1921 aFrmSet.Put( SwFmtFrmSize( ATT_MIN_SIZE,
1922 Max( nWidth, long(MINFLY) ),
1923 Max( nHeight, long(MINFLY) )));
1925 if( SFX_ITEM_SET != aFrmSet.GetItemState( RES_HORI_ORIENT ))
1926 aFrmSet.Put( SwFmtHoriOrient( aRelPos.X(), text::HoriOrientation::NONE, text::RelOrientation::FRAME ));
1928 if( SFX_ITEM_SET != aFrmSet.GetItemState( RES_VERT_ORIENT ))
1929 aFrmSet.Put( SwFmtVertOrient( aRelPos.Y(), text::VertOrientation::NONE, text::RelOrientation::FRAME ));
1933 pObj->GetOrdNum();
1935 StartAllAction();
1936 StartUndo();
1938 // das "Sdr-Object" loeschen und dafuer die Grafik einfuegen
1939 DelSelectedObj();
1941 pFmt = GetDoc()->Insert( *GetCrsr(), rGrfName, rFltName, pGrf, &aFrmSet, NULL, NULL );
1943 // die Ordnungsnummer (Z-Order) noch uebertragen
1944 // JP 04.07.98: klappt aber nicht richtig!
1945 //SdrObject* pNewObj = ::FindSdrObject( pFmt );
1946 //pNewObj->SetOrdNum( nOrdNum );
1948 EndUndo();
1949 EndAllAction();
1950 bRet = sal_True;
1952 return bRet;
1955 static USHORT SwFmtGetPageNum(const SwFlyFrmFmt * pFmt)
1957 ASSERT(pFmt != NULL, "invalid argument");
1959 SwFlyFrm * pFrm = pFmt->GetFrm();
1961 USHORT aResult;
1963 if (pFrm != NULL)
1964 aResult = pFrm->GetPhyPageNum();
1965 else
1966 aResult = pFmt->GetAnchor().GetPageNum();
1968 return aResult;
1971 #include <fmtcnct.hxx>
1973 void SwFEShell::GetConnectableFrmFmts(SwFrmFmt & rFmt,
1974 const String & rReference,
1975 BOOL bSuccessors,
1976 ::std::vector< String > & aPrevPageVec,
1977 ::std::vector< String > & aThisPageVec,
1978 ::std::vector< String > & aNextPageVec,
1979 ::std::vector< String > & aRestVec)
1981 StartAction();
1983 SwFmtChain rChain = rFmt.GetChain();
1984 SwFrmFmt * pOldChainNext = (SwFrmFmt *) rChain.GetNext();
1985 SwFrmFmt * pOldChainPrev = (SwFrmFmt *) rChain.GetPrev();
1987 if (pOldChainNext)
1988 pDoc->Unchain(rFmt);
1990 if (pOldChainPrev)
1991 pDoc->Unchain(*pOldChainPrev);
1993 sal_uInt16 nCnt = pDoc->GetFlyCount(FLYCNTTYPE_FRM);
1995 /* potential successors resp. predecessors */
1996 ::std::vector< const SwFrmFmt * > aTmpSpzArray;
1998 (SwFrmFmt *) pDoc->FindFlyByName(rReference);
2000 for (sal_uInt16 n = 0; n < nCnt; n++)
2002 const SwFrmFmt & rFmt1 = *(pDoc->GetFlyNum(n, FLYCNTTYPE_FRM));
2005 pFmt is a potential successor of rFmt if it is chainable after
2006 rFmt.
2008 pFmt is a potential predecessor of rFmt if rFmt is chainable
2009 after pFmt.
2012 int nChainState;
2014 if (bSuccessors)
2015 nChainState = pDoc->Chainable(rFmt, rFmt1);
2016 else
2017 nChainState = pDoc->Chainable(rFmt1, rFmt);
2019 if (nChainState == SW_CHAIN_OK)
2021 aTmpSpzArray.push_back(&rFmt1);
2027 if (aTmpSpzArray.size() > 0)
2029 aPrevPageVec.clear();
2030 aThisPageVec.clear();
2031 aNextPageVec.clear();
2032 aRestVec.clear();
2034 /* number of page rFmt resides on */
2035 USHORT nPageNum = SwFmtGetPageNum((SwFlyFrmFmt *) &rFmt);
2037 ::std::vector< const SwFrmFmt * >::const_iterator aIt;
2039 for (aIt = aTmpSpzArray.begin(); aIt != aTmpSpzArray.end(); aIt++)
2041 String aString = (*aIt)->GetName();
2043 /* rFmt is not a vaild successor or predecessor of
2044 itself */
2045 if (aString != rReference && aString != rFmt.GetName())
2047 USHORT nNum1 =
2048 SwFmtGetPageNum((SwFlyFrmFmt *) *aIt);
2050 if (nNum1 == nPageNum -1)
2051 aPrevPageVec.push_back(aString);
2052 else if (nNum1 == nPageNum)
2053 aThisPageVec.push_back(aString);
2054 else if (nNum1 == nPageNum + 1)
2055 aNextPageVec.push_back(aString);
2056 else
2057 aRestVec.push_back(aString);
2063 if (pOldChainNext)
2064 pDoc->Chain(rFmt, *pOldChainNext);
2066 if (pOldChainPrev)
2067 pDoc->Chain(*pOldChainPrev, rFmt);
2069 EndAction();
2072 // --> OD 2009-07-13 #i73249#
2073 const String SwFEShell::GetObjTitle() const
2075 String aTitle;
2077 if ( Imp()->HasDrawView() )
2079 const SdrMarkList *pMrkList = &Imp()->GetDrawView()->GetMarkedObjectList();
2080 if ( pMrkList->GetMarkCount() == 1 )
2082 const SdrObject* pObj = pMrkList->GetMark( 0 )->GetMarkedSdrObj();
2083 const SwFrmFmt* pFmt = FindFrmFmt( pObj );
2084 if ( pFmt->Which() == RES_FLYFRMFMT )
2086 aTitle = dynamic_cast<const SwFlyFrmFmt*>(pFmt)->GetObjTitle();
2088 else
2090 aTitle = pObj->GetTitle();
2095 return aTitle;
2098 void SwFEShell::SetObjTitle( const String& rTitle )
2100 if ( Imp()->HasDrawView() )
2102 const SdrMarkList *pMrkList = &Imp()->GetDrawView()->GetMarkedObjectList();
2103 if ( pMrkList->GetMarkCount() == 1 )
2105 SdrObject* pObj = pMrkList->GetMark( 0 )->GetMarkedSdrObj();
2106 SwFrmFmt* pFmt = FindFrmFmt( pObj );
2107 if ( pFmt->Which() == RES_FLYFRMFMT )
2109 GetDoc()->SetFlyFrmTitle( *(dynamic_cast<SwFlyFrmFmt*>(pFmt)),
2110 rTitle );
2112 else
2114 pObj->SetTitle( rTitle );
2120 const String SwFEShell::GetObjDescription() const
2122 String aDescription;
2124 if ( Imp()->HasDrawView() )
2126 const SdrMarkList *pMrkList = &Imp()->GetDrawView()->GetMarkedObjectList();
2127 if ( pMrkList->GetMarkCount() == 1 )
2129 const SdrObject* pObj = pMrkList->GetMark( 0 )->GetMarkedSdrObj();
2130 const SwFrmFmt* pFmt = FindFrmFmt( pObj );
2131 if ( pFmt->Which() == RES_FLYFRMFMT )
2133 aDescription = dynamic_cast<const SwFlyFrmFmt*>(pFmt)->GetObjDescription();
2135 else
2137 aDescription = pObj->GetDescription();
2142 return aDescription;
2145 void SwFEShell::SetObjDescription( const String& rDescription )
2147 if ( Imp()->HasDrawView() )
2149 const SdrMarkList *pMrkList = &Imp()->GetDrawView()->GetMarkedObjectList();
2150 if ( pMrkList->GetMarkCount() == 1 )
2152 SdrObject* pObj = pMrkList->GetMark( 0 )->GetMarkedSdrObj();
2153 SwFrmFmt* pFmt = FindFrmFmt( pObj );
2154 if ( pFmt->Which() == RES_FLYFRMFMT )
2156 GetDoc()->SetFlyFrmDescription( *(dynamic_cast<SwFlyFrmFmt*>(pFmt)),
2157 rDescription );
2159 else
2161 pObj->SetDescription( rDescription );
2166 // <--