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