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/XVisualObject.hpp>
21 : #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
22 : #include <vcl/wrkwin.hxx>
23 : #include <vcl/settings.hxx>
24 :
25 : #include <sfx2/printer.hxx>
26 : #include <sfx2/app.hxx>
27 : #include "Outliner.hxx"
28 : #include <editeng/paperinf.hxx>
29 : #include <svx/svdopage.hxx>
30 : #include <svx/svdoole2.hxx>
31 : #include <svx/svdotext.hxx>
32 : #include <svx/svdograf.hxx>
33 : #include <svx/svdundo.hxx>
34 : #include <vcl/svapp.hxx>
35 : #include <editeng/eeitem.hxx>
36 : #include <editeng/langitem.hxx>
37 : #include <svl/itempool.hxx>
38 : #include <svx/svdpool.hxx>
39 : #include <editeng/flditem.hxx>
40 :
41 : #include <sfx2/linkmgr.hxx>
42 : #include <editeng/editdata.hxx>
43 : #include <svx/dialogs.hrc>
44 : #include <svx/dialmgr.hxx>
45 :
46 : #include <editeng/outliner.hxx>
47 : #include <svx/svditer.hxx>
48 : #include <svtools/imapobj.hxx>
49 :
50 :
51 : #include "sdresid.hxx"
52 : #include "drawdoc.hxx"
53 : #include "sdpage.hxx"
54 : #include "pglink.hxx"
55 : #include "glob.hrc"
56 : #include "glob.hxx"
57 : #include "stlpool.hxx"
58 : #include "sdiocmpt.hxx"
59 : #include "anminfo.hxx"
60 : #include "imapinfo.hxx"
61 : #include "cusshow.hxx"
62 : #include "undo/undomanager.hxx"
63 :
64 : #include "../ui/inc/DrawDocShell.hxx"
65 : #include "../ui/inc/FrameView.hxx"
66 : #include "../ui/inc/cfgids.hxx"
67 : #include "../ui/inc/strings.hrc"
68 :
69 : #include "PageListWatcher.hxx"
70 : #include <vcl/virdev.hxx>
71 : #include "customshowlist.hxx"
72 :
73 : using namespace ::sd;
74 :
75 : const long PRINT_OFFSET = 30; // see /svx/source/dialog/page.cxx
76 :
77 : using namespace com::sun::star;
78 :
79 : // Looks up an object by name
80 0 : SdrObject* SdDrawDocument::GetObj(const OUString& rObjName) const
81 : {
82 0 : SdrObject* pObj = NULL;
83 0 : SdrObject* pObjFound = NULL;
84 0 : SdPage* pPage = NULL;
85 :
86 : // First search in all pages
87 0 : sal_uInt16 nPage = 0;
88 0 : const sal_uInt16 nMaxPages = GetPageCount();
89 :
90 0 : while (nPage < nMaxPages && !pObjFound)
91 : {
92 0 : pPage = (SdPage*) GetPage(nPage);
93 0 : SdrObjListIter aIter(*pPage, IM_DEEPWITHGROUPS);
94 :
95 0 : while (aIter.IsMore() && !pObjFound)
96 : {
97 0 : pObj = aIter.Next();
98 :
99 0 : if( ( pObj->GetName().equals(rObjName) ) ||
100 0 : ( SdrInventor == pObj->GetObjInventor() &&
101 0 : OBJ_OLE2 == pObj->GetObjIdentifier() &&
102 0 : rObjName == static_cast< SdrOle2Obj* >( pObj )->GetPersistName() ) )
103 : {
104 0 : pObjFound = pObj;
105 : }
106 : }
107 :
108 0 : nPage++;
109 0 : }
110 :
111 : // If it couldn't be found, look through all master pages
112 0 : nPage = 0;
113 0 : const sal_uInt16 nMaxMasterPages = GetMasterPageCount();
114 :
115 0 : while (nPage < nMaxMasterPages && !pObjFound)
116 : {
117 0 : pPage = (SdPage*) GetMasterPage(nPage);
118 0 : SdrObjListIter aIter(*pPage, IM_DEEPWITHGROUPS);
119 :
120 0 : while (aIter.IsMore() && !pObjFound)
121 : {
122 0 : pObj = aIter.Next();
123 :
124 0 : if( ( pObj->GetName().equals(rObjName) ) ||
125 0 : ( SdrInventor == pObj->GetObjInventor() &&
126 0 : OBJ_OLE2 == pObj->GetObjIdentifier() &&
127 0 : rObjName == static_cast< SdrOle2Obj* >( pObj )->GetPersistName() ) )
128 : {
129 0 : pObjFound = pObj;
130 : }
131 : }
132 :
133 0 : nPage++;
134 0 : }
135 :
136 0 : return (pObjFound);
137 : }
138 :
139 :
140 : // Find SdPage by name
141 0 : sal_uInt16 SdDrawDocument::GetPageByName(const OUString& rPgName, sal_Bool& rbIsMasterPage) const
142 : {
143 0 : SdPage* pPage = NULL;
144 0 : sal_uInt16 nPage = 0;
145 0 : const sal_uInt16 nMaxPages = GetPageCount();
146 0 : sal_uInt16 nPageNum = SDRPAGE_NOTFOUND;
147 :
148 0 : rbIsMasterPage = sal_False;
149 :
150 : // Search all regular pages and all notes pages (handout pages are
151 : // ignored)
152 0 : while (nPage < nMaxPages && nPageNum == SDRPAGE_NOTFOUND)
153 : {
154 : pPage = const_cast<SdPage*>(static_cast<const SdPage*>(
155 0 : GetPage(nPage)));
156 :
157 0 : if (pPage != NULL
158 0 : && pPage->GetPageKind() != PK_HANDOUT
159 0 : && pPage->GetName() == rPgName)
160 : {
161 0 : nPageNum = nPage;
162 : }
163 :
164 0 : nPage++;
165 : }
166 :
167 : // Search all master pages when not found among non-master pages
168 0 : const sal_uInt16 nMaxMasterPages = GetMasterPageCount();
169 0 : nPage = 0;
170 :
171 0 : while (nPage < nMaxMasterPages && nPageNum == SDRPAGE_NOTFOUND)
172 : {
173 : pPage = const_cast<SdPage*>(static_cast<const SdPage*>(
174 0 : GetMasterPage(nPage)));
175 :
176 0 : if (pPage && pPage->GetName() == rPgName)
177 : {
178 0 : nPageNum = nPage;
179 0 : rbIsMasterPage = sal_True;
180 : }
181 :
182 0 : nPage++;
183 : }
184 :
185 0 : return nPageNum;
186 : }
187 :
188 0 : SdPage* SdDrawDocument::GetSdPage(sal_uInt16 nPgNum, PageKind ePgKind) const
189 : {
190 0 : return mpDrawPageListWatcher->GetSdPage(ePgKind, sal_uInt32(nPgNum));
191 : }
192 :
193 0 : sal_uInt16 SdDrawDocument::GetSdPageCount(PageKind ePgKind) const
194 : {
195 0 : return (sal_uInt16)mpDrawPageListWatcher->GetSdPageCount(ePgKind);
196 : }
197 :
198 0 : SdPage* SdDrawDocument::GetMasterSdPage(sal_uInt16 nPgNum, PageKind ePgKind)
199 : {
200 0 : return mpMasterPageListWatcher->GetSdPage(ePgKind, sal_uInt32(nPgNum));
201 : }
202 :
203 0 : sal_uInt16 SdDrawDocument::GetMasterSdPageCount(PageKind ePgKind) const
204 : {
205 0 : return (sal_uInt16)mpMasterPageListWatcher->GetSdPageCount(ePgKind);
206 : }
207 :
208 0 : sal_uInt16 SdDrawDocument::GetActiveSdPageCount() const
209 : {
210 0 : return (sal_uInt16)mpDrawPageListWatcher->GetVisibleSdPageCount();
211 : }
212 :
213 : // Adapt the page numbers that are registered in the page objects of the notes
214 : // pages
215 0 : void SdDrawDocument::UpdatePageObjectsInNotes(sal_uInt16 nStartPos)
216 : {
217 0 : sal_uInt16 nPageCount = GetPageCount();
218 0 : SdPage* pPage = NULL;
219 :
220 0 : for (sal_uInt16 nPage = nStartPos; nPage < nPageCount; nPage++)
221 : {
222 0 : pPage = (SdPage*)GetPage(nPage);
223 :
224 : // If this is a notes page, find its page object and correct the page
225 : // number
226 0 : if (pPage && pPage->GetPageKind() == PK_NOTES)
227 : {
228 0 : sal_uLong nObjCount = pPage->GetObjCount();
229 0 : SdrObject* pObj = NULL;
230 0 : for (sal_uLong nObj = 0; nObj < nObjCount; nObj++)
231 : {
232 0 : pObj = pPage->GetObj(nObj);
233 0 : if (pObj->GetObjIdentifier() == OBJ_PAGE &&
234 0 : pObj->GetObjInventor() == SdrInventor)
235 : {
236 : // The page object is the preceding page (drawing page)
237 : DBG_ASSERTWARNING(nStartPos, "Position of notes page must not be 0.");
238 :
239 : DBG_ASSERTWARNING(nPage > 1, "Page object must not be a handout.");
240 :
241 0 : if (nStartPos > 0 && nPage > 1)
242 0 : ((SdrPageObj*)pObj)->SetReferencedPage(GetPage(nPage - 1));
243 : }
244 : }
245 : }
246 : }
247 0 : }
248 :
249 0 : void SdDrawDocument::UpdatePageRelativeURLs(const OUString& rOldName, const OUString& rNewName)
250 : {
251 0 : if (rNewName.isEmpty())
252 0 : return;
253 :
254 0 : SfxItemPool& pPool(GetPool());
255 0 : sal_uInt32 nCount = pPool.GetItemCount2(EE_FEATURE_FIELD);
256 0 : for (sal_uInt32 nOff = 0; nOff < nCount; nOff++)
257 : {
258 0 : const SfxPoolItem *pItem = pPool.GetItem2(EE_FEATURE_FIELD, nOff);
259 0 : const SvxFieldItem* pFldItem = dynamic_cast< const SvxFieldItem * > (pItem);
260 :
261 0 : if(pFldItem)
262 : {
263 0 : SvxURLField* pURLField = const_cast< SvxURLField* >( dynamic_cast<const SvxURLField*>( pFldItem->GetField() ) );
264 :
265 0 : if(pURLField)
266 : {
267 0 : OUString aURL = pURLField->GetURL();
268 :
269 0 : if (!aURL.isEmpty() && (aURL[0] == 35) && (aURL.indexOf(rOldName, 1) == 1))
270 : {
271 0 : if (aURL.getLength() == rOldName.getLength() + 1) // standard page name
272 : {
273 0 : aURL = aURL.replaceAt(1, aURL.getLength() - 1, "");
274 0 : aURL += rNewName;
275 0 : pURLField->SetURL(aURL);
276 : }
277 : else
278 : {
279 0 : const OUString sNotes(SD_RESSTR(STR_NOTES));
280 0 : if (aURL.getLength() == rOldName.getLength() + 2 + sNotes.getLength()
281 0 : && aURL.indexOf(sNotes, rOldName.getLength() + 2) == rOldName.getLength() + 2)
282 : {
283 0 : aURL = aURL.replaceAt(1, aURL.getLength() - 1, "");
284 0 : aURL += rNewName + " " + sNotes;
285 0 : pURLField->SetURL(aURL);
286 0 : }
287 : }
288 0 : }
289 : }
290 : }
291 : }
292 : }
293 :
294 0 : void SdDrawDocument::UpdatePageRelativeURLs(SdPage* pPage, sal_uInt16 nPos, sal_Int32 nIncrement)
295 : {
296 0 : bool bNotes = (pPage->GetPageKind() == PK_NOTES);
297 :
298 0 : SfxItemPool& pPool(GetPool());
299 0 : sal_uInt32 nCount = pPool.GetItemCount2(EE_FEATURE_FIELD);
300 0 : for (sal_uInt32 nOff = 0; nOff < nCount; nOff++)
301 : {
302 0 : const SfxPoolItem *pItem = pPool.GetItem2(EE_FEATURE_FIELD, nOff);
303 : const SvxFieldItem* pFldItem;
304 :
305 0 : if ((pFldItem = dynamic_cast< const SvxFieldItem * > (pItem)) != 0)
306 : {
307 0 : SvxURLField* pURLField = const_cast< SvxURLField* >( dynamic_cast<const SvxURLField*>( pFldItem->GetField() ) );
308 :
309 0 : if(pURLField)
310 : {
311 0 : OUString aURL = pURLField->GetURL();
312 :
313 0 : if (!aURL.isEmpty() && (aURL[0] == 35))
314 : {
315 0 : OUString aHashSlide("#");
316 0 : aHashSlide += SD_RESSTR(STR_PAGE);
317 :
318 0 : if (aURL.startsWith(aHashSlide))
319 : {
320 0 : OUString aURLCopy = aURL;
321 0 : const OUString sNotes(SD_RESSTR(STR_NOTES));
322 :
323 0 : aURLCopy = aURLCopy.replaceAt(0, aHashSlide.getLength(), "");
324 :
325 0 : bool bNotesLink = ( aURLCopy.getLength() >= sNotes.getLength() + 3
326 0 : && aURLCopy.endsWith(sNotes) );
327 :
328 0 : if (bNotesLink != bNotes)
329 0 : continue; // no compatible link and page
330 :
331 0 : if (bNotes)
332 0 : aURLCopy = aURLCopy.replaceAt(aURLCopy.getLength() - sNotes.getLength(), sNotes.getLength(), "");
333 :
334 0 : sal_Int32 number = aURLCopy.toInt32();
335 0 : sal_uInt16 realPageNumber = (nPos + 1)/ 2;
336 :
337 0 : if ( number >= realPageNumber )
338 : {
339 : // update link page number
340 0 : number += nIncrement;
341 0 : aURL = aURL.replaceAt(aHashSlide.getLength() + 1, aURL.getLength() - aHashSlide.getLength() - 1, "");
342 0 : aURL += OUString::number(number);
343 0 : if (bNotes)
344 : {
345 0 : aURL += " " + sNotes;
346 : }
347 0 : pURLField->SetURL(aURL);
348 0 : }
349 0 : }
350 0 : }
351 : }
352 : }
353 : }
354 0 : }
355 :
356 : // Move page
357 0 : void SdDrawDocument::MovePage(sal_uInt16 nPgNum, sal_uInt16 nNewPos)
358 : {
359 0 : FmFormModel::MovePage(nPgNum, nNewPos);
360 :
361 0 : sal_uInt16 nMin = std::min(nPgNum, nNewPos);
362 :
363 0 : UpdatePageObjectsInNotes(nMin);
364 0 : }
365 :
366 : // Insert page
367 0 : void SdDrawDocument::InsertPage(SdrPage* pPage, sal_uInt16 nPos)
368 : {
369 0 : bool bLast = (nPos == GetPageCount());
370 :
371 0 : FmFormModel::InsertPage(pPage, nPos);
372 :
373 0 : ((SdPage*)pPage)->ConnectLink();
374 :
375 0 : UpdatePageObjectsInNotes(nPos);
376 :
377 0 : if (!bLast)
378 0 : UpdatePageRelativeURLs(static_cast<SdPage*>( pPage ), nPos, 1);
379 :
380 0 : }
381 :
382 : // Delete page
383 0 : void SdDrawDocument::DeletePage(sal_uInt16 nPgNum)
384 : {
385 0 : FmFormModel::DeletePage(nPgNum);
386 :
387 0 : UpdatePageObjectsInNotes(nPgNum);
388 0 : }
389 :
390 : // Remove page
391 0 : SdrPage* SdDrawDocument::RemovePage(sal_uInt16 nPgNum)
392 : {
393 0 : SdrPage* pPage = FmFormModel::RemovePage(nPgNum);
394 :
395 0 : bool bLast = ((nPgNum+1)/2 == (GetPageCount()+1)/2);
396 :
397 0 : ((SdPage*)pPage)->DisconnectLink();
398 0 : ReplacePageInCustomShows( dynamic_cast< SdPage* >( pPage ), 0 );
399 0 : UpdatePageObjectsInNotes(nPgNum);
400 :
401 0 : if (!bLast)
402 0 : UpdatePageRelativeURLs((SdPage*)pPage, nPgNum, -1);
403 :
404 0 : return pPage;
405 : }
406 :
407 : // Warning: This is not called for new master pages created from SdrModel::Merge,
408 : // you also have to modify code in SdDrawDocument::Merge!
409 0 : void SdDrawDocument::InsertMasterPage(SdrPage* pPage, sal_uInt16 nPos )
410 : {
411 0 : FmFormModel::InsertMasterPage( pPage, nPos );
412 0 : if( pPage->IsMasterPage() && (static_cast<SdPage*>(pPage)->GetPageKind() == PK_STANDARD) )
413 : {
414 : // new master page created, add its style family
415 0 : SdStyleSheetPool* pStylePool = (SdStyleSheetPool*) GetStyleSheetPool();
416 0 : if( pStylePool )
417 0 : pStylePool->AddStyleFamily( static_cast<SdPage*>(pPage) );
418 : }
419 0 : }
420 :
421 0 : SdrPage* SdDrawDocument::RemoveMasterPage(sal_uInt16 nPgNum)
422 : {
423 0 : SdPage* pPage = static_cast<SdPage*>(GetMasterPage(nPgNum ));
424 0 : if( pPage && pPage->IsMasterPage() && (pPage->GetPageKind() == PK_STANDARD) )
425 : {
426 : // master page removed, remove its style family
427 0 : SdStyleSheetPool* pStylePool = (SdStyleSheetPool*) GetStyleSheetPool();
428 0 : if( pStylePool )
429 0 : pStylePool->RemoveStyleFamily( pPage );
430 : }
431 :
432 0 : return FmFormModel::RemoveMasterPage(nPgNum);
433 : }
434 :
435 : //Select pages
436 0 : void SdDrawDocument::SetSelected(SdPage* pPage, sal_Bool bSelect)
437 : {
438 0 : PageKind ePageKind = pPage->GetPageKind();
439 :
440 0 : if (ePageKind == PK_STANDARD)
441 : {
442 0 : pPage->SetSelected(bSelect);
443 :
444 0 : const sal_uInt16 nDestPageNum(pPage->GetPageNum() + 1);
445 0 : SdPage* pNotesPage = 0L;
446 :
447 0 : if(nDestPageNum < GetPageCount())
448 : {
449 0 : pNotesPage = (SdPage*)GetPage(nDestPageNum);
450 : }
451 :
452 0 : if (pNotesPage && pNotesPage->GetPageKind() == PK_NOTES)
453 : {
454 0 : pNotesPage->SetSelected(bSelect);
455 : }
456 : }
457 0 : else if (ePageKind == PK_NOTES)
458 : {
459 0 : pPage->SetSelected(bSelect);
460 0 : SdPage* pStandardPage = (SdPage*) GetPage( pPage->GetPageNum() - 1 );
461 :
462 0 : if (pStandardPage && pStandardPage->GetPageKind() == PK_STANDARD)
463 0 : pStandardPage->SetSelected(bSelect);
464 : }
465 0 : }
466 :
467 : // If no pages exist yet, create them now
468 0 : void SdDrawDocument::CreateFirstPages( SdDrawDocument* pRefDocument /* = 0 */ )
469 : {
470 : // If no page exists yet in the model, (File -> New), insert a page
471 0 : sal_uInt16 nPageCount = GetPageCount();
472 :
473 0 : if (nPageCount <= 1)
474 : {
475 : // #i57181# Paper size depends on Language, like in Writer
476 0 : Size aDefSize = SvxPaperInfo::GetDefaultPaperSize( MAP_100TH_MM );
477 :
478 : // Insert handout page
479 0 : SdPage* pHandoutPage = dynamic_cast< SdPage* >( AllocPage(false) );
480 :
481 0 : SdPage* pRefPage = NULL;
482 :
483 0 : if( pRefDocument )
484 0 : pRefPage = pRefDocument->GetSdPage( 0, PK_HANDOUT );
485 :
486 0 : if( pRefPage )
487 : {
488 0 : pHandoutPage->SetSize(pRefPage->GetSize());
489 0 : pHandoutPage->SetBorder( pRefPage->GetLftBorder(), pRefPage->GetUppBorder(), pRefPage->GetRgtBorder(), pRefPage->GetLwrBorder() );
490 : }
491 : else
492 : {
493 0 : pHandoutPage->SetSize(aDefSize);
494 0 : pHandoutPage->SetBorder(0, 0, 0, 0);
495 : }
496 :
497 0 : pHandoutPage->SetPageKind(PK_HANDOUT);
498 0 : pHandoutPage->SetName( SD_RESSTR(STR_HANDOUT) );
499 0 : InsertPage(pHandoutPage, 0);
500 :
501 : // Insert master page and register this with the handout page
502 0 : SdPage* pHandoutMPage = (SdPage*) AllocPage(true);
503 0 : pHandoutMPage->SetSize( pHandoutPage->GetSize() );
504 0 : pHandoutMPage->SetPageKind(PK_HANDOUT);
505 0 : pHandoutMPage->SetBorder( pHandoutPage->GetLftBorder(),
506 0 : pHandoutPage->GetUppBorder(),
507 0 : pHandoutPage->GetRgtBorder(),
508 0 : pHandoutPage->GetLwrBorder() );
509 0 : InsertMasterPage(pHandoutMPage, 0);
510 0 : pHandoutPage->TRG_SetMasterPage( *pHandoutMPage );
511 :
512 : // Insert page
513 : // If nPageCount==1 is, the model for the clipboard was created, thus a
514 : // default page must already exist
515 : SdPage* pPage;
516 0 : sal_Bool bClipboard = sal_False;
517 :
518 0 : if( pRefDocument )
519 0 : pRefPage = pRefDocument->GetSdPage( 0, PK_STANDARD );
520 :
521 0 : if (nPageCount == 0)
522 : {
523 0 : pPage = dynamic_cast< SdPage* >( AllocPage(false) );
524 :
525 0 : if( pRefPage )
526 : {
527 0 : pPage->SetSize( pRefPage->GetSize() );
528 0 : pPage->SetBorder( pRefPage->GetLftBorder(), pRefPage->GetUppBorder(), pRefPage->GetRgtBorder(), pRefPage->GetLwrBorder() );
529 : }
530 0 : else if (meDocType == DOCUMENT_TYPE_DRAW)
531 : {
532 : // Draw: always use default size with margins
533 0 : pPage->SetSize(aDefSize);
534 :
535 0 : SfxPrinter* pPrinter = mpDocSh->GetPrinter(sal_False);
536 0 : if (pPrinter && pPrinter->IsValid())
537 : {
538 0 : Size aOutSize(pPrinter->GetOutputSize());
539 0 : Point aPageOffset(pPrinter->GetPageOffset());
540 0 : aPageOffset -= pPrinter->PixelToLogic( Point() );
541 0 : long nOffset = !aPageOffset.X() && !aPageOffset.Y() ? 0 : PRINT_OFFSET;
542 :
543 0 : sal_uLong nTop = aPageOffset.Y();
544 0 : sal_uLong nLeft = aPageOffset.X();
545 0 : sal_uLong nBottom = std::max((long)(aDefSize.Height() - aOutSize.Height() - nTop + nOffset), 0L);
546 0 : sal_uLong nRight = std::max((long)(aDefSize.Width() - aOutSize.Width() - nLeft + nOffset), 0L);
547 :
548 0 : pPage->SetBorder(nLeft, nTop, nRight, nBottom);
549 : }
550 : else
551 : {
552 : // The printer is not available. Use a border of 10mm
553 : // on each side instead.
554 : // This has to be kept synchronized with the border
555 : // width set in the
556 : // SvxPageDescPage::PaperSizeSelect_Impl callback.
557 0 : pPage->SetBorder(1000, 1000, 1000, 1000);
558 : }
559 : }
560 : else
561 : {
562 : // Impress: always use screen format, landscape.
563 0 : Size aSz( SvxPaperInfo::GetPaperSize(PAPER_SCREEN_4_3, MAP_100TH_MM) );
564 0 : pPage->SetSize( Size( aSz.Height(), aSz.Width() ) );
565 0 : pPage->SetBorder(0, 0, 0, 0);
566 : }
567 :
568 0 : InsertPage(pPage, 1);
569 : }
570 : else
571 : {
572 0 : bClipboard = sal_True;
573 0 : pPage = (SdPage*) GetPage(1);
574 : }
575 :
576 : // Insert master page, then register this with the page
577 0 : SdPage* pMPage = (SdPage*) AllocPage(true);
578 0 : pMPage->SetSize( pPage->GetSize() );
579 0 : pMPage->SetBorder( pPage->GetLftBorder(),
580 0 : pPage->GetUppBorder(),
581 0 : pPage->GetRgtBorder(),
582 0 : pPage->GetLwrBorder() );
583 0 : InsertMasterPage(pMPage, 1);
584 0 : pPage->TRG_SetMasterPage( *pMPage );
585 0 : if( bClipboard )
586 0 : pMPage->SetLayoutName( pPage->GetLayoutName() );
587 :
588 : // Insert notes page
589 0 : SdPage* pNotesPage = (SdPage*) AllocPage(false);
590 :
591 0 : if( pRefDocument )
592 0 : pRefPage = pRefDocument->GetSdPage( 0, PK_NOTES );
593 :
594 0 : if( pRefPage )
595 : {
596 0 : pNotesPage->SetSize( pRefPage->GetSize() );
597 0 : pNotesPage->SetBorder( pRefPage->GetLftBorder(), pRefPage->GetUppBorder(), pRefPage->GetRgtBorder(), pRefPage->GetLwrBorder() );
598 : }
599 : else
600 : {
601 : // Always use portrait format
602 0 : if (aDefSize.Height() >= aDefSize.Width())
603 : {
604 0 : pNotesPage->SetSize(aDefSize);
605 : }
606 : else
607 : {
608 0 : pNotesPage->SetSize( Size(aDefSize.Height(), aDefSize.Width()) );
609 : }
610 :
611 0 : pNotesPage->SetBorder(0, 0, 0, 0);
612 : }
613 0 : pNotesPage->SetPageKind(PK_NOTES);
614 0 : InsertPage(pNotesPage, 2);
615 0 : if( bClipboard )
616 0 : pNotesPage->SetLayoutName( pPage->GetLayoutName() );
617 :
618 : // Insert master page, then register this with the notes page
619 0 : SdPage* pNotesMPage = (SdPage*) AllocPage(true);
620 0 : pNotesMPage->SetSize( pNotesPage->GetSize() );
621 0 : pNotesMPage->SetPageKind(PK_NOTES);
622 0 : pNotesMPage->SetBorder( pNotesPage->GetLftBorder(),
623 0 : pNotesPage->GetUppBorder(),
624 0 : pNotesPage->GetRgtBorder(),
625 0 : pNotesPage->GetLwrBorder() );
626 0 : InsertMasterPage(pNotesMPage, 2);
627 0 : pNotesPage->TRG_SetMasterPage( *pNotesMPage );
628 0 : if( bClipboard )
629 0 : pNotesMPage->SetLayoutName( pPage->GetLayoutName() );
630 :
631 :
632 0 : if( !pRefPage && (meDocType != DOCUMENT_TYPE_DRAW) )
633 0 : pPage->SetAutoLayout( AUTOLAYOUT_TITLE, sal_True, sal_True );
634 :
635 0 : mpWorkStartupTimer = new Timer();
636 0 : mpWorkStartupTimer->SetTimeoutHdl( LINK(this, SdDrawDocument, WorkStartupHdl) );
637 0 : mpWorkStartupTimer->SetTimeout(2000);
638 0 : mpWorkStartupTimer->Start();
639 :
640 0 : SetChanged(false);
641 : }
642 0 : }
643 :
644 : // Creates missing notes and handout pages (after PowerPoint import).
645 : // We assume that at least one default page and one default master page exist.
646 :
647 0 : sal_Bool SdDrawDocument::CreateMissingNotesAndHandoutPages()
648 : {
649 0 : sal_Bool bOK = sal_False;
650 0 : sal_uInt16 nPageCount = GetPageCount();
651 :
652 0 : if (nPageCount != 0)
653 : {
654 : // Set PageKind
655 0 : SdPage* pHandoutMPage = (SdPage*) GetMasterPage(0);
656 0 : pHandoutMPage->SetPageKind(PK_HANDOUT);
657 :
658 0 : SdPage* pHandoutPage = (SdPage*) GetPage(0);
659 0 : pHandoutPage->SetPageKind(PK_HANDOUT);
660 0 : pHandoutPage->TRG_SetMasterPage( *pHandoutMPage );
661 :
662 0 : for (sal_uInt16 i = 1; i < nPageCount; i = i + 2)
663 : {
664 0 : SdPage* pPage = (SdPage*) GetPage(i);
665 :
666 0 : if(!pPage->TRG_HasMasterPage())
667 : {
668 : // No master page set -> use first default master page
669 : // (If there was no default page in the PPT)
670 0 : pPage->TRG_SetMasterPage(*GetMasterPage(1));
671 : }
672 :
673 0 : SdPage* pNotesPage = (SdPage*) GetPage(i+1);
674 0 : pNotesPage->SetPageKind(PK_NOTES);
675 :
676 : // Set notes master page
677 0 : sal_uInt16 nMasterPageAfterPagesMasterPage = (pPage->TRG_GetMasterPage()).GetPageNum() + 1;
678 0 : pNotesPage->TRG_SetMasterPage(*GetMasterPage(nMasterPageAfterPagesMasterPage));
679 : }
680 :
681 0 : bOK = sal_True;
682 0 : StopWorkStartupDelay();
683 0 : SetChanged(false);
684 : }
685 :
686 0 : return(bOK);
687 : }
688 :
689 : // + Move selected pages after said page
690 : // (nTargetPage = (sal_uInt16)-1 --> move before first page)
691 : // + Returns sal_True when the page has been moved
692 0 : sal_Bool SdDrawDocument::MovePages(sal_uInt16 nTargetPage)
693 : {
694 0 : SdPage* pPage = NULL;
695 : sal_uInt16 nPage;
696 0 : sal_uInt16 nNoOfPages = GetSdPageCount(PK_STANDARD);
697 0 : sal_Bool bSomethingHappened = sal_False;
698 :
699 0 : const bool bUndo = IsUndoEnabled();
700 :
701 0 : if( bUndo )
702 0 : BegUndo(SD_RESSTR(STR_UNDO_MOVEPAGES));
703 :
704 : // List of selected pages
705 0 : std::vector<SdPage*> aPageList;
706 0 : for (nPage = 0; nPage < nNoOfPages; nPage++)
707 : {
708 0 : pPage = GetSdPage(nPage, PK_STANDARD);
709 :
710 0 : if (pPage->IsSelected())
711 0 : aPageList.push_back(pPage);
712 : }
713 :
714 : // If necessary, look backwards, until we find a page that wasn't selected
715 0 : nPage = nTargetPage;
716 0 : if (nPage != (sal_uInt16)-1)
717 : {
718 0 : pPage = GetSdPage(nPage, PK_STANDARD);
719 0 : while (nPage > 0 && pPage->IsSelected())
720 : {
721 0 : nPage--;
722 0 : pPage = GetSdPage(nPage, PK_STANDARD);
723 : }
724 :
725 0 : if (pPage->IsSelected())
726 : {
727 0 : nPage = (sal_uInt16)-1;
728 : }
729 : }
730 :
731 : // Insert before the first page
732 0 : if (nPage == (sal_uInt16)-1)
733 : {
734 0 : std::vector<SdPage*>::reverse_iterator iter;
735 0 : for (iter = aPageList.rbegin(); iter != aPageList.rend(); ++iter)
736 : {
737 0 : nPage = (*iter)->GetPageNum();
738 0 : if (nPage != 0)
739 : {
740 0 : SdrPage* pPg = GetPage(nPage);
741 0 : if( bUndo )
742 0 : AddUndo(GetSdrUndoFactory().CreateUndoSetPageNum(*pPg, nPage, 1));
743 0 : MovePage(nPage, 1);
744 0 : pPg = GetPage(nPage+1);
745 0 : if( bUndo )
746 0 : AddUndo(GetSdrUndoFactory().CreateUndoSetPageNum(*pPg, nPage+1, 2));
747 0 : MovePage(nPage+1, 2);
748 0 : bSomethingHappened = sal_True;
749 : }
750 : }
751 : }
752 : // Insert after <nPage>
753 : else
754 : {
755 0 : nTargetPage = nPage;
756 0 : nTargetPage = 2 * nTargetPage + 1; // PK_STANDARD --> absolute
757 :
758 0 : std::vector<SdPage*>::iterator iter;
759 0 : for (iter = aPageList.begin(); iter != aPageList.end(); ++iter)
760 : {
761 0 : pPage = *iter;
762 0 : nPage = pPage->GetPageNum();
763 0 : if (nPage > nTargetPage)
764 : {
765 0 : nTargetPage += 2; // Insert _after_ the page
766 :
767 0 : if (nPage != nTargetPage)
768 : {
769 0 : SdrPage* pPg = GetPage(nPage);
770 0 : if( bUndo )
771 0 : AddUndo(GetSdrUndoFactory().CreateUndoSetPageNum(*pPg, nPage, nTargetPage));
772 0 : MovePage(nPage, nTargetPage);
773 0 : pPg = GetPage(nPage+1);
774 0 : if( bUndo )
775 0 : AddUndo(GetSdrUndoFactory().CreateUndoSetPageNum(*pPg, nPage+1, nTargetPage+1));
776 0 : MovePage(nPage+1, nTargetPage+1);
777 0 : bSomethingHappened = sal_True;
778 : }
779 : }
780 : else
781 : {
782 0 : if (nPage != nTargetPage)
783 : {
784 0 : SdrPage* pPg = GetPage(nPage+1);
785 0 : if( bUndo )
786 0 : AddUndo(GetSdrUndoFactory().CreateUndoSetPageNum(*pPg, nPage+1, nTargetPage+1));
787 0 : MovePage(nPage+1, nTargetPage+1);
788 0 : pPg = GetPage(nPage);
789 0 : if( bUndo )
790 0 : AddUndo(GetSdrUndoFactory().CreateUndoSetPageNum(*pPg, nPage, nTargetPage));
791 0 : MovePage(nPage, nTargetPage);
792 0 : bSomethingHappened = sal_True;
793 : }
794 : }
795 0 : nTargetPage = pPage->GetPageNum();
796 : }
797 : }
798 :
799 0 : if( bUndo )
800 0 : EndUndo();
801 :
802 0 : return bSomethingHappened;
803 : }
804 :
805 :
806 : // Return number of links in sfx2::LinkManager
807 0 : sal_uLong SdDrawDocument::GetLinkCount()
808 : {
809 0 : return pLinkManager->GetLinks().size();
810 : }
811 :
812 : // Set Language
813 0 : void SdDrawDocument::SetLanguage( const LanguageType eLang, const sal_uInt16 nId )
814 : {
815 0 : sal_Bool bChanged = sal_False;
816 :
817 0 : if( nId == EE_CHAR_LANGUAGE && meLanguage != eLang )
818 : {
819 0 : meLanguage = eLang;
820 0 : bChanged = sal_True;
821 : }
822 0 : else if( nId == EE_CHAR_LANGUAGE_CJK && meLanguageCJK != eLang )
823 : {
824 0 : meLanguageCJK = eLang;
825 0 : bChanged = sal_True;
826 : }
827 0 : else if( nId == EE_CHAR_LANGUAGE_CTL && meLanguageCTL != eLang )
828 : {
829 0 : meLanguageCTL = eLang;
830 0 : bChanged = sal_True;
831 : }
832 :
833 0 : if( bChanged )
834 : {
835 0 : GetDrawOutliner().SetDefaultLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() );
836 0 : pHitTestOutliner->SetDefaultLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() );
837 0 : pItemPool->SetPoolDefaultItem( SvxLanguageItem( eLang, nId ) );
838 0 : SetChanged( bChanged );
839 : }
840 0 : }
841 :
842 :
843 : // Return language
844 0 : LanguageType SdDrawDocument::GetLanguage( const sal_uInt16 nId ) const
845 : {
846 0 : LanguageType eLangType = meLanguage;
847 :
848 0 : if( nId == EE_CHAR_LANGUAGE_CJK )
849 0 : eLangType = meLanguageCJK;
850 0 : else if( nId == EE_CHAR_LANGUAGE_CTL )
851 0 : eLangType = meLanguageCTL;
852 :
853 0 : return eLangType;
854 : }
855 :
856 :
857 : // Initiate WorkStartup
858 0 : IMPL_LINK_NOARG(SdDrawDocument, WorkStartupHdl)
859 : {
860 0 : if( mpDocSh )
861 0 : mpDocSh->SetWaitCursor( true );
862 :
863 0 : sal_Bool bChanged = IsChanged(); // remember this
864 :
865 : // Initialize Autolayouts
866 0 : SdPage* pHandoutMPage = GetMasterSdPage(0, PK_HANDOUT);
867 :
868 0 : if (pHandoutMPage->GetAutoLayout() == AUTOLAYOUT_NONE)
869 : {
870 : // No AutoLayout yet -> initialize
871 0 : pHandoutMPage->SetAutoLayout(AUTOLAYOUT_HANDOUT6, sal_True, sal_True);
872 : }
873 :
874 0 : SdPage* pPage = GetSdPage(0, PK_STANDARD);
875 :
876 0 : if (pPage->GetAutoLayout() == AUTOLAYOUT_NONE)
877 : {
878 : // No AutoLayout yet -> initialize
879 0 : pPage->SetAutoLayout(AUTOLAYOUT_NONE, sal_True, sal_True);
880 : }
881 :
882 0 : SdPage* pNotesPage = GetSdPage(0, PK_NOTES);
883 :
884 0 : if (pNotesPage->GetAutoLayout() == AUTOLAYOUT_NONE)
885 : {
886 : // No AutoLayout yet -> initialize
887 0 : pNotesPage->SetAutoLayout(AUTOLAYOUT_NOTES, sal_True, sal_True);
888 : }
889 :
890 0 : SetChanged(bChanged);
891 :
892 0 : if( mpDocSh )
893 0 : mpDocSh->SetWaitCursor( false );
894 0 : return 0;
895 : }
896 :
897 :
898 : // When the WorkStartupTimer has been created (this only happens in
899 : // SdDrawViewShell::Construct() ), the timer may be stopped and the WorkStartup
900 : // may be initiated.
901 0 : void SdDrawDocument::StopWorkStartupDelay()
902 : {
903 0 : if (mpWorkStartupTimer)
904 : {
905 0 : if ( mpWorkStartupTimer->IsActive() )
906 : {
907 : // Timer not yet expired -> initiate WorkStartup
908 0 : mpWorkStartupTimer->Stop();
909 0 : WorkStartupHdl(NULL);
910 : }
911 :
912 0 : delete mpWorkStartupTimer;
913 0 : mpWorkStartupTimer = NULL;
914 : }
915 0 : }
916 :
917 : // When the WorkStartupTimer has been created (this only happens in
918 : // SdDrawViewShell::Construct() ), the timer may be stopped and the WorkStartup
919 : // may be initiated.
920 0 : SdAnimationInfo* SdDrawDocument::GetAnimationInfo(SdrObject* pObject) const
921 : {
922 : DBG_ASSERT(pObject, "sd::SdDrawDocument::GetAnimationInfo(), invalid argument!");
923 0 : if( pObject )
924 0 : return GetShapeUserData( *pObject, false );
925 : else
926 0 : return 0;
927 : }
928 :
929 0 : SdAnimationInfo* SdDrawDocument::GetShapeUserData(SdrObject& rObject, bool bCreate /* = false */ )
930 : {
931 0 : sal_uInt16 nUD = 0;
932 0 : sal_uInt16 nUDCount = rObject.GetUserDataCount();
933 0 : SdrObjUserData* pUD = 0;
934 0 : SdAnimationInfo* pRet = 0;
935 :
936 : // Can we find animation information within the user data?
937 0 : for (nUD = 0; nUD < nUDCount; nUD++)
938 : {
939 0 : pUD = rObject.GetUserData(nUD);
940 0 : if((pUD->GetInventor() == SdUDInventor) && (pUD->GetId() == SD_ANIMATIONINFO_ID))
941 : {
942 0 : pRet = dynamic_cast<SdAnimationInfo*>(pUD);
943 0 : break;
944 : }
945 : }
946 :
947 0 : if( (pRet == 0) && bCreate )
948 : {
949 0 : pRet = new SdAnimationInfo( rObject );
950 0 : rObject.AppendUserData( pRet);
951 : }
952 :
953 0 : return pRet;
954 : }
955 :
956 0 : SdIMapInfo* SdDrawDocument::GetIMapInfo( SdrObject* pObject ) const
957 : {
958 : DBG_ASSERT(pObject, "Without an object there is no IMapInfo");
959 :
960 0 : SdrObjUserData* pUserData = NULL;
961 0 : SdIMapInfo* pIMapInfo = NULL;
962 0 : sal_uInt16 nCount = pObject->GetUserDataCount();
963 :
964 : // Can we find IMap information within the user data?
965 0 : for ( sal_uInt16 i = 0; i < nCount; i++ )
966 : {
967 0 : pUserData = pObject->GetUserData( i );
968 :
969 0 : if ( ( pUserData->GetInventor() == SdUDInventor ) && ( pUserData->GetId() == SD_IMAPINFO_ID ) )
970 0 : pIMapInfo = (SdIMapInfo*) pUserData;
971 : }
972 :
973 0 : return pIMapInfo;
974 : }
975 :
976 0 : IMapObject* SdDrawDocument::GetHitIMapObject( SdrObject* pObj,
977 : const Point& rWinPoint,
978 : const ::Window& /* rCmpWnd */ )
979 : {
980 0 : SdIMapInfo* pIMapInfo = GetIMapInfo( pObj );
981 0 : IMapObject* pIMapObj = NULL;
982 :
983 0 : if ( pIMapInfo )
984 : {
985 0 : const MapMode aMap100( MAP_100TH_MM );
986 0 : Size aGraphSize;
987 0 : Point aRelPoint( rWinPoint );
988 0 : ImageMap& rImageMap = (ImageMap&) pIMapInfo->GetImageMap();
989 0 : const Rectangle& rRect = pObj->GetLogicRect();
990 0 : sal_Bool bObjSupported = sal_False;
991 :
992 : // execute HitTest
993 0 : if ( pObj->ISA( SdrGrafObj ) ) // simple graphics object
994 : {
995 0 : const SdrGrafObj* pGrafObj = (const SdrGrafObj*) pObj;
996 0 : const GeoStat& rGeo = pGrafObj->GetGeoStat();
997 0 : SdrGrafObjGeoData* pGeoData = (SdrGrafObjGeoData*) pGrafObj->GetGeoData();
998 :
999 : // Undo rotation
1000 0 : if ( rGeo.nDrehWink )
1001 0 : RotatePoint( aRelPoint, rRect.TopLeft(), -rGeo.nSin, rGeo.nCos );
1002 :
1003 : // Undo mirroring
1004 0 : if ( pGeoData->bMirrored )
1005 0 : aRelPoint.X() = rRect.Right() + rRect.Left() - aRelPoint.X();
1006 :
1007 : // Undo shearing
1008 0 : if ( rGeo.nShearWink )
1009 0 : ShearPoint( aRelPoint, rRect.TopLeft(), -rGeo.nTan );
1010 :
1011 0 : if ( pGrafObj->GetGrafPrefMapMode().GetMapUnit() == MAP_PIXEL )
1012 0 : aGraphSize = Application::GetDefaultDevice()->PixelToLogic( pGrafObj->GetGrafPrefSize(), aMap100 );
1013 : else
1014 0 : aGraphSize = OutputDevice::LogicToLogic( pGrafObj->GetGrafPrefSize(),
1015 0 : pGrafObj->GetGrafPrefMapMode(), aMap100 );
1016 :
1017 0 : delete pGeoData;
1018 0 : bObjSupported = sal_True;
1019 : }
1020 0 : else if ( pObj->ISA( SdrOle2Obj ) ) // OLE object
1021 : {
1022 0 : aGraphSize = ( (SdrOle2Obj*) pObj )->GetOrigObjSize();
1023 0 : bObjSupported = sal_True;
1024 : }
1025 :
1026 : // Everything worked out well, thus execute HitTest
1027 0 : if ( bObjSupported )
1028 : {
1029 : // Calculate relative position of mouse cursor
1030 0 : aRelPoint -= rRect.TopLeft();
1031 0 : pIMapObj = rImageMap.GetHitIMapObject( aGraphSize, rRect.GetSize(), aRelPoint );
1032 :
1033 : // We don't care about deactivated objects
1034 0 : if ( pIMapObj && !pIMapObj->IsActive() )
1035 0 : pIMapObj = NULL;
1036 0 : }
1037 : }
1038 :
1039 0 : return pIMapObj;
1040 : }
1041 :
1042 0 : ImageMap* SdDrawDocument::GetImageMapForObject(SdrObject* pObj)
1043 : {
1044 0 : SdIMapInfo* pIMapInfo = GetIMapInfo( pObj );
1045 0 : if ( pIMapInfo )
1046 : {
1047 0 : return const_cast<ImageMap*>( &(pIMapInfo->GetImageMap()) );
1048 : }
1049 0 : return NULL;
1050 : }
1051 :
1052 : /** this method enforces that the masterpages are in the currect order,
1053 : that is at position 1 is a PK_STANDARD masterpage followed by a
1054 : PK_NOTES masterpage and so on. #
1055 : */
1056 0 : void SdDrawDocument::CheckMasterPages()
1057 : {
1058 0 : sal_uInt16 nMaxPages = GetMasterPageCount();
1059 :
1060 : // we need at least a handout master and one master page
1061 0 : if( nMaxPages < 2 )
1062 : {
1063 0 : return;
1064 : }
1065 :
1066 0 : SdPage* pPage = NULL;
1067 0 : SdPage* pNotesPage = NULL;
1068 :
1069 : sal_uInt16 nPage;
1070 :
1071 : // first see if the page order is correct
1072 0 : for( nPage = 1; nPage < nMaxPages; nPage++ )
1073 : {
1074 0 : pPage = static_cast<SdPage*> (GetMasterPage( nPage ));
1075 : // if an odd page is not a standard page or an even page is not a notes page
1076 0 : if( ((1 == (nPage & 1)) && (pPage->GetPageKind() != PK_STANDARD) ) ||
1077 0 : ((0 == (nPage & 1)) && (pPage->GetPageKind() != PK_NOTES) ) )
1078 0 : break; // then we have a fatal error
1079 : }
1080 :
1081 0 : if( nPage < nMaxPages )
1082 : {
1083 : // there is a fatal error in the master page order,
1084 : // we need to repair the document
1085 0 : sal_Bool bChanged = sal_False;
1086 :
1087 0 : nPage = 1;
1088 0 : while( nPage < nMaxPages )
1089 : {
1090 0 : pPage = static_cast<SdPage*> (GetMasterPage( nPage ));
1091 0 : if( pPage->GetPageKind() != PK_STANDARD )
1092 : {
1093 0 : bChanged = sal_True;
1094 0 : sal_uInt16 nFound = nPage + 1;
1095 0 : while( nFound < nMaxPages )
1096 : {
1097 0 : pPage = static_cast<SdPage*>(GetMasterPage( nFound ));
1098 0 : if( PK_STANDARD == pPage->GetPageKind() )
1099 : {
1100 0 : MoveMasterPage( nFound, nPage );
1101 0 : pPage->SetInserted(true);
1102 0 : break;
1103 :
1104 : }
1105 :
1106 0 : nFound++;
1107 : }
1108 :
1109 : // if we don't have any more standard pages, were done
1110 0 : if( nMaxPages == nFound )
1111 0 : break;
1112 : }
1113 :
1114 0 : nPage++;
1115 :
1116 0 : if( nPage < nMaxPages )
1117 0 : pNotesPage = static_cast<SdPage*>(GetMasterPage( nPage ));
1118 : else
1119 0 : pNotesPage = NULL;
1120 :
1121 0 : if( (NULL == pNotesPage) || (pNotesPage->GetPageKind() != PK_NOTES) || ( pPage->GetLayoutName() != pNotesPage->GetLayoutName() ) )
1122 : {
1123 0 : bChanged = sal_True;
1124 :
1125 0 : sal_uInt16 nFound = nPage + 1;
1126 0 : while( nFound < nMaxPages )
1127 : {
1128 0 : pNotesPage = static_cast<SdPage*>(GetMasterPage( nFound ));
1129 0 : if( (PK_NOTES == pNotesPage->GetPageKind()) && ( pPage->GetLayoutName() == pNotesPage->GetLayoutName() ) )
1130 : {
1131 0 : MoveMasterPage( nFound, nPage );
1132 0 : pNotesPage->SetInserted(true);
1133 0 : break;
1134 : }
1135 :
1136 0 : nFound++;
1137 : }
1138 :
1139 : // looks like we lost a notes page
1140 0 : if( nMaxPages == nFound )
1141 : {
1142 : // so create one
1143 :
1144 : // first find a reference notes page for size
1145 0 : SdPage* pRefNotesPage = NULL;
1146 0 : nFound = 0;
1147 0 : while( nFound < nMaxPages )
1148 : {
1149 0 : pRefNotesPage = static_cast<SdPage*>(GetMasterPage( nFound ));
1150 0 : if( PK_NOTES == pRefNotesPage->GetPageKind() )
1151 0 : break;
1152 0 : nFound++;
1153 : }
1154 0 : if( nFound == nMaxPages )
1155 0 : pRefNotesPage = NULL;
1156 :
1157 0 : SdPage* pNewNotesPage = static_cast<SdPage*>(AllocPage(true));
1158 0 : pNewNotesPage->SetPageKind(PK_NOTES);
1159 0 : if( pRefNotesPage )
1160 : {
1161 0 : pNewNotesPage->SetSize( pRefNotesPage->GetSize() );
1162 0 : pNewNotesPage->SetBorder( pRefNotesPage->GetLftBorder(),
1163 0 : pRefNotesPage->GetUppBorder(),
1164 0 : pRefNotesPage->GetRgtBorder(),
1165 0 : pRefNotesPage->GetLwrBorder() );
1166 : }
1167 0 : InsertMasterPage(pNewNotesPage, nPage );
1168 0 : pNewNotesPage->SetLayoutName( pPage->GetLayoutName() );
1169 0 : pNewNotesPage->SetAutoLayout(AUTOLAYOUT_NOTES, sal_True, sal_True );
1170 0 : nMaxPages++;
1171 : }
1172 : }
1173 :
1174 0 : nPage++;
1175 : }
1176 :
1177 : // now remove all remaining and unused non PK_STANDARD slides
1178 0 : while( nPage < nMaxPages )
1179 : {
1180 0 : bChanged = sal_True;
1181 :
1182 0 : RemoveMasterPage( nPage );
1183 0 : nMaxPages--;
1184 : }
1185 :
1186 0 : if( bChanged )
1187 : {
1188 : OSL_FAIL( "master pages where in a wrong order" );
1189 0 : RecalcPageNums( true);
1190 : }
1191 : }
1192 : }
1193 :
1194 0 : sal_uInt16 SdDrawDocument::CreatePage (
1195 : SdPage* pActualPage,
1196 : PageKind ePageKind,
1197 : const OUString& sStandardPageName,
1198 : const OUString& sNotesPageName,
1199 : AutoLayout eStandardLayout,
1200 : AutoLayout eNotesLayout,
1201 : sal_Bool bIsPageBack,
1202 : sal_Bool bIsPageObj,
1203 : const sal_Int32 nInsertPosition)
1204 : {
1205 : SdPage* pPreviousStandardPage;
1206 : SdPage* pPreviousNotesPage;
1207 : SdPage* pStandardPage;
1208 : SdPage* pNotesPage;
1209 :
1210 : // From the given page determine the standard page and notes page of which
1211 : // to take the layout and the position where to insert the new pages.
1212 0 : if (ePageKind == PK_NOTES)
1213 : {
1214 0 : pPreviousNotesPage = pActualPage;
1215 0 : sal_uInt16 nNotesPageNum = pPreviousNotesPage->GetPageNum() + 2;
1216 0 : pPreviousStandardPage = (SdPage*) GetPage(nNotesPageNum - 3);
1217 0 : eStandardLayout = pPreviousStandardPage->GetAutoLayout();
1218 : }
1219 : else
1220 : {
1221 0 : pPreviousStandardPage = pActualPage;
1222 0 : sal_uInt16 nStandardPageNum = pPreviousStandardPage->GetPageNum() + 2;
1223 0 : pPreviousNotesPage = (SdPage*) GetPage(nStandardPageNum - 1);
1224 0 : eNotesLayout = pPreviousNotesPage->GetAutoLayout();
1225 : }
1226 :
1227 : // Create new standard page and set it up
1228 0 : pStandardPage = (SdPage*) AllocPage(false);
1229 :
1230 : // Set the size here since else the presobj autolayout
1231 : // will be wrong.
1232 0 : pStandardPage->SetSize( pPreviousStandardPage->GetSize() );
1233 0 : pStandardPage->SetBorder( pPreviousStandardPage->GetLftBorder(),
1234 0 : pPreviousStandardPage->GetUppBorder(),
1235 0 : pPreviousStandardPage->GetRgtBorder(),
1236 0 : pPreviousStandardPage->GetLwrBorder() );
1237 :
1238 : // Use master page of current page.
1239 0 : pStandardPage->TRG_SetMasterPage(pPreviousStandardPage->TRG_GetMasterPage());
1240 :
1241 : // User layout of current standard page
1242 0 : pStandardPage->SetLayoutName( pPreviousStandardPage->GetLayoutName() );
1243 0 : pStandardPage->SetAutoLayout(eStandardLayout, sal_True);
1244 0 : pStandardPage->setHeaderFooterSettings( pPreviousStandardPage->getHeaderFooterSettings() );
1245 :
1246 : // transition settings of current page
1247 0 : pStandardPage->setTransitionType( pPreviousStandardPage->getTransitionType() );
1248 0 : pStandardPage->setTransitionSubtype( pPreviousStandardPage->getTransitionSubtype() );
1249 0 : pStandardPage->setTransitionDirection( pPreviousStandardPage->getTransitionDirection() );
1250 0 : pStandardPage->setTransitionFadeColor( pPreviousStandardPage->getTransitionFadeColor() );
1251 0 : pStandardPage->setTransitionDuration( pPreviousStandardPage->getTransitionDuration() );
1252 :
1253 : // apply previous animation timing
1254 0 : pStandardPage->SetPresChange( pPreviousStandardPage->GetPresChange() );
1255 0 : pStandardPage->SetTime( pPreviousStandardPage->GetTime() );
1256 :
1257 : // Create new notes page and set it up
1258 0 : pNotesPage = (SdPage*) AllocPage(false);
1259 0 : pNotesPage->SetPageKind(PK_NOTES);
1260 :
1261 : // Use master page of current page
1262 0 : pNotesPage->TRG_SetMasterPage(pPreviousNotesPage->TRG_GetMasterPage());
1263 :
1264 : // Use layout of current notes page
1265 0 : pNotesPage->SetLayoutName( pPreviousNotesPage->GetLayoutName() );
1266 0 : pNotesPage->SetAutoLayout(eNotesLayout, sal_True);
1267 0 : pNotesPage->setHeaderFooterSettings( pPreviousNotesPage->getHeaderFooterSettings() );
1268 :
1269 : return InsertPageSet (
1270 : pActualPage,
1271 : ePageKind,
1272 : sStandardPageName,
1273 : sNotesPageName,
1274 : bIsPageBack,
1275 : bIsPageObj,
1276 : pStandardPage,
1277 : pNotesPage,
1278 0 : nInsertPosition);
1279 : }
1280 :
1281 :
1282 :
1283 :
1284 0 : sal_uInt16 SdDrawDocument::DuplicatePage (sal_uInt16 nPageNum)
1285 : {
1286 0 : PageKind ePageKind = PK_STANDARD;
1287 :
1288 : // Get current page
1289 0 : SdPage* pActualPage = GetSdPage(nPageNum, ePageKind);
1290 :
1291 : // Get background flags
1292 0 : SdrLayerAdmin& rLayerAdmin = GetLayerAdmin();
1293 0 : sal_uInt8 aBckgrnd = rLayerAdmin.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRND), false);
1294 0 : sal_uInt8 aBckgrndObj = rLayerAdmin.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRNDOBJ), false);
1295 0 : SetOfByte aVisibleLayers = pActualPage->TRG_GetMasterPageVisibleLayers();
1296 :
1297 : return DuplicatePage (
1298 : pActualPage, ePageKind,
1299 : // No names for the new slides
1300 : OUString(), OUString(),
1301 0 : aVisibleLayers.IsSet(aBckgrnd),
1302 0 : aVisibleLayers.IsSet(aBckgrndObj));
1303 : }
1304 :
1305 :
1306 :
1307 :
1308 0 : sal_uInt16 SdDrawDocument::DuplicatePage (
1309 : SdPage* pActualPage,
1310 : PageKind ePageKind,
1311 : const OUString& sStandardPageName,
1312 : const OUString& sNotesPageName,
1313 : sal_Bool bIsPageBack,
1314 : sal_Bool bIsPageObj,
1315 : const sal_Int32 nInsertPosition)
1316 : {
1317 : SdPage* pPreviousStandardPage;
1318 : SdPage* pPreviousNotesPage;
1319 : SdPage* pStandardPage;
1320 : SdPage* pNotesPage;
1321 :
1322 : // From the given page determine the standard page and the notes page
1323 : // of which to make copies.
1324 0 : if (ePageKind == PK_NOTES)
1325 : {
1326 0 : pPreviousNotesPage = pActualPage;
1327 0 : sal_uInt16 nNotesPageNum = pPreviousNotesPage->GetPageNum() + 2;
1328 0 : pPreviousStandardPage = (SdPage*) GetPage(nNotesPageNum - 3);
1329 : }
1330 : else
1331 : {
1332 0 : pPreviousStandardPage = pActualPage;
1333 0 : sal_uInt16 nStandardPageNum = pPreviousStandardPage->GetPageNum() + 2;
1334 0 : pPreviousNotesPage = (SdPage*) GetPage(nStandardPageNum - 1);
1335 : }
1336 :
1337 : // Create duplicates of a standard page and the associated notes page
1338 0 : pStandardPage = (SdPage*) pPreviousStandardPage->Clone();
1339 0 : pNotesPage = (SdPage*) pPreviousNotesPage->Clone();
1340 :
1341 : return InsertPageSet (
1342 : pActualPage,
1343 : ePageKind,
1344 : sStandardPageName,
1345 : sNotesPageName,
1346 : bIsPageBack,
1347 : bIsPageObj,
1348 : pStandardPage,
1349 : pNotesPage,
1350 0 : nInsertPosition);
1351 : }
1352 :
1353 :
1354 :
1355 :
1356 0 : sal_uInt16 SdDrawDocument::InsertPageSet (
1357 : SdPage* pActualPage,
1358 : PageKind ePageKind,
1359 : const OUString& sStandardPageName,
1360 : const OUString& sNotesPageName,
1361 : sal_Bool bIsPageBack,
1362 : sal_Bool bIsPageObj,
1363 : SdPage* pStandardPage,
1364 : SdPage* pNotesPage,
1365 : sal_Int32 nInsertPosition)
1366 : {
1367 : SdPage* pPreviousStandardPage;
1368 : SdPage* pPreviousNotesPage;
1369 : sal_uInt16 nStandardPageNum;
1370 : sal_uInt16 nNotesPageNum;
1371 0 : OUString aStandardPageName(sStandardPageName);
1372 0 : OUString aNotesPageName(sNotesPageName);
1373 :
1374 : // Gather some information about the standard page and the notes page
1375 : // that are to be inserted. This makes sure that there is always one
1376 : // standard page followed by one notes page.
1377 0 : if (ePageKind == PK_NOTES)
1378 : {
1379 0 : pPreviousNotesPage = pActualPage;
1380 0 : nNotesPageNum = pPreviousNotesPage->GetPageNum() + 2;
1381 0 : pPreviousStandardPage = (SdPage*) GetPage(nNotesPageNum - 3);
1382 0 : nStandardPageNum = nNotesPageNum - 1;
1383 : }
1384 : else
1385 : {
1386 0 : pPreviousStandardPage = pActualPage;
1387 0 : nStandardPageNum = pPreviousStandardPage->GetPageNum() + 2;
1388 0 : pPreviousNotesPage = (SdPage*) GetPage(nStandardPageNum - 1);
1389 0 : nNotesPageNum = nStandardPageNum + 1;
1390 0 : aNotesPageName = aStandardPageName;
1391 : }
1392 :
1393 : OSL_ASSERT(nNotesPageNum==nStandardPageNum+1);
1394 0 : if (nInsertPosition < 0)
1395 0 : nInsertPosition = nStandardPageNum;
1396 :
1397 : // Set up and insert the standard page
1398 : SetupNewPage (
1399 : pPreviousStandardPage,
1400 : pStandardPage,
1401 : aStandardPageName,
1402 : nInsertPosition,
1403 : bIsPageBack,
1404 0 : bIsPageObj);
1405 :
1406 : // Set up and insert the notes page
1407 0 : pNotesPage->SetPageKind(PK_NOTES);
1408 : SetupNewPage (
1409 : pPreviousNotesPage,
1410 : pNotesPage,
1411 : aNotesPageName,
1412 : nInsertPosition+1,
1413 : bIsPageBack,
1414 0 : bIsPageObj);
1415 :
1416 : // Return an index that allows the caller to access the newly inserted
1417 : // pages by using GetSdPage()
1418 0 : return pStandardPage->GetPageNum() / 2;
1419 : }
1420 :
1421 :
1422 :
1423 :
1424 0 : void SdDrawDocument::SetupNewPage (
1425 : SdPage* pPreviousPage,
1426 : SdPage* pPage,
1427 : const OUString& sPageName,
1428 : sal_uInt16 nInsertionPoint,
1429 : sal_Bool bIsPageBack,
1430 : sal_Bool bIsPageObj)
1431 : {
1432 0 : if (pPreviousPage != NULL)
1433 : {
1434 0 : pPage->SetSize( pPreviousPage->GetSize() );
1435 0 : pPage->SetBorder( pPreviousPage->GetLftBorder(),
1436 0 : pPreviousPage->GetUppBorder(),
1437 0 : pPreviousPage->GetRgtBorder(),
1438 0 : pPreviousPage->GetLwrBorder() );
1439 : }
1440 0 : pPage->SetName(sPageName);
1441 :
1442 0 : InsertPage(pPage, nInsertionPoint);
1443 :
1444 0 : if (pPreviousPage != NULL)
1445 : {
1446 0 : SdrLayerAdmin& rLayerAdmin = GetLayerAdmin();
1447 0 : sal_uInt8 aBckgrnd = rLayerAdmin.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRND), false);
1448 0 : sal_uInt8 aBckgrndObj = rLayerAdmin.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRNDOBJ), false);
1449 0 : SetOfByte aVisibleLayers = pPreviousPage->TRG_GetMasterPageVisibleLayers();
1450 0 : aVisibleLayers.Set(aBckgrnd, bIsPageBack);
1451 0 : aVisibleLayers.Set(aBckgrndObj, bIsPageObj);
1452 0 : pPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
1453 : }
1454 0 : }
1455 :
1456 0 : sd::UndoManager* SdDrawDocument::GetUndoManager() const
1457 : {
1458 0 : return mpDocSh ? dynamic_cast< sd::UndoManager* >(mpDocSh->GetUndoManager()) : 0;
1459 : }
1460 :
1461 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|