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