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