xref: /aoo41x/main/sd/source/core/sdpage.cxx (revision 79aad27f)
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;
797 			while( (pObj = pMasterPage->GetPresObj(PRESOBJ_HANDOUT)) != 0 )
798 			{
799 				if( bUndo )
800 					pUndoManager->AddUndoAction(pModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pObj));
801 
802 				pMasterPage->RemoveObject(pObj->GetOrdNum());
803 			}
804 
805 			std::vector< Rectangle > aAreas;
806 			CalculateHandoutAreas( *static_cast< SdDrawDocument* >(GetModel() ), pMasterPage->GetAutoLayout(), false, aAreas );
807 
808 			const bool bSkip = pMasterPage->GetAutoLayout() == AUTOLAYOUT_HANDOUT3;
809 			std::vector< Rectangle >::iterator iter( aAreas.begin() );
810 
811             while( iter != aAreas.end() )
812 			{
813 				SdrPageObj* pPageObj = static_cast<SdrPageObj*>(pMasterPage->CreatePresObj(PRESOBJ_HANDOUT, sal_False, (*iter++), sal_True) );
814                 // #i105146# We want no content to be displayed for PK_HANDOUT,
815                 // so just never set a page as content
816                 pPageObj->SetReferencedPage(0L);
817 
818 				if( bSkip && iter != aAreas.end() )
819 					iter++;
820 			}
821 		}
822 
823 		if( mePageKind != PK_HANDOUT )
824 		{
825 			SdrObject* pMasterTitle = pMasterPage->GetPresObj( PRESOBJ_TITLE );
826 			if( pMasterTitle == NULL )
827 				pMasterPage->CreateDefaultPresObj(PRESOBJ_TITLE, true);
828 
829 			SdrObject* pMasterOutline = pMasterPage->GetPresObj( mePageKind==PK_NOTES ? PRESOBJ_NOTES : PRESOBJ_OUTLINE );
830 			if( pMasterOutline == NULL )
831 				pMasterPage->CreateDefaultPresObj( mePageKind == PK_STANDARD ? PRESOBJ_OUTLINE : PRESOBJ_NOTES, true );
832 		}
833 
834 		// create header&footer objects
835 
836 		if( bCreate )
837 		{
838 			if( mePageKind != PK_STANDARD )
839 			{
840 				SdrObject* pHeader = pMasterPage->GetPresObj( PRESOBJ_HEADER );
841 				if( pHeader == NULL )
842 					pMasterPage->CreateDefaultPresObj( PRESOBJ_HEADER, true );
843 			}
844 
845 			SdrObject* pDate   = pMasterPage->GetPresObj( PRESOBJ_DATETIME );
846 			if( pDate == NULL )
847 				pMasterPage->CreateDefaultPresObj( PRESOBJ_DATETIME, true );
848 
849 			SdrObject* pFooter = pMasterPage->GetPresObj( PRESOBJ_FOOTER );
850 			if( pFooter == NULL )
851 				pMasterPage->CreateDefaultPresObj( PRESOBJ_FOOTER, true );
852 
853 			SdrObject* pNumber = pMasterPage->GetPresObj( PRESOBJ_SLIDENUMBER );
854 			if( pNumber == NULL )
855 				pMasterPage->CreateDefaultPresObj( PRESOBJ_SLIDENUMBER, true );
856 		}
857 	}
858 }
859 
860 SdrObject* SdPage::CreateDefaultPresObj(PresObjKind eObjKind, bool bInsert)
861 {
862 	if( eObjKind == PRESOBJ_TITLE )
863 	{
864 		Rectangle aTitleRect( GetTitleRect() );
865 		return CreatePresObj(PRESOBJ_TITLE, sal_False, aTitleRect, bInsert);
866 	}
867 	else if( eObjKind == PRESOBJ_OUTLINE )
868 	{
869 		Rectangle aLayoutRect( GetLayoutRect() );
870 		return CreatePresObj( PRESOBJ_OUTLINE, sal_False, aLayoutRect, bInsert);
871 	}
872 	else if( eObjKind == PRESOBJ_NOTES )
873 	{
874 		Rectangle aLayoutRect( GetLayoutRect() );
875 		return CreatePresObj( PRESOBJ_NOTES, sal_False, aLayoutRect, bInsert);
876 	}
877 	else if( (eObjKind == PRESOBJ_FOOTER) || (eObjKind == PRESOBJ_DATETIME) || (eObjKind == PRESOBJ_SLIDENUMBER) || (eObjKind == PRESOBJ_HEADER ) )
878 	{
879 		// create footer objects for standard master page
880 		if( mePageKind == PK_STANDARD )
881 		{
882 			const long nLftBorder = GetLftBorder();
883 			const long nUppBorder = GetUppBorder();
884 
885 			Point aTitlePos ( nLftBorder, nUppBorder );
886 			Size aPageSize ( GetSize() );
887 			aPageSize.Width()  -= nLftBorder + GetRgtBorder();
888 			aPageSize.Height() -= nUppBorder + GetLwrBorder();
889 
890 			const int Y = long(nUppBorder + aPageSize.Height() * 0.911);
891 			const int W1 = long(aPageSize.Width() * 0.233);
892 			const int W2 = long(aPageSize.Width() * 0.317);
893 			const int H = long(aPageSize.Height() * 0.069);
894 
895 			if( eObjKind == PRESOBJ_DATETIME )
896 			{
897 				Point aPos( long(nLftBorder+(aPageSize.Width()*0.05)), Y );
898 				Size aSize( W1, H );
899 				Rectangle aRect( aPos, aSize );
900 				return CreatePresObj( PRESOBJ_DATETIME, sal_False, aRect, bInsert );
901 			}
902 			else if( eObjKind == PRESOBJ_FOOTER )
903 			{
904 				Point aPos( long(nLftBorder+ aPageSize.Width() * 0.342), Y );
905 				Size aSize( W2, H );
906 				Rectangle aRect( aPos, aSize );
907 				return CreatePresObj( PRESOBJ_FOOTER, sal_False, aRect, bInsert );
908 			}
909 			else if( eObjKind == PRESOBJ_SLIDENUMBER )
910 			{
911 				Point aPos( long(nLftBorder+(aPageSize.Width()*0.717)), Y );
912 				Size aSize( W1, H );
913 				Rectangle aRect( aPos, aSize );
914 				return CreatePresObj( PRESOBJ_SLIDENUMBER, sal_False, aRect, bInsert );
915 			}
916 			else
917 			{
918 				DBG_ERROR( "SdPage::CreateDefaultPresObj() - can't create a header placeholder for a slide master" );
919 				return NULL;
920 			}
921 		}
922 		else
923 		{
924 			// create header&footer objects for handout and notes master
925 			Point aTitlePos ( GetLftBorder(), GetUppBorder() );
926 			Size aPageSize ( GetSize() );
927 			aPageSize.Width()  -= GetLftBorder() + GetRgtBorder();
928 			aPageSize.Height() -= GetUppBorder() + GetLwrBorder();
929 
930 
931 			const int NOTES_HEADER_FOOTER_WIDTH = long(aPageSize.Width() * 0.434);
932 			const int NOTES_HEADER_FOOTER_HEIGHT = long(aPageSize.Height() * 0.05);
933 
934 			Size aSize( NOTES_HEADER_FOOTER_WIDTH, NOTES_HEADER_FOOTER_HEIGHT );
935 
936 			const int X1 = GetLftBorder();
937 			const int X2 = GetLftBorder() + long(aPageSize.Width() - NOTES_HEADER_FOOTER_WIDTH);
938 			const int Y1 = GetUppBorder();
939 			const int Y2 = GetUppBorder() + long(aPageSize.Height() - NOTES_HEADER_FOOTER_HEIGHT );
940 
941 			if( eObjKind == PRESOBJ_HEADER )
942 			{
943 				Point aPos( X1, Y1 );
944 				Rectangle aRect( aPos, aSize );
945 				return CreatePresObj( PRESOBJ_HEADER, sal_False, aRect, bInsert );
946 			}
947 			else if( eObjKind == PRESOBJ_DATETIME )
948 			{
949 				Point aPos( X2, Y1 );
950 				Rectangle aRect( aPos, aSize );
951 				return CreatePresObj( PRESOBJ_DATETIME, sal_False, aRect, bInsert );
952 			}
953 			else if( eObjKind == PRESOBJ_FOOTER )
954 			{
955 				Point aPos( X1, Y2 );
956 				Rectangle aRect( aPos, aSize );
957 				return CreatePresObj( PRESOBJ_FOOTER, sal_False, aRect, bInsert );
958 			}
959 			else if( eObjKind == PRESOBJ_SLIDENUMBER )
960 			{
961 				Point aPos( X2, Y2 );
962 				Rectangle aRect( aPos, aSize );
963 				return CreatePresObj( PRESOBJ_SLIDENUMBER, sal_False, aRect, bInsert );
964 			}
965 
966 			DBG_ERROR("SdPage::CreateDefaultPresObj() - this should not happen!");
967 			return NULL;
968 		}
969 	}
970 	else
971 	{
972 		DBG_ERROR("SdPage::CreateDefaultPresObj() - unknown PRESOBJ kind" );
973 		return NULL;
974 	}
975 }
976 
977 /*************************************************************************
978 |*
979 |* Titelbereich zurueckgeben
980 |*
981 \************************************************************************/
982 
983 Rectangle SdPage::GetTitleRect() const
984 {
985 	Rectangle aTitleRect;
986 
987 	if (mePageKind != PK_HANDOUT)
988 	{
989 		/******************************************************************
990 		* Standard- oder Notiz-Seite: Titelbereich
991 		******************************************************************/
992 		Point aTitlePos ( GetLftBorder(), GetUppBorder() );
993 		Size aTitleSize ( GetSize() );
994 		aTitleSize.Width()  -= GetLftBorder() + GetRgtBorder();
995 		aTitleSize.Height() -= GetUppBorder() + GetLwrBorder();
996 
997 		if (mePageKind == PK_STANDARD)
998 		{
999 			aTitlePos.X() += long( aTitleSize.Width() * 0.05 );
1000 			aTitlePos.Y() += long( aTitleSize.Height() * 0.0399 );
1001 			aTitleSize.Width() = long( aTitleSize.Width() * 0.9 );
1002 			aTitleSize.Height() = long( aTitleSize.Height() * 0.167 );
1003 		}
1004 		else if (mePageKind == PK_NOTES)
1005 		{
1006 			Point aPos = aTitlePos;
1007 			aPos.Y() += long( aTitleSize.Height() * 0.076 );
1008 
1009 			// Hoehe beschraenken
1010 			aTitleSize.Height() = (long) (aTitleSize.Height() * 0.375);
1011 
1012 			Size aPartArea = aTitleSize;
1013 			Size aSize;
1014 			sal_uInt16 nDestPageNum(GetPageNum());
1015 			SdrPage* pRefPage = 0L;
1016 
1017 			if(nDestPageNum)
1018 			{
1019 				// only decrement if != 0, else we get 0xffff
1020 				nDestPageNum -= 1;
1021 			}
1022 
1023 			if(nDestPageNum < pModel->GetPageCount())
1024 			{
1025 				pRefPage = pModel->GetPage(nDestPageNum);
1026 			}
1027 
1028 			if ( pRefPage )
1029 			{
1030 				// tatsaechliche Seitengroesse in das Handout-Rechteck skalieren
1031 				double fH = (double) aPartArea.Width()  / pRefPage->GetWdt();
1032 				double fV = (double) aPartArea.Height() / pRefPage->GetHgt();
1033 
1034 				if ( fH > fV )
1035 					fH = fV;
1036 				aSize.Width()  = (long) (fH * pRefPage->GetWdt());
1037 				aSize.Height() = (long) (fH * pRefPage->GetHgt());
1038 
1039 				aPos.X() += (aPartArea.Width() - aSize.Width()) / 2;
1040 				aPos.Y() += (aPartArea.Height()- aSize.Height())/ 2;
1041 			}
1042 
1043 			aTitlePos = aPos;
1044 			aTitleSize = aSize;
1045 		}
1046 
1047 		aTitleRect.SetPos(aTitlePos);
1048 		aTitleRect.SetSize(aTitleSize);
1049 	}
1050 
1051 	return aTitleRect;
1052 }
1053 
1054 
1055 /*************************************************************************
1056 |*
1057 |* Gliederungsbereich zurueckgeben
1058 |*
1059 \************************************************************************/
1060 
1061 Rectangle SdPage::GetLayoutRect() const
1062 {
1063 	Rectangle aLayoutRect;
1064 
1065 	if (mePageKind != PK_HANDOUT)
1066 	{
1067 		Point aLayoutPos ( GetLftBorder(), GetUppBorder() );
1068 		Size aLayoutSize ( GetSize() );
1069 		aLayoutSize.Width()  -= GetLftBorder() + GetRgtBorder();
1070 		aLayoutSize.Height() -= GetUppBorder() + GetLwrBorder();
1071 
1072 		if (mePageKind == PK_STANDARD)
1073 		{
1074 			aLayoutPos.X() += long( aLayoutSize.Width() * 0.05 );
1075 			aLayoutPos.Y() += long( aLayoutSize.Height() * 0.234 );
1076 			aLayoutSize.Width() = long( aLayoutSize.Width() * 0.9 );
1077 			aLayoutSize.Height() = long( aLayoutSize.Height() * 0.66 );
1078 			aLayoutRect.SetPos(aLayoutPos);
1079 			aLayoutRect.SetSize(aLayoutSize);
1080 		}
1081 		else if (mePageKind == PK_NOTES)
1082 		{
1083 			aLayoutPos.X() += long( aLayoutSize.Width() * 0.1 );
1084 			aLayoutPos.Y() += long( aLayoutSize.Height() * 0.475 );
1085 			aLayoutSize.Width() = long( aLayoutSize.Width() * 0.8 );
1086 			aLayoutSize.Height() = long( aLayoutSize.Height() * 0.45 );
1087 			aLayoutRect.SetPos(aLayoutPos);
1088 			aLayoutRect.SetSize(aLayoutSize);
1089 		}
1090 	}
1091 
1092 	return aLayoutRect;
1093 }
1094 
1095 
1096 /**************************************************************************
1097 |*
1098 |* Diese Methode weist ein AutoLayout zu
1099 |*
1100 \*************************************************************************/
1101 
1102 const int MAX_PRESOBJS = 7;	// maximum number of presentation objects per layout
1103 const int VERTICAL = 0x8000;
1104 
1105 struct LayoutDescriptor
1106 {
1107 	int mnLayout;
1108 	PresObjKind meKind[MAX_PRESOBJS];
1109 	bool mbVertical[MAX_PRESOBJS];
1110 
1111 	LayoutDescriptor( int nLayout, int k0 = 0, int k1 = 0, int k2 = 0, int k3 = 0, int k4 = 0, int k5 = 0, int k6 = 0 );
1112 };
1113 
1114 LayoutDescriptor::LayoutDescriptor( int nLayout, int k0, int k1, int k2, int k3, int k4, int k5, int k6 )
1115 : mnLayout( nLayout )
1116 {
1117 	meKind[0] = static_cast<PresObjKind>(k0 & (~VERTICAL)); mbVertical[0] = (k0 & VERTICAL) == VERTICAL;
1118 	meKind[1] = static_cast<PresObjKind>(k1 & (~VERTICAL)); mbVertical[1] = (k1 & VERTICAL) == VERTICAL;
1119 	meKind[2] = static_cast<PresObjKind>(k2 & (~VERTICAL)); mbVertical[2] = (k2 & VERTICAL) == VERTICAL;
1120 	meKind[3] = static_cast<PresObjKind>(k3 & (~VERTICAL)); mbVertical[3] = (k3 & VERTICAL) == VERTICAL;
1121 	meKind[4] = static_cast<PresObjKind>(k4 & (~VERTICAL)); mbVertical[4] = (k4 & VERTICAL) == VERTICAL;
1122     meKind[5] = static_cast<PresObjKind>(k5 & (~VERTICAL)); mbVertical[5] = (k5 & VERTICAL) == VERTICAL;
1123 	meKind[6] = static_cast<PresObjKind>(k6 & (~VERTICAL)); mbVertical[6] = (k6	& VERTICAL) == VERTICAL;
1124 }
1125 
1126 static const LayoutDescriptor& GetLayoutDescriptor( AutoLayout eLayout )
1127 {
1128 	static LayoutDescriptor aLayouts[AUTOLAYOUT__END-AUTOLAYOUT__START] =
1129 	{
1130 		LayoutDescriptor( 0, PRESOBJ_TITLE, PRESOBJ_TEXT ),									// AUTOLAYOUT_TITLE
1131 		LayoutDescriptor( 0, PRESOBJ_TITLE, PRESOBJ_OUTLINE ),								// AUTOLAYOUT_ENUM
1132 		LayoutDescriptor( 0, PRESOBJ_TITLE, PRESOBJ_OUTLINE ),								// AUTOLAYOUT_CHART
1133 		LayoutDescriptor( 1, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),				// AUTOLAYOUT_2TEXT
1134 		LayoutDescriptor( 1, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),				// AUTOLAYOUT_TEXTCHART
1135 		LayoutDescriptor( 0, PRESOBJ_TITLE, PRESOBJ_OUTLINE ),								// AUTOLAYOUT_ORG
1136 		LayoutDescriptor( 1, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),				// AUTOLAYOUT_TEXTCLbIP
1137 		LayoutDescriptor( 1, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),				// AUTOLAYOUT_CHARTTEXT
1138 		LayoutDescriptor( 0, PRESOBJ_TITLE, PRESOBJ_OUTLINE ),								// AUTOLAYOUT_TAB
1139 		LayoutDescriptor( 1, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),				// AUTOLAYOUT_CLIPTEXT
1140 		LayoutDescriptor( 1, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),				// AUTOLAYOUT_TEXTOBJ
1141 		LayoutDescriptor( 0, PRESOBJ_TITLE, PRESOBJ_OBJECT ),								// AUTOLAYOUT_OBJ
1142 		LayoutDescriptor( 2, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),	// AUTOLAYOUT_TEXT2OBJ
1143 		LayoutDescriptor( 1, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),				// AUTOLAYOUT_TEXTOBJ
1144 		LayoutDescriptor( 4, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),				// AUTOLAYOUT_OBJOVERTEXT
1145 		LayoutDescriptor( 3, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),	// AUTOLAYOUT_2OBJTEXT
1146 		LayoutDescriptor( 5, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),	// AUTOLAYOUT_2OBJOVERTEXT
1147 		LayoutDescriptor( 4, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),				// AUTOLAYOUT_TEXTOVEROBJ
1148 		LayoutDescriptor( 6, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE,					// AUTOLAYOUT_4OBJ
1149 			PRESOBJ_OUTLINE, PRESOBJ_OUTLINE ),
1150 		LayoutDescriptor( 0, PRESOBJ_TITLE, PRESOBJ_NONE ),									// AUTOLAYOUT_ONLY_TITLE
1151 		LayoutDescriptor( 0, PRESOBJ_NONE ),												// AUTOLAYOUT_NONE
1152 		LayoutDescriptor( 0, PRESOBJ_PAGE, PRESOBJ_NOTES ),									// AUTOLAYOUT_NOTES
1153 		LayoutDescriptor( 0 ),																// AUTOLAYOUT_HANDOUT1
1154 		LayoutDescriptor( 0 ),																// AUTOLAYOUT_HANDOUT2
1155 		LayoutDescriptor( 0 ),																// AUTOLAYOUT_HANDOUT3
1156 		LayoutDescriptor( 0 ),																// AUTOLAYOUT_HANDOUT4
1157 		LayoutDescriptor( 0 ),																// AUTOLAYOUT_HANDOUT6
1158 		LayoutDescriptor( 7, PRESOBJ_TITLE|VERTICAL, PRESOBJ_OUTLINE|VERTICAL, PRESOBJ_OUTLINE ),// AUTOLAYOUT_VERTICAL_TITLE_TEXT_CHART
1159 		LayoutDescriptor( 8, PRESOBJ_TITLE|VERTICAL, PRESOBJ_OUTLINE|VERTICAL ),			// AUTOLAYOUT_VERTICAL_TITLE_VERTICAL_OUTLINE
1160 		LayoutDescriptor( 0, PRESOBJ_TITLE, PRESOBJ_OUTLINE|VERTICAL ),						// AUTOLAYOUT_TITLE_VERTICAL_OUTLINE
1161 		LayoutDescriptor( 9, PRESOBJ_TITLE, PRESOBJ_OUTLINE|VERTICAL, PRESOBJ_OUTLINE|VERTICAL ),	// AUTOLAYOUT_TITLE_VERTICAL_OUTLINE_CLIPART
1162 		LayoutDescriptor( 0 ),																// AUTOLAYOUT_HANDOUT9
1163         LayoutDescriptor( 10, PRESOBJ_TEXT, PRESOBJ_NONE ),                                 // AUTOLAYOUT_ONLY_TEXT
1164         LayoutDescriptor( 6, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE,			    // AUTOLAYOUT_4CLIPART
1165 			PRESOBJ_GRAPHIC, PRESOBJ_GRAPHIC ),
1166         LayoutDescriptor( 11, PRESOBJ_TITLE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE,				// AUTOLAYOUT_6CLIPART
1167             PRESOBJ_OUTLINE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE, PRESOBJ_OUTLINE )
1168 	};
1169 
1170 	if( (eLayout < AUTOLAYOUT__START) || (eLayout >= AUTOLAYOUT__END) )
1171 		eLayout = AUTOLAYOUT_NONE;
1172 
1173 	return aLayouts[ eLayout - AUTOLAYOUT__START ];
1174 }
1175 
1176 static void CalcAutoLayoutRectangles( SdPage& rPage, int nLayout, Rectangle* rRectangle )
1177 {
1178 	Rectangle aTitleRect;
1179 	Rectangle aLayoutRect;
1180 
1181 	if( rPage.GetPageKind() != PK_HANDOUT )
1182 	{
1183 		SdPage& rMasterPage = static_cast<SdPage&>(rPage.TRG_GetMasterPage());
1184 		SdrObject* pMasterTitle = rMasterPage.GetPresObj( PRESOBJ_TITLE );
1185 		SdrObject* pMasterOutline = rMasterPage.GetPresObj( rPage.GetPageKind()==PK_NOTES ? PRESOBJ_NOTES : PRESOBJ_OUTLINE );
1186 
1187 		if( pMasterTitle )
1188 			aTitleRect = pMasterTitle->GetLogicRect();
1189 
1190 		if (aTitleRect.IsEmpty() )
1191 			aTitleRect = rPage.GetTitleRect();
1192 
1193 		if( pMasterOutline )
1194 			aLayoutRect = pMasterOutline->GetLogicRect();
1195 
1196 		if (aLayoutRect.IsEmpty() )
1197 			aLayoutRect = rPage.GetLayoutRect();
1198 	}
1199 
1200 	rRectangle[0] = aTitleRect;
1201 
1202 	int i;
1203 	for( i = 1; i < MAX_PRESOBJS; i++ )
1204 		rRectangle[i] = aLayoutRect;
1205 
1206 	Size        aTitleSize( aTitleRect.GetSize() );
1207 	Point       aTitlePos( aTitleRect.TopLeft() );
1208 	Size        aLayoutSize( aLayoutRect.GetSize() );
1209 	Point       aLayoutPos( aLayoutRect.TopLeft() );
1210 	Size        aTempSize;
1211 	Point       aTempPnt;
1212 
1213     sal_Bool    bRightToLeft = ( rPage.GetModel() && static_cast< SdDrawDocument* >( rPage.GetModel() )->GetDefaultWritingMode() == ::com::sun::star::text::WritingMode_RL_TB );
1214 
1215 	switch( nLayout )
1216 	{
1217 	case 0: // default layout using only the title and layout area
1218 		break; // do nothing
1219 	case 1: // title, 2 shapes
1220 	case 9: // title, 2 vertical shapes
1221 		aLayoutSize.Width()  = long (aLayoutSize.Width() * 0.488);
1222 		rRectangle[1] = Rectangle (aLayoutPos, aLayoutSize);
1223 
1224 		aLayoutPos.X() = long (aLayoutPos.X() + aLayoutSize.Width() * 1.05);
1225 		rRectangle[2] = Rectangle (aLayoutPos, aLayoutSize);
1226 
1227         if( bRightToLeft && (nLayout != 9) )
1228             ::std::swap< Rectangle >( rRectangle[1], rRectangle[2] );
1229 		break;
1230 	case 2: // title, shape, 2 shapes
1231 		aTempPnt = aLayoutPos;
1232 		aTempSize = aLayoutSize;
1233 		aLayoutSize.Height() = long (aLayoutSize.Height() * 0.477);
1234 		aLayoutSize.Width() = long (aLayoutSize.Width() * 0.488);
1235 		aLayoutPos.X() = long (aLayoutPos.X() + aLayoutSize.Width() * 1.05);
1236 		rRectangle[2] = Rectangle (aLayoutPos, aLayoutSize);
1237 
1238 		aLayoutPos.Y() = long (aLayoutPos.Y() + aLayoutSize.Height() * 1.095);
1239 		rRectangle[3] = Rectangle (aLayoutPos, aLayoutSize);
1240 
1241 		aLayoutPos = aTempPnt;
1242 		aLayoutSize = aTempSize;
1243 		aLayoutSize.Width() = long (aLayoutSize.Width() * 0.488);
1244 		rRectangle[1] = Rectangle (aLayoutPos, aLayoutSize);
1245 
1246 		if( bRightToLeft )
1247 		{
1248 			::std::swap< long >( rRectangle[1].Left(), rRectangle[2].Left() );
1249 			rRectangle[3].Left() = rRectangle[2].Left();
1250 		}
1251 		break;
1252 	case 3: // title, 2 shapes, shape
1253 		aTempPnt = aLayoutPos;
1254 		aTempSize = aLayoutSize;
1255 		aLayoutSize.Height() = long (aLayoutSize.Height() * 0.477);
1256 		aLayoutSize.Width() = long (aLayoutSize.Width() * 0.488);
1257 		rRectangle[1] = Rectangle (aLayoutPos, aLayoutSize);
1258 
1259 		aLayoutPos.Y() = long (aLayoutPos.Y() + aLayoutSize.Height() * 1.095);
1260 		rRectangle[2] = Rectangle (aLayoutPos, aLayoutSize);
1261 
1262 		aLayoutPos = aTempPnt;
1263 		aLayoutSize = aTempSize;
1264 		aLayoutSize.Width() = long (aLayoutSize.Width() * 0.488);
1265 		aLayoutPos.X() = long (aLayoutPos.X() + aLayoutSize.Width() * 1.05);
1266 		rRectangle[3] = Rectangle (aLayoutPos, aLayoutSize);
1267 
1268         if( bRightToLeft )
1269         {
1270             ::std::swap< long >( rRectangle[1].Left(), rRectangle[2].Left() );
1271             rRectangle[3].Left() = rRectangle[2].Left();
1272         }
1273 		break;
1274 	case 4: // title, shape above shape
1275 		aLayoutSize.Height() = long (aLayoutSize.Height() * 0.477);
1276 		rRectangle[1] = Rectangle (aLayoutPos, aLayoutSize);
1277 
1278 		aLayoutPos.Y() = long (aLayoutPos.Y() + aLayoutSize.Height() * 1.095);
1279 		rRectangle[2] = Rectangle (aLayoutPos, aLayoutSize);
1280 		break;
1281 
1282 	case 5: // title, 2 shapes above shape
1283 		aLayoutSize.Height() = long (aLayoutSize.Height() * 0.477);
1284 		aLayoutSize.Width() = long (aLayoutSize.Width() * 0.488);
1285 		rRectangle[1] = Rectangle (aLayoutPos, aLayoutSize);
1286 
1287 		aTempPnt = aLayoutPos;
1288 		aLayoutPos.X() = long (aLayoutPos.X() + aLayoutSize.Width() * 1.05);
1289 		rRectangle[2] = Rectangle (aLayoutPos, aLayoutSize);
1290 
1291 		aLayoutPos.X() = aTempPnt.X();
1292 		aLayoutPos.Y() = long (aLayoutPos.Y() + aLayoutSize.Height() * 1.095);
1293 		aLayoutSize.Width() = long (aLayoutSize.Width() / 0.488);
1294 		rRectangle[3] = Rectangle (aLayoutPos, aLayoutSize);
1295 		break;
1296 	case 6: // title, 4 shapes
1297 	{
1298 		sal_uLong nX = long (aLayoutPos.X());
1299 
1300 		aLayoutSize.Height() = long (aLayoutSize.Height() * 0.477);
1301 		aLayoutSize.Width()  = long (aLayoutSize.Width() * 0.488);
1302 		rRectangle[1] = Rectangle (aLayoutPos, aLayoutSize);
1303 
1304 		aLayoutPos.X() = long (nX + aLayoutSize.Width() * 1.05);
1305 		rRectangle[2] = Rectangle (aLayoutPos, aLayoutSize);
1306 
1307 		aLayoutPos.Y() = long (aLayoutPos.Y() + aLayoutSize.Height() * 1.095);
1308 		rRectangle[3] = Rectangle (aLayoutPos, aLayoutSize);
1309 
1310 		aLayoutPos.X() = nX;
1311 		rRectangle[4] = Rectangle (aLayoutPos, aLayoutSize);
1312 		break;
1313 	}
1314 	case 7: // vertical title, shape above shape
1315 	{
1316 		Size aSize( rRectangle[0].GetSize().Height(), rRectangle[1].BottomLeft().Y() - rRectangle[0].TopLeft().Y() );
1317 		rRectangle[0].SetSize( aSize );
1318 		rRectangle[0].SetPos( aTitleRect.TopRight() - Point( aSize.Width(), 0 ) );
1319 
1320 		Size aPageSize ( rPage.GetSize() );
1321 		aPageSize.Height() -= rPage.GetUppBorder() + rPage.GetLwrBorder();
1322 		aSize.Height() = long ( rRectangle[0].GetSize().Height() * 0.47 );
1323 		aSize.Width() = long( aPageSize.Width() * 0.7 );
1324 		rRectangle[1].SetPos( aTitleRect.TopLeft() );
1325 		rRectangle[1].SetSize( aSize );
1326 
1327 		aSize.Height() = rRectangle[0].GetSize().Height();
1328 		Point aPos( aTitleRect.TopLeft() );
1329 		aPos.Y() += long ( aSize.Height() * 0.53 );
1330 		rRectangle[2].SetPos( aPos );
1331 		aSize.Height() = long ( rRectangle[0].GetSize().Height() * 0.47 );
1332 		rRectangle[2].SetSize( aSize );
1333 		break;
1334 	}
1335 	case 8: // vertical title, shape
1336 	{
1337 		Size aSize( rRectangle[0].GetSize().Height(), rRectangle[1].BottomLeft().Y() - rRectangle[0].TopLeft().Y() );
1338 		rRectangle[0].SetSize( aSize );
1339 		rRectangle[0].SetPos( aTitleRect.TopRight() - Point( aSize.Width(), 0 ) );
1340 
1341 		Size aPageSize ( rPage.GetSize() );
1342 		aPageSize.Height() -= rPage.GetUppBorder() + rPage.GetLwrBorder();
1343 		aSize.Height() = rRectangle[0].GetSize().Height();
1344 		aSize.Width() = long( aPageSize.Width() * 0.7 );
1345 		rRectangle[1].SetPos( aTitleRect.TopLeft() );
1346 		rRectangle[1].SetSize( aSize );
1347 		break;
1348 	}
1349     case 10: // onlytext
1350     {
1351         Size aSize( rRectangle[0].GetSize().Width(), rRectangle[1].BottomLeft().Y() - rRectangle[0].TopLeft().Y() );
1352 		rRectangle[0].SetSize( aSize );
1353 		rRectangle[0].SetPos( aTitlePos);
1354 		break;
1355     }
1356     case 11: // title, 6 shapes
1357 	{
1358 		sal_uLong nX = long (aLayoutPos.X());
1359 
1360 		aLayoutSize.Height() = long (aLayoutSize.Height() * 0.477);
1361 		aLayoutSize.Width()  = long (aLayoutSize.Width() * 0.322);
1362 		rRectangle[1] = Rectangle (aLayoutPos, aLayoutSize);
1363 
1364 		aLayoutPos.X() = long (nX + aLayoutSize.Width() * 1.05);
1365 		rRectangle[2] = Rectangle (aLayoutPos, aLayoutSize);
1366 
1367 		aLayoutPos.X() = long (nX + aLayoutSize.Width() * 2 * 1.05);
1368 		rRectangle[3] = Rectangle (aLayoutPos, aLayoutSize);
1369 
1370 		aLayoutPos.Y() = long (aLayoutPos.Y() + aLayoutSize.Height() * 1.095);
1371 		rRectangle[4] = Rectangle (aLayoutPos, aLayoutSize);
1372 
1373 		aLayoutPos.X() = long (nX + aLayoutSize.Width() * 1.05);
1374 		rRectangle[5] = Rectangle (aLayoutPos, aLayoutSize);
1375 
1376 		aLayoutPos.X() = nX;
1377 		rRectangle[6] = Rectangle (aLayoutPos, aLayoutSize);
1378 
1379 		break;
1380     }
1381 
1382 	}
1383 }
1384 
1385 
1386 void findAutoLayoutShapesImpl( SdPage& rPage, const LayoutDescriptor& rDescriptor, std::vector< SdrObject* >& rShapes, bool bInit, bool bSwitchLayout )
1387 {
1388 	int i;
1389 
1390 	// init list of indexes for each presentation shape kind
1391 	// this is used to find subsequent shapes with the same presentation shape kind
1392 	int PresObjIndex[PRESOBJ_MAX];
1393 	for( i = 0; i < PRESOBJ_MAX; i++ ) PresObjIndex[i] = 1;
1394 
1395 	bool bMissing = false;
1396 
1397 	// for each entry in the layoutdescriptor, arrange a presentation shape
1398 	for( i = 0; (i < PRESOBJ_MAX) && (rDescriptor.meKind[i] != PRESOBJ_NONE); i++ )
1399 	{
1400 		PresObjKind eKind = rDescriptor.meKind[i];
1401 		SdrObject* pObj = 0;
1402 		while( (pObj = rPage.GetPresObj( eKind, PresObjIndex[eKind], true )) != 0 )
1403 		{
1404 			PresObjIndex[eKind]++; // on next search for eKind, find next shape with same eKind
1405 
1406 			if( !bSwitchLayout || !pObj->IsEmptyPresObj() )
1407 			{
1408 				rShapes[i] = pObj;
1409 				break;
1410 			}
1411 		}
1412 
1413 		if( !pObj )
1414 			bMissing = true;
1415 	}
1416 
1417 	if( bMissing && bInit )
1418 	{
1419 		// for each entry in the layoutdescriptor, look for an alternative shape
1420 		for( i = 0; (i < PRESOBJ_MAX) && (rDescriptor.meKind[i] != PRESOBJ_NONE); i++ )
1421 		{
1422 			if( rShapes[i] )
1423 				continue;
1424 
1425 			PresObjKind eKind = rDescriptor.meKind[i];
1426 
1427 			SdrObject* pObj = 0;
1428 			bool bFound = false;
1429 
1430 			const int nShapeCount = rPage.GetObjCount();
1431 			int nShapeIndex = 0;
1432 			while((nShapeIndex < nShapeCount) && !bFound )
1433 			{
1434 				pObj = rPage.GetObj(nShapeIndex++);
1435 
1436 				if( pObj->IsEmptyPresObj() )
1437 					continue;
1438 
1439 				if( pObj->GetObjInventor() != SdrInventor )
1440 					continue;
1441 
1442 				// do not reuse shapes that are already part of the layout
1443 				if( std::find( rShapes.begin(), rShapes.end(), pObj ) != rShapes.end() )
1444 					continue;
1445 
1446 				bool bPresStyle = pObj->GetStyleSheet() && (pObj->GetStyleSheet()->GetFamily() == SD_STYLE_FAMILY_MASTERPAGE);
1447 				SdrObjKind eSdrObjKind = static_cast< SdrObjKind >( pObj->GetObjIdentifier() );
1448 
1449 				switch( eKind )
1450 				{
1451 				case PRESOBJ_TITLE:
1452 					bFound = eSdrObjKind == OBJ_TITLETEXT;
1453 					break;
1454 				case PRESOBJ_TABLE:
1455 					bFound = eSdrObjKind == OBJ_TABLE;
1456 					break;
1457 				case PRESOBJ_MEDIA:
1458 					bFound = eSdrObjKind == OBJ_MEDIA;
1459 					break;
1460 				case PRESOBJ_OUTLINE:
1461 					bFound = (eSdrObjKind == OBJ_OUTLINETEXT) ||
1462 						     ((eSdrObjKind == OBJ_TEXT) && bPresStyle) ||
1463 							 (eSdrObjKind == OBJ_TABLE) || (eSdrObjKind == OBJ_MEDIA) || (eSdrObjKind == OBJ_GRAF) || (eSdrObjKind == OBJ_OLE2);
1464 					break;
1465 				case PRESOBJ_GRAPHIC:
1466 					bFound = eSdrObjKind == OBJ_GRAF;
1467 					break;
1468 				case PRESOBJ_OBJECT:
1469                     if( eSdrObjKind == OBJ_OLE2 )
1470 					{
1471 						SdrOle2Obj* pOle2 = dynamic_cast< SdrOle2Obj* >( pObj );
1472 						if( pOle2 )
1473 						{
1474                             if( pOle2->IsEmpty() )
1475                                 bFound = true;
1476                             else if( rPage.GetModel() )
1477                             {
1478 							    SdrModel* pSdrModel = rPage.GetModel();
1479 							    ::comphelper::IEmbeddedHelper *pPersist = pSdrModel->GetPersist();
1480 							    if( pPersist )
1481 							    {
1482 								    uno::Reference < embed::XEmbeddedObject > xObject = pPersist->getEmbeddedObjectContainer().
1483 										    GetEmbeddedObject( static_cast< SdrOle2Obj* >( pObj )->GetPersistName() );
1484 
1485 								    // TODO CL->KA: Why is this not working anymore?
1486 								    if( xObject.is() )
1487 								    {
1488 									    SvGlobalName aClassId( xObject->getClassID() );
1489 
1490 									    const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
1491 									    const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
1492 									    const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
1493 
1494 									    if( aPluginClassId != aClassId && aAppletClassId != aClassId && aIFrameClassId != aClassId )
1495 									    {
1496                                             bFound = true;
1497                                         }
1498 								    }
1499 							    }
1500                              }
1501                          }
1502                     }
1503 					break;
1504 				case PRESOBJ_CHART:
1505 				case PRESOBJ_CALC:
1506 					if( eSdrObjKind == OBJ_OLE2 )
1507 					{
1508 						SdrOle2Obj* pOle2 = dynamic_cast< SdrOle2Obj* >( pObj );
1509 						if( pOle2 )
1510 						{
1511 							if(
1512 								((eKind == PRESOBJ_CHART) &&
1513 									( pOle2->GetProgName().EqualsAscii( "StarChart" ) || pOle2->IsChart() ) )
1514 								||
1515 								((eKind == PRESOBJ_CALC) &&
1516 									( pOle2->GetProgName().EqualsAscii( "StarCalc" ) || pOle2->IsCalc() ) ) )
1517 							{
1518 								bFound = true;
1519 							}
1520 						}
1521 						break;
1522 					}
1523 					else if( eSdrObjKind == OBJ_TABLE )
1524 					{
1525 						bFound = true;
1526 					}
1527 					break;
1528 				case PRESOBJ_PAGE:
1529 				case PRESOBJ_HANDOUT:
1530 					bFound = eSdrObjKind == OBJ_PAGE;
1531 					break;
1532 				case PRESOBJ_NOTES:
1533 				case PRESOBJ_TEXT:
1534 					bFound = (bPresStyle && (eSdrObjKind == OBJ_TEXT)) || (eSdrObjKind == OBJ_OUTLINETEXT);
1535 					break;
1536 				default:
1537 					break;
1538 				}
1539 			}
1540 
1541 			if( bFound )
1542 				rShapes[i] = pObj;
1543 		}
1544 	}
1545 }
1546 
1547 void SdPage::SetAutoLayout(AutoLayout eLayout, sal_Bool bInit, sal_Bool bCreate )
1548 {
1549 	sd::ScopeLockGuard aGuard( maLockAutoLayoutArrangement );
1550 
1551 	const bool bSwitchLayout = eLayout != GetAutoLayout();
1552 
1553 	::svl::IUndoManager* pUndoManager = pModel ? static_cast<SdDrawDocument*>(pModel)->GetUndoManager() : 0;
1554 	const bool bUndo = pUndoManager && pUndoManager->IsInListAction() && IsInserted();
1555 
1556 	meAutoLayout = eLayout;
1557 
1558 	// if needed, creates and initialises the presentation shapes on this slides master page
1559 	CreateTitleAndLayout(bInit, bCreate);
1560 
1561 	if((meAutoLayout == AUTOLAYOUT_NONE && maPresentationShapeList.isEmpty()) || mbMaster)
1562 	{
1563 		// MasterPage or no layout and no presentation shapes available, noting to do
1564 		return;
1565 	}
1566 
1567 	Rectangle aRectangle[MAX_PRESOBJS];
1568 	const LayoutDescriptor& aDescriptor = GetLayoutDescriptor( meAutoLayout );
1569 	CalcAutoLayoutRectangles( *this, aDescriptor.mnLayout, aRectangle );
1570 
1571 	std::set< SdrObject* > aUsedPresentationObjects;
1572 
1573 
1574 	std::vector< SdrObject* > aLayoutShapes(PRESOBJ_MAX, 0);
1575 	findAutoLayoutShapesImpl( *this, aDescriptor, aLayoutShapes, bInit, bSwitchLayout );
1576 
1577 	int i;
1578 
1579 	// for each entry in the layoutdescriptor, arrange a presentation shape
1580 	for( i = 0; (i < PRESOBJ_MAX) && (aDescriptor.meKind[i] != PRESOBJ_NONE); i++ )
1581 	{
1582 		PresObjKind eKind = aDescriptor.meKind[i];
1583 		SdrObject* pObj = InsertAutoLayoutShape( aLayoutShapes[i], eKind, aDescriptor.mbVertical[i], aRectangle[i], bInit );
1584 		if( pObj )
1585 			aUsedPresentationObjects.insert(pObj); // remember that we used this empty shape
1586 	}
1587 
1588 	// now delete all empty presentation objects that are no longer used by the new layout
1589 	if( bInit )
1590 	{
1591 		SdrObject* pObj = maPresentationShapeList.getNextShape(0);
1592 
1593 		while( pObj )
1594 		{
1595 			SdrObject* pNext = maPresentationShapeList.getNextShape(pObj);
1596 			if( aUsedPresentationObjects.count(pObj) == 0 )
1597 			{
1598 
1599 				if( pObj->IsEmptyPresObj() )
1600 				{
1601 					if( bUndo )
1602 						pUndoManager->AddUndoAction(pModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pObj));
1603 
1604 					RemoveObject( pObj->GetOrdNum() );
1605 
1606 					if( !bUndo )
1607 						SdrObject::Free( pObj );
1608 				}
1609 /* #i108541# keep non empty pres obj as pres obj even if they are not part of the current layout
1610 				else
1611 				{
1612 					if( bUndo )
1613 					{
1614 						pUndoManager->AddUndoAction( new UndoObjectPresentationKind( *pObj ) );
1615 						if( pObj->GetUserCall() )
1616 							pUndoManager->AddUndoAction( new UndoObjectUserCall( *pObj ) );
1617 					}
1618 					maPresentationShapeList.removeShape( *pObj );
1619 					pObj->SetUserCall(0);
1620 				}
1621 */
1622 			}
1623 			pObj = pNext;
1624 		}
1625 	}
1626 }
1627 
1628 /*************************************************************************
1629 |*
1630 |* Objekt einfuegen
1631 |*
1632 \************************************************************************/
1633 
1634 void SdPage::NbcInsertObject(SdrObject* pObj, sal_uLong nPos, const SdrInsertReason* pReason)
1635 {
1636 	FmFormPage::NbcInsertObject(pObj, nPos, pReason);
1637 
1638 	((SdDrawDocument*) pModel)->InsertObject(pObj, this);
1639 
1640 	SdrLayerID nId = pObj->GetLayer();
1641 	if( mbMaster )
1642 	{
1643 		if( nId == 0 )
1644 			pObj->NbcSetLayer( 2 );     // wrong layer. corrected to BackgroundObj layer
1645 	}
1646 	else
1647 	{
1648 		if( nId == 2 )
1649 			pObj->NbcSetLayer( 0 );     // wrong layer. corrected to layout layer
1650 	}
1651 }
1652 
1653 /*************************************************************************
1654 |*
1655 |* Objekt loeschen
1656 |*
1657 \************************************************************************/
1658 
1659 SdrObject* SdPage::RemoveObject(sal_uLong nObjNum)
1660 {
1661 	onRemoveObject(GetObj( nObjNum ));
1662 	return FmFormPage::RemoveObject(nObjNum);
1663 }
1664 
1665 /*************************************************************************
1666 |*
1667 |* Objekt loeschen, ohne Broadcast
1668 |*
1669 \************************************************************************/
1670 
1671 SdrObject* SdPage::NbcRemoveObject(sal_uLong nObjNum)
1672 {
1673 	onRemoveObject(GetObj( nObjNum ));
1674 	return FmFormPage::NbcRemoveObject(nObjNum);
1675 }
1676 
1677 // #95876# Also overload ReplaceObject methods to realize when
1678 // objects are removed with this mechanism instead of RemoveObject
1679 SdrObject* SdPage::NbcReplaceObject(SdrObject* pNewObj, sal_uLong nObjNum)
1680 {
1681 	onRemoveObject(GetObj( nObjNum ));
1682 	return FmFormPage::NbcReplaceObject(pNewObj, nObjNum);
1683 }
1684 
1685 // #95876# Also overload ReplaceObject methods to realize when
1686 // objects are removed with this mechanism instead of RemoveObject
1687 SdrObject* SdPage::ReplaceObject(SdrObject* pNewObj, sal_uLong nObjNum)
1688 {
1689 	onRemoveObject(GetObj( nObjNum ));
1690 	return FmFormPage::ReplaceObject(pNewObj, nObjNum);
1691 }
1692 
1693 // -------------------------------------------------------------------------
1694 
1695 // called after a shape is removed or replaced from this slide
1696 
1697 void SdPage::onRemoveObject( SdrObject* pObject )
1698 {
1699 	if( pObject )
1700 	{
1701 		RemovePresObj(pObject);
1702 
1703 		if( pModel )
1704 			static_cast<SdDrawDocument*>(pModel)->RemoveObject(pObject, this);
1705 
1706 		removeAnimations( pObject );
1707 	}
1708 }
1709 
1710 /*************************************************************************
1711 |*
1712 |*
1713 |*
1714 \************************************************************************/
1715 
1716 void SdPage::SetSize(const Size& aSize)
1717 {
1718 	Size aOldSize = GetSize();
1719 
1720 	if (aSize != aOldSize)
1721 	{
1722 		FmFormPage::SetSize(aSize);
1723 
1724 		if (aOldSize.Height() == 10 && aOldSize.Width() == 10)
1725 		{
1726 			// Die Seite bekommt erstmalig eine gueltige Groesse gesetzt,
1727 			// daher wird nun die Orientation initialisiert
1728 			if (aSize.Width() > aSize.Height())
1729 			{
1730 				meOrientation = ORIENTATION_LANDSCAPE;
1731 			}
1732 			else
1733 			{
1734 				meOrientation = ORIENTATION_PORTRAIT;
1735 			}
1736 		}
1737 	}
1738 }
1739 
1740 
1741 /*************************************************************************
1742 |*
1743 |*
1744 |*
1745 \************************************************************************/
1746 
1747 void SdPage::SetBorder(sal_Int32 nLft, sal_Int32 nUpp, sal_Int32 nRgt, sal_Int32 nLwr)
1748 {
1749 	if (nLft != GetLftBorder() || nUpp != GetUppBorder() ||
1750 		nRgt != GetRgtBorder() || nLwr != GetLwrBorder() )
1751 	{
1752 		FmFormPage::SetBorder(nLft, nUpp, nRgt, nLwr);
1753 	}
1754 }
1755 
1756 
1757 /*************************************************************************
1758 |*
1759 |*
1760 |*
1761 \************************************************************************/
1762 
1763 void SdPage::SetLftBorder(sal_Int32 nBorder)
1764 {
1765 	if (nBorder != GetLftBorder() )
1766 	{
1767 		FmFormPage::SetLftBorder(nBorder);
1768 	}
1769 }
1770 
1771 
1772 /*************************************************************************
1773 |*
1774 |*
1775 |*
1776 \************************************************************************/
1777 
1778 void SdPage::SetRgtBorder(sal_Int32 nBorder)
1779 {
1780 	if (nBorder != GetRgtBorder() )
1781 	{
1782 		FmFormPage::SetRgtBorder(nBorder);
1783 	}
1784 }
1785 
1786 
1787 /*************************************************************************
1788 |*
1789 |*
1790 |*
1791 \************************************************************************/
1792 
1793 void SdPage::SetUppBorder(sal_Int32 nBorder)
1794 {
1795 	if (nBorder != GetUppBorder() )
1796 	{
1797 		FmFormPage::SetUppBorder(nBorder);
1798 	}
1799 }
1800 
1801 
1802 /*************************************************************************
1803 |*
1804 |*
1805 |*
1806 \************************************************************************/
1807 
1808 void SdPage::SetLwrBorder(sal_Int32 nBorder)
1809 {
1810 	if (nBorder != GetLwrBorder() )
1811 	{
1812 		FmFormPage::SetLwrBorder(nBorder);
1813 	}
1814 }
1815 
1816 /*************************************************************************
1817 |*
1818 |* Setzt BackgroundFullSize und ruft dann AdjustBackground auf
1819 |*
1820 \************************************************************************/
1821 
1822 void SdPage::SetBackgroundFullSize( sal_Bool bIn )
1823 {
1824 	if( bIn != mbBackgroundFullSize )
1825 	{
1826 		mbBackgroundFullSize = bIn;
1827 	}
1828 }
1829 
1830 /*************************************************************************
1831 |*
1832 |* Alle Objekte an neue Seitengroesse anpassen
1833 |*
1834 |* bScaleAllObj: Alle Objekte werden in die neue Flaeche innerhalb der
1835 |* Seitenraender skaliert. Dabei werden die Position, Groesse und bei
1836 |* Praesentationsobjekten auf der MasterPage auch die Schrifthoehe der
1837 |* Praesentationsvorlagen skaliert.
1838 |*
1839 \************************************************************************/
1840 
1841 void SdPage::ScaleObjects(const Size& rNewPageSize, const Rectangle& rNewBorderRect, sal_Bool bScaleAllObj)
1842 {
1843 	sd::ScopeLockGuard aGuard( maLockAutoLayoutArrangement );
1844 
1845 	mbScaleObjects = bScaleAllObj;
1846 	SdrObject* pObj = NULL;
1847 	Point aRefPnt(0, 0);
1848 	Size aNewPageSize(rNewPageSize);
1849 	sal_Int32 nLeft  = rNewBorderRect.Left();
1850 	sal_Int32 nRight = rNewBorderRect.Right();
1851 	sal_Int32 nUpper = rNewBorderRect.Top();
1852 	sal_Int32 nLower = rNewBorderRect.Bottom();
1853 
1854 	// Negative Werte stehen fuer nicht zu aendernde Werte
1855 	// -> aktuelle Werte verwenden
1856 	if (aNewPageSize.Width() < 0)
1857 	{
1858 		aNewPageSize.Width() = GetWdt();
1859 	}
1860 	if (aNewPageSize.Height() < 0)
1861 	{
1862 		aNewPageSize.Height() = GetHgt();
1863 	}
1864 	if (nLeft < 0)
1865 	{
1866 		nLeft = GetLftBorder();
1867 	}
1868 	if (nRight < 0)
1869 	{
1870 		nRight = GetRgtBorder();
1871 	}
1872 	if (nUpper < 0)
1873 	{
1874 		nUpper = GetUppBorder();
1875 	}
1876 	if (nLower < 0)
1877 	{
1878 		nLower = GetLwrBorder();
1879 	}
1880 
1881 	Point aBackgroundPos(nLeft, nUpper);
1882 	Size aBackgroundSize(aNewPageSize);
1883 	Rectangle aBorderRect (aBackgroundPos, aBackgroundSize);
1884 
1885 	if (mbScaleObjects)
1886 	{
1887 		aBackgroundSize.Width()  -= nLeft  + nRight;
1888 		aBackgroundSize.Height() -= nUpper + nLower;
1889 		aBorderRect.SetSize(aBackgroundSize);
1890 		aNewPageSize = aBackgroundSize;
1891 	}
1892 
1893 	long nOldWidth  = GetWdt() - GetLftBorder() - GetRgtBorder();
1894 	long nOldHeight = GetHgt() - GetUppBorder() - GetLwrBorder();
1895 
1896 	Fraction aFractX = Fraction(aNewPageSize.Width(), nOldWidth);
1897 	Fraction aFractY = Fraction(aNewPageSize.Height(), nOldHeight);
1898 
1899 	sal_uLong nObjCnt = (mbScaleObjects ? GetObjCount() : 0);
1900 
1901 	for (sal_uLong nObj = 0; nObj < nObjCnt; nObj++)
1902 	{
1903 		sal_Bool bIsPresObjOnMaster = sal_False;
1904 
1905 		// Alle Objekte
1906 		pObj = GetObj(nObj);
1907 
1908 		if (mbMaster && IsPresObj(pObj))
1909 		{
1910 			// Es ist ein Praesentationsobjekt auf der MasterPage
1911 			bIsPresObjOnMaster = sal_True;
1912 		}
1913 
1914 		if (pObj)
1915 		{
1916 			// #88084# remember aTopLeft as original TopLeft
1917 			Point aTopLeft(pObj->GetCurrentBoundRect().TopLeft());
1918 
1919             if (!pObj->IsEdgeObj())
1920 			{
1921 				/**************************************************************
1922 				* Objekt skalieren
1923 				**************************************************************/
1924 				if (mbScaleObjects)
1925 				{
1926 					// #88084# use aTopLeft as original TopLeft
1927 					aRefPnt = aTopLeft;
1928 				}
1929 
1930 				pObj->Resize(aRefPnt, aFractX, aFractY);
1931 
1932 				if (mbScaleObjects)
1933 				{
1934 					SdrObjKind eObjKind = (SdrObjKind) pObj->GetObjIdentifier();
1935 
1936 					if (bIsPresObjOnMaster)
1937 					{
1938 						/**********************************************************
1939 						* Praesentationsvorlage: Texthoehe anpassen
1940 						**********************************************************/
1941 						sal_uInt16 nIndexTitle = 0;
1942 						sal_uInt16 nIndexOutline = 0;
1943 						sal_uInt16 nIndexNotes = 0;
1944 
1945 						if (pObj == GetPresObj(PRESOBJ_TITLE, nIndexTitle))
1946 						{
1947 							SfxStyleSheet* pTitleSheet = GetStyleSheetForPresObj(PRESOBJ_TITLE);
1948 
1949 							if (pTitleSheet)
1950 							{
1951 								SfxItemSet& rSet = pTitleSheet->GetItemSet();
1952 
1953 								SvxFontHeightItem& rOldHgt = (SvxFontHeightItem&) rSet.Get(EE_CHAR_FONTHEIGHT);
1954 								sal_uLong nFontHeight = rOldHgt.GetHeight();
1955 								nFontHeight = long(nFontHeight * (double) aFractY);
1956 								rSet.Put(SvxFontHeightItem(nFontHeight, 100, EE_CHAR_FONTHEIGHT));
1957 
1958 								if( SFX_ITEM_AVAILABLE == rSet.GetItemState( EE_CHAR_FONTHEIGHT_CJK ) )
1959 								{
1960 									rOldHgt = (SvxFontHeightItem&) rSet.Get(EE_CHAR_FONTHEIGHT_CJK);
1961 									nFontHeight = rOldHgt.GetHeight();
1962 									nFontHeight = long(nFontHeight * (double) aFractY);
1963 									rSet.Put(SvxFontHeightItem(nFontHeight, 100, EE_CHAR_FONTHEIGHT_CJK));
1964 								}
1965 
1966 								if( SFX_ITEM_AVAILABLE == rSet.GetItemState( EE_CHAR_FONTHEIGHT_CTL ) )
1967 								{
1968 									rOldHgt = (SvxFontHeightItem&) rSet.Get(EE_CHAR_FONTHEIGHT_CTL);
1969 									nFontHeight = rOldHgt.GetHeight();
1970 									nFontHeight = long(nFontHeight * (double) aFractY);
1971 									rSet.Put(SvxFontHeightItem(nFontHeight, 100, EE_CHAR_FONTHEIGHT_CTL));
1972 								}
1973 
1974 								pTitleSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
1975 							}
1976 						}
1977 						else if (pObj == GetPresObj(PRESOBJ_OUTLINE, nIndexOutline))
1978 						{
1979 							String aName(GetLayoutName());
1980 							aName += sal_Unicode( ' ' );
1981 
1982 							for (sal_uInt16 i=1; i<=9; i++)
1983 							{
1984 								String sLayoutName(aName);
1985 								sLayoutName += String::CreateFromInt32( (sal_Int32)i );
1986 								SfxStyleSheet* pOutlineSheet = (SfxStyleSheet*)((SdDrawDocument*) pModel)->GetStyleSheetPool()->Find(sLayoutName, SD_STYLE_FAMILY_MASTERPAGE);
1987 
1988 								if (pOutlineSheet)
1989 								{
1990 									// Neue Fonthoehe berechnen
1991 									SfxItemSet aTempSet(pOutlineSheet->GetItemSet());
1992 
1993 									SvxFontHeightItem& rOldHgt = (SvxFontHeightItem&) aTempSet.Get(EE_CHAR_FONTHEIGHT);
1994 									sal_uLong nFontHeight = rOldHgt.GetHeight();
1995 									nFontHeight = long(nFontHeight * (double) aFractY);
1996 									aTempSet.Put(SvxFontHeightItem(nFontHeight, 100, EE_CHAR_FONTHEIGHT));
1997 
1998 									if( SFX_ITEM_AVAILABLE == aTempSet.GetItemState( EE_CHAR_FONTHEIGHT_CJK ) )
1999 									{
2000 										rOldHgt = (SvxFontHeightItem&) aTempSet.Get(EE_CHAR_FONTHEIGHT_CJK);
2001 										nFontHeight = rOldHgt.GetHeight();
2002 										nFontHeight = long(nFontHeight * (double) aFractY);
2003 										aTempSet.Put(SvxFontHeightItem(nFontHeight, 100, EE_CHAR_FONTHEIGHT_CJK));
2004 									}
2005 
2006 									if( SFX_ITEM_AVAILABLE == aTempSet.GetItemState( EE_CHAR_FONTHEIGHT_CTL ) )
2007 									{
2008 										rOldHgt = (SvxFontHeightItem&) aTempSet.Get(EE_CHAR_FONTHEIGHT_CTL);
2009 										nFontHeight = rOldHgt.GetHeight();
2010 										nFontHeight = long(nFontHeight * (double) aFractY);
2011 										aTempSet.Put(SvxFontHeightItem(nFontHeight, 100, EE_CHAR_FONTHEIGHT_CTL));
2012 									}
2013 
2014 									// Bullet anpassen
2015 									((SdStyleSheet*) pOutlineSheet)->AdjustToFontHeight(aTempSet, sal_False);
2016 
2017 									// Sonderbehandlung: die INVALIDS auf NULL-Pointer
2018 									// zurueckgesetzen (sonst landen INVALIDs oder
2019 									// Pointer auf die DefaultItems in der Vorlage;
2020 									// beides wuerde die Attribut-Vererbung unterbinden)
2021 									aTempSet.ClearInvalidItems();
2022 
2023 									// Sonderbehandlung: nur die gueltigen Anteile des
2024 									// BulletItems
2025 									if (aTempSet.GetItemState(EE_PARA_BULLET) == SFX_ITEM_AVAILABLE)
2026 									{
2027 										SvxBulletItem aOldBulItem((SvxBulletItem&) pOutlineSheet->GetItemSet().Get(EE_PARA_BULLET));
2028 										SvxBulletItem& rNewBulItem = (SvxBulletItem&) aTempSet.Get(EE_PARA_BULLET);
2029 										aOldBulItem.CopyValidProperties(rNewBulItem);
2030 										aTempSet.Put(aOldBulItem);
2031 									}
2032 
2033 									pOutlineSheet->GetItemSet().Put(aTempSet);
2034 									pOutlineSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
2035 								}
2036 							}
2037 						}
2038 						else if (pObj == GetPresObj(PRESOBJ_NOTES, nIndexNotes))
2039 						{
2040 							SfxStyleSheet* pNotesSheet = GetStyleSheetForPresObj(PRESOBJ_NOTES);
2041 
2042 							if (pNotesSheet)
2043 							{
2044 								sal_uLong nHeight = pObj->GetLogicRect().GetSize().Height();
2045 								sal_uLong nFontHeight = (sal_uLong) (nHeight * 0.0741);
2046 								SfxItemSet& rSet = pNotesSheet->GetItemSet();
2047                                 rSet.Put( SvxFontHeightItem(nFontHeight, 100, EE_CHAR_FONTHEIGHT ));
2048                                 rSet.Put( SvxFontHeightItem(nFontHeight, 100, EE_CHAR_FONTHEIGHT_CJK ));
2049                                 rSet.Put( SvxFontHeightItem(nFontHeight, 100, EE_CHAR_FONTHEIGHT_CTL ));
2050 								pNotesSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
2051 							}
2052 						}
2053 					}
2054 					else if ( eObjKind != OBJ_TITLETEXT   &&
2055 							  eObjKind != OBJ_OUTLINETEXT &&
2056 							  pObj->ISA(SdrTextObj)       &&
2057 							  pObj->GetOutlinerParaObject() )
2058 					{
2059 						/******************************************************
2060 						* Normales Textobjekt: Texthoehe anpassen
2061 						******************************************************/
2062 						sal_uLong nScriptType = pObj->GetOutlinerParaObject()->GetTextObject().GetScriptType();
2063 						sal_uInt16 nWhich = EE_CHAR_FONTHEIGHT;
2064 						if ( nScriptType == SCRIPTTYPE_ASIAN )
2065 							nWhich = EE_CHAR_FONTHEIGHT_CJK;
2066 						else if ( nScriptType == SCRIPTTYPE_COMPLEX )
2067 							nWhich = EE_CHAR_FONTHEIGHT_CTL;
2068 
2069 						// #88084# use more modern method to scale the text height
2070 						sal_uInt32 nFontHeight = ((SvxFontHeightItem&)pObj->GetMergedItem(nWhich)).GetHeight();
2071 						sal_uInt32 nNewFontHeight = sal_uInt32((double)nFontHeight * (double)aFractY);
2072 
2073 						pObj->SetMergedItem(SvxFontHeightItem(nNewFontHeight, 100, nWhich));
2074 					}
2075 				}
2076 			}
2077 
2078 			if (mbScaleObjects && !pObj->IsEdgeObj())
2079 			{
2080 				/**************************************************************
2081 				* Objektposition skalieren
2082 				**************************************************************/
2083 				Point aNewPos;
2084 
2085 				// #76447# corrected scaling; only distances may be scaled
2086 				// #88084# use aTopLeft as original TopLeft
2087 				aNewPos.X() = long((aTopLeft.X() - GetLftBorder()) * (double)aFractX) + nLeft;
2088 				aNewPos.Y() = long((aTopLeft.Y() - GetUppBorder()) * (double)aFractY) + nUpper;
2089 
2090 				Size aVec(aNewPos.X() - aTopLeft.X(), aNewPos.Y() - aTopLeft.Y());
2091 
2092 				if (aVec.Height() != 0 || aVec.Width() != 0)
2093 				{
2094 					pObj->NbcMove(aVec);
2095 				}
2096 
2097 				pObj->SetChanged();
2098 				pObj->BroadcastObjectChange();
2099 			}
2100 		}
2101 	}
2102 }
2103 
2104 SdrObject* convertPresentationObjectImpl( SdPage& rPage, SdrObject* pSourceObj, PresObjKind& eObjKind, bool bVertical, Rectangle aRect )
2105 {
2106 	SdDrawDocument* pModel = static_cast< SdDrawDocument* >( rPage.GetModel() );
2107 	DBG_ASSERT( pModel, "sd::convertPresentationObjectImpl(), no model on page!" );
2108 	if( !pModel || !pSourceObj )
2109 		return pSourceObj;
2110 
2111 	::svl::IUndoManager* pUndoManager = pModel ? static_cast<SdDrawDocument*>(pModel)->GetUndoManager() : 0;
2112 	const bool bUndo = pUndoManager && pUndoManager->IsInListAction() && rPage.IsInserted();
2113 
2114 	SdrObject* pNewObj = pSourceObj;
2115 	if((eObjKind == PRESOBJ_OUTLINE) && (pSourceObj->GetObjIdentifier() == OBJ_TEXT) )
2116 	{
2117 		pNewObj = rPage.CreatePresObj(PRESOBJ_OUTLINE, bVertical, aRect);
2118 
2119 		// Text des Untertitels in das PRESOBJ_OUTLINE setzen
2120 		OutlinerParaObject* pOutlParaObj = pSourceObj->GetOutlinerParaObject();
2121 
2122 		if(pOutlParaObj)
2123 		{
2124 			// Text umsetzen
2125 			::sd::Outliner* pOutl = pModel->GetInternalOutliner( sal_True );
2126 			pOutl->Clear();
2127 			pOutl->SetText( *pOutlParaObj );
2128 			pOutlParaObj = pOutl->CreateParaObject();
2129 			pNewObj->SetOutlinerParaObject( pOutlParaObj );
2130 			pOutl->Clear();
2131 			pNewObj->SetEmptyPresObj(sal_False);
2132 
2133 			for (sal_uInt16 nLevel = 1; nLevel < 10; nLevel++)
2134 			{
2135 				// Neue Vorlage zuweisen
2136 				String aName(rPage.GetLayoutName());
2137 				aName += sal_Unicode( ' ' );
2138 				aName += String::CreateFromInt32( nLevel );
2139 				SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>( pModel->GetStyleSheetPool()->Find(aName, SD_STYLE_FAMILY_MASTERPAGE) );
2140 
2141 				if (pSheet)
2142 				{
2143 					if (nLevel == 1)
2144 					{
2145 						SfxStyleSheet* pSubtitleSheet = rPage.GetStyleSheetForPresObj(PRESOBJ_TEXT);
2146 
2147 						if (pSubtitleSheet)
2148 							pOutlParaObj->ChangeStyleSheetName(SD_STYLE_FAMILY_MASTERPAGE, pSubtitleSheet->GetName(), pSheet->GetName());
2149 					}
2150 
2151 					pNewObj->StartListening(*pSheet);
2152 				}
2153 			}
2154 
2155 			// LRSpace-Item loeschen
2156 			SfxItemSet aSet(pModel->GetPool(), EE_PARA_LRSPACE, EE_PARA_LRSPACE );
2157 
2158 			aSet.Put(pNewObj->GetMergedItemSet());
2159 
2160 			aSet.ClearItem(EE_PARA_LRSPACE);
2161 
2162 			pNewObj->SetMergedItemSet(aSet);
2163 
2164 			if( bUndo )
2165 				pUndoManager->AddUndoAction( pModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pSourceObj) );
2166 
2167 			// Remove outline shape from page
2168 			rPage.RemoveObject( pSourceObj->GetOrdNum() );
2169 
2170 			if( !bUndo )
2171 				SdrObject::Free( pSourceObj );
2172 		}
2173 	}
2174 	else if((eObjKind == PRESOBJ_TEXT) && (pSourceObj->GetObjIdentifier() == OBJ_OUTLINETEXT) )
2175 	{
2176 		// is there an outline shape we can use to replace empty subtitle shape?
2177 		pNewObj = rPage.CreatePresObj(PRESOBJ_TEXT, bVertical, aRect);
2178 
2179 		// Text des Gliederungsobjekts in das PRESOBJ_TITLE setzen
2180 		OutlinerParaObject* pOutlParaObj = pSourceObj->GetOutlinerParaObject();
2181 
2182 		if(pOutlParaObj)
2183 		{
2184 			// Text umsetzen
2185 			::sd::Outliner* pOutl = pModel->GetInternalOutliner();
2186 			pOutl->Clear();
2187 			pOutl->SetText( *pOutlParaObj );
2188 			pOutlParaObj = pOutl->CreateParaObject();
2189 			pNewObj->SetOutlinerParaObject( pOutlParaObj );
2190 			pOutl->Clear();
2191 			pNewObj->SetEmptyPresObj(sal_False);
2192 
2193 			// Linken Einzug zuruecksetzen
2194 			SfxItemSet aSet(pModel->GetPool(), EE_PARA_LRSPACE, EE_PARA_LRSPACE );
2195 
2196 			aSet.Put(pNewObj->GetMergedItemSet());
2197 
2198 			const SvxLRSpaceItem& rLRItem = (const SvxLRSpaceItem&) aSet.Get(EE_PARA_LRSPACE);
2199 			SvxLRSpaceItem aNewLRItem(rLRItem);
2200 			aNewLRItem.SetTxtLeft(0);
2201 			aSet.Put(aNewLRItem);
2202 
2203 			pNewObj->SetMergedItemSet(aSet);
2204 
2205 			SfxStyleSheet* pSheet = rPage.GetStyleSheetForPresObj(PRESOBJ_TEXT);
2206 			if (pSheet)
2207 				pNewObj->SetStyleSheet(pSheet, sal_True);
2208 
2209 			// Remove subtitle shape from page
2210 			if( bUndo )
2211 				pUndoManager->AddUndoAction(pModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pSourceObj));
2212 
2213 			rPage.RemoveObject( pSourceObj->GetOrdNum() );
2214 
2215 			if( !bUndo )
2216 				SdrObject::Free( pSourceObj );
2217 		}
2218 	}
2219 	else if((eObjKind == PRESOBJ_OUTLINE) && (pSourceObj->GetObjIdentifier() != OBJ_OUTLINETEXT) )
2220 	{
2221 		switch( pSourceObj->GetObjIdentifier() )
2222 		{
2223 		case OBJ_TABLE: eObjKind = PRESOBJ_TABLE; break;
2224 		case OBJ_MEDIA: eObjKind = PRESOBJ_MEDIA; break;
2225 		case OBJ_GRAF: eObjKind = PRESOBJ_GRAPHIC; break;
2226 		case OBJ_OLE2: eObjKind = PRESOBJ_OBJECT; break;
2227 		}
2228 	}
2229 
2230 	return pNewObj;
2231 }
2232 
2233 /** reuses or creates a presentation shape for an auto layout that fits the given parameter
2234 
2235 	@param	eObjKind
2236 		The kind of presentation shape we like to have
2237 	@param	nIndex
2238 		If > 1 we skip the first nIndex-1 shapes with the presentation shape kind eObjKind while
2239 		looking for an existing presentation shape
2240 	@param	bVertical
2241 		If true, the shape is created vertical if bInit is true
2242 	@param	aRect
2243 		The rectangle that should be used to transform the shape
2244 	@param	bInit
2245 		If true the shape is created if not found
2246 	@returns
2247 		A presentation shape that was either found or created with the given parameters
2248 */
2249 SdrObject* SdPage::InsertAutoLayoutShape( SdrObject* pObj, PresObjKind eObjKind, bool bVertical, Rectangle aRect, bool bInit )
2250 {
2251 	::svl::IUndoManager* pUndoManager = pModel ? static_cast<SdDrawDocument*>(pModel)->GetUndoManager() : 0;
2252 	const bool bUndo = pUndoManager && pUndoManager->IsInListAction() && IsInserted();
2253 
2254 	if (!pObj && bInit)
2255 	{
2256 		pObj = CreatePresObj(eObjKind, bVertical, aRect);
2257 	}
2258 	else if ( pObj && (pObj->GetUserCall() || bInit) )
2259 	{
2260 		// convert object if shape type does not match kind (f.e. converting outline text to subtitle text)
2261 		if( bInit )
2262 			pObj = convertPresentationObjectImpl( *this, pObj, eObjKind, bVertical, aRect );
2263 
2264 		if( bUndo )
2265 		{
2266 			pUndoManager->AddUndoAction( pModel->GetSdrUndoFactory().CreateUndoGeoObject( *pObj ) );
2267 			pUndoManager->AddUndoAction( pModel->GetSdrUndoFactory().CreateUndoAttrObject( *pObj, sal_True, sal_True ) );
2268 			pUndoManager->AddUndoAction( new UndoObjectUserCall( *pObj ) );
2269 		}
2270 
2271 //		if ( pObj->ISA(SdrGrafObj) && !pObj->IsEmptyPresObj() )
2272 			( /*(SdrGrafObj*)*/ pObj)->AdjustToMaxRect( aRect );
2273 //		else
2274 //			SetLogicRect( pObj, aRect );
2275 
2276 		pObj->SetUserCall(this);
2277 
2278 		SdrTextObj* pTextObject = dynamic_cast< SdrTextObj* >(pObj);
2279 		if( pTextObject )
2280 		{
2281 			if( pTextObject->IsVerticalWriting() != (bVertical ? sal_True : sal_False) )
2282 			{
2283 				pTextObject->SetVerticalWriting( bVertical );
2284 
2285 				// #94826# here make sure the correct anchoring is used when the object
2286 				// is re-used but orientation is changed
2287 				if(PRESOBJ_OUTLINE == eObjKind)
2288 					pTextObject->SetMergedItem(SdrTextHorzAdjustItem( bVertical ? SDRTEXTHORZADJUST_RIGHT : SDRTEXTHORZADJUST_BLOCK ));
2289 			}
2290 
2291 			if( !mbMaster && (pTextObject->GetObjIdentifier() != OBJ_TABLE) )
2292 			{
2293 				if ( pTextObject->IsAutoGrowHeight() )
2294 				{
2295 					// switch off AutoGrowHeight, set new MinHeight
2296 					SfxItemSet aTempAttr( ((SdDrawDocument*) pModel)->GetPool() );
2297 					SdrTextMinFrameHeightItem aMinHeight( aRect.GetSize().Height() );
2298 					aTempAttr.Put( aMinHeight );
2299 					aTempAttr.Put( SdrTextAutoGrowHeightItem(sal_False) );
2300 					pTextObject->SetMergedItemSet(aTempAttr);
2301 					pTextObject->SetLogicRect(aRect);
2302 
2303 					// switch on AutoGrowHeight
2304 					SfxItemSet aAttr( ((SdDrawDocument*) pModel)->GetPool() );
2305 					aAttr.Put( SdrTextAutoGrowHeightItem(sal_True) );
2306 
2307 					pTextObject->SetMergedItemSet(aAttr);
2308 				}
2309 
2310 				if ( pTextObject->IsAutoGrowWidth() )
2311 				{
2312 					// switch off AutoGrowWidth , set new MinWidth
2313 					SfxItemSet aTempAttr( ((SdDrawDocument*) pModel)->GetPool() );
2314 					SdrTextMinFrameWidthItem aMinWidth( aRect.GetSize().Width() );
2315 					aTempAttr.Put( aMinWidth );
2316 					aTempAttr.Put( SdrTextAutoGrowWidthItem(sal_False) );
2317 					pTextObject->SetMergedItemSet(aTempAttr);
2318 					pTextObject->SetLogicRect(aRect);
2319 
2320 					// switch on AutoGrowWidth
2321 					SfxItemSet aAttr( ((SdDrawDocument*) pModel)->GetPool() );
2322 					aAttr.Put( SdrTextAutoGrowWidthItem(sal_True) );
2323 					pTextObject->SetMergedItemSet(aAttr);
2324 				}
2325 			}
2326 		}
2327 	}
2328 
2329 	if(pObj && bInit )
2330 	{
2331 		if( !IsPresObj( pObj ) )
2332 		{
2333 			if( bUndo )
2334 				pUndoManager->AddUndoAction( new UndoObjectPresentationKind( *pObj ) );
2335 
2336 			InsertPresObj( pObj, eObjKind );
2337 		}
2338 
2339 		// make adjustments for vertical title and outline shapes
2340 		if( bVertical && (( eObjKind == PRESOBJ_TITLE) || (eObjKind == PRESOBJ_OUTLINE)))
2341 		{
2342 			SfxItemSet aNewSet(pObj->GetMergedItemSet());
2343 			aNewSet.Put( SdrTextAutoGrowWidthItem(sal_True) );
2344 			aNewSet.Put( SdrTextAutoGrowHeightItem(sal_False) );
2345 			if( eObjKind == PRESOBJ_OUTLINE )
2346 			{
2347 				aNewSet.Put( SdrTextVertAdjustItem(SDRTEXTVERTADJUST_TOP) );
2348 				aNewSet.Put( SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT) );
2349 			}
2350 			pObj->SetMergedItemSet(aNewSet);
2351 		}
2352 	}
2353 
2354 	if ( pObj && (pObj->GetUserCall() || bInit) && ( pObj->IsEmptyPresObj() || !pObj->ISA(SdrGrafObj) ) )
2355 		pObj->AdjustToMaxRect( aRect );
2356 
2357 	return pObj;
2358 }
2359 
2360 
2361 /*************************************************************************
2362 |*
2363 |* Liefert den PresObjKind eines Objektes zurueck
2364 |*
2365 \************************************************************************/
2366 
2367 PresObjKind SdPage::GetPresObjKind(SdrObject* pObj) const
2368 {
2369 	PresObjKind eKind = PRESOBJ_NONE;
2370 	if( (pObj != 0) && (maPresentationShapeList.hasShape(*pObj)) )
2371 	{
2372 		SdAnimationInfo* pInfo = SdDrawDocument::GetShapeUserData(*pObj);
2373 		if( pInfo )
2374 			eKind = pInfo->mePresObjKind;
2375 	}
2376 
2377 	return eKind;
2378 }
2379 
2380 bool SdPage::IsPresObj(const SdrObject* pObj)
2381 {
2382 	return pObj && maPresentationShapeList.hasShape( const_cast<SdrObject&>(*pObj) );
2383 }
2384 
2385 void SdPage::RemovePresObj(const SdrObject* pObj)
2386 {
2387 	if( pObj && maPresentationShapeList.hasShape(const_cast<SdrObject&>(*pObj)) )
2388 	{
2389 		SdAnimationInfo* pInfo = SdDrawDocument::GetShapeUserData(const_cast<SdrObject&>(*pObj));
2390 		if( pInfo )
2391 			pInfo->mePresObjKind = PRESOBJ_NONE;
2392 		maPresentationShapeList.removeShape(const_cast<SdrObject&>(*pObj));
2393 	}
2394 }
2395 
2396 void SdPage::InsertPresObj(SdrObject* pObj, PresObjKind eKind )
2397 {
2398 	DBG_ASSERT( pObj, "sd::SdPage::InsertPresObj(), invalid presentation object inserted!" );
2399 	DBG_ASSERT( !IsPresObj(pObj), "sd::SdPage::InsertPresObj(), presentation object inserted twice!" );
2400 	if( pObj )
2401 	{
2402 		SdAnimationInfo* pInfo = SdDrawDocument::GetShapeUserData(*pObj, true);
2403 		if( pInfo )
2404 			pInfo->mePresObjKind = eKind;
2405 		maPresentationShapeList.addShape(*pObj);
2406 	}
2407 }
2408 
2409 /*************************************************************************
2410 |*
2411 |* Text des Objektes setzen
2412 |*
2413 \************************************************************************/
2414 
2415 void SdPage::SetObjText(SdrTextObj* pObj, SdrOutliner* pOutliner, PresObjKind eObjKind,	const String& rString )
2416 {
2417 	if ( pObj )
2418 	{
2419 		DBG_ASSERT( pObj->ISA(SdrTextObj), "SetObjText: Kein SdrTextObj!" );
2420 		::Outliner* pOutl = pOutliner;
2421 
2422 		if (!pOutliner)
2423 		{
2424 			SfxItemPool* pPool = ((SdDrawDocument*) GetModel())->GetDrawOutliner().GetEmptyItemSet().GetPool();
2425 			pOutl = new ::Outliner( pPool, OUTLINERMODE_OUTLINEOBJECT );
2426 			pOutl->SetRefDevice( SD_MOD()->GetRefDevice( *( (SdDrawDocument*) GetModel() )->GetDocSh() ) );
2427 			pOutl->SetEditTextObjectPool(pPool);
2428 			pOutl->SetStyleSheetPool((SfxStyleSheetPool*)GetModel()->GetStyleSheetPool());
2429 			pOutl->EnableUndo(sal_False);
2430 			pOutl->SetUpdateMode( sal_False );
2431 		}
2432 
2433 		sal_uInt16 nOutlMode = pOutl->GetMode();
2434 		Size aPaperSize = pOutl->GetPaperSize();
2435 		sal_Bool bUpdateMode = pOutl->GetUpdateMode();
2436 		pOutl->SetUpdateMode(sal_False);
2437 		pOutl->SetParaAttribs( 0, pOutl->GetEmptyItemSet() );
2438 
2439 		// #95114# Always set the object's StyleSheet at the Outliner to
2440 		// use the current objects StyleSheet. Thus it's the same as in
2441 		// SetText(...).
2442 		// #95114# Moved this implementation from where SetObjText(...) was called
2443 		// to inside this method to work even when outliner is fetched here.
2444 		pOutl->SetStyleSheet(0, pObj->GetStyleSheet());
2445 
2446 		String aString;
2447 
2448 		switch( eObjKind )
2449 		{
2450 			case PRESOBJ_OUTLINE:
2451 			{
2452 				pOutl->Init( OUTLINERMODE_OUTLINEOBJECT );
2453 
2454 				aString += sal_Unicode( '\t' );
2455 				aString += rString;
2456 
2457 				if (mbMaster)
2458 				{
2459 					pOutl->SetStyleSheet( 0, GetStyleSheetForPresObj(eObjKind) );
2460 					aString += String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\n\t\t" ));
2461 					aString += String ( SdResId( STR_PRESOBJ_MPOUTLLAYER2 ) );
2462 
2463 					aString += String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\n\t\t\t" ));
2464 					aString += String ( SdResId( STR_PRESOBJ_MPOUTLLAYER3 ) );
2465 
2466 					aString += String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\n\t\t\t\t" ));
2467 					aString += String ( SdResId( STR_PRESOBJ_MPOUTLLAYER4 ) );
2468 
2469 					aString += String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\n\t\t\t\t\t" ));
2470 					aString += String ( SdResId( STR_PRESOBJ_MPOUTLLAYER5 ) );
2471 
2472 					aString += String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\n\t\t\t\t\t\t" ));
2473 					aString += String ( SdResId( STR_PRESOBJ_MPOUTLLAYER6 ) );
2474 
2475 					aString += String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\n\t\t\t\t\t\t\t" ));
2476 					aString += String ( SdResId( STR_PRESOBJ_MPOUTLLAYER7 ) );
2477 
2478 					aString += String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\n\t\t\t\t\t\t\t\t" ));
2479 					aString += String ( SdResId( STR_PRESOBJ_MPOUTLLAYER8 ) );
2480 
2481 					aString += String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "\n\t\t\t\t\t\t\t\t\t" ));
2482 					aString += String ( SdResId( STR_PRESOBJ_MPOUTLLAYER9 ) );
2483 				}
2484 			}
2485 			break;
2486 
2487 			case PRESOBJ_TITLE:
2488 			{
2489 				pOutl->Init( OUTLINERMODE_TITLEOBJECT );
2490 				aString += rString;
2491 			}
2492 			break;
2493 
2494 			default:
2495 			{
2496 				pOutl->Init( OUTLINERMODE_TEXTOBJECT );
2497 				aString += rString;
2498 
2499 				// check if we need to add a text field
2500 				SvxFieldData* pData = NULL;
2501 
2502 				switch( eObjKind )
2503 				{
2504 				case PRESOBJ_HEADER:
2505 					pData = new SvxHeaderField();
2506 					break;
2507 				case PRESOBJ_FOOTER:
2508 					pData = new SvxFooterField();
2509 					break;
2510 				case PRESOBJ_SLIDENUMBER:
2511 					pData = new SvxPageField();
2512 					break;
2513 				case PRESOBJ_DATETIME:
2514 					pData = new SvxDateTimeField();
2515 					break;
2516 				default:
2517 					break;
2518 				}
2519 
2520 				if( pData )
2521 				{
2522 					ESelection e;
2523                     SvxFieldItem aField( *pData, EE_FEATURE_FIELD );
2524 					pOutl->QuickInsertField(aField,e);
2525 					delete pData;
2526 				}
2527 			}
2528 			break;
2529 		}
2530 
2531 		pOutl->SetPaperSize( pObj->GetLogicRect().GetSize() );
2532 
2533 		if( aString.Len() )
2534 			pOutl->SetText( aString, pOutl->GetParagraph( 0 ) );
2535 
2536 		( (SdrTextObj*) pObj)->SetOutlinerParaObject( pOutl->CreateParaObject() );
2537 
2538 		if (!pOutliner)
2539 		{
2540 			delete pOutl;
2541 			pOutl = NULL;
2542 		}
2543 		else
2544 		{
2545 			// Outliner restaurieren
2546 			pOutl->Init( nOutlMode );
2547 			pOutl->SetParaAttribs( 0, pOutl->GetEmptyItemSet() );
2548 			pOutl->SetUpdateMode( bUpdateMode );
2549 			pOutl->SetPaperSize( aPaperSize );
2550 		}
2551 	}
2552 }
2553 
2554 /*************************************************************************
2555 |*
2556 |* Link & Daten von einem VControl empfangen
2557 |*
2558 \************************************************************************/
2559 
2560 void SdPage::SetLinkData(const String&, const String& )
2561 {
2562 }
2563 
2564 /*************************************************************************
2565 |*
2566 |* Layoutname setzen
2567 |*
2568 \************************************************************************/
2569 void SdPage::SetLayoutName(String aName)
2570 {
2571 	maLayoutName = aName;
2572 
2573 	if( mbMaster )
2574 	{
2575 		String aSep( RTL_CONSTASCII_USTRINGPARAM(SD_LT_SEPARATOR) );
2576 		sal_uInt16 nPos = maLayoutName.Search( aSep );
2577 		if ( nPos != STRING_NOTFOUND )
2578 		{
2579             FmFormPage::SetName(maLayoutName.Copy(0, nPos));
2580 		}
2581 	}
2582 }
2583 
2584 
2585 /*************************************************************************
2586 |*
2587 |* Seitenname zurueckgeben und ggf. generieren
2588 |*
2589 \************************************************************************/
2590 
2591 const String& SdPage::GetName() const
2592 {
2593 	String aCreatedPageName( maCreatedPageName );
2594 	if (GetRealName().Len() == 0)
2595 	{
2596 		if ((mePageKind == PK_STANDARD || mePageKind == PK_NOTES) && !mbMaster)
2597 		{
2598 			// default name for handout pages
2599 			sal_uInt16	nNum = (GetPageNum() + 1) / 2;
2600 
2601 			aCreatedPageName = String(SdResId(STR_PAGE));
2602 			aCreatedPageName += sal_Unicode( ' ' );
2603 			if( GetModel()->GetPageNumType() == SVX_NUMBER_NONE )
2604 			{
2605 				// if the document has number none as a formating
2606 				// for page numbers we still default to arabic numbering
2607 				// to keep the default page names unique
2608 				aCreatedPageName += String::CreateFromInt32( (sal_Int32)nNum );
2609 			}
2610 			else
2611 			{
2612 				aCreatedPageName += ((SdDrawDocument*) GetModel())->CreatePageNumValue(nNum);
2613 			}
2614 		}
2615 		else
2616 		{
2617 			/******************************************************************
2618 			* Defaultname fuer Handzettelseiten
2619 			******************************************************************/
2620 			aCreatedPageName = String(SdResId(STR_LAYOUT_DEFAULT_NAME));
2621 		}
2622 	}
2623 	else
2624 	{
2625 		aCreatedPageName = GetRealName();
2626 	}
2627 
2628 	if (mePageKind == PK_NOTES)
2629 	{
2630 		aCreatedPageName += sal_Unicode( ' ' );
2631 		aCreatedPageName += String(SdResId(STR_NOTES));
2632 	}
2633 	else if (mePageKind == PK_HANDOUT && mbMaster)
2634 	{
2635 		aCreatedPageName += String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( " (" ));
2636 		aCreatedPageName += String(SdResId(STR_HANDOUT));
2637 		aCreatedPageName += sal_Unicode( ')' );
2638 	}
2639 
2640 	const_cast< SdPage* >(this)->maCreatedPageName = aCreatedPageName;
2641 	return maCreatedPageName;
2642 }
2643 
2644 /*************************************************************************
2645 |*
2646 |*
2647 |*
2648 \************************************************************************/
2649 
2650 void SdPage::SetOrientation( Orientation eOrient)
2651 {
2652 	meOrientation = eOrient;
2653 }
2654 
2655 /*************************************************************************
2656 |*
2657 |*
2658 |*
2659 \************************************************************************/
2660 
2661 Orientation SdPage::GetOrientation() const
2662 {
2663 	return meOrientation;
2664 }
2665 
2666 /*************************************************************************
2667 |*
2668 |* Liefert den Default-Text eines PresObjektes zurueck
2669 |*
2670 \************************************************************************/
2671 
2672 String SdPage::GetPresObjText(PresObjKind eObjKind) const
2673 {
2674 	String aString;
2675 
2676 	if (eObjKind == PRESOBJ_TITLE)
2677 	{
2678 		if (mbMaster)
2679 		{
2680 			if (mePageKind != PK_NOTES)
2681 			{
2682 				aString = String ( SdResId( STR_PRESOBJ_MPTITLE ) );
2683 			}
2684 			else
2685 			{
2686 				aString = String ( SdResId( STR_PRESOBJ_MPNOTESTITLE ) );
2687 			}
2688 		}
2689 		else
2690 		{
2691 			aString = String ( SdResId( STR_PRESOBJ_TITLE ) );
2692 		}
2693 	}
2694 	else if (eObjKind == PRESOBJ_OUTLINE)
2695 	{
2696 		if (mbMaster)
2697 		{
2698 			aString = String ( SdResId( STR_PRESOBJ_MPOUTLINE ) );
2699 		}
2700 		else
2701 		{
2702 			aString = String ( SdResId( STR_PRESOBJ_OUTLINE ) );
2703 		}
2704 	}
2705 	else if (eObjKind == PRESOBJ_NOTES)
2706 	{
2707 		if (mbMaster)
2708 		{
2709 			aString = String ( SdResId( STR_PRESOBJ_MPNOTESTEXT ) );
2710 		}
2711 		else
2712 		{
2713 			aString = String ( SdResId( STR_PRESOBJ_NOTESTEXT ) );
2714 		}
2715 	}
2716 	else if (eObjKind == PRESOBJ_TEXT)
2717 	{
2718 		aString = String ( SdResId( STR_PRESOBJ_TEXT ) );
2719 	}
2720 	else if (eObjKind == PRESOBJ_GRAPHIC)
2721 	{
2722 		aString = String ( SdResId( STR_PRESOBJ_GRAPHIC ) );
2723 	}
2724 	else if (eObjKind == PRESOBJ_OBJECT)
2725 	{
2726 		aString = String ( SdResId( STR_PRESOBJ_OBJECT ) );
2727 	}
2728 	else if (eObjKind == PRESOBJ_CHART)
2729 	{
2730 		aString = String ( SdResId( STR_PRESOBJ_CHART ) );
2731 	}
2732 	else if (eObjKind == PRESOBJ_ORGCHART)
2733 	{
2734 		aString = String ( SdResId( STR_PRESOBJ_ORGCHART ) );
2735 	}
2736 	else if (eObjKind == PRESOBJ_CALC)
2737 	{
2738 		aString = String ( SdResId( STR_PRESOBJ_TABLE ) );
2739 	}
2740 
2741 	return(aString);
2742 }
2743 
2744 extern uno::Reference< uno::XInterface > createUnoPageImpl( SdPage* pPage );
2745 
2746 uno::Reference< uno::XInterface > SdPage::createUnoPage()
2747 {
2748 	return createUnoPageImpl( this );
2749 }
2750 
2751 /** returns the SdPage implementation for the given XDrawPage or 0 if not available */
2752 SdPage* SdPage::getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& xPage )
2753 {
2754 	try
2755 	{
2756 	    ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUnoTunnel( xPage, ::com::sun::star::uno::UNO_QUERY );
2757 		if( xUnoTunnel.is() )
2758 		{
2759 			SvxDrawPage* pUnoPage = reinterpret_cast<SvxDrawPage*>(sal::static_int_cast<sal_uIntPtr>(xUnoTunnel->getSomething( SvxDrawPage::getUnoTunnelId()) ) );
2760 			if( pUnoPage )
2761 				return static_cast< SdPage* >( pUnoPage->GetSdrPage() );
2762 		}
2763 	}
2764 	catch( ::com::sun::star::uno::Exception& e )
2765 	{
2766 		(void)e;
2767 		DBG_ERROR("sd::SdPage::getImplementation(), exception cathced!" );
2768 	}
2769 
2770 	return 0;
2771 }
2772 
2773 void SdPage::SetName (const String& rName)
2774 {
2775     String aOldName = GetName();
2776     FmFormPage::SetName (rName);
2777     static_cast<SdDrawDocument*>(pModel)->UpdatePageRelativeURLs(aOldName, rName);
2778     ActionChanged();
2779 }
2780 
2781 const HeaderFooterSettings& SdPage::getHeaderFooterSettings() const
2782 {
2783 	if( mePageKind == PK_HANDOUT && !mbMaster )
2784 	{
2785 		return (((SdPage&)TRG_GetMasterPage()).maHeaderFooterSettings);
2786 	}
2787 	else
2788 	{
2789 		return maHeaderFooterSettings;
2790 	}
2791 }
2792 
2793 void SdPage::setHeaderFooterSettings( const sd::HeaderFooterSettings& rNewSettings )
2794 {
2795 	if( mePageKind == PK_HANDOUT && !mbMaster )
2796 	{
2797 		(((SdPage&)TRG_GetMasterPage()).maHeaderFooterSettings) = rNewSettings;
2798 	}
2799 	else
2800 	{
2801 		maHeaderFooterSettings = rNewSettings;
2802 	}
2803 
2804 	SetChanged();
2805 	if(TRG_HasMasterPage())
2806 	{
2807 		TRG_GetMasterPageDescriptorViewContact().ActionChanged();
2808 	}
2809 }
2810 
2811 bool SdPage::checkVisibility(
2812 	const sdr::contact::ViewObjectContact& rOriginal,
2813 	const sdr::contact::DisplayInfo& rDisplayInfo,
2814 	bool bEdit )
2815 {
2816 	if( !FmFormPage::checkVisibility( rOriginal, rDisplayInfo, bEdit ) )
2817 		return false;
2818 
2819 	SdrObject* pObj = rOriginal.GetViewContact().TryToGetSdrObject();
2820 	if( pObj == NULL )
2821 		return false;
2822 
2823     const SdrPage* pVisualizedPage = GetSdrPageFromXDrawPage(rOriginal.GetObjectContact().getViewInformation2D().getVisualizedPage());
2824 	const bool bIsPrinting(rOriginal.GetObjectContact().isOutputToPrinter() || rOriginal.GetObjectContact().isOutputToPDFFile());
2825 	const SdrPageView* pPageView = rOriginal.GetObjectContact().TryToGetSdrPageView();
2826 	const bool bIsInsidePageObj(pPageView && pPageView->GetPage() != pVisualizedPage);
2827 
2828 	// empty presentation objects only visible during edit mode
2829 	if( (bIsPrinting || !bEdit || bIsInsidePageObj ) && pObj->IsEmptyPresObj() )
2830 	{
2831 		if( (pObj->GetObjInventor() != SdrInventor) || ( (pObj->GetObjIdentifier() != OBJ_RECT) && (pObj->GetObjIdentifier() != OBJ_PAGE) ) )
2832 			return false;
2833 	}
2834 
2835 	if( ( pObj->GetObjInventor() == SdrInventor ) && ( pObj->GetObjIdentifier() == OBJ_TEXT ) )
2836 	{
2837        	const SdPage* pCheckPage = dynamic_cast< const SdPage* >(pObj->GetPage());
2838 
2839 		if( pCheckPage )
2840 		{
2841 			PresObjKind eKind = pCheckPage->GetPresObjKind(pObj);
2842 
2843 			if((eKind == PRESOBJ_FOOTER) || (eKind == PRESOBJ_HEADER) || (eKind == PRESOBJ_DATETIME) || (eKind == PRESOBJ_SLIDENUMBER) )
2844 			{
2845 				const bool bSubContentProcessing(rDisplayInfo.GetSubContentActive());
2846 
2847                 if( bSubContentProcessing || ( pCheckPage->GetPageKind() == PK_HANDOUT && bIsPrinting ) )
2848 				{
2849 					// use the page that is currently processed
2850                 	const SdPage* pVisualizedSdPage = dynamic_cast< const SdPage* >(pVisualizedPage);
2851 
2852                     if( pVisualizedSdPage )
2853 					{
2854 						// if we are not on a masterpage, see if we have to draw this header&footer object at all
2855 						const sd::HeaderFooterSettings& rSettings = pVisualizedSdPage->getHeaderFooterSettings();
2856 
2857 						switch( eKind )
2858 						{
2859 						case PRESOBJ_FOOTER:
2860 							return rSettings.mbFooterVisible;
2861 						case PRESOBJ_HEADER:
2862 							return rSettings.mbHeaderVisible;
2863 						case PRESOBJ_DATETIME:
2864 							return rSettings.mbDateTimeVisible;
2865 						case PRESOBJ_SLIDENUMBER:
2866 							return rSettings.mbSlideNumberVisible;
2867 						default:
2868 							break;
2869 						}
2870 					}
2871 				}
2872 			} // check for placeholders on master
2873 			else if( (eKind != PRESOBJ_NONE) && pCheckPage->IsMasterPage() && ( pVisualizedPage != pCheckPage ) )
2874 			{
2875 			    // presentation objects on master slide are always invisible if slide is shown.
2876                 return false;
2877 			}
2878 		}
2879 	}
2880 
2881 	// i63977, do not print SdrpageObjs from master pages
2882 	if( ( pObj->GetObjInventor() == SdrInventor ) && ( pObj->GetObjIdentifier() == OBJ_PAGE ) )
2883 	{
2884 		if( pObj->GetPage() && pObj->GetPage()->IsMasterPage() )
2885 			return false;
2886 	}
2887 
2888 	return true;
2889 }
2890 
2891 bool SdPage::RestoreDefaultText( SdrObject* pObj )
2892 {
2893 	bool bRet = false;
2894 
2895 	SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( pObj );
2896 
2897 	if( pTextObj )
2898 	{
2899 		PresObjKind ePresObjKind = GetPresObjKind(pTextObj);
2900 
2901 		if (ePresObjKind == PRESOBJ_TITLE   ||
2902 			ePresObjKind == PRESOBJ_OUTLINE ||
2903 			ePresObjKind == PRESOBJ_NOTES   ||
2904 			ePresObjKind == PRESOBJ_TEXT)
2905 		{
2906 			String aString( GetPresObjText(ePresObjKind) );
2907 
2908 			if (aString.Len())
2909 			{
2910 				sal_Bool bVertical = sal_False;
2911 				OutlinerParaObject* pOldPara = pTextObj->GetOutlinerParaObject();
2912 				if( pOldPara )
2913 					bVertical = pOldPara->IsVertical();  // is old para object vertical?
2914 
2915 				SetObjText( pTextObj, 0, ePresObjKind, aString );
2916 
2917 				if( pOldPara )
2918 				{
2919 					//pTextObj->SetVerticalWriting( bVertical );
2920 					//
2921 					// #94826# Here, only the vertical flag for the
2922 					// OutlinerParaObjects needs to be changed. The
2923 					// AutoGrowWidth/Height items still exist in the
2924 					// not changed object.
2925 					if(pTextObj
2926 						&& pTextObj->GetOutlinerParaObject()
2927 						&& pTextObj->GetOutlinerParaObject()->IsVertical() != (bool)bVertical)
2928 					{
2929 						Rectangle aObjectRect = pTextObj->GetSnapRect();
2930 						pTextObj->GetOutlinerParaObject()->SetVertical(bVertical);
2931 						pTextObj->SetSnapRect(aObjectRect);
2932 					}
2933 				}
2934 
2935 				pTextObj->SetTextEditOutliner( NULL );  // to make stylesheet settings work
2936 				pTextObj->NbcSetStyleSheet( GetStyleSheetForPresObj(ePresObjKind), sal_True );
2937 				pTextObj->SetEmptyPresObj(sal_True);
2938 				bRet = true;
2939 			}
2940 		}
2941 	}
2942 	return bRet;
2943 }
2944 
2945 void SdPage::CalculateHandoutAreas( SdDrawDocument& rModel, AutoLayout eLayout, bool bHorizontal, std::vector< Rectangle >& rAreas )
2946 {
2947 	SdPage& rHandoutMaster = *rModel.GetMasterSdPage( 0, PK_HANDOUT );
2948 
2949 	if( eLayout == AUTOLAYOUT_NONE )
2950 	{
2951 		// use layout from handout master
2952         SdrObjListIter aShapeIter (rHandoutMaster);
2953         while (aShapeIter.IsMore())
2954         {
2955             SdrPageObj* pPageObj = dynamic_cast<SdrPageObj*>(aShapeIter.Next());
2956             if (pPageObj)
2957                 rAreas.push_back( pPageObj->GetCurrentBoundRect() );
2958         }
2959 	}
2960 	else
2961 	{
2962 		Size    aArea = rHandoutMaster.GetSize();
2963 
2964 		const long nGapW = 1000; // gap is 1cm
2965 		const long nGapH = 1000;
2966 
2967 		long nLeftBorder = rHandoutMaster.GetLftBorder();
2968 		long nRightBorder = rHandoutMaster.GetRgtBorder();
2969 		long nTopBorder = rHandoutMaster.GetUppBorder();
2970 		long nBottomBorder = rHandoutMaster.GetLwrBorder();
2971 
2972 		const long nHeaderFooterHeight = static_cast< long >( (aArea.Height() - nTopBorder - nLeftBorder) * 0.05  );
2973 
2974 		nTopBorder += nHeaderFooterHeight;
2975 		nBottomBorder += nHeaderFooterHeight;
2976 
2977 		long nX = nGapW + nLeftBorder;
2978 		long nY = nGapH + nTopBorder;
2979 
2980 		aArea.Width() -= nGapW * 2 + nLeftBorder + nRightBorder;
2981 		aArea.Height() -= nGapH * 2 + nTopBorder + nBottomBorder;
2982 
2983 		const bool bLandscape = aArea.Width() > aArea.Height();
2984 
2985 		static sal_uInt16 aOffsets[5][9] =
2986 		{
2987 			{ 0, 1, 2, 3, 4, 5, 6, 7, 8 }, // AUTOLAYOUT_HANDOUT9, Portrait, Horizontal order
2988 			{ 0, 2, 4, 1, 3, 5, 0, 0, 0 }, // AUTOLAYOUT_HANDOUT3, Landscape, Vertical
2989 			{ 0, 2, 1, 3, 0, 0, 0, 0, 0 }, // AUTOLAYOUT_HANDOUT4, Landscape, Vertical
2990 			{ 0, 3, 1, 4, 2, 5, 0, 0, 0 }, // AUTOLAYOUT_HANDOUT4, Portrait, Vertical
2991 			{ 0, 3, 6, 1, 4, 7, 2, 5, 8 }, // AUTOLAYOUT_HANDOUT9, Landscape, Vertical
2992 		};
2993 
2994 		sal_uInt16* pOffsets = aOffsets[0];
2995 		sal_uInt16  nColCnt = 0, nRowCnt = 0;
2996 		switch ( eLayout )
2997 		{
2998 			case AUTOLAYOUT_HANDOUT1:
2999 				nColCnt = 1; nRowCnt = 1;
3000 				break;
3001 
3002 			case AUTOLAYOUT_HANDOUT2:
3003 				if( bLandscape )
3004 				{
3005 					nColCnt = 2; nRowCnt = 1;
3006 				}
3007 				else
3008 				{
3009 					nColCnt = 1; nRowCnt = 2;
3010 				}
3011 				break;
3012 
3013 			case AUTOLAYOUT_HANDOUT3:
3014 				if( bLandscape )
3015 				{
3016 					nColCnt = 3; nRowCnt = 2;
3017 				}
3018 				else
3019 				{
3020 					nColCnt = 2; nRowCnt = 3;
3021 				}
3022 				pOffsets = aOffsets[ bLandscape ? 1 : 0 ];
3023 				break;
3024 
3025 			case AUTOLAYOUT_HANDOUT4:
3026 				nColCnt = 2; nRowCnt = 2;
3027 				pOffsets = aOffsets[ bHorizontal ? 0 : 2 ];
3028 				break;
3029 
3030 			case AUTOLAYOUT_HANDOUT6:
3031 				if( bLandscape )
3032 				{
3033 					nColCnt = 3; nRowCnt = 2;
3034 				}
3035 				else
3036 				{
3037 					nColCnt = 2; nRowCnt = 3;
3038 				}
3039 				if( !bHorizontal )
3040 					pOffsets = aOffsets[ bLandscape ? 1 : 3 ];
3041 				break;
3042 
3043 			default:
3044 			case AUTOLAYOUT_HANDOUT9:
3045 				nColCnt = 3; nRowCnt = 3;
3046 
3047 				if( !bHorizontal )
3048 					pOffsets = aOffsets[4];
3049 				break;
3050 		}
3051 
3052 		rAreas.resize( nColCnt * nRowCnt );
3053 
3054 		Size aPartArea, aSize;
3055 		aPartArea.Width()  = ((aArea.Width()  - ((nColCnt-1) * nGapW) ) / nColCnt);
3056 		aPartArea.Height() = ((aArea.Height() - ((nRowCnt-1) * nGapH) ) / nRowCnt);
3057 
3058 		SdrPage* pFirstPage = rModel.GetMasterSdPage(0, PK_STANDARD);
3059 		if ( pFirstPage )
3060 		{
3061 			// scale actual size into handout rect
3062 			double fScale = (double)aPartArea.Width() / (double)pFirstPage->GetWdt();
3063 
3064 			aSize.Height() = (long)(fScale * pFirstPage->GetHgt() );
3065 			if( aSize.Height() > aPartArea.Height() )
3066 			{
3067 				fScale = (double)aPartArea.Height() / (double)pFirstPage->GetHgt();
3068 				aSize.Height() = aPartArea.Height();
3069 				aSize.Width() = (long)(fScale * pFirstPage->GetWdt());
3070 			}
3071 			else
3072 			{
3073 				aSize.Width() = aPartArea.Width();
3074 			}
3075 
3076 			nX += (aPartArea.Width() - aSize.Width()) / 2;
3077 			nY += (aPartArea.Height()- aSize.Height())/ 2;
3078 		}
3079 		else
3080 		{
3081 			aSize = aPartArea;
3082 		}
3083 
3084 		Point aPos( nX, nY );
3085 
3086 		const bool bRTL = rModel.GetDefaultWritingMode() == ::com::sun::star::text::WritingMode_RL_TB;
3087 
3088 		const long nOffsetX = (aPartArea.Width() + nGapW) * (bRTL ? -1 : 1);
3089 		const long nOffsetY = aPartArea.Height() + nGapH;
3090 		const long nStartX = bRTL ? nOffsetX*(1 - nColCnt) - nX : nX;
3091 
3092 		for(sal_uInt16 nRow = 0; nRow < nRowCnt; nRow++)
3093 		{
3094 			aPos.X() = nStartX;
3095 			for(sal_uInt16 nCol = 0; nCol < nColCnt; nCol++)
3096 			{
3097 				rAreas[*pOffsets++] = Rectangle(aPos, aSize);
3098 				aPos.X() += nOffsetX;
3099 			}
3100 
3101 			aPos.Y() += nOffsetY;
3102 		}
3103 	}
3104 }
3105 
3106 
3107 
3108 
3109 void SdPage::SetPrecious (const bool bIsPrecious)
3110 {
3111     mbIsPrecious = bIsPrecious;
3112 }
3113 
3114 
3115 
3116 
3117 bool SdPage::IsPrecious (void) const
3118 {
3119     return mbIsPrecious;
3120 }
3121 
3122 
3123 
3124 
3125 HeaderFooterSettings::HeaderFooterSettings()
3126 {
3127 	mbHeaderVisible = true;
3128 	mbFooterVisible = true;
3129 	mbSlideNumberVisible = false;
3130 	mbDateTimeVisible = true;
3131 	mbDateTimeIsFixed = true;
3132 	meDateTimeFormat = SVXDATEFORMAT_A;
3133 }
3134 
3135 bool HeaderFooterSettings::operator==( const HeaderFooterSettings& rSettings ) const
3136 {
3137 	return (mbHeaderVisible == rSettings.mbHeaderVisible) &&
3138 		   (maHeaderText == rSettings.maHeaderText) &&
3139 		   (mbFooterVisible == rSettings.mbFooterVisible) &&
3140 		   (maFooterText == rSettings.maFooterText) &&
3141 		   (mbSlideNumberVisible == rSettings.mbSlideNumberVisible) &&
3142 		   (mbDateTimeVisible == rSettings.mbDateTimeVisible) &&
3143 		   (mbDateTimeIsFixed == rSettings.mbDateTimeIsFixed) &&
3144 		   (meDateTimeFormat == rSettings.meDateTimeFormat) &&
3145 		   (maDateTimeText == rSettings.maDateTimeText);
3146 }
3147 
3148