1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_SD_SOURCE_UI_INC_FRAMEWORK_FRAMEWORKHELPER_HXX
21 #define INCLUDED_SD_SOURCE_UI_INC_FRAMEWORK_FRAMEWORKHELPER_HXX
23 #include "ViewShell.hxx"
25 #include "tools/SdGlobalResourceContainer.hxx"
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>
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>
43 namespace sd
{ namespace framework
{
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.
52 Note that a FrameworkHelper disposes itself when one of the resource
53 controllers called by it throws a DisposedException.
56 : public ::boost::enable_shared_from_this
<FrameworkHelper
>,
57 public SdGlobalResource
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
;
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
;
79 // URLs of frequently used tool bars.
80 static const OUString msToolBarURLPrefix
;
81 static const OUString msViewTabBarURL
;
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
;
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
;
102 // Service names of the common controllers.
103 static const OUString msModuleControllerService
;
104 static const OUString msConfigurationControllerService
;
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
110 static ::boost::shared_ptr
<FrameworkHelper
> Instance (ViewShellBase
& rBase
);
112 /** Mark the FrameworkHelper object for the given ViewShellBase as
113 disposed. A following ReleaseInstance() call will destroy the
114 FrameworkHelper object.
116 Do not call this method. It is an internally used method that can
119 static void DisposeInstance (ViewShellBase
& rBase
);
121 /** Destroy the FrameworkHelper object for the given ViewShellBase.
123 Do not call this method. It is an internally used method that can
126 static void ReleaseInstance (ViewShellBase
& rBase
);
128 /** Return an identifier for the given view URL. This identifier can be
129 used in a switch statement. See GetViewURL() for a mapping in the
132 static ViewShell::ShellType
GetViewId (const OUString
& rsViewURL
);
134 /** Return a view URL for the given identifier. See GetViewId() for a
135 mapping in the opposite direction.
137 static OUString
GetViewURL (ViewShell::ShellType eType
);
139 /** Return a ViewShell pointer for the given XView reference. This
140 assumes that the given reference is implemented by the
141 ViewShellWrapper class that supports the XTunnel interface.
143 When the ViewShell pointer can not be inferred from the given
144 reference then an empty pointer is returned.
146 static ::boost::shared_ptr
<ViewShell
> GetViewShell (
147 const css::uno::Reference
<css::drawing::framework::XView
>& rxView
);
149 typedef ::boost::function
<bool(const css::drawing::framework::ConfigurationChangeEvent
&)>
150 ConfigurationChangeEventFilter
;
151 typedef ::boost::function
<void(bool bEventSeen
)> Callback
;
152 typedef ::boost::function
<
154 const css::uno::Reference
<
155 css::drawing::framework::XResourceId
>&)
158 /** Test whether the called FrameworkHelper object is valid.
160 When the object has already been disposed then <FALSE/> is returned.
164 /** Return a pointer to the view shell that is displayed in the
165 specified pane. See GetView() for a variant that returns a
166 reference to XView instead of a ViewShell pointer.
168 An empty pointer is returned when for example the specified pane
169 does not exist or is not visible or does not show a view or one
170 of the involved objects does not support XUnoTunnel (where
173 ::boost::shared_ptr
<ViewShell
> GetViewShell (const OUString
& rsPaneURL
);
175 /** Return a reference to the view that is displayed in the specified
176 pane. See GetViewShell () for a variant that returns a ViewShell
177 pointer instead of a reference to XView.
178 @param rxPaneOrViewId
179 When this ResourceId specifies a view then that view is
180 returned. When it belongs to a pane then one view in that pane
183 An empty reference is returned when for example the specified pane
184 does not exist or is not visible or does not show a view or one
185 of the involved objects does not support XTunnel (where
188 css::uno::Reference
<css::drawing::framework::XView
> GetView (
189 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxPaneOrViewId
);
191 /** Request the specified view to be displayed in the specified pane.
192 When the pane is not visible its creation is also requested. The
193 update that creates the actual view object is done asynchronously.
195 The resource URL of the view to show.
197 The URL of the pane in which to show the view.
199 The resource id of the requested view is returned. With that
200 the caller can, for example, call RunOnResourceActivation() to
201 do some initialization after the requested view becomes active.
203 css::uno::Reference
<css::drawing::framework::XResourceId
> RequestView (
204 const OUString
& rsResourceURL
,
205 const OUString
& rsAnchorURL
);
207 /** Process a slot call that requests a view shell change.
209 void HandleModeChangeSlot (
211 SfxRequest
& rRequest
);
213 /** Run the given callback when the specified event is notified by the
214 ConfigurationManager. When there are no pending requests and
215 therefore no events would be notified (in the foreseeable future)
216 then the callback is called immediately.
217 The callback is called with a flag that tells the callback whether
218 the event it waits for has been sent.
220 void RunOnConfigurationEvent(
221 const OUString
& rsEventType
,
222 const Callback
& rCallback
);
224 /** Run the given callback when the specified resource has been
225 activated. When the resource is active already when this method is
226 called then rCallback is called before this method returns.
228 Wait for the activation of this resource before calling
231 The callback to be called when the resource is activated.
234 void RunOnResourceActivation(
235 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxResourceId
,
236 const Callback
& rCallback
);
238 /** Normally the requested changes of the configuration are executed
239 asynchronously. However, there is at least one situation (searching
240 with the Outliner) where the surrounding code does not cope with
241 this. So, instead of calling Reschedule until the global event loop
242 executes the configuration update, this method does (almost) the
243 same without the reschedules.
245 Do not use this method until there is absolutely no other way.
247 void RequestSynchronousUpdate();
249 /** Block until the specified event is notified by the configuration
250 controller. When the configuration controller is not processing any
251 requests the method returns immediately.
253 void WaitForEvent (const OUString
& rsEventName
) const;
255 /** This is a short cut for WaitForEvent(msConfigurationUpdateEndEvent).
256 Call this method to execute the pending requests.
258 void WaitForUpdate() const;
260 /** Explicit request for an update of the current configuration. Call
261 this method when one of the resources managed by the sd framework
262 has been activated or deactivated from the outside, i.e. not by the
263 framework itself. An example for this is a click on the closer
264 button of one of the side panes.
266 void UpdateConfiguration();
268 /** Return a string representation of the given XResourceId object.
270 static OUString
ResourceIdToString (
271 const css::uno::Reference
<
272 css::drawing::framework::XResourceId
>& rxResourceId
);
274 /** Create a new XResourceId object for the given resource URL.
276 static css::uno::Reference
<
277 css::drawing::framework::XResourceId
>
279 const OUString
& rsResourceURL
);
281 /** Create a new XResourceId object for the given resource URL and a
284 static css::uno::Reference
<
285 css::drawing::framework::XResourceId
>
287 const OUString
& rsResourceURL
,
288 const OUString
& rsAnchorURL
);
290 /** Create a new XResourceId object for the given resource URL.
292 static css::uno::Reference
<
293 css::drawing::framework::XResourceId
>
295 const OUString
& rsResourceURL
,
296 const css::uno::Reference
<
297 css::drawing::framework::XResourceId
>& rxAnchor
);
299 css::uno::Reference
<css::drawing::framework::XConfigurationController
>
300 GetConfigurationController() const { return mxConfigurationController
;}
305 ::boost::shared_ptr
<FrameworkHelper
> > InstanceMap
;
306 /** The instance map holds (at least) one FrameworkHelper instance for
307 every ViewShellBase object.
309 static InstanceMap maInstanceMap
;
311 static ::boost::scoped_ptr
<ViewURLMap
> mpViewURLMap
;
313 ViewShellBase
& mrBase
;
314 css::uno::Reference
<css::drawing::framework::XConfigurationController
>
315 mxConfigurationController
;
317 class DisposeListener
;
318 friend class DisposeListener
;
319 css::uno::Reference
<css::lang::XComponent
>
322 FrameworkHelper (ViewShellBase
& rBase
);
323 FrameworkHelper (const FrameworkHelper
& rHelper
) SAL_DELETED_FUNCTION
;
324 virtual ~FrameworkHelper();
325 class Deleter
; friend class Deleter
;
326 FrameworkHelper
& operator= (const FrameworkHelper
& rHelper
) SAL_DELETED_FUNCTION
;
332 /** Run the given callback when an event of the specified type is
333 received from the ConfigurationController or when the
334 ConfigurationController has no pending change requests.
336 Run rCallback only on this event.
338 This filter has to return <TRUE/> in order for rCallback to be
341 The callback functor to be called.
344 const OUString
& rsEventType
,
345 const ConfigurationChangeEventFilter
& rFilter
,
346 const Callback
& rCallback
) const;
348 /** This disposing method is forwarded from the inner DisposeListener class.
350 void disposing (const css::lang::EventObject
& rEventObject
);
353 } } // end of namespace sd::framework
357 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */