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 : #include <com/sun/star/embed/ElementModes.hpp>
21 : #include <com/sun/star/beans/XPropertySet.hpp>
22 :
23 : #include "comphelper/anytostring.hxx"
24 : #include "cppuhelper/exc_hlp.hxx"
25 :
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>
31 :
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>
43 :
44 : #include "glob.hrc"
45 : #include "drawdoc.hxx"
46 : #include "sdpage.hxx"
47 : #include "stlpool.hxx"
48 : #include "sdresid.hxx"
49 : #include "sdiocmpt.hxx"
50 : #include "strmname.h"
51 : #include "anminfo.hxx"
52 : #include "customshowlist.hxx"
53 :
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"
63 :
64 : using namespace ::com::sun::star;
65 :
66 : /** Concrete incarnations get called by lcl_IterateBookmarkPages, for
67 : every page in the bookmark document/list
68 : */
69 :
70 : class InsertBookmarkAsPage_FindDuplicateLayouts
71 : {
72 : public:
73 0 : InsertBookmarkAsPage_FindDuplicateLayouts( std::vector<rtl::OUString> &rLayoutsToTransfer )
74 0 : : mrLayoutsToTransfer(rLayoutsToTransfer) {}
75 : void operator()( SdDrawDocument&, SdPage* );
76 : private:
77 : std::vector<rtl::OUString> &mrLayoutsToTransfer;
78 : };
79 :
80 0 : void InsertBookmarkAsPage_FindDuplicateLayouts::operator()( SdDrawDocument& rDoc, SdPage* pBMMPage )
81 : {
82 : // now check for duplicate masterpage and layout names
83 : // ===================================================
84 :
85 0 : String aFullNameLayout( pBMMPage->GetLayoutName() );
86 0 : aFullNameLayout.Erase( aFullNameLayout.SearchAscii( SD_LT_SEPARATOR ));
87 :
88 0 : rtl::OUString aLayout(aFullNameLayout);
89 :
90 : std::vector<rtl::OUString>::const_iterator pIter =
91 0 : find(mrLayoutsToTransfer.begin(),mrLayoutsToTransfer.end(),aLayout);
92 :
93 0 : bool bFound = pIter != mrLayoutsToTransfer.end();
94 :
95 0 : const sal_uInt16 nMPageCount = rDoc.GetMasterPageCount();
96 0 : for (sal_uInt16 nMPage = 0; nMPage < nMPageCount && !bFound; nMPage++)
97 : {
98 : /**************************************************************
99 : * Gibt es die Layouts schon im Dokument?
100 : **************************************************************/
101 0 : SdPage* pTestPage = (SdPage*) rDoc.GetMasterPage(nMPage);
102 0 : String aFullTest(pTestPage->GetLayoutName());
103 0 : aFullTest.Erase( aFullTest.SearchAscii( SD_LT_SEPARATOR ));
104 :
105 0 : rtl::OUString aTest(aFullTest);
106 :
107 0 : if (aTest == aLayout)
108 0 : bFound = true;
109 0 : }
110 :
111 0 : if (!bFound)
112 0 : mrLayoutsToTransfer.push_back(aLayout);
113 0 : }
114 :
115 : /*************************************************************************
116 : |*
117 : |* Fuegt ein Bookmark als Seite ein
118 : |*
119 : \************************************************************************/
120 :
121 0 : static void lcl_IterateBookmarkPages( SdDrawDocument &rDoc, SdDrawDocument* pBookmarkDoc,
122 : const std::vector<rtl::OUString> &rBookmarkList, sal_uInt16 nBMSdPageCount,
123 : InsertBookmarkAsPage_FindDuplicateLayouts& rPageIterator )
124 : {
125 : //
126 : // Refactored copy'n'pasted layout name collection from InsertBookmarkAsPage
127 : //
128 : int nPos, nEndPos;
129 :
130 0 : if( rBookmarkList.empty() )
131 : {
132 : // no list? whole source document
133 0 : nEndPos = nBMSdPageCount;
134 : }
135 : else
136 : {
137 : // bookmark list? number of entries
138 0 : nEndPos = rBookmarkList.size();
139 : }
140 :
141 : SdPage* pBMPage;
142 :
143 : // iterate over number of pages to insert
144 0 : for (nPos = 0; nPos < nEndPos; ++nPos)
145 : {
146 : // the master page associated to the nPos'th page to insert
147 0 : SdPage* pBMMPage = NULL;
148 :
149 0 : if( rBookmarkList.empty() )
150 : {
151 : // simply take master page of nPos'th page in source document
152 0 : pBMMPage = (SdPage*)(&(pBookmarkDoc->GetSdPage((sal_uInt16)nPos, PK_STANDARD)->TRG_GetMasterPage()));
153 : }
154 : else
155 : {
156 : // fetch nPos'th entry from bookmark list, and determine master page
157 0 : String aBMPgName(rBookmarkList[nPos]);
158 : sal_Bool bIsMasterPage;
159 :
160 0 : sal_uInt16 nBMPage = pBookmarkDoc->GetPageByName( aBMPgName, bIsMasterPage );
161 :
162 0 : if (nBMPage != SDRPAGE_NOTFOUND)
163 : {
164 0 : pBMPage = (SdPage*) pBookmarkDoc->GetPage(nBMPage);
165 : }
166 : else
167 : {
168 0 : pBMPage = NULL;
169 : }
170 :
171 : // enforce that bookmarked page is a standard page and not already a master page
172 0 : if (pBMPage && pBMPage->GetPageKind()==PK_STANDARD && !pBMPage->IsMasterPage())
173 : {
174 0 : const sal_uInt16 nBMSdPage = (nBMPage - 1) / 2;
175 0 : pBMMPage = (SdPage*) (&(pBookmarkDoc->GetSdPage(nBMSdPage, PK_STANDARD)->TRG_GetMasterPage()));
176 0 : }
177 : }
178 :
179 : // successfully determined valid (bookmarked) page?
180 0 : if( pBMMPage )
181 : {
182 : // yes, call functor
183 0 : rPageIterator( rDoc, pBMMPage );
184 : }
185 : }
186 0 : }
187 :
188 : /*************************************************************************
189 : |*
190 : |* Oeffnet ein Bookmark-Dokument
191 : |*
192 : \************************************************************************/
193 :
194 0 : SdDrawDocument* SdDrawDocument::OpenBookmarkDoc(SfxMedium& rMedium)
195 : {
196 0 : sal_Bool bOK = sal_True;
197 0 : SdDrawDocument* pBookmarkDoc = NULL;
198 0 : String aBookmarkName = rMedium.GetName();
199 0 : const SfxFilter* pFilter = rMedium.GetFilter();
200 0 : if ( !pFilter )
201 : {
202 0 : rMedium.UseInteractionHandler( sal_True );
203 0 : SFX_APP()->GetFilterMatcher().GuessFilter( rMedium, &pFilter );
204 : }
205 :
206 0 : if ( !pFilter )
207 : {
208 0 : bOK = sal_False;
209 : }
210 0 : else if ( maBookmarkFile != aBookmarkName && aBookmarkName.Len() )
211 : {
212 0 : sal_Bool bCreateGraphicShell = pFilter->GetServiceName() == "com.sun.star.drawing.DrawingDocument";
213 0 : sal_Bool bCreateImpressShell = pFilter->GetServiceName() == "com.sun.star.presentation.PresentationDocument";
214 0 : if ( bCreateGraphicShell || bCreateImpressShell )
215 : {
216 0 : CloseBookmarkDoc();
217 :
218 : // Es wird eine DocShell erzeugt, da in dem Dokument OLE-Objekte
219 : // enthalten sein koennten (Persist)
220 : // Wenn dem nicht so waere, so koennte man auch das Model
221 : // direkt laden
222 0 : if ( bCreateGraphicShell )
223 : // Draw
224 0 : mxBookmarkDocShRef = new ::sd::GraphicDocShell(SFX_CREATE_MODE_STANDARD, sal_True);
225 : else
226 : // Impress
227 0 : mxBookmarkDocShRef = new ::sd::DrawDocShell(SFX_CREATE_MODE_STANDARD, sal_True);
228 :
229 0 : bOK = mxBookmarkDocShRef->DoLoad(&rMedium);
230 0 : if( bOK )
231 : {
232 0 : maBookmarkFile = aBookmarkName;
233 0 : pBookmarkDoc = mxBookmarkDocShRef->GetDoc();
234 : }
235 : }
236 : }
237 :
238 : DBG_ASSERT(aBookmarkName.Len(), "Empty document name!");
239 :
240 0 : if (!bOK)
241 : {
242 0 : ErrorBox aErrorBox( NULL, (WinBits)WB_OK, String(SdResId(STR_READ_DATA_ERROR)));
243 0 : aErrorBox.Execute();
244 :
245 0 : CloseBookmarkDoc();
246 0 : pBookmarkDoc = NULL;
247 : }
248 0 : else if (mxBookmarkDocShRef.Is())
249 : {
250 0 : pBookmarkDoc = mxBookmarkDocShRef->GetDoc();
251 : }
252 :
253 0 : return(pBookmarkDoc);
254 : }
255 :
256 : /*************************************************************************
257 : |*
258 : |* Oeffnet ein Bookmark-Dokument
259 : |*
260 : \************************************************************************/
261 :
262 0 : SdDrawDocument* SdDrawDocument::OpenBookmarkDoc(const String& rBookmarkFile)
263 : {
264 0 : SdDrawDocument* pBookmarkDoc = NULL;
265 :
266 0 : if (maBookmarkFile != rBookmarkFile && rBookmarkFile.Len())
267 : {
268 0 : SfxMedium* pMedium = new SfxMedium( rBookmarkFile, STREAM_READ );
269 0 : pBookmarkDoc = OpenBookmarkDoc(*pMedium);
270 : }
271 0 : else if (mxBookmarkDocShRef.Is())
272 : {
273 0 : pBookmarkDoc = mxBookmarkDocShRef->GetDoc();
274 : }
275 :
276 0 : return(pBookmarkDoc);
277 : }
278 :
279 : /*************************************************************************
280 : |*
281 : |* Fuegt ein Bookmark (Seite oder Objekt) ein
282 : |*
283 : \************************************************************************/
284 :
285 0 : sal_Bool SdDrawDocument::InsertBookmark(
286 : const std::vector<rtl::OUString> &rBookmarkList, // Liste der Namen der einzufuegenden Bookmarks
287 : std::vector<rtl::OUString> &rExchangeList, // Liste der zu verwendenen Namen
288 : sal_Bool bLink, // Bookmarks sollen als Verknuepfung eingefuegt werden
289 : sal_Bool bReplace, // Aktuellen Seiten (Standard&Notiz) werden ersetzt
290 : sal_uInt16 nInsertPos, // Einfuegeposition fuer Seiten
291 : sal_Bool bNoDialogs, // Keine Dialoge anzeigen
292 : ::sd::DrawDocShell* pBookmarkDocSh, // Wenn gesetzt, so ist dieses das Source-Dokument
293 : sal_Bool bCopy, // Seiten werden kopiert
294 : Point* pObjPos) // Einfuegeposition fuer Objekte
295 : {
296 0 : sal_Bool bOK = sal_True;
297 0 : sal_Bool bInsertPages = sal_False;
298 :
299 0 : if (rBookmarkList.empty())
300 : {
301 : /**********************************************************************
302 : * Alle Seiten werden eingefuegt
303 : **********************************************************************/
304 0 : bInsertPages = sal_True;
305 : }
306 : else
307 : {
308 0 : SdDrawDocument* pBookmarkDoc = NULL;
309 0 : String aBookmarkName;
310 :
311 0 : if (pBookmarkDocSh)
312 : {
313 0 : pBookmarkDoc = pBookmarkDocSh->GetDoc();
314 0 : aBookmarkName = pBookmarkDocSh->GetMedium()->GetName();
315 : }
316 0 : else if ( mxBookmarkDocShRef.Is() )
317 : {
318 0 : pBookmarkDoc = mxBookmarkDocShRef->GetDoc();
319 0 : aBookmarkName = maBookmarkFile;
320 : }
321 : else
322 0 : bOK = sal_False;
323 :
324 0 : std::vector<rtl::OUString>::const_iterator pIter;
325 0 : for ( pIter = rBookmarkList.begin(); bOK && pIter != rBookmarkList.end() && !bInsertPages; ++pIter )
326 : {
327 : /******************************************************************
328 : * Gibt es in der Bookmark-Liste einen Seitennamen?
329 : ******************************************************************/
330 0 : String aBMPgName(*pIter);
331 : sal_Bool bIsMasterPage;
332 :
333 0 : if( pBookmarkDoc->GetPageByName( aBMPgName, bIsMasterPage ) != SDRPAGE_NOTFOUND )
334 : {
335 : // Seite gefunden
336 0 : bInsertPages = sal_True;
337 : }
338 0 : }
339 : }
340 :
341 0 : sal_Bool bCalcObjCount = !rExchangeList.empty();
342 :
343 0 : if ( bOK && bInsertPages )
344 : {
345 : // Zuerst werden alle Seiten-Bookmarks eingefuegt
346 : bOK = InsertBookmarkAsPage(rBookmarkList, &rExchangeList, bLink, bReplace,
347 0 : nInsertPos, bNoDialogs, pBookmarkDocSh, bCopy, sal_True, sal_False);
348 : }
349 :
350 0 : if ( bOK && !rBookmarkList.empty() )
351 : {
352 : // Es werden alle Objekt-Bookmarks eingefuegt
353 : bOK = InsertBookmarkAsObject(rBookmarkList, rExchangeList, bLink,
354 0 : pBookmarkDocSh, pObjPos, bCalcObjCount);
355 : }
356 :
357 0 : return bOK;
358 : }
359 :
360 0 : sal_Bool SdDrawDocument::InsertBookmarkAsPage(
361 : const std::vector<rtl::OUString> &rBookmarkList,
362 : std::vector<rtl::OUString> *pExchangeList, // Liste der zu verwendenen Namen
363 : sal_Bool bLink,
364 : sal_Bool bReplace,
365 : sal_uInt16 nInsertPos,
366 : sal_Bool bNoDialogs,
367 : ::sd::DrawDocShell* pBookmarkDocSh,
368 : sal_Bool bCopy,
369 : sal_Bool bMergeMasterPages,
370 : sal_Bool bPreservePageNames)
371 : {
372 0 : sal_Bool bOK = sal_True;
373 0 : sal_Bool bContinue = sal_True;
374 0 : sal_Bool bScaleObjects = sal_False;
375 0 : sal_uInt16 nReplacedStandardPages = 0;
376 :
377 0 : SdDrawDocument* pBookmarkDoc = NULL;
378 0 : String aBookmarkName;
379 :
380 0 : if (pBookmarkDocSh)
381 : {
382 0 : pBookmarkDoc = pBookmarkDocSh->GetDoc();
383 :
384 0 : if (pBookmarkDocSh->GetMedium())
385 : {
386 0 : aBookmarkName = pBookmarkDocSh->GetMedium()->GetName();
387 : }
388 : }
389 0 : else if ( mxBookmarkDocShRef.Is() )
390 : {
391 0 : pBookmarkDoc = mxBookmarkDocShRef->GetDoc();
392 0 : aBookmarkName = maBookmarkFile;
393 : }
394 : else
395 : {
396 0 : return sal_False;
397 : }
398 :
399 0 : const sal_uInt16 nSdPageCount = GetSdPageCount(PK_STANDARD);
400 0 : const sal_uInt16 nBMSdPageCount = pBookmarkDoc->GetSdPageCount(PK_STANDARD);
401 0 : const sal_uInt16 nMPageCount = GetMasterPageCount();
402 :
403 0 : if (nSdPageCount==0 || nBMSdPageCount==0 || nMPageCount==0)
404 : {
405 0 : bContinue = bOK = sal_False;
406 0 : return(bContinue);
407 : }
408 :
409 : // Store the size and some other properties of the first page and notes
410 : // page so that inserted pages can be properly scaled even when inserted
411 : // before the first page.
412 : // Note that the pointers are used later on as general page pointers.
413 0 : SdPage* pRefPage = GetSdPage(0, PK_STANDARD);
414 0 : Size aSize(pRefPage->GetSize());
415 0 : sal_Int32 nLeft = pRefPage->GetLftBorder();
416 0 : sal_Int32 nRight = pRefPage->GetRgtBorder();
417 0 : sal_Int32 nUpper = pRefPage->GetUppBorder();
418 0 : sal_Int32 nLower = pRefPage->GetLwrBorder();
419 0 : Orientation eOrient = pRefPage->GetOrientation();
420 :
421 0 : SdPage* pNPage = GetSdPage(0, PK_NOTES);
422 0 : Size aNSize(GetSdPage(0, PK_NOTES)->GetSize());
423 0 : sal_Int32 nNLeft = pNPage->GetLftBorder();
424 0 : sal_Int32 nNRight = pNPage->GetRgtBorder();
425 0 : sal_Int32 nNUpper = pNPage->GetUppBorder();
426 0 : sal_Int32 nNLower = pNPage->GetLwrBorder();
427 0 : Orientation eNOrient = pRefPage->GetOrientation();
428 :
429 : // Seitengroesse und -raender an die Werte der letzten
430 : // Seiten anpassen?
431 0 : pRefPage = GetSdPage(nSdPageCount - 1, PK_STANDARD);
432 :
433 0 : if( bNoDialogs )
434 : {
435 0 : if( rBookmarkList.empty() )
436 0 : bScaleObjects = pRefPage->IsScaleObjects();
437 : else
438 0 : bScaleObjects = sal_True;
439 : }
440 : else
441 : {
442 0 : SdPage* pBMPage = pBookmarkDoc->GetSdPage(0,PK_STANDARD);
443 :
444 0 : if (pBMPage->GetSize() != pRefPage->GetSize() ||
445 0 : pBMPage->GetLftBorder() != pRefPage->GetLftBorder() ||
446 0 : pBMPage->GetRgtBorder() != pRefPage->GetRgtBorder() ||
447 0 : pBMPage->GetUppBorder() != pRefPage->GetUppBorder() ||
448 0 : pBMPage->GetLwrBorder() != pRefPage->GetLwrBorder())
449 : {
450 0 : String aStr(SdResId(STR_SCALE_OBJECTS));
451 0 : sal_uInt16 nBut = QueryBox( NULL, WB_YES_NO_CANCEL, aStr).Execute();
452 :
453 0 : bScaleObjects = nBut == RET_YES;
454 0 : bContinue = nBut != RET_CANCEL;
455 :
456 0 : if (!bContinue)
457 : {
458 0 : return(bContinue);
459 0 : }
460 : }
461 : }
462 :
463 :
464 : /**************************************************************************
465 : |* Die benoetigten Praesentations-StyleSheets ermitteln und vor
466 : |* den Seiten transferieren, sonst verlieren die Textobjekte
467 : |* beim Transfer den Bezug zur Vorlage
468 : \*************************************************************************/
469 0 : ::svl::IUndoManager* pUndoMgr = NULL;
470 0 : if( mpDocSh )
471 : {
472 0 : pUndoMgr = mpDocSh->GetUndoManager();
473 0 : pUndoMgr->EnterListAction(String(SdResId(STR_UNDO_INSERTPAGES)), String());
474 : }
475 :
476 : //
477 : // Refactored copy'n'pasted layout name collection into IterateBookmarkPages
478 : //
479 0 : std::vector<rtl::OUString> aLayoutsToTransfer;
480 0 : InsertBookmarkAsPage_FindDuplicateLayouts aSearchFunctor( aLayoutsToTransfer );
481 0 : lcl_IterateBookmarkPages( *this, pBookmarkDoc, rBookmarkList, nBMSdPageCount, aSearchFunctor );
482 :
483 :
484 : /**************************************************************************
485 : * Die tatsaechlich benoetigten Vorlagen kopieren
486 : **************************************************************************/
487 : SdStyleSheetPool* pBookmarkStyleSheetPool =
488 0 : (SdStyleSheetPool*) pBookmarkDoc->GetStyleSheetPool();
489 :
490 : // Wenn Vorlagen kopiert werden muessen, dann muessen auch die
491 : // MasterPages kopiert werden!
492 0 : if( !aLayoutsToTransfer.empty() )
493 0 : bMergeMasterPages = sal_True;
494 :
495 0 : std::vector<rtl::OUString>::const_iterator pIter;
496 0 : for ( pIter = aLayoutsToTransfer.begin(); pIter != aLayoutsToTransfer.end(); ++pIter )
497 : {
498 0 : SdStyleSheetVector aCreatedStyles;
499 0 : String layoutName = *pIter;
500 :
501 0 : ((SdStyleSheetPool*)GetStyleSheetPool())->CopyLayoutSheets(layoutName, *pBookmarkStyleSheetPool,aCreatedStyles);
502 :
503 0 : if(!aCreatedStyles.empty())
504 : {
505 0 : if( pUndoMgr )
506 : {
507 0 : SdMoveStyleSheetsUndoAction* pMovStyles = new SdMoveStyleSheetsUndoAction(this, aCreatedStyles, sal_True);
508 0 : pUndoMgr->AddUndoAction(pMovStyles);
509 : }
510 : }
511 0 : }
512 :
513 : /**************************************************************************
514 : * Dokument einfuegen
515 : **************************************************************************/
516 :
517 0 : const bool bUndo = IsUndoEnabled();
518 :
519 0 : if( bUndo )
520 0 : BegUndo(String(SdResId(STR_UNDO_INSERTPAGES)));
521 :
522 0 : if (rBookmarkList.empty())
523 : {
524 0 : if (nInsertPos >= GetPageCount())
525 : {
526 : // Seiten werden hinten angefuegt
527 0 : nInsertPos = GetPageCount();
528 : }
529 :
530 0 : sal_uInt16 nActualInsertPos = nInsertPos;
531 :
532 : sal_uInt16 nBMSdPage;
533 0 : std::set<sal_uInt16> aRenameSet;
534 0 : std::map<sal_uInt16,rtl::OUString> aNameMap;
535 :
536 0 : for (nBMSdPage=0; nBMSdPage < nBMSdPageCount; nBMSdPage++)
537 : {
538 0 : SdPage* pBMPage = pBookmarkDoc->GetSdPage(nBMSdPage, PK_STANDARD);
539 0 : String sName( pBMPage->GetName() );
540 : sal_Bool bIsMasterPage;
541 :
542 0 : if (bLink)
543 : {
544 : // Es werden sich die Namen aller Seiten gemerkt
545 0 : aNameMap.insert(std::make_pair(nBMSdPage,sName));
546 : }
547 :
548 : // Have to check for duplicate names here, too
549 : // don't change name if source and dest model are the same!
550 0 : if( pBookmarkDoc != this &&
551 0 : GetPageByName(sName, bIsMasterPage ) != SDRPAGE_NOTFOUND )
552 : {
553 : // delay renaming *after* pages are copied (might destroy source otherwise)
554 0 : aRenameSet.insert(nBMSdPage);
555 : }
556 0 : }
557 :
558 : Merge(*pBookmarkDoc,
559 : 1, // Nicht die Handzettelseite
560 : 0xFFFF, // Aber alle anderen
561 : nActualInsertPos, // An Position einfuegen
562 : bMergeMasterPages, // MasterPages mitnehmen
563 : sal_False, // Aber nur die benoetigten MasterPages
564 : sal_True, // Undo-Aktion erzeugen
565 0 : bCopy); // Seiten kopieren (oder mergen)
566 :
567 0 : for (nBMSdPage=0; nBMSdPage < nBMSdPageCount; nBMSdPage++)
568 : {
569 0 : SdPage* pPage = (SdPage*) GetPage(nActualInsertPos);
570 0 : SdPage* pNotesPage = (SdPage*) GetPage(nActualInsertPos+1);
571 :
572 : // delay renaming *after* pages are copied (might destroy source otherwise)
573 0 : if( aRenameSet.find(nBMSdPage) != aRenameSet.end() )
574 : {
575 : // Seitenname schon vorhanden -> Defaultname
576 : // fuer Standard & Notizseite
577 0 : pPage->SetName(String());
578 0 : pNotesPage->SetName(String());
579 : }
580 :
581 0 : if (bLink)
582 : {
583 0 : String aName(aNameMap[nBMSdPage]);
584 :
585 : // Nun werden die Link-Namen zusammengestellt
586 0 : pPage->SetFileName(aBookmarkName);
587 0 : pPage->SetBookmarkName(aName);
588 0 : pPage->SetModel(this);
589 : }
590 :
591 0 : nActualInsertPos += 2;
592 0 : }
593 : }
594 : else
595 : {
596 : /**********************************************************************
597 : * Ausgewaehlte Seiten einfuegen
598 : **********************************************************************/
599 : SdPage* pBMPage;
600 :
601 0 : if (nInsertPos >= GetPageCount())
602 : {
603 : // Seiten werden hinten angefuegt
604 0 : bReplace = sal_False;
605 0 : nInsertPos = GetPageCount();
606 : }
607 :
608 0 : sal_uInt16 nActualInsertPos = nInsertPos;
609 :
610 : // Collect the bookmarked pages.
611 0 : ::std::vector<SdPage*> aBookmarkedPages (rBookmarkList.size(), NULL);
612 0 : for ( size_t nPos = 0, n = rBookmarkList.size(); nPos < n; ++nPos)
613 : {
614 0 : String aPgName(rBookmarkList[nPos]);
615 : sal_Bool bIsMasterPage;
616 0 : sal_uInt16 nBMPage = pBookmarkDoc->GetPageByName( aPgName, bIsMasterPage );
617 :
618 0 : if (nBMPage != SDRPAGE_NOTFOUND)
619 : {
620 0 : aBookmarkedPages[nPos] = dynamic_cast<SdPage*>(pBookmarkDoc->GetPage(nBMPage));
621 : }
622 0 : }
623 :
624 0 : for ( size_t nPos = 0, n = rBookmarkList.size(); nPos < n; ++nPos)
625 : {
626 0 : pBMPage = aBookmarkedPages[nPos];
627 0 : sal_uInt16 nBMPage = pBMPage!=NULL ? pBMPage->GetPageNum() : SDRPAGE_NOTFOUND;
628 :
629 0 : if (pBMPage && pBMPage->GetPageKind()==PK_STANDARD && !pBMPage->IsMasterPage())
630 : {
631 : /**************************************************************
632 : * Es muss eine StandardSeite sein
633 : **************************************************************/
634 0 : sal_Bool bMustRename = sal_False;
635 :
636 : // delay renaming *after* pages are copied (might destroy source otherwise)
637 : // don't change name if source and dest model are the same!
638 : // avoid renaming if replacing the same page
639 0 : String aPgName(rBookmarkList[nPos]);
640 : sal_Bool bIsMasterPage;
641 0 : sal_uInt16 nPageSameName = GetPageByName(aPgName, bIsMasterPage);
642 0 : if( pBookmarkDoc != this &&
643 : nPageSameName != SDRPAGE_NOTFOUND &&
644 : ( !bReplace ||
645 : nPageSameName != nActualInsertPos ) )
646 : {
647 0 : bMustRename = sal_True;
648 : }
649 :
650 0 : SdPage* pBookmarkPage = pBMPage;
651 0 : if (bReplace )
652 : {
653 0 : ReplacePageInCustomShows( dynamic_cast< SdPage* >( GetPage( nActualInsertPos ) ), pBookmarkPage );
654 : }
655 :
656 : Merge(*pBookmarkDoc,
657 : nBMPage, // Von Seite (Standard)
658 : nBMPage+1, // Bis Seite (Notizen)
659 : nActualInsertPos, // An Position einfuegen
660 : bMergeMasterPages, // MasterPages mitnehmen
661 : sal_False, // Aber nur die benoetigten MasterPages
662 : sal_True, // Undo-Aktion erzeugen
663 0 : bCopy); // Seiten kopieren (oder mergen)
664 :
665 0 : if( bReplace )
666 : {
667 0 : if( GetPage( nActualInsertPos ) != pBookmarkPage )
668 : {
669 : // bookmark page was not moved but cloned, so update custom shows again
670 0 : ReplacePageInCustomShows( pBookmarkPage, dynamic_cast< SdPage* >( GetPage( nActualInsertPos ) ) );
671 : }
672 : }
673 :
674 0 : if( bMustRename )
675 : {
676 : // Seitenname schon vorhanden -> Defaultname
677 : // fuer Standard & Notizseite
678 0 : SdPage* pPage = (SdPage*) GetPage(nActualInsertPos);
679 0 : pPage->SetName(String());
680 0 : SdPage* pNotesPage = (SdPage*) GetPage(nActualInsertPos+1);
681 0 : pNotesPage->SetName(String());
682 : }
683 :
684 0 : if (bLink)
685 : {
686 0 : SdPage* pPage = (SdPage*) GetPage(nActualInsertPos);
687 0 : pPage->SetFileName(aBookmarkName);
688 0 : pPage->SetBookmarkName(aPgName);
689 0 : pPage->SetModel(this);
690 : }
691 :
692 0 : if (bReplace)
693 : {
694 : // Seite & Notizseite ausfuegen
695 0 : const sal_uInt16 nDestPageNum(nActualInsertPos + 2);
696 0 : SdPage* pStandardPage = 0L;
697 :
698 0 : if(nDestPageNum < GetPageCount())
699 : {
700 0 : pStandardPage = (SdPage*)GetPage(nDestPageNum);
701 : }
702 :
703 0 : if (pStandardPage)
704 : {
705 0 : if( bPreservePageNames )
706 : {
707 : // Take old slide names for inserted pages
708 0 : SdPage* pPage = (SdPage*) GetPage(nActualInsertPos);
709 0 : pPage->SetName( pStandardPage->GetRealName() );
710 : }
711 :
712 0 : if( bUndo )
713 0 : AddUndo(GetSdrUndoFactory().CreateUndoDeletePage(*pStandardPage));
714 :
715 0 : RemovePage(nDestPageNum);
716 :
717 0 : if( !bUndo )
718 0 : delete pStandardPage;
719 : }
720 :
721 0 : SdPage* pNotesPage = 0L;
722 :
723 0 : if(nDestPageNum < GetPageCount())
724 : {
725 0 : pNotesPage = (SdPage*)GetPage(nDestPageNum);
726 : }
727 :
728 0 : if (pNotesPage)
729 : {
730 0 : if( bPreservePageNames )
731 : {
732 : // Take old slide names for inserted pages
733 0 : SdPage* pNewNotesPage = (SdPage*) GetPage(nActualInsertPos+1);
734 0 : if( pNewNotesPage )
735 0 : pNewNotesPage->SetName( pStandardPage->GetRealName() );
736 : }
737 :
738 0 : if( bUndo )
739 0 : AddUndo(GetSdrUndoFactory().CreateUndoDeletePage(*pNotesPage));
740 :
741 0 : RemovePage(nDestPageNum);
742 :
743 0 : if( !bUndo )
744 0 : delete pNotesPage;
745 : }
746 :
747 0 : nReplacedStandardPages++;
748 : }
749 :
750 0 : nActualInsertPos += 2;
751 : }
752 0 : }
753 : }
754 :
755 :
756 : /**************************************************************************
757 : |* Dabei sind evtl. zu viele Masterpages ruebergekommen, da die
758 : |* DrawingEngine gleiche Praesentationslayouts nicht erkennen kann.
759 : |* Ueberzaehlige MasterPages entfernen.
760 : \*************************************************************************/
761 0 : sal_uInt16 nNewMPageCount = GetMasterPageCount();
762 :
763 : // rueckwaerts, damit Nummern nicht durcheinander geraten
764 0 : for (sal_uInt16 nPage = nNewMPageCount - 1; nPage >= nMPageCount; nPage--)
765 : {
766 0 : pRefPage = (SdPage*) GetMasterPage(nPage);
767 0 : String aMPLayout(pRefPage->GetLayoutName());
768 0 : PageKind eKind = pRefPage->GetPageKind();
769 :
770 : // gibt's den schon?
771 0 : for (sal_uInt16 nTest = 0; nTest < nMPageCount; nTest++)
772 : {
773 0 : SdPage* pTest = (SdPage*) GetMasterPage(nTest);
774 0 : String aTest(pTest->GetLayoutName());
775 :
776 : // nInsertPos > 2 is always true when inserting into non-empty models
777 0 : if ( nInsertPos > 2 &&
778 0 : aTest == aMPLayout &&
779 0 : eKind == pTest->GetPageKind() )
780 : {
781 0 : if( bUndo )
782 0 : AddUndo(GetSdrUndoFactory().CreateUndoDeletePage(*pRefPage));
783 :
784 0 : RemoveMasterPage(nPage);
785 :
786 0 : if( !bUndo )
787 0 : delete pRefPage;
788 0 : nNewMPageCount--;
789 : break;
790 : }
791 0 : }
792 0 : }
793 :
794 : // nInsertPos > 2 is always true when inserting into non-empty models
795 0 : if (nInsertPos > 0)
796 : {
797 0 : sal_uInt16 nSdPageStart = (nInsertPos - 1) / 2;
798 0 : sal_uInt16 nSdPageEnd = GetSdPageCount(PK_STANDARD) - nSdPageCount +
799 0 : nSdPageStart - 1;
800 : const bool bRemoveEmptyPresObj = pBookmarkDoc &&
801 0 : (pBookmarkDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS) &&
802 0 : (GetDocumentType() == DOCUMENT_TYPE_DRAW);
803 :
804 0 : if( bReplace )
805 : {
806 0 : nSdPageEnd = nSdPageStart + nReplacedStandardPages - 1;
807 : }
808 :
809 0 : std::vector<rtl::OUString>::iterator pExchangeIter;
810 :
811 0 : if (pExchangeList)
812 0 : pExchangeIter = pExchangeList->begin();
813 :
814 0 : for (sal_uInt16 nSdPage = nSdPageStart; nSdPage <= nSdPageEnd; nSdPage++)
815 : {
816 0 : pRefPage = GetSdPage(nSdPage, PK_STANDARD);
817 :
818 0 : if (pExchangeList && pExchangeIter != pExchangeList->end())
819 : {
820 : // Zuverwendener Name aus Exchange-Liste holen
821 0 : String aExchangeName (*pExchangeIter);
822 0 : pRefPage->SetName(aExchangeName);
823 0 : SdrHint aHint(HINT_PAGEORDERCHG);
824 0 : aHint.SetPage(pRefPage);
825 0 : Broadcast(aHint);
826 0 : SdPage* pNewNotesPage = GetSdPage(nSdPage, PK_NOTES);
827 0 : pNewNotesPage->SetName(aExchangeName);
828 0 : aHint.SetPage(pNewNotesPage);
829 0 : Broadcast(aHint);
830 :
831 0 : ++pExchangeIter;
832 : }
833 :
834 0 : String aLayout(pRefPage->GetLayoutName());
835 0 : aLayout.Erase(aLayout.SearchAscii( SD_LT_SEPARATOR ));
836 :
837 : // update layout and referred master page
838 0 : pRefPage->SetPresentationLayout(aLayout);
839 0 : if( bUndo )
840 0 : AddUndo( GetSdrUndoFactory().CreateUndoPageChangeMasterPage( *pRefPage ) );
841 :
842 0 : if (bScaleObjects)
843 : {
844 0 : Rectangle aBorderRect(nLeft, nUpper, nRight, nLower);
845 0 : pRefPage->ScaleObjects(aSize, aBorderRect, sal_True);
846 : }
847 0 : pRefPage->SetSize(aSize);
848 0 : pRefPage->SetBorder(nLeft, nUpper, nRight, nLower);
849 0 : pRefPage->SetOrientation( eOrient );
850 :
851 0 : if( bRemoveEmptyPresObj )
852 0 : pRefPage->RemoveEmptyPresentationObjects();
853 :
854 0 : pRefPage = GetSdPage(nSdPage, PK_NOTES);
855 :
856 : // update layout and referred master page
857 0 : pRefPage->SetPresentationLayout(aLayout);
858 0 : if( bUndo )
859 0 : AddUndo( GetSdrUndoFactory().CreateUndoPageChangeMasterPage( *pRefPage ) );
860 :
861 0 : if (bScaleObjects)
862 : {
863 0 : Rectangle aBorderRect(nNLeft, nNUpper, nNRight, nNLower);
864 0 : pRefPage->ScaleObjects(aNSize, aBorderRect, sal_True);
865 : }
866 :
867 0 : pRefPage->SetSize(aNSize);
868 0 : pRefPage->SetBorder(nNLeft, nNUpper, nNRight, nNLower);
869 0 : pRefPage->SetOrientation( eNOrient );
870 :
871 0 : if( bRemoveEmptyPresObj )
872 0 : pRefPage->RemoveEmptyPresentationObjects();
873 0 : }
874 :
875 : ///Remove processed elements, to avoid doings hacks in InsertBookmarkAsObject
876 0 : if ( pExchangeList )
877 0 : pExchangeList->erase(pExchangeList->begin(),pExchangeIter);
878 :
879 0 : for (sal_uInt16 nPage = nMPageCount; nPage < nNewMPageCount; nPage++)
880 : {
881 0 : pRefPage = (SdPage*) GetMasterPage(nPage);
882 0 : if (pRefPage->GetPageKind() == PK_STANDARD)
883 : {
884 0 : if (bScaleObjects)
885 : {
886 0 : Rectangle aBorderRect(nLeft, nUpper, nRight, nLower);
887 0 : pRefPage->ScaleObjects(aSize, aBorderRect, sal_True);
888 : }
889 0 : pRefPage->SetSize(aSize);
890 0 : pRefPage->SetBorder(nLeft, nUpper, nRight, nLower);
891 0 : pRefPage->SetOrientation( eOrient );
892 : }
893 : else // kann nur noch NOTES sein
894 : {
895 0 : if (bScaleObjects)
896 : {
897 0 : Rectangle aBorderRect(nNLeft, nNUpper, nNRight, nNLower);
898 0 : pRefPage->ScaleObjects(aNSize, aBorderRect, sal_True);
899 : }
900 0 : pRefPage->SetSize(aNSize);
901 0 : pRefPage->SetBorder(nNLeft, nNUpper, nNRight, nNLower);
902 0 : pRefPage->SetOrientation( eNOrient );
903 : }
904 :
905 0 : if( bRemoveEmptyPresObj )
906 0 : pRefPage->RemoveEmptyPresentationObjects();
907 : }
908 : }
909 :
910 : // Make absolutely sure no double masterpages are there
911 0 : RemoveUnnecessaryMasterPages(NULL, sal_True, sal_True);
912 :
913 0 : if( bUndo )
914 0 : EndUndo();
915 0 : pUndoMgr->LeaveListAction();
916 :
917 0 : return bContinue;
918 : }
919 :
920 : /*************************************************************************
921 : |*
922 : |* Fuegt ein Bookmark als Objekt ein
923 : |*
924 : \************************************************************************/
925 :
926 0 : sal_Bool SdDrawDocument::InsertBookmarkAsObject(
927 : const std::vector<rtl::OUString> &rBookmarkList,
928 : const std::vector<rtl::OUString> &rExchangeList, // Liste der zu verwendenen Namen
929 : sal_Bool /* bLink */,
930 : ::sd::DrawDocShell* pBookmarkDocSh,
931 : Point* pObjPos, bool bCalcObjCount)
932 : {
933 0 : sal_Bool bOK = sal_True;
934 0 : sal_Bool bOLEObjFound = sal_False;
935 0 : ::sd::View* pBMView = NULL;
936 :
937 0 : SdDrawDocument* pBookmarkDoc = NULL;
938 0 : String aBookmarkName;
939 :
940 0 : if (pBookmarkDocSh)
941 : {
942 0 : pBookmarkDoc = pBookmarkDocSh->GetDoc();
943 :
944 0 : if (pBookmarkDocSh->GetMedium())
945 : {
946 0 : aBookmarkName = pBookmarkDocSh->GetMedium()->GetName();
947 : }
948 : }
949 0 : else if ( mxBookmarkDocShRef.Is() )
950 : {
951 0 : pBookmarkDoc = mxBookmarkDocShRef->GetDoc();
952 0 : aBookmarkName = maBookmarkFile;
953 : }
954 : else
955 : {
956 0 : return sal_False;
957 : }
958 :
959 0 : if (rBookmarkList.empty())
960 : {
961 0 : pBMView = new ::sd::View(*pBookmarkDoc, (OutputDevice*) NULL);
962 0 : pBMView->EndListening(*pBookmarkDoc);
963 0 : pBMView->MarkAll();
964 : }
965 : else
966 : {
967 : SdrPage* pPage;
968 : SdrPageView* pPV;
969 :
970 0 : std::vector<rtl::OUString>::const_iterator pIter;
971 0 : for ( pIter = rBookmarkList.begin(); pIter != rBookmarkList.end(); ++pIter )
972 : {
973 : /******************************************************************
974 : * Namen der Bookmarks aus Liste holen
975 : ******************************************************************/
976 0 : String aBMName (*pIter);
977 :
978 0 : SdrObject* pObj = pBookmarkDoc->GetObj(aBMName);
979 :
980 0 : if (pObj)
981 : {
982 : // Objekt gefunden
983 :
984 0 : if (pObj->GetObjInventor() == SdrInventor &&
985 0 : pObj->GetObjIdentifier() == OBJ_OLE2)
986 : {
987 0 : bOLEObjFound = sal_True;
988 : }
989 :
990 0 : if (!pBMView)
991 : {
992 : // View erstmalig erzeugen
993 0 : pBMView = new ::sd::View(*pBookmarkDoc, (OutputDevice*) NULL);
994 0 : pBMView->EndListening(*pBookmarkDoc);
995 : }
996 :
997 0 : pPage = pObj->GetPage();
998 :
999 0 : if (pPage->IsMasterPage())
1000 : {
1001 0 : pPV = pBMView->ShowSdrPage(pBMView->GetModel()->GetMasterPage(pPage->GetPageNum()));
1002 : }
1003 : else
1004 : {
1005 0 : pPV = pBMView->GetSdrPageView();
1006 0 : if( !pPV || (pPV->GetPage() != pPage))
1007 0 : pPV = pBMView->ShowSdrPage(pPage);
1008 : }
1009 :
1010 0 : pBMView->MarkObj(pObj, pPV, sal_False);
1011 : }
1012 0 : }
1013 : }
1014 :
1015 0 : if (pBMView)
1016 : {
1017 : /**********************************************************************
1018 : * Selektierte Objekte einfuegen
1019 : **********************************************************************/
1020 0 : ::sd::View* pView = new ::sd::View(*this, (OutputDevice*) NULL);
1021 0 : pView->EndListening(*this);
1022 :
1023 : // Seite bestimmen, auf der die Objekte eingefuegt werden sollen
1024 0 : SdrPage* pPage = GetSdPage(0, PK_STANDARD);
1025 :
1026 0 : if (mpDocSh)
1027 : {
1028 0 : ::sd::ViewShell* pViewSh = mpDocSh->GetViewShell();
1029 :
1030 0 : if (pViewSh)
1031 : {
1032 : // Welche Seite wird denn aktuell angezeigt?
1033 0 : SdrPageView* pPV = pViewSh->GetView()->GetSdrPageView();
1034 :
1035 0 : if (pPV)
1036 : {
1037 0 : pPage = pPV->GetPage();
1038 : }
1039 0 : else if (pViewSh->GetActualPage())
1040 : {
1041 0 : pPage = pViewSh->GetActualPage();
1042 : }
1043 : }
1044 : }
1045 :
1046 0 : Point aObjPos;
1047 :
1048 0 : if (pObjPos)
1049 : {
1050 0 : aObjPos = *pObjPos;
1051 : }
1052 : else
1053 : {
1054 0 : aObjPos = Rectangle(Point(), pPage->GetSize()).Center();
1055 : }
1056 :
1057 0 : sal_uLong nCountBefore = 0;
1058 :
1059 0 : if (!rExchangeList.empty() || bCalcObjCount)
1060 : {
1061 : // OrdNums sortieren und Anzahl Objekte vor dem Einfuegen bestimmen
1062 0 : pPage->RecalcObjOrdNums();
1063 0 : nCountBefore = pPage->GetObjCount();
1064 : }
1065 :
1066 0 : if (bOLEObjFound)
1067 0 : pBMView->GetDoc().SetAllocDocSh(sal_True);
1068 :
1069 0 : SdDrawDocument* pTmpDoc = (SdDrawDocument*) pBMView->GetAllMarkedModel();
1070 0 : bOK = pView->Paste(*pTmpDoc, aObjPos, pPage);
1071 :
1072 0 : if (bOLEObjFound)
1073 0 : pBMView->GetDoc().SetAllocDocSh(sal_False);
1074 :
1075 0 : if (!bOLEObjFound)
1076 0 : delete pTmpDoc; // Wird ansonsten von der DocShell zerstoert
1077 :
1078 0 : delete pView;
1079 :
1080 0 : if (!rExchangeList.empty())
1081 : {
1082 : // Anzahl Objekte nach dem Einfuegen bestimmen
1083 0 : sal_uLong nCount = pPage->GetObjCount();
1084 :
1085 0 : std::vector<rtl::OUString>::const_iterator pIter = rExchangeList.begin();
1086 0 : for (sal_uLong nObj = nCountBefore; nObj < nCount; nObj++)
1087 : {
1088 : // Zuverwendener Name aus Exchange-Liste holen
1089 0 : if (pIter != rExchangeList.end())
1090 : {
1091 0 : String aExchangeName (*pIter);
1092 :
1093 0 : if (pPage->GetObj(nObj))
1094 : {
1095 0 : pPage->GetObj(nObj)->SetName(aExchangeName);
1096 : }
1097 :
1098 0 : ++pIter;
1099 : }
1100 : }
1101 : }
1102 : }
1103 :
1104 0 : delete pBMView;
1105 :
1106 0 : return bOK;
1107 : }
1108 :
1109 : /*************************************************************************
1110 : |*
1111 : |* Beendet das Einfuegen von Bookmarks
1112 : |*
1113 : \************************************************************************/
1114 :
1115 18 : void SdDrawDocument::CloseBookmarkDoc()
1116 : {
1117 18 : if (mxBookmarkDocShRef.Is())
1118 : {
1119 0 : mxBookmarkDocShRef->DoClose();
1120 : }
1121 :
1122 18 : mxBookmarkDocShRef.Clear();
1123 18 : maBookmarkFile = String();
1124 18 : }
1125 :
1126 : /*************************************************************************
1127 : |*
1128 : |* Dokument laden (fuer gelinkte Objekte)
1129 : |*
1130 : \************************************************************************/
1131 :
1132 0 : const SdrModel* SdDrawDocument::LoadModel(const String& rFileName)
1133 : {
1134 0 : return ( OpenBookmarkDoc(rFileName) );
1135 : }
1136 :
1137 : /*************************************************************************
1138 : |*
1139 : |* Dokument schliessen (fuer gelinkte Objekte)
1140 : |*
1141 : \************************************************************************/
1142 :
1143 0 : void SdDrawDocument::DisposeLoadedModels()
1144 : {
1145 0 : CloseBookmarkDoc();
1146 0 : }
1147 :
1148 : /*************************************************************************
1149 : |*
1150 : |* Ist das Dokument read-only?
1151 : |*
1152 : \************************************************************************/
1153 :
1154 0 : bool SdDrawDocument::IsReadOnly() const
1155 : {
1156 0 : return sal_False;
1157 : }
1158 :
1159 :
1160 : /*************************************************************************
1161 : |*
1162 : |* In anschliessendem AllocModel() wird eine DocShell erzeugt
1163 : |* (xAllocedDocShRef). Eine bereits bestehende DocShell wird ggf. geloescht
1164 : |*
1165 : \************************************************************************/
1166 :
1167 18 : void SdDrawDocument::SetAllocDocSh(sal_Bool bAlloc)
1168 : {
1169 18 : mbAllocDocSh = bAlloc;
1170 :
1171 18 : if(mxAllocedDocShRef.Is())
1172 : {
1173 0 : mxAllocedDocShRef->DoClose();
1174 : }
1175 :
1176 18 : mxAllocedDocShRef.Clear();
1177 18 : }
1178 :
1179 : /*************************************************************************
1180 : |*
1181 : |* Liste der CustomShows zurueckgeben (ggf. zuerst erzeugen)
1182 : |*
1183 : \************************************************************************/
1184 :
1185 1 : SdCustomShowList* SdDrawDocument::GetCustomShowList(sal_Bool bCreate)
1186 : {
1187 1 : if (!mpCustomShowList && bCreate)
1188 : {
1189 : // Liste erzeugen
1190 1 : mpCustomShowList = new SdCustomShowList;
1191 : }
1192 :
1193 1 : return mpCustomShowList;
1194 : }
1195 :
1196 : /*************************************************************************
1197 : |*
1198 : |* Nicht benutzte MasterPages und Layouts entfernen
1199 : |*
1200 : \************************************************************************/
1201 :
1202 0 : void SdDrawDocument::RemoveUnnecessaryMasterPages(SdPage* pMasterPage, sal_Bool bOnlyDuplicatePages, sal_Bool bUndo)
1203 : {
1204 0 : ::sd::View* pView = NULL;
1205 0 : ::svl::IUndoManager* pUndoMgr = NULL;
1206 :
1207 0 : if( bUndo && !IsUndoEnabled() )
1208 0 : bUndo = sal_False;
1209 :
1210 0 : if (mpDocSh)
1211 : {
1212 0 : pUndoMgr = mpDocSh->GetUndoManager();
1213 :
1214 0 : if (mpDocSh->GetViewShell())
1215 0 : pView = mpDocSh->GetViewShell()->GetView();
1216 : }
1217 :
1218 : /***********************************************************
1219 : * Alle MasterPages pruefen
1220 : ***********************************************************/
1221 0 : sal_uInt16 nSdMasterPageCount = GetMasterSdPageCount( PK_STANDARD );
1222 0 : for (sal_Int32 nMPage = nSdMasterPageCount - 1; nMPage >= 0; nMPage--)
1223 : {
1224 0 : SdPage* pMaster = pMasterPage;
1225 0 : SdPage* pNotesMaster = NULL;
1226 :
1227 0 : if (!pMaster)
1228 : {
1229 0 : pMaster = (SdPage*) GetMasterSdPage( (sal_uInt16) nMPage, PK_STANDARD );
1230 0 : pNotesMaster = (SdPage*) GetMasterSdPage( (sal_uInt16) nMPage, PK_NOTES );
1231 : }
1232 : else
1233 : {
1234 0 : for ( sal_uInt16 nMPg = 0; nMPg < GetMasterPageCount(); nMPg++ )
1235 : {
1236 0 : if ( pMaster == GetMasterPage( nMPg ) )
1237 : {
1238 0 : pNotesMaster = (SdPage*) GetMasterPage( ++nMPg );
1239 0 : break;
1240 : }
1241 : }
1242 : }
1243 :
1244 : DBG_ASSERT( pMaster->GetPageKind() == PK_STANDARD, "wrong page kind" );
1245 :
1246 0 : if ( pMaster->GetPageKind() == PK_STANDARD &&
1247 0 : GetMasterPageUserCount( pMaster ) == 0 &&
1248 : pNotesMaster )
1249 : {
1250 : // Do not delete master pages that have their precious flag set.
1251 0 : sal_Bool bDeleteMaster = !pMaster->IsPrecious();
1252 0 : OUString aLayoutName = pMaster->GetLayoutName();
1253 :
1254 0 : if(bOnlyDuplicatePages )
1255 : {
1256 : // remove only duplicate pages
1257 0 : bDeleteMaster = sal_False;
1258 0 : for (sal_uInt16 i = 0; i < GetMasterSdPageCount( PK_STANDARD ); i++)
1259 : {
1260 0 : SdPage* pMPg = (SdPage*) GetMasterSdPage( i, PK_STANDARD );
1261 0 : if( pMPg != pMaster &&
1262 0 : pMPg->GetLayoutName() == aLayoutName )
1263 : {
1264 : // duplicate page found -> remove it
1265 0 : bDeleteMaster = sal_True;
1266 : }
1267 : }
1268 : }
1269 :
1270 0 : if( bDeleteMaster )
1271 : {
1272 0 : if (pView)
1273 : {
1274 : // if MasterPage is visible hide on pageview
1275 0 : SdrPageView* pPgView = pView->GetSdrPageView();
1276 0 : if (pPgView)
1277 : {
1278 0 : SdrPage* pShownPage = pPgView->GetPage();
1279 0 : if( (pShownPage == pMaster) || (pShownPage == pNotesMaster) )
1280 : {
1281 0 : pView->HideSdrPage();
1282 0 : pView->ShowSdrPage( GetSdPage( 0, PK_STANDARD ) );
1283 : }
1284 : }
1285 : }
1286 :
1287 0 : if( bUndo )
1288 : {
1289 0 : BegUndo();
1290 0 : AddUndo( GetSdrUndoFactory().CreateUndoDeletePage( *pNotesMaster ) );
1291 : }
1292 :
1293 0 : RemoveMasterPage( pNotesMaster->GetPageNum() );
1294 :
1295 0 : if( !bUndo )
1296 0 : delete pNotesMaster;
1297 :
1298 0 : if( bUndo )
1299 0 : AddUndo(GetSdrUndoFactory().CreateUndoDeletePage(*pMaster));
1300 :
1301 0 : RemoveMasterPage( pMaster->GetPageNum() );
1302 :
1303 0 : if( !bUndo )
1304 0 : delete pMaster;
1305 :
1306 0 : if( bUndo )
1307 0 : EndUndo(); // schon hier, damit sich Joes Actions ZWISCHEN unsere eigenen schieben
1308 :
1309 : // alte Layoutvorlagen loeschen, wenn sie nicht mehr benoetigt werden
1310 0 : sal_Bool bDeleteOldStyleSheets = sal_True;
1311 0 : for ( sal_uInt16 nMPg = 0;
1312 0 : nMPg < GetMasterPageCount() && bDeleteOldStyleSheets;
1313 : nMPg++ )
1314 : {
1315 0 : SdPage* pMPg = (SdPage*) GetMasterPage(nMPg);
1316 0 : if (pMPg->GetLayoutName() == aLayoutName)
1317 : {
1318 0 : bDeleteOldStyleSheets = sal_False;
1319 : }
1320 : }
1321 :
1322 0 : if (bDeleteOldStyleSheets)
1323 : {
1324 0 : SdStyleSheetVector aRemove;
1325 0 : static_cast<SdStyleSheetPool*>( mxStyleSheetPool.get())->CreateLayoutSheetList( aLayoutName, aRemove );
1326 :
1327 0 : if( bUndo )
1328 : {
1329 : // die Liste gehoert der UndoAction
1330 0 : SdMoveStyleSheetsUndoAction* pMovStyles = new SdMoveStyleSheetsUndoAction( this, aRemove, false );
1331 :
1332 0 : if (pUndoMgr)
1333 0 : pUndoMgr->AddUndoAction(pMovStyles);
1334 : }
1335 :
1336 0 : for( SdStyleSheetVector::iterator iter = aRemove.begin(); iter != aRemove.end(); ++iter )
1337 0 : static_cast<SdStyleSheetPool*>( mxStyleSheetPool.get())->Remove((*iter).get());
1338 : }
1339 0 : }
1340 : }
1341 :
1342 0 : if (pMasterPage)
1343 0 : break; // Nur diese eine MasterPage!
1344 : }
1345 0 : }
1346 :
1347 :
1348 : /*************************************************************************
1349 : |*
1350 : |* MasterPage austauschen
1351 : |*
1352 : |* Entweder erhaelt nSdPageNum eine neue, eigene MasterPage, oder die MasterPage
1353 : |* wird komplett ausgetauscht (gilt dann fuer alle Seiten).
1354 : |*
1355 : |* nSdPageNum : Nummer der Seite, welche die neue MasterPage erhalten soll
1356 : |* rLayoutName : LayoutName der neuen MasterPage
1357 : |* pSourceDoc : Dokument (Vorlage) aus dem die MasterPage geholt wird
1358 : |* bMaster : Die MasterPage von nSdPageNum soll ausgetauscht werden
1359 : |* bCheckMasters: Nicht benutzte MasterPages sollen entfernt werden
1360 : |*
1361 : |* Ist pSourceDoc == NULL, so wird eine leere MasterPage zugewiesen.
1362 : |* Ist rLayoutName leer, so wird die erste MasterPage genommen
1363 : \************************************************************************/
1364 :
1365 0 : void SdDrawDocument::SetMasterPage(sal_uInt16 nSdPageNum,
1366 : const String& rLayoutName,
1367 : SdDrawDocument* pSourceDoc,
1368 : sal_Bool bMaster,
1369 : sal_Bool bCheckMasters)
1370 : {
1371 0 : if( mpDocSh )
1372 0 : mpDocSh->SetWaitCursor( sal_True );
1373 :
1374 0 : ::svl::IUndoManager* pUndoMgr = mpDocSh->GetUndoManager();
1375 :
1376 0 : const bool bUndo = IsUndoEnabled();
1377 :
1378 0 : if( bUndo )
1379 : {
1380 0 : pUndoMgr->EnterListAction(String(SdResId(STR_UNDO_SET_PRESLAYOUT)), String());
1381 : }
1382 :
1383 0 : SdPage* pSelectedPage = GetSdPage(nSdPageNum, PK_STANDARD);
1384 0 : SdPage* pNotes = (SdPage*) GetPage(pSelectedPage->GetPageNum()+1);
1385 0 : SdPage& rOldMaster = (SdPage&)pSelectedPage->TRG_GetMasterPage();
1386 0 : SdPage& rOldNotesMaster = (SdPage&)pNotes->TRG_GetMasterPage();
1387 0 : SdPage* pMaster = NULL;
1388 0 : SdPage* pNotesMaster = NULL;
1389 0 : SdPage* pPage = NULL;
1390 0 : String aOldPageLayoutName(pSelectedPage->GetLayoutName());
1391 0 : String aOldLayoutName(aOldPageLayoutName);
1392 0 : aOldLayoutName.Erase(aOldLayoutName.SearchAscii( SD_LT_SEPARATOR ));
1393 :
1394 0 : String aNewLayoutName( rLayoutName );
1395 :
1396 0 : if (pSourceDoc)
1397 : {
1398 0 : std::vector<StyleReplaceData> aReplList; // Liste fuer ersetzte StyleSheets
1399 0 : sal_Bool bLayoutReloaded = sal_False; // Wurde ex. Layout wieder geladen?
1400 :
1401 : /*********************************************************************
1402 : |* LayoutName, Page and Notespage
1403 : \*********************************************************************/
1404 0 : if (rLayoutName.Len() == 0)
1405 : {
1406 : // No LayoutName: take first MasterPage
1407 0 : pMaster = (SdPage*) pSourceDoc->GetMasterSdPage(0, PK_STANDARD);
1408 0 : pNotesMaster = (SdPage*) pSourceDoc->GetMasterSdPage(0, PK_NOTES);
1409 0 : aNewLayoutName = pMaster->GetName();
1410 : }
1411 : else
1412 : {
1413 0 : OUStringBuffer aBuf(rLayoutName);
1414 0 : aBuf.append(SD_LT_SEPARATOR).append(SdResId(STR_LAYOUT_OUTLINE).toString());
1415 0 : OUString aSearchFor(aBuf.makeStringAndClear());
1416 :
1417 0 : for (sal_uInt16 nMP = 0; nMP < pSourceDoc->GetMasterPageCount(); ++nMP)
1418 : {
1419 0 : SdPage* pMP = (SdPage*) pSourceDoc->GetMasterPage(nMP);
1420 :
1421 0 : if (pMP->GetLayoutName() == aSearchFor)
1422 : {
1423 0 : if (pMP->GetPageKind() == PK_STANDARD)
1424 0 : pMaster = pMP;
1425 0 : if (pMP->GetPageKind() == PK_NOTES)
1426 0 : pNotesMaster = pMP;
1427 : }
1428 0 : if (pMaster && pNotesMaster)
1429 0 : break;
1430 : }
1431 : DBG_ASSERT(pMaster, "MasterPage (Standard page) not found");
1432 : DBG_ASSERT(pNotesMaster, "MasterPage (Notes page) not found");
1433 :
1434 : // this should not happen, but looking at crashreports, it does
1435 0 : if( (pMaster == NULL) || (pNotesMaster == NULL) )
1436 : {
1437 : // so take the first MasterPage
1438 0 : pMaster = (SdPage*) pSourceDoc->GetMasterSdPage(0, PK_STANDARD);
1439 0 : pNotesMaster = (SdPage*) pSourceDoc->GetMasterSdPage(0, PK_NOTES);
1440 0 : aNewLayoutName = pMaster->GetName();
1441 0 : }
1442 : }
1443 :
1444 : // we should never reach this, but one never knows....
1445 0 : if( (pMaster == NULL) || (pNotesMaster == NULL) )
1446 : {
1447 0 : pUndoMgr->LeaveListAction();
1448 :
1449 0 : if( mpDocSh )
1450 0 : mpDocSh->SetWaitCursor( sal_False );
1451 :
1452 : OSL_FAIL( "SdDrawDocument::SetMasterPage() failed!" );
1453 :
1454 0 : return;
1455 : }
1456 :
1457 0 : if (pSourceDoc != this)
1458 : {
1459 0 : const sal_uInt16 nMasterPageCount = GetMasterPageCount();
1460 0 : for ( sal_uInt16 nMPage = 0; nMPage < nMasterPageCount; nMPage++ )
1461 : {
1462 0 : SdPage* pCheckMaster = (SdPage*)GetMasterPage(nMPage);
1463 0 : if( pCheckMaster->GetName() == aNewLayoutName )
1464 : {
1465 0 : bLayoutReloaded = sal_True;
1466 0 : break;
1467 : }
1468 : }
1469 :
1470 : /*****************************************************************
1471 : |* Praesentationsvorlagen korrigieren bzw. neu anlegen
1472 : \****************************************************************/
1473 : // nur die Praesentationsvorlagen beachten
1474 0 : String aName;
1475 0 : SdStyleSheetPool* pSourceStyleSheetPool = (SdStyleSheetPool*) pSourceDoc->GetStyleSheetPool();
1476 0 : pSourceStyleSheetPool->SetSearchMask(SD_STYLE_FAMILY_MASTERPAGE);
1477 0 : static_cast<SdStyleSheetPool*>( mxStyleSheetPool.get())->SetSearchMask(SD_STYLE_FAMILY_MASTERPAGE);
1478 :
1479 0 : SdStyleSheetVector aCreatedStyles; // Liste fuer erzeugte StyleSheets
1480 0 : SfxStyleSheetBase* pHisSheet = pSourceStyleSheetPool->First();
1481 :
1482 0 : while (pHisSheet)
1483 : {
1484 0 : aName = pHisSheet->GetName();
1485 :
1486 0 : if( aName.Search( aNewLayoutName ) == 0 )
1487 : {
1488 0 : SfxStyleSheet* pMySheet = static_cast<SfxStyleSheet*>( mxStyleSheetPool->Find(aName, SD_STYLE_FAMILY_MASTERPAGE) );
1489 :
1490 0 : if (pMySheet)
1491 : {
1492 : // Es ist eine gleichnamige Vorlage vorhanden ist: Inhalte ersetzen
1493 : #ifdef DBG_UTIL
1494 : sal_Bool bTest =
1495 : #endif
1496 0 : pMySheet->SetName(pHisSheet->GetName());
1497 : DBG_ASSERT(bTest, "StyleSheet-Umbenennung fehlgeschlagen");
1498 0 : pMySheet->GetItemSet().ClearItem(0); // alle loeschen
1499 :
1500 : StyleSheetUndoAction* pUndoChStyle = new StyleSheetUndoAction(this,
1501 0 : pMySheet, &pHisSheet->GetItemSet());
1502 0 : pUndoMgr->AddUndoAction(pUndoChStyle);
1503 0 : pMySheet->GetItemSet().Put(pHisSheet->GetItemSet());
1504 0 : pMySheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
1505 : }
1506 : else
1507 : {
1508 : // create new style
1509 0 : String aHelpFile;
1510 0 : pMySheet = static_cast<SfxStyleSheet*>( &mxStyleSheetPool->Make(aName, SD_STYLE_FAMILY_MASTERPAGE, pHisSheet->GetMask()) );
1511 0 : pMySheet->SetHelpId( aHelpFile, pHisSheet->GetHelpId(aHelpFile) );
1512 0 : pMySheet->GetItemSet().ClearItem(0); // alle loeschen
1513 0 : pMySheet->GetItemSet().Put(pHisSheet->GetItemSet());
1514 :
1515 0 : aCreatedStyles.push_back( SdStyleSheetRef( static_cast< SdStyleSheet* >( pMySheet ) ) );
1516 : }
1517 :
1518 0 : StyleReplaceData aReplData;
1519 0 : aReplData.nNewFamily = pMySheet->GetFamily();
1520 0 : aReplData.nFamily = pMySheet->GetFamily();
1521 0 : aReplData.aNewName = pMySheet->GetName();
1522 :
1523 0 : String aTemp(pMySheet->GetName());
1524 0 : sal_uInt16 nPos = aTemp.SearchAscii( SD_LT_SEPARATOR );
1525 0 : aTemp.Erase(0, nPos);
1526 0 : aTemp.Insert(aOldLayoutName, 0);
1527 0 : aReplData.aName = aTemp;
1528 0 : aReplList.push_back(aReplData);
1529 : }
1530 :
1531 0 : pHisSheet = (SfxStyleSheet*) pSourceStyleSheetPool->Next();
1532 : }
1533 :
1534 : // wenn neue Vorlagen erzeugt wurden:
1535 : // eventuell bestehende Parent-Verkettung der Itemsets in den
1536 : // Vorlagen wieder aufbauen
1537 0 : if(!aCreatedStyles.empty())
1538 : {
1539 0 : std::vector<StyleReplaceData>::iterator pRDataIter;
1540 0 : for ( pRDataIter = aReplList.begin(); pRDataIter != aReplList.end(); ++pRDataIter )
1541 : {
1542 0 : SfxStyleSheetBase* pSOld = mxStyleSheetPool->Find(pRDataIter->aName);
1543 0 : SfxStyleSheetBase* pSNew = mxStyleSheetPool->Find(pRDataIter->aNewName);
1544 :
1545 0 : if (pSOld && pSNew)
1546 : {
1547 0 : const String& rParentOfOld = pSOld->GetParent();
1548 0 : const String& rParentOfNew = pSNew->GetParent();
1549 :
1550 0 : if (rParentOfOld.Len() > 0 && rParentOfNew.Len() == 0)
1551 : {
1552 0 : std::vector<StyleReplaceData>::iterator pRDIter;
1553 0 : for ( pRDIter = aReplList.begin(); pRDIter != aReplList.end(); ++pRDIter )
1554 : {
1555 0 : if ((pRDIter->aName == rParentOfOld) && (pRDIter->aName != pRDIter->aNewName))
1556 : {
1557 0 : String aParentOfNew(pRDIter->aNewName);
1558 0 : pSNew->SetParent(aParentOfNew);
1559 0 : break;
1560 : }
1561 : }
1562 : }
1563 : }
1564 : }
1565 :
1566 : // ab jetzt beim Suchen alle beachten
1567 0 : pSourceStyleSheetPool->SetSearchMask(SFX_STYLE_FAMILY_ALL);
1568 0 : mxStyleSheetPool->SetSearchMask(SFX_STYLE_FAMILY_ALL);
1569 : }
1570 :
1571 0 : if( !aCreatedStyles.empty() )
1572 : {
1573 : // UndoAction fuer das Erzeugen und Einfuegen vorn StyleSheets
1574 : // auf den UndoManager legen
1575 0 : SdMoveStyleSheetsUndoAction* pMovStyles = new SdMoveStyleSheetsUndoAction( this, aCreatedStyles, sal_True);
1576 0 : pUndoMgr->AddUndoAction(pMovStyles);
1577 0 : }
1578 : }
1579 :
1580 : // Layoutnamen auf Basis des Seitenlayoutnamens der Masterpage bilden
1581 0 : String aPageLayoutName(pMaster->GetLayoutName());
1582 0 : String aLayoutName = aPageLayoutName;
1583 0 : aLayoutName.Erase( aLayoutName.SearchAscii( SD_LT_SEPARATOR ));
1584 :
1585 0 : if (pSourceDoc != this)
1586 : {
1587 : // Aus dem Source-Dokument austragen
1588 0 : pSourceDoc->RemoveMasterPage(pNotesMaster->GetPageNum());
1589 0 : pSourceDoc->RemoveMasterPage(pMaster->GetPageNum());
1590 : }
1591 :
1592 : /*********************************************************************
1593 : |* Neue MasterPages ins Dokument eintragen und den Standard- und
1594 : |* Notizseiten das Praesentationslayout ueberbraten
1595 : \********************************************************************/
1596 0 : if (pSourceDoc != this)
1597 : {
1598 : // Die Masterpages einfuegen:
1599 : // Masterpages von neuen Layouts hinten anhaengen; wird ein Layout
1600 : // dagegen ersetzt, so muss vor der Position der alten Masterpage
1601 : // eingefuegt werden, damit ab jetzt beim Suchen (z. B. SdPage::
1602 : // SetPresentationLayout) die neue Masterpage zuerst gefunden wird
1603 0 : sal_uInt16 nInsertPos = rOldMaster.GetPageNum();
1604 0 : BegUndo();
1605 :
1606 0 : if (!bLayoutReloaded)
1607 0 : nInsertPos = 0xFFFF;
1608 0 : InsertMasterPage(pMaster, nInsertPos);
1609 0 : if( bUndo )
1610 0 : AddUndo(GetSdrUndoFactory().CreateUndoNewPage(*pMaster));
1611 :
1612 0 : nInsertPos++;
1613 0 : if (!bLayoutReloaded)
1614 0 : nInsertPos = 0xFFFF;
1615 0 : InsertMasterPage(pNotesMaster, nInsertPos);
1616 0 : if( bUndo )
1617 : {
1618 0 : AddUndo(GetSdrUndoFactory().CreateUndoNewPage(*pNotesMaster));
1619 :
1620 0 : EndUndo(); // schon hier, damit sich Joes Actions ZWISCHEN unsere eigenen schieben
1621 : }
1622 : }
1623 :
1624 : // Liste mit Seiten fuellen
1625 0 : std::vector<SdPage*> aPageList;
1626 :
1627 : // #98456, this has to be removed according to CL (KA 07/08/2002)
1628 : // #109884# but we need them again to restore the styles of the presentation objects while undo
1629 0 : aPageList.push_back(pMaster);
1630 0 : aPageList.push_back(pNotesMaster);
1631 :
1632 0 : if (bMaster || bLayoutReloaded)
1633 : {
1634 0 : for (sal_uInt16 nPage = 1; nPage < GetPageCount(); nPage++)
1635 : {
1636 0 : pPage = (SdPage*) GetPage(nPage);
1637 0 : String aTest = pPage->GetLayoutName();
1638 0 : if (aTest == aOldPageLayoutName)
1639 : {
1640 0 : aPageList.push_back(pPage);
1641 : }
1642 0 : }
1643 :
1644 : }
1645 : else
1646 : {
1647 0 : aPageList.push_back(pSelectedPage);
1648 0 : aPageList.push_back(pNotes);
1649 : }
1650 :
1651 0 : for (std::vector<SdPage*>::iterator pIter = aPageList.begin(); pIter != aPageList.end(); ++pIter)
1652 : {
1653 0 : AutoLayout eAutoLayout = (*pIter)->GetAutoLayout();
1654 :
1655 0 : if( bUndo )
1656 : {
1657 : SdPresentationLayoutUndoAction * pPLUndoAction =
1658 : new SdPresentationLayoutUndoAction
1659 : (this,
1660 0 : ( pPage && pPage->IsMasterPage() ) ? aLayoutName : aOldLayoutName,
1661 : aLayoutName,
1662 0 : eAutoLayout, eAutoLayout, sal_False, *pIter);
1663 0 : pUndoMgr->AddUndoAction(pPLUndoAction);
1664 : }
1665 0 : (*pIter)->SetPresentationLayout(aLayoutName);
1666 0 : (*pIter)->SetAutoLayout(eAutoLayout);
1667 : }
1668 :
1669 : /*********************************************************************
1670 : |* Neue Masterpages angleichen
1671 : \********************************************************************/
1672 0 : if (pSourceDoc != this)
1673 : {
1674 : // die Masterpages angleichen
1675 0 : Size aSize(rOldMaster.GetSize());
1676 0 : Rectangle aBorderRect(rOldMaster.GetLftBorder(),
1677 0 : rOldMaster.GetUppBorder(),
1678 0 : rOldMaster.GetRgtBorder(),
1679 0 : rOldMaster.GetLwrBorder());
1680 0 : pMaster->ScaleObjects(aSize, aBorderRect, sal_True);
1681 0 : pMaster->SetSize(aSize);
1682 0 : pMaster->SetBorder(rOldMaster.GetLftBorder(),
1683 0 : rOldMaster.GetUppBorder(),
1684 0 : rOldMaster.GetRgtBorder(),
1685 0 : rOldMaster.GetLwrBorder());
1686 0 : pMaster->SetOrientation( rOldMaster.GetOrientation() );
1687 0 : pMaster->SetAutoLayout(pMaster->GetAutoLayout());
1688 :
1689 0 : aSize = rOldNotesMaster.GetSize();
1690 0 : Rectangle aNotesBorderRect(rOldNotesMaster.GetLftBorder(),
1691 0 : rOldNotesMaster.GetUppBorder(),
1692 0 : rOldNotesMaster.GetRgtBorder(),
1693 0 : rOldNotesMaster.GetLwrBorder());
1694 0 : pNotesMaster->ScaleObjects(aSize, aNotesBorderRect, sal_True);
1695 0 : pNotesMaster->SetSize(aSize);
1696 0 : pNotesMaster->SetBorder(rOldNotesMaster.GetLftBorder(),
1697 0 : rOldNotesMaster.GetUppBorder(),
1698 0 : rOldNotesMaster.GetRgtBorder(),
1699 0 : rOldNotesMaster.GetLwrBorder());
1700 0 : pNotesMaster->SetOrientation( rOldNotesMaster.GetOrientation() );
1701 0 : pNotesMaster->SetAutoLayout(pNotesMaster->GetAutoLayout());
1702 :
1703 0 : if( (pSourceDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS) &&
1704 0 : (GetDocumentType() == DOCUMENT_TYPE_DRAW) )
1705 : {
1706 0 : pMaster->RemoveEmptyPresentationObjects();
1707 0 : pNotesMaster->RemoveEmptyPresentationObjects();
1708 : }
1709 0 : }
1710 : }
1711 : else
1712 : {
1713 : /*********************************************************************
1714 : |* Einen neuen Layoutnamen ausdenken
1715 : \********************************************************************/
1716 0 : String aName = String(SdResId(STR_LAYOUT_DEFAULT_NAME));
1717 0 : String aTest;
1718 0 : sal_Bool bNotANewName = sal_True;
1719 0 : sal_uInt16 nCount = 0;
1720 0 : sal_uInt16 nMPgCount = GetMasterPageCount();
1721 :
1722 0 : for (nCount = 0; bNotANewName; nCount++)
1723 : {
1724 : // Testnamen bilden
1725 0 : aTest = aName; // Standard, Standard1, Standard2, ...
1726 0 : if (nCount > 0)
1727 0 : aTest += String::CreateFromInt32( nCount );
1728 :
1729 : // gibt's schon eine, die so heisst?
1730 0 : bNotANewName = sal_False;
1731 0 : for (sal_uInt16 nMPg = 1; nMPg < nMPgCount; nMPg++)
1732 : {
1733 0 : const SdrPage* pTest = GetMasterPage(nMPg);
1734 0 : String aPageLayoutName(pTest->GetLayoutName());
1735 0 : aPageLayoutName.Erase( aPageLayoutName.SearchAscii( SD_LT_SEPARATOR ));
1736 :
1737 0 : if (aPageLayoutName == aTest)
1738 0 : bNotANewName = sal_True;
1739 0 : }
1740 : }
1741 0 : aName = aTest;
1742 0 : String aPageLayoutName(aName);
1743 0 : aPageLayoutName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( SD_LT_SEPARATOR ));
1744 0 : aPageLayoutName += String(SdResId(STR_LAYOUT_OUTLINE));
1745 :
1746 : /*********************************************************************
1747 : |* Neue StyleSheets erzeugen
1748 : \********************************************************************/
1749 0 : static_cast<SdStyleSheetPool*>( mxStyleSheetPool.get())->CreateLayoutStyleSheets(aName);
1750 0 : SdStyleSheetVector aCreatedStyles;
1751 0 : static_cast<SdStyleSheetPool*>( mxStyleSheetPool.get())->CreateLayoutSheetList(aName, aCreatedStyles);
1752 :
1753 0 : if( bUndo )
1754 : {
1755 0 : SdMoveStyleSheetsUndoAction* pMovStyles = new SdMoveStyleSheetsUndoAction(this, aCreatedStyles, sal_True);
1756 0 : pUndoMgr->AddUndoAction(pMovStyles);
1757 : }
1758 :
1759 : /*********************************************************************
1760 : |* Neue MasterPages erzeugen und ins Dokument eintragen
1761 : \********************************************************************/
1762 :
1763 0 : if( bUndo )
1764 0 : BegUndo();
1765 :
1766 0 : pMaster = (SdPage*) AllocPage(sal_True);
1767 0 : pMaster->SetSize(pSelectedPage->GetSize());
1768 0 : pMaster->SetBorder(pSelectedPage->GetLftBorder(),
1769 0 : pSelectedPage->GetUppBorder(),
1770 0 : pSelectedPage->GetRgtBorder(),
1771 0 : pSelectedPage->GetLwrBorder() );
1772 0 : pMaster->SetName(aName);
1773 0 : pMaster->SetLayoutName(aPageLayoutName);
1774 0 : InsertMasterPage(pMaster);
1775 :
1776 0 : if( bUndo )
1777 0 : AddUndo(GetSdrUndoFactory().CreateUndoNewPage(*pMaster));
1778 :
1779 0 : pMaster->SetAutoLayout(AUTOLAYOUT_NONE, true, true);
1780 :
1781 0 : pNotesMaster = (SdPage*) AllocPage(sal_True);
1782 0 : pNotesMaster->SetPageKind(PK_NOTES);
1783 0 : pNotesMaster->SetSize(pNotes->GetSize());
1784 0 : pNotesMaster->SetBorder(pNotes->GetLftBorder(),
1785 0 : pNotes->GetUppBorder(),
1786 0 : pNotes->GetRgtBorder(),
1787 0 : pNotes->GetLwrBorder() );
1788 0 : pNotesMaster->SetName(aName);
1789 0 : pNotesMaster->SetLayoutName(aPageLayoutName);
1790 0 : InsertMasterPage(pNotesMaster);
1791 :
1792 0 : if( bUndo )
1793 0 : AddUndo(GetSdrUndoFactory().CreateUndoNewPage(*pNotesMaster));
1794 :
1795 0 : pNotesMaster->SetAutoLayout(AUTOLAYOUT_NOTES, true, true);
1796 :
1797 0 : if( bUndo )
1798 0 : EndUndo();
1799 :
1800 : /*********************************************************************
1801 : |* Liste der betroffenen Standard- und Notizseiten erstellen
1802 : \********************************************************************/
1803 0 : std::vector<SdPage*> aPageList;
1804 0 : if (bMaster)
1805 : {
1806 0 : for (sal_uInt16 nPage = 1; nPage < GetPageCount(); nPage++)
1807 : {
1808 0 : pPage = (SdPage*) GetPage(nPage);
1809 0 : const String s(pPage->GetLayoutName());
1810 0 : if(s == aOldPageLayoutName)
1811 : {
1812 0 : aPageList.push_back(pPage);
1813 : }
1814 0 : }
1815 : }
1816 : else
1817 : {
1818 0 : aPageList.push_back(pSelectedPage);
1819 0 : aPageList.push_back(pNotes);
1820 : }
1821 :
1822 : /*********************************************************************
1823 : |* An den betroffenen Seiten Praesentations- und Autolayout setzen
1824 : \********************************************************************/
1825 0 : for ( std::vector<SdPage*>::iterator pIter = aPageList.begin(); pIter != aPageList.end(); ++pIter )
1826 : {
1827 0 : AutoLayout eOldAutoLayout = (*pIter)->GetAutoLayout();
1828 : AutoLayout eNewAutoLayout =
1829 0 : (*pIter)->GetPageKind() == PK_STANDARD ? AUTOLAYOUT_NONE : AUTOLAYOUT_NOTES;
1830 :
1831 0 : if( bUndo )
1832 : {
1833 : SdPresentationLayoutUndoAction * pPLUndoAction =
1834 : new SdPresentationLayoutUndoAction
1835 : (this, aOldLayoutName, aName,
1836 : eOldAutoLayout, eNewAutoLayout, sal_True,
1837 0 : *pIter);
1838 0 : pUndoMgr->AddUndoAction(pPLUndoAction);
1839 : }
1840 :
1841 0 : (*pIter)->SetPresentationLayout(aName);
1842 0 : (*pIter)->SetAutoLayout(eNewAutoLayout);
1843 0 : }
1844 : }
1845 :
1846 : /*********************************************************************
1847 : |* falls die alten Masterpages nicht mehr benoetigt werden,
1848 : |* muessen sie und die entsprechenden Praesentationsvorlagen
1849 : |* entfernt werden
1850 : \********************************************************************/
1851 0 : if (bCheckMasters)
1852 : {
1853 : // Alle pruefen
1854 0 : RemoveUnnecessaryMasterPages();
1855 : }
1856 : else
1857 : {
1858 : // Nur die ausgetauschte MasterPage pruefen
1859 0 : RemoveUnnecessaryMasterPages(&rOldMaster);
1860 : }
1861 :
1862 0 : if( bUndo )
1863 0 : pUndoMgr->LeaveListAction();
1864 :
1865 0 : if( mpDocSh )
1866 0 : mpDocSh->SetWaitCursor( sal_False );
1867 : }
1868 :
1869 :
1870 :
1871 0 : void SdDrawDocument::Merge(SdrModel& rSourceModel,
1872 : sal_uInt16 nFirstPageNum, sal_uInt16 nLastPageNum,
1873 : sal_uInt16 nDestPos,
1874 : bool bMergeMasterPages, bool bAllMasterPages,
1875 : bool bUndo, bool bTreadSourceAsConst)
1876 : {
1877 0 : sal_uInt16 nMasterPageCount = GetMasterPageCount();
1878 0 : SdrModel::Merge( rSourceModel, nFirstPageNum, nLastPageNum, nDestPos, bMergeMasterPages, bAllMasterPages, bUndo, bTreadSourceAsConst );
1879 :
1880 : // add style family for each new master page
1881 0 : for( sal_uInt16 nMaster = nMasterPageCount; nMaster < GetMasterPageCount(); nMaster++ )
1882 : {
1883 0 : SdPage* pPage = static_cast< SdPage* >( GetMasterPage( nMaster ) );
1884 0 : if( pPage && pPage->IsMasterPage() && (pPage->GetPageKind() == PK_STANDARD) )
1885 : {
1886 : // new master page created, add its style family
1887 0 : SdStyleSheetPool* pStylePool = (SdStyleSheetPool*) GetStyleSheetPool();
1888 0 : if( pStylePool )
1889 0 : pStylePool->AddStyleFamily( pPage );
1890 : }
1891 : }
1892 9 : }
1893 :
1894 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|