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 188 : SwFrmFmt *SwDoc::MakeLayoutFmt( RndStdIds eRequest, const SfxItemSet* pSet )
124 : {
125 188 : SwFrmFmt *pFmt = 0;
126 188 : const sal_Bool bMod = IsModified();
127 188 : bool bHeader = false;
128 :
129 188 : switch ( eRequest )
130 : {
131 : case RND_STD_HEADER:
132 : case RND_STD_HEADERL:
133 : case RND_STD_HEADERR:
134 : {
135 90 : 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 188 : GetDfltFrmFmt() );
145 :
146 188 : SwNodeIndex aTmpIdx( GetNodes().GetEndOfAutotext() );
147 : SwStartNode* pSttNd =
148 188 : 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 376 : ) ) );
163 188 : pFmt->SetFmtAttr( SwFmtCntnt( pSttNd ));
164 :
165 188 : 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 188 : if ( !bMod )
171 0 : ResetModified();
172 : }
173 188 : 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 188 : return pFmt;
205 : }
206 :
207 : /*************************************************************************
208 : |*
209 : |* SwDoc::DelLayoutFmt()
210 : |*
211 : |* Description: Deletes the denoted format and its content.
212 : |*
213 : |*************************************************************************/
214 168 : 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 168 : const SwFmtChain &rChain = pFmt->GetChain();
219 168 : 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 168 : 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 168 : const SwNodeIndex* pCntIdx = pFmt->GetCntnt().GetCntntIdx();
233 168 : if (pCntIdx && !GetIDocumentUndoRedo().DoesUndo())
234 : {
235 : // Disconnect if it's an OLE object
236 10 : SwOLENode* pOLENd = GetNodes()[ pCntIdx->GetIndex()+1 ]->GetOLENode();
237 10 : 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 168 : pFmt->DelFrms();
259 :
260 : // Only FlyFrames are undoable at first
261 168 : const sal_uInt16 nWh = pFmt->Which();
262 168 : 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 168 : if ( nWh == RES_FLYFRMFMT )
271 : {
272 : // determine frame formats of at-frame anchored objects
273 108 : const SwNodeIndex* pCntntIdx = pFmt->GetCntnt().GetCntntIdx();
274 108 : if ( pCntntIdx )
275 : {
276 10 : const SwFrmFmts* pTbl = pFmt->GetDoc()->GetSpzFrmFmts();
277 10 : if ( pTbl )
278 : {
279 10 : std::vector<SwFrmFmt*> aToDeleteFrmFmts;
280 10 : const sal_uLong nNodeIdxOfFlyFmt( pCntntIdx->GetIndex() );
281 :
282 38 : for ( sal_uInt16 i = 0; i < pTbl->size(); ++i )
283 : {
284 28 : SwFrmFmt* pTmpFmt = (*pTbl)[i];
285 28 : const SwFmtAnchor &rAnch = pTmpFmt->GetAnchor();
286 28 : 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 20 : while ( !aToDeleteFrmFmts.empty() )
295 : {
296 0 : SwFrmFmt* pTmpFmt = aToDeleteFrmFmts.back();
297 0 : pFmt->GetDoc()->DelLayoutFmt( pTmpFmt );
298 :
299 0 : aToDeleteFrmFmts.pop_back();
300 10 : }
301 : }
302 : }
303 : }
304 :
305 : // Delete content
306 168 : if( pCntIdx )
307 : {
308 10 : SwNode *pNode = &pCntIdx->GetNode();
309 10 : ((SwFmtCntnt&)pFmt->GetFmtAttr( RES_CNTNT )).SetNewCntntIdx( 0 );
310 10 : DeleteSection( pNode );
311 : }
312 :
313 : // Delete the character for FlyFrames anchored as char (if necessary)
314 168 : const SwFmtAnchor& rAnchor = pFmt->GetAnchor();
315 168 : if ((FLY_AS_CHAR == rAnchor.GetAnchorId()) && rAnchor.GetCntntAnchor())
316 : {
317 6 : const SwPosition* pPos = rAnchor.GetCntntAnchor();
318 6 : SwTxtNode *pTxtNd = pPos->nNode.GetNode().GetTxtNode();
319 :
320 : // attribute is still in text node, delete it
321 6 : if ( pTxtNd )
322 : {
323 : SwTxtFlyCnt* const pAttr = static_cast<SwTxtFlyCnt*>(
324 4 : pTxtNd->GetTxtAttrForCharAt( pPos->nContent.GetIndex(),
325 4 : RES_TXTATR_FLYCNT ));
326 4 : 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 168 : DelFrmFmt( pFmt );
337 : }
338 168 : SetModified();
339 168 : }
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 14 : SwFrmFmt *SwDoc::CopyLayoutFmt( const SwFrmFmt& rSource,
353 : const SwFmtAnchor& rNewAnchor,
354 : bool bSetTxtFlyAtt, bool bMakeFrms )
355 : {
356 14 : const bool bFly = RES_FLYFRMFMT == rSource.Which();
357 14 : const bool bDraw = RES_DRAWFRMFMT == rSource.Which();
358 : OSL_ENSURE( bFly || bDraw, "this method only works for fly or draw" );
359 :
360 14 : 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 14 : bool bMayNotCopy = false;
367 14 : if( bDraw )
368 : {
369 : const SwDrawContact* pDrawContact =
370 6 : static_cast<const SwDrawContact*>( rSource.FindContactObj() );
371 :
372 : bMayNotCopy =
373 6 : ((FLY_AT_PARA == rNewAnchor.GetAnchorId()) ||
374 0 : (FLY_AT_FLY == rNewAnchor.GetAnchorId()) ||
375 0 : (FLY_AT_CHAR == rNewAnchor.GetAnchorId())) &&
376 6 : rNewAnchor.GetCntntAnchor() &&
377 6 : IsInHeaderFooter( rNewAnchor.GetCntntAnchor()->nNode ) &&
378 : pDrawContact != NULL &&
379 6 : pDrawContact->GetMaster() != NULL &&
380 24 : CheckControlLayer( pDrawContact->GetMaster() );
381 : }
382 :
383 : // just return if we can't copy this
384 14 : if( bMayNotCopy )
385 0 : return NULL;
386 :
387 14 : SwFrmFmt* pDest = GetDfltFrmFmt();
388 14 : if( rSource.GetRegisteredIn() != pSrcDoc->GetDfltFrmFmt() )
389 8 : pDest = CopyFrmFmt( *(SwFrmFmt*)rSource.GetRegisteredIn() );
390 14 : 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 8 : SwFlyFrmFmt *pFormat = MakeFlyFrmFmt( rSource.GetName(), pDest );
399 8 : pDest = pFormat;
400 :
401 8 : SwXFrame::GetOrCreateSdrObject(pFormat);
402 : }
403 : else
404 6 : pDest = MakeDrawFrmFmt( aEmptyStr, pDest );
405 :
406 : // Copy all other or new attributes
407 14 : pDest->CopyAttrs( rSource );
408 :
409 : // Do not copy chains
410 14 : pDest->ResetFmtAttr( RES_CHAIN );
411 :
412 14 : if( bFly )
413 : {
414 : // Duplicate the content.
415 8 : const SwNode& rCSttNd = rSource.GetCntnt().GetCntntIdx()->GetNode();
416 8 : SwNodeRange aRg( rCSttNd, 1, *rCSttNd.EndOfSectionNode() );
417 :
418 8 : SwNodeIndex aIdx( GetNodes().GetEndOfAutotext() );
419 8 : 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 8 : aIdx = *pSttNd;
424 8 : SwFmtCntnt aAttr( rSource.GetCntnt() );
425 8 : aAttr.SetNewCntntIdx( &aIdx );
426 8 : pDest->SetFmtAttr( aAttr );
427 8 : pDest->SetFmtAttr( rNewAnchor );
428 :
429 8 : if( !mbCopyIsMove || this != pSrcDoc )
430 : {
431 8 : if( mbInReading )
432 8 : 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 8 : 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 8 : 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 8 : const ::sw::DrawUndoGuard drawUndoGuard(GetIDocumentUndoRedo());
463 :
464 8 : 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 6 : SwDrawContact* pSourceContact = (SwDrawContact *)rSource.FindContactObj();
471 :
472 : SwDrawContact* pContact = new SwDrawContact( (SwDrawFrmFmt*)pDest,
473 6 : CloneSdrObj( *pSourceContact->GetMaster(),
474 12 : 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 18 : if ( pDest->ISA(SwDrawFrmFmt) &&
479 6 : rSource.ISA(SwDrawFrmFmt) &&
480 6 : static_cast<const SwDrawFrmFmt&>(rSource).IsPosAttrSet() )
481 : {
482 0 : static_cast<SwDrawFrmFmt*>(pDest)->PosAttrSet();
483 : }
484 :
485 6 : 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 6 : pDest->SetFmtAttr( rNewAnchor );
495 :
496 6 : if (GetIDocumentUndoRedo().DoesUndo())
497 : {
498 0 : GetIDocumentUndoRedo().AppendUndo(new SwUndoInsLayFmt(pDest,0,0));
499 : }
500 : }
501 :
502 14 : 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 14 : if( bMakeFrms )
511 12 : pDest->MakeFrms();
512 :
513 14 : return pDest;
514 : }
515 :
516 6 : SdrObject* SwDoc::CloneSdrObj( const SdrObject& rObj, bool bMoveWithinDoc,
517 : bool bInsInPage )
518 : {
519 : // #i52858# - method name changed
520 6 : SdrPage *pPg = GetOrCreateDrawModel()->GetPage( 0 );
521 6 : if( !pPg )
522 : {
523 0 : pPg = GetDrawModel()->AllocPage( sal_False );
524 0 : GetDrawModel()->InsertPage( pPg );
525 : }
526 :
527 6 : SdrObject *pObj = rObj.Clone();
528 6 : 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 6 : else if( bInsInPage )
543 6 : pPg->InsertObject( pObj );
544 :
545 : // For drawing objects: set layer of cloned object to invisible layer
546 6 : SdrLayerID nLayerIdForClone = rObj.GetLayer();
547 18 : if ( !pObj->ISA(SwFlyDrawObj) &&
548 6 : !pObj->ISA(SwVirtFlyDrawObj) &&
549 6 : !IS_TYPE(SdrObject,pObj) )
550 : {
551 6 : if ( IsVisibleLayerId( nLayerIdForClone ) )
552 : {
553 0 : nLayerIdForClone = GetInvisibleLayerIdByVisibleOne( nLayerIdForClone );
554 : }
555 : }
556 6 : pObj->SetLayer( nLayerIdForClone );
557 :
558 :
559 6 : return pObj;
560 : }
561 :
562 440 : SwFlyFrmFmt* SwDoc::_MakeFlySection( const SwPosition& rAnchPos,
563 : const SwCntntNode& rNode,
564 : RndStdIds eRequestId,
565 : const SfxItemSet* pFlySet,
566 : SwFrmFmt* pFrmFmt )
567 : {
568 440 : if( !pFrmFmt )
569 0 : pFrmFmt = GetFrmFmtFromPool( RES_POOLFRM_FRAME );
570 :
571 440 : String sName;
572 440 : if( !mbInReading )
573 2 : switch( rNode.GetNodeType() )
574 : {
575 2 : case ND_GRFNODE: sName = GetUniqueGrfName(); break;
576 0 : case ND_OLENODE: sName = GetUniqueOLEName(); break;
577 0 : default: sName = GetUniqueFrameName(); break;
578 : }
579 440 : 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 440 : SwNodeRange aRange( GetNodes().GetEndOfAutotext(), -1,
584 880 : GetNodes().GetEndOfAutotext() );
585 440 : GetNodes().SectionDown( &aRange, SwFlyStartNode );
586 :
587 440 : pFmt->SetFmtAttr( SwFmtCntnt( rNode.StartOfSectionNode() ));
588 :
589 :
590 440 : const SwFmtAnchor* pAnchor = 0;
591 440 : if( pFlySet )
592 : {
593 : pFlySet->GetItemState( RES_ANCHOR, sal_False,
594 440 : (const SfxPoolItem**)&pAnchor );
595 440 : 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 440 : pFmt->SetFmtAttr( *pFlySet );
603 : }
604 :
605 : // Anchor not yet set?
606 440 : RndStdIds eAnchorId = pAnchor ? pAnchor->GetAnchorId()
607 880 : : pFmt->GetAnchor().GetAnchorId();
608 : // #i107811# Assure that at-page anchored fly frames have a page num or a
609 : // content anchor set.
610 1422 : if ( !pAnchor ||
611 440 : ( FLY_AT_PAGE != pAnchor->GetAnchorId() &&
612 412 : !pAnchor->GetCntntAnchor() ) ||
613 74 : ( FLY_AT_PAGE == pAnchor->GetAnchorId() &&
614 28 : !pAnchor->GetCntntAnchor() &&
615 28 : pAnchor->GetPageNum() == 0 ) )
616 : {
617 : // set it again, needed for Undo
618 366 : SwFmtAnchor aAnch( pFmt->GetAnchor() );
619 366 : 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 716 : if( eRequestId != aAnch.GetAnchorId() &&
628 350 : SFX_ITEM_SET != pFmt->GetItemState( RES_ANCHOR, sal_True ) )
629 : {
630 0 : aAnch.SetType( eRequestId );
631 : }
632 :
633 366 : eAnchorId = aAnch.GetAnchorId();
634 366 : if ( FLY_AT_PAGE != eAnchorId ||
635 : ( FLY_AT_PAGE == eAnchorId &&
636 0 : ( !pAnchor ||
637 0 : aAnch.GetPageNum() == 0 ) ) )
638 : {
639 366 : aAnch.SetAnchor( &rAnchPos );
640 : }
641 : }
642 366 : pFmt->SetFmtAttr( aAnch );
643 : }
644 : else
645 74 : eAnchorId = pFmt->GetAnchor().GetAnchorId();
646 :
647 440 : if ( FLY_AS_CHAR == eAnchorId )
648 : {
649 332 : xub_StrLen nStt = rAnchPos.nContent.GetIndex();
650 332 : SwTxtNode * pTxtNode = rAnchPos.nNode.GetNode().GetTxtNode();
651 :
652 : OSL_ENSURE(pTxtNode!= 0, "There should be a SwTxtNode!");
653 :
654 332 : if (pTxtNode != NULL)
655 : {
656 332 : SwFmtFlyCnt aFmt( pFmt );
657 332 : pTxtNode->InsertItem( aFmt, nStt, nStt );
658 : }
659 : }
660 :
661 440 : if( SFX_ITEM_SET != pFmt->GetAttrSet().GetItemState( RES_FRM_SIZE ))
662 : {
663 2 : SwFmtFrmSize aFmtSize( ATT_VAR_SIZE, 0, DEF_FLY_WIDTH );
664 2 : const SwNoTxtNode* pNoTxtNode = rNode.GetNoTxtNode();
665 2 : if( pNoTxtNode )
666 : {
667 : // Set size
668 2 : Size aSize( pNoTxtNode->GetTwipSize() );
669 2 : if( MINFLY > aSize.Width() )
670 2 : aSize.Width() = DEF_FLY_WIDTH;
671 2 : aFmtSize.SetWidth( aSize.Width() );
672 2 : if( aSize.Height() )
673 : {
674 0 : aFmtSize.SetHeight( aSize.Height() );
675 0 : aFmtSize.SetHeightSizeType( ATT_FIX_SIZE );
676 : }
677 : }
678 2 : pFmt->SetFmtAttr( aFmtSize );
679 : }
680 :
681 : // Set up frames
682 440 : if( GetCurrentViewShell() )
683 0 : pFmt->MakeFrms(); // ??? //swmod 071108//swmod 071225
684 :
685 440 : 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 440 : SetModified();
694 440 : return pFmt;
695 : }
696 :
697 68 : SwFlyFrmFmt* SwDoc::MakeFlySection( RndStdIds eAnchorType,
698 : const SwPosition* pAnchorPos,
699 : const SfxItemSet* pFlySet,
700 : SwFrmFmt* pFrmFmt, bool bCalledFromShell )
701 : {
702 68 : SwFlyFrmFmt* pFmt = 0;
703 68 : bool bCallMake = true;
704 68 : 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 68 : if( bCallMake )
724 : {
725 68 : if( !pFrmFmt )
726 62 : pFrmFmt = GetFrmFmtFromPool( RES_POOLFRM_FRAME );
727 :
728 : sal_uInt16 nCollId = static_cast<sal_uInt16>(
729 68 : 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 68 : SwCntntNode * pNewTxtNd = GetNodes().MakeTxtNode
734 68 : (SwNodeIndex( GetNodes().GetEndOfAutotext()),
735 204 : GetTxtCollFromPool( nCollId ));
736 68 : SwCntntNode * pAnchorNode = pAnchorPos->nNode.GetNode().GetCntntNode();
737 :
738 68 : const SfxPoolItem * pItem = NULL;
739 :
740 68 : 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 68 : eAnchorType, pFlySet, pFrmFmt );
747 : }
748 68 : return pFmt;
749 : }
750 :
751 28 : SwFlyFrmFmt* SwDoc::MakeFlyAndMove( const SwPaM& rPam, const SfxItemSet& rSet,
752 : const SwSelBoxes* pSelBoxes,
753 : SwFrmFmt *pParent )
754 : {
755 28 : SwFmtAnchor& rAnch = (SwFmtAnchor&)rSet.Get( RES_ANCHOR );
756 :
757 28 : GetIDocumentUndoRedo().StartUndo( UNDO_INSLAYFMT, NULL );
758 :
759 : SwFlyFrmFmt* pFmt = MakeFlySection( rAnch.GetAnchorId(), rPam.GetPoint(),
760 28 : &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 28 : if( pFmt )
766 : {
767 : do { // middle check loop
768 28 : const SwFmtCntnt &rCntnt = pFmt->GetCntnt();
769 : OSL_ENSURE( rCntnt.GetCntntIdx(), "No content prepared." );
770 28 : SwNodeIndex aIndex( *(rCntnt.GetCntntIdx()), 1 );
771 28 : 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 28 : SwPosition aPos( aIndex );
776 28 : aPos.nContent.Assign( pNode, 0 );
777 :
778 28 : 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 28 : SwPaM* pTmp = (SwPaM*)&rPam;
833 28 : bool bOldFlag = mbCopyIsMove;
834 28 : bool const bOldUndo = GetIDocumentUndoRedo().DoesUndo();
835 28 : bool const bOldRedlineMove(IsRedlineMove());
836 28 : mbCopyIsMove = true;
837 28 : GetIDocumentUndoRedo().DoUndo(false);
838 28 : SetRedlineMove(true);
839 28 : do {
840 56 : if( pTmp->HasMark() &&
841 28 : *pTmp->GetPoint() != *pTmp->GetMark() )
842 : {
843 28 : CopyRange( *pTmp, aPos, false );
844 : }
845 28 : pTmp = static_cast<SwPaM*>(pTmp->GetNext());
846 : } while ( &rPam != pTmp );
847 28 : SetRedlineMove(bOldRedlineMove);
848 28 : mbCopyIsMove = bOldFlag;
849 28 : GetIDocumentUndoRedo().DoUndo(bOldUndo);
850 :
851 28 : pTmp = (SwPaM*)&rPam;
852 28 : do {
853 56 : if( pTmp->HasMark() &&
854 28 : *pTmp->GetPoint() != *pTmp->GetMark() )
855 : {
856 28 : DeleteAndJoin( *pTmp );
857 : }
858 28 : pTmp = static_cast<SwPaM*>(pTmp->GetNext());
859 : } while ( &rPam != pTmp );
860 28 : }
861 : } while( false );
862 : }
863 :
864 28 : SetModified();
865 :
866 28 : GetIDocumentUndoRedo().EndUndo( UNDO_INSLAYFMT, NULL );
867 :
868 28 : return pFmt;
869 : }
870 :
871 : // Insert a DrawObject.
872 : // The Object has to be already registered in the DrawModel.
873 212 : SwDrawFrmFmt* SwDoc::Insert( const SwPaM &rRg,
874 : SdrObject& rDrawObj,
875 : const SfxItemSet* pFlyAttrSet,
876 : SwFrmFmt* pDefFmt )
877 : {
878 : SwDrawFrmFmt *pFmt = MakeDrawFrmFmt( aEmptyStr,
879 212 : pDefFmt ? pDefFmt : GetDfltFrmFmt() );
880 :
881 212 : const SwFmtAnchor* pAnchor = 0;
882 212 : if( pFlyAttrSet )
883 : {
884 : pFlyAttrSet->GetItemState( RES_ANCHOR, sal_False,
885 212 : (const SfxPoolItem**)&pAnchor );
886 212 : pFmt->SetFmtAttr( *pFlyAttrSet );
887 : }
888 :
889 212 : RndStdIds eAnchorId = pAnchor ? pAnchor->GetAnchorId()
890 424 : : pFmt->GetAnchor().GetAnchorId();
891 :
892 : // Didn't set the Anchor yet?
893 : // DrawObjecte must never end up in the Header/Footer!
894 212 : const bool bIsAtCntnt = (FLY_AT_PAGE != eAnchorId);
895 :
896 212 : const SwNodeIndex* pChkIdx = 0;
897 212 : if( !pAnchor )
898 : {
899 0 : pChkIdx = &rRg.GetPoint()->nNode;
900 : }
901 212 : else if( bIsAtCntnt )
902 : {
903 94 : pChkIdx = pAnchor->GetCntntAnchor()
904 90 : ? &pAnchor->GetCntntAnchor()->nNode
905 184 : : &rRg.GetPoint()->nNode;
906 : }
907 :
908 : // Allow drawing objects in header/footer, but control objects aren't
909 : // allowed in header/footer.
910 310 : if( pChkIdx &&
911 94 : ::CheckControlLayer( &rDrawObj ) &&
912 4 : IsInHeaderFooter( *pChkIdx ) )
913 : {
914 0 : pFmt->SetFmtAttr( SwFmtAnchor( eAnchorId = FLY_AT_PAGE ) );
915 : }
916 212 : else if( !pAnchor || (bIsAtCntnt && !pAnchor->GetCntntAnchor() ))
917 : {
918 : // then set it, we need this in the Undo
919 4 : SwFmtAnchor aAnch( pAnchor ? *pAnchor : pFmt->GetAnchor() );
920 4 : eAnchorId = aAnch.GetAnchorId();
921 4 : if( FLY_AT_FLY == eAnchorId )
922 : {
923 0 : SwPosition aPos( *rRg.GetNode()->FindFlyStartNode() );
924 0 : aAnch.SetAnchor( &aPos );
925 : }
926 : else
927 : {
928 4 : aAnch.SetAnchor( rRg.GetPoint() );
929 4 : 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 4 : pFmt->SetFmtAttr( aAnch );
937 : }
938 :
939 : // For Draws anchored as character we set the attribute in the paragraph
940 212 : if ( FLY_AS_CHAR == eAnchorId )
941 : {
942 16 : xub_StrLen nStt = rRg.GetPoint()->nContent.GetIndex();
943 16 : SwFmtFlyCnt aFmt( pFmt );
944 16 : rRg.GetPoint()->nNode.GetNode().GetTxtNode()->InsertItem(
945 32 : aFmt, nStt, nStt );
946 : }
947 :
948 212 : SwDrawContact* pContact = new SwDrawContact( pFmt, &rDrawObj );
949 :
950 : // Create Frames if necessary
951 212 : 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 212 : if (GetIDocumentUndoRedo().DoesUndo())
964 : {
965 0 : GetIDocumentUndoRedo().AppendUndo( new SwUndoInsLayFmt(pFmt, 0, 0) );
966 : }
967 :
968 212 : SetModified();
969 212 : 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 112 : void SwDoc::GetAllFlyFmts( SwPosFlyFrms& rPosFlyFmts,
1013 : const SwPaM* pCmpRange, bool bDrawAlso,
1014 : bool bAsCharAlso ) const
1015 : {
1016 112 : SwPosFlyFrm *pFPos = 0;
1017 : SwFrmFmt *pFly;
1018 :
1019 : // collect all anchored somehow to paragraphs
1020 268 : for( sal_uInt16 n = 0; n < GetSpzFrmFmts()->size(); ++n )
1021 : {
1022 156 : pFly = (*GetSpzFrmFmts())[ n ];
1023 156 : bool bDrawFmt = bDrawAlso ? RES_DRAWFRMFMT == pFly->Which() : false;
1024 156 : bool bFlyFmt = RES_FLYFRMFMT == pFly->Which();
1025 156 : if( bFlyFmt || bDrawFmt )
1026 : {
1027 156 : const SwFmtAnchor& rAnchor = pFly->GetAnchor();
1028 156 : SwPosition const*const pAPos = rAnchor.GetCntntAnchor();
1029 752 : if (pAPos &&
1030 156 : ((FLY_AT_PARA == rAnchor.GetAnchorId()) ||
1031 148 : (FLY_AT_FLY == rAnchor.GetAnchorId()) ||
1032 148 : (FLY_AT_CHAR == rAnchor.GetAnchorId()) ||
1033 144 : ((FLY_AS_CHAR == rAnchor.GetAnchorId()) && bAsCharAlso)))
1034 : {
1035 12 : if( pCmpRange &&
1036 0 : !lcl_TstFlyRange( pCmpRange, pAPos, rAnchor.GetAnchorId() ))
1037 0 : continue; // not a valid FlyFrame
1038 12 : pFPos = new SwPosFlyFrm( pAPos->nNode, pFly, rPosFlyFmts.size() );
1039 12 : 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 112 : if( !GetCurrentViewShell() || pCmpRange ) //swmod 071108//swmod 071225
1047 112 : return;
1048 :
1049 112 : pFPos = 0;
1050 112 : SwPageFrm *pPage = (SwPageFrm*)GetCurrentLayout()->GetLower(); //swmod 080218
1051 350 : while( pPage )
1052 : {
1053 126 : if( pPage->GetSortedObjs() )
1054 : {
1055 10 : SwSortedObjs &rObjs = *pPage->GetSortedObjs();
1056 22 : for( sal_uInt16 i = 0; i < rObjs.Count(); ++i)
1057 : {
1058 12 : SwAnchoredObject* pAnchoredObj = rObjs[i];
1059 12 : if ( pAnchoredObj->ISA(SwFlyFrm) )
1060 8 : pFly = &(pAnchoredObj->GetFrmFmt());
1061 4 : else if ( bDrawAlso )
1062 4 : pFly = &(pAnchoredObj->GetFrmFmt());
1063 : else
1064 0 : continue;
1065 :
1066 12 : const SwFmtAnchor& rAnchor = pFly->GetAnchor();
1067 20 : if ((FLY_AT_PARA != rAnchor.GetAnchorId()) &&
1068 4 : (FLY_AT_FLY != rAnchor.GetAnchorId()) &&
1069 4 : (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 12 : if ( pFPos )
1091 : {
1092 0 : rPosFlyFmts.insert( pFPos );
1093 0 : pFPos = 0;
1094 : }
1095 : }
1096 : }
1097 126 : 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 478 : void SwDoc::StartIdling()
1795 : {
1796 478 : mbStartIdleTimer = true;
1797 478 : if( !mIdleBlockCount )
1798 478 : aIdleTimer.Start();
1799 478 : }
1800 :
1801 628 : void SwDoc::StopIdling()
1802 : {
1803 628 : mbStartIdleTimer = false;
1804 628 : aIdleTimer.Stop();
1805 628 : }
1806 :
1807 2040 : void SwDoc::BlockIdling()
1808 : {
1809 2040 : aIdleTimer.Stop();
1810 2040 : ++mIdleBlockCount;
1811 2040 : }
1812 :
1813 2040 : void SwDoc::UnblockIdling()
1814 : {
1815 2040 : --mIdleBlockCount;
1816 2040 : if( !mIdleBlockCount && mbStartIdleTimer && !aIdleTimer.IsActive() )
1817 458 : aIdleTimer.Start();
1818 2040 : }
1819 :
1820 : /*************************************************************************
1821 : |*
1822 : |* SwDoc::DoIdleJobs()
1823 : |*
1824 : |*************************************************************************/
1825 17338 : IMPL_LINK( SwDoc, DoIdleJobs, Timer *, pTimer )
1826 : {
1827 : #ifdef TIMELOG
1828 : static ::rtl::Logfile* pModLogFile = 0;
1829 : if( !pModLogFile )
1830 : pModLogFile = new ::rtl::Logfile( "First DoIdleJobs" );
1831 : #endif
1832 :
1833 8669 : SwRootFrm* pTmpRoot = GetCurrentLayout();//swmod 080219
1834 17338 : if( pTmpRoot &&
1835 8669 : !SfxProgress::GetActiveProgress( pDocShell ) )
1836 : {
1837 : ViewShell *pSh, *pStartSh;
1838 8669 : pSh = pStartSh = GetCurrentViewShell();
1839 8669 : do {
1840 8669 : if( pSh->ActionPend() )
1841 : {
1842 0 : if( pTimer )
1843 0 : pTimer->Start();
1844 0 : return 0;
1845 : }
1846 8669 : pSh = (ViewShell*)pSh->GetNext();
1847 : } while( pSh != pStartSh );
1848 :
1849 8669 : if( pTmpRoot->IsNeedGrammarCheck() )
1850 : {
1851 8669 : sal_Bool bIsOnlineSpell = pSh->GetViewOptions()->IsOnlineSpell();
1852 8669 : sal_Bool bIsAutoGrammar = sal_False;
1853 : SvtLinguConfig().GetProperty( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1854 8669 : UPN_IS_GRAMMAR_AUTO )) ) >>= bIsAutoGrammar;
1855 :
1856 8669 : if (bIsOnlineSpell && bIsAutoGrammar)
1857 8669 : StartGrammarChecking( *this );
1858 : }
1859 : SwFldUpdateFlags nFldUpdFlag;
1860 8669 : std::set<SwRootFrm*> aAllLayouts = GetAllLayouts();//swmod 080320
1861 8669 : std::set<SwRootFrm*>::iterator pLayIter = aAllLayouts.begin();
1862 16214 : for ( ;pLayIter != aAllLayouts.end();++pLayIter )
1863 : {
1864 8669 : if ((*pLayIter)->IsIdleFormat())
1865 : {
1866 1124 : (*pLayIter)->GetCurrShell()->LayoutIdle();
1867 1124 : break;
1868 : }
1869 : }
1870 8669 : bool bAllValid = pLayIter == aAllLayouts.end() ? 1 : 0;
1871 23775 : if( bAllValid && ( AUTOUPD_FIELD_ONLY ==
1872 7545 : ( nFldUpdFlag = getFieldUpdateFlags(true) )
1873 : || AUTOUPD_FIELD_AND_CHARTS == nFldUpdFlag ) &&
1874 7545 : GetUpdtFlds().IsFieldsDirty() &&
1875 8 : !GetUpdtFlds().IsInUpdateFlds() &&
1876 8 : !IsExpFldsLocked()
1877 : // If we switch the field name the Fields are not updated.
1878 : // So the "backgorund update" should always be carried out
1879 : /* && !pStartSh->GetViewOptions()->IsFldName()*/ )
1880 : {
1881 : // Action brackets!
1882 8 : GetUpdtFlds().SetInUpdateFlds( true );
1883 :
1884 8 : pTmpRoot->StartAllAction();
1885 :
1886 : // no jump on update of fields #i85168#
1887 8 : const sal_Bool bOldLockView = pStartSh->IsViewLocked();
1888 8 : pStartSh->LockView( sal_True );
1889 :
1890 8 : GetSysFldType( RES_CHAPTERFLD )->ModifyNotification( 0, 0 ); // ChapterField
1891 8 : UpdateExpFlds( 0, sal_False ); // Updates ExpressionFields
1892 8 : UpdateTblFlds(NULL); // Tables
1893 8 : UpdateRefFlds(NULL); // References
1894 :
1895 8 : pTmpRoot->EndAllAction();
1896 :
1897 8 : pStartSh->LockView( bOldLockView );
1898 :
1899 8 : GetUpdtFlds().SetInUpdateFlds( false );
1900 8 : GetUpdtFlds().SetFieldsDirty( false );
1901 8669 : }
1902 : } //swmod 080219
1903 : #ifdef TIMELOG
1904 : if( pModLogFile && 1 != (long)pModLogFile )
1905 : delete pModLogFile, ((long&)pModLogFile) = 1;
1906 : #endif
1907 8669 : if( pTimer )
1908 8669 : pTimer->Start();
1909 8669 : return 0;
1910 : }
1911 :
1912 0 : IMPL_STATIC_LINK( SwDoc, BackgroundDone, SvxBrushItem*, EMPTYARG )
1913 : {
1914 : ViewShell *pSh, *pStartSh;
1915 0 : pSh = pStartSh = pThis->GetCurrentViewShell(); //swmod 071108//swmod 071225
1916 0 : if( pStartSh )
1917 0 : do {
1918 0 : if( pSh->GetWin() )
1919 : {
1920 : // Make sure to repaint with virtual device
1921 0 : pSh->LockPaint();
1922 0 : pSh->UnlockPaint( sal_True );
1923 : }
1924 0 : pSh = (ViewShell*)pSh->GetNext();
1925 : } while( pSh != pStartSh );
1926 0 : return 0;
1927 : }
1928 :
1929 44 : static String lcl_GetUniqueFlyName( const SwDoc* pDoc, sal_uInt16 nDefStrId )
1930 : {
1931 44 : ResId aId( nDefStrId, *pSwResMgr );
1932 44 : String aName( aId );
1933 44 : xub_StrLen nNmLen = aName.Len();
1934 :
1935 44 : const SwFrmFmts& rFmts = *pDoc->GetSpzFrmFmts();
1936 :
1937 44 : sal_uInt16 nNum, nTmp, nFlagSize = ( rFmts.size() / 8 ) +2;
1938 44 : sal_uInt8* pSetFlags = new sal_uInt8[ nFlagSize ];
1939 : sal_uInt16 n;
1940 :
1941 44 : memset( pSetFlags, 0, nFlagSize );
1942 :
1943 154 : for( n = 0; n < rFmts.size(); ++n )
1944 : {
1945 110 : const SwFrmFmt* pFlyFmt = rFmts[ n ];
1946 210 : if( RES_FLYFRMFMT == pFlyFmt->Which() &&
1947 100 : pFlyFmt->GetName().Match( aName ) == nNmLen )
1948 : {
1949 : // Only get and set the Flag
1950 38 : nNum = static_cast< sal_uInt16 >( pFlyFmt->GetName().Copy( nNmLen ).ToInt32() );
1951 38 : if( nNum-- && nNum < rFmts.size() )
1952 38 : pSetFlags[ nNum / 8 ] |= (0x01 << ( nNum & 0x07 ));
1953 : }
1954 : }
1955 :
1956 : // All numbers are flagged accordingly, so determine the right one
1957 44 : nNum = rFmts.size();
1958 44 : for( n = 0; n < nFlagSize; ++n )
1959 44 : if( 0xff != ( nTmp = pSetFlags[ n ] ))
1960 : {
1961 : // so determine the number
1962 44 : nNum = n * 8;
1963 126 : while( nTmp & 1 )
1964 38 : ++nNum, nTmp >>= 1;
1965 44 : break;
1966 : }
1967 :
1968 44 : delete [] pSetFlags;
1969 44 : return aName += String::CreateFromInt32( ++nNum );
1970 : }
1971 :
1972 2 : String SwDoc::GetUniqueGrfName() const
1973 : {
1974 2 : return lcl_GetUniqueFlyName( this, STR_GRAPHIC_DEFNAME );
1975 : }
1976 :
1977 0 : String SwDoc::GetUniqueOLEName() const
1978 : {
1979 0 : return lcl_GetUniqueFlyName( this, STR_OBJECT_DEFNAME );
1980 : }
1981 :
1982 28 : String SwDoc::GetUniqueFrameName() const
1983 : {
1984 28 : return lcl_GetUniqueFlyName( this, STR_FRAME_DEFNAME );
1985 : }
1986 :
1987 86 : const SwFlyFrmFmt* SwDoc::FindFlyByName( const String& rName, sal_Int8 nNdTyp ) const
1988 : {
1989 86 : const SwFrmFmts& rFmts = *GetSpzFrmFmts();
1990 320 : for( sal_uInt16 n = rFmts.size(); n; )
1991 : {
1992 162 : const SwFrmFmt* pFlyFmt = rFmts[ --n ];
1993 : const SwNodeIndex* pIdx;
1994 190 : if( RES_FLYFRMFMT == pFlyFmt->Which() && pFlyFmt->GetName() == rName &&
1995 14 : 0 != ( pIdx = pFlyFmt->GetCntnt().GetCntntIdx() ) &&
1996 14 : pIdx->GetNode().GetNodes().IsDocNodes() )
1997 : {
1998 14 : if( nNdTyp )
1999 : {
2000 : // query for the right NodeType
2001 0 : const SwNode* pNd = GetNodes()[ pIdx->GetIndex()+1 ];
2002 0 : if( nNdTyp == ND_TEXTNODE
2003 0 : ? !pNd->IsNoTxtNode()
2004 0 : : nNdTyp == pNd->GetNodeType() )
2005 0 : return (SwFlyFrmFmt*)pFlyFmt;
2006 : }
2007 : else
2008 14 : return (SwFlyFrmFmt*)pFlyFmt;
2009 : }
2010 : }
2011 72 : return 0;
2012 : }
2013 :
2014 62 : void SwDoc::SetFlyName( SwFlyFrmFmt& rFmt, const String& rName )
2015 : {
2016 62 : String sName( rName );
2017 62 : if( !rName.Len() || FindFlyByName( rName ) )
2018 : {
2019 14 : sal_uInt16 nTyp = STR_FRAME_DEFNAME;
2020 14 : const SwNodeIndex* pIdx = rFmt.GetCntnt().GetCntntIdx();
2021 14 : if( pIdx && pIdx->GetNode().GetNodes().IsDocNodes() )
2022 14 : switch( GetNodes()[ pIdx->GetIndex() + 1 ]->GetNodeType() )
2023 : {
2024 14 : case ND_GRFNODE: nTyp = STR_GRAPHIC_DEFNAME; break;
2025 0 : case ND_OLENODE: nTyp = STR_OBJECT_DEFNAME; break;
2026 : }
2027 14 : sName = lcl_GetUniqueFlyName( this, nTyp );
2028 : }
2029 62 : rFmt.SetName( sName, sal_True );
2030 62 : SetModified();
2031 62 : }
2032 :
2033 123 : void SwDoc::SetAllUniqueFlyNames()
2034 : {
2035 123 : sal_uInt16 n, nFlyNum = 0, nGrfNum = 0, nOLENum = 0;
2036 :
2037 123 : ResId nFrmId( STR_FRAME_DEFNAME, *pSwResMgr ),
2038 123 : nGrfId( STR_GRAPHIC_DEFNAME, *pSwResMgr ),
2039 123 : nOLEId( STR_OBJECT_DEFNAME, *pSwResMgr );
2040 123 : String sFlyNm( nFrmId );
2041 123 : String sGrfNm( nGrfId );
2042 123 : String sOLENm( nOLEId );
2043 :
2044 123 : if( 255 < ( n = GetSpzFrmFmts()->size() ))
2045 0 : n = 255;
2046 123 : SwFrmFmts aArr;
2047 123 : aArr.reserve( n );
2048 : SwFrmFmt* pFlyFmt;
2049 123 : bool bLoadedFlag = true; // something for the Layout
2050 :
2051 406 : for( n = GetSpzFrmFmts()->size(); n; )
2052 : {
2053 160 : if( RES_FLYFRMFMT == (pFlyFmt = (*GetSpzFrmFmts())[ --n ])->Which() )
2054 : {
2055 62 : sal_uInt16 *pNum = 0;
2056 : xub_StrLen nLen;
2057 62 : const String& rNm = pFlyFmt->GetName();
2058 62 : if( rNm.Len() )
2059 : {
2060 8 : if( rNm.Match( sGrfNm ) == ( nLen = sGrfNm.Len() ))
2061 0 : pNum = &nGrfNum;
2062 8 : else if( rNm.Match( sFlyNm ) == ( nLen = sFlyNm.Len() ))
2063 6 : pNum = &nFlyNum;
2064 2 : else if( rNm.Match( sOLENm ) == ( nLen = sOLENm.Len() ))
2065 2 : pNum = &nOLENum;
2066 :
2067 8 : if ( pNum && *pNum < ( nLen = static_cast< xub_StrLen >( rNm.Copy( nLen ).ToInt32() ) ) )
2068 6 : *pNum = nLen;
2069 : }
2070 : else
2071 : // we want to set that afterwards
2072 54 : aArr.push_back( pFlyFmt );
2073 :
2074 : }
2075 160 : if( bLoadedFlag )
2076 : {
2077 45 : const SwFmtAnchor& rAnchor = pFlyFmt->GetAnchor();
2078 114 : if (((FLY_AT_PAGE == rAnchor.GetAnchorId()) &&
2079 1 : rAnchor.GetCntntAnchor()) ||
2080 : // Or are DrawObjects adjusted relatively to something?
2081 45 : ( RES_DRAWFRMFMT == pFlyFmt->Which() && (
2082 : SFX_ITEM_SET == pFlyFmt->GetItemState(
2083 23 : RES_VERT_ORIENT )||
2084 : SFX_ITEM_SET == pFlyFmt->GetItemState(
2085 0 : RES_HORI_ORIENT ))) )
2086 : {
2087 23 : bLoadedFlag = false;
2088 : }
2089 : }
2090 : }
2091 :
2092 : const SwNodeIndex* pIdx;
2093 :
2094 300 : for( n = aArr.size(); n; )
2095 108 : if( 0 != ( pIdx = ( pFlyFmt = aArr[ --n ])->GetCntnt().GetCntntIdx() )
2096 54 : && pIdx->GetNode().GetNodes().IsDocNodes() )
2097 : {
2098 : sal_uInt16 nNum;
2099 54 : String sNm;
2100 54 : switch( GetNodes()[ pIdx->GetIndex() + 1 ]->GetNodeType() )
2101 : {
2102 : case ND_GRFNODE:
2103 40 : sNm = sGrfNm;
2104 40 : nNum = ++nGrfNum;
2105 40 : break;
2106 : case ND_OLENODE:
2107 0 : sNm = sOLENm;
2108 0 : nNum = ++nOLENum;
2109 0 : break;
2110 : default:
2111 14 : sNm = sFlyNm;
2112 14 : nNum = ++nFlyNum;
2113 14 : break;
2114 : }
2115 54 : pFlyFmt->SetName( sNm += String::CreateFromInt32( nNum ));
2116 : }
2117 123 : aArr.clear();
2118 :
2119 123 : if( !GetFtnIdxs().empty() )
2120 : {
2121 6 : SwTxtFtn::SetUniqueSeqRefNo( *this );
2122 : // #i52775# Chapter footnotes did not get updated correctly.
2123 : // Calling UpdateAllFtn() instead of UpdateFtn() solves this problem,
2124 : // but I do not dare to call UpdateAllFtn() in all cases: Safety first.
2125 6 : if ( FTNNUM_CHAPTER == GetFtnInfo().eNum )
2126 : {
2127 0 : GetFtnIdxs().UpdateAllFtn();
2128 : }
2129 : else
2130 : {
2131 6 : SwNodeIndex aTmp( GetNodes() );
2132 6 : GetFtnIdxs().UpdateFtn( aTmp );
2133 : }
2134 : }
2135 :
2136 : // Found a new document, but not a page anchored Frame/DrawObjects
2137 : // that are anchored to another Node.
2138 123 : if( bLoadedFlag )
2139 100 : SetLoaded( sal_True );
2140 123 : }
2141 :
2142 144 : bool SwDoc::IsInHeaderFooter( const SwNodeIndex& rIdx ) const
2143 : {
2144 : // If there's a Layout, use it!
2145 : // That can also be a Fly in a Fly in the Header.
2146 : // Is also used by sw3io, to determine if a Redline object is
2147 : // in the Header or Footer.
2148 : // Because Redlines are also attached to Start and EndNoden,
2149 : // the Index must not necessarily be from a ContentNode.
2150 144 : SwNode* pNd = &rIdx.GetNode();
2151 144 : if( pNd->IsCntntNode() && pCurrentView )//swmod 071029//swmod 071225
2152 : {
2153 90 : const SwFrm *pFrm = pNd->GetCntntNode()->getLayoutFrm( GetCurrentLayout() );
2154 90 : if( pFrm )
2155 : {
2156 90 : const SwFrm *pUp = pFrm->GetUpper();
2157 420 : while ( pUp && !pUp->IsHeaderFrm() && !pUp->IsFooterFrm() )
2158 : {
2159 240 : if ( pUp->IsFlyFrm() )
2160 0 : pUp = ((SwFlyFrm*)pUp)->GetAnchorFrm();
2161 240 : pUp = pUp->GetUpper();
2162 : }
2163 90 : if ( pUp )
2164 16 : return true;
2165 :
2166 74 : return false;
2167 : }
2168 : }
2169 :
2170 :
2171 54 : const SwNode* pFlyNd = pNd->FindFlyStartNode();
2172 108 : while( pFlyNd )
2173 : {
2174 : // get up by using the Anchor
2175 : sal_uInt16 n;
2176 0 : for( n = 0; n < GetSpzFrmFmts()->size(); ++n )
2177 : {
2178 0 : const SwFrmFmt* pFmt = (*GetSpzFrmFmts())[ n ];
2179 0 : const SwNodeIndex* pIdx = pFmt->GetCntnt().GetCntntIdx();
2180 0 : if( pIdx && pFlyNd == &pIdx->GetNode() )
2181 : {
2182 0 : const SwFmtAnchor& rAnchor = pFmt->GetAnchor();
2183 0 : if ((FLY_AT_PAGE == rAnchor.GetAnchorId()) ||
2184 0 : !rAnchor.GetCntntAnchor() )
2185 : {
2186 0 : return false;
2187 : }
2188 :
2189 0 : pNd = &rAnchor.GetCntntAnchor()->nNode.GetNode();
2190 0 : pFlyNd = pNd->FindFlyStartNode();
2191 0 : break;
2192 : }
2193 : }
2194 0 : if( n >= GetSpzFrmFmts()->size() )
2195 : {
2196 : OSL_ENSURE( mbInReading, "Found a FlySection but not a Format!" );
2197 0 : return false;
2198 : }
2199 : }
2200 :
2201 54 : return 0 != pNd->FindHeaderStartNode() ||
2202 54 : 0 != pNd->FindFooterStartNode();
2203 : }
2204 :
2205 1351 : short SwDoc::GetTextDirection( const SwPosition& rPos,
2206 : const Point* pPt ) const
2207 : {
2208 1351 : short nRet = -1;
2209 :
2210 1351 : SwCntntNode *pNd = rPos.nNode.GetNode().GetCntntNode();
2211 :
2212 : // #i42921# - use new method <SwCntntNode::GetTextDirection(..)>
2213 1351 : if ( pNd )
2214 : {
2215 1351 : nRet = pNd->GetTextDirection( rPos, pPt );
2216 : }
2217 1351 : if ( nRet == -1 )
2218 : {
2219 0 : const SvxFrameDirectionItem* pItem = 0;
2220 0 : if( pNd )
2221 : {
2222 : // Are we in a FlyFrame? Then look at that for the correct attribute
2223 0 : const SwFrmFmt* pFlyFmt = pNd->GetFlyFmt();
2224 0 : while( pFlyFmt )
2225 : {
2226 0 : pItem = &pFlyFmt->GetFrmDir();
2227 0 : if( FRMDIR_ENVIRONMENT == pItem->GetValue() )
2228 : {
2229 0 : pItem = 0;
2230 0 : const SwFmtAnchor* pAnchor = &pFlyFmt->GetAnchor();
2231 0 : if ((FLY_AT_PAGE != pAnchor->GetAnchorId()) &&
2232 0 : pAnchor->GetCntntAnchor())
2233 : {
2234 0 : pFlyFmt = pAnchor->GetCntntAnchor()->nNode.
2235 0 : GetNode().GetFlyFmt();
2236 : }
2237 : else
2238 0 : pFlyFmt = 0;
2239 : }
2240 : else
2241 0 : pFlyFmt = 0;
2242 : }
2243 :
2244 0 : if( !pItem )
2245 : {
2246 0 : const SwPageDesc* pPgDsc = pNd->FindPageDesc( sal_False );
2247 0 : if( pPgDsc )
2248 0 : pItem = &pPgDsc->GetMaster().GetFrmDir();
2249 : }
2250 : }
2251 0 : if( !pItem )
2252 0 : pItem = (SvxFrameDirectionItem*)&GetAttrPool().GetDefaultItem(
2253 0 : RES_FRAMEDIR );
2254 0 : nRet = pItem->GetValue();
2255 : }
2256 1351 : return nRet;
2257 : }
2258 :
2259 0 : bool SwDoc::IsInVerticalText( const SwPosition& rPos, const Point* pPt ) const
2260 : {
2261 0 : const short nDir = GetTextDirection( rPos, pPt );
2262 0 : return FRMDIR_VERT_TOP_RIGHT == nDir || FRMDIR_VERT_TOP_LEFT == nDir;
2263 : }
2264 :
2265 842 : void SwDoc::SetCurrentViewShell( ViewShell* pNew )
2266 : {
2267 842 : pCurrentView = pNew;
2268 842 : }
2269 :
2270 4746 : SwLayouter* SwDoc::GetLayouter()
2271 : {
2272 4746 : return pLayouter;
2273 : }
2274 :
2275 489407 : const SwLayouter* SwDoc::GetLayouter() const
2276 : {
2277 489407 : return pLayouter;
2278 : }
2279 :
2280 478 : void SwDoc::SetLayouter( SwLayouter* pNew )
2281 : {
2282 478 : pLayouter = pNew;
2283 478 : }
2284 :
2285 13380 : const ViewShell *SwDoc::GetCurrentViewShell() const
2286 : {
2287 13380 : return pCurrentView;
2288 : }
2289 :
2290 231126 : ViewShell *SwDoc::GetCurrentViewShell()
2291 : {
2292 231126 : return pCurrentView;
2293 : }
2294 :
2295 : //swmod 080219
2296 : // It must be able to communicate to a ViewShell. This is going to be removed later.
2297 6581 : const SwRootFrm *SwDoc::GetCurrentLayout() const
2298 : {
2299 6581 : if(GetCurrentViewShell())
2300 6489 : return GetCurrentViewShell()->GetLayout();
2301 92 : return 0;
2302 : }
2303 :
2304 54760 : SwRootFrm *SwDoc::GetCurrentLayout()
2305 : {
2306 54760 : if(GetCurrentViewShell())
2307 19878 : return GetCurrentViewShell()->GetLayout();
2308 34882 : return 0;
2309 : }
2310 :
2311 830 : bool SwDoc::HasLayout() const
2312 : {
2313 : // if there is a view, there is always a layout
2314 830 : return (pCurrentView != 0);
2315 : }
2316 :
2317 8669 : std::set<SwRootFrm*> SwDoc::GetAllLayouts()
2318 : {
2319 8669 : std::set<SwRootFrm*> aAllLayouts;
2320 8669 : ViewShell *pStart = GetCurrentViewShell();
2321 8669 : ViewShell *pTemp = pStart;
2322 8669 : if ( pTemp )
2323 : {
2324 8669 : do
2325 : {
2326 8669 : if (pTemp->GetLayout())
2327 : {
2328 8669 : aAllLayouts.insert(pTemp->GetLayout());
2329 8669 : pTemp = (ViewShell*)pTemp->GetNext();
2330 : }
2331 : } while(pTemp!=pStart);
2332 : }
2333 :
2334 8669 : return aAllLayouts;
2335 : } //swmod 070825
2336 :
2337 478 : void SwDoc::ShareLayout(boost::shared_ptr<SwRootFrm>& rPtr)
2338 : {
2339 478 : pLayoutPtr = rPtr;
2340 478 : }
2341 :
2342 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|