1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/embed/ElementModes.hpp>
21 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include "comphelper/anytostring.hxx"
24 #include "cppuhelper/exc_hlp.hxx"
26 #include <vcl/wrkwin.hxx>
27 #include <sfx2/docfile.hxx>
28 #include <sot/storage.hxx>
29 #include <sfx2/app.hxx>
30 #include <svl/itemset.hxx>
32 #include <unotools/ucbstreamhelper.hxx>
33 #include <sfx2/fcontnr.hxx>
34 #include <svx/svdopath.hxx>
35 #include <svx/svditer.hxx>
36 #include <svl/style.hxx>
37 #include <sfx2/linkmgr.hxx>
38 #include <svx/svdpagv.hxx>
39 #include <svx/svdogrp.hxx>
40 #include <svx/svdundo.hxx>
41 #include <vcl/msgbox.hxx>
42 #include <sot/formats.hxx>
45 #include "drawdoc.hxx"
47 #include "stlpool.hxx"
48 #include "sdresid.hxx"
49 #include "sdiocmpt.hxx"
51 #include "anminfo.hxx"
52 #include "customshowlist.hxx"
54 #include "../ui/inc/unmovss.hxx"
55 #include "../ui/inc/unchss.hxx"
56 #include "../ui/inc/unprlout.hxx"
57 #include "../ui/inc/DrawDocShell.hxx"
58 #include "../ui/inc/GraphicDocShell.hxx"
59 #include "../ui/inc/ViewShell.hxx"
60 #include "../ui/inc/View.hxx"
61 #include "../ui/inc/cfgids.hxx"
62 #include "../ui/inc/strings.hrc"
64 using namespace ::com::sun::star
;
66 /** Concrete incarnations get called by lcl_IterateBookmarkPages, for
67 every page in the bookmark document/list
70 class InsertBookmarkAsPage_FindDuplicateLayouts
73 InsertBookmarkAsPage_FindDuplicateLayouts( std::vector
<OUString
> &rLayoutsToTransfer
)
74 : mrLayoutsToTransfer(rLayoutsToTransfer
) {}
75 void operator()( SdDrawDocument
&, SdPage
* );
77 std::vector
<OUString
> &mrLayoutsToTransfer
;
80 void InsertBookmarkAsPage_FindDuplicateLayouts::operator()( SdDrawDocument
& rDoc
, SdPage
* pBMMPage
)
82 // now check for duplicate masterpage and layout names
83 // ===================================================
85 String
aFullNameLayout( pBMMPage
->GetLayoutName() );
86 aFullNameLayout
.Erase( aFullNameLayout
.SearchAscii( SD_LT_SEPARATOR
));
88 OUString
aLayout(aFullNameLayout
);
90 std::vector
<OUString
>::const_iterator pIter
=
91 find(mrLayoutsToTransfer
.begin(),mrLayoutsToTransfer
.end(),aLayout
);
93 bool bFound
= pIter
!= mrLayoutsToTransfer
.end();
95 const sal_uInt16 nMPageCount
= rDoc
.GetMasterPageCount();
96 for (sal_uInt16 nMPage
= 0; nMPage
< nMPageCount
&& !bFound
; nMPage
++)
98 // Do the layouts already exist within the document?
99 SdPage
* pTestPage
= (SdPage
*) rDoc
.GetMasterPage(nMPage
);
100 String
aFullTest(pTestPage
->GetLayoutName());
101 aFullTest
.Erase( aFullTest
.SearchAscii( SD_LT_SEPARATOR
));
103 OUString
aTest(aFullTest
);
105 if (aTest
== aLayout
)
110 mrLayoutsToTransfer
.push_back(aLayout
);
113 // Inserts a bookmark as a page
114 static void lcl_IterateBookmarkPages( SdDrawDocument
&rDoc
, SdDrawDocument
* pBookmarkDoc
,
115 const std::vector
<OUString
> &rBookmarkList
, sal_uInt16 nBMSdPageCount
,
116 InsertBookmarkAsPage_FindDuplicateLayouts
& rPageIterator
)
119 // Refactored copy'n'pasted layout name collection from InsertBookmarkAsPage
123 if( rBookmarkList
.empty() )
125 // no list? whole source document
126 nEndPos
= nBMSdPageCount
;
130 // bookmark list? number of entries
131 nEndPos
= rBookmarkList
.size();
136 // iterate over number of pages to insert
137 for (nPos
= 0; nPos
< nEndPos
; ++nPos
)
139 // the master page associated to the nPos'th page to insert
140 SdPage
* pBMMPage
= NULL
;
142 if( rBookmarkList
.empty() )
144 // simply take master page of nPos'th page in source document
145 pBMMPage
= (SdPage
*)(&(pBookmarkDoc
->GetSdPage((sal_uInt16
)nPos
, PK_STANDARD
)->TRG_GetMasterPage()));
149 // fetch nPos'th entry from bookmark list, and determine master page
150 String
aBMPgName(rBookmarkList
[nPos
]);
151 sal_Bool bIsMasterPage
;
153 sal_uInt16 nBMPage
= pBookmarkDoc
->GetPageByName( aBMPgName
, bIsMasterPage
);
155 if (nBMPage
!= SDRPAGE_NOTFOUND
)
157 pBMPage
= (SdPage
*) pBookmarkDoc
->GetPage(nBMPage
);
164 // enforce that bookmarked page is a standard page and not already a master page
165 if (pBMPage
&& pBMPage
->GetPageKind()==PK_STANDARD
&& !pBMPage
->IsMasterPage())
167 const sal_uInt16 nBMSdPage
= (nBMPage
- 1) / 2;
168 pBMMPage
= (SdPage
*) (&(pBookmarkDoc
->GetSdPage(nBMSdPage
, PK_STANDARD
)->TRG_GetMasterPage()));
172 // successfully determined valid (bookmarked) page?
176 rPageIterator( rDoc
, pBMMPage
);
181 // Opens a bookmark document
182 SdDrawDocument
* SdDrawDocument::OpenBookmarkDoc(SfxMedium
& rMedium
)
184 sal_Bool bOK
= sal_True
;
185 SdDrawDocument
* pBookmarkDoc
= NULL
;
186 String aBookmarkName
= rMedium
.GetName();
187 const SfxFilter
* pFilter
= rMedium
.GetFilter();
190 rMedium
.UseInteractionHandler( sal_True
);
191 SFX_APP()->GetFilterMatcher().GuessFilter( rMedium
, &pFilter
);
198 else if ( maBookmarkFile
!= aBookmarkName
&& aBookmarkName
.Len() )
200 sal_Bool bCreateGraphicShell
= pFilter
->GetServiceName() == "com.sun.star.drawing.DrawingDocument";
201 sal_Bool bCreateImpressShell
= pFilter
->GetServiceName() == "com.sun.star.presentation.PresentationDocument";
202 if ( bCreateGraphicShell
|| bCreateImpressShell
)
206 // Create a DocShell, as OLE objects might be contained in the
207 // document. (Persist)
208 // If that wasn't the case, we could load the model directly.
209 if ( bCreateGraphicShell
)
211 mxBookmarkDocShRef
= new ::sd::GraphicDocShell(SFX_CREATE_MODE_STANDARD
, sal_True
);
214 mxBookmarkDocShRef
= new ::sd::DrawDocShell(SFX_CREATE_MODE_STANDARD
, sal_True
);
216 bOK
= mxBookmarkDocShRef
->DoLoad(&rMedium
);
219 maBookmarkFile
= aBookmarkName
;
220 pBookmarkDoc
= mxBookmarkDocShRef
->GetDoc();
225 DBG_ASSERT(aBookmarkName
.Len(), "Empty document name!");
229 ErrorBox
aErrorBox( NULL
, (WinBits
)WB_OK
, String(SdResId(STR_READ_DATA_ERROR
)));
235 else if (mxBookmarkDocShRef
.Is())
237 pBookmarkDoc
= mxBookmarkDocShRef
->GetDoc();
240 return(pBookmarkDoc
);
243 // Opens a bookmark document
244 SdDrawDocument
* SdDrawDocument::OpenBookmarkDoc(const String
& rBookmarkFile
)
246 SdDrawDocument
* pBookmarkDoc
= NULL
;
248 if (maBookmarkFile
!= rBookmarkFile
&& rBookmarkFile
.Len())
250 SfxMedium
* pMedium
= new SfxMedium( rBookmarkFile
, STREAM_READ
);
251 pBookmarkDoc
= OpenBookmarkDoc(*pMedium
);
253 else if (mxBookmarkDocShRef
.Is())
255 pBookmarkDoc
= mxBookmarkDocShRef
->GetDoc();
258 return(pBookmarkDoc
);
261 // Inserts a bookmark (page or object)
262 sal_Bool
SdDrawDocument::InsertBookmark(
263 const std::vector
<OUString
> &rBookmarkList
, // List of names of the bookmarks to be inserted
264 std::vector
<OUString
> &rExchangeList
, // List of the names to be used
265 sal_Bool bLink
, // Insert bookmarks as links?
266 sal_Bool bReplace
, // Replace current default and notes pages?
267 sal_uInt16 nInsertPos
, // Insertion position of pages
268 sal_Bool bNoDialogs
, // Don't show dialogs
269 ::sd::DrawDocShell
* pBookmarkDocSh
, // If set, this is the source document
270 sal_Bool bCopy
, // Copy the pages?
271 Point
* pObjPos
) // Insertion position of objects
273 sal_Bool bOK
= sal_True
;
274 sal_Bool bInsertPages
= sal_False
;
276 if (rBookmarkList
.empty())
279 bInsertPages
= sal_True
;
283 SdDrawDocument
* pBookmarkDoc
= NULL
;
284 String aBookmarkName
;
288 pBookmarkDoc
= pBookmarkDocSh
->GetDoc();
289 aBookmarkName
= pBookmarkDocSh
->GetMedium()->GetName();
291 else if ( mxBookmarkDocShRef
.Is() )
293 pBookmarkDoc
= mxBookmarkDocShRef
->GetDoc();
294 aBookmarkName
= maBookmarkFile
;
299 std::vector
<OUString
>::const_iterator pIter
;
300 for ( pIter
= rBookmarkList
.begin(); bOK
&& pIter
!= rBookmarkList
.end() && !bInsertPages
; ++pIter
)
302 // Is there a page name in the bookmark list?
303 String
aBMPgName(*pIter
);
304 sal_Bool bIsMasterPage
;
306 if( pBookmarkDoc
->GetPageByName( aBMPgName
, bIsMasterPage
) != SDRPAGE_NOTFOUND
)
309 bInsertPages
= sal_True
;
314 sal_Bool bCalcObjCount
= !rExchangeList
.empty();
316 if ( bOK
&& bInsertPages
)
318 // Insert all page bookmarks
319 bOK
= InsertBookmarkAsPage(rBookmarkList
, &rExchangeList
, bLink
, bReplace
,
320 nInsertPos
, bNoDialogs
, pBookmarkDocSh
, bCopy
, sal_True
, sal_False
);
323 if ( bOK
&& !rBookmarkList
.empty() )
325 // Insert all object bookmarks
326 bOK
= InsertBookmarkAsObject(rBookmarkList
, rExchangeList
, bLink
,
327 pBookmarkDocSh
, pObjPos
, bCalcObjCount
);
337 lcl_removeUnusedStyles(SfxStyleSheetBasePool
* const pStyleSheetPool
, SdStyleSheetVector
& rStyles
)
339 SdStyleSheetVector aUsedStyles
;
340 aUsedStyles
.reserve(rStyles
.size());
341 for (SdStyleSheetVector::const_iterator
aIt(rStyles
.begin()), aLast(rStyles
.end()); aIt
!= aLast
; ++aIt
)
343 if ((*aIt
)->IsUsed())
344 aUsedStyles
.push_back(*aIt
);
346 pStyleSheetPool
->Remove((*aIt
).get());
348 rStyles
= aUsedStyles
;
353 sal_Bool
SdDrawDocument::InsertBookmarkAsPage(
354 const std::vector
<OUString
> &rBookmarkList
,
355 std::vector
<OUString
> *pExchangeList
, // List of names to be used
358 sal_uInt16 nInsertPos
,
360 ::sd::DrawDocShell
* pBookmarkDocSh
,
362 sal_Bool bMergeMasterPages
,
363 sal_Bool bPreservePageNames
)
365 sal_Bool bOK
= sal_True
;
366 sal_Bool bContinue
= sal_True
;
367 sal_Bool bScaleObjects
= sal_False
;
368 sal_uInt16 nReplacedStandardPages
= 0;
370 SdDrawDocument
* pBookmarkDoc
= NULL
;
371 String aBookmarkName
;
375 pBookmarkDoc
= pBookmarkDocSh
->GetDoc();
377 if (pBookmarkDocSh
->GetMedium())
379 aBookmarkName
= pBookmarkDocSh
->GetMedium()->GetName();
382 else if ( mxBookmarkDocShRef
.Is() )
384 pBookmarkDoc
= mxBookmarkDocShRef
->GetDoc();
385 aBookmarkName
= maBookmarkFile
;
392 const sal_uInt16 nSdPageCount
= GetSdPageCount(PK_STANDARD
);
393 const sal_uInt16 nBMSdPageCount
= pBookmarkDoc
->GetSdPageCount(PK_STANDARD
);
394 const sal_uInt16 nMPageCount
= GetMasterPageCount();
396 if (nSdPageCount
==0 || nBMSdPageCount
==0 || nMPageCount
==0)
398 bContinue
= bOK
= sal_False
;
402 // Store the size and some other properties of the first page and notes
403 // page so that inserted pages can be properly scaled even when inserted
404 // before the first page.
405 // Note that the pointers are used later on as general page pointers.
406 SdPage
* pRefPage
= GetSdPage(0, PK_STANDARD
);
407 Size
aSize(pRefPage
->GetSize());
408 sal_Int32 nLeft
= pRefPage
->GetLftBorder();
409 sal_Int32 nRight
= pRefPage
->GetRgtBorder();
410 sal_Int32 nUpper
= pRefPage
->GetUppBorder();
411 sal_Int32 nLower
= pRefPage
->GetLwrBorder();
412 Orientation eOrient
= pRefPage
->GetOrientation();
414 SdPage
* pNPage
= GetSdPage(0, PK_NOTES
);
415 Size
aNSize(pNPage
->GetSize());
416 sal_Int32 nNLeft
= pNPage
->GetLftBorder();
417 sal_Int32 nNRight
= pNPage
->GetRgtBorder();
418 sal_Int32 nNUpper
= pNPage
->GetUppBorder();
419 sal_Int32 nNLower
= pNPage
->GetLwrBorder();
420 Orientation eNOrient
= pRefPage
->GetOrientation();
422 // Adapt page size and margins to those of the later pages?
423 pRefPage
= GetSdPage(nSdPageCount
- 1, PK_STANDARD
);
427 if( rBookmarkList
.empty() )
428 bScaleObjects
= pRefPage
->IsScaleObjects();
430 bScaleObjects
= sal_True
;
434 SdPage
* pBMPage
= pBookmarkDoc
->GetSdPage(0,PK_STANDARD
);
436 if (pBMPage
->GetSize() != pRefPage
->GetSize() ||
437 pBMPage
->GetLftBorder() != pRefPage
->GetLftBorder() ||
438 pBMPage
->GetRgtBorder() != pRefPage
->GetRgtBorder() ||
439 pBMPage
->GetUppBorder() != pRefPage
->GetUppBorder() ||
440 pBMPage
->GetLwrBorder() != pRefPage
->GetLwrBorder())
442 String
aStr(SdResId(STR_SCALE_OBJECTS
));
443 sal_uInt16 nBut
= QueryBox( NULL
, WB_YES_NO_CANCEL
, aStr
).Execute();
445 bScaleObjects
= nBut
== RET_YES
;
446 bContinue
= nBut
!= RET_CANCEL
;
456 // Get the necessary presentation stylesheets and transfer them before
457 // the pages, else, the text objects won't reference their styles anymore.
458 ::svl::IUndoManager
* pUndoMgr
= NULL
;
461 pUndoMgr
= mpDocSh
->GetUndoManager();
462 pUndoMgr
->EnterListAction(String(SdResId(STR_UNDO_INSERTPAGES
)), String());
466 // Refactored copy'n'pasted layout name collection into IterateBookmarkPages
468 std::vector
<OUString
> aLayoutsToTransfer
;
469 InsertBookmarkAsPage_FindDuplicateLayouts
aSearchFunctor( aLayoutsToTransfer
);
470 lcl_IterateBookmarkPages( *this, pBookmarkDoc
, rBookmarkList
, nBMSdPageCount
, aSearchFunctor
);
473 // Copy the style that we actually need.
474 SdStyleSheetPool
* pBookmarkStyleSheetPool
= dynamic_cast<SdStyleSheetPool
*>(pBookmarkDoc
->GetStyleSheetPool());
475 SdStyleSheetPool
* pStyleSheetPool
= dynamic_cast<SdStyleSheetPool
*>(GetStyleSheetPool());
477 // When copying styles, also copy the master pages!
478 if( !aLayoutsToTransfer
.empty() )
479 bMergeMasterPages
= sal_True
;
481 std::vector
<OUString
>::const_iterator pIter
;
482 for ( pIter
= aLayoutsToTransfer
.begin(); pIter
!= aLayoutsToTransfer
.end(); ++pIter
)
484 SdStyleSheetVector aCreatedStyles
;
485 String layoutName
= *pIter
;
487 pStyleSheetPool
->CopyLayoutSheets(layoutName
, *pBookmarkStyleSheetPool
,aCreatedStyles
);
489 if(!aCreatedStyles
.empty())
493 SdMoveStyleSheetsUndoAction
* pMovStyles
= new SdMoveStyleSheetsUndoAction(this, aCreatedStyles
, sal_True
);
494 pUndoMgr
->AddUndoAction(pMovStyles
);
499 // Copy styles. This unconditionally copies all styles, even those
500 // that are not used in any of the inserted pages. The unused styles
501 // are then removed at the end of the function, where we also create
502 // undo records for the inserted styles.
503 SdStyleSheetVector aNewGraphicStyles
;
504 pStyleSheetPool
->CopyGraphicSheets(*pBookmarkStyleSheetPool
, aNewGraphicStyles
);
505 SdStyleSheetVector aNewCellStyles
;
506 pStyleSheetPool
->CopyCellSheets(*pBookmarkStyleSheetPool
, aNewCellStyles
);
508 // TODO handle undo of table styles too
509 pStyleSheetPool
->CopyTableStyles(*pBookmarkStyleSheetPool
);
513 const bool bUndo
= IsUndoEnabled();
516 BegUndo(String(SdResId(STR_UNDO_INSERTPAGES
)));
518 if (rBookmarkList
.empty())
520 if (nInsertPos
>= GetPageCount())
522 // Add pages to the end
523 nInsertPos
= GetPageCount();
526 sal_uInt16 nActualInsertPos
= nInsertPos
;
528 sal_uInt16 nBMSdPage
;
529 std::set
<sal_uInt16
> aRenameSet
;
530 std::map
<sal_uInt16
,OUString
> aNameMap
;
532 for (nBMSdPage
=0; nBMSdPage
< nBMSdPageCount
; nBMSdPage
++)
534 SdPage
* pBMPage
= pBookmarkDoc
->GetSdPage(nBMSdPage
, PK_STANDARD
);
535 String
sName( pBMPage
->GetName() );
536 sal_Bool bIsMasterPage
;
540 // Remember the names of all pages
541 aNameMap
.insert(std::make_pair(nBMSdPage
,sName
));
544 // Have to check for duplicate names here, too
545 // don't change name if source and dest model are the same!
546 if( pBookmarkDoc
!= this &&
547 GetPageByName(sName
, bIsMasterPage
) != SDRPAGE_NOTFOUND
)
549 // delay renaming *after* pages are copied (might destroy source otherwise)
550 aRenameSet
.insert(nBMSdPage
);
555 1, // Not the handout page
556 0xFFFF, // But all others
557 nActualInsertPos
, // Insert at position ...
558 bMergeMasterPages
, // Move master pages?
559 sal_False
, // But only the master pages used
560 sal_True
, // Create an undo action
561 bCopy
); // Copy (or merge) pages?
563 for (nBMSdPage
=0; nBMSdPage
< nBMSdPageCount
; nBMSdPage
++)
565 SdPage
* pPage
= (SdPage
*) GetPage(nActualInsertPos
);
566 SdPage
* pNotesPage
= (SdPage
*) GetPage(nActualInsertPos
+1);
568 // delay renaming *after* pages are copied (might destroy source otherwise)
569 if( aRenameSet
.find(nBMSdPage
) != aRenameSet
.end() )
571 // Page name already in use -> Use default name for default and
573 pPage
->SetName(String());
574 pNotesPage
->SetName(String());
579 String
aName(aNameMap
[nBMSdPage
]);
581 // Assemble all link names
582 pPage
->SetFileName(aBookmarkName
);
583 pPage
->SetBookmarkName(aName
);
584 pPage
->SetModel(this);
587 nActualInsertPos
+= 2;
592 // Insert selected pages
595 if (nInsertPos
>= GetPageCount())
597 // Add pages to the end
598 bReplace
= sal_False
;
599 nInsertPos
= GetPageCount();
602 sal_uInt16 nActualInsertPos
= nInsertPos
;
604 // Collect the bookmarked pages
605 ::std::vector
<SdPage
*> aBookmarkedPages (rBookmarkList
.size(), NULL
);
606 for ( size_t nPos
= 0, n
= rBookmarkList
.size(); nPos
< n
; ++nPos
)
608 String
aPgName(rBookmarkList
[nPos
]);
609 sal_Bool bIsMasterPage
;
610 sal_uInt16 nBMPage
= pBookmarkDoc
->GetPageByName( aPgName
, bIsMasterPage
);
612 if (nBMPage
!= SDRPAGE_NOTFOUND
)
614 aBookmarkedPages
[nPos
] = dynamic_cast<SdPage
*>(pBookmarkDoc
->GetPage(nBMPage
));
618 for ( size_t nPos
= 0, n
= rBookmarkList
.size(); nPos
< n
; ++nPos
)
620 pBMPage
= aBookmarkedPages
[nPos
];
621 sal_uInt16 nBMPage
= pBMPage
!=NULL
? pBMPage
->GetPageNum() : SDRPAGE_NOTFOUND
;
623 if (pBMPage
&& pBMPage
->GetPageKind()==PK_STANDARD
&& !pBMPage
->IsMasterPage())
625 // It has to be a default page
626 sal_Bool bMustRename
= sal_False
;
628 // delay renaming *after* pages are copied (might destroy source otherwise)
629 // don't change name if source and dest model are the same!
630 // avoid renaming if replacing the same page
631 String
aPgName(rBookmarkList
[nPos
]);
632 sal_Bool bIsMasterPage
;
633 sal_uInt16 nPageSameName
= GetPageByName(aPgName
, bIsMasterPage
);
634 if( pBookmarkDoc
!= this &&
635 nPageSameName
!= SDRPAGE_NOTFOUND
&&
637 nPageSameName
!= nActualInsertPos
) )
639 bMustRename
= sal_True
;
642 SdPage
* pBookmarkPage
= pBMPage
;
645 ReplacePageInCustomShows( dynamic_cast< SdPage
* >( GetPage( nActualInsertPos
) ), pBookmarkPage
);
649 nBMPage
, // From page (default page)
650 nBMPage
+1, // To page (notes page)
651 nActualInsertPos
, // Insert at position
652 bMergeMasterPages
, // Move master pages?
653 sal_False
, // But only the master pages used
654 sal_True
, // Create undo action
655 bCopy
); // Copy (or merge) pages?
659 if( GetPage( nActualInsertPos
) != pBookmarkPage
)
661 // bookmark page was not moved but cloned, so update custom shows again
662 ReplacePageInCustomShows( pBookmarkPage
, dynamic_cast< SdPage
* >( GetPage( nActualInsertPos
) ) );
668 // Page name already in use -> use default name for default and
670 SdPage
* pPage
= (SdPage
*) GetPage(nActualInsertPos
);
671 pPage
->SetName(String());
672 SdPage
* pNotesPage
= (SdPage
*) GetPage(nActualInsertPos
+1);
673 pNotesPage
->SetName(String());
678 SdPage
* pPage
= (SdPage
*) GetPage(nActualInsertPos
);
679 pPage
->SetFileName(aBookmarkName
);
680 pPage
->SetBookmarkName(aPgName
);
681 pPage
->SetModel(this);
686 // Remove page and notes page.
687 const sal_uInt16
nDestPageNum(nActualInsertPos
+ 2);
688 SdPage
* pStandardPage
= 0L;
690 if(nDestPageNum
< GetPageCount())
692 pStandardPage
= (SdPage
*)GetPage(nDestPageNum
);
697 if( bPreservePageNames
)
699 // Take old slide names for inserted pages
700 SdPage
* pPage
= (SdPage
*) GetPage(nActualInsertPos
);
701 pPage
->SetName( pStandardPage
->GetRealName() );
705 AddUndo(GetSdrUndoFactory().CreateUndoDeletePage(*pStandardPage
));
707 RemovePage(nDestPageNum
);
710 delete pStandardPage
;
713 SdPage
* pNotesPage
= 0L;
715 if(nDestPageNum
< GetPageCount())
717 pNotesPage
= (SdPage
*)GetPage(nDestPageNum
);
722 if( bPreservePageNames
)
724 // Take old slide names for inserted pages
725 SdPage
* pNewNotesPage
= (SdPage
*) GetPage(nActualInsertPos
+1);
727 pNewNotesPage
->SetName( pStandardPage
->GetRealName() );
731 AddUndo(GetSdrUndoFactory().CreateUndoDeletePage(*pNotesPage
));
733 RemovePage(nDestPageNum
);
739 nReplacedStandardPages
++;
742 nActualInsertPos
+= 2;
748 // We might have duplicate master pages now, as the drawing engine does not
749 // recognize duplicates. Remove these now.
750 sal_uInt16 nNewMPageCount
= GetMasterPageCount();
752 // Go backwards, so the numbers don't become messed up
753 for (sal_uInt16 nPage
= nNewMPageCount
- 1; nPage
>= nMPageCount
; nPage
--)
755 pRefPage
= (SdPage
*) GetMasterPage(nPage
);
756 String
aMPLayout(pRefPage
->GetLayoutName());
757 PageKind eKind
= pRefPage
->GetPageKind();
759 // Does this already exist?
760 for (sal_uInt16 nTest
= 0; nTest
< nMPageCount
; nTest
++)
762 SdPage
* pTest
= (SdPage
*) GetMasterPage(nTest
);
763 String
aTest(pTest
->GetLayoutName());
765 // nInsertPos > 2 is always true when inserting into non-empty models
766 if ( nInsertPos
> 2 &&
767 aTest
== aMPLayout
&&
768 eKind
== pTest
->GetPageKind() )
771 AddUndo(GetSdrUndoFactory().CreateUndoDeletePage(*pRefPage
));
773 RemoveMasterPage(nPage
);
783 // nInsertPos > 2 is always true when inserting into non-empty models
786 sal_uInt16 nSdPageStart
= (nInsertPos
- 1) / 2;
787 sal_uInt16 nSdPageEnd
= GetSdPageCount(PK_STANDARD
) - nSdPageCount
+
789 const bool bRemoveEmptyPresObj
= pBookmarkDoc
&&
790 (pBookmarkDoc
->GetDocumentType() == DOCUMENT_TYPE_IMPRESS
) &&
791 (GetDocumentType() == DOCUMENT_TYPE_DRAW
);
795 nSdPageEnd
= nSdPageStart
+ nReplacedStandardPages
- 1;
798 std::vector
<OUString
>::iterator pExchangeIter
;
801 pExchangeIter
= pExchangeList
->begin();
803 for (sal_uInt16 nSdPage
= nSdPageStart
; nSdPage
<= nSdPageEnd
; nSdPage
++)
805 pRefPage
= GetSdPage(nSdPage
, PK_STANDARD
);
807 if (pExchangeList
&& pExchangeIter
!= pExchangeList
->end())
809 // Get the name to use from Exchange list
810 String
aExchangeName (*pExchangeIter
);
811 pRefPage
->SetName(aExchangeName
);
812 SdrHint
aHint(HINT_PAGEORDERCHG
);
813 aHint
.SetPage(pRefPage
);
815 SdPage
* pNewNotesPage
= GetSdPage(nSdPage
, PK_NOTES
);
816 pNewNotesPage
->SetName(aExchangeName
);
817 aHint
.SetPage(pNewNotesPage
);
823 String
aLayout(pRefPage
->GetLayoutName());
824 aLayout
.Erase(aLayout
.SearchAscii( SD_LT_SEPARATOR
));
826 // update layout and referred master page
827 pRefPage
->SetPresentationLayout(aLayout
);
829 AddUndo( GetSdrUndoFactory().CreateUndoPageChangeMasterPage( *pRefPage
) );
833 Rectangle
aBorderRect(nLeft
, nUpper
, nRight
, nLower
);
834 pRefPage
->ScaleObjects(aSize
, aBorderRect
, sal_True
);
836 pRefPage
->SetSize(aSize
);
837 pRefPage
->SetBorder(nLeft
, nUpper
, nRight
, nLower
);
838 pRefPage
->SetOrientation( eOrient
);
840 if( bRemoveEmptyPresObj
)
841 pRefPage
->RemoveEmptyPresentationObjects();
843 pRefPage
= GetSdPage(nSdPage
, PK_NOTES
);
845 // update layout and referred master page
846 pRefPage
->SetPresentationLayout(aLayout
);
848 AddUndo( GetSdrUndoFactory().CreateUndoPageChangeMasterPage( *pRefPage
) );
852 Rectangle
aBorderRect(nNLeft
, nNUpper
, nNRight
, nNLower
);
853 pRefPage
->ScaleObjects(aNSize
, aBorderRect
, sal_True
);
856 pRefPage
->SetSize(aNSize
);
857 pRefPage
->SetBorder(nNLeft
, nNUpper
, nNRight
, nNLower
);
858 pRefPage
->SetOrientation( eNOrient
);
860 if( bRemoveEmptyPresObj
)
861 pRefPage
->RemoveEmptyPresentationObjects();
864 ///Remove processed elements, to avoid doings hacks in InsertBookmarkAsObject
866 pExchangeList
->erase(pExchangeList
->begin(),pExchangeIter
);
868 for (sal_uInt16 nPage
= nMPageCount
; nPage
< nNewMPageCount
; nPage
++)
870 pRefPage
= (SdPage
*) GetMasterPage(nPage
);
871 if (pRefPage
->GetPageKind() == PK_STANDARD
)
875 Rectangle
aBorderRect(nLeft
, nUpper
, nRight
, nLower
);
876 pRefPage
->ScaleObjects(aSize
, aBorderRect
, sal_True
);
878 pRefPage
->SetSize(aSize
);
879 pRefPage
->SetBorder(nLeft
, nUpper
, nRight
, nLower
);
880 pRefPage
->SetOrientation( eOrient
);
882 else // Can only be notes
886 Rectangle
aBorderRect(nNLeft
, nNUpper
, nNRight
, nNLower
);
887 pRefPage
->ScaleObjects(aNSize
, aBorderRect
, sal_True
);
889 pRefPage
->SetSize(aNSize
);
890 pRefPage
->SetBorder(nNLeft
, nNUpper
, nNRight
, nNLower
);
891 pRefPage
->SetOrientation( eNOrient
);
894 if( bRemoveEmptyPresObj
)
895 pRefPage
->RemoveEmptyPresentationObjects();
899 // Make absolutely sure no double masterpages are there
900 RemoveUnnecessaryMasterPages(NULL
, sal_True
, sal_True
);
902 // remove copied styles not used on any inserted page and create
904 // WARNING: SdMoveStyleSheetsUndoAction clears the passed list of
905 // styles, so it cannot be used after this point
906 lcl_removeUnusedStyles(GetStyleSheetPool(), aNewGraphicStyles
);
907 if (!aNewGraphicStyles
.empty() && pUndoMgr
)
908 pUndoMgr
->AddUndoAction(new SdMoveStyleSheetsUndoAction(this, aNewGraphicStyles
, sal_True
));
909 lcl_removeUnusedStyles(GetStyleSheetPool(), aNewCellStyles
);
910 if (!aNewCellStyles
.empty() && pUndoMgr
)
911 pUndoMgr
->AddUndoAction(new SdMoveStyleSheetsUndoAction(this, aNewCellStyles
, sal_True
));
915 pUndoMgr
->LeaveListAction();
920 // Inserts a bookmark as an object
921 sal_Bool
SdDrawDocument::InsertBookmarkAsObject(
922 const std::vector
<OUString
> &rBookmarkList
,
923 const std::vector
<OUString
> &rExchangeList
, // List of names to use
924 sal_Bool
/* bLink */,
925 ::sd::DrawDocShell
* pBookmarkDocSh
,
926 Point
* pObjPos
, bool bCalcObjCount
)
928 sal_Bool bOK
= sal_True
;
929 sal_Bool bOLEObjFound
= sal_False
;
930 ::sd::View
* pBMView
= NULL
;
932 SdDrawDocument
* pBookmarkDoc
= NULL
;
933 String aBookmarkName
;
937 pBookmarkDoc
= pBookmarkDocSh
->GetDoc();
939 if (pBookmarkDocSh
->GetMedium())
941 aBookmarkName
= pBookmarkDocSh
->GetMedium()->GetName();
944 else if ( mxBookmarkDocShRef
.Is() )
946 pBookmarkDoc
= mxBookmarkDocShRef
->GetDoc();
947 aBookmarkName
= maBookmarkFile
;
954 if (rBookmarkList
.empty())
956 pBMView
= new ::sd::View(*pBookmarkDoc
, (OutputDevice
*) NULL
);
957 pBMView
->EndListening(*pBookmarkDoc
);
965 std::vector
<OUString
>::const_iterator pIter
;
966 for ( pIter
= rBookmarkList
.begin(); pIter
!= rBookmarkList
.end(); ++pIter
)
968 // Get names of bookmarks from the list
969 String
aBMName (*pIter
);
971 SdrObject
* pObj
= pBookmarkDoc
->GetObj(aBMName
);
976 if (pObj
->GetObjInventor() == SdrInventor
&&
977 pObj
->GetObjIdentifier() == OBJ_OLE2
)
979 bOLEObjFound
= sal_True
;
984 // Create View for the first time
985 pBMView
= new ::sd::View(*pBookmarkDoc
, (OutputDevice
*) NULL
);
986 pBMView
->EndListening(*pBookmarkDoc
);
989 pPage
= pObj
->GetPage();
991 if (pPage
->IsMasterPage())
993 pPV
= pBMView
->ShowSdrPage(pBMView
->GetModel()->GetMasterPage(pPage
->GetPageNum()));
997 pPV
= pBMView
->GetSdrPageView();
998 if( !pPV
|| (pPV
->GetPage() != pPage
))
999 pPV
= pBMView
->ShowSdrPage(pPage
);
1002 pBMView
->MarkObj(pObj
, pPV
, sal_False
);
1009 // Insert selected objects
1010 ::sd::View
* pView
= new ::sd::View(*this, (OutputDevice
*) NULL
);
1011 pView
->EndListening(*this);
1013 // Look for the page into which the objects are supposed to be inserted
1014 SdrPage
* pPage
= GetSdPage(0, PK_STANDARD
);
1018 ::sd::ViewShell
* pViewSh
= mpDocSh
->GetViewShell();
1022 // Which page is currently in view?
1023 SdrPageView
* pPV
= pViewSh
->GetView()->GetSdrPageView();
1027 pPage
= pPV
->GetPage();
1029 else if (pViewSh
->GetActualPage())
1031 pPage
= pViewSh
->GetActualPage();
1044 aObjPos
= Rectangle(Point(), pPage
->GetSize()).Center();
1047 sal_uLong nCountBefore
= 0;
1049 if (!rExchangeList
.empty() || bCalcObjCount
)
1051 // Sort OrdNums and get the number of objects before inserting
1052 pPage
->RecalcObjOrdNums();
1053 nCountBefore
= pPage
->GetObjCount();
1057 pBMView
->GetDoc().SetAllocDocSh(sal_True
);
1059 SdDrawDocument
* pTmpDoc
= (SdDrawDocument
*) pBMView
->GetMarkedObjModel();
1060 bOK
= pView
->Paste(*pTmpDoc
, aObjPos
, pPage
);
1063 pBMView
->GetDoc().SetAllocDocSh(sal_False
);
1066 delete pTmpDoc
; // Would otherwise be destroyed by DocShell
1070 if (!rExchangeList
.empty())
1072 // Get number of objects after inserting.
1073 sal_uLong nCount
= pPage
->GetObjCount();
1075 std::vector
<OUString
>::const_iterator pIter
= rExchangeList
.begin();
1076 for (sal_uLong nObj
= nCountBefore
; nObj
< nCount
; nObj
++)
1078 // Get the name to use from the Exchange list
1079 if (pIter
!= rExchangeList
.end())
1081 String
aExchangeName (*pIter
);
1083 if (pPage
->GetObj(nObj
))
1085 pPage
->GetObj(nObj
)->SetName(aExchangeName
);
1099 // Stops the bookmark insertion
1100 void SdDrawDocument::CloseBookmarkDoc()
1102 if (mxBookmarkDocShRef
.Is())
1104 mxBookmarkDocShRef
->DoClose();
1107 mxBookmarkDocShRef
.Clear();
1108 maBookmarkFile
= String();
1111 // Is this document read-only?
1112 bool SdDrawDocument::IsReadOnly() const
1118 // In the subsequent AllocModel() a DocShell (xAllocedDocShRef) is created.
1119 // Any pre-existing DocShell is deleted
1120 void SdDrawDocument::SetAllocDocSh(sal_Bool bAlloc
)
1122 mbAllocDocSh
= bAlloc
;
1124 if(mxAllocedDocShRef
.Is())
1126 mxAllocedDocShRef
->DoClose();
1129 mxAllocedDocShRef
.Clear();
1132 // Return list of CustomShows (create it, too, if necessary)
1133 SdCustomShowList
* SdDrawDocument::GetCustomShowList(sal_Bool bCreate
)
1135 if (!mpCustomShowList
&& bCreate
)
1137 mpCustomShowList
= new SdCustomShowList
;
1140 return mpCustomShowList
;
1143 // Remove unused master pages and layouts
1144 void SdDrawDocument::RemoveUnnecessaryMasterPages(SdPage
* pMasterPage
, sal_Bool bOnlyDuplicatePages
, sal_Bool bUndo
)
1146 ::sd::View
* pView
= NULL
;
1147 ::svl::IUndoManager
* pUndoMgr
= NULL
;
1149 if( bUndo
&& !IsUndoEnabled() )
1154 pUndoMgr
= mpDocSh
->GetUndoManager();
1156 if (mpDocSh
->GetViewShell())
1157 pView
= mpDocSh
->GetViewShell()->GetView();
1160 // Check all master pages
1161 sal_uInt16 nSdMasterPageCount
= GetMasterSdPageCount( PK_STANDARD
);
1162 for (sal_Int32 nMPage
= nSdMasterPageCount
- 1; nMPage
>= 0; nMPage
--)
1164 SdPage
* pMaster
= pMasterPage
;
1165 SdPage
* pNotesMaster
= NULL
;
1169 pMaster
= (SdPage
*) GetMasterSdPage( (sal_uInt16
) nMPage
, PK_STANDARD
);
1170 pNotesMaster
= (SdPage
*) GetMasterSdPage( (sal_uInt16
) nMPage
, PK_NOTES
);
1174 for ( sal_uInt16 nMPg
= 0; nMPg
< GetMasterPageCount(); nMPg
++ )
1176 if ( pMaster
== GetMasterPage( nMPg
) )
1178 pNotesMaster
= (SdPage
*) GetMasterPage( ++nMPg
);
1184 DBG_ASSERT( pMaster
->GetPageKind() == PK_STANDARD
, "wrong page kind" );
1186 if ( pMaster
->GetPageKind() == PK_STANDARD
&&
1187 GetMasterPageUserCount( pMaster
) == 0 &&
1190 // Do not delete master pages that have their precious flag set
1191 sal_Bool bDeleteMaster
= !pMaster
->IsPrecious();
1192 OUString aLayoutName
= pMaster
->GetLayoutName();
1194 if(bOnlyDuplicatePages
)
1196 // remove only duplicate pages
1197 bDeleteMaster
= sal_False
;
1198 for (sal_uInt16 i
= 0; i
< GetMasterSdPageCount( PK_STANDARD
); i
++)
1200 SdPage
* pMPg
= (SdPage
*) GetMasterSdPage( i
, PK_STANDARD
);
1201 if( pMPg
!= pMaster
&&
1202 pMPg
->GetLayoutName() == aLayoutName
)
1204 // duplicate page found -> remove it
1205 bDeleteMaster
= sal_True
;
1214 // if MasterPage is visible hide on pageview
1215 SdrPageView
* pPgView
= pView
->GetSdrPageView();
1218 SdrPage
* pShownPage
= pPgView
->GetPage();
1219 if( (pShownPage
== pMaster
) || (pShownPage
== pNotesMaster
) )
1221 pView
->HideSdrPage();
1222 pView
->ShowSdrPage( GetSdPage( 0, PK_STANDARD
) );
1230 AddUndo( GetSdrUndoFactory().CreateUndoDeletePage( *pNotesMaster
) );
1233 RemoveMasterPage( pNotesMaster
->GetPageNum() );
1236 delete pNotesMaster
;
1239 AddUndo(GetSdrUndoFactory().CreateUndoDeletePage(*pMaster
));
1241 RemoveMasterPage( pMaster
->GetPageNum() );
1247 EndUndo(); // do this here already, so Joe's actions happen _between_ our own
1249 // Delete old, unused layout stylesheets
1250 sal_Bool bDeleteOldStyleSheets
= sal_True
;
1251 for ( sal_uInt16 nMPg
= 0;
1252 nMPg
< GetMasterPageCount() && bDeleteOldStyleSheets
;
1255 SdPage
* pMPg
= (SdPage
*) GetMasterPage(nMPg
);
1256 if (pMPg
->GetLayoutName() == aLayoutName
)
1258 bDeleteOldStyleSheets
= sal_False
;
1262 if (bDeleteOldStyleSheets
)
1264 SdStyleSheetVector aRemove
;
1265 static_cast<SdStyleSheetPool
*>( mxStyleSheetPool
.get())->CreateLayoutSheetList( aLayoutName
, aRemove
);
1269 // This list belongs to UndoAction
1270 SdMoveStyleSheetsUndoAction
* pMovStyles
= new SdMoveStyleSheetsUndoAction( this, aRemove
, false );
1273 pUndoMgr
->AddUndoAction(pMovStyles
);
1276 for( SdStyleSheetVector::iterator iter
= aRemove
.begin(); iter
!= aRemove
.end(); ++iter
)
1277 static_cast<SdStyleSheetPool
*>( mxStyleSheetPool
.get())->Remove((*iter
).get());
1283 break; // Just this one master page!
1288 /** Exchange master page
1290 * Either the nSdPageNum gets a new, own master page or the master page is
1291 * exchanged completely (which then applies to all pages).
1293 * nSdPageNum : page number that the new master page should get.
1294 * rLayoutName : LayoutName of the new master page
1295 * pSourceDoc : document (template) to get the master page from
1296 * bMaster : exchange the master page of nSdPageNum
1297 * bCheckMasters: remove unused master pages
1299 * If pSourceDoc == NULL, an empty master page is applied.
1300 * If rLayoutName is empty, the first master page is used.
1302 void SdDrawDocument::SetMasterPage(sal_uInt16 nSdPageNum
,
1303 const String
& rLayoutName
,
1304 SdDrawDocument
* pSourceDoc
,
1306 sal_Bool bCheckMasters
)
1309 mpDocSh
->SetWaitCursor( sal_True
);
1311 ::svl::IUndoManager
* pUndoMgr
= mpDocSh
->GetUndoManager();
1313 const bool bUndo
= IsUndoEnabled();
1317 pUndoMgr
->EnterListAction(String(SdResId(STR_UNDO_SET_PRESLAYOUT
)), String());
1320 SdPage
* pSelectedPage
= GetSdPage(nSdPageNum
, PK_STANDARD
);
1321 SdPage
* pNotes
= (SdPage
*) GetPage(pSelectedPage
->GetPageNum()+1);
1322 SdPage
& rOldMaster
= (SdPage
&)pSelectedPage
->TRG_GetMasterPage();
1323 SdPage
& rOldNotesMaster
= (SdPage
&)pNotes
->TRG_GetMasterPage();
1324 SdPage
* pMaster
= NULL
;
1325 SdPage
* pNotesMaster
= NULL
;
1326 SdPage
* pPage
= NULL
;
1327 String
aOldPageLayoutName(pSelectedPage
->GetLayoutName());
1328 String
aOldLayoutName(aOldPageLayoutName
);
1329 aOldLayoutName
.Erase(aOldLayoutName
.SearchAscii( SD_LT_SEPARATOR
));
1331 String
aNewLayoutName( rLayoutName
);
1335 std::vector
<StyleReplaceData
> aReplList
; // List of replaced stylesheets
1336 sal_Bool bLayoutReloaded
= sal_False
; // Wurde ex. Layout wieder geladen?
1338 // LayoutName, Page and Notes page
1339 if (rLayoutName
.Len() == 0)
1341 // No LayoutName: take first MasterPage
1342 pMaster
= (SdPage
*) pSourceDoc
->GetMasterSdPage(0, PK_STANDARD
);
1343 pNotesMaster
= (SdPage
*) pSourceDoc
->GetMasterSdPage(0, PK_NOTES
);
1344 aNewLayoutName
= pMaster
->GetName();
1348 OUStringBuffer
aBuf(rLayoutName
);
1349 aBuf
.append(SD_LT_SEPARATOR
).append(SdResId(STR_LAYOUT_OUTLINE
).toString());
1350 OUString
aSearchFor(aBuf
.makeStringAndClear());
1352 for (sal_uInt16 nMP
= 0; nMP
< pSourceDoc
->GetMasterPageCount(); ++nMP
)
1354 SdPage
* pMP
= (SdPage
*) pSourceDoc
->GetMasterPage(nMP
);
1356 if (pMP
->GetLayoutName() == aSearchFor
)
1358 if (pMP
->GetPageKind() == PK_STANDARD
)
1360 if (pMP
->GetPageKind() == PK_NOTES
)
1363 if (pMaster
&& pNotesMaster
)
1366 DBG_ASSERT(pMaster
, "MasterPage (Standard page) not found");
1367 DBG_ASSERT(pNotesMaster
, "MasterPage (Notes page) not found");
1369 // this should not happen, but looking at crashreports, it does
1370 if( (pMaster
== NULL
) || (pNotesMaster
== NULL
) )
1372 // so take the first MasterPage
1373 pMaster
= (SdPage
*) pSourceDoc
->GetMasterSdPage(0, PK_STANDARD
);
1374 pNotesMaster
= (SdPage
*) pSourceDoc
->GetMasterSdPage(0, PK_NOTES
);
1375 aNewLayoutName
= pMaster
->GetName();
1379 // we should never reach this, but one never knows...
1380 if( (pMaster
== NULL
) || (pNotesMaster
== NULL
) )
1382 pUndoMgr
->LeaveListAction();
1385 mpDocSh
->SetWaitCursor( sal_False
);
1387 OSL_FAIL( "SdDrawDocument::SetMasterPage() failed!" );
1392 if (pSourceDoc
!= this)
1394 const sal_uInt16 nMasterPageCount
= GetMasterPageCount();
1395 for ( sal_uInt16 nMPage
= 0; nMPage
< nMasterPageCount
; nMPage
++ )
1397 SdPage
* pCheckMaster
= (SdPage
*)GetMasterPage(nMPage
);
1398 if( pCheckMaster
->GetName() == aNewLayoutName
)
1400 bLayoutReloaded
= sal_True
;
1405 // Correct or create presentation templates --
1406 // only worry about presentation templates
1408 SdStyleSheetPool
* pSourceStyleSheetPool
= (SdStyleSheetPool
*) pSourceDoc
->GetStyleSheetPool();
1409 pSourceStyleSheetPool
->SetSearchMask(SD_STYLE_FAMILY_MASTERPAGE
);
1410 static_cast<SdStyleSheetPool
*>( mxStyleSheetPool
.get())->SetSearchMask(SD_STYLE_FAMILY_MASTERPAGE
);
1412 SdStyleSheetVector aCreatedStyles
; // List of created stylesheets
1413 SfxStyleSheetBase
* pHisSheet
= pSourceStyleSheetPool
->First();
1417 aName
= pHisSheet
->GetName();
1419 if( aName
.Search( aNewLayoutName
) == 0 )
1421 SfxStyleSheet
* pMySheet
= static_cast<SfxStyleSheet
*>( mxStyleSheetPool
->Find(aName
, SD_STYLE_FAMILY_MASTERPAGE
) );
1425 // A stylesheet of the same name already exists -> overwrite contents
1429 pMySheet
->SetName(pHisSheet
->GetName());
1430 DBG_ASSERT(bTest
, "Renaming StyleSheet failed.");
1431 pMySheet
->GetItemSet().ClearItem(0); // Delete all
1433 StyleSheetUndoAction
* pUndoChStyle
= new StyleSheetUndoAction(this,
1434 pMySheet
, &pHisSheet
->GetItemSet());
1435 pUndoMgr
->AddUndoAction(pUndoChStyle
);
1436 pMySheet
->GetItemSet().Put(pHisSheet
->GetItemSet());
1437 pMySheet
->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED
));
1443 pMySheet
= static_cast<SfxStyleSheet
*>( &mxStyleSheetPool
->Make(aName
, SD_STYLE_FAMILY_MASTERPAGE
, pHisSheet
->GetMask()) );
1444 pMySheet
->SetHelpId( aHelpFile
, pHisSheet
->GetHelpId(aHelpFile
) );
1445 pMySheet
->GetItemSet().ClearItem(0); // Delete all
1446 pMySheet
->GetItemSet().Put(pHisSheet
->GetItemSet());
1448 aCreatedStyles
.push_back( SdStyleSheetRef( static_cast< SdStyleSheet
* >( pMySheet
) ) );
1451 StyleReplaceData aReplData
;
1452 aReplData
.nNewFamily
= pMySheet
->GetFamily();
1453 aReplData
.nFamily
= pMySheet
->GetFamily();
1454 aReplData
.aNewName
= pMySheet
->GetName();
1456 String
aTemp(pMySheet
->GetName());
1457 sal_uInt16 nPos
= aTemp
.SearchAscii( SD_LT_SEPARATOR
);
1458 aTemp
.Erase(0, nPos
);
1459 aTemp
.Insert(aOldLayoutName
, 0);
1460 aReplData
.aName
= aTemp
;
1461 aReplList
.push_back(aReplData
);
1464 pHisSheet
= (SfxStyleSheet
*) pSourceStyleSheetPool
->Next();
1467 // If new styles were created: re-create parent chaining of the item
1468 // sets in the styles.
1469 if(!aCreatedStyles
.empty())
1471 std::vector
<StyleReplaceData
>::iterator pRDataIter
;
1472 for ( pRDataIter
= aReplList
.begin(); pRDataIter
!= aReplList
.end(); ++pRDataIter
)
1474 SfxStyleSheetBase
* pSOld
= mxStyleSheetPool
->Find(pRDataIter
->aName
);
1475 SfxStyleSheetBase
* pSNew
= mxStyleSheetPool
->Find(pRDataIter
->aNewName
);
1479 const String
& rParentOfOld
= pSOld
->GetParent();
1480 const String
& rParentOfNew
= pSNew
->GetParent();
1482 if (rParentOfOld
.Len() > 0 && rParentOfNew
.Len() == 0)
1484 std::vector
<StyleReplaceData
>::iterator pRDIter
;
1485 for ( pRDIter
= aReplList
.begin(); pRDIter
!= aReplList
.end(); ++pRDIter
)
1487 if ((pRDIter
->aName
== rParentOfOld
) && (pRDIter
->aName
!= pRDIter
->aNewName
))
1489 String
aParentOfNew(pRDIter
->aNewName
);
1490 pSNew
->SetParent(aParentOfNew
);
1498 // Now look for all of them when searching
1499 pSourceStyleSheetPool
->SetSearchMask(SFX_STYLE_FAMILY_ALL
);
1500 mxStyleSheetPool
->SetSearchMask(SFX_STYLE_FAMILY_ALL
);
1503 if( !aCreatedStyles
.empty() )
1505 // Add UndoAction for creating and inserting the stylesheets to
1506 // the top of the UndoManager
1507 SdMoveStyleSheetsUndoAction
* pMovStyles
= new SdMoveStyleSheetsUndoAction( this, aCreatedStyles
, sal_True
);
1508 pUndoMgr
->AddUndoAction(pMovStyles
);
1512 // Create layout name based upon the name of the page layout of the
1514 String
aPageLayoutName(pMaster
->GetLayoutName());
1515 String aLayoutName
= aPageLayoutName
;
1516 aLayoutName
.Erase( aLayoutName
.SearchAscii( SD_LT_SEPARATOR
));
1518 if (pSourceDoc
!= this)
1520 // Remove from the source document
1521 pSourceDoc
->RemoveMasterPage(pNotesMaster
->GetPageNum());
1522 pSourceDoc
->RemoveMasterPage(pMaster
->GetPageNum());
1525 // Register the new master pages with the document and then use the
1526 // the new presentation layout for the default and notes pages
1527 if (pSourceDoc
!= this)
1529 // Insert the master pages:
1530 // Insert master pages from new layouts at the end.
1531 // If a layout is being replaced, however, insert them before the
1532 // position of the old master page, so from now on the new master
1533 // page will be found when searching (e.g.
1534 // SdPage::SetPresentationLayout).
1535 sal_uInt16 nInsertPos
= rOldMaster
.GetPageNum();
1538 if (!bLayoutReloaded
)
1539 nInsertPos
= 0xFFFF;
1540 InsertMasterPage(pMaster
, nInsertPos
);
1542 AddUndo(GetSdrUndoFactory().CreateUndoNewPage(*pMaster
));
1545 if (!bLayoutReloaded
)
1546 nInsertPos
= 0xFFFF;
1547 InsertMasterPage(pNotesMaster
, nInsertPos
);
1550 AddUndo(GetSdrUndoFactory().CreateUndoNewPage(*pNotesMaster
));
1552 EndUndo(); // do this here already, so Joe's actions happen _between_ our own.
1556 // Fill list with pages
1557 std::vector
<SdPage
*> aPageList
;
1559 // #98456, this has to be removed according to CL (KA 07/08/2002)
1560 // #109884# but we need them again to restore the styles of the presentation objects while undo
1561 aPageList
.push_back(pMaster
);
1562 aPageList
.push_back(pNotesMaster
);
1564 if (bMaster
|| bLayoutReloaded
)
1566 for (sal_uInt16 nPage
= 1; nPage
< GetPageCount(); nPage
++)
1568 pPage
= (SdPage
*) GetPage(nPage
);
1569 String aTest
= pPage
->GetLayoutName();
1570 if (aTest
== aOldPageLayoutName
)
1572 aPageList
.push_back(pPage
);
1579 aPageList
.push_back(pSelectedPage
);
1580 aPageList
.push_back(pNotes
);
1583 for (std::vector
<SdPage
*>::iterator pIter
= aPageList
.begin(); pIter
!= aPageList
.end(); ++pIter
)
1585 AutoLayout eAutoLayout
= (*pIter
)->GetAutoLayout();
1589 SdPresentationLayoutUndoAction
* pPLUndoAction
=
1590 new SdPresentationLayoutUndoAction
1592 ( pPage
&& pPage
->IsMasterPage() ) ? aLayoutName
: aOldLayoutName
,
1594 eAutoLayout
, eAutoLayout
, sal_False
, *pIter
);
1595 pUndoMgr
->AddUndoAction(pPLUndoAction
);
1597 (*pIter
)->SetPresentationLayout(aLayoutName
);
1598 (*pIter
)->SetAutoLayout(eAutoLayout
);
1601 // Adapt new master pages
1602 if (pSourceDoc
!= this)
1604 Size
aSize(rOldMaster
.GetSize());
1605 Rectangle
aBorderRect(rOldMaster
.GetLftBorder(),
1606 rOldMaster
.GetUppBorder(),
1607 rOldMaster
.GetRgtBorder(),
1608 rOldMaster
.GetLwrBorder());
1609 pMaster
->ScaleObjects(aSize
, aBorderRect
, sal_True
);
1610 pMaster
->SetSize(aSize
);
1611 pMaster
->SetBorder(rOldMaster
.GetLftBorder(),
1612 rOldMaster
.GetUppBorder(),
1613 rOldMaster
.GetRgtBorder(),
1614 rOldMaster
.GetLwrBorder());
1615 pMaster
->SetOrientation( rOldMaster
.GetOrientation() );
1616 pMaster
->SetAutoLayout(pMaster
->GetAutoLayout());
1618 aSize
= rOldNotesMaster
.GetSize();
1619 Rectangle
aNotesBorderRect(rOldNotesMaster
.GetLftBorder(),
1620 rOldNotesMaster
.GetUppBorder(),
1621 rOldNotesMaster
.GetRgtBorder(),
1622 rOldNotesMaster
.GetLwrBorder());
1623 pNotesMaster
->ScaleObjects(aSize
, aNotesBorderRect
, sal_True
);
1624 pNotesMaster
->SetSize(aSize
);
1625 pNotesMaster
->SetBorder(rOldNotesMaster
.GetLftBorder(),
1626 rOldNotesMaster
.GetUppBorder(),
1627 rOldNotesMaster
.GetRgtBorder(),
1628 rOldNotesMaster
.GetLwrBorder());
1629 pNotesMaster
->SetOrientation( rOldNotesMaster
.GetOrientation() );
1630 pNotesMaster
->SetAutoLayout(pNotesMaster
->GetAutoLayout());
1632 if( (pSourceDoc
->GetDocumentType() == DOCUMENT_TYPE_IMPRESS
) &&
1633 (GetDocumentType() == DOCUMENT_TYPE_DRAW
) )
1635 pMaster
->RemoveEmptyPresentationObjects();
1636 pNotesMaster
->RemoveEmptyPresentationObjects();
1642 // Find a new name for the layout
1643 String aName
= String(SdResId(STR_LAYOUT_DEFAULT_NAME
));
1645 sal_Bool bNotANewName
= sal_True
;
1646 sal_uInt16 nCount
= 0;
1647 sal_uInt16 nMPgCount
= GetMasterPageCount();
1649 for (nCount
= 0; bNotANewName
; nCount
++)
1651 // Create a test name
1652 aTest
= aName
; // Default, Default1, Default2, ...
1654 aTest
+= OUString::number( nCount
);
1656 // Is there any page that's already named the same?
1657 bNotANewName
= sal_False
;
1658 for (sal_uInt16 nMPg
= 1; nMPg
< nMPgCount
; nMPg
++)
1660 const SdrPage
* pTest
= GetMasterPage(nMPg
);
1661 String
aPageLayoutName(pTest
->GetLayoutName());
1662 aPageLayoutName
.Erase( aPageLayoutName
.SearchAscii( SD_LT_SEPARATOR
));
1664 if (aPageLayoutName
== aTest
)
1665 bNotANewName
= sal_True
;
1669 String
aPageLayoutName(aName
);
1670 aPageLayoutName
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( SD_LT_SEPARATOR
));
1671 aPageLayoutName
+= String(SdResId(STR_LAYOUT_OUTLINE
));
1673 // Generate new stylesheets
1674 static_cast<SdStyleSheetPool
*>( mxStyleSheetPool
.get())->CreateLayoutStyleSheets(aName
);
1675 SdStyleSheetVector aCreatedStyles
;
1676 static_cast<SdStyleSheetPool
*>( mxStyleSheetPool
.get())->CreateLayoutSheetList(aName
, aCreatedStyles
);
1680 SdMoveStyleSheetsUndoAction
* pMovStyles
= new SdMoveStyleSheetsUndoAction(this, aCreatedStyles
, sal_True
);
1681 pUndoMgr
->AddUndoAction(pMovStyles
);
1684 // Generate new master pages and register them with the document
1688 pMaster
= (SdPage
*) AllocPage(sal_True
);
1689 pMaster
->SetSize(pSelectedPage
->GetSize());
1690 pMaster
->SetBorder(pSelectedPage
->GetLftBorder(),
1691 pSelectedPage
->GetUppBorder(),
1692 pSelectedPage
->GetRgtBorder(),
1693 pSelectedPage
->GetLwrBorder() );
1694 pMaster
->SetName(aName
);
1695 pMaster
->SetLayoutName(aPageLayoutName
);
1696 InsertMasterPage(pMaster
);
1699 AddUndo(GetSdrUndoFactory().CreateUndoNewPage(*pMaster
));
1701 pMaster
->SetAutoLayout(AUTOLAYOUT_NONE
, true, true);
1703 pNotesMaster
= (SdPage
*) AllocPage(sal_True
);
1704 pNotesMaster
->SetPageKind(PK_NOTES
);
1705 pNotesMaster
->SetSize(pNotes
->GetSize());
1706 pNotesMaster
->SetBorder(pNotes
->GetLftBorder(),
1707 pNotes
->GetUppBorder(),
1708 pNotes
->GetRgtBorder(),
1709 pNotes
->GetLwrBorder() );
1710 pNotesMaster
->SetName(aName
);
1711 pNotesMaster
->SetLayoutName(aPageLayoutName
);
1712 InsertMasterPage(pNotesMaster
);
1715 AddUndo(GetSdrUndoFactory().CreateUndoNewPage(*pNotesMaster
));
1717 pNotesMaster
->SetAutoLayout(AUTOLAYOUT_NOTES
, true, true);
1722 // Create a list of affected default and notes pages
1723 std::vector
<SdPage
*> aPageList
;
1726 for (sal_uInt16 nPage
= 1; nPage
< GetPageCount(); nPage
++)
1728 pPage
= (SdPage
*) GetPage(nPage
);
1729 const String
s(pPage
->GetLayoutName());
1730 if(s
== aOldPageLayoutName
)
1732 aPageList
.push_back(pPage
);
1738 aPageList
.push_back(pSelectedPage
);
1739 aPageList
.push_back(pNotes
);
1742 // Set presentation layout and AutoLayout for the affected pages
1743 for ( std::vector
<SdPage
*>::iterator pIter
= aPageList
.begin(); pIter
!= aPageList
.end(); ++pIter
)
1745 AutoLayout eOldAutoLayout
= (*pIter
)->GetAutoLayout();
1746 AutoLayout eNewAutoLayout
=
1747 (*pIter
)->GetPageKind() == PK_STANDARD
? AUTOLAYOUT_NONE
: AUTOLAYOUT_NOTES
;
1751 SdPresentationLayoutUndoAction
* pPLUndoAction
=
1752 new SdPresentationLayoutUndoAction
1753 (this, aOldLayoutName
, aName
,
1754 eOldAutoLayout
, eNewAutoLayout
, sal_True
,
1756 pUndoMgr
->AddUndoAction(pPLUndoAction
);
1759 (*pIter
)->SetPresentationLayout(aName
);
1760 (*pIter
)->SetAutoLayout(eNewAutoLayout
);
1764 // If the old master pages aren't used anymore, they and their styles have
1769 RemoveUnnecessaryMasterPages();
1773 // Check only the master page that was replaced
1774 RemoveUnnecessaryMasterPages(&rOldMaster
);
1778 pUndoMgr
->LeaveListAction();
1781 mpDocSh
->SetWaitCursor( sal_False
);
1786 void SdDrawDocument::Merge(SdrModel
& rSourceModel
,
1787 sal_uInt16 nFirstPageNum
, sal_uInt16 nLastPageNum
,
1788 sal_uInt16 nDestPos
,
1789 bool bMergeMasterPages
, bool bAllMasterPages
,
1790 bool bUndo
, bool bTreadSourceAsConst
)
1792 sal_uInt16 nMasterPageCount
= GetMasterPageCount();
1793 SdrModel::Merge( rSourceModel
, nFirstPageNum
, nLastPageNum
, nDestPos
, bMergeMasterPages
, bAllMasterPages
, bUndo
, bTreadSourceAsConst
);
1795 // add style family for each new master page
1796 for( sal_uInt16 nMaster
= nMasterPageCount
; nMaster
< GetMasterPageCount(); nMaster
++ )
1798 SdPage
* pPage
= static_cast< SdPage
* >( GetMasterPage( nMaster
) );
1799 if( pPage
&& pPage
->IsMasterPage() && (pPage
->GetPageKind() == PK_STANDARD
) )
1801 // new master page created, add its style family
1802 SdStyleSheetPool
* pStylePool
= (SdStyleSheetPool
*) GetStyleSheetPool();
1804 pStylePool
->AddStyleFamily( pPage
);
1809 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */