xref: /trunk/main/sd/source/core/sdpage.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include <algorithm>
32 
33 #include <comphelper/classids.hxx>
34 
35 #include <vcl/svapp.hxx>
36 #include "eetext.hxx"
37 #include <editeng/eeitem.hxx>
38 #include <svx/svdoutl.hxx>
39 #include <editeng/editdata.hxx>
40 #include <svx/pageitem.hxx>
41 #include <editeng/lrspitem.hxx>
42 #include <editeng/bulitem.hxx>
43 #include <svx/svdpagv.hxx>
44 #include <editeng/fhgtitem.hxx>
45 #include <editeng/outlobj.hxx>
46 #include <svx/svdoole2.hxx>
47 #include <svx/svdograf.hxx>
48 #include <svx/svdopage.hxx>
49 #include <svx/svdopage.hxx>
50 #include <sfx2/printer.hxx>
51 #include <basic/basmgr.hxx>
52 #include <editeng/pbinitem.hxx>
53 #include <svx/svdundo.hxx>
54 #include <svl/smplhint.hxx>
55 #include <editeng/adjitem.hxx>
56 #include <editeng/editobj.hxx>
57 #ifndef _SVX_SRIPTTYPEITEM_HXX
58 #include <editeng/scripttypeitem.hxx>
59 #endif
60 #include <svx/unopage.hxx>
61 #include <editeng/flditem.hxx>
62 #include <svx/sdr/contact/displayinfo.hxx>
63 #include <svx/svditer.hxx>
64 
65 #include <editeng/adjitem.hxx>
66 
67 #include "../ui/inc/DrawDocShell.hxx"
68 #include "Outliner.hxx"
69 #include "app.hrc"
70 #include "misc.hxx"
71 #include "eetext.hxx"
72 #include "drawdoc.hxx"
73 #include "sdpage.hxx"
74 #include "pglink.hxx"
75 #include "sdresid.hxx"
76 #include "stlsheet.hxx"
77 #include "glob.hrc"
78 #include "glob.hxx"
79 #include "helpids.h"
80 #include "anminfo.hxx"
81 #include "undo/undomanager.hxx"
82 #include "undo/undoobjects.hxx"
83 #include <svx/sdr/contact/displayinfo.hxx>
84 #include <svx/sdr/contact/viewobjectcontact.hxx>
85 #include <svx/sdr/contact/viewcontact.hxx>
86 #include <svx/sdr/contact/objectcontact.hxx>
87 #include <svx/unoapi.hxx>
88 
89 #include <set>
90 
91 using namespace ::sd;
92 using namespace ::com::sun::star;
93 
94 TYPEINIT2( SdPage, FmFormPage, SdrObjUserCall );
95 
96 /*************************************************************************
97 |*
98 |*      Ctor
99 |*
100 \************************************************************************/
101 
102 SdPage::SdPage(SdDrawDocument& rNewDoc, StarBASIC* pBasic, sal_Bool bMasterPage)
103 :   FmFormPage(rNewDoc, pBasic, bMasterPage)
104 ,   SdrObjUserCall()
105 ,   mePageKind(PK_STANDARD)
106 ,   meAutoLayout(AUTOLAYOUT_NONE)
107 ,   mbSelected(sal_False)
108 ,   mePresChange(PRESCHANGE_MANUAL)
109 ,   mnTime(1)
110 ,   mbSoundOn(sal_False)
111 ,   mbExcluded(sal_False)
112 ,   mbLoopSound(sal_False)
113 ,   mbStopSound(sal_False)
114 ,   mbScaleObjects(sal_True)
115 ,   mbBackgroundFullSize( sal_False )
116 ,   meCharSet(gsl_getSystemTextEncoding())
117 ,   mnPaperBin(PAPERBIN_PRINTER_SETTINGS)
118 ,   mpPageLink(NULL)
119 ,   mpItems(NULL)
120 ,   mnTransitionType(0)
121 ,   mnTransitionSubtype(0)
122 ,   mbTransitionDirection(sal_True)
123 ,   mnTransitionFadeColor(0)
124 ,   mfTransitionDuration(2.0)
125 ,   mbIsPrecious(true)
126 {
127     // Der Layoutname der Seite wird von SVDRAW benutzt, um die Praesentations-
128     // vorlagen der Gliederungsobjekte zu ermitteln. Darum enthaelt er bereits
129     // den Bezeichner fuer die Gliederung (STR_LAYOUT_OUTLINE).
130     maLayoutName  = String(SdResId(STR_LAYOUT_DEFAULT_NAME));
131     maLayoutName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( SD_LT_SEPARATOR ));
132     maLayoutName += String(SdResId(STR_LAYOUT_OUTLINE));
133 
134     Size aPageSize(GetSize());
135 
136     if (aPageSize.Width() > aPageSize.Height())
137     {
138         meOrientation = ORIENTATION_LANDSCAPE;
139     }
140     else
141     {
142         meOrientation = ORIENTATION_PORTRAIT;
143     }
144 }
145 
146 /*************************************************************************
147 |*
148 |* Dtor
149 |*
150 \************************************************************************/
151 
152 SdPage::~SdPage()
153 {
154     DisconnectLink();
155 
156     EndListenOutlineText();
157 
158     if( mpItems )
159         delete mpItems;
160 }
161 
162 struct OrdNumSorter
163 {
164     bool operator()( SdrObject* p1, SdrObject* p2 )
165     {
166         return p1->GetOrdNum() < p2->GetOrdNum();
167     }
168 };
169 
170 /** returns the nIndex'th object from the given PresObjKind, index starts with 1 */
171 SdrObject* SdPage::GetPresObj(PresObjKind eObjKind, int nIndex, bool bFuzzySearch /* = false */ )
172 {
173     // first sort all matching shapes with z-order
174     std::vector< SdrObject* > aMatches;
175 
176     SdrObject* pObj = 0;
177     while( (pObj = maPresentationShapeList.getNextShape(pObj)) != 0 )
178     {
179         SdAnimationInfo* pInfo = SdDrawDocument::GetShapeUserData(*pObj);
180         if( pInfo )
181         {
182             bool bFound = false;
183             if( pInfo->mePresObjKind == eObjKind )
184             {
185                 bFound = true;
186             }
187             else if( bFuzzySearch && (eObjKind == PRESOBJ_OUTLINE) )
188             {
189                 switch( pInfo->mePresObjKind )
190                 {
191                 case PRESOBJ_GRAPHIC:
192                 case PRESOBJ_OBJECT:
193                 case PRESOBJ_CHART:
194                 case PRESOBJ_ORGCHART:
195                 case PRESOBJ_TABLE:
196                 case PRESOBJ_CALC:
197                 case PRESOBJ_IMAGE:
198                 case PRESOBJ_MEDIA:
199                     bFound = sal_True;
200                     break;
201                 default:
202                     break;
203                 }
204             }
205             if( bFound )
206             {
207                 aMatches.push_back( pObj );
208             }
209         }
210     }
211 
212     if( aMatches.size() > 1 )
213     {
214         OrdNumSorter aSortHelper;
215         std::sort( aMatches.begin(), aMatches.end(), aSortHelper );
216     }
217 
218     if( nIndex > 0 )
219         nIndex--;
220 
221     if( (nIndex >= 0) && ( aMatches.size() > static_cast<unsigned int>(nIndex)) )
222         return aMatches[nIndex];
223 
224     return 0;
225 }
226 
227 /** create background properties */
228 void SdPage::EnsureMasterPageDefaultBackground()
229 {
230     if(mbMaster)
231     {
232         // no hard attributes on MasterPage attributes
233         getSdrPageProperties().ClearItem();
234         SfxStyleSheet* pSheetForPresObj = GetStyleSheetForMasterPageBackground();
235 
236         if(pSheetForPresObj)
237         {
238             // set StyleSheet for background fill attributes
239             getSdrPageProperties().SetStyleSheet(pSheetForPresObj);
240         }
241         else
242         {
243             // no style found, assert and set at least XFILL_NONE
244             OSL_ENSURE(false, "No Style for MasterPageBackground fill found (!)");
245             getSdrPageProperties().PutItem(XFillStyleItem(XFILL_NONE));
246         }
247     }
248 }
249 
250 /** creates a presentation object with the given PresObjKind on this page. A user call will be set
251 */
252 SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, sal_Bool bVertical, const Rectangle& rRect, sal_Bool /* bInsert */ )
253 {
254     ::svl::IUndoManager* pUndoManager = pModel ? static_cast<SdDrawDocument*>(pModel)->GetUndoManager() : 0;
255     const bool bUndo = pUndoManager && pUndoManager->IsInListAction() && IsInserted();
256 
257     SdrObject* pSdrObj = NULL;
258 
259     bool bForceText = false;    // forces the shape text to be set even if its empty
260     bool bEmptyPresObj = true;
261 
262     switch( eObjKind )
263     {
264         case PRESOBJ_TITLE:
265         {
266             pSdrObj = new SdrRectObj(OBJ_TITLETEXT);
267 
268             if (mbMaster)
269             {
270                 pSdrObj->SetNotVisibleAsMaster(sal_True);
271             }
272         }
273         break;
274 
275         case PRESOBJ_OUTLINE:
276         {
277             pSdrObj = new SdrRectObj(OBJ_OUTLINETEXT);
278 
279             if (mbMaster)
280             {
281                 pSdrObj->SetNotVisibleAsMaster(sal_True);
282             }
283         }
284         break;
285 
286         case PRESOBJ_NOTES:
287         {
288             pSdrObj = new SdrRectObj(OBJ_TEXT);
289 
290             if (mbMaster)
291             {
292                 pSdrObj->SetNotVisibleAsMaster(sal_True);
293             }
294         }
295         break;
296 
297         case PRESOBJ_TEXT:
298         {
299             pSdrObj = new SdrRectObj(OBJ_TEXT);
300         }
301         break;
302 
303         case PRESOBJ_GRAPHIC:
304         {
305             BitmapEx aBmpEx( SdResId( BMP_PRESOBJ_GRAPHIC ) );
306             Graphic  aGraphic( aBmpEx );
307             OutputDevice &aOutDev = *Application::GetDefaultDevice();
308             aOutDev.Push();
309 
310             aOutDev.SetMapMode( aGraphic.GetPrefMapMode() );
311             Size aSizePix = aOutDev.LogicToPixel( aGraphic.GetPrefSize() );
312             aOutDev.SetMapMode(MAP_100TH_MM);
313 
314             Size aSize = aOutDev.PixelToLogic(aSizePix);
315             Point aPnt (0, 0);
316             Rectangle aRect (aPnt, aSize);
317             pSdrObj = new SdrGrafObj(aGraphic, aRect);
318             aOutDev.Pop();
319         }
320         break;
321 
322         case PRESOBJ_MEDIA:
323         case PRESOBJ_OBJECT:
324         {
325             pSdrObj = new SdrOle2Obj();
326             BitmapEx aBmpEx( SdResId( BMP_PRESOBJ_OBJECT ) );
327             Graphic aGraphic( aBmpEx );
328             ( (SdrOle2Obj*) pSdrObj)->SetGraphic(&aGraphic);
329         }
330         break;
331 
332         case PRESOBJ_CHART:
333         {
334             pSdrObj = new SdrOle2Obj();
335             ( (SdrOle2Obj*) pSdrObj)->SetProgName( String( RTL_CONSTASCII_USTRINGPARAM( "StarChart" )));
336             BitmapEx aBmpEx( SdResId( BMP_PRESOBJ_CHART ) );
337             Graphic aGraphic( aBmpEx );
338             ( (SdrOle2Obj*) pSdrObj)->SetGraphic(&aGraphic);
339         }
340         break;
341 
342         case PRESOBJ_ORGCHART:
343         {
344             pSdrObj = new SdrOle2Obj();
345             ( (SdrOle2Obj*) pSdrObj)->SetProgName( String( RTL_CONSTASCII_USTRINGPARAM( "StarOrg" )));
346             BitmapEx aBmpEx( SdResId( BMP_PRESOBJ_ORGCHART ) );
347             Graphic aGraphic( aBmpEx );
348             ( (SdrOle2Obj*) pSdrObj)->SetGraphic(&aGraphic);
349         }
350 
351         case PRESOBJ_TABLE:
352         case PRESOBJ_CALC:
353         {
354             pSdrObj = new SdrOle2Obj();
355             ( (SdrOle2Obj*) pSdrObj)->SetProgName( String( RTL_CONSTASCII_USTRINGPARAM( "StarCalc" )));
356             BitmapEx aBmpEx( SdResId( BMP_PRESOBJ_TABLE ) );
357             Graphic aGraphic( aBmpEx );
358             ( (SdrOle2Obj*) pSdrObj)->SetGraphic(&aGraphic);
359         }
360         break;
361 
362         case PRESOBJ_HANDOUT:
363         {
364             //Erste Standardseite am SdrPageObj vermerken
365             // #i105146# We want no content to be displayed for PK_HANDOUT,
366             // so just never set a page as content
367             pSdrObj = new SdrPageObj(0);
368 //          pSdrObj->SetResizeProtect(sal_True);
369         }
370         break;
371 
372         case PRESOBJ_PAGE:
373         {
374             //Notizseite am SdrPageObj vermerken
375             sal_uInt16 nDestPageNum(GetPageNum());
376 
377             if(nDestPageNum)
378             {
379                 // decrement only when != 0, else we get a 0xffff
380                 nDestPageNum -= 1;
381             }
382 
383             if(nDestPageNum < pModel->GetPageCount())
384             {
385                 pSdrObj = new SdrPageObj(pModel->GetPage(nDestPageNum));
386             }
387             else
388             {
389                 pSdrObj = new SdrPageObj();
390             }
391 
392             pSdrObj->SetResizeProtect(sal_True);
393         }
394         break;
395 
396         case PRESOBJ_HEADER:
397         case PRESOBJ_FOOTER:
398         case PRESOBJ_DATETIME:
399         case PRESOBJ_SLIDENUMBER:
400         {
401             pSdrObj = new SdrRectObj(OBJ_TEXT);
402             bEmptyPresObj = false;
403             bForceText = true;
404         }
405         break;
406         default:
407             break;
408     }
409 
410     if (pSdrObj)
411     {
412         pSdrObj->SetEmptyPresObj(bEmptyPresObj);
413         pSdrObj->SetLogicRect(rRect);
414 
415         InsertObject(pSdrObj);
416 
417         if ( pSdrObj->ISA(SdrTextObj) )
418         {
419             // #96243# Tell the object EARLY that it is vertical to have the
420             // defaults for AutoGrowWidth/Height reversed
421             if(bVertical)
422                 ((SdrTextObj*)pSdrObj)->SetVerticalWriting(sal_True);
423 
424             SfxItemSet aTempAttr( ((SdDrawDocument*) pModel)->GetPool() );
425             if( bVertical )
426                 aTempAttr.Put( SdrTextMinFrameWidthItem( rRect.GetSize().Width() ) );
427             else
428                 aTempAttr.Put( SdrTextMinFrameHeightItem( rRect.GetSize().Height() ) );
429 
430             if (mbMaster)
431             {
432                 // Bei Praesentationsobjekten auf der MasterPage soll die
433                 // Groesse vom Benutzwer frei waehlbar sein
434 
435                 // #96243# potential problem: This action was still NOT
436                 // adapted for vertical text. This sure needs to be done.
437                 if(bVertical)
438                     aTempAttr.Put(SdrTextAutoGrowWidthItem(sal_False));
439                 else
440                     aTempAttr.Put(SdrTextAutoGrowHeightItem(sal_False));
441             }
442 
443             // check if we need another vertical adjustement than the default
444             SdrTextVertAdjust eV = SDRTEXTVERTADJUST_TOP;
445 
446             if( (eObjKind == PRESOBJ_FOOTER) && (mePageKind != PK_STANDARD) )
447             {
448                 eV = SDRTEXTVERTADJUST_BOTTOM;
449             }
450             else if( (eObjKind == PRESOBJ_SLIDENUMBER) && (mePageKind != PK_STANDARD) )
451             {
452                 eV = SDRTEXTVERTADJUST_BOTTOM;
453             }
454 
455             if( eV != SDRTEXTVERTADJUST_TOP )
456                 aTempAttr.Put(SdrTextVertAdjustItem(eV));
457 
458             pSdrObj->SetMergedItemSet(aTempAttr);
459 
460             pSdrObj->SetLogicRect(rRect);
461         }
462 
463         String aString = GetPresObjText(eObjKind);
464         if( (aString.Len() || bForceText) && pSdrObj->ISA(SdrTextObj) )
465         {
466             SdrOutliner* pOutliner = ( (SdDrawDocument*) GetModel() )->GetInternalOutliner();
467 
468             sal_uInt16 nOutlMode = pOutliner->GetMode();
469             pOutliner->Init( OUTLINERMODE_TEXTOBJECT );
470             pOutliner->SetStyleSheet( 0, NULL );
471             pOutliner->SetVertical( bVertical );
472 
473             String aEmptyStr;
474             SetObjText( (SdrTextObj*) pSdrObj, (SdrOutliner*)pOutliner, eObjKind, aString );
475 
476             pOutliner->Init( nOutlMode );
477             pOutliner->SetStyleSheet( 0, NULL );
478         }
479 
480         if( (eObjKind == PRESOBJ_HEADER) || (eObjKind == PRESOBJ_FOOTER) || (eObjKind == PRESOBJ_SLIDENUMBER) || (eObjKind == PRESOBJ_DATETIME) )
481         {
482             SfxItemSet aTempAttr( ((SdDrawDocument*) pModel)->GetPool() );
483             aTempAttr.Put( SvxFontHeightItem( 493, 100, EE_CHAR_FONTHEIGHT ) );
484             aTempAttr.Put( SvxFontHeightItem( 493, 100, EE_CHAR_FONTHEIGHT_CTL ) );
485             aTempAttr.Put( SvxFontHeightItem( 493, 100, EE_CHAR_FONTHEIGHT_CJK ) );
486 
487             SvxAdjust eH = SVX_ADJUST_LEFT;
488 
489             if( (eObjKind == PRESOBJ_DATETIME) && (mePageKind != PK_STANDARD ) )
490             {
491                 eH = SVX_ADJUST_RIGHT;
492             }
493             else if( (eObjKind == PRESOBJ_FOOTER) && (mePageKind == PK_STANDARD ) )
494             {
495                 eH = SVX_ADJUST_CENTER;
496             }
497             else if( eObjKind == PRESOBJ_SLIDENUMBER )
498             {
499                 eH = SVX_ADJUST_RIGHT;
500             }
501 
502             if( eH != SVX_ADJUST_LEFT )
503                 aTempAttr.Put(SvxAdjustItem(eH, EE_PARA_JUST ));
504 
505             pSdrObj->SetMergedItemSet(aTempAttr);
506         }
507 
508         if (mbMaster)
509         {
510             SdrLayerAdmin& rLayerAdmin = pModel->GetLayerAdmin();
511 
512             // Hintergrundobjekte der MasterPage
513             pSdrObj->SetLayer( rLayerAdmin.
514                 GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ)), sal_False) );
515         }
516 
517         // Objekt am StyleSheet anmelden
518         // #95114# Set style only when one was found (as in 5.2)
519         // pSdrObj->NbcSetStyleSheet( GetStyleSheetForPresObj(eObjKind), sal_False );
520         if( mePageKind != PK_HANDOUT )
521         {
522             SfxStyleSheet* pSheetForPresObj = GetStyleSheetForPresObj(eObjKind);
523             if(pSheetForPresObj)
524                 pSdrObj->SetStyleSheet(pSheetForPresObj, sal_False);
525         }
526 
527         if (eObjKind == PRESOBJ_OUTLINE)
528         {
529             for (sal_uInt16 nLevel = 1; nLevel < 10; nLevel++)
530             {
531                 String aName(maLayoutName);
532                 aName += sal_Unicode( ' ' );
533                 aName += String::CreateFromInt32( nLevel );
534                 SfxStyleSheet* pSheet = (SfxStyleSheet*)pModel->GetStyleSheetPool()->Find(aName, SD_STYLE_FAMILY_MASTERPAGE);
535                 DBG_ASSERT(pSheet, "Vorlage fuer Gliederungsobjekt nicht gefunden");
536                 if (pSheet)
537                     pSdrObj->StartListening(*pSheet);
538             }
539         }
540 
541         if ( eObjKind == PRESOBJ_OBJECT   ||
542              eObjKind == PRESOBJ_CHART    ||
543              eObjKind == PRESOBJ_ORGCHART ||
544              eObjKind == PRESOBJ_CALC    ||
545              eObjKind == PRESOBJ_GRAPHIC )
546         {
547             SfxItemSet aSet( ((SdDrawDocument*) pModel)->GetPool() );
548             aSet.Put( SdrTextContourFrameItem( sal_True ) );
549             aSet.Put( SvxAdjustItem( SVX_ADJUST_CENTER, EE_PARA_JUST ) );
550 
551             pSdrObj->SetMergedItemSet(aSet);
552         }
553 
554         if( bUndo )
555         {
556             pUndoManager->AddUndoAction(pModel->GetSdrUndoFactory().CreateUndoNewObject(*pSdrObj));
557         }
558 
559         if( bUndo )
560         {
561             pUndoManager->AddUndoAction( new UndoObjectPresentationKind( *pSdrObj ) );
562             pUndoManager->AddUndoAction( new UndoObjectUserCall(*pSdrObj) );
563         }
564 
565         InsertPresObj(pSdrObj, eObjKind);
566         pSdrObj->SetUserCall(this);
567 
568         pSdrObj->RecalcBoundRect();
569     }
570 
571     return(pSdrObj);
572 }
573 
574 /*************************************************************************
575 |*
576 |* Es werden Praesentationsobjekte auf der Page erzeugt.
577 |* Alle Praesentationsobjekte erhalten einen UserCall auf die Page.
578 |*
579 \************************************************************************/
580 
581 SfxStyleSheet* SdPage::GetStyleSheetForMasterPageBackground() const
582 {
583     String aName(GetLayoutName());
584     String aSep( RTL_CONSTASCII_USTRINGPARAM( SD_LT_SEPARATOR ));
585     sal_uInt16 nPos = aName.Search(aSep);
586 
587     if (nPos != STRING_NOTFOUND)
588     {
589         nPos = nPos + aSep.Len();
590         aName.Erase(nPos);
591     }
592 
593     aName += String(SdResId(STR_LAYOUT_BACKGROUND));
594 
595     SfxStyleSheetBasePool* pStShPool = pModel->GetStyleSheetPool();
596     SfxStyleSheetBase*     pResult   = pStShPool->Find(aName, SD_STYLE_FAMILY_MASTERPAGE);
597     return (SfxStyleSheet*)pResult;
598 }
599 
600 SfxStyleSheet* SdPage::GetStyleSheetForPresObj(PresObjKind eObjKind) const
601 {
602     String aName(GetLayoutName());
603     String aSep( RTL_CONSTASCII_USTRINGPARAM( SD_LT_SEPARATOR ));
604     sal_uInt16 nPos = aName.Search(aSep);
605     if (nPos != STRING_NOTFOUND)
606     {
607         nPos = nPos + aSep.Len();
608         aName.Erase(nPos);
609     }
610 
611     switch (eObjKind)
612     {
613         case PRESOBJ_OUTLINE:
614         {
615             aName = GetLayoutName();
616             aName += sal_Unicode( ' ' );
617             aName += String::CreateFromInt32( 1 );
618         }
619         break;
620 
621         case PRESOBJ_TITLE:
622             aName += String(SdResId(STR_LAYOUT_TITLE));
623             break;
624 
625         case PRESOBJ_NOTES:
626             aName += String(SdResId(STR_LAYOUT_NOTES));
627             break;
628 
629         case PRESOBJ_TEXT:
630             aName += String(SdResId(STR_LAYOUT_SUBTITLE));
631             break;
632 
633         case PRESOBJ_HEADER:
634         case PRESOBJ_FOOTER:
635         case PRESOBJ_DATETIME:
636         case PRESOBJ_SLIDENUMBER:
637             aName += String(SdResId(STR_LAYOUT_BACKGROUNDOBJECTS));
638             break;
639 
640         default:
641             break;
642     }
643 
644     SfxStyleSheetBasePool* pStShPool = pModel->GetStyleSheetPool();
645     SfxStyleSheetBase*     pResult   = pStShPool->Find(aName, SD_STYLE_FAMILY_MASTERPAGE);
646     return (SfxStyleSheet*)pResult;
647 }
648 
649 /** returns the presentation style with the given helpid from this masterpage or this
650     slides masterpage */
651 SdStyleSheet* SdPage::getPresentationStyle( sal_uInt32 nHelpId ) const
652 {
653     String aStyleName( pPage->GetLayoutName() );
654     const String aSep( RTL_CONSTASCII_USTRINGPARAM( SD_LT_SEPARATOR ));
655     aStyleName.Erase(aStyleName.Search(aSep) + aSep.Len());
656 
657     sal_uInt16 nNameId;
658     switch( nHelpId )
659     {
660     case HID_PSEUDOSHEET_TITLE:             nNameId = STR_LAYOUT_TITLE;             break;
661     case HID_PSEUDOSHEET_SUBTITLE:          nNameId = STR_LAYOUT_SUBTITLE;          break;
662     case HID_PSEUDOSHEET_OUTLINE1:
663     case HID_PSEUDOSHEET_OUTLINE2:
664     case HID_PSEUDOSHEET_OUTLINE3:
665     case HID_PSEUDOSHEET_OUTLINE4:
666     case HID_PSEUDOSHEET_OUTLINE5:
667     case HID_PSEUDOSHEET_OUTLINE6:
668     case HID_PSEUDOSHEET_OUTLINE7:
669     case HID_PSEUDOSHEET_OUTLINE8:
670     case HID_PSEUDOSHEET_OUTLINE9:          nNameId = STR_LAYOUT_OUTLINE;           break;
671     case HID_PSEUDOSHEET_BACKGROUNDOBJECTS: nNameId = STR_LAYOUT_BACKGROUNDOBJECTS; break;
672     case HID_PSEUDOSHEET_BACKGROUND:        nNameId = STR_LAYOUT_BACKGROUND;        break;
673     case HID_PSEUDOSHEET_NOTES:             nNameId = STR_LAYOUT_NOTES;             break;
674 
675     default:
676         DBG_ERROR( "SdPage::getPresentationStyle(), illegal argument!" );
677         return 0;
678     }
679     aStyleName.Append( String( SdResId( nNameId ) ) );
680     if( nNameId == STR_LAYOUT_OUTLINE )
681     {
682         aStyleName.Append( sal_Unicode( ' ' ));
683         aStyleName.Append( String::CreateFromInt32( sal_Int32( nHelpId - HID_PSEUDOSHEET_OUTLINE )));
684     }
685 
686     SfxStyleSheetBasePool* pStShPool = pModel->GetStyleSheetPool();
687     SfxStyleSheetBase*     pResult   = pStShPool->Find(aStyleName, SD_STYLE_FAMILY_MASTERPAGE);
688     return dynamic_cast<SdStyleSheet*>(pResult);
689 }
690 
691 /*************************************************************************
692 |*
693 |* Das Praesentationsobjekt rObj hat sich geaendert und wird nicht mehr
694 |* durch das Praesentationsobjekt der MasterPage referenziert.
695 |* Der UserCall wird geloescht.
696 |*
697 \************************************************************************/
698 
699 void SdPage::Changed(const SdrObject& rObj, SdrUserCallType eType, const Rectangle& )
700 {
701     if (!maLockAutoLayoutArrangement.isLocked())
702     {
703         switch (eType)
704         {
705             case SDRUSERCALL_MOVEONLY:
706             case SDRUSERCALL_RESIZE:
707             {
708                 if( pModel->isLocked() )
709                     break;
710 
711                 SdrObject* pObj = (SdrObject*) &rObj;
712 
713                 if (pObj)
714                 {
715                     if (!mbMaster)
716                     {
717                         if( pObj->GetUserCall() )
718                         {
719                             ::svl::IUndoManager* pUndoManager = pModel ? static_cast<SdDrawDocument*>(pModel)->GetUndoManager() : 0;
720                             const bool bUndo = pUndoManager && pUndoManager->IsInListAction() && IsInserted();
721 /*
722                             DBG_ASSERT( bUndo || (pUndoManager && pUndoManager->IsDoing()),
723                                             "SdPage::Changed(), model change without undo!?" );
724 */
725                             if( bUndo )
726                                 pUndoManager->AddUndoAction( new UndoObjectUserCall(*pObj) );
727 
728                             // Objekt was resized by user and does not listen to its slide anymore
729                             pObj->SetUserCall(0);
730                         }
731                     }
732                     else if (pModel)
733                     {
734                         // MasterPage-Objekt wurde veraendert, daher
735                         // Objekte auf allen Seiten anpassen
736                         sal_uInt16 nPageCount = ((SdDrawDocument*) pModel)->GetSdPageCount(mePageKind);
737 
738                         for (sal_uInt16 i = 0; i < nPageCount; i++)
739                         {
740                             SdPage* pLoopPage = ((SdDrawDocument*) pModel)->GetSdPage(i, mePageKind);
741 
742                             if (pLoopPage && this == &(pLoopPage->TRG_GetMasterPage()))
743                             {
744                                 // Seite hoert auf diese MasterPage, daher
745                                 // AutoLayout anpassen
746                                 pLoopPage->SetAutoLayout(pLoopPage->GetAutoLayout());
747                             }
748                         }
749                     }
750                 }
751             }
752             break;
753 
754             case SDRUSERCALL_DELETE:
755             case SDRUSERCALL_REMOVED:
756             default:
757                 break;
758         }
759     }
760 }
761 
762 /*************************************************************************
763 |*
764 |* Erzeugt auf einer MasterPage Hintergrund, Titel- und Layout-Bereich
765 |*
766 \************************************************************************/
767 
768 void SdPage::CreateTitleAndLayout(sal_Bool bInit, sal_Bool bCreate )
769 {
770     ::svl::IUndoManager* pUndoManager = pModel ? static_cast<SdDrawDocument*>(pModel)->GetUndoManager() : 0;
771     const bool bUndo = pUndoManager && pUndoManager->IsInListAction() && IsInserted();
772 
773     SdPage* pMasterPage = this;
774 
775     if (!mbMaster)
776     {
777         pMasterPage = (SdPage*)(&(TRG_GetMasterPage()));
778     }
779 
780     if (!pMasterPage)
781     {
782         return;
783     }
784 
785     /**************************************************************************
786     * Hintergrund, Titel- und Layout-Bereich werden angelegt
787     **************************************************************************/
788     if( mePageKind == PK_STANDARD )
789     {
790         pMasterPage->EnsureMasterPageDefaultBackground();
791     }
792 
793     if( ( (SdDrawDocument*) GetModel() )->GetDocumentType() == DOCUMENT_TYPE_IMPRESS )
794     {
795         if( mePageKind == PK_HANDOUT && bInit )
796         {
797             // handout template
798 
799             // delete all available handout presentation objects
800             SdrObject* pObj;
801             while( (pObj = pMasterPage->GetPresObj(PRESOBJ_HANDOUT)) != 0 )
802             {
803                 if( bUndo )
804                     pUndoManager->AddUndoAction(pModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pObj));
805 
806                 pMasterPage->RemoveObject(pObj->GetOrdNum());
807             }
808 
809             std::vector< Rectangle > aAreas;
810             CalculateHandoutAreas( *static_cast< SdDrawDocument* >(GetModel() ), pMasterPage->GetAutoLayout(), false, aAreas );
811 
812             const bool bSkip = pMasterPage->GetAutoLayout() == AUTOLAYOUT_HANDOUT3;
813             std::vector< Rectangle >::iterator iter( aAreas.begin() );
814 
815             while( iter != aAreas.end() )
816             {
817                 SdrPageObj* pPageObj = static_cast<SdrPageObj*>(pMasterPage->CreatePresObj(PRESOBJ_HANDOUT, sal_False, (*iter++), sal_True) );
818                 // #i105146# We want no content to be displayed for PK_HANDOUT,
819                 // so just never set a page as content
820                 pPageObj->SetReferencedPage(0L);
821 
822                 if( bSkip && iter != aAreas.end() )
823                     iter++;
824             }
825         }
826 
827         if( mePageKind != PK_HANDOUT )
828         {
829             SdrObject* pMasterTitle = pMasterPage->GetPresObj( PRESOBJ_TITLE );
830             if( pMasterTitle == NULL )
831                 pMasterPage->CreateDefaultPresObj(PRESOBJ_TITLE, true);
832 
833             SdrObject* pMasterOutline = pMasterPage->GetPresObj( mePageKind==PK_NOTES ? PRESOBJ_NOTES : PRESOBJ_OUTLINE );
834             if( pMasterOutline == NULL )
835                 pMasterPage->CreateDefaultPresObj( mePageKind == PK_STANDARD ? PRESOBJ_OUTLINE : PRESOBJ_NOTES, true );
836         }
837 
838         // create header&footer objects
839 
840         if( bCreate )
841         {
842             if( mePageKind != PK_STANDARD )
843             {
844                 SdrObject* pHeader = pMasterPage->GetPresObj( PRESOBJ_HEADER );
845                 if( pHeader == NULL )
846                     pMasterPage->CreateDefaultPresObj( PRESOBJ_HEADER, true );
847             }
848 
849             SdrObject* pDate   = pMasterPage->GetPresObj( PRESOBJ_DATETIME );
850             if( pDate == NULL )
851                 pMasterPage->CreateDefaultPresObj( PRESOBJ_DATETIME, true );
852 
853             SdrObject* pFooter = pMasterPage->GetPresObj( PRESOBJ_FOOTER );
854             if( pFooter == NULL )
855                 pMasterPage->CreateDefaultPresObj( PRESOBJ_FOOTER, true );
856 
857             SdrObject* pNumber = pMasterPage->GetPresObj( PRESOBJ_SLIDENUMBER );
858             if( pNumber == NULL )
859                 pMasterPage->CreateDefaultPresObj( PRESOBJ_SLIDENUMBER, true );
860         }
861     }
862 }
863 
864 SdrObject* SdPage::CreateDefaultPresObj(PresObjKind eObjKind, bool bInsert)
865 {
866     if( eObjKind == PRESOBJ_TITLE )
867     {
868         Rectangle aTitleRect( GetTitleRect() );
869         return CreatePresObj(PRESOBJ_TITLE, sal_False, aTitleRect, bInsert);
870     }
871     else if( eObjKind == PRESOBJ_OUTLINE )
872     {
873         Rectangle aLayoutRect( GetLayoutRect() );
874         return CreatePresObj( PRESOBJ_OUTLINE, sal_False, aLayoutRect, bInsert);
875     }
876     else if( eObjKind == PRESOBJ_NOTES )
877     {
878         Rectangle aLayoutRect( GetLayoutRect() );
879         return CreatePresObj( PRESOBJ_NOTES, sal_False, aLayoutRect, bInsert);
880     }
881     else if( (eObjKind == PRESOBJ_FOOTER) || (eObjKind == PRESOBJ_DATETIME) || (eObjKind == PRESOBJ_SLIDENUMBER) || (eObjKind == PRESOBJ_HEADER ) )
882     {
883         // create footer objects for standard master page
884         if( mePageKind == PK_STANDARD )
885         {
886             const long nLftBorder = GetLftBorder();
887             const long nUppBorder = GetUppBorder();
888 
889             Point aTitlePos ( nLftBorder, nUppBorder );
890             Size aPageSize ( GetSize() );
891             aPageSize.Width()  -= nLftBorder + GetRgtBorder();
892             aPageSize.Height() -= nUppBorder + GetLwrBorder();
893 
894             const int Y = long(nUppBorder + aPageSize.Height() * 0.911);
895             const int W1 = long(aPageSize.Width() * 0.233);
896             const int W2 = long(aPageSize.Width() * 0.317);
897             const int H = long(aPageSize.Height() * 0.069);
898 
899             if( eObjKind == PRESOBJ_DATETIME )
900             {
901                 Point aPos( long(nLftBorder+(aPageSize.Width()*0.05)), Y );
902                 Size aSize( W1, H );
903                 Rectangle aRect( aPos, aSize );
904                 return CreatePresObj( PRESOBJ_DATETIME, sal_False, aRect, bInsert );
905             }
906             else if( eObjKind == PRESOBJ_FOOTER )
907             {
908                 Point aPos( long(nLftBorder+ aPageSize.Width() * 0.342), Y );
909                 Size aSize( W2, H );
910                 Rectangle aRect( aPos, aSize );
911                 return CreatePresObj( PRESOBJ_FOOTER, sal_False, aRect, bInsert );
912             }
913             else if( eObjKind == PRESOBJ_SLIDENUMBER )
914             {
915                 Point aPos( long(nLftBorder+(aPageSize.Width()*0.717)), Y );
916                 Size aSize( W1, H );
917                 Rectangle aRect( aPos, aSize );
918                 return CreatePresObj( PRESOBJ_SLIDENUMBER, sal_False, aRect, bInsert );
919             }
920             else
921             {
922                 DBG_ERROR( "SdPage::CreateDefaultPresObj() - can't create a header placeholder for a slide master" );
923                 return NULL;
924             }
925         }
926         else
927         {
928             // create header&footer objects for handout and notes master
929             Point aTitlePos ( GetLftBorder(), GetUppBorder() );
930             Size aPageSize ( GetSize() );
931             aPageSize.Width()  -= GetLftBorder() + GetRgtBorder();
932             aPageSize.Height() -= GetUppBorder() + GetLwrBorder();
933 
934 
935             const int NOTES_HEADER_FOOTER_WIDTH = long(aPageSize.Width() * 0.434);
936             const int NOTES_HEADER_FOOTER_HEIGHT = long(aPageSize.Height() * 0.05);
937 
938             Size aSize( NOTES_HEADER_FOOTER_WIDTH, NOTES_HEADER_FOOTER_HEIGHT );
939 
940             const int X1 = GetLftBorder();
941             const int X2 = GetLftBorder() + long(aPageSize.Width() - NOTES_HEADER_FOOTER_WIDTH);
942             const int Y1 = GetUppBorder();
943             const int Y2 = GetUppBorder() + long(aPageSize.Height() - NOTES_HEADER_FOOTER_HEIGHT );
944 
945             if( eObjKind == PRESOBJ_HEADER )
946             {
947                 Point aPos( X1, Y1 );
948                 Rectangle aRect( aPos, aSize );
949                 return CreatePresObj( PRESOBJ_HEADER, sal_False, aRect, bInsert );
950             }
951             else if( eObjKind == PRESOBJ_DATETIME )
952             {
953                 Point aPos( X2, Y1 );
954                 Rectangle aRect( aPos, aSize );
955                 return CreatePresObj( PRESOBJ_DATETIME, sal_False, aRect, bInsert );
956             }
957             else if( eObjKind == PRESOBJ_FOOTER )
958             {
959                 Point aPos( X1, Y2 );
960                 Rectangle aRect( aPos, aSize );
961                 return CreatePresObj( PRESOBJ_FOOTER, sal_False, aRect, bInsert );
962             }
963             else if( eObjKind == PRESOBJ_SLIDENUMBER )
964             {
965                 Point aPos( X2, Y2 );
966                 Rectangle aRect( aPos, aSize );
967                 return CreatePresObj( PRESOBJ_SLIDENUMBER, sal_False, aRect, bInsert );
968             }
969 
970             DBG_ERROR("SdPage::CreateDefaultPresObj() - this should not happen!");
971             return NULL;
972         }
973     }
974     else
975     {
976         DBG_ERROR("SdPage::CreateDefaultPresObj() - unknown PRESOBJ kind" );
977         return NULL;
978     }
979 }
980 
981 /*************************************************************************
982 |*
983 |* Titelbereich zurueckgeben
984 |*
985 \************************************************************************/
986 
987 Rectangle SdPage::GetTitleRect() const
988 {
989     Rectangle aTitleRect;
990 
991     if (mePageKind != PK_HANDOUT)
992     {
993         /******************************************************************
994         * Standard- oder Notiz-Seite: Titelbereich
995         ******************************************************************/
996         Point aTitlePos ( GetLftBorder(), GetUppBorder() );
997         Size aTitleSize ( GetSize() );
998         aTitleSize.Width()  -= GetLftBorder() + GetRgtBorder();
999         aTitleSize.Height() -= GetUppBorder() + GetLwrBorder();
1000 
1001         if (mePageKind == PK_STANDARD)
1002         {
1003             aTitlePos.X() += long( aTitleSize.Width() * 0.05 );
1004             aTitlePos.Y() += long( aTitleSize.Height() * 0.0399 );
1005             aTitleSize.Width() = long( aTitleSize.Width() * 0.9 );
1006             aTitleSize.Height() = long( aTitleSize.Height() * 0.167 );
1007         }
1008         else if (mePageKind == PK_NOTES)
1009         {
1010             Point aPos = aTitlePos;
1011             aPos.Y() += long( aTitleSize.Height() * 0.076 );
1012 
1013             // Hoehe beschraenken
1014             aTitleSize.Height() = (long) (aTitleSize.Height() * 0.375);
1015 
1016             Size aPartArea = aTitleSize;
1017             Size aSize;
1018             sal_uInt16 nDestPageNum(GetPageNum());
1019             SdrPage* pRefPage = 0L;
1020 
1021             if(nDestPageNum)
1022             {
1023                 // only decrement if != 0, else we get 0xffff
1024                 nDestPageNum -= 1;
1025             }
1026 
1027             if(nDestPageNum < pModel->GetPageCount())
1028             {
1029                 pRefPage = pModel->GetPage(nDestPageNum);
1030             }
1031 
1032             if ( pRefPage )
1033             {
1034                 // tatsaechliche Seitengroesse in das Handout-Rechteck skalieren
1035                 double fH = (double) aPartArea.Width()  / pRefPage->GetWdt();
1036                 double fV = (double) aPartArea.Height() / pRefPage->GetHgt();
1037 
1038                 if ( fH > fV )
1039                     fH = fV;
1040                 aSize.Width()  = (long) (fH * pRefPage->GetWdt());
1041                 aSize.Height() = (long) (fH * pRefPage->GetHgt());
1042 
1043                 aPos.X() += (aPartArea.Width() - aSize.Width()) / 2;
1044                 aPos.Y() += (aPartArea.Height()- aSize.Height())/ 2;
1045             }
1046 
1047             aTitlePos = aPos;
1048             aTitleSize = aSize;
1049         }
1050 
1051         aTitleRect.SetPos(aTitlePos);
1052         aTitleRect.SetSize(aTitleSize);
1053     }
1054 
1055     return aTitleRect;
1056 }
1057 
1058 
1059 /*************************************************************************
1060 |*
1061 |* Gliederungsbereich zurueckgeben
1062 |*
1063 \************************************************************************/
1064 
1065 Rectangle SdPage::GetLayoutRect() const
1066 {
1067     Rectangle aLayoutRect;
1068 
1069     if (mePageKind != PK_HANDOUT)
1070     {
1071         Point aLayoutPos ( GetLftBorder(), GetUppBorder() );
1072         Size aLayoutSize ( GetSize() );
1073         aLayoutSize.Width()  -= GetLftBorder() + GetRgtBorder();
1074         aLayoutSize.Height() -= GetUppBorder() + GetLwrBorder();
1075 
1076         if (mePageKind == PK_STANDARD)
1077         {
1078             aLayoutPos.X() += long( aLayoutSize.Width() * 0.05 );
1079             aLayoutPos.Y() += long( aLayoutSize.Height() * 0.234 );
1080             aLayoutSize.Width() = long( aLayoutSize.Width() * 0.9 );
1081             aLayoutSize.Height() = long( aLayoutSize.Height() * 0.66 );
1082             aLayoutRect.SetPos(aLayoutPos);
1083             aLayoutRect.SetSize(aLayoutSize);
1084         }
1085         else if (mePageKind == PK_NOTES)
1086         {
1087             aLayoutPos.X() += long( aLayoutSize.Width() * 0.1 );
1088             aLayoutPos.Y() += long( aLayoutSize.Height() * 0.475 );
1089             aLayoutSize.Width() = long( aLayoutSize.Width() * 0.8 );
1090             aLayoutSize.Height() = long( aLayoutSize.Height() * 0.45 );
1091             aLayoutRect.SetPos(aLayoutPos);
1092             aLayoutRect.SetSize(aLayoutSize);
1093         }
1094     }
1095 
1096     return aLayoutRect;
1097 }
1098 
1099 
1100 /**************************************************************************
1101 |*
1102 |* Diese Methode weist ein AutoLayout zu
1103 |*
1104 \*************************************************************************/
1105 
1106 const int MAX_PRESOBJS = 7; // maximum number of presentation objects per layout
1107 const int VERTICAL = 0x8000;
1108 
1109 struct LayoutDescriptor
1110 {
1111     int mnLayout;
1112     PresObjKind meKind[MAX_PRESOBJS];
1113     bool mbVertical[MAX_PRESOBJS];
1114 
1115     LayoutDescriptor( int nLayout, int k0 = 0, int k1 = 0, int k2 = 0, int k3 = 0, int k4 = 0, int k5 = 0, int k6 = 0 );
1116 };
1117 
1118 LayoutDescriptor::LayoutDescriptor( int nLayout, int k0, int k1, int k2, int k3, int k4, int k5, int k6 )
1119 : mnLayout( nLayout )
1120 {
1121     meKind[0] = static_cast<PresObjKind>(k0 & (~VERTICAL)); mbVertical[0] = (k0 & VERTICAL) == VERTICAL;
1122     meKind[1] = static_cast<PresObjKind>(k1 & (~VERTICAL)); mbVertical[1] = (k1 & VERTICAL) == VERTICAL;
1123     meKind[2] = static_cast<PresObjKind>(k2 & (~VERTICAL)); mbVertical[2] = (k2 & VERTICAL) == VERTICAL;
1124     meKind[3] = static_cast<PresObjKind>(k3 & (~VERTICAL)); mbVertical[3] = (k3 & VERTICAL) == VERTICAL;
1125     meKind[4] = static_cast<PresObjKind>(k4 & (~VERTICAL)); mbVertical[4] = (k4 & VERTICAL) == VERTICAL;
1126     meKind[5] = static_cast<PresObjKind>(k5 & (~VERTICAL)); mbVertical[5] = (k5 & VERTICAL) == VERTICAL;
1127     meKind[6] = static_cast<PresObjKind>(k6 & (~VERTICAL)); mbVertical[6] = (k6 & VERTICAL) == VERTICAL;
1128 }
1129 
1130 static const LayoutDescriptor& GetLayoutDescriptor( AutoLayout eLayout )
1131 {
1132     static LayoutDescriptor aLayouts[AUTOLAYOUT__END-AUTOLAYOUT__START] =
1133     {
1134         LayoutDescriptor( 0, PRESOBJ_TITLE, PRESOBJ_TEXT ),                                 // AUTOLAYOUT_TITLE
1135         LayoutDescriptor( 0, PRESOBJ_TITLE, PRESOBJ_OUTLINE ),                              // AUTOLAYOUT_ENUM
1136         LayoutDescriptor( 0, PRESOBJ_TITLE, PRESOBJ_OUTLINE ),                              // AUTOLAYOUT_CHART
1137         LayoutDescriptor( 1, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),             // AUTOLAYOUT_2TEXT
1138         LayoutDescriptor( 1, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),             // AUTOLAYOUT_TEXTCHART
1139         LayoutDescriptor( 0, PRESOBJ_TITLE, PRESOBJ_OUTLINE ),                              // AUTOLAYOUT_ORG
1140         LayoutDescriptor( 1, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),             // AUTOLAYOUT_TEXTCLbIP
1141         LayoutDescriptor( 1, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),             // AUTOLAYOUT_CHARTTEXT
1142         LayoutDescriptor( 0, PRESOBJ_TITLE, PRESOBJ_OUTLINE ),                              // AUTOLAYOUT_TAB
1143         LayoutDescriptor( 1, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),             // AUTOLAYOUT_CLIPTEXT
1144         LayoutDescriptor( 1, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),             // AUTOLAYOUT_TEXTOBJ
1145         LayoutDescriptor( 0, PRESOBJ_TITLE, PRESOBJ_OBJECT ),                               // AUTOLAYOUT_OBJ
1146         LayoutDescriptor( 2, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),    // AUTOLAYOUT_TEXT2OBJ
1147         LayoutDescriptor( 1, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),             // AUTOLAYOUT_TEXTOBJ
1148         LayoutDescriptor( 4, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),             // AUTOLAYOUT_OBJOVERTEXT
1149         LayoutDescriptor( 3, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),    // AUTOLAYOUT_2OBJTEXT
1150         LayoutDescriptor( 5, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),    // AUTOLAYOUT_2OBJOVERTEXT
1151         LayoutDescriptor( 4, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),             // AUTOLAYOUT_TEXTOVEROBJ
1152         LayoutDescriptor( 6, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE,                   // AUTOLAYOUT_4OBJ
1153             PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),
1154         LayoutDescriptor( 0, PRESOBJ_TITLE, PRESOBJ_NONE ),                                 // AUTOLAYOUT_ONLY_TITLE
1155         LayoutDescriptor( 0, PRESOBJ_NONE ),                                                // AUTOLAYOUT_NONE
1156         LayoutDescriptor( 0, PRESOBJ_PAGE, PRESOBJ_NOTES ),                                 // AUTOLAYOUT_NOTES
1157         LayoutDescriptor( 0 ),                                                              // AUTOLAYOUT_HANDOUT1
1158         LayoutDescriptor( 0 ),                                                              // AUTOLAYOUT_HANDOUT2
1159         LayoutDescriptor( 0 ),                                                              // AUTOLAYOUT_HANDOUT3
1160         LayoutDescriptor( 0 ),                                                              // AUTOLAYOUT_HANDOUT4
1161         LayoutDescriptor( 0 ),                                                              // AUTOLAYOUT_HANDOUT6
1162         LayoutDescriptor( 7, PRESOBJ_TITLE|VERTICAL, PRESOBJ_OUTLINE|VERTICAL, PRESOBJ_OUTLINE ),// AUTOLAYOUT_VERTICAL_TITLE_TEXT_CHART
1163         LayoutDescriptor( 8, PRESOBJ_TITLE|VERTICAL, PRESOBJ_OUTLINE|VERTICAL ),            // AUTOLAYOUT_VERTICAL_TITLE_VERTICAL_OUTLINE
1164         LayoutDescriptor( 0, PRESOBJ_TITLE, PRESOBJ_OUTLINE|VERTICAL ),                     // AUTOLAYOUT_TITLE_VERTICAL_OUTLINE
1165         LayoutDescriptor( 9, PRESOBJ_TITLE, PRESOBJ_OUTLINE|VERTICAL, PRESOBJ_OUTLINE|VERTICAL ),   // AUTOLAYOUT_TITLE_VERTICAL_OUTLINE_CLIPART
1166         LayoutDescriptor( 0 ),                                                              // AUTOLAYOUT_HANDOUT9
1167         LayoutDescriptor( 10, PRESOBJ_TEXT, PRESOBJ_NONE ),                                 // AUTOLAYOUT_ONLY_TEXT
1168         LayoutDescriptor( 6, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE,               // AUTOLAYOUT_4CLIPART
1169             PRESOBJ_GRAPHIC, PRESOBJ_GRAPHIC ),
1170         LayoutDescriptor( 11, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE,              // AUTOLAYOUT_6CLIPART
1171             PRESOBJ_OUTLINE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE )
1172     };
1173 
1174     if( (eLayout < AUTOLAYOUT__START) || (eLayout >= AUTOLAYOUT__END) )
1175         eLayout = AUTOLAYOUT_NONE;
1176 
1177     return aLayouts[ eLayout - AUTOLAYOUT__START ];
1178 }
1179 
1180 static void CalcAutoLayoutRectangles( SdPage& rPage, int nLayout, Rectangle* rRectangle )
1181 {
1182     Rectangle aTitleRect;
1183     Rectangle aLayoutRect;
1184 
1185     if( rPage.GetPageKind() != PK_HANDOUT )
1186     {
1187         SdPage& rMasterPage = static_cast<SdPage&>(rPage.TRG_GetMasterPage());
1188         SdrObject* pMasterTitle = rMasterPage.GetPresObj( PRESOBJ_TITLE );
1189         SdrObject* pMasterOutline = rMasterPage.GetPresObj( rPage.GetPageKind()==PK_NOTES ? PRESOBJ_NOTES : PRESOBJ_OUTLINE );
1190 
1191         if( pMasterTitle )
1192             aTitleRect = pMasterTitle->GetLogicRect();
1193 
1194         if (aTitleRect.IsEmpty() )
1195             aTitleRect = rPage.GetTitleRect();
1196 
1197         if( pMasterOutline )
1198             aLayoutRect = pMasterOutline->GetLogicRect();
1199 
1200         if (aLayoutRect.IsEmpty() )
1201             aLayoutRect = rPage.GetLayoutRect();
1202     }
1203 
1204     rRectangle[0] = aTitleRect;
1205 
1206     int i;
1207     for( i = 1; i < MAX_PRESOBJS; i++ )
1208         rRectangle[i] = aLayoutRect;
1209 
1210     Size        aTitleSize( aTitleRect.GetSize() );
1211     Point       aTitlePos( aTitleRect.TopLeft() );
1212     Size        aLayoutSize( aLayoutRect.GetSize() );
1213     Point       aLayoutPos( aLayoutRect.TopLeft() );
1214     Size        aTempSize;
1215     Point       aTempPnt;
1216 
1217     sal_Bool    bRightToLeft = ( rPage.GetModel() && static_cast< SdDrawDocument* >( rPage.GetModel() )->GetDefaultWritingMode() == ::com::sun::star::text::WritingMode_RL_TB );
1218 
1219     switch( nLayout )
1220     {
1221     case 0: // default layout using only the title and layout area
1222         break; // do nothing
1223     case 1: // title, 2 shapes
1224     case 9: // title, 2 vertical shapes
1225         aLayoutSize.Width()  = long (aLayoutSize.Width() * 0.488);
1226         rRectangle[1] = Rectangle (aLayoutPos, aLayoutSize);
1227 
1228         aLayoutPos.X() = long (aLayoutPos.X() + aLayoutSize.Width() * 1.05);
1229         rRectangle[2] = Rectangle (aLayoutPos, aLayoutSize);
1230 
1231         if( bRightToLeft && (nLayout != 9) )
1232             ::std::swap< Rectangle >( rRectangle[1], rRectangle[2] );
1233         break;
1234     case 2: // title, shape, 2 shapes
1235         aTempPnt = aLayoutPos;
1236         aTempSize = aLayoutSize;
1237         aLayoutSize.Height() = long (aLayoutSize.Height() * 0.477);
1238         aLayoutSize.Width() = long (aLayoutSize.Width() * 0.488);
1239         aLayoutPos.X() = long (aLayoutPos.X() + aLayoutSize.Width() * 1.05);
1240         rRectangle[2] = Rectangle (aLayoutPos, aLayoutSize);
1241 
1242         aLayoutPos.Y() = long (aLayoutPos.Y() + aLayoutSize.Height() * 1.095);
1243         rRectangle[3] = Rectangle (aLayoutPos, aLayoutSize);
1244 
1245         aLayoutPos = aTempPnt;
1246         aLayoutSize = aTempSize;
1247         aLayoutSize.Width() = long (aLayoutSize.Width() * 0.488);
1248         rRectangle[1] = Rectangle (aLayoutPos, aLayoutSize);
1249 
1250         if( bRightToLeft )
1251         {
1252             ::std::swap< long >( rRectangle[1].Left(), rRectangle[2].Left() );
1253             rRectangle[3].Left() = rRectangle[2].Left();
1254         }
1255         break;
1256     case 3: // title, 2 shapes, shape
1257         aTempPnt = aLayoutPos;
1258         aTempSize = aLayoutSize;
1259         aLayoutSize.Height() = long (aLayoutSize.Height() * 0.477);
1260         aLayoutSize.Width() = long (aLayoutSize.Width() * 0.488);
1261         rRectangle[1] = Rectangle (aLayoutPos, aLayoutSize);
1262 
1263         aLayoutPos.Y() = long (aLayoutPos.Y() + aLayoutSize.Height() * 1.095);
1264         rRectangle[2] = Rectangle (aLayoutPos, aLayoutSize);
1265 
1266         aLayoutPos = aTempPnt;
1267         aLayoutSize = aTempSize;
1268         aLayoutSize.Width() = long (aLayoutSize.Width() * 0.488);
1269         aLayoutPos.X() = long (aLayoutPos.X() + aLayoutSize.Width() * 1.05);
1270         rRectangle[3] = Rectangle (aLayoutPos, aLayoutSize);
1271 
1272         if( bRightToLeft )
1273         {
1274             ::std::swap< long >( rRectangle[1].Left(), rRectangle[2].Left() );
1275             rRectangle[3].Left() = rRectangle[2].Left();
1276         }
1277         break;
1278     case 4: // title, shape above shape
1279         aLayoutSize.Height() = long (aLayoutSize.Height() * 0.477);
1280         rRectangle[1] = Rectangle (aLayoutPos, aLayoutSize);
1281 
1282         aLayoutPos.Y() = long (aLayoutPos.Y() + aLayoutSize.Height() * 1.095);
1283         rRectangle[2] = Rectangle (aLayoutPos, aLayoutSize);
1284         break;
1285 
1286     case 5: // title, 2 shapes above shape
1287         aLayoutSize.Height() = long (aLayoutSize.Height() * 0.477);
1288         aLayoutSize.Width() = long (aLayoutSize.Width() * 0.488);
1289         rRectangle[1] = Rectangle (aLayoutPos, aLayoutSize);
1290 
1291         aTempPnt = aLayoutPos;
1292         aLayoutPos.X() = long (aLayoutPos.X() + aLayoutSize.Width() * 1.05);
1293         rRectangle[2] = Rectangle (aLayoutPos, aLayoutSize);
1294 
1295         aLayoutPos.X() = aTempPnt.X();
1296         aLayoutPos.Y() = long (aLayoutPos.Y() + aLayoutSize.Height() * 1.095);
1297         aLayoutSize.Width() = long (aLayoutSize.Width() / 0.488);
1298         rRectangle[3] = Rectangle (aLayoutPos, aLayoutSize);
1299         break;
1300     case 6: // title, 4 shapes
1301     {
1302         sal_uLong nX = long (aLayoutPos.X());
1303 
1304         aLayoutSize.Height() = long (aLayoutSize.Height() * 0.477);
1305         aLayoutSize.Width()  = long (aLayoutSize.Width() * 0.488);
1306         rRectangle[1] = Rectangle (aLayoutPos, aLayoutSize);
1307 
1308         aLayoutPos.X() = long (nX + aLayoutSize.Width() * 1.05);
1309         rRectangle[2] = Rectangle (aLayoutPos, aLayoutSize);
1310 
1311         aLayoutPos.Y() = long (aLayoutPos.Y() + aLayoutSize.Height() * 1.095);
1312         rRectangle[3] = Rectangle (aLayoutPos, aLayoutSize);
1313 
1314         aLayoutPos.X() = nX;
1315         rRectangle[4] = Rectangle (aLayoutPos, aLayoutSize);
1316         break;
1317     }
1318     case 7: // vertical title, shape above shape
1319     {
1320         Size aSize( rRectangle[0].GetSize().Height(), rRectangle[1].BottomLeft().Y() - rRectangle[0].TopLeft().Y() );
1321         rRectangle[0].SetSize( aSize );
1322         rRectangle[0].SetPos( aTitleRect.TopRight() - Point( aSize.Width(), 0 ) );
1323 
1324         Size aPageSize ( rPage.GetSize() );
1325         aPageSize.Height() -= rPage.GetUppBorder() + rPage.GetLwrBorder();
1326         aSize.Height() = long ( rRectangle[0].GetSize().Height() * 0.47 );
1327         aSize.Width() = long( aPageSize.Width() * 0.7 );
1328         rRectangle[1].SetPos( aTitleRect.TopLeft() );
1329         rRectangle[1].SetSize( aSize );
1330 
1331         aSize.Height() = rRectangle[0].GetSize().Height();
1332         Point aPos( aTitleRect.TopLeft() );
1333         aPos.Y() += long ( aSize.Height() * 0.53 );
1334         rRectangle[2].SetPos( aPos );
1335         aSize.Height() = long ( rRectangle[0].GetSize().Height() * 0.47 );
1336         rRectangle[2].SetSize( aSize );
1337         break;
1338     }
1339     case 8: // vertical title, shape
1340     {
1341         Size aSize( rRectangle[0].GetSize().Height(), rRectangle[1].BottomLeft().Y() - rRectangle[0].TopLeft().Y() );
1342         rRectangle[0].SetSize( aSize );
1343         rRectangle[0].SetPos( aTitleRect.TopRight() - Point( aSize.Width(), 0 ) );
1344 
1345         Size aPageSize ( rPage.GetSize() );
1346         aPageSize.Height() -= rPage.GetUppBorder() + rPage.GetLwrBorder();
1347         aSize.Height() = rRectangle[0].GetSize().Height();
1348         aSize.Width() = long( aPageSize.Width() * 0.7 );
1349         rRectangle[1].SetPos( aTitleRect.TopLeft() );
1350         rRectangle[1].SetSize( aSize );
1351         break;
1352     }
1353     case 10: // onlytext
1354     {
1355         Size aSize( rRectangle[0].GetSize().Width(), rRectangle[1].BottomLeft().Y() - rRectangle[0].TopLeft().Y() );
1356         rRectangle[0].SetSize( aSize );
1357         rRectangle[0].SetPos( aTitlePos);
1358         break;
1359     }
1360     case 11: // title, 6 shapes
1361     {
1362         sal_uLong nX = long (aLayoutPos.X());
1363 
1364         aLayoutSize.Height() = long (aLayoutSize.Height() * 0.477);
1365         aLayoutSize.Width()  = long (aLayoutSize.Width() * 0.322);
1366         rRectangle[1] = Rectangle (aLayoutPos, aLayoutSize);
1367 
1368         aLayoutPos.X() = long (nX + aLayoutSize.Width() * 1.05);
1369         rRectangle[2] = Rectangle (aLayoutPos, aLayoutSize);
1370 
1371         aLayoutPos.X() = long (nX + aLayoutSize.Width() * 2 * 1.05);
1372         rRectangle[3] = Rectangle (aLayoutPos, aLayoutSize);
1373 
1374         aLayoutPos.Y() = long (aLayoutPos.Y() + aLayoutSize.Height() * 1.095);
1375         rRectangle[4] = Rectangle (aLayoutPos, aLayoutSize);
1376 
1377         aLayoutPos.X() = long (nX + aLayoutSize.Width() * 1.05);
1378         rRectangle[5] = Rectangle (aLayoutPos, aLayoutSize);
1379 
1380         aLayoutPos.X() = nX;
1381         rRectangle[6] = Rectangle (aLayoutPos, aLayoutSize);
1382 
1383         break;
1384     }
1385 
1386     }
1387 }
1388 
1389 
1390 void findAutoLayoutShapesImpl( SdPage& rPage, const LayoutDescriptor& rDescriptor, std::vector< SdrObject* >& rShapes, bool bInit, bool bSwitchLayout )
1391 {
1392     int i;
1393 
1394     // init list of indexes for each presentation shape kind
1395     // this is used to find subsequent shapes with the same presentation shape kind
1396     int PresObjIndex[PRESOBJ_MAX];
1397     for( i = 0; i < PRESOBJ_MAX; i++ ) PresObjIndex[i] = 1;
1398 
1399     bool bMissing = false;
1400 
1401     // for each entry in the layoutdescriptor, arrange a presentation shape
1402     for( i = 0; (i < PRESOBJ_MAX) && (rDescriptor.meKind[i] != PRESOBJ_NONE); i++ )
1403     {
1404         PresObjKind eKind = rDescriptor.meKind[i];
1405         SdrObject* pObj = 0;
1406         while( (pObj = rPage.GetPresObj( eKind, PresObjIndex[eKind], true )) != 0 )
1407         {
1408             PresObjIndex[eKind]++; // on next search for eKind, find next shape with same eKind
1409 
1410             if( !bSwitchLayout || !pObj->IsEmptyPresObj() )
1411             {
1412                 rShapes[i] = pObj;
1413                 break;
1414             }
1415         }
1416 
1417         if( !pObj )
1418             bMissing = true;
1419     }
1420 
1421     if( bMissing && bInit )
1422     {
1423         // for each entry in the layoutdescriptor, look for an alternative shape
1424         for( i = 0; (i < PRESOBJ_MAX) && (rDescriptor.meKind[i] != PRESOBJ_NONE); i++ )
1425         {
1426             if( rShapes[i] )
1427                 continue;
1428 
1429             PresObjKind eKind = rDescriptor.meKind[i];
1430 
1431             SdrObject* pObj = 0;
1432             bool bFound = false;
1433 
1434             const int nShapeCount = rPage.GetObjCount();
1435             int nShapeIndex = 0;
1436             while((nShapeIndex < nShapeCount) && !bFound )
1437             {
1438                 pObj = rPage.GetObj(nShapeIndex++);
1439 
1440                 if( pObj->IsEmptyPresObj() )
1441                     continue;
1442 
1443                 if( pObj->GetObjInventor() != SdrInventor )
1444                     continue;
1445 
1446                 // do not reuse shapes that are already part of the layout
1447                 if( std::find( rShapes.begin(), rShapes.end(), pObj ) != rShapes.end() )
1448                     continue;
1449 
1450                 bool bPresStyle = pObj->GetStyleSheet() && (pObj->GetStyleSheet()->GetFamily() == SD_STYLE_FAMILY_MASTERPAGE);
1451                 SdrObjKind eSdrObjKind = static_cast< SdrObjKind >( pObj->GetObjIdentifier() );
1452 
1453                 switch( eKind )
1454                 {
1455                 case PRESOBJ_TITLE:
1456                     bFound = eSdrObjKind == OBJ_TITLETEXT;
1457                     break;
1458                 case PRESOBJ_TABLE:
1459                     bFound = eSdrObjKind == OBJ_TABLE;
1460                     break;
1461                 case PRESOBJ_MEDIA:
1462                     bFound = eSdrObjKind == OBJ_MEDIA;
1463                     break;
1464                 case PRESOBJ_OUTLINE:
1465                     bFound = (eSdrObjKind == OBJ_OUTLINETEXT) ||
1466                              ((eSdrObjKind == OBJ_TEXT) && bPresStyle) ||
1467                              (eSdrObjKind == OBJ_TABLE) || (eSdrObjKind == OBJ_MEDIA) || (eSdrObjKind == OBJ_GRAF) || (eSdrObjKind == OBJ_OLE2);
1468                     break;
1469                 case PRESOBJ_GRAPHIC:
1470                     bFound = eSdrObjKind == OBJ_GRAF;
1471                     break;
1472                 case PRESOBJ_OBJECT:
1473                     if( eSdrObjKind == OBJ_OLE2 )
1474                     {
1475                         SdrOle2Obj* pOle2 = dynamic_cast< SdrOle2Obj* >( pObj );
1476                         if( pOle2 )
1477                         {
1478                             if( pOle2->IsEmpty() )
1479                                 bFound = true;
1480                             else if( rPage.GetModel() )
1481                             {
1482                                 SdrModel* pSdrModel = rPage.GetModel();
1483                                 ::comphelper::IEmbeddedHelper *pPersist = pSdrModel->GetPersist();
1484                                 if( pPersist )
1485                                 {
1486                                     uno::Reference < embed::XEmbeddedObject > xObject = pPersist->getEmbeddedObjectContainer().
1487                                             GetEmbeddedObject( static_cast< SdrOle2Obj* >( pObj )->GetPersistName() );
1488 
1489                                     // TODO CL->KA: Why is this not working anymore?
1490                                     if( xObject.is() )
1491                                     {
1492                                         SvGlobalName aClassId( xObject->getClassID() );
1493 
1494                                         const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
1495                                         const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
1496                                         const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
1497 
1498                                         if( aPluginClassId != aClassId && aAppletClassId != aClassId && aIFrameClassId != aClassId )
1499                                         {
1500                                             bFound = true;
1501                                         }
1502                                     }
1503                                 }
1504                              }
1505                          }
1506                     }
1507                     break;
1508                 case PRESOBJ_CHART:
1509                 case PRESOBJ_CALC:
1510                     if( eSdrObjKind == OBJ_OLE2 )
1511                     {
1512                         SdrOle2Obj* pOle2 = dynamic_cast< SdrOle2Obj* >( pObj );
1513                         if( pOle2 )
1514                         {
1515                             if(
1516                                 ((eKind == PRESOBJ_CHART) &&
1517                                     ( pOle2->GetProgName().EqualsAscii( "StarChart" ) || pOle2->IsChart() ) )
1518                                 ||
1519                                 ((eKind == PRESOBJ_CALC) &&
1520                                     ( pOle2->GetProgName().EqualsAscii( "StarCalc" ) || pOle2->IsCalc() ) ) )
1521                             {
1522                                 bFound = true;
1523                             }
1524                         }
1525                         break;
1526                     }
1527                     else if( eSdrObjKind == OBJ_TABLE )
1528                     {
1529                         bFound = true;
1530                     }
1531                     break;
1532                 case PRESOBJ_PAGE:
1533                 case PRESOBJ_HANDOUT:
1534                     bFound = eSdrObjKind == OBJ_PAGE;
1535                     break;
1536                 case PRESOBJ_NOTES:
1537                 case PRESOBJ_TEXT:
1538                     bFound = (bPresStyle && (eSdrObjKind == OBJ_TEXT)) || (eSdrObjKind == OBJ_OUTLINETEXT);
1539                     break;
1540                 default:
1541                     break;
1542                 }
1543             }
1544 
1545             if( bFound )
1546                 rShapes[i] = pObj;
1547         }
1548     }
1549 }
1550 
1551 void SdPage::SetAutoLayout(AutoLayout eLayout, sal_Bool bInit, sal_Bool bCreate )
1552 {
1553     sd::ScopeLockGuard aGuard( maLockAutoLayoutArrangement );
1554 
1555     const bool bSwitchLayout = eLayout != GetAutoLayout();
1556 
1557     ::svl::IUndoManager* pUndoManager = pModel ? static_cast<SdDrawDocument*>(pModel)->GetUndoManager() : 0;
1558     const bool bUndo = pUndoManager && pUndoManager->IsInListAction() && IsInserted();
1559 
1560     meAutoLayout = eLayout;
1561 
1562     // if needed, creates and initialises the presentation shapes on this slides master page
1563     CreateTitleAndLayout(bInit, bCreate);
1564 
1565     if((meAutoLayout == AUTOLAYOUT_NONE && maPresentationShapeList.isEmpty()) || mbMaster)
1566     {
1567         // MasterPage or no layout and no presentation shapes available, noting to do
1568         return;
1569     }
1570 
1571     Rectangle aRectangle[MAX_PRESOBJS];
1572     const LayoutDescriptor& aDescriptor = GetLayoutDescriptor( meAutoLayout );
1573     CalcAutoLayoutRectangles( *this, aDescriptor.mnLayout, aRectangle );
1574 
1575     std::set< SdrObject* > aUsedPresentationObjects;
1576 
1577 
1578     std::vector< SdrObject* > aLayoutShapes(PRESOBJ_MAX, 0);
1579     findAutoLayoutShapesImpl( *this, aDescriptor, aLayoutShapes, bInit, bSwitchLayout );
1580 
1581     int i;
1582 
1583     // for each entry in the layoutdescriptor, arrange a presentation shape
1584     for( i = 0; (i < PRESOBJ_MAX) && (aDescriptor.meKind[i] != PRESOBJ_NONE); i++ )
1585     {
1586         PresObjKind eKind = aDescriptor.meKind[i];
1587         SdrObject* pObj = InsertAutoLayoutShape( aLayoutShapes[i], eKind, aDescriptor.mbVertical[i], aRectangle[i], bInit );
1588         if( pObj )
1589             aUsedPresentationObjects.insert(pObj); // remember that we used this empty shape
1590     }
1591 
1592     // now delete all empty presentation objects that are no longer used by the new layout
1593     if( bInit )
1594     {
1595         SdrObject* pObj = maPresentationShapeList.getNextShape(0);
1596 
1597         while( pObj )
1598         {
1599             SdrObject* pNext = maPresentationShapeList.getNextShape(pObj);
1600             if( aUsedPresentationObjects.count(pObj) == 0 )
1601             {
1602 
1603                 if( pObj->IsEmptyPresObj() )
1604                 {
1605                     if( bUndo )
1606                         pUndoManager->AddUndoAction(pModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pObj));
1607 
1608                     RemoveObject( pObj->GetOrdNum() );
1609 
1610                     if( !bUndo )
1611                         SdrObject::Free( pObj );
1612                 }
1613 /* #i108541# keep non empty pres obj as pres obj even if they are not part of the current layout
1614                 else
1615                 {
1616                     if( bUndo )
1617                     {
1618                         pUndoManager->AddUndoAction( new UndoObjectPresentationKind( *pObj ) );
1619                         if( pObj->GetUserCall() )
1620                             pUndoManager->AddUndoAction( new UndoObjectUserCall( *pObj ) );
1621                     }
1622                     maPresentationShapeList.removeShape( *pObj );
1623                     pObj->SetUserCall(0);
1624                 }
1625 */
1626             }
1627             pObj = pNext;
1628         }
1629     }
1630 }
1631 
1632 /*************************************************************************
1633 |*
1634 |* Objekt einfuegen
1635 |*
1636 \************************************************************************/
1637 
1638 void SdPage::NbcInsertObject(SdrObject* pObj, sal_uLong nPos, const SdrInsertReason* pReason)
1639 {
1640     FmFormPage::NbcInsertObject(pObj, nPos, pReason);
1641 
1642     ((SdDrawDocument*) pModel)->InsertObject(pObj, this);
1643 
1644     SdrLayerID nId = pObj->GetLayer();
1645     if( mbMaster )
1646     {
1647         if( nId == 0 )
1648             pObj->NbcSetLayer( 2 );     // wrong layer. corrected to BackgroundObj layer
1649     }
1650     else
1651     {
1652         if( nId == 2 )
1653             pObj->NbcSetLayer( 0 );     // wrong layer. corrected to layout layer
1654     }
1655 }
1656 
1657 /*************************************************************************
1658 |*
1659 |* Objekt loeschen
1660 |*
1661 \************************************************************************/
1662 
1663 SdrObject* SdPage::RemoveObject(sal_uLong nObjNum)
1664 {
1665     onRemoveObject(GetObj( nObjNum ));
1666     return FmFormPage::RemoveObject(nObjNum);
1667 }
1668 
1669 /*************************************************************************
1670 |*
1671 |* Objekt loeschen, ohne Broadcast
1672 |*
1673 \************************************************************************/
1674 
1675 SdrObject* SdPage::NbcRemoveObject(sal_uLong nObjNum)
1676 {
1677     onRemoveObject(GetObj( nObjNum ));
1678     return FmFormPage::NbcRemoveObject(nObjNum);
1679 }
1680 
1681 // #95876# Also overload ReplaceObject methods to realize when
1682 // objects are removed with this mechanism instead of RemoveObject
1683 SdrObject* SdPage::NbcReplaceObject(SdrObject* pNewObj, sal_uLong nObjNum)
1684 {
1685     onRemoveObject(GetObj( nObjNum ));
1686     return FmFormPage::NbcReplaceObject(pNewObj, nObjNum);
1687 }
1688 
1689 // #95876# Also overload ReplaceObject methods to realize when
1690 // objects are removed with this mechanism instead of RemoveObject
1691 SdrObject* SdPage::ReplaceObject(SdrObject* pNewObj, sal_uLong nObjNum)
1692 {
1693     onRemoveObject(GetObj( nObjNum ));
1694     return FmFormPage::ReplaceObject(pNewObj, nObjNum);
1695 }
1696 
1697 // -------------------------------------------------------------------------
1698 
1699 // called after a shape is removed or replaced from this slide
1700 
1701 void SdPage::onRemoveObject( SdrObject* pObject )
1702 {
1703     if( pObject )
1704     {
1705         RemovePresObj(pObject);
1706 
1707         if( pModel )
1708             static_cast<SdDrawDocument*>(pModel)->RemoveObject(pObject, this);
1709 
1710         removeAnimations( pObject );
1711     }
1712 }
1713 
1714 /*************************************************************************
1715 |*
1716 |*
1717 |*
1718 \************************************************************************/
1719 
1720 void SdPage::SetSize(const Size& aSize)
1721 {
1722     Size aOldSize = GetSize();
1723 
1724     if (aSize != aOldSize)
1725     {
1726         FmFormPage::SetSize(aSize);
1727 
1728         if (aOldSize.Height() == 10 && aOldSize.Width() == 10)
1729         {
1730             // Die Seite bekommt erstmalig eine gueltige Groesse gesetzt,
1731             // daher wird nun die Orientation initialisiert
1732             if (aSize.Width() > aSize.Height())
1733             {
1734                 meOrientation = ORIENTATION_LANDSCAPE;
1735             }
1736             else
1737             {
1738                 meOrientation = ORIENTATION_PORTRAIT;
1739             }
1740         }
1741     }
1742 }
1743 
1744 
1745 /*************************************************************************
1746 |*
1747 |*
1748 |*
1749 \************************************************************************/
1750 
1751 void SdPage::SetBorder(sal_Int32 nLft, sal_Int32 nUpp, sal_Int32 nRgt, sal_Int32 nLwr)
1752 {
1753     if (nLft != GetLftBorder() || nUpp != GetUppBorder() ||
1754         nRgt != GetRgtBorder() || nLwr != GetLwrBorder() )
1755     {
1756         FmFormPage::SetBorder(nLft, nUpp, nRgt, nLwr);
1757     }
1758 }
1759 
1760 
1761 /*************************************************************************
1762 |*
1763 |*
1764 |*
1765 \************************************************************************/
1766 
1767 void SdPage::SetLftBorder(sal_Int32 nBorder)
1768 {
1769     if (nBorder != GetLftBorder() )
1770     {
1771         FmFormPage::SetLftBorder(nBorder);
1772     }
1773 }
1774 
1775 
1776 /*************************************************************************
1777 |*
1778 |*
1779 |*
1780 \************************************************************************/
1781 
1782 void SdPage::SetRgtBorder(sal_Int32 nBorder)
1783 {
1784     if (nBorder != GetRgtBorder() )
1785     {
1786         FmFormPage::SetRgtBorder(nBorder);
1787     }
1788 }
1789 
1790 
1791 /*************************************************************************
1792 |*
1793 |*
1794 |*
1795 \************************************************************************/
1796 
1797 void SdPage::SetUppBorder(sal_Int32 nBorder)
1798 {
1799     if (nBorder != GetUppBorder() )
1800     {
1801         FmFormPage::SetUppBorder(nBorder);
1802     }
1803 }
1804 
1805 
1806 /*************************************************************************
1807 |*
1808 |*
1809 |*
1810 \************************************************************************/
1811 
1812 void SdPage::SetLwrBorder(sal_Int32 nBorder)
1813 {
1814     if (nBorder != GetLwrBorder() )
1815     {
1816         FmFormPage::SetLwrBorder(nBorder);
1817     }
1818 }
1819 
1820 /*************************************************************************
1821 |*
1822 |* Setzt BackgroundFullSize und ruft dann AdjustBackground auf
1823 |*
1824 \************************************************************************/
1825 
1826 void SdPage::SetBackgroundFullSize( sal_Bool bIn )
1827 {
1828     if( bIn != mbBackgroundFullSize )
1829     {
1830         mbBackgroundFullSize = bIn;
1831     }
1832 }
1833 
1834 /*************************************************************************
1835 |*
1836 |* Alle Objekte an neue Seitengroesse anpassen
1837 |*
1838 |* bScaleAllObj: Alle Objekte werden in die neue Flaeche innerhalb der
1839 |* Seitenraender skaliert. Dabei werden die Position, Groesse und bei
1840 |* Praesentationsobjekten auf der MasterPage auch die Schrifthoehe der
1841 |* Praesentationsvorlagen skaliert.
1842 |*
1843 \************************************************************************/
1844 
1845 void SdPage::ScaleObjects(const Size& rNewPageSize, const Rectangle& rNewBorderRect, sal_Bool bScaleAllObj)
1846 {
1847     sd::ScopeLockGuard aGuard( maLockAutoLayoutArrangement );
1848 
1849     mbScaleObjects = bScaleAllObj;
1850     SdrObject* pObj = NULL;
1851     Point aRefPnt(0, 0);
1852     Size aNewPageSize(rNewPageSize);
1853     sal_Int32 nLeft  = rNewBorderRect.Left();
1854     sal_Int32 nRight = rNewBorderRect.Right();
1855     sal_Int32 nUpper = rNewBorderRect.Top();
1856     sal_Int32 nLower = rNewBorderRect.Bottom();
1857 
1858     // Negative Werte stehen fuer nicht zu aendernde Werte
1859     // -> aktuelle Werte verwenden
1860     if (aNewPageSize.Width() < 0)
1861     {
1862         aNewPageSize.Width() = GetWdt();
1863     }
1864     if (aNewPageSize.Height() < 0)
1865     {
1866         aNewPageSize.Height() = GetHgt();
1867     }
1868     if (nLeft < 0)
1869     {
1870         nLeft = GetLftBorder();
1871     }
1872     if (nRight < 0)
1873     {
1874         nRight = GetRgtBorder();
1875     }
1876     if (nUpper < 0)
1877     {
1878         nUpper = GetUppBorder();
1879     }
1880     if (nLower < 0)
1881     {
1882         nLower = GetLwrBorder();
1883     }
1884 
1885     Point aBackgroundPos(nLeft, nUpper);
1886     Size aBackgroundSize(aNewPageSize);
1887     Rectangle aBorderRect (aBackgroundPos, aBackgroundSize);
1888 
1889     if (mbScaleObjects)
1890     {
1891         aBackgroundSize.Width()  -= nLeft  + nRight;
1892         aBackgroundSize.Height() -= nUpper + nLower;
1893         aBorderRect.SetSize(aBackgroundSize);
1894         aNewPageSize = aBackgroundSize;
1895     }
1896 
1897     long nOldWidth  = GetWdt() - GetLftBorder() - GetRgtBorder();
1898     long nOldHeight = GetHgt() - GetUppBorder() - GetLwrBorder();
1899 
1900     Fraction aFractX = Fraction(aNewPageSize.Width(), nOldWidth);
1901     Fraction aFractY = Fraction(aNewPageSize.Height(), nOldHeight);
1902 
1903     sal_uLong nObjCnt = (mbScaleObjects ? GetObjCount() : 0);
1904 
1905     for (sal_uLong nObj = 0; nObj < nObjCnt; nObj++)
1906     {
1907         sal_Bool bIsPresObjOnMaster = sal_False;
1908 
1909         // Alle Objekte
1910         pObj = GetObj(nObj);
1911 
1912         if (mbMaster && IsPresObj(pObj))
1913         {
1914             // Es ist ein Praesentationsobjekt auf der MasterPage
1915             bIsPresObjOnMaster = sal_True;
1916         }
1917 
1918         if (pObj)
1919         {
1920             // #88084# remember aTopLeft as original TopLeft
1921             Point aTopLeft(pObj->GetCurrentBoundRect().TopLeft());
1922 
1923             if (!pObj->IsEdgeObj())
1924             {
1925                 /**************************************************************
1926                 * Objekt skalieren
1927                 **************************************************************/
1928                 if (mbScaleObjects)
1929                 {
1930                     // #88084# use aTopLeft as original TopLeft
1931                     aRefPnt = aTopLeft;
1932                 }
1933 
1934                 pObj->Resize(aRefPnt, aFractX, aFractY);
1935 
1936                 if (mbScaleObjects)
1937                 {
1938                     SdrObjKind eObjKind = (SdrObjKind) pObj->GetObjIdentifier();
1939 
1940                     if (bIsPresObjOnMaster)
1941                     {
1942                         /**********************************************************
1943                         * Praesentationsvorlage: Texthoehe anpassen
1944                         **********************************************************/
1945                         sal_uInt16 nIndexTitle = 0;
1946                         sal_uInt16 nIndexOutline = 0;
1947                         sal_uInt16 nIndexNotes = 0;
1948 
1949                         if (pObj == GetPresObj(PRESOBJ_TITLE, nIndexTitle))
1950                         {
1951                             SfxStyleSheet* pTitleSheet = GetStyleSheetForPresObj(PRESOBJ_TITLE);
1952 
1953                             if (pTitleSheet)
1954                             {
1955                                 SfxItemSet& rSet = pTitleSheet->GetItemSet();
1956 
1957                                 SvxFontHeightItem& rOldHgt = (SvxFontHeightItem&) rSet.Get(EE_CHAR_FONTHEIGHT);
1958                                 sal_uLong nFontHeight = rOldHgt.GetHeight();
1959                                 nFontHeight = long(nFontHeight * (double) aFractY);
1960                                 rSet.Put(SvxFontHeightItem(nFontHeight, 100, EE_CHAR_FONTHEIGHT));
1961 
1962                                 if( SFX_ITEM_AVAILABLE == rSet.GetItemState( EE_CHAR_FONTHEIGHT_CJK ) )
1963                                 {
1964                                     rOldHgt = (SvxFontHeightItem&) rSet.Get(EE_CHAR_FONTHEIGHT_CJK);
1965                                     nFontHeight = rOldHgt.GetHeight();
1966                                     nFontHeight = long(nFontHeight * (double) aFractY);
1967                                     rSet.Put(SvxFontHeightItem(nFontHeight, 100, EE_CHAR_FONTHEIGHT_CJK));
1968                                 }
1969 
1970                                 if( SFX_ITEM_AVAILABLE == rSet.GetItemState( EE_CHAR_FONTHEIGHT_CTL ) )
1971                                 {
1972                                     rOldHgt = (SvxFontHeightItem&) rSet.Get(EE_CHAR_FONTHEIGHT_CTL);
1973                                     nFontHeight = rOldHgt.GetHeight();
1974                                     nFontHeight = long(nFontHeight * (double) aFractY);
1975                                     rSet.Put(SvxFontHeightItem(nFontHeight, 100, EE_CHAR_FONTHEIGHT_CTL));
1976                                 }
1977 
1978                                 pTitleSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
1979                             }
1980                         }
1981                         else if (pObj == GetPresObj(PRESOBJ_OUTLINE, nIndexOutline))
1982                         {
1983                             String aName(GetLayoutName());
1984                             aName += sal_Unicode( ' ' );
1985 
1986                             for (sal_uInt16 i=1; i<=9; i++)
1987                             {
1988                                 String sLayoutName(aName);
1989                                 sLayoutName += String::CreateFromInt32( (sal_Int32)i );
1990                                 SfxStyleSheet* pOutlineSheet = (SfxStyleSheet*)((SdDrawDocument*) pModel)->GetStyleSheetPool()->Find(sLayoutName, SD_STYLE_FAMILY_MASTERPAGE);
1991 
1992                                 if (pOutlineSheet)
1993                                 {
1994                                     // Neue Fonthoehe berechnen
1995                                     SfxItemSet aTempSet(pOutlineSheet->GetItemSet());
1996 
1997                                     SvxFontHeightItem& rOldHgt = (SvxFontHeightItem&) aTempSet.Get(EE_CHAR_FONTHEIGHT);
1998                                     sal_uLong nFontHeight = rOldHgt.GetHeight();
1999                                     nFontHeight = long(nFontHeight * (double) aFractY);
2000                                     aTempSet.Put(SvxFontHeightItem(nFontHeight, 100, EE_CHAR_FONTHEIGHT));
2001 
2002                                     if( SFX_ITEM_AVAILABLE == aTempSet.GetItemState( EE_CHAR_FONTHEIGHT_CJK ) )
2003                                     {
2004                                         rOldHgt = (SvxFontHeightItem&) aTempSet.Get(EE_CHAR_FONTHEIGHT_CJK);
2005                                         nFontHeight = rOldHgt.GetHeight();
2006                                         nFontHeight = long(nFontHeight * (double) aFractY);
2007                                         aTempSet.Put(SvxFontHeightItem(nFontHeight, 100, EE_CHAR_FONTHEIGHT_CJK));
2008                                     }
2009 
2010                                     if( SFX_ITEM_AVAILABLE == aTempSet.GetItemState( EE_CHAR_FONTHEIGHT_CTL ) )
2011                                     {
2012                                         rOldHgt = (SvxFontHeightItem&) aTempSet.Get(EE_CHAR_FONTHEIGHT_CTL);
2013                                         nFontHeight = rOldHgt.GetHeight();
2014                                         nFontHeight = long(nFontHeight * (double) aFractY);
2015                                         aTempSet.Put(SvxFontHeightItem(nFontHeight, 100, EE_CHAR_FONTHEIGHT_CTL));
2016                                     }
2017 
2018                                     // Bullet anpassen
2019                                     ((SdStyleSheet*) pOutlineSheet)->AdjustToFontHeight(aTempSet, sal_False);
2020 
2021                                     // Sonderbehandlung: die INVALIDS auf NULL-Pointer
2022                                     // zurueckgesetzen (sonst landen INVALIDs oder
2023                                     // Pointer auf die DefaultItems in der Vorlage;
2024                                     // beides wuerde die Attribut-Vererbung unterbinden)
2025                                     aTempSet.ClearInvalidItems();
2026 
2027                                     // Sonderbehandlung: nur die gueltigen Anteile des
2028                                     // BulletItems
2029                                     if (aTempSet.GetItemState(EE_PARA_BULLET) == SFX_ITEM_AVAILABLE)
2030                                     {
2031                                         SvxBulletItem aOldBulItem((SvxBulletItem&) pOutlineSheet->GetItemSet().Get(EE_PARA_BULLET));
2032                                         SvxBulletItem& rNewBulItem = (SvxBulletItem&) aTempSet.Get(EE_PARA_BULLET);
2033                                         aOldBulItem.CopyValidProperties(rNewBulItem);
2034                                         aTempSet.Put(aOldBulItem);
2035                                     }
2036 
2037                                     pOutlineSheet->GetItemSet().Put(aTempSet);
2038                                     pOutlineSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
2039                                 }
2040                             }
2041                         }
2042                         else if (pObj == GetPresObj(PRESOBJ_NOTES, nIndexNotes))
2043                         {
2044                             SfxStyleSheet* pNotesSheet = GetStyleSheetForPresObj(PRESOBJ_NOTES);
2045 
2046                             if (pNotesSheet)
2047                             {
2048                                 sal_uLong nHeight = pObj->GetLogicRect().GetSize().Height();
2049                                 sal_uLong nFontHeight = (sal_uLong) (nHeight * 0.0741);
2050                                 SfxItemSet& rSet = pNotesSheet->GetItemSet();
2051                                 rSet.Put( SvxFontHeightItem(nFontHeight, 100, EE_CHAR_FONTHEIGHT ));
2052                                 rSet.Put( SvxFontHeightItem(nFontHeight, 100, EE_CHAR_FONTHEIGHT_CJK ));
2053                                 rSet.Put( SvxFontHeightItem(nFontHeight, 100, EE_CHAR_FONTHEIGHT_CTL ));
2054                                 pNotesSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
2055                             }
2056                         }
2057                     }
2058                     else if ( eObjKind != OBJ_TITLETEXT   &&
2059                               eObjKind != OBJ_OUTLINETEXT &&
2060                               pObj->ISA(SdrTextObj)       &&
2061                               pObj->GetOutlinerParaObject() )
2062                     {
2063                         /******************************************************
2064                         * Normales Textobjekt: Texthoehe anpassen
2065                         ******************************************************/
2066                         sal_uLong nScriptType = pObj->GetOutlinerParaObject()->GetTextObject().GetScriptType();
2067                         sal_uInt16 nWhich = EE_CHAR_FONTHEIGHT;
2068                         if ( nScriptType == SCRIPTTYPE_ASIAN )
2069                             nWhich = EE_CHAR_FONTHEIGHT_CJK;
2070                         else if ( nScriptType == SCRIPTTYPE_COMPLEX )
2071                             nWhich = EE_CHAR_FONTHEIGHT_CTL;
2072 
2073                         // #88084# use more modern method to scale the text height
2074                         sal_uInt32 nFontHeight = ((SvxFontHeightItem&)pObj->GetMergedItem(nWhich)).GetHeight();
2075                         sal_uInt32 nNewFontHeight = sal_uInt32((double)nFontHeight * (double)aFractY);
2076 
2077                         pObj->SetMergedItem(SvxFontHeightItem(nNewFontHeight, 100, nWhich));
2078                     }
2079                 }
2080             }
2081 
2082             if (mbScaleObjects && !pObj->IsEdgeObj())
2083             {
2084                 /**************************************************************
2085                 * Objektposition skalieren
2086                 **************************************************************/
2087                 Point aNewPos;
2088 
2089                 // #76447# corrected scaling; only distances may be scaled
2090                 // #88084# use aTopLeft as original TopLeft
2091                 aNewPos.X() = long((aTopLeft.X() - GetLftBorder()) * (double)aFractX) + nLeft;
2092                 aNewPos.Y() = long((aTopLeft.Y() - GetUppBorder()) * (double)aFractY) + nUpper;
2093 
2094                 Size aVec(aNewPos.X() - aTopLeft.X(), aNewPos.Y() - aTopLeft.Y());
2095 
2096                 if (aVec.Height() != 0 || aVec.Width() != 0)
2097                 {
2098                     pObj->NbcMove(aVec);
2099                 }
2100 
2101                 pObj->SetChanged();
2102                 pObj->BroadcastObjectChange();
2103             }
2104         }
2105     }
2106 }
2107 
2108 SdrObject* convertPresentationObjectImpl( SdPage& rPage, SdrObject* pSourceObj, PresObjKind& eObjKind, bool bVertical, Rectangle aRect )
2109 {
2110     SdDrawDocument* pModel = static_cast< SdDrawDocument* >( rPage.GetModel() );
2111     DBG_ASSERT( pModel, "sd::convertPresentationObjectImpl(), no model on page!" );
2112     if( !pModel || !pSourceObj )
2113         return pSourceObj;
2114 
2115     ::svl::IUndoManager* pUndoManager = pModel ? static_cast<SdDrawDocument*>(pModel)->GetUndoManager() : 0;
2116     const bool bUndo = pUndoManager && pUndoManager->IsInListAction() && rPage.IsInserted();
2117 
2118     SdrObject* pNewObj = pSourceObj;
2119     if((eObjKind == PRESOBJ_OUTLINE) && (pSourceObj->GetObjIdentifier() == OBJ_TEXT) )
2120     {
2121         pNewObj = rPage.CreatePresObj(PRESOBJ_OUTLINE, bVertical, aRect);
2122 
2123         // Text des Untertitels in das PRESOBJ_OUTLINE setzen
2124         OutlinerParaObject* pOutlParaObj = pSourceObj->GetOutlinerParaObject();
2125 
2126         if(pOutlParaObj)
2127         {
2128             // Text umsetzen
2129             ::sd::Outliner* pOutl = pModel->GetInternalOutliner( sal_True );
2130             pOutl->Clear();
2131             pOutl->SetText( *pOutlParaObj );
2132             pOutlParaObj = pOutl->CreateParaObject();
2133             pNewObj->SetOutlinerParaObject( pOutlParaObj );
2134             pOutl->Clear();
2135             pNewObj->SetEmptyPresObj(sal_False);
2136 
2137             for (sal_uInt16 nLevel = 1; nLevel < 10; nLevel++)
2138             {
2139                 // Neue Vorlage zuweisen
2140                 String aName(rPage.GetLayoutName());
2141                 aName += sal_Unicode( ' ' );
2142                 aName += String::CreateFromInt32( nLevel );
2143                 SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>( pModel->GetStyleSheetPool()->Find(aName, SD_STYLE_FAMILY_MASTERPAGE) );
2144 
2145                 if (pSheet)
2146                 {
2147                     if (nLevel == 1)
2148                     {
2149                         SfxStyleSheet* pSubtitleSheet = rPage.GetStyleSheetForPresObj(PRESOBJ_TEXT);
2150 
2151                         if (pSubtitleSheet)
2152                             pOutlParaObj->ChangeStyleSheetName(SD_STYLE_FAMILY_MASTERPAGE, pSubtitleSheet->GetName(), pSheet->GetName());
2153                     }
2154 
2155                     pNewObj->StartListening(*pSheet);
2156                 }
2157             }
2158 
2159             // LRSpace-Item loeschen
2160             SfxItemSet aSet(pModel->GetPool(), EE_PARA_LRSPACE, EE_PARA_LRSPACE );
2161 
2162             aSet.Put(pNewObj->GetMergedItemSet());
2163 
2164             aSet.ClearItem(EE_PARA_LRSPACE);
2165 
2166             pNewObj->SetMergedItemSet(aSet);
2167 
2168             if( bUndo )
2169                 pUndoManager->AddUndoAction( pModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pSourceObj) );
2170 
2171             // Remove outline shape from page
2172             rPage.RemoveObject( pSourceObj->GetOrdNum() );
2173 
2174             if( !bUndo )
2175                 SdrObject::Free( pSourceObj );
2176         }
2177     }
2178     else if((eObjKind == PRESOBJ_TEXT) && (pSourceObj->GetObjIdentifier() == OBJ_OUTLINETEXT) )
2179     {
2180         // is there an outline shape we can use to replace empty subtitle shape?
2181         pNewObj = rPage.CreatePresObj(PRESOBJ_TEXT, bVertical, aRect);
2182 
2183         // Text des Gliederungsobjekts in das PRESOBJ_TITLE setzen
2184         OutlinerParaObject* pOutlParaObj = pSourceObj->GetOutlinerParaObject();
2185 
2186         if(pOutlParaObj)
2187         {
2188             // Text umsetzen
2189             ::sd::Outliner* pOutl = pModel->GetInternalOutliner();
2190             pOutl->Clear();
2191             pOutl->SetText( *pOutlParaObj );
2192             pOutlParaObj = pOutl->CreateParaObject();
2193             pNewObj->SetOutlinerParaObject( pOutlParaObj );
2194             pOutl->Clear();
2195             pNewObj->SetEmptyPresObj(sal_False);
2196 
2197             // Linken Einzug zuruecksetzen
2198             SfxItemSet aSet(pModel->GetPool(), EE_PARA_LRSPACE, EE_PARA_LRSPACE );
2199 
2200             aSet.Put(pNewObj->GetMergedItemSet());
2201 
2202             const SvxLRSpaceItem& rLRItem = (const SvxLRSpaceItem&) aSet.Get(EE_PARA_LRSPACE);
2203             SvxLRSpaceItem aNewLRItem(rLRItem);
2204             aNewLRItem.SetTxtLeft(0);
2205             aSet.Put(aNewLRItem);
2206 
2207             pNewObj->SetMergedItemSet(aSet);
2208 
2209             SfxStyleSheet* pSheet = rPage.GetStyleSheetForPresObj(PRESOBJ_TEXT);
2210             if (pSheet)
2211                 pNewObj->SetStyleSheet(pSheet, sal_True);
2212 
2213             // Remove subtitle shape from page
2214             if( bUndo )
2215                 pUndoManager->AddUndoAction(pModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pSourceObj));
2216 
2217             rPage.RemoveObject( pSourceObj->GetOrdNum() );
2218 
2219             if( !bUndo )
2220                 SdrObject::Free( pSourceObj );
2221         }
2222     }
2223     else if((eObjKind == PRESOBJ_OUTLINE) && (pSourceObj->GetObjIdentifier() != OBJ_OUTLINETEXT) )
2224     {
2225         switch( pSourceObj->GetObjIdentifier() )
2226         {
2227         case OBJ_TABLE: eObjKind = PRESOBJ_TABLE; break;
2228         case OBJ_MEDIA: eObjKind = PRESOBJ_MEDIA; break;
2229         case OBJ_GRAF: eObjKind = PRESOBJ_GRAPHIC; break;
2230         case OBJ_OLE2: eObjKind = PRESOBJ_OBJECT; break;
2231         }
2232     }
2233 
2234     return pNewObj;
2235 }
2236 
2237 /** reuses or creates a presentation shape for an auto layout that fits the given parameter
2238 
2239     @param  eObjKind
2240         The kind of presentation shape we like to have
2241     @param  nIndex
2242         If > 1 we skip the first nIndex-1 shapes with the presentation shape kind eObjKind while
2243         looking for an existing presentation shape
2244     @param  bVertical
2245         If true, the shape is created vertical if bInit is true
2246     @param  aRect
2247         The rectangle that should be used to transform the shape
2248     @param  bInit
2249         If true the shape is created if not found
2250     @returns
2251         A presentation shape that was either found or created with the given parameters
2252 */
2253 SdrObject* SdPage::InsertAutoLayoutShape( SdrObject* pObj, PresObjKind eObjKind, bool bVertical, Rectangle aRect, bool bInit )
2254 {
2255     ::svl::IUndoManager* pUndoManager = pModel ? static_cast<SdDrawDocument*>(pModel)->GetUndoManager() : 0;
2256     const bool bUndo = pUndoManager && pUndoManager->IsInListAction() && IsInserted();
2257 
2258     if (!pObj && bInit)
2259     {
2260         pObj = CreatePresObj(eObjKind, bVertical, aRect);
2261     }
2262     else if ( pObj && (pObj->GetUserCall() || bInit) )
2263     {
2264         // convert object if shape type does not match kind (f.e. converting outline text to subtitle text)
2265         if( bInit )
2266             pObj = convertPresentationObjectImpl( *this, pObj, eObjKind, bVertical, aRect );
2267 
2268         if( bUndo )
2269         {
2270             pUndoManager->AddUndoAction( pModel->GetSdrUndoFactory().CreateUndoGeoObject( *pObj ) );
2271             pUndoManager->AddUndoAction( pModel->GetSdrUndoFactory().CreateUndoAttrObject( *pObj, sal_True, sal_True ) );
2272             pUndoManager->AddUndoAction( new UndoObjectUserCall( *pObj ) );
2273         }
2274 
2275 //      if ( pObj->ISA(SdrGrafObj) && !pObj->IsEmptyPresObj() )
2276             ( /*(SdrGrafObj*)*/ pObj)->AdjustToMaxRect( aRect );
2277 //      else
2278 //          SetLogicRect( pObj, aRect );
2279 
2280         pObj->SetUserCall(this);
2281 
2282         SdrTextObj* pTextObject = dynamic_cast< SdrTextObj* >(pObj);
2283         if( pTextObject )
2284         {
2285             if( pTextObject->IsVerticalWriting() != (bVertical ? sal_True : sal_False) )
2286             {
2287                 pTextObject->SetVerticalWriting( bVertical );
2288 
2289                 // #94826# here make sure the correct anchoring is used when the object
2290                 // is re-used but orientation is changed
2291                 if(PRESOBJ_OUTLINE == eObjKind)
2292                     pTextObject->SetMergedItem(SdrTextHorzAdjustItem( bVertical ? SDRTEXTHORZADJUST_RIGHT : SDRTEXTHORZADJUST_BLOCK ));
2293             }
2294 
2295             if( !mbMaster && (pTextObject->GetObjIdentifier() != OBJ_TABLE) )
2296             {
2297                 if ( pTextObject->IsAutoGrowHeight() )
2298                 {
2299                     // switch off AutoGrowHeight, set new MinHeight
2300                     SfxItemSet aTempAttr( ((SdDrawDocument*) pModel)->GetPool() );
2301                     SdrTextMinFrameHeightItem aMinHeight( aRect.GetSize().Height() );
2302                     aTempAttr.Put( aMinHeight );
2303                     aTempAttr.Put( SdrTextAutoGrowHeightItem(sal_False) );
2304                     pTextObject->SetMergedItemSet(aTempAttr);
2305                     pTextObject->SetLogicRect(aRect);
2306 
2307                     // switch on AutoGrowHeight
2308                     SfxItemSet aAttr( ((SdDrawDocument*) pModel)->GetPool() );
2309                     aAttr.Put( SdrTextAutoGrowHeightItem(sal_True) );
2310 
2311                     pTextObject->SetMergedItemSet(aAttr);
2312                 }
2313 
2314                 if ( pTextObject->IsAutoGrowWidth() )
2315                 {
2316                     // switch off AutoGrowWidth , set new MinWidth
2317                     SfxItemSet aTempAttr( ((SdDrawDocument*) pModel)->GetPool() );
2318                     SdrTextMinFrameWidthItem aMinWidth( aRect.GetSize().Width() );
2319                     aTempAttr.Put( aMinWidth );
2320                     aTempAttr.Put( SdrTextAutoGrowWidthItem(sal_False) );
2321                     pTextObject->SetMergedItemSet(aTempAttr);
2322                     pTextObject->SetLogicRect(aRect);
2323 
2324                     // switch on AutoGrowWidth
2325                     SfxItemSet aAttr( ((SdDrawDocument*) pModel)->GetPool() );
2326                     aAttr.Put( SdrTextAutoGrowWidthItem(sal_True) );
2327                     pTextObject->SetMergedItemSet(aAttr);
2328                 }
2329             }
2330         }
2331     }
2332 
2333     if(pObj && bInit )
2334     {
2335         if( !IsPresObj( pObj ) )
2336         {
2337             if( bUndo )
2338                 pUndoManager->AddUndoAction( new UndoObjectPresentationKind( *pObj ) );
2339 
2340             InsertPresObj( pObj, eObjKind );
2341         }
2342 
2343         // make adjustments for vertical title and outline shapes
2344         if( bVertical && (( eObjKind == PRESOBJ_TITLE) || (eObjKind == PRESOBJ_OUTLINE)))
2345         {
2346             SfxItemSet aNewSet(pObj->GetMergedItemSet());
2347             aNewSet.Put( SdrTextAutoGrowWidthItem(sal_True) );
2348             aNewSet.Put( SdrTextAutoGrowHeightItem(sal_False) );
2349             if( eObjKind == PRESOBJ_OUTLINE )
2350             {
2351                 aNewSet.Put( SdrTextVertAdjustItem(SDRTEXTVERTADJUST_TOP) );
2352                 aNewSet.Put( SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT) );
2353             }
2354             pObj->SetMergedItemSet(aNewSet);
2355         }
2356     }
2357 
2358     if ( pObj && (pObj->GetUserCall() || bInit) && ( pObj->IsEmptyPresObj() || !pObj->ISA(SdrGrafObj) ) )
2359         pObj->AdjustToMaxRect( aRect );
2360 
2361     return pObj;
2362 }
2363 
2364 
2365 /*************************************************************************
2366 |*
2367 |* Liefert den PresObjKind eines Objektes zurueck
2368 |*
2369 \************************************************************************/
2370 
2371 PresObjKind SdPage::GetPresObjKind(SdrObject* pObj) const
2372 {
2373     PresObjKind eKind = PRESOBJ_NONE;
2374     if( (pObj != 0) && (maPresentationShapeList.hasShape(*pObj)) )
2375     {
2376         SdAnimationInfo* pInfo = SdDrawDocument::GetShapeUserData(*pObj);
2377         if( pInfo )
2378             eKind = pInfo->mePresObjKind;
2379     }
2380 
2381     return eKind;
2382 }
2383 
2384 bool SdPage::IsPresObj(const SdrObject* pObj)
2385 {
2386     return pObj && maPresentationShapeList.hasShape( const_cast<SdrObject&>(*pObj) );
2387 }
2388 
2389 void SdPage::RemovePresObj(const SdrObject* pObj)
2390 {
2391     if( pObj && maPresentationShapeList.hasShape(const_cast<SdrObject&>(*pObj)) )
2392     {
2393         SdAnimationInfo* pInfo = SdDrawDocument::GetShapeUserData(const_cast<SdrObject&>(*pObj));
2394         if( pInfo )
2395             pInfo->mePresObjKind = PRESOBJ_NONE;
2396         maPresentationShapeList.removeShape(const_cast<SdrObject&>(*pObj));
2397     }
2398 }
2399 
2400 void SdPage::InsertPresObj(SdrObject* pObj, PresObjKind eKind )
2401 {
2402     DBG_ASSERT( pObj, "sd::SdPage::InsertPresObj(), invalid presentation object inserted!" );
2403     DBG_ASSERT( !IsPresObj(pObj), "sd::SdPage::InsertPresObj(), presentation object inserted twice!" );
2404     if( pObj )
2405     {
2406         SdAnimationInfo* pInfo = SdDrawDocument::GetShapeUserData(*pObj, true);
2407         if( pInfo )
2408             pInfo->mePresObjKind = eKind;
2409         maPresentationShapeList.addShape(*pObj);
2410     }
2411 }
2412 
2413 /*************************************************************************
2414 |*
2415 |* Text des Objektes setzen
2416 |*
2417 \************************************************************************/
2418 
2419 void SdPage::SetObjText(SdrTextObj* pObj, SdrOutliner* pOutliner, PresObjKind eObjKind, const String& rString )
2420 {
2421     if ( pObj )
2422     {
2423         DBG_ASSERT( pObj->ISA(SdrTextObj), "SetObjText: Kein SdrTextObj!" );
2424         ::Outliner* pOutl = pOutliner;
2425 
2426         if (!pOutliner)
2427         {
2428             SfxItemPool* pPool = ((SdDrawDocument*) GetModel())->GetDrawOutliner().GetEmptyItemSet().GetPool();
2429             pOutl = new ::Outliner( pPool, OUTLINERMODE_OUTLINEOBJECT );
2430             pOutl->SetRefDevice( SD_MOD()->GetRefDevice( *( (SdDrawDocument*) GetModel() )->GetDocSh() ) );
2431             pOutl->SetEditTextObjectPool(pPool);
2432             pOutl->SetStyleSheetPool((SfxStyleSheetPool*)GetModel()->GetStyleSheetPool());
2433             pOutl->EnableUndo(sal_False);
2434             pOutl->SetUpdateMode( sal_False );
2435         }
2436 
2437         sal_uInt16 nOutlMode = pOutl->GetMode();
2438         Size aPaperSize = pOutl->GetPaperSize();
2439         sal_Bool bUpdateMode = pOutl->GetUpdateMode();
2440         pOutl->SetUpdateMode(sal_False);
2441         pOutl->SetParaAttribs( 0, pOutl->GetEmptyItemSet() );
2442 
2443         // #95114# Always set the object's StyleSheet at the Outliner to
2444         // use the current objects StyleSheet. Thus it's the same as in
2445         // SetText(...).
2446         // #95114# Moved this implementation from where SetObjText(...) was called
2447         // to inside this method to work even when outliner is fetched here.
2448         pOutl->SetStyleSheet(0, pObj->GetStyleSheet());
2449 
2450         String aString;
2451 
2452         switch( eObjKind )
2453         {
2454             case PRESOBJ_OUTLINE:
2455             {
2456                 pOutl->Init( OUTLINERMODE_OUTLINEOBJECT );
2457 
2458                 aString += sal_Unicode( '\t' );
2459                 aString += rString;
2460 
2461                 if (mbMaster)
2462                 {
2463                     pOutl->SetStyleSheet( 0, GetStyleSheetForPresObj(eObjKind) );
2464                     aString += String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\n\t\t" ));
2465                     aString += String ( SdResId( STR_PRESOBJ_MPOUTLLAYER2 ) );
2466 
2467                     aString += String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\n\t\t\t" ));
2468                     aString += String ( SdResId( STR_PRESOBJ_MPOUTLLAYER3 ) );
2469 
2470                     aString += String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\n\t\t\t\t" ));
2471                     aString += String ( SdResId( STR_PRESOBJ_MPOUTLLAYER4 ) );
2472 
2473                     aString += String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\n\t\t\t\t\t" ));
2474                     aString += String ( SdResId( STR_PRESOBJ_MPOUTLLAYER5 ) );
2475 
2476                     aString += String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\n\t\t\t\t\t\t" ));
2477                     aString += String ( SdResId( STR_PRESOBJ_MPOUTLLAYER6 ) );
2478 
2479                     aString += String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\n\t\t\t\t\t\t\t" ));
2480                     aString += String ( SdResId( STR_PRESOBJ_MPOUTLLAYER7 ) );
2481 
2482                     aString += String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\n\t\t\t\t\t\t\t\t" ));
2483                     aString += String ( SdResId( STR_PRESOBJ_MPOUTLLAYER8 ) );
2484 
2485                     aString += String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\n\t\t\t\t\t\t\t\t\t" ));
2486                     aString += String ( SdResId( STR_PRESOBJ_MPOUTLLAYER9 ) );
2487                 }
2488             }
2489             break;
2490 
2491             case PRESOBJ_TITLE:
2492             {
2493                 pOutl->Init( OUTLINERMODE_TITLEOBJECT );
2494                 aString += rString;
2495             }
2496             break;
2497 
2498             default:
2499             {
2500                 pOutl->Init( OUTLINERMODE_TEXTOBJECT );
2501                 aString += rString;
2502 
2503                 // check if we need to add a text field
2504                 SvxFieldData* pData = NULL;
2505 
2506                 switch( eObjKind )
2507                 {
2508                 case PRESOBJ_HEADER:
2509                     pData = new SvxHeaderField();
2510                     break;
2511                 case PRESOBJ_FOOTER:
2512                     pData = new SvxFooterField();
2513                     break;
2514                 case PRESOBJ_SLIDENUMBER:
2515                     pData = new SvxPageField();
2516                     break;
2517                 case PRESOBJ_DATETIME:
2518                     pData = new SvxDateTimeField();
2519                     break;
2520                 default:
2521                     break;
2522                 }
2523 
2524                 if( pData )
2525                 {
2526                     ESelection e;
2527                     SvxFieldItem aField( *pData, EE_FEATURE_FIELD );
2528                     pOutl->QuickInsertField(aField,e);
2529                     delete pData;
2530                 }
2531             }
2532             break;
2533         }
2534 
2535         pOutl->SetPaperSize( pObj->GetLogicRect().GetSize() );
2536 
2537         if( aString.Len() )
2538             pOutl->SetText( aString, pOutl->GetParagraph( 0 ) );
2539 
2540         ( (SdrTextObj*) pObj)->SetOutlinerParaObject( pOutl->CreateParaObject() );
2541 
2542         if (!pOutliner)
2543         {
2544             delete pOutl;
2545             pOutl = NULL;
2546         }
2547         else
2548         {
2549             // Outliner restaurieren
2550             pOutl->Init( nOutlMode );
2551             pOutl->SetParaAttribs( 0, pOutl->GetEmptyItemSet() );
2552             pOutl->SetUpdateMode( bUpdateMode );
2553             pOutl->SetPaperSize( aPaperSize );
2554         }
2555     }
2556 }
2557 
2558 /*************************************************************************
2559 |*
2560 |* Link & Daten von einem VControl empfangen
2561 |*
2562 \************************************************************************/
2563 
2564 void SdPage::SetLinkData(const String&, const String& )
2565 {
2566 }
2567 
2568 /*************************************************************************
2569 |*
2570 |* Layoutname setzen
2571 |*
2572 \************************************************************************/
2573 void SdPage::SetLayoutName(String aName)
2574 {
2575     maLayoutName = aName;
2576 
2577     if( mbMaster )
2578     {
2579         String aSep( RTL_CONSTASCII_USTRINGPARAM(SD_LT_SEPARATOR) );
2580         sal_uInt16 nPos = maLayoutName.Search( aSep );
2581         if ( nPos != STRING_NOTFOUND )
2582         {
2583             FmFormPage::SetName(maLayoutName.Copy(0, nPos));
2584         }
2585     }
2586 }
2587 
2588 
2589 /*************************************************************************
2590 |*
2591 |* Seitenname zurueckgeben und ggf. generieren
2592 |*
2593 \************************************************************************/
2594 
2595 const String& SdPage::GetName() const
2596 {
2597     String aCreatedPageName( maCreatedPageName );
2598     if (GetRealName().Len() == 0)
2599     {
2600         if ((mePageKind == PK_STANDARD || mePageKind == PK_NOTES) && !mbMaster)
2601         {
2602             // default name for handout pages
2603             sal_uInt16  nNum = (GetPageNum() + 1) / 2;
2604 
2605             aCreatedPageName = String(SdResId(STR_PAGE));
2606             aCreatedPageName += sal_Unicode( ' ' );
2607             if( GetModel()->GetPageNumType() == SVX_NUMBER_NONE )
2608             {
2609                 // if the document has number none as a formating
2610                 // for page numbers we still default to arabic numbering
2611                 // to keep the default page names unique
2612                 aCreatedPageName += String::CreateFromInt32( (sal_Int32)nNum );
2613             }
2614             else
2615             {
2616                 aCreatedPageName += ((SdDrawDocument*) GetModel())->CreatePageNumValue(nNum);
2617             }
2618         }
2619         else
2620         {
2621             /******************************************************************
2622             * Defaultname fuer Handzettelseiten
2623             ******************************************************************/
2624             aCreatedPageName = String(SdResId(STR_LAYOUT_DEFAULT_NAME));
2625         }
2626     }
2627     else
2628     {
2629         aCreatedPageName = GetRealName();
2630     }
2631 
2632     if (mePageKind == PK_NOTES)
2633     {
2634         aCreatedPageName += sal_Unicode( ' ' );
2635         aCreatedPageName += String(SdResId(STR_NOTES));
2636     }
2637     else if (mePageKind == PK_HANDOUT && mbMaster)
2638     {
2639         aCreatedPageName += String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( " (" ));
2640         aCreatedPageName += String(SdResId(STR_HANDOUT));
2641         aCreatedPageName += sal_Unicode( ')' );
2642     }
2643 
2644     const_cast< SdPage* >(this)->maCreatedPageName = aCreatedPageName;
2645     return maCreatedPageName;
2646 }
2647 
2648 /*************************************************************************
2649 |*
2650 |*
2651 |*
2652 \************************************************************************/
2653 
2654 void SdPage::SetOrientation( Orientation eOrient)
2655 {
2656     meOrientation = eOrient;
2657 }
2658 
2659 /*************************************************************************
2660 |*
2661 |*
2662 |*
2663 \************************************************************************/
2664 
2665 Orientation SdPage::GetOrientation() const
2666 {
2667     return meOrientation;
2668 }
2669 
2670 /*************************************************************************
2671 |*
2672 |* Liefert den Default-Text eines PresObjektes zurueck
2673 |*
2674 \************************************************************************/
2675 
2676 String SdPage::GetPresObjText(PresObjKind eObjKind) const
2677 {
2678     String aString;
2679 
2680     if (eObjKind == PRESOBJ_TITLE)
2681     {
2682         if (mbMaster)
2683         {
2684             if (mePageKind != PK_NOTES)
2685             {
2686                 aString = String ( SdResId( STR_PRESOBJ_MPTITLE ) );
2687             }
2688             else
2689             {
2690                 aString = String ( SdResId( STR_PRESOBJ_MPNOTESTITLE ) );
2691             }
2692         }
2693         else
2694         {
2695             aString = String ( SdResId( STR_PRESOBJ_TITLE ) );
2696         }
2697     }
2698     else if (eObjKind == PRESOBJ_OUTLINE)
2699     {
2700         if (mbMaster)
2701         {
2702             aString = String ( SdResId( STR_PRESOBJ_MPOUTLINE ) );
2703         }
2704         else
2705         {
2706             aString = String ( SdResId( STR_PRESOBJ_OUTLINE ) );
2707         }
2708     }
2709     else if (eObjKind == PRESOBJ_NOTES)
2710     {
2711         if (mbMaster)
2712         {
2713             aString = String ( SdResId( STR_PRESOBJ_MPNOTESTEXT ) );
2714         }
2715         else
2716         {
2717             aString = String ( SdResId( STR_PRESOBJ_NOTESTEXT ) );
2718         }
2719     }
2720     else if (eObjKind == PRESOBJ_TEXT)
2721     {
2722         aString = String ( SdResId( STR_PRESOBJ_TEXT ) );
2723     }
2724     else if (eObjKind == PRESOBJ_GRAPHIC)
2725     {
2726         aString = String ( SdResId( STR_PRESOBJ_GRAPHIC ) );
2727     }
2728     else if (eObjKind == PRESOBJ_OBJECT)
2729     {
2730         aString = String ( SdResId( STR_PRESOBJ_OBJECT ) );
2731     }
2732     else if (eObjKind == PRESOBJ_CHART)
2733     {
2734         aString = String ( SdResId( STR_PRESOBJ_CHART ) );
2735     }
2736     else if (eObjKind == PRESOBJ_ORGCHART)
2737     {
2738         aString = String ( SdResId( STR_PRESOBJ_ORGCHART ) );
2739     }
2740     else if (eObjKind == PRESOBJ_CALC)
2741     {
2742         aString = String ( SdResId( STR_PRESOBJ_TABLE ) );
2743     }
2744 
2745     return(aString);
2746 }
2747 
2748 extern uno::Reference< uno::XInterface > createUnoPageImpl( SdPage* pPage );
2749 
2750 uno::Reference< uno::XInterface > SdPage::createUnoPage()
2751 {
2752     return createUnoPageImpl( this );
2753 }
2754 
2755 /** returns the SdPage implementation for the given XDrawPage or 0 if not available */
2756 SdPage* SdPage::getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& xPage )
2757 {
2758     try
2759     {
2760         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUnoTunnel( xPage, ::com::sun::star::uno::UNO_QUERY );
2761         if( xUnoTunnel.is() )
2762         {
2763             SvxDrawPage* pUnoPage = reinterpret_cast<SvxDrawPage*>(sal::static_int_cast<sal_uIntPtr>(xUnoTunnel->getSomething( SvxDrawPage::getUnoTunnelId()) ) );
2764             if( pUnoPage )
2765                 return static_cast< SdPage* >( pUnoPage->GetSdrPage() );
2766         }
2767     }
2768     catch( ::com::sun::star::uno::Exception& e )
2769     {
2770         (void)e;
2771         DBG_ERROR("sd::SdPage::getImplementation(), exception cathced!" );
2772     }
2773 
2774     return 0;
2775 }
2776 
2777 void SdPage::SetName (const String& rName)
2778 {
2779     String aOldName = GetName();
2780     FmFormPage::SetName (rName);
2781     static_cast<SdDrawDocument*>(pModel)->UpdatePageRelativeURLs(aOldName, rName);
2782     ActionChanged();
2783 }
2784 
2785 const HeaderFooterSettings& SdPage::getHeaderFooterSettings() const
2786 {
2787     if( mePageKind == PK_HANDOUT && !mbMaster )
2788     {
2789         return (((SdPage&)TRG_GetMasterPage()).maHeaderFooterSettings);
2790     }
2791     else
2792     {
2793         return maHeaderFooterSettings;
2794     }
2795 }
2796 
2797 void SdPage::setHeaderFooterSettings( const sd::HeaderFooterSettings& rNewSettings )
2798 {
2799     if( mePageKind == PK_HANDOUT && !mbMaster )
2800     {
2801         (((SdPage&)TRG_GetMasterPage()).maHeaderFooterSettings) = rNewSettings;
2802     }
2803     else
2804     {
2805         maHeaderFooterSettings = rNewSettings;
2806     }
2807 
2808     SetChanged();
2809     if(TRG_HasMasterPage())
2810     {
2811         TRG_GetMasterPageDescriptorViewContact().ActionChanged();
2812     }
2813 }
2814 
2815 bool SdPage::checkVisibility(
2816     const sdr::contact::ViewObjectContact& rOriginal,
2817     const sdr::contact::DisplayInfo& rDisplayInfo,
2818     bool bEdit )
2819 {
2820     if( !FmFormPage::checkVisibility( rOriginal, rDisplayInfo, bEdit ) )
2821         return false;
2822 
2823     SdrObject* pObj = rOriginal.GetViewContact().TryToGetSdrObject();
2824     if( pObj == NULL )
2825         return false;
2826 
2827     const SdrPage* pVisualizedPage = GetSdrPageFromXDrawPage(rOriginal.GetObjectContact().getViewInformation2D().getVisualizedPage());
2828     const bool bIsPrinting(rOriginal.GetObjectContact().isOutputToPrinter() || rOriginal.GetObjectContact().isOutputToPDFFile());
2829     const SdrPageView* pPageView = rOriginal.GetObjectContact().TryToGetSdrPageView();
2830     const bool bIsInsidePageObj(pPageView && pPageView->GetPage() != pVisualizedPage);
2831 
2832     // empty presentation objects only visible during edit mode
2833     if( (bIsPrinting || !bEdit || bIsInsidePageObj ) && pObj->IsEmptyPresObj() )
2834     {
2835         if( (pObj->GetObjInventor() != SdrInventor) || ( (pObj->GetObjIdentifier() != OBJ_RECT) && (pObj->GetObjIdentifier() != OBJ_PAGE) ) )
2836             return false;
2837     }
2838 
2839     if( ( pObj->GetObjInventor() == SdrInventor ) && ( pObj->GetObjIdentifier() == OBJ_TEXT ) )
2840     {
2841         const SdPage* pCheckPage = dynamic_cast< const SdPage* >(pObj->GetPage());
2842 
2843         if( pCheckPage )
2844         {
2845             PresObjKind eKind = pCheckPage->GetPresObjKind(pObj);
2846 
2847             if((eKind == PRESOBJ_FOOTER) || (eKind == PRESOBJ_HEADER) || (eKind == PRESOBJ_DATETIME) || (eKind == PRESOBJ_SLIDENUMBER) )
2848             {
2849                 const bool bSubContentProcessing(rDisplayInfo.GetSubContentActive());
2850 
2851                 if( bSubContentProcessing || ( pCheckPage->GetPageKind() == PK_HANDOUT && bIsPrinting ) )
2852                 {
2853                     // use the page that is currently processed
2854                     const SdPage* pVisualizedSdPage = dynamic_cast< const SdPage* >(pVisualizedPage);
2855 
2856                     if( pVisualizedSdPage )
2857                     {
2858                         // if we are not on a masterpage, see if we have to draw this header&footer object at all
2859                         const sd::HeaderFooterSettings& rSettings = pVisualizedSdPage->getHeaderFooterSettings();
2860 
2861                         switch( eKind )
2862                         {
2863                         case PRESOBJ_FOOTER:
2864                             return rSettings.mbFooterVisible;
2865                         case PRESOBJ_HEADER:
2866                             return rSettings.mbHeaderVisible;
2867                         case PRESOBJ_DATETIME:
2868                             return rSettings.mbDateTimeVisible;
2869                         case PRESOBJ_SLIDENUMBER:
2870                             return rSettings.mbSlideNumberVisible;
2871                         default:
2872                             break;
2873                         }
2874                     }
2875                 }
2876             } // check for placeholders on master
2877             else if( (eKind != PRESOBJ_NONE) && pCheckPage->IsMasterPage() && ( pVisualizedPage != pCheckPage ) )
2878             {
2879                 // presentation objects on master slide are always invisible if slide is shown.
2880                 return false;
2881             }
2882         }
2883     }
2884 
2885     // i63977, do not print SdrpageObjs from master pages
2886     if( ( pObj->GetObjInventor() == SdrInventor ) && ( pObj->GetObjIdentifier() == OBJ_PAGE ) )
2887     {
2888         if( pObj->GetPage() && pObj->GetPage()->IsMasterPage() )
2889             return false;
2890     }
2891 
2892     return true;
2893 }
2894 
2895 bool SdPage::RestoreDefaultText( SdrObject* pObj )
2896 {
2897     bool bRet = false;
2898 
2899     SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( pObj );
2900 
2901     if( pTextObj )
2902     {
2903         PresObjKind ePresObjKind = GetPresObjKind(pTextObj);
2904 
2905         if (ePresObjKind == PRESOBJ_TITLE   ||
2906             ePresObjKind == PRESOBJ_OUTLINE ||
2907             ePresObjKind == PRESOBJ_NOTES   ||
2908             ePresObjKind == PRESOBJ_TEXT)
2909         {
2910             String aString( GetPresObjText(ePresObjKind) );
2911 
2912             if (aString.Len())
2913             {
2914                 sal_Bool bVertical = sal_False;
2915                 OutlinerParaObject* pOldPara = pTextObj->GetOutlinerParaObject();
2916                 if( pOldPara )
2917                     bVertical = pOldPara->IsVertical();  // is old para object vertical?
2918 
2919                 SetObjText( pTextObj, 0, ePresObjKind, aString );
2920 
2921                 if( pOldPara )
2922                 {
2923                     //pTextObj->SetVerticalWriting( bVertical );
2924                     //
2925                     // #94826# Here, only the vertical flag for the
2926                     // OutlinerParaObjects needs to be changed. The
2927                     // AutoGrowWidth/Height items still exist in the
2928                     // not changed object.
2929                     if(pTextObj
2930                         && pTextObj->GetOutlinerParaObject()
2931                         && pTextObj->GetOutlinerParaObject()->IsVertical() != (bool)bVertical)
2932                     {
2933                         Rectangle aObjectRect = pTextObj->GetSnapRect();
2934                         pTextObj->GetOutlinerParaObject()->SetVertical(bVertical);
2935                         pTextObj->SetSnapRect(aObjectRect);
2936                     }
2937                 }
2938 
2939                 pTextObj->SetTextEditOutliner( NULL );  // to make stylesheet settings work
2940                 pTextObj->NbcSetStyleSheet( GetStyleSheetForPresObj(ePresObjKind), sal_True );
2941                 pTextObj->SetEmptyPresObj(sal_True);
2942                 bRet = true;
2943             }
2944         }
2945     }
2946     return bRet;
2947 }
2948 
2949 void SdPage::CalculateHandoutAreas( SdDrawDocument& rModel, AutoLayout eLayout, bool bHorizontal, std::vector< Rectangle >& rAreas )
2950 {
2951     SdPage& rHandoutMaster = *rModel.GetMasterSdPage( 0, PK_HANDOUT );
2952 
2953     if( eLayout == AUTOLAYOUT_NONE )
2954     {
2955         // use layout from handout master
2956         SdrObjListIter aShapeIter (rHandoutMaster);
2957         while (aShapeIter.IsMore())
2958         {
2959             SdrPageObj* pPageObj = dynamic_cast<SdrPageObj*>(aShapeIter.Next());
2960             if (pPageObj)
2961                 rAreas.push_back( pPageObj->GetCurrentBoundRect() );
2962         }
2963     }
2964     else
2965     {
2966         Size    aArea = rHandoutMaster.GetSize();
2967 
2968         const long nGapW = 1000; // gap is 1cm
2969         const long nGapH = 1000;
2970 
2971         long nLeftBorder = rHandoutMaster.GetLftBorder();
2972         long nRightBorder = rHandoutMaster.GetRgtBorder();
2973         long nTopBorder = rHandoutMaster.GetUppBorder();
2974         long nBottomBorder = rHandoutMaster.GetLwrBorder();
2975 
2976         const long nHeaderFooterHeight = static_cast< long >( (aArea.Height() - nTopBorder - nLeftBorder) * 0.05  );
2977 
2978         nTopBorder += nHeaderFooterHeight;
2979         nBottomBorder += nHeaderFooterHeight;
2980 
2981         long nX = nGapW + nLeftBorder;
2982         long nY = nGapH + nTopBorder;
2983 
2984         aArea.Width() -= nGapW * 2 + nLeftBorder + nRightBorder;
2985         aArea.Height() -= nGapH * 2 + nTopBorder + nBottomBorder;
2986 
2987         const bool bLandscape = aArea.Width() > aArea.Height();
2988 
2989         static sal_uInt16 aOffsets[5][9] =
2990         {
2991             { 0, 1, 2, 3, 4, 5, 6, 7, 8 }, // AUTOLAYOUT_HANDOUT9, Portrait, Horizontal order
2992             { 0, 2, 4, 1, 3, 5, 0, 0, 0 }, // AUTOLAYOUT_HANDOUT3, Landscape, Vertical
2993             { 0, 2, 1, 3, 0, 0, 0, 0, 0 }, // AUTOLAYOUT_HANDOUT4, Landscape, Vertical
2994             { 0, 3, 1, 4, 2, 5, 0, 0, 0 }, // AUTOLAYOUT_HANDOUT4, Portrait, Vertical
2995             { 0, 3, 6, 1, 4, 7, 2, 5, 8 }, // AUTOLAYOUT_HANDOUT9, Landscape, Vertical
2996         };
2997 
2998         sal_uInt16* pOffsets = aOffsets[0];
2999         sal_uInt16  nColCnt = 0, nRowCnt = 0;
3000         switch ( eLayout )
3001         {
3002             case AUTOLAYOUT_HANDOUT1:
3003                 nColCnt = 1; nRowCnt = 1;
3004                 break;
3005 
3006             case AUTOLAYOUT_HANDOUT2:
3007                 if( bLandscape )
3008                 {
3009                     nColCnt = 2; nRowCnt = 1;
3010                 }
3011                 else
3012                 {
3013                     nColCnt = 1; nRowCnt = 2;
3014                 }
3015                 break;
3016 
3017             case AUTOLAYOUT_HANDOUT3:
3018                 if( bLandscape )
3019                 {
3020                     nColCnt = 3; nRowCnt = 2;
3021                 }
3022                 else
3023                 {
3024                     nColCnt = 2; nRowCnt = 3;
3025                 }
3026                 pOffsets = aOffsets[ bLandscape ? 1 : 0 ];
3027                 break;
3028 
3029             case AUTOLAYOUT_HANDOUT4:
3030                 nColCnt = 2; nRowCnt = 2;
3031                 pOffsets = aOffsets[ bHorizontal ? 0 : 2 ];
3032                 break;
3033 
3034             case AUTOLAYOUT_HANDOUT6:
3035                 if( bLandscape )
3036                 {
3037                     nColCnt = 3; nRowCnt = 2;
3038                 }
3039                 else
3040                 {
3041                     nColCnt = 2; nRowCnt = 3;
3042                 }
3043                 if( !bHorizontal )
3044                     pOffsets = aOffsets[ bLandscape ? 1 : 3 ];
3045                 break;
3046 
3047             default:
3048             case AUTOLAYOUT_HANDOUT9:
3049                 nColCnt = 3; nRowCnt = 3;
3050 
3051                 if( !bHorizontal )
3052                     pOffsets = aOffsets[4];
3053                 break;
3054         }
3055 
3056         rAreas.resize( nColCnt * nRowCnt );
3057 
3058         Size aPartArea, aSize;
3059         aPartArea.Width()  = ((aArea.Width()  - ((nColCnt-1) * nGapW) ) / nColCnt);
3060         aPartArea.Height() = ((aArea.Height() - ((nRowCnt-1) * nGapH) ) / nRowCnt);
3061 
3062         SdrPage* pFirstPage = rModel.GetMasterSdPage(0, PK_STANDARD);
3063         if ( pFirstPage )
3064         {
3065             // scale actual size into handout rect
3066             double fScale = (double)aPartArea.Width() / (double)pFirstPage->GetWdt();
3067 
3068             aSize.Height() = (long)(fScale * pFirstPage->GetHgt() );
3069             if( aSize.Height() > aPartArea.Height() )
3070             {
3071                 fScale = (double)aPartArea.Height() / (double)pFirstPage->GetHgt();
3072                 aSize.Height() = aPartArea.Height();
3073                 aSize.Width() = (long)(fScale * pFirstPage->GetWdt());
3074             }
3075             else
3076             {
3077                 aSize.Width() = aPartArea.Width();
3078             }
3079 
3080             nX += (aPartArea.Width() - aSize.Width()) / 2;
3081             nY += (aPartArea.Height()- aSize.Height())/ 2;
3082         }
3083         else
3084         {
3085             aSize = aPartArea;
3086         }
3087 
3088         Point aPos( nX, nY );
3089 
3090         const bool bRTL = rModel.GetDefaultWritingMode() == ::com::sun::star::text::WritingMode_RL_TB;
3091 
3092         const long nOffsetX = (aPartArea.Width() + nGapW) * (bRTL ? -1 : 1);
3093         const long nOffsetY = aPartArea.Height() + nGapH;
3094         const long nStartX = bRTL ? nOffsetX*(1 - nColCnt) - nX : nX;
3095 
3096         for(sal_uInt16 nRow = 0; nRow < nRowCnt; nRow++)
3097         {
3098             aPos.X() = nStartX;
3099             for(sal_uInt16 nCol = 0; nCol < nColCnt; nCol++)
3100             {
3101                 rAreas[*pOffsets++] = Rectangle(aPos, aSize);
3102                 aPos.X() += nOffsetX;
3103             }
3104 
3105             aPos.Y() += nOffsetY;
3106         }
3107     }
3108 }
3109 
3110 
3111 
3112 
3113 void SdPage::SetPrecious (const bool bIsPrecious)
3114 {
3115     mbIsPrecious = bIsPrecious;
3116 }
3117 
3118 
3119 
3120 
3121 bool SdPage::IsPrecious (void) const
3122 {
3123     return mbIsPrecious;
3124 }
3125 
3126 
3127 
3128 
3129 HeaderFooterSettings::HeaderFooterSettings()
3130 {
3131     mbHeaderVisible = true;
3132     mbFooterVisible = true;
3133     mbSlideNumberVisible = false;
3134     mbDateTimeVisible = true;
3135     mbDateTimeIsFixed = true;
3136     meDateTimeFormat = SVXDATEFORMAT_A;
3137 }
3138 
3139 bool HeaderFooterSettings::operator==( const HeaderFooterSettings& rSettings ) const
3140 {
3141     return (mbHeaderVisible == rSettings.mbHeaderVisible) &&
3142            (maHeaderText == rSettings.maHeaderText) &&
3143            (mbFooterVisible == rSettings.mbFooterVisible) &&
3144            (maFooterText == rSettings.maFooterText) &&
3145            (mbSlideNumberVisible == rSettings.mbSlideNumberVisible) &&
3146            (mbDateTimeVisible == rSettings.mbDateTimeVisible) &&
3147            (mbDateTimeIsFixed == rSettings.mbDateTimeIsFixed) &&
3148            (meDateTimeFormat == rSettings.meDateTimeFormat) &&
3149            (maDateTimeText == rSettings.maDateTimeText);
3150 }
3151 
3152