bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / view / drawview.cxx
blobae2f99c74e4f3cfd74d21317194c45041cdbb39f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <sfx2/dispatch.hxx>
21 #include <vcl/msgbox.hxx>
22 #include <svx/svdpagv.hxx>
23 #include <sfx2/request.hxx>
24 #include <svl/style.hxx>
25 #include <editeng/outliner.hxx>
26 #include <svx/view3d.hxx>
27 #include <svx/svxids.hrc>
28 #include <svx/svdotext.hxx>
29 #include <svx/svdograf.hxx>
30 #include <svx/svdogrp.hxx>
31 #include <svx/svdorect.hxx>
32 #include <svl/poolitem.hxx>
33 #include <editeng/eeitem.hxx>
34 #include <editeng/bulletitem.hxx>
35 #include <svl/itempool.hxx>
36 #include <editeng/numitem.hxx>
37 #include <svl/whiter.hxx>
39 #include <sfx2/viewfrm.hxx>
40 #include <sfx2/objface.hxx>
41 #include "stlsheet.hxx"
43 #include <svx/svdoutl.hxx>
44 #include <svx/svdstr.hrc>
45 #include <svx/dialmgr.hxx>
47 #include "glob.hrc"
48 #include "strings.hrc"
49 #include "View.hxx"
50 #include "sdattr.hxx"
51 #include "drawview.hxx"
52 #include "drawdoc.hxx"
53 #include "DrawDocShell.hxx"
54 #include "sdpage.hxx"
55 #include "DrawViewShell.hxx"
56 #include "pres.hxx"
57 #include "sdresid.hxx"
58 #include "Window.hxx"
59 #include "unchss.hxx"
60 #include "FrameView.hxx"
61 #include "anminfo.hxx"
62 #include "slideshow.hxx"
63 #include <vcl/virdev.hxx>
64 #include <svx/sdrpaintwindow.hxx>
65 #include <svx/sdr/contact/viewobjectcontact.hxx>
66 #include <svx/sdr/contact/viewcontact.hxx>
67 #include <svx/sdr/contact/displayinfo.hxx>
69 #include "undo/undomanager.hxx"
71 using namespace ::com::sun::star;
73 namespace sd {
75 TYPEINIT1(DrawView, View);
77 /**
78 * Shows the first page of document at position 0,0. In the case
79 * that there is no page a page is created.
82 DrawView::DrawView( DrawDocShell* pDocSh, OutputDevice* pOutDev, DrawViewShell* pShell)
83 : ::sd::View(*pDocSh->GetDoc(), pOutDev, pShell)
84 , mpDocShell(pDocSh)
85 , mpDrawViewShell(pShell)
86 , mpVDev(NULL)
87 , mnPOCHSmph(0)
89 SetCurrentObj(OBJ_RECT, SdrInventor);
92 DrawView::~DrawView()
94 mpVDev.disposeAndClear();
97 /**
98 * Virtual method from SdrView, called at selection change.
101 void DrawView::MarkListHasChanged()
103 ::sd::View::MarkListHasChanged();
105 if (mpDrawViewShell)
106 mpDrawViewShell->SelectionHasChanged();
110 * Virtual method from SdrView, called at model change.
113 void DrawView::ModelHasChanged()
115 ::sd::View::ModelHasChanged();
117 // force framer to rerender
118 SfxStyleSheetBasePool* pSSPool = mrDoc.GetStyleSheetPool();
119 pSSPool->Broadcast(SfxStyleSheetPoolHint(SfxStyleSheetHintId::CREATED));
121 if( mpDrawViewShell )
122 mpDrawViewShell->ModelHasChanged();
127 * Redirect attributes onto title and outline text and background
128 * rectangle of a masterpage into templates, otherwise pass on baseclass.
131 bool DrawView::SetAttributes(const SfxItemSet& rSet,
132 bool bReplaceAll)
134 bool bOk = false;
136 // is there a masterpage edit?
137 if ( mpDrawViewShell && mpDrawViewShell->GetEditMode() == EM_MASTERPAGE )
139 SfxStyleSheetBasePool* pStShPool = mrDoc.GetStyleSheetPool();
140 SdPage& rPage = *mpDrawViewShell->getCurrentPage();
141 SdrTextObj* pEditObject = static_cast< SdrTextObj* >( GetTextEditObject() );
143 if (pEditObject)
145 // Textedit
147 sal_uInt32 nInv = pEditObject->GetObjInventor();
149 if (nInv == SdrInventor)
151 sal_uInt16 eObjKind = pEditObject->GetObjIdentifier();
152 PresObjKind ePresObjKind = rPage.GetPresObjKind(pEditObject);
154 if ( ePresObjKind == PRESOBJ_TITLE ||
155 ePresObjKind == PRESOBJ_NOTES )
157 // Presentation object (except outline)
158 SfxStyleSheet* pSheet = rPage.GetStyleSheetForPresObj( ePresObjKind );
159 DBG_ASSERT(pSheet, "StyleSheet not found");
161 SfxItemSet aTempSet( pSheet->GetItemSet() );
162 aTempSet.Put( rSet );
163 aTempSet.ClearInvalidItems();
165 // Undo-Action
166 StyleSheetUndoAction* pAction = new StyleSheetUndoAction(&mrDoc, pSheet, &aTempSet);
167 mpDocSh->GetUndoManager()->AddUndoAction(pAction);
169 pSheet->GetItemSet().Put(aTempSet);
170 pSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
171 bOk = true;
173 else if (eObjKind == OBJ_OUTLINETEXT)
175 // Presentation object outline
176 OutlinerView* pOV = GetTextEditOutlinerView();
177 ::Outliner* pOutliner = pOV->GetOutliner();
179 pOutliner->SetUpdateMode(false);
180 mpDocSh->SetWaitCursor( true );
182 // replace placeholder by template name
183 OUString aComment(SD_RESSTR(STR_UNDO_CHANGE_PRES_OBJECT));
184 aComment = aComment.replaceFirst("$", SD_RESSTR(STR_PSEUDOSHEET_OUTLINE));
185 mpDocSh->GetUndoManager()->EnterListAction( aComment, OUString() );
187 std::vector<Paragraph*> aSelList;
188 pOV->CreateSelectionList(aSelList);
190 std::vector<Paragraph*>::reverse_iterator iter = aSelList.rbegin();
191 Paragraph* pPara = iter != aSelList.rend() ? *iter : NULL;
193 while (pPara)
195 sal_Int32 nParaPos = pOutliner->GetAbsPos( pPara );
196 sal_Int16 nDepth = pOutliner->GetDepth( nParaPos );
197 OUString aName = rPage.GetLayoutName() + " " +
198 OUString::number((nDepth <= 0) ? 1 : nDepth + 1);
199 SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>(pStShPool->Find(aName, SD_STYLE_FAMILY_MASTERPAGE));
200 //We have no stylesheet if we access outline level 10
201 //in the master preview, there is no true style backing
202 //that entry
203 SAL_WARN_IF(!pSheet, "sd", "StyleSheet " << aName << " not found");
204 if (pSheet)
206 SfxItemSet aTempSet( pSheet->GetItemSet() );
207 aTempSet.Put( rSet );
208 aTempSet.ClearInvalidItems();
210 if( nDepth > 0 && aTempSet.GetItemState( EE_PARA_NUMBULLET ) == SfxItemState::SET )
212 // no SvxNumBulletItem in outline level 1 to 8!
213 aTempSet.ClearItem( EE_PARA_NUMBULLET );
216 // Undo-Action
217 StyleSheetUndoAction* pAction = new StyleSheetUndoAction(&mrDoc, pSheet, &aTempSet);
218 mpDocSh->GetUndoManager()->AddUndoAction(pAction);
220 pSheet->GetItemSet().Put(aTempSet);
221 pSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
223 // now also broadcast any child sheets
224 sal_Int16 nChild;
225 for( nChild = nDepth + 1; nChild < 9; nChild++ )
227 OUString aSheetName = rPage.GetLayoutName() + " " +
228 OUString::number((nChild <= 0) ? 1 : nChild + 1);
229 SfxStyleSheet* pOutlSheet = static_cast< SfxStyleSheet* >(pStShPool->Find(aSheetName, SD_STYLE_FAMILY_MASTERPAGE));
231 if( pOutlSheet )
232 pOutlSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
236 ++iter;
237 pPara = iter != aSelList.rend() ? *iter : NULL;
239 bool bJumpToLevel1 = false;
240 if( !pPara && nDepth > 0 && rSet.GetItemState( EE_PARA_NUMBULLET ) == SfxItemState::SET )
241 bJumpToLevel1 = true;
243 if (bJumpToLevel1)
245 iter = aSelList.rend();
246 --iter;
248 if (pOutliner->GetDepth(pOutliner->GetAbsPos(*iter)) > 0)
249 pPara = pOutliner->GetParagraph( 0 ); // Put NumBulletItem in outline level 1
253 mpDocSh->SetWaitCursor( false );
254 pOV->GetOutliner()->SetUpdateMode(true);
256 mpDocSh->GetUndoManager()->LeaveListAction();
258 bOk = true;
260 else
262 bOk = ::sd::View::SetAttributes(rSet, bReplaceAll);
266 else
268 // Selection
269 const SdrMarkList& rList = GetMarkedObjectList();
270 const size_t nMarkCount = rList.GetMarkCount();
271 for (size_t nMark = 0; nMark < nMarkCount; ++nMark)
273 SdrObject* pObject = rList.GetMark(nMark)->GetMarkedSdrObj();
274 sal_uInt32 nInv = pObject->GetObjInventor();
276 if (nInv == SdrInventor)
278 sal_uInt16 eObjKind = pObject->GetObjIdentifier();
279 PresObjKind ePresObjKind = rPage.GetPresObjKind(pObject);
281 if (ePresObjKind == PRESOBJ_TITLE ||
282 ePresObjKind == PRESOBJ_NOTES)
284 // Presentation object (except outline)
285 SfxStyleSheet* pSheet = rPage.GetStyleSheetForPresObj( ePresObjKind );
286 DBG_ASSERT(pSheet, "StyleSheet not found");
288 SfxItemSet aTempSet( pSheet->GetItemSet() );
289 aTempSet.Put( rSet );
290 aTempSet.ClearInvalidItems();
292 // Undo-Action
293 StyleSheetUndoAction* pAction = new StyleSheetUndoAction(&mrDoc, pSheet, &aTempSet);
294 mpDocSh->GetUndoManager()->AddUndoAction(pAction);
296 pSheet->GetItemSet().Put(aTempSet,false);
297 pSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
298 bOk = true;
300 else if (eObjKind == OBJ_OUTLINETEXT)
302 // Presentation object outline
303 for (sal_uInt16 nLevel = 9; nLevel > 0; nLevel--)
305 OUString aName = rPage.GetLayoutName() + " " +
306 OUString::number(nLevel);
307 SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>(pStShPool->
308 Find(aName, SD_STYLE_FAMILY_MASTERPAGE));
309 DBG_ASSERT(pSheet, "StyleSheet not found");
311 SfxItemSet aTempSet( pSheet->GetItemSet() );
313 if( nLevel > 1 )
315 // for all levels over 1, clear all items that will be
316 // hard set to level 1
317 SfxWhichIter aWhichIter(rSet);
318 sal_uInt16 nWhich(aWhichIter.FirstWhich());
319 while( nWhich )
321 if( SfxItemState::SET == rSet.GetItemState( nWhich ) )
322 aTempSet.ClearItem( nWhich );
323 nWhich = aWhichIter.NextWhich();
327 else
329 // put the items hard into level one
330 aTempSet.Put( rSet );
333 aTempSet.ClearInvalidItems();
335 // Undo-Action
336 StyleSheetUndoAction* pAction = new StyleSheetUndoAction(&mrDoc, pSheet, &aTempSet);
337 mpDocSh->GetUndoManager()->AddUndoAction(pAction);
339 pSheet->GetItemSet().Set(aTempSet,false);
340 pSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED));
343 // remove all hard set items from shape that are now set in style
344 SfxWhichIter aWhichIter(rSet);
345 sal_uInt16 nWhich(aWhichIter.FirstWhich());
346 while( nWhich )
348 if( SfxItemState::SET == rSet.GetItemState( nWhich ) )
349 pObject->ClearMergedItem( nWhich );
350 nWhich = aWhichIter.NextWhich();
353 bOk = true;
358 if(!bOk)
359 bOk = ::sd::View::SetAttributes(rSet, bReplaceAll);
362 else // not at masterpage
364 bOk = ::sd::View::SetAttributes(rSet, bReplaceAll);
367 return bOk;
371 * Notify for change of site arragement
374 void DrawView::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
376 if ( mpDrawViewShell && dynamic_cast<const SdrHint*>(&rHint) )
378 SdrHintKind eHintKind = static_cast<const SdrHint&>(rHint).GetKind();
380 if ( mnPOCHSmph == 0 && eHintKind == HINT_PAGEORDERCHG )
382 mpDrawViewShell->ResetActualPage();
384 else if ( eHintKind == HINT_LAYERCHG || eHintKind == HINT_LAYERORDERCHG )
386 mpDrawViewShell->ResetActualLayer();
389 // switch to that page when it's not a master page
390 if(HINT_SWITCHTOPAGE == eHintKind)
392 const SdrPage* pPage = static_cast<const SdrHint&>(rHint).GetPage();
394 if(pPage && !pPage->IsMasterPage())
396 if(mpDrawViewShell->GetActualPage() != pPage)
398 sal_uInt16 nPageNum = (pPage->GetPageNum() - 1) / 2; // Sdr --> Sd
399 mpDrawViewShell->SwitchPage(nPageNum);
405 ::sd::View::Notify(rBC, rHint);
409 * Lock/Unlock PageOrderChangedHint
412 void DrawView::BlockPageOrderChangedHint(bool bBlock)
414 if (bBlock)
415 mnPOCHSmph++;
416 else
418 DBG_ASSERT(mnPOCHSmph, "counter overflow");
419 mnPOCHSmph--;
424 * If presentation objects are selected, intercept stylesheet-positing at
425 * masterpage.
428 bool DrawView::SetStyleSheet(SfxStyleSheet* pStyleSheet, bool bDontRemoveHardAttr)
430 bool bResult = true;
432 // is there a masterpage edit?
433 if (mpDrawViewShell && mpDrawViewShell->GetEditMode() == EM_MASTERPAGE)
435 if (IsPresObjSelected(false, true))
437 ScopedVclPtr<InfoBox>::Create(mpDrawViewShell->GetActiveWindow(),
438 SD_RESSTR(STR_ACTION_NOTPOSSIBLE))->Execute();
439 bResult = false;
441 else
443 bResult = ::sd::View::SetStyleSheet(pStyleSheet, bDontRemoveHardAttr);
446 else
448 bResult = ::sd::View::SetStyleSheet(pStyleSheet, bDontRemoveHardAttr);
450 return bResult;
454 * Paint-method: Redirect event to the view
457 void DrawView::CompleteRedraw(OutputDevice* pOutDev, const vcl::Region& rReg, sdr::contact::ViewObjectContactRedirector* pRedirector /*=0L*/)
459 if( mpVDev )
461 mpVDev.disposeAndClear();
464 bool bStandardPaint = true;
466 SdDrawDocument* pDoc = mpDocShell->GetDoc();
467 if( pDoc && pDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS)
469 rtl::Reference< sd::SlideShow > xSlideshow( SlideShow::GetSlideShow( pDoc ) );
470 if(xSlideshow.is() && xSlideshow->isRunning())
472 OutputDevice* pShowWindow = xSlideshow->getShowWindow();
473 if( (pShowWindow == pOutDev) || (xSlideshow->getAnimationMode() == ANIMATIONMODE_PREVIEW) )
475 if( pShowWindow == pOutDev )
476 PresPaint(rReg);
477 bStandardPaint = false;
482 if(bStandardPaint)
484 ::sd::View::CompleteRedraw(pOutDev, rReg, pRedirector);
489 * Paint-Event during running slide show
492 void DrawView::PresPaint(const vcl::Region& rRegion)
494 if(mpViewSh)
496 rtl::Reference< SlideShow > xSlideshow( SlideShow::GetSlideShow( GetDoc() ) );
497 if( xSlideshow.is() && xSlideshow->isRunning() )
498 xSlideshow->paint( rRegion.GetBoundRect() );
503 * Decides if an object could get marked (eg. unreleased animation objects
504 * in slide show).
507 bool DrawView::IsObjMarkable(SdrObject* pObj, SdrPageView* pPV) const
509 return FmFormView::IsObjMarkable(pObj, pPV);
513 * Make passed region visible (scrolling if necessary)
516 void DrawView::MakeVisible(const Rectangle& rRect, vcl::Window& rWin)
518 if (!rRect.IsEmpty() && mpDrawViewShell)
520 mpDrawViewShell->MakeVisible(rRect, rWin);
525 * Hide page.
528 void DrawView::HideSdrPage()
530 if (mpDrawViewShell)
532 mpDrawViewShell->HidePage();
535 ::sd::View::HideSdrPage();
538 void DrawView::DeleteMarked()
540 OSL_TRACE( "DrawView::DeleteMarked() - enter" );
542 sd::UndoManager* pUndoManager = mrDoc.GetUndoManager();
543 DBG_ASSERT( pUndoManager, "sd::DrawView::DeleteMarked(), ui action without undo manager!?" );
545 if( pUndoManager )
547 OUString aUndo(SVX_RESSTR(STR_EditDelete));
548 aUndo = aUndo.replaceFirst("%1", GetDescriptionOfMarkedObjects());
549 pUndoManager->EnterListAction(aUndo, aUndo);
552 SdPage* pPage = 0;
553 bool bResetLayout = false;
555 const size_t nMarkCount = GetMarkedObjectList().GetMarkCount();
556 if( nMarkCount )
558 SdrMarkList aList( GetMarkedObjectList() );
559 for (size_t nMark = 0; nMark < nMarkCount; ++nMark)
561 SdrObject* pObj = aList.GetMark(nMark)->GetMarkedSdrObj();
562 if( pObj && !pObj->IsEmptyPresObj() && pObj->GetUserCall() )
564 pPage = static_cast< SdPage* >( pObj->GetPage() );
565 PresObjKind ePresObjKind;
566 if( pPage && ((ePresObjKind = pPage->GetPresObjKind(pObj)) != PRESOBJ_NONE))
568 switch( ePresObjKind )
570 case PRESOBJ_GRAPHIC:
571 case PRESOBJ_OBJECT:
572 case PRESOBJ_CHART:
573 case PRESOBJ_ORGCHART:
574 case PRESOBJ_TABLE:
575 case PRESOBJ_CALC:
576 case PRESOBJ_IMAGE:
577 case PRESOBJ_MEDIA:
578 ePresObjKind = PRESOBJ_OUTLINE;
579 break;
580 default:
581 break;
583 SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( pObj );
584 bool bVertical = pTextObj && pTextObj->IsVerticalWriting();
585 Rectangle aRect( pObj->GetLogicRect() );
586 SdrObject* pNewObj = pPage->InsertAutoLayoutShape( 0, ePresObjKind, bVertical, aRect, true );
588 // pUndoManager should not be NULL (see assert above)
589 // but since we have defensive code
590 // for it earlier and later in the function
591 // we might as well be consistent
592 if(pUndoManager)
594 // Move the new PresObj to the position before the
595 // object it will replace.
596 pUndoManager->AddUndoAction(
597 mrDoc.GetSdrUndoFactory().CreateUndoObjectOrdNum(
598 *pNewObj,
599 pNewObj->GetOrdNum(),
600 pObj->GetOrdNum()));
602 pPage->SetObjectOrdNum( pNewObj->GetOrdNum(), pObj->GetOrdNum() );
604 bResetLayout = true;
606 OSL_TRACE( "DrawView::InsertAutoLayoutShape() - InsertAutoLayoutShape" );
612 ::sd::View::DeleteMarked();
614 if( pPage && bResetLayout )
615 pPage->SetAutoLayout( pPage->GetAutoLayout() );
617 if( pUndoManager )
618 pUndoManager->LeaveListAction();
620 OSL_TRACE( "DrawView::InsertAutoLayoutShape() - leave" );
623 } // end of namespace sd
625 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */