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 <vcl/svapp.hxx>
21 #include <vcl/weld.hxx>
22 #include <svl/style.hxx>
23 #include <editeng/outliner.hxx>
24 #include <svx/svdotext.hxx>
25 #include <svl/poolitem.hxx>
26 #include <editeng/eeitem.hxx>
27 #include <svl/whiter.hxx>
28 #include <sal/log.hxx>
29 #include <tools/debug.hxx>
31 #include <svx/svdundo.hxx>
32 #include <svx/strings.hrc>
33 #include <svx/dialmgr.hxx>
35 #include <strings.hrc>
37 #include <drawview.hxx>
38 #include <drawdoc.hxx>
39 #include <DrawDocShell.hxx>
41 #include <ViewShellBase.hxx>
42 #include <DrawViewShell.hxx>
44 #include <sdresid.hxx>
46 #include <slideshow.hxx>
48 #include <undo/undomanager.hxx>
50 using namespace ::com::sun::star
;
56 * Shows the first page of document at position 0,0. In the case
57 * that there is no page a page is created.
62 OutputDevice
* pOutDev
,
63 DrawViewShell
* pShell
)
64 : ::sd::View(*pDocSh
->GetDoc(), pOutDev
, pShell
)
65 ,mpDrawViewShell(pShell
)
68 SetCurrentObj(SdrObjKind::Rectangle
);
76 * Virtual method from SdrView, called at selection change.
79 void DrawView::MarkListHasChanged()
81 ::sd::View::MarkListHasChanged();
84 mpDrawViewShell
->SelectionHasChanged();
88 * Virtual method from SdrView, called at model change.
91 void DrawView::ModelHasChanged()
93 ::sd::View::ModelHasChanged();
95 // force framer to rerender
96 SfxStyleSheetBasePool
* pSSPool
= mrDoc
.GetStyleSheetPool();
97 pSSPool
->Broadcast(SfxStyleSheetPoolHint());
100 mpDrawViewShell
->ModelHasChanged();
105 * Redirect attributes onto title and outline text and background
106 * rectangle of a masterpage into templates, otherwise pass on baseclass.
109 bool DrawView::SetAttributes(const SfxItemSet
& rSet
,
110 bool bReplaceAll
, bool bSlide
, bool bMaster
)
114 if (mpDrawViewShell
&& bMaster
)
116 SfxStyleSheetBasePool
* pStShPool
= mrDoc
.GetStyleSheetPool();
117 SdPage
& rPage
= *mpDrawViewShell
->getCurrentPage();
118 SdrPage
& rMasterPage
= rPage
.TRG_GetMasterPage();
119 for (const rtl::Reference
<SdrObject
>& pObject
: rMasterPage
)
120 SetMasterAttributes(pObject
.get(), rPage
, rSet
, pStShPool
, bOk
, bMaster
, bSlide
);
123 if (mpDrawViewShell
&& bSlide
)
125 SfxStyleSheetBasePool
* pStShPool
= mrDoc
.GetStyleSheetPool();
126 SdPage
& rPage
= *mpDrawViewShell
->getCurrentPage();
127 for (const rtl::Reference
<SdrObject
>& pObject
: rPage
)
128 SetMasterAttributes(pObject
.get(), rPage
, rSet
, pStShPool
, bOk
, bMaster
, bSlide
);
132 // is there a masterpage edit?
133 if ( mpDrawViewShell
&& (mpDrawViewShell
->GetEditMode() == EditMode::MasterPage
) )
135 SfxStyleSheetBasePool
* pStShPool
= mrDoc
.GetStyleSheetPool();
136 SdPage
& rPage
= *mpDrawViewShell
->getCurrentPage();
137 SdrTextObj
* pEditObject
= GetTextEditObject();
143 SdrInventor nInv
= pEditObject
->GetObjInventor();
145 if (nInv
== SdrInventor::Default
)
147 SdrObjKind eObjKind
= pEditObject
->GetObjIdentifier();
148 PresObjKind ePresObjKind
= rPage
.GetPresObjKind(pEditObject
);
150 if ( ePresObjKind
== PresObjKind::Title
||
151 ePresObjKind
== PresObjKind::Notes
)
153 // Presentation object (except outline)
154 SfxStyleSheet
* pSheet
= rPage
.GetStyleSheetForPresObj( ePresObjKind
);
155 DBG_ASSERT(pSheet
, "StyleSheet not found");
157 SfxItemSet
aTempSet( pSheet
->GetItemSet() );
158 aTempSet
.Put( rSet
);
159 aTempSet
.ClearInvalidItems();
162 mpDocSh
->GetUndoManager()->AddUndoAction(
163 std::make_unique
<StyleSheetUndoAction
>(&mrDoc
, *pSheet
, &aTempSet
));
165 pSheet
->GetItemSet().Put(aTempSet
);
166 pSheet
->Broadcast(SfxHint(SfxHintId::DataChanged
));
169 else if (eObjKind
== SdrObjKind::OutlineText
)
171 // Presentation object outline
172 OutlinerView
* pOV
= GetTextEditOutlinerView();
173 ::Outliner
* pOutliner
= pOV
->GetOutliner();
175 pOutliner
->SetUpdateLayout(false);
176 mpDocSh
->SetWaitCursor( true );
178 // replace placeholder by template name
179 OUString
aComment(SdResId(STR_UNDO_CHANGE_PRES_OBJECT
));
180 aComment
= aComment
.replaceFirst("$", SdResId(STR_PSEUDOSHEET_OUTLINE
));
181 mpDocSh
->GetUndoManager()->EnterListAction( aComment
, OUString(), 0, mpDrawViewShell
->GetViewShellBase().GetViewShellId() );
183 std::vector
<Paragraph
*> aSelList
;
184 pOV
->CreateSelectionList(aSelList
);
186 std::vector
<Paragraph
*>::reverse_iterator iter
= aSelList
.rbegin();
187 Paragraph
* pPara
= iter
!= aSelList
.rend() ? *iter
: nullptr;
191 sal_Int32 nParaPos
= pOutliner
->GetAbsPos( pPara
);
192 sal_Int16 nDepth
= pOutliner
->GetDepth( nParaPos
);
193 OUString aName
= rPage
.GetLayoutName() + " " +
194 OUString::number((nDepth
<= 0) ? 1 : nDepth
+ 1);
195 SfxStyleSheet
* pSheet
= static_cast<SfxStyleSheet
*>(pStShPool
->Find(aName
, SfxStyleFamily::Page
));
196 //We have no stylesheet if we access outline level 10
197 //in the master preview, there is no true style backing
199 SAL_WARN_IF(!pSheet
, "sd", "StyleSheet " << aName
<< " not found");
202 SfxItemSet
aTempSet( pSheet
->GetItemSet() );
203 aTempSet
.Put( rSet
);
204 aTempSet
.ClearInvalidItems();
206 if( nDepth
> 0 && aTempSet
.GetItemState( EE_PARA_NUMBULLET
) == SfxItemState::SET
)
208 // no SvxNumBulletItem in outline level 1 to 8!
209 aTempSet
.ClearItem( EE_PARA_NUMBULLET
);
213 mpDocSh
->GetUndoManager()->AddUndoAction(
214 std::make_unique
<StyleSheetUndoAction
>(&mrDoc
, *pSheet
, &aTempSet
));
216 pSheet
->GetItemSet().Put(aTempSet
);
217 pSheet
->Broadcast(SfxHint(SfxHintId::DataChanged
));
219 // now also broadcast any child sheets
221 for( nChild
= nDepth
+ 1; nChild
< 9; nChild
++ )
223 OUString aSheetName
= rPage
.GetLayoutName() + " " +
224 OUString::number((nChild
<= 0) ? 1 : nChild
+ 1);
225 SfxStyleSheet
* pOutlSheet
= static_cast< SfxStyleSheet
* >(pStShPool
->Find(aSheetName
, SfxStyleFamily::Page
));
228 pOutlSheet
->Broadcast(SfxHint(SfxHintId::DataChanged
));
233 pPara
= iter
!= aSelList
.rend() ? *iter
: nullptr;
235 bool bJumpToLevel1
= false;
236 if( !pPara
&& nDepth
> 0 && rSet
.GetItemState( EE_PARA_NUMBULLET
) == SfxItemState::SET
)
237 bJumpToLevel1
= true;
241 iter
= aSelList
.rend();
244 if (pOutliner
->GetDepth(pOutliner
->GetAbsPos(*iter
)) > 0)
245 pPara
= pOutliner
->GetParagraph( 0 ); // Put NumBulletItem in outline level 1
249 mpDocSh
->SetWaitCursor( false );
250 pOV
->GetOutliner()->SetUpdateLayout(true);
252 mpDocSh
->GetUndoManager()->LeaveListAction();
258 bOk
= ::sd::View::SetAttributes(rSet
, bReplaceAll
);
265 const SdrMarkList
& rList
= GetMarkedObjectList();
266 const size_t nMarkCount
= rList
.GetMarkCount();
267 for (size_t nMark
= 0; nMark
< nMarkCount
; ++nMark
)
269 SdrObject
* pObject
= rList
.GetMark(nMark
)->GetMarkedSdrObj();
270 SetMasterAttributes(pObject
, rPage
, rSet
, pStShPool
, bOk
, bMaster
, bSlide
);
274 bOk
= ::sd::View::SetAttributes(rSet
, bReplaceAll
);
277 else // not at masterpage
279 bOk
= ::sd::View::SetAttributes(rSet
, bReplaceAll
);
285 void DrawView::SetMasterAttributes( SdrObject
* pObject
, const SdPage
& rPage
, const SfxItemSet
& rSet
, SfxStyleSheetBasePool
* pStShPool
, bool& bOk
, bool bMaster
, bool bSlide
)
287 SdrInventor nInv
= pObject
->GetObjInventor();
289 if (nInv
!= SdrInventor::Default
)
292 SdrObjKind eObjKind
= pObject
->GetObjIdentifier();
293 PresObjKind ePresObjKind
= rPage
.GetPresObjKind(pObject
);
294 if (bSlide
&& eObjKind
== SdrObjKind::Text
)
296 // Presentation object (except outline)
297 SfxStyleSheet
* pSheet
= rPage
.GetTextStyleSheetForObject(pObject
);
298 assert(pSheet
&& "StyleSheet not found");
300 SfxItemSet
aTempSet( pSheet
->GetItemSet() );
301 aTempSet
.Put( rSet
);
302 aTempSet
.ClearInvalidItems();
305 mpDocSh
->GetUndoManager()->AddUndoAction(
306 std::make_unique
<StyleSheetUndoAction
>(&mrDoc
, *pSheet
, &aTempSet
));
308 pSheet
->GetItemSet().Put(aTempSet
,false);
309 pSheet
->Broadcast(SfxHint(SfxHintId::DataChanged
));
314 (ePresObjKind
== PresObjKind::Title
||
315 ePresObjKind
== PresObjKind::Notes
))
317 // Presentation object (except outline)
318 SfxStyleSheet
* pSheet
= rPage
.GetStyleSheetForPresObj( ePresObjKind
);
319 assert(pSheet
&& "StyleSheet not found");
321 SfxItemSet
aTempSet( pSheet
->GetItemSet() );
322 aTempSet
.Put( rSet
);
323 aTempSet
.ClearInvalidItems();
326 mpDocSh
->GetUndoManager()->AddUndoAction(
327 std::make_unique
<StyleSheetUndoAction
>(&mrDoc
, *pSheet
, &aTempSet
));
329 pSheet
->GetItemSet().Put(aTempSet
,false);
330 pSheet
->Broadcast(SfxHint(SfxHintId::DataChanged
));
333 else if (eObjKind
== SdrObjKind::OutlineText
)
335 // tdf#127900: do not forget to apply master style to placeholders
336 if (!rSet
.HasItem(EE_PARA_NUMBULLET
) || bMaster
)
338 // Presentation object outline
339 for (sal_uInt16 nLevel
= 9; nLevel
> 0; nLevel
--)
341 OUString aName
= rPage
.GetLayoutName() + " " +
342 OUString::number(nLevel
);
343 SfxStyleSheet
* pSheet
= static_cast<SfxStyleSheet
*>(pStShPool
->
344 Find(aName
, SfxStyleFamily::Page
));
345 assert(pSheet
&& "StyleSheet not found");
347 SfxItemSet
aTempSet( pSheet
->GetItemSet() );
351 // for all levels over 1, clear all items that will be
352 // hard set to level 1
353 SfxWhichIter
aWhichIter(rSet
);
354 sal_uInt16
nWhich(aWhichIter
.FirstWhich());
357 if( SfxItemState::SET
== aWhichIter
.GetItemState() )
358 aTempSet
.ClearItem( nWhich
);
359 nWhich
= aWhichIter
.NextWhich();
365 // put the items hard into level one
366 aTempSet
.Put( rSet
);
369 aTempSet
.ClearInvalidItems();
372 mpDocSh
->GetUndoManager()->AddUndoAction(
373 std::make_unique
<StyleSheetUndoAction
>(&mrDoc
, *pSheet
, &aTempSet
));
375 pSheet
->GetItemSet().Set(aTempSet
,false);
376 pSheet
->Broadcast(SfxHint(SfxHintId::DataChanged
));
379 // remove all hard set items from shape that are now set in style
380 SfxWhichIter
aWhichIter(rSet
);
381 sal_uInt16
nWhich(aWhichIter
.FirstWhich());
384 if( SfxItemState::SET
== aWhichIter
.GetItemState() )
385 pObject
->ClearMergedItem( nWhich
);
386 nWhich
= aWhichIter
.NextWhich();
390 pObject
->SetMergedItemSet(rSet
);
397 * Notify for change of site arrangement
400 void DrawView::Notify(SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
402 if ( mpDrawViewShell
&& rHint
.GetId() == SfxHintId::ThisIsAnSdrHint
)
404 SdrHintKind eHintKind
= static_cast<const SdrHint
&>(rHint
).GetKind();
406 if ( mnPOCHSmph
== 0 && eHintKind
== SdrHintKind::PageOrderChange
)
408 mpDrawViewShell
->ResetActualPage();
409 mpDrawViewShell
->UpdateScrollBars();
411 else if ( eHintKind
== SdrHintKind::LayerChange
|| eHintKind
== SdrHintKind::LayerOrderChange
)
413 mpDrawViewShell
->ResetActualLayer();
416 // switch to that page when it's not a master page
417 if(SdrHintKind::SwitchToPage
== eHintKind
)
419 // We switch page only in the current view, which triggered this event
420 // and keep other views untouched.
421 SfxViewShell
* pViewShell
= SfxViewShell::Current();
422 if(pViewShell
&& pViewShell
!= &mpDrawViewShell
->GetViewShellBase())
425 const SdrPage
* pPage
= static_cast<const SdrHint
&>(rHint
).GetPage();
426 if(pPage
&& !pPage
->IsMasterPage())
428 if(mpDrawViewShell
->GetActualPage() != pPage
)
430 sal_uInt16 nPageNum
= (pPage
->GetPageNum() - 1) / 2; // Sdr --> Sd
431 mpDrawViewShell
->SwitchPage(nPageNum
);
437 ::sd::View::Notify(rBC
, rHint
);
441 * Lock/Unlock PageOrderChangedHint
444 void DrawView::BlockPageOrderChangedHint(bool bBlock
)
450 DBG_ASSERT(mnPOCHSmph
, "counter overflow");
456 * If presentation objects are selected, intercept stylesheet-positioning at
460 bool DrawView::SetStyleSheet(SfxStyleSheet
* pStyleSheet
, bool bDontRemoveHardAttr
)
464 // is there a masterpage edit?
465 if (mpDrawViewShell
&& mpDrawViewShell
->GetEditMode() == EditMode::MasterPage
)
467 if (IsPresObjSelected(false))
469 std::unique_ptr
<weld::MessageDialog
> xInfoBox(Application::CreateMessageDialog(mpDrawViewShell
->GetFrameWeld(),
470 VclMessageType::Info
, VclButtonsType::Ok
,
471 SdResId(STR_ACTION_NOTPOSSIBLE
)));
477 bResult
= ::sd::View::SetStyleSheet(pStyleSheet
, bDontRemoveHardAttr
);
482 bResult
= ::sd::View::SetStyleSheet(pStyleSheet
, bDontRemoveHardAttr
);
488 * Paint-method: Redirect event to the view
491 void DrawView::CompleteRedraw(OutputDevice
* pOutDev
, const vcl::Region
& rReg
, sdr::contact::ViewObjectContactRedirector
* pRedirector
/*=0*/)
493 SdDrawDocument
* pDoc
= GetDocSh()->GetDoc();
494 if( pDoc
&& pDoc
->GetDocumentType() == DocumentType::Impress
)
496 rtl::Reference
< sd::SlideShow
> xSlideshow( SlideShow::GetSlideShow( pDoc
) );
497 if(xSlideshow
.is() && xSlideshow
->isRunning())
499 OutputDevice
* pShowWindow
= xSlideshow
->getShowWindow();
500 if( (pShowWindow
== pOutDev
) || (xSlideshow
->getAnimationMode() == ANIMATIONMODE_PREVIEW
) )
502 if( pShowWindow
== pOutDev
&& mpViewSh
)
504 if (!xSlideshow
->IsInteractiveSlideshow()) // IASS
510 ::sd::View::CompleteRedraw(pOutDev
, rReg
, pRedirector
);
514 * Make passed region visible (scrolling if necessary)
517 void DrawView::MakeVisible(const ::tools::Rectangle
& rRect
, vcl::Window
& rWin
)
519 if (!rRect
.IsEmpty() && mpDrawViewShell
)
521 mpDrawViewShell
->MakeVisible(rRect
, rWin
);
529 void DrawView::HideSdrPage()
533 mpDrawViewShell
->HidePage();
536 ::sd::View::HideSdrPage();
539 void DrawView::DeleteMarked()
541 sd::UndoManager
* pUndoManager
= mrDoc
.GetUndoManager();
542 DBG_ASSERT( pUndoManager
, "sd::DrawView::DeleteMarked(), ui action without undo manager!?" );
544 const SdrMarkList
& rMarkList
= GetMarkedObjectList();
547 OUString
aUndo(SvxResId(STR_EditDelete
));
548 aUndo
= aUndo
.replaceFirst("%1", rMarkList
.GetMarkDescription());
549 ViewShellId nViewShellId
= mpDrawViewShell
? mpDrawViewShell
->GetViewShellBase().GetViewShellId() : ViewShellId(-1);
550 pUndoManager
->EnterListAction(aUndo
, aUndo
, 0, nViewShellId
);
553 SdPage
* pPage
= nullptr;
554 bool bResetLayout
= false;
556 const size_t nMarkCount
= rMarkList
.GetMarkCount();
559 SdrMarkList
aList( GetMarkedObjectList() );
560 for (size_t nMark
= 0; nMark
< nMarkCount
; ++nMark
)
562 SdrObject
* pObj
= aList
.GetMark(nMark
)->GetMarkedSdrObj();
563 if( pObj
&& !pObj
->IsEmptyPresObj() && pObj
->GetUserCall() )
565 pPage
= static_cast< SdPage
* >( pObj
->getSdrPageFromSdrObject() );
568 PresObjKind
ePresObjKind(pPage
->GetPresObjKind(pObj
));
569 switch( ePresObjKind
)
571 case PresObjKind::NONE
:
572 continue; // ignore it
573 case PresObjKind::Graphic
:
574 case PresObjKind::Object
:
575 case PresObjKind::Chart
:
576 case PresObjKind::OrgChart
:
577 case PresObjKind::Table
:
578 case PresObjKind::Calc
:
579 case PresObjKind::Media
:
580 ePresObjKind
= PresObjKind::Outline
;
585 SdrTextObj
* pTextObj
= DynCastSdrTextObj( pObj
);
586 bool bVertical
= pTextObj
&& pTextObj
->IsVerticalWriting();
587 ::tools::Rectangle
aRect( pObj
->GetLogicRect() );
588 SdrObject
* pNewObj
= pPage
->InsertAutoLayoutShape( nullptr, ePresObjKind
, bVertical
, aRect
, true );
590 // pUndoManager should not be NULL (see assert above)
591 // but since we have defensive code
592 // for it earlier and later in the function
593 // we might as well be consistent
596 // Move the new PresObj to the position before the
597 // object it will replace.
598 pUndoManager
->AddUndoAction(
599 mrDoc
.GetSdrUndoFactory().CreateUndoObjectOrdNum(
601 pNewObj
->GetOrdNum(),
604 pPage
->SetObjectOrdNum( pNewObj
->GetOrdNum(), pObj
->GetOrdNum() );
612 ::sd::View::DeleteMarked();
614 if( pPage
&& bResetLayout
)
615 pPage
->SetAutoLayout( pPage
->GetAutoLayout() );
618 pUndoManager
->LeaveListAction();
621 } // end of namespace sd
623 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */