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