Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include <vector>
22 : #include <boost/ptr_container/ptr_vector.hpp>
23 :
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>
33 :
34 : #include "sdresid.hxx"
35 : #include "sdpage.hxx"
36 : #include "glob.hxx"
37 : #include "glob.hrc"
38 : #include "drawdoc.hxx"
39 : #include "stlpool.hxx"
40 : #include "pglink.hxx"
41 : #include "anminfo.hxx"
42 :
43 : #include "../ui/inc/strings.hrc"
44 : #include "../ui/inc/DrawDocShell.hxx"
45 :
46 : #include <tools/tenccvt.hxx>
47 : #include <svl/itemset.hxx>
48 :
49 : using namespace ::sd;
50 : using namespace ::com::sun::star;
51 : using namespace ::com::sun::star::uno;
52 : using namespace ::com::sun::star::office;
53 :
54 : extern void NotifyDocumentEvent( SdDrawDocument* pDocument, const OUString& rEventName, const Reference< XInterface >& xSource );
55 :
56 : /*************************************************************************
57 : |*
58 : |* Sets: names of layout, master page links and templates for presentation
59 : |* objects
60 : |*
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
64 : |* pool.
65 : |*
66 : |* bReplaceStyleSheets = sal_True : Named style sheets are replaced
67 : |* sal_False: All style sheets are reassigned
68 : |*
69 : |* bSetMasterPage = sal_True : search and assign master page
70 : |*
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)
74 : |*
75 : \************************************************************************/
76 :
77 1 : void SdPage::SetPresentationLayout(const String& rLayoutName,
78 : sal_Bool bReplaceStyleSheets,
79 : sal_Bool bSetMasterPage,
80 : sal_Bool bReverseOrder)
81 : {
82 : /*********************************************************************
83 : |* Name of the layout of the page
84 : \********************************************************************/
85 1 : OUString aOldLayoutName(maLayoutName); // merken
86 2 : OUStringBuffer aBuf(rLayoutName);
87 1 : aBuf.append(SD_LT_SEPARATOR).append(SdResId(STR_LAYOUT_OUTLINE).toString());
88 1 : maLayoutName = aBuf.makeStringAndClear();
89 :
90 : /*********************************************************************
91 : |* search and replace master page if necessary
92 : \********************************************************************/
93 1 : if (bSetMasterPage && !IsMasterPage())
94 : {
95 : SdPage* pMaster;
96 0 : SdPage* pFoundMaster = 0;
97 0 : sal_uInt16 nMaster = 0;
98 0 : sal_uInt16 nMasterCount = pModel->GetMasterPageCount();
99 :
100 0 : if( !bReverseOrder )
101 : {
102 0 : for ( nMaster = 0; nMaster < nMasterCount; nMaster++ )
103 : {
104 0 : pMaster = static_cast<SdPage*>(pModel->GetMasterPage(nMaster));
105 0 : if (pMaster->GetPageKind() == mePageKind && pMaster->GetLayoutName() == maLayoutName)
106 : {
107 0 : pFoundMaster = pMaster;
108 0 : break;
109 : }
110 : }
111 : }
112 : else
113 : {
114 0 : for ( nMaster = nMasterCount; nMaster > 0; nMaster-- )
115 : {
116 0 : pMaster = static_cast<SdPage*>(pModel->GetMasterPage(nMaster - 1));
117 0 : if (pMaster->GetPageKind() == mePageKind && pMaster->GetLayoutName() == maLayoutName)
118 : {
119 0 : pFoundMaster = pMaster;
120 0 : break;
121 : }
122 : }
123 : }
124 :
125 : DBG_ASSERT(pFoundMaster, "Masterpage for presentation layout not found!");
126 :
127 : // this should never happen, but we play failsafe here
128 0 : if( pFoundMaster == 0 )
129 0 : pFoundMaster = static_cast< SdDrawDocument *>(pModel)->GetSdPage( 0, mePageKind );
130 :
131 0 : if( pFoundMaster )
132 0 : TRG_SetMasterPage(*pFoundMaster);
133 : }
134 :
135 : /*********************************************************************
136 : |* templates for presentation objects
137 : \********************************************************************/
138 : // list with:
139 : // - pointer to templates for outline text object (old and new templates)
140 : // - replace-data for OutlinerParaObject
141 2 : std::vector<SfxStyleSheetBase*> aOutlineStyles;
142 2 : std::vector<SfxStyleSheetBase*> aOldOutlineStyles;
143 2 : boost::ptr_vector<StyleReplaceData> aReplList;
144 1 : bool bListsFilled = false;
145 :
146 1 : sal_uLong nObjCount = GetObjCount();
147 :
148 3 : for (sal_uLong nObj = 0; nObj < nObjCount; nObj++)
149 : {
150 2 : SdrTextObj* pObj = (SdrTextObj*) GetObj(nObj);
151 :
152 4 : if (pObj->GetObjInventor() == SdrInventor &&
153 2 : pObj->GetObjIdentifier() == OBJ_OUTLINETEXT)
154 : {
155 0 : if (!bListsFilled || !bReplaceStyleSheets)
156 : {
157 0 : String aFullName;
158 0 : String aOldFullName;
159 0 : SfxStyleSheetBase* pSheet = NULL;
160 0 : SfxStyleSheetBasePool* pStShPool = pModel->GetStyleSheetPool();
161 :
162 0 : for (sal_Int16 i = -1; i < 9; i++)
163 : {
164 0 : aFullName = maLayoutName;
165 0 : aOldFullName = aOldLayoutName;
166 0 : aFullName += sal_Unicode( ' ' );
167 0 : aFullName += OUString::number( (sal_Int32) (i <= 0 ) ? 1 : i + 1);
168 0 : aOldFullName += sal_Unicode( ' ' );
169 0 : aOldFullName += OUString::number( (sal_Int32) (i <= 0 ) ? 1 : i + 1 );
170 :
171 0 : pSheet = pStShPool->Find(aOldFullName, SD_STYLE_FAMILY_MASTERPAGE);
172 : DBG_ASSERT(pSheet, "Old outline style sheet not found");
173 0 : aOldOutlineStyles.push_back(pSheet);
174 :
175 0 : pSheet = pStShPool->Find(aFullName, SD_STYLE_FAMILY_MASTERPAGE);
176 : DBG_ASSERT(pSheet, "New outline style sheet not found");
177 0 : aOutlineStyles.push_back(pSheet);
178 :
179 0 : if (bReplaceStyleSheets && pSheet)
180 : {
181 : // Replace instead Set
182 0 : StyleReplaceData* pReplData = new StyleReplaceData;
183 0 : pReplData->nNewFamily = pSheet->GetFamily();
184 0 : pReplData->nFamily = pSheet->GetFamily();
185 0 : pReplData->aNewName = aFullName;
186 0 : pReplData->aName = aOldFullName;
187 0 : aReplList.push_back(pReplData);
188 : }
189 : else
190 : {
191 0 : OutlinerParaObject* pOPO = ((SdrTextObj*)pObj)->GetOutlinerParaObject();
192 :
193 0 : if( pOPO )
194 0 : pOPO->SetStyleSheets( i, aFullName, SD_STYLE_FAMILY_MASTERPAGE );
195 : }
196 : }
197 :
198 0 : bListsFilled = true;
199 : }
200 :
201 0 : SfxStyleSheet* pSheet = NULL;
202 0 : SfxStyleSheet* pOldSheet = NULL;
203 :
204 0 : std::vector<SfxStyleSheetBase*>::iterator iterOut = aOutlineStyles.begin();
205 0 : std::vector<SfxStyleSheetBase*>::iterator iterOldOut = aOldOutlineStyles.begin();
206 :
207 0 : while (iterOut != aOutlineStyles.end())
208 : {
209 0 : pSheet = static_cast<SfxStyleSheet*>(*iterOut);
210 0 : pOldSheet = static_cast<SfxStyleSheet*>(*iterOldOut);
211 :
212 0 : if (pSheet != pOldSheet)
213 : {
214 0 : pObj->EndListening(*pOldSheet);
215 :
216 0 : if (!pObj->IsListening(*pSheet))
217 0 : pObj->StartListening(*pSheet);
218 : }
219 :
220 0 : ++iterOut;
221 0 : ++iterOldOut;
222 : }
223 :
224 0 : OutlinerParaObject* pOPO = ((SdrTextObj*)pObj)->GetOutlinerParaObject();
225 0 : if ( bReplaceStyleSheets && pOPO )
226 : {
227 0 : boost::ptr_vector<StyleReplaceData>::const_iterator it = aReplList.begin();
228 0 : while (it != aReplList.end())
229 : {
230 0 : pOPO->ChangeStyleSheets( it->aName, it->nFamily, it->aNewName, it->nNewFamily );
231 0 : ++it;
232 : }
233 : }
234 : }
235 4 : else if (pObj->GetObjInventor() == SdrInventor &&
236 2 : pObj->GetObjIdentifier() == OBJ_TITLETEXT)
237 : {
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 1 : SfxStyleSheet* pSheet = GetStyleSheetForPresObj(PRESOBJ_TITLE);
242 :
243 1 : if (pSheet)
244 1 : pObj->SetStyleSheet(pSheet, sal_True);
245 : }
246 : else
247 : {
248 1 : SfxStyleSheet* pSheet = GetStyleSheetForPresObj(GetPresObjKind(pObj));
249 :
250 1 : if (pSheet)
251 1 : pObj->SetStyleSheet(pSheet, sal_True);
252 : }
253 1 : }
254 1 : }
255 :
256 :
257 : /*************************************************************************
258 : |*
259 : |* disconnect outline text object from templates for outline levels
260 : |*
261 : \************************************************************************/
262 :
263 581 : void SdPage::EndListenOutlineText()
264 : {
265 581 : SdrObject* pOutlineTextObj = GetPresObj(PRESOBJ_OUTLINE);
266 :
267 581 : if (pOutlineTextObj)
268 : {
269 51 : SdStyleSheetPool* pSPool = (SdStyleSheetPool*)pModel->GetStyleSheetPool();
270 : DBG_ASSERT(pSPool, "StyleSheetPool missing");
271 51 : String aTrueLayoutName(maLayoutName);
272 51 : aTrueLayoutName.Erase( aTrueLayoutName.SearchAscii( SD_LT_SEPARATOR ));
273 :
274 51 : SfxStyleSheet *pSheet = NULL;
275 102 : std::vector<SfxStyleSheetBase*> aOutlineStyles;
276 51 : pSPool->CreateOutlineSheetList(aTrueLayoutName,aOutlineStyles);
277 :
278 51 : std::vector<SfxStyleSheetBase*>::iterator iter;
279 510 : for (iter = aOutlineStyles.begin(); iter != aOutlineStyles.end(); ++iter)
280 : {
281 459 : pSheet = static_cast<SfxStyleSheet*>(*iter);
282 459 : pOutlineTextObj->EndListening(*pSheet);
283 51 : }
284 : }
285 581 : }
286 :
287 : /*************************************************************************
288 : |*
289 : |* Set new model
290 : |*
291 : \************************************************************************/
292 :
293 599 : void SdPage::SetModel(SdrModel* pNewModel)
294 : {
295 599 : DisconnectLink();
296 :
297 : // assign model
298 599 : FmFormPage::SetModel(pNewModel);
299 :
300 599 : ConnectLink();
301 599 : }
302 :
303 : /*************************************************************************
304 : |*
305 : |* Is this page read-only?
306 : |*
307 : \************************************************************************/
308 :
309 2 : bool SdPage::IsReadOnly() const
310 : {
311 2 : return false;
312 : }
313 :
314 : /*************************************************************************
315 : |*
316 : |* Connect to sfx2::LinkManager
317 : |*
318 : \************************************************************************/
319 :
320 938 : void SdPage::ConnectLink()
321 : {
322 938 : sfx2::LinkManager* pLinkManager = pModel!=NULL ? pModel->GetLinkManager() : NULL;
323 :
324 1873 : if (pLinkManager && !mpPageLink && maFileName.Len() && maBookmarkName.Len() &&
325 938 : mePageKind==PK_STANDARD && !IsMasterPage() &&
326 0 : ( (SdDrawDocument*) pModel)->IsNewOrLoadCompleted())
327 : {
328 : /**********************************************************************
329 : * Connect
330 : * Only standard pages are allowed to be linked
331 : **********************************************************************/
332 0 : ::sd::DrawDocShell* pDocSh = ((SdDrawDocument*) pModel)->GetDocSh();
333 :
334 0 : if (!pDocSh || !pDocSh->GetMedium()->GetOrigURL().equals(maFileName))
335 : {
336 : // No links to document owned pages!
337 0 : mpPageLink = new SdPageLink(this, maFileName, maBookmarkName);
338 0 : String aFilterName(SdResId(STR_IMPRESS));
339 : pLinkManager->InsertFileLink(*mpPageLink, OBJECT_CLIENT_FILE,
340 0 : maFileName, &aFilterName, &maBookmarkName);
341 0 : mpPageLink->Connect();
342 : }
343 : }
344 938 : }
345 :
346 :
347 : /*************************************************************************
348 : |*
349 : |* Disconnect from sfx2::LinkManager
350 : |*
351 : \************************************************************************/
352 :
353 1510 : void SdPage::DisconnectLink()
354 : {
355 1510 : sfx2::LinkManager* pLinkManager = pModel!=NULL ? pModel->GetLinkManager() : NULL;
356 :
357 1510 : if (pLinkManager && mpPageLink)
358 : {
359 : /**********************************************************************
360 : * Disconnect
361 : * (remove deletes *pGraphicLink implicit)
362 : **********************************************************************/
363 0 : pLinkManager->Remove(mpPageLink);
364 0 : mpPageLink=NULL;
365 : }
366 1510 : }
367 :
368 : /*************************************************************************
369 : |*
370 : |* Copy-Ctor
371 : |*
372 : \************************************************************************/
373 :
374 1 : SdPage::SdPage(const SdPage& rSrcPage)
375 : : FmFormPage(rSrcPage)
376 : , SdrObjUserCall()
377 1 : , mpItems(NULL)
378 : {
379 1 : mePageKind = rSrcPage.mePageKind;
380 1 : meAutoLayout = rSrcPage.meAutoLayout;
381 :
382 : // use shape list directly to preserve constness of rSrcPage
383 1 : const std::list< SdrObject* >& rShapeList = rSrcPage.maPresentationShapeList.getList();
384 9 : for( std::list< SdrObject* >::const_iterator aIter = rShapeList.begin();
385 6 : aIter != rShapeList.end(); ++aIter )
386 : {
387 2 : SdrObject* pObj = *aIter;
388 2 : InsertPresObj(GetObj(pObj->GetOrdNum()), rSrcPage.GetPresObjKind(pObj));
389 : }
390 :
391 1 : mbSelected = sal_False;
392 1 : mnTransitionType = rSrcPage.mnTransitionType;
393 1 : mnTransitionSubtype = rSrcPage.mnTransitionSubtype;
394 1 : mbTransitionDirection = rSrcPage.mbTransitionDirection;
395 1 : mnTransitionFadeColor = rSrcPage.mnTransitionFadeColor;
396 1 : mfTransitionDuration = rSrcPage.mfTransitionDuration;
397 1 : mePresChange = rSrcPage.mePresChange;
398 1 : mfTime = rSrcPage.mfTime;
399 1 : mbSoundOn = rSrcPage.mbSoundOn;
400 1 : mbExcluded = rSrcPage.mbExcluded;
401 :
402 1 : maLayoutName = rSrcPage.maLayoutName;
403 1 : maSoundFile = rSrcPage.maSoundFile;
404 1 : mbLoopSound = rSrcPage.mbLoopSound;
405 1 : mbStopSound = rSrcPage.mbStopSound;
406 1 : maCreatedPageName = String();
407 1 : maFileName = rSrcPage.maFileName;
408 1 : maBookmarkName = rSrcPage.maBookmarkName;
409 1 : mbScaleObjects = rSrcPage.mbScaleObjects;
410 1 : mbBackgroundFullSize = rSrcPage.mbBackgroundFullSize;
411 1 : meCharSet = rSrcPage.meCharSet;
412 1 : mnPaperBin = rSrcPage.mnPaperBin;
413 1 : meOrientation = rSrcPage.meOrientation;
414 :
415 : // header footer
416 1 : setHeaderFooterSettings( rSrcPage.getHeaderFooterSettings() );
417 :
418 1 : mpPageLink = NULL; // is set when inserting via ConnectLink()
419 1 : }
420 :
421 :
422 :
423 : /*************************************************************************
424 : |*
425 : |* Clone
426 : |*
427 : \************************************************************************/
428 :
429 1 : SdrPage* SdPage::Clone() const
430 : {
431 1 : return Clone(NULL);
432 : }
433 :
434 1 : SdrPage* SdPage::Clone(SdrModel* pNewModel) const
435 : {
436 : DBG_ASSERT( pNewModel == 0, "sd::SdPage::Clone(), new page ignored, please check code! CL" );
437 : (void)pNewModel;
438 :
439 1 : SdPage* pNewPage = new SdPage(*this);
440 :
441 1 : cloneAnimations( *pNewPage );
442 :
443 : // fix user calls for duplicated slide
444 1 : SdrObjListIter aSourceIter( *this, IM_DEEPWITHGROUPS );
445 2 : SdrObjListIter aTargetIter( *pNewPage, IM_DEEPWITHGROUPS );
446 :
447 4 : while( aSourceIter.IsMore() && aTargetIter.IsMore() )
448 : {
449 2 : SdrObject* pSource = aSourceIter.Next();
450 2 : SdrObject* pTarget = aTargetIter.Next();
451 :
452 2 : if( pSource->GetUserCall() )
453 2 : pTarget->SetUserCall( pNewPage );
454 : }
455 :
456 2 : return pNewPage;
457 : }
458 :
459 : /*************************************************************************
460 : |*
461 : |* GetTextStyleSheetForObject
462 : |*
463 : \************************************************************************/
464 :
465 :
466 310 : SfxStyleSheet* SdPage::GetTextStyleSheetForObject( SdrObject* pObj ) const
467 : {
468 310 : const PresObjKind eKind = ((SdPage*)this)->GetPresObjKind(pObj);
469 310 : if( eKind != PRESOBJ_NONE )
470 : {
471 17 : return ((SdPage*)this)->GetStyleSheetForPresObj(eKind);
472 : }
473 :
474 293 : return FmFormPage::GetTextStyleSheetForObject( pObj );
475 : }
476 :
477 0 : SfxItemSet* SdPage::getOrCreateItems()
478 : {
479 0 : if( mpItems == NULL )
480 0 : mpItems = new SfxItemSet( pModel->GetItemPool(), SDRATTR_XMLATTRIBUTES, SDRATTR_XMLATTRIBUTES );
481 :
482 0 : return mpItems;
483 : }
484 :
485 :
486 0 : sal_Bool SdPage::setAlienAttributes( const com::sun::star::uno::Any& rAttributes )
487 : {
488 0 : SfxItemSet* pSet = getOrCreateItems();
489 :
490 0 : SvXMLAttrContainerItem aAlienAttributes( SDRATTR_XMLATTRIBUTES );
491 0 : if( aAlienAttributes.PutValue( rAttributes, 0 ) )
492 : {
493 0 : pSet->Put( aAlienAttributes );
494 0 : return sal_True;
495 : }
496 :
497 0 : return sal_False;
498 : }
499 :
500 24 : void SdPage::getAlienAttributes( com::sun::star::uno::Any& rAttributes )
501 : {
502 : const SfxPoolItem* pItem;
503 :
504 24 : if( (mpItems == NULL) || ( SFX_ITEM_SET != mpItems->GetItemState( SDRATTR_XMLATTRIBUTES, sal_False, &pItem ) ) )
505 : {
506 24 : SvXMLAttrContainerItem aAlienAttributes;
507 24 : aAlienAttributes.QueryValue( rAttributes, 0 );
508 : }
509 : else
510 : {
511 0 : ((SvXMLAttrContainerItem*)pItem)->QueryValue( rAttributes, 0 );
512 : }
513 24 : }
514 :
515 0 : void SdPage::RemoveEmptyPresentationObjects()
516 : {
517 0 : SdrObjListIter aShapeIter( *this, IM_DEEPWITHGROUPS );
518 :
519 : SdrObject* pShape;
520 0 : for( pShape = aShapeIter.Next(); pShape; pShape = aShapeIter.Next() )
521 : {
522 0 : if( pShape && pShape->IsEmptyPresObj() )
523 : {
524 0 : RemoveObject( pShape->GetOrdNum() );
525 0 : SdrObject::Free( pShape );
526 : }
527 :
528 0 : }
529 0 : }
530 :
531 1630 : sal_Int16 SdPage::getTransitionType (void) const
532 : {
533 1630 : return mnTransitionType;
534 : }
535 :
536 2 : void SdPage::setTransitionType( sal_Int16 nTransitionType )
537 : {
538 2 : mnTransitionType = nTransitionType;
539 2 : ActionChanged();
540 2 : }
541 :
542 2 : sal_Int16 SdPage::getTransitionSubtype (void) const
543 : {
544 2 : return mnTransitionSubtype;
545 : }
546 :
547 2 : void SdPage::setTransitionSubtype ( sal_Int16 nTransitionSubtype )
548 : {
549 2 : mnTransitionSubtype = nTransitionSubtype;
550 2 : ActionChanged();
551 2 : }
552 :
553 2 : sal_Bool SdPage::getTransitionDirection (void) const
554 : {
555 2 : return mbTransitionDirection;
556 : }
557 :
558 2 : void SdPage::setTransitionDirection ( sal_Bool bTransitionbDirection )
559 : {
560 2 : mbTransitionDirection = bTransitionbDirection;
561 2 : ActionChanged();
562 2 : }
563 :
564 2 : sal_Int32 SdPage::getTransitionFadeColor (void) const
565 : {
566 2 : return mnTransitionFadeColor;
567 : }
568 :
569 2 : void SdPage::setTransitionFadeColor ( sal_Int32 nTransitionFadeColor )
570 : {
571 2 : mnTransitionFadeColor = nTransitionFadeColor;
572 2 : ActionChanged();
573 2 : }
574 :
575 2 : double SdPage::getTransitionDuration (void) const
576 : {
577 2 : return mfTransitionDuration;
578 : }
579 :
580 7 : void SdPage::setTransitionDuration ( double fTranstionDuration )
581 : {
582 7 : mfTransitionDuration = fTranstionDuration;
583 7 : ActionChanged();
584 7 : }
585 :
586 : namespace sd {
587 : extern void createAnnotation( Reference< XAnnotation >& xAnnotation, SdPage* pPage );
588 : extern SdrUndoAction* CreateUndoInsertOrRemoveAnnotation( const Reference< XAnnotation >& xAnnotation, bool bInsert );
589 : }
590 :
591 0 : void SdPage::createAnnotation( ::com::sun::star::uno::Reference< ::com::sun::star::office::XAnnotation >& xAnnotation )
592 : {
593 0 : sd::createAnnotation( xAnnotation, this );
594 0 : }
595 :
596 0 : void SdPage::addAnnotation( const Reference< XAnnotation >& xAnnotation, int nIndex )
597 : {
598 0 : if( (nIndex == -1) || (nIndex > (int)maAnnotations.size()) )
599 : {
600 0 : maAnnotations.push_back( xAnnotation );
601 : }
602 : else
603 : {
604 0 : maAnnotations.insert( maAnnotations.begin() + nIndex, xAnnotation );
605 : }
606 :
607 0 : if( pModel && pModel->IsUndoEnabled() )
608 : {
609 0 : SdrUndoAction* pAction = CreateUndoInsertOrRemoveAnnotation( xAnnotation, true );
610 0 : if( pAction )
611 0 : pModel->AddUndo( pAction );
612 : }
613 :
614 0 : SetChanged();
615 :
616 0 : if( pModel )
617 : {
618 0 : pModel->SetChanged();
619 0 : NotifyDocumentEvent( static_cast< SdDrawDocument* >( pModel ), "OnAnnotationInserted" , xAnnotation );
620 : }
621 0 : }
622 :
623 0 : void SdPage::removeAnnotation( const Reference< XAnnotation >& xAnnotation )
624 : {
625 0 : if( pModel && pModel->IsUndoEnabled() )
626 : {
627 0 : SdrUndoAction* pAction = CreateUndoInsertOrRemoveAnnotation( xAnnotation, false );
628 0 : if( pAction )
629 0 : pModel->AddUndo( pAction );
630 : }
631 :
632 0 : AnnotationVector::iterator iter = std::find( maAnnotations.begin(), maAnnotations.end(), xAnnotation );
633 0 : if( iter != maAnnotations.end() )
634 0 : maAnnotations.erase( iter );
635 :
636 0 : if( pModel )
637 : {
638 0 : pModel->SetChanged();
639 0 : NotifyDocumentEvent( static_cast< SdDrawDocument* >( pModel ), OUString( "OnAnnotationRemoved" ), xAnnotation );
640 : }
641 33 : }
642 :
643 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|