android: Update app-specific/MIME type icons
[LibreOffice.git] / sd / source / ui / view / drawview.cxx
blobbd454bec194b909a08f51b3b849826ccc9a1856a
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 <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>
36 #include <View.hxx>
37 #include <drawview.hxx>
38 #include <drawdoc.hxx>
39 #include <DrawDocShell.hxx>
40 #include <sdpage.hxx>
41 #include <ViewShellBase.hxx>
42 #include <DrawViewShell.hxx>
43 #include <pres.hxx>
44 #include <sdresid.hxx>
45 #include <unchss.hxx>
46 #include <slideshow.hxx>
48 #include <undo/undomanager.hxx>
50 using namespace ::com::sun::star;
52 namespace sd {
55 /**
56 * Shows the first page of document at position 0,0. In the case
57 * that there is no page a page is created.
60 DrawView::DrawView(
61 DrawDocShell* pDocSh,
62 OutputDevice* pOutDev,
63 DrawViewShell* pShell)
64 : ::sd::View(*pDocSh->GetDoc(), pOutDev, pShell)
65 ,mpDocShell(pDocSh)
66 ,mpDrawViewShell(pShell)
67 ,mnPOCHSmph(0)
69 SetCurrentObj(SdrObjKind::Rectangle);
72 DrawView::~DrawView()
76 /**
77 * Virtual method from SdrView, called at selection change.
80 void DrawView::MarkListHasChanged()
82 ::sd::View::MarkListHasChanged();
84 if (mpDrawViewShell)
85 mpDrawViewShell->SelectionHasChanged();
88 /**
89 * Virtual method from SdrView, called at model change.
92 void DrawView::ModelHasChanged()
94 ::sd::View::ModelHasChanged();
96 // force framer to rerender
97 SfxStyleSheetBasePool* pSSPool = mrDoc.GetStyleSheetPool();
98 pSSPool->Broadcast(SfxStyleSheetPoolHint());
100 if( mpDrawViewShell )
101 mpDrawViewShell->ModelHasChanged();
106 * Redirect attributes onto title and outline text and background
107 * rectangle of a masterpage into templates, otherwise pass on baseclass.
110 bool DrawView::SetAttributes(const SfxItemSet& rSet,
111 bool bReplaceAll, bool bSlide, bool bMaster)
113 bool bOk = false;
115 if (mpDrawViewShell && bMaster)
117 SfxStyleSheetBasePool* pStShPool = mrDoc.GetStyleSheetPool();
118 SdPage& rPage = *mpDrawViewShell->getCurrentPage();
119 SdrPage& rMasterPage = rPage.TRG_GetMasterPage();
120 size_t nObjCount = rMasterPage.GetObjCount();
121 for (size_t nObj = 0; nObj < nObjCount; ++nObj)
123 SdrObject* pObject = rMasterPage.GetObj(nObj);
124 SetMasterAttributes(pObject, rPage, rSet, pStShPool, bOk, bMaster, bSlide);
126 return bOk;
128 if (mpDrawViewShell && bSlide)
130 SfxStyleSheetBasePool* pStShPool = mrDoc.GetStyleSheetPool();
131 SdPage& rPage = *mpDrawViewShell->getCurrentPage();
132 size_t nObjCount = rPage.GetObjCount();
133 for (size_t nObj = 0; nObj < nObjCount; ++nObj)
135 SdrObject* pObject = rPage.GetObj(nObj);
136 SetMasterAttributes(pObject, rPage, rSet, pStShPool, bOk, bMaster, bSlide);
138 return bOk;
141 // is there a masterpage edit?
142 if ( mpDrawViewShell && (mpDrawViewShell->GetEditMode() == EditMode::MasterPage) )
144 SfxStyleSheetBasePool* pStShPool = mrDoc.GetStyleSheetPool();
145 SdPage& rPage = *mpDrawViewShell->getCurrentPage();
146 SdrTextObj* pEditObject = GetTextEditObject();
148 if (pEditObject)
150 // Textedit
152 SdrInventor nInv = pEditObject->GetObjInventor();
154 if (nInv == SdrInventor::Default)
156 SdrObjKind eObjKind = pEditObject->GetObjIdentifier();
157 PresObjKind ePresObjKind = rPage.GetPresObjKind(pEditObject);
159 if ( ePresObjKind == PresObjKind::Title ||
160 ePresObjKind == PresObjKind::Notes )
162 // Presentation object (except outline)
163 SfxStyleSheet* pSheet = rPage.GetStyleSheetForPresObj( ePresObjKind );
164 DBG_ASSERT(pSheet, "StyleSheet not found");
166 SfxItemSet aTempSet( pSheet->GetItemSet() );
167 aTempSet.Put( rSet );
168 aTempSet.ClearInvalidItems();
170 // Undo-Action
171 mpDocSh->GetUndoManager()->AddUndoAction(
172 std::make_unique<StyleSheetUndoAction>(&mrDoc, pSheet, &aTempSet));
174 pSheet->GetItemSet().Put(aTempSet);
175 pSheet->Broadcast(SfxHint(SfxHintId::DataChanged));
176 bOk = true;
178 else if (eObjKind == SdrObjKind::OutlineText)
180 // Presentation object outline
181 OutlinerView* pOV = GetTextEditOutlinerView();
182 ::Outliner* pOutliner = pOV->GetOutliner();
184 pOutliner->SetUpdateLayout(false);
185 mpDocSh->SetWaitCursor( true );
187 // replace placeholder by template name
188 OUString aComment(SdResId(STR_UNDO_CHANGE_PRES_OBJECT));
189 aComment = aComment.replaceFirst("$", SdResId(STR_PSEUDOSHEET_OUTLINE));
190 mpDocSh->GetUndoManager()->EnterListAction( aComment, OUString(), 0, mpDrawViewShell->GetViewShellBase().GetViewShellId() );
192 std::vector<Paragraph*> aSelList;
193 pOV->CreateSelectionList(aSelList);
195 std::vector<Paragraph*>::reverse_iterator iter = aSelList.rbegin();
196 Paragraph* pPara = iter != aSelList.rend() ? *iter : nullptr;
198 while (pPara)
200 sal_Int32 nParaPos = pOutliner->GetAbsPos( pPara );
201 sal_Int16 nDepth = pOutliner->GetDepth( nParaPos );
202 OUString aName = rPage.GetLayoutName() + " " +
203 OUString::number((nDepth <= 0) ? 1 : nDepth + 1);
204 SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>(pStShPool->Find(aName, SfxStyleFamily::Page));
205 //We have no stylesheet if we access outline level 10
206 //in the master preview, there is no true style backing
207 //that entry
208 SAL_WARN_IF(!pSheet, "sd", "StyleSheet " << aName << " not found");
209 if (pSheet)
211 SfxItemSet aTempSet( pSheet->GetItemSet() );
212 aTempSet.Put( rSet );
213 aTempSet.ClearInvalidItems();
215 if( nDepth > 0 && aTempSet.GetItemState( EE_PARA_NUMBULLET ) == SfxItemState::SET )
217 // no SvxNumBulletItem in outline level 1 to 8!
218 aTempSet.ClearItem( EE_PARA_NUMBULLET );
221 // Undo-Action
222 mpDocSh->GetUndoManager()->AddUndoAction(
223 std::make_unique<StyleSheetUndoAction>(&mrDoc, pSheet, &aTempSet));
225 pSheet->GetItemSet().Put(aTempSet);
226 pSheet->Broadcast(SfxHint(SfxHintId::DataChanged));
228 // now also broadcast any child sheets
229 sal_Int16 nChild;
230 for( nChild = nDepth + 1; nChild < 9; nChild++ )
232 OUString aSheetName = rPage.GetLayoutName() + " " +
233 OUString::number((nChild <= 0) ? 1 : nChild + 1);
234 SfxStyleSheet* pOutlSheet = static_cast< SfxStyleSheet* >(pStShPool->Find(aSheetName, SfxStyleFamily::Page));
236 if( pOutlSheet )
237 pOutlSheet->Broadcast(SfxHint(SfxHintId::DataChanged));
241 ++iter;
242 pPara = iter != aSelList.rend() ? *iter : nullptr;
244 bool bJumpToLevel1 = false;
245 if( !pPara && nDepth > 0 && rSet.GetItemState( EE_PARA_NUMBULLET ) == SfxItemState::SET )
246 bJumpToLevel1 = true;
248 if (bJumpToLevel1)
250 iter = aSelList.rend();
251 --iter;
253 if (pOutliner->GetDepth(pOutliner->GetAbsPos(*iter)) > 0)
254 pPara = pOutliner->GetParagraph( 0 ); // Put NumBulletItem in outline level 1
258 mpDocSh->SetWaitCursor( false );
259 pOV->GetOutliner()->SetUpdateLayout(true);
261 mpDocSh->GetUndoManager()->LeaveListAction();
263 bOk = true;
265 else
267 bOk = ::sd::View::SetAttributes(rSet, bReplaceAll);
271 else
273 // Selection
274 const SdrMarkList& rList = GetMarkedObjectList();
275 const size_t nMarkCount = rList.GetMarkCount();
276 for (size_t nMark = 0; nMark < nMarkCount; ++nMark)
278 SdrObject* pObject = rList.GetMark(nMark)->GetMarkedSdrObj();
279 SetMasterAttributes(pObject, rPage, rSet, pStShPool, bOk, bMaster, bSlide);
282 if(!bOk)
283 bOk = ::sd::View::SetAttributes(rSet, bReplaceAll);
286 else // not at masterpage
288 bOk = ::sd::View::SetAttributes(rSet, bReplaceAll);
291 return bOk;
294 void DrawView::SetMasterAttributes( SdrObject* pObject, const SdPage& rPage, SfxItemSet rSet, SfxStyleSheetBasePool* pStShPool, bool& bOk, bool bMaster, bool bSlide )
296 SdrInventor nInv = pObject->GetObjInventor();
298 if (nInv != SdrInventor::Default)
299 return;
301 SdrObjKind eObjKind = pObject->GetObjIdentifier();
302 PresObjKind ePresObjKind = rPage.GetPresObjKind(pObject);
303 if (bSlide && eObjKind == SdrObjKind::Text)
305 // Presentation object (except outline)
306 SfxStyleSheet* pSheet = rPage.GetTextStyleSheetForObject(pObject);
307 DBG_ASSERT(pSheet, "StyleSheet not found");
309 SfxItemSet aTempSet( pSheet->GetItemSet() );
310 aTempSet.Put( rSet );
311 aTempSet.ClearInvalidItems();
313 // Undo-Action
314 mpDocSh->GetUndoManager()->AddUndoAction(
315 std::make_unique<StyleSheetUndoAction>(&mrDoc, pSheet, &aTempSet));
317 pSheet->GetItemSet().Put(aTempSet,false);
318 pSheet->Broadcast(SfxHint(SfxHintId::DataChanged));
319 bOk = true;
322 if (!bSlide &&
323 (ePresObjKind == PresObjKind::Title ||
324 ePresObjKind == PresObjKind::Notes))
326 // Presentation object (except outline)
327 SfxStyleSheet* pSheet = rPage.GetStyleSheetForPresObj( ePresObjKind );
328 DBG_ASSERT(pSheet, "StyleSheet not found");
330 SfxItemSet aTempSet( pSheet->GetItemSet() );
331 aTempSet.Put( rSet );
332 aTempSet.ClearInvalidItems();
334 // Undo-Action
335 mpDocSh->GetUndoManager()->AddUndoAction(
336 std::make_unique<StyleSheetUndoAction>(&mrDoc, pSheet, &aTempSet));
338 pSheet->GetItemSet().Put(aTempSet,false);
339 pSheet->Broadcast(SfxHint(SfxHintId::DataChanged));
340 bOk = true;
342 else if (eObjKind == SdrObjKind::OutlineText)
344 // tdf#127900: do not forget to apply master style to placeholders
345 if (!rSet.HasItem(EE_PARA_NUMBULLET) || bMaster)
347 // Presentation object outline
348 for (sal_uInt16 nLevel = 9; nLevel > 0; nLevel--)
350 OUString aName = rPage.GetLayoutName() + " " +
351 OUString::number(nLevel);
352 SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>(pStShPool->
353 Find(aName, SfxStyleFamily::Page));
354 DBG_ASSERT(pSheet, "StyleSheet not found");
356 SfxItemSet aTempSet( pSheet->GetItemSet() );
358 if( nLevel > 1 )
360 // for all levels over 1, clear all items that will be
361 // hard set to level 1
362 SfxWhichIter aWhichIter(rSet);
363 sal_uInt16 nWhich(aWhichIter.FirstWhich());
364 while( nWhich )
366 if( SfxItemState::SET == aWhichIter.GetItemState() )
367 aTempSet.ClearItem( nWhich );
368 nWhich = aWhichIter.NextWhich();
372 else
374 // put the items hard into level one
375 aTempSet.Put( rSet );
378 aTempSet.ClearInvalidItems();
380 // Undo-Action
381 mpDocSh->GetUndoManager()->AddUndoAction(
382 std::make_unique<StyleSheetUndoAction>(&mrDoc, pSheet, &aTempSet));
384 pSheet->GetItemSet().Set(aTempSet,false);
385 pSheet->Broadcast(SfxHint(SfxHintId::DataChanged));
388 // remove all hard set items from shape that are now set in style
389 SfxWhichIter aWhichIter(rSet);
390 sal_uInt16 nWhich(aWhichIter.FirstWhich());
391 while( nWhich )
393 if( SfxItemState::SET == aWhichIter.GetItemState() )
394 pObject->ClearMergedItem( nWhich );
395 nWhich = aWhichIter.NextWhich();
398 else
399 pObject->SetMergedItemSet(rSet);
401 bOk = true;
406 * Notify for change of site arrangement
409 void DrawView::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
411 if ( mpDrawViewShell && rHint.GetId() == SfxHintId::ThisIsAnSdrHint )
413 SdrHintKind eHintKind = static_cast<const SdrHint&>(rHint).GetKind();
415 if ( mnPOCHSmph == 0 && eHintKind == SdrHintKind::PageOrderChange )
417 mpDrawViewShell->ResetActualPage();
419 else if ( eHintKind == SdrHintKind::LayerChange || eHintKind == SdrHintKind::LayerOrderChange )
421 mpDrawViewShell->ResetActualLayer();
424 // switch to that page when it's not a master page
425 if(SdrHintKind::SwitchToPage == eHintKind)
427 // We switch page only in the current view, which triggered this event
428 // and keep other views untouched.
429 SfxViewShell* pViewShell = SfxViewShell::Current();
430 if(pViewShell && pViewShell != &mpDrawViewShell->GetViewShellBase())
431 return;
433 const SdrPage* pPage = static_cast<const SdrHint&>(rHint).GetPage();
434 if(pPage && !pPage->IsMasterPage())
436 if(mpDrawViewShell->GetActualPage() != pPage)
438 sal_uInt16 nPageNum = (pPage->GetPageNum() - 1) / 2; // Sdr --> Sd
439 mpDrawViewShell->SwitchPage(nPageNum);
445 ::sd::View::Notify(rBC, rHint);
449 * Lock/Unlock PageOrderChangedHint
452 void DrawView::BlockPageOrderChangedHint(bool bBlock)
454 if (bBlock)
455 mnPOCHSmph++;
456 else
458 DBG_ASSERT(mnPOCHSmph, "counter overflow");
459 mnPOCHSmph--;
464 * If presentation objects are selected, intercept stylesheet-positioning at
465 * masterpage.
468 bool DrawView::SetStyleSheet(SfxStyleSheet* pStyleSheet, bool bDontRemoveHardAttr)
470 bool bResult = true;
472 // is there a masterpage edit?
473 if (mpDrawViewShell && mpDrawViewShell->GetEditMode() == EditMode::MasterPage)
475 if (IsPresObjSelected(false))
477 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(mpDrawViewShell->GetFrameWeld(),
478 VclMessageType::Info, VclButtonsType::Ok,
479 SdResId(STR_ACTION_NOTPOSSIBLE)));
480 xInfoBox->run();
481 bResult = false;
483 else
485 bResult = ::sd::View::SetStyleSheet(pStyleSheet, bDontRemoveHardAttr);
488 else
490 bResult = ::sd::View::SetStyleSheet(pStyleSheet, bDontRemoveHardAttr);
492 return bResult;
496 * Paint-method: Redirect event to the view
499 void DrawView::CompleteRedraw(OutputDevice* pOutDev, const vcl::Region& rReg, sdr::contact::ViewObjectContactRedirector* pRedirector /*=0*/)
501 SdDrawDocument* pDoc = mpDocShell->GetDoc();
502 if( pDoc && pDoc->GetDocumentType() == DocumentType::Impress)
504 rtl::Reference< sd::SlideShow > xSlideshow( SlideShow::GetSlideShow( pDoc ) );
505 if(xSlideshow.is() && xSlideshow->isRunning())
507 OutputDevice* pShowWindow = xSlideshow->getShowWindow();
508 if( (pShowWindow == pOutDev) || (xSlideshow->getAnimationMode() == ANIMATIONMODE_PREVIEW) )
510 if( pShowWindow == pOutDev && mpViewSh )
511 xSlideshow->paint();
512 return;
517 ::sd::View::CompleteRedraw(pOutDev, rReg, pRedirector);
521 * Make passed region visible (scrolling if necessary)
524 void DrawView::MakeVisible(const ::tools::Rectangle& rRect, vcl::Window& rWin)
526 if (!rRect.IsEmpty() && mpDrawViewShell)
528 mpDrawViewShell->MakeVisible(rRect, rWin);
533 * Hide page.
536 void DrawView::HideSdrPage()
538 if (mpDrawViewShell)
540 mpDrawViewShell->HidePage();
543 ::sd::View::HideSdrPage();
546 void DrawView::DeleteMarked()
548 sd::UndoManager* pUndoManager = mrDoc.GetUndoManager();
549 DBG_ASSERT( pUndoManager, "sd::DrawView::DeleteMarked(), ui action without undo manager!?" );
551 if( pUndoManager )
553 OUString aUndo(SvxResId(STR_EditDelete));
554 aUndo = aUndo.replaceFirst("%1", GetDescriptionOfMarkedObjects());
555 ViewShellId nViewShellId = mpDrawViewShell ? mpDrawViewShell->GetViewShellBase().GetViewShellId() : ViewShellId(-1);
556 pUndoManager->EnterListAction(aUndo, aUndo, 0, nViewShellId);
559 SdPage* pPage = nullptr;
560 bool bResetLayout = false;
562 const size_t nMarkCount = GetMarkedObjectList().GetMarkCount();
563 if( nMarkCount )
565 SdrMarkList aList( GetMarkedObjectList() );
566 for (size_t nMark = 0; nMark < nMarkCount; ++nMark)
568 SdrObject* pObj = aList.GetMark(nMark)->GetMarkedSdrObj();
569 if( pObj && !pObj->IsEmptyPresObj() && pObj->GetUserCall() )
571 pPage = static_cast< SdPage* >( pObj->getSdrPageFromSdrObject() );
572 if (pPage)
574 PresObjKind ePresObjKind(pPage->GetPresObjKind(pObj));
575 switch( ePresObjKind )
577 case PresObjKind::NONE:
578 continue; // ignore it
579 case PresObjKind::Graphic:
580 case PresObjKind::Object:
581 case PresObjKind::Chart:
582 case PresObjKind::OrgChart:
583 case PresObjKind::Table:
584 case PresObjKind::Calc:
585 case PresObjKind::Media:
586 ePresObjKind = PresObjKind::Outline;
587 break;
588 default:
589 break;
591 SdrTextObj* pTextObj = DynCastSdrTextObj( pObj );
592 bool bVertical = pTextObj && pTextObj->IsVerticalWriting();
593 ::tools::Rectangle aRect( pObj->GetLogicRect() );
594 SdrObject* pNewObj = pPage->InsertAutoLayoutShape( nullptr, ePresObjKind, bVertical, aRect, true );
596 // pUndoManager should not be NULL (see assert above)
597 // but since we have defensive code
598 // for it earlier and later in the function
599 // we might as well be consistent
600 if(pUndoManager)
602 // Move the new PresObj to the position before the
603 // object it will replace.
604 pUndoManager->AddUndoAction(
605 mrDoc.GetSdrUndoFactory().CreateUndoObjectOrdNum(
606 *pNewObj,
607 pNewObj->GetOrdNum(),
608 pObj->GetOrdNum()));
610 pPage->SetObjectOrdNum( pNewObj->GetOrdNum(), pObj->GetOrdNum() );
612 bResetLayout = true;
618 ::sd::View::DeleteMarked();
620 if( pPage && bResetLayout )
621 pPage->SetAutoLayout( pPage->GetAutoLayout() );
623 if( pUndoManager )
624 pUndoManager->LeaveListAction();
627 } // end of namespace sd
629 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */