xref: /trunk/main/sw/source/core/doc/doclay.cxx (revision 321594d2d360557d383d443eff35f44610055cea)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_sw.hxx"
24 
25 #include <unotools/linguprops.hxx>
26 #include <unotools/lingucfg.hxx>
27 #include <com/sun/star/embed/EmbedStates.hpp>
28 #include <hintids.hxx>
29 #include <com/sun/star/util/XCloseable.hpp>
30 #include <sfx2/progress.hxx>
31 #include <svx/svdmodel.hxx>
32 #include <svx/svdpage.hxx>
33 #include <editeng/keepitem.hxx>
34 #include <editeng/ulspitem.hxx>
35 #include <editeng/lrspitem.hxx>
36 #include <editeng/boxitem.hxx>
37 #include <editeng/shaditem.hxx>
38 #include <editeng/protitem.hxx>
39 #include <editeng/opaqitem.hxx>
40 #include <editeng/prntitem.hxx>
41 #include <svx/fmglob.hxx>
42 #include <svx/svdouno.hxx>
43 #include <svx/fmpage.hxx>
44 #include <editeng/frmdiritem.hxx>
45 #include <swmodule.hxx>
46 #include <modcfg.hxx>
47 #include <com/sun/star/beans/XPropertySet.hpp>
48 #include <rtl/logfile.hxx>
49 #include <SwStyleNameMapper.hxx>
50 #include <fchrfmt.hxx>
51 #include <errhdl.hxx>
52 #include <frmatr.hxx>
53 #include <txatbase.hxx>
54 #include <fmtfld.hxx>
55 #include <fmtornt.hxx>
56 #include <fmtcntnt.hxx>
57 #include <fmtanchr.hxx>
58 #include <fmtfsize.hxx>
59 #include <fmtsrnd.hxx>
60 #include <fmtflcnt.hxx>
61 #include <fmtcnct.hxx>
62 #include <frmfmt.hxx>
63 #include <dcontact.hxx>
64 #include <txtflcnt.hxx>
65 #include <docfld.hxx>   // fuer Expression-Felder
66 #include <pam.hxx>
67 #include <ndtxt.hxx>
68 #include <ndnotxt.hxx>
69 #include <ndole.hxx>
70 #include <doc.hxx>
71 #include <IDocumentUndoRedo.hxx>
72 #include <rootfrm.hxx>
73 #include <pagefrm.hxx>
74 #include <cntfrm.hxx>
75 #include <flyfrm.hxx>
76 #include <fesh.hxx>
77 #include <docsh.hxx>
78 #include <dflyobj.hxx>
79 #include <dcontact.hxx>
80 #include <swundo.hxx>
81 #include <flypos.hxx>
82 #include <UndoInsert.hxx>
83 #include <expfld.hxx>       // InsertLabel
84 #include <poolfmt.hxx>      // PoolVorlagen-Id's
85 #include <docary.hxx>
86 #include <swtable.hxx>
87 #include <tblsel.hxx>
88 #include <viewopt.hxx>
89 #include <fldupde.hxx>
90 #include <txtftn.hxx>
91 #include <ftnidx.hxx>
92 #include <ftninfo.hxx>
93 #include <pagedesc.hxx>
94 #include <PostItMgr.hxx>
95 #include <comcore.hrc>      // STR-ResId's
96 #include <unoframe.hxx>
97 #include <sortedobjs.hxx>
98 #include <vector>
99 #include <drawdoc.hxx>
100 
101 using namespace ::com::sun::star;
102 using ::rtl::OUString;
103 
104 #define DEF_FLY_WIDTH    2268   //Defaultbreite fuer FlyFrms    (2268 == 4cm)
105 
106 /* #109161# */
lcl_IsItemSet(const SwCntntNode & rNode,sal_uInt16 which)107 static bool lcl_IsItemSet(const SwCntntNode & rNode, sal_uInt16 which)
108 {
109     bool bResult = false;
110 
111     if (SFX_ITEM_SET == rNode.GetSwAttrSet().GetItemState(which))
112         bResult = true;
113 
114     return bResult;
115 }
116 
117 /*************************************************************************
118 |*
119 |*  SwDoc::MakeLayoutFmt()
120 |*
121 |*  Beschreibung        Erzeugt ein neues Format das in seinen Einstellungen
122 |*      Defaultmaessig zu dem Request passt. Das Format wird in das
123 |*      entsprechende Formate-Array gestellt.
124 |*      Wenn bereits ein passendes Format existiert, so wird dies
125 |*      zurueckgeliefert.
126 |*  Ersterstellung      MA 22. Sep. 92
127 |*  Letzte Aenderung    JP 08.05.98
128 |*
129 |*************************************************************************/
130 
MakeLayoutFmt(RndStdIds eRequest,const SfxItemSet * pSet)131 SwFrmFmt *SwDoc::MakeLayoutFmt( RndStdIds eRequest, const SfxItemSet* pSet )
132 {
133     SwFrmFmt *pFmt = 0;
134     const sal_Bool bMod = IsModified();
135     sal_Bool bHeader = sal_False;
136 
137     switch ( eRequest )
138     {
139     case RND_STD_HEADER:
140     case RND_STD_HEADERL:
141     case RND_STD_HEADERR:
142         {
143             bHeader = sal_True;
144             // kein break, es geht unten weiter
145         }
146     case RND_STD_FOOTER:
147     case RND_STD_FOOTERL:
148     case RND_STD_FOOTERR:
149         {
150             pFmt = new SwFrmFmt( GetAttrPool(),
151                                  (bHeader ? "Header" : "Footer"),
152                                  GetDfltFrmFmt() );
153 
154             SwNodeIndex aTmpIdx( GetNodes().GetEndOfAutotext() );
155             SwStartNode* pSttNd =
156                 GetNodes().MakeTextSection
157                 ( aTmpIdx,
158                   bHeader ? SwHeaderStartNode : SwFooterStartNode,
159                   GetTxtCollFromPool(static_cast<sal_uInt16>( bHeader
160                                      ? ( eRequest == RND_STD_HEADERL
161                                          ? RES_POOLCOLL_HEADERL
162                                          : eRequest == RND_STD_HEADERR
163                                          ? RES_POOLCOLL_HEADERR
164                                          : RES_POOLCOLL_HEADER )
165                                      : ( eRequest == RND_STD_FOOTERL
166                                          ? RES_POOLCOLL_FOOTERL
167                                          : eRequest == RND_STD_FOOTERR
168                                          ? RES_POOLCOLL_FOOTERR
169                                          : RES_POOLCOLL_FOOTER )
170                                      ) ) );
171             pFmt->SetFmtAttr( SwFmtCntnt( pSttNd ));
172 
173             if( pSet )      // noch ein paar Attribute setzen ?
174                 pFmt->SetFmtAttr( *pSet );
175 
176             // JP: warum zuruecksetzen ???  Doc. ist doch veraendert ???
177             // bei den Fly auf jedenfall verkehrt !!
178             if ( !bMod )
179                 ResetModified();
180         }
181         break;
182 
183     case RND_DRAW_OBJECT:
184         {
185             pFmt = MakeDrawFrmFmt( aEmptyStr, GetDfltFrmFmt() );
186             if( pSet )      // noch ein paar Attribute setzen ?
187                 pFmt->SetFmtAttr( *pSet );
188 
189             if (GetIDocumentUndoRedo().DoesUndo())
190             {
191                 GetIDocumentUndoRedo().AppendUndo(
192                     new SwUndoInsLayFmt(pFmt, 0, 0));
193             }
194         }
195         break;
196 
197 #ifdef DBG_UTIL
198     case FLY_AT_PAGE:
199     case FLY_AT_CHAR:
200     case FLY_AT_FLY:
201     case FLY_AT_PARA:
202     case FLY_AS_CHAR:
203         ASSERT( false, "use new interface instead: SwDoc::MakeFlySection!" );
204         break;
205 #endif
206 
207     default:
208         ASSERT( sal_False,
209                 "Layout format requested with invalid request." );
210 
211     }
212     return pFmt;
213 }
214 /*************************************************************************
215 |*
216 |*  SwDoc::DelLayoutFmt()
217 |*
218 |*  Beschreibung        Loescht das angegebene Format, der Inhalt wird mit
219 |*      geloescht.
220 |*  Ersterstellung      MA 23. Sep. 92
221 |*  Letzte Aenderung    MA 05. Feb. 93
222 |*
223 |*************************************************************************/
224 
DelLayoutFmt(SwFrmFmt * pFmt)225 void SwDoc::DelLayoutFmt( SwFrmFmt *pFmt )
226 {
227     //Verkettung von Rahmen muss ggf. zusammengefuehrt werden.
228     //Bevor die Frames vernichtet werden, damit die Inhalte der Rahmen
229     //ggf. entsprechend gerichtet werden.
230     const SwFmtChain &rChain = pFmt->GetChain();
231     if ( rChain.GetPrev() )
232     {
233         SwFmtChain aChain( rChain.GetPrev()->GetChain() );
234         aChain.SetNext( rChain.GetNext() );
235         SetAttr( aChain, *rChain.GetPrev() );
236     }
237     if ( rChain.GetNext() )
238     {
239         SwFmtChain aChain( rChain.GetNext()->GetChain() );
240         aChain.SetPrev( rChain.GetPrev() );
241         SetAttr( aChain, *rChain.GetNext() );
242     }
243 
244     const SwNodeIndex* pCntIdx = pFmt->GetCntnt().GetCntntIdx();
245     if (pCntIdx && !GetIDocumentUndoRedo().DoesUndo())
246     {
247         //Verbindung abbauen, falls es sich um ein OLE-Objekt handelt.
248         SwOLENode* pOLENd = GetNodes()[ pCntIdx->GetIndex()+1 ]->GetOLENode();
249         if( pOLENd && pOLENd->GetOLEObj().IsOleRef() )
250         {
251             /*
252             SwDoc* pDoc = (SwDoc*)pFmt->GetDoc();
253             if( pDoc )
254             {
255                 SfxObjectShell* p = pDoc->GetPersist();
256                 if( p )     // muss da sein
257                 {
258                     SvInfoObjectRef aRef( p->Find( pOLENd->GetOLEObj().GetName() ) );
259                     if( aRef.Is() )
260                         aRef->SetObj(0);
261                 }
262             } */
263 
264             // TODO/MBA: the old object closed the object, cleared all references to it, but didn't remove it from the container.
265             // I have no idea, why, nobody could explain it - so I do my very best to mimic this behavior
266             //uno::Reference < util::XCloseable > xClose( pOLENd->GetOLEObj().GetOleRef(), uno::UNO_QUERY );
267             //if ( xClose.is() )
268             {
269                 try
270                 {
271                     pOLENd->GetOLEObj().GetOleRef()->changeState( embed::EmbedStates::LOADED );
272                 }
273                 catch ( uno::Exception& )
274                 {
275                 }
276             }
277 
278             //pOLENd->GetOLEObj().GetOleRef() = 0;
279         }
280     }
281 
282     //Frms vernichten.
283     pFmt->DelFrms();
284 
285     // erstmal sind nur Fly's Undofaehig
286     const sal_uInt16 nWh = pFmt->Which();
287     if (GetIDocumentUndoRedo().DoesUndo() &&
288         (RES_FLYFRMFMT == nWh || RES_DRAWFRMFMT == nWh))
289     {
290         GetIDocumentUndoRedo().AppendUndo( new SwUndoDelLayFmt( pFmt ));
291     }
292     else
293     {
294         // --> OD 2004-07-26 #i32089# - delete at-frame anchored objects
295         if ( nWh == RES_FLYFRMFMT )
296         {
297             // determine frame formats of at-frame anchored objects
298             const SwNodeIndex* pCntntIdx = pFmt->GetCntnt().GetCntntIdx();
299             if ( pCntntIdx )
300             {
301                 const SwSpzFrmFmts* pTbl = pFmt->GetDoc()->GetSpzFrmFmts();
302                 if ( pTbl )
303                 {
304                     std::vector<SwFrmFmt*> aToDeleteFrmFmts;
305                     const sal_uLong nNodeIdxOfFlyFmt( pCntntIdx->GetIndex() );
306 
307                     for ( sal_uInt16 i = 0; i < pTbl->Count(); ++i )
308                     {
309                         SwFrmFmt* pTmpFmt = (*pTbl)[i];
310                         const SwFmtAnchor &rAnch = pTmpFmt->GetAnchor();
311                         if ( rAnch.GetAnchorId() == FLY_AT_FLY &&
312                              rAnch.GetCntntAnchor()->nNode.GetIndex() == nNodeIdxOfFlyFmt )
313                         {
314                             aToDeleteFrmFmts.push_back( pTmpFmt );
315                         }
316                     }
317 
318                     // delete found frame formats
319                     while ( !aToDeleteFrmFmts.empty() )
320                     {
321                         SwFrmFmt* pTmpFmt = aToDeleteFrmFmts.back();
322                         pFmt->GetDoc()->DelLayoutFmt( pTmpFmt );
323 
324                         aToDeleteFrmFmts.pop_back();
325                     }
326                 }
327             }
328         }
329         // <--
330 
331         //Inhalt Loeschen.
332         if( pCntIdx )
333         {
334             SwNode *pNode = &pCntIdx->GetNode();
335             ((SwFmtCntnt&)pFmt->GetFmtAttr( RES_CNTNT )).SetNewCntntIdx( 0 );
336             DeleteSection( pNode );
337         }
338 
339         // ggfs. bei Zeichengebundenen Flys das Zeichen loeschen
340         const SwFmtAnchor& rAnchor = pFmt->GetAnchor();
341         if ((FLY_AS_CHAR == rAnchor.GetAnchorId()) && rAnchor.GetCntntAnchor())
342         {
343             const SwPosition* pPos = rAnchor.GetCntntAnchor();
344             SwTxtNode *pTxtNd = pPos->nNode.GetNode().GetTxtNode();
345 
346             // attribute is still in text node, delete it
347             if ( pTxtNd )
348             {
349                 SwTxtFlyCnt* const pAttr = static_cast<SwTxtFlyCnt*>(
350                     pTxtNd->GetTxtAttrForCharAt( pPos->nContent.GetIndex(),
351                         RES_TXTATR_FLYCNT ));
352                 if ( pAttr && (pAttr->GetFlyCnt().GetFrmFmt() == pFmt) )
353                 {
354                     // dont delete, set pointer to 0
355                     const_cast<SwFmtFlyCnt&>(pAttr->GetFlyCnt()).SetFlyFmt();
356                     SwIndex aIdx( pPos->nContent );
357                     pTxtNd->EraseText( aIdx, 1 );
358                 }
359             }
360         }
361 
362         DelFrmFmt( pFmt );
363     }
364     SetModified();
365 }
366 
367 /*************************************************************************
368 |*
369 |*  SwDoc::CopyLayoutFmt()
370 |*
371 |*  Beschreibung        Kopiert das angegebene Format pSrc in pDest und
372 |*                      returnt pDest. Wenn es noch kein pDest gibt, wird
373 |*                      eins angelegt.
374 |*                      JP: steht das Source Format in einem anderen
375 |*                          Dokument, so kopiere auch dann noch richtig !!
376 |*                          Vom chaos::Anchor-Attribut wird die Position immer
377 |*                          auf 0 gesetzt !!!
378 |*
379 |*  Ersterstellung      BP 18.12.92
380 |*  Letzte Aenderung    MA 17. Jul. 96
381 |*
382 |*************************************************************************/
383 
CopyLayoutFmt(const SwFrmFmt & rSource,const SwFmtAnchor & rNewAnchor,bool bSetTxtFlyAtt,bool bMakeFrms)384 SwFrmFmt *SwDoc::CopyLayoutFmt(
385     const SwFrmFmt& rSource,
386     const SwFmtAnchor& rNewAnchor,
387     bool bSetTxtFlyAtt,
388     bool bMakeFrms )
389 {
390     const bool bFly = RES_FLYFRMFMT == rSource.Which();
391     const bool bDraw = RES_DRAWFRMFMT == rSource.Which();
392     ASSERT( bFly || bDraw, "this method only works for fly or draw" );
393 
394     SwDoc* pSrcDoc = (SwDoc*)rSource.GetDoc();
395 
396     // #108784# may we copy this object?
397     // We may, unless it's 1) it's a control (and therfore a draw)
398     //                     2) anchored in a header/footer
399     //                     3) anchored (to paragraph?)
400     bool bMayNotCopy = false;
401     if( bDraw )
402     {
403         const SwDrawContact* pDrawContact =
404             static_cast<const SwDrawContact*>( rSource.FindContactObj() );
405 
406         bMayNotCopy =
407             ((FLY_AT_PARA == rNewAnchor.GetAnchorId()) ||
408              (FLY_AT_FLY  == rNewAnchor.GetAnchorId()) ||
409              (FLY_AT_CHAR == rNewAnchor.GetAnchorId())) &&
410             rNewAnchor.GetCntntAnchor() &&
411             IsInHeaderFooter( rNewAnchor.GetCntntAnchor()->nNode ) &&
412             pDrawContact != NULL  &&
413             pDrawContact->GetMaster() != NULL  &&
414             CheckControlLayer( pDrawContact->GetMaster() );
415     }
416 
417     // just return if we can't copy this
418     if( bMayNotCopy )
419         return NULL;
420 
421     SwFrmFmt* pDest = GetDfltFrmFmt();
422     if( rSource.GetRegisteredIn() != pSrcDoc->GetDfltFrmFmt() )
423         pDest = CopyFrmFmt( *(SwFrmFmt*)rSource.GetRegisteredIn() );
424     if( bFly )
425     {
426         // #i11176#
427         // To do a correct cloning concerning the ZOrder for all objects
428         // it is necessary to actually create a draw object for fly frames, too.
429         // These are then added to the DrawingLayer (which needs to exist).
430         // Together with correct sorting of all drawinglayer based objects
431         // before cloning ZOrder transfer works correctly then.
432         SwFlyFrmFmt *pFormat = MakeFlyFrmFmt( rSource.GetName(), pDest );
433         pDest = pFormat;
434 
435         SwXFrame::GetOrCreateSdrObject(pFormat);
436     }
437     else
438         pDest = MakeDrawFrmFmt( aEmptyStr, pDest );
439 
440     // alle anderen/neue Attribute kopieren.
441     pDest->CopyAttrs( rSource );
442 
443     //Chains werden nicht kopiert.
444     pDest->ResetFmtAttr( RES_CHAIN );
445 
446     if( bFly )
447     {
448         //Der Inhalt wird dupliziert.
449         const SwNode& rCSttNd = rSource.GetCntnt().GetCntntIdx()->GetNode();
450         SwNodeRange aRg( rCSttNd, 1, *rCSttNd.EndOfSectionNode() );
451 
452         SwNodeIndex aIdx( GetNodes().GetEndOfAutotext() );
453         SwStartNode* pSttNd = GetNodes().MakeEmptySection( aIdx, SwFlyStartNode );
454 
455         // erst den chaos::Anchor/CntntIndex setzen, innerhalb des Kopierens
456         // auf die Werte zugegriffen werden kann (DrawFmt in Kopf-/Fusszeilen)
457         aIdx = *pSttNd;
458         SwFmtCntnt aAttr( rSource.GetCntnt() );
459         aAttr.SetNewCntntIdx( &aIdx );
460         pDest->SetFmtAttr( aAttr );
461         pDest->SetFmtAttr( rNewAnchor );
462 
463         if( !mbCopyIsMove || this != pSrcDoc )
464         {
465             if( mbInReading )
466                 pDest->SetName( aEmptyStr );
467             else
468             {
469                 // Teste erstmal ob der Name schon vergeben ist.
470                 // Wenn ja -> neuen generieren
471                 sal_Int8 nNdTyp = aRg.aStart.GetNode().GetNodeType();
472 
473                 String sOld( pDest->GetName() );
474                 pDest->SetName( aEmptyStr );
475                 if( FindFlyByName( sOld, nNdTyp ) )     // einen gefunden
476                     switch( nNdTyp )
477                     {
478                     case ND_GRFNODE:    sOld = GetUniqueGrfName();      break;
479                     case ND_OLENODE:    sOld = GetUniqueOLEName();      break;
480                     default:            sOld = GetUniqueFrameName();    break;
481                     }
482 
483                 pDest->SetName( sOld );
484             }
485         }
486 
487         if (GetIDocumentUndoRedo().DoesUndo())
488         {
489             GetIDocumentUndoRedo().AppendUndo(new SwUndoInsLayFmt(pDest,0,0));
490         }
491 
492         // sorge dafuer das auch Fly's in Fly's kopiert werden
493         aIdx = *pSttNd->EndOfSectionNode();
494         pSrcDoc->CopyWithFlyInFly( aRg, 0, aIdx, NULL, sal_False, sal_True, sal_True );
495     }
496     else
497     {
498         ASSERT( RES_DRAWFRMFMT == rSource.Which(), "Weder Fly noch Draw." );
499         // OD 2005-08-02 #i52780# - Note: moving object to visible layer not needed.
500         SwDrawContact* pSourceContact = (SwDrawContact *)rSource.FindContactObj();
501 
502         SwDrawContact* pContact = new SwDrawContact( (SwDrawFrmFmt*)pDest,
503                                 CloneSdrObj( *pSourceContact->GetMaster(),
504                                         mbCopyIsMove && this == pSrcDoc ) );
505         // --> OD 2005-05-23 #i49730# - notify draw frame format
506         // that position attributes are already set, if the position attributes
507         // are already set at the source draw frame format.
508         if ( pDest->ISA(SwDrawFrmFmt) &&
509              rSource.ISA(SwDrawFrmFmt) &&
510              static_cast<const SwDrawFrmFmt&>(rSource).IsPosAttrSet() )
511         {
512             static_cast<SwDrawFrmFmt*>(pDest)->PosAttrSet();
513         }
514         // <--
515 
516         if( pDest->GetAnchor() == rNewAnchor )
517         {
518             // OD 03.07.2003 #108784# - do *not* connect to layout, if
519             // a <MakeFrms> will not be called.
520             if ( bMakeFrms )
521             {
522                 pContact->ConnectToLayout( &rNewAnchor );
523             }
524         }
525         else
526             pDest->SetFmtAttr( rNewAnchor );
527 
528         if (GetIDocumentUndoRedo().DoesUndo())
529         {
530             GetIDocumentUndoRedo().AppendUndo(new SwUndoInsLayFmt(pDest,0,0));
531         }
532     }
533 
534     if (bSetTxtFlyAtt && (FLY_AS_CHAR == rNewAnchor.GetAnchorId()))
535     {
536         const SwPosition* pPos = rNewAnchor.GetCntntAnchor();
537         SwFmtFlyCnt aFmt( pDest );
538         pPos->nNode.GetNode().GetTxtNode()->InsertItem(
539             aFmt, pPos->nContent.GetIndex(), 0 );
540     }
541 
542     if( bMakeFrms )
543         pDest->MakeFrms();
544 
545     return pDest;
546 }
547 
CloneSdrObj(const SdrObject & rObj,sal_Bool bMoveWithinDoc,sal_Bool bInsInPage)548 SdrObject* SwDoc::CloneSdrObj( const SdrObject& rObj, sal_Bool bMoveWithinDoc,
549                                 sal_Bool bInsInPage )
550 {
551     // --> OD 2005-08-08 #i52858# - method name changed
552     SdrPage *pPg = GetOrCreateDrawModel()->GetPage( 0 );
553     // <--
554     if( !pPg )
555     {
556         pPg = GetDrawModel()->AllocPage( sal_False );
557         GetDrawModel()->InsertPage( pPg );
558     }
559 
560     SdrObject *pObj = rObj.Clone();
561     if( bMoveWithinDoc && FmFormInventor == pObj->GetObjInventor() )
562     {
563         // bei Controls muss der Name erhalten bleiben
564         uno::Reference< awt::XControlModel >  xModel = ((SdrUnoObj*)pObj)->GetUnoControlModel();
565         uno::Any aVal;
566         uno::Reference< beans::XPropertySet >  xSet(xModel, uno::UNO_QUERY);
567         OUString sName( rtl::OUString::createFromAscii("Name") );
568         if( xSet.is() )
569             aVal = xSet->getPropertyValue( sName );
570         if( bInsInPage )
571             pPg->InsertObject( pObj );
572         if( xSet.is() )
573             xSet->setPropertyValue( sName, aVal );
574     }
575     else if( bInsInPage )
576         pPg->InsertObject( pObj );
577 
578     // OD 02.07.2003 #108784# - for drawing objects: set layer of cloned object
579     // to invisible layer
580     SdrLayerID nLayerIdForClone = rObj.GetLayer();
581     if ( !pObj->ISA(SwFlyDrawObj) &&
582          !pObj->ISA(SwVirtFlyDrawObj) &&
583          !IS_TYPE(SdrObject,pObj) )
584     {
585         if ( IsVisibleLayerId( nLayerIdForClone ) )
586         {
587             nLayerIdForClone = GetInvisibleLayerIdByVisibleOne( nLayerIdForClone );
588         }
589     }
590     pObj->SetLayer( nLayerIdForClone );
591 
592 
593     return pObj;
594 }
595 
_MakeFlySection(const SwPosition & rAnchPos,const SwCntntNode & rNode,RndStdIds eRequestId,const SfxItemSet * pFlySet,SwFrmFmt * pFrmFmt)596 SwFlyFrmFmt* SwDoc::_MakeFlySection( const SwPosition& rAnchPos,
597                                     const SwCntntNode& rNode,
598                                     RndStdIds eRequestId,
599                                     const SfxItemSet* pFlySet,
600                                     SwFrmFmt* pFrmFmt )
601 {
602     if( !pFrmFmt )
603         pFrmFmt = GetFrmFmtFromPool( RES_POOLFRM_FRAME );
604 
605     String sName;
606     if( !mbInReading )
607         switch( rNode.GetNodeType() )
608         {
609         case ND_GRFNODE:        sName = GetUniqueGrfName();     break;
610         case ND_OLENODE:        sName = GetUniqueOLEName();     break;
611         default:                sName = GetUniqueFrameName();       break;
612         }
613     SwFlyFrmFmt* pFmt = MakeFlyFrmFmt( sName, pFrmFmt );
614 
615     //Inhalt erzeugen und mit dem Format verbinden.
616     //CntntNode erzeugen und in die Autotextsection stellen
617     SwNodeRange aRange( GetNodes().GetEndOfAutotext(), -1,
618                         GetNodes().GetEndOfAutotext() );
619     GetNodes().SectionDown( &aRange, SwFlyStartNode );
620 
621     pFmt->SetFmtAttr( SwFmtCntnt( rNode.StartOfSectionNode() ));
622 
623 
624     const SwFmtAnchor* pAnchor = 0;
625     if( pFlySet )
626     {
627         pFlySet->GetItemState( RES_ANCHOR, sal_False,
628                                 (const SfxPoolItem**)&pAnchor );
629         if( SFX_ITEM_SET == pFlySet->GetItemState( RES_CNTNT, sal_False ))
630         {
631             SfxItemSet aTmpSet( *pFlySet );
632             aTmpSet.ClearItem( RES_CNTNT );
633             pFmt->SetFmtAttr( aTmpSet );
634         }
635         else
636             pFmt->SetFmtAttr( *pFlySet );
637     }
638 
639     // Anker noch nicht gesetzt ?
640     RndStdIds eAnchorId = pAnchor ? pAnchor->GetAnchorId()
641                                   : pFmt->GetAnchor().GetAnchorId();
642     // --> OD 2010-01-07 #i107811#
643     // Assure that at-page anchored fly frames have a page num or a content anchor set.
644     if ( !pAnchor ||
645          ( FLY_AT_PAGE != pAnchor->GetAnchorId() &&
646            !pAnchor->GetCntntAnchor() ) ||
647          ( FLY_AT_PAGE == pAnchor->GetAnchorId() &&
648            !pAnchor->GetCntntAnchor() &&
649            pAnchor->GetPageNum() == 0 ) )
650     {
651         // dann setze ihn, wird im Undo gebraucht
652         SwFmtAnchor aAnch( pFmt->GetAnchor() );
653         if (pAnchor && (FLY_AT_FLY == pAnchor->GetAnchorId()))
654         {
655             SwPosition aPos( *rAnchPos.nNode.GetNode().FindFlyStartNode() );
656             aAnch.SetAnchor( &aPos );
657             eAnchorId = FLY_AT_FLY;
658         }
659         else
660         {
661             if( eRequestId != aAnch.GetAnchorId() &&
662                 SFX_ITEM_SET != pFmt->GetItemState( RES_ANCHOR, sal_True ) )
663             {
664                 aAnch.SetType( eRequestId );
665             }
666 
667             eAnchorId = aAnch.GetAnchorId();
668             if ( FLY_AT_PAGE != eAnchorId ||
669                  ( FLY_AT_PAGE == eAnchorId &&
670                    ( !pAnchor ||
671                      aAnch.GetPageNum() == 0 ) ) )
672             {
673                 aAnch.SetAnchor( &rAnchPos );
674             }
675         }
676         // <--
677         pFmt->SetFmtAttr( aAnch );
678     }
679     else
680         eAnchorId = pFmt->GetAnchor().GetAnchorId();
681 
682     if ( FLY_AS_CHAR == eAnchorId )
683     {
684         xub_StrLen nStt = rAnchPos.nContent.GetIndex();
685         SwTxtNode * pTxtNode = rAnchPos.nNode.GetNode().GetTxtNode();
686 
687         ASSERT(pTxtNode!= 0, "There should be a SwTxtNode!");
688 
689         if (pTxtNode != NULL)
690         {
691             SwFmtFlyCnt aFmt( pFmt );
692             pTxtNode->InsertItem( aFmt, nStt, nStt );
693         }
694     }
695 
696     if( SFX_ITEM_SET != pFmt->GetAttrSet().GetItemState( RES_FRM_SIZE ))
697     {
698         SwFmtFrmSize aFmtSize( ATT_VAR_SIZE, 0, DEF_FLY_WIDTH );
699         const SwNoTxtNode* pNoTxtNode = rNode.GetNoTxtNode();
700         if( pNoTxtNode )
701         {
702             //Groesse einstellen.
703             Size aSize( pNoTxtNode->GetTwipSize() );
704             if( MINFLY > aSize.Width() )
705                 aSize.Width() = DEF_FLY_WIDTH;
706             aFmtSize.SetWidth( aSize.Width() );
707             if( aSize.Height() )
708             {
709                 aFmtSize.SetHeight( aSize.Height() );
710                 aFmtSize.SetHeightSizeType( ATT_FIX_SIZE );
711             }
712         }
713         pFmt->SetFmtAttr( aFmtSize );
714     }
715 
716     // Frames anlegen
717     if( GetCurrentViewShell() )
718         pFmt->MakeFrms();           // ???  //swmod 071108//swmod 071225
719 
720     if (GetIDocumentUndoRedo().DoesUndo())
721     {
722         sal_uLong nNodeIdx = rAnchPos.nNode.GetIndex();
723         xub_StrLen nCntIdx = rAnchPos.nContent.GetIndex();
724         GetIDocumentUndoRedo().AppendUndo(
725             new SwUndoInsLayFmt( pFmt, nNodeIdx, nCntIdx ));
726     }
727 
728     SetModified();
729     return pFmt;
730 }
731 
MakeFlySection(RndStdIds eAnchorType,const SwPosition * pAnchorPos,const SfxItemSet * pFlySet,SwFrmFmt * pFrmFmt,sal_Bool bCalledFromShell)732 SwFlyFrmFmt* SwDoc::MakeFlySection( RndStdIds eAnchorType,
733                                     const SwPosition* pAnchorPos,
734                                     const SfxItemSet* pFlySet,
735                                     SwFrmFmt* pFrmFmt, sal_Bool bCalledFromShell )
736 {
737     SwFlyFrmFmt* pFmt = 0;
738     sal_Bool bCallMake = sal_True;
739     if ( !pAnchorPos && (FLY_AT_PAGE != eAnchorType) )
740     {
741         const SwFmtAnchor* pAnch;
742         if( (pFlySet && SFX_ITEM_SET == pFlySet->GetItemState(
743                 RES_ANCHOR, sal_False, (const SfxPoolItem**)&pAnch )) ||
744             ( pFrmFmt && SFX_ITEM_SET == pFrmFmt->GetItemState(
745                 RES_ANCHOR, sal_True, (const SfxPoolItem**)&pAnch )) )
746         {
747             if ( (FLY_AT_PAGE != pAnch->GetAnchorId()) )
748             {
749                 pAnchorPos = pAnch->GetCntntAnchor();
750                 if (pAnchorPos)
751                 {
752                     bCallMake = sal_False;
753                 }
754             }
755         }
756     }
757 
758     if( bCallMake )
759     {
760         if( !pFrmFmt )
761             pFrmFmt = GetFrmFmtFromPool( RES_POOLFRM_FRAME );
762 
763         sal_uInt16 nCollId = static_cast<sal_uInt16>(
764             get(IDocumentSettingAccess::HTML_MODE) ? RES_POOLCOLL_TEXT : RES_POOLCOLL_FRAME );
765 
766         /* #109161# If there exists no adjust item in the paragraph
767             style for the content node of the new fly section
768             propagate an existing adjust item at the anchor to the new
769             content node. */
770         SwCntntNode * pNewTxtNd = GetNodes().MakeTxtNode
771             (SwNodeIndex( GetNodes().GetEndOfAutotext()),
772              GetTxtCollFromPool( nCollId ));
773         SwCntntNode * pAnchorNode = pAnchorPos->nNode.GetNode().GetCntntNode();
774 
775         const SfxPoolItem * pItem = NULL;
776 
777         if (bCalledFromShell && !lcl_IsItemSet(*pNewTxtNd, RES_PARATR_ADJUST) &&
778             SFX_ITEM_SET == pAnchorNode->GetSwAttrSet().
779             GetItemState(RES_PARATR_ADJUST, sal_True, &pItem))
780             static_cast<SwCntntNode *>(pNewTxtNd)->SetAttr(*pItem);
781 
782         pFmt = _MakeFlySection( *pAnchorPos, *pNewTxtNd,
783                                 eAnchorType, pFlySet, pFrmFmt );
784     }
785     return pFmt;
786 }
787 
MakeFlyAndMove(const SwPaM & rPam,const SfxItemSet & rSet,const SwSelBoxes * pSelBoxes,SwFrmFmt * pParent)788 SwFlyFrmFmt* SwDoc::MakeFlyAndMove( const SwPaM& rPam, const SfxItemSet& rSet,
789                                     const SwSelBoxes* pSelBoxes,
790                                     SwFrmFmt *pParent )
791 {
792     SwFmtAnchor& rAnch = (SwFmtAnchor&)rSet.Get( RES_ANCHOR );
793 
794     GetIDocumentUndoRedo().StartUndo( UNDO_INSLAYFMT, NULL );
795 
796     SwFlyFrmFmt* pFmt = MakeFlySection( rAnch.GetAnchorId(), rPam.GetPoint(),
797                                         &rSet, pParent );
798 
799     // Wenn Inhalt selektiert ist, so wird dieser jetzt zum Inhalt des
800     // neuen Rahmen. Sprich er wird in die entspr. Sektion des NodesArr
801     //gemoved.
802 
803     if( pFmt )
804     {
805         do {        // middle check loop
806             const SwFmtCntnt &rCntnt = pFmt->GetCntnt();
807             ASSERT( rCntnt.GetCntntIdx(), "Kein Inhalt vorbereitet." );
808             SwNodeIndex aIndex( *(rCntnt.GetCntntIdx()), 1 );
809             SwCntntNode *pNode = aIndex.GetNode().GetCntntNode();
810 
811             // ACHTUNG: nicht einen Index auf dem Stack erzeugen, sonst
812             //          kann der CntntnNode am Ende nicht geloscht werden !!
813             SwPosition aPos( aIndex );
814             aPos.nContent.Assign( pNode, 0 );
815 
816             if( pSelBoxes && pSelBoxes->Count() )
817             {
818                 // Tabellenselection
819                 // kopiere Teile aus einer Tabelle: lege eine Tabelle mit der
820                 // Breite der Originalen an und move (kopiere/loesche) die
821                 // selektierten Boxen. Die Groessen werden prozentual
822                 // korrigiert.
823 
824                 SwTableNode* pTblNd = (SwTableNode*)(*pSelBoxes)[0]->
825                                                 GetSttNd()->FindTableNode();
826                 if( !pTblNd )
827                     break;
828 
829                 SwTable& rTbl = pTblNd->GetTable();
830 
831                 // ist die gesamte Tabelle selektiert ?
832                 if( pSelBoxes->Count() == rTbl.GetTabSortBoxes().Count() )
833                 {
834                     // verschiebe die gesamte Tabelle
835                     SwNodeRange aRg( *pTblNd, 0, *pTblNd->EndOfSectionNode(), 1 );
836 
837                     // wird die gesamte Tabelle verschoben und steht diese
838                     // in einem FlyFrame, dann erzeuge dahinter einen neuen
839                     // TextNode. Dadurch bleibt dieser Fly erhalten !
840                     if( aRg.aEnd.GetNode().IsEndNode() )
841                         GetNodes().MakeTxtNode( aRg.aStart,
842                                     (SwTxtFmtColl*)GetDfltTxtFmtColl() );
843 
844                     MoveNodeRange( aRg, aPos.nNode, DOC_MOVEDEFAULT );
845                 }
846                 else
847                 {
848                     rTbl.MakeCopy( this, aPos, *pSelBoxes );
849                     // Don't delete a part of a table with row span!!
850                     // You could delete the content instead -> ToDo
851                     //rTbl.DeleteSel( this, *pSelBoxes, 0, 0, sal_True, sal_True );
852                 }
853 
854                 // wenn Tabelle im Rahmen, dann ohne nachfolgenden TextNode
855                 aIndex = rCntnt.GetCntntIdx()->GetNode().EndOfSectionIndex() - 1;
856                 ASSERT( aIndex.GetNode().GetTxtNode(),
857                         "hier sollte ein TextNode stehen" );
858                 aPos.nContent.Assign( 0, 0 );       // Index abmelden !!
859                 GetNodes().Delete( aIndex, 1 );
860 
861 //JP erstmal ein Hack, solange keine Flys/Headers/Footers Undofaehig sind
862 // werden erstmal alle Undo - Objecte geloescht.
863 if( GetIDocumentUndoRedo().DoesUndo() )
864 {
865     GetIDocumentUndoRedo().DelAllUndoObj();
866 }
867 
868             }
869             else
870             {
871 /*
872                 // alle Pams verschieben
873                 SwPaM* pTmp = (SwPaM*)&rPam;
874                 do {
875                     if( pTmp->HasMark() &&
876                         *pTmp->GetPoint() != *pTmp->GetMark() )
877                         MoveAndJoin( *pTmp, aPos );
878                 } while( &rPam != ( pTmp = (SwPaM*)pTmp->GetNext() ) );
879 */
880                 // copy all Pams and then delete all
881                 SwPaM* pTmp = (SwPaM*)&rPam;
882                 sal_Bool bOldFlag = mbCopyIsMove;
883                 bool const bOldUndo = GetIDocumentUndoRedo().DoesUndo();
884                 mbCopyIsMove = sal_True;
885                 GetIDocumentUndoRedo().DoUndo(false);
886                 do {
887                     if( pTmp->HasMark() &&
888                         *pTmp->GetPoint() != *pTmp->GetMark() )
889                     {
890                         CopyRange( *pTmp, aPos, false );
891                     }
892                     pTmp = static_cast<SwPaM*>(pTmp->GetNext());
893                 } while ( &rPam != pTmp );
894                 mbCopyIsMove = bOldFlag;
895                 GetIDocumentUndoRedo().DoUndo(bOldUndo);
896 
897                 pTmp = (SwPaM*)&rPam;
898                 do {
899                     if( pTmp->HasMark() &&
900                         *pTmp->GetPoint() != *pTmp->GetMark() )
901                     {
902                         DeleteAndJoin( *pTmp );
903                     }
904                     pTmp = static_cast<SwPaM*>(pTmp->GetNext());
905                 } while ( &rPam != pTmp );
906             }
907         } while( sal_False );
908     }
909 
910     SetModified();
911 
912     GetIDocumentUndoRedo().EndUndo( UNDO_INSLAYFMT, NULL );
913 
914     return pFmt;
915 }
916 
917 
918 // Insert drawing object, which has to be already inserted in the DrawModel
InsertDrawObj(const SwPaM & rRg,SdrObject & rDrawObj,const SfxItemSet & rFlyAttrSet)919 SwDrawFrmFmt* SwDoc::InsertDrawObj(
920     const SwPaM &rRg,
921     SdrObject& rDrawObj,
922     const SfxItemSet& rFlyAttrSet )
923 {
924     SwDrawFrmFmt* pFmt = MakeDrawFrmFmt( aEmptyStr, GetDfltFrmFmt() );
925 
926     const SwFmtAnchor* pAnchor = 0;
927     rFlyAttrSet.GetItemState( RES_ANCHOR, sal_False, (const SfxPoolItem**) &pAnchor );
928     pFmt->SetFmtAttr( rFlyAttrSet );
929 
930     RndStdIds eAnchorId = pAnchor != NULL ? pAnchor->GetAnchorId() : pFmt->GetAnchor().GetAnchorId();
931     const bool bIsAtCntnt = (FLY_AT_PAGE != eAnchorId);
932 
933     const SwNodeIndex* pChkIdx = 0;
934     if ( pAnchor == NULL )
935     {
936         pChkIdx = &rRg.GetPoint()->nNode;
937     }
938     else if ( bIsAtCntnt )
939     {
940         pChkIdx =
941             pAnchor->GetCntntAnchor() ? &pAnchor->GetCntntAnchor()->nNode : &rRg.GetPoint()->nNode;
942     }
943 
944     // allow drawing objects in header/footer, but control objects aren't allowed in header/footer.
945     if( pChkIdx != NULL
946         && ::CheckControlLayer( &rDrawObj )
947         && IsInHeaderFooter( *pChkIdx ) )
948     {
949         // apply at-page anchor format
950         eAnchorId = FLY_AT_PAGE;
951         pFmt->SetFmtAttr( SwFmtAnchor( eAnchorId ) );
952     }
953     else if( pAnchor == NULL
954              || ( bIsAtCntnt
955                   && pAnchor->GetCntntAnchor() == NULL ) )
956     {
957         // apply anchor format
958         SwFmtAnchor aAnch( pAnchor != NULL ? *pAnchor : pFmt->GetAnchor() );
959         eAnchorId = aAnch.GetAnchorId();
960         if ( eAnchorId == FLY_AT_FLY )
961         {
962             SwPosition aPos( *rRg.GetNode()->FindFlyStartNode() );
963             aAnch.SetAnchor( &aPos );
964         }
965         else
966         {
967             aAnch.SetAnchor( rRg.GetPoint() );
968             if ( eAnchorId == FLY_AT_PAGE )
969             {
970                 eAnchorId = rDrawObj.ISA( SdrUnoObj ) ? FLY_AS_CHAR : FLY_AT_PARA;
971                 aAnch.SetType( eAnchorId );
972             }
973         }
974         pFmt->SetFmtAttr( aAnch );
975     }
976 
977     // insert text attribute for as-character anchored drawing object
978     if ( eAnchorId == FLY_AS_CHAR )
979     {
980         bool bAnchorAtPageAsFallback = true;
981         const SwFmtAnchor& rDrawObjAnchorFmt = pFmt->GetAnchor();
982         if ( rDrawObjAnchorFmt.GetCntntAnchor() != NULL )
983         {
984             SwTxtNode* pAnchorTxtNode =
985                     rDrawObjAnchorFmt.GetCntntAnchor()->nNode.GetNode().GetTxtNode();
986             if ( pAnchorTxtNode != NULL )
987             {
988                 const xub_StrLen nStt = rDrawObjAnchorFmt.GetCntntAnchor()->nContent.GetIndex();
989                 SwFmtFlyCnt aFmt( pFmt );
990                 pAnchorTxtNode->InsertItem( aFmt, nStt, nStt );
991                 bAnchorAtPageAsFallback = false;
992             }
993         }
994 
995         if ( bAnchorAtPageAsFallback )
996         {
997             ASSERT( false, "SwDoc::InsertDrawObj(..) - missing content anchor for as-character anchored drawing object --> anchor at-page" );
998             pFmt->SetFmtAttr( SwFmtAnchor( FLY_AT_PAGE ) );
999         }
1000     }
1001 
1002     SwDrawContact* pContact = new SwDrawContact( pFmt, &rDrawObj );
1003 
1004     if ( GetCurrentViewShell() )
1005     {
1006         // create layout representation
1007         pFmt->MakeFrms();
1008         if ( pContact->GetAnchorFrm() )
1009         {
1010             pContact->MoveObjToVisibleLayer( &rDrawObj );
1011         }
1012     }
1013 
1014     if (GetIDocumentUndoRedo().DoesUndo())
1015     {
1016         GetIDocumentUndoRedo().AppendUndo( new SwUndoInsLayFmt(pFmt, 0, 0) );
1017     }
1018 
1019     SetModified();
1020     return pFmt;
1021 }
1022 
1023 /*************************************************************************
1024 |*
1025 |*  SwDoc::GetAllFlyFmts
1026 |*
1027 |*  Ersterstellung      MA 14. Jul. 93
1028 |*  Letzte Aenderung    MD 23. Feb. 95
1029 |*
1030 |*************************************************************************/
1031 
1032 /*sal_Bool TstFlyRange( const SwPaM* pPam, sal_uInt32 nFlyPos )
1033 {
1034     sal_Bool bOk = sal_False;
1035     const SwPaM* pTmp = pPam;
1036     do {
1037         bOk = pTmp->Start()->nNode.GetIndex() < nFlyPos &&
1038                 pTmp->End()->nNode.GetIndex() > nFlyPos;
1039     } while( !bOk && pPam != ( pTmp = (const SwPaM*)pTmp->GetNext() ));
1040     return bOk;
1041 }
1042 */
1043 /* -----------------------------04.04.00 10:55--------------------------------
1044     paragraph frames - o.k. if the PaM includes the paragraph from the beginning
1045                        to the beginning of the next paragraph at least
1046     frames at character - o.k. if the pam start at least at the same position
1047                         as the frame
1048  ---------------------------------------------------------------------------*/
TstFlyRange(const SwPaM * pPam,const SwPosition * pFlyPos,RndStdIds nAnchorId)1049 sal_Bool TstFlyRange( const SwPaM* pPam, const SwPosition* pFlyPos,
1050                         RndStdIds nAnchorId )
1051 {
1052     sal_Bool bOk = sal_False;
1053     const SwPaM* pTmp = pPam;
1054     do {
1055         const sal_uInt32 nFlyIndex = pFlyPos->nNode.GetIndex();
1056         const SwPosition* pPaMStart = pTmp->Start();
1057         const SwPosition* pPaMEnd = pTmp->End();
1058         const sal_uInt32 nPamStartIndex = pPaMStart->nNode.GetIndex();
1059         const sal_uInt32 nPamEndIndex = pPaMEnd->nNode.GetIndex();
1060         if (FLY_AT_PARA == nAnchorId)
1061             bOk = (nPamStartIndex < nFlyIndex && nPamEndIndex > nFlyIndex) ||
1062                (((nPamStartIndex == nFlyIndex) && (pPaMStart->nContent.GetIndex() == 0)) &&
1063                (nPamEndIndex > nFlyIndex));
1064         else
1065         {
1066             xub_StrLen nFlyContentIndex = pFlyPos->nContent.GetIndex();
1067             xub_StrLen nPamEndContentIndex = pPaMEnd->nContent.GetIndex();
1068             bOk = (nPamStartIndex < nFlyIndex &&
1069                 (( nPamEndIndex > nFlyIndex )||
1070                  ((nPamEndIndex == nFlyIndex) &&
1071                   (nPamEndContentIndex > nFlyContentIndex))) )
1072                 ||
1073                     (((nPamStartIndex == nFlyIndex) &&
1074                       (pPaMStart->nContent.GetIndex() <= nFlyContentIndex)) &&
1075                      ((nPamEndIndex > nFlyIndex) ||
1076                      (nPamEndContentIndex > nFlyContentIndex )));
1077         }
1078 
1079     } while( !bOk && pPam != ( pTmp = (const SwPaM*)pTmp->GetNext() ));
1080     return bOk;
1081 }
1082 
1083 
GetAllFlyFmts(const SwPaM * pCmpRange,sal_Bool bDrawAlso) const1084 SwPosFlyFrms SwDoc::GetAllFlyFmts( const SwPaM* pCmpRange, sal_Bool bDrawAlso ) const
1085 {
1086     SwPosFlyFrms aRetval;
1087     SwFrmFmt *pFly;
1088 
1089     // erstmal alle Absatzgebundenen einsammeln
1090     for( sal_uInt16 n = 0; n < GetSpzFrmFmts()->Count(); ++n )
1091     {
1092         pFly = (*GetSpzFrmFmts())[ n ];
1093         bool bDrawFmt = bDrawAlso ? RES_DRAWFRMFMT == pFly->Which() : false;
1094         bool bFlyFmt = RES_FLYFRMFMT == pFly->Which();
1095         if( bFlyFmt || bDrawFmt )
1096         {
1097             const SwFmtAnchor& rAnchor = pFly->GetAnchor();
1098             SwPosition const*const pAPos = rAnchor.GetCntntAnchor();
1099             if (pAPos &&
1100                 ((FLY_AT_PARA == rAnchor.GetAnchorId()) ||
1101                  (FLY_AT_FLY  == rAnchor.GetAnchorId()) ||
1102                  (FLY_AT_CHAR == rAnchor.GetAnchorId())))
1103             {
1104                 if( pCmpRange &&
1105                     !TstFlyRange( pCmpRange, pAPos, rAnchor.GetAnchorId() ))
1106                         continue;       // kein gueltiger FlyFrame
1107                 aRetval.insert(SwPosFlyFrmPtr(new SwPosFlyFrm(pAPos->nNode, pFly, aRetval.size())));
1108             }
1109         }
1110     }
1111 
1112     // kein Layout oder nur ein Teil, dann wars das
1113     // Seitenbezogen Flys nur, wenn vollstaendig "gewuenscht" wird !
1114     if( !GetCurrentViewShell() || pCmpRange )   //swmod 071108//swmod 071225
1115     {
1116         return aRetval;
1117     }
1118 
1119     SwPageFrm *pPage = (SwPageFrm*)GetCurrentLayout()->GetLower();  //swmod 080218
1120     while( pPage )
1121     {
1122         if( pPage->GetSortedObjs() )
1123         {
1124             SwSortedObjs &rObjs = *pPage->GetSortedObjs();
1125             for( sal_uInt16 i = 0; i < rObjs.Count(); ++i)
1126             {
1127                 SwAnchoredObject* pAnchoredObj = rObjs[i];
1128                 if ( pAnchoredObj->ISA(SwFlyFrm) )
1129                     pFly = &(pAnchoredObj->GetFrmFmt());
1130                 else if ( bDrawAlso )
1131                     pFly = &(pAnchoredObj->GetFrmFmt());
1132                 else
1133                     continue;
1134 
1135                 const SwFmtAnchor& rAnchor = pFly->GetAnchor();
1136                 if ((FLY_AT_PARA != rAnchor.GetAnchorId()) &&
1137                     (FLY_AT_FLY  != rAnchor.GetAnchorId()) &&
1138                     (FLY_AT_CHAR != rAnchor.GetAnchorId()))
1139                 {
1140                     const SwCntntFrm * pCntntFrm = pPage->FindFirstBodyCntnt();
1141                     if ( !pCntntFrm )
1142                     {
1143                         //Oops! Eine leere Seite. Damit der Rahmen nicht ganz
1144                         //verlorengeht (RTF) suchen wir schnell den letzen
1145                         //Cntnt der vor der Seite steht.
1146                         SwPageFrm *pPrv = (SwPageFrm*)pPage->GetPrev();
1147                         while ( !pCntntFrm && pPrv )
1148                         {
1149                             pCntntFrm = pPrv->FindFirstBodyCntnt();
1150                             pPrv = (SwPageFrm*)pPrv->GetPrev();
1151                         }
1152                     }
1153                     if ( pCntntFrm )
1154                     {
1155                         SwNodeIndex aIdx( *pCntntFrm->GetNode() );
1156                         aRetval.insert(SwPosFlyFrmPtr(new SwPosFlyFrm(aIdx, pFly, aRetval.size())));
1157                     }
1158                 }
1159             }
1160         }
1161         pPage = (SwPageFrm*)pPage->GetNext();
1162     }
1163 
1164     return aRetval;
1165 }
1166 
1167 /*************************************************************************
1168 |*
1169 |*  SwDoc::InsertLabel()
1170 |*
1171 |*  Ersterstellung      MA 11. Feb. 94
1172 |*  Letzte Aenderung    MA 12. Nov. 97
1173 |*
1174 |*************************************************************************/
1175 
1176 /* #i6447# changed behaviour if lcl_CpyAttr:
1177 
1178    If the old item set contains the item to set (no inheritance) copy the item
1179    into the new set.
1180 
1181    If the old item set contains the item by inheritance and the new set
1182    contains the item, too:
1183       If the two items differ copy the item from the old set to the new set.
1184 
1185    Otherwise the new set will not be changed.
1186 */
1187 
lcl_CpyAttr(SfxItemSet & rNewSet,const SfxItemSet & rOldSet,sal_uInt16 nWhich)1188 void lcl_CpyAttr( SfxItemSet &rNewSet, const SfxItemSet &rOldSet, sal_uInt16 nWhich )
1189 {
1190     const SfxPoolItem *pOldItem = NULL, *pNewItem = NULL;
1191 
1192     rOldSet.GetItemState( nWhich, sal_False, &pOldItem);
1193     if (pOldItem != NULL)
1194         rNewSet.Put( *pOldItem );
1195     else
1196     {
1197         pOldItem = rOldSet.GetItem( nWhich, sal_True);
1198         if (pOldItem != NULL)
1199         {
1200             pNewItem = rNewSet.GetItem( nWhich, sal_True);
1201             if (pNewItem != NULL)
1202             {
1203                 if (*pOldItem != *pNewItem)
1204                     rNewSet.Put( *pOldItem );
1205             }
1206             else {
1207                 ASSERT(0, "What am I doing here?");
1208             }
1209         }
1210         else {
1211             ASSERT(0, "What am I doing here?");
1212         }
1213     }
1214 
1215 }
1216 
1217 
1218 static SwFlyFrmFmt *
lcl_InsertLabel(SwDoc & rDoc,SwTxtFmtColls * const pTxtFmtCollTbl,SwUndoInsertLabel * const pUndo,SwLabelType const eType,String const & rTxt,String const & rSeparator,const String & rNumberingSeparator,const sal_Bool bBefore,const sal_uInt16 nId,const sal_uLong nNdIdx,const String & rCharacterStyle,const sal_Bool bCpyBrd)1219 lcl_InsertLabel(SwDoc & rDoc, SwTxtFmtColls *const pTxtFmtCollTbl,
1220         SwUndoInsertLabel *const pUndo,
1221         SwLabelType const eType, String const& rTxt, String const& rSeparator,
1222             const String& rNumberingSeparator,
1223             const sal_Bool bBefore, const sal_uInt16 nId, const sal_uLong nNdIdx,
1224             const String& rCharacterStyle,
1225             const sal_Bool bCpyBrd )
1226 {
1227     ::sw::UndoGuard const undoGuard(rDoc.GetIDocumentUndoRedo());
1228 
1229     sal_Bool bTable = sal_False;    //Um etwas Code zu sparen.
1230 
1231     //Erstmal das Feld bauen, weil ueber den Namen die TxtColl besorgt werden
1232     //muss
1233     OSL_ENSURE( nId == USHRT_MAX  || nId < rDoc.GetFldTypes()->Count(),
1234             "FldType index out of bounds." );
1235     SwFieldType *pType = (nId != USHRT_MAX) ? (*rDoc.GetFldTypes())[nId] : NULL;
1236     OSL_ENSURE(!pType || pType->Which() == RES_SETEXPFLD, "wrong Id for Label");
1237 
1238     SwTxtFmtColl * pColl = NULL;
1239     if( pType )
1240     {
1241         for( sal_uInt16 i = pTxtFmtCollTbl->Count(); i; )
1242         {
1243             if( (*pTxtFmtCollTbl)[ --i ]->GetName() == pType->GetName() )
1244             {
1245                 pColl = (*pTxtFmtCollTbl)[i];
1246                 break;
1247             }
1248         }
1249         DBG_ASSERT( pColl, "no text collection found" );
1250     }
1251 
1252     if( !pColl )
1253     {
1254         pColl = rDoc.GetTxtCollFromPool( RES_POOLCOLL_LABEL );
1255     }
1256 
1257     SwTxtNode *pNew = NULL;
1258     SwFlyFrmFmt* pNewFmt = NULL;
1259 
1260     switch ( eType )
1261     {
1262         case LTYPE_TABLE:
1263             bTable = sal_True;
1264             /* Kein Break hier */
1265         case LTYPE_FLY:
1266             //Am Anfang/Ende der Fly-Section den entsprechenden Node mit Feld
1267             //einfuegen (Frame wird automatisch erzeugt).
1268             {
1269                 SwStartNode *pSttNd = rDoc.GetNodes()[nNdIdx]->GetStartNode();
1270                 ASSERT( pSttNd, "Kein StartNode in InsertLabel." );
1271                 sal_uLong nNode;
1272                 if( bBefore )
1273                 {
1274                     nNode = pSttNd->GetIndex();
1275                     if( !bTable )
1276                         ++nNode;
1277                 }
1278                 else
1279                 {
1280                     nNode = pSttNd->EndOfSectionIndex();
1281                     if( bTable )
1282                         ++nNode;
1283                 }
1284 
1285                 if( pUndo )
1286                     pUndo->SetNodePos( nNode );
1287 
1288                 //Node fuer Beschriftungsabsatz erzeugen.
1289                 SwNodeIndex aIdx( rDoc.GetNodes(), nNode );
1290                 pNew = rDoc.GetNodes().MakeTxtNode( aIdx, pColl );
1291             }
1292             break;
1293 
1294         case LTYPE_OBJECT:
1295             {
1296                 //Rahmen zerstoeren, neuen Rahmen einfuegen, entsprechenden
1297                 // Node mit Feld in den neuen Rahmen, den alten Rahmen mit
1298                 // dem Object (Grafik/Ole) absatzgebunden in den neuen Rahmen,
1299                 // Frames erzeugen.
1300 
1301                 //Erstmal das Format zum Fly besorgen und das Layout entkoppeln.
1302                 SwFrmFmt *pOldFmt = rDoc.GetNodes()[nNdIdx]->GetFlyFmt();
1303                 ASSERT( pOldFmt, "Format des Fly nicht gefunden." );
1304                 // --> OD #i115719#
1305                 // <title> and <description> attributes are lost when calling <DelFrms()>.
1306                 // Thus, keep them and restore them after the calling <MakeFrms()>
1307                 const bool bIsSwFlyFrmFmtInstance( dynamic_cast<SwFlyFrmFmt*>(pOldFmt) != 0 );
1308                 const String sTitle( bIsSwFlyFrmFmtInstance
1309                                      ? static_cast<SwFlyFrmFmt*>(pOldFmt)->GetObjTitle()
1310                                      : String() );
1311                 const String sDescription( bIsSwFlyFrmFmtInstance
1312                                            ? static_cast<SwFlyFrmFmt*>(pOldFmt)->GetObjDescription()
1313                                            : String() );
1314                 const bool bDecorative( bIsSwFlyFrmFmtInstance
1315                                         && static_cast<SwFlyFrmFmt*>(pOldFmt)->IsObjDecorative() );
1316                 // <--
1317                 pOldFmt->DelFrms();
1318 
1319                 pNewFmt = rDoc.MakeFlyFrmFmt( rDoc.GetUniqueFrameName(),
1320                                 rDoc.GetFrmFmtFromPool(RES_POOLFRM_FRAME) );
1321 
1322                 /* #i6447#: Only the selected items are copied from the old
1323                    format. */
1324                 SfxItemSet* pNewSet = pNewFmt->GetAttrSet().Clone( sal_True );
1325 
1326 
1327                 //Diejenigen Attribute uebertragen die auch gesetzt sind,
1328                 //andere sollen weiterhin aus den Vorlagen gueltig werden.
1329                 lcl_CpyAttr( *pNewSet, pOldFmt->GetAttrSet(), RES_PRINT );
1330                 lcl_CpyAttr( *pNewSet, pOldFmt->GetAttrSet(), RES_OPAQUE );
1331                 lcl_CpyAttr( *pNewSet, pOldFmt->GetAttrSet(), RES_PROTECT );
1332                 lcl_CpyAttr( *pNewSet, pOldFmt->GetAttrSet(), RES_SURROUND );
1333                 lcl_CpyAttr( *pNewSet, pOldFmt->GetAttrSet(), RES_VERT_ORIENT );
1334                 lcl_CpyAttr( *pNewSet, pOldFmt->GetAttrSet(), RES_HORI_ORIENT );
1335                 lcl_CpyAttr( *pNewSet, pOldFmt->GetAttrSet(), RES_LR_SPACE );
1336                 lcl_CpyAttr( *pNewSet, pOldFmt->GetAttrSet(), RES_UL_SPACE );
1337                 lcl_CpyAttr( *pNewSet, pOldFmt->GetAttrSet(), RES_BACKGROUND );
1338                 if( bCpyBrd )
1339                 {
1340                     // JP 07.07.99: Bug 67029 - if at Grafik no BoxItem but
1341                     //              in the new Format is any, then set the
1342                     //              default item in the new Set. Because
1343                     //              the Size of the Grafik have never been
1344                     //              changed!
1345                     const SfxPoolItem *pItem;
1346                     if( SFX_ITEM_SET == pOldFmt->GetAttrSet().
1347                             GetItemState( RES_BOX, sal_True, &pItem ))
1348                         pNewSet->Put( *pItem );
1349                     else if( SFX_ITEM_SET == pNewFmt->GetAttrSet().
1350                             GetItemState( RES_BOX, sal_True ))
1351                         pNewSet->Put( *GetDfltAttr( RES_BOX ) );
1352 
1353                     if( SFX_ITEM_SET == pOldFmt->GetAttrSet().
1354                             GetItemState( RES_SHADOW, sal_True, &pItem ))
1355                         pNewSet->Put( *pItem );
1356                     else if( SFX_ITEM_SET == pNewFmt->GetAttrSet().
1357                             GetItemState( RES_SHADOW, sal_True ))
1358                         pNewSet->Put( *GetDfltAttr( RES_SHADOW ) );
1359                 }
1360                 else
1361                 {
1362                     //Die Attribute hart setzen, weil sie sonst aus der
1363                     // Vorlage kommen koenten und dann passt die
1364                     // Grossenberechnung nicht mehr.
1365                     pNewSet->Put( SvxBoxItem(RES_BOX) );
1366                     pNewSet->Put( SvxShadowItem(RES_SHADOW) );
1367 
1368                 }
1369 
1370                 //Anker immer uebertragen, ist sowieso ein hartes Attribut.
1371                 pNewSet->Put( pOldFmt->GetAnchor() );
1372 
1373                 //In der Hoehe soll der neue Varabel sein!
1374                 SwFmtFrmSize aFrmSize( pOldFmt->GetFrmSize() );
1375                 aFrmSize.SetHeightSizeType( ATT_MIN_SIZE );
1376                 pNewSet->Put( aFrmSize );
1377 
1378                 SwStartNode* pSttNd = rDoc.GetNodes().MakeTextSection(
1379                             SwNodeIndex( rDoc.GetNodes().GetEndOfAutotext() ),
1380                             SwFlyStartNode, pColl );
1381                 pNewSet->Put( SwFmtCntnt( pSttNd ));
1382 
1383                 pNewFmt->SetFmtAttr( *pNewSet );
1384 
1385                 //Bei InCntnt's wird es spannend: Das TxtAttribut muss
1386                 //vernichtet werden. Leider reisst dies neben den Frms auch
1387                 //noch das Format mit in sein Grab. Um dass zu unterbinden
1388                 //loesen wir vorher die Verbindung zwischen Attribut und Format.
1389 
1390                 const SwFmtAnchor& rAnchor = pNewFmt->GetAnchor();
1391                 if ( FLY_AS_CHAR == rAnchor.GetAnchorId() )
1392                 {
1393                     const SwPosition *pPos = rAnchor.GetCntntAnchor();
1394                     SwTxtNode *pTxtNode = pPos->nNode.GetNode().GetTxtNode();
1395                     ASSERT( pTxtNode->HasHints(), "Missing FlyInCnt-Hint." );
1396                     const xub_StrLen nIdx = pPos->nContent.GetIndex();
1397                     SwTxtAttr * const pHnt =
1398                         pTxtNode->GetTxtAttrForCharAt(nIdx, RES_TXTATR_FLYCNT);
1399 
1400                     ASSERT( pHnt && pHnt->Which() == RES_TXTATR_FLYCNT,
1401                                 "Missing FlyInCnt-Hint." );
1402                     ASSERT( pHnt && pHnt->GetFlyCnt().GetFrmFmt() == pOldFmt,
1403                                 "Wrong TxtFlyCnt-Hint." );
1404 
1405                     const_cast<SwFmtFlyCnt&>(pHnt->GetFlyCnt()).SetFlyFmt(
1406                             pNewFmt );
1407                 }
1408 
1409 
1410                 //Der Alte soll keinen Umlauf haben, und er soll oben/mittig
1411                 //ausgerichtet sein.
1412                 //Ausserdem soll die Breite 100% betragen und bei Aenderungen
1413                 //Die Hoehe mit anpassen.
1414                 pNewSet->ClearItem();
1415 
1416                 pNewSet->Put( SwFmtSurround( SURROUND_NONE ) );
1417                 pNewSet->Put( SvxOpaqueItem( RES_OPAQUE, sal_True ) );
1418                 pNewSet->Put( SwFmtVertOrient( 0, text::VertOrientation::TOP, text::RelOrientation::FRAME ) );
1419                 pNewSet->Put( SwFmtHoriOrient( 0, text::HoriOrientation::CENTER, text::RelOrientation::FRAME ) );
1420 
1421                 aFrmSize = pOldFmt->GetFrmSize();
1422                 aFrmSize.SetWidthPercent( 0 );
1423                 aFrmSize.SetHeightPercent( 255 );
1424                 pNewSet->Put( aFrmSize );
1425 
1426                 //Die Attribute setzen wir hart, weil sie sonst aus der Vorlage
1427                 //kommen koenten und dann passt die Grossenberechnung nicht mehr.
1428                 if( bCpyBrd )
1429                 {
1430                     pNewSet->Put( SvxBoxItem(RES_BOX) );
1431                     pNewSet->Put( SvxShadowItem(RES_SHADOW) );
1432                 }
1433                 pNewSet->Put( SvxLRSpaceItem(RES_LR_SPACE) );
1434                 pNewSet->Put( SvxULSpaceItem(RES_UL_SPACE) );
1435 
1436                 //Der Alte ist absatzgebunden, und zwar am Absatz im neuen.
1437                 SwFmtAnchor aAnch( FLY_AT_PARA );
1438                 SwNodeIndex aAnchIdx( *pNewFmt->GetCntnt().GetCntntIdx(), 1 );
1439                 pNew = aAnchIdx.GetNode().GetTxtNode();
1440                 SwPosition aPos( aAnchIdx );
1441                 aAnch.SetAnchor( &aPos );
1442                 pNewSet->Put( aAnch );
1443 
1444                 if( pUndo )
1445                     pUndo->SetFlys( *pOldFmt, *pNewSet, *pNewFmt );
1446                 else
1447                     pOldFmt->SetFmtAttr( *pNewSet );
1448 
1449                 delete pNewSet;
1450 
1451                 //Nun nur noch die Flys erzeugen lassen. Das ueberlassen
1452                 //wir vorhanden Methoden (insb. fuer InCntFlys etwas aufwendig).
1453                 pNewFmt->MakeFrms();
1454                 // --> OD #i115719#
1455                 if ( bIsSwFlyFrmFmtInstance )
1456                 {
1457                     static_cast<SwFlyFrmFmt*>(pOldFmt)->SetObjTitle( sTitle );
1458                     static_cast<SwFlyFrmFmt*>(pOldFmt)->SetObjDescription( sDescription );
1459                     static_cast<SwFlyFrmFmt*>(pOldFmt)->SetObjDecorative( bDecorative );
1460                 }
1461                 // <--
1462             }
1463             break;
1464 
1465         default:
1466             OSL_ENSURE(false, "unknown LabelType?");
1467     }
1468     ASSERT( pNew, "No Label inserted" );
1469     if( pNew )
1470     {
1471         //#i61007# order of captions
1472         sal_Bool bOrderNumberingFirst = SW_MOD()->GetModuleConfig()->IsCaptionOrderNumberingFirst();
1473         //String aufbereiten
1474         String aTxt;
1475         if( bOrderNumberingFirst )
1476         {
1477             aTxt = rNumberingSeparator;
1478         }
1479         if( pType)
1480         {
1481             aTxt += pType->GetName();
1482             if( !bOrderNumberingFirst )
1483                 aTxt += ' ';
1484         }
1485         xub_StrLen nIdx = aTxt.Len();
1486         if( rTxt.Len() > 0 )
1487         {
1488             aTxt += rSeparator;
1489         }
1490         xub_StrLen nSepIdx = aTxt.Len();
1491         aTxt += rTxt;
1492 
1493         //String einfuegen
1494         SwIndex aIdx( pNew, 0 );
1495         pNew->InsertText( aTxt, aIdx );
1496 
1497         //
1498         //Feld einfuegen
1499         if(pType)
1500         {
1501             SwSetExpField aFld( (SwSetExpFieldType*)pType, aEmptyStr, SVX_NUM_ARABIC);
1502             if( bOrderNumberingFirst )
1503                 nIdx = 0;
1504             SwFmtFld aFmt( aFld );
1505             pNew->InsertItem( aFmt, nIdx, nIdx );
1506             if(rCharacterStyle.Len())
1507             {
1508                 SwCharFmt* pCharFmt = rDoc.FindCharFmtByName(rCharacterStyle);
1509                 if( !pCharFmt )
1510                 {
1511                     const sal_uInt16 nMyId = SwStyleNameMapper::GetPoolIdFromUIName(rCharacterStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT);
1512                     pCharFmt = rDoc.GetCharFmtFromPool( nMyId );
1513                 }
1514                 if (pCharFmt)
1515                 {
1516                     SwFmtCharFmt aCharFmt( pCharFmt );
1517                     pNew->InsertItem( aCharFmt, 0,
1518                         nSepIdx + 1, nsSetAttrMode::SETATTR_DONTEXPAND );
1519                 }
1520             }
1521         }
1522 
1523         if ( bTable )
1524         {
1525             if ( bBefore )
1526             {
1527                 if ( !pNew->GetSwAttrSet().GetKeep().GetValue()  )
1528                     pNew->SetAttr( SvxFmtKeepItem( sal_True, RES_KEEP ) );
1529             }
1530             else
1531             {
1532                 SwTableNode *const pNd =
1533                     rDoc.GetNodes()[nNdIdx]->GetStartNode()->GetTableNode();
1534                 SwTable &rTbl = pNd->GetTable();
1535                 if ( !rTbl.GetFrmFmt()->GetKeep().GetValue() )
1536                     rTbl.GetFrmFmt()->SetFmtAttr( SvxFmtKeepItem( sal_True, RES_KEEP ) );
1537                 if ( pUndo )
1538                     pUndo->SetUndoKeep();
1539             }
1540         }
1541         rDoc.SetModified();
1542     }
1543 
1544     return pNewFmt;
1545 }
1546 
1547 SwFlyFrmFmt *
InsertLabel(SwLabelType const eType,String const & rTxt,String const & rSeparator,String const & rNumberingSeparator,sal_Bool const bBefore,sal_uInt16 const nId,sal_uLong const nNdIdx,String const & rCharacterStyle,sal_Bool const bCpyBrd)1548 SwDoc::InsertLabel(
1549         SwLabelType const eType, String const& rTxt, String const& rSeparator,
1550         String const& rNumberingSeparator,
1551         sal_Bool const bBefore, sal_uInt16 const nId, sal_uLong const nNdIdx,
1552         String const& rCharacterStyle,
1553         sal_Bool const bCpyBrd )
1554 {
1555     SwUndoInsertLabel * pUndo(0);
1556     if (GetIDocumentUndoRedo().DoesUndo())
1557     {
1558         pUndo = new SwUndoInsertLabel(
1559                         eType, rTxt, rSeparator, rNumberingSeparator,
1560                         bBefore, nId, rCharacterStyle, bCpyBrd );
1561     }
1562 
1563     SwFlyFrmFmt *const pNewFmt = lcl_InsertLabel(*this, pTxtFmtCollTbl, pUndo,
1564             eType, rTxt, rSeparator, rNumberingSeparator, bBefore,
1565             nId, nNdIdx, rCharacterStyle, bCpyBrd);
1566 
1567     if (pUndo)
1568     {
1569         GetIDocumentUndoRedo().AppendUndo(pUndo);
1570     }
1571     else
1572     {
1573         GetIDocumentUndoRedo().DelAllUndoObj();
1574     }
1575 
1576     return pNewFmt;
1577 }
1578 
1579 
1580 /*************************************************************************
1581 |*
1582 |*  SwDoc::InsertDrawLabel()
1583 |*
1584 |*  Ersterstellung      MIB 7. Dez. 98
1585 |*  Letzte Aenderung    MIB 7. Dez. 98
1586 |*
1587 |*************************************************************************/
1588 
1589 static SwFlyFrmFmt *
lcl_InsertDrawLabel(SwDoc & rDoc,SwTxtFmtColls * const pTxtFmtCollTbl,SwUndoInsertLabel * const pUndo,SwDrawFrmFmt * const pOldFmt,String const & rTxt,const String & rSeparator,const String & rNumberSeparator,const sal_uInt16 nId,const String & rCharacterStyle,SdrObject & rSdrObj)1590 lcl_InsertDrawLabel( SwDoc & rDoc, SwTxtFmtColls *const pTxtFmtCollTbl,
1591         SwUndoInsertLabel *const pUndo, SwDrawFrmFmt *const pOldFmt,
1592         String const& rTxt,
1593                                      const String& rSeparator,
1594                                      const String& rNumberSeparator,
1595                                      const sal_uInt16 nId,
1596                                      const String& rCharacterStyle,
1597                                      SdrObject& rSdrObj )
1598 {
1599     ::sw::UndoGuard const undoGuard(rDoc.GetIDocumentUndoRedo());
1600     ::sw::DrawUndoGuard const drawUndoGuard(rDoc.GetIDocumentUndoRedo());
1601 
1602     // Erstmal das Feld bauen, weil ueber den Namen die TxtColl besorgt
1603     // werden muss
1604     OSL_ENSURE( nId == USHRT_MAX  || nId < rDoc.GetFldTypes()->Count(),
1605             "FldType index out of bounds" );
1606     SwFieldType *pType = nId != USHRT_MAX ? (*rDoc.GetFldTypes())[nId] : 0;
1607     OSL_ENSURE( !pType || pType->Which() == RES_SETEXPFLD, "Wrong label id" );
1608 
1609     SwTxtFmtColl *pColl = NULL;
1610     if( pType )
1611     {
1612         for( sal_uInt16 i = pTxtFmtCollTbl->Count(); i; )
1613         {
1614             if( (*pTxtFmtCollTbl)[ --i ]->GetName() == pType->GetName() )
1615             {
1616                 pColl = (*pTxtFmtCollTbl)[i];
1617                 break;
1618             }
1619         }
1620         DBG_ASSERT( pColl, "no text collection found" );
1621     }
1622 
1623     if( !pColl )
1624     {
1625         pColl = rDoc.GetTxtCollFromPool( RES_POOLCOLL_LABEL );
1626     }
1627 
1628     SwTxtNode* pNew = NULL;
1629     SwFlyFrmFmt* pNewFmt = NULL;
1630 
1631     // Rahmen zerstoeren, neuen Rahmen einfuegen, entsprechenden
1632     // Node mit Feld in den neuen Rahmen, den alten Rahmen mit
1633     // dem Object (Grafik/Ole) absatzgebunden in den neuen Rahmen,
1634     // Frames erzeugen.
1635 
1636     // OD 27.11.2003 #112045# - Keep layer ID of drawing object before removing
1637     // its frames.
1638     // Note: The layer ID is passed to the undo and have to be the correct value.
1639     //       Removing the frames of the drawing object changes its layer.
1640     const SdrLayerID nLayerId = rSdrObj.GetLayer();
1641 
1642     pOldFmt->DelFrms();
1643 
1644     //Bei InCntnt's wird es spannend: Das TxtAttribut muss
1645     //vernichtet werden. Leider reisst dies neben den Frms auch
1646     //noch das Format mit in sein Grab. Um dass zu unterbinden
1647     //loesen wir vorher die Verbindung zwischen Attribut und Format.
1648     SfxItemSet* pNewSet = pOldFmt->GetAttrSet().Clone( sal_False );
1649 
1650     // Ggf. Groesse und Position des Rahmens schuetzen
1651     if ( rSdrObj.IsMoveProtect() || rSdrObj.IsResizeProtect() )
1652     {
1653         SvxProtectItem aProtect(RES_PROTECT);
1654         aProtect.SetCntntProtect( sal_False );
1655         aProtect.SetPosProtect( rSdrObj.IsMoveProtect() );
1656         aProtect.SetSizeProtect( rSdrObj.IsResizeProtect() );
1657         pNewSet->Put( aProtect );
1658     }
1659 
1660     // Umlauf uebernehmen
1661     lcl_CpyAttr( *pNewSet, pOldFmt->GetAttrSet(), RES_SURROUND );
1662 
1663     // Den Rahmen ggf. in den Hintergrund schicken.
1664     // OD 02.07.2003 #108784# - consider 'invisible' hell layer.
1665     if ( rDoc.GetHellId() != nLayerId &&
1666          rDoc.GetInvisibleHellId() != nLayerId )
1667     {
1668         SvxOpaqueItem aOpaque( RES_OPAQUE );
1669         aOpaque.SetValue( sal_True );
1670         pNewSet->Put( aOpaque );
1671     }
1672 
1673     // Position uebernehmen
1674     // OD 2004-04-15 #i26791# - use directly the positioning attributes of
1675     // the drawing object.
1676     pNewSet->Put( pOldFmt->GetHoriOrient() );
1677     pNewSet->Put( pOldFmt->GetVertOrient() );
1678 
1679     pNewSet->Put( pOldFmt->GetAnchor() );
1680 
1681     //In der Hoehe soll der neue Varabel sein!
1682     Size aSz( rSdrObj.GetCurrentBoundRect().GetSize() );
1683     SwFmtFrmSize aFrmSize( ATT_MIN_SIZE, aSz.Width(), aSz.Height() );
1684     pNewSet->Put( aFrmSize );
1685 
1686     // Abstaende auf den neuen Rahmen uebertragen. Eine Umrandung
1687     // gibt es beu Zeichen-Objekten nicht, also muss sie geloescht
1688     // werden.
1689     // MA: Falsch sie wird nicht gesetzt, denn die aus der Vorlage
1690     // soll ruhig wirksam werden
1691     pNewSet->Put( pOldFmt->GetLRSpace() );
1692     pNewSet->Put( pOldFmt->GetULSpace() );
1693 
1694     SwStartNode* pSttNd =
1695         rDoc.GetNodes().MakeTextSection(
1696             SwNodeIndex( rDoc.GetNodes().GetEndOfAutotext() ),
1697                                     SwFlyStartNode, pColl );
1698 
1699     pNewFmt = rDoc.MakeFlyFrmFmt( rDoc.GetUniqueFrameName(),
1700                  rDoc.GetFrmFmtFromPool( RES_POOLFRM_FRAME ) );
1701 
1702     // JP 28.10.99: Bug 69487 - set border and shadow to default if the
1703     //              template contains any.
1704     if( SFX_ITEM_SET == pNewFmt->GetAttrSet().GetItemState( RES_BOX, sal_True ))
1705         pNewSet->Put( *GetDfltAttr( RES_BOX ) );
1706 
1707     if( SFX_ITEM_SET == pNewFmt->GetAttrSet().GetItemState(RES_SHADOW,sal_True))
1708         pNewSet->Put( *GetDfltAttr( RES_SHADOW ) );
1709 
1710     pNewFmt->SetFmtAttr( SwFmtCntnt( pSttNd ));
1711     pNewFmt->SetFmtAttr( *pNewSet );
1712 
1713     const SwFmtAnchor& rAnchor = pNewFmt->GetAnchor();
1714     if ( FLY_AS_CHAR == rAnchor.GetAnchorId() )
1715     {
1716         const SwPosition *pPos = rAnchor.GetCntntAnchor();
1717         SwTxtNode *pTxtNode = pPos->nNode.GetNode().GetTxtNode();
1718         ASSERT( pTxtNode->HasHints(), "Missing FlyInCnt-Hint." );
1719         const xub_StrLen nIdx = pPos->nContent.GetIndex();
1720         SwTxtAttr * const pHnt =
1721             pTxtNode->GetTxtAttrForCharAt( nIdx, RES_TXTATR_FLYCNT );
1722 
1723 #ifdef DBG_UTIL
1724         ASSERT( pHnt && pHnt->Which() == RES_TXTATR_FLYCNT,
1725                     "Missing FlyInCnt-Hint." );
1726         ASSERT( pHnt && ((SwFmtFlyCnt&)pHnt->GetFlyCnt()).
1727                     GetFrmFmt() == (SwFrmFmt*)pOldFmt,
1728                     "Wrong TxtFlyCnt-Hint." );
1729 #endif
1730         const_cast<SwFmtFlyCnt&>(pHnt->GetFlyCnt()).SetFlyFmt( pNewFmt );
1731     }
1732 
1733 
1734     //Der Alte soll keinen Umlauf haben, und er soll oben/mittig
1735     //ausgerichtet sein.
1736     pNewSet->ClearItem();
1737 
1738     pNewSet->Put( SwFmtSurround( SURROUND_NONE ) );
1739     if (nLayerId == rDoc.GetHellId())
1740     {
1741         rSdrObj.SetLayer( rDoc.GetHeavenId() );
1742     }
1743     // OD 02.07.2003 #108784# - consider drawing objects in 'invisible' hell layer
1744     else if (nLayerId == rDoc.GetInvisibleHellId())
1745     {
1746         rSdrObj.SetLayer( rDoc.GetInvisibleHeavenId() );
1747     }
1748     pNewSet->Put( SvxLRSpaceItem( RES_LR_SPACE ) );
1749     pNewSet->Put( SvxULSpaceItem( RES_UL_SPACE ) );
1750 
1751     // OD 2004-04-15 #i26791# - set position of the drawing object, which is labeled.
1752     pNewSet->Put( SwFmtVertOrient( 0, text::VertOrientation::TOP, text::RelOrientation::FRAME ) );
1753     pNewSet->Put( SwFmtHoriOrient( 0, text::HoriOrientation::CENTER, text::RelOrientation::FRAME ) );
1754 
1755     //Der Alte ist absatzgebunden, und zwar am Absatz im neuen.
1756     SwFmtAnchor aAnch( FLY_AT_PARA );
1757     SwNodeIndex aAnchIdx( *pNewFmt->GetCntnt().GetCntntIdx(), 1 );
1758     pNew = aAnchIdx.GetNode().GetTxtNode();
1759     SwPosition aPos( aAnchIdx );
1760     aAnch.SetAnchor( &aPos );
1761     pNewSet->Put( aAnch );
1762 
1763     if( pUndo )
1764     {
1765         pUndo->SetFlys( *pOldFmt, *pNewSet, *pNewFmt );
1766         // OD 2004-04-15 #i26791# - position no longer needed
1767         pUndo->SetDrawObj( nLayerId );
1768     }
1769     else
1770         pOldFmt->SetFmtAttr( *pNewSet );
1771 
1772     delete pNewSet;
1773 
1774     //Nun nur noch die Flys erzeugen lassen. Das ueberlassen
1775     //wir vorhanden Methoden (insb. fuer InCntFlys etwas aufwendig).
1776     pNewFmt->MakeFrms();
1777 
1778     ASSERT( pNew, "No Label inserted" );
1779 
1780     if( pNew )
1781     {
1782         //#i61007# order of captions
1783         sal_Bool bOrderNumberingFirst = SW_MOD()->GetModuleConfig()->IsCaptionOrderNumberingFirst();
1784 
1785         // prepare string
1786         String aTxt;
1787         if( bOrderNumberingFirst )
1788         {
1789             aTxt = rNumberSeparator;
1790         }
1791         if ( pType )
1792         {
1793             aTxt += pType->GetName();
1794             if( !bOrderNumberingFirst )
1795                 aTxt += ' ';
1796         }
1797         xub_StrLen nIdx = aTxt.Len();
1798         aTxt += rSeparator;
1799         xub_StrLen nSepIdx = aTxt.Len();
1800         aTxt += rTxt;
1801 
1802         // insert text
1803         SwIndex aIdx( pNew, 0 );
1804         pNew->InsertText( aTxt, aIdx );
1805 
1806         // insert field
1807         if ( pType )
1808         {
1809             SwSetExpField aFld( (SwSetExpFieldType*)pType, aEmptyStr, SVX_NUM_ARABIC );
1810             if( bOrderNumberingFirst )
1811                 nIdx = 0;
1812             SwFmtFld aFmt( aFld );
1813             pNew->InsertItem( aFmt, nIdx, nIdx );
1814             if ( rCharacterStyle.Len() )
1815             {
1816                 SwCharFmt * pCharFmt = rDoc.FindCharFmtByName(rCharacterStyle);
1817                 if ( !pCharFmt )
1818                 {
1819                     const sal_uInt16 nMyId = SwStyleNameMapper::GetPoolIdFromUIName( rCharacterStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
1820                     pCharFmt = rDoc.GetCharFmtFromPool( nMyId );
1821                 }
1822                 if ( pCharFmt )
1823                 {
1824                     SwFmtCharFmt aCharFmt( pCharFmt );
1825                     pNew->InsertItem( aCharFmt, 0, nSepIdx + 1,
1826                             nsSetAttrMode::SETATTR_DONTEXPAND );
1827                 }
1828             }
1829         }
1830     }
1831 
1832     return pNewFmt;
1833 }
1834 
InsertDrawLabel(String const & rTxt,String const & rSeparator,String const & rNumberSeparator,sal_uInt16 const nId,String const & rCharacterStyle,SdrObject & rSdrObj)1835 SwFlyFrmFmt* SwDoc::InsertDrawLabel(
1836         String const& rTxt,
1837         String const& rSeparator,
1838         String const& rNumberSeparator,
1839         sal_uInt16 const nId,
1840         String const& rCharacterStyle,
1841         SdrObject& rSdrObj )
1842 {
1843     SwDrawContact *const pContact =
1844         static_cast<SwDrawContact*>(GetUserCall( &rSdrObj ));
1845     OSL_ENSURE( RES_DRAWFRMFMT == pContact->GetFmt()->Which(),
1846             "InsertDrawLabel(): not a DrawFrmFmt" );
1847     if (!pContact)
1848         return 0;
1849 
1850     SwDrawFrmFmt* pOldFmt = (SwDrawFrmFmt *)pContact->GetFmt();
1851     if (!pOldFmt)
1852         return 0;
1853 
1854     SwUndoInsertLabel * pUndo = 0;
1855     if (GetIDocumentUndoRedo().DoesUndo())
1856     {
1857         GetIDocumentUndoRedo().ClearRedo();
1858         pUndo = new SwUndoInsertLabel(
1859             LTYPE_DRAW, rTxt, rSeparator, rNumberSeparator, sal_False,
1860             nId, rCharacterStyle, sal_False );
1861     }
1862 
1863     SwFlyFrmFmt *const pNewFmt = lcl_InsertDrawLabel(
1864         *this, pTxtFmtCollTbl, pUndo, pOldFmt,
1865         rTxt, rSeparator, rNumberSeparator, nId, rCharacterStyle, rSdrObj);
1866 
1867     if (pUndo)
1868     {
1869         GetIDocumentUndoRedo().AppendUndo( pUndo );
1870     }
1871     else
1872     {
1873         GetIDocumentUndoRedo().DelAllUndoObj();
1874     }
1875 
1876     return pNewFmt;
1877 }
1878 
1879 
1880 /*************************************************************************
1881 |*
1882 |*  IDocumentTimerAccess-methods
1883 |*
1884 |*************************************************************************/
1885 
StartIdling()1886 void SwDoc::StartIdling()
1887 {
1888     mbStartIdleTimer = sal_True;
1889     if( !mIdleBlockCount )
1890         aIdleTimer.Start();
1891 }
1892 
StopIdling()1893 void SwDoc::StopIdling()
1894 {
1895     mbStartIdleTimer = sal_False;
1896     aIdleTimer.Stop();
1897 }
1898 
BlockIdling()1899 void SwDoc::BlockIdling()
1900 {
1901     aIdleTimer.Stop();
1902     ++mIdleBlockCount;
1903 }
1904 
UnblockIdling()1905 void SwDoc::UnblockIdling()
1906 {
1907     --mIdleBlockCount;
1908     if( !mIdleBlockCount && mbStartIdleTimer && !aIdleTimer.IsActive() )
1909         aIdleTimer.Start();
1910 }
1911 
1912 
1913 /*************************************************************************
1914 |*
1915 |*  SwDoc::DoIdleJobs()
1916 |*
1917 |*  Ersterstellung      OK 30.03.94
1918 |*  Letzte Aenderung    MA 09. Jun. 95
1919 |*
1920 |*************************************************************************/
1921 
IMPL_LINK(SwDoc,DoIdleJobs,Timer *,pTimer)1922 IMPL_LINK( SwDoc, DoIdleJobs, Timer *, pTimer )
1923 {
1924 #ifdef TIMELOG
1925     static ::rtl::Logfile* pModLogFile = 0;
1926     if( !pModLogFile )
1927         pModLogFile = new ::rtl::Logfile( "First DoIdleJobs" );
1928 #endif
1929 
1930     SwRootFrm* pTmpRoot = GetCurrentLayout();//swmod 080219
1931     if( pTmpRoot &&
1932         !SfxProgress::GetActiveProgress( pDocShell ) )
1933     {
1934         ViewShell *pSh, *pStartSh;
1935         pSh = pStartSh = GetCurrentViewShell();
1936         do {
1937             if( pSh->ActionPend() )
1938             {
1939                 if( pTimer )
1940                     pTimer->Start();
1941                 return 0;
1942             }
1943             pSh = (ViewShell*)pSh->GetNext();
1944         } while( pSh != pStartSh );
1945 
1946         if( pTmpRoot->IsNeedGrammarCheck() )
1947         {
1948             sal_Bool bIsOnlineSpell = pSh->GetViewOptions()->IsOnlineSpell();
1949             sal_Bool bIsAutoGrammar = sal_False;
1950             SvtLinguConfig().GetProperty( ::rtl::OUString::createFromAscii(
1951                         UPN_IS_GRAMMAR_AUTO ) ) >>= bIsAutoGrammar;
1952 
1953             if (bIsOnlineSpell && bIsAutoGrammar)
1954                 StartGrammarChecking( *this );
1955         }
1956         SwFldUpdateFlags nFldUpdFlag;
1957         std::set<SwRootFrm*> aAllLayouts = GetAllLayouts();//swmod 080320
1958         std::set<SwRootFrm*>::iterator pLayIter = aAllLayouts.begin();
1959         for ( ;pLayIter != aAllLayouts.end();pLayIter++ )
1960         {
1961             if ((*pLayIter)->IsIdleFormat())
1962             {
1963                 (*pLayIter)->GetCurrShell()->LayoutIdle();
1964                 break;
1965             }
1966         }
1967         bool bAllValid = pLayIter == aAllLayouts.end() ? 1 : 0;
1968         if( bAllValid && ( AUTOUPD_FIELD_ONLY ==
1969                  ( nFldUpdFlag = getFieldUpdateFlags(true) )
1970                     || AUTOUPD_FIELD_AND_CHARTS == nFldUpdFlag ) &&
1971                 GetUpdtFlds().IsFieldsDirty() &&
1972                 !GetUpdtFlds().IsInUpdateFlds() &&
1973                 !IsExpFldsLocked()
1974                 // das umschalten der Feldname fuehrt zu keinem Update der
1975                 // Felder, also der "Hintergrund-Update" immer erfolgen
1976                 /* && !pStartSh->GetViewOptions()->IsFldName()*/ )
1977         {
1978             // chaos::Action-Klammerung!
1979             GetUpdtFlds().SetInUpdateFlds( sal_True );
1980 
1981             pTmpRoot->StartAllAction();
1982 
1983             // no jump on update of fields #i85168#
1984             const sal_Bool bOldLockView = pStartSh->IsViewLocked();
1985             pStartSh->LockView( sal_True );
1986 
1987             GetSysFldType( RES_CHAPTERFLD )->ModifyNotification( 0, 0 );    // KapitelFld
1988             UpdateExpFlds( 0, sal_False );      // Expression-Felder Updaten
1989             UpdateTblFlds(NULL);                // Tabellen
1990             UpdateRefFlds(NULL);                // Referenzen
1991 
1992             pTmpRoot->EndAllAction();
1993 
1994             pStartSh->LockView( bOldLockView );
1995 
1996             GetUpdtFlds().SetInUpdateFlds( sal_False );
1997             GetUpdtFlds().SetFieldsDirty( sal_False );
1998         }
1999     }   //swmod 080219
2000 #ifdef TIMELOG
2001     if( pModLogFile && 1 != (long)pModLogFile )
2002         delete pModLogFile, ((long&)pModLogFile) = 1;
2003 #endif
2004     if( pTimer )
2005         pTimer->Start();
2006     return 0;
2007 }
2008 
IMPL_STATIC_LINK(SwDoc,BackgroundDone,SvxBrushItem *,EMPTYARG)2009 IMPL_STATIC_LINK( SwDoc, BackgroundDone, SvxBrushItem*, EMPTYARG )
2010 {
2011     ViewShell *pSh, *pStartSh;
2012     pSh = pStartSh = pThis->GetCurrentViewShell();  //swmod 071108//swmod 071225
2013     if( pStartSh )
2014         do {
2015             if( pSh->GetWin() )
2016             {
2017                 //Fuer Repaint mir virtuellen Device sorgen.
2018                 pSh->LockPaint();
2019                 pSh->UnlockPaint( sal_True );
2020             }
2021             pSh = (ViewShell*)pSh->GetNext();
2022         } while( pSh != pStartSh );
2023     return 0;
2024 }
2025 
lcl_GetUniqueFlyName(const SwDoc * pDoc,sal_uInt16 nDefStrId)2026 static String lcl_GetUniqueFlyName( const SwDoc* pDoc, sal_uInt16 nDefStrId )
2027 {
2028     ResId aId( nDefStrId, *pSwResMgr );
2029     String aName( aId );
2030     xub_StrLen nNmLen = aName.Len();
2031 
2032     const SwSpzFrmFmts& rFmts = *pDoc->GetSpzFrmFmts();
2033 
2034     sal_uInt16 nNum, nTmp, nFlagSize = ( rFmts.Count() / 8 ) +2;
2035     sal_uInt8* pSetFlags = new sal_uInt8[ nFlagSize ];
2036     sal_uInt16 n;
2037 
2038     memset( pSetFlags, 0, nFlagSize );
2039 
2040     for( n = 0; n < rFmts.Count(); ++n )
2041     {
2042         const SwFrmFmt* pFlyFmt = rFmts[ n ];
2043         if( RES_FLYFRMFMT == pFlyFmt->Which() &&
2044             pFlyFmt->GetName().Match( aName ) == nNmLen )
2045         {
2046             // Nummer bestimmen und das Flag setzen
2047             nNum = static_cast< sal_uInt16 >( pFlyFmt->GetName().Copy( nNmLen ).ToInt32() );
2048             if( nNum-- && nNum < rFmts.Count() )
2049                 pSetFlags[ nNum / 8 ] |= (0x01 << ( nNum & 0x07 ));
2050         }
2051     }
2052 
2053     // alle Nummern entsprechend geflag, also bestimme die richtige Nummer
2054     nNum = rFmts.Count();
2055     for( n = 0; n < nFlagSize; ++n )
2056         if( 0xff != ( nTmp = pSetFlags[ n ] ))
2057         {
2058             // also die Nummer bestimmen
2059             nNum = n * 8;
2060             while( nTmp & 1 )
2061                 ++nNum, nTmp >>= 1;
2062             break;
2063         }
2064 
2065     delete [] pSetFlags;
2066     return aName += String::CreateFromInt32( ++nNum );
2067 }
2068 
GetUniqueGrfName() const2069 String SwDoc::GetUniqueGrfName() const
2070 {
2071     return lcl_GetUniqueFlyName( this, STR_GRAPHIC_DEFNAME );
2072 }
2073 
GetUniqueOLEName() const2074 String SwDoc::GetUniqueOLEName() const
2075 {
2076     return lcl_GetUniqueFlyName( this, STR_OBJECT_DEFNAME );
2077 }
2078 
GetUniqueFrameName() const2079 String SwDoc::GetUniqueFrameName() const
2080 {
2081     return lcl_GetUniqueFlyName( this, STR_FRAME_DEFNAME );
2082 }
2083 
FindFlyByName(const String & rName,sal_Int8 nNdTyp) const2084 const SwFlyFrmFmt* SwDoc::FindFlyByName( const String& rName, sal_Int8 nNdTyp ) const
2085 {
2086     const SwSpzFrmFmts& rFmts = *GetSpzFrmFmts();
2087     for( sal_uInt16 n = rFmts.Count(); n; )
2088     {
2089         const SwFrmFmt* pFlyFmt = rFmts[ --n ];
2090         const SwNodeIndex* pIdx;
2091         if( RES_FLYFRMFMT == pFlyFmt->Which() && pFlyFmt->GetName() == rName &&
2092             0 != ( pIdx = pFlyFmt->GetCntnt().GetCntntIdx() ) &&
2093             pIdx->GetNode().GetNodes().IsDocNodes() )
2094         {
2095             if( nNdTyp )
2096             {
2097                 // dann noch auf den richtigen Node-Typ abfragen
2098                 const SwNode* pNd = GetNodes()[ pIdx->GetIndex()+1 ];
2099                 if( nNdTyp == ND_TEXTNODE
2100                         ? !pNd->IsNoTxtNode()
2101                         : nNdTyp == pNd->GetNodeType() )
2102                     return (SwFlyFrmFmt*)pFlyFmt;
2103             }
2104             else
2105                 return (SwFlyFrmFmt*)pFlyFmt;
2106         }
2107     }
2108     return 0;
2109 }
2110 
SetFlyName(SwFlyFrmFmt & rFmt,const String & rName)2111 void SwDoc::SetFlyName( SwFlyFrmFmt& rFmt, const String& rName )
2112 {
2113     String sName( rName );
2114     if( !rName.Len() || FindFlyByName( rName ) )
2115     {
2116         sal_uInt16 nTyp = STR_FRAME_DEFNAME;
2117         const SwNodeIndex* pIdx = rFmt.GetCntnt().GetCntntIdx();
2118         if( pIdx && pIdx->GetNode().GetNodes().IsDocNodes() )
2119             switch( GetNodes()[ pIdx->GetIndex() + 1 ]->GetNodeType() )
2120             {
2121             case ND_GRFNODE:    nTyp = STR_GRAPHIC_DEFNAME; break;
2122             case ND_OLENODE:    nTyp = STR_OBJECT_DEFNAME;  break;
2123             }
2124         sName = lcl_GetUniqueFlyName( this, nTyp );
2125     }
2126     rFmt.SetName( sName, sal_True );
2127     SetModified();
2128 }
2129 
SetAllUniqueFlyNames()2130 void SwDoc::SetAllUniqueFlyNames()
2131 {
2132     sal_uInt16 n, nFlyNum = 0, nGrfNum = 0, nOLENum = 0;
2133 
2134     ResId nFrmId( STR_FRAME_DEFNAME, *pSwResMgr ),
2135           nGrfId( STR_GRAPHIC_DEFNAME, *pSwResMgr ),
2136           nOLEId( STR_OBJECT_DEFNAME, *pSwResMgr );
2137     String sFlyNm( nFrmId );
2138     String sGrfNm( nGrfId );
2139     String sOLENm( nOLEId );
2140 
2141     if( 255 < ( n = GetSpzFrmFmts()->Count() ))
2142         n = 255;
2143     SwSpzFrmFmts aArr( (sal_Int8)n, 10 );
2144     SwFrmFmtPtr pFlyFmt;
2145     bool bContainsAtPageObjWithContentAnchor = false;
2146 
2147     for( n = GetSpzFrmFmts()->Count(); n; )
2148     {
2149         if( RES_FLYFRMFMT == (pFlyFmt = (*GetSpzFrmFmts())[ --n ])->Which() )
2150         {
2151             sal_uInt16 *pNum = 0;
2152             xub_StrLen nLen;
2153             const String& rNm = pFlyFmt->GetName();
2154             if( rNm.Len() )
2155             {
2156                 if( rNm.Match( sGrfNm ) == ( nLen = sGrfNm.Len() ))
2157                     pNum = &nGrfNum;
2158                 else if( rNm.Match( sFlyNm ) == ( nLen = sFlyNm.Len() ))
2159                     pNum = &nFlyNum;
2160                 else if( rNm.Match( sOLENm ) == ( nLen = sOLENm.Len() ))
2161                     pNum = &nOLENum;
2162 
2163                 if ( pNum && *pNum < ( nLen = static_cast< xub_StrLen >( rNm.Copy( nLen ).ToInt32() ) ) )
2164                     *pNum = nLen;
2165             }
2166             else
2167                 // das wollen wir nachher setzen
2168                 aArr.Insert( pFlyFmt, aArr.Count() );
2169 
2170         }
2171         if ( !bContainsAtPageObjWithContentAnchor )
2172         {
2173             const SwFmtAnchor& rAnchor = pFlyFmt->GetAnchor();
2174             if ( (FLY_AT_PAGE == rAnchor.GetAnchorId()) &&
2175                  rAnchor.GetCntntAnchor() )
2176             {
2177                 bContainsAtPageObjWithContentAnchor = true;
2178             }
2179         }
2180     }
2181     SetContainsAtPageObjWithContentAnchor( bContainsAtPageObjWithContentAnchor );
2182 
2183     const SwNodeIndex* pIdx;
2184 
2185     for( n = aArr.Count(); n; )
2186         if( 0 != ( pIdx = ( pFlyFmt = aArr[ --n ])->GetCntnt().GetCntntIdx() )
2187             && pIdx->GetNode().GetNodes().IsDocNodes() )
2188         {
2189             sal_uInt16 nNum;
2190             String sNm;
2191             switch( GetNodes()[ pIdx->GetIndex() + 1 ]->GetNodeType() )
2192             {
2193             case ND_GRFNODE:
2194                 sNm = sGrfNm;
2195                 nNum = ++nGrfNum;
2196                 break;
2197             case ND_OLENODE:
2198                 sNm = sOLENm;
2199                 nNum = ++nOLENum;
2200                 break;
2201             default:
2202                 sNm = sFlyNm;
2203                 nNum = ++nFlyNum;
2204                 break;
2205             }
2206             pFlyFmt->SetName( sNm += String::CreateFromInt32( nNum ));
2207         }
2208     aArr.Remove( 0, aArr.Count() );
2209 
2210     if( GetFtnIdxs().Count() )
2211     {
2212         SwTxtFtn::SetUniqueSeqRefNo( *this );
2213         // --> FME 2005-08-02 #i52775# Chapter footnotes did not
2214         // get updated correctly. Calling UpdateAllFtn() instead of
2215         // UpdateFtn() solves this problem, but I do not dare to
2216         // call UpdateAllFtn() in all cases: Safety first.
2217         if ( FTNNUM_CHAPTER == GetFtnInfo().eNum )
2218         {
2219             GetFtnIdxs().UpdateAllFtn();
2220         }
2221         // <--
2222         else
2223         {
2224             SwNodeIndex aTmp( GetNodes() );
2225             GetFtnIdxs().UpdateFtn( aTmp );
2226         }
2227     }
2228 }
2229 
IsInHeaderFooter(const SwNodeIndex & rIdx) const2230 sal_Bool SwDoc::IsInHeaderFooter( const SwNodeIndex& rIdx ) const
2231 {
2232     // gibt es ein Layout, dann ueber das laufen!!
2233     //  (Das kann dann auch Fly in Fly in Kopfzeile !)
2234     // MIB 9.2.98: Wird auch vom sw3io benutzt, um festzustellen, ob sich
2235     // ein Redline-Objekt in einer Kopf- oder Fusszeile befindet. Da
2236     // Redlines auch an Start- und Endnodes haengen, muss der Index nicht
2237     // unbedingt der eines Content-Nodes sein.
2238     SwNode* pNd = &rIdx.GetNode();
2239     if( pNd->IsCntntNode() && pCurrentView )//swmod 071029//swmod 071225
2240     {
2241         const SwFrm *pFrm = pNd->GetCntntNode()->getLayoutFrm( GetCurrentLayout() );
2242         if( pFrm )
2243         {
2244             const SwFrm *pUp = pFrm->GetUpper();
2245             while ( pUp && !pUp->IsHeaderFrm() && !pUp->IsFooterFrm() )
2246             {
2247                 if ( pUp->IsFlyFrm() )
2248                     pUp = ((SwFlyFrm*)pUp)->GetAnchorFrm();
2249                 pUp = pUp->GetUpper();
2250             }
2251             if ( pUp )
2252                 return sal_True;
2253 
2254             return sal_False;
2255         }
2256     }
2257 
2258 
2259     const SwNode* pFlyNd = pNd->FindFlyStartNode();
2260     while( pFlyNd )
2261     {
2262         // dann ueber den Anker nach oben "hangeln"
2263         sal_uInt16 n;
2264         for( n = 0; n < GetSpzFrmFmts()->Count(); ++n )
2265         {
2266             const SwFrmFmt* pFmt = (*GetSpzFrmFmts())[ n ];
2267             const SwNodeIndex* pIdx = pFmt->GetCntnt().GetCntntIdx();
2268             if( pIdx && pFlyNd == &pIdx->GetNode() )
2269             {
2270                 const SwFmtAnchor& rAnchor = pFmt->GetAnchor();
2271                 if ((FLY_AT_PAGE == rAnchor.GetAnchorId()) ||
2272                     !rAnchor.GetCntntAnchor() )
2273                 {
2274                     return sal_False;
2275                 }
2276 
2277                 pNd = &rAnchor.GetCntntAnchor()->nNode.GetNode();
2278                 pFlyNd = pNd->FindFlyStartNode();
2279                 break;
2280             }
2281         }
2282         if( n >= GetSpzFrmFmts()->Count() )
2283         {
2284             ASSERT( mbInReading, "Fly-Section aber kein Format gefunden" );
2285             return sal_False;
2286         }
2287     }
2288 
2289     return 0 != pNd->FindHeaderStartNode() ||
2290             0 != pNd->FindFooterStartNode();
2291 }
2292 
GetTextDirection(const SwPosition & rPos,const Point * pPt) const2293 short SwDoc::GetTextDirection( const SwPosition& rPos,
2294                                const Point* pPt ) const
2295 {
2296     short nRet = -1;
2297 
2298     SwCntntNode *pNd = rPos.nNode.GetNode().GetCntntNode();
2299 
2300     // --> OD 2005-02-21 #i42921# - use new method <SwCntntNode::GetTextDirection(..)>
2301     if ( pNd )
2302     {
2303         nRet = pNd->GetTextDirection( rPos, pPt );
2304     }
2305     if ( nRet == -1 )
2306     // <--
2307     {
2308         const SvxFrameDirectionItem* pItem = 0;
2309         if( pNd )
2310         {
2311             // in a flyframe? Then look at that for the correct attribute
2312             const SwFrmFmt* pFlyFmt = pNd->GetFlyFmt();
2313             while( pFlyFmt )
2314             {
2315                 pItem = &pFlyFmt->GetFrmDir();
2316                 if( FRMDIR_ENVIRONMENT == pItem->GetValue() )
2317                 {
2318                     pItem = 0;
2319                     const SwFmtAnchor* pAnchor = &pFlyFmt->GetAnchor();
2320                     if ((FLY_AT_PAGE != pAnchor->GetAnchorId()) &&
2321                         pAnchor->GetCntntAnchor())
2322                     {
2323                         pFlyFmt = pAnchor->GetCntntAnchor()->nNode.
2324                                             GetNode().GetFlyFmt();
2325                     }
2326                     else
2327                         pFlyFmt = 0;
2328                 }
2329                 else
2330                     pFlyFmt = 0;
2331             }
2332 
2333             if( !pItem )
2334             {
2335                 const SwPageDesc* pPgDsc = pNd->FindPageDesc( sal_False );
2336                 if( pPgDsc )
2337                     pItem = &pPgDsc->GetMaster().GetFrmDir();
2338             }
2339         }
2340         if( !pItem )
2341             pItem = (SvxFrameDirectionItem*)&GetAttrPool().GetDefaultItem(
2342                                                             RES_FRAMEDIR );
2343         nRet = pItem->GetValue();
2344     }
2345     return nRet;
2346 }
2347 
IsInVerticalText(const SwPosition & rPos,const Point * pPt) const2348 sal_Bool SwDoc::IsInVerticalText( const SwPosition& rPos, const Point* pPt ) const
2349 {
2350     const short nDir = GetTextDirection( rPos, pPt );
2351     return FRMDIR_VERT_TOP_RIGHT == nDir || FRMDIR_VERT_TOP_LEFT == nDir;
2352 }
2353 
SetCurrentViewShell(ViewShell * pNew)2354 void SwDoc::SetCurrentViewShell( ViewShell* pNew )
2355 {
2356     pCurrentView = pNew;
2357 }
2358 
GetLayouter()2359 SwLayouter* SwDoc::GetLayouter()
2360 {
2361     return pLayouter;
2362 }
2363 
GetLayouter() const2364 const SwLayouter* SwDoc::GetLayouter() const
2365 {
2366     return pLayouter;
2367 }
2368 
SetLayouter(SwLayouter * pNew)2369 void SwDoc::SetLayouter( SwLayouter* pNew )
2370 {
2371     pLayouter = pNew;
2372 }
2373 
GetCurrentViewShell() const2374 const ViewShell *SwDoc::GetCurrentViewShell() const
2375 {
2376     return pCurrentView;
2377 }
2378 
GetCurrentViewShell()2379 ViewShell *SwDoc::GetCurrentViewShell()
2380 {
2381     return pCurrentView;
2382 }   //swmod 080219 It must be able to communicate to a ViewShell.This is going to be removedd later.
2383 
GetCurrentLayout() const2384 const SwRootFrm *SwDoc::GetCurrentLayout() const
2385 {
2386     if(GetCurrentViewShell())
2387         return GetCurrentViewShell()->GetLayout();
2388     return 0;
2389 }
2390 
GetCurrentLayout()2391 SwRootFrm *SwDoc::GetCurrentLayout()
2392 {
2393     if(GetCurrentViewShell())
2394         return GetCurrentViewShell()->GetLayout();
2395     return 0;
2396 }
2397 
HasLayout() const2398 bool SwDoc::HasLayout() const
2399 {
2400     // if there is a view, there is always a layout
2401     return (pCurrentView != 0);
2402 }
2403 
GetAllLayouts()2404 std::set<SwRootFrm*> SwDoc::GetAllLayouts()
2405 {
2406     std::set<SwRootFrm*> aAllLayouts;
2407     ViewShell *pStart = GetCurrentViewShell();
2408     ViewShell *pTemp = pStart;
2409     if ( pTemp )
2410     {
2411         do
2412         {
2413             if (pTemp->GetLayout())
2414             {
2415                 aAllLayouts.insert(pTemp->GetLayout());
2416                 pTemp = (ViewShell*)pTemp->GetNext();
2417             }
2418         } while(pTemp!=pStart);
2419     }
2420 
2421     return aAllLayouts;
2422 }//swmod 070825
2423 
2424 
ShareLayout(boost::shared_ptr<SwRootFrm> & rPtr)2425 void SwDoc::ShareLayout(boost::shared_ptr<SwRootFrm>& rPtr)
2426 {
2427     pLayoutPtr = rPtr;
2428 }
2429