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