Update ooo320-m1
[ooovba.git] / sd / source / core / sdpage2.cxx
blobbfa87d633d779df57b92d1e1e015fc327b1a8918
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdpage2.cxx,v $
10 * $Revision: 1.38 $
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>
36 #ifndef _SVXLINK_HXX
37 #include <svx/linkmgr.hxx>
38 #endif
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"
48 #include "sdpage.hxx"
49 #include "glob.hxx"
50 #include "glob.hrc"
51 #include "drawdoc.hxx"
52 #include "stlpool.hxx"
53 //#include "sdiocmpt.hxx"
54 #include "pglink.hxx"
55 //#include "strmname.h"
56 #include "anminfo.hxx"
58 #include "../ui/inc/strings.hrc"
59 #include "../ui/inc/DrawDocShell.hxx"
61 // #90477#
62 #include <tools/tenccvt.hxx>
63 #include <svtools/itemset.hxx>
65 using namespace ::sd;
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,
94 BOOL bSetMasterPage,
95 BOOL bReverseOrder)
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())
110 SdPage* pMaster;
111 SdPage* pFoundMaster = 0;
112 USHORT nMaster = 0;
113 USHORT nMasterCount = pModel->GetMasterPageCount();
115 if( !bReverseOrder )
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;
123 break;
127 else
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;
135 break;
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 );
146 if( pFoundMaster )
147 TRG_SetMasterPage(*pFoundMaster);
150 /*********************************************************************
151 |* Vorlagen fuer Praesentationsobjekte
152 \********************************************************************/
153 // Listen mit:
154 // - Vorlagenzeigern fuer Gliederungstextobjekt (alte und neue Vorlagen)
155 // -Replacedaten fuer OutlinerParaObject
156 List aOutlineStyles;
157 List aOldOutlineStyles;
158 List aReplList;
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)
172 String aFullName;
173 String aOldFullName;
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);
204 else
206 OutlinerParaObject* pOPO = ((SdrTextObj*)pObj)->GetOutlinerParaObject();
208 if( pOPO )
209 pOPO->SetStyleSheets( i, aFullName, SD_STYLE_FAMILY_MASTERPAGE );
213 bListsFilled = TRUE;
216 SfxStyleSheet* pSheet = (SfxStyleSheet*)aOutlineStyles.First();
217 SfxStyleSheet* pOldSheet = (SfxStyleSheet*)aOldOutlineStyles.First();
218 while (pSheet)
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();
237 while( pReplData )
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);
252 if (pSheet)
253 pObj->SetStyleSheet(pSheet, TRUE);
255 else
257 SfxStyleSheet* pSheet = GetStyleSheetForPresObj(GetPresObjKind(pObj));
259 if (pSheet)
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
274 |* abmelden
276 \************************************************************************/
278 void SdPage::EndListenOutlineText()
280 SdrObject* pOutlineTextObj = GetPresObj(PRESOBJ_OUTLINE);
282 if (pOutlineTextObj)
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();
290 pSheet;
291 pSheet = (SfxStyleSheet*)pOutlineStyles->Next())
293 pOutlineTextObj->EndListening(*pSheet);
296 delete pOutlineStyles;
300 /*************************************************************************
302 |* Neues Model setzen
304 \************************************************************************/
306 void SdPage::SetModel(SdrModel* pNewModel)
308 DisconnectLink();
310 // Model umsetzen
311 FmFormPage::SetModel(pNewModel);
313 ConnectLink();
316 /*************************************************************************
318 |* Ist die Seite read-only?
320 \************************************************************************/
322 FASTBOOL SdPage::IsReadOnly() const
324 return FALSE;
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 /**********************************************************************
342 * Anmelden
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 /**********************************************************************
373 * Abmelden
374 * (Bei Remove wird *pGraphicLink implizit deleted)
375 **********************************************************************/
376 pLinkManager->Remove(mpPageLink);
377 mpPageLink=NULL;
381 /*************************************************************************
383 |* Copy-Ctor
385 \************************************************************************/
387 SdPage::SdPage(const SdPage& rSrcPage)
388 : FmFormPage(rSrcPage)
389 , SdrObjUserCall()
390 , mpItems(NULL)
392 mePageKind = rSrcPage.mePageKind;
393 meAutoLayout = rSrcPage.meAutoLayout;
395 SdrObject* pObj = 0;
396 while((pObj = rSrcPage.maPresentationShapeList.getNextShape(pObj)) != 0)
397 InsertPresObj(GetObj(pObj->GetOrdNum()), rSrcPage.GetPresObjKind(pObj));
399 mbSelected = FALSE;
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;
423 // header footer
424 setHeaderFooterSettings( rSrcPage.getHeaderFooterSettings() );
426 mpPageLink = NULL; // Wird beim Einfuegen ueber ConnectLink() gesetzt
431 /*************************************************************************
433 |* Clone
435 \************************************************************************/
437 SdrPage* SdPage::Clone() const
439 return Clone(NULL);
442 SdrPage* SdPage::Clone(SdrModel* pNewModel) const
444 DBG_ASSERT( pNewModel == 0, "sd::SdPage::Clone(), new page ignored, please check code! CL" );
445 (void)pNewModel;
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 );
464 return 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 );
490 return mpItems;
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 );
502 return sal_True;
505 return sal_False;
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 );
517 else
519 ((SvXMLAttrContainerItem*)pItem)->QueryValue( rAttributes, 0 );
523 void SdPage::RemoveEmptyPresentationObjects()
525 SdrObjListIter aShapeIter( *this, IM_DEEPWITHGROUPS );
527 SdrObject* pShape;
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;
547 ActionChanged();
550 sal_Int16 SdPage::getTransitionSubtype (void) const
552 return mnTransitionSubtype;
555 void SdPage::setTransitionSubtype ( sal_Int16 nTransitionSubtype )
557 mnTransitionSubtype = nTransitionSubtype;
558 ActionChanged();
561 sal_Bool SdPage::getTransitionDirection (void) const
563 return mbTransitionDirection;
566 void SdPage::setTransitionDirection ( sal_Bool bTransitionbDirection )
568 mbTransitionDirection = bTransitionbDirection;
569 ActionChanged();
572 sal_Int32 SdPage::getTransitionFadeColor (void) const
574 return mnTransitionFadeColor;
577 void SdPage::setTransitionFadeColor ( sal_Int32 nTransitionFadeColor )
579 mnTransitionFadeColor = nTransitionFadeColor;
580 ActionChanged();
583 double SdPage::getTransitionDuration (void) const
585 return mfTransitionDuration;
588 void SdPage::setTransitionDuration ( double fTranstionDuration )
590 mfTransitionDuration = fTranstionDuration;
591 ActionChanged();
594 namespace sd {
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 );
610 else
612 maAnnotations.insert( maAnnotations.begin() + nIndex, xAnnotation );
615 if( pModel && pModel->IsUndoEnabled() )
617 SdrUndoAction* pAction = CreateUndoInsertOrRemoveAnnotation( xAnnotation, true );
618 if( pAction )
619 pModel->AddUndo( pAction );
622 SetChanged();
624 if( pModel )
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 );
637 if( pAction )
638 pModel->AddUndo( pAction );
641 AnnotationVector::iterator iter = std::find( maAnnotations.begin(), maAnnotations.end(), xAnnotation );
642 if( iter != maAnnotations.end() )
643 maAnnotations.erase( iter );
645 if( pModel )
647 pModel->SetChanged();
648 Reference< XInterface > xSource( xAnnotation, UNO_QUERY );
649 NotifyDocumentEvent( static_cast< SdDrawDocument* >( pModel ), rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnAnnotationRemoved" ) ), xSource );