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