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 .
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>
54 #include <drawview.hxx>
55 #include <drawdoc.hxx>
56 #include <DrawDocShell.hxx>
58 #include <ViewShellBase.hxx>
59 #include <DrawViewShell.hxx>
61 #include <sdresid.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
;
81 * Shows the first page of document at position 0,0. In the case
82 * that there is no page a page is created.
87 OutputDevice
* pOutDev
,
88 DrawViewShell
* pShell
)
89 : ::sd::View(*pDocSh
->GetDoc(), pOutDev
, pShell
)
91 ,mpDrawViewShell(pShell
)
94 SetCurrentObj(OBJ_RECT
);
102 * Virtual method from SdrView, called at selection change.
105 void DrawView::MarkListHasChanged()
107 ::sd::View::MarkListHasChanged();
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
)
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
);
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
);
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();
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();
196 mpDocSh
->GetUndoManager()->AddUndoAction(
197 std::make_unique
<StyleSheetUndoAction
>(&mrDoc
, pSheet
, &aTempSet
));
199 pSheet
->GetItemSet().Put(aTempSet
);
200 pSheet
->Broadcast(SfxHint(SfxHintId::DataChanged
));
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;
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
233 SAL_WARN_IF(!pSheet
, "sd", "StyleSheet " << aName
<< " not found");
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
);
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
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
));
262 pOutlSheet
->Broadcast(SfxHint(SfxHintId::DataChanged
));
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;
275 iter
= aSelList
.rend();
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();
292 bOk
= ::sd::View::SetAttributes(rSet
, bReplaceAll
);
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
);
308 bOk
= ::sd::View::SetAttributes(rSet
, bReplaceAll
);
311 else // not at masterpage
313 bOk
= ::sd::View::SetAttributes(rSet
, bReplaceAll
);
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();
338 mpDocSh
->GetUndoManager()->AddUndoAction(
339 std::make_unique
<StyleSheetUndoAction
>(&mrDoc
, pSheet
, &aTempSet
));
341 pSheet
->GetItemSet().Put(aTempSet
,false);
342 pSheet
->Broadcast(SfxHint(SfxHintId::DataChanged
));
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();
359 mpDocSh
->GetUndoManager()->AddUndoAction(
360 std::make_unique
<StyleSheetUndoAction
>(&mrDoc
, pSheet
, &aTempSet
));
362 pSheet
->GetItemSet().Put(aTempSet
,false);
363 pSheet
->Broadcast(SfxHint(SfxHintId::DataChanged
));
366 else if (eObjKind
== OBJ_OUTLINETEXT
)
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() );
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());
389 if( SfxItemState::SET
== rSet
.GetItemState( nWhich
) )
390 aTempSet
.ClearItem( nWhich
);
391 nWhich
= aWhichIter
.NextWhich();
397 // put the items hard into level one
398 aTempSet
.Put( rSet
);
401 aTempSet
.ClearInvalidItems();
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());
416 if( SfxItemState::SET
== rSet
.GetItemState( nWhich
) )
417 pObject
->ClearMergedItem( nWhich
);
418 nWhich
= aWhichIter
.NextWhich();
422 pObject
->SetMergedItemSet(rSet
);
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
)
477 DBG_ASSERT(mnPOCHSmph
, "counter overflow");
483 * If presentation objects are selected, intercept stylesheet-positing at
487 bool DrawView::SetStyleSheet(SfxStyleSheet
* pStyleSheet
, bool bDontRemoveHardAttr
)
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
)));
504 bResult
= ::sd::View::SetStyleSheet(pStyleSheet
, bDontRemoveHardAttr
);
509 bResult
= ::sd::View::SetStyleSheet(pStyleSheet
, bDontRemoveHardAttr
);
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
)
533 bStandardPaint
= false;
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
);
560 void DrawView::HideSdrPage()
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!?" );
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();
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() );
598 PresObjKind
ePresObjKind(pPage
->GetPresObjKind(pObj
));
599 switch( ePresObjKind
)
602 continue; // ignore it
603 case PRESOBJ_GRAPHIC
:
606 case PRESOBJ_ORGCHART
:
610 ePresObjKind
= PRESOBJ_OUTLINE
;
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
626 // Move the new PresObj to the position before the
627 // object it will replace.
628 pUndoManager
->AddUndoAction(
629 mrDoc
.GetSdrUndoFactory().CreateUndoObjectOrdNum(
631 pNewObj
->GetOrdNum(),
634 pPage
->SetObjectOrdNum( pNewObj
->GetOrdNum(), pObj
->GetOrdNum() );
642 ::sd::View::DeleteMarked();
644 if( pPage
&& bResetLayout
)
645 pPage
->SetAutoLayout( pPage
->GetAutoLayout() );
648 pUndoManager
->LeaveListAction();
651 } // end of namespace sd
653 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */