bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / inc / framework / FrameworkHelper.hxx
blob9964bb6fd32cdadcd426cbc45a5e5255a5a081c3
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 #ifndef SD_FRAMEWORK_FRAMEWORK_HELPER_HXX
21 #define SD_FRAMEWORK_FRAMEWORK_HELPER_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>
35 #include <map>
37 namespace sd {
38 class ViewShell;
39 class ViewShellBase;
42 namespace css = ::com::sun::star;
43 namespace cssu = ::com::sun::star::uno;
44 namespace cssdf = ::com::sun::star::drawing::framework;
46 namespace sd { namespace framework {
48 /** The FrameworkHelper is a convenience class that simplifies the
49 access to the drawing framework.
50 It has three main tasks:
51 1. Provide frequently used strings of resource URLs and event names.
52 2. Provide shortcuts for accessing the sd framework.
53 3. Ease the migration to the drawing framwork.
55 Note that a FrameworkHelper disposes itself when one of the resource
56 controllers called by it throws a DisposedException.
58 class FrameworkHelper
59 : public ::boost::enable_shared_from_this<FrameworkHelper>,
60 public SdGlobalResource
62 public:
63 // URLs of frequently used panes.
64 static const OUString msPaneURLPrefix;
65 static const OUString msCenterPaneURL;
66 static const OUString msFullScreenPaneURL;
67 static const OUString msLeftImpressPaneURL;
68 static const OUString msLeftDrawPaneURL;
69 static const OUString msRightPaneURL;
70 static const OUString msSidebarPaneURL;
72 // URLs of frequently used views.
73 static const OUString msViewURLPrefix;
74 static const OUString msImpressViewURL;
75 static const OUString msDrawViewURL;
76 static const OUString msOutlineViewURL;
77 static const OUString msNotesViewURL;
78 static const OUString msHandoutViewURL;
79 static const OUString msSlideSorterURL;
80 static const OUString msPresentationViewURL;
81 static const OUString msTaskPaneURL;
82 static const OUString msSidebarViewURL;
84 // URLs of frequently used tool bars.
85 static const OUString msToolBarURLPrefix;
86 static const OUString msViewTabBarURL;
88 // URLs of task panels.
89 static const OUString msTaskPanelURLPrefix;
90 static const OUString msMasterPagesTaskPanelURL;
91 static const OUString msAllMasterPagesTaskPanelURL;
92 static const OUString msRecentMasterPagesTaskPanelURL;
93 static const OUString msUsedMasterPagesTaskPanelURL;
94 static const OUString msLayoutTaskPanelURL;
95 static const OUString msTableDesignPanelURL;
96 static const OUString msCustomAnimationTaskPanelURL;
97 static const OUString msSlideTransitionTaskPanelURL;
99 // Names of frequently used events.
100 static const OUString msResourceActivationRequestEvent;
101 static const OUString msResourceDeactivationRequestEvent;
102 static const OUString msResourceActivationEvent;
103 static const OUString msResourceDeactivationEvent;
104 static const OUString msResourceDeactivationEndEvent;
105 static const OUString msConfigurationUpdateStartEvent;
106 static const OUString msConfigurationUpdateEndEvent;
108 // Service names of the common controllers.
109 static const OUString msModuleControllerService;
110 static const OUString msConfigurationControllerService;
112 /** Return the FrameworkHelper object that is associated with the given
113 ViewShellBase. If such an object does not yet exist, a new one is
114 created.
116 static ::boost::shared_ptr<FrameworkHelper> Instance (ViewShellBase& rBase);
118 static ::boost::shared_ptr<FrameworkHelper> Instance (
119 const cssu::Reference<css::frame::XController>& rxController);
121 /** Mark the FrameworkHelper object for the given ViewShellBase as
122 disposed. A following ReleaseInstance() call will destroy the
123 FrameworkHelper object.
125 Do not call this method. It is an internally used method that can
126 not be made private.
128 static void DisposeInstance (ViewShellBase& rBase);
130 /** Destroy the FrameworkHelper object for the given ViewShellBase.
132 Do not call this method. It is an internally used method that can
133 not be made private.
135 static void ReleaseInstance (ViewShellBase& rBase);
137 /** Return an identifier for the given view URL. This identifier can be
138 used in a switch statement. See GetViewURL() for a mapping in the
139 opposite direction.
141 static ViewShell::ShellType GetViewId (const OUString& rsViewURL);
143 /** Return a view URL for the given identifier. See GetViewId() for a
144 mapping in the opposite direction.
146 static OUString GetViewURL (ViewShell::ShellType eType);
148 /** Return a ViewShell pointer for the given XView reference. This
149 assumes that the given reference is implemented by the
150 ViewShellWrapper class that supports the XTunnel interface.
151 @return
152 When the ViewShell pointer can not be inferred from the given
153 reference then an empty pointer is returned.
155 static ::boost::shared_ptr<ViewShell> GetViewShell (
156 const cssu::Reference<cssdf::XView>& rxView);
158 typedef ::boost::function<bool(const cssdf::ConfigurationChangeEvent&)>
159 ConfigurationChangeEventFilter;
160 typedef ::boost::function<void(bool bEventSeen)> Callback;
161 typedef ::boost::function<
162 void(
163 const cssu::Reference<
164 cssdf::XResourceId>&)
165 > ResourceFunctor;
167 /** Test whether the called FrameworkHelper object is valid.
168 @return
169 When the object has already been disposed then <FALSE/> is returned.
171 bool IsValid (void);
173 /** Return a pointer to the view shell that is displayed in the
174 specified pane. See GetView() for a variant that returns a
175 reference to XView instead of a ViewShell pointer.
176 @return
177 An empty pointer is returned when for example the specified pane
178 does not exist or is not visible or does not show a view or one
179 of the involved objects does not support XUnoTunnel (where
180 necessary).
182 ::boost::shared_ptr<ViewShell> GetViewShell (const OUString& rsPaneURL);
184 /** Return a reference to the view that is displayed in the specified
185 pane. See GetViewShell () for a variant that returns a ViewShell
186 pointer instead of a reference to XView.
187 @param rxPaneOrViewId
188 When this ResourceId specifies a view then that view is
189 returned. When it belongs to a pane then one view in that pane
190 is returned.
191 @return
192 An empty reference is returned when for example the specified pane
193 does not exist or is not visible or does not show a view or one
194 of the involved objects does not support XTunnel (where
195 necessary).
197 cssu::Reference<cssdf::XView> GetView (
198 const cssu::Reference<cssdf::XResourceId>& rxPaneOrViewId);
200 /** Return the XWindow that is represented by the pane with the
201 given resource id.
203 cssu::Reference<css::awt::XWindow> GetPaneWindow (
204 const cssu::Reference<cssdf::XResourceId>& rxPaneId);
206 /** Return the XResource object with the given resource id.
208 cssu::Reference<cssdf::XResource> GetResource (
209 const cssu::Reference<cssdf::XResourceId>& rxResourceId);
211 /** Request the specified view to be displayed in the specified pane.
212 When the pane is not visible its creation is also requested. The
213 update that creates the actual view object is done asynchronously.
214 @param rsResourceURL
215 The resource URL of the view to show.
216 @param rsAnchorURL
217 The URL of the pane in which to show the view.
218 @return
219 The resource id of the requested view is returned. With that
220 the caller can, for example, call RunOnResourceActivation() to
221 do some initialization after the requested view becomes active.
223 cssu::Reference<cssdf::XResourceId> RequestView (
224 const OUString& rsResourceURL,
225 const OUString& rsAnchorURL);
227 /** Request the activation of the specified panel in the
228 sidebar.
229 @param rsSidebarPanelURL
230 The panel that is to be activated.
231 @param bEnsurePaneIsVisible
232 When this is <TRUE/> then the sidebar pane is activated when not
233 yet active.
234 When this flag is <FALSE/> then the requested panel
235 is activated only when the task pane is already active. When it
236 is not active then this call is silently ignored.
237 @return
238 The resource id of the requested sidebar panel is returned. With that
239 the caller can, for example, call RunOnResourceActivation() to
240 do some initialization after the requested view becomes active.
242 cssu::Reference<cssdf::XResourceId> RequestSidebarPanel (
243 const OUString& rsSidebarPanelURL,
244 const bool bEnsureTaskPaneIsVisible = true);
246 /** Request the deactivation of the specified resource.
248 void RequestResourceDeactivation (
249 const cssu::Reference<cssdf::XResourceId>& rxResourceId);
251 /** Process a slot call that requests a view shell change.
253 void HandleModeChangeSlot (
254 sal_uLong nSlotId,
255 SfxRequest& rRequest);
257 /** Run the given callback when the specified event is notified by the
258 ConfigurationManager. When there are no pending requests and
259 therefore no events would be notified (in the foreseeable future)
260 then the callback is called immediately.
261 The callback is called with a flag that tells the callback whether
262 the event it waits for has been sent.
264 void RunOnConfigurationEvent(
265 const OUString& rsEventType,
266 const Callback& rCallback);
268 /** Run the given callback when the specified resource has been
269 activated. When the resource is active already when this method is
270 called then rCallback is called before this method returns.
271 @param rxResourceId
272 Wait for the activation of this resource before calling
273 rCallback.
274 @param rCallback
275 The callback to be called when the resource is activated.
278 void RunOnResourceActivation(
279 const cssu::Reference<cssdf::XResourceId>& rxResourceId,
280 const Callback& rCallback);
282 /** Run the given callback when the specified resource has been
283 deactivated. When the resource is not active already when
284 this method is called then rCallback is called before this
285 method returns.
286 @param rxResourceId
287 Wait for the deactivation of this resource before calling
288 rCallback.
289 @param rCallback
290 The callback to be called when the resource is
291 deactivated.
292 @param bRunOnDeactivationEnd
293 The callback is run either when the deactivation starts
294 and the callback can still access the resource or when the
295 deactivatio is complete and the resource is no longer available.
298 void RunOnResourceDeactivation(
299 const cssu::Reference<cssdf::XResourceId>& rxResourceId,
300 const Callback& rCallback,
301 const bool bRunOnDeactivationEnd);
303 /** Normally the requested changes of the configuration are executed
304 asynchronously. However, there is at least one situation (searching
305 with the Outliner) where the surrounding code does not cope with
306 this. So, instead of calling Reschedule until the global event loop
307 executes the configuration update, this method does (almost) the
308 same without the reschedules.
310 Do not use this method until there is absolutely no other way.
312 void RequestSynchronousUpdate (void);
314 /** Block until the specified event is notified by the configuration
315 controller. When the configuration controller is not processing any
316 requests the method returns immediately.
318 void WaitForEvent (const OUString& rsEventName) const;
320 /** This is a short cut for WaitForEvent(msConfigurationUpdateEndEvent).
321 Call this method to execute the pending requests.
323 void WaitForUpdate (void) const;
325 /** Explicit request for an update of the current configuration. Call
326 this method when one of the resources managed by the sd framework
327 has been activated or deactivated from the outside, i.e. not by the
328 framework itself. An example for this is a click on the closer
329 button of one of the side panes.
331 void UpdateConfiguration (void);
333 /** Return a string representation of the given XResourceId object.
335 static OUString ResourceIdToString (
336 const cssu::Reference<
337 cssdf::XResourceId>& rxResourceId);
339 /** Create a new XResourceId object for the given resource URL.
341 static cssu::Reference<
342 cssdf::XResourceId>
343 CreateResourceId (
344 const OUString& rsResourceURL);
346 /** Create a new XResourceId object for the given resource URL and a
347 single anchor URL.
349 static cssu::Reference<
350 cssdf::XResourceId>
351 CreateResourceId (
352 const OUString& rsResourceURL,
353 const OUString& rsAnchorURL);
355 /** Create a new XResourceId object for the given resource URL and the
356 two given anchor URLs.
358 static cssu::Reference<
359 cssdf::XResourceId>
360 CreateResourceId (
361 const OUString& rsResourceURL,
362 const OUString& rsFirstAnchorURL,
363 const OUString& rsSecondAnchorURL);
365 /** Create a new XResourceId object for the given resource URL.
367 static cssu::Reference<
368 cssdf::XResourceId>
369 CreateResourceId (
370 const OUString& rsResourceURL,
371 const cssu::Reference<
372 cssdf::XResourceId>& rxAnchor);
374 cssu::Reference<cssdf::XConfigurationController>
375 GetConfigurationController (void) const;
378 private:
379 typedef ::std::map<
380 ViewShellBase*,
381 ::boost::shared_ptr<FrameworkHelper> > InstanceMap;
382 /** The instance map holds (at least) one FrameworkHelper instance for
383 every ViewShellBase object.
385 static InstanceMap maInstanceMap;
386 class ViewURLMap;
387 static ::boost::scoped_ptr<ViewURLMap> mpViewURLMap;
389 ViewShellBase& mrBase;
390 cssu::Reference<cssdf::XConfigurationController>
391 mxConfigurationController;
393 class DisposeListener;
394 friend class DisposeListener;
395 cssu::Reference<css::lang::XComponent>
396 mxDisposeListener;
398 FrameworkHelper (ViewShellBase& rBase);
399 FrameworkHelper (const FrameworkHelper& rHelper); // Not implemented.
400 ~FrameworkHelper (void);
401 class Deleter; friend class Deleter;
402 FrameworkHelper& operator= (const FrameworkHelper& rHelper); // Not implemented.
404 void Initialize (void);
406 void Dispose (void);
408 /** Run the given callback when an event of the specified type is
409 received from the ConfigurationController or when the
410 ConfigurationController has no pending change requests.
411 @param rsEventType
412 Run rCallback only on this event.
413 @param rFilter
414 This filter has to return <TRUE/> in order for rCallback to be
415 called.
416 @param rCallback
417 The callback functor to be called.
419 void RunOnEvent(
420 const OUString& rsEventType,
421 const ConfigurationChangeEventFilter& rFilter,
422 const Callback& rCallback) const;
424 /** This disposing method is forwarded from the inner DisposeListener class.
426 void disposing (const css::lang::EventObject& rEventObject);
430 } } // end of namespace sd::framework
434 namespace sd { namespace framework {
436 namespace {
438 class FrameworkHelperAllPassFilter
440 public:
441 bool operator() (const cssdf::ConfigurationChangeEvent&) { return true; }
445 class FrameworkHelperResourceIdFilter
447 public:
448 FrameworkHelperResourceIdFilter (
449 const cssu::Reference<cssdf::XResourceId>& rxResourceId);
450 bool operator() (const cssdf::ConfigurationChangeEvent& rEvent)
451 { return mxResourceId.is() && rEvent.ResourceId.is()
452 && mxResourceId->compareTo(rEvent.ResourceId) == 0; }
453 private:
454 cssu::Reference<cssdf::XResourceId> mxResourceId;
457 } // end of anonymous namespace
462 } } // end of namespace sd::framework
465 #endif
467 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */