xref: /AOO41X/main/sw/source/core/frmedt/fefly1.cxx (revision 8809db7a87f97847b57a57f4cd2b0104b2b83182)
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 <hintids.hxx>
28 #include <svl/itemiter.hxx>
29 #include <svtools/imapobj.hxx>
30 #include <svtools/soerr.hxx>
31 #include <editeng/protitem.hxx>
32 #include <svx/svdogrp.hxx>
33 #include <svx/svdouno.hxx>
34 #include <svx/fmglob.hxx>
35 #include <com/sun/star/form/FormButtonType.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <fmtanchr.hxx>
38 #include <txtflcnt.hxx>
39 #include <fmtcntnt.hxx>
40 #include <fmtornt.hxx>
41 #include <fmtflcnt.hxx>
42 #include <fmturl.hxx>
43 #include <fmtclds.hxx>
44 #include <fmtfsize.hxx>
45 #include <docary.hxx>
46 #include <fesh.hxx>
47 #include <rootfrm.hxx>
48 #include <pagefrm.hxx>
49 #include <cntfrm.hxx>
50 #include <txtfrm.hxx>
51 #include <viewimp.hxx>
52 #include <viscrs.hxx>
53 #include <doc.hxx>
54 #include <IDocumentUndoRedo.hxx>
55 #include <dview.hxx>
56 #include <dflyobj.hxx>
57 #include <dcontact.hxx>
58 #include <frmfmt.hxx>
59 #include <flyfrm.hxx>
60 #include <ndtxt.hxx>
61 #include <edimp.hxx>
62 #include <swtable.hxx>
63 #include <mvsave.hxx>       // Strukturen zum Sichern beim Move/Delete
64 #include <ndgrf.hxx>
65 #include <flyfrms.hxx>
66 #include <flypos.hxx>
67 #include <fldbas.hxx>
68 #include <fmtfld.hxx>
69 #include <swundo.hxx>
70 #include <frame.hxx>
71 #include <notxtfrm.hxx>
72 // --> OD 2006-03-06 #125892#
73 #include <HandleAnchorNodeChg.hxx>
74 // <--
75 #include <frmatr.hxx>
76 // --> 3.7.2010 #i972#
77 #include <ndole.hxx>
78 // <--
79 // --> OD 2009-12-29 #i89920#
80 #include <fmtsrnd.hxx>
81 #include <editeng/opaqitem.hxx>
82 // <--
83 
84 using ::rtl::OUString;
85 using namespace ::com::sun::star;
86 
87 //Zum anmelden von Flys in Flys in ...
88 //definiert in layout/frmtool.cxx
89 void RegistFlys( SwPageFrm*, const SwLayoutFrm* );
90 
91 /***********************************************************************
92 #*  Class       :  SwDoc
93 #*  Methode     :  UseSpzLayoutFmt
94 #*  Beschreibung:  Anhand des Request werden zu dem Format entsprechende
95 #*      Aenderungen an den Spezifischen Layouts vorgenommen.
96 #*  Datum       :  MA 23. Sep. 92
97 #*  Update      :  JP 09.03.98
98 #***********************************************************************/
99 
100 sal_Bool lcl_SetNewFlyPos( const SwNode& rNode, SwFmtAnchor& rAnchor,
101                         const Point& rPt )
102 {
103     sal_Bool bRet = sal_False;
104     const SwStartNode* pStNode = rNode.FindFlyStartNode();
105     if( pStNode )
106     {
107         SwPosition aPos( *pStNode );
108         rAnchor.SetAnchor( &aPos );
109         bRet = sal_True;
110     }
111     else
112     {
113         const SwCntntNode *pCntNd = rNode.GetCntntNode();
114         const SwCntntFrm* pCFrm = pCntNd ? pCntNd->getLayoutFrm( pCntNd->GetDoc()->GetCurrentLayout(), &rPt, 0, sal_False ) : 0;
115         const SwPageFrm *pPg = pCFrm ? pCFrm->FindPageFrm() : 0;
116 
117         rAnchor.SetPageNum( pPg ? pPg->GetPhyPageNum() : 1 );
118         rAnchor.SetType( FLY_AT_PAGE );
119     }
120     return bRet;
121 }
122 
123 sal_Bool lcl_FindAnchorPos( SwDoc& rDoc, const Point& rPt, const SwFrm& rFrm,
124                         SfxItemSet& rSet )
125 {
126     sal_Bool bRet = sal_True;
127     SwFmtAnchor aNewAnch( (SwFmtAnchor&)rSet.Get( RES_ANCHOR ) );
128     RndStdIds nNew = aNewAnch.GetAnchorId();
129     const SwFrm *pNewAnch;
130 
131     //Neuen Anker ermitteln
132     Point aTmpPnt( rPt );
133     switch( nNew )
134     {
135     case FLY_AS_CHAR:  // sollte der nicht auch mit hinein?
136     case FLY_AT_PARA:
137     case FLY_AT_CHAR: // LAYER_IMPL
138         {
139             //Ausgehend von der linken oberen Ecke des Fly den
140             //dichtesten CntntFrm suchen.
141             const SwFrm* pFrm = rFrm.IsFlyFrm() ? ((SwFlyFrm&)rFrm).GetAnchorFrm()
142                                                 : &rFrm;
143             pNewAnch = ::FindAnchor( pFrm, aTmpPnt );
144             if( pNewAnch->IsProtected() )
145             {
146                 bRet = sal_False;
147                 break;
148             }
149 
150             SwPosition aPos( *((SwCntntFrm*)pNewAnch)->GetNode() );
151             if ((FLY_AT_CHAR == nNew) || (FLY_AS_CHAR == nNew))
152             {
153                 // es muss ein TextNode gefunden werden, denn nur in diesen
154                 // ist ein Inhaltsgebundene Frames zu verankern
155                 SwCrsrMoveState aState( MV_SETONLYTEXT );
156                 aTmpPnt.X() -= 1;                   //nicht im Fly landen!!
157                 if( !pNewAnch->GetCrsrOfst( &aPos, aTmpPnt, &aState ) )
158                 {
159                     SwCntntNode* pCNd = ((SwCntntFrm*)pNewAnch)->GetNode();
160                     if( pNewAnch->Frm().Bottom() < aTmpPnt.Y() )
161                         pCNd->MakeStartIndex( &aPos.nContent );
162                     else
163                         pCNd->MakeEndIndex( &aPos.nContent );
164                 }
165             }
166             aNewAnch.SetAnchor( &aPos );
167         }
168         break;
169 
170     case FLY_AT_FLY: // LAYER_IMPL
171         {
172             //Ausgehend von der linken oberen Ecke des Fly den
173             //dichtesten SwFlyFrm suchen.
174             SwCrsrMoveState aState( MV_SETONLYTEXT );
175             SwPosition aPos( rDoc.GetNodes() );
176             aTmpPnt.X() -= 1;                   //nicht im Fly landen!!
177             rDoc.GetCurrentLayout()->GetCrsrOfst( &aPos, aTmpPnt, &aState );    //swmod 071108//swmod 071225
178             pNewAnch = ::FindAnchor(
179                 aPos.nNode.GetNode().GetCntntNode()->getLayoutFrm( rFrm.getRootFrm(), 0, 0, sal_False ),
180                 aTmpPnt )->FindFlyFrm();
181 
182             if( pNewAnch && &rFrm != pNewAnch && !pNewAnch->IsProtected() )
183             {
184                 aPos.nNode = *((SwFlyFrm*)pNewAnch)->GetFmt()->GetCntnt().
185                                 GetCntntIdx();
186                 aNewAnch.SetAnchor( &aPos );
187                 break;
188             }
189         }
190 
191         aNewAnch.SetType( nNew = FLY_AT_PAGE );
192         // no break
193 
194     case FLY_AT_PAGE:
195         pNewAnch = rFrm.FindPageFrm();
196         aNewAnch.SetPageNum( pNewAnch->GetPhyPageNum() );
197         break;
198 
199     default:
200         ASSERT( !&rDoc, "Falsche ID fuer neuen Anker." );
201     }
202 
203     rSet.Put( aNewAnch );
204     return bRet;
205 }
206 
207 //
208 //! also used in unoframe.cxx
209 //
210 sal_Bool lcl_ChkAndSetNewAnchor( const SwFlyFrm& rFly, SfxItemSet& rSet )
211 {
212     const SwFrmFmt& rFmt = *rFly.GetFmt();
213     const SwFmtAnchor &rOldAnch = rFmt.GetAnchor();
214     const RndStdIds nOld = rOldAnch.GetAnchorId();
215 
216     RndStdIds nNew = ((SwFmtAnchor&)rSet.Get( RES_ANCHOR )).GetAnchorId();
217 
218     if( nOld == nNew )
219         return sal_False;
220 
221     SwDoc* pDoc = (SwDoc*)rFmt.GetDoc();
222 
223 #ifdef DBG_UTIL
224     ASSERT( !(nNew == FLY_AT_PAGE &&
225         (FLY_AT_PARA==nOld || FLY_AT_CHAR==nOld || FLY_AS_CHAR==nOld ) &&
226         pDoc->IsInHeaderFooter( rOldAnch.GetCntntAnchor()->nNode )),
227             "Unerlaubter Ankerwechsel in Head/Foot." );
228 #endif
229 
230     return ::lcl_FindAnchorPos( *pDoc, rFly.Frm().Pos(), rFly, rSet );
231 }
232 
233 void SwFEShell::SelectFlyFrm( SwFlyFrm& rFrm, sal_Bool bNew )
234 {
235     SET_CURR_SHELL( this );
236 
237     //  Wenn es ein neuer Rahmen ist, so soll er selektiert sein.
238     //  !!Rahmen immer selektieren, wenn sie nicht selektiert sind.
239     //  - Es kann ein neuer 'alter' sein weil der Anker gewechselt wurde.
240     //  - 'alte' Rahmen sind vorher immer selektiert denn sonst wird nix
241     //    an ihnen veraendert.
242     //  Der Rahmen darf nicht per Dokumentposition selektiert werden, weil er
243     //  auf jedenfall selektiert sein muss!
244     SwViewImp *pImpl = Imp();
245     if( GetWin() && (bNew || !pImpl->GetDrawView()->AreObjectsMarked()) )
246     {
247         ASSERT( rFrm.IsFlyFrm(), "SelectFlyFrm will einen Fly" );
248 
249         //Wenn der Fly bereits selektiert ist gibt es hier ja wohl nichts
250         //zu tun.
251         if ( FindFlyFrm() == &rFrm )
252             return;
253 
254         //Damit der Anker ueberhaupt noch gepaintet wird.
255         if( rFrm.IsFlyInCntFrm() && rFrm.GetAnchorFrm() )
256              rFrm.GetAnchorFrm()->SetCompletePaint();
257 
258         // --> OD 2004-06-11 #i28701# - no format at all.
259 //        //Hier wurde immer kalkuliert. Leider ist der Sonderfall Fly in Fly mit
260 //        //Spalten u.U. sehr kritisch wenn der innenliegende zuerst formatiert
261 //        //wird. Um kein Risiko einzugehen entschaerfen wir nur diesen Sonderfall.
262 //        if( !rFrm.GetAnchorFrm()->IsInFly() )
263 //            rFrm.Calc();
264 
265         if( pImpl->GetDrawView()->AreObjectsMarked() )
266             pImpl->GetDrawView()->UnmarkAll();
267 
268         pImpl->GetDrawView()->MarkObj( rFrm.GetVirtDrawObj(),
269                                       pImpl->GetPageView(), sal_False, sal_False );
270         KillPams();
271         ClearMark();
272         SelFlyGrabCrsr();
273     }
274 }
275 
276 /*************************************************************************
277 |*
278 |*  SwFEShell::FindFlyFrm()
279 |*
280 |*  Beschreibung        Liefert den Fly wenn einer Selektiert ist.
281 |*  Ersterstellung      MA 03. Nov. 92
282 |*  Letzte Aenderung    MA 05. Mar. 96
283 |*
284 *************************************************************************/
285 
286 SwFlyFrm *SwFEShell::FindFlyFrm() const
287 {
288     if ( Imp()->HasDrawView() )
289     {
290         // Ein Fly ist genau dann erreichbar, wenn er selektiert ist.
291         const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
292         if( rMrkList.GetMarkCount() != 1 )
293             return 0;
294 
295         SdrObject *pO = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
296         return ( pO && pO->ISA(SwVirtFlyDrawObj) ) ? ((SwVirtFlyDrawObj*)pO)->GetFlyFrm() : 0;
297     }
298     return 0;
299 }
300 
301 /*************************************************************************
302 |*
303 |*  SwFEShell::IsFlyInFly()
304 |*
305 |*  Beschreibung        Liefert sal_True, wenn der aktuelle Fly an einem anderen
306 |*                      verankert werden koennte (also innerhalb ist)
307 |*  Ersterstellung      AMA 11. Sep. 97
308 |*  Letzte Aenderung    AMA 14. Jan. 98
309 |*
310 *************************************************************************/
311 
312 const SwFrmFmt* SwFEShell::IsFlyInFly()
313 {
314     SET_CURR_SHELL( this );
315 
316     if ( !Imp()->HasDrawView() )
317         return NULL;
318 
319     const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
320     if ( !rMrkList.GetMarkCount() )
321     {
322         SwCntntFrm *pCntnt = GetCurrFrm( sal_False );
323         if( !pCntnt )
324             return NULL;
325         SwFlyFrm *pFly = pCntnt->FindFlyFrm();
326         if ( !pFly )
327             return NULL;
328         return pFly->GetFmt();
329     }
330     else if ( rMrkList.GetMarkCount() != 1 ||
331          !GetUserCall(rMrkList.GetMark( 0 )->GetMarkedSdrObj()) )
332         return NULL;
333 
334     SdrObject *pObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
335 
336     SwFrmFmt *pFmt = FindFrmFmt( pObj );
337     if( pFmt && FLY_AT_FLY == pFmt->GetAnchor().GetAnchorId() )
338     {
339         const SwFrm* pFly = pObj->ISA(SwVirtFlyDrawObj) ?
340             ((SwVirtFlyDrawObj*)pObj)->GetFlyFrm()->GetAnchorFrm() :
341             ((SwDrawContact*)GetUserCall(pObj))->GetAnchorFrm( pObj );
342         ASSERT( pFly, "IsFlyInFly: Where's my anchor?" );
343         ASSERT( pFly->IsFlyFrm(), "IsFlyInFly: Funny anchor!" );
344         return ((SwFlyFrm*)pFly)->GetFmt();
345     }
346 
347     Point aTmpPos = pObj->GetCurrentBoundRect().TopLeft();
348 
349     SwFrm *pTxtFrm;
350     {
351         SwCrsrMoveState aState( MV_SETONLYTEXT );
352         SwNodeIndex aSwNodeIndex( GetDoc()->GetNodes() );
353         SwPosition aPos( aSwNodeIndex );
354         Point aPoint( aTmpPos );
355         aPoint.X() -= 1;                    //nicht im Fly landen!!
356         GetLayout()->GetCrsrOfst( &aPos, aPoint, &aState );
357         // OD 01.07.2003 #108784# - determine text frame by left-top-corner
358         // of object
359         //pTxtFrm = aPos.nNode.GetNode().GetCntntNode()->GetFrm( 0, 0, sal_False );
360         pTxtFrm = aPos.nNode.GetNode().GetCntntNode()->getLayoutFrm( GetLayout(), &aTmpPos, 0, sal_False );
361     }
362     const SwFrm *pTmp = ::FindAnchor( pTxtFrm, aTmpPos );
363     const SwFlyFrm *pFly = pTmp->FindFlyFrm();
364     if( pFly )
365         return pFly->GetFmt();
366     return NULL;
367 }
368 
369 /*************************************************************************
370 |*
371 |*  SwFEShell::SetFlyPos
372 |*
373 |*  Ersterstellung      MA 14. Jan. 93
374 |*  Letzte Aenderung    MA 14. Feb. 95
375 |*
376 *************************************************************************/
377 
378 void SwFEShell::SetFlyPos( const Point& rAbsPos )
379 {
380     SET_CURR_SHELL( this );
381 
382     //Bezugspunkt in Dokumentkoordinaten bestimmen
383     SwCntntFrm *pCntnt = GetCurrFrm( sal_False );
384     if( !pCntnt )
385         return;
386     SwFlyFrm *pFly = pCntnt->FindFlyFrm();
387     if ( !pFly )
388         return;
389 
390     //SwSaveHdl aSaveX( Imp() );
391 
392     //Bei Absatzgebundenen Flys muss ausgehend von der absoluten
393     //Position ein neuer Anker gesetzt werden. Anker und neue RelPos werden
394     //vom Fly selbst berechnet und gesetzt.
395     if ( pFly->IsFlyAtCntFrm() )
396         ((SwFlyAtCntFrm*)pFly)->SetAbsPos( rAbsPos );
397     else
398     {
399             const SwFrm *pAnch = pFly->GetAnchorFrm();
400             // --> OD 2004-06-11 #i28701# - no format here
401 //          pAnch->Calc();
402             Point aOrient( pAnch->Frm().Pos() );
403 
404         if ( pFly->IsFlyInCntFrm() )
405             aOrient.X() = rAbsPos.X();
406 
407         //RelPos errechnen.
408         aOrient.X() = rAbsPos.X() - aOrient.X();
409         aOrient.Y() = rAbsPos.Y() - aOrient.Y();
410         pFly->ChgRelPos( aOrient );
411     }
412     // --> OD 2004-06-11 #i28701# - no format here
413 //    pFly->Calc();
414     CallChgLnk();       // rufe das AttrChangeNotify auf der UI-Seite.
415 }
416 
417 /*************************************************************************
418 |*
419 |*  SwFEShell::FindAnchorPos
420 |*
421 |*  Ersterstellung      AMA 24. Sep. 97
422 |*  Letzte Aenderung    AMA 24. Sep. 97
423 |*
424 *************************************************************************/
425 
426 Point SwFEShell::FindAnchorPos( const Point& rAbsPos, sal_Bool bMoveIt )
427 {
428     Point aRet;
429 
430     SET_CURR_SHELL( this );
431 
432     if ( !Imp()->HasDrawView() )
433         return aRet;
434 
435     const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
436     if ( rMrkList.GetMarkCount() != 1 ||
437          !GetUserCall(rMrkList.GetMark( 0 )->GetMarkedSdrObj()) )
438         return aRet;
439 
440     SdrObject* pObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
441     // --> OD 2004-07-16 #i28701#
442     SwAnchoredObject* pAnchoredObj = ::GetUserCall( pObj )->GetAnchoredObj( pObj );
443     SwFrmFmt& rFmt = pAnchoredObj->GetFrmFmt();
444     RndStdIds nAnchorId = rFmt.GetAnchor().GetAnchorId();
445 
446     if ( FLY_AS_CHAR == nAnchorId )
447         return aRet;
448 
449     sal_Bool bFlyFrame = pObj->ISA(SwVirtFlyDrawObj);
450 
451     SwFlyFrm* pFly = 0L;
452     const SwFrm* pOldAnch;
453     const SwFrm* pFooterOrHeader = NULL;
454 
455     if( bFlyFrame )
456     {
457         //Bezugspunkt in Dokumentkoordinaten bestimmen
458         SwCntntFrm *pCntnt = GetCurrFrm( sal_False );
459         if( !pCntnt )
460             return aRet;
461         pFly = pCntnt->FindFlyFrm();
462         if ( !pFly )
463             return aRet;
464         pOldAnch = pFly->GetAnchorFrm();
465         if( !pOldAnch )
466             return aRet;
467         if ( FLY_AT_PAGE != nAnchorId )
468         {
469             pFooterOrHeader = pCntnt->FindFooterOrHeader();
470         }
471     }
472     // OD 26.06.2003 #108784# - set <pFooterOrHeader> also for drawing
473     // objects, but not for control objects.
474     // Necessary for moving 'anchor symbol' at the user interface inside header/footer.
475     else if ( !::CheckControlLayer( pObj ) )
476     {
477         SwCntntFrm *pCntnt = GetCurrFrm( sal_False );
478         if( !pCntnt )
479             return aRet;
480         pFooterOrHeader = pCntnt->FindFooterOrHeader();
481     }
482 
483     //Ausgehend von der linken oberen Ecke des Fly den
484     //dichtesten SwFlyFrm suchen.
485     SwCntntFrm *pTxtFrm;
486     {
487         SwCrsrMoveState aState( MV_SETONLYTEXT );
488         SwPosition aPos( GetDoc()->GetNodes().GetEndOfExtras() );
489         Point aTmpPnt( rAbsPos );
490         GetLayout()->GetCrsrOfst( &aPos, aTmpPnt, &aState );
491         pTxtFrm = aPos.nNode.GetNode().GetCntntNode()->getLayoutFrm( GetLayout(),0,&aPos,sal_False );
492     }
493     const SwFrm *pNewAnch;
494     if( pTxtFrm )
495     {
496         if ( FLY_AT_PAGE == nAnchorId )
497         {
498             pNewAnch = pTxtFrm->FindPageFrm();
499         }
500         else
501         {
502             pNewAnch = ::FindAnchor( pTxtFrm, rAbsPos );
503 
504             if( FLY_AT_FLY == nAnchorId ) // LAYER_IMPL
505             {
506                 pNewAnch = pNewAnch->FindFlyFrm();
507             }
508         }
509     }
510     else
511         pNewAnch = 0;
512 
513     if( pNewAnch && !pNewAnch->IsProtected() )
514     {
515         const SwFlyFrm* pCheck = bFlyFrame ? pNewAnch->FindFlyFrm() : 0;
516         // Falls wir innerhalb eines Rahmens landen, muss sichergestellt werden,
517         // dass der Rahmen nicht in seinem eigenen Inhalt landet!
518         while( pCheck )
519         {
520             if( pCheck == pFly )
521                 break;
522             const SwFrm *pTmp = pCheck->GetAnchorFrm();
523             pCheck = pTmp ? pTmp->FindFlyFrm() : NULL;
524         }
525         // Es darf nicht aus einer Kopf-/Fusszeile in einen anderen Bereich
526         // gewechselt werden, es darf nicht in eine Kopf-/Fusszeile hinein-
527         // gewechselt werden.
528         if( !pCheck &&
529             pFooterOrHeader == pNewAnch->FindFooterOrHeader() )
530         {
531             aRet = pNewAnch->GetFrmAnchorPos( ::HasWrap( pObj ) );
532 
533             if ( bMoveIt || (nAnchorId == FLY_AT_CHAR) )
534             {
535                 SwFmtAnchor aAnch( rFmt.GetAnchor() );
536                 switch ( nAnchorId )
537                 {
538                     case FLY_AT_PARA:
539                     {
540                         SwPosition *pPos = (SwPosition*)aAnch.GetCntntAnchor();
541                         pPos->nNode = *pTxtFrm->GetNode();
542                         pPos->nContent.Assign(0,0);
543                         break;
544                     }
545                     case FLY_AT_PAGE:
546                     {
547                         aAnch.SetPageNum( ((const SwPageFrm*)pNewAnch)->
548                                           GetPhyPageNum() );
549                         break;
550                     }
551                     case FLY_AT_FLY:
552                     {
553                         SwPosition aPos( *((SwFlyFrm*)pNewAnch)->GetFmt()->
554                                                   GetCntnt().GetCntntIdx() );
555                         aAnch.SetAnchor( &aPos );
556                         break;
557                     }
558                     case FLY_AT_CHAR:
559                     {
560                         SwPosition *pPos = (SwPosition*)aAnch.GetCntntAnchor();
561                         Point aTmpPnt( rAbsPos );
562                         if( pTxtFrm->GetCrsrOfst( pPos, aTmpPnt, NULL ) )
563                         {
564                             SwRect aTmpRect;
565                             pTxtFrm->GetCharRect( aTmpRect, *pPos );
566                             aRet = aTmpRect.Pos();
567                         }
568                         else
569                         {
570                             pPos->nNode = *pTxtFrm->GetNode();
571                             pPos->nContent.Assign(0,0);
572                         }
573                         break;
574                     }
575                     default:
576                         break;
577                 }
578                 if( bMoveIt )
579                 {
580                     StartAllAction();
581                     // --> OD 2006-02-28 #125892#
582                     // handle change of anchor node:
583                     // if count of the anchor frame also change, the fly frames have to be
584                     // re-created. Thus, delete all fly frames except the <this> before the
585                     // anchor attribute is change and re-create them afterwards.
586                     {
587                         SwHandleAnchorNodeChg* pHandleAnchorNodeChg( 0L );
588                         SwFlyFrmFmt* pFlyFrmFmt( dynamic_cast<SwFlyFrmFmt*>(&rFmt) );
589                         if ( pFlyFrmFmt )
590                         {
591                             pHandleAnchorNodeChg =
592                                 new SwHandleAnchorNodeChg( *pFlyFrmFmt, aAnch );
593                         }
594                         rFmt.GetDoc()->SetAttr( aAnch, rFmt );
595                         delete pHandleAnchorNodeChg;
596                     }
597                     // <--
598                     // --> OD 2004-06-24 #i28701# - no call of method
599                     // <CheckCharRectAndTopOfLine()> for to-character anchored
600                     // Writer fly frame needed. This method call can cause a
601                     // format of the anchor frame, which is no longer intended.
602                     // Instead clear the anchor character rectangle and
603                     // the top of line values for all to-character anchored objects.
604                     pAnchoredObj->ClearCharRectAndTopOfLine();
605                     // <--
606                     EndAllAction();
607                 }
608             }
609 
610             SwRect aTmpRect( aRet, rAbsPos );
611             if( aTmpRect.HasArea() )
612                 MakeVisible( aTmpRect );
613 #ifdef DBG_UTIL
614             //TODO: That doesn't seem to be intended
615             if( Color(COL_TRANSPARENT) != GetOut()->GetLineColor() )
616             {
617                 ASSERT( sal_False, "Hey, Joe: Where's my Null Pen?" );
618                 GetOut()->SetLineColor( Color(COL_TRANSPARENT) );
619             }
620 #endif
621         }
622     }
623 
624     return aRet;
625 }
626 
627 /***********************************************************************
628 #*  Class       :  SwFEShell
629 #*  Methode     :  NewFlyFrm
630 #*  Beschreibung:
631 #*  Datum       :  MA 03. Nov. 92
632 #*  Update      :  JP 11. Aug. 93
633 #***********************************************************************/
634 
635 const SwFrmFmt *SwFEShell::NewFlyFrm( const SfxItemSet& rSet, sal_Bool bAnchValid,
636                            SwFrmFmt *pParent )
637 {
638     SET_CURR_SHELL( this );
639     StartAllAction();
640 
641     SwPaM* pCrsr = GetCrsr();
642     const Point aPt( GetCrsrDocPos() );
643 
644     SwSelBoxes aBoxes;
645     sal_Bool bMoveCntnt = sal_True;
646     if( IsTableMode() )
647     {
648         GetTblSel( *this, aBoxes );
649         if( aBoxes.Count() )
650         {
651             // die Crsr muessen noch aus dem Loeschbereich entfernt
652             // werden. Setze sie immer hinter/auf die Tabelle; ueber die
653             // Dokument-Position werden sie dann immer an die alte
654             // Position gesetzt.
655             ParkCrsr( SwNodeIndex( *aBoxes[0]->GetSttNd() ));
656 
657             // --> FME 2005-12-01 #i127787# pCurCrsr will be deleted in ParkCrsr,
658             // we better get the current pCurCrsr instead of working with the
659             // deleted one:
660             pCrsr = GetCrsr();
661             // <--
662 
663 //          KillPams();
664         }
665         else
666             bMoveCntnt = sal_False;
667     }
668     else if( !pCrsr->HasMark() && pCrsr->GetNext() == pCrsr )
669         bMoveCntnt = sal_False;
670 
671     const SwPosition& rPos = *pCrsr->Start();
672 
673     SwFmtAnchor& rAnch = (SwFmtAnchor&)rSet.Get( RES_ANCHOR );
674     RndStdIds eRndId = rAnch.GetAnchorId();
675     switch( eRndId )
676     {
677     case FLY_AT_PAGE:
678         if( !rAnch.GetPageNum() )       //HotFix: Bug in UpdateByExample
679             rAnch.SetPageNum( 1 );
680         break;
681 
682     case FLY_AT_FLY:
683     case FLY_AT_PARA:
684     case FLY_AT_CHAR:
685     case FLY_AS_CHAR:
686         if( !bAnchValid )
687         {
688             if( FLY_AT_FLY != eRndId )
689             {
690                 rAnch.SetAnchor( &rPos );
691             }
692             else if( lcl_SetNewFlyPos( rPos.nNode.GetNode(), rAnch, aPt ) )
693             {
694                 eRndId = FLY_AT_PAGE;
695             }
696         }
697         break;
698 
699     default:
700         ASSERT( !this, "Was sollte das fuer ein Fly werden?" )
701         break;
702     }
703 
704     SwFlyFrmFmt *pRet;
705     if( bMoveCntnt )
706     {
707         GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_INSLAYFMT, NULL );
708         SwFmtAnchor* pOldAnchor = 0;
709         sal_Bool bHOriChgd = sal_False, bVOriChgd = sal_False;
710         SwFmtVertOrient aOldV;
711         SwFmtHoriOrient aOldH;
712 
713         if ( FLY_AT_PAGE != eRndId )
714         {
715             // erstmal als mit Seitenbindung, Absatz/Zeichenbindung erst wenn
716             // alles verschoben ist. Dann ist die Position gueltig!
717             // JP 13.05.98: ggfs. auch noch die Hori/Vert-Orientierung
718             //              umsetzen, damit diese beim Umanker NICHT
719             //              korrigiert wird
720             pOldAnchor = new SwFmtAnchor( rAnch );
721             const_cast<SfxItemSet&>(rSet).Put( SwFmtAnchor( FLY_AT_PAGE, 1 ) );
722 
723             const SfxPoolItem* pItem;
724             if( SFX_ITEM_SET == rSet.GetItemState( RES_HORI_ORIENT, sal_False, &pItem )
725                 && text::HoriOrientation::NONE == ((SwFmtHoriOrient*)pItem)->GetHoriOrient() )
726             {
727                 bHOriChgd = sal_True;
728                 aOldH = *((SwFmtHoriOrient*)pItem);
729                 ((SfxItemSet&)rSet).Put( SwFmtHoriOrient( 0, text::HoriOrientation::LEFT ) );
730             }
731             if( SFX_ITEM_SET == rSet.GetItemState( RES_VERT_ORIENT, sal_False, &pItem )
732                 && text::VertOrientation::NONE == ((SwFmtVertOrient*)pItem)->GetVertOrient() )
733             {
734                 bVOriChgd = sal_True;
735                 aOldV = *((SwFmtVertOrient*)pItem);
736                 ((SfxItemSet&)rSet).Put( SwFmtVertOrient( 0, text::VertOrientation::TOP ) );
737             }
738         }
739 
740         pRet = GetDoc()->MakeFlyAndMove( *pCrsr, rSet, &aBoxes, pParent );
741 
742         KillPams();
743 
744         if( pOldAnchor )
745         {
746             if( pRet )
747             {
748                 // neue Position bestimmen
749                 //JP 24.03.97: immer ueber die Seitenbindung gehen - der
750                 //           chaos::Anchor darf nie im verschobenen Bereich
751                 //              liegen
752                 pRet->DelFrms();
753 
754                 const SwFrm* pAnch = ::FindAnchor( GetLayout(), aPt, sal_False );
755                 SwPosition aPos( *((SwCntntFrm*)pAnch)->GetNode() );
756                 if ( FLY_AS_CHAR == eRndId )
757                 {
758                     aPos.nContent.Assign( ((SwCntntFrm*)pAnch)->GetNode(), 0 );
759                 }
760                 pOldAnchor->SetAnchor( &aPos );
761 
762                 // das verschieben von TabelleSelektion ist noch nicht
763                 // Undofaehig - also darf das UmAnkern auch nicht
764                 // aufgezeichnet werden.
765                 bool const bDoesUndo =
766                     GetDoc()->GetIDocumentUndoRedo().DoesUndo();
767                 SwUndoId nLastUndoId(UNDO_EMPTY);
768                 if (bDoesUndo &&
769                     GetDoc()->GetIDocumentUndoRedo().GetLastUndoInfo(0,
770                         & nLastUndoId))
771                 {
772                     if (UNDO_INSLAYFMT == nLastUndoId)
773                     {
774                         GetDoc()->GetIDocumentUndoRedo().DoUndo(false);
775                     }
776                 }
777 
778                 ((SfxItemSet&)rSet).Put( *pOldAnchor );
779 
780                 if( bHOriChgd )
781                     ((SfxItemSet&)rSet).Put( aOldH );
782                 if( bVOriChgd )
783                     ((SfxItemSet&)rSet).Put( aOldV );
784 
785                 GetDoc()->SetFlyFrmAttr( *pRet, (SfxItemSet&)rSet );
786                 GetDoc()->GetIDocumentUndoRedo().DoUndo(bDoesUndo);
787             }
788             delete pOldAnchor;
789         }
790         GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_INSLAYFMT, NULL );
791     }
792     else
793         /* #109161# If called from a shell try to propagate an
794             existing adjust item from rPos to the content node of the
795             new frame. */
796         pRet = GetDoc()->MakeFlySection( eRndId, &rPos, &rSet, pParent, sal_True );
797 
798     if( pRet )
799     {
800         SwFlyFrm* pFrm = pRet->GetFrm( &aPt );
801         if( pFrm )
802             SelectFlyFrm( *pFrm, sal_True );
803         else
804         {
805             GetLayout()->SetAssertFlyPages();
806             pRet = 0;
807         }
808     }
809     EndAllActionAndCall();
810 
811     return pRet;
812 }
813 
814 /***********************************************************************
815 #*  Class       :  SwFEShell
816 #*  Methode     :  Insert
817 #*  Datum       :  ??
818 #*  Update      :  MA 12. Sep. 94
819 #***********************************************************************/
820 
821 void SwFEShell::Insert( const String& rGrfName, const String& rFltName,
822                         const Graphic* pGraphic,
823                         const SfxItemSet* pFlyAttrSet,
824                         const SfxItemSet* pGrfAttrSet,
825                         SwFrmFmt* pFrmFmt )
826 {
827     SwFlyFrmFmt* pFmt = 0;
828     SET_CURR_SHELL( this );
829     StartAllAction();
830     SwShellCrsr *pStartCursor = dynamic_cast<SwShellCrsr*>(this->GetSwCrsr());
831     SwShellCrsr *pCursor = pStartCursor;
832     do {
833 
834         // Anker noch nicht oder unvollstaendig gesetzt ?
835         if( pFlyAttrSet )
836         {
837             const SfxPoolItem* pItem;
838             if( SFX_ITEM_SET == pFlyAttrSet->GetItemState( RES_ANCHOR, sal_False,
839                     &pItem ) )
840             {
841                 SwFmtAnchor* pAnchor = (SwFmtAnchor*)pItem;
842                 switch( pAnchor->GetAnchorId())
843                 {
844                 case FLY_AT_PARA:
845                 case FLY_AT_CHAR: // LAYER_IMPL
846                 case FLY_AS_CHAR:
847                     if( !pAnchor->GetCntntAnchor() )
848                     {
849                         pAnchor->SetAnchor( pCursor->GetPoint() );
850                     }
851                     break;
852                 case FLY_AT_FLY:
853                     if( !pAnchor->GetCntntAnchor() )
854                     {
855                         lcl_SetNewFlyPos( *pCursor->GetNode(),
856                                 *pAnchor, GetCrsrDocPos() );
857                     }
858                     break;
859                 case FLY_AT_PAGE:
860                     if( !pAnchor->GetPageNum() )
861                     {
862                         pAnchor->SetPageNum( pCursor->GetPageNum(
863                                 sal_True, &pCursor->GetPtPos() ) );
864                     }
865                     break;
866                 default :
867                     break;
868                 }
869             }
870         }
871         pFmt = GetDoc()->Insert(*pCursor, rGrfName,
872                                 rFltName, pGraphic,
873                                 pFlyAttrSet,
874                                 pGrfAttrSet, pFrmFmt );
875         ASSERT( pFmt, "Doc->Insert(notxt) failed." );
876 
877     } while( (pCursor = dynamic_cast<SwShellCrsr*>(pCursor->GetNext()))
878              != pStartCursor );
879 
880     EndAllAction();
881 
882     if( pFmt )
883     {
884         const Point aPt( GetCrsrDocPos() );
885         SwFlyFrm* pFrm = pFmt->GetFrm( &aPt );
886 
887         if( pFrm )
888             SelectFlyFrm( *pFrm, sal_True );
889         else
890             GetLayout()->SetAssertFlyPages();
891     }
892 }
893 
894 SwFlyFrmFmt* SwFEShell::InsertObject( const svt::EmbeddedObjectRef&  xObj,
895                         const SfxItemSet* pFlyAttrSet,
896                         const SfxItemSet* pGrfAttrSet,
897                         SwFrmFmt* pFrmFmt )
898 {
899     SwFlyFrmFmt* pFmt = 0;
900     SET_CURR_SHELL( this );
901     StartAllAction();
902         FOREACHPAM_START( this )
903             pFmt = GetDoc()->Insert(*PCURCRSR, xObj,
904                                     pFlyAttrSet, pGrfAttrSet, pFrmFmt );
905             ASSERT( pFmt, "Doc->Insert(notxt) failed." );
906 
907         FOREACHPAM_END()
908     EndAllAction();
909 
910     if( pFmt )
911     {
912         const Point aPt( GetCrsrDocPos() );
913         SwFlyFrm* pFrm = pFmt->GetFrm( &aPt );
914 
915         if( pFrm )
916             SelectFlyFrm( *pFrm, sal_True );
917         else
918             GetLayout()->SetAssertFlyPages();
919     }
920 
921     return pFmt;
922 }
923 
924 
925 void SwFEShell::InsertDrawObj( SdrObject& rDrawObj,
926                                const Point& rInsertPosition )
927 {
928     SET_CURR_SHELL( this );
929 
930     SfxItemSet rFlyAttrSet( GetDoc()->GetAttrPool(), aFrmFmtSetRange );
931     rFlyAttrSet.Put( SwFmtAnchor( FLY_AT_PARA ));
932     // --> OD 2009-12-29 #i89920#
933     rFlyAttrSet.Put( SwFmtSurround( SURROUND_THROUGHT ) );
934     rDrawObj.SetLayer( getIDocumentDrawModelAccess()->GetHeavenId() );
935     // <--
936 
937     // find anchor position
938     SwPaM aPam( pDoc->GetNodes() );
939     {
940         SwCrsrMoveState aState( MV_SETONLYTEXT );
941         Point aTmpPt( rInsertPosition );
942         GetLayout()->GetCrsrOfst( aPam.GetPoint(), aTmpPt, &aState );
943         const SwFrm* pFrm = aPam.GetCntntNode()->getLayoutFrm( GetLayout(), 0, 0, sal_False );
944         const Point aRelPos( rInsertPosition.X() - pFrm->Frm().Left(),
945                              rInsertPosition.Y() - pFrm->Frm().Top() );
946         rDrawObj.SetRelativePos( aRelPos );
947         ::lcl_FindAnchorPos( *GetDoc(), rInsertPosition, *pFrm, rFlyAttrSet );
948     }
949     // insert drawing object into the document creating a new <SwDrawFrmFmt> instance
950     SwDrawFrmFmt* pFmt = GetDoc()->Insert( aPam, rDrawObj, &rFlyAttrSet, 0 );
951 
952     // move object to visible layer
953     SwContact* pContact = static_cast<SwContact*>(rDrawObj.GetUserCall());
954     if ( pContact )
955     {
956         pContact->MoveObjToVisibleLayer( &rDrawObj );
957     }
958 
959     if ( pFmt )
960     {
961         // select drawing object
962         Imp()->GetDrawView()->MarkObj( &rDrawObj, Imp()->GetPageView(),
963                                        sal_False, sal_False );
964     }
965     else
966     {
967         GetLayout()->SetAssertFlyPages();
968     }
969 }
970 
971 /***********************************************************************
972 #*  Class       :  SwFEShell
973 #*  Methode     :  GetPageObjs
974 #*  Datum       :  ??
975 #*  Update      :  MA 11. Jan. 95
976 #***********************************************************************/
977 
978 void SwFEShell::GetPageObjs( SvPtrarr& rFillArr )
979 {
980     if( rFillArr.Count() )
981         rFillArr.Remove( 0, rFillArr.Count() );
982 
983     const SwFrmFmt* pFmt;
984     for( sal_uInt16 n = 0; n < pDoc->GetSpzFrmFmts()->Count(); ++n )
985     {
986         pFmt = (const SwFrmFmt*)(*pDoc->GetSpzFrmFmts())[n];
987         if (FLY_AT_PAGE == pFmt->GetAnchor().GetAnchorId())
988         {
989             rFillArr.Insert( (VoidPtr)pFmt, rFillArr.Count() );
990         }
991     }
992 }
993 
994 /***********************************************************************
995 #*  Class       :  SwFEShell
996 #*  Methode     :  SetPageFlysNewPage
997 #*  Datum       :  ??
998 #*  Update      :  MA 14. Feb. 95
999 #***********************************************************************/
1000 
1001 void SwFEShell::SetPageObjsNewPage( SvPtrarr& rFillArr, int nOffset )
1002 {
1003     if( !rFillArr.Count() || !nOffset )
1004         return;
1005 
1006     StartAllAction();
1007     StartUndo();
1008 
1009     SwFrmFmt* pFmt;
1010     long nNewPage;
1011     SwRootFrm* pTmpRootFrm = GetLayout();//swmod 080317
1012     sal_uInt16 nMaxPage = pTmpRootFrm->GetPageNum();
1013     sal_Bool bTmpAssert = sal_False;
1014     for( sal_uInt16 n = 0; n < rFillArr.Count(); ++n )
1015     {
1016         pFmt = (SwFrmFmt*)rFillArr[n];
1017         if( USHRT_MAX != pDoc->GetSpzFrmFmts()->GetPos( pFmt ))
1018         {
1019             // FlyFmt ist noch gueltig, also behandeln
1020             SwFmtAnchor aNewAnchor( pFmt->GetAnchor() );
1021             if ((FLY_AT_PAGE != aNewAnchor.GetAnchorId()) ||
1022                 0 >= ( nNewPage = aNewAnchor.GetPageNum() + nOffset ) )
1023                 // chaos::Anchor wurde veraendert oder ungueltige SeitenNummer,
1024                 // also nicht veraendern !!
1025                 continue;
1026 
1027             if( sal_uInt16(nNewPage) > nMaxPage )
1028             {
1029                 if ( RES_DRAWFRMFMT == pFmt->Which() )
1030                 {
1031                     SwContact *pCon = pFmt->FindContactObj();
1032                     if( pCon )
1033                         ((SwDrawContact*)pCon)->DisconnectFromLayout();
1034                 }
1035                 else
1036                     pFmt->DelFrms();
1037                 bTmpAssert = sal_True;
1038             }
1039             aNewAnchor.SetPageNum( sal_uInt16(nNewPage) );
1040             pDoc->SetAttr( aNewAnchor, *pFmt );
1041         }
1042     }
1043 
1044     if( bTmpAssert )
1045         pTmpRootFrm->SetAssertFlyPages();
1046 
1047     EndUndo();
1048     EndAllAction();
1049 }
1050 
1051 /***********************************************************************
1052 #*  Class       :  SwFEShell
1053 #*  Methode     :  GetFlyFrmAttr
1054 #*  Beschreibung:  Alle Attribute in dem 'Koerbchen' werden mit den
1055 #*                 Attributen des aktuellen FlyFrms gefuellt.
1056 #*                 Sind Attribute nicht zu fuellen weil fehl am Platz oder
1057 #*                 uneindeutig (Mehrfachtselektionen) so werden sie entfernt.
1058 #*  Datum       :  MA 03. Nov. 92
1059 #*  Update      :  MA 03. Feb. 94
1060 #***********************************************************************/
1061 
1062 sal_Bool SwFEShell::GetFlyFrmAttr( SfxItemSet &rSet ) const
1063 {
1064     SwFlyFrm *pFly = FindFlyFrm();
1065     if ( !pFly )
1066     {
1067         // --> OD 2006-11-08 #139670# - make code robust
1068         SwFrm* pCurrFrm( GetCurrFrm() );
1069         if ( !pCurrFrm )
1070         {
1071             ASSERT( false,
1072                     "<SwFEShell::GetFlyFrmAttr(..)> - missing current frame. This is a serious defect, please inform OD." );
1073             return sal_False;
1074         }
1075         // <--
1076         pFly = GetCurrFrm()->FindFlyFrm();
1077         if ( !pFly )
1078         {
1079             ASSERT( !this, "GetFlyFrmAttr, no Fly selected." );
1080             return sal_False;
1081         }
1082     }
1083 
1084     SET_CURR_SHELL( (ViewShell*)this );
1085 
1086     if( !rSet.Set( pFly->GetFmt()->GetAttrSet(), sal_True ) )
1087         return sal_False;
1088 
1089     //Und die Attribute durchschaufeln. Unerlaubte Attribute entfernen, dann
1090     //alle restlichen Attribute besorgen und eintragen.
1091     const SfxPoolItem* pItem;
1092     if( SFX_ITEM_SET == rSet.GetItemState( RES_ANCHOR, sal_False, &pItem ) )
1093     {
1094         SwFmtAnchor* pAnchor = (SwFmtAnchor*)pItem;
1095         RndStdIds eType = pAnchor->GetAnchorId();
1096 
1097         if ( FLY_AT_PAGE != eType )
1098         {
1099             // OD 12.11.2003 #i22341# - content anchor of anchor item is needed.
1100             // Thus, don't overwrite anchor item by default contructed anchor item.
1101             //rSet.Put( SwFmtAnchor( eType ) );
1102             if ( FLY_AS_CHAR == eType )
1103             {
1104                 rSet.ClearItem( RES_OPAQUE );
1105                 rSet.ClearItem( RES_SURROUND );
1106             }
1107         }
1108     }
1109     rSet.SetParent( pFly->GetFmt()->GetAttrSet().GetParent() );
1110     //JP 11.02.97: Bug #35894#: die Attribute MUESSEN entfern werden!
1111     rSet.ClearItem( RES_FILL_ORDER );
1112     rSet.ClearItem( RES_CNTNT );
1113     //MA: Ersteinmal entfernen (Template by example usw.)
1114     rSet.ClearItem( RES_CHAIN );
1115     return sal_True;
1116 }
1117 /***********************************************************************
1118 #*  Class       :  SwFEShell
1119 #*  Methode     :  SetFlyFrmAttr
1120 #*  Beschreibung:  Die Attribute des aktuellen Flys aendern sich.
1121 #*  Datum       :  MA 03. Nov. 92
1122 #*  Update      :  MA 01. Aug. 95
1123 #***********************************************************************/
1124 
1125 sal_Bool SwFEShell::SetFlyFrmAttr( SfxItemSet& rSet )
1126 {
1127     SET_CURR_SHELL( this );
1128     sal_Bool bRet = sal_False;
1129 
1130     if( rSet.Count() )
1131     {
1132         SwFlyFrm *pFly = FindFlyFrm();
1133         if( !pFly )
1134         {
1135             ASSERT( GetCurrFrm(), "Crsr in parking zone" );
1136             pFly = GetCurrFrm()->FindFlyFrm();
1137             ASSERT( pFly, "SetFlyFrmAttr, no Fly selected." );
1138         }
1139         if( pFly )
1140         {
1141             StartAllAction();
1142             const Point aPt( pFly->Frm().Pos() );
1143 
1144             if( SFX_ITEM_SET == rSet.GetItemState( RES_ANCHOR, sal_False ))
1145                 ::lcl_ChkAndSetNewAnchor( *pFly, rSet );
1146             SwFlyFrmFmt* pFlyFmt = (SwFlyFrmFmt*)pFly->GetFmt();
1147 
1148             if( GetDoc()->SetFlyFrmAttr( *pFlyFmt, rSet ))
1149             {
1150                 bRet = sal_True;
1151                 SwFlyFrm* pFrm = pFlyFmt->GetFrm( &aPt );
1152                 if( pFrm )
1153                     SelectFlyFrm( *pFrm, sal_True );
1154                 else
1155                     GetLayout()->SetAssertFlyPages();
1156             }
1157 
1158             EndAllActionAndCall();
1159         }
1160     }
1161     return bRet;
1162 }
1163 /*-- 30.03.2004 15:05:07---------------------------------------------------
1164 
1165   -----------------------------------------------------------------------*/
1166 sal_Bool SwFEShell::SetDrawingAttr( SfxItemSet& rSet )
1167 {
1168     sal_Bool bRet = sal_False;
1169     SET_CURR_SHELL( this );
1170     if ( !rSet.Count() ||
1171             !Imp()->HasDrawView() )
1172         return bRet;
1173 
1174     const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
1175     if ( rMrkList.GetMarkCount() != 1 )
1176         return bRet;
1177 
1178     StartUndo();
1179     SdrObject *pObj = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
1180     SwFrmFmt *pFmt = FindFrmFmt( pObj );
1181     StartAllAction();
1182     if( SFX_ITEM_SET == rSet.GetItemState( RES_ANCHOR, sal_False ))
1183     {
1184         RndStdIds nNew = ((SwFmtAnchor&)rSet.Get( RES_ANCHOR )).GetAnchorId();
1185         if ( nNew != pFmt->GetAnchor().GetAnchorId() )
1186         {
1187             ChgAnchor( nNew );
1188             // --> OD 2004-06-17 #i26791# - clear anchor attribute in item set,
1189             // because method <ChgAnchor(..)> takes care of it.
1190             rSet.ClearItem( RES_ANCHOR );
1191         }
1192     }
1193 
1194     if( GetDoc()->SetFlyFrmAttr( *pFmt, rSet ))
1195     {
1196         bRet = sal_True;
1197         Point aTmp;
1198         SelectObj( aTmp, 0, pObj );
1199     }
1200     EndAllActionAndCall();
1201     EndUndo();
1202     return bRet;
1203 }
1204 
1205 
1206 /***********************************************************************
1207 #*  Class       :  SwFEShell
1208 #*  Methode     :  ResetFlyFrmAttr
1209 #*  Beschreibung:  Das gewuenschte Attribut oder die im Set befindlichen
1210 #*                  werden zurueckgesetzt.
1211 #*  Datum       :  MA 14. Mar. 97
1212 #*  Update      :  MA 14. Mar. 97
1213 #***********************************************************************/
1214 
1215 sal_Bool SwFEShell::ResetFlyFrmAttr( sal_uInt16 nWhich, const SfxItemSet* pSet )
1216 {
1217     sal_Bool bRet = sal_False;
1218 
1219     if( RES_ANCHOR != nWhich && RES_CHAIN != nWhich && RES_CNTNT != nWhich )
1220     {
1221         SET_CURR_SHELL( this );
1222 
1223         SwFlyFrm *pFly = FindFlyFrm();
1224         if( !pFly )
1225         {
1226             ASSERT( GetCurrFrm(), "Crsr in parking zone" );
1227             pFly = GetCurrFrm()->FindFlyFrm();
1228             ASSERT( pFly, "SetFlyFrmAttr, no Fly selected." );
1229         }
1230 
1231         if( pFly )
1232         {
1233             StartAllAction();
1234 
1235             if( pSet )
1236             {
1237                 SfxItemIter aIter( *pSet );
1238                 const SfxPoolItem* pItem = aIter.FirstItem();
1239                 while( pItem )
1240                 {
1241                     if( !IsInvalidItem( pItem ) &&
1242                         RES_ANCHOR != ( nWhich = pItem->Which() ) &&
1243                         RES_CHAIN != nWhich && RES_CNTNT != nWhich )
1244                         pFly->GetFmt()->ResetFmtAttr( nWhich );
1245                     pItem = aIter.NextItem();
1246                 }
1247             }
1248             else
1249                 pFly->GetFmt()->ResetFmtAttr( nWhich );
1250 
1251             bRet = sal_True;
1252             EndAllActionAndCall();
1253             GetDoc()->SetModified();
1254         }
1255     }
1256     return bRet;
1257 }
1258 
1259 /***********************************************************************
1260 #*  Class       :  SwFEShell
1261 #*  Methode     :  GetCurFrmFmt
1262 #*  Beschreibung:  liefert wenn Rahmen, dann Rahmenvorlage, sonst 0
1263 #*  Datum       :  ST 04. Jun. 93
1264 #*  Update      :
1265 #***********************************************************************/
1266 
1267 SwFrmFmt* SwFEShell::GetCurFrmFmt() const
1268 {
1269     SwFrmFmt* pRet = 0;
1270     SwLayoutFrm *pFly = FindFlyFrm();
1271     if( pFly && ( pRet = (SwFrmFmt*)pFly->GetFmt()->DerivedFrom() ) ==
1272                                             GetDoc()->GetDfltFrmFmt() )
1273         pRet = 0;
1274     return pRet;
1275 }
1276 
1277 /******************************************************************************
1278  *  Methode     :   void SwFEShell::SetFrmFmt(SwFrmFmt *pNewFmt)
1279  *  Beschreibung:
1280  *  Erstellt    :   OK 14.04.94 15:40
1281  *  Aenderung   :   MA 23. Apr. 97
1282  ******************************************************************************/
1283 
1284 void SwFEShell::SetFrmFmt( SwFrmFmt *pNewFmt, sal_Bool bKeepOrient, Point* pDocPos )
1285 {
1286     SwFlyFrm *pFly = 0;
1287     if(pDocPos)
1288     {
1289         const SwFrmFmt* pFmt = GetFmtFromObj( *pDocPos );
1290 
1291         if(PTR_CAST(SwFlyFrmFmt, pFmt))
1292             pFly = ((SwFlyFrmFmt*)pFmt)->GetFrm();
1293     }
1294     else
1295         pFly = FindFlyFrm();
1296     ASSERT( pFly, "SetFrmFmt: kein Frame" );
1297     if( pFly )
1298     {
1299         StartAllAction();
1300         SET_CURR_SHELL( this );
1301 
1302         SwFlyFrmFmt* pFlyFmt = (SwFlyFrmFmt*)pFly->GetFmt();
1303         const Point aPt( pFly->Frm().Pos() );
1304 
1305         SfxItemSet* pSet = 0;
1306         const SfxPoolItem* pItem;
1307         if( SFX_ITEM_SET == pNewFmt->GetItemState( RES_ANCHOR, sal_False, &pItem ))
1308         {
1309             pSet = new SfxItemSet( GetDoc()->GetAttrPool(), aFrmFmtSetRange );
1310             pSet->Put( *pItem );
1311             if( !::lcl_ChkAndSetNewAnchor( *pFly, *pSet ))
1312                 delete pSet, pSet = 0;
1313         }
1314 
1315         if( GetDoc()->SetFrmFmtToFly( *pFlyFmt, *pNewFmt, pSet, bKeepOrient ))
1316         {
1317             SwFlyFrm* pFrm = pFlyFmt->GetFrm( &aPt );
1318             if( pFrm )
1319                 SelectFlyFrm( *pFrm, sal_True );
1320             else
1321                 GetLayout()->SetAssertFlyPages();
1322         }
1323         if( pSet )
1324             delete pSet;
1325 
1326         EndAllActionAndCall();
1327     }
1328 }
1329 
1330 /*************************************************************************
1331 |*
1332 |*  SwFEShell::GetFlyFrmFmt()
1333 |*
1334 |*  Ersterstellung      OK 23.06.93 13:15
1335 |*  Letzte Aenderung    OK 23.06.93 13:15
1336 |*
1337 *************************************************************************/
1338 
1339 const SwFrmFmt* SwFEShell::GetFlyFrmFmt() const
1340 {
1341     const SwFlyFrm* pFly = FindFlyFrm();
1342     if ( !pFly )
1343     {
1344         SwFrm* pCurrFrm = GetCurrFrm();
1345         pFly = pCurrFrm ? pCurrFrm->FindFlyFrm() : 0;
1346     }
1347     if( pFly )
1348         return pFly->GetFmt();
1349     return 0;
1350 }
1351 
1352 SwFrmFmt* SwFEShell::GetFlyFrmFmt()
1353 {
1354     SwFlyFrm* pFly = FindFlyFrm();
1355     if ( !pFly )
1356     {
1357         SwFrm* pCurrFrm = GetCurrFrm();
1358         pFly = pCurrFrm ? pCurrFrm->FindFlyFrm() : 0;
1359     }
1360     if( pFly )
1361         return pFly->GetFmt();
1362     return 0;
1363 }
1364 
1365 /*************************************************************************
1366 |*
1367 |*  SwFEShell::GetFlyRect()
1368 |*
1369 |*  Ersterstellung      AMA 6. Mae. 97
1370 |*  Letzte Aenderung    AMA 6. Mae. 97
1371 |*
1372 *************************************************************************/
1373 
1374 SwRect SwFEShell::GetFlyRect() const
1375 {
1376     SwCntntFrm *pCntnt = GetCurrFrm( sal_False );
1377     SwFlyFrm *pFly = pCntnt ? pCntnt->FindFlyFrm() : 0;
1378     if ( !pFly )
1379     {
1380         SwRect aRect;
1381         return aRect;
1382     }
1383     else
1384         return pFly->Frm();
1385 }
1386 
1387 /*************************************************************************
1388 |*
1389 |*  SwFEShell::GetObjRect()
1390 |*
1391 |*  Ersterstellung      MA 22. Aug. 93
1392 |*  Letzte Aenderung    MA 11. Jan. 95
1393 |*
1394 *************************************************************************/
1395 
1396 SwRect SwFEShell::GetObjRect() const
1397 {
1398     if( Imp()->HasDrawView() )
1399         return Imp()->GetDrawView()->GetAllMarkedRect();
1400     else
1401     {
1402         SwRect aRect;
1403         return aRect;
1404     }
1405 }
1406 
1407 void SwFEShell::SetObjRect( const SwRect& rRect )
1408 {
1409     if ( Imp()->HasDrawView() )
1410     {
1411         Imp()->GetDrawView()->SetAllMarkedRect( rRect.SVRect() );
1412         CallChgLnk();   // rufe das AttrChangeNotify auf der UI-Seite.
1413     }
1414 }
1415 
1416 /***********************************************************************
1417 #*  Class       :  SwFEShell
1418 #*  Methode     :  RequestObjectResize()
1419 #*  Datum       :  MA 10. Feb. 95
1420 #*  Update      :  MA 13. Jul. 95
1421 #***********************************************************************/
1422 
1423 Size SwFEShell::RequestObjectResize( const SwRect &rRect, const uno::Reference < embed::XEmbeddedObject >& xObj )
1424 {
1425     Size aResult;
1426 
1427     SwFlyFrm *pFly = FindFlyFrm( xObj );
1428     if ( !pFly )
1429     {
1430         aResult = rRect.SSize();
1431         return aResult;
1432     }
1433 
1434     aResult = pFly->Prt().SSize();
1435 
1436     sal_Bool bPosProt = pFly->GetFmt()->GetProtect().IsPosProtected();
1437     sal_Bool bSizeProt = pFly->GetFmt()->GetProtect().IsSizeProtected();
1438 
1439     StartAllAction();
1440 
1441     //MA wir lassen den Fly nicht Clippen, damit die Ole-Server mit
1442     //beliebigen Wuenschen kommen koennen. Die Formatierung uebernimmt das
1443     //Clippen. Die richtige Darstellung wird per Scalierung erledigt.
1444     //Die Scalierung wird von SwNoTxtFrm::Format durch einen Aufruf von
1445     //SwWrtShell::CalcAndSetScale() erledigt.
1446     if ( rRect.SSize() != pFly->Prt().SSize() && !bSizeProt )
1447     {
1448         Size aSz( rRect.SSize() );
1449 
1450         //JP 28.02.2001: Task 74707 - ask for fly in fly with automatic size
1451         //
1452         const SwFrm* pAnchor;
1453         const SwTxtNode* pTNd;
1454         const SwpHints* pHts;
1455         const SwFmtFrmSize& rFrmSz = pFly->GetFmt()->GetFrmSize();
1456         if( bCheckForOLEInCaption &&
1457             0 != rFrmSz.GetWidthPercent() &&
1458             0 != (pAnchor = pFly->GetAnchorFrm()) &&
1459             pAnchor->IsTxtFrm() &&
1460             !pAnchor->GetNext() && !pAnchor->GetPrev() &&
1461             pAnchor->GetUpper()->IsFlyFrm() &&
1462             0 != ( pTNd = ((SwTxtFrm*)pAnchor)->GetNode()->GetTxtNode()) &&
1463             0 != ( pHts = pTNd->GetpSwpHints() ))
1464         {
1465             // search for a sequence field:
1466             const SfxPoolItem* pItem;
1467             for( sal_uInt16 n = 0, nEnd = pHts->Count(); n < nEnd; ++n )
1468                 if( RES_TXTATR_FIELD == ( pItem =
1469                             &(*pHts)[ n ]->GetAttr())->Which() &&
1470                     TYP_SEQFLD == ((SwFmtFld*)pItem)->GetFld()->GetTypeId() )
1471                 {
1472                     // sequence field found
1473                     SwFlyFrm* pChgFly = (SwFlyFrm*)pAnchor->GetUpper();
1474                     // calculate the changed size:
1475                     // width must change, height can change
1476                     Size aNewSz( aSz.Width() + pChgFly->Frm().Width() -
1477                                    pFly->Prt().Width(), aSz.Height() );
1478 
1479                     SwFrmFmt *pFmt = pChgFly->GetFmt();
1480                     SwFmtFrmSize aFrmSz( pFmt->GetFrmSize() );
1481                     aFrmSz.SetWidth( aNewSz.Width() );
1482                     if( ATT_MIN_SIZE != aFrmSz.GetHeightSizeType() )
1483                     {
1484                         aNewSz.Height() += pChgFly->Frm().Height() -
1485                                             pFly->Prt().Height();
1486                         if( Abs( aNewSz.Height() - pChgFly->Frm().Height()) > 1 )
1487                             aFrmSz.SetHeight( aNewSz.Height() );
1488                     }
1489                     // uebers Doc fuers Undo!
1490                     pFmt->GetDoc()->SetAttr( aFrmSz, *pFmt );
1491                     break;
1492                 }
1493         }
1494 
1495         // set the new Size at the fly themself
1496         if ( pFly->Prt().Height() > 0 && pFly->Prt().Width() > 0 )
1497         {
1498             aSz.Width() += pFly->Frm().Width() - pFly->Prt().Width();
1499             aSz.Height()+= pFly->Frm().Height()- pFly->Prt().Height();
1500         }
1501         aResult = pFly->ChgSize( aSz );
1502 
1503         //Wenn sich das Objekt aendert ist die Kontur hoechstwahrscheinlich daneben.
1504         ASSERT( pFly->Lower()->IsNoTxtFrm(), "Request ohne NoTxt" );
1505         SwNoTxtNode *pNd = ((SwCntntFrm*)pFly->Lower())->GetNode()->GetNoTxtNode();
1506         ASSERT( pNd, "Request ohne Node" );
1507         pNd->SetContour( 0 );
1508         ClrContourCache();
1509     }
1510 
1511     //Wenn nur die Size angepasst werden soll, so wird eine Pos mit
1512     //ausgezeichneten Werten transportiert.
1513     Point aPt( pFly->Prt().Pos() );
1514     aPt += pFly->Frm().Pos();
1515     if ( rRect.Top() != LONG_MIN && rRect.Pos() != aPt && !bPosProt )
1516     {
1517         aPt = rRect.Pos();
1518         aPt.X() -= pFly->Prt().Left();
1519         aPt.Y() -= pFly->Prt().Top();
1520         //Bei Absatzgebundenen Flys muss ausgehend von der neuen Position ein
1521         //neuer Anker gesetzt werden. Anker und neue RelPos werden vom Fly
1522         //selbst berechnet und gesetzt.
1523         if( pFly->IsFlyAtCntFrm() )
1524             ((SwFlyAtCntFrm*)pFly)->SetAbsPos( aPt );
1525         else
1526         {
1527             const SwFrmFmt *pFmt = pFly->GetFmt();
1528             const SwFmtVertOrient &rVert = pFmt->GetVertOrient();
1529             const SwFmtHoriOrient &rHori = pFmt->GetHoriOrient();
1530             const long lXDiff = aPt.X() - pFly->Frm().Left();
1531             const long lYDiff = aPt.Y() - pFly->Frm().Top();
1532             const Point aTmp( rHori.GetPos() + lXDiff,
1533                               rVert.GetPos() + lYDiff );
1534             pFly->ChgRelPos( aTmp );
1535         }
1536     }
1537 
1538     SwFlyFrmFmt *pFlyFrmFmt = pFly->GetFmt();
1539     ASSERT( pFlyFrmFmt, "fly frame format missing!" );
1540     if ( pFlyFrmFmt )
1541         pFlyFrmFmt->SetLastFlyFrmPrtRectPos( pFly->Prt().Pos() ); //stores the value of last Prt rect
1542 
1543     EndAllAction();
1544 
1545     return aResult;
1546 }
1547 
1548 
1549 /***********************************************************************
1550 #*  Class       :  SwFEShell
1551 #*  Methode     :  WizzardFindCurFrmFmt
1552 #*  Datum       :  JP 31.07.95
1553 #*  Update      :  JP 31.07.95
1554 #***********************************************************************/
1555 
1556 SwFrmFmt* SwFEShell::WizzardGetFly()
1557 {
1558     // mal nicht uebers Layout den Fly suchen. Dann kann auch ohne gueltiges
1559     // Layout ein Rahmen geloescht werden. ( z.B.: fuer die Wizard's )
1560     SwSpzFrmFmts& rSpzArr = *pDoc->GetSpzFrmFmts();
1561     sal_uInt16 nCnt = rSpzArr.Count();
1562     if( nCnt )
1563     {
1564         SwNodeIndex& rCrsrNd = GetCrsr()->GetPoint()->nNode;
1565         if( rCrsrNd.GetIndex() > pDoc->GetNodes().GetEndOfExtras().GetIndex() )
1566             // Cusor steht im Body-Bereich!
1567             return 0;
1568 
1569         for( sal_uInt16 n = 0; n < nCnt; ++n )
1570         {
1571             SwFrmFmt* pFmt = rSpzArr[ n ];
1572             const SwNodeIndex* pIdx = pFmt->GetCntnt( sal_False ).GetCntntIdx();
1573             SwStartNode* pSttNd;
1574             if( pIdx &&
1575                 0 != ( pSttNd = pIdx->GetNode().GetStartNode() ) &&
1576                 pSttNd->GetIndex() < rCrsrNd.GetIndex() &&
1577                 rCrsrNd.GetIndex() < pSttNd->EndOfSectionIndex() )
1578             {
1579                 // gefunden: also raus damit
1580                 return pFmt;
1581             }
1582         }
1583     }
1584     return 0;
1585 }
1586 
1587 void SwFEShell::SetFlyName( const String& rName )
1588 {
1589     SwLayoutFrm *pFly = FindFlyFrm();
1590     if( pFly )
1591         GetDoc()->SetFlyName( *(SwFlyFrmFmt*)pFly->GetFmt(), rName );
1592     else {
1593         ASSERT( !this, "kein FlyFrame selektiert" )
1594     }
1595 }
1596 
1597 const String& SwFEShell::GetFlyName() const
1598 {
1599     SwLayoutFrm *pFly = FindFlyFrm();
1600     if( pFly )
1601         return pFly->GetFmt()->GetName();
1602 
1603     ASSERT( !this, "kein FlyFrame selektiert" )
1604     return aEmptyStr;
1605 }
1606 
1607 
1608 const uno::Reference < embed::XEmbeddedObject > SwFEShell::GetOleRef() const
1609 {
1610     uno::Reference < embed::XEmbeddedObject > xObj;
1611     SwFlyFrm * pFly = FindFlyFrm();
1612     if (pFly && pFly->Lower() && pFly->Lower()->IsNoTxtFrm())
1613     {
1614         SwOLENode *pNd = ((SwNoTxtFrm*)pFly->Lower())->GetNode()->GetOLENode();
1615         if (pNd)
1616             xObj = pNd->GetOLEObj().GetOleRef();
1617     }
1618     return xObj;
1619 }
1620 
1621 
1622 String SwFEShell::GetUniqueGrfName() const
1623 {
1624     return GetDoc()->GetUniqueGrfName();
1625 }
1626 
1627 const SwFrmFmt* SwFEShell::IsURLGrfAtPos( const Point& rPt, String* pURL,
1628                                         String *pTargetFrameName,
1629                                         String *pDescription ) const
1630 {
1631     if( !Imp()->HasDrawView() )
1632         return 0;
1633 
1634     SdrObject* pObj;
1635     SdrPageView* pPV;
1636     const SwFrmFmt* pRet = 0;
1637     SwDrawView *pDView = (SwDrawView*)Imp()->GetDrawView();
1638 
1639     sal_uInt16 nOld = pDView->GetHitTolerancePixel();
1640     pDView->SetHitTolerancePixel( 2 );
1641 
1642     if( pDView->PickObj( rPt, pDView->getHitTolLog(), pObj, pPV,SDRSEARCH_PICKMACRO ) &&
1643         pObj->ISA(SwVirtFlyDrawObj) )
1644     {
1645         SwFlyFrm *pFly = ((SwVirtFlyDrawObj*)pObj)->GetFlyFrm();
1646         const SwFmtURL &rURL = pFly->GetFmt()->GetURL();
1647         if( rURL.GetURL().Len() || rURL.GetMap() )
1648         {
1649             sal_Bool bSetTargetFrameName = pTargetFrameName != 0;
1650             sal_Bool bSetDescription = pDescription != 0;
1651             if ( rURL.GetMap() )
1652             {
1653                 IMapObject *pObject = pFly->GetFmt()->GetIMapObject( rPt, pFly );
1654                 if ( pObject && pObject->GetURL().Len() )
1655                 {
1656                     if( pURL )
1657                         *pURL = pObject->GetURL();
1658                     if ( bSetTargetFrameName && pObject->GetTarget().Len() )
1659                     {
1660                         bSetTargetFrameName = sal_False;
1661                         *pTargetFrameName = pObject->GetTarget();
1662                     }
1663                     if ( bSetDescription )
1664                     {
1665                         bSetDescription = sal_False;
1666                         *pDescription = pObject->GetAltText();
1667                     }
1668                     pRet = pFly->GetFmt();
1669                 }
1670             }
1671             else
1672             {
1673                 if( pURL )
1674                 {
1675                     *pURL = rURL.GetURL();
1676                     if( rURL.IsServerMap() )
1677                     {
1678                         // dann die rel. Pixel Position anhaengen !!
1679                         Point aPt( rPt );
1680                         aPt -= pFly->Frm().Pos();
1681                         // ohne MapMode-Offset, ohne Offset, o ... !!!!!
1682                         aPt = GetOut()->LogicToPixel(
1683                                 aPt, MapMode( MAP_TWIP ) );
1684                         ((( *pURL += '?' ) += String::CreateFromInt32( aPt.X() ))
1685                                   += ',' ) += String::CreateFromInt32(aPt.Y() );
1686                     }
1687                 }
1688                 pRet = pFly->GetFmt();
1689             }
1690             if ( bSetTargetFrameName )
1691                 *pTargetFrameName = rURL.GetTargetFrameName();
1692             if ( bSetDescription )
1693                 *pDescription = pFly->GetFmt()->GetName();
1694         }
1695     }
1696     pDView->SetHitTolerancePixel( nOld );
1697     return pRet;
1698 }
1699 
1700 const Graphic *SwFEShell::GetGrfAtPos( const Point &rPt,
1701                                        String &rName, sal_Bool &rbLink ) const
1702 {
1703     if( !Imp()->HasDrawView() )
1704         return 0;
1705 
1706     SdrObject* pObj;
1707     SdrPageView* pPV;
1708     SwDrawView *pDView = (SwDrawView*)Imp()->GetDrawView();
1709 
1710     if( pDView->PickObj( rPt, pDView->getHitTolLog(), pObj, pPV ) && pObj->ISA(SwVirtFlyDrawObj) )
1711     {
1712         SwFlyFrm *pFly = ((SwVirtFlyDrawObj*)pObj)->GetFlyFrm();
1713         if ( pFly->Lower() && pFly->Lower()->IsNoTxtFrm() )
1714         {
1715             SwGrfNode *pNd = ((SwCntntFrm*)pFly->Lower())->GetNode()->GetGrfNode();
1716             if ( pNd )
1717             {
1718                 if ( pNd->IsGrfLink() )
1719                 {
1720                     //Halbfertige Grafik?
1721                     ::sfx2::SvLinkSource* pLnkObj = pNd->GetLink()->GetObj();
1722                     if( pLnkObj && pLnkObj->IsPending() )
1723                         return 0;
1724                     rbLink = sal_True;
1725                 }
1726 
1727                 pNd->GetFileFilterNms( &rName, 0 );
1728                 if ( !rName.Len() )
1729                     rName = pFly->GetFmt()->GetName();
1730                 pNd->SwapIn( sal_True );
1731                 return &pNd->GetGrf();
1732             }
1733         }
1734     }
1735     return 0;
1736 }
1737 
1738 
1739 const SwFrmFmt* SwFEShell::GetFmtFromObj( const Point& rPt, SwRect** pRectToFill ) const
1740 {
1741     SwFrmFmt* pRet = 0;
1742 
1743     if( Imp()->HasDrawView() )
1744     {
1745         SdrObject* pObj;
1746         SdrPageView* pPView;
1747 
1748         SwDrawView *pDView = (SwDrawView*)Imp()->GetDrawView();
1749 
1750         sal_uInt16 nOld = pDView->GetHitTolerancePixel();
1751         // Tattergrenze fuer Drawing-SS
1752         pDView->SetHitTolerancePixel( pDView->GetMarkHdlSizePixel()/2 );
1753 
1754         if( pDView->PickObj( rPt, pDView->getHitTolLog(), pObj, pPView, SDRSEARCH_PICKMARKABLE ) )
1755         {
1756             // dann teste mal was es ist:
1757             if ( pObj->ISA(SwVirtFlyDrawObj) )
1758                 pRet = ((SwVirtFlyDrawObj*)pObj)->GetFmt();
1759             else if ( pObj->GetUserCall() ) //nicht fuer Gruppenobjekte
1760                 pRet = ((SwDrawContact*)pObj->GetUserCall())->GetFmt();
1761             if(pRet && pRectToFill)
1762                 **pRectToFill = pObj->GetCurrentBoundRect();
1763         }
1764         pDView->SetHitTolerancePixel( nOld );
1765     }
1766     return pRet;
1767 }
1768 
1769 // returns a format too, if the point is over the text of any fly
1770 const SwFrmFmt* SwFEShell::GetFmtFromAnyObj( const Point& rPt ) const
1771 {
1772     const SwFrmFmt* pRet = GetFmtFromObj( rPt );
1773     if( !pRet || RES_FLYFRMFMT == pRet->Which() )
1774     {
1775         SwPosition aPos( *GetCrsr()->GetPoint() );
1776         Point aPt( rPt );
1777         GetLayout()->GetCrsrOfst( &aPos, aPt );
1778         SwCntntNode *pNd = aPos.nNode.GetNode().GetCntntNode();
1779         SwFrm* pFrm = pNd->getLayoutFrm( GetLayout(), &rPt, 0, sal_False )->FindFlyFrm();
1780         pRet = pFrm ? ((SwLayoutFrm*)pFrm)->GetFmt() : 0;
1781     }
1782     return pRet;
1783 }
1784 
1785 ObjCntType SwFEShell::GetObjCntType( const SdrObject& rObj ) const
1786 {
1787     ObjCntType eType = OBJCNT_NONE;
1788 
1789     // OD 23.06.2003 #108784# - investigate 'master' drawing object, if method
1790     // is called for a 'virtual' drawing object.
1791     const SdrObject* pInvestigatedObj;
1792     if ( rObj.ISA(SwDrawVirtObj) )
1793     {
1794         const SwDrawVirtObj* pDrawVirtObj = static_cast<const SwDrawVirtObj*>(&rObj);
1795         pInvestigatedObj = &(pDrawVirtObj->GetReferencedObj());
1796     }
1797     else
1798     {
1799         pInvestigatedObj = &rObj;
1800     }
1801 
1802     if( FmFormInventor == pInvestigatedObj->GetObjInventor() )
1803     {
1804         eType = OBJCNT_CONTROL;
1805         uno::Reference< awt::XControlModel >  xModel =
1806                 ((SdrUnoObj&)(*pInvestigatedObj)).GetUnoControlModel();
1807         if( xModel.is() )
1808         {
1809             uno::Any aVal;
1810             OUString sName = OUString::createFromAscii("ButtonType");
1811             uno::Reference< beans::XPropertySet >  xSet(xModel, uno::UNO_QUERY);
1812 
1813             uno::Reference< beans::XPropertySetInfo >  xInfo = xSet->getPropertySetInfo();
1814             if(xInfo->hasPropertyByName( sName ))
1815             {
1816                 beans::Property xProperty = xInfo->getPropertyByName( sName );
1817                 aVal = xSet->getPropertyValue( sName );
1818                 if( aVal.getValue() && form::FormButtonType_URL == *((form::FormButtonType*)aVal.getValue()) )
1819                     eType = OBJCNT_URLBUTTON;
1820             }
1821         }
1822     }
1823     else if( pInvestigatedObj->ISA(SwVirtFlyDrawObj) )
1824     {
1825         SwFlyFrm *pFly = ((SwVirtFlyDrawObj&)(*pInvestigatedObj)).GetFlyFrm();
1826         if ( pFly->Lower() && pFly->Lower()->IsNoTxtFrm() )
1827         {
1828             if ( ((SwCntntFrm*)pFly->Lower())->GetNode()->GetGrfNode() )
1829                 eType = OBJCNT_GRF;
1830             else
1831                 eType = OBJCNT_OLE;
1832         }
1833         else
1834             eType = OBJCNT_FLY;
1835     }
1836     else if ( pInvestigatedObj->ISA( SdrObjGroup ) )
1837     {
1838         SwDrawContact* pDrawContact( dynamic_cast<SwDrawContact*>(GetUserCall( pInvestigatedObj ) ) );
1839         if ( !pDrawContact )
1840         {
1841             ASSERT( false,
1842                     "<SwFEShell::GetObjCntType(..)> - missing draw contact object" );
1843             eType = OBJCNT_NONE;
1844         }
1845         else
1846         {
1847             SwFrmFmt* pFrmFmt( pDrawContact->GetFmt() );
1848             if ( !pFrmFmt )
1849             {
1850                 ASSERT( false,
1851                         "<SwFEShell::GetObjCntType(..)> - missing frame format" );
1852                 eType = OBJCNT_NONE;
1853             }
1854             else if ( FLY_AS_CHAR != pFrmFmt->GetAnchor().GetAnchorId() )
1855             {
1856                 eType = OBJCNT_GROUPOBJ;
1857             }
1858         }
1859     }
1860     else
1861         eType = OBJCNT_SIMPLE;
1862     return eType;
1863 }
1864 
1865 ObjCntType SwFEShell::GetObjCntType( const Point &rPt, SdrObject *&rpObj ) const
1866 {
1867     ObjCntType eType = OBJCNT_NONE;
1868 
1869     if( Imp()->HasDrawView() )
1870     {
1871         SdrObject* pObj;
1872         SdrPageView* pPView;
1873 
1874         SwDrawView *pDView = (SwDrawView*)Imp()->GetDrawView();
1875 
1876         sal_uInt16 nOld = pDView->GetHitTolerancePixel();
1877         // Tattergrenze fuer Drawing-SS
1878         pDView->SetHitTolerancePixel( pDView->GetMarkHdlSizePixel()/2 );
1879 
1880         if( pDView->PickObj( rPt, pDView->getHitTolLog(), pObj, pPView, SDRSEARCH_PICKMARKABLE ) )
1881             eType = GetObjCntType( *(rpObj = pObj) );
1882 
1883         pDView->SetHitTolerancePixel( nOld );
1884     }
1885     return eType;
1886 }
1887 
1888 ObjCntType SwFEShell::GetObjCntTypeOfSelection( SdrObject** ppObj ) const
1889 {
1890     ObjCntType eType = OBJCNT_NONE;
1891 
1892     if( Imp()->HasDrawView() )
1893     {
1894         const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
1895         for( sal_uInt32 i = 0, nE = rMrkList.GetMarkCount(); i < nE; ++i )
1896         {
1897             SdrObject* pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
1898             if( !pObj )
1899                 continue;
1900             ObjCntType eTmp = GetObjCntType( *pObj );
1901             if( !i )
1902             {
1903                 eType = eTmp;
1904                 if( ppObj ) *ppObj = pObj;
1905             }
1906             else if( eTmp != eType )
1907             {
1908                 eType = OBJCNT_DONTCARE;
1909                 // einmal DontCare, immer DontCare!
1910                 break;
1911             }
1912         }
1913     }
1914     return eType;
1915 }
1916 
1917 
1918 sal_Bool SwFEShell::ReplaceSdrObj( const String& rGrfName, const String& rFltName,
1919                                 const Graphic* pGrf )
1920 {
1921     SET_CURR_SHELL( this );
1922 
1923     sal_Bool bRet = sal_False;
1924     const SdrMarkList *pMrkList;
1925     if( Imp()->HasDrawView() &&  1 ==
1926         ( pMrkList = &Imp()->GetDrawView()->GetMarkedObjectList())->GetMarkCount() )
1927     {
1928         SdrObject* pObj = pMrkList->GetMark( 0 )->GetMarkedSdrObj();
1929         SwFrmFmt *pFmt = FindFrmFmt( pObj );
1930 
1931         // Attribute sichern und dann an der Grafik setzen
1932         SfxItemSet aFrmSet( pDoc->GetAttrPool(),
1933                             pFmt->GetAttrSet().GetRanges() );
1934         aFrmSet.Set( pFmt->GetAttrSet() );
1935 
1936         // Groesse und Position setzen ??
1937         if( !pObj->ISA(SwVirtFlyDrawObj) )
1938         {
1939             // dann mal los:
1940             const Rectangle &rBound = pObj->GetSnapRect();
1941             Point aRelPos( pObj->GetRelativePos() );
1942 
1943             const long nWidth = rBound.Right()  - rBound.Left();
1944             const long nHeight= rBound.Bottom() - rBound.Top();
1945             aFrmSet.Put( SwFmtFrmSize( ATT_MIN_SIZE,
1946                                 Max( nWidth,  long(MINFLY) ),
1947                                 Max( nHeight, long(MINFLY) )));
1948 
1949             if( SFX_ITEM_SET != aFrmSet.GetItemState( RES_HORI_ORIENT ))
1950                 aFrmSet.Put( SwFmtHoriOrient( aRelPos.X(), text::HoriOrientation::NONE, text::RelOrientation::FRAME ));
1951 
1952             if( SFX_ITEM_SET != aFrmSet.GetItemState( RES_VERT_ORIENT ))
1953                 aFrmSet.Put( SwFmtVertOrient( aRelPos.Y(), text::VertOrientation::NONE, text::RelOrientation::FRAME ));
1954 
1955         }
1956 
1957         pObj->GetOrdNum();
1958 
1959         StartAllAction();
1960         StartUndo();
1961 
1962         // das "Sdr-Object" loeschen und dafuer die Grafik einfuegen
1963         DelSelectedObj();
1964 
1965         pFmt = GetDoc()->Insert( *GetCrsr(), rGrfName, rFltName, pGrf, &aFrmSet, NULL, NULL );
1966 
1967         // die Ordnungsnummer (Z-Order) noch uebertragen
1968         // JP 04.07.98: klappt aber nicht richtig!
1969         //SdrObject* pNewObj = ::FindSdrObject( pFmt );
1970         //pNewObj->SetOrdNum( nOrdNum );
1971 
1972         EndUndo();
1973         EndAllAction();
1974         bRet = sal_True;
1975     }
1976     return bRet;
1977 }
1978 
1979 static sal_uInt16 SwFmtGetPageNum(const SwFlyFrmFmt * pFmt)
1980 {
1981     ASSERT(pFmt != NULL, "invalid argument");
1982 
1983     SwFlyFrm * pFrm = pFmt->GetFrm();
1984 
1985     sal_uInt16 aResult;
1986 
1987     if (pFrm != NULL)
1988         aResult = pFrm->GetPhyPageNum();
1989     else
1990         aResult = pFmt->GetAnchor().GetPageNum();
1991 
1992     return aResult;
1993 }
1994 
1995 #include <fmtcnct.hxx>
1996 
1997 void SwFEShell::GetConnectableFrmFmts(SwFrmFmt & rFmt,
1998                                       const String & rReference,
1999                                       sal_Bool bSuccessors,
2000                                       ::std::vector< String > & aPrevPageVec,
2001                                       ::std::vector< String > & aThisPageVec,
2002                                       ::std::vector< String > & aNextPageVec,
2003                                       ::std::vector< String > & aRestVec)
2004 {
2005     StartAction();
2006 
2007     SwFmtChain rChain = rFmt.GetChain();
2008     SwFrmFmt * pOldChainNext = (SwFrmFmt *) rChain.GetNext();
2009     SwFrmFmt * pOldChainPrev = (SwFrmFmt *) rChain.GetPrev();
2010 
2011     if (pOldChainNext)
2012         pDoc->Unchain(rFmt);
2013 
2014     if (pOldChainPrev)
2015         pDoc->Unchain(*pOldChainPrev);
2016 
2017     sal_uInt16 nCnt = pDoc->GetFlyCount(FLYCNTTYPE_FRM);
2018 
2019     /* potential successors resp. predecessors */
2020     ::std::vector< const SwFrmFmt * > aTmpSpzArray;
2021 
2022     (SwFrmFmt *) pDoc->FindFlyByName(rReference);
2023 
2024     for (sal_uInt16 n = 0; n < nCnt; n++)
2025     {
2026         const SwFrmFmt & rFmt1 = *(pDoc->GetFlyNum(n, FLYCNTTYPE_FRM));
2027 
2028         /*
2029            pFmt is a potential successor of rFmt if it is chainable after
2030            rFmt.
2031 
2032            pFmt is a potential predecessor of rFmt if rFmt is chainable
2033            after pFmt.
2034         */
2035 
2036         int nChainState;
2037 
2038         if (bSuccessors)
2039             nChainState = pDoc->Chainable(rFmt, rFmt1);
2040         else
2041             nChainState = pDoc->Chainable(rFmt1, rFmt);
2042 
2043         if (nChainState == SW_CHAIN_OK)
2044         {
2045             aTmpSpzArray.push_back(&rFmt1);
2046 
2047         }
2048 
2049     }
2050 
2051     if  (aTmpSpzArray.size() > 0)
2052     {
2053         aPrevPageVec.clear();
2054         aThisPageVec.clear();
2055         aNextPageVec.clear();
2056         aRestVec.clear();
2057 
2058         /* number of page rFmt resides on */
2059         sal_uInt16 nPageNum = SwFmtGetPageNum((SwFlyFrmFmt *) &rFmt);
2060 
2061         ::std::vector< const SwFrmFmt * >::const_iterator aIt;
2062 
2063         for (aIt = aTmpSpzArray.begin(); aIt != aTmpSpzArray.end(); aIt++)
2064         {
2065             String  aString = (*aIt)->GetName();
2066 
2067             /* rFmt is not a vaild successor or predecessor of
2068                itself */
2069             if (aString != rReference && aString != rFmt.GetName())
2070             {
2071                 sal_uInt16 nNum1 =
2072                     SwFmtGetPageNum((SwFlyFrmFmt *) *aIt);
2073 
2074                 if (nNum1 == nPageNum -1)
2075                     aPrevPageVec.push_back(aString);
2076                 else if (nNum1 == nPageNum)
2077                     aThisPageVec.push_back(aString);
2078                 else if (nNum1 == nPageNum + 1)
2079                     aNextPageVec.push_back(aString);
2080                 else
2081                     aRestVec.push_back(aString);
2082             }
2083         }
2084 
2085     }
2086 
2087     if (pOldChainNext)
2088         pDoc->Chain(rFmt, *pOldChainNext);
2089 
2090     if (pOldChainPrev)
2091         pDoc->Chain(*pOldChainPrev, rFmt);
2092 
2093     EndAction();
2094 }
2095 
2096 // --> OD 2009-07-13 #i73249#
2097 const String SwFEShell::GetObjTitle() const
2098 {
2099     String aTitle;
2100 
2101     if ( Imp()->HasDrawView() )
2102     {
2103         const SdrMarkList *pMrkList = &Imp()->GetDrawView()->GetMarkedObjectList();
2104         if ( pMrkList->GetMarkCount() == 1 )
2105         {
2106             const SdrObject* pObj = pMrkList->GetMark( 0 )->GetMarkedSdrObj();
2107             const SwFrmFmt* pFmt = FindFrmFmt( pObj );
2108             if ( pFmt->Which() == RES_FLYFRMFMT )
2109             {
2110                 aTitle = dynamic_cast<const SwFlyFrmFmt*>(pFmt)->GetObjTitle();
2111             }
2112             else
2113             {
2114                 aTitle = pObj->GetTitle();
2115             }
2116         }
2117     }
2118 
2119     return aTitle;
2120 }
2121 
2122 void SwFEShell::SetObjTitle( const String& rTitle )
2123 {
2124     if ( Imp()->HasDrawView() )
2125     {
2126         const SdrMarkList *pMrkList = &Imp()->GetDrawView()->GetMarkedObjectList();
2127         if ( pMrkList->GetMarkCount() == 1 )
2128         {
2129             SdrObject* pObj = pMrkList->GetMark( 0 )->GetMarkedSdrObj();
2130             SwFrmFmt* pFmt = FindFrmFmt( pObj );
2131             if ( pFmt->Which() == RES_FLYFRMFMT )
2132             {
2133                 GetDoc()->SetFlyFrmTitle( *(dynamic_cast<SwFlyFrmFmt*>(pFmt)),
2134                                           rTitle );
2135             }
2136             else
2137             {
2138                 pObj->SetTitle( rTitle );
2139             }
2140         }
2141     }
2142 }
2143 
2144 const String SwFEShell::GetObjDescription() const
2145 {
2146     String aDescription;
2147 
2148     if ( Imp()->HasDrawView() )
2149     {
2150         const SdrMarkList *pMrkList = &Imp()->GetDrawView()->GetMarkedObjectList();
2151         if ( pMrkList->GetMarkCount() == 1 )
2152         {
2153             const SdrObject* pObj = pMrkList->GetMark( 0 )->GetMarkedSdrObj();
2154             const SwFrmFmt* pFmt = FindFrmFmt( pObj );
2155             if ( pFmt->Which() == RES_FLYFRMFMT )
2156             {
2157                 aDescription = dynamic_cast<const SwFlyFrmFmt*>(pFmt)->GetObjDescription();
2158             }
2159             else
2160             {
2161                 aDescription = pObj->GetDescription();
2162             }
2163         }
2164     }
2165 
2166     return aDescription;
2167 }
2168 
2169 void SwFEShell::SetObjDescription( const String& rDescription )
2170 {
2171     if ( Imp()->HasDrawView() )
2172     {
2173         const SdrMarkList *pMrkList = &Imp()->GetDrawView()->GetMarkedObjectList();
2174         if ( pMrkList->GetMarkCount() == 1 )
2175         {
2176             SdrObject* pObj = pMrkList->GetMark( 0 )->GetMarkedSdrObj();
2177             SwFrmFmt* pFmt = FindFrmFmt( pObj );
2178             if ( pFmt->Which() == RES_FLYFRMFMT )
2179             {
2180                 GetDoc()->SetFlyFrmDescription( *(dynamic_cast<SwFlyFrmFmt*>(pFmt)),
2181                                                 rDescription );
2182             }
2183             else
2184             {
2185                 pObj->SetDescription( rDescription );
2186             }
2187         }
2188     }
2189 }
2190 
2191 
2192 void SwFEShell::AlignFormulaToBaseline( const uno::Reference < embed::XEmbeddedObject >& xObj, SwFlyFrm * pFly )
2193 {
2194 #if OSL_DEBUG_LEVEL > 1
2195     SvGlobalName aCLSID( xObj->getClassID() );
2196     const bool bStarMath = ( SotExchange::IsMath( aCLSID ) != 0 );
2197     ASSERT( bStarMath, "AlignFormulaToBaseline should only be called for Math objects" );
2198 
2199     if ( !bStarMath )
2200         return;
2201 #endif
2202 
2203     if (!pFly)
2204         pFly = FindFlyFrm( xObj );
2205     ASSERT( pFly , "No fly frame!" );
2206     SwFrmFmt * pFrmFmt = pFly ? pFly->GetFmt() : 0;
2207 
2208     // baseline to baseline alignment should only be applied to formulas anchored as char
2209     if ( pFly && pFrmFmt && FLY_AS_CHAR == pFrmFmt->GetAnchor().GetAnchorId() )
2210     {
2211         // get baseline from Math object
2212         uno::Any aBaseline;
2213         if( svt::EmbeddedObjectRef::TryRunningState( xObj ) )
2214         {
2215             uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY );
2216             if ( xSet.is() )
2217             {
2218                 try
2219                 {
2220                     aBaseline = xSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BaseLine") ) );
2221                 }
2222                 catch ( uno::Exception& )
2223                 {
2224                     ASSERT( sal_False , "Baseline could not be retrieved from Starmath!" );
2225                 }
2226             }
2227         }
2228 
2229         sal_Int32 nBaseline = ::comphelper::getINT32(aBaseline);
2230         const MapMode aSourceMapMode( MAP_100TH_MM );
2231         const MapMode aTargetMapMode( MAP_TWIP );
2232         nBaseline = OutputDevice::LogicToLogic( nBaseline, aSourceMapMode.GetMapUnit(), aTargetMapMode.GetMapUnit() );
2233 
2234         ASSERT( nBaseline > 0, "Wrong value of Baseline while retrieving from Starmath!" );
2235         //nBaseline must be moved by aPrt position
2236         const SwFlyFrmFmt *pFlyFrmFmt = pFly->GetFmt();
2237         ASSERT( pFlyFrmFmt, "fly frame format missing!" );
2238         if ( pFlyFrmFmt )
2239             nBaseline += pFlyFrmFmt->GetLastFlyFrmPrtRectPos().Y();
2240 
2241         const SwFmtVertOrient &rVert = pFrmFmt->GetVertOrient();
2242         SwFmtVertOrient aVert( rVert );
2243         aVert.SetPos( -nBaseline );
2244         aVert.SetVertOrient( com::sun::star::text::VertOrientation::NONE );
2245 
2246         pFrmFmt->LockModify();
2247         pFrmFmt->SetFmtAttr( aVert );
2248         pFrmFmt->UnlockModify();
2249         pFly->InvalidatePos();
2250     }
2251 }
2252 
2253 
2254 void SwFEShell::AlignAllFormulasToBaseline()
2255 {
2256     StartAllAction();
2257 
2258     SwStartNode *pStNd;
2259     SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
2260     while ( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
2261     {
2262         ++aIdx;
2263         SwOLENode *pOleNode = dynamic_cast< SwOLENode * >( &aIdx.GetNode() );
2264         if ( pOleNode )
2265         {
2266             const uno::Reference < embed::XEmbeddedObject > & xObj( pOleNode->GetOLEObj().GetOleRef() );
2267             if (xObj.is())
2268             {
2269                 SvGlobalName aCLSID( xObj->getClassID() );
2270                 if ( SotExchange::IsMath( aCLSID ) )
2271                     AlignFormulaToBaseline( xObj );
2272             }
2273         }
2274 
2275         aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
2276     }
2277 
2278     EndAllAction();
2279 }
2280