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