update credits
[LibreOffice.git] / sd / source / core / drawdoc2.cxx
blob73ae2771f05214de67a50251413ed806373ae799
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/XVisualObject.hpp>
21 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
22 #include <vcl/wrkwin.hxx>
23 #include <sfx2/printer.hxx>
24 #include <sfx2/app.hxx>
25 #include "Outliner.hxx"
26 #include <editeng/paperinf.hxx>
27 #include <svx/svdopage.hxx>
28 #include <svx/svdoole2.hxx>
29 #include <svx/svdotext.hxx>
30 #include <svx/svdograf.hxx>
31 #include <svx/svdundo.hxx>
32 #include <vcl/svapp.hxx>
33 #include <editeng/eeitem.hxx>
34 #include <editeng/langitem.hxx>
35 #include <svl/itempool.hxx>
36 #include <svx/svdpool.hxx>
37 #include <editeng/flditem.hxx>
39 #include <sfx2/linkmgr.hxx>
40 #include <editeng/editdata.hxx>
41 #include <svx/dialogs.hrc>
42 #include <svx/dialmgr.hxx> // SVX_RESSTR
44 #include <editeng/outliner.hxx>
45 #include <svx/svditer.hxx>
46 #include <svtools/imapobj.hxx>
49 #include "sdresid.hxx"
50 #include "drawdoc.hxx"
51 #include "sdpage.hxx"
52 #include "pglink.hxx"
53 #include "glob.hrc"
54 #include "glob.hxx"
55 #include "stlpool.hxx"
56 #include "sdiocmpt.hxx"
57 #include "anminfo.hxx"
58 #include "imapinfo.hxx"
59 #include "cusshow.hxx"
60 #include "undo/undomanager.hxx"
62 #include "../ui/inc/DrawDocShell.hxx"
63 #include "../ui/inc/FrameView.hxx"
64 #include "../ui/inc/cfgids.hxx"
65 #include "../ui/inc/strings.hrc"
67 #include "PageListWatcher.hxx"
68 #include <vcl/virdev.hxx>
69 #include "customshowlist.hxx"
71 using namespace ::sd;
73 const long PRINT_OFFSET = 30; // see /svx/source/dialog/page.cxx
75 using namespace com::sun::star;
77 // Looks up an object by name
78 SdrObject* SdDrawDocument::GetObj(const String& rObjName) const
80 SdrObject* pObj = NULL;
81 SdrObject* pObjFound = NULL;
82 SdPage* pPage = NULL;
84 // First search in all pages
85 sal_uInt16 nPage = 0;
86 const sal_uInt16 nMaxPages = GetPageCount();
88 while (nPage < nMaxPages && !pObjFound)
90 pPage = (SdPage*) GetPage(nPage);
91 SdrObjListIter aIter(*pPage, IM_DEEPWITHGROUPS);
93 while (aIter.IsMore() && !pObjFound)
95 pObj = aIter.Next();
97 if( ( pObj->GetName().equals(rObjName) ) ||
98 ( SdrInventor == pObj->GetObjInventor() &&
99 OBJ_OLE2 == pObj->GetObjIdentifier() &&
100 rObjName == static_cast< SdrOle2Obj* >( pObj )->GetPersistName() ) )
102 pObjFound = pObj;
106 nPage++;
109 // If it couldn't be found, look through all master pages
110 nPage = 0;
111 const sal_uInt16 nMaxMasterPages = GetMasterPageCount();
113 while (nPage < nMaxMasterPages && !pObjFound)
115 pPage = (SdPage*) GetMasterPage(nPage);
116 SdrObjListIter aIter(*pPage, IM_DEEPWITHGROUPS);
118 while (aIter.IsMore() && !pObjFound)
120 pObj = aIter.Next();
122 if( ( pObj->GetName().equals(rObjName) ) ||
123 ( SdrInventor == pObj->GetObjInventor() &&
124 OBJ_OLE2 == pObj->GetObjIdentifier() &&
125 rObjName == static_cast< SdrOle2Obj* >( pObj )->GetPersistName() ) )
127 pObjFound = pObj;
131 nPage++;
134 return (pObjFound);
138 // Find SdPage by name
139 sal_uInt16 SdDrawDocument::GetPageByName(const String& rPgName, sal_Bool& rbIsMasterPage) const
141 SdPage* pPage = NULL;
142 sal_uInt16 nPage = 0;
143 const sal_uInt16 nMaxPages = GetPageCount();
144 sal_uInt16 nPageNum = SDRPAGE_NOTFOUND;
146 rbIsMasterPage = sal_False;
148 // Search all regular pages and all notes pages (handout pages are
149 // ignored)
150 while (nPage < nMaxPages && nPageNum == SDRPAGE_NOTFOUND)
152 pPage = const_cast<SdPage*>(static_cast<const SdPage*>(
153 GetPage(nPage)));
155 if (pPage != NULL
156 && pPage->GetPageKind() != PK_HANDOUT
157 && pPage->GetName() == rPgName)
159 nPageNum = nPage;
162 nPage++;
165 // Search all master pages when not found among non-master pages
166 const sal_uInt16 nMaxMasterPages = GetMasterPageCount();
167 nPage = 0;
169 while (nPage < nMaxMasterPages && nPageNum == SDRPAGE_NOTFOUND)
171 pPage = const_cast<SdPage*>(static_cast<const SdPage*>(
172 GetMasterPage(nPage)));
174 if (pPage && pPage->GetName() == rPgName)
176 nPageNum = nPage;
177 rbIsMasterPage = sal_True;
180 nPage++;
183 return nPageNum;
186 SdPage* SdDrawDocument::GetSdPage(sal_uInt16 nPgNum, PageKind ePgKind) const
188 return mpDrawPageListWatcher->GetSdPage(ePgKind, sal_uInt32(nPgNum));
191 sal_uInt16 SdDrawDocument::GetSdPageCount(PageKind ePgKind) const
193 return (sal_uInt16)mpDrawPageListWatcher->GetSdPageCount(ePgKind);
196 SdPage* SdDrawDocument::GetMasterSdPage(sal_uInt16 nPgNum, PageKind ePgKind)
198 return mpMasterPageListWatcher->GetSdPage(ePgKind, sal_uInt32(nPgNum));
201 sal_uInt16 SdDrawDocument::GetMasterSdPageCount(PageKind ePgKind) const
203 return (sal_uInt16)mpMasterPageListWatcher->GetSdPageCount(ePgKind);
206 sal_uInt16 SdDrawDocument::GetActiveSdPageCount() const
208 return (sal_uInt16)mpDrawPageListWatcher->GetVisibleSdPageCount();
211 // Adapt the page numbers that are registered in the page objects of the notes
212 // pages
213 void SdDrawDocument::UpdatePageObjectsInNotes(sal_uInt16 nStartPos)
215 sal_uInt16 nPageCount = GetPageCount();
216 SdPage* pPage = NULL;
218 for (sal_uInt16 nPage = nStartPos; nPage < nPageCount; nPage++)
220 pPage = (SdPage*)GetPage(nPage);
222 // If this is a notes page, find its page object and correct the page
223 // number
224 if (pPage && pPage->GetPageKind() == PK_NOTES)
226 sal_uLong nObjCount = pPage->GetObjCount();
227 SdrObject* pObj = NULL;
228 for (sal_uLong nObj = 0; nObj < nObjCount; nObj++)
230 pObj = pPage->GetObj(nObj);
231 if (pObj->GetObjIdentifier() == OBJ_PAGE &&
232 pObj->GetObjInventor() == SdrInventor)
234 // The page object is the preceding page (drawing page)
235 DBG_ASSERTWARNING(nStartPos, "Position of notes page must not be 0.");
237 DBG_ASSERTWARNING(nPage > 1, "Page object must not be a handout.");
239 if (nStartPos > 0 && nPage > 1)
240 ((SdrPageObj*)pObj)->SetReferencedPage(GetPage(nPage - 1));
247 void SdDrawDocument::UpdatePageRelativeURLs(const String& rOldName, const String& rNewName)
249 if (rNewName.Len() == 0)
250 return;
252 SfxItemPool& pPool(GetPool());
253 sal_uInt32 nCount = pPool.GetItemCount2(EE_FEATURE_FIELD);
254 for (sal_uInt32 nOff = 0; nOff < nCount; nOff++)
256 const SfxPoolItem *pItem = pPool.GetItem2(EE_FEATURE_FIELD, nOff);
257 const SvxFieldItem* pFldItem = dynamic_cast< const SvxFieldItem * > (pItem);
259 if(pFldItem)
261 SvxURLField* pURLField = const_cast< SvxURLField* >( dynamic_cast<const SvxURLField*>( pFldItem->GetField() ) );
263 if(pURLField)
265 XubString aURL = pURLField->GetURL();
267 if (aURL.Len() && (aURL.GetChar(0) == 35) && (aURL.Search(rOldName, 1) == 1))
269 if (aURL.Len() == rOldName.Len() + 1) // standard page name
271 aURL.Erase (1, aURL.Len() - 1);
272 aURL += rNewName;
273 pURLField->SetURL(aURL);
275 else
277 const XubString sNotes = SdResId(STR_NOTES);
278 if (aURL.Len() == rOldName.Len() + 2 + sNotes.Len() && aURL.Search(sNotes, rOldName.Len() + 2) == rOldName.Len() + 2)
280 aURL.Erase (1, aURL.Len() - 1);
281 aURL += rNewName;
282 aURL += ' ';
283 aURL += sNotes;
284 pURLField->SetURL(aURL);
293 void SdDrawDocument::UpdatePageRelativeURLs(SdPage* pPage, sal_uInt16 nPos, sal_Int32 nIncrement)
295 bool bNotes = (pPage->GetPageKind() == PK_NOTES);
297 SfxItemPool& pPool(GetPool());
298 sal_uInt32 nCount = pPool.GetItemCount2(EE_FEATURE_FIELD);
299 for (sal_uInt32 nOff = 0; nOff < nCount; nOff++)
301 const SfxPoolItem *pItem = pPool.GetItem2(EE_FEATURE_FIELD, nOff);
302 const SvxFieldItem* pFldItem;
304 if ((pFldItem = dynamic_cast< const SvxFieldItem * > (pItem)) != 0)
306 SvxURLField* pURLField = const_cast< SvxURLField* >( dynamic_cast<const SvxURLField*>( pFldItem->GetField() ) );
308 if(pURLField)
310 XubString aURL = pURLField->GetURL();
312 if (aURL.Len() && (aURL.GetChar(0) == 35))
314 XubString aHashSlide = OUString('#');
315 aHashSlide += SD_RESSTR(STR_PAGE);
317 if (aURL.CompareTo(aHashSlide, aHashSlide.Len()) == COMPARE_EQUAL)
319 XubString aURLCopy = aURL;
320 const XubString sNotes = SdResId(STR_NOTES);
322 aURLCopy.Erase(0, aHashSlide.Len());
324 bool bNotesLink = (aURLCopy.Len() >= sNotes.Len() + 3 && aURLCopy.Search(sNotes, aURLCopy.Len() - sNotes.Len()) == aURLCopy.Len() - sNotes.Len());
326 if (bNotesLink ^ bNotes)
327 continue; // no compatible link and page
329 if (bNotes)
330 aURLCopy.Erase(aURLCopy.Len() - sNotes.Len(), sNotes.Len());
332 sal_Int32 number = aURLCopy.ToInt32();
333 sal_uInt16 realPageNumber = (nPos + 1)/ 2;
335 if ( number >= realPageNumber )
337 // update link page number
338 number += nIncrement;
339 aURL.Erase (aHashSlide.Len() + 1, aURL.Len() - aHashSlide.Len() - 1);
340 aURL += OUString::number(number);
341 if (bNotes)
343 aURL += ' ';
344 aURL += sNotes;
346 pURLField->SetURL(aURL);
355 // Move page
356 void SdDrawDocument::MovePage(sal_uInt16 nPgNum, sal_uInt16 nNewPos)
358 FmFormModel::MovePage(nPgNum, nNewPos);
360 sal_uInt16 nMin = std::min(nPgNum, nNewPos);
362 UpdatePageObjectsInNotes(nMin);
365 // Insert page
366 void SdDrawDocument::InsertPage(SdrPage* pPage, sal_uInt16 nPos)
368 bool bLast = (nPos == GetPageCount());
370 FmFormModel::InsertPage(pPage, nPos);
372 ((SdPage*)pPage)->ConnectLink();
374 UpdatePageObjectsInNotes(nPos);
376 if (!bLast)
377 UpdatePageRelativeURLs(static_cast<SdPage*>( pPage ), nPos, 1);
381 // Delete page
382 void SdDrawDocument::DeletePage(sal_uInt16 nPgNum)
384 FmFormModel::DeletePage(nPgNum);
386 UpdatePageObjectsInNotes(nPgNum);
389 // Remove page
390 SdrPage* SdDrawDocument::RemovePage(sal_uInt16 nPgNum)
392 SdrPage* pPage = FmFormModel::RemovePage(nPgNum);
394 bool bLast = ((nPgNum+1)/2 == (GetPageCount()+1)/2);
396 ((SdPage*)pPage)->DisconnectLink();
397 ReplacePageInCustomShows( dynamic_cast< SdPage* >( pPage ), 0 );
398 UpdatePageObjectsInNotes(nPgNum);
400 if (!bLast)
401 UpdatePageRelativeURLs((SdPage*)pPage, nPgNum, -1);
403 return pPage;
406 // Warning: This is not called for new master pages created from SdrModel::Merge,
407 // you also have to modify code in SdDrawDocument::Merge!
408 void SdDrawDocument::InsertMasterPage(SdrPage* pPage, sal_uInt16 nPos )
410 FmFormModel::InsertMasterPage( pPage, nPos );
411 if( pPage && pPage->IsMasterPage() && (static_cast<SdPage*>(pPage)->GetPageKind() == PK_STANDARD) )
413 // new master page created, add its style family
414 SdStyleSheetPool* pStylePool = (SdStyleSheetPool*) GetStyleSheetPool();
415 if( pStylePool )
416 pStylePool->AddStyleFamily( static_cast<SdPage*>(pPage) );
420 SdrPage* SdDrawDocument::RemoveMasterPage(sal_uInt16 nPgNum)
422 SdPage* pPage = static_cast<SdPage*>(GetMasterPage(nPgNum ));
423 if( pPage && pPage->IsMasterPage() && (pPage->GetPageKind() == PK_STANDARD) )
425 // master page removed, remove its style family
426 SdStyleSheetPool* pStylePool = (SdStyleSheetPool*) GetStyleSheetPool();
427 if( pStylePool )
428 pStylePool->RemoveStyleFamily( pPage );
431 return FmFormModel::RemoveMasterPage(nPgNum);
434 //Select pages
435 void SdDrawDocument::SetSelected(SdPage* pPage, sal_Bool bSelect)
437 PageKind ePageKind = pPage->GetPageKind();
439 if (ePageKind == PK_STANDARD)
441 pPage->SetSelected(bSelect);
443 const sal_uInt16 nDestPageNum(pPage->GetPageNum() + 1);
444 SdPage* pNotesPage = 0L;
446 if(nDestPageNum < GetPageCount())
448 pNotesPage = (SdPage*)GetPage(nDestPageNum);
451 if (pNotesPage && pNotesPage->GetPageKind() == PK_NOTES)
453 pNotesPage->SetSelected(bSelect);
456 else if (ePageKind == PK_NOTES)
458 pPage->SetSelected(bSelect);
459 SdPage* pStandardPage = (SdPage*) GetPage( pPage->GetPageNum() - 1 );
461 if (pStandardPage && pStandardPage->GetPageKind() == PK_STANDARD)
462 pStandardPage->SetSelected(bSelect);
466 // If no pages exist yet, create them now
467 void SdDrawDocument::CreateFirstPages( SdDrawDocument* pRefDocument /* = 0 */ )
469 // If no page exists yet in the model, (File -> New), insert a page
470 sal_uInt16 nPageCount = GetPageCount();
472 if (nPageCount <= 1)
474 // #i57181# Paper size depends on Language, like in Writer
475 Size aDefSize = SvxPaperInfo::GetDefaultPaperSize( MAP_100TH_MM );
477 // Insert handout page
478 SdPage* pHandoutPage = dynamic_cast< SdPage* >( AllocPage(sal_False) );
480 SdPage* pRefPage = NULL;
482 if( pRefDocument )
483 pRefPage = pRefDocument->GetSdPage( 0, PK_HANDOUT );
485 if( pRefPage )
487 pHandoutPage->SetSize(pRefPage->GetSize());
488 pHandoutPage->SetBorder( pRefPage->GetLftBorder(), pRefPage->GetUppBorder(), pRefPage->GetRgtBorder(), pRefPage->GetLwrBorder() );
490 else
492 pHandoutPage->SetSize(aDefSize);
493 pHandoutPage->SetBorder(0, 0, 0, 0);
496 pHandoutPage->SetPageKind(PK_HANDOUT);
497 pHandoutPage->SetName( String (SdResId(STR_HANDOUT) ) );
498 InsertPage(pHandoutPage, 0);
500 // Insert master page and register this with the handout page
501 SdPage* pHandoutMPage = (SdPage*) AllocPage(sal_True);
502 pHandoutMPage->SetSize( pHandoutPage->GetSize() );
503 pHandoutMPage->SetPageKind(PK_HANDOUT);
504 pHandoutMPage->SetBorder( pHandoutPage->GetLftBorder(),
505 pHandoutPage->GetUppBorder(),
506 pHandoutPage->GetRgtBorder(),
507 pHandoutPage->GetLwrBorder() );
508 InsertMasterPage(pHandoutMPage, 0);
509 pHandoutPage->TRG_SetMasterPage( *pHandoutMPage );
511 // Insert page
512 // If nPageCount==1 is, the model for the clipboard was created, thus a
513 // default page must already exist
514 SdPage* pPage;
515 sal_Bool bClipboard = sal_False;
517 if( pRefDocument )
518 pRefPage = pRefDocument->GetSdPage( 0, PK_STANDARD );
520 if (nPageCount == 0)
522 pPage = dynamic_cast< SdPage* >( AllocPage(sal_False) );
524 if( pRefPage )
526 pPage->SetSize( pRefPage->GetSize() );
527 pPage->SetBorder( pRefPage->GetLftBorder(), pRefPage->GetUppBorder(), pRefPage->GetRgtBorder(), pRefPage->GetLwrBorder() );
529 else if (meDocType == DOCUMENT_TYPE_DRAW)
531 // Draw: always use default size with margins
532 pPage->SetSize(aDefSize);
534 SfxPrinter* pPrinter = mpDocSh->GetPrinter(sal_False);
535 if (pPrinter && pPrinter->IsValid())
537 Size aOutSize(pPrinter->GetOutputSize());
538 Point aPageOffset(pPrinter->GetPageOffset());
539 aPageOffset -= pPrinter->PixelToLogic( Point() );
540 long nOffset = !aPageOffset.X() && !aPageOffset.X() ? 0 : PRINT_OFFSET;
542 sal_uLong nTop = aPageOffset.Y();
543 sal_uLong nLeft = aPageOffset.X();
544 sal_uLong nBottom = std::max((long)(aDefSize.Height() - aOutSize.Height() - nTop + nOffset), 0L);
545 sal_uLong nRight = std::max((long)(aDefSize.Width() - aOutSize.Width() - nLeft + nOffset), 0L);
547 pPage->SetBorder(nLeft, nTop, nRight, nBottom);
549 else
551 // The printer is not available. Use a border of 10mm
552 // on each side instead.
553 // This has to be kept synchronized with the border
554 // width set in the
555 // SvxPageDescPage::PaperSizeSelect_Impl callback.
556 pPage->SetBorder(1000, 1000, 1000, 1000);
559 else
561 // Impress: always use screen format, landscape.
562 Size aSz( SvxPaperInfo::GetPaperSize(PAPER_SCREEN_4_3, MAP_100TH_MM) );
563 pPage->SetSize( Size( aSz.Height(), aSz.Width() ) );
564 pPage->SetBorder(0, 0, 0, 0);
567 InsertPage(pPage, 1);
569 else
571 bClipboard = sal_True;
572 pPage = (SdPage*) GetPage(1);
575 // Insert master page, then register this with the page
576 SdPage* pMPage = (SdPage*) AllocPage(sal_True);
577 pMPage->SetSize( pPage->GetSize() );
578 pMPage->SetBorder( pPage->GetLftBorder(),
579 pPage->GetUppBorder(),
580 pPage->GetRgtBorder(),
581 pPage->GetLwrBorder() );
582 InsertMasterPage(pMPage, 1);
583 pPage->TRG_SetMasterPage( *pMPage );
584 if( bClipboard )
585 pMPage->SetLayoutName( pPage->GetLayoutName() );
587 // Insert notes page
588 SdPage* pNotesPage = (SdPage*) AllocPage(sal_False);
590 if( pRefDocument )
591 pRefPage = pRefDocument->GetSdPage( 0, PK_NOTES );
593 if( pRefPage )
595 pNotesPage->SetSize( pRefPage->GetSize() );
596 pNotesPage->SetBorder( pRefPage->GetLftBorder(), pRefPage->GetUppBorder(), pRefPage->GetRgtBorder(), pRefPage->GetLwrBorder() );
598 else
600 // Always use portrait format
601 if (aDefSize.Height() >= aDefSize.Width())
603 pNotesPage->SetSize(aDefSize);
605 else
607 pNotesPage->SetSize( Size(aDefSize.Height(), aDefSize.Width()) );
610 pNotesPage->SetBorder(0, 0, 0, 0);
612 pNotesPage->SetPageKind(PK_NOTES);
613 InsertPage(pNotesPage, 2);
614 if( bClipboard )
615 pNotesPage->SetLayoutName( pPage->GetLayoutName() );
617 // Insert master page, then register this with the notes page
618 SdPage* pNotesMPage = (SdPage*) AllocPage(sal_True);
619 pNotesMPage->SetSize( pNotesPage->GetSize() );
620 pNotesMPage->SetPageKind(PK_NOTES);
621 pNotesMPage->SetBorder( pNotesPage->GetLftBorder(),
622 pNotesPage->GetUppBorder(),
623 pNotesPage->GetRgtBorder(),
624 pNotesPage->GetLwrBorder() );
625 InsertMasterPage(pNotesMPage, 2);
626 pNotesPage->TRG_SetMasterPage( *pNotesMPage );
627 if( bClipboard )
628 pNotesMPage->SetLayoutName( pPage->GetLayoutName() );
631 if( !pRefPage && (meDocType != DOCUMENT_TYPE_DRAW) )
632 pPage->SetAutoLayout( AUTOLAYOUT_TITLE, sal_True, sal_True );
634 mpWorkStartupTimer = new Timer();
635 mpWorkStartupTimer->SetTimeoutHdl( LINK(this, SdDrawDocument, WorkStartupHdl) );
636 mpWorkStartupTimer->SetTimeout(2000);
637 mpWorkStartupTimer->Start();
639 SetChanged(sal_False);
643 // Creates missing notes and handout pages (after PowerPoint import).
644 // We assume that at least one default page and one default master page exist.
646 sal_Bool SdDrawDocument::CreateMissingNotesAndHandoutPages()
648 sal_Bool bOK = sal_False;
649 sal_uInt16 nPageCount = GetPageCount();
651 if (nPageCount != 0)
653 // Set PageKind
654 SdPage* pHandoutMPage = (SdPage*) GetMasterPage(0);
655 pHandoutMPage->SetPageKind(PK_HANDOUT);
657 SdPage* pHandoutPage = (SdPage*) GetPage(0);
658 pHandoutPage->SetPageKind(PK_HANDOUT);
659 pHandoutPage->TRG_SetMasterPage( *pHandoutMPage );
661 for (sal_uInt16 i = 1; i < nPageCount; i = i + 2)
663 SdPage* pPage = (SdPage*) GetPage(i);
665 if(!pPage->TRG_HasMasterPage())
667 // No master page set -> use first default master page
668 // (If there was no default page in the PPT)
669 pPage->TRG_SetMasterPage(*GetMasterPage(1));
672 SdPage* pNotesPage = (SdPage*) GetPage(i+1);
673 pNotesPage->SetPageKind(PK_NOTES);
675 // Set notes master page
676 sal_uInt16 nMasterPageAfterPagesMasterPage = (pPage->TRG_GetMasterPage()).GetPageNum() + 1;
677 pNotesPage->TRG_SetMasterPage(*GetMasterPage(nMasterPageAfterPagesMasterPage));
680 bOK = sal_True;
681 StopWorkStartupDelay();
682 SetChanged(sal_False);
685 return(bOK);
688 // + Move selected pages after said page
689 // (nTargetPage = (sal_uInt16)-1 --> move before first page)
690 // + Returns sal_True when the page has been moved
691 sal_Bool SdDrawDocument::MovePages(sal_uInt16 nTargetPage)
693 SdPage* pPage = NULL;
694 sal_uInt16 nPage;
695 sal_uInt16 nNoOfPages = GetSdPageCount(PK_STANDARD);
696 sal_Bool bSomethingHappened = sal_False;
698 const bool bUndo = IsUndoEnabled();
700 if( bUndo )
701 BegUndo(String(SdResId(STR_UNDO_MOVEPAGES)));
703 // List of selected pages
704 std::vector<SdPage*> aPageList;
705 for (nPage = 0; nPage < nNoOfPages; nPage++)
707 pPage = GetSdPage(nPage, PK_STANDARD);
709 if (pPage->IsSelected())
710 aPageList.push_back(pPage);
713 // If necessary, look backwards, until we find a page that wasn't selected
714 nPage = nTargetPage;
715 if (nPage != (sal_uInt16)-1)
717 pPage = GetSdPage(nPage, PK_STANDARD);
718 while (nPage > 0 && pPage->IsSelected())
720 nPage--;
721 pPage = GetSdPage(nPage, PK_STANDARD);
724 if (pPage->IsSelected())
726 nPage = (sal_uInt16)-1;
730 // Insert before the first page
731 if (nPage == (sal_uInt16)-1)
733 std::vector<SdPage*>::reverse_iterator iter;
734 for (iter = aPageList.rbegin(); iter != aPageList.rend(); ++iter)
736 nPage = (*iter)->GetPageNum();
737 if (nPage != 0)
739 SdrPage* pPg = GetPage(nPage);
740 if( bUndo )
741 AddUndo(GetSdrUndoFactory().CreateUndoSetPageNum(*pPg, nPage, 1));
742 MovePage(nPage, 1);
743 pPg = GetPage(nPage+1);
744 if( bUndo )
745 AddUndo(GetSdrUndoFactory().CreateUndoSetPageNum(*pPg, nPage+1, 2));
746 MovePage(nPage+1, 2);
747 bSomethingHappened = sal_True;
751 // Insert after <nPage>
752 else
754 nTargetPage = nPage;
755 nTargetPage = 2 * nTargetPage + 1; // PK_STANDARD --> absolute
757 std::vector<SdPage*>::iterator iter;
758 for (iter = aPageList.begin(); iter != aPageList.end(); ++iter)
760 pPage = *iter;
761 nPage = pPage->GetPageNum();
762 if (nPage > nTargetPage)
764 nTargetPage += 2; // Insert _after_ the page
766 if (nPage != nTargetPage)
768 SdrPage* pPg = GetPage(nPage);
769 if( bUndo )
770 AddUndo(GetSdrUndoFactory().CreateUndoSetPageNum(*pPg, nPage, nTargetPage));
771 MovePage(nPage, nTargetPage);
772 pPg = GetPage(nPage+1);
773 if( bUndo )
774 AddUndo(GetSdrUndoFactory().CreateUndoSetPageNum(*pPg, nPage+1, nTargetPage+1));
775 MovePage(nPage+1, nTargetPage+1);
776 bSomethingHappened = sal_True;
779 else
781 if (nPage != nTargetPage)
783 SdrPage* pPg = GetPage(nPage+1);
784 if( bUndo )
785 AddUndo(GetSdrUndoFactory().CreateUndoSetPageNum(*pPg, nPage+1, nTargetPage+1));
786 MovePage(nPage+1, nTargetPage+1);
787 pPg = GetPage(nPage);
788 if( bUndo )
789 AddUndo(GetSdrUndoFactory().CreateUndoSetPageNum(*pPg, nPage, nTargetPage));
790 MovePage(nPage, nTargetPage);
791 bSomethingHappened = sal_True;
794 nTargetPage = pPage->GetPageNum();
798 if( bUndo )
799 EndUndo();
801 return bSomethingHappened;
805 // Return number of links in sfx2::LinkManager
806 sal_uLong SdDrawDocument::GetLinkCount()
808 return pLinkManager->GetLinks().size();
811 // Set Language
812 void SdDrawDocument::SetLanguage( const LanguageType eLang, const sal_uInt16 nId )
814 sal_Bool bChanged = sal_False;
816 if( nId == EE_CHAR_LANGUAGE && meLanguage != eLang )
818 meLanguage = eLang;
819 bChanged = sal_True;
821 else if( nId == EE_CHAR_LANGUAGE_CJK && meLanguageCJK != eLang )
823 meLanguageCJK = eLang;
824 bChanged = sal_True;
826 else if( nId == EE_CHAR_LANGUAGE_CTL && meLanguageCTL != eLang )
828 meLanguageCTL = eLang;
829 bChanged = sal_True;
832 if( bChanged )
834 GetDrawOutliner().SetDefaultLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() );
835 pHitTestOutliner->SetDefaultLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() );
836 pItemPool->SetPoolDefaultItem( SvxLanguageItem( eLang, nId ) );
837 SetChanged( bChanged );
842 // Return language
843 LanguageType SdDrawDocument::GetLanguage( const sal_uInt16 nId ) const
845 LanguageType eLangType = meLanguage;
847 if( nId == EE_CHAR_LANGUAGE_CJK )
848 eLangType = meLanguageCJK;
849 else if( nId == EE_CHAR_LANGUAGE_CTL )
850 eLangType = meLanguageCTL;
852 return eLangType;
856 // Initiate WorkStartup
857 IMPL_LINK_NOARG(SdDrawDocument, WorkStartupHdl)
859 if( mpDocSh )
860 mpDocSh->SetWaitCursor( sal_True );
862 sal_Bool bChanged = IsChanged(); // remember this
864 // Initialize Autolayouts
865 SdPage* pHandoutMPage = GetMasterSdPage(0, PK_HANDOUT);
867 if (pHandoutMPage->GetAutoLayout() == AUTOLAYOUT_NONE)
869 // No AutoLayout yet -> initialize
870 pHandoutMPage->SetAutoLayout(AUTOLAYOUT_HANDOUT6, sal_True, sal_True);
873 SdPage* pPage = GetSdPage(0, PK_STANDARD);
875 if (pPage->GetAutoLayout() == AUTOLAYOUT_NONE)
877 // No AutoLayout yet -> initialize
878 pPage->SetAutoLayout(AUTOLAYOUT_NONE, sal_True, sal_True);
881 SdPage* pNotesPage = GetSdPage(0, PK_NOTES);
883 if (pNotesPage->GetAutoLayout() == AUTOLAYOUT_NONE)
885 // No AutoLayout yet -> initialize
886 pNotesPage->SetAutoLayout(AUTOLAYOUT_NOTES, sal_True, sal_True);
889 SetChanged(bChanged);
891 if( mpDocSh )
892 mpDocSh->SetWaitCursor( sal_False );
893 return 0;
897 // When the WorkStartupTimer has been created (this only happens in
898 // SdDrawViewShell::Construct() ), the timer may be stopped and the WorkStartup
899 // may be initiated.
900 void SdDrawDocument::StopWorkStartupDelay()
902 if (mpWorkStartupTimer)
904 if ( mpWorkStartupTimer->IsActive() )
906 // Timer not yet expired -> initiate WorkStartup
907 mpWorkStartupTimer->Stop();
908 WorkStartupHdl(NULL);
911 delete mpWorkStartupTimer;
912 mpWorkStartupTimer = NULL;
916 // When the WorkStartupTimer has been created (this only happens in
917 // SdDrawViewShell::Construct() ), the timer may be stopped and the WorkStartup
918 // may be initiated.
919 SdAnimationInfo* SdDrawDocument::GetAnimationInfo(SdrObject* pObject) const
921 DBG_ASSERT(pObject, "sd::SdDrawDocument::GetAnimationInfo(), invalid argument!");
922 if( pObject )
923 return GetShapeUserData( *pObject, false );
924 else
925 return 0;
928 SdAnimationInfo* SdDrawDocument::GetShapeUserData(SdrObject& rObject, bool bCreate /* = false */ )
930 sal_uInt16 nUD = 0;
931 sal_uInt16 nUDCount = rObject.GetUserDataCount();
932 SdrObjUserData* pUD = 0;
933 SdAnimationInfo* pRet = 0;
935 // Can we find animation information within the user data?
936 for (nUD = 0; nUD < nUDCount; nUD++)
938 pUD = rObject.GetUserData(nUD);
939 if((pUD->GetInventor() == SdUDInventor) && (pUD->GetId() == SD_ANIMATIONINFO_ID))
941 pRet = dynamic_cast<SdAnimationInfo*>(pUD);
942 break;
946 if( (pRet == 0) && bCreate )
948 pRet = new SdAnimationInfo( rObject );
949 rObject.AppendUserData( pRet);
952 return pRet;
955 SdIMapInfo* SdDrawDocument::GetIMapInfo( SdrObject* pObject ) const
957 DBG_ASSERT(pObject, "Without an object there is no IMapInfo");
959 SdrObjUserData* pUserData = NULL;
960 SdIMapInfo* pIMapInfo = NULL;
961 sal_uInt16 nCount = pObject->GetUserDataCount();
963 // Can we find IMap information within the user data?
964 for ( sal_uInt16 i = 0; i < nCount; i++ )
966 pUserData = pObject->GetUserData( i );
968 if ( ( pUserData->GetInventor() == SdUDInventor ) && ( pUserData->GetId() == SD_IMAPINFO_ID ) )
969 pIMapInfo = (SdIMapInfo*) pUserData;
972 return pIMapInfo;
975 IMapObject* SdDrawDocument::GetHitIMapObject( SdrObject* pObj,
976 const Point& rWinPoint,
977 const ::Window& /* rCmpWnd */ )
979 SdIMapInfo* pIMapInfo = GetIMapInfo( pObj );
980 IMapObject* pIMapObj = NULL;
982 if ( pIMapInfo )
984 const MapMode aMap100( MAP_100TH_MM );
985 Size aGraphSize;
986 Point aRelPoint( rWinPoint );
987 ImageMap& rImageMap = (ImageMap&) pIMapInfo->GetImageMap();
988 const Rectangle& rRect = pObj->GetLogicRect();
989 sal_Bool bObjSupported = sal_False;
991 // execute HitTest
992 if ( pObj->ISA( SdrGrafObj ) ) // simple graphics object
994 const SdrGrafObj* pGrafObj = (const SdrGrafObj*) pObj;
995 const GeoStat& rGeo = pGrafObj->GetGeoStat();
996 SdrGrafObjGeoData* pGeoData = (SdrGrafObjGeoData*) pGrafObj->GetGeoData();
998 // Undo rotation
999 if ( rGeo.nDrehWink )
1000 RotatePoint( aRelPoint, rRect.TopLeft(), -rGeo.nSin, rGeo.nCos );
1002 // Undo mirroring
1003 if ( pGeoData->bMirrored )
1004 aRelPoint.X() = rRect.Right() + rRect.Left() - aRelPoint.X();
1006 // Undo shearing
1007 if ( rGeo.nShearWink )
1008 ShearPoint( aRelPoint, rRect.TopLeft(), -rGeo.nTan );
1010 if ( pGrafObj->GetGrafPrefMapMode().GetMapUnit() == MAP_PIXEL )
1011 aGraphSize = Application::GetDefaultDevice()->PixelToLogic( pGrafObj->GetGrafPrefSize(), aMap100 );
1012 else
1013 aGraphSize = OutputDevice::LogicToLogic( pGrafObj->GetGrafPrefSize(),
1014 pGrafObj->GetGrafPrefMapMode(), aMap100 );
1016 delete pGeoData;
1017 bObjSupported = sal_True;
1019 else if ( pObj->ISA( SdrOle2Obj ) ) // OLE object
1021 aGraphSize = ( (SdrOle2Obj*) pObj )->GetOrigObjSize();
1022 bObjSupported = sal_True;
1025 // Everything worked out well, thus execute HitTest
1026 if ( bObjSupported )
1028 // Calculate relative position of mouse cursor
1029 aRelPoint -= rRect.TopLeft();
1030 pIMapObj = rImageMap.GetHitIMapObject( aGraphSize, rRect.GetSize(), aRelPoint );
1032 // We don't care about deactivated objects
1033 if ( pIMapObj && !pIMapObj->IsActive() )
1034 pIMapObj = NULL;
1038 return pIMapObj;
1041 /** this method enforces that the masterpages are in the currect order,
1042 that is at position 1 is a PK_STANDARD masterpage followed by a
1043 PK_NOTES masterpage and so on. #
1045 void SdDrawDocument::CheckMasterPages()
1047 // RemoveMasterPage(2); // code to test the creation of notes pages
1049 sal_uInt16 nMaxPages = GetMasterPageCount();
1051 // we need at least a handout master and one master page
1052 if( nMaxPages < 2 )
1054 return;
1057 SdPage* pPage = NULL;
1058 SdPage* pNotesPage = NULL;
1060 sal_uInt16 nPage;
1062 // first see if the page order is correct
1063 for( nPage = 1; nPage < nMaxPages; nPage++ )
1065 pPage = static_cast<SdPage*> (GetMasterPage( nPage ));
1066 // if an odd page is not a standard page or an even page is not a notes page
1067 if( ((1 == (nPage & 1)) && (pPage->GetPageKind() != PK_STANDARD) ) ||
1068 ((0 == (nPage & 1)) && (pPage->GetPageKind() != PK_NOTES) ) )
1069 break; // then we have a fatal error
1072 if( nPage < nMaxPages )
1074 // there is a fatal error in the master page order,
1075 // we need to repair the document
1076 sal_Bool bChanged = sal_False;
1078 nPage = 1;
1079 while( nPage < nMaxPages )
1081 pPage = static_cast<SdPage*> (GetMasterPage( nPage ));
1082 if( pPage->GetPageKind() != PK_STANDARD )
1084 bChanged = sal_True;
1085 sal_uInt16 nFound = nPage + 1;
1086 while( nFound < nMaxPages )
1088 pPage = static_cast<SdPage*>(GetMasterPage( nFound ));
1089 if( PK_STANDARD == pPage->GetPageKind() )
1091 MoveMasterPage( nFound, nPage );
1092 pPage->SetInserted(sal_True);
1093 break;
1097 nFound++;
1100 // if we don't have any more standard pages, were done
1101 if( nMaxPages == nFound )
1102 break;
1105 nPage++;
1107 if( nPage < nMaxPages )
1108 pNotesPage = static_cast<SdPage*>(GetMasterPage( nPage ));
1109 else
1110 pNotesPage = NULL;
1112 if( (NULL == pNotesPage) || (pNotesPage->GetPageKind() != PK_NOTES) || ( pPage->GetLayoutName() != pNotesPage->GetLayoutName() ) )
1114 bChanged = sal_True;
1116 sal_uInt16 nFound = nPage + 1;
1117 while( nFound < nMaxPages )
1119 pNotesPage = static_cast<SdPage*>(GetMasterPage( nFound ));
1120 if( (PK_NOTES == pNotesPage->GetPageKind()) && ( pPage->GetLayoutName() == pNotesPage->GetLayoutName() ) )
1122 MoveMasterPage( nFound, nPage );
1123 pNotesPage->SetInserted(sal_True);
1124 break;
1127 nFound++;
1130 // looks like we lost a notes page
1131 if( nMaxPages == nFound )
1133 // so create one
1135 // first find a reference notes page for size
1136 SdPage* pRefNotesPage = NULL;
1137 nFound = 0;
1138 while( nFound < nMaxPages )
1140 pRefNotesPage = static_cast<SdPage*>(GetMasterPage( nFound ));
1141 if( PK_NOTES == pRefNotesPage->GetPageKind() )
1142 break;
1143 nFound++;
1145 if( nFound == nMaxPages )
1146 pRefNotesPage = NULL;
1148 SdPage* pNewNotesPage = static_cast<SdPage*>(AllocPage(sal_True));
1149 pNewNotesPage->SetPageKind(PK_NOTES);
1150 if( pRefNotesPage )
1152 pNewNotesPage->SetSize( pRefNotesPage->GetSize() );
1153 pNewNotesPage->SetBorder( pRefNotesPage->GetLftBorder(),
1154 pRefNotesPage->GetUppBorder(),
1155 pRefNotesPage->GetRgtBorder(),
1156 pRefNotesPage->GetLwrBorder() );
1158 InsertMasterPage(pNewNotesPage, nPage );
1159 pNewNotesPage->SetLayoutName( pPage->GetLayoutName() );
1160 pNewNotesPage->SetAutoLayout(AUTOLAYOUT_NOTES, sal_True, sal_True );
1161 nMaxPages++;
1165 nPage++;
1168 // now remove all remaining and unused non PK_STANDARD slides
1169 while( nPage < nMaxPages )
1171 bChanged = sal_True;
1173 RemoveMasterPage( nPage );
1174 nMaxPages--;
1177 if( bChanged )
1179 OSL_FAIL( "master pages where in a wrong order" );
1180 RecalcPageNums( sal_True);
1185 sal_uInt16 SdDrawDocument::CreatePage (
1186 SdPage* pActualPage,
1187 PageKind ePageKind,
1188 const String& sStandardPageName,
1189 const String& sNotesPageName,
1190 AutoLayout eStandardLayout,
1191 AutoLayout eNotesLayout,
1192 sal_Bool bIsPageBack,
1193 sal_Bool bIsPageObj,
1194 const sal_Int32 nInsertPosition)
1196 SdPage* pPreviousStandardPage;
1197 SdPage* pPreviousNotesPage;
1198 SdPage* pStandardPage;
1199 SdPage* pNotesPage;
1201 // From the given page determine the standard page and notes page of which
1202 // to take the layout and the position where to insert the new pages.
1203 if (ePageKind == PK_NOTES)
1205 pPreviousNotesPage = pActualPage;
1206 sal_uInt16 nNotesPageNum = pPreviousNotesPage->GetPageNum() + 2;
1207 pPreviousStandardPage = (SdPage*) GetPage(nNotesPageNum - 3);
1208 eStandardLayout = pPreviousStandardPage->GetAutoLayout();
1210 else
1212 pPreviousStandardPage = pActualPage;
1213 sal_uInt16 nStandardPageNum = pPreviousStandardPage->GetPageNum() + 2;
1214 pPreviousNotesPage = (SdPage*) GetPage(nStandardPageNum - 1);
1215 eNotesLayout = pPreviousNotesPage->GetAutoLayout();
1218 // Create new standard page and set it up
1219 pStandardPage = (SdPage*) AllocPage(sal_False);
1221 // Set the size here since else the presobj autolayout
1222 // will be wrong.
1223 pStandardPage->SetSize( pPreviousStandardPage->GetSize() );
1224 pStandardPage->SetBorder( pPreviousStandardPage->GetLftBorder(),
1225 pPreviousStandardPage->GetUppBorder(),
1226 pPreviousStandardPage->GetRgtBorder(),
1227 pPreviousStandardPage->GetLwrBorder() );
1229 // Use master page of current page.
1230 pStandardPage->TRG_SetMasterPage(pPreviousStandardPage->TRG_GetMasterPage());
1232 // User layout of current standard page
1233 pStandardPage->SetLayoutName( pPreviousStandardPage->GetLayoutName() );
1234 pStandardPage->SetAutoLayout(eStandardLayout, sal_True);
1235 pStandardPage->setHeaderFooterSettings( pPreviousStandardPage->getHeaderFooterSettings() );
1237 // transition settings of current page
1238 pStandardPage->setTransitionType( pPreviousStandardPage->getTransitionType() );
1239 pStandardPage->setTransitionSubtype( pPreviousStandardPage->getTransitionSubtype() );
1240 pStandardPage->setTransitionDirection( pPreviousStandardPage->getTransitionDirection() );
1241 pStandardPage->setTransitionFadeColor( pPreviousStandardPage->getTransitionFadeColor() );
1242 pStandardPage->setTransitionDuration( pPreviousStandardPage->getTransitionDuration() );
1244 // apply previous animation timing
1245 pStandardPage->SetPresChange( pPreviousStandardPage->GetPresChange() );
1246 pStandardPage->SetTime( pPreviousStandardPage->GetTime() );
1248 // Create new notes page and set it up
1249 pNotesPage = (SdPage*) AllocPage(sal_False);
1250 pNotesPage->SetPageKind(PK_NOTES);
1252 // Use master page of current page
1253 pNotesPage->TRG_SetMasterPage(pPreviousNotesPage->TRG_GetMasterPage());
1255 // Use layout of current notes page
1256 pNotesPage->SetLayoutName( pPreviousNotesPage->GetLayoutName() );
1257 pNotesPage->SetAutoLayout(eNotesLayout, sal_True);
1258 pNotesPage->setHeaderFooterSettings( pPreviousNotesPage->getHeaderFooterSettings() );
1260 return InsertPageSet (
1261 pActualPage,
1262 ePageKind,
1263 sStandardPageName,
1264 sNotesPageName,
1265 bIsPageBack,
1266 bIsPageObj,
1267 pStandardPage,
1268 pNotesPage,
1269 nInsertPosition);
1275 sal_uInt16 SdDrawDocument::DuplicatePage (sal_uInt16 nPageNum)
1277 PageKind ePageKind = PK_STANDARD;
1279 // Get current page
1280 SdPage* pActualPage = GetSdPage(nPageNum, ePageKind);
1282 // Get background flags
1283 SdrLayerAdmin& rLayerAdmin = GetLayerAdmin();
1284 sal_uInt8 aBckgrnd = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRND)), sal_False);
1285 sal_uInt8 aBckgrndObj = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ)), sal_False);
1286 SetOfByte aVisibleLayers = pActualPage->TRG_GetMasterPageVisibleLayers();
1288 return DuplicatePage (
1289 pActualPage, ePageKind,
1290 // No names for the new slides
1291 String(), String(),
1292 aVisibleLayers.IsSet(aBckgrnd),
1293 aVisibleLayers.IsSet(aBckgrndObj));
1299 sal_uInt16 SdDrawDocument::DuplicatePage (
1300 SdPage* pActualPage,
1301 PageKind ePageKind,
1302 const String& sStandardPageName,
1303 const String& sNotesPageName,
1304 sal_Bool bIsPageBack,
1305 sal_Bool bIsPageObj,
1306 const sal_Int32 nInsertPosition)
1308 SdPage* pPreviousStandardPage;
1309 SdPage* pPreviousNotesPage;
1310 SdPage* pStandardPage;
1311 SdPage* pNotesPage;
1313 // From the given page determine the standard page and the notes page
1314 // of which to make copies.
1315 if (ePageKind == PK_NOTES)
1317 pPreviousNotesPage = pActualPage;
1318 sal_uInt16 nNotesPageNum = pPreviousNotesPage->GetPageNum() + 2;
1319 pPreviousStandardPage = (SdPage*) GetPage(nNotesPageNum - 3);
1321 else
1323 pPreviousStandardPage = pActualPage;
1324 sal_uInt16 nStandardPageNum = pPreviousStandardPage->GetPageNum() + 2;
1325 pPreviousNotesPage = (SdPage*) GetPage(nStandardPageNum - 1);
1328 // Create duplicates of a standard page and the associated notes page
1329 pStandardPage = (SdPage*) pPreviousStandardPage->Clone();
1330 pNotesPage = (SdPage*) pPreviousNotesPage->Clone();
1332 return InsertPageSet (
1333 pActualPage,
1334 ePageKind,
1335 sStandardPageName,
1336 sNotesPageName,
1337 bIsPageBack,
1338 bIsPageObj,
1339 pStandardPage,
1340 pNotesPage,
1341 nInsertPosition);
1347 sal_uInt16 SdDrawDocument::InsertPageSet (
1348 SdPage* pActualPage,
1349 PageKind ePageKind,
1350 const String& sStandardPageName,
1351 const String& sNotesPageName,
1352 sal_Bool bIsPageBack,
1353 sal_Bool bIsPageObj,
1354 SdPage* pStandardPage,
1355 SdPage* pNotesPage,
1356 sal_Int32 nInsertPosition)
1358 SdPage* pPreviousStandardPage;
1359 SdPage* pPreviousNotesPage;
1360 sal_uInt16 nStandardPageNum;
1361 sal_uInt16 nNotesPageNum;
1362 String aStandardPageName = sStandardPageName;
1363 String aNotesPageName = sNotesPageName;
1365 // Gather some information about the standard page and the notes page
1366 // that are to be inserted. This makes sure that there is always one
1367 // standard page followed by one notes page.
1368 if (ePageKind == PK_NOTES)
1370 pPreviousNotesPage = pActualPage;
1371 nNotesPageNum = pPreviousNotesPage->GetPageNum() + 2;
1372 pPreviousStandardPage = (SdPage*) GetPage(nNotesPageNum - 3);
1373 nStandardPageNum = nNotesPageNum - 1;
1375 else
1377 pPreviousStandardPage = pActualPage;
1378 nStandardPageNum = pPreviousStandardPage->GetPageNum() + 2;
1379 pPreviousNotesPage = (SdPage*) GetPage(nStandardPageNum - 1);
1380 nNotesPageNum = nStandardPageNum + 1;
1381 aNotesPageName = aStandardPageName;
1384 OSL_ASSERT(nNotesPageNum==nStandardPageNum+1);
1385 if (nInsertPosition < 0)
1386 nInsertPosition = nStandardPageNum;
1388 // Set up and insert the standard page
1389 SetupNewPage (
1390 pPreviousStandardPage,
1391 pStandardPage,
1392 aStandardPageName,
1393 nInsertPosition,
1394 bIsPageBack,
1395 bIsPageObj);
1397 // Set up and insert the notes page
1398 pNotesPage->SetPageKind(PK_NOTES);
1399 SetupNewPage (
1400 pPreviousNotesPage,
1401 pNotesPage,
1402 aNotesPageName,
1403 nInsertPosition+1,
1404 bIsPageBack,
1405 bIsPageObj);
1407 // Return an index that allows the caller to access the newly inserted
1408 // pages by using GetSdPage()
1409 return pStandardPage->GetPageNum() / 2;
1415 void SdDrawDocument::SetupNewPage (
1416 SdPage* pPreviousPage,
1417 SdPage* pPage,
1418 const String& sPageName,
1419 sal_uInt16 nInsertionPoint,
1420 sal_Bool bIsPageBack,
1421 sal_Bool bIsPageObj)
1423 if (pPreviousPage != NULL)
1425 pPage->SetSize( pPreviousPage->GetSize() );
1426 pPage->SetBorder( pPreviousPage->GetLftBorder(),
1427 pPreviousPage->GetUppBorder(),
1428 pPreviousPage->GetRgtBorder(),
1429 pPreviousPage->GetLwrBorder() );
1431 pPage->SetName(sPageName);
1433 InsertPage(pPage, nInsertionPoint);
1435 if (pPreviousPage != NULL)
1437 SdrLayerAdmin& rLayerAdmin = GetLayerAdmin();
1438 sal_uInt8 aBckgrnd = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRND)), sal_False);
1439 sal_uInt8 aBckgrndObj = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ)), sal_False);
1440 SetOfByte aVisibleLayers = pPreviousPage->TRG_GetMasterPageVisibleLayers();
1441 aVisibleLayers.Set(aBckgrnd, bIsPageBack);
1442 aVisibleLayers.Set(aBckgrndObj, bIsPageObj);
1443 pPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
1447 sd::UndoManager* SdDrawDocument::GetUndoManager() const
1449 return mpDocSh ? dynamic_cast< sd::UndoManager* >(mpDocSh->GetUndoManager()) : 0;
1452 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */