1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_sd.hxx"
31 #include <sfx2/docfile.hxx>
32 #include <vcl/svapp.hxx>
33 #include <editeng/outliner.hxx>
34 #include <sfx2/linkmgr.hxx>
35 #include <svx/svdotext.hxx>
36 #include <tools/urlobj.hxx>
37 #include <editeng/outlobj.hxx>
38 #include <svl/urihelper.hxx>
39 #include <editeng/xmlcnitm.hxx>
40 #include <svx/svditer.hxx>
41 #include <tools/list.hxx>
43 #include "sdresid.hxx"
47 #include "drawdoc.hxx"
48 #include "stlpool.hxx"
50 #include "anminfo.hxx"
52 #include "../ui/inc/strings.hrc"
53 #include "../ui/inc/DrawDocShell.hxx"
56 #include <tools/tenccvt.hxx>
57 #include <svl/itemset.hxx>
60 using namespace ::com::sun::star
;
61 using namespace ::com::sun::star::uno
;
62 using namespace ::com::sun::star::office
;
64 extern void NotifyDocumentEvent( SdDrawDocument
* pDocument
, const rtl::OUString
& rEventName
, const Reference
< XInterface
>& xSource
);
66 /*************************************************************************
68 |* SetPresentationLayout, setzt: Layoutnamen, Masterpage-Verkn�pfung und
69 |* Vorlagen fuer Praesentationsobjekte
71 |* Vorraussetzungen: - Die Seite muss bereits das richtige Model kennen!
72 |* - Die entsprechende Masterpage muss bereits im Model sein.
73 |* - Die entsprechenden StyleSheets muessen bereits im
74 |* im StyleSheetPool sein.
76 |* bReplaceStyleSheets = TRUE : Benannte StyleSheets werden ausgetauscht
77 |* FALSE: Alle StyleSheets werden neu zugewiesen
79 |* bSetMasterPage = TRUE : MasterPage suchen und zuweisen
81 |* bReverseOrder = FALSE: MasterPages von vorn nach hinten suchen
82 |* TRUE : MasterPages von hinten nach vorn suchen (fuer Undo-Action)
84 \************************************************************************/
86 void SdPage::SetPresentationLayout(const String
& rLayoutName
,
87 BOOL bReplaceStyleSheets
,
91 /*********************************************************************
92 |* Layoutname der Seite
93 \********************************************************************/
94 String
aOldLayoutName(maLayoutName
); // merken
95 maLayoutName
= rLayoutName
;
96 maLayoutName
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( SD_LT_SEPARATOR
));
97 maLayoutName
+= String(SdResId(STR_LAYOUT_OUTLINE
));
99 /*********************************************************************
100 |* ggf. Masterpage suchen und setzen
101 \********************************************************************/
102 if (bSetMasterPage
&& !IsMasterPage())
105 SdPage
* pFoundMaster
= 0;
107 USHORT nMasterCount
= pModel
->GetMasterPageCount();
111 for ( nMaster
= 0; nMaster
< nMasterCount
; nMaster
++ )
113 pMaster
= static_cast<SdPage
*>(pModel
->GetMasterPage(nMaster
));
114 if (pMaster
->GetPageKind() == mePageKind
&& pMaster
->GetLayoutName() == maLayoutName
)
116 pFoundMaster
= pMaster
;
123 for ( nMaster
= nMasterCount
; nMaster
> 0; nMaster
-- )
125 pMaster
= static_cast<SdPage
*>(pModel
->GetMasterPage(nMaster
- 1));
126 if (pMaster
->GetPageKind() == mePageKind
&& pMaster
->GetLayoutName() == maLayoutName
)
128 pFoundMaster
= pMaster
;
134 DBG_ASSERT(pFoundMaster
, "Masterpage for presentation layout not found!");
136 // this should never happen, but we play failsafe here
137 if( pFoundMaster
== 0 )
138 pFoundMaster
= static_cast< SdDrawDocument
*>(pModel
)->GetSdPage( 0, mePageKind
);
141 TRG_SetMasterPage(*pFoundMaster
);
144 /*********************************************************************
145 |* Vorlagen fuer Praesentationsobjekte
146 \********************************************************************/
148 // - Vorlagenzeigern fuer Gliederungstextobjekt (alte und neue Vorlagen)
149 // -Replacedaten fuer OutlinerParaObject
151 List aOldOutlineStyles
;
153 BOOL bListsFilled
= FALSE
;
155 ULONG nObjCount
= GetObjCount();
157 for (ULONG nObj
= 0; nObj
< nObjCount
; nObj
++)
159 SdrTextObj
* pObj
= (SdrTextObj
*) GetObj(nObj
);
161 if (pObj
->GetObjInventor() == SdrInventor
&&
162 pObj
->GetObjIdentifier() == OBJ_OUTLINETEXT
)
164 if (!bListsFilled
|| !bReplaceStyleSheets
)
168 SfxStyleSheetBase
* pSheet
= NULL
;
169 SfxStyleSheetBasePool
* pStShPool
= pModel
->GetStyleSheetPool();
171 for (sal_Int16 i
= -1; i
< 9; i
++)
173 aFullName
= maLayoutName
;
174 aOldFullName
= aOldLayoutName
;
175 aFullName
+= sal_Unicode( ' ' );
176 aFullName
+= String::CreateFromInt32( (sal_Int32
) (i
<= 0 ) ? 1 : i
+ 1);
177 aOldFullName
+= sal_Unicode( ' ' );
178 aOldFullName
+= String::CreateFromInt32( (sal_Int32
) (i
<= 0 ) ? 1 : i
+ 1 );
180 pSheet
= pStShPool
->Find(aOldFullName
, SD_STYLE_FAMILY_MASTERPAGE
);
181 DBG_ASSERT(pSheet
, "alte Gliederungsvorlage nicht gefunden");
182 aOldOutlineStyles
.Insert(pSheet
, LIST_APPEND
);
184 pSheet
= pStShPool
->Find(aFullName
, SD_STYLE_FAMILY_MASTERPAGE
);
185 DBG_ASSERT(pSheet
, "neue Gliederungsvorlage nicht gefunden");
186 aOutlineStyles
.Insert(pSheet
, LIST_APPEND
);
188 if (bReplaceStyleSheets
&& pSheet
)
190 // Replace anstatt Set
191 StyleReplaceData
* pReplData
= new StyleReplaceData
;
192 pReplData
->nNewFamily
= pSheet
->GetFamily();
193 pReplData
->nFamily
= pSheet
->GetFamily();
194 pReplData
->aNewName
= aFullName
;
195 pReplData
->aName
= aOldFullName
;
196 aReplList
.Insert(pReplData
, LIST_APPEND
);
200 OutlinerParaObject
* pOPO
= ((SdrTextObj
*)pObj
)->GetOutlinerParaObject();
203 pOPO
->SetStyleSheets( i
, aFullName
, SD_STYLE_FAMILY_MASTERPAGE
);
210 SfxStyleSheet
* pSheet
= (SfxStyleSheet
*)aOutlineStyles
.First();
211 SfxStyleSheet
* pOldSheet
= (SfxStyleSheet
*)aOldOutlineStyles
.First();
214 if (pSheet
!= pOldSheet
)
216 pObj
->EndListening(*pOldSheet
);
218 if (!pObj
->IsListening(*pSheet
))
219 pObj
->StartListening(*pSheet
);
222 pSheet
= (SfxStyleSheet
*)aOutlineStyles
.Next();
223 pOldSheet
= (SfxStyleSheet
*)aOldOutlineStyles
.Next();
226 OutlinerParaObject
* pOPO
= ((SdrTextObj
*)pObj
)->GetOutlinerParaObject();
227 if ( bReplaceStyleSheets
&& pOPO
)
229 StyleReplaceData
* pReplData
= (StyleReplaceData
*) aReplList
.First();
233 pOPO
->ChangeStyleSheets( pReplData
->aName
, pReplData
->nFamily
, pReplData
->aNewName
, pReplData
->nNewFamily
);
234 pReplData
= (StyleReplaceData
*) aReplList
.Next();
238 else if (pObj
->GetObjInventor() == SdrInventor
&&
239 pObj
->GetObjIdentifier() == OBJ_TITLETEXT
)
241 // PresObjKind nicht ueber GetPresObjKind() holen, da dort nur
242 // die PresObjListe beruecksichtigt wird. Es sollen aber alle
243 // "Titelobjekte" hier beruecksichtigt werden (Paste aus Clipboard usw.)
244 SfxStyleSheet
* pSheet
= GetStyleSheetForPresObj(PRESOBJ_TITLE
);
247 pObj
->SetStyleSheet(pSheet
, TRUE
);
251 SfxStyleSheet
* pSheet
= GetStyleSheetForPresObj(GetPresObjKind(pObj
));
254 pObj
->SetStyleSheet(pSheet
, TRUE
);
258 for (ULONG i
= 0; i
< aReplList
.Count(); i
++)
260 delete (StyleReplaceData
*) aReplList
.GetObject(i
);
265 /*************************************************************************
267 |* das Gliederungstextobjekt bei den Vorlagen fuer die Gliederungsebenen
270 \************************************************************************/
272 void SdPage::EndListenOutlineText()
274 SdrObject
* pOutlineTextObj
= GetPresObj(PRESOBJ_OUTLINE
);
278 SdStyleSheetPool
* pSPool
= (SdStyleSheetPool
*)pModel
->GetStyleSheetPool();
279 DBG_ASSERT(pSPool
, "StyleSheetPool nicht gefunden");
280 String
aTrueLayoutName(maLayoutName
);
281 aTrueLayoutName
.Erase( aTrueLayoutName
.SearchAscii( SD_LT_SEPARATOR
));
282 List
* pOutlineStyles
= pSPool
->CreateOutlineSheetList(aTrueLayoutName
);
283 for (SfxStyleSheet
* pSheet
= (SfxStyleSheet
*)pOutlineStyles
->First();
285 pSheet
= (SfxStyleSheet
*)pOutlineStyles
->Next())
287 pOutlineTextObj
->EndListening(*pSheet
);
290 delete pOutlineStyles
;
294 /*************************************************************************
296 |* Neues Model setzen
298 \************************************************************************/
300 void SdPage::SetModel(SdrModel
* pNewModel
)
305 FmFormPage::SetModel(pNewModel
);
310 /*************************************************************************
312 |* Ist die Seite read-only?
314 \************************************************************************/
316 bool SdPage::IsReadOnly() const
321 /*************************************************************************
323 |* Beim sfx2::LinkManager anmelden
325 \************************************************************************/
327 void SdPage::ConnectLink()
329 sfx2::LinkManager
* pLinkManager
= pModel
!=NULL
? pModel
->GetLinkManager() : NULL
;
331 if (pLinkManager
&& !mpPageLink
&& maFileName
.Len() && maBookmarkName
.Len() &&
332 mePageKind
==PK_STANDARD
&& !IsMasterPage() &&
333 ( (SdDrawDocument
*) pModel
)->IsNewOrLoadCompleted())
335 /**********************************************************************
337 * Nur Standardseiten duerfen gelinkt sein
338 **********************************************************************/
339 ::sd::DrawDocShell
* pDocSh
= ((SdDrawDocument
*) pModel
)->GetDocSh();
341 if (!pDocSh
|| pDocSh
->GetMedium()->GetOrigURL() != maFileName
)
343 // Keine Links auf Dokument-eigene Seiten!
344 mpPageLink
= new SdPageLink(this, maFileName
, maBookmarkName
);
345 String
aFilterName(SdResId(STR_IMPRESS
));
346 pLinkManager
->InsertFileLink(*mpPageLink
, OBJECT_CLIENT_FILE
,
347 maFileName
, &aFilterName
, &maBookmarkName
);
348 mpPageLink
->Connect();
354 /*************************************************************************
356 |* Beim sfx2::LinkManager abmelden
358 \************************************************************************/
360 void SdPage::DisconnectLink()
362 sfx2::LinkManager
* pLinkManager
= pModel
!=NULL
? pModel
->GetLinkManager() : NULL
;
364 if (pLinkManager
&& mpPageLink
)
366 /**********************************************************************
368 * (Bei Remove wird *pGraphicLink implizit deleted)
369 **********************************************************************/
370 pLinkManager
->Remove(mpPageLink
);
375 /*************************************************************************
379 \************************************************************************/
381 SdPage::SdPage(const SdPage
& rSrcPage
)
382 : FmFormPage(rSrcPage
)
386 mePageKind
= rSrcPage
.mePageKind
;
387 meAutoLayout
= rSrcPage
.meAutoLayout
;
390 while((pObj
= rSrcPage
.maPresentationShapeList
.getNextShape(pObj
)) != 0)
391 InsertPresObj(GetObj(pObj
->GetOrdNum()), rSrcPage
.GetPresObjKind(pObj
));
394 mnTransitionType
= rSrcPage
.mnTransitionType
;
395 mnTransitionSubtype
= rSrcPage
.mnTransitionSubtype
;
396 mbTransitionDirection
= rSrcPage
.mbTransitionDirection
;
397 mnTransitionFadeColor
= rSrcPage
.mnTransitionFadeColor
;
398 mfTransitionDuration
= rSrcPage
.mfTransitionDuration
;
399 mePresChange
= rSrcPage
.mePresChange
;
400 mnTime
= rSrcPage
.mnTime
;
401 mbSoundOn
= rSrcPage
.mbSoundOn
;
402 mbExcluded
= rSrcPage
.mbExcluded
;
404 maLayoutName
= rSrcPage
.maLayoutName
;
405 maSoundFile
= rSrcPage
.maSoundFile
;
406 mbLoopSound
= rSrcPage
.mbLoopSound
;
407 mbStopSound
= rSrcPage
.mbStopSound
;
408 maCreatedPageName
= String();
409 maFileName
= rSrcPage
.maFileName
;
410 maBookmarkName
= rSrcPage
.maBookmarkName
;
411 mbScaleObjects
= rSrcPage
.mbScaleObjects
;
412 mbBackgroundFullSize
= rSrcPage
.mbBackgroundFullSize
;
413 meCharSet
= rSrcPage
.meCharSet
;
414 mnPaperBin
= rSrcPage
.mnPaperBin
;
415 meOrientation
= rSrcPage
.meOrientation
;
418 setHeaderFooterSettings( rSrcPage
.getHeaderFooterSettings() );
420 mpPageLink
= NULL
; // Wird beim Einfuegen ueber ConnectLink() gesetzt
425 /*************************************************************************
429 \************************************************************************/
431 SdrPage
* SdPage::Clone() const
436 SdrPage
* SdPage::Clone(SdrModel
* pNewModel
) const
438 DBG_ASSERT( pNewModel
== 0, "sd::SdPage::Clone(), new page ignored, please check code! CL" );
441 SdPage
* pNewPage
= new SdPage(*this);
443 cloneAnimations( *pNewPage
);
445 // fix user calls for duplicated slide
446 SdrObjListIter
aSourceIter( *this, IM_DEEPWITHGROUPS
);
447 SdrObjListIter
aTargetIter( *pNewPage
, IM_DEEPWITHGROUPS
);
449 while( aSourceIter
.IsMore() && aTargetIter
.IsMore() )
451 SdrObject
* pSource
= aSourceIter
.Next();
452 SdrObject
* pTarget
= aTargetIter
.Next();
454 if( pSource
->GetUserCall() )
455 pTarget
->SetUserCall( pNewPage
);
461 /*************************************************************************
463 |* GetTextStyleSheetForObject
465 \************************************************************************/
468 SfxStyleSheet
* SdPage::GetTextStyleSheetForObject( SdrObject
* pObj
) const
470 const PresObjKind eKind
= ((SdPage
*)this)->GetPresObjKind(pObj
);
471 if( eKind
!= PRESOBJ_NONE
)
473 return ((SdPage
*)this)->GetStyleSheetForPresObj(eKind
);
476 return FmFormPage::GetTextStyleSheetForObject( pObj
);
479 SfxItemSet
* SdPage::getOrCreateItems()
481 if( mpItems
== NULL
)
482 mpItems
= new SfxItemSet( pModel
->GetItemPool(), SDRATTR_XMLATTRIBUTES
, SDRATTR_XMLATTRIBUTES
);
488 sal_Bool
SdPage::setAlienAttributes( const com::sun::star::uno::Any
& rAttributes
)
490 SfxItemSet
* pSet
= getOrCreateItems();
492 SvXMLAttrContainerItem
aAlienAttributes( SDRATTR_XMLATTRIBUTES
);
493 if( aAlienAttributes
.PutValue( rAttributes
, 0 ) )
495 pSet
->Put( aAlienAttributes
);
502 void SdPage::getAlienAttributes( com::sun::star::uno::Any
& rAttributes
)
504 const SfxPoolItem
* pItem
;
506 if( (mpItems
== NULL
) || ( SFX_ITEM_SET
!= mpItems
->GetItemState( SDRATTR_XMLATTRIBUTES
, sal_False
, &pItem
) ) )
508 SvXMLAttrContainerItem aAlienAttributes
;
509 aAlienAttributes
.QueryValue( rAttributes
, 0 );
513 ((SvXMLAttrContainerItem
*)pItem
)->QueryValue( rAttributes
, 0 );
517 void SdPage::RemoveEmptyPresentationObjects()
519 SdrObjListIter
aShapeIter( *this, IM_DEEPWITHGROUPS
);
522 for( pShape
= aShapeIter
.Next(); pShape
; pShape
= aShapeIter
.Next() )
524 if( pShape
&& pShape
->IsEmptyPresObj() )
526 RemoveObject( pShape
->GetOrdNum() );
527 SdrObject::Free( pShape
);
533 sal_Int16
SdPage::getTransitionType (void) const
535 return mnTransitionType
;
538 void SdPage::setTransitionType( sal_Int16 nTransitionType
)
540 mnTransitionType
= nTransitionType
;
544 sal_Int16
SdPage::getTransitionSubtype (void) const
546 return mnTransitionSubtype
;
549 void SdPage::setTransitionSubtype ( sal_Int16 nTransitionSubtype
)
551 mnTransitionSubtype
= nTransitionSubtype
;
555 sal_Bool
SdPage::getTransitionDirection (void) const
557 return mbTransitionDirection
;
560 void SdPage::setTransitionDirection ( sal_Bool bTransitionbDirection
)
562 mbTransitionDirection
= bTransitionbDirection
;
566 sal_Int32
SdPage::getTransitionFadeColor (void) const
568 return mnTransitionFadeColor
;
571 void SdPage::setTransitionFadeColor ( sal_Int32 nTransitionFadeColor
)
573 mnTransitionFadeColor
= nTransitionFadeColor
;
577 double SdPage::getTransitionDuration (void) const
579 return mfTransitionDuration
;
582 void SdPage::setTransitionDuration ( double fTranstionDuration
)
584 mfTransitionDuration
= fTranstionDuration
;
589 extern void createAnnotation( Reference
< XAnnotation
>& xAnnotation
, SdPage
* pPage
);
590 extern SdrUndoAction
* CreateUndoInsertOrRemoveAnnotation( const Reference
< XAnnotation
>& xAnnotation
, bool bInsert
);
593 void SdPage::createAnnotation( ::com::sun::star::uno::Reference
< ::com::sun::star::office::XAnnotation
>& xAnnotation
)
595 sd::createAnnotation( xAnnotation
, this );
598 void SdPage::addAnnotation( const Reference
< XAnnotation
>& xAnnotation
, int nIndex
)
600 if( (nIndex
== -1) || (nIndex
> (int)maAnnotations
.size()) )
602 maAnnotations
.push_back( xAnnotation
);
606 maAnnotations
.insert( maAnnotations
.begin() + nIndex
, xAnnotation
);
609 if( pModel
&& pModel
->IsUndoEnabled() )
611 SdrUndoAction
* pAction
= CreateUndoInsertOrRemoveAnnotation( xAnnotation
, true );
613 pModel
->AddUndo( pAction
);
620 pModel
->SetChanged();
621 Reference
< XInterface
> xSource( xAnnotation
, UNO_QUERY
);
622 NotifyDocumentEvent( static_cast< SdDrawDocument
* >( pModel
), rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnAnnotationInserted" ) ), xSource
);
626 void SdPage::removeAnnotation( const Reference
< XAnnotation
>& xAnnotation
)
628 if( pModel
&& pModel
->IsUndoEnabled() )
630 SdrUndoAction
* pAction
= CreateUndoInsertOrRemoveAnnotation( xAnnotation
, false );
632 pModel
->AddUndo( pAction
);
635 AnnotationVector::iterator iter
= std::find( maAnnotations
.begin(), maAnnotations
.end(), xAnnotation
);
636 if( iter
!= maAnnotations
.end() )
637 maAnnotations
.erase( iter
);
641 pModel
->SetChanged();
642 Reference
< XInterface
> xSource( xAnnotation
, UNO_QUERY
);
643 NotifyDocumentEvent( static_cast< SdDrawDocument
* >( pModel
), rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnAnnotationRemoved" ) ), xSource
);
647 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */