LCOV - code coverage report
Current view: top level - sd/source/ui/inc/framework - FrameworkHelper.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 1 0.0 %
Date: 2014-11-03 Functions: 0 1 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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_SD_SOURCE_UI_INC_FRAMEWORK_FRAMEWORKHELPER_HXX
      21             : #define INCLUDED_SD_SOURCE_UI_INC_FRAMEWORK_FRAMEWORKHELPER_HXX
      22             : 
      23             : #include "ViewShell.hxx"
      24             : 
      25             : #include "tools/SdGlobalResourceContainer.hxx"
      26             : 
      27             : #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
      28             : #include <com/sun/star/drawing/framework/XView.hpp>
      29             : #include <com/sun/star/lang/XEventListener.hpp>
      30             : 
      31             : #include <boost/scoped_ptr.hpp>
      32             : #include <boost/shared_ptr.hpp>
      33             : #include <boost/enable_shared_from_this.hpp>
      34             : #include <boost/function.hpp>
      35             : #include <map>
      36             : 
      37             : namespace sd {
      38             : class ViewShell;
      39             : class ViewShellBase;
      40             : }
      41             : 
      42             : 
      43             : namespace sd { namespace framework {
      44             : 
      45             : /** The FrameworkHelper is a convenience class that simplifies the
      46             :     access to the drawing framework.
      47             :     It has three main tasks:
      48             :     1. Provide frequently used strings of resource URLs and event names.
      49             :     2. Provide shortcuts for accessing the sd framework.
      50             :     3. Ease the migration to the drawing framwork.
      51             : 
      52             :     Note that a FrameworkHelper disposes itself when one of the resource
      53             :     controllers called by it throws a DisposedException.
      54             : */
      55             : class FrameworkHelper
      56             :     : public ::boost::enable_shared_from_this<FrameworkHelper>,
      57             :       public SdGlobalResource
      58             : {
      59             : public:
      60             :     // URLs of frequently used panes.
      61             :     static const OUString msPaneURLPrefix;
      62             :     static const OUString msCenterPaneURL;
      63             :     static const OUString msFullScreenPaneURL;
      64             :     static const OUString msLeftImpressPaneURL;
      65             :     static const OUString msLeftDrawPaneURL;
      66             :     static const OUString msSidebarPaneURL;
      67             : 
      68             :     // URLs of frequently used views.
      69             :     static const OUString msViewURLPrefix;
      70             :     static const OUString msImpressViewURL;
      71             :     static const OUString msDrawViewURL;
      72             :     static const OUString msOutlineViewURL;
      73             :     static const OUString msNotesViewURL;
      74             :     static const OUString msHandoutViewURL;
      75             :     static const OUString msSlideSorterURL;
      76             :     static const OUString msPresentationViewURL;
      77             :     static const OUString msSidebarViewURL;
      78             : 
      79             :     // URLs of frequently used tool bars.
      80             :     static const OUString msToolBarURLPrefix;
      81             :     static const OUString msViewTabBarURL;
      82             : 
      83             :     // URLs of task panels.
      84             :     static const OUString msTaskPanelURLPrefix;
      85             :     static const OUString msAllMasterPagesTaskPanelURL;
      86             :     static const OUString msRecentMasterPagesTaskPanelURL;
      87             :     static const OUString msUsedMasterPagesTaskPanelURL;
      88             :     static const OUString msLayoutTaskPanelURL;
      89             :     static const OUString msTableDesignPanelURL;
      90             :     static const OUString msCustomAnimationTaskPanelURL;
      91             :     static const OUString msSlideTransitionTaskPanelURL;
      92             : 
      93             :     // Names of frequently used events.
      94             :     static const OUString msResourceActivationRequestEvent;
      95             :     static const OUString msResourceDeactivationRequestEvent;
      96             :     static const OUString msResourceActivationEvent;
      97             :     static const OUString msResourceDeactivationEvent;
      98             :     static const OUString msResourceDeactivationEndEvent;
      99             :     static const OUString msConfigurationUpdateStartEvent;
     100             :     static const OUString msConfigurationUpdateEndEvent;
     101             : 
     102             :     // Service names of the common controllers.
     103             :     static const OUString msModuleControllerService;
     104             :     static const OUString msConfigurationControllerService;
     105             : 
     106             :     /** Return the FrameworkHelper object that is associated with the given
     107             :         ViewShellBase.  If such an object does not yet exist, a new one is
     108             :         created.
     109             :     */
     110             :     static ::boost::shared_ptr<FrameworkHelper> Instance (ViewShellBase& rBase);
     111             : 
     112             :     static ::boost::shared_ptr<FrameworkHelper> Instance (
     113             :         const css::uno::Reference<css::frame::XController>& rxController);
     114             : 
     115             :     /** Mark the FrameworkHelper object for the given ViewShellBase as
     116             :         disposed.  A following ReleaseInstance() call will destroy the
     117             :         FrameworkHelper object.
     118             : 
     119             :         Do not call this method.  It is an internally used method that can
     120             :         not be made private.
     121             :     */
     122             :     static void DisposeInstance (ViewShellBase& rBase);
     123             : 
     124             :     /** Destroy the FrameworkHelper object for the given ViewShellBase.
     125             : 
     126             :         Do not call this method.  It is an internally used method that can
     127             :         not be made private.
     128             :     */
     129             :     static void ReleaseInstance (ViewShellBase& rBase);
     130             : 
     131             :     /** Return an identifier for the given view URL.  This identifier can be
     132             :         used in a switch statement.  See GetViewURL() for a mapping in the
     133             :         opposite direction.
     134             :     */
     135             :     static ViewShell::ShellType GetViewId (const OUString& rsViewURL);
     136             : 
     137             :     /** Return a view URL for the given identifier.  See GetViewId() for a
     138             :         mapping in the opposite direction.
     139             :     */
     140             :     static OUString GetViewURL (ViewShell::ShellType eType);
     141             : 
     142             :     /** Return a ViewShell pointer for the given XView reference.  This
     143             :         assumes that the given reference is implemented by the
     144             :         ViewShellWrapper class that supports the XTunnel interface.
     145             :         @return
     146             :             When the ViewShell pointer can not be inferred from the given
     147             :             reference then an empty pointer is returned.
     148             :     */
     149             :     static ::boost::shared_ptr<ViewShell> GetViewShell (
     150             :         const css::uno::Reference<css::drawing::framework::XView>& rxView);
     151             : 
     152             :     typedef ::boost::function<bool(const css::drawing::framework::ConfigurationChangeEvent&)>
     153             :         ConfigurationChangeEventFilter;
     154             :     typedef ::boost::function<void(bool bEventSeen)> Callback;
     155             :     typedef ::boost::function<
     156             :         void(
     157             :             const css::uno::Reference<
     158             :                 css::drawing::framework::XResourceId>&)
     159             :         > ResourceFunctor;
     160             : 
     161             :     /** Test whether the called FrameworkHelper object is valid.
     162             :         @return
     163             :             When the object has already been disposed then <FALSE/> is returned.
     164             :     */
     165             :     bool IsValid (void);
     166             : 
     167             :     /** Return a pointer to the view shell that is displayed in the
     168             :         specified pane.  See GetView() for a variant that returns a
     169             :         reference to XView instead of a ViewShell pointer.
     170             :         @return
     171             :             An empty pointer is returned when for example the specified pane
     172             :             does not exist or is not visible or does not show a view or one
     173             :             of the involved objects does not support XUnoTunnel (where
     174             :             necessary).
     175             :     */
     176             :     ::boost::shared_ptr<ViewShell> GetViewShell (const OUString& rsPaneURL);
     177             : 
     178             :     /** Return a reference to the view that is displayed in the specified
     179             :         pane.  See GetViewShell () for a variant that returns a ViewShell
     180             :         pointer instead of a reference to XView.
     181             :         @param rxPaneOrViewId
     182             :             When this ResourceId specifies a view then that view is
     183             :             returned.  When it belongs to a pane then one view in that pane
     184             :             is returned.
     185             :         @return
     186             :             An empty reference is returned when for example the specified pane
     187             :             does not exist or is not visible or does not show a view or one
     188             :             of the involved objects does not support XTunnel (where
     189             :             necessary).
     190             :     */
     191             :     css::uno::Reference<css::drawing::framework::XView> GetView (
     192             :         const css::uno::Reference<css::drawing::framework::XResourceId>& rxPaneOrViewId);
     193             : 
     194             :     /** Request the specified view to be displayed in the specified pane.
     195             :         When the pane is not visible its creation is also requested.  The
     196             :         update that creates the actual view object is done asynchronously.
     197             :         @param rsResourceURL
     198             :             The resource URL of the view to show.
     199             :         @param rsAnchorURL
     200             :             The URL of the pane in which to show the view.
     201             :         @return
     202             :             The resource id of the requested view is returned.  With that
     203             :             the caller can, for example, call RunOnResourceActivation() to
     204             :             do some initialization after the requested view becomes active.
     205             :     */
     206             :     css::uno::Reference<css::drawing::framework::XResourceId> RequestView (
     207             :         const OUString& rsResourceURL,
     208             :         const OUString& rsAnchorURL);
     209             : 
     210             :     /** Process a slot call that requests a view shell change.
     211             :     */
     212             :     void HandleModeChangeSlot (
     213             :         sal_uLong nSlotId,
     214             :         SfxRequest& rRequest);
     215             : 
     216             :     /** Run the given callback when the specified event is notified by the
     217             :         ConfigurationManager.  When there are no pending requests and
     218             :         therefore no events would be notified (in the foreseeable future)
     219             :         then the callback is called immediately.
     220             :         The callback is called with a flag that tells the callback whether
     221             :         the event it waits for has been sent.
     222             :     */
     223             :     void RunOnConfigurationEvent(
     224             :         const OUString& rsEventType,
     225             :         const Callback& rCallback);
     226             : 
     227             :     /** Run the given callback when the specified resource has been
     228             :         activated.  When the resource is active already when this method is
     229             :         called then rCallback is called before this method returns.
     230             :         @param rxResourceId
     231             :             Wait for the activation of this resource before calling
     232             :             rCallback.
     233             :         @param rCallback
     234             :             The callback to be called when the resource is activated.
     235             : 
     236             :     */
     237             :     void RunOnResourceActivation(
     238             :         const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId,
     239             :         const Callback& rCallback);
     240             : 
     241             :     /** Normally the requested changes of the configuration are executed
     242             :         asynchronously.  However, there is at least one situation (searching
     243             :         with the Outliner) where the surrounding code does not cope with
     244             :         this.  So, instead of calling Reschedule until the global event loop
     245             :         executes the configuration update, this method does (almost) the
     246             :         same without the reschedules.
     247             : 
     248             :         Do not use this method until there is absolutely no other way.
     249             :     */
     250             :     void RequestSynchronousUpdate (void);
     251             : 
     252             :     /** Block until the specified event is notified by the configuration
     253             :         controller.  When the configuration controller is not processing any
     254             :         requests the method returns immediately.
     255             :     */
     256             :     void WaitForEvent (const OUString& rsEventName) const;
     257             : 
     258             :     /** This is a short cut for WaitForEvent(msConfigurationUpdateEndEvent).
     259             :         Call this method to execute the pending requests.
     260             :     */
     261             :     void WaitForUpdate (void) const;
     262             : 
     263             :     /** Explicit request for an update of the current configuration.  Call
     264             :         this method when one of the resources managed by the sd framework
     265             :         has been activated or deactivated from the outside, i.e. not by the
     266             :         framework itself.  An example for this is a click on the closer
     267             :         button of one of the side panes.
     268             :     */
     269             :     void UpdateConfiguration (void);
     270             : 
     271             :     /** Return a string representation of the given XResourceId object.
     272             :     */
     273             :     static OUString ResourceIdToString (
     274             :         const css::uno::Reference<
     275             :             css::drawing::framework::XResourceId>& rxResourceId);
     276             : 
     277             :     /** Create a new XResourceId object for the given resource URL.
     278             :     */
     279             :     static css::uno::Reference<
     280             :         css::drawing::framework::XResourceId>
     281             :             CreateResourceId (
     282             :                 const OUString& rsResourceURL);
     283             : 
     284             :     /** Create a new XResourceId object for the given resource URL and a
     285             :         single anchor URL.
     286             :     */
     287             :     static css::uno::Reference<
     288             :         css::drawing::framework::XResourceId>
     289             :             CreateResourceId (
     290             :                 const OUString& rsResourceURL,
     291             :                 const OUString& rsAnchorURL);
     292             : 
     293             :     /** Create a new XResourceId object for the given resource URL.
     294             :     */
     295             :     static css::uno::Reference<
     296             :         css::drawing::framework::XResourceId>
     297             :             CreateResourceId (
     298             :                 const OUString& rsResourceURL,
     299             :                 const css::uno::Reference<
     300             :                     css::drawing::framework::XResourceId>& rxAnchor);
     301             : 
     302             :     css::uno::Reference<css::drawing::framework::XConfigurationController>
     303           0 :         GetConfigurationController (void) const { return mxConfigurationController;}
     304             : 
     305             : private:
     306             :     typedef ::std::map<
     307             :         ViewShellBase*,
     308             :         ::boost::shared_ptr<FrameworkHelper> > InstanceMap;
     309             :     /** The instance map holds (at least) one FrameworkHelper instance for
     310             :         every ViewShellBase object.
     311             :     */
     312             :     static InstanceMap maInstanceMap;
     313             :     class ViewURLMap;
     314             :     static ::boost::scoped_ptr<ViewURLMap> mpViewURLMap;
     315             : 
     316             :     ViewShellBase& mrBase;
     317             :     css::uno::Reference<css::drawing::framework::XConfigurationController>
     318             :         mxConfigurationController;
     319             : 
     320             :     class DisposeListener;
     321             :     friend class DisposeListener;
     322             :     css::uno::Reference<css::lang::XComponent>
     323             :         mxDisposeListener;
     324             : 
     325             :     FrameworkHelper (ViewShellBase& rBase);
     326             :     FrameworkHelper (const FrameworkHelper& rHelper); // Not implemented.
     327             :     virtual ~FrameworkHelper (void);
     328             :     class Deleter; friend class Deleter;
     329             :     FrameworkHelper& operator= (const FrameworkHelper& rHelper); // Not implemented.
     330             : 
     331             :     void Initialize (void);
     332             : 
     333             :     void Dispose (void);
     334             : 
     335             :     /** Run the given callback when an event of the specified type is
     336             :         received from the ConfigurationController or when the
     337             :         ConfigurationController has no pending change requests.
     338             :         @param rsEventType
     339             :             Run rCallback only on this event.
     340             :         @param rFilter
     341             :             This filter has to return <TRUE/> in order for rCallback to be
     342             :             called.
     343             :         @param rCallback
     344             :             The callback functor to be called.
     345             :     */
     346             :     void RunOnEvent(
     347             :         const OUString& rsEventType,
     348             :         const ConfigurationChangeEventFilter& rFilter,
     349             :         const Callback& rCallback) const;
     350             : 
     351             :     /** This disposing method is forwarded from the inner DisposeListener class.
     352             :     */
     353             :     void disposing (const css::lang::EventObject& rEventObject);
     354             : };
     355             : 
     356             : } } // end of namespace sd::framework
     357             : 
     358             : #endif
     359             : 
     360             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10