Follow up patch tdf#126067 Correct indentation.
[LibreOffice.git] / sd / source / ui / view / drawview.cxx
blob5bc53d0700fa4c7c5ee6fd4164a39185280df71b
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/svapp.hxx>
22 #include <vcl/weld.hxx>
23 #include <svx/svdpagv.hxx>
24 #include <sfx2/request.hxx>
25 #include <svl/style.hxx>
26 #include <editeng/outliner.hxx>
27 #include <svx/view3d.hxx>
28 #include <svx/svxids.hrc>
29 #include <svx/svdotext.hxx>
30 #include <svx/svdograf.hxx>
31 #include <svx/svdogrp.hxx>
32 #include <svx/svdorect.hxx>
33 #include <svl/poolitem.hxx>
34 #include <editeng/eeitem.hxx>
35 #include <editeng/bulletitem.hxx>
36 #include <svl/itempool.hxx>
37 #include <editeng/numitem.hxx>
38 #include <svl/whiter.hxx>
39 #include <sal/log.hxx>
40 #include <tools/debug.hxx>
42 #include <sfx2/viewfrm.hxx>
43 #include <sfx2/objface.hxx>
44 #include <stlsheet.hxx>
46 #include <svx/svdoutl.hxx>
47 #include <svx/svdundo.hxx>
48 #include <svx/strings.hrc>
49 #include <svx/dialmgr.hxx>
51 #include <strings.hrc>
52 #include <View.hxx>
53 #include <sdattr.hxx>
54 #include <drawview.hxx>
55 #include <drawdoc.hxx>
56 #include <DrawDocShell.hxx>
57 #include <sdpage.hxx>
58 #include <ViewShellBase.hxx>
59 #include <DrawViewShell.hxx>
60 #include <pres.hxx>
61 #include <sdresid.hxx>
62 #include <Window.hxx>
63 #include <unchss.hxx>
64 #include <FrameView.hxx>
65 #include <anminfo.hxx>
66 #include <slideshow.hxx>
67 #include <vcl/virdev.hxx>
68 #include <svx/sdrpaintwindow.hxx>
69 #include <svx/sdr/contact/viewobjectcontact.hxx>
70 #include <svx/sdr/contact/viewcontact.hxx>
71 #include <svx/sdr/contact/displayinfo.hxx>
73 #include <undo/undomanager.hxx>
75 using namespace ::com::sun::star;
77 namespace sd {
80 /**
81 * Shows the first page of document at position 0,0. In the case
82 * that there is no page a page is created.
85 DrawView::DrawView(
86 DrawDocShell* pDocSh,
87 OutputDevice* pOutDev,
88 DrawViewShell* pShell)
89 : ::sd::View(*pDocSh->GetDoc(), pOutDev, pShell)
90 ,mpDocShell(pDocSh)
91 ,mpDrawViewShell(pShell)
92 ,mnPOCHSmph(0)
94 SetCurrentObj(OBJ_RECT);
97 DrawView::~DrawView()
102 * Virtual method from SdrView, called at selection change.
105 void DrawView::MarkListHasChanged()
107 ::sd::View::MarkListHasChanged();
109 if (mpDrawViewShell)
110 mpDrawViewShell->SelectionHasChanged();
114 * Virtual method from SdrView, called at model change.
117 void DrawView::ModelHasChanged()
119 ::sd::View::ModelHasChanged();
121 // force framer to rerender
122 SfxStyleSheetBasePool* pSSPool = mrDoc.GetStyleSheetPool();
123 pSSPool->Broadcast(SfxStyleSheetPoolHint());
125 if( mpDrawViewShell )
126 mpDrawViewShell->ModelHasChanged();
131 * Redirect attributes onto title and outline text and background
132 * rectangle of a masterpage into templates, otherwise pass on baseclass.
135 bool DrawView::SetAttributes(const SfxItemSet& rSet,
136 bool bReplaceAll, bool bSlide, bool bMaster)
138 bool bOk = false;
140 if (mpDrawViewShell && bMaster)
142 SfxStyleSheetBasePool* pStShPool = mrDoc.GetStyleSheetPool();
143 SdPage& rPage = *mpDrawViewShell->getCurrentPage();
144 SdrPage& rMasterPage = rPage.TRG_GetMasterPage();
145 size_t nObjCount = rMasterPage.GetObjCount();
146 for (size_t nObj = 0; nObj < nObjCount; ++nObj)
148 SdrObject* pObject = rMasterPage.GetObj(nObj);
149 SetMasterAttributes(pObject, rPage, rSet, pStShPool, bOk, bMaster, bSlide);
151 return bOk;
153 if (mpDrawViewShell && bSlide)
155 SfxStyleSheetBasePool* pStShPool = mrDoc.GetStyleSheetPool();
156 SdPage& rPage = *mpDrawViewShell->getCurrentPage();
157 size_t nObjCount = rPage.GetObjCount();
158 for (size_t nObj = 0; nObj < nObjCount; ++nObj)
160 SdrObject* pObject = rPage.GetObj(nObj);
161 SetMasterAttributes(pObject, rPage, rSet, pStShPool, bOk, bMaster, bSlide);
163 return bOk;
166 // is there a masterpage edit?
167 if ( mpDrawViewShell && (mpDrawViewShell->GetEditMode() == EditMode::MasterPage) )
169 SfxStyleSheetBasePool* pStShPool = mrDoc.GetStyleSheetPool();
170 SdPage& rPage = *mpDrawViewShell->getCurrentPage();
171 SdrTextObj* pEditObject = GetTextEditObject();
173 if (pEditObject)
175 // Textedit
177 SdrInventor nInv = pEditObject->GetObjInventor();
179 if (nInv == SdrInventor::Default)
181 sal_uInt16 eObjKind = pEditObject->GetObjIdentifier();
182 PresObjKind ePresObjKind = rPage.GetPresObjKind(pEditObject);
184 if ( ePresObjKind == PRESOBJ_TITLE ||
185 ePresObjKind == PRESOBJ_NOTES )
187 // Presentation object (except outline)
188 SfxStyleSheet* pSheet = rPage.GetStyleSheetForPresObj( ePresObjKind );
189 DBG_ASSERT(pSheet, "StyleSheet not found");
191 SfxItemSet aTempSet( pSheet->GetItemSet() );
192 aTempSet.Put( rSet );
193 aTempSet.ClearInvalidItems();
195 // Undo-Action
196 mpDocSh->GetUndoManager()->AddUndoAction(
197 std::make_unique<StyleSheetUndoAction>(&mrDoc, pSheet, &aTempSet));
199 pSheet->GetItemSet().Put(aTempSet);
200 pSheet->Broadcast(SfxHint(SfxHintId::DataChanged));
201 bOk = true;
203 else if (eObjKind == OBJ_OUTLINETEXT)
205 // Presentation object outline
206 OutlinerView* pOV = GetTextEditOutlinerView();
207 ::Outliner* pOutliner = pOV->GetOutliner();
209 pOutliner->SetUpdateMode(false);
210 mpDocSh->SetWaitCursor( true );
212 // replace placeholder by template name
213 OUString aComment(SdResId(STR_UNDO_CHANGE_PRES_OBJECT));
214 aComment = aComment.replaceFirst("$", SdResId(STR_PSEUDOSHEET_OUTLINE));
215 mpDocSh->GetUndoManager()->EnterListAction( aComment, OUString(), 0, mpDrawViewShell->GetViewShellBase().GetViewShellId() );
217 std::vector<Paragraph*> aSelList;
218 pOV->CreateSelectionList(aSelList);
220 std::vector<Paragraph*>::reverse_iterator iter = aSelList.rbegin();
221 Paragraph* pPara = iter != aSelList.rend() ? *iter : nullptr;
223 while (pPara)
225 sal_Int32 nParaPos = pOutliner->GetAbsPos( pPara );
226 sal_Int16 nDepth = pOutliner->GetDepth( nParaPos );
227 OUString aName = rPage.GetLayoutName() + " " +
228 OUString::number((nDepth <= 0) ? 1 : nDepth + 1);
229 SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>(pStShPool->Find(aName, SfxStyleFamily::Page));
230 //We have no stylesheet if we access outline level 10
231 //in the master preview, there is no true style backing
232 //that entry
233 SAL_WARN_IF(!pSheet, "sd", "StyleSheet " << aName << " not found");
234 if (pSheet)
236 SfxItemSet aTempSet( pSheet->GetItemSet() );
237 aTempSet.Put( rSet );
238 aTempSet.ClearInvalidItems();
240 if( nDepth > 0 && aTempSet.GetItemState( EE_PARA_NUMBULLET ) == SfxItemState::SET )
242 // no SvxNumBulletItem in outline level 1 to 8!
243 aTempSet.ClearItem( EE_PARA_NUMBULLET );
246 // Undo-Action
247 mpDocSh->GetUndoManager()->AddUndoAction(
248 std::make_unique<StyleSheetUndoAction>(&mrDoc, pSheet, &aTempSet));
250 pSheet->GetItemSet().Put(aTempSet);
251 pSheet->Broadcast(SfxHint(SfxHintId::DataChanged));
253 // now also broadcast any child sheets
254 sal_Int16 nChild;
255 for( nChild = nDepth + 1; nChild < 9; nChild++ )
257 OUString aSheetName = rPage.GetLayoutName() + " " +
258 OUString::number((nChild <= 0) ? 1 : nChild + 1);
259 SfxStyleSheet* pOutlSheet = static_cast< SfxStyleSheet* >(pStShPool->Find(aSheetName, SfxStyleFamily::Page));
261 if( pOutlSheet )
262 pOutlSheet->Broadcast(SfxHint(SfxHintId::DataChanged));
266 ++iter;
267 pPara = iter != aSelList.rend() ? *iter : nullptr;
269 bool bJumpToLevel1 = false;
270 if( !pPara && nDepth > 0 && rSet.GetItemState( EE_PARA_NUMBULLET ) == SfxItemState::SET )
271 bJumpToLevel1 = true;
273 if (bJumpToLevel1)
275 iter = aSelList.rend();
276 --iter;
278 if (pOutliner->GetDepth(pOutliner->GetAbsPos(*iter)) > 0)
279 pPara = pOutliner->GetParagraph( 0 ); // Put NumBulletItem in outline level 1
283 mpDocSh->SetWaitCursor( false );
284 pOV->GetOutliner()->SetUpdateMode(true);
286 mpDocSh->GetUndoManager()->LeaveListAction();
288 bOk = true;
290 else
292 bOk = ::sd::View::SetAttributes(rSet, bReplaceAll);
296 else
298 // Selection
299 const SdrMarkList& rList = GetMarkedObjectList();
300 const size_t nMarkCount = rList.GetMarkCount();
301 for (size_t nMark = 0; nMark < nMarkCount; ++nMark)
303 SdrObject* pObject = rList.GetMark(nMark)->GetMarkedSdrObj();
304 SetMasterAttributes(pObject, rPage, rSet, pStShPool, bOk, bMaster, bSlide);
307 if(!bOk)
308 bOk = ::sd::View::SetAttributes(rSet, bReplaceAll);
311 else // not at masterpage
313 bOk = ::sd::View::SetAttributes(rSet, bReplaceAll);
316 return bOk;
319 void DrawView::SetMasterAttributes( SdrObject* pObject, SdPage& rPage, SfxItemSet rSet, SfxStyleSheetBasePool* pStShPool, bool& bOk, bool bMaster, bool bSlide )
321 SdrInventor nInv = pObject->GetObjInventor();
323 if (nInv == SdrInventor::Default)
325 sal_uInt16 eObjKind = pObject->GetObjIdentifier();
326 PresObjKind ePresObjKind = rPage.GetPresObjKind(pObject);
327 if (bSlide && eObjKind == OBJ_TEXT)
329 // Presentation object (except outline)
330 SfxStyleSheet* pSheet = rPage.GetTextStyleSheetForObject(pObject);
331 DBG_ASSERT(pSheet, "StyleSheet not found");
333 SfxItemSet aTempSet( pSheet->GetItemSet() );
334 aTempSet.Put( rSet );
335 aTempSet.ClearInvalidItems();
337 // Undo-Action
338 mpDocSh->GetUndoManager()->AddUndoAction(
339 std::make_unique<StyleSheetUndoAction>(&mrDoc, pSheet, &aTempSet));
341 pSheet->GetItemSet().Put(aTempSet,false);
342 pSheet->Broadcast(SfxHint(SfxHintId::DataChanged));
343 bOk = true;
346 if (!bSlide &&
347 (ePresObjKind == PRESOBJ_TITLE ||
348 ePresObjKind == PRESOBJ_NOTES))
350 // Presentation object (except outline)
351 SfxStyleSheet* pSheet = rPage.GetStyleSheetForPresObj( ePresObjKind );
352 DBG_ASSERT(pSheet, "StyleSheet not found");
354 SfxItemSet aTempSet( pSheet->GetItemSet() );
355 aTempSet.Put( rSet );
356 aTempSet.ClearInvalidItems();
358 // Undo-Action
359 mpDocSh->GetUndoManager()->AddUndoAction(
360 std::make_unique<StyleSheetUndoAction>(&mrDoc, pSheet, &aTempSet));
362 pSheet->GetItemSet().Put(aTempSet,false);
363 pSheet->Broadcast(SfxHint(SfxHintId::DataChanged));
364 bOk = true;
366 else if (eObjKind == OBJ_OUTLINETEXT)
368 if (bMaster)
370 // Presentation object outline
371 for (sal_uInt16 nLevel = 9; nLevel > 0; nLevel--)
373 OUString aName = rPage.GetLayoutName() + " " +
374 OUString::number(nLevel);
375 SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>(pStShPool->
376 Find(aName, SfxStyleFamily::Page));
377 DBG_ASSERT(pSheet, "StyleSheet not found");
379 SfxItemSet aTempSet( pSheet->GetItemSet() );
381 if( nLevel > 1 )
383 // for all levels over 1, clear all items that will be
384 // hard set to level 1
385 SfxWhichIter aWhichIter(rSet);
386 sal_uInt16 nWhich(aWhichIter.FirstWhich());
387 while( nWhich )
389 if( SfxItemState::SET == rSet.GetItemState( nWhich ) )
390 aTempSet.ClearItem( nWhich );
391 nWhich = aWhichIter.NextWhich();
395 else
397 // put the items hard into level one
398 aTempSet.Put( rSet );
401 aTempSet.ClearInvalidItems();
403 // Undo-Action
404 mpDocSh->GetUndoManager()->AddUndoAction(
405 std::make_unique<StyleSheetUndoAction>(&mrDoc, pSheet, &aTempSet));
407 pSheet->GetItemSet().Set(aTempSet,false);
408 pSheet->Broadcast(SfxHint(SfxHintId::DataChanged));
411 // remove all hard set items from shape that are now set in style
412 SfxWhichIter aWhichIter(rSet);
413 sal_uInt16 nWhich(aWhichIter.FirstWhich());
414 while( nWhich )
416 if( SfxItemState::SET == rSet.GetItemState( nWhich ) )
417 pObject->ClearMergedItem( nWhich );
418 nWhich = aWhichIter.NextWhich();
421 else
422 pObject->SetMergedItemSet(rSet);
424 bOk = true;
430 * Notify for change of site arrangement
433 void DrawView::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
435 if ( mpDrawViewShell && rHint.GetId() == SfxHintId::ThisIsAnSdrHint )
437 SdrHintKind eHintKind = static_cast<const SdrHint&>(rHint).GetKind();
439 if ( mnPOCHSmph == 0 && eHintKind == SdrHintKind::PageOrderChange )
441 mpDrawViewShell->ResetActualPage();
443 else if ( eHintKind == SdrHintKind::LayerChange || eHintKind == SdrHintKind::LayerOrderChange )
445 mpDrawViewShell->ResetActualLayer();
448 // switch to that page when it's not a master page
449 if(SdrHintKind::SwitchToPage == eHintKind)
451 const SdrPage* pPage = static_cast<const SdrHint&>(rHint).GetPage();
453 if(pPage && !pPage->IsMasterPage())
455 if(mpDrawViewShell->GetActualPage() != pPage)
457 sal_uInt16 nPageNum = (pPage->GetPageNum() - 1) / 2; // Sdr --> Sd
458 mpDrawViewShell->SwitchPage(nPageNum);
464 ::sd::View::Notify(rBC, rHint);
468 * Lock/Unlock PageOrderChangedHint
471 void DrawView::BlockPageOrderChangedHint(bool bBlock)
473 if (bBlock)
474 mnPOCHSmph++;
475 else
477 DBG_ASSERT(mnPOCHSmph, "counter overflow");
478 mnPOCHSmph--;
483 * If presentation objects are selected, intercept stylesheet-positing at
484 * masterpage.
487 bool DrawView::SetStyleSheet(SfxStyleSheet* pStyleSheet, bool bDontRemoveHardAttr)
489 bool bResult = true;
491 // is there a masterpage edit?
492 if (mpDrawViewShell && mpDrawViewShell->GetEditMode() == EditMode::MasterPage)
494 if (IsPresObjSelected(false))
496 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(mpDrawViewShell->GetFrameWeld(),
497 VclMessageType::Info, VclButtonsType::Ok,
498 SdResId(STR_ACTION_NOTPOSSIBLE)));
499 xInfoBox->run();
500 bResult = false;
502 else
504 bResult = ::sd::View::SetStyleSheet(pStyleSheet, bDontRemoveHardAttr);
507 else
509 bResult = ::sd::View::SetStyleSheet(pStyleSheet, bDontRemoveHardAttr);
511 return bResult;
515 * Paint-method: Redirect event to the view
518 void DrawView::CompleteRedraw(OutputDevice* pOutDev, const vcl::Region& rReg, sdr::contact::ViewObjectContactRedirector* pRedirector /*=0*/)
520 bool bStandardPaint = true;
522 SdDrawDocument* pDoc = mpDocShell->GetDoc();
523 if( pDoc && pDoc->GetDocumentType() == DocumentType::Impress)
525 rtl::Reference< sd::SlideShow > xSlideshow( SlideShow::GetSlideShow( pDoc ) );
526 if(xSlideshow.is() && xSlideshow->isRunning())
528 OutputDevice* pShowWindow = xSlideshow->getShowWindow();
529 if( (pShowWindow == pOutDev) || (xSlideshow->getAnimationMode() == ANIMATIONMODE_PREVIEW) )
531 if( pShowWindow == pOutDev && mpViewSh )
532 xSlideshow->paint();
533 bStandardPaint = false;
538 if(bStandardPaint)
540 ::sd::View::CompleteRedraw(pOutDev, rReg, pRedirector);
545 * Make passed region visible (scrolling if necessary)
548 void DrawView::MakeVisible(const ::tools::Rectangle& rRect, vcl::Window& rWin)
550 if (!rRect.IsEmpty() && mpDrawViewShell)
552 mpDrawViewShell->MakeVisible(rRect, rWin);
557 * Hide page.
560 void DrawView::HideSdrPage()
562 if (mpDrawViewShell)
564 mpDrawViewShell->HidePage();
567 ::sd::View::HideSdrPage();
570 void DrawView::DeleteMarked()
572 sd::UndoManager* pUndoManager = mrDoc.GetUndoManager();
573 DBG_ASSERT( pUndoManager, "sd::DrawView::DeleteMarked(), ui action without undo manager!?" );
575 if( pUndoManager )
577 OUString aUndo(SvxResId(STR_EditDelete));
578 aUndo = aUndo.replaceFirst("%1", GetDescriptionOfMarkedObjects());
579 ViewShellId nViewShellId = mpDrawViewShell ? mpDrawViewShell->GetViewShellBase().GetViewShellId() : ViewShellId(-1);
580 pUndoManager->EnterListAction(aUndo, aUndo, 0, nViewShellId);
583 SdPage* pPage = nullptr;
584 bool bResetLayout = false;
586 const size_t nMarkCount = GetMarkedObjectList().GetMarkCount();
587 if( nMarkCount )
589 SdrMarkList aList( GetMarkedObjectList() );
590 for (size_t nMark = 0; nMark < nMarkCount; ++nMark)
592 SdrObject* pObj = aList.GetMark(nMark)->GetMarkedSdrObj();
593 if( pObj && !pObj->IsEmptyPresObj() && pObj->GetUserCall() )
595 pPage = static_cast< SdPage* >( pObj->getSdrPageFromSdrObject() );
596 if (pPage)
598 PresObjKind ePresObjKind(pPage->GetPresObjKind(pObj));
599 switch( ePresObjKind )
601 case PRESOBJ_NONE:
602 continue; // ignore it
603 case PRESOBJ_GRAPHIC:
604 case PRESOBJ_OBJECT:
605 case PRESOBJ_CHART:
606 case PRESOBJ_ORGCHART:
607 case PRESOBJ_TABLE:
608 case PRESOBJ_CALC:
609 case PRESOBJ_MEDIA:
610 ePresObjKind = PRESOBJ_OUTLINE;
611 break;
612 default:
613 break;
615 SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( pObj );
616 bool bVertical = pTextObj && pTextObj->IsVerticalWriting();
617 ::tools::Rectangle aRect( pObj->GetLogicRect() );
618 SdrObject* pNewObj = pPage->InsertAutoLayoutShape( nullptr, ePresObjKind, bVertical, aRect, true );
620 // pUndoManager should not be NULL (see assert above)
621 // but since we have defensive code
622 // for it earlier and later in the function
623 // we might as well be consistent
624 if(pUndoManager)
626 // Move the new PresObj to the position before the
627 // object it will replace.
628 pUndoManager->AddUndoAction(
629 mrDoc.GetSdrUndoFactory().CreateUndoObjectOrdNum(
630 *pNewObj,
631 pNewObj->GetOrdNum(),
632 pObj->GetOrdNum()));
634 pPage->SetObjectOrdNum( pNewObj->GetOrdNum(), pObj->GetOrdNum() );
636 bResetLayout = true;
642 ::sd::View::DeleteMarked();
644 if( pPage && bResetLayout )
645 pPage->SetAutoLayout( pPage->GetAutoLayout() );
647 if( pUndoManager )
648 pUndoManager->LeaveListAction();
651 } // end of namespace sd
653 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */