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