cid#1607171 Data race condition
[LibreOffice.git] / sd / source / ui / view / ViewShellBase.cxx
blobbfbff51d13892e12ca93c7ddfa45fbd54c71ac2c
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 <comphelper/processfactory.hxx>
22 #include <boost/property_tree/json_parser.hpp>
24 #include <ViewShellBase.hxx>
25 #include <algorithm>
26 #include <EventMultiplexer.hxx>
27 #include <cache/SlsPageCacheManager.hxx>
28 #include <app.hrc>
29 #include <slideshow.hxx>
30 #include <unokywds.hxx>
31 #include <svx/svxids.hrc>
32 #include <DrawDocShell.hxx>
33 #include <ViewShellManager.hxx>
34 #include <DrawController.hxx>
35 #include <FrameView.hxx>
36 #include <ViewTabBar.hxx>
37 #include <sfx2/event.hxx>
38 #include <drawdoc.hxx>
39 #include <sdpage.hxx>
40 #include <sfx2/dispatch.hxx>
41 #include <sfx2/request.hxx>
42 #include <sfx2/printer.hxx>
43 #include <DrawViewShell.hxx>
44 #include <OutlineViewShell.hxx>
45 #include <FormShellManager.hxx>
46 #include <ToolBarManager.hxx>
47 #include <Window.hxx>
48 #include <framework/ConfigurationController.hxx>
49 #include <DocumentRenderer.hxx>
50 #include <optsitem.hxx>
51 #include <sdmod.hxx>
53 #include <com/sun/star/document/XViewDataSupplier.hpp>
54 #include <com/sun/star/container/XIndexAccess.hpp>
55 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
56 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
57 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
58 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
59 #include <com/sun/star/drawing/framework/ResourceId.hpp>
60 #include <framework/FrameworkHelper.hxx>
62 #include <sal/log.hxx>
63 #include <rtl/ref.hxx>
64 #include <sfx2/msg.hxx>
65 #include <sfx2/objface.hxx>
66 #include <sfx2/viewfrm.hxx>
67 #include <svl/intitem.hxx>
68 #include <svl/whiter.hxx>
69 #include <svx/theme/ThemeColorChangerCommon.hxx>
70 #include <vcl/commandinfoprovider.hxx>
71 #include <vcl/settings.hxx>
72 #include <vcl/svapp.hxx>
74 #include <sfx2/notebookbar/SfxNotebookBar.hxx>
76 #include <comphelper/diagnose_ex.hxx>
77 #include <comphelper/lok.hxx>
78 #include <sfx2/lokhelper.hxx>
79 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
80 #include <editeng/editview.hxx>
81 #include <tools/svborder.hxx>
82 #include <o3tl/unreachable.hxx>
84 #include <fubullet.hxx>
85 #include <drawview.hxx>
87 using namespace sd;
88 #define ShellClass_ViewShellBase
89 #include <sdslots.hxx>
91 using ::sd::framework::FrameworkHelper;
93 using namespace com::sun::star;
94 using namespace com::sun::star::beans;
95 using namespace com::sun::star::container;
96 using namespace com::sun::star::drawing::framework;
97 using namespace com::sun::star::lang;
98 using namespace com::sun::star::uno;
100 namespace {
102 class CurrentPageSetter
104 public:
105 explicit CurrentPageSetter (ViewShellBase& rBase);
106 void operator () (bool);
107 private:
108 ViewShellBase& mrBase;
111 } // end of anonymous namespace
113 namespace sd {
115 class ViewShellBase::Implementation
117 public:
118 SdViewOptions maViewOptions;
120 /** Main controller of the view shell. During the switching from one
121 stacked shell to another this pointer may be NULL.
123 ::rtl::Reference<DrawController> mpController;
125 /** The view tab bar is the control for switching between different
126 views in one pane.
128 ::rtl::Reference<ViewTabBar> mpViewTabBar;
130 // contains the complete area of the current view relative to the frame window
131 ::tools::Rectangle maClientArea;
133 // This is set to true when PrepareClose() is called.
134 bool mbIsClosing;
136 /** The view window is the parent of all UI elements that belong to the
137 view or ViewShell. This comprises the rulers, the scroll bars, and
138 the content window.
139 It does not include the ViewTabBar.
141 VclPtr<vcl::Window> mpViewWindow;
142 std::shared_ptr<ToolBarManager> mpToolBarManager;
143 std::shared_ptr<ViewShellManager> mpViewShellManager;
144 std::shared_ptr<tools::EventMultiplexer> mpEventMultiplexer;
145 std::shared_ptr<FormShellManager> mpFormShellManager;
147 explicit Implementation (ViewShellBase& rBase);
148 ~Implementation();
150 void LateInit();
152 /** Show or hide the ViewTabBar.
153 @param bShow
154 When <TRUE/> then the ViewTabBar is shown, otherwise it is hidden.
156 void ShowViewTabBar (bool bShow);
158 void SetUserWantsTabBar(bool inValue);
159 bool GetUserWantsTabBar() const { return mbUserWantsTabBar; }
161 /** Common code of ViewShellBase::OuterResizePixel() and
162 ViewShellBase::InnerResizePixel().
164 void ResizePixel (
165 const Point& rOrigin,
166 const Size& rSize,
167 bool bOuterResize);
169 /** Show or hide the specified pane. The visibility state is taken
170 from the given request.
171 @param rRequest
172 The request determines the new visibility state. The state can
173 either be toggled or be set to a given value.
174 @param rsPaneURL
175 This URL specifies the pane whose visibility state to set.
176 @param rsViewURL
177 When the pane becomes visible then this view URL specifies which
178 type of view to show in it.
180 void SetPaneVisibility (
181 const SfxRequest& rRequest,
182 const OUString& rsPaneURL,
183 const OUString& rsViewURL);
185 void GetSlotState (SfxItemSet& rSet);
187 void ProcessRestoreEditingViewSlot();
189 private:
190 ViewShellBase& mrBase;
191 bool mbUserWantsTabBar;
192 bool mbTabBarShouldBeVisible;
193 /** Hold a reference to the page cache manager of the slide sorter in
194 order to ensure that it stays alive while the ViewShellBase is
195 alive.
197 std::shared_ptr<slidesorter::cache::PageCacheManager> mpPageCacheManager;
200 namespace {
201 /** The only task of this window is to forward key presses to the content
202 window of the main view shell. With the key press it forwards the focus
203 so that it is not called very often.
205 class FocusForwardingWindow : public vcl::Window
207 public:
208 FocusForwardingWindow (vcl::Window& rParentWindow, ViewShellBase& rBase);
209 virtual ~FocusForwardingWindow() override;
210 virtual void dispose() override;
211 virtual void KeyInput (const KeyEvent& rEvent) override;
212 virtual void Command (const CommandEvent& rEvent) override;
214 private:
215 ViewShellBase& mrBase;
217 } // end of anonymous namespace
219 //===== ViewShellBase =========================================================
222 // We have to expand the SFX_IMPL_VIEWFACTORY macro to call LateInit() after a
223 // new ViewShellBase object has been constructed.
225 SFX_IMPL_SUPERCLASS_INTERFACE(ViewShellBase, SfxViewShell)
227 void ViewShellBase::InitInterface_Impl()
231 ViewShellBase::ViewShellBase (
232 SfxViewFrame& _rFrame,
233 SfxViewShell*)
234 : SfxViewShell(_rFrame, SfxViewShellFlags::HAS_PRINTOPTIONS),
235 mpDocShell (nullptr),
236 mpDocument (nullptr)
238 mpImpl.reset(new Implementation(*this));
239 mpImpl->mpViewWindow = VclPtr<FocusForwardingWindow>::Create(_rFrame.GetWindow(),*this);
240 mpImpl->mpViewWindow->SetBackground(Wallpaper());
242 _rFrame.GetWindow().SetBackground(Application::GetSettings().GetStyleSettings().GetLightColor());
244 // Set up the members in the correct order.
245 if (auto pDrawDocShell = dynamic_cast< DrawDocShell *>( GetViewFrame().GetObjectShell() ))
246 mpDocShell = pDrawDocShell;
247 if (mpDocShell != nullptr)
248 mpDocument = mpDocShell->GetDoc();
249 mpImpl->mpViewShellManager = std::make_shared<ViewShellManager>(*this);
251 SetWindow(mpImpl->mpViewWindow.get());
253 // Hide the window to avoid complaints from Sfx...SwitchViewShell...
254 _rFrame.GetWindow().Hide();
257 /** In this destructor the order in which some of the members are destroyed
258 (and/or being prepared to being destroyed) is important. Change it only
259 when you know what you are doing.
261 ViewShellBase::~ViewShellBase()
263 // Notify other LOK views that we are going away.
264 SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_VIEW_CURSOR_VISIBLE, "visible", "false"_ostr);
265 SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", ""_ostr);
266 SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_GRAPHIC_VIEW_SELECTION, "selection", "EMPTY"_ostr);
268 sfx2::SfxNotebookBar::CloseMethod(GetFrame()->GetBindings());
270 rtl::Reference<SlideShow> xSlideShow(SlideShow::GetSlideShow(*this));
271 if (xSlideShow.is() && xSlideShow->dependsOn(this))
272 SlideShow::Stop(*this);
273 xSlideShow.clear();
275 // Tell the controller that the ViewShellBase is not available anymore.
276 if (mpImpl->mpController)
277 mpImpl->mpController->ReleaseViewShellBase();
279 // We have to hide the main window to prevent SFX complaining after a
280 // reload about it being already visible.
281 ViewShell* pShell = GetMainViewShell().get();
282 if (pShell!=nullptr
283 && pShell->GetActiveWindow()!=nullptr
284 && pShell->GetActiveWindow()->GetParent()!=nullptr)
286 pShell->GetActiveWindow()->GetParent()->Hide();
289 mpImpl->mpToolBarManager->Shutdown();
290 mpImpl->mpViewShellManager->Shutdown();
292 EndListening(GetViewFrame());
293 EndListening(*GetDocShell());
295 SetWindow(nullptr);
297 mpImpl->mpFormShellManager.reset();
300 void ViewShellBase::LateInit (const OUString& rsDefaultView)
302 StartListening(GetViewFrame(), DuplicateHandling::Prevent);
303 StartListening(*GetDocShell(), DuplicateHandling::Prevent);
304 mpImpl->LateInit();
305 InitializeFramework();
307 mpImpl->mpEventMultiplexer = std::make_shared<tools::EventMultiplexer>(*this);
309 mpImpl->mpFormShellManager = std::make_shared<FormShellManager>(*this);
311 mpImpl->mpToolBarManager = ToolBarManager::Create(
312 *this,
313 mpImpl->mpEventMultiplexer,
314 mpImpl->mpViewShellManager);
318 rtl::Reference<::sd::DrawController> xControllerManager (GetDrawController());
319 Reference<XConfigurationController> xConfigurationController;
320 if (xControllerManager)
321 xConfigurationController = xControllerManager->getConfigurationController();
322 if (xConfigurationController.is())
324 OUString sView (rsDefaultView);
325 if (sView.isEmpty())
326 sView = GetInitialViewShellType();
328 FrameworkHelper::Instance(*this);
330 // Create the resource ids for the center pane and view.
331 const Reference<drawing::framework::XResourceId> xCenterPaneId (
332 FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL));
333 const Reference<drawing::framework::XResourceId> xCenterViewId (
334 FrameworkHelper::CreateResourceId(sView, xCenterPaneId));
336 // Request center pane and view.
337 xConfigurationController->requestResourceActivation(xCenterPaneId, ResourceActivationMode_ADD);
338 xConfigurationController->requestResourceActivation(xCenterViewId, ResourceActivationMode_REPLACE);
340 // Process configuration events synchronously until the center view
341 // has been created.
342 sd::framework::ConfigurationController* pConfigurationController
343 = dynamic_cast<sd::framework::ConfigurationController*>(xConfigurationController.get());
344 if (pConfigurationController != nullptr)
346 while (
347 ! pConfigurationController->getResource(xCenterViewId).is()
348 && pConfigurationController->hasPendingRequests())
350 pConfigurationController->ProcessEvent();
355 catch (const RuntimeException&)
359 // AutoLayouts have to be ready.
360 GetDocument()->StopWorkStartupDelay();
362 UpdateBorder();
364 // Remember the type of the current main view shell in the frame view.
365 ViewShell* pViewShell = GetMainViewShell().get();
366 if (pViewShell != nullptr)
368 FrameView* pFrameView = pViewShell->GetFrameView();
369 if (pFrameView != nullptr)
370 pFrameView->SetViewShellTypeOnLoad(pViewShell->GetShellType());
372 // Show/Hide the TabBar
373 SdOptions* pOptions = SdModule::get()->GetSdOptions(GetDocument()->GetDocumentType());
374 bool bIsTabBarVisible = pOptions->IsTabBarVisible();
375 mpImpl->SetUserWantsTabBar( bIsTabBarVisible );
378 std::shared_ptr<ViewShellManager> const & ViewShellBase::GetViewShellManager() const
380 return mpImpl->mpViewShellManager;
383 std::shared_ptr<ViewShell> ViewShellBase::GetMainViewShell() const
385 std::shared_ptr<ViewShell> pMainViewShell (
386 framework::FrameworkHelper::Instance(*const_cast<ViewShellBase*>(this))
387 ->GetViewShell(framework::FrameworkHelper::msCenterPaneURL));
388 if (pMainViewShell == nullptr)
389 pMainViewShell = framework::FrameworkHelper::Instance(*const_cast<ViewShellBase*>(this))
390 ->GetViewShell(framework::FrameworkHelper::msFullScreenPaneURL);
391 return pMainViewShell;
394 ViewShellBase* ViewShellBase::GetViewShellBase (SfxViewFrame const * pViewFrame)
396 ViewShellBase* pBase = nullptr;
398 if (pViewFrame != nullptr)
400 // Get the view shell for the frame and cast it to
401 // sd::ViewShellBase.
402 SfxViewShell* pSfxViewShell = pViewFrame->GetViewShell();
403 pBase = dynamic_cast< ::sd::ViewShellBase *>( pSfxViewShell );
406 return pBase;
409 void ViewShellBase::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
411 SfxViewShell::Notify(rBC, rHint);
413 const SfxHintId nHintId = rHint.GetId();
415 if (nHintId == SfxHintId::ThisIsAnSfxEventHint)
417 switch (static_cast<const SfxEventHint&>(rHint).GetEventId())
419 case SfxEventHintId::OpenDoc:
421 const sal_uInt16 nStartingSlide
422 = GetDocument() ? GetDocument()->GetStartWithPresentation() : 0;
423 if (nStartingSlide)
425 SfxUInt16Item aItem(FN_PARAM_1, nStartingSlide);
426 GetViewFrame().GetDispatcher()->ExecuteList(
427 SID_PRESENTATION, SfxCallMode::ASYNCHRON, { &aItem });
429 break;
431 default:
432 break;
435 else
437 switch (nHintId)
439 case SfxHintId::LanguageChanged:
441 GetViewFrame().GetBindings().Invalidate(SID_LANGUAGE_STATUS);
443 break;
445 default:
446 break;
451 void ViewShellBase::InitializeFramework()
455 OUString ViewShellBase::GetSelectionText(bool bCompleteWords, bool /*bOnlyASample*/)
457 std::shared_ptr<ViewShell> const pMainShell(GetMainViewShell());
458 DrawViewShell *const pDrawViewShell(
459 dynamic_cast<DrawViewShell*>(pMainShell.get()));
460 return pDrawViewShell
461 ? pDrawViewShell->GetSelectionText(bCompleteWords)
462 : SfxViewShell::GetSelectionText(bCompleteWords);
465 bool ViewShellBase::HasSelection(bool bText) const
467 std::shared_ptr<ViewShell> const pMainShell(GetMainViewShell());
468 DrawViewShell *const pDrawViewShell(
469 dynamic_cast<DrawViewShell*>(pMainShell.get()));
470 return pDrawViewShell
471 ? pDrawViewShell->HasSelection(bText)
472 : SfxViewShell::HasSelection(bText);
475 void ViewShellBase::InnerResizePixel (const Point& rOrigin, const Size &rSize, bool)
477 Size aObjSize = GetObjectShell()->GetVisArea().GetSize();
478 if ( !aObjSize.IsEmpty() )
480 SvBorder aBorder( GetBorderPixel() );
481 Size aSize( rSize );
482 aSize.AdjustWidth( -(aBorder.Left() + aBorder.Right()) );
483 aSize.AdjustHeight( -(aBorder.Top() + aBorder.Bottom()) );
484 Size aObjSizePixel = mpImpl->mpViewWindow->LogicToPixel(aObjSize, MapMode(MapUnit::Map100thMM));
485 SfxViewShell::SetZoomFactor(
486 Fraction( aSize.Width(), std::max( aObjSizePixel.Width(), static_cast<::tools::Long>(1) ) ),
487 Fraction( aSize.Height(), std::max( aObjSizePixel.Height(), static_cast<::tools::Long>(1)) ) );
490 mpImpl->ResizePixel(rOrigin, rSize, false);
493 void ViewShellBase::OuterResizePixel (const Point& rOrigin, const Size &rSize)
495 mpImpl->ResizePixel (rOrigin, rSize, true);
498 void ViewShellBase::Rearrange()
500 // There is a bug in the communication between embedded objects and the
501 // framework::LayoutManager that leads to missing resize updates. The
502 // following workaround enforces such an update by cycling the border to
503 // zero and back to the current value.
504 if (GetWindow() != nullptr)
506 SetBorderPixel(SvBorder());
507 UpdateBorder(true);
509 else
511 SAL_WARN("sd.view", "Rearrange: window missing");
514 GetViewFrame().Resize(true);
517 ErrCode ViewShellBase::DoVerb(sal_Int32 nVerb)
519 ErrCode aResult = ERRCODE_NONE;
521 ::sd::ViewShell* pShell = GetMainViewShell().get();
522 if (pShell != nullptr)
523 aResult = pShell->DoVerb(nVerb);
525 return aResult;
528 Reference<view::XRenderable> ViewShellBase::GetRenderable()
530 // Create a new DocumentRenderer on every call. It observes the life
531 // time of this ViewShellBase object.
532 return Reference<view::XRenderable>(new DocumentRenderer(*this));
535 SfxPrinter* ViewShellBase::GetPrinter (bool bCreate)
537 OSL_ASSERT(mpImpl != nullptr);
539 return GetDocShell()->GetPrinter (bCreate);
542 sal_uInt16 ViewShellBase::SetPrinter (
543 SfxPrinter* pNewPrinter,
544 SfxPrinterChangeFlags nDiffFlags)
546 OSL_ASSERT(mpImpl != nullptr);
548 GetDocShell()->SetPrinter(pNewPrinter);
550 if ( (nDiffFlags & SfxPrinterChangeFlags::CHG_ORIENTATION ||
551 nDiffFlags & SfxPrinterChangeFlags::CHG_SIZE) && pNewPrinter )
553 MapMode aMap = pNewPrinter->GetMapMode();
554 aMap.SetMapUnit(MapUnit::Map100thMM);
555 MapMode aOldMap = pNewPrinter->GetMapMode();
556 pNewPrinter->SetMapMode(aMap);
557 Size aNewSize = pNewPrinter->GetOutputSize();
559 std::shared_ptr<DrawViewShell> pDrawViewShell (
560 std::dynamic_pointer_cast<DrawViewShell>(GetMainViewShell()));
561 if (pDrawViewShell)
563 SdPage* pPage = GetDocument()->GetSdPage(
564 0, PageKind::Standard );
565 pDrawViewShell->SetPageSizeAndBorder (
566 pDrawViewShell->GetPageKind(),
567 aNewSize,
568 -1,-1,-1,-1,
569 false/*bScaleAll*/,
570 pNewPrinter->GetOrientation(),
571 pPage->GetPaperBin(),
572 pPage->IsBackgroundFullSize());
575 pNewPrinter->SetMapMode(aOldMap);
578 return 0;
581 void ViewShellBase::UIActivating( SfxInPlaceClient* pClient )
583 mpImpl->ShowViewTabBar(false);
585 ViewShell* pViewShell = GetMainViewShell().get();
586 if ( pViewShell )
587 pViewShell->UIActivating( pClient );
589 SfxViewShell::UIActivating( pClient );
592 void ViewShellBase::UIDeactivated( SfxInPlaceClient* pClient )
594 SfxViewShell::UIDeactivated( pClient );
596 mpImpl->ShowViewTabBar(true);
598 ViewShell* pViewShell = GetMainViewShell().get();
599 if ( pViewShell )
600 pViewShell->UIDeactivated( pClient );
603 SvBorder ViewShellBase::GetBorder (bool )
605 int nTop = 0;
606 if (mpImpl->mpViewTabBar.is() && mpImpl->mpViewTabBar->GetTabControl()->IsVisible())
607 nTop = mpImpl->mpViewTabBar->GetHeight();
608 return SvBorder(0,nTop,0,0);
611 void ViewShellBase::Execute (SfxRequest& rRequest)
613 sal_uInt16 nSlotId = rRequest.GetSlot();
615 switch (nSlotId)
617 case SID_SWITCH_SHELL:
619 DrawController* pDrawController(GetDrawController());
620 if (pDrawController)
622 Reference<XConfigurationController> xConfigurationController (
623 pDrawController->getConfigurationController());
624 if (xConfigurationController.is())
625 xConfigurationController->update();
628 break;
630 case SID_LEFT_PANE_DRAW:
631 mpImpl->SetPaneVisibility(
632 rRequest,
633 framework::FrameworkHelper::msLeftDrawPaneURL,
634 framework::FrameworkHelper::msSlideSorterURL);
635 break;
637 case SID_LEFT_PANE_IMPRESS:
638 mpImpl->SetPaneVisibility(
639 rRequest,
640 framework::FrameworkHelper::msLeftImpressPaneURL,
641 framework::FrameworkHelper::msSlideSorterURL);
642 break;
644 case SID_BOTTOM_PANE_IMPRESS:
645 mpImpl->SetPaneVisibility(
646 rRequest,
647 framework::FrameworkHelper::msBottomImpressPaneURL,
648 framework::FrameworkHelper::msNotesPanelViewURL);
649 break;
651 case SID_TOGGLE_TABBAR_VISIBILITY:
653 SdOptions* pOptions = SdModule::get()->GetSdOptions(GetDocument()->GetDocumentType());
654 bool bIsTabBarVisible = pOptions->IsTabBarVisible();
655 pOptions->SetTabBarVisible( !bIsTabBarVisible );
656 mpImpl->SetUserWantsTabBar( !bIsTabBarVisible );
657 rRequest.Done();
659 break;
661 // draw
662 case SID_DRAWINGMODE:
663 // impress normal
664 case SID_NORMAL_MULTI_PANE_GUI:
665 case SID_NOTES_MODE:
666 case SID_OUTLINE_MODE:
667 case SID_SLIDE_SORTER_MULTI_PANE_GUI:
668 case SID_SLIDE_SORTER_MODE:
669 // impress master
670 case SID_SLIDE_MASTER_MODE:
671 case SID_NOTES_MASTER_MODE:
672 case SID_HANDOUT_MASTER_MODE:
673 framework::FrameworkHelper::Instance(*this)->HandleModeChangeSlot(nSlotId, rRequest);
674 break;
676 case SID_WIN_FULLSCREEN:
677 // The full screen mode is not supported. Ignore the request.
678 break;
680 case SID_RESTORE_EDITING_VIEW:
681 mpImpl->ProcessRestoreEditingViewSlot();
682 break;
684 default:
685 // Ignore any other slot.
686 rRequest.Ignore ();
687 break;
691 void ViewShellBase::GetState (SfxItemSet& rSet)
693 mpImpl->GetSlotState(rSet);
695 FuBullet::GetSlotState( rSet, nullptr, &GetViewFrame() );
698 void ViewShellBase::WriteUserDataSequence (
699 css::uno::Sequence< css::beans::PropertyValue >& rSequence)
701 // Forward call to main sub shell.
702 ViewShell* pShell = GetMainViewShell().get();
703 if (pShell != nullptr)
704 pShell->WriteUserDataSequence (rSequence);
707 void ViewShellBase::ReadUserDataSequence (
708 const css::uno::Sequence< css::beans::PropertyValue >& rSequence)
710 // Forward call to main sub shell.
711 ViewShell* pShell = GetMainViewShell().get();
712 if (pShell == nullptr)
713 return;
715 pShell->ReadUserDataSequence (rSequence);
717 // For certain shell types ReadUserDataSequence may have changed the
718 // type to another one. Make sure that the center pane shows the
719 // right view shell.
720 switch (pShell->GetShellType())
722 case ViewShell::ST_IMPRESS:
723 case ViewShell::ST_NOTES:
724 case ViewShell::ST_HANDOUT:
726 OUString sViewURL;
727 switch (dynamic_cast<DrawViewShell&>(*pShell).GetPageKind())
729 default:
730 case PageKind::Standard:
731 sViewURL = framework::FrameworkHelper::msImpressViewURL;
732 break;
733 case PageKind::Notes:
734 sViewURL = framework::FrameworkHelper::msNotesViewURL;
735 break;
736 case PageKind::Handout:
737 sViewURL = framework::FrameworkHelper::msHandoutViewURL;
738 break;
740 if (!sViewURL.isEmpty())
741 framework::FrameworkHelper::Instance(*this)->RequestView(
742 sViewURL,
743 framework::FrameworkHelper::msCenterPaneURL);
745 break;
747 default:
748 break;
752 void ViewShellBase::Activate (bool bIsMDIActivate)
754 SfxViewShell::Activate(bIsMDIActivate);
756 DrawController* pDrawController(GetDrawController());
757 if (pDrawController)
759 Reference<XConfigurationController> xConfigurationController (
760 pDrawController->getConfigurationController());
761 if (xConfigurationController.is())
762 xConfigurationController->update();
764 GetToolBarManager()->RequestUpdate();
767 void ViewShellBase::SetZoomFactor (
768 const Fraction &rZoomX,
769 const Fraction &rZoomY)
771 SfxViewShell::SetZoomFactor (rZoomX, rZoomY);
772 // Forward call to main sub shell.
773 ViewShell* pShell = GetMainViewShell().get();
774 if (pShell != nullptr)
775 pShell->SetZoomFactor (rZoomX, rZoomY);
778 bool ViewShellBase::PrepareClose (bool bUI)
780 bool bResult = SfxViewShell::PrepareClose (bUI);
782 if (bResult)
784 mpImpl->mbIsClosing = true;
786 // Forward call to main sub shell.
787 ViewShell* pShell = GetMainViewShell().get();
788 if (pShell != nullptr)
789 bResult = pShell->PrepareClose (bUI);
792 return bResult;
795 void ViewShellBase::WriteUserData (OUString& rString, bool bBrowse)
797 SfxViewShell::WriteUserData (rString, bBrowse);
799 // Forward call to main sub shell.
800 ViewShell* pShell = GetMainViewShell().get();
801 if (pShell != nullptr)
802 pShell->WriteUserData();
805 void ViewShellBase::ReadUserData (const OUString& rString, bool bBrowse)
807 SfxViewShell::ReadUserData (rString, bBrowse);
809 // Forward call to main sub shell.
810 ViewShell* pShell = GetMainViewShell().get();
811 if (pShell != nullptr)
812 pShell->ReadUserData();
815 SdrView* ViewShellBase::GetDrawView() const
817 // Forward call to main sub shell.
818 ViewShell* pShell = GetMainViewShell().get();
819 if (pShell != nullptr)
820 return pShell->GetDrawView ();
822 return nullptr;
825 void ViewShellBase::SetBusyState (bool bBusy)
827 if (GetDocShell() != nullptr)
828 GetDocShell()->SetWaitCursor (bBusy);
831 void ViewShellBase::UpdateBorder ( bool bForce /* = false */ )
833 // The following calls to SetBorderPixel() and InvalidateBorder() are
834 // made only for the main view shell. This not only avoids unnecessary
835 // calls for the views in side panes but prevents calling an already
836 // dying SfxViewShell base class.
837 // We have to check the existence of the window, too.
838 // The SfxViewFrame accesses the window without checking it.
839 ViewShell* pMainViewShell = GetMainViewShell().get();
840 if (pMainViewShell == nullptr || GetWindow()==nullptr)
841 return;
843 SvBorder aCurrentBorder (GetBorderPixel());
844 bool bOuterResize ( ! GetDocShell()->IsInPlaceActive());
845 SvBorder aBorder (GetBorder(bOuterResize));
846 aBorder += pMainViewShell->GetBorder();
848 if (bForce || (aBorder != aCurrentBorder))
850 SetBorderPixel (aBorder);
851 InvalidateBorder();
855 void ViewShellBase::ShowUIControls (bool bVisible)
857 mpImpl->ShowViewTabBar(bVisible);
859 ViewShell* pMainViewShell = GetMainViewShell().get();
860 if (pMainViewShell != nullptr)
861 pMainViewShell->ShowUIControls (bVisible);
863 UpdateBorder();
864 if (bVisible)
865 Rearrange();
868 OUString ViewShellBase::GetInitialViewShellType() const
870 OUString sRequestedView (FrameworkHelper::msImpressViewURL);
874 Reference<document::XViewDataSupplier> xViewDataSupplier (
875 GetDocShell()->GetModel(), UNO_QUERY);
876 if ( ! xViewDataSupplier.is())
877 break;
879 Reference<container::XIndexAccess> xViewData (xViewDataSupplier->getViewData());
880 if ( ! xViewData.is())
881 break;
882 if (xViewData->getCount() == 0)
883 break;
885 css::uno::Any aAny = xViewData->getByIndex(0);
886 Sequence<beans::PropertyValue> aProperties;
887 if ( ! (aAny >>= aProperties))
888 break;
890 // Search the properties for the one that tells us what page kind to
891 // use.
892 auto pProperty = std::find_if(std::cbegin(aProperties), std::cend(aProperties),
893 [](const beans::PropertyValue& rProperty) { return rProperty.Name == sUNO_View_PageKind; });
894 if (pProperty != std::cend(aProperties))
896 sal_Int16 nPageKind = 0;
897 pProperty->Value >>= nPageKind;
898 switch (static_cast<PageKind>(nPageKind))
900 case PageKind::Standard:
901 sRequestedView = FrameworkHelper::msImpressViewURL;
902 break;
904 case PageKind::Handout:
905 sRequestedView = FrameworkHelper::msHandoutViewURL;
906 break;
908 case PageKind::Notes:
909 sRequestedView = FrameworkHelper::msNotesViewURL;
910 break;
912 default:
913 // The page kind is invalid. This is probably an
914 // error by the caller. We use the standard type to
915 // keep things going.
916 SAL_WARN( "sd.view", "ViewShellBase::GetInitialViewShellType: invalid page kind");
917 sRequestedView = FrameworkHelper::msImpressViewURL;
918 break;
922 while (false);
924 return sRequestedView;
927 const SdViewOptions& ViewShellBase::GetViewOptions() const
929 return mpImpl->maViewOptions;
932 void ViewShellBase::SetViewOptions(const SdViewOptions& rOptions) const
934 mpImpl->maViewOptions = rOptions;
937 std::shared_ptr<tools::EventMultiplexer> const & ViewShellBase::GetEventMultiplexer() const
939 OSL_ASSERT(mpImpl != nullptr);
940 OSL_ASSERT(mpImpl->mpEventMultiplexer != nullptr);
942 return mpImpl->mpEventMultiplexer;
945 const ::tools::Rectangle& ViewShellBase::getClientRectangle() const
947 return mpImpl->maClientArea;
950 std::shared_ptr<ToolBarManager> const & ViewShellBase::GetToolBarManager() const
952 OSL_ASSERT(mpImpl != nullptr);
953 OSL_ASSERT(mpImpl->mpToolBarManager != nullptr);
955 return mpImpl->mpToolBarManager;
958 std::shared_ptr<FormShellManager> const & ViewShellBase::GetFormShellManager() const
960 OSL_ASSERT(mpImpl != nullptr);
961 OSL_ASSERT(mpImpl->mpFormShellManager != nullptr);
963 return mpImpl->mpFormShellManager;
966 DrawController* ViewShellBase::GetDrawController() const
968 OSL_ASSERT(mpImpl != nullptr);
970 return mpImpl->mpController.get();
973 void ViewShellBase::SetViewTabBar (const ::rtl::Reference<ViewTabBar>& rViewTabBar)
975 OSL_ASSERT(mpImpl != nullptr);
977 mpImpl->mpViewTabBar = rViewTabBar;
980 vcl::Window* ViewShellBase::GetViewWindow()
982 OSL_ASSERT(mpImpl != nullptr);
984 return mpImpl->mpViewWindow.get();
987 OUString ViewShellBase::RetrieveLabelFromCommand( const OUString& aCmdURL ) const
989 OUString aModuleName;
990 if (SfxViewFrame* pViewFrame = GetMainViewShell()->GetViewFrame())
991 aModuleName = vcl::CommandInfoProvider::GetModuleIdentifier(pViewFrame->GetFrame().GetFrameInterface());
992 auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(aCmdURL, aModuleName);
993 return vcl::CommandInfoProvider::GetLabelForCommand(aProperties);
996 int ViewShellBase::getPart() const
998 ViewShell* pViewShell = framework::FrameworkHelper::Instance(*const_cast<ViewShellBase*>(this))->GetViewShell(FrameworkHelper::msCenterPaneURL).get();
1000 if (DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(pViewShell))
1002 return pDrawViewShell->GetCurPagePos();
1005 return 0;
1008 int ViewShellBase::getEditMode() const
1010 ViewShell* pViewShell = framework::FrameworkHelper::Instance(*const_cast<ViewShellBase*>(this))->GetViewShell(FrameworkHelper::msCenterPaneURL).get();
1012 if (DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(pViewShell))
1014 switch ( pDrawViewShell->GetEditMode() )
1016 case EditMode::Page:
1017 switch (pDrawViewShell->GetPageKind())
1019 case PageKind::Standard:
1020 return 0;
1021 case PageKind::Notes:
1022 return 2;
1023 default:
1024 assert(!"Unhandled page kind");
1025 return 0;
1027 case EditMode::MasterPage:
1028 switch (pDrawViewShell->GetPageKind())
1030 case PageKind::Standard:
1031 return 1;
1032 default:
1033 assert(!"Unhandled page kind");
1034 return 1;
1039 return 0;
1042 void ViewShellBase::setEditMode(int nMode)
1044 ViewShell* pViewShell = framework::FrameworkHelper::Instance(*this)->GetViewShell(FrameworkHelper::msCenterPaneURL).get();
1046 if (DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(pViewShell))
1048 EditMode eOrigEditMode = pDrawViewShell->GetEditMode();
1049 PageKind eOrigPageKind = pDrawViewShell->GetPageKind();
1050 sal_uInt16 nSelectedPage = pDrawViewShell->GetCurPagePos();
1052 switch ( nMode )
1054 case 0:
1055 pDrawViewShell->SetPageKind(PageKind::Standard);
1056 pDrawViewShell->ChangeEditMode(EditMode::Page, false);
1057 break;
1058 case 1:
1059 pDrawViewShell->SetPageKind(PageKind::Standard);
1060 pDrawViewShell->ChangeEditMode(EditMode::MasterPage, false);
1061 break;
1062 case 2:
1063 pDrawViewShell->SetPageKind(PageKind::Notes);
1064 pDrawViewShell->ChangeEditMode(EditMode::Page, false);
1065 break;
1069 If the EditMode is unchanged, then ChangeEditMode was typically a
1070 no-op, and an additional explicit SwitchPage is required to reselect
1071 the equivalent page from the other mode, otherwise a switch from
1072 e.g. Notes to Standard will still render the still selected Note
1073 page.
1075 if (eOrigEditMode == pDrawViewShell->GetEditMode() &&
1076 eOrigPageKind != pDrawViewShell->GetPageKind())
1078 pDrawViewShell->SwitchPage(nSelectedPage);
1083 void ViewShellBase::afterCallbackRegistered()
1085 // common tasks
1086 SfxViewShell::afterCallbackRegistered();
1088 SfxObjectShell* pDocShell = GetObjectShell();
1089 if (pDocShell)
1091 std::shared_ptr<model::ColorSet> pThemeColors = pDocShell->GetThemeColors();
1092 std::set<Color> aDocumentColors = pDocShell->GetDocColors();
1093 svx::theme::notifyLOK(pThemeColors, aDocumentColors);
1096 if (comphelper::LibreOfficeKit::isActive() && mpDocument && mpDocument->GetStartWithPresentation())
1098 // Be consistent with SidebarController, emit JSON.
1099 boost::property_tree::ptree aTree;
1100 aTree.put("commandName", ".uno:StartWithPresentation");
1101 aTree.put("state", "true");
1102 std::stringstream aStream;
1103 boost::property_tree::write_json(aStream, aTree);
1104 libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, OString(aStream.str()));
1108 void ViewShellBase::NotifyCursor(SfxViewShell* pOtherShell) const
1110 ViewShell* pThisShell = framework::FrameworkHelper::Instance(*const_cast<ViewShellBase*>(this))->GetViewShell(FrameworkHelper::msCenterPaneURL).get();
1112 DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(pThisShell);
1113 if (!pDrawViewShell)
1114 return;
1116 if (this == pOtherShell)
1117 return;
1119 DrawView* pDrawView = pDrawViewShell->GetDrawView();
1120 if (!pDrawView)
1121 return;
1123 if (pDrawView->GetTextEditObject())
1125 // Blinking cursor.
1126 EditView& rEditView = pDrawView->GetTextEditOutlinerView()->GetEditView();
1127 rEditView.RegisterOtherShell(pOtherShell);
1128 rEditView.ShowCursor();
1129 rEditView.RegisterOtherShell(nullptr);
1130 // Text selection, if any.
1131 rEditView.DrawSelectionXOR(pOtherShell);
1133 // Shape text lock.
1134 if (OutlinerView* pOutlinerView = pDrawView->GetTextEditOutlinerView())
1136 ::tools::Rectangle aRectangle = pOutlinerView->GetOutputArea();
1137 vcl::Window* pWin = pThisShell->GetActiveWindow();
1138 if (pWin && pWin->GetMapMode().GetMapUnit() == MapUnit::Map100thMM)
1139 aRectangle = o3tl::toTwips(aRectangle, o3tl::Length::mm100);
1140 OString sRectangle = aRectangle.toString();
1141 SfxLokHelper::notifyOtherView(&pDrawViewShell->GetViewShellBase(), pOtherShell, LOK_CALLBACK_VIEW_LOCK, "rectangle", sRectangle);
1144 else
1146 // Graphic selection.
1147 pDrawView->AdjustMarkHdl(pOtherShell);
1151 ::Color ViewShellBase::GetColorConfigColor(svtools::ColorConfigEntry nColorType) const
1153 Color aColor;
1155 const SdViewOptions& rViewOptions = GetViewOptions();
1156 switch (nColorType)
1158 case svtools::ColorConfigEntry::DOCCOLOR:
1160 aColor = rViewOptions.mnDocBackgroundColor;
1161 break;
1163 // Should never be called for an unimplemented color type
1164 default:
1166 O3TL_UNREACHABLE;
1170 return aColor;
1173 //===== ViewShellBase::Implementation =========================================
1175 ViewShellBase::Implementation::Implementation (ViewShellBase& rBase)
1176 : mbIsClosing(false),
1177 mrBase(rBase),
1178 mbUserWantsTabBar(false),
1179 mbTabBarShouldBeVisible(true),
1180 mpPageCacheManager(slidesorter::cache::PageCacheManager::Instance())
1184 ViewShellBase::Implementation::~Implementation()
1186 mpController = nullptr;
1187 mpViewTabBar = nullptr;
1188 mpViewWindow.disposeAndClear();
1189 mpToolBarManager.reset();
1192 void ViewShellBase::Implementation::LateInit()
1194 mpController = new DrawController(mrBase);
1197 void ViewShellBase::Implementation::ProcessRestoreEditingViewSlot()
1199 ViewShell* pViewShell = mrBase.GetMainViewShell().get();
1200 if (pViewShell == nullptr)
1201 return;
1203 FrameView* pFrameView = pViewShell->GetFrameView();
1204 if (pFrameView == nullptr)
1205 return;
1207 // Set view shell, edit mode, and page kind.
1208 // pFrameView->SetViewShEditMode(
1209 // pFrameView->GetViewShEditModeOnLoad(),
1210 // pFrameView->GetPageKindOnLoad());
1211 pFrameView->SetViewShEditMode(
1212 pFrameView->GetViewShEditModeOnLoad() );
1213 pFrameView->SetPageKind(
1214 pFrameView->GetPageKindOnLoad());
1215 std::shared_ptr<FrameworkHelper> pHelper (FrameworkHelper::Instance(mrBase));
1216 pHelper->RequestView(
1217 FrameworkHelper::GetViewURL(pFrameView->GetViewShellTypeOnLoad()),
1218 FrameworkHelper::msCenterPaneURL);
1219 pHelper->RunOnConfigurationEvent(u"ConfigurationUpdateEnd"_ustr, CurrentPageSetter(mrBase));
1222 void ViewShellBase::Implementation::SetUserWantsTabBar(bool inValue)
1224 mbUserWantsTabBar = inValue;
1225 // Call ShowViewTabBar to refresh the TabBar visibility
1226 ShowViewTabBar(mbTabBarShouldBeVisible);
1229 void ViewShellBase::Implementation::ShowViewTabBar (bool bShow)
1231 mbTabBarShouldBeVisible = bShow;
1232 bShow = bShow && mbUserWantsTabBar;
1234 if (mpViewTabBar.is()
1235 && mpViewTabBar->GetTabControl()->IsVisible() != bShow)
1237 mpViewTabBar->GetTabControl()->Show(bShow);
1238 mrBase.Rearrange();
1242 void ViewShellBase::Implementation::ResizePixel (
1243 const Point& rOrigin,
1244 const Size &rSize,
1245 bool bOuterResize)
1247 if (mbIsClosing)
1248 return;
1250 // Forward the call to both the base class and the main stacked sub
1251 // shell only when main sub shell exists.
1252 ViewShell* pMainViewShell = mrBase.GetMainViewShell().get();
1254 // Set the ViewTabBar temporarily to full size so that, when asked
1255 // later, it can return its true height.
1256 mrBase.SetWindow (mpViewWindow.get());
1257 if (mpViewTabBar.is() && mpViewTabBar->GetTabControl()->IsVisible())
1258 mpViewTabBar->GetTabControl()->SetPosSizePixel (rOrigin, rSize);
1260 // Calculate and set the border before the controls are placed.
1261 SvBorder aBorder;
1262 if (pMainViewShell != nullptr)
1263 aBorder = pMainViewShell->GetBorder();
1264 aBorder += mrBase.GetBorder(bOuterResize);
1265 if (mrBase.GetBorderPixel() != aBorder)
1266 mrBase.SetBorderPixel(aBorder);
1268 // Place the ViewTabBar at the top. It is part of the border.
1269 SvBorder aBaseBorder;
1270 if (mpViewTabBar.is() && mpViewTabBar->GetTabControl()->IsVisible())
1272 aBaseBorder.Top() = mpViewTabBar->GetHeight();
1273 mpViewTabBar->GetTabControl()->SetPosSizePixel(
1274 rOrigin, Size(rSize.Width(),aBaseBorder.Top()));
1277 // The view window gets the remaining space.
1278 Point aViewWindowPosition (
1279 rOrigin.X()+aBaseBorder.Left(),
1280 rOrigin.Y()+aBaseBorder.Top());
1282 Size aViewWindowSize (
1283 rSize.Width() - aBaseBorder.Left() - aBaseBorder.Right(),
1284 rSize.Height() - aBaseBorder.Top() - aBaseBorder.Bottom());
1285 mpViewWindow->SetPosSizePixel(aViewWindowPosition, aViewWindowSize);
1287 maClientArea = ::tools::Rectangle(Point(0,0), aViewWindowSize);
1290 void ViewShellBase::Implementation::SetPaneVisibility (
1291 const SfxRequest& rRequest,
1292 const OUString& rsPaneURL,
1293 const OUString& rsViewURL)
1297 DrawController* pDrawController(mrBase.GetDrawController());
1298 if (!pDrawController)
1299 return;
1301 const Reference< XComponentContext >& xContext(
1302 ::comphelper::getProcessComponentContext() );
1303 Reference<XResourceId> xPaneId (ResourceId::create(
1304 xContext, rsPaneURL));
1305 Reference<XResourceId> xViewId (ResourceId::createWithAnchorURL(
1306 xContext, rsViewURL, rsPaneURL));
1308 // Determine the new visibility state.
1309 const SfxItemSet* pArguments = rRequest.GetArgs();
1310 bool bShowChildWindow;
1311 sal_uInt16 nSlotId = rRequest.GetSlot();
1312 if (pArguments != nullptr)
1313 bShowChildWindow = static_cast<const SfxBoolItem&>(
1314 pArguments->Get(nSlotId)).GetValue();
1315 else
1317 Reference<XConfigurationController> xConfigurationController (
1318 pDrawController->getConfigurationController());
1319 if ( ! xConfigurationController.is())
1320 throw RuntimeException();
1321 Reference<XConfiguration> xConfiguration (
1322 xConfigurationController->getRequestedConfiguration());
1323 if ( ! xConfiguration.is())
1324 throw RuntimeException();
1326 bShowChildWindow = ! xConfiguration->hasResource(xPaneId);
1329 // Set the desired visibility state at the current configuration
1330 // and update it accordingly.
1331 Reference<XConfigurationController> xConfigurationController (
1332 pDrawController->getConfigurationController());
1333 if ( ! xConfigurationController.is())
1334 throw RuntimeException();
1335 if (bShowChildWindow)
1337 xConfigurationController->requestResourceActivation(
1338 xPaneId,
1339 ResourceActivationMode_ADD);
1340 xConfigurationController->requestResourceActivation(
1341 xViewId,
1342 ResourceActivationMode_REPLACE);
1344 else
1345 xConfigurationController->requestResourceDeactivation(
1346 xPaneId);
1348 catch (const Exception&)
1350 DBG_UNHANDLED_EXCEPTION("sd.view");
1354 void ViewShellBase::Implementation::GetSlotState (SfxItemSet& rSet)
1358 // Get some frequently used values.
1359 DrawController* pDrawController(mrBase.GetDrawController());
1360 if (!pDrawController)
1361 return;
1362 Reference<XConfigurationController> xConfigurationController (
1363 pDrawController->getConfigurationController());
1364 if ( ! xConfigurationController.is())
1365 throw RuntimeException();
1366 Reference<XConfiguration> xConfiguration (
1367 xConfigurationController->getRequestedConfiguration());
1368 if ( ! xConfiguration.is())
1369 throw RuntimeException();
1371 const Reference< XComponentContext >& xContext(
1372 ::comphelper::getProcessComponentContext() );
1373 SfxWhichIter aSetIterator (rSet);
1374 sal_uInt16 nItemId (aSetIterator.FirstWhich());
1376 while (nItemId > 0)
1378 bool bState (false);
1379 Reference<XResourceId> xResourceId;
1382 // Check if the right view is active
1383 switch (nItemId)
1385 case SID_LEFT_PANE_IMPRESS:
1386 xResourceId = ResourceId::create(
1387 xContext, FrameworkHelper::msLeftImpressPaneURL);
1388 bState = xConfiguration->hasResource(xResourceId);
1389 break;
1391 case SID_LEFT_PANE_DRAW:
1392 xResourceId = ResourceId::create(
1393 xContext, FrameworkHelper::msLeftDrawPaneURL);
1394 bState = xConfiguration->hasResource(xResourceId);
1395 break;
1397 case SID_BOTTOM_PANE_IMPRESS:
1398 xResourceId = ResourceId::create(
1399 xContext, FrameworkHelper::msBottomImpressPaneURL);
1400 bState = xConfiguration->hasResource(xResourceId);
1401 break;
1403 case SID_DRAWINGMODE:
1404 case SID_NORMAL_MULTI_PANE_GUI:
1405 case SID_SLIDE_MASTER_MODE:
1406 xResourceId = ResourceId::createWithAnchorURL(
1407 xContext, FrameworkHelper::msImpressViewURL,
1408 FrameworkHelper::msCenterPaneURL);
1409 bState = xConfiguration->hasResource(xResourceId);
1410 break;
1412 case SID_SLIDE_SORTER_MULTI_PANE_GUI:
1413 case SID_SLIDE_SORTER_MODE:
1414 xResourceId = ResourceId::createWithAnchorURL(
1415 xContext,
1416 FrameworkHelper::msSlideSorterURL,
1417 FrameworkHelper::msCenterPaneURL);
1418 bState = xConfiguration->hasResource(xResourceId);
1419 break;
1421 case SID_OUTLINE_MODE:
1422 xResourceId = ResourceId::createWithAnchorURL(
1423 xContext,
1424 FrameworkHelper::msOutlineViewURL,
1425 FrameworkHelper::msCenterPaneURL);
1426 bState = xConfiguration->hasResource(xResourceId);
1427 break;
1429 case SID_HANDOUT_MASTER_MODE:
1430 xResourceId = ResourceId::createWithAnchorURL(
1431 xContext, FrameworkHelper::msHandoutViewURL,
1432 FrameworkHelper::msCenterPaneURL);
1433 bState = xConfiguration->hasResource(xResourceId);
1434 break;
1436 case SID_NOTES_MODE:
1437 case SID_NOTES_MASTER_MODE:
1438 xResourceId = ResourceId::createWithAnchorURL(
1439 xContext, FrameworkHelper::msNotesViewURL,
1440 FrameworkHelper::msCenterPaneURL);
1441 bState = xConfiguration->hasResource(xResourceId);
1442 break;
1444 case SID_TOGGLE_TABBAR_VISIBILITY:
1445 bState = GetUserWantsTabBar();
1446 break;
1448 default:
1449 // Ignore all other items. They are not meant to be
1450 // handled by us.
1451 break;
1454 catch (const DeploymentException&)
1458 // Check if edit mode fits too
1459 if (bState)
1461 ViewShell* const pCenterViewShell = FrameworkHelper::Instance(mrBase)->GetViewShell(
1462 FrameworkHelper::msCenterPaneURL).get();
1463 DrawViewShell* const pShell = dynamic_cast<DrawViewShell*>(pCenterViewShell);
1464 if (pShell)
1466 switch (nItemId)
1468 case SID_DRAWINGMODE:
1469 case SID_NORMAL_MULTI_PANE_GUI:
1470 case SID_NOTES_MODE:
1471 bState = pShell->GetEditMode() == EditMode::Page;
1472 break;
1473 case SID_SLIDE_MASTER_MODE:
1474 case SID_NOTES_MASTER_MODE:
1475 bState = pShell->GetEditMode() == EditMode::MasterPage;
1476 break;
1481 // And finally set the state.
1482 rSet.Put(SfxBoolItem(nItemId, bState));
1484 nItemId = aSetIterator.NextWhich();
1487 catch (const RuntimeException&)
1489 DBG_UNHANDLED_EXCEPTION("sd.view");
1494 } // end of namespace sd
1496 //===== CurrentPageSetter ===========================================
1498 namespace {
1500 CurrentPageSetter::CurrentPageSetter (ViewShellBase& rBase)
1501 : mrBase(rBase)
1505 void CurrentPageSetter::operator() (bool)
1507 FrameView* pFrameView = nullptr;
1509 if (auto pViewShell = mrBase.GetMainViewShell().get())
1511 pFrameView = pViewShell->GetFrameView();
1514 if (pFrameView==nullptr)
1515 return;
1519 // Get the current page either from the DrawPagesSupplier or the
1520 // MasterPagesSupplier.
1521 Any aPage;
1522 if (pFrameView->GetViewShEditModeOnLoad() == EditMode::Page)
1524 Reference<drawing::XDrawPagesSupplier> xPagesSupplier (
1525 mrBase.GetController()->getModel(), UNO_QUERY_THROW);
1526 Reference<container::XIndexAccess> xPages (
1527 xPagesSupplier->getDrawPages(), UNO_QUERY_THROW);
1528 aPage = xPages->getByIndex(pFrameView->GetSelectedPageOnLoad());
1530 else
1532 Reference<drawing::XMasterPagesSupplier> xPagesSupplier (
1533 mrBase.GetController()->getModel(), UNO_QUERY_THROW);
1534 Reference<container::XIndexAccess> xPages (
1535 xPagesSupplier->getMasterPages(), UNO_QUERY_THROW);
1536 aPage = xPages->getByIndex(pFrameView->GetSelectedPageOnLoad());
1538 // Switch to the page last edited by setting the CurrentPage
1539 // property.
1540 DrawController* pDrawController = mrBase.GetDrawController();
1541 pDrawController->setPropertyValue (u"CurrentPage"_ustr, aPage);
1543 catch (const RuntimeException&)
1545 // We have not been able to set the current page at the main view.
1546 // This is sad but still leaves us in a valid state. Therefore,
1547 // this exception is silently ignored.
1549 catch (const beans::UnknownPropertyException&)
1551 SAL_WARN("sd.view", "CurrentPage property unknown");
1555 } // end of anonymous namespace
1557 SdViewOptions::SdViewOptions()
1558 : msColorSchemeName(u"Default"_ustr)
1560 const svtools::ColorConfig& rColorConfig = SdModule::get()->GetColorConfig();
1561 mnAppBackgroundColor = rColorConfig.GetColorValue(svtools::APPBACKGROUND).nColor;
1562 mnDocBackgroundColor = rColorConfig.GetColorValue(svtools::DOCCOLOR).nColor;
1565 //===== FocusForwardingWindow =================================================
1567 namespace sd {
1568 namespace {
1570 FocusForwardingWindow::FocusForwardingWindow (
1571 vcl::Window& rParentWindow,
1572 ViewShellBase& rBase)
1573 : vcl::Window(&rParentWindow, WinBits(WB_CLIPCHILDREN | WB_DIALOGCONTROL)),
1574 mrBase(rBase)
1576 SAL_INFO("sd.view", "created FocusForwardingWindow at " << this);
1579 FocusForwardingWindow::~FocusForwardingWindow()
1581 disposeOnce();
1584 void FocusForwardingWindow::dispose()
1586 SAL_INFO("sd.view", "destroyed FocusForwardingWindow at " << this);
1587 vcl::Window::dispose();
1590 void FocusForwardingWindow::KeyInput (const KeyEvent& rKEvt)
1592 std::shared_ptr<ViewShell> pViewShell = mrBase.GetMainViewShell();
1593 if (pViewShell != nullptr)
1595 vcl::Window* pWindow = pViewShell->GetActiveWindow();
1596 if (pWindow != nullptr)
1598 // Forward the focus so that the window is called directly the
1599 // next time.
1600 pWindow->GrabFocus();
1601 // Forward the key press as well.
1602 pWindow->KeyInput(rKEvt);
1607 void FocusForwardingWindow::Command (const CommandEvent& rEvent)
1609 std::shared_ptr<ViewShell> pViewShell = mrBase.GetMainViewShell();
1610 if (pViewShell != nullptr)
1612 vcl::Window* pWindow = pViewShell->GetActiveWindow();
1613 if (pWindow != nullptr)
1615 pWindow->Command(rEvent);
1620 } // end of anonymous namespace
1622 } // end of namespace sd
1624 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */