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
;
68 /*************************************************************************
70 |* SetPresentationLayout, setzt: Layoutnamen, Masterpage-Verkn�pfung und
71 |* Vorlagen fuer Praesentationsobjekte
73 |* Vorraussetzungen: - Die Seite muss bereits das richtige Model kennen!
74 |* - Die entsprechende Masterpage muss bereits im Model sein.
75 |* - Die entsprechenden StyleSheets muessen bereits im
76 |* im StyleSheetPool sein.
78 |* bReplaceStyleSheets = TRUE : Benannte StyleSheets werden ausgetauscht
79 |* FALSE: Alle StyleSheets werden neu zugewiesen
81 |* bSetMasterPage = TRUE : MasterPage suchen und zuweisen
83 |* bReverseOrder = FALSE: MasterPages von vorn nach hinten suchen
84 |* TRUE : MasterPages von hinten nach vorn suchen (fuer Undo-Action)
86 \************************************************************************/
88 void SdPage::SetPresentationLayout(const String
& rLayoutName
,
89 BOOL bReplaceStyleSheets
,
93 /*********************************************************************
94 |* Layoutname der Seite
95 \********************************************************************/
96 String
aOldLayoutName(maLayoutName
); // merken
97 maLayoutName
= rLayoutName
;
98 maLayoutName
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( SD_LT_SEPARATOR
));
99 maLayoutName
+= String(SdResId(STR_LAYOUT_OUTLINE
));
101 /*********************************************************************
102 |* ggf. Masterpage suchen und setzen
103 \********************************************************************/
104 if (bSetMasterPage
&& !IsMasterPage())
107 SdPage
* pFoundMaster
= 0;
109 USHORT nMasterCount
= pModel
->GetMasterPageCount();
113 for ( nMaster
= 0; nMaster
< nMasterCount
; nMaster
++ )
115 pMaster
= static_cast<SdPage
*>(pModel
->GetMasterPage(nMaster
));
116 if (pMaster
->GetPageKind() == mePageKind
&& pMaster
->GetLayoutName() == maLayoutName
)
118 pFoundMaster
= pMaster
;
125 for ( nMaster
= nMasterCount
; nMaster
> 0; nMaster
-- )
127 pMaster
= static_cast<SdPage
*>(pModel
->GetMasterPage(nMaster
- 1));
128 if (pMaster
->GetPageKind() == mePageKind
&& pMaster
->GetLayoutName() == maLayoutName
)
130 pFoundMaster
= pMaster
;
136 DBG_ASSERT(pFoundMaster
, "Masterpage for presentation layout not found!");
138 // this should never happen, but we play failsafe here
139 if( pFoundMaster
== 0 )
140 pFoundMaster
= static_cast< SdDrawDocument
*>(pModel
)->GetSdPage( 0, mePageKind
);
143 TRG_SetMasterPage(*pFoundMaster
);
146 /*********************************************************************
147 |* Vorlagen fuer Praesentationsobjekte
148 \********************************************************************/
150 // - Vorlagenzeigern fuer Gliederungstextobjekt (alte und neue Vorlagen)
151 // -Replacedaten fuer OutlinerParaObject
153 List aOldOutlineStyles
;
155 BOOL bListsFilled
= FALSE
;
157 ULONG nObjCount
= GetObjCount();
159 for (ULONG nObj
= 0; nObj
< nObjCount
; nObj
++)
161 SdrTextObj
* pObj
= (SdrTextObj
*) GetObj(nObj
);
163 if (pObj
->GetObjInventor() == SdrInventor
&&
164 pObj
->GetObjIdentifier() == OBJ_OUTLINETEXT
)
166 if (!bListsFilled
|| !bReplaceStyleSheets
)
170 SfxStyleSheetBase
* pSheet
= NULL
;
171 SfxStyleSheetBasePool
* pStShPool
= pModel
->GetStyleSheetPool();
173 for (sal_Int16 i
= -1; i
< 9; i
++)
175 aFullName
= maLayoutName
;
176 aOldFullName
= aOldLayoutName
;
177 aFullName
+= sal_Unicode( ' ' );
178 aFullName
+= String::CreateFromInt32( (sal_Int32
) (i
<= 0 ) ? 1 : i
+ 1);
179 aOldFullName
+= sal_Unicode( ' ' );
180 aOldFullName
+= String::CreateFromInt32( (sal_Int32
) (i
<= 0 ) ? 1 : i
+ 1 );
182 pSheet
= pStShPool
->Find(aOldFullName
, SD_STYLE_FAMILY_MASTERPAGE
);
183 DBG_ASSERT(pSheet
, "alte Gliederungsvorlage nicht gefunden");
184 aOldOutlineStyles
.Insert(pSheet
, LIST_APPEND
);
186 pSheet
= pStShPool
->Find(aFullName
, SD_STYLE_FAMILY_MASTERPAGE
);
187 DBG_ASSERT(pSheet
, "neue Gliederungsvorlage nicht gefunden");
188 aOutlineStyles
.Insert(pSheet
, LIST_APPEND
);
190 if (bReplaceStyleSheets
&& pSheet
)
192 // Replace anstatt Set
193 StyleReplaceData
* pReplData
= new StyleReplaceData
;
194 pReplData
->nNewFamily
= pSheet
->GetFamily();
195 pReplData
->nFamily
= pSheet
->GetFamily();
196 pReplData
->aNewName
= aFullName
;
197 pReplData
->aName
= aOldFullName
;
198 aReplList
.Insert(pReplData
, LIST_APPEND
);
202 OutlinerParaObject
* pOPO
= ((SdrTextObj
*)pObj
)->GetOutlinerParaObject();
205 pOPO
->SetStyleSheets( i
, aFullName
, SD_STYLE_FAMILY_MASTERPAGE
);
212 SfxStyleSheet
* pSheet
= (SfxStyleSheet
*)aOutlineStyles
.First();
213 SfxStyleSheet
* pOldSheet
= (SfxStyleSheet
*)aOldOutlineStyles
.First();
216 if (pSheet
!= pOldSheet
)
218 pObj
->EndListening(*pOldSheet
);
220 if (!pObj
->IsListening(*pSheet
))
221 pObj
->StartListening(*pSheet
);
224 pSheet
= (SfxStyleSheet
*)aOutlineStyles
.Next();
225 pOldSheet
= (SfxStyleSheet
*)aOldOutlineStyles
.Next();
228 OutlinerParaObject
* pOPO
= ((SdrTextObj
*)pObj
)->GetOutlinerParaObject();
229 if ( bReplaceStyleSheets
&& pOPO
)
231 StyleReplaceData
* pReplData
= (StyleReplaceData
*) aReplList
.First();
235 pOPO
->ChangeStyleSheets( pReplData
->aName
, pReplData
->nFamily
, pReplData
->aNewName
, pReplData
->nNewFamily
);
236 pReplData
= (StyleReplaceData
*) aReplList
.Next();
240 else if (pObj
->GetObjInventor() == SdrInventor
&&
241 pObj
->GetObjIdentifier() == OBJ_TITLETEXT
)
243 // PresObjKind nicht ueber GetPresObjKind() holen, da dort nur
244 // die PresObjListe beruecksichtigt wird. Es sollen aber alle
245 // "Titelobjekte" hier beruecksichtigt werden (Paste aus Clipboard usw.)
246 SfxStyleSheet
* pSheet
= GetStyleSheetForPresObj(PRESOBJ_TITLE
);
249 pObj
->SetStyleSheet(pSheet
, TRUE
);
253 SfxStyleSheet
* pSheet
= GetStyleSheetForPresObj(GetPresObjKind(pObj
));
256 pObj
->SetStyleSheet(pSheet
, TRUE
);
260 for (ULONG i
= 0; i
< aReplList
.Count(); i
++)
262 delete (StyleReplaceData
*) aReplList
.GetObject(i
);
267 /*************************************************************************
269 |* das Gliederungstextobjekt bei den Vorlagen fuer die Gliederungsebenen
272 \************************************************************************/
274 void SdPage::EndListenOutlineText()
276 SdrObject
* pOutlineTextObj
= GetPresObj(PRESOBJ_OUTLINE
);
280 SdStyleSheetPool
* pSPool
= (SdStyleSheetPool
*)pModel
->GetStyleSheetPool();
281 DBG_ASSERT(pSPool
, "StyleSheetPool nicht gefunden");
282 String
aTrueLayoutName(maLayoutName
);
283 aTrueLayoutName
.Erase( aTrueLayoutName
.SearchAscii( SD_LT_SEPARATOR
));
284 List
* pOutlineStyles
= pSPool
->CreateOutlineSheetList(aTrueLayoutName
);
285 for (SfxStyleSheet
* pSheet
= (SfxStyleSheet
*)pOutlineStyles
->First();
287 pSheet
= (SfxStyleSheet
*)pOutlineStyles
->Next())
289 pOutlineTextObj
->EndListening(*pSheet
);
292 delete pOutlineStyles
;
296 /*************************************************************************
298 |* Neues Model setzen
300 \************************************************************************/
302 void SdPage::SetModel(SdrModel
* pNewModel
)
307 FmFormPage::SetModel(pNewModel
);
312 /*************************************************************************
314 |* Ist die Seite read-only?
316 \************************************************************************/
318 FASTBOOL
SdPage::IsReadOnly() const
323 /*************************************************************************
325 |* Beim LinkManager anmelden
327 \************************************************************************/
329 void SdPage::ConnectLink()
331 SvxLinkManager
* pLinkManager
= pModel
!=NULL
? pModel
->GetLinkManager() : NULL
;
333 if (pLinkManager
&& !mpPageLink
&& maFileName
.Len() && maBookmarkName
.Len() &&
334 mePageKind
==PK_STANDARD
&& !IsMasterPage() &&
335 ( (SdDrawDocument
*) pModel
)->IsNewOrLoadCompleted())
337 /**********************************************************************
339 * Nur Standardseiten duerfen gelinkt sein
340 **********************************************************************/
341 ::sd::DrawDocShell
* pDocSh
= ((SdDrawDocument
*) pModel
)->GetDocSh();
343 if (!pDocSh
|| pDocSh
->GetMedium()->GetOrigURL() != maFileName
)
345 // Keine Links auf Dokument-eigene Seiten!
346 mpPageLink
= new SdPageLink(this, maFileName
, maBookmarkName
);
347 String
aFilterName(SdResId(STR_IMPRESS
));
348 pLinkManager
->InsertFileLink(*mpPageLink
, OBJECT_CLIENT_FILE
,
349 maFileName
, &aFilterName
, &maBookmarkName
);
350 mpPageLink
->Connect();
356 /*************************************************************************
358 |* Beim LinkManager abmelden
360 \************************************************************************/
362 void SdPage::DisconnectLink()
364 SvxLinkManager
* pLinkManager
= pModel
!=NULL
? pModel
->GetLinkManager() : NULL
;
366 if (pLinkManager
&& mpPageLink
)
368 /**********************************************************************
370 * (Bei Remove wird *pGraphicLink implizit deleted)
371 **********************************************************************/
372 pLinkManager
->Remove(mpPageLink
);
377 /*************************************************************************
381 \************************************************************************/
383 SdPage::SdPage(const SdPage
& rSrcPage
)
384 : FmFormPage(rSrcPage
)
388 mePageKind
= rSrcPage
.mePageKind
;
389 meAutoLayout
= rSrcPage
.meAutoLayout
;
392 while((pObj
= rSrcPage
.maPresentationShapeList
.getNextShape(pObj
)) != 0)
393 InsertPresObj(GetObj(pObj
->GetOrdNum()), rSrcPage
.GetPresObjKind(pObj
));
396 mnTransitionType
= rSrcPage
.mnTransitionType
;
397 mnTransitionSubtype
= rSrcPage
.mnTransitionSubtype
;
398 mbTransitionDirection
= rSrcPage
.mbTransitionDirection
;
399 mnTransitionFadeColor
= rSrcPage
.mnTransitionFadeColor
;
400 mfTransitionDuration
= rSrcPage
.mfTransitionDuration
;
401 mePresChange
= rSrcPage
.mePresChange
;
402 mnTime
= rSrcPage
.mnTime
;
403 mbSoundOn
= rSrcPage
.mbSoundOn
;
404 mbExcluded
= rSrcPage
.mbExcluded
;
406 maLayoutName
= rSrcPage
.maLayoutName
;
407 maSoundFile
= rSrcPage
.maSoundFile
;
408 mbLoopSound
= rSrcPage
.mbLoopSound
;
409 mbStopSound
= rSrcPage
.mbStopSound
;
410 maCreatedPageName
= String();
411 maFileName
= rSrcPage
.maFileName
;
412 maBookmarkName
= rSrcPage
.maBookmarkName
;
413 mbScaleObjects
= rSrcPage
.mbScaleObjects
;
414 mbBackgroundFullSize
= rSrcPage
.mbBackgroundFullSize
;
415 meCharSet
= rSrcPage
.meCharSet
;
416 mnPaperBin
= rSrcPage
.mnPaperBin
;
417 meOrientation
= rSrcPage
.meOrientation
;
420 setHeaderFooterSettings( rSrcPage
.getHeaderFooterSettings() );
422 mpPageLink
= NULL
; // Wird beim Einfuegen ueber ConnectLink() gesetzt
427 /*************************************************************************
431 \************************************************************************/
433 SdrPage
* SdPage::Clone() const
438 SdrPage
* SdPage::Clone(SdrModel
* pNewModel
) const
440 DBG_ASSERT( pNewModel
== 0, "sd::SdPage::Clone(), new page ignored, please check code! CL" );
443 SdPage
* pNewPage
= new SdPage(*this);
445 cloneAnimations( *pNewPage
);
447 // fix user calls for duplicated slide
448 SdrObjListIter
aSourceIter( *this, IM_DEEPWITHGROUPS
);
449 SdrObjListIter
aTargetIter( *pNewPage
, IM_DEEPWITHGROUPS
);
451 while( aSourceIter
.IsMore() && aTargetIter
.IsMore() )
453 SdrObject
* pSource
= aSourceIter
.Next();
454 SdrObject
* pTarget
= aTargetIter
.Next();
456 if( pSource
->GetUserCall() )
457 pTarget
->SetUserCall( pNewPage
);
463 /*************************************************************************
465 |* GetTextStyleSheetForObject
467 \************************************************************************/
470 SfxStyleSheet
* SdPage::GetTextStyleSheetForObject( SdrObject
* pObj
) const
472 const PresObjKind eKind
= ((SdPage
*)this)->GetPresObjKind(pObj
);
473 if( eKind
!= PRESOBJ_NONE
)
475 return ((SdPage
*)this)->GetStyleSheetForPresObj(eKind
);
478 return FmFormPage::GetTextStyleSheetForObject( pObj
);
481 SfxItemSet
* SdPage::getOrCreateItems()
483 if( mpItems
== NULL
)
484 mpItems
= new SfxItemSet( pModel
->GetItemPool(), SDRATTR_XMLATTRIBUTES
, SDRATTR_XMLATTRIBUTES
);
490 sal_Bool
SdPage::setAlienAttributes( const com::sun::star::uno::Any
& rAttributes
)
492 SfxItemSet
* pSet
= getOrCreateItems();
494 SvXMLAttrContainerItem
aAlienAttributes( SDRATTR_XMLATTRIBUTES
);
495 if( aAlienAttributes
.PutValue( rAttributes
, 0 ) )
497 pSet
->Put( aAlienAttributes
);
504 void SdPage::getAlienAttributes( com::sun::star::uno::Any
& rAttributes
)
506 const SfxPoolItem
* pItem
;
508 if( (mpItems
== NULL
) || ( SFX_ITEM_SET
!= mpItems
->GetItemState( SDRATTR_XMLATTRIBUTES
, sal_False
, &pItem
) ) )
510 SvXMLAttrContainerItem aAlienAttributes
;
511 aAlienAttributes
.QueryValue( rAttributes
, 0 );
515 ((SvXMLAttrContainerItem
*)pItem
)->QueryValue( rAttributes
, 0 );
519 void SdPage::RemoveEmptyPresentationObjects()
521 SdrObjListIter
aShapeIter( *this, IM_DEEPWITHGROUPS
);
524 for( pShape
= aShapeIter
.Next(); pShape
; pShape
= aShapeIter
.Next() )
526 if( pShape
&& pShape
->IsEmptyPresObj() )
528 RemoveObject( pShape
->GetOrdNum() );
529 SdrObject::Free( pShape
);
535 sal_Int16
SdPage::getTransitionType (void) const
537 return mnTransitionType
;
540 void SdPage::setTransitionType( sal_Int16 nTransitionType
)
542 mnTransitionType
= nTransitionType
;
546 sal_Int16
SdPage::getTransitionSubtype (void) const
548 return mnTransitionSubtype
;
551 void SdPage::setTransitionSubtype ( sal_Int16 nTransitionSubtype
)
553 mnTransitionSubtype
= nTransitionSubtype
;
557 sal_Bool
SdPage::getTransitionDirection (void) const
559 return mbTransitionDirection
;
562 void SdPage::setTransitionDirection ( sal_Bool bTransitionbDirection
)
564 mbTransitionDirection
= bTransitionbDirection
;
568 sal_Int32
SdPage::getTransitionFadeColor (void) const
570 return mnTransitionFadeColor
;
573 void SdPage::setTransitionFadeColor ( sal_Int32 nTransitionFadeColor
)
575 mnTransitionFadeColor
= nTransitionFadeColor
;
579 double SdPage::getTransitionDuration (void) const
581 return mfTransitionDuration
;
584 void SdPage::setTransitionDuration ( double fTranstionDuration
)
586 mfTransitionDuration
= fTranstionDuration
;