xref: /aoo41x/main/sd/source/ui/unoidl/unomodel.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 <com/sun/star/presentation/XPresentation2.hpp>
28 
29 #include <com/sun/star/lang/DisposedException.hpp>
30 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
31 #include <com/sun/star/lang/Locale.hpp>
32 #include <com/sun/star/style/XStyle.hpp>
33 #include <com/sun/star/awt/XDevice.hpp>
34 
35 #include <com/sun/star/embed/Aspects.hpp>
36 #include <com/sun/star/presentation/XPresentation2.hpp>
37 
38 #include <osl/mutex.hxx>
39 #include <comphelper/serviceinfohelper.hxx>
40 
41 #include <comphelper/sequence.hxx>
42 
43 #include <rtl/uuid.h>
44 #include <rtl/memory.h>
45 #include <editeng/unofield.hxx>
46 #include <unomodel.hxx>
47 #include <sfx2/dispatch.hxx>
48 #include <sfx2/bindings.hxx>
49 #include <vcl/svapp.hxx>
50 #include <editeng/UnoForbiddenCharsTable.hxx>
51 #include <svx/svdoutl.hxx>
52 #include <editeng/forbiddencharacterstable.hxx>
53 #include <svx/UnoNamespaceMap.hxx>
54 #include <svx/svdlayer.hxx>
55 #include <svx/svdsob.hxx>
56 #include <svx/unoapi.hxx>
57 #include <svx/unofill.hxx>
58 #include <svx/unopool.hxx>
59 #include <svx/svdorect.hxx>
60 #include <editeng/flditem.hxx>
61 #include <vos/mutex.hxx>
62 #include <toolkit/awt/vclxdevice.hxx>
63 #include <svx/svdpool.hxx>
64 #include <editeng/unolingu.hxx>
65 #include <svx/svdpagv.hxx>
66 #include <svtools/unoimap.hxx>
67 #include <svx/unoshape.hxx>
68 #include <editeng/unonrule.hxx>
69 #include <editeng/eeitem.hxx>
70 
71 // #99870# Support creation of GraphicObjectResolver and EmbeddedObjectResolver
72 #include <svx/xmleohlp.hxx>
73 #include <svx/xmlgrhlp.hxx>
74 #include "DrawDocShell.hxx"
75 #include "ViewShellBase.hxx"
76 #include <UnoDocumentSettings.hxx>
77 
78 #include <drawdoc.hxx>
79 #include <glob.hrc>
80 #include <sdresid.hxx>
81 #include <sdpage.hxx>
82 
83 #include <strings.hrc>
84 #include "unohelp.hxx"
85 #include <unolayer.hxx>
86 #include <unoprnms.hxx>
87 #include <unopage.hxx>
88 #include <unocpres.hxx>
89 #include <unoobj.hxx>
90 #include <stlpool.hxx>
91 #include <unopback.hxx>
92 #include <unokywds.hxx>
93 #include "FrameView.hxx"
94 #include "ClientView.hxx"
95 #include "ViewShell.hxx"
96 #include "app.hrc"
97 #include <vcl/pdfextoutdevdata.hxx>
98 #include <com/sun/star/presentation/AnimationEffect.hpp>
99 #include <com/sun/star/presentation/AnimationSpeed.hpp>
100 #include <com/sun/star/presentation/ClickAction.hpp>
101 #include <tools/urlobj.hxx>
102 #include <svx/sdr/contact/viewobjectcontact.hxx>
103 #include <svx/sdr/contact/viewcontact.hxx>
104 #include <svx/sdr/contact/displayinfo.hxx>
105 
106 #include <com/sun/star/office/XAnnotation.hpp>
107 #include <com/sun/star/office/XAnnotationAccess.hpp>
108 #include <com/sun/star/office/XAnnotationEnumeration.hpp>
109 #include <com/sun/star/geometry/RealPoint2D.hpp>
110 #include <com/sun/star/util/DateTime.hpp>
111 
112 using ::rtl::OUString;
113 
114 #include <drawinglayer/primitive2d/structuretagprimitive2d.hxx>
115 
116 using namespace ::osl;
117 using namespace ::vos;
118 using namespace ::cppu;
119 using namespace ::com::sun::star;
120 
121 extern uno::Reference< uno::XInterface > SdUnoCreatePool( SdDrawDocument* pDrawModel );
122 
123 class SdUnoForbiddenCharsTable : public SvxUnoForbiddenCharsTable,
124 								 public SfxListener
125 {
126 public:
127 	SdUnoForbiddenCharsTable( SdrModel* pModel );
128 	~SdUnoForbiddenCharsTable();
129 
130 	// SfxListener
131 	virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) throw ();
132 protected:
133 	virtual void onChange();
134 
135 private:
136 	SdrModel*	mpModel;
137 };
138 
139 SdUnoForbiddenCharsTable::SdUnoForbiddenCharsTable( SdrModel* pModel )
140 : SvxUnoForbiddenCharsTable( pModel->GetForbiddenCharsTable() ), mpModel( pModel )
141 {
142 	StartListening( *pModel );
143 }
144 
145 void SdUnoForbiddenCharsTable::onChange()
146 {
147 	if( mpModel )
148 	{
149 		mpModel->ReformatAllTextObjects();
150 	}
151 }
152 
153 SdUnoForbiddenCharsTable::~SdUnoForbiddenCharsTable()
154 {
155 	if( mpModel )
156 		EndListening( *mpModel );
157 }
158 
159 void SdUnoForbiddenCharsTable::Notify( SfxBroadcaster&, const SfxHint& rHint ) throw()
160 {
161 	const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint );
162 
163 	if( pSdrHint )
164 	{
165 		if( HINT_MODELCLEARED == pSdrHint->GetKind() )
166 		{
167 			mpModel = NULL;
168 		}
169 	}
170 }
171 
172 ///////////////////////////////////////////////////////////////////////
173 
174 const sal_Int32 WID_MODEL_LANGUAGE = 1;
175 const sal_Int32 WID_MODEL_TABSTOP  = 2;
176 const sal_Int32 WID_MODEL_VISAREA  = 3;
177 const sal_Int32 WID_MODEL_MAPUNIT  = 4;
178 const sal_Int32 WID_MODEL_FORBCHARS= 5;
179 const sal_Int32 WID_MODEL_CONTFOCUS = 6;
180 const sal_Int32 WID_MODEL_DSGNMODE	= 7;
181 const sal_Int32 WID_MODEL_BASICLIBS = 8;
182 const sal_Int32 WID_MODEL_RUNTIMEUID = 9;
183 const sal_Int32 WID_MODEL_BUILDID = 10;
184 const sal_Int32 WID_MODEL_HASVALIDSIGNATURES = 11;
185 const sal_Int32 WID_MODEL_DIALOGLIBS = 12;
186 
187 const SvxItemPropertySet* ImplGetDrawModelPropertySet()
188 {
189 	// Achtung: Der erste Parameter MUSS sortiert vorliegen !!!
190 	const static SfxItemPropertyMapEntry aDrawModelPropertyMap_Impl[] =
191 	{
192 		{ MAP_CHAR_LEN("BuildId"),						WID_MODEL_BUILDID,	&::getCppuType(static_cast< const rtl::OUString * >(0)), 0, 0},
193 		{ MAP_CHAR_LEN(sUNO_Prop_CharLocale),		  	WID_MODEL_LANGUAGE,	&::getCppuType((const lang::Locale*)0),		0,	0},
194 		{ MAP_CHAR_LEN(sUNO_Prop_TabStop),				WID_MODEL_TABSTOP,	&::getCppuType((const sal_Int32*)0),		0,  0},
195 		{ MAP_CHAR_LEN(sUNO_Prop_VisibleArea),			WID_MODEL_VISAREA,	&::getCppuType((const awt::Rectangle*)0),	0,	0},
196 		{ MAP_CHAR_LEN(sUNO_Prop_MapUnit),				WID_MODEL_MAPUNIT,	&::getCppuType((const sal_Int16*)0),		beans::PropertyAttribute::READONLY,	0},
197 		{ MAP_CHAR_LEN(sUNO_Prop_ForbiddenCharacters),	WID_MODEL_FORBCHARS,&::getCppuType((const uno::Reference< i18n::XForbiddenCharacters > *)0), beans::PropertyAttribute::READONLY, 0 },
198 		{ MAP_CHAR_LEN(sUNO_Prop_AutomContFocus ),	WID_MODEL_CONTFOCUS,	&::getBooleanCppuType(),					0,	0},
199 		{ MAP_CHAR_LEN(sUNO_Prop_ApplyFrmDsgnMode),	WID_MODEL_DSGNMODE,		&::getBooleanCppuType(),					0,	0},
200 		{ MAP_CHAR_LEN("BasicLibraries"),				WID_MODEL_BASICLIBS,&::getCppuType((const uno::Reference< script::XLibraryContainer > *)0), beans::PropertyAttribute::READONLY, 0 },
201         { MAP_CHAR_LEN("DialogLibraries"),              WID_MODEL_DIALOGLIBS,   &::getCppuType((const uno::Reference< script::XLibraryContainer > *)0), beans::PropertyAttribute::READONLY, 0 },
202         { MAP_CHAR_LEN(sUNO_Prop_RuntimeUID),           WID_MODEL_RUNTIMEUID,   &::getCppuType(static_cast< const rtl::OUString * >(0)), beans::PropertyAttribute::READONLY, 0 },
203         { MAP_CHAR_LEN(sUNO_Prop_HasValidSignatures),   WID_MODEL_HASVALIDSIGNATURES, &::getCppuType(static_cast< const sal_Bool * >(0)), beans::PropertyAttribute::READONLY, 0 },
204 		{ 0,0,0,0,0,0 }
205 	};
206     static SvxItemPropertySet aDrawModelPropertySet_Impl( aDrawModelPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
207     return &aDrawModelPropertySet_Impl;
208 }
209 
210 // this ctor is used from the DocShell
211 SdXImpressDocument::SdXImpressDocument (::sd::DrawDocShell* pShell, bool bClipBoard ) throw()
212 :	SfxBaseModel( pShell ),
213 	mpDocShell( pShell ),
214     mpDoc( pShell ? pShell->GetDoc() : NULL ),
215 	mbDisposed(false),
216 	mbImpressDoc( pShell && pShell->GetDoc() && pShell->GetDoc()->GetDocumentType() == DOCUMENT_TYPE_IMPRESS ),
217 	mbClipBoard( bClipBoard ),
218 	mpPropSet( ImplGetDrawModelPropertySet() )
219 {
220 	if( mpDoc )
221 	{
222 		StartListening( *mpDoc );
223 	}
224 	else
225 	{
226 		DBG_ERROR("DocShell is invalid");
227 	}
228 }
229 
230 SdXImpressDocument::SdXImpressDocument( SdDrawDocument* pDoc, bool bClipBoard ) throw()
231 :	SfxBaseModel( NULL ),
232 	mpDocShell( NULL ),
233 	mpDoc( pDoc ),
234 	mbDisposed(false),
235 	mbImpressDoc( pDoc && pDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS ),
236 	mbClipBoard( bClipBoard ),
237 	mpPropSet( ImplGetDrawModelPropertySet() )
238 {
239 	if( mpDoc )
240 	{
241 		StartListening( *mpDoc );
242 	}
243 	else
244 	{
245 		DBG_ERROR("SdDrawDocument is invalid");
246 	}
247 }
248 
249 /***********************************************************************
250 *                                                                      *
251 ***********************************************************************/
252 SdXImpressDocument::~SdXImpressDocument() throw()
253 {
254 }
255 
256 // uno helper
257 
258 
259 /******************************************************************************
260 * Erzeugt anhand der uebergebennen SdPage eine SdDrawPage. Wurde fuer diese   *
261 * SdPage bereits eine SdDrawPage erzeugt, wird keine neue SdDrawPage erzeug.  *
262 ******************************************************************************/
263 /*
264 uno::Reference< drawing::XDrawPage >  SdXImpressDocument::CreateXDrawPage( SdPage* pPage ) throw()
265 {
266 	DBG_ASSERT(pPage,"SdXImpressDocument::CreateXDrawPage( NULL? )");
267 
268 	uno::Reference< drawing::XDrawPage >  xDrawPage;
269 
270 	if(pPage)
271 	{
272 		xDrawPage = SvxDrawPage::GetPageForSdrPage(pPage);
273 
274 		if(!xDrawPage.is())
275 		{
276 			if(pPage->IsMasterPage())
277 			{
278 				xDrawPage = (presentation::XPresentationPage*)new SdMasterPage( this, pPage );
279 			}
280 			else
281 			{
282 				xDrawPage = (SvxDrawPage*)new SdDrawPage( this, pPage );
283 			}
284 		}
285 	}
286 
287 	return xDrawPage;
288 }
289 */
290 
291 // XInterface
292 uno::Any SAL_CALL SdXImpressDocument::queryInterface( const uno::Type & rType ) throw(uno::RuntimeException)
293 {
294 	uno::Any aAny;
295 
296 	QUERYINT(lang::XServiceInfo);
297 	else QUERYINT(beans::XPropertySet);
298 	else QUERYINT(lang::XMultiServiceFactory);
299 	else QUERYINT(drawing::XDrawPageDuplicator);
300 	else QUERYINT(drawing::XLayerSupplier);
301 	else QUERYINT(drawing::XMasterPagesSupplier);
302 	else QUERYINT(drawing::XDrawPagesSupplier);
303 	else QUERYINT(presentation::XHandoutMasterSupplier);
304 	else QUERYINT(document::XLinkTargetSupplier);
305 	else QUERYINT(style::XStyleFamiliesSupplier);
306 	else QUERYINT(com::sun::star::ucb::XAnyCompareFactory);
307 	else QUERYINT(view::XRenderable);
308 	else if( mbImpressDoc && rType == ITYPE(presentation::XPresentationSupplier) )
309 			aAny <<= uno::Reference< presentation::XPresentationSupplier >(this);
310 	else if( mbImpressDoc && rType == ITYPE(presentation::XCustomPresentationSupplier) )
311 			aAny <<= uno::Reference< presentation::XCustomPresentationSupplier >(this);
312 	else
313 		return SfxBaseModel::queryInterface( rType );
314 
315 	return aAny;
316 }
317 
318 void SAL_CALL SdXImpressDocument::acquire() throw ( )
319 {
320 	SfxBaseModel::acquire();
321 }
322 
323 void SAL_CALL SdXImpressDocument::release() throw ( )
324 {
325     if (osl_decrementInterlockedCount( &m_refCount ) == 0)
326 	{
327         // restore reference count:
328         osl_incrementInterlockedCount( &m_refCount );
329         if(!mbDisposed)
330 		{
331             try
332 			{
333                 dispose();
334             }
335 			catch (uno::RuntimeException const& exc)
336 			{ // don't break throw ()
337                 OSL_ENSURE(
338                     false, OUStringToOString(
339                         exc.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
340                 static_cast<void>(exc);
341             }
342         }
343         SfxBaseModel::release();
344     }
345 }
346 
347 // XUnoTunnel
348 const ::com::sun::star::uno::Sequence< sal_Int8 > & SdXImpressDocument::getUnoTunnelId() throw()
349 {
350     static ::com::sun::star::uno::Sequence< sal_Int8 > * pSeq = 0;
351     if( !pSeq )
352     {
353         ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() );
354         if( !pSeq )
355         {
356             static ::com::sun::star::uno::Sequence< sal_Int8 > aSeq( 16 );
357             rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
358             pSeq = &aSeq;
359         }
360     }
361     return *pSeq;
362 }
363 
364 SdXImpressDocument* SdXImpressDocument::getImplementation( const uno::Reference< uno::XInterface >& xInt )
365 {
366     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUT( xInt, ::com::sun::star::uno::UNO_QUERY );
367     if( xUT.is() )
368         return reinterpret_cast<SdXImpressDocument*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething( SdXImpressDocument::getUnoTunnelId() )));
369     else
370         return NULL;
371 }
372 
373 sal_Int64 SAL_CALL SdXImpressDocument::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rIdentifier ) throw(::com::sun::star::uno::RuntimeException)
374 {
375     if( rIdentifier.getLength() == 16 )
376     {
377         if( (0 == rtl_compareMemory( SdXImpressDocument::getUnoTunnelId().getConstArray(), rIdentifier.getConstArray(), 16 )) )
378             return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
379 
380         if( (0 == rtl_compareMemory( SdrModel::getUnoTunnelImplementationId().getConstArray(), rIdentifier.getConstArray(), 16 )) )
381             return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(mpDoc));
382     }
383 
384     return SfxBaseModel::getSomething( rIdentifier );
385 }
386 
387 // XTypeProvider
388 uno::Sequence< uno::Type > SAL_CALL SdXImpressDocument::getTypes(  ) throw(uno::RuntimeException)
389 {
390 	OGuard aGuard( Application::GetSolarMutex() );
391 
392 	if( maTypeSequence.getLength() == 0 )
393 	{
394 		const uno::Sequence< uno::Type > aBaseTypes( SfxBaseModel::getTypes() );
395 		const sal_Int32 nBaseTypes = aBaseTypes.getLength();
396 		const uno::Type* pBaseTypes = aBaseTypes.getConstArray();
397 
398 		const sal_Int32 nOwnTypes = mbImpressDoc ? 14 : 11;		// !DANGER! Keep this updated!
399 
400 		maTypeSequence.realloc(  nBaseTypes + nOwnTypes );
401 		uno::Type* pTypes = maTypeSequence.getArray();
402 
403 		*pTypes++ = ITYPE(beans::XPropertySet);
404 		*pTypes++ = ITYPE(lang::XServiceInfo);
405 		*pTypes++ = ITYPE(lang::XMultiServiceFactory);
406 		*pTypes++ = ITYPE(drawing::XDrawPageDuplicator);
407 		*pTypes++ = ITYPE(drawing::XLayerSupplier);
408 		*pTypes++ = ITYPE(drawing::XMasterPagesSupplier);
409 		*pTypes++ = ITYPE(drawing::XDrawPagesSupplier);
410 		*pTypes++ = ITYPE(document::XLinkTargetSupplier);
411 		*pTypes++ = ITYPE(style::XStyleFamiliesSupplier);
412 		*pTypes++ = ITYPE(com::sun::star::ucb::XAnyCompareFactory);
413 		*pTypes++ = ITYPE(view::XRenderable);
414 		if( mbImpressDoc )
415 		{
416 			*pTypes++ = ITYPE(presentation::XPresentationSupplier);
417 			*pTypes++ = ITYPE(presentation::XCustomPresentationSupplier);
418 			*pTypes++ = ITYPE(presentation::XHandoutMasterSupplier);
419 		}
420 
421 		for( sal_Int32 nType = 0; nType < nBaseTypes; nType++ )
422 			*pTypes++ = *pBaseTypes++;
423 	}
424 
425 	return maTypeSequence;
426 }
427 
428 uno::Sequence< sal_Int8 > SAL_CALL SdXImpressDocument::getImplementationId(  ) throw(uno::RuntimeException)
429 {
430 	OGuard aGuard( Application::GetSolarMutex() );
431 
432 	static uno::Sequence< sal_Int8 > aId;
433 	if( aId.getLength() == 0 )
434 	{
435 		aId.realloc( 16 );
436 		rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
437 	}
438 	return aId;
439 }
440 
441 /***********************************************************************
442 *                                                                      *
443 ***********************************************************************/
444 void SdXImpressDocument::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
445 {
446 	if( mpDoc )
447 	{
448 		const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint );
449 
450 		if( pSdrHint )
451 		{
452 			if( hasEventListeners() )
453 			{
454 				document::EventObject aEvent;
455 				if( SvxUnoDrawMSFactory::createEvent( mpDoc, pSdrHint, aEvent ) )
456 					notifyEvent( aEvent );
457 			}
458 
459 			if( pSdrHint->GetKind() == HINT_MODELCLEARED )
460 			{
461 				if( mpDoc )
462 					EndListening( *mpDoc );
463 				mpDoc = NULL;
464 				mpDocShell = NULL;
465 			}
466 		}
467 		else
468 		{
469 			const SfxSimpleHint* pSfxHint = PTR_CAST(SfxSimpleHint, &rHint );
470 
471 			// ist unser SdDrawDocument gerade gestorben?
472 			if(pSfxHint && pSfxHint->GetId() == SFX_HINT_DYING)
473 			{
474 				// yup, also schnell ein neues erfragen
475 				if( mpDocShell )
476 				{
477 					SdDrawDocument *pNewDoc = mpDocShell->GetDoc();
478 
479 					// ist ueberhaupt ein neues da?
480 					if( pNewDoc != mpDoc )
481 					{
482 						mpDoc = pNewDoc;
483 						if(mpDoc)
484 							StartListening( *mpDoc );
485 					}
486 				}
487 			}
488 		}
489 	}
490 	SfxBaseModel::Notify( rBC, rHint );
491 }
492 
493 /******************************************************************************
494 *                                                                             *
495 ******************************************************************************/
496 SdPage* SdXImpressDocument::InsertSdPage( sal_uInt16 nPage, sal_Bool bDuplicate ) throw()
497 {
498 	sal_uInt16 nPageCount = mpDoc->GetSdPageCount( PK_STANDARD );
499 	SdrLayerAdmin& rLayerAdmin = mpDoc->GetLayerAdmin();
500 	sal_uInt8 aBckgrnd = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRND)), sal_False);
501 	sal_uInt8 aBckgrndObj = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ)), sal_False);
502 
503 	SdPage* pStandardPage = NULL;
504 
505 	if( 0 == nPageCount )
506 	{
507 		// this is only used for clipboard where we only have one page
508 		pStandardPage = (SdPage*) mpDoc->AllocPage(sal_False);
509 
510 		Size aDefSize(21000, 29700);   // A4-Hochformat
511 		pStandardPage->SetSize( aDefSize );
512 		mpDoc->InsertPage(pStandardPage, 0);
513 	}
514 	else
515 	{
516 		// Hier wird die Seite ermittelt, hinter der eingefuegt werden soll
517 		SdPage* pPreviousStandardPage = mpDoc->GetSdPage( Min( (sal_uInt16)(nPageCount - 1), nPage ), PK_STANDARD );
518 		SetOfByte aVisibleLayers = pPreviousStandardPage->TRG_GetMasterPageVisibleLayers();
519 		sal_Bool bIsPageBack = aVisibleLayers.IsSet( aBckgrnd );
520 		sal_Bool bIsPageObj = aVisibleLayers.IsSet( aBckgrndObj );
521 
522 		// AutoLayouts muessen fertig sein
523 		mpDoc->StopWorkStartupDelay();
524 
525 		/**************************************************************
526 		* Es wird stets zuerst eine Standardseite und dann eine
527 		* Notizseite erzeugt. Es ist sichergestellt, dass auf eine
528 		* Standardseite stets die zugehoerige Notizseite folgt.
529 		**************************************************************/
530 
531 		sal_uInt16 nStandardPageNum = pPreviousStandardPage->GetPageNum() + 2;
532 		SdPage* pPreviousNotesPage = (SdPage*) mpDoc->GetPage( nStandardPageNum - 1 );
533 		sal_uInt16 nNotesPageNum = nStandardPageNum + 1;
534 		String aStandardPageName;
535 		String aNotesPageName;
536 
537 		/**************************************************************
538 		* Standardseite
539 		**************************************************************/
540 		if( bDuplicate )
541 			pStandardPage = (SdPage*) pPreviousStandardPage->Clone();
542 		else
543 			pStandardPage = (SdPage*) mpDoc->AllocPage(sal_False);
544 
545 		pStandardPage->SetSize( pPreviousStandardPage->GetSize() );
546 		pStandardPage->SetBorder( pPreviousStandardPage->GetLftBorder(),
547 									pPreviousStandardPage->GetUppBorder(),
548 									pPreviousStandardPage->GetRgtBorder(),
549 									pPreviousStandardPage->GetLwrBorder() );
550 		pStandardPage->SetOrientation( pPreviousStandardPage->GetOrientation() );
551 		pStandardPage->SetName(aStandardPageName);
552 
553 		// Seite hinter aktueller Seite einfuegen
554 		mpDoc->InsertPage(pStandardPage, nStandardPageNum);
555 
556 		if( !bDuplicate )
557 		{
558 			// MasterPage der aktuellen Seite verwenden
559 			pStandardPage->TRG_SetMasterPage(pPreviousStandardPage->TRG_GetMasterPage());
560 			pStandardPage->SetLayoutName( pPreviousStandardPage->GetLayoutName() );
561 			pStandardPage->SetAutoLayout(AUTOLAYOUT_NONE, sal_True );
562 		}
563 
564 		aBckgrnd = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRND)), sal_False);
565 		aBckgrndObj = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ)), sal_False);
566 		aVisibleLayers.Set(aBckgrnd, bIsPageBack);
567 		aVisibleLayers.Set(aBckgrndObj, bIsPageObj);
568 		pStandardPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
569 
570 		/**************************************************************
571 		* Notizseite
572 		**************************************************************/
573 		SdPage* pNotesPage = NULL;
574 
575 		if( bDuplicate )
576 			pNotesPage = (SdPage*) pPreviousNotesPage->Clone();
577 		else
578 			pNotesPage = (SdPage*) mpDoc->AllocPage(sal_False);
579 
580 		pNotesPage->SetSize( pPreviousNotesPage->GetSize() );
581 		pNotesPage->SetBorder( pPreviousNotesPage->GetLftBorder(),
582 								pPreviousNotesPage->GetUppBorder(),
583 								pPreviousNotesPage->GetRgtBorder(),
584 								pPreviousNotesPage->GetLwrBorder() );
585 		pNotesPage->SetOrientation( pPreviousNotesPage->GetOrientation() );
586 		pNotesPage->SetName(aNotesPageName);
587 		pNotesPage->SetPageKind(PK_NOTES);
588 
589 		// Seite hinter aktueller Seite einfuegen
590 		mpDoc->InsertPage(pNotesPage, nNotesPageNum);
591 
592 		if( !bDuplicate )
593 		{
594 			// MasterPage der aktuellen Seite verwenden
595 			pNotesPage->TRG_SetMasterPage(pPreviousNotesPage->TRG_GetMasterPage());
596 			pNotesPage->SetLayoutName( pPreviousNotesPage->GetLayoutName() );
597 			pNotesPage->SetAutoLayout(AUTOLAYOUT_NOTES, sal_True );
598 		}
599 	}
600 
601 	SetModified();
602 
603 	return( pStandardPage );
604 }
605 
606 void SdXImpressDocument::SetModified( sal_Bool bModified /* = sal_True */ ) throw()
607 {
608 	if( mpDoc )
609 		mpDoc->SetChanged( bModified );
610 }
611 
612 // XModel
613 void SAL_CALL SdXImpressDocument	::lockControllers(  )
614 	throw(uno::RuntimeException)
615 {
616 	OGuard aGuard( Application::GetSolarMutex() );
617 
618 	if( NULL == mpDoc )
619 		throw lang::DisposedException();
620 
621 	mpDoc->setLock( sal_True );
622 }
623 
624 void SAL_CALL SdXImpressDocument::unlockControllers(  )
625 	throw(uno::RuntimeException)
626 {
627 	OGuard aGuard( Application::GetSolarMutex() );
628 
629 	if( NULL == mpDoc )
630 		throw lang::DisposedException();
631 
632 	if( mpDoc->isLocked() )
633 	{
634 		mpDoc->setLock( sal_False );
635 	}
636 }
637 
638 sal_Bool SAL_CALL SdXImpressDocument::hasControllersLocked(  )
639 	throw(uno::RuntimeException)
640 {
641 	OGuard aGuard( Application::GetSolarMutex() );
642 
643 	if( NULL == mpDoc )
644 		throw lang::DisposedException();
645 
646 	return mpDoc && mpDoc->isLocked();
647 }
648 
649 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
650 #include <comphelper/processfactory.hxx>
651 #endif
652 
653 uno::Reference < container::XIndexAccess > SAL_CALL SdXImpressDocument::getViewData() throw( uno::RuntimeException )
654 {
655 	OGuard aGuard( Application::GetSolarMutex() );
656 
657 	if( NULL == mpDoc )
658 		throw lang::DisposedException();
659 
660 	uno::Reference < container::XIndexAccess > xRet( SfxBaseModel::getViewData() );
661 
662 	if( !xRet.is() )
663 	{
664 		List* pFrameViewList = mpDoc->GetFrameViewList();
665 
666 		if( pFrameViewList && pFrameViewList->Count() )
667 		{
668 			xRet = uno::Reference < container::XIndexAccess >::query(::comphelper::getProcessServiceFactory()->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.IndexedPropertyValues"))));
669 
670 
671 			uno::Reference < container::XIndexContainer > xCont( xRet, uno::UNO_QUERY );
672 			DBG_ASSERT( xCont.is(), "SdXImpressDocument::getViewData() failed for OLE object" );
673 			if( xCont.is() )
674 			{
675 				sal_uInt32 i;
676 				for( i = 0; i < pFrameViewList->Count(); i++ )
677 				{
678 					::sd::FrameView* pFrameView =
679                           static_cast< ::sd::FrameView*>(
680                               pFrameViewList->GetObject(i));
681 
682 					if(pFrameView)
683 					{
684 						uno::Sequence< beans::PropertyValue > aSeq;
685 						pFrameView->WriteUserDataSequence( aSeq );
686 						xCont->insertByIndex( i, uno::makeAny( aSeq ) );
687 					}
688 				}
689 			}
690 		}
691 	}
692 
693 	return xRet;
694 }
695 
696 void SAL_CALL SdXImpressDocument::setViewData( const uno::Reference < container::XIndexAccess >& xData ) throw(::com::sun::star::uno::RuntimeException)
697 {
698 	OGuard aGuard( Application::GetSolarMutex() );
699 
700 	if( NULL == mpDoc )
701 		throw lang::DisposedException();
702 
703 	SfxBaseModel::setViewData( xData );
704 	if( mpDocShell && (mpDocShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED) && xData.is() )
705 	{
706 		const sal_Int32 nCount = xData->getCount();
707 
708 		List* pFrameViewList = mpDoc->GetFrameViewList();
709 
710 		DBG_ASSERT( pFrameViewList, "No FrameViewList?" );
711 		if( pFrameViewList )
712 		{
713 			::sd::FrameView* pFrameView;
714 
715 			sal_uInt32 i;
716 			for ( i = 0; i < pFrameViewList->Count(); i++)
717 			{
718 				// Ggf. FrameViews loeschen
719 				pFrameView = static_cast< ::sd::FrameView*>(
720                     pFrameViewList->GetObject(i));
721 
722 				if (pFrameView)
723 					delete pFrameView;
724 			}
725 
726 			pFrameViewList->Clear();
727 
728 			uno::Sequence< beans::PropertyValue > aSeq;
729 			sal_Int32 nIndex;
730 			for( nIndex = 0; nIndex < nCount; nIndex++ )
731 			{
732 				if( xData->getByIndex( nIndex ) >>= aSeq )
733 				{
734 					pFrameView = new ::sd::FrameView( mpDoc );
735 					pFrameView->ReadUserDataSequence( aSeq );
736 					pFrameViewList->Insert( pFrameView );
737 				}
738 			}
739 		}
740 	}
741 }
742 
743 // XDrawPageDuplicator
744 uno::Reference< drawing::XDrawPage > SAL_CALL SdXImpressDocument::duplicate( const uno::Reference< drawing::XDrawPage >& xPage )
745 	throw(uno::RuntimeException)
746 {
747 	OGuard aGuard( Application::GetSolarMutex() );
748 
749 	if( NULL == mpDoc )
750 		throw lang::DisposedException();
751 
752 	// pPage von xPage besorgen und dann die Id (nPos )ermitteln
753 	SvxDrawPage* pSvxPage = SvxDrawPage::getImplementation( xPage );
754 	if( pSvxPage )
755 	{
756 		SdPage* pPage = (SdPage*) pSvxPage->GetSdrPage();
757 		sal_uInt16 nPos = pPage->GetPageNum();
758 		nPos = ( nPos - 1 ) / 2;
759 		pPage = InsertSdPage( nPos, sal_True );
760 		if( pPage )
761 		{
762 			uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
763 			return xDrawPage;
764 		}
765 	}
766 
767 	uno::Reference< drawing::XDrawPage > xDrawPage;
768 	return xDrawPage;
769 }
770 
771 
772 // XDrawPagesSupplier
773 uno::Reference< drawing::XDrawPages > SAL_CALL SdXImpressDocument::getDrawPages()
774 	throw(uno::RuntimeException)
775 {
776 	OGuard aGuard( Application::GetSolarMutex() );
777 
778 	if( NULL == mpDoc )
779 		throw lang::DisposedException();
780 
781 	uno::Reference< drawing::XDrawPages >  xDrawPages( mxDrawPagesAccess );
782 
783 	if( !xDrawPages.is() )
784 	{
785 		initializeDocument();
786 		mxDrawPagesAccess = xDrawPages = (drawing::XDrawPages*)new SdDrawPagesAccess(*this);
787 	}
788 
789 	return xDrawPages;
790 }
791 
792 // XMasterPagesSupplier
793 uno::Reference< drawing::XDrawPages > SAL_CALL SdXImpressDocument::getMasterPages()
794 	throw(uno::RuntimeException)
795 {
796 	OGuard aGuard( Application::GetSolarMutex() );
797 
798 	if( NULL == mpDoc )
799 		throw lang::DisposedException();
800 
801 	uno::Reference< drawing::XDrawPages >  xMasterPages( mxMasterPagesAccess );
802 
803 	if( !xMasterPages.is() )
804 	{
805 		initializeDocument();
806 		mxMasterPagesAccess = xMasterPages = new SdMasterPagesAccess(*this);
807 	}
808 
809 	return xMasterPages;
810 }
811 
812 // XLayerManagerSupplier
813 uno::Reference< container::XNameAccess > SAL_CALL SdXImpressDocument::getLayerManager(  )
814 	throw(uno::RuntimeException)
815 {
816 	OGuard aGuard( Application::GetSolarMutex() );
817 
818 	if( NULL == mpDoc )
819 		throw lang::DisposedException();
820 
821 	uno::Reference< container::XNameAccess >  xLayerManager( mxLayerManager );
822 
823 	if( !xLayerManager.is() )
824 		mxLayerManager = xLayerManager = new SdLayerManager(*this);
825 
826 	return xLayerManager;
827 }
828 
829 // XCustomPresentationSupplier
830 uno::Reference< container::XNameContainer > SAL_CALL SdXImpressDocument::getCustomPresentations()
831 	throw(uno::RuntimeException)
832 {
833 	OGuard aGuard( Application::GetSolarMutex() );
834 
835 	if( NULL == mpDoc )
836 		throw lang::DisposedException();
837 
838 	uno::Reference< container::XNameContainer >  xCustomPres( mxCustomPresentationAccess );
839 
840 	if( !xCustomPres.is() )
841 		mxCustomPresentationAccess = xCustomPres = new SdXCustomPresentationAccess(*this);
842 
843 	return xCustomPres;
844 }
845 
846 extern uno::Reference< presentation::XPresentation > createPresentation( SdXImpressDocument& rModel );
847 
848 // XPresentationSupplier
849 uno::Reference< presentation::XPresentation > SAL_CALL SdXImpressDocument::getPresentation()
850 	throw(uno::RuntimeException)
851 {
852 	OGuard aGuard( Application::GetSolarMutex() );
853 
854 	if( NULL == mpDoc )
855 		throw lang::DisposedException();
856 
857 	return uno::Reference< presentation::XPresentation >( mpDoc->getPresentation().get() );
858 }
859 
860 // XHandoutMasterSupplier
861 uno::Reference< drawing::XDrawPage > SAL_CALL SdXImpressDocument::getHandoutMasterPage()
862 	throw (uno::RuntimeException)
863 {
864 	OGuard aGuard( Application::GetSolarMutex() );
865 
866 	if( NULL == mpDoc )
867 		throw lang::DisposedException();
868 
869 	uno::Reference< drawing::XDrawPage > xPage;
870 
871 	if( mpDoc )
872 	{
873 		initializeDocument();
874 		SdPage* pPage = mpDoc->GetMasterSdPage( 0, PK_HANDOUT );
875 		if( pPage )
876 			xPage = uno::Reference< drawing::XDrawPage >::query( pPage->getUnoPage() );
877 	}
878 	return xPage;
879 }
880 
881 // XMultiServiceFactory ( SvxFmMSFactory )
882 uno::Reference< uno::XInterface > SAL_CALL SdXImpressDocument::createInstance( const OUString& aServiceSpecifier )
883 	throw(uno::Exception, uno::RuntimeException)
884 {
885 	OGuard aGuard( Application::GetSolarMutex() );
886 
887 	if( NULL == mpDoc )
888 		throw lang::DisposedException();
889 
890 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.DashTable") ) )
891 	{
892 		if( !mxDashTable.is() )
893 			mxDashTable = SvxUnoDashTable_createInstance( mpDoc );
894 
895 		return mxDashTable;
896 	}
897 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.GradientTable") ) )
898 	{
899 		if( !mxGradientTable.is() )
900 			mxGradientTable = SvxUnoGradientTable_createInstance( mpDoc );
901 
902 		return mxGradientTable;
903 	}
904 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.HatchTable") ) )
905 	{
906 		if( !mxHatchTable.is() )
907 			mxHatchTable = SvxUnoHatchTable_createInstance( mpDoc );
908 
909 		return mxHatchTable;
910 	}
911 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.BitmapTable") ) )
912 	{
913 		if( !mxBitmapTable.is() )
914 			mxBitmapTable = SvxUnoBitmapTable_createInstance( mpDoc );
915 
916 		return mxBitmapTable;
917 	}
918 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.TransparencyGradientTable") ) )
919 	{
920 		if( !mxTransGradientTable.is() )
921 			mxTransGradientTable = SvxUnoTransGradientTable_createInstance( mpDoc );
922 
923 		return mxTransGradientTable;
924 	}
925 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.MarkerTable") ) )
926 	{
927 		if( !mxMarkerTable.is() )
928 			mxMarkerTable = SvxUnoMarkerTable_createInstance( mpDoc );
929 
930 		return mxMarkerTable;
931 	}
932 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.NumberingRules" ) ) )
933 	{
934 		return uno::Reference< uno::XInterface >( SvxCreateNumRule( mpDoc ), uno::UNO_QUERY );
935 	}
936 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.Background" ) ) )
937 	{
938 		return uno::Reference< uno::XInterface >(
939             static_cast<uno::XWeak*>(new SdUnoPageBackground( mpDoc )));
940 	}
941 
942 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.Defaults") ) )
943 	{
944 		if( !mxDrawingPool.is() )
945 			mxDrawingPool = SdUnoCreatePool( mpDoc );
946 
947 		return mxDrawingPool;
948 
949 	}
950 
951 	if( aServiceSpecifier.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(sUNO_Service_ImageMapRectangleObject) ) )
952 	{
953 		return SvUnoImageMapRectangleObject_createInstance( ImplGetSupportedMacroItems() );
954 	}
955 
956 	if( aServiceSpecifier.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(sUNO_Service_ImageMapCircleObject) ) )
957 	{
958 		return SvUnoImageMapCircleObject_createInstance( ImplGetSupportedMacroItems() );
959 	}
960 
961 	if( aServiceSpecifier.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(sUNO_Service_ImageMapPolygonObject) ) )
962 	{
963 		return SvUnoImageMapPolygonObject_createInstance( ImplGetSupportedMacroItems() );
964 	}
965 
966 	if( ( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.document.Settings") ) ) ||
967 		( !mbImpressDoc && ( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.DocumentSettings") ) ) ) ||
968 		( mbImpressDoc && ( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation.DocumentSettings") ) ) ) )
969 	{
970 		return sd::DocumentSettings_createInstance( this );
971 	}
972 
973 	if( ( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.TextField.DateTime") ) ) ||
974 	    ( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.textfield.DateTime") ) ) )
975 	{
976 		return (::cppu::OWeakObject * )new SvxUnoTextField( ID_EXT_DATEFIELD );
977 	}
978 
979 	if( (0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation.TextField.Header"))) ||
980 	    (0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation.textfield.Header"))) )
981 	{
982 		return (::cppu::OWeakObject * )new SvxUnoTextField( ID_HEADERFIELD );
983 	}
984 
985 	if( (0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation.TextField.Footer"))) ||
986 	    (0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation.textfield.Footer"))) )
987 	{
988 		return (::cppu::OWeakObject * )new SvxUnoTextField( ID_FOOTERFIELD );
989 	}
990 
991 	if( (0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation.TextField.DateTime"))) ||
992 	    (0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.presentation.textfield.DateTime"))) )
993 	{
994 		return (::cppu::OWeakObject * )new SvxUnoTextField( ID_DATETIMEFIELD );
995 	}
996 
997 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.xml.NamespaceMap") ) )
998 	{
999 		static sal_uInt16 aWhichIds[] = { SDRATTR_XMLATTRIBUTES, EE_CHAR_XMLATTRIBS, EE_PARA_XMLATTRIBS, 0 };
1000 
1001 		return svx::NamespaceMap_createInstance( aWhichIds, &mpDoc->GetItemPool() );
1002 	}
1003 
1004 	// #99870# Support creation of GraphicObjectResolver and EmbeddedObjectResolver
1005 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.document.ExportGraphicObjectResolver") ) )
1006 	{
1007 		return (::cppu::OWeakObject * )new SvXMLGraphicHelper( GRAPHICHELPER_MODE_WRITE );
1008 	}
1009 
1010 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.document.ImportGraphicObjectResolver") ) )
1011 	{
1012 		return (::cppu::OWeakObject * )new SvXMLGraphicHelper( GRAPHICHELPER_MODE_READ );
1013 	}
1014 
1015 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.document.ExportEmbeddedObjectResolver") ) )
1016 	{
1017         ::comphelper::IEmbeddedHelper *pPersist = mpDoc ? mpDoc->GetPersist() : NULL;
1018 		if( NULL == pPersist )
1019 			throw lang::DisposedException();
1020 
1021 		return (::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pPersist, EMBEDDEDOBJECTHELPER_MODE_WRITE );
1022 	}
1023 
1024 	if( 0 == aServiceSpecifier.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.document.ImportEmbeddedObjectResolver") ) )
1025 	{
1026         ::comphelper::IEmbeddedHelper *pPersist = mpDoc ? mpDoc->GetPersist() : NULL;
1027 		if( NULL == pPersist )
1028 			throw lang::DisposedException();
1029 
1030 		return (::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pPersist, EMBEDDEDOBJECTHELPER_MODE_READ );
1031     }
1032 
1033 	uno::Reference< uno::XInterface > xRet;
1034 
1035 	const String aType( aServiceSpecifier );
1036 	if( aType.EqualsAscii( "com.sun.star.presentation.", 0, 26 ) )
1037 	{
1038 		SvxShape* pShape = NULL;
1039 
1040 		sal_uInt16 nType = OBJ_TEXT;
1041 		// create a shape wrapper
1042 		if( aType.EqualsAscii( "TitleTextShape", 26, 14 ) )
1043 		{
1044 			nType = OBJ_TEXT;
1045 		}
1046 		else if( aType.EqualsAscii( "OutlinerShape", 26, 13 ) )
1047 		{
1048 			nType = OBJ_TEXT;
1049 		}
1050 		else if( aType.EqualsAscii( "SubtitleShape", 26, 13 ) )
1051 		{
1052 			nType = OBJ_TEXT;
1053 		}
1054 		else if( aType.EqualsAscii( "GraphicObjectShape", 26, 18 ) )
1055 		{
1056 			nType = OBJ_GRAF;
1057 		}
1058 		else if( aType.EqualsAscii( "PageShape", 26, 9 ) )
1059 		{
1060 			nType = OBJ_PAGE;
1061 		}
1062 		else if( aType.EqualsAscii( "OLE2Shape", 26, 9 ) )
1063 		{
1064 			nType = OBJ_OLE2;
1065 		}
1066 		else if( aType.EqualsAscii( "ChartShape", 26, 10 ) )
1067 		{
1068 			nType = OBJ_OLE2;
1069 		}
1070 		else if( aType.EqualsAscii( "CalcShape", 26, 9 ) )
1071 		{
1072 			nType = OBJ_OLE2;
1073 		}
1074 		else if( aType.EqualsAscii( "TableShape", 26, 10 ) )
1075 		{
1076 			nType = OBJ_TABLE;
1077 		}
1078 		else if( aType.EqualsAscii( "OrgChartShape", 26, 13 ) )
1079 		{
1080 			nType = OBJ_OLE2;
1081 		}
1082 		else if( aType.EqualsAscii( "NotesShape", 26, 13 ) )
1083 		{
1084 			nType = OBJ_TEXT;
1085 		}
1086 		else if( aType.EqualsAscii( "HandoutShape", 26, 13 ) )
1087 		{
1088 			nType = OBJ_PAGE;
1089 		}
1090 		else if( aType.EqualsAscii( "FooterShape", 26, 12 ) )
1091 		{
1092 			nType = OBJ_TEXT;
1093 		}
1094 		else if( aType.EqualsAscii( "HeaderShape", 26, 12 ) )
1095 		{
1096 			nType = OBJ_TEXT;
1097 		}
1098 		else if( aType.EqualsAscii( "SlideNumberShape", 26, 17 ) )
1099 		{
1100 			nType = OBJ_TEXT;
1101 		}
1102 		else if( aType.EqualsAscii( "DateTimeShape", 26, 17 ) )
1103 		{
1104 			nType = OBJ_TEXT;
1105 		}
1106 		else if( aType.EqualsAscii( "MediaShape", 26, 10 ) )
1107 		{
1108 			nType = OBJ_MEDIA;
1109 		}
1110 		else
1111 		{
1112 			throw lang::ServiceNotRegisteredException();
1113 		}
1114 
1115 		// create the API wrapper
1116 		pShape = CreateSvxShapeByTypeAndInventor( nType, SdrInventor );
1117 
1118 		// set shape type
1119 		if( pShape && !mbClipBoard )
1120 			pShape->SetShapeType(aServiceSpecifier);
1121 
1122 		xRet = (uno::XWeak*)pShape;
1123 	}
1124 	else if( aServiceSpecifier.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.TableShape") ) )
1125 	{
1126 		SvxShape* pShape = CreateSvxShapeByTypeAndInventor( OBJ_TABLE, SdrInventor );
1127 		if( pShape && !mbClipBoard )
1128 			pShape->SetShapeType(aServiceSpecifier);
1129 
1130 		xRet = (uno::XWeak*)pShape;
1131 	}
1132 	else
1133 	{
1134 		xRet = SvxFmMSFactory::createInstance( aServiceSpecifier );
1135 	}
1136 
1137 	uno::Reference< drawing::XShape > xShape( xRet, uno::UNO_QUERY );
1138 	if( xShape.is() )
1139 	{
1140 		xRet.clear();
1141 		new SdXShape( SvxShape::getImplementation( xShape ), (SdXImpressDocument*)this );
1142 		xRet = xShape;
1143 		xShape.clear();
1144 	}
1145 
1146 	return xRet;
1147 }
1148 
1149 uno::Sequence< OUString > SAL_CALL SdXImpressDocument::getAvailableServiceNames()
1150 	throw(uno::RuntimeException)
1151 {
1152 	OGuard aGuard( Application::GetSolarMutex() );
1153 
1154 	if( NULL == mpDoc )
1155 		throw lang::DisposedException();
1156 
1157 	const uno::Sequence< OUString > aSNS_ORG( SvxFmMSFactory::getAvailableServiceNames() );
1158 
1159 	uno::Sequence< OUString > aSNS( mbImpressDoc ? (36) : (19) );
1160 
1161 	sal_uInt16 i(0);
1162 
1163 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.DashTable"));
1164 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.GradientTable"));
1165 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.HatchTable"));
1166 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.BitmapTable"));
1167 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.TransparencyGradientTable"));
1168 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.MarkerTable"));
1169 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.NumberingRules"));
1170 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.Background"));
1171 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.Settings"));
1172 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM(sUNO_Service_ImageMapRectangleObject));
1173 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM(sUNO_Service_ImageMapCircleObject));
1174 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM(sUNO_Service_ImageMapPolygonObject));
1175 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.NamespaceMap"));
1176 
1177 	// #99870# Support creation of GraphicObjectResolver and EmbeddedObjectResolver
1178 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.ExportGraphicObjectResolver"));
1179 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.ImportGraphicObjectResolver"));
1180 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.ExportEmbeddedObjectResolver"));
1181 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.ImportEmbeddedObjectResolver"));
1182 	aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.TableShape"));
1183 
1184 	if(mbImpressDoc)
1185 	{
1186 		aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.TitleTextShape"));
1187 		aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.OutlinerShape"));
1188 		aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.SubtitleShape"));
1189 		aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.GraphicObjectShape"));
1190 		aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.ChartShape"));
1191 		aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.PageShape"));
1192 		aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.OLE2Shape"));
1193 		aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.TableShape"));
1194 		aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.OrgChartShape"));
1195 		aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.NotesShape"));
1196 		aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.HandoutShape"));
1197 		aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.DocumentSettings"));
1198 		aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.FooterShape"));
1199 		aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.HeaderShape"));
1200 		aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.SlideNumberShape"));
1201 		aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.DateTimeShape"));
1202 		aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.CalcShape"));
1203 		aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.MediaShape"));
1204 	}
1205 	else
1206 	{
1207 		aSNS[i++] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.DocumentSettings"));
1208 	}
1209 
1210 	DBG_ASSERT( i == aSNS.getLength(), "Sequence overrun!" );
1211 
1212 	return comphelper::concatSequences( aSNS_ORG, aSNS );
1213 }
1214 
1215 // lang::XServiceInfo
1216 OUString SAL_CALL SdXImpressDocument::getImplementationName()
1217 	throw(uno::RuntimeException)
1218 {
1219 	return OUString( RTL_CONSTASCII_USTRINGPARAM("SdXImpressDocument"));
1220 }
1221 
1222 sal_Bool SAL_CALL SdXImpressDocument::supportsService( const OUString& ServiceName )
1223 	throw(uno::RuntimeException)
1224 {
1225 	OGuard aGuard( Application::GetSolarMutex() );
1226 
1227     if (
1228         (ServiceName.equalsAscii("com.sun.star.document.OfficeDocument"       )) ||
1229         (ServiceName.equalsAscii("com.sun.star.drawing.GenericDrawingDocument")) ||
1230         (ServiceName.equalsAscii("com.sun.star.drawing.DrawingDocumentFactory"))
1231        )
1232     {
1233         return sal_True;
1234     }
1235 
1236     return (
1237             ( mbImpressDoc && ServiceName.equalsAscii("com.sun.star.presentation.PresentationDocument")) ||
1238             (!mbImpressDoc && ServiceName.equalsAscii("com.sun.star.drawing.DrawingDocument"          ))
1239            );
1240 }
1241 
1242 uno::Sequence< OUString > SAL_CALL SdXImpressDocument::getSupportedServiceNames() throw(uno::RuntimeException)
1243 {
1244 	OGuard aGuard( Application::GetSolarMutex() );
1245 
1246 	uno::Sequence< OUString > aSeq( 4 );
1247 	OUString* pServices = aSeq.getArray();
1248 
1249 	*pServices++ = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.OfficeDocument"));
1250 	*pServices++ = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.GenericDrawingDocument"));
1251 	*pServices++ = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.DrawingDocumentFactory"));
1252 
1253 	if( mbImpressDoc )
1254 		*pServices++ = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.PresentationDocument"));
1255     else
1256 		*pServices++ = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.DrawingDocument"));
1257 
1258 	return aSeq;
1259 }
1260 
1261 // XPropertySet
1262 uno::Reference< beans::XPropertySetInfo > SAL_CALL SdXImpressDocument::getPropertySetInfo(  )
1263 	throw(uno::RuntimeException)
1264 {
1265 	OGuard aGuard( Application::GetSolarMutex() );
1266 	return mpPropSet->getPropertySetInfo();
1267 }
1268 
1269 void SAL_CALL SdXImpressDocument::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
1270 	throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
1271 {
1272 	OGuard aGuard( Application::GetSolarMutex() );
1273 
1274 	if( NULL == mpDoc )
1275 		throw lang::DisposedException();
1276 
1277 	const SfxItemPropertySimpleEntry* pEntry = mpPropSet->getPropertyMapEntry(aPropertyName);
1278 
1279 	switch( pEntry ? pEntry->nWID : -1 )
1280 	{
1281 		case WID_MODEL_LANGUAGE:
1282 		{
1283 			lang::Locale aLocale;
1284 			if(!(aValue >>= aLocale))
1285 				throw lang::IllegalArgumentException();
1286 
1287 			mpDoc->SetLanguage( SvxLocaleToLanguage(aLocale), EE_CHAR_LANGUAGE );
1288 			break;
1289 		}
1290 		case WID_MODEL_TABSTOP:
1291 		{
1292 			sal_Int32 nValue = 0;
1293 			if(!(aValue >>= nValue) || nValue < 0 )
1294 				throw lang::IllegalArgumentException();
1295 
1296 			mpDoc->SetDefaultTabulator((sal_uInt16)nValue);
1297 			break;
1298 		}
1299 		case WID_MODEL_VISAREA:
1300 			{
1301                 SfxObjectShell* pEmbeddedObj = mpDoc->GetDocSh();
1302 				if( !pEmbeddedObj )
1303 					break;
1304 
1305 				awt::Rectangle aVisArea;
1306 				if( !(aValue >>= aVisArea) || (aVisArea.Width < 0) || (aVisArea.Height < 0) )
1307 					throw lang::IllegalArgumentException();
1308 
1309 				pEmbeddedObj->SetVisArea( Rectangle( aVisArea.X, aVisArea.Y, aVisArea.X + aVisArea.Width - 1, aVisArea.Y + aVisArea.Height - 1 ) );
1310 			}
1311 			break;
1312 		case WID_MODEL_CONTFOCUS:
1313 			{
1314 				sal_Bool bFocus = sal_False;
1315 				if( !(aValue >>= bFocus ) )
1316 					throw lang::IllegalArgumentException();
1317 				mpDoc->SetAutoControlFocus( bFocus );
1318 			}
1319 			break;
1320 		case WID_MODEL_DSGNMODE:
1321 			{
1322 				sal_Bool bMode = sal_False;
1323 				if( !(aValue >>= bMode ) )
1324 					throw lang::IllegalArgumentException();
1325 				mpDoc->SetOpenInDesignMode( bMode );
1326 			}
1327 			break;
1328 		case WID_MODEL_BUILDID:
1329 			aValue >>= maBuildId;
1330 			return;
1331 		case WID_MODEL_MAPUNIT:
1332 		case WID_MODEL_BASICLIBS:
1333         case WID_MODEL_RUNTIMEUID: // is read-only
1334         case WID_MODEL_DIALOGLIBS:
1335 			throw beans::PropertyVetoException();
1336 		default:
1337 			throw beans::UnknownPropertyException();
1338 	}
1339 
1340 	SetModified();
1341 }
1342 
1343 uno::Any SAL_CALL SdXImpressDocument::getPropertyValue( const OUString& PropertyName )
1344 	throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
1345 {
1346 	OGuard aGuard( Application::GetSolarMutex() );
1347 
1348 	uno::Any aAny;
1349 	if( NULL == mpDoc )
1350 		throw lang::DisposedException();
1351 
1352 	const SfxItemPropertySimpleEntry* pEntry = mpPropSet->getPropertyMapEntry(PropertyName);
1353 
1354 	switch( pEntry ? pEntry->nWID : -1 )
1355 	{
1356 		case WID_MODEL_LANGUAGE:
1357 		{
1358 			LanguageType eLang = mpDoc->GetLanguage( EE_CHAR_LANGUAGE );
1359 			lang::Locale aLocale;
1360 			SvxLanguageToLocale( aLocale, eLang );
1361 			aAny <<= aLocale;
1362 			break;
1363 		}
1364 		case WID_MODEL_TABSTOP:
1365 			aAny <<= (sal_Int32)mpDoc->GetDefaultTabulator();
1366 			break;
1367 		case WID_MODEL_VISAREA:
1368 			{
1369                 SfxObjectShell* pEmbeddedObj = mpDoc->GetDocSh();
1370 				if( !pEmbeddedObj )
1371 					break;
1372 
1373 				const Rectangle& aRect = pEmbeddedObj->GetVisArea();
1374 				awt::Rectangle aVisArea( aRect.nLeft, aRect.nTop, aRect.getWidth(), aRect.getHeight() );
1375 				aAny <<= aVisArea;
1376 			}
1377 			break;
1378 		case WID_MODEL_MAPUNIT:
1379 			{
1380                 SfxObjectShell* pEmbeddedObj = mpDoc->GetDocSh();
1381 				if( !pEmbeddedObj )
1382 					break;
1383 
1384 				sal_Int16 nMeasureUnit = 0;
1385 				SvxMapUnitToMeasureUnit( (const short)pEmbeddedObj->GetMapUnit(), nMeasureUnit );
1386 				aAny <<= (sal_Int16)nMeasureUnit;
1387 		}
1388 		break;
1389 		case WID_MODEL_FORBCHARS:
1390 		{
1391 			aAny <<= getForbiddenCharsTable();
1392 		}
1393 		break;
1394 		case WID_MODEL_CONTFOCUS:
1395 			aAny <<= (sal_Bool)mpDoc->GetAutoControlFocus();
1396 			break;
1397 		case WID_MODEL_DSGNMODE:
1398 			aAny <<= mpDoc->GetOpenInDesignMode();
1399 			break;
1400 		case WID_MODEL_BASICLIBS:
1401 			aAny <<= mpDocShell->GetBasicContainer();
1402 			break;
1403         case WID_MODEL_DIALOGLIBS:
1404             aAny <<= mpDocShell->GetDialogContainer();
1405             break;
1406         case WID_MODEL_RUNTIMEUID:
1407             aAny <<= getRuntimeUID();
1408             break;
1409 		case WID_MODEL_BUILDID:
1410 			return uno::Any( maBuildId );
1411         case WID_MODEL_HASVALIDSIGNATURES:
1412             aAny <<= hasValidSignatures();
1413             break;
1414         default:
1415 			throw beans::UnknownPropertyException();
1416 	}
1417 
1418 	return aAny;
1419 }
1420 
1421 void SAL_CALL SdXImpressDocument::addPropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >&  ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
1422 void SAL_CALL SdXImpressDocument::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >&  ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
1423 void SAL_CALL SdXImpressDocument::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >&  ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
1424 void SAL_CALL SdXImpressDocument::removeVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >&  ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
1425 
1426 // XLinkTargetSupplier
1427 uno::Reference< container::XNameAccess > SAL_CALL SdXImpressDocument::getLinks()
1428 	throw(uno::RuntimeException)
1429 {
1430 	OGuard aGuard( Application::GetSolarMutex() );
1431 
1432 	if( NULL == mpDoc )
1433 		throw lang::DisposedException();
1434 
1435 	uno::Reference< container::XNameAccess > xLinks( mxLinks );
1436 	if( !xLinks.is() )
1437 		mxLinks = xLinks = new SdDocLinkTargets( *this );
1438 	return xLinks;
1439 }
1440 
1441 // XStyleFamiliesSupplier
1442 uno::Reference< container::XNameAccess > SAL_CALL SdXImpressDocument::getStyleFamilies(  )
1443 	throw(uno::RuntimeException)
1444 {
1445 	OGuard aGuard( Application::GetSolarMutex() );
1446 
1447 	if( NULL == mpDoc )
1448 		throw lang::DisposedException();
1449 
1450 	uno::Reference< container::XNameAccess > xStyles( dynamic_cast< container::XNameAccess* >( mpDoc->GetStyleSheetPool()) );
1451 	return xStyles;
1452 }
1453 
1454 // XAnyCompareFactory
1455 uno::Reference< com::sun::star::ucb::XAnyCompare > SAL_CALL SdXImpressDocument::createAnyCompareByName( const OUString& )
1456     throw (uno::RuntimeException)
1457 {
1458 	return SvxCreateNumRuleCompare();
1459 }
1460 
1461 // XRenderable
1462 sal_Int32 SAL_CALL SdXImpressDocument::getRendererCount( const uno::Any& rSelection,
1463                                                          const uno::Sequence< beans::PropertyValue >&  )
1464     throw (lang::IllegalArgumentException, uno::RuntimeException)
1465 {
1466 	OGuard      aGuard( Application::GetSolarMutex() );
1467 	sal_Int32   nRet = 0;
1468 
1469 	if( NULL == mpDoc )
1470 		throw lang::DisposedException();
1471 
1472     uno::Sequence< beans::PropertyValue > aRenderer;
1473 
1474     if( mpDocShell && mpDoc )
1475     {
1476         uno::Reference< frame::XModel > xModel;
1477 
1478         rSelection >>= xModel;
1479 
1480         if( xModel == mpDocShell->GetModel() )
1481             nRet = mpDoc->GetSdPageCount( PK_STANDARD );
1482         else
1483         {
1484             uno::Reference< drawing::XShapes > xShapes;
1485 
1486             rSelection >>= xShapes;
1487 
1488             if( xShapes.is() && xShapes->getCount() )
1489                 nRet = 1;
1490         }
1491     }
1492     return nRet;
1493 }
1494 
1495 uno::Sequence< beans::PropertyValue > SAL_CALL SdXImpressDocument::getRenderer( sal_Int32 , const uno::Any& ,
1496                                                                                 const uno::Sequence< beans::PropertyValue >& rxOptions )
1497     throw (lang::IllegalArgumentException, uno::RuntimeException)
1498 {
1499 	OGuard aGuard( Application::GetSolarMutex() );
1500 
1501 	if( NULL == mpDoc )
1502 		throw lang::DisposedException();
1503 
1504 	sal_Bool bExportNotesPages = sal_False;
1505 	for( sal_Int32 nProperty = 0, nPropertyCount = rxOptions.getLength(); nProperty < nPropertyCount; ++nProperty )
1506     {
1507         if( rxOptions[ nProperty ].Name.equalsAscii( "ExportNotesPages" ) )
1508 			rxOptions[ nProperty].Value >>= bExportNotesPages;
1509     }
1510     uno::Sequence< beans::PropertyValue > aRenderer;
1511     if( mpDocShell && mpDoc )
1512     {
1513 		awt::Size aPageSize;
1514 		if ( bExportNotesPages )
1515 		{
1516 			Size aNotesPageSize = mpDoc->GetSdPage( 0, PK_NOTES )->GetSize();
1517 			aPageSize = awt::Size( aNotesPageSize.Width(), aNotesPageSize.Height() );
1518 		}
1519 		else
1520 		{
1521 			const Rectangle aVisArea( mpDocShell->GetVisArea( embed::Aspects::MSOLE_DOCPRINT ) );
1522 			aPageSize = awt::Size( aVisArea.GetWidth(), aVisArea.GetHeight() );
1523 		}
1524         aRenderer.realloc( 1 );
1525 
1526         aRenderer[ 0 ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "PageSize" ) );
1527         aRenderer[ 0 ].Value <<= aPageSize;
1528     }
1529     return aRenderer;
1530 }
1531 
1532 class ImplRenderPaintProc : public ::sdr::contact::ViewObjectContactRedirector
1533 {
1534 	const SdrLayerAdmin&	rLayerAdmin;
1535 	SdrPageView*			pSdrPageView;
1536 	vcl::PDFExtOutDevData*	pPDFExtOutDevData;
1537 
1538 	vcl::PDFWriter::StructElement ImplBegStructureTag( SdrObject& rObject );
1539 
1540 public:
1541 	sal_Bool IsVisible  ( const SdrObject* pObj ) const;
1542 	sal_Bool IsPrintable( const SdrObject* pObj ) const;
1543 
1544 	ImplRenderPaintProc( const SdrLayerAdmin& rLA, SdrPageView* pView, vcl::PDFExtOutDevData* pData );
1545 	virtual ~ImplRenderPaintProc();
1546 
1547 	// all default implementations just call the same methods at the original. To do something
1548 	// different, overload the method and at least do what the method does.
1549 	virtual drawinglayer::primitive2d::Primitive2DSequence createRedirectedPrimitive2DSequence(
1550 		const sdr::contact::ViewObjectContact& rOriginal,
1551 		const sdr::contact::DisplayInfo& rDisplayInfo);
1552 };
1553 
1554 ImplRenderPaintProc::ImplRenderPaintProc( const SdrLayerAdmin& rLA, SdrPageView* pView, vcl::PDFExtOutDevData* pData )
1555 :	ViewObjectContactRedirector(),
1556 	rLayerAdmin			( rLA ),
1557 	pSdrPageView		( pView ),
1558 	pPDFExtOutDevData	( pData )
1559 {
1560 }
1561 
1562 ImplRenderPaintProc::~ImplRenderPaintProc()
1563 {
1564 }
1565 
1566 sal_Int32 ImplPDFGetBookmarkPage( const String& rBookmark, SdDrawDocument& rDoc )
1567 {
1568 	sal_Int32 nPage = -1;
1569 
1570     OSL_TRACE("GotoBookmark %s",
1571         ::rtl::OUStringToOString(rBookmark, RTL_TEXTENCODING_UTF8).getStr());
1572 
1573 	String aBookmark( rBookmark );
1574 
1575 	if( rBookmark.Len() && rBookmark.GetChar( 0 ) == sal_Unicode('#') )
1576 		aBookmark = rBookmark.Copy( 1 );
1577 
1578 	// is the bookmark a page ?
1579 	sal_Bool        bIsMasterPage;
1580     sal_uInt16      nPgNum = rDoc.GetPageByName( aBookmark, bIsMasterPage );
1581 	SdrObject*  pObj = NULL;
1582 
1583 	if ( nPgNum == SDRPAGE_NOTFOUND )
1584 	{
1585 		// is the bookmark a object ?
1586 		pObj = rDoc.GetObj( aBookmark );
1587 		if (pObj)
1588 			nPgNum = pObj->GetPage()->GetPageNum();
1589 	}
1590 	if ( nPgNum != SDRPAGE_NOTFOUND )
1591 		nPage = ( nPgNum - 1 ) / 2;
1592 	return nPage;
1593 }
1594 
1595 void ImplPDFExportComments( uno::Reference< drawing::XDrawPage > xPage, vcl::PDFExtOutDevData& rPDFExtOutDevData )
1596 {
1597 	try
1598 	{
1599 		uno::Reference< office::XAnnotationAccess > xAnnotationAccess( xPage, uno::UNO_QUERY_THROW );
1600 		uno::Reference< office::XAnnotationEnumeration > xAnnotationEnumeration( xAnnotationAccess->createAnnotationEnumeration() );
1601 
1602 		LanguageType eLanguage = Application::GetSettings().GetLanguage();
1603 		while( xAnnotationEnumeration->hasMoreElements() )
1604 		{
1605 			uno::Reference< office::XAnnotation > xAnnotation( xAnnotationEnumeration->nextElement() );
1606 
1607 			geometry::RealPoint2D aRealPoint2D( xAnnotation->getPosition() );
1608 			uno::Reference< text::XText > xText( xAnnotation->getTextRange() );
1609 //			rtl::OUString sInitials( getInitials( sAuthor ) );
1610 			util::DateTime aDateTime( xAnnotation->getDateTime() );
1611 
1612 			Date aDate( aDateTime.Day, aDateTime.Month, aDateTime.Year );
1613 			Time aTime;
1614 			String aStr( SvxDateTimeField::GetFormatted( aDate, aTime, SVXDATEFORMAT_B, *(SD_MOD()->GetNumberFormatter()), eLanguage ) );
1615 
1616 			vcl::PDFNote aNote;
1617 			String sTitle( xAnnotation->getAuthor() );
1618             sTitle.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ", " ) );
1619             sTitle += aStr;
1620             aNote.Title = sTitle;
1621 			aNote.Contents = xText->getString();
1622 			rPDFExtOutDevData.CreateNote( Rectangle( Point( static_cast< long >( aRealPoint2D.X * 100 ),
1623 				static_cast< long >( aRealPoint2D.Y * 100 ) ), Size( 1000, 1000 ) ), aNote );
1624 		}
1625 	}
1626 	catch( uno::Exception& )
1627 	{
1628 	}
1629 }
1630 
1631 void ImplPDFExportShapeInteraction( uno::Reference< drawing::XShape > xShape, SdDrawDocument& rDoc, vcl::PDFExtOutDevData& rPDFExtOutDevData )
1632 {
1633 	const rtl::OUString sGroup   ( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.GroupShape" ) );
1634 	const rtl::OUString sOnClick ( RTL_CONSTASCII_USTRINGPARAM( "OnClick" ) );
1635 	const rtl::OUString sBookmark( RTL_CONSTASCII_USTRINGPARAM( "Bookmark" ) );
1636 
1637 	if ( xShape->getShapeType().equals( sGroup ) )
1638 	{
1639 		uno::Reference< container::XIndexAccess > xIndexAccess( xShape, uno::UNO_QUERY );
1640 		if ( xIndexAccess.is() )
1641 		{
1642 			sal_Int32 i, nCount = xIndexAccess->getCount();
1643 			for ( i = 0; i < nCount; i++ )
1644 			{
1645 				uno::Reference< drawing::XShape > xSubShape( xIndexAccess->getByIndex( i ), uno::UNO_QUERY );
1646 				if ( xSubShape.is() )
1647 					ImplPDFExportShapeInteraction( xSubShape, rDoc, rPDFExtOutDevData );
1648 			}
1649 		}
1650 	}
1651 	else
1652 	{
1653 		uno::Reference< beans::XPropertySet > xShapePropSet( xShape, uno::UNO_QUERY );
1654 		if( xShapePropSet.is() )
1655 		{
1656 			Size		aPageSize( rDoc.GetSdPage( 0, PK_STANDARD )->GetSize() );
1657 			Point aPoint( 0, 0 );
1658 			Rectangle	aPageRect( aPoint, aPageSize );
1659 
1660 			awt::Point	aShapePos( xShape->getPosition() );
1661 			awt::Size	aShapeSize( xShape->getSize() );
1662 			Rectangle	aLinkRect( Point( aShapePos.X, aShapePos.Y ), Size( aShapeSize.Width, aShapeSize.Height ) );
1663 
1664 			presentation::ClickAction eCa;
1665 			uno::Any aAny( xShapePropSet->getPropertyValue( sOnClick ) );
1666 			if ( aAny >>= eCa )
1667 			{
1668 				switch ( eCa )
1669 				{
1670 					case presentation::ClickAction_LASTPAGE :
1671 					{
1672 						sal_Int32 nCount = rDoc.GetSdPageCount( PK_STANDARD );
1673 						sal_Int32 nDestId = rPDFExtOutDevData.CreateDest( aPageRect, nCount - 1, vcl::PDFWriter::FitRectangle );
1674 					    sal_Int32 nLinkId = rPDFExtOutDevData.CreateLink( aLinkRect, -1 );
1675 						rPDFExtOutDevData.SetLinkDest( nLinkId, nDestId );
1676 					}
1677 					break;
1678 					case presentation::ClickAction_FIRSTPAGE :
1679 					{
1680 						sal_Int32 nDestId = rPDFExtOutDevData.CreateDest( aPageRect, 0, vcl::PDFWriter::FitRectangle );
1681 					    sal_Int32 nLinkId = rPDFExtOutDevData.CreateLink( aLinkRect, -1 );
1682 						rPDFExtOutDevData.SetLinkDest( nLinkId, nDestId );
1683 					}
1684 					break;
1685 					case presentation::ClickAction_PREVPAGE :
1686 					{
1687 						sal_Int32 nDestPage = rPDFExtOutDevData.GetCurrentPageNumber();
1688 						if ( nDestPage )
1689 							nDestPage--;
1690 						sal_Int32 nDestId = rPDFExtOutDevData.CreateDest( aPageRect, nDestPage, vcl::PDFWriter::FitRectangle );
1691 					    sal_Int32 nLinkId = rPDFExtOutDevData.CreateLink( aLinkRect, -1 );
1692 						rPDFExtOutDevData.SetLinkDest( nLinkId, nDestId );
1693 					}
1694 					break;
1695 					case presentation::ClickAction_NEXTPAGE :
1696 					{
1697 						sal_Int32 nDestPage = rPDFExtOutDevData.GetCurrentPageNumber() + 1;
1698 						sal_Int32 nLastPage = rDoc.GetSdPageCount( PK_STANDARD ) - 1;
1699 						if ( nDestPage > nLastPage )
1700 							nDestPage = nLastPage;
1701 						sal_Int32 nDestId = rPDFExtOutDevData.CreateDest( aPageRect, nDestPage, vcl::PDFWriter::FitRectangle );
1702 					    sal_Int32 nLinkId = rPDFExtOutDevData.CreateLink( aLinkRect, -1 );
1703 						rPDFExtOutDevData.SetLinkDest( nLinkId, nDestId );
1704 					}
1705 					break;
1706 
1707 					case presentation::ClickAction_PROGRAM :
1708 					case presentation::ClickAction_BOOKMARK :
1709 					case presentation::ClickAction_DOCUMENT :
1710 					{
1711 						rtl::OUString aBookmark;
1712 						xShapePropSet->getPropertyValue( sBookmark ) >>= aBookmark;
1713 						if( aBookmark.getLength() )
1714 						{
1715 							switch( eCa )
1716 							{
1717 								case presentation::ClickAction_DOCUMENT :
1718 								case presentation::ClickAction_PROGRAM :
1719 								{
1720 									sal_Int32 nLinkId = rPDFExtOutDevData.CreateLink( aLinkRect, -1 );
1721 									rPDFExtOutDevData.SetLinkURL( nLinkId, aBookmark );
1722 								}
1723 								break;
1724 								case presentation::ClickAction_BOOKMARK :
1725 								{
1726 									sal_Int32 nPage = ImplPDFGetBookmarkPage( aBookmark, rDoc );
1727 									if ( nPage != -1 )
1728 									{
1729 										sal_Int32 nDestId = rPDFExtOutDevData.CreateDest( aPageRect, nPage, vcl::PDFWriter::FitRectangle );
1730 										sal_Int32 nLinkId = rPDFExtOutDevData.CreateLink( aLinkRect, -1 );
1731 										rPDFExtOutDevData.SetLinkDest( nLinkId, nDestId );
1732 									}
1733 								}
1734 								break;
1735 								default:
1736 									break;
1737 							}
1738 						}
1739 					}
1740 					break;
1741 
1742 					case presentation::ClickAction_STOPPRESENTATION :
1743 					case presentation::ClickAction_SOUND :
1744 					case presentation::ClickAction_INVISIBLE :
1745 					case presentation::ClickAction_VERB :
1746 					case presentation::ClickAction_VANISH :
1747 					case presentation::ClickAction_MACRO :
1748 					default :
1749 					break;
1750 				}
1751 			}
1752 		}
1753 	}
1754 }
1755 
1756 vcl::PDFWriter::StructElement ImplRenderPaintProc::ImplBegStructureTag( SdrObject& rObject )
1757 {
1758 	vcl::PDFWriter::StructElement eElement(vcl::PDFWriter::NonStructElement);
1759 
1760 	if ( pPDFExtOutDevData && pPDFExtOutDevData->GetIsExportTaggedPDF() )
1761 	{
1762 		sal_uInt32 nInventor   = rObject.GetObjInventor();
1763 		sal_uInt16 nIdentifier = rObject.GetObjIdentifier();
1764 		sal_Bool   bIsTextObj  = rObject.ISA( SdrTextObj );
1765 
1766 		if ( nInventor == SdrInventor )
1767 		{
1768 			if ( nIdentifier == OBJ_GRUP )
1769 				eElement = vcl::PDFWriter::Section;
1770 			else if ( nIdentifier == OBJ_TITLETEXT )
1771 				eElement = vcl::PDFWriter::Heading;
1772 			else if ( nIdentifier == OBJ_OUTLINETEXT )
1773 				eElement = vcl::PDFWriter::Division;
1774 			else if ( !bIsTextObj || !((SdrTextObj&)rObject).HasText() )
1775 				eElement = vcl::PDFWriter::Figure;
1776 		}
1777 	}
1778 
1779 	return eElement;
1780 }
1781 
1782 drawinglayer::primitive2d::Primitive2DSequence ImplRenderPaintProc::createRedirectedPrimitive2DSequence(
1783 	const sdr::contact::ViewObjectContact& rOriginal,
1784 	const sdr::contact::DisplayInfo& rDisplayInfo)
1785 {
1786 	SdrObject* pObject = rOriginal.GetViewContact().TryToGetSdrObject();
1787 
1788     if(pObject)
1789 	{
1790 		drawinglayer::primitive2d::Primitive2DSequence xRetval;
1791 
1792 		if(pObject->GetPage())
1793 		{
1794 			if(pObject->GetPage()->checkVisibility(rOriginal, rDisplayInfo, false))
1795 			{
1796 				if(IsVisible(pObject) && IsPrintable(pObject))
1797 				{
1798 					const vcl::PDFWriter::StructElement eElement(ImplBegStructureTag( *pObject ));
1799 					const bool bTagUsed(vcl::PDFWriter::NonStructElement != eElement);
1800 
1801 					xRetval = ::sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(rOriginal, rDisplayInfo);
1802 
1803 					if(xRetval.hasElements() && bTagUsed)
1804 					{
1805 						// embed Primitive2DSequence in a structure tag element for
1806 						// exactly this purpose (StructureTagPrimitive2D)
1807 						const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::StructureTagPrimitive2D(eElement, xRetval));
1808 						xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
1809 					}
1810 				}
1811 			}
1812 		}
1813 
1814 		return xRetval;
1815 	}
1816 	else
1817 	{
1818 		// not an object, maybe a page
1819 		return sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(rOriginal, rDisplayInfo);
1820 	}
1821 }
1822 
1823 sal_Bool ImplRenderPaintProc::IsVisible( const SdrObject* pObj ) const
1824 {
1825 	sal_Bool bVisible = sal_True;
1826 	SdrLayerID nLayerId = pObj->GetLayer();
1827 	if( pSdrPageView )
1828 	{
1829 		const SdrLayer* pSdrLayer = rLayerAdmin.GetLayer( nLayerId );
1830 		if ( pSdrLayer )
1831 		{
1832 			String aLayerName = pSdrLayer->GetName();
1833 			bVisible = pSdrPageView->IsLayerVisible( aLayerName );
1834 		}
1835 	}
1836 	return bVisible;
1837 }
1838 sal_Bool ImplRenderPaintProc::IsPrintable( const SdrObject* pObj ) const
1839 {
1840 	sal_Bool bPrintable = sal_True;
1841 	SdrLayerID nLayerId = pObj->GetLayer();
1842 	if( pSdrPageView )
1843 	{
1844 		const SdrLayer* pSdrLayer = rLayerAdmin.GetLayer( nLayerId );
1845 		if ( pSdrLayer )
1846 		{
1847 			String aLayerName = pSdrLayer->GetName();
1848 			bPrintable = pSdrPageView->IsLayerPrintable( aLayerName );
1849 		}
1850 	}
1851 	return bPrintable;
1852 
1853 }
1854 void SAL_CALL SdXImpressDocument::render( sal_Int32 nRenderer, const uno::Any& rSelection,
1855                                           const uno::Sequence< beans::PropertyValue >& rxOptions )
1856     throw (lang::IllegalArgumentException, uno::RuntimeException)
1857 {
1858 	OGuard aGuard( Application::GetSolarMutex() );
1859 
1860 	if( NULL == mpDoc )
1861 		throw lang::DisposedException();
1862 
1863     if( mpDocShell && mpDoc )
1864     {
1865         uno::Reference< awt::XDevice >  xRenderDevice;
1866         const sal_Int32					nPageNumber = nRenderer + 1;
1867 		PageKind						ePageKind = PK_STANDARD;
1868 		sal_Bool						bExportNotesPages = sal_False;
1869 
1870 		for( sal_Int32 nProperty = 0, nPropertyCount = rxOptions.getLength(); nProperty < nPropertyCount; ++nProperty )
1871         {
1872 			if( rxOptions[ nProperty ].Name == OUString( RTL_CONSTASCII_USTRINGPARAM( "RenderDevice" ) ) )
1873 				rxOptions[ nProperty ].Value >>= xRenderDevice;
1874 			else if ( rxOptions[ nProperty ].Name == OUString( RTL_CONSTASCII_USTRINGPARAM( "ExportNotesPages" ) ) )
1875 			{
1876 				rxOptions[ nProperty].Value >>= bExportNotesPages;
1877 				if ( bExportNotesPages )
1878 					ePageKind = PK_NOTES;
1879 			}
1880         }
1881 
1882         if( xRenderDevice.is() && nPageNumber && ( nPageNumber <= mpDoc->GetSdPageCount( ePageKind ) ) )
1883         {
1884             VCLXDevice*     pDevice = VCLXDevice::GetImplementation( xRenderDevice );
1885             OutputDevice*   pOut = pDevice ? pDevice->GetOutputDevice() : NULL;
1886 
1887             if( pOut )
1888             {
1889 				vcl::PDFExtOutDevData* pPDFExtOutDevData = PTR_CAST( vcl::PDFExtOutDevData, pOut->GetExtOutDevData() );
1890 
1891 	            ::sd::ClientView* pView = new ::sd::ClientView( mpDocShell, pOut, NULL );
1892 				Rectangle				aVisArea = Rectangle( Point(), mpDoc->GetSdPage( (sal_uInt16)nPageNumber - 1, ePageKind )->GetSize() );
1893         		Region					aRegion( aVisArea );
1894                 Point					aOrigin;
1895 
1896 				::sd::ViewShell* pOldViewSh = mpDocShell->GetViewShell();
1897 				::sd::View* pOldSdView = pOldViewSh ? pOldViewSh->GetView() : NULL;
1898 
1899 				if  ( pOldSdView )
1900 					pOldSdView->SdrEndTextEdit();
1901 
1902                 pView->SetHlplVisible( sal_False );
1903                 pView->SetGridVisible( sal_False );
1904 	            pView->SetBordVisible( sal_False );
1905 	            pView->SetPageVisible( sal_False );
1906 	            pView->SetGlueVisible( sal_False );
1907 
1908                 pOut->SetMapMode( MAP_100TH_MM );
1909 	            pOut->IntersectClipRegion( aVisArea );
1910 
1911 
1912 
1913                 uno::Reference< frame::XModel > xModel;
1914                 rSelection >>= xModel;
1915 
1916                 if( xModel == mpDocShell->GetModel() )
1917                 {
1918                     pView->ShowSdrPage( mpDoc->GetSdPage( (sal_uInt16)nPageNumber - 1, ePageKind ));
1919 					SdrPageView* pPV = pView->GetSdrPageView();
1920 
1921 				    if( pOldSdView )
1922                     {
1923                         SdrPageView* pOldPV = pOldSdView->GetSdrPageView();
1924                         if( pPV && pOldPV )
1925                         {
1926                             pPV->SetVisibleLayers( pOldPV->GetVisibleLayers() );
1927                             pPV->SetPrintableLayers( pOldPV->GetPrintableLayers() );
1928                         }
1929                     }
1930 
1931 					ImplRenderPaintProc	aImplRenderPaintProc( mpDoc->GetLayerAdmin(),
1932 						pPV, pPDFExtOutDevData );
1933 
1934 					// background color for outliner :o
1935 					SdPage* pPage = (SdPage*)pPV->GetPage();
1936 					if( pPage )
1937 					{
1938 						SdrOutliner& rOutl = mpDoc->GetDrawOutliner( NULL );
1939                         bool bScreenDisplay(true);
1940 
1941                         if(bScreenDisplay && pOut && OUTDEV_PRINTER == pOut->GetOutDevType())
1942                         {
1943                             // #i75566# printing; suppress AutoColor BackgroundColor generation
1944                             // for visibility reasons by giving GetPageBackgroundColor()
1945                             // the needed hint
1946                             bScreenDisplay = false;
1947                         }
1948 
1949                         if(bScreenDisplay && pOut && pOut->GetPDFWriter())
1950                         {
1951                             // #i75566# PDF export; suppress AutoColor BackgroundColor generation (see above)
1952                             bScreenDisplay = false;
1953                         }
1954 
1955                         // #i75566# Name change GetBackgroundColor -> GetPageBackgroundColor and
1956                         // hint value if screen display. Only then the AutoColor mechanisms shall be applied
1957 						rOutl.SetBackgroundColor( pPage->GetPageBackgroundColor( pPV, bScreenDisplay ) );
1958 					}
1959 					pView->SdrPaintView::CompleteRedraw( pOut, aRegion, &aImplRenderPaintProc );
1960 
1961 					if ( pPDFExtOutDevData )
1962 					{
1963 						try
1964 						{
1965 							uno::Any aAny;
1966 							uno::Reference< drawing::XDrawPage > xPage( uno::Reference< drawing::XDrawPage >::query( pPage->getUnoPage() ) );
1967 							if ( xPage.is() )
1968 							{
1969 								if ( pPDFExtOutDevData->GetIsExportNotes() )
1970 									ImplPDFExportComments( xPage, *pPDFExtOutDevData );
1971 								uno::Reference< beans::XPropertySet > xPagePropSet( xPage, uno::UNO_QUERY );
1972 								if( xPagePropSet.is() )
1973 								{
1974 									// exporting object interactions to pdf
1975 
1976 									// if necessary, the master page interactions will be exported first
1977 									sal_Bool bIsBackgroundObjectsVisible = sal_False;	// SJ: #i39428# IsBackgroundObjectsVisible not available for Draw
1978 									const rtl::OUString sIsBackgroundObjectsVisible( RTL_CONSTASCII_USTRINGPARAM( "IsBackgroundObjectsVisible" ) );
1979 									if ( mbImpressDoc && !pPDFExtOutDevData->GetIsExportNotesPages() && ( xPagePropSet->getPropertyValue( sIsBackgroundObjectsVisible ) >>= bIsBackgroundObjectsVisible ) && bIsBackgroundObjectsVisible )
1980 									{
1981 										uno::Reference< drawing::XMasterPageTarget > xMasterPageTarget( xPage, uno::UNO_QUERY );
1982 										if ( xMasterPageTarget.is() )
1983 										{
1984 											uno::Reference< drawing::XDrawPage > xMasterPage = xMasterPageTarget->getMasterPage();
1985 											if ( xMasterPage.is() )
1986 											{
1987 												uno::Reference< drawing::XShapes> xShapes( xMasterPage, uno::UNO_QUERY );
1988 												sal_Int32 i, nCount = xShapes->getCount();
1989 												for ( i = 0; i < nCount; i++ )
1990 												{
1991 													aAny = xShapes->getByIndex( i );
1992 													uno::Reference< drawing::XShape > xShape;
1993 													if ( aAny >>= xShape )
1994 														ImplPDFExportShapeInteraction( xShape, *mpDoc, *pPDFExtOutDevData );
1995 												}
1996 											}
1997 										}
1998 									}
1999 
2000 									// exporting slide page object interactions
2001 									uno::Reference< drawing::XShapes> xShapes( xPage, uno::UNO_QUERY );
2002 									sal_Int32 i, nCount = xShapes->getCount();
2003 									for ( i = 0; i < nCount; i++ )
2004 									{
2005 										aAny = xShapes->getByIndex( i );
2006 										uno::Reference< drawing::XShape > xShape;
2007 										if ( aAny >>= xShape )
2008 											ImplPDFExportShapeInteraction( xShape, *mpDoc, *pPDFExtOutDevData );
2009 									}
2010 
2011 									// exporting transition effects to pdf
2012 									if ( mbImpressDoc && !pPDFExtOutDevData->GetIsExportNotesPages() && pPDFExtOutDevData->GetIsExportTransitionEffects() )
2013 									{
2014 										const rtl::OUString sEffect( RTL_CONSTASCII_USTRINGPARAM( "Effect" ) );
2015 										const rtl::OUString sSpeed ( RTL_CONSTASCII_USTRINGPARAM( "Speed" ) );
2016 										sal_Int32 nTime = 800;
2017 										presentation::AnimationSpeed aAs;
2018 										aAny = xPagePropSet->getPropertyValue( sSpeed );
2019 										if ( aAny >>= aAs )
2020 										{
2021 											switch( aAs )
2022 											{
2023 												case presentation::AnimationSpeed_SLOW : nTime = 1500; break;
2024 												case presentation::AnimationSpeed_FAST : nTime = 300; break;
2025 												default:
2026 												case presentation::AnimationSpeed_MEDIUM : nTime = 800;
2027 											}
2028 										}
2029 										presentation::FadeEffect eFe;
2030 										aAny = xPagePropSet->getPropertyValue( sEffect );
2031 										vcl::PDFWriter::PageTransition eType = vcl::PDFWriter::Regular;
2032 										if ( aAny >>= eFe )
2033 										{
2034 											switch( eFe )
2035 											{
2036 												case presentation::FadeEffect_HORIZONTAL_LINES :
2037 												case presentation::FadeEffect_HORIZONTAL_CHECKERBOARD :
2038 												case presentation::FadeEffect_HORIZONTAL_STRIPES : eType = vcl::PDFWriter::BlindsHorizontal; break;
2039 
2040 												case presentation::FadeEffect_VERTICAL_LINES :
2041 												case presentation::FadeEffect_VERTICAL_CHECKERBOARD :
2042 												case presentation::FadeEffect_VERTICAL_STRIPES : eType = vcl::PDFWriter::BlindsVertical; break;
2043 
2044 												case presentation::FadeEffect_UNCOVER_TO_RIGHT :
2045 												case presentation::FadeEffect_UNCOVER_TO_UPPERRIGHT :
2046 												case presentation::FadeEffect_ROLL_FROM_LEFT :
2047 												case presentation::FadeEffect_FADE_FROM_UPPERLEFT :
2048 												case presentation::FadeEffect_MOVE_FROM_UPPERLEFT :
2049 												case presentation::FadeEffect_FADE_FROM_LEFT :
2050 												case presentation::FadeEffect_MOVE_FROM_LEFT : eType = vcl::PDFWriter::WipeLeftToRight; break;
2051 
2052 												case presentation::FadeEffect_UNCOVER_TO_BOTTOM :
2053 												case presentation::FadeEffect_UNCOVER_TO_LOWERRIGHT :
2054 												case presentation::FadeEffect_ROLL_FROM_TOP :
2055 												case presentation::FadeEffect_FADE_FROM_UPPERRIGHT :
2056 												case presentation::FadeEffect_MOVE_FROM_UPPERRIGHT :
2057 												case presentation::FadeEffect_FADE_FROM_TOP :
2058 												case presentation::FadeEffect_MOVE_FROM_TOP : eType = vcl::PDFWriter::WipeTopToBottom; break;
2059 
2060 												case presentation::FadeEffect_UNCOVER_TO_LEFT :
2061 												case presentation::FadeEffect_UNCOVER_TO_LOWERLEFT :
2062 												case presentation::FadeEffect_ROLL_FROM_RIGHT :
2063 
2064 												case presentation::FadeEffect_FADE_FROM_LOWERRIGHT :
2065 												case presentation::FadeEffect_MOVE_FROM_LOWERRIGHT :
2066 												case presentation::FadeEffect_FADE_FROM_RIGHT :
2067 												case presentation::FadeEffect_MOVE_FROM_RIGHT : eType = vcl::PDFWriter::WipeRightToLeft; break;
2068 
2069 												case presentation::FadeEffect_UNCOVER_TO_TOP :
2070 												case presentation::FadeEffect_UNCOVER_TO_UPPERLEFT :
2071 												case presentation::FadeEffect_ROLL_FROM_BOTTOM :
2072 												case presentation::FadeEffect_FADE_FROM_LOWERLEFT :
2073 												case presentation::FadeEffect_MOVE_FROM_LOWERLEFT :
2074 												case presentation::FadeEffect_FADE_FROM_BOTTOM :
2075 												case presentation::FadeEffect_MOVE_FROM_BOTTOM : eType = vcl::PDFWriter::WipeBottomToTop; break;
2076 
2077 												case presentation::FadeEffect_OPEN_VERTICAL : eType = vcl::PDFWriter::SplitHorizontalInward; break;
2078 												case presentation::FadeEffect_CLOSE_HORIZONTAL : eType = vcl::PDFWriter::SplitHorizontalOutward; break;
2079 
2080 												case presentation::FadeEffect_OPEN_HORIZONTAL : eType = vcl::PDFWriter::SplitVerticalInward; break;
2081 												case presentation::FadeEffect_CLOSE_VERTICAL : eType = vcl::PDFWriter::SplitVerticalOutward; break;
2082 
2083 												case presentation::FadeEffect_FADE_TO_CENTER : eType = vcl::PDFWriter::BoxInward; break;
2084 												case presentation::FadeEffect_FADE_FROM_CENTER : eType = vcl::PDFWriter::BoxOutward; break;
2085 
2086 												case presentation::FadeEffect_NONE : eType = vcl::PDFWriter::Regular; break;
2087 
2088 												case presentation::FadeEffect_RANDOM :
2089 												case presentation::FadeEffect_DISSOLVE :
2090 												default: eType = vcl::PDFWriter::Dissolve; break;
2091 											}
2092 										}
2093 										pPDFExtOutDevData->SetPageTransition( eType, nTime, -1 );
2094 									}
2095 								}
2096 							}
2097 							Size		aPageSize( mpDoc->GetSdPage( 0, PK_STANDARD )->GetSize() );
2098 							Point aPoint( 0, 0 );
2099 							Rectangle	aPageRect( aPoint, aPageSize );
2100 
2101 							// resolving links found in this page by the method ImpEditEngine::Paint
2102 							std::vector< vcl::PDFExtOutDevBookmarkEntry >& rBookmarks = pPDFExtOutDevData->GetBookmarks();
2103 							std::vector< vcl::PDFExtOutDevBookmarkEntry >::iterator aIBeg = rBookmarks.begin();
2104 							std::vector< vcl::PDFExtOutDevBookmarkEntry >::iterator aIEnd = rBookmarks.end();
2105 							while ( aIBeg != aIEnd )
2106 							{
2107 								sal_Int32 nPage = ImplPDFGetBookmarkPage( aIBeg->aBookmark, *mpDoc );
2108 								if ( nPage != -1 )
2109 								{
2110 									if ( aIBeg->nLinkId != -1 )
2111 										pPDFExtOutDevData->SetLinkDest( aIBeg->nLinkId, pPDFExtOutDevData->CreateDest( aPageRect, nPage, vcl::PDFWriter::FitRectangle ) );
2112 									else
2113 										pPDFExtOutDevData->DescribeRegisteredDest( aIBeg->nDestId, aPageRect, nPage, vcl::PDFWriter::FitRectangle );
2114 								}
2115 								else
2116 									pPDFExtOutDevData->SetLinkURL( aIBeg->nLinkId, aIBeg->aBookmark );
2117 								aIBeg++;
2118 							}
2119 							rBookmarks.clear();
2120 							//---> i56629, i40318
2121 							//get the page name, will be used as outline element in PDF bookmark pane
2122 							String aPageName = mpDoc->GetSdPage( (sal_uInt16)nPageNumber - 1 , PK_STANDARD )->GetName();
2123 							if( aPageName.Len() > 0 )
2124 							{
2125 								// insert the bookmark to this page into the NamedDestinations
2126 								if( pPDFExtOutDevData->GetIsExportNamedDestinations() )
2127 									pPDFExtOutDevData->CreateNamedDest( aPageName, aPageRect,  nPageNumber - 1 );
2128 								//
2129 								// add the name to the outline, (almost) same code as in sc/source/ui/unoobj/docuno.cxx
2130 								// issue i40318.
2131 								//
2132 								if( pPDFExtOutDevData->GetIsExportBookmarks() )
2133 								{
2134 									// Destination Export
2135 									const sal_Int32 nDestId =
2136 										pPDFExtOutDevData->CreateDest( aPageRect , nPageNumber - 1 );
2137 
2138 									// Create a new outline item:
2139 									pPDFExtOutDevData->CreateOutlineItem( -1 , aPageName, nDestId );
2140 								}
2141 							}
2142 							//<--- i56629, i40318
2143 						}
2144 						catch( uno::Exception& )
2145 						{
2146 						}
2147 
2148 					}
2149             	}
2150             	else
2151             	{
2152 		            uno::Reference< drawing::XShapes > xShapes;
2153 		            rSelection >>= xShapes;
2154 
2155 		            if( xShapes.is() && xShapes->getCount() )
2156 		            {
2157 		               SdrPageView* pPV = NULL;
2158 
2159 					   ImplRenderPaintProc	aImplRenderPaintProc( mpDoc->GetLayerAdmin(),
2160 										pOldSdView ? pOldSdView->GetSdrPageView() : NULL, pPDFExtOutDevData );
2161 
2162 			            for( sal_uInt32 i = 0, nCount = xShapes->getCount(); i < nCount; i++ )
2163 			            {
2164 			                uno::Reference< drawing::XShape > xShape;
2165 				            xShapes->getByIndex( i ) >>= xShape;
2166 
2167 				            if( xShape.is() )
2168 				            {
2169 					            SvxShape* pShape = SvxShape::getImplementation( xShape );
2170 
2171 					            if( pShape )
2172 					            {
2173 						            SdrObject* pObj = pShape->GetSdrObject();
2174 						            if( pObj && pObj->GetPage()
2175 										&& aImplRenderPaintProc.IsVisible( pObj )
2176 											&& aImplRenderPaintProc.IsPrintable( pObj ) )
2177 						            {
2178 						                if( !pPV )
2179                                             pPV = pView->ShowSdrPage( pObj->GetPage() );
2180 
2181                                         if( pPV )
2182 							                pView->MarkObj( pObj, pPV );
2183 							        }
2184 					            }
2185 				            }
2186 			            }
2187                         pView->DrawMarkedObj(*pOut);
2188 		            }
2189 		        }
2190 
2191                 delete pView;
2192             }
2193         }
2194     }
2195 }
2196 
2197 uno::Reference< i18n::XForbiddenCharacters > SdXImpressDocument::getForbiddenCharsTable()
2198 {
2199 	uno::Reference< i18n::XForbiddenCharacters > xForb(mxForbidenCharacters);
2200 
2201 	if( !xForb.is() )
2202 		mxForbidenCharacters = xForb = new SdUnoForbiddenCharsTable( mpDoc );
2203 
2204 	return xForb;
2205 }
2206 
2207 void SdXImpressDocument::initializeDocument()
2208 {
2209     if( !mbClipBoard )
2210     {
2211         switch( mpDoc->GetPageCount() )
2212         {
2213         case 1:
2214         {
2215             // nasty hack to detect clipboard document
2216             mbClipBoard = true;
2217             break;
2218         }
2219         case 0:
2220         {
2221 	        mpDoc->CreateFirstPages();
2222 		    mpDoc->StopWorkStartupDelay();
2223             break;
2224         }
2225 	    }
2226     }
2227 }
2228 
2229 void SAL_CALL SdXImpressDocument::dispose() throw (::com::sun::star::uno::RuntimeException)
2230 {
2231     if( !mbDisposed )
2232     {
2233         {
2234 			OGuard aGuard( Application::GetSolarMutex() );
2235 
2236 			if( mpDoc )
2237 			{
2238 				EndListening( *mpDoc );
2239 				mpDoc = NULL;
2240 			}
2241 
2242 			// Call the base class dispose() before setting the mbDisposed flag
2243 			// to true.  The reason for this is that if close() has not yet been
2244 			// called this is done in SfxBaseModel::dispose().  At the end of
2245 			// that dispose() is called again.  It is important to forward this
2246 			// second dispose() to the base class, too.
2247 			// As a consequence the following code has to be able to be run twice.
2248 			SfxBaseModel::dispose();
2249 			mbDisposed = true;
2250 
2251 			uno::Reference< container::XNameAccess > xStyles(mxStyleFamilies);
2252 			if( xStyles.is() )
2253 			{
2254 				uno::Reference< lang::XComponent > xComp( xStyles, uno::UNO_QUERY );
2255 				if( xComp.is() )
2256 					xComp->dispose();
2257 
2258 				xStyles = 0;
2259 			}
2260 
2261 			uno::Reference< presentation::XPresentation > xPresentation( mxPresentation );
2262 			if( xPresentation.is() )
2263 			{
2264 				uno::Reference< ::com::sun::star::presentation::XPresentation2 > xPres( mpDoc->getPresentation().get() );
2265 				uno::Reference< lang::XComponent > xPresComp( xPres, uno::UNO_QUERY );
2266 				if( xPresComp.is() )
2267 					xPresComp->dispose();
2268 			}
2269 
2270 			uno::Reference< container::XNameAccess > xLinks( mxLinks );
2271 			if( xLinks.is() )
2272 			{
2273 				uno::Reference< lang::XComponent > xComp( xLinks, uno::UNO_QUERY );
2274 				if( xComp.is() )
2275 					xComp->dispose();
2276 
2277 				xLinks = 0;
2278 			}
2279 
2280 			uno::Reference< drawing::XDrawPages > xDrawPagesAccess( mxDrawPagesAccess );
2281 			if( xDrawPagesAccess.is() )
2282 			{
2283 				uno::Reference< lang::XComponent > xComp( xDrawPagesAccess, uno::UNO_QUERY );
2284 				if( xComp.is() )
2285 					xComp->dispose();
2286 
2287 				xDrawPagesAccess = 0;
2288 			}
2289 
2290 			uno::Reference< drawing::XDrawPages > xMasterPagesAccess( mxMasterPagesAccess );
2291 			if( xDrawPagesAccess.is() )
2292 			{
2293 				uno::Reference< lang::XComponent > xComp( xMasterPagesAccess, uno::UNO_QUERY );
2294 				if( xComp.is() )
2295 					xComp->dispose();
2296 
2297 				xDrawPagesAccess = 0;
2298 			}
2299 
2300 			uno::Reference< container::XNameAccess > xLayerManager( mxLayerManager );
2301 			if( xLayerManager.is() )
2302 			{
2303 				uno::Reference< lang::XComponent > xComp( xLayerManager, uno::UNO_QUERY );
2304 				if( xComp.is() )
2305 					xComp->dispose();
2306 
2307 				xLayerManager = 0;
2308 			}
2309 
2310 			uno::Reference< container::XNameContainer > xCustomPresentationAccess( mxCustomPresentationAccess );
2311 			if( xCustomPresentationAccess.is() )
2312 			{
2313 				uno::Reference< lang::XComponent > xComp( xCustomPresentationAccess, uno::UNO_QUERY );
2314 				if( xComp.is() )
2315 					xComp->dispose();
2316 
2317 				xCustomPresentationAccess = 0;
2318 			}
2319 
2320 			mxDashTable = 0;
2321 			mxGradientTable = 0;
2322 			mxHatchTable = 0;
2323 			mxBitmapTable = 0;
2324 			mxTransGradientTable = 0;
2325 			mxMarkerTable = 0;
2326 			mxDrawingPool = 0;
2327 		}
2328 	}
2329 }
2330 
2331 //=============================================================================
2332 // class SdDrawPagesAccess
2333 //=============================================================================
2334 
2335 SdDrawPagesAccess::SdDrawPagesAccess( SdXImpressDocument& rMyModel )  throw()
2336 :	mpModel( &rMyModel)
2337 {
2338 }
2339 
2340 SdDrawPagesAccess::~SdDrawPagesAccess() throw()
2341 {
2342 }
2343 
2344 // XIndexAccess
2345 sal_Int32 SAL_CALL SdDrawPagesAccess::getCount()
2346 	throw(uno::RuntimeException)
2347 {
2348 	OGuard aGuard( Application::GetSolarMutex() );
2349 
2350 	if( NULL == mpModel )
2351 		throw lang::DisposedException();
2352 
2353 	return mpModel->mpDoc->GetSdPageCount( PK_STANDARD );
2354 }
2355 
2356 uno::Any SAL_CALL SdDrawPagesAccess::getByIndex( sal_Int32 Index )
2357 	throw(lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
2358 {
2359 	OGuard aGuard( Application::GetSolarMutex() );
2360 
2361 	if( NULL == mpModel )
2362 		throw lang::DisposedException();
2363 
2364 	uno::Any aAny;
2365 
2366 	if( (Index < 0) || (Index >= mpModel->mpDoc->GetSdPageCount( PK_STANDARD ) ) )
2367 		throw lang::IndexOutOfBoundsException();
2368 
2369 	SdPage* pPage = mpModel->mpDoc->GetSdPage( (sal_uInt16)Index, PK_STANDARD );
2370 	if( pPage )
2371 	{
2372 		uno::Reference< drawing::XDrawPage >  xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
2373 		aAny <<= xDrawPage;
2374 	}
2375 
2376 	return aAny;
2377 }
2378 
2379 // XNameAccess
2380 uno::Any SAL_CALL SdDrawPagesAccess::getByName( const OUString& aName ) throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
2381 {
2382 	OGuard aGuard( Application::GetSolarMutex() );
2383 
2384 	if( NULL == mpModel )
2385 		throw lang::DisposedException();
2386 
2387 	if( aName.getLength() != 0 )
2388 	{
2389 		const sal_uInt16 nCount = mpModel->mpDoc->GetSdPageCount( PK_STANDARD );
2390 		sal_uInt16 nPage;
2391 		for( nPage = 0; nPage < nCount; nPage++ )
2392 		{
2393 			SdPage* pPage = mpModel->mpDoc->GetSdPage( nPage, PK_STANDARD );
2394 			if(NULL == pPage)
2395 				continue;
2396 
2397 			if( aName == SdDrawPage::getPageApiName( pPage ) )
2398 			{
2399 				uno::Any aAny;
2400 				uno::Reference< drawing::XDrawPage >  xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
2401 				aAny <<= xDrawPage;
2402 				return aAny;
2403 			}
2404 		}
2405 	}
2406 
2407 	throw container::NoSuchElementException();
2408 }
2409 
2410 uno::Sequence< OUString > SAL_CALL SdDrawPagesAccess::getElementNames() throw(uno::RuntimeException)
2411 {
2412 	OGuard aGuard( Application::GetSolarMutex() );
2413 
2414 	if( NULL == mpModel )
2415 		throw lang::DisposedException();
2416 
2417 	const sal_uInt16 nCount = mpModel->mpDoc->GetSdPageCount( PK_STANDARD );
2418 	uno::Sequence< OUString > aNames( nCount );
2419 	OUString* pNames = aNames.getArray();
2420 
2421 	sal_uInt16 nPage;
2422 	for( nPage = 0; nPage < nCount; nPage++ )
2423 	{
2424 		SdPage* pPage = mpModel->mpDoc->GetSdPage( nPage, PK_STANDARD );
2425 		*pNames++ = SdDrawPage::getPageApiName( pPage );
2426 	}
2427 
2428 	return aNames;
2429 }
2430 
2431 sal_Bool SAL_CALL SdDrawPagesAccess::hasByName( const OUString& aName ) throw(uno::RuntimeException)
2432 {
2433 	OGuard aGuard( Application::GetSolarMutex() );
2434 
2435 	if( NULL == mpModel )
2436 		throw lang::DisposedException();
2437 
2438 	const sal_uInt16 nCount = mpModel->mpDoc->GetSdPageCount( PK_STANDARD );
2439 	sal_uInt16 nPage;
2440 	for( nPage = 0; nPage < nCount; nPage++ )
2441 	{
2442 		SdPage* pPage = mpModel->mpDoc->GetSdPage( nPage, PK_STANDARD );
2443 		if(NULL == pPage)
2444 			continue;
2445 
2446 		if( aName == SdDrawPage::getPageApiName( pPage ) )
2447 			return sal_True;
2448 	}
2449 
2450 	return sal_False;
2451 }
2452 
2453 // XElementAccess
2454 uno::Type SAL_CALL SdDrawPagesAccess::getElementType()
2455 	throw(uno::RuntimeException)
2456 {
2457 	return ITYPE( drawing::XDrawPage );
2458 }
2459 
2460 sal_Bool SAL_CALL SdDrawPagesAccess::hasElements()
2461 	throw(uno::RuntimeException)
2462 {
2463 	return getCount() > 0;
2464 }
2465 
2466 // XDrawPages
2467 
2468 /******************************************************************************
2469 * Erzeugt eine neue Seite mit Model an der angegebennen Position und gibt die *
2470 * dazugehoerige SdDrawPage zurueck.                                           *
2471 ******************************************************************************/
2472 uno::Reference< drawing::XDrawPage > SAL_CALL SdDrawPagesAccess::insertNewByIndex( sal_Int32 nIndex )
2473 	throw(uno::RuntimeException)
2474 {
2475 	OGuard aGuard( Application::GetSolarMutex() );
2476 
2477 	if( NULL == mpModel )
2478 		throw lang::DisposedException();
2479 
2480 	if( mpModel->mpDoc )
2481 	{
2482 		SdPage* pPage = mpModel->InsertSdPage( (sal_uInt16)nIndex );
2483 		if( pPage )
2484 		{
2485 			uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
2486 			return xDrawPage;
2487 		}
2488 	}
2489 	uno::Reference< drawing::XDrawPage > xDrawPage;
2490 	return xDrawPage;
2491 }
2492 
2493 /******************************************************************************
2494 * Entfernt die angegebenne SdDrawPage aus dem Model und aus der internen      *
2495 * Liste. Dies funktioniert nur, wenn mindestens eine *normale* Seite im Model *
2496 * nach dem entfernen dieser Seite vorhanden ist.							  *
2497 ******************************************************************************/
2498 void SAL_CALL SdDrawPagesAccess::remove( const uno::Reference< drawing::XDrawPage >& xPage )
2499 		throw(uno::RuntimeException)
2500 {
2501 	OGuard aGuard( Application::GetSolarMutex() );
2502 
2503 	if( NULL == mpModel || mpModel->mpDoc == NULL )
2504 		throw lang::DisposedException();
2505 
2506 	SdDrawDocument& rDoc = *mpModel->mpDoc;
2507 
2508 	sal_uInt16 nPageCount = rDoc.GetSdPageCount( PK_STANDARD );
2509 	if( nPageCount > 1 )
2510 	{
2511 		// pPage von xPage besorgen und dann die Id (nPos )ermitteln
2512 		SdDrawPage* pSvxPage = SdDrawPage::getImplementation( xPage );
2513 		if( pSvxPage )
2514 		{
2515 			SdPage* pPage = (SdPage*) pSvxPage->GetSdrPage();
2516 			if(pPage && ( pPage->GetPageKind() == PK_STANDARD ) )
2517 			{
2518 				sal_uInt16 nPage = pPage->GetPageNum();
2519 
2520 				SdPage* pNotesPage = static_cast< SdPage* >( rDoc.GetPage( nPage+1 ) );
2521 
2522 				bool bUndo = rDoc.IsUndoEnabled();
2523 				if( bUndo )
2524 				{
2525 					// Add undo actions and delete the pages.  The order of adding
2526 					// the undo actions is important.
2527 					rDoc.BegUndo( SdResId( STR_UNDO_DELETEPAGES ) );
2528 					rDoc.AddUndo(rDoc.GetSdrUndoFactory().CreateUndoDeletePage(*pNotesPage));
2529 					rDoc.AddUndo(rDoc.GetSdrUndoFactory().CreateUndoDeletePage(*pPage));
2530 				}
2531 
2532 				rDoc.RemovePage( nPage ); // the page
2533 				rDoc.RemovePage( nPage ); // the notes page
2534 
2535 				if( bUndo )
2536 				{
2537 					rDoc.EndUndo();
2538 				}
2539 				else
2540 				{
2541 					delete pNotesPage;
2542 					delete pPage;
2543 				}
2544 			}
2545 		}
2546 	}
2547 
2548 	mpModel->SetModified();
2549 }
2550 
2551 // XServiceInfo
2552 sal_Char pSdDrawPagesAccessService[sizeof("com.sun.star.drawing.DrawPages")] = "com.sun.star.drawing.DrawPages";
2553 
2554 OUString SAL_CALL SdDrawPagesAccess::getImplementationName(  ) throw(uno::RuntimeException)
2555 {
2556 	return OUString( RTL_CONSTASCII_USTRINGPARAM( "SdDrawPagesAccess" ) );
2557 }
2558 
2559 sal_Bool SAL_CALL SdDrawPagesAccess::supportsService( const OUString& ServiceName ) throw(uno::RuntimeException)
2560 {
2561 	return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( pSdDrawPagesAccessService ) );
2562 }
2563 
2564 uno::Sequence< OUString > SAL_CALL SdDrawPagesAccess::getSupportedServiceNames(  ) throw(uno::RuntimeException)
2565 {
2566 	OUString aService( RTL_CONSTASCII_USTRINGPARAM( pSdDrawPagesAccessService ) );
2567 	uno::Sequence< OUString > aSeq( &aService, 1 );
2568 	return aSeq;
2569 }
2570 
2571 // XComponent
2572 void SAL_CALL SdDrawPagesAccess::dispose(  ) throw (uno::RuntimeException)
2573 {
2574 	mpModel = NULL;
2575 }
2576 
2577 void SAL_CALL SdDrawPagesAccess::addEventListener( const uno::Reference< lang::XEventListener >&  ) throw (uno::RuntimeException)
2578 {
2579 	DBG_ERROR( "not implemented!" );
2580 }
2581 
2582 void SAL_CALL SdDrawPagesAccess::removeEventListener( const uno::Reference< lang::XEventListener >&  ) throw (uno::RuntimeException)
2583 {
2584 	DBG_ERROR( "not implemented!" );
2585 }
2586 
2587 //=============================================================================
2588 // class SdMasterPagesAccess
2589 //=============================================================================
2590 
2591 SdMasterPagesAccess::SdMasterPagesAccess( SdXImpressDocument& rMyModel ) throw()
2592 :	mpModel(&rMyModel)
2593 {
2594 }
2595 
2596 SdMasterPagesAccess::~SdMasterPagesAccess() throw()
2597 {
2598 }
2599 
2600 // XComponent
2601 void SAL_CALL SdMasterPagesAccess::dispose(  ) throw (uno::RuntimeException)
2602 {
2603 	mpModel = NULL;
2604 }
2605 
2606 void SAL_CALL SdMasterPagesAccess::addEventListener( const uno::Reference< lang::XEventListener >&  ) throw (uno::RuntimeException)
2607 {
2608 	DBG_ERROR( "not implemented!" );
2609 }
2610 
2611 void SAL_CALL SdMasterPagesAccess::removeEventListener( const uno::Reference< lang::XEventListener >&  ) throw (uno::RuntimeException)
2612 {
2613 	DBG_ERROR( "not implemented!" );
2614 }
2615 
2616 // XIndexAccess
2617 sal_Int32 SAL_CALL SdMasterPagesAccess::getCount()
2618 	throw(uno::RuntimeException)
2619 {
2620 	OGuard aGuard( Application::GetSolarMutex() );
2621 
2622 	if( NULL == mpModel->mpDoc )
2623 		throw lang::DisposedException();
2624 
2625 	return mpModel->mpDoc->GetMasterSdPageCount(PK_STANDARD);
2626 }
2627 
2628 /******************************************************************************
2629 * Liefert ein drawing::XDrawPage Interface fuer den Zugriff auf die Masterpage and der *
2630 * angegebennen Position im Model.                                             *
2631 ******************************************************************************/
2632 uno::Any SAL_CALL SdMasterPagesAccess::getByIndex( sal_Int32 Index )
2633 	throw(lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
2634 {
2635 	OGuard aGuard( Application::GetSolarMutex() );
2636 
2637 	if( NULL == mpModel )
2638 		throw lang::DisposedException();
2639 
2640 	uno::Any aAny;
2641 
2642 	if( (Index < 0) || (Index >= mpModel->mpDoc->GetMasterSdPageCount( PK_STANDARD ) ) )
2643 		throw lang::IndexOutOfBoundsException();
2644 
2645 	SdPage* pPage = mpModel->mpDoc->GetMasterSdPage( (sal_uInt16)Index, PK_STANDARD );
2646 	if( pPage )
2647 	{
2648 		uno::Reference< drawing::XDrawPage >  xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
2649 		aAny <<= xDrawPage;
2650 	}
2651 
2652 	return aAny;
2653 }
2654 
2655 // XElementAccess
2656 uno::Type SAL_CALL SdMasterPagesAccess::getElementType()
2657 	throw(uno::RuntimeException)
2658 {
2659 	return ITYPE(drawing::XDrawPage);
2660 }
2661 
2662 sal_Bool SAL_CALL SdMasterPagesAccess::hasElements()
2663 	throw(uno::RuntimeException)
2664 {
2665 	return getCount() > 0;
2666 }
2667 
2668 // XDrawPages
2669 uno::Reference< drawing::XDrawPage > SAL_CALL SdMasterPagesAccess::insertNewByIndex( sal_Int32 nInsertPos )
2670 	throw(uno::RuntimeException)
2671 {
2672 	OGuard aGuard( Application::GetSolarMutex() );
2673 
2674 	if( NULL == mpModel )
2675 		throw lang::DisposedException();
2676 
2677 	uno::Reference< drawing::XDrawPage > xDrawPage;
2678 
2679 	SdDrawDocument* mpDoc = mpModel->mpDoc;
2680 	if( mpDoc )
2681 	{
2682 		// calculate internal index and check for range errors
2683 		const sal_Int32 nMPageCount = mpDoc->GetMasterPageCount();
2684 		nInsertPos = nInsertPos * 2 + 1;
2685 		if( nInsertPos < 0 || nInsertPos > nMPageCount )
2686 			nInsertPos = nMPageCount;
2687 
2688 		// now generate a unique name for the new masterpage
2689 		const String aStdPrefix( SdResId(STR_LAYOUT_DEFAULT_NAME) );
2690 		String aPrefix( aStdPrefix );
2691 
2692 		sal_Bool bUnique = sal_True;
2693 		sal_Int32 i = 0;
2694 		do
2695 		{
2696 			bUnique = sal_True;
2697 			for( sal_Int32 nMaster = 1; nMaster < nMPageCount; nMaster++ )
2698 			{
2699 				SdPage* pPage = (SdPage*)mpDoc->GetMasterPage((sal_uInt16)nMaster);
2700 				if( pPage && pPage->GetName() == aPrefix )
2701 				{
2702 					bUnique = sal_False;
2703 					break;
2704 				}
2705 			}
2706 
2707 			if( !bUnique )
2708 			{
2709 				i++;
2710 				aPrefix = aStdPrefix;
2711 				aPrefix += sal_Unicode( ' ' );
2712 				aPrefix += String::CreateFromInt32( i );
2713 			}
2714 
2715 		} while( !bUnique );
2716 
2717 		String aLayoutName( aPrefix );
2718 		aLayoutName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( SD_LT_SEPARATOR ));
2719 		aLayoutName += String(SdResId(STR_LAYOUT_OUTLINE));
2720 
2721 		// create styles
2722 		((SdStyleSheetPool*)mpDoc->GetStyleSheetPool())->CreateLayoutStyleSheets( aPrefix );
2723 
2724 		// get the first page for initial size and border settings
2725 		SdPage* pPage = mpModel->mpDoc->GetSdPage( (sal_uInt16)0, PK_STANDARD );
2726 		SdPage* pRefNotesPage = mpModel->mpDoc->GetSdPage( (sal_uInt16)0, PK_NOTES);
2727 
2728 		// create and instert new draw masterpage
2729 		SdPage* pMPage = (SdPage*)mpModel->mpDoc->AllocPage(sal_True);
2730 		pMPage->SetSize( pPage->GetSize() );
2731 		pMPage->SetBorder( pPage->GetLftBorder(),
2732 						   pPage->GetUppBorder(),
2733 						   pPage->GetRgtBorder(),
2734 						   pPage->GetLwrBorder() );
2735 		pMPage->SetLayoutName( aLayoutName );
2736 		mpDoc->InsertMasterPage(pMPage,  (sal_uInt16)nInsertPos);
2737 
2738 		{
2739 			// ensure default MasterPage fill
2740             pMPage->EnsureMasterPageDefaultBackground();
2741 		}
2742 
2743 		xDrawPage = uno::Reference< drawing::XDrawPage >::query( pMPage->getUnoPage() );
2744 
2745 		// create and instert new notes masterpage
2746 		SdPage* pMNotesPage = (SdPage*)mpModel->mpDoc->AllocPage(sal_True);
2747 		pMNotesPage->SetSize( pRefNotesPage->GetSize() );
2748 		pMNotesPage->SetPageKind(PK_NOTES);
2749 		pMNotesPage->SetBorder( pRefNotesPage->GetLftBorder(),
2750 								pRefNotesPage->GetUppBorder(),
2751 								pRefNotesPage->GetRgtBorder(),
2752 								pRefNotesPage->GetLwrBorder() );
2753 		pMNotesPage->SetLayoutName( aLayoutName );
2754 		mpDoc->InsertMasterPage(pMNotesPage,  (sal_uInt16)nInsertPos + 1);
2755 //		pMNotesPage->InsertMasterPage( pMPage->GetPageNum() );
2756 		pMNotesPage->SetAutoLayout(AUTOLAYOUT_NOTES, sal_True, sal_True);
2757 		mpModel->SetModified();
2758 	}
2759 
2760 	return( xDrawPage );
2761 }
2762 
2763 /******************************************************************************
2764 * Entfernt die angegebenne SdMasterPage aus dem Model und aus der internen    *
2765 * Liste. Dies funktioniert nur, wenn keine *normale* Seite im Model diese     *
2766 * Seite als Masterpage benutzt.                                               *
2767 ******************************************************************************/
2768 void SAL_CALL SdMasterPagesAccess::remove( const uno::Reference< drawing::XDrawPage >& xPage )
2769 	throw(uno::RuntimeException)
2770 {
2771 	OGuard aGuard( Application::GetSolarMutex() );
2772 
2773 	if( NULL == mpModel || mpModel->mpDoc == NULL )
2774 		throw lang::DisposedException();
2775 
2776 	SdDrawDocument& rDoc = *mpModel->mpDoc;
2777 
2778 	SdMasterPage* pSdPage = SdMasterPage::getImplementation( xPage );
2779 	if(pSdPage == NULL)
2780 		return;
2781 
2782 	SdPage* pPage = dynamic_cast< SdPage* > (pSdPage->GetSdrPage());
2783 
2784 	DBG_ASSERT( pPage && pPage->IsMasterPage(), "SdMasterPage is not masterpage?");
2785 
2786 	if( !pPage || !pPage->IsMasterPage() || (mpModel->mpDoc->GetMasterPageUserCount(pPage) > 0))
2787 		return; //Todo: this should be excepted
2788 
2789 	// only standard pages can be removed directly
2790 	if( pPage->GetPageKind() == PK_STANDARD )
2791 	{
2792 		sal_uInt16 nPage = pPage->GetPageNum();
2793 
2794 		SdPage* pNotesPage = static_cast< SdPage* >( rDoc.GetMasterPage( nPage+1 ) );
2795 
2796 		bool bUndo = rDoc.IsUndoEnabled();
2797 		if( bUndo )
2798 		{
2799 			// Add undo actions and delete the pages.  The order of adding
2800 			// the undo actions is important.
2801 			rDoc.BegUndo( SdResId( STR_UNDO_DELETEPAGES ) );
2802 			rDoc.AddUndo(rDoc.GetSdrUndoFactory().CreateUndoDeletePage(*pNotesPage));
2803 			rDoc.AddUndo(rDoc.GetSdrUndoFactory().CreateUndoDeletePage(*pPage));
2804 		}
2805 
2806 		rDoc.RemoveMasterPage( nPage );
2807 		rDoc.RemoveMasterPage( nPage );
2808 
2809 		if( bUndo )
2810 		{
2811 			rDoc.EndUndo();
2812 		}
2813 		else
2814 		{
2815 			delete pNotesPage;
2816 			delete pPage;
2817 		}
2818 	}
2819 }
2820 
2821 // XServiceInfo
2822 sal_Char pSdMasterPagesAccessService[sizeof("com.sun.star.drawing.MasterPages")] = "com.sun.star.drawing.MasterPages";
2823 
2824 OUString SAL_CALL SdMasterPagesAccess::getImplementationName(  ) throw(uno::RuntimeException)
2825 {
2826 	return OUString( RTL_CONSTASCII_USTRINGPARAM( "SdMasterPagesAccess" ) );
2827 }
2828 
2829 sal_Bool SAL_CALL SdMasterPagesAccess::supportsService( const OUString& ServiceName ) throw(uno::RuntimeException)
2830 {
2831 	return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( pSdMasterPagesAccessService ) );
2832 }
2833 
2834 uno::Sequence< OUString > SAL_CALL SdMasterPagesAccess::getSupportedServiceNames(  ) throw(uno::RuntimeException)
2835 {
2836 	OUString aService( RTL_CONSTASCII_USTRINGPARAM( pSdMasterPagesAccessService ) );
2837 	uno::Sequence< OUString > aSeq( &aService, 1 );
2838 	return aSeq;
2839 }
2840 
2841 //=============================================================================
2842 // class SdDocLinkTargets
2843 //=============================================================================
2844 
2845 SdDocLinkTargets::SdDocLinkTargets( SdXImpressDocument& rMyModel ) throw()
2846 : mpModel( &rMyModel )
2847 {
2848 }
2849 
2850 SdDocLinkTargets::~SdDocLinkTargets() throw()
2851 {
2852 }
2853 
2854 // XComponent
2855 void SAL_CALL SdDocLinkTargets::dispose(  ) throw (uno::RuntimeException)
2856 {
2857 	mpModel = NULL;
2858 }
2859 
2860 void SAL_CALL SdDocLinkTargets::addEventListener( const uno::Reference< lang::XEventListener >&  ) throw (uno::RuntimeException)
2861 {
2862 	DBG_ERROR( "not implemented!" );
2863 }
2864 
2865 void SAL_CALL SdDocLinkTargets::removeEventListener( const uno::Reference< lang::XEventListener >&  ) throw (uno::RuntimeException)
2866 {
2867 	DBG_ERROR( "not implemented!" );
2868 }
2869 
2870 // XNameAccess
2871 uno::Any SAL_CALL SdDocLinkTargets::getByName( const OUString& aName )
2872 	throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
2873 {
2874 	OGuard aGuard( Application::GetSolarMutex() );
2875 
2876 	if( NULL == mpModel )
2877 		throw lang::DisposedException();
2878 
2879 	SdPage* pPage = FindPage( aName );
2880 
2881 	if( pPage == NULL )
2882 		throw container::NoSuchElementException();
2883 
2884 	uno::Any aAny;
2885 
2886 	uno::Reference< beans::XPropertySet > xProps( pPage->getUnoPage(), uno::UNO_QUERY );
2887 	if( xProps.is() )
2888 		aAny <<= xProps;
2889 
2890 	return aAny;
2891 }
2892 
2893 uno::Sequence< OUString > SAL_CALL SdDocLinkTargets::getElementNames()
2894 	throw(uno::RuntimeException)
2895 {
2896 	OGuard aGuard( Application::GetSolarMutex() );
2897 
2898 	if( NULL == mpModel )
2899 		throw lang::DisposedException();
2900 
2901 	SdDrawDocument* mpDoc = mpModel->GetDoc();
2902 	if( mpDoc == NULL )
2903 	{
2904 		uno::Sequence< OUString > aSeq;
2905 		return aSeq;
2906 	}
2907 
2908 	if( mpDoc->GetDocumentType() == DOCUMENT_TYPE_DRAW )
2909 	{
2910 		const sal_uInt16 nMaxPages = mpDoc->GetSdPageCount( PK_STANDARD );
2911 		const sal_uInt16 nMaxMasterPages = mpDoc->GetMasterSdPageCount( PK_STANDARD );
2912 
2913 		uno::Sequence< OUString > aSeq( nMaxPages + nMaxMasterPages );
2914 		OUString* pStr = aSeq.getArray();
2915 
2916 		sal_uInt16 nPage;
2917 		// standard pages
2918 		for( nPage = 0; nPage < nMaxPages; nPage++ )
2919 			*pStr++ = mpDoc->GetSdPage( nPage, PK_STANDARD )->GetName();
2920 
2921 		// master pages
2922 		for( nPage = 0; nPage < nMaxMasterPages; nPage++ )
2923 			*pStr++ = mpDoc->GetMasterSdPage( nPage, PK_STANDARD )->GetName();
2924 		return aSeq;
2925 	}
2926 	else
2927 	{
2928 		const sal_uInt16 nMaxPages = mpDoc->GetPageCount();
2929 		const sal_uInt16 nMaxMasterPages = mpDoc->GetMasterPageCount();
2930 
2931 		uno::Sequence< OUString > aSeq( nMaxPages + nMaxMasterPages );
2932 		OUString* pStr = aSeq.getArray();
2933 
2934 		sal_uInt16 nPage;
2935 		// standard pages
2936 		for( nPage = 0; nPage < nMaxPages; nPage++ )
2937 			*pStr++ = ((SdPage*)mpDoc->GetPage( nPage ))->GetName();
2938 
2939 		// master pages
2940 		for( nPage = 0; nPage < nMaxMasterPages; nPage++ )
2941 			*pStr++ = ((SdPage*)mpDoc->GetMasterPage( nPage ))->GetName();
2942 		return aSeq;
2943 	}
2944 }
2945 
2946 sal_Bool SAL_CALL SdDocLinkTargets::hasByName( const OUString& aName )
2947 	throw(uno::RuntimeException)
2948 {
2949 	OGuard aGuard( Application::GetSolarMutex() );
2950 
2951 	if( NULL == mpModel )
2952 		throw lang::DisposedException();
2953 
2954 	return FindPage( aName ) != NULL;
2955 }
2956 
2957 // container::XElementAccess
2958 uno::Type SAL_CALL SdDocLinkTargets::getElementType()
2959 	throw(uno::RuntimeException)
2960 {
2961 	return ITYPE(beans::XPropertySet);
2962 }
2963 
2964 sal_Bool SAL_CALL SdDocLinkTargets::hasElements()
2965 	throw(uno::RuntimeException)
2966 {
2967 	OGuard aGuard( Application::GetSolarMutex() );
2968 
2969 	if( NULL == mpModel )
2970 		throw lang::DisposedException();
2971 
2972 	return mpModel->GetDoc() != NULL;
2973 }
2974 
2975 SdPage* SdDocLinkTargets::FindPage( const OUString& rName ) const throw()
2976 {
2977 	SdDrawDocument* mpDoc = mpModel->GetDoc();
2978 	if( mpDoc == NULL )
2979 		return NULL;
2980 
2981 	const sal_uInt16 nMaxPages = mpDoc->GetPageCount();
2982 	const sal_uInt16 nMaxMasterPages = mpDoc->GetMasterPageCount();
2983 
2984 	sal_uInt16 nPage;
2985 	SdPage* pPage;
2986 
2987 	const String aName( rName );
2988 
2989 	const bool bDraw = mpDoc->GetDocumentType() == DOCUMENT_TYPE_DRAW;
2990 
2991 	// standard pages
2992 	for( nPage = 0; nPage < nMaxPages; nPage++ )
2993 	{
2994 		pPage = (SdPage*)mpDoc->GetPage( nPage );
2995 		if( (pPage->GetName() == aName) && (!bDraw || (pPage->GetPageKind() == PK_STANDARD)) )
2996 			return pPage;
2997 	}
2998 
2999 	// master pages
3000 	for( nPage = 0; nPage < nMaxMasterPages; nPage++ )
3001 	{
3002 		pPage = (SdPage*)mpDoc->GetMasterPage( nPage );
3003 		if( (pPage->GetName() == aName) && (!bDraw || (pPage->GetPageKind() == PK_STANDARD)) )
3004 			return pPage;
3005 	}
3006 
3007 	return NULL;
3008 }
3009 
3010 // XServiceInfo
3011 OUString SAL_CALL SdDocLinkTargets::getImplementationName()
3012 	throw(uno::RuntimeException)
3013 {
3014 	return OUString( RTL_CONSTASCII_USTRINGPARAM("SdDocLinkTargets") );
3015 }
3016 
3017 sal_Bool SAL_CALL SdDocLinkTargets::supportsService( const OUString& ServiceName )
3018 	throw(uno::RuntimeException)
3019 {
3020 	return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
3021 }
3022 
3023 uno::Sequence< OUString > SAL_CALL SdDocLinkTargets::getSupportedServiceNames()
3024 	throw(uno::RuntimeException)
3025 {
3026 	const OUString aSN( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.LinkTargets") );
3027 	uno::Sequence< OUString > aSeq( &aSN, 1 );
3028 	return aSeq;
3029 }
3030 
3031 rtl::Reference< SdXImpressDocument > SdXImpressDocument::GetModel( SdDrawDocument* pDocument )
3032 {
3033 	rtl::Reference< SdXImpressDocument > xRet;
3034 	if( pDocument )
3035 	{
3036 		::sd::DrawDocShell* pDocShell = pDocument->GetDocSh();
3037 		if( pDocShell )
3038 		{
3039 			uno::Reference<frame::XModel> xModel(pDocShell->GetModel());
3040 
3041 			xRet.set( dynamic_cast< SdXImpressDocument* >( xModel.get() ) );
3042 		}
3043 	}
3044 
3045 	return xRet;
3046 }
3047 
3048 void NotifyDocumentEvent( SdDrawDocument* pDocument, const rtl::OUString& rEventName )
3049 {
3050 	rtl::Reference< SdXImpressDocument > xModel( SdXImpressDocument::GetModel( pDocument ) );
3051 
3052 	if( xModel.is() )
3053 	{
3054 		uno::Reference< uno::XInterface > xSource( static_cast<uno::XWeak*>( xModel.get() ) );
3055 		::com::sun::star::document::EventObject aEvent( xSource, rEventName );
3056 		xModel->notifyEvent(aEvent );
3057 	}
3058 }
3059 
3060 void NotifyDocumentEvent( SdDrawDocument* pDocument, const rtl::OUString& rEventName, const uno::Reference< uno::XInterface >& xSource )
3061 {
3062 	rtl::Reference< SdXImpressDocument > xModel( SdXImpressDocument::GetModel( pDocument ) );
3063 
3064 	if( xModel.is() )
3065 	{
3066 		::com::sun::star::document::EventObject aEvent( xSource, rEventName );
3067 		xModel->notifyEvent(aEvent );
3068 	}
3069 }
3070