android: Update app-specific/MIME type icons
[LibreOffice.git] / sd / source / ui / view / drviewsa.cxx
blob2868c38d6c902f356c8a279f56fe95691613a5c3
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 <DrawViewShell.hxx>
21 #include <com/sun/star/scanner/ScannerManager.hpp>
22 #include <cppuhelper/implbase.hxx>
23 #include <comphelper/processfactory.hxx>
24 #include <editeng/sizeitem.hxx>
25 #include <svx/svdlayer.hxx>
26 #include <svx/svdograf.hxx>
27 #include <sfx2/zoomitem.hxx>
28 #include <svx/svdpagv.hxx>
29 #include <svl/ptitem.hxx>
30 #include <svl/stritem.hxx>
31 #include <sfx2/request.hxx>
32 #include <sfx2/dispatch.hxx>
33 #include <svx/zoomslideritem.hxx>
34 #include <svl/eitem.hxx>
36 #include <sdcommands.h>
37 #include <svx/f3dchild.hxx>
38 #include <svx/clipfmtitem.hxx>
40 #include <sfx2/viewfrm.hxx>
41 #include <svtools/cliplistener.hxx>
42 #include <svx/float3d.hxx>
43 #include <svx/extedit.hxx>
44 #include <svx/sidebar/SelectionAnalyzer.hxx>
45 #include <svx/sidebar/SelectionChangeHandler.hxx>
46 #include <helpids.h>
48 #include <view/viewoverlaymanager.hxx>
49 #include <app.hrc>
50 #include <strings.hrc>
51 #include <sdmod.hxx>
52 #include <sdpage.hxx>
53 #include <FrameView.hxx>
54 #include <drawdoc.hxx>
55 #include <sdresid.hxx>
56 #include <DrawDocShell.hxx>
57 #include <Window.hxx>
58 #include <fupoor.hxx>
59 #include <fusel.hxx>
60 #include <funavig.hxx>
61 #include <drawview.hxx>
62 #include <SdUnoDrawView.hxx>
63 #include <ViewShellBase.hxx>
64 #include <slideshow.hxx>
65 #include <annotationmanager.hxx>
66 #include <DrawController.hxx>
67 #include <comphelper/diagnose_ex.hxx>
68 #include <LayerTabBar.hxx>
70 #include <memory>
72 using namespace ::com::sun::star;
73 using namespace ::com::sun::star::uno;
74 using vcl::EnumContext;
76 namespace sd {
78 bool DrawViewShell::mbPipette = false;
80 namespace {
82 class ScannerEventListener : public ::cppu::WeakImplHelper< lang::XEventListener >
84 private:
86 DrawViewShell* mpParent;
88 public:
90 explicit ScannerEventListener( DrawViewShell* pParent ) : mpParent( pParent ) {}
92 // XEventListener
93 virtual void SAL_CALL disposing( const lang::EventObject& rEventObject ) override;
95 void ParentDestroyed() { mpParent = nullptr; }
100 void SAL_CALL ScannerEventListener::disposing( const lang::EventObject& /*rEventObject*/ )
102 if( mpParent )
103 mpParent->ScannerEvent();
106 DrawViewShell::DrawViewShell( ViewShellBase& rViewShellBase, vcl::Window* pParentWindow, PageKind ePageKind, FrameView* pFrameViewArgument )
107 : ViewShell (pParentWindow, rViewShellBase)
108 , maTabControl(VclPtr<sd::TabControl>::Create(this, pParentWindow))
109 , mbIsLayerModeActive(false)
110 , mbIsInSwitchPage(false)
111 , mpSelectionChangeHandler(new svx::sidebar::SelectionChangeHandler(
112 [this] () { return this->GetSidebarContextName(); },
113 uno::Reference<frame::XController>(rViewShellBase.GetDrawController()),
114 vcl::EnumContext::Context::Default))
115 , mbMouseButtonDown(false)
116 , mbMouseSelecting(false)
118 if (pFrameViewArgument != nullptr)
119 mpFrameView = pFrameViewArgument;
120 else
121 mpFrameView = new FrameView(GetDoc());
122 Construct(GetDocSh(), ePageKind);
124 mpSelectionChangeHandler->Connect();
126 SetContextName(GetSidebarContextName());
128 doShow();
130 ConfigureAppBackgroundColor();
131 SD_MOD()->GetColorConfig().AddListener(this);
132 maViewOptions.mnDocBackgroundColor = SD_MOD()->GetColorConfig().GetColorValue(svtools::DOCCOLOR).nColor;
135 DrawViewShell::~DrawViewShell()
137 suppress_fun_call_w_exception(ImplDestroy());
140 void DrawViewShell::ImplDestroy()
142 SD_MOD()->GetColorConfig().RemoveListener(this);
144 mpSelectionChangeHandler->Disconnect();
146 mpAnnotationManager.reset();
147 mpViewOverlayManager.reset();
149 OSL_ASSERT (GetViewShell()!=nullptr);
151 if( mxScannerListener.is() )
152 static_cast< ScannerEventListener* >( mxScannerListener.get() )->ParentDestroyed();
154 // Remove references to items within Svx3DWin
155 // (maybe do a listening sometime in Svx3DWin)
156 sal_uInt16 nId = Svx3DChildWindow::GetChildWindowId();
157 SfxChildWindow* pWindow = GetViewFrame() ? GetViewFrame()->GetChildWindow(nId) : nullptr;
158 if(pWindow)
160 Svx3DWin* p3DWin = static_cast< Svx3DWin* > (pWindow->GetWindow());
161 if(p3DWin)
162 p3DWin->DocumentReload();
165 EndListening (*GetDoc());
166 EndListening (*GetDocSh());
168 if( SlideShow::IsRunning(*this) )
169 StopSlideShow();
171 DisposeFunctions();
173 sal_uInt16 aPageCnt = GetDoc()->GetSdPageCount(mePageKind);
175 for (sal_uInt16 i = 0; i < aPageCnt; i++)
177 SdPage* pPage = GetDoc()->GetSdPage(i, mePageKind);
179 if (pPage == mpActualPage)
181 GetDoc()->SetSelected(pPage, true);
183 else
185 GetDoc()->SetSelected(pPage, false);
189 if ( mxClipEvtLstnr.is() )
191 mxClipEvtLstnr->RemoveListener( GetActiveWindow() );
192 mxClipEvtLstnr->ClearCallbackLink(); // prevent callback if another thread is waiting
193 mxClipEvtLstnr.clear();
196 mpDrawView.reset();
197 // Set mpView to NULL so that the destructor of the ViewShell base class
198 // does not access it.
199 mpView = nullptr;
201 mpFrameView->Disconnect();
202 maTabControl.disposeAndClear();
206 * common part of both constructors
208 void DrawViewShell::Construct(DrawDocShell* pDocSh, PageKind eInitialPageKind)
210 mpActualPage = nullptr;
211 mbReadOnly = GetDocSh()->IsReadOnly();
212 mxClipEvtLstnr.clear();
213 mbPastePossible = false;
214 mbIsLayerModeActive = false;
216 mpFrameView->Connect();
218 OSL_ASSERT (GetViewShell()!=nullptr);
220 SetPool( &GetDoc()->GetPool() );
222 GetDoc()->CreateFirstPages();
224 mpDrawView.reset( new DrawView(pDocSh, GetActiveWindow()->GetOutDev(), this) );
225 mpView = mpDrawView.get(); // Pointer of base class ViewShell
226 mpDrawView->SetSwapAsynchron(); // Asynchronous load of graphics
228 // We do not read the page kind from the frame view anymore so we have
229 // to set it in order to resync frame view and this view.
230 mpFrameView->SetPageKind(eInitialPageKind);
231 mePageKind = eInitialPageKind;
232 meEditMode = EditMode::Page;
233 DocumentType eDocType = GetDoc()->GetDocumentType(); // RTTI does not work here
234 switch (mePageKind)
236 case PageKind::Standard:
237 meShellType = ST_IMPRESS;
238 break;
240 case PageKind::Notes:
241 meShellType = ST_NOTES;
242 break;
244 case PageKind::Handout:
245 meShellType = ST_HANDOUT;
246 break;
249 Size aPageSize( GetDoc()->GetSdPage(0, mePageKind)->GetSize() );
250 Point aPageOrg( aPageSize.Width(), aPageSize.Height() / 2);
251 Size aSize(aPageSize.Width() * 3, aPageSize.Height() * 2);
252 InitWindows(aPageOrg, aSize, Point(-1, -1));
254 Point aVisAreaPos;
256 if ( pDocSh->GetCreateMode() == SfxObjectCreateMode::EMBEDDED )
258 aVisAreaPos = pDocSh->GetVisArea(ASPECT_CONTENT).TopLeft();
261 mpDrawView->SetWorkArea(::tools::Rectangle(Point() - aVisAreaPos - aPageOrg, aSize));
263 // objects can not grow bigger than ViewSize
264 GetDoc()->SetMaxObjSize(aSize);
266 // Split-Handler for TabControls
267 maTabControl->SetSplitHdl( LINK( this, DrawViewShell, TabSplitHdl ) );
269 /* In order to set the correct EditMode of the FrameView, we select another
270 one (small trick). */
271 if (mpFrameView->GetViewShEditMode(/*mePageKind*/) == EditMode::Page)
273 meEditMode = EditMode::MasterPage;
275 else
277 meEditMode = EditMode::Page;
280 // Use configuration of FrameView
281 ReadFrameViewData(mpFrameView);
283 if( eDocType == DocumentType::Draw )
285 GetActiveWindow()->SetHelpId( HID_SDGRAPHICVIEWSHELL );
287 else
289 if (mePageKind == PageKind::Notes)
291 GetActiveWindow()->SetHelpId( CMD_SID_NOTES_MODE );
293 // AutoLayouts have to be created
294 GetDoc()->StopWorkStartupDelay();
296 else if (mePageKind == PageKind::Handout)
298 GetActiveWindow()->SetHelpId( CMD_SID_HANDOUT_MASTER_MODE );
300 // AutoLayouts have to be created
301 GetDoc()->StopWorkStartupDelay();
303 else
305 GetActiveWindow()->SetHelpId( HID_SDDRAWVIEWSHELL );
309 // start selection function
310 SfxRequest aReq(SID_OBJECT_SELECT, SfxCallMode::SLOT, GetDoc()->GetItemPool());
311 FuPermanent(aReq);
312 mpDrawView->SetFrameDragSingles();
314 if (pDocSh->GetCreateMode() == SfxObjectCreateMode::EMBEDDED)
316 mbZoomOnPage = false;
318 else
320 mbZoomOnPage = true;
323 mbIsRulerDrag = false;
325 SetName ("DrawViewShell");
327 mnLockCount = 0;
329 uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
333 mxScannerManager = scanner::ScannerManager::create( xContext );
335 mxScannerListener = new ScannerEventListener( this );
337 catch (Exception const &)
339 // Eat the exception and log it
340 // We can still continue if scanner manager is not available.
341 DBG_UNHANDLED_EXCEPTION("sd");
344 mpAnnotationManager.reset( new AnnotationManager( GetViewShellBase() ) );
345 mpViewOverlayManager.reset( new ViewOverlayManager( GetViewShellBase() ) );
348 void DrawViewShell::Init (bool bIsMainViewShell)
350 ViewShell::Init(bIsMainViewShell);
352 if (!IsListening(*GetDocSh()))
353 StartListening (*GetDocSh());
356 void DrawViewShell::Shutdown()
358 ViewShell::Shutdown();
360 if(SlideShow::IsRunning( GetViewShellBase() ) )
362 // Turn off effects.
363 GetDrawView()->SetAnimationMode(SdrAnimationMode::Disable);
367 css::uno::Reference<css::drawing::XDrawSubController> DrawViewShell::CreateSubController()
369 css::uno::Reference<css::drawing::XDrawSubController> xSubController;
371 if (IsMainViewShell())
373 // Create uno sub controller for the main view shell.
374 xSubController.set( new SdUnoDrawView( *this, *GetView()));
377 return xSubController;
380 bool DrawViewShell::RelocateToParentWindow (vcl::Window* pParentWindow)
382 // DrawViewShells can not be relocated to a new parent window at the
383 // moment, so return <FALSE/> except when the given parent window is the
384 // parent window that is already in use.
385 return pParentWindow==GetParentWindow();
389 * check if we have to draw a polyline
393 Polylines are represented by macros as a sequence of:
394 MoveTo (x, y)
395 LineTo (x, y) [or BezierTo (x, y)]
396 LineTo (x, y)
398 There is no end command for polylines. Therefore, we have to test all
399 commands in the requests for LineTo (BezierTo) and we have to gather
400 the point-parameter. The first not-LineTo leads to the creation of the
401 polyline from the gathered points.
404 void DrawViewShell::CheckLineTo(SfxRequest& rReq)
406 #ifdef DBG_UTIL
407 if(rReq.IsAPI())
409 if(SID_LINETO == rReq.GetSlot() || SID_BEZIERTO == rReq.GetSlot() || SID_MOVETO == rReq.GetSlot() )
411 OSL_FAIL("DrawViewShell::CheckLineTo: slots SID_LINETO, SID_BEZIERTO, SID_MOVETO no longer supported.");
414 #endif
416 rReq.Ignore ();
420 * Change page parameter if SID_PAGESIZE or SID_PAGEMARGIN
422 void DrawViewShell::SetupPage (Size const &rSize,
423 ::tools::Long nLeft,
424 ::tools::Long nRight,
425 ::tools::Long nUpper,
426 ::tools::Long nLower,
427 bool bSize,
428 bool bMargin,
429 bool bScaleAll)
431 sal_uInt16 nPageCnt = GetDoc()->GetMasterSdPageCount(mePageKind);
432 sal_uInt16 i;
434 for (i = 0; i < nPageCnt; i++)
436 // first, handle all master pages
437 SdPage *pPage = GetDoc()->GetMasterSdPage(i, mePageKind);
439 if( pPage )
441 if( bSize )
443 ::tools::Rectangle aBorderRect(nLeft, nUpper, nRight, nLower);
444 pPage->ScaleObjects(rSize, aBorderRect, bScaleAll);
445 pPage->SetSize(rSize);
448 if( bMargin )
450 pPage->SetLeftBorder(nLeft);
451 pPage->SetRightBorder(nRight);
452 pPage->SetUpperBorder(nUpper);
453 pPage->SetLowerBorder(nLower);
456 if ( mePageKind == PageKind::Standard )
458 GetDoc()->GetMasterSdPage(i, PageKind::Notes)->CreateTitleAndLayout();
461 pPage->CreateTitleAndLayout();
465 nPageCnt = GetDoc()->GetSdPageCount(mePageKind);
467 for (i = 0; i < nPageCnt; i++)
469 // then, handle all pages
470 SdPage *pPage = GetDoc()->GetSdPage(i, mePageKind);
472 if( pPage )
474 if( bSize )
476 ::tools::Rectangle aBorderRect(nLeft, nUpper, nRight, nLower);
477 pPage->ScaleObjects(rSize, aBorderRect, bScaleAll);
478 pPage->SetSize(rSize);
480 if( bMargin )
482 pPage->SetLeftBorder(nLeft);
483 pPage->SetRightBorder(nRight);
484 pPage->SetUpperBorder(nUpper);
485 pPage->SetLowerBorder(nLower);
488 if ( mePageKind == PageKind::Standard )
490 SdPage* pNotesPage = GetDoc()->GetSdPage(i, PageKind::Notes);
491 pNotesPage->SetAutoLayout( pNotesPage->GetAutoLayout() );
494 pPage->SetAutoLayout( pPage->GetAutoLayout() );
498 if ( mePageKind == PageKind::Standard )
500 SdPage* pHandoutPage = GetDoc()->GetSdPage(0, PageKind::Handout);
501 pHandoutPage->CreateTitleAndLayout(true);
504 ::tools::Long nWidth = mpActualPage->GetSize().Width();
505 ::tools::Long nHeight = mpActualPage->GetSize().Height();
507 Point aPageOrg(nWidth, nHeight / 2);
508 Size aSize( nWidth * 3, nHeight * 2);
510 InitWindows(aPageOrg, aSize, Point(-1, -1), true);
512 Point aVisAreaPos;
514 if ( GetDocSh()->GetCreateMode() == SfxObjectCreateMode::EMBEDDED )
516 aVisAreaPos = GetDocSh()->GetVisArea(ASPECT_CONTENT).TopLeft();
519 GetView()->SetWorkArea(::tools::Rectangle(Point() - aVisAreaPos - aPageOrg, aSize));
521 UpdateScrollBars();
523 Point aNewOrigin(mpActualPage->GetLeftBorder(), mpActualPage->GetUpperBorder());
524 GetView()->GetSdrPageView()->SetPageOrigin(aNewOrigin);
526 GetViewFrame()->GetBindings().Invalidate(SID_RULER_NULL_OFFSET);
528 // zoom onto (new) page size
529 GetViewFrame()->GetDispatcher()->Execute(SID_SIZE_PAGE,
530 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
533 void DrawViewShell::GetStatusBarState(SfxItemSet& rSet)
535 /* Zoom-Item
536 Here we should propagate the corresponding value (Optimal ?, page width
537 or page) with the help of the ZoomItems !!! */
538 if( SfxItemState::DEFAULT == rSet.GetItemState( SID_ATTR_ZOOM ) )
540 if (GetDocSh()->IsUIActive() || SlideShow::IsRunning(GetViewShellBase())
541 || !GetActiveWindow())
543 rSet.DisableItem( SID_ATTR_ZOOM );
545 else
547 std::unique_ptr<SvxZoomItem> pZoomItem;
548 sal_uInt16 nZoom = static_cast<sal_uInt16>(GetActiveWindow()->GetZoom());
550 if( mbZoomOnPage )
551 pZoomItem.reset(new SvxZoomItem( SvxZoomType::WHOLEPAGE, nZoom ));
552 else
553 pZoomItem.reset(new SvxZoomItem( SvxZoomType::PERCENT, nZoom ));
555 // constrain area
556 SvxZoomEnableFlags nZoomValues = SvxZoomEnableFlags::ALL;
557 SdrPageView* pPageView = mpDrawView->GetSdrPageView();
559 if( pPageView && pPageView->GetObjList()->GetObjCount() == 0 )
561 nZoomValues &= ~SvxZoomEnableFlags::OPTIMAL;
564 pZoomItem->SetValueSet( nZoomValues );
565 rSet.Put( std::move(pZoomItem) );
568 if( SfxItemState::DEFAULT == rSet.GetItemState( SID_ATTR_ZOOMSLIDER ) )
570 rtl::Reference< sd::SlideShow > xSlideshow( SlideShow::GetSlideShow( GetDoc() ) );
571 if (GetDocSh()->IsUIActive() || (xSlideshow.is() && xSlideshow->isRunning()) || !GetActiveWindow() )
573 rSet.DisableItem( SID_ATTR_ZOOMSLIDER );
575 else
577 sd::Window * pActiveWindow = GetActiveWindow();
578 SvxZoomSliderItem aZoomItem( static_cast<sal_uInt16>(pActiveWindow->GetZoom()), static_cast<sal_uInt16>(pActiveWindow->GetMinZoom()), static_cast<sal_uInt16>(pActiveWindow->GetMaxZoom()) ) ;
580 SdrPageView* pPageView = mpDrawView->GetSdrPageView();
581 if( pPageView )
583 Point aPagePos(0, 0);
584 Size aPageSize = pPageView->GetPage()->GetSize();
586 aPagePos.AdjustX(aPageSize.Width() / 2 );
587 aPageSize.setWidth( static_cast<::tools::Long>(aPageSize.Width() * 1.03) );
589 aPagePos.AdjustY(aPageSize.Height() / 2 );
590 aPageSize.setHeight( static_cast<::tools::Long>(aPageSize.Height() * 1.03) );
591 aPagePos.AdjustY( -(aPageSize.Height() / 2) );
593 aPagePos.AdjustX( -(aPageSize.Width() / 2) );
595 ::tools::Rectangle aFullPageZoomRect( aPagePos, aPageSize );
596 aZoomItem.AddSnappingPoint( pActiveWindow->GetZoomForRect( aFullPageZoomRect ) );
598 aZoomItem.AddSnappingPoint(100);
599 rSet.Put( aZoomItem );
603 SdrPageView* pPageView = mpDrawView->GetSdrPageView();
604 if (pPageView)
606 Point aPos = GetActiveWindow()->PixelToLogic(maMousePos);
607 pPageView->LogicToPagePos(aPos);
608 Fraction aUIScale(GetDoc()->GetUIScale());
609 aPos.setX( ::tools::Long(aPos.X() / aUIScale) );
610 aPos.setY( ::tools::Long(aPos.Y() / aUIScale) );
612 // position- and size items
613 if ( mpDrawView->IsAction() )
615 ::tools::Rectangle aRect;
616 mpDrawView->TakeActionRect( aRect );
618 if ( aRect.IsEmpty() )
619 rSet.Put( SfxPointItem(SID_ATTR_POSITION, aPos) );
620 else
622 pPageView->LogicToPagePos(aRect);
623 aPos = aRect.TopLeft();
624 aPos.setX( ::tools::Long(aPos.X() / aUIScale) );
625 aPos.setY( ::tools::Long(aPos.Y() / aUIScale) );
626 rSet.Put( SfxPointItem( SID_ATTR_POSITION, aPos) );
627 Size aSize( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() );
628 aSize.setHeight( ::tools::Long(aSize.Height() / aUIScale) );
629 aSize.setWidth( ::tools::Long(aSize.Width() / aUIScale) );
630 rSet.Put( SvxSizeItem( SID_ATTR_SIZE, aSize) );
633 else
635 if ( mpDrawView->AreObjectsMarked() )
637 ::tools::Rectangle aRect = mpDrawView->GetAllMarkedRect();
638 pPageView->LogicToPagePos(aRect);
640 // Show the position of the selected shape(s)
641 Point aShapePosition (aRect.TopLeft());
642 aShapePosition.setX( ::tools::Long(aShapePosition.X() / aUIScale) );
643 aShapePosition.setY( ::tools::Long(aShapePosition.Y() / aUIScale) );
644 rSet.Put (SfxPointItem(SID_ATTR_POSITION, aShapePosition));
646 Size aSize( aRect.Right() - aRect.Left(), aRect.Bottom() - aRect.Top() );
647 aSize.setHeight( ::tools::Long(aSize.Height() / aUIScale) );
648 aSize.setWidth( ::tools::Long(aSize.Width() / aUIScale) );
649 rSet.Put( SvxSizeItem( SID_ATTR_SIZE, aSize) );
651 else
653 rSet.Put( SfxPointItem(SID_ATTR_POSITION, aPos) );
654 rSet.Put( SvxSizeItem( SID_ATTR_SIZE, Size( 0, 0 ) ) );
659 // Display of current page and layer.
660 if( SfxItemState::DEFAULT == rSet.GetItemState( SID_STATUS_PAGE ) )
662 sal_Int32 nPageCount = sal_Int32(GetDoc()->GetSdPageCount(mePageKind));
663 sal_Int32 nActivePageCount = sal_Int32(GetDoc()->GetActiveSdPageCount());
664 // Always show the slide/page number.
665 OUString aOUString;
666 if (GetDoc()->GetDocumentType() == DocumentType::Draw)
667 aOUString = (nPageCount == nActivePageCount) ? SdResId(STR_SD_PAGE_COUNT_DRAW) : SdResId(STR_SD_PAGE_COUNT_CUSTOM_DRAW);
668 else
669 aOUString = (nPageCount == nActivePageCount) ? SdResId(STR_SD_PAGE_COUNT) : SdResId(STR_SD_PAGE_COUNT_CUSTOM);
671 aOUString = aOUString.replaceFirst("%1", OUString::number(maTabControl->GetCurPagePos() + 1));
672 aOUString = aOUString.replaceFirst("%2", OUString::number(nPageCount));
673 if(nPageCount != nActivePageCount)
674 aOUString = aOUString.replaceFirst("%3", OUString::number(nActivePageCount));
676 // If in layer mode additionally show the layer that contains all
677 // selected shapes of the page. If the shapes are distributed on
678 // more than one layer, no layer name is shown.
679 if (IsLayerModeActive())
681 SdrLayerAdmin& rLayerAdmin = GetDoc()->GetLayerAdmin();
682 SdrLayerID nLayer(0), nOldLayer(0);
683 SdrObject* pObj = nullptr;
684 const SdrMarkList& rMarkList = mpDrawView->GetMarkedObjectList();
685 const size_t nMarkCount = rMarkList.GetMarkCount();
686 bool bOneLayer = true;
688 // Use the first ten selected shapes as a (hopefully
689 // representative) sample of all shapes of the current page.
690 // Detect whether they belong to the same layer.
691 for( size_t j = 0; j < nMarkCount && bOneLayer && j < 10; ++j )
693 pObj = rMarkList.GetMark( j )->GetMarkedSdrObj();
694 if( pObj )
696 nLayer = pObj->GetLayer();
698 if( j != 0 && nLayer != nOldLayer )
699 bOneLayer = false;
701 nOldLayer = nLayer;
705 // Append the layer name to the current page number.
706 if( bOneLayer && nMarkCount )
708 SdrLayer* pLayer = rLayerAdmin.GetLayerPerID( nLayer );
709 if( pLayer )
711 aOUString += " (" + LayerTabBar::convertToLocalizedName(pLayer->GetName()) + ")";
716 rSet.Put (SfxStringItem (SID_STATUS_PAGE, aOUString));
718 // Layout
719 if( SfxItemState::DEFAULT == rSet.GetItemState( SID_STATUS_LAYOUT ) )
721 OUString aString = mpActualPage->GetLayoutName();
722 sal_Int32 nPos = aString.indexOf(SD_LT_SEPARATOR);
723 if (nPos != -1)
724 aString = aString.copy(0, nPos);
725 rSet.Put( SfxStringItem( SID_STATUS_LAYOUT, aString ) );
727 // Scale
728 if( SfxItemState::DEFAULT == rSet.GetItemState( SID_SCALE ) )
730 const Fraction& aUIScale = GetDoc()->GetUIScale();
731 OUString aString = OUString::number(aUIScale.GetNumerator()) +
732 ":" + OUString::number(aUIScale.GetDenominator());
733 rSet.Put( SfxStringItem( SID_SCALE, aString ) );
737 void DrawViewShell::Notify (SfxBroadcaster&, const SfxHint& rHint)
739 if (rHint.GetId()!=SfxHintId::ModeChanged)
740 return;
742 // Change to selection when turning on read-only mode.
743 if(GetDocSh()->IsReadOnly() && dynamic_cast< FuSelection* >( GetCurrentFunction().get() ) )
745 SfxRequest aReq(SID_OBJECT_SELECT, SfxCallMode::SLOT, GetDoc()->GetItemPool());
746 FuPermanent(aReq);
749 // Turn on design mode when document is not read-only.
750 if (GetDocSh()->IsReadOnly() != mbReadOnly )
752 mbReadOnly = GetDocSh()->IsReadOnly();
754 SfxBoolItem aItem( SID_FM_DESIGN_MODE, !mbReadOnly );
755 GetViewFrame()->GetDispatcher()->ExecuteList(SID_FM_DESIGN_MODE,
756 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD, { &aItem });
761 void DrawViewShell::ExecuteAnnotation (SfxRequest const & rRequest)
763 if (mpAnnotationManager)
764 mpAnnotationManager->ExecuteAnnotation( rRequest );
767 void DrawViewShell::GetAnnotationState (SfxItemSet& rItemSet )
769 if (mpAnnotationManager)
770 mpAnnotationManager->GetAnnotationState( rItemSet );
773 OUString const & DrawViewShell::GetSidebarContextName() const
775 svx::sidebar::SelectionAnalyzer::ViewType eViewType (svx::sidebar::SelectionAnalyzer::ViewType::Standard);
776 switch (mePageKind)
778 case PageKind::Handout:
779 eViewType = svx::sidebar::SelectionAnalyzer::ViewType::Handout;
780 break;
781 case PageKind::Notes:
782 eViewType = svx::sidebar::SelectionAnalyzer::ViewType::Notes;
783 break;
784 case PageKind::Standard:
785 if (meEditMode == EditMode::MasterPage)
786 eViewType = svx::sidebar::SelectionAnalyzer::ViewType::Master;
787 else
788 eViewType = svx::sidebar::SelectionAnalyzer::ViewType::Standard;
789 break;
791 return EnumContext::GetContextName(
792 svx::sidebar::SelectionAnalyzer::GetContextForSelection_SD(
793 mpDrawView->GetMarkedObjectList(),
794 eViewType));
797 void DrawViewShell::ExecGoToNextPage (SfxRequest& rReq)
799 SetCurrentFunction( FuNavigation::Create( this, GetActiveWindow(), mpDrawView.get(), GetDoc(), rReq) );
800 Cancel();
803 void DrawViewShell::GetStateGoToNextPage (SfxItemSet& rSet)
805 SdPage* pPage = GetActualPage();
806 sal_uInt16 nSdPage = (pPage->GetPageNum() - 1) / 2;
807 sal_uInt16 totalPages = GetDoc()->GetSdPageCount(pPage->GetPageKind());
808 if (nSdPage + 1 >= totalPages)
809 rSet.DisableItem( SID_GO_TO_NEXT_PAGE );
812 void DrawViewShell::ExecGoToPreviousPage (SfxRequest& rReq)
814 SetCurrentFunction( FuNavigation::Create( this, GetActiveWindow(), mpDrawView.get(), GetDoc(), rReq) );
815 Cancel();
818 void DrawViewShell::GetStateGoToPreviousPage (SfxItemSet& rSet)
820 SdPage* pPage = GetActualPage();
821 sal_uInt16 nSdPage = (pPage->GetPageNum() - 1) / 2;
822 if (nSdPage == 0)
823 rSet.DisableItem( SID_GO_TO_PREVIOUS_PAGE );
827 void DrawViewShell::ExecGoToFirstPage (SfxRequest& rReq)
829 SetCurrentFunction( FuNavigation::Create( this, GetActiveWindow(), mpDrawView.get(), GetDoc(), rReq) );
830 Cancel();
833 void DrawViewShell::GetStateGoToFirstPage (SfxItemSet& rSet)
835 SdPage* pPage = GetActualPage();
836 sal_uInt16 nSdPage = (pPage->GetPageNum() - 1) / 2;
837 if (nSdPage == 0)
838 rSet.DisableItem( SID_GO_TO_FIRST_PAGE );
841 void DrawViewShell::ExecGoToLastPage (SfxRequest& rReq)
843 SetCurrentFunction( FuNavigation::Create( this, GetActiveWindow(), mpDrawView.get(), GetDoc(), rReq) );
844 Cancel();
847 void DrawViewShell::GetStateGoToLastPage (SfxItemSet& rSet)
849 SdPage* pPage = GetActualPage();
850 sal_uInt16 nSdPage = (pPage->GetPageNum() - 1) / 2;
851 sal_uInt16 totalPages = GetDoc()->GetSdPageCount(pPage->GetPageKind());
852 if (nSdPage + 1 >= totalPages)
853 rSet.DisableItem( SID_GO_TO_LAST_PAGE );
857 } // end of namespace sd
859 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */