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