1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdpage2.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
33 #include <sfx2/docfile.hxx>
34 #include <vcl/svapp.hxx>
35 #include <svx/outliner.hxx>
37 #include <svx/linkmgr.hxx>
39 #include <svx/svdotext.hxx>
40 #include <tools/urlobj.hxx>
41 #include <svx/outlobj.hxx>
42 #include <svtools/urihelper.hxx>
43 #include <svx/xmlcnitm.hxx>
44 #include <svx/svditer.hxx>
45 #include <tools/list.hxx>
47 #include "sdresid.hxx"
51 #include "drawdoc.hxx"
52 #include "stlpool.hxx"
53 //#include "sdiocmpt.hxx"
55 //#include "strmname.h"
56 #include "anminfo.hxx"
58 #include "../ui/inc/strings.hrc"
59 #include "../ui/inc/DrawDocShell.hxx"
62 #include <tools/tenccvt.hxx>
63 #include <svtools/itemset.hxx>
66 using namespace ::com::sun::star
;
67 using namespace ::com::sun::star::uno
;
68 using namespace ::com::sun::star::office
;
70 extern void NotifyDocumentEvent( SdDrawDocument
* pDocument
, const rtl::OUString
& rEventName
, const Reference
< XInterface
>& xSource
);
72 /*************************************************************************
74 |* SetPresentationLayout, setzt: Layoutnamen, Masterpage-Verkn�pfung und
75 |* Vorlagen fuer Praesentationsobjekte
77 |* Vorraussetzungen: - Die Seite muss bereits das richtige Model kennen!
78 |* - Die entsprechende Masterpage muss bereits im Model sein.
79 |* - Die entsprechenden StyleSheets muessen bereits im
80 |* im StyleSheetPool sein.
82 |* bReplaceStyleSheets = TRUE : Benannte StyleSheets werden ausgetauscht
83 |* FALSE: Alle StyleSheets werden neu zugewiesen
85 |* bSetMasterPage = TRUE : MasterPage suchen und zuweisen
87 |* bReverseOrder = FALSE: MasterPages von vorn nach hinten suchen
88 |* TRUE : MasterPages von hinten nach vorn suchen (fuer Undo-Action)
90 \************************************************************************/
92 void SdPage::SetPresentationLayout(const String
& rLayoutName
,
93 BOOL bReplaceStyleSheets
,
97 /*********************************************************************
98 |* Layoutname der Seite
99 \********************************************************************/
100 String
aOldLayoutName(maLayoutName
); // merken
101 maLayoutName
= rLayoutName
;
102 maLayoutName
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( SD_LT_SEPARATOR
));
103 maLayoutName
+= String(SdResId(STR_LAYOUT_OUTLINE
));
105 /*********************************************************************
106 |* ggf. Masterpage suchen und setzen
107 \********************************************************************/
108 if (bSetMasterPage
&& !IsMasterPage())
111 SdPage
* pFoundMaster
= 0;
113 USHORT nMasterCount
= pModel
->GetMasterPageCount();
117 for ( nMaster
= 0; nMaster
< nMasterCount
; nMaster
++ )
119 pMaster
= static_cast<SdPage
*>(pModel
->GetMasterPage(nMaster
));
120 if (pMaster
->GetPageKind() == mePageKind
&& pMaster
->GetLayoutName() == maLayoutName
)
122 pFoundMaster
= pMaster
;
129 for ( nMaster
= nMasterCount
; nMaster
> 0; nMaster
-- )
131 pMaster
= static_cast<SdPage
*>(pModel
->GetMasterPage(nMaster
- 1));
132 if (pMaster
->GetPageKind() == mePageKind
&& pMaster
->GetLayoutName() == maLayoutName
)
134 pFoundMaster
= pMaster
;
140 DBG_ASSERT(pFoundMaster
, "Masterpage for presentation layout not found!");
142 // this should never happen, but we play failsafe here
143 if( pFoundMaster
== 0 )
144 pFoundMaster
= static_cast< SdDrawDocument
*>(pModel
)->GetSdPage( 0, mePageKind
);
147 TRG_SetMasterPage(*pFoundMaster
);
150 /*********************************************************************
151 |* Vorlagen fuer Praesentationsobjekte
152 \********************************************************************/
154 // - Vorlagenzeigern fuer Gliederungstextobjekt (alte und neue Vorlagen)
155 // -Replacedaten fuer OutlinerParaObject
157 List aOldOutlineStyles
;
159 BOOL bListsFilled
= FALSE
;
161 ULONG nObjCount
= GetObjCount();
163 for (ULONG nObj
= 0; nObj
< nObjCount
; nObj
++)
165 SdrTextObj
* pObj
= (SdrTextObj
*) GetObj(nObj
);
167 if (pObj
->GetObjInventor() == SdrInventor
&&
168 pObj
->GetObjIdentifier() == OBJ_OUTLINETEXT
)
170 if (!bListsFilled
|| !bReplaceStyleSheets
)
174 SfxStyleSheetBase
* pSheet
= NULL
;
175 SfxStyleSheetBasePool
* pStShPool
= pModel
->GetStyleSheetPool();
177 for (sal_Int16 i
= -1; i
< 9; i
++)
179 aFullName
= maLayoutName
;
180 aOldFullName
= aOldLayoutName
;
181 aFullName
+= sal_Unicode( ' ' );
182 aFullName
+= String::CreateFromInt32( (sal_Int32
) (i
<= 0 ) ? 1 : i
+ 1);
183 aOldFullName
+= sal_Unicode( ' ' );
184 aOldFullName
+= String::CreateFromInt32( (sal_Int32
) (i
<= 0 ) ? 1 : i
+ 1 );
186 pSheet
= pStShPool
->Find(aOldFullName
, SD_STYLE_FAMILY_MASTERPAGE
);
187 DBG_ASSERT(pSheet
, "alte Gliederungsvorlage nicht gefunden");
188 aOldOutlineStyles
.Insert(pSheet
, LIST_APPEND
);
190 pSheet
= pStShPool
->Find(aFullName
, SD_STYLE_FAMILY_MASTERPAGE
);
191 DBG_ASSERT(pSheet
, "neue Gliederungsvorlage nicht gefunden");
192 aOutlineStyles
.Insert(pSheet
, LIST_APPEND
);
194 if (bReplaceStyleSheets
&& pSheet
)
196 // Replace anstatt Set
197 StyleReplaceData
* pReplData
= new StyleReplaceData
;
198 pReplData
->nNewFamily
= pSheet
->GetFamily();
199 pReplData
->nFamily
= pSheet
->GetFamily();
200 pReplData
->aNewName
= aFullName
;
201 pReplData
->aName
= aOldFullName
;
202 aReplList
.Insert(pReplData
, LIST_APPEND
);
206 OutlinerParaObject
* pOPO
= ((SdrTextObj
*)pObj
)->GetOutlinerParaObject();
209 pOPO
->SetStyleSheets( i
, aFullName
, SD_STYLE_FAMILY_MASTERPAGE
);
216 SfxStyleSheet
* pSheet
= (SfxStyleSheet
*)aOutlineStyles
.First();
217 SfxStyleSheet
* pOldSheet
= (SfxStyleSheet
*)aOldOutlineStyles
.First();
220 if (pSheet
!= pOldSheet
)
222 pObj
->EndListening(*pOldSheet
);
224 if (!pObj
->IsListening(*pSheet
))
225 pObj
->StartListening(*pSheet
);
228 pSheet
= (SfxStyleSheet
*)aOutlineStyles
.Next();
229 pOldSheet
= (SfxStyleSheet
*)aOldOutlineStyles
.Next();
232 OutlinerParaObject
* pOPO
= ((SdrTextObj
*)pObj
)->GetOutlinerParaObject();
233 if ( bReplaceStyleSheets
&& pOPO
)
235 StyleReplaceData
* pReplData
= (StyleReplaceData
*) aReplList
.First();
239 pOPO
->ChangeStyleSheets( pReplData
->aName
, pReplData
->nFamily
, pReplData
->aNewName
, pReplData
->nNewFamily
);
240 pReplData
= (StyleReplaceData
*) aReplList
.Next();
244 else if (pObj
->GetObjInventor() == SdrInventor
&&
245 pObj
->GetObjIdentifier() == OBJ_TITLETEXT
)
247 // PresObjKind nicht ueber GetPresObjKind() holen, da dort nur
248 // die PresObjListe beruecksichtigt wird. Es sollen aber alle
249 // "Titelobjekte" hier beruecksichtigt werden (Paste aus Clipboard usw.)
250 SfxStyleSheet
* pSheet
= GetStyleSheetForPresObj(PRESOBJ_TITLE
);
253 pObj
->SetStyleSheet(pSheet
, TRUE
);
257 SfxStyleSheet
* pSheet
= GetStyleSheetForPresObj(GetPresObjKind(pObj
));
260 pObj
->SetStyleSheet(pSheet
, TRUE
);
264 for (ULONG i
= 0; i
< aReplList
.Count(); i
++)
266 delete (StyleReplaceData
*) aReplList
.GetObject(i
);
271 /*************************************************************************
273 |* das Gliederungstextobjekt bei den Vorlagen fuer die Gliederungsebenen
276 \************************************************************************/
278 void SdPage::EndListenOutlineText()
280 SdrObject
* pOutlineTextObj
= GetPresObj(PRESOBJ_OUTLINE
);
284 SdStyleSheetPool
* pSPool
= (SdStyleSheetPool
*)pModel
->GetStyleSheetPool();
285 DBG_ASSERT(pSPool
, "StyleSheetPool nicht gefunden");
286 String
aTrueLayoutName(maLayoutName
);
287 aTrueLayoutName
.Erase( aTrueLayoutName
.SearchAscii( SD_LT_SEPARATOR
));
288 List
* pOutlineStyles
= pSPool
->CreateOutlineSheetList(aTrueLayoutName
);
289 for (SfxStyleSheet
* pSheet
= (SfxStyleSheet
*)pOutlineStyles
->First();
291 pSheet
= (SfxStyleSheet
*)pOutlineStyles
->Next())
293 pOutlineTextObj
->EndListening(*pSheet
);
296 delete pOutlineStyles
;
300 /*************************************************************************
302 |* Neues Model setzen
304 \************************************************************************/
306 void SdPage::SetModel(SdrModel
* pNewModel
)
311 FmFormPage::SetModel(pNewModel
);
316 /*************************************************************************
318 |* Ist die Seite read-only?
320 \************************************************************************/
322 FASTBOOL
SdPage::IsReadOnly() const
327 /*************************************************************************
329 |* Beim LinkManager anmelden
331 \************************************************************************/
333 void SdPage::ConnectLink()
335 SvxLinkManager
* pLinkManager
= pModel
!=NULL
? pModel
->GetLinkManager() : NULL
;
337 if (pLinkManager
&& !mpPageLink
&& maFileName
.Len() && maBookmarkName
.Len() &&
338 mePageKind
==PK_STANDARD
&& !IsMasterPage() &&
339 ( (SdDrawDocument
*) pModel
)->IsNewOrLoadCompleted())
341 /**********************************************************************
343 * Nur Standardseiten duerfen gelinkt sein
344 **********************************************************************/
345 ::sd::DrawDocShell
* pDocSh
= ((SdDrawDocument
*) pModel
)->GetDocSh();
347 if (!pDocSh
|| pDocSh
->GetMedium()->GetOrigURL() != maFileName
)
349 // Keine Links auf Dokument-eigene Seiten!
350 mpPageLink
= new SdPageLink(this, maFileName
, maBookmarkName
);
351 String
aFilterName(SdResId(STR_IMPRESS
));
352 pLinkManager
->InsertFileLink(*mpPageLink
, OBJECT_CLIENT_FILE
,
353 maFileName
, &aFilterName
, &maBookmarkName
);
354 mpPageLink
->Connect();
360 /*************************************************************************
362 |* Beim LinkManager abmelden
364 \************************************************************************/
366 void SdPage::DisconnectLink()
368 SvxLinkManager
* pLinkManager
= pModel
!=NULL
? pModel
->GetLinkManager() : NULL
;
370 if (pLinkManager
&& mpPageLink
)
372 /**********************************************************************
374 * (Bei Remove wird *pGraphicLink implizit deleted)
375 **********************************************************************/
376 pLinkManager
->Remove(mpPageLink
);
381 /*************************************************************************
385 \************************************************************************/
387 SdPage::SdPage(const SdPage
& rSrcPage
)
388 : FmFormPage(rSrcPage
)
392 mePageKind
= rSrcPage
.mePageKind
;
393 meAutoLayout
= rSrcPage
.meAutoLayout
;
396 while((pObj
= rSrcPage
.maPresentationShapeList
.getNextShape(pObj
)) != 0)
397 InsertPresObj(GetObj(pObj
->GetOrdNum()), rSrcPage
.GetPresObjKind(pObj
));
400 mnTransitionType
= rSrcPage
.mnTransitionType
;
401 mnTransitionSubtype
= rSrcPage
.mnTransitionSubtype
;
402 mbTransitionDirection
= rSrcPage
.mbTransitionDirection
;
403 mnTransitionFadeColor
= rSrcPage
.mnTransitionFadeColor
;
404 mfTransitionDuration
= rSrcPage
.mfTransitionDuration
;
405 mePresChange
= rSrcPage
.mePresChange
;
406 mnTime
= rSrcPage
.mnTime
;
407 mbSoundOn
= rSrcPage
.mbSoundOn
;
408 mbExcluded
= rSrcPage
.mbExcluded
;
410 maLayoutName
= rSrcPage
.maLayoutName
;
411 maSoundFile
= rSrcPage
.maSoundFile
;
412 mbLoopSound
= rSrcPage
.mbLoopSound
;
413 mbStopSound
= rSrcPage
.mbStopSound
;
414 maCreatedPageName
= String();
415 maFileName
= rSrcPage
.maFileName
;
416 maBookmarkName
= rSrcPage
.maBookmarkName
;
417 mbScaleObjects
= rSrcPage
.mbScaleObjects
;
418 mbBackgroundFullSize
= rSrcPage
.mbBackgroundFullSize
;
419 meCharSet
= rSrcPage
.meCharSet
;
420 mnPaperBin
= rSrcPage
.mnPaperBin
;
421 meOrientation
= rSrcPage
.meOrientation
;
424 setHeaderFooterSettings( rSrcPage
.getHeaderFooterSettings() );
426 mpPageLink
= NULL
; // Wird beim Einfuegen ueber ConnectLink() gesetzt
431 /*************************************************************************
435 \************************************************************************/
437 SdrPage
* SdPage::Clone() const
442 SdrPage
* SdPage::Clone(SdrModel
* pNewModel
) const
444 DBG_ASSERT( pNewModel
== 0, "sd::SdPage::Clone(), new page ignored, please check code! CL" );
447 SdPage
* pNewPage
= new SdPage(*this);
449 cloneAnimations( *pNewPage
);
451 // fix user calls for duplicated slide
452 SdrObjListIter
aSourceIter( *this, IM_DEEPWITHGROUPS
);
453 SdrObjListIter
aTargetIter( *pNewPage
, IM_DEEPWITHGROUPS
);
455 while( aSourceIter
.IsMore() && aTargetIter
.IsMore() )
457 SdrObject
* pSource
= aSourceIter
.Next();
458 SdrObject
* pTarget
= aTargetIter
.Next();
460 if( pSource
->GetUserCall() )
461 pTarget
->SetUserCall( pNewPage
);
467 /*************************************************************************
469 |* GetTextStyleSheetForObject
471 \************************************************************************/
474 SfxStyleSheet
* SdPage::GetTextStyleSheetForObject( SdrObject
* pObj
) const
476 const PresObjKind eKind
= ((SdPage
*)this)->GetPresObjKind(pObj
);
477 if( eKind
!= PRESOBJ_NONE
)
479 return ((SdPage
*)this)->GetStyleSheetForPresObj(eKind
);
482 return FmFormPage::GetTextStyleSheetForObject( pObj
);
485 SfxItemSet
* SdPage::getOrCreateItems()
487 if( mpItems
== NULL
)
488 mpItems
= new SfxItemSet( pModel
->GetItemPool(), SDRATTR_XMLATTRIBUTES
, SDRATTR_XMLATTRIBUTES
);
494 sal_Bool
SdPage::setAlienAttributes( const com::sun::star::uno::Any
& rAttributes
)
496 SfxItemSet
* pSet
= getOrCreateItems();
498 SvXMLAttrContainerItem
aAlienAttributes( SDRATTR_XMLATTRIBUTES
);
499 if( aAlienAttributes
.PutValue( rAttributes
, 0 ) )
501 pSet
->Put( aAlienAttributes
);
508 void SdPage::getAlienAttributes( com::sun::star::uno::Any
& rAttributes
)
510 const SfxPoolItem
* pItem
;
512 if( (mpItems
== NULL
) || ( SFX_ITEM_SET
!= mpItems
->GetItemState( SDRATTR_XMLATTRIBUTES
, sal_False
, &pItem
) ) )
514 SvXMLAttrContainerItem aAlienAttributes
;
515 aAlienAttributes
.QueryValue( rAttributes
, 0 );
519 ((SvXMLAttrContainerItem
*)pItem
)->QueryValue( rAttributes
, 0 );
523 void SdPage::RemoveEmptyPresentationObjects()
525 SdrObjListIter
aShapeIter( *this, IM_DEEPWITHGROUPS
);
528 for( pShape
= aShapeIter
.Next(); pShape
; pShape
= aShapeIter
.Next() )
530 if( pShape
&& pShape
->IsEmptyPresObj() )
532 RemoveObject( pShape
->GetOrdNum() );
533 SdrObject::Free( pShape
);
539 sal_Int16
SdPage::getTransitionType (void) const
541 return mnTransitionType
;
544 void SdPage::setTransitionType( sal_Int16 nTransitionType
)
546 mnTransitionType
= nTransitionType
;
550 sal_Int16
SdPage::getTransitionSubtype (void) const
552 return mnTransitionSubtype
;
555 void SdPage::setTransitionSubtype ( sal_Int16 nTransitionSubtype
)
557 mnTransitionSubtype
= nTransitionSubtype
;
561 sal_Bool
SdPage::getTransitionDirection (void) const
563 return mbTransitionDirection
;
566 void SdPage::setTransitionDirection ( sal_Bool bTransitionbDirection
)
568 mbTransitionDirection
= bTransitionbDirection
;
572 sal_Int32
SdPage::getTransitionFadeColor (void) const
574 return mnTransitionFadeColor
;
577 void SdPage::setTransitionFadeColor ( sal_Int32 nTransitionFadeColor
)
579 mnTransitionFadeColor
= nTransitionFadeColor
;
583 double SdPage::getTransitionDuration (void) const
585 return mfTransitionDuration
;
588 void SdPage::setTransitionDuration ( double fTranstionDuration
)
590 mfTransitionDuration
= fTranstionDuration
;
595 extern void createAnnotation( Reference
< XAnnotation
>& xAnnotation
, SdPage
* pPage
);
596 extern SdrUndoAction
* CreateUndoInsertOrRemoveAnnotation( const Reference
< XAnnotation
>& xAnnotation
, bool bInsert
);
599 void SdPage::createAnnotation( ::com::sun::star::uno::Reference
< ::com::sun::star::office::XAnnotation
>& xAnnotation
)
601 sd::createAnnotation( xAnnotation
, this );
604 void SdPage::addAnnotation( const Reference
< XAnnotation
>& xAnnotation
, int nIndex
)
606 if( (nIndex
== -1) || (nIndex
> (int)maAnnotations
.size()) )
608 maAnnotations
.push_back( xAnnotation
);
612 maAnnotations
.insert( maAnnotations
.begin() + nIndex
, xAnnotation
);
615 if( pModel
&& pModel
->IsUndoEnabled() )
617 SdrUndoAction
* pAction
= CreateUndoInsertOrRemoveAnnotation( xAnnotation
, true );
619 pModel
->AddUndo( pAction
);
626 pModel
->SetChanged();
627 Reference
< XInterface
> xSource( xAnnotation
, UNO_QUERY
);
628 NotifyDocumentEvent( static_cast< SdDrawDocument
* >( pModel
), rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnAnnotationInserted" ) ), xSource
);
632 void SdPage::removeAnnotation( const Reference
< XAnnotation
>& xAnnotation
)
634 if( pModel
&& pModel
->IsUndoEnabled() )
636 SdrUndoAction
* pAction
= CreateUndoInsertOrRemoveAnnotation( xAnnotation
, false );
638 pModel
->AddUndo( pAction
);
641 AnnotationVector::iterator iter
= std::find( maAnnotations
.begin(), maAnnotations
.end(), xAnnotation
);
642 if( iter
!= maAnnotations
.end() )
643 maAnnotations
.erase( iter
);
647 pModel
->SetChanged();
648 Reference
< XInterface
> xSource( xAnnotation
, UNO_QUERY
);
649 NotifyDocumentEvent( static_cast< SdDrawDocument
* >( pModel
), rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnAnnotationRemoved" ) ), xSource
);