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_VIEW_SHELL_MANAGER_HXX 29*cdf0e10cSrcweir #define SD_VIEW_SHELL_MANAGER_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "ShellFactory.hxx" 32*cdf0e10cSrcweir #include <tools/link.hxx> 33*cdf0e10cSrcweir #include <memory> 34*cdf0e10cSrcweir #include <vector> 35*cdf0e10cSrcweir #include <boost/shared_ptr.hpp> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir class FmFormShell; 38*cdf0e10cSrcweir class SfxShell; 39*cdf0e10cSrcweir class SfxUndoManager; 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir namespace sd { 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir class ViewShell; 44*cdf0e10cSrcweir class ViewShellBase; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir /** The ViewShellManager has the responsibility to manage the view shells 47*cdf0e10cSrcweir and sub shells on the SFX shell stack. They form a two level hierarchy 48*cdf0e10cSrcweir (the underlying ViewShellBase, the only true SfxViewShell descendant, 49*cdf0e10cSrcweir forms a third level.) On the first level there are the view shells 50*cdf0e10cSrcweir (what formely was called view shell, anyway; nowadays they are derived 51*cdf0e10cSrcweir from SfxShell.) and shells for panes. On the second level there are sub 52*cdf0e10cSrcweir shells (also derived from SfxShell) that usually are tool bars. 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir <p>On the SFX shell stack the regular sub shells are placed above their 55*cdf0e10cSrcweir view shells. The FormShell is a special case. With the SetFormShell() 56*cdf0e10cSrcweir method it can be placed directly above or below one of the view 57*cdf0e10cSrcweir shells.</p> 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir <p>Shells managed by this class are created by factories or are given 60*cdf0e10cSrcweir directly to Activate... methods. For the sub shells there is one 61*cdf0e10cSrcweir factory for every view shell. Factories are added or removed via the 62*cdf0e10cSrcweir (Add|Remove)SubShellFactory() methods. The FormShell is managed with the 63*cdf0e10cSrcweir factory of its view shell.</p> 64*cdf0e10cSrcweir */ 65*cdf0e10cSrcweir class ViewShellManager 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir public: 68*cdf0e10cSrcweir typedef ::boost::shared_ptr<ShellFactory<SfxShell> > SharedShellFactory; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir ViewShellManager (ViewShellBase& rBase); 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir /** Before the destructor is called the method Shutdown() has to have 73*cdf0e10cSrcweir been called. 74*cdf0e10cSrcweir */ 75*cdf0e10cSrcweir ~ViewShellManager (void); 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir /** Tell a ViewShellManager object to prepare to be deleted, i.e. to 78*cdf0e10cSrcweir destroy all of its resources and to ignore all following calls. 79*cdf0e10cSrcweir Use this when the owner of the view shell manager is about being 80*cdf0e10cSrcweir destroyed but the view shell manager itself can not yet be deleted. 81*cdf0e10cSrcweir */ 82*cdf0e10cSrcweir void Shutdown (void); 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir /** Set the factory for sub shells of the specified view shell. 85*cdf0e10cSrcweir */ 86*cdf0e10cSrcweir void AddSubShellFactory ( 87*cdf0e10cSrcweir ViewShell* pViewShell, 88*cdf0e10cSrcweir const SharedShellFactory& rpFactory); 89*cdf0e10cSrcweir void RemoveSubShellFactory ( 90*cdf0e10cSrcweir ViewShell* pViewShell, 91*cdf0e10cSrcweir const SharedShellFactory& rpFactory); 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir /** Activate the given view shell. 94*cdf0e10cSrcweir */ 95*cdf0e10cSrcweir void ActivateViewShell (ViewShell* pViewShell); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir /** Activate the given shell which is not a view shell. For view shells 98*cdf0e10cSrcweir use the ActivateViewShell() method. 99*cdf0e10cSrcweir */ 100*cdf0e10cSrcweir void ActivateShell (SfxShell* pShell); 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir /** Deactivate the specified shell, i.e. take it and all of its 103*cdf0e10cSrcweir object bars from the shell stack. 104*cdf0e10cSrcweir @param pShell 105*cdf0e10cSrcweir The shell to deactivate. 106*cdf0e10cSrcweir */ 107*cdf0e10cSrcweir void DeactivateViewShell (const ViewShell* pShell); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir /** Deactivate the specified shell. The shell is not destroyed. 110*cdf0e10cSrcweir */ 111*cdf0e10cSrcweir void DeactivateShell (const SfxShell* pShell); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir /** Associate the form shell with a view shell and their relative 114*cdf0e10cSrcweir position. This method does not change the shell stack, it just 115*cdf0e10cSrcweir stores the given values for the next shell stack update. 116*cdf0e10cSrcweir @param pParentShell 117*cdf0e10cSrcweir The view shell of the form shell. 118*cdf0e10cSrcweir @param pFormShell 119*cdf0e10cSrcweir The form shell. 120*cdf0e10cSrcweir @param bAbove 121*cdf0e10cSrcweir When <TRUE/> then the form shell will be placed directly above 122*cdf0e10cSrcweir pViewShell on the SFX shell stack. Otherwise the form shell is 123*cdf0e10cSrcweir placed directly below the view shell. 124*cdf0e10cSrcweir */ 125*cdf0e10cSrcweir void SetFormShell (const ViewShell* pParentShell, FmFormShell* pFormShell, bool bAbove); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir /** Activate the specified shell as sub shell for the given view shell. 128*cdf0e10cSrcweir The sub shell factory associated with the view shell is used to 129*cdf0e10cSrcweir create the sub shell. 130*cdf0e10cSrcweir @param rParentShell 131*cdf0e10cSrcweir The new sub shell will be placed above this view shell. 132*cdf0e10cSrcweir @param nId 133*cdf0e10cSrcweir This id is used only with the factory registered for the parent 134*cdf0e10cSrcweir view shell. 135*cdf0e10cSrcweir */ 136*cdf0e10cSrcweir void ActivateSubShell (const ViewShell& rParentShell, ShellId nId); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir /** Deactivate the specified sub shell. 139*cdf0e10cSrcweir */ 140*cdf0e10cSrcweir void DeactivateSubShell (const ViewShell& rParentShell, ShellId nId); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir /** Move the specified sub shells to the top position among the sub 143*cdf0e10cSrcweir shells of the parent view shell. The rest of the SFX shell stack 144*cdf0e10cSrcweir does not change (but the all shells above the sub shells have to be 145*cdf0e10cSrcweir taken once off the stack and are then moved back on again.) 146*cdf0e10cSrcweir */ 147*cdf0e10cSrcweir void MoveSubShellToTop (const ViewShell& rParentShell, ShellId nId); 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir /** Send all sub shells of the specified view shell an Invalidate() 150*cdf0e10cSrcweir call. This does not modify the shell stack. 151*cdf0e10cSrcweir */ 152*cdf0e10cSrcweir void InvalidateAllSubShells ( 153*cdf0e10cSrcweir ViewShell* pViewShell); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir /** Move the specified view shell to the top most position on the stack 156*cdf0e10cSrcweir of view shells in relation to the other view shells. After this the 157*cdf0e10cSrcweir only shells that are higher on the stack are its object bars. 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir Call this method after a focus change to bring a view mode view 160*cdf0e10cSrcweir shell and ist associated tool bar shells to the top of the 161*cdf0e10cSrcweir stack. 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir The mbKeepMainViewShellOnTop flag is not obeyed. 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir @param nId 166*cdf0e10cSrcweir The id of the shell to move to the top. 167*cdf0e10cSrcweir */ 168*cdf0e10cSrcweir void MoveToTop (const ViewShell& rShell); 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir /** Return the first, i.e. top most, view shell that has been activated 171*cdf0e10cSrcweir under the given id. 172*cdf0e10cSrcweir @param nId 173*cdf0e10cSrcweir The id of the shell for which to return a pointer. 174*cdf0e10cSrcweir @return 175*cdf0e10cSrcweir When the specified shell is currently not active then NULL is 176*cdf0e10cSrcweir returned. 177*cdf0e10cSrcweir */ 178*cdf0e10cSrcweir SfxShell* GetShell (ShellId nId) const; 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir /** Return the top-most shell on the SFX shell stack regardless of 181*cdf0e10cSrcweir whether that is a view shell or a sub shell. 182*cdf0e10cSrcweir */ 183*cdf0e10cSrcweir SfxShell* GetTopShell (void) const; 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir /** Use this class to safely lock updates of the view shell stack. 186*cdf0e10cSrcweir */ 187*cdf0e10cSrcweir class UpdateLock 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir public: 190*cdf0e10cSrcweir UpdateLock (const ::boost::shared_ptr<ViewShellManager>& rpManager) 191*cdf0e10cSrcweir : mpManager(rpManager) {mpManager->LockUpdate();} 192*cdf0e10cSrcweir ~UpdateLock (void) {mpManager->UnlockUpdate();}; 193*cdf0e10cSrcweir private: 194*cdf0e10cSrcweir ::boost::shared_ptr<ViewShellManager> mpManager; 195*cdf0e10cSrcweir }; 196*cdf0e10cSrcweir friend class UpdateLock; 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir private: 199*cdf0e10cSrcweir class Implementation; 200*cdf0e10cSrcweir ::std::auto_ptr<ViewShellManager::Implementation> mpImpl; 201*cdf0e10cSrcweir bool mbValid; 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir void LockUpdate (void); 204*cdf0e10cSrcweir void UnlockUpdate (void); 205*cdf0e10cSrcweir }; 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir } // end of namespace sd 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir #endif 212*cdf0e10cSrcweir 213