1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <boost/ptr_container/ptr_vector.hpp>
24 #include <sfx2/docfile.hxx>
25 #include <vcl/svapp.hxx>
26 #include <editeng/outliner.hxx>
27 #include <sfx2/linkmgr.hxx>
28 #include <svx/svdotext.hxx>
29 #include <editeng/outlobj.hxx>
30 #include <svl/urihelper.hxx>
31 #include <editeng/xmlcnitm.hxx>
32 #include <svx/svditer.hxx>
34 #include "sdresid.hxx"
38 #include "drawdoc.hxx"
39 #include "stlpool.hxx"
41 #include "anminfo.hxx"
43 #include "../ui/inc/strings.hrc"
44 #include "../ui/inc/DrawDocShell.hxx"
46 #include <tools/tenccvt.hxx>
47 #include <svl/itemset.hxx>
50 using namespace ::com::sun::star
;
51 using namespace ::com::sun::star::uno
;
52 using namespace ::com::sun::star::office
;
54 extern void NotifyDocumentEvent( SdDrawDocument
* pDocument
, const OUString
& rEventName
, const Reference
< XInterface
>& xSource
);
56 /*************************************************************************
58 |* Sets: names of layout, master page links and templates for presentation
61 |* Preconditions: - The page has to know the correct model!
62 |* - The corresponding master page has to be in the model.
63 |* - The corresponding style sheets have to be in the style sheet
66 |* bReplaceStyleSheets = sal_True : Named style sheets are replaced
67 |* sal_False: All style sheets are reassigned
69 |* bSetMasterPage = sal_True : search and assign master page
71 |* bReverseOrder = sal_False: search master page from head to tail
72 |* sal_True : search master page from tail to head
73 |* (for undo operations)
75 \************************************************************************/
77 void SdPage::SetPresentationLayout(const String
& rLayoutName
,
78 sal_Bool bReplaceStyleSheets
,
79 sal_Bool bSetMasterPage
,
80 sal_Bool bReverseOrder
)
82 /*********************************************************************
83 |* Name of the layout of the page
84 \********************************************************************/
85 OUString
aOldLayoutName(maLayoutName
); // merken
86 OUStringBuffer
aBuf(rLayoutName
);
87 aBuf
.append(SD_LT_SEPARATOR
).append(SdResId(STR_LAYOUT_OUTLINE
).toString());
88 maLayoutName
= aBuf
.makeStringAndClear();
90 /*********************************************************************
91 |* search and replace master page if necessary
92 \********************************************************************/
93 if (bSetMasterPage
&& !IsMasterPage())
96 SdPage
* pFoundMaster
= 0;
97 sal_uInt16 nMaster
= 0;
98 sal_uInt16 nMasterCount
= pModel
->GetMasterPageCount();
102 for ( nMaster
= 0; nMaster
< nMasterCount
; nMaster
++ )
104 pMaster
= static_cast<SdPage
*>(pModel
->GetMasterPage(nMaster
));
105 if (pMaster
->GetPageKind() == mePageKind
&& pMaster
->GetLayoutName() == maLayoutName
)
107 pFoundMaster
= pMaster
;
114 for ( nMaster
= nMasterCount
; nMaster
> 0; nMaster
-- )
116 pMaster
= static_cast<SdPage
*>(pModel
->GetMasterPage(nMaster
- 1));
117 if (pMaster
->GetPageKind() == mePageKind
&& pMaster
->GetLayoutName() == maLayoutName
)
119 pFoundMaster
= pMaster
;
125 DBG_ASSERT(pFoundMaster
, "Masterpage for presentation layout not found!");
127 // this should never happen, but we play failsafe here
128 if( pFoundMaster
== 0 )
129 pFoundMaster
= static_cast< SdDrawDocument
*>(pModel
)->GetSdPage( 0, mePageKind
);
132 TRG_SetMasterPage(*pFoundMaster
);
135 /*********************************************************************
136 |* templates for presentation objects
137 \********************************************************************/
139 // - pointer to templates for outline text object (old and new templates)
140 // - replace-data for OutlinerParaObject
141 std::vector
<SfxStyleSheetBase
*> aOutlineStyles
;
142 std::vector
<SfxStyleSheetBase
*> aOldOutlineStyles
;
143 boost::ptr_vector
<StyleReplaceData
> aReplList
;
144 bool bListsFilled
= false;
146 sal_uLong nObjCount
= GetObjCount();
148 for (sal_uLong nObj
= 0; nObj
< nObjCount
; nObj
++)
150 SdrTextObj
* pObj
= (SdrTextObj
*) GetObj(nObj
);
152 if (pObj
->GetObjInventor() == SdrInventor
&&
153 pObj
->GetObjIdentifier() == OBJ_OUTLINETEXT
)
155 if (!bListsFilled
|| !bReplaceStyleSheets
)
159 SfxStyleSheetBase
* pSheet
= NULL
;
160 SfxStyleSheetBasePool
* pStShPool
= pModel
->GetStyleSheetPool();
162 for (sal_Int16 i
= -1; i
< 9; i
++)
164 aFullName
= maLayoutName
;
165 aOldFullName
= aOldLayoutName
;
166 aFullName
+= sal_Unicode( ' ' );
167 aFullName
+= OUString::number( (sal_Int32
) (i
<= 0 ) ? 1 : i
+ 1);
168 aOldFullName
+= sal_Unicode( ' ' );
169 aOldFullName
+= OUString::number( (sal_Int32
) (i
<= 0 ) ? 1 : i
+ 1 );
171 pSheet
= pStShPool
->Find(aOldFullName
, SD_STYLE_FAMILY_MASTERPAGE
);
172 DBG_ASSERT(pSheet
, "Old outline style sheet not found");
173 aOldOutlineStyles
.push_back(pSheet
);
175 pSheet
= pStShPool
->Find(aFullName
, SD_STYLE_FAMILY_MASTERPAGE
);
176 DBG_ASSERT(pSheet
, "New outline style sheet not found");
177 aOutlineStyles
.push_back(pSheet
);
179 if (bReplaceStyleSheets
&& pSheet
)
181 // Replace instead Set
182 StyleReplaceData
* pReplData
= new StyleReplaceData
;
183 pReplData
->nNewFamily
= pSheet
->GetFamily();
184 pReplData
->nFamily
= pSheet
->GetFamily();
185 pReplData
->aNewName
= aFullName
;
186 pReplData
->aName
= aOldFullName
;
187 aReplList
.push_back(pReplData
);
191 OutlinerParaObject
* pOPO
= ((SdrTextObj
*)pObj
)->GetOutlinerParaObject();
194 pOPO
->SetStyleSheets( i
, aFullName
, SD_STYLE_FAMILY_MASTERPAGE
);
201 SfxStyleSheet
* pSheet
= NULL
;
202 SfxStyleSheet
* pOldSheet
= NULL
;
204 std::vector
<SfxStyleSheetBase
*>::iterator iterOut
= aOutlineStyles
.begin();
205 std::vector
<SfxStyleSheetBase
*>::iterator iterOldOut
= aOldOutlineStyles
.begin();
207 while (iterOut
!= aOutlineStyles
.end())
209 pSheet
= static_cast<SfxStyleSheet
*>(*iterOut
);
210 pOldSheet
= static_cast<SfxStyleSheet
*>(*iterOldOut
);
212 if (pSheet
!= pOldSheet
)
214 pObj
->EndListening(*pOldSheet
);
216 if (!pObj
->IsListening(*pSheet
))
217 pObj
->StartListening(*pSheet
);
224 OutlinerParaObject
* pOPO
= ((SdrTextObj
*)pObj
)->GetOutlinerParaObject();
225 if ( bReplaceStyleSheets
&& pOPO
)
227 boost::ptr_vector
<StyleReplaceData
>::const_iterator it
= aReplList
.begin();
228 while (it
!= aReplList
.end())
230 pOPO
->ChangeStyleSheets( it
->aName
, it
->nFamily
, it
->aNewName
, it
->nNewFamily
);
235 else if (pObj
->GetObjInventor() == SdrInventor
&&
236 pObj
->GetObjIdentifier() == OBJ_TITLETEXT
)
238 // We do net get PresObjKind via GetPresObjKind() since there are
239 // only PresObjListe considered. But we want to consider all "Title
240 // objects" here (paste from clipboard etc.)
241 SfxStyleSheet
* pSheet
= GetStyleSheetForPresObj(PRESOBJ_TITLE
);
244 pObj
->SetStyleSheet(pSheet
, sal_True
);
248 SfxStyleSheet
* pSheet
= GetStyleSheetForPresObj(GetPresObjKind(pObj
));
251 pObj
->SetStyleSheet(pSheet
, sal_True
);
257 /*************************************************************************
259 |* disconnect outline text object from templates for outline levels
261 \************************************************************************/
263 void SdPage::EndListenOutlineText()
265 SdrObject
* pOutlineTextObj
= GetPresObj(PRESOBJ_OUTLINE
);
269 SdStyleSheetPool
* pSPool
= (SdStyleSheetPool
*)pModel
->GetStyleSheetPool();
270 DBG_ASSERT(pSPool
, "StyleSheetPool missing");
271 String
aTrueLayoutName(maLayoutName
);
272 aTrueLayoutName
.Erase( aTrueLayoutName
.SearchAscii( SD_LT_SEPARATOR
));
274 SfxStyleSheet
*pSheet
= NULL
;
275 std::vector
<SfxStyleSheetBase
*> aOutlineStyles
;
276 pSPool
->CreateOutlineSheetList(aTrueLayoutName
,aOutlineStyles
);
278 std::vector
<SfxStyleSheetBase
*>::iterator iter
;
279 for (iter
= aOutlineStyles
.begin(); iter
!= aOutlineStyles
.end(); ++iter
)
281 pSheet
= static_cast<SfxStyleSheet
*>(*iter
);
282 pOutlineTextObj
->EndListening(*pSheet
);
287 /*************************************************************************
291 \************************************************************************/
293 void SdPage::SetModel(SdrModel
* pNewModel
)
298 FmFormPage::SetModel(pNewModel
);
303 /*************************************************************************
305 |* Is this page read-only?
307 \************************************************************************/
309 bool SdPage::IsReadOnly() const
314 /*************************************************************************
316 |* Connect to sfx2::LinkManager
318 \************************************************************************/
320 void SdPage::ConnectLink()
322 sfx2::LinkManager
* pLinkManager
= pModel
!=NULL
? pModel
->GetLinkManager() : NULL
;
324 if (pLinkManager
&& !mpPageLink
&& maFileName
.Len() && maBookmarkName
.Len() &&
325 mePageKind
==PK_STANDARD
&& !IsMasterPage() &&
326 ( (SdDrawDocument
*) pModel
)->IsNewOrLoadCompleted())
328 /**********************************************************************
330 * Only standard pages are allowed to be linked
331 **********************************************************************/
332 ::sd::DrawDocShell
* pDocSh
= ((SdDrawDocument
*) pModel
)->GetDocSh();
334 if (!pDocSh
|| !pDocSh
->GetMedium()->GetOrigURL().equals(maFileName
))
336 // No links to document owned pages!
337 mpPageLink
= new SdPageLink(this, maFileName
, maBookmarkName
);
338 String
aFilterName(SdResId(STR_IMPRESS
));
339 pLinkManager
->InsertFileLink(*mpPageLink
, OBJECT_CLIENT_FILE
,
340 maFileName
, &aFilterName
, &maBookmarkName
);
341 mpPageLink
->Connect();
347 /*************************************************************************
349 |* Disconnect from sfx2::LinkManager
351 \************************************************************************/
353 void SdPage::DisconnectLink()
355 sfx2::LinkManager
* pLinkManager
= pModel
!=NULL
? pModel
->GetLinkManager() : NULL
;
357 if (pLinkManager
&& mpPageLink
)
359 /**********************************************************************
361 * (remove deletes *pGraphicLink implicit)
362 **********************************************************************/
363 pLinkManager
->Remove(mpPageLink
);
368 /*************************************************************************
372 \************************************************************************/
374 SdPage::SdPage(const SdPage
& rSrcPage
)
375 : FmFormPage(rSrcPage
)
379 mePageKind
= rSrcPage
.mePageKind
;
380 meAutoLayout
= rSrcPage
.meAutoLayout
;
383 while((pObj
= rSrcPage
.maPresentationShapeList
.getNextShape(pObj
)) != 0)
384 InsertPresObj(GetObj(pObj
->GetOrdNum()), rSrcPage
.GetPresObjKind(pObj
));
386 mbSelected
= sal_False
;
387 mnTransitionType
= rSrcPage
.mnTransitionType
;
388 mnTransitionSubtype
= rSrcPage
.mnTransitionSubtype
;
389 mbTransitionDirection
= rSrcPage
.mbTransitionDirection
;
390 mnTransitionFadeColor
= rSrcPage
.mnTransitionFadeColor
;
391 mfTransitionDuration
= rSrcPage
.mfTransitionDuration
;
392 mePresChange
= rSrcPage
.mePresChange
;
393 mfTime
= rSrcPage
.mfTime
;
394 mbSoundOn
= rSrcPage
.mbSoundOn
;
395 mbExcluded
= rSrcPage
.mbExcluded
;
397 maLayoutName
= rSrcPage
.maLayoutName
;
398 maSoundFile
= rSrcPage
.maSoundFile
;
399 mbLoopSound
= rSrcPage
.mbLoopSound
;
400 mbStopSound
= rSrcPage
.mbStopSound
;
401 maCreatedPageName
= String();
402 maFileName
= rSrcPage
.maFileName
;
403 maBookmarkName
= rSrcPage
.maBookmarkName
;
404 mbScaleObjects
= rSrcPage
.mbScaleObjects
;
405 mbBackgroundFullSize
= rSrcPage
.mbBackgroundFullSize
;
406 meCharSet
= rSrcPage
.meCharSet
;
407 mnPaperBin
= rSrcPage
.mnPaperBin
;
408 meOrientation
= rSrcPage
.meOrientation
;
411 setHeaderFooterSettings( rSrcPage
.getHeaderFooterSettings() );
413 mpPageLink
= NULL
; // is set when inserting via ConnectLink()
418 /*************************************************************************
422 \************************************************************************/
424 SdrPage
* SdPage::Clone() const
429 SdrPage
* SdPage::Clone(SdrModel
* pNewModel
) const
431 DBG_ASSERT( pNewModel
== 0, "sd::SdPage::Clone(), new page ignored, please check code! CL" );
434 SdPage
* pNewPage
= new SdPage(*this);
436 cloneAnimations( *pNewPage
);
438 // fix user calls for duplicated slide
439 SdrObjListIter
aSourceIter( *this, IM_DEEPWITHGROUPS
);
440 SdrObjListIter
aTargetIter( *pNewPage
, IM_DEEPWITHGROUPS
);
442 while( aSourceIter
.IsMore() && aTargetIter
.IsMore() )
444 SdrObject
* pSource
= aSourceIter
.Next();
445 SdrObject
* pTarget
= aTargetIter
.Next();
447 if( pSource
->GetUserCall() )
448 pTarget
->SetUserCall( pNewPage
);
454 /*************************************************************************
456 |* GetTextStyleSheetForObject
458 \************************************************************************/
461 SfxStyleSheet
* SdPage::GetTextStyleSheetForObject( SdrObject
* pObj
) const
463 const PresObjKind eKind
= ((SdPage
*)this)->GetPresObjKind(pObj
);
464 if( eKind
!= PRESOBJ_NONE
)
466 return ((SdPage
*)this)->GetStyleSheetForPresObj(eKind
);
469 return FmFormPage::GetTextStyleSheetForObject( pObj
);
472 SfxItemSet
* SdPage::getOrCreateItems()
474 if( mpItems
== NULL
)
475 mpItems
= new SfxItemSet( pModel
->GetItemPool(), SDRATTR_XMLATTRIBUTES
, SDRATTR_XMLATTRIBUTES
);
481 sal_Bool
SdPage::setAlienAttributes( const com::sun::star::uno::Any
& rAttributes
)
483 SfxItemSet
* pSet
= getOrCreateItems();
485 SvXMLAttrContainerItem
aAlienAttributes( SDRATTR_XMLATTRIBUTES
);
486 if( aAlienAttributes
.PutValue( rAttributes
, 0 ) )
488 pSet
->Put( aAlienAttributes
);
495 void SdPage::getAlienAttributes( com::sun::star::uno::Any
& rAttributes
)
497 const SfxPoolItem
* pItem
;
499 if( (mpItems
== NULL
) || ( SFX_ITEM_SET
!= mpItems
->GetItemState( SDRATTR_XMLATTRIBUTES
, sal_False
, &pItem
) ) )
501 SvXMLAttrContainerItem aAlienAttributes
;
502 aAlienAttributes
.QueryValue( rAttributes
, 0 );
506 ((SvXMLAttrContainerItem
*)pItem
)->QueryValue( rAttributes
, 0 );
510 void SdPage::RemoveEmptyPresentationObjects()
512 SdrObjListIter
aShapeIter( *this, IM_DEEPWITHGROUPS
);
515 for( pShape
= aShapeIter
.Next(); pShape
; pShape
= aShapeIter
.Next() )
517 if( pShape
&& pShape
->IsEmptyPresObj() )
519 RemoveObject( pShape
->GetOrdNum() );
520 SdrObject::Free( pShape
);
526 sal_Int16
SdPage::getTransitionType (void) const
528 return mnTransitionType
;
531 void SdPage::setTransitionType( sal_Int16 nTransitionType
)
533 mnTransitionType
= nTransitionType
;
537 sal_Int16
SdPage::getTransitionSubtype (void) const
539 return mnTransitionSubtype
;
542 void SdPage::setTransitionSubtype ( sal_Int16 nTransitionSubtype
)
544 mnTransitionSubtype
= nTransitionSubtype
;
548 sal_Bool
SdPage::getTransitionDirection (void) const
550 return mbTransitionDirection
;
553 void SdPage::setTransitionDirection ( sal_Bool bTransitionbDirection
)
555 mbTransitionDirection
= bTransitionbDirection
;
559 sal_Int32
SdPage::getTransitionFadeColor (void) const
561 return mnTransitionFadeColor
;
564 void SdPage::setTransitionFadeColor ( sal_Int32 nTransitionFadeColor
)
566 mnTransitionFadeColor
= nTransitionFadeColor
;
570 double SdPage::getTransitionDuration (void) const
572 return mfTransitionDuration
;
575 void SdPage::setTransitionDuration ( double fTranstionDuration
)
577 mfTransitionDuration
= fTranstionDuration
;
582 extern void createAnnotation( Reference
< XAnnotation
>& xAnnotation
, SdPage
* pPage
);
583 extern SdrUndoAction
* CreateUndoInsertOrRemoveAnnotation( const Reference
< XAnnotation
>& xAnnotation
, bool bInsert
);
586 void SdPage::createAnnotation( ::com::sun::star::uno::Reference
< ::com::sun::star::office::XAnnotation
>& xAnnotation
)
588 sd::createAnnotation( xAnnotation
, this );
591 void SdPage::addAnnotation( const Reference
< XAnnotation
>& xAnnotation
, int nIndex
)
593 if( (nIndex
== -1) || (nIndex
> (int)maAnnotations
.size()) )
595 maAnnotations
.push_back( xAnnotation
);
599 maAnnotations
.insert( maAnnotations
.begin() + nIndex
, xAnnotation
);
602 if( pModel
&& pModel
->IsUndoEnabled() )
604 SdrUndoAction
* pAction
= CreateUndoInsertOrRemoveAnnotation( xAnnotation
, true );
606 pModel
->AddUndo( pAction
);
613 pModel
->SetChanged();
614 Reference
< XInterface
> xSource( xAnnotation
, UNO_QUERY
);
615 NotifyDocumentEvent( static_cast< SdDrawDocument
* >( pModel
), "OnAnnotationInserted" , xSource
);
619 void SdPage::removeAnnotation( const Reference
< XAnnotation
>& xAnnotation
)
621 if( pModel
&& pModel
->IsUndoEnabled() )
623 SdrUndoAction
* pAction
= CreateUndoInsertOrRemoveAnnotation( xAnnotation
, false );
625 pModel
->AddUndo( pAction
);
628 AnnotationVector::iterator iter
= std::find( maAnnotations
.begin(), maAnnotations
.end(), xAnnotation
);
629 if( iter
!= maAnnotations
.end() )
630 maAnnotations
.erase( iter
);
634 pModel
->SetChanged();
635 Reference
< XInterface
> xSource( xAnnotation
, UNO_QUERY
);
636 NotifyDocumentEvent( static_cast< SdDrawDocument
* >( pModel
), OUString( "OnAnnotationRemoved" ), xSource
);
640 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */