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