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