1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 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/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 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 . 18 */ 19 20 #ifndef INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERVIEWFACTORY_HXX 21 #define INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERVIEWFACTORY_HXX 22 23 #include "PresenterController.hxx" 24 #include <cppuhelper/compbase.hxx> 25 #include <cppuhelper/basemutex.hxx> 26 #include <com/sun/star/drawing/framework/XConfigurationController.hpp> 27 #include <com/sun/star/drawing/framework/XResourceFactory.hpp> 28 #include <com/sun/star/drawing/framework/XView.hpp> 29 #include <com/sun/star/uno/XComponentContext.hpp> 30 #include <rtl/ref.hxx> 31 #include <memory> 32 33 namespace sdext::presenter { 34 35 typedef ::cppu::WeakComponentImplHelper < 36 css::drawing::framework::XResourceFactory 37 > PresenterViewFactoryInterfaceBase; 38 39 /** Base class for presenter views that allows the view factory to store 40 them in a cache and reuse deactivated views. 41 */ 42 class CachablePresenterView 43 { 44 public: 45 virtual void ActivatePresenterView(); 46 47 /** Called when the view is put into a cache. The view must not paint 48 itself while being deactivated. 49 */ 50 virtual void DeactivatePresenterView(); 51 52 /** Called before the view is disposed. This gives the view the 53 opportunity to trigger actions that may lead to (synchronous) 54 callbacks that do not result in DisposedExceptions. 55 */ 56 virtual void ReleaseView(); 57 58 protected: 59 bool mbIsPresenterViewActive; 60 61 CachablePresenterView(); 62 ~CachablePresenterView()63 ~CachablePresenterView() {} 64 }; 65 66 /** Factory of the presenter screen specific views. The supported set of 67 views includes: 68 a life view of the current slide, 69 a static preview of the next slide, 70 the notes of the current slide, 71 a tool bar 72 */ 73 class PresenterViewFactory 74 : public ::cppu::BaseMutex, 75 public PresenterViewFactoryInterfaceBase 76 { 77 public: 78 static constexpr OUStringLiteral msCurrentSlidePreviewViewURL 79 = u"private:resource/view/Presenter/CurrentSlidePreview"; 80 static constexpr OUStringLiteral msNextSlidePreviewViewURL 81 = u"private:resource/view/Presenter/NextSlidePreview"; 82 static constexpr OUStringLiteral msNotesViewURL = u"private:resource/view/Presenter/Notes"; 83 static constexpr OUStringLiteral msToolBarViewURL = u"private:resource/view/Presenter/ToolBar"; 84 static constexpr OUStringLiteral msSlideSorterURL 85 = u"private:resource/view/Presenter/SlideSorter"; 86 static constexpr OUStringLiteral msHelpViewURL = u"private:resource/view/Presenter/Help"; 87 88 /** Create a new instance of this class and register it as resource 89 factory in the drawing framework of the given controller. 90 This registration keeps it alive. When the drawing framework is 91 shut down and releases its reference to the factory then the factory 92 is destroyed. 93 */ 94 static css::uno::Reference<css::drawing::framework::XResourceFactory> Create ( 95 const css::uno::Reference<css::uno::XComponentContext>& rxContext, 96 const css::uno::Reference<css::frame::XController>& rxController, 97 const ::rtl::Reference<PresenterController>& rpPresenterController); 98 virtual ~PresenterViewFactory() override; 99 100 virtual void SAL_CALL disposing() override; 101 102 // XResourceFactory 103 104 virtual css::uno::Reference<css::drawing::framework::XResource> 105 SAL_CALL createResource ( 106 const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId) override; 107 108 virtual void SAL_CALL 109 releaseResource ( 110 const css::uno::Reference<css::drawing::framework::XResource>& rxPane) override; 111 112 private: 113 css::uno::Reference<css::uno::XComponentContext> mxComponentContext; 114 css::uno::Reference<css::drawing::framework::XConfigurationController> 115 mxConfigurationController; 116 css::uno::WeakReference<css::frame::XController> mxControllerWeak; 117 ::rtl::Reference<PresenterController> mpPresenterController; 118 typedef ::std::pair<css::uno::Reference<css::drawing::framework::XView>, 119 css::uno::Reference<css::drawing::framework::XPane> > ViewResourceDescriptor; 120 typedef ::std::map<OUString, ViewResourceDescriptor> ResourceContainer; 121 std::unique_ptr<ResourceContainer> mpResourceCache; 122 123 PresenterViewFactory ( 124 const css::uno::Reference<css::uno::XComponentContext>& rxContext, 125 const css::uno::Reference<css::frame::XController>& rxController, 126 const ::rtl::Reference<PresenterController>& rpPresenterController); 127 128 void Register (const css::uno::Reference<css::frame::XController>& rxController); 129 130 css::uno::Reference<css::drawing::framework::XView> CreateSlideShowView( 131 const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId) const; 132 133 css::uno::Reference<css::drawing::framework::XView> CreateSlidePreviewView( 134 const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId, 135 const css::uno::Reference<css::drawing::framework::XPane>& rxPane) const; 136 137 css::uno::Reference<css::drawing::framework::XView> CreateToolBarView( 138 const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId) const; 139 140 css::uno::Reference<css::drawing::framework::XView> CreateNotesView( 141 const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId) const; 142 143 css::uno::Reference<css::drawing::framework::XView> CreateSlideSorterView( 144 const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId) const; 145 146 css::uno::Reference<css::drawing::framework::XView> CreateHelpView( 147 const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId) const; 148 149 css::uno::Reference<css::drawing::framework::XResource> GetViewFromCache ( 150 const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId, 151 const css::uno::Reference<css::drawing::framework::XPane>& rxAnchorPane) const; 152 css::uno::Reference<css::drawing::framework::XResource> CreateView( 153 const css::uno::Reference<css::drawing::framework::XResourceId>& rxViewId, 154 const css::uno::Reference<css::drawing::framework::XPane>& rxAnchorPane); 155 156 /// @throws css::lang::DisposedException 157 void ThrowIfDisposed() const; 158 }; 159 160 } 161 162 #endif 163 164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 165