1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include "ShellFactory.hxx"
23 #include <rtl/ustring.hxx>
25 #include <sal/types.h>
30 namespace sd
{ class ViewShell
; }
31 namespace sd::tools
{ class EventMultiplexer
; }
36 class ViewShellManager
;
38 /** Manage the set of visible tool bars (and object bars). Usually they
39 belong to the current view in the center pane.
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.
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.
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.
60 : public std::enable_shared_from_this
<ToolBarManager
>
63 /** Use this method instead of the constructor to create new objects of
66 static std::shared_ptr
<ToolBarManager
> Create (
68 const std::shared_ptr
<tools::EventMultiplexer
>& rpMultiplexer
,
69 const std::shared_ptr
<ViewShellManager
>& rpViewShellManager
);
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.)
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
86 The type of the new main view shell.
88 void MainViewShellChanged ();
89 void MainViewShellChanged (const ViewShell
& rMainViewShell
);
91 /** Call this method when the selection has changed to update the more
92 temporary tool bars (those in the ToolBarGroup::Function group.)
94 void SelectionHasChanged (
95 const ViewShell
& rViewShell
,
96 const SdrView
& rView
);
98 /** The set of tool bars that are handled by this manager class.
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
128 /** The set of tool bar groups.
130 enum class ToolBarGroup
{
138 /** Reset the set of visible object bars in the specified group. Tool
139 bars in other groups are not affected.
141 When this shell is not the main view then the method returns
144 Only the tool bars in this group are rest.
146 void ResetToolBars (ToolBarGroup eGroup
);
148 /** Reset all tool bars, regardless of the group they belong to.
150 When this shell is not the main view then the method returns
153 void ResetAllToolBars();
155 /** Add the tool bar with the given name to the specified group of tool
158 When this shell is not the main view then the method returns
161 The new tool bar is added to this group.
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.
169 const OUString
& rsToolBarName
);
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.
175 When this shell is not the main view then the method returns
178 The group is used for the actual tool bars.
180 Id of the tool bar shell.
182 void AddToolBarShell (
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
193 const OUString
& rsToolBarName
);
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.
199 When this shell is not the main view then the method returns
202 The new tool bar is added to this group.
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.
210 const OUString
& rsToolBarName
);
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.
216 When this shell is not the main view then the method returns
219 When this shell is not the main view then the method returns
222 The group is currently not used.
224 Id of the tool bar shell.
226 void SetToolBarShell (
232 /** Request an update of the active tool bars. The update is made
235 void RequestUpdate();
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.
242 void LockViewShellManager();
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.
248 class UpdateLock
{ public:
249 UpdateLock(std::shared_ptr
<ToolBarManager
> pManager
)
250 : mpManager(std::move(pManager
)) { mpManager
->LockUpdate(); }
251 ~UpdateLock() COVERITY_NOEXCEPT_FALSE
{ mpManager
->UnlockUpdate(); }
253 std::shared_ptr
<ToolBarManager
> mpManager
;
255 friend class UpdateLock
;
257 void ToolBarsDestroyed();
260 class Implementation
;
261 std::unique_ptr
<Implementation
> mpImpl
;
263 /** The ViewShellBase is used to get the XLayoutManager and to determine
272 } // end of namespace sd
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */