xref: /aoo4110/main/sd/source/ui/inc/ToolBarManager.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SD_TOOL_BAR_MANAGER_HXX
25 #define SD_TOOL_BAR_MANAGER_HXX
26 
27 #include "ViewShell.hxx"
28 #include "ShellFactory.hxx"
29 #include <rtl/ustring.hxx>
30 #include <com/sun/star/frame/XFrame.hpp>
31 
32 #include <sal/types.h>
33 #include <boost/scoped_ptr.hpp>
34 #include <boost/shared_ptr.hpp>
35 #include <boost/enable_shared_from_this.hpp>
36 
37 class SdrView;
38 
39 namespace sd { namespace tools {
40 class EventMultiplexer;
41 } }
42 
43 
44 namespace sd {
45 
46 class ViewShellBase;
47 class ViewShellManager;
48 
49 /** Manage the set of visible tool bars (and object bars).  Usually they
50     belong to the current view in the center pane.
51 
52     Tool bars are managed in groups.  Each group can be set, reset, or
53     modified independently of the others.  This allows for instance to
54     replace the toolbars associated with the current function independently
55     from those assoicated with the main view.
56 
57     The ToolBarManager has two high level methods which contain the
58     knowledge about which tool bars to show in a specific context.
59     When the view in the center pane changes then MainViewShellChanged()
60     sets up the tool bars for the new view.  On changes of the selection the
61     SelectionHasChanged() method shows the tool bars for the new context.
62 
63     The update of the actually visible tool bars to the set currently
64     required by the main view shell and its functions is divided into two
65     parts, PreUpdate() and PostUpdate().  This are to be called before
66     respectively after the update of the view shell stack.  The reason for
67     this is to save time by not updating tool bars that will not be visible
68     in a short time on a view shell switch.
69 */
70 class ToolBarManager
71     : public ::boost::enable_shared_from_this<ToolBarManager>
72 {
73 public:
74     /** Use this method instead of the constructor to create new objects of
75         this class.
76     */
77     static ::boost::shared_ptr<ToolBarManager> Create (
78         ViewShellBase& rBase,
79         const ::boost::shared_ptr<tools::EventMultiplexer>& rpMultiplexer,
80         const ::boost::shared_ptr<ViewShellManager>& rpViewShellManager);
81 
82     ~ToolBarManager (void);
83 
84     /** Call this method prior to the destructor to prevent the
85         ToolBarManager from accessing the ViewShellManager or the
86         XLayoutManager when those are possibly not well and alive anymore
87         (like during the destruction of the ViewShellBase.)
88     */
89     void Shutdown (void);
90 
91     /** When the view in the center pane changes then this method sets up
92         the initial set of tool bars for the new view.
93         The ToolBarManager listenes for view switching itself and then calls
94         MainViewShellChanged().  Calling this method from the outside should
95         not be necessary.
96         @param nShellType
97             The type of the new main view shell.
98     */
99     void MainViewShellChanged (ViewShell::ShellType nShellType);
100     void MainViewShellChanged (const ViewShell& rMainViewShell);
101 
102     /** Call this method when the selection has changed to update the more
103         temporary tool bars (those in the TBG_FUNCTION group.)
104     */
105     void SelectionHasChanged (
106         const ViewShell& rViewShell,
107         const SdrView& rView);
108 
109     /** The set of tool bars that are handled by this manager class.
110     */
111     const static ::rtl::OUString msToolBar;                  // RID_DRAW_TOOLBOX, 23011
112                                                              // RID_GRAPHIC_TOOLBOX, 23025
113     const static ::rtl::OUString msOptionsToolBar;           // RID_DRAW_OPTIONS_TOOLBOX, 23020
114                                                              // RID_GRAPHIC_OPTIONS_TOOLBOX, 23026
115     const static ::rtl::OUString msCommonTaskToolBar;        // RID_DRAW_COMMONTASK_TOOLBOX, 23021
116     const static ::rtl::OUString msViewerToolBar;            // RID_DRAW_VIEWER_TOOLBOX, 23023
117                                                              // RID_GRAPHIC_VIEWER_TOOLBOX, 23024
118     const static ::rtl::OUString msSlideSorterToolBar;       // RID_SLIDE_TOOLBOX, 23012
119     const static ::rtl::OUString msSlideSorterObjectBar;     // RID_SLIDE_OBJ_TOOLBOX, 23014
120     const static ::rtl::OUString msOutlineToolBar;           // RID_OUTLINE_TOOLBOX, 23017
121     const static ::rtl::OUString msMasterViewToolBar;        // SID_MASTERPAGE, 27053
122     const static ::rtl::OUString msDrawingObjectToolBar;     // RID_DRAW_OBJ_TOOLBOX, 23013
123     const static ::rtl::OUString msGluePointsToolBar;        // RID_GLUEPOINTS_TOOLBOX, 23019
124     const static ::rtl::OUString msTextObjectBar;            // RID_DRAW_TEXT_TOOLBOX, 23016
125                                                              // RID_GRAPHIC_TEXT_TOOLBOX, 23028
126     const static ::rtl::OUString msBezierObjectBar;          // RID_BEZIER_TOOLBOX, 23015
127     const static ::rtl::OUString msGraphicObjectBar;         // RID_DRAW_GRAF_TOOLBOX, 23030
128     const static ::rtl::OUString msMediaObjectBar;           // RID_DRAW_MEDIA_TOOLBOX, 23031
129 	const static ::rtl::OUString msTableObjectBar;			 // RID_DRAW_TABLE_TOOLBOX
130 
131     /** The set of tool bar groups.
132     */
133     enum ToolBarGroup {
134         TBG__FIRST,
135 
136         TBG_PERMANENT = TBG__FIRST,
137         TBG_FUNCTION,
138         TBG_MASTER_MODE,
139 
140         TBG__LAST = TBG_MASTER_MODE
141     };
142 
143     /** Reset the set of visible object bars in the specified group.  Tool
144         bars in other groups are not affected.
145         @param rParentShell
146             When this shell is not the main view then the method returns
147             immediately.
148         @param eGroup
149             Only the tool bars in this group are rest.
150     */
151     void ResetToolBars (ToolBarGroup eGroup);
152 
153     /** Reset all tool bars, regardless of the group they belong to.
154         @param rParentShell
155             When this shell is not the main view then the method returns
156             immediately.
157     */
158     void ResetAllToolBars (void);
159 
160     /** Add the tool bar with the given name to the specified group of tool
161         bars.
162         @param rParentShell
163             When this shell is not the main view then the method returns
164             immediately.
165         @param eGroup
166             The new tool bar is added to this group.
167         @param rsToolBarName
168             The base name of the tool bar.  A proper prefix (like
169             private:resource/toolbar/) is added.  The name may be one of the
170             ones defined above.  Other names are allowed as well.
171     */
172     void AddToolBar (
173         ToolBarGroup eGroup,
174         const ::rtl::OUString& rsToolBarName);
175 
176     /** Add the tool bar shell to the shell stack.  This method basically
177         forwards the call to the ViewShellManager.
178         For some tool bar shells additional tool bars are made visible.
179         @param rParentShell
180             When this shell is not the main view then the method returns
181             immediately.
182         @param eGroup
183             The group is used for the actual tool bars.
184         @param nToolBarId
185             Id of the tool bar shell.
186     */
187     void AddToolBarShell (
188         ToolBarGroup eGroup,
189         ShellId nToolBarId);
190 
191     /** Remove the tool bar with the given name from the specified group.
192         If the tool bar is not visible then nothing happens.
193         If the tool bar is a member of another group then nothing happens
194         either.
195     */
196     void RemoveToolBar (
197         ToolBarGroup eGroup,
198         const ::rtl::OUString& rsToolBarName);
199 
200     /** This is basically a shortcut for ResetToolBars(),AddToolBar().  The
201         main difference is, that all sub shells of the specified parent
202         shell are deactivated as well.
203         @param rParentShell
204             When this shell is not the main view then the method returns
205             immediately.
206         @param eGroup
207             The new tool bar is added to this group.
208         @param rsToolBarName
209             The base name of the tool bar.  A proper prefix (like
210             private:resource/toolbar/) is added.  The name may be one of the
211             ones defined above.  Other names are allowed as well.
212     */
213     void SetToolBar (
214         ToolBarGroup eGroup,
215         const ::rtl::OUString& rsToolBarName);
216 
217     /** This is basically a shortcut for ResetToolBars(),AddToolBar().  The
218         main difference is, that all sub shells of the specified parent
219         shell are deactivated as well.
220         @param rParentShell
221             When this shell is not the main view then the method returns
222             immediately.
223         @param rParentShell
224             When this shell is not the main view then the method returns
225             immediately.
226         @param eGroup
227             The group is currently not used.
228         @param nToolBarId
229             Id of the tool bar shell.
230     */
231     void SetToolBarShell (
232         ToolBarGroup eGroup,
233         ShellId nToolBarId);
234 
235     void PreUpdate (void);
236 
237     /** Request an update of the active tool bars.  The update is made
238         asynchronously.
239     */
240     void RequestUpdate (void);
241 
242     /** This is a hint for the ToolBarManager to improve the performance
243         when it updates its tool bars when its own lock is released.  Taking
244         control of the release of the update lock of the ViewShellManager
245         avoids some shell stack modifications and tool bar updates.
246     */
247     void LockViewShellManager (void);
248 
249     /** Use this class to prevent the visible tool bars from being updated
250         (and thus causing repaints and GUI rearrangements) when several tool
251         bar operations are made in a row.
252     */
253     class UpdateLock { public:
UpdateLock(const::boost::shared_ptr<ToolBarManager> & rpManager)254         UpdateLock(const ::boost::shared_ptr<ToolBarManager>& rpManager)
255             : mpManager(rpManager) { mpManager->LockUpdate(); }
~UpdateLock(void)256         ~UpdateLock(void) { mpManager->UnlockUpdate(); }
257     private:
258         ::boost::shared_ptr<ToolBarManager> mpManager;
259     };
260     friend class UpdateLock;
261 
262     void ToolBarsDestroyed(void);
263 
264 private:
265     class Implementation;
266     ::boost::scoped_ptr<Implementation> mpImpl;
267 
268     /** The ViewShellBase is used to get the XLayoutManager and to determine
269         the plug in mode.
270     */
271     ToolBarManager (void);
272 
273     void LockUpdate (void);
274     void UnlockUpdate (void);
275 };
276 
277 } // end of namespace sd
278 
279 #endif
280