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