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