15b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
35b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
45b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file
55b190011SAndrew Rist * distributed with this work for additional information
65b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file
75b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the
85b190011SAndrew Rist * "License"); you may not use this file except in compliance
95b190011SAndrew Rist * with the License. You may obtain a copy of the License at
105b190011SAndrew Rist *
115b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
125b190011SAndrew Rist *
135b190011SAndrew Rist * Unless required by applicable law or agreed to in writing,
145b190011SAndrew Rist * software distributed under the License is distributed on an
155b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165b190011SAndrew Rist * KIND, either express or implied. See the License for the
175b190011SAndrew Rist * specific language governing permissions and limitations
185b190011SAndrew Rist * under the License.
195b190011SAndrew Rist *
205b190011SAndrew Rist *************************************************************/
215b190011SAndrew Rist
225b190011SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sd.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "ViewShellManager.hxx"
28cdf0e10cSrcweir #include "ViewShell.hxx"
29cdf0e10cSrcweir #include "ViewShellBase.hxx"
30cdf0e10cSrcweir #include "Window.hxx"
31cdf0e10cSrcweir #include "DrawDocShell.hxx"
32cdf0e10cSrcweir #include "FormShellManager.hxx"
33cdf0e10cSrcweir
34cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
35cdf0e10cSrcweir #include <svx/svxids.hrc>
36cdf0e10cSrcweir #include <svx/fmshell.hxx>
37cdf0e10cSrcweir
38cdf0e10cSrcweir #include <hash_map>
39cdf0e10cSrcweir
40cdf0e10cSrcweir #undef VERBOSE
41cdf0e10cSrcweir //#define VERBOSE 2
42cdf0e10cSrcweir
43cdf0e10cSrcweir namespace sd {
44cdf0e10cSrcweir
45cdf0e10cSrcweir namespace {
46cdf0e10cSrcweir
47cdf0e10cSrcweir /** The ShellDescriptor class is used to shells together with their ids and
48cdf0e10cSrcweir the factory that was used to create the shell.
49cdf0e10cSrcweir
50cdf0e10cSrcweir The shell pointer may be NULL. In that case the shell is created on
51cdf0e10cSrcweir demand by a factory.
52cdf0e10cSrcweir
53cdf0e10cSrcweir The factory pointer may be NULL. In that case the shell pointer is
54cdf0e10cSrcweir given to the ViewShellManager.
55cdf0e10cSrcweir
56cdf0e10cSrcweir Shell pointer and factory pointer can but should not be NULL at the same
57cdf0e10cSrcweir time.
58cdf0e10cSrcweir */
59cdf0e10cSrcweir class ShellDescriptor {
60cdf0e10cSrcweir public:
61cdf0e10cSrcweir SfxShell* mpShell;
62cdf0e10cSrcweir ShellId mnId;
63cdf0e10cSrcweir ViewShellManager::SharedShellFactory mpFactory;
647a32b0c8SAndre Fischer bool mbIsListenerAddedToWindow;
657a32b0c8SAndre Fischer
66cdf0e10cSrcweir ShellDescriptor ();
67cdf0e10cSrcweir ShellDescriptor (SfxShell* pShell, ShellId nId);
68cdf0e10cSrcweir ShellDescriptor (const ShellDescriptor& rDescriptor);
69cdf0e10cSrcweir ShellDescriptor& operator= (const ShellDescriptor& rDescriptor);
70cdf0e10cSrcweir bool IsMainViewShell (void) const;
71cdf0e10cSrcweir ::Window* GetWindow (void) const;
72cdf0e10cSrcweir };
73cdf0e10cSrcweir
74cdf0e10cSrcweir
75cdf0e10cSrcweir
76cdf0e10cSrcweir
77cdf0e10cSrcweir /** This functor can be used to search for a shell in an STL container when the
78cdf0e10cSrcweir shell pointer is given.
79cdf0e10cSrcweir */
80cdf0e10cSrcweir class IsShell : public ::std::unary_function<ShellDescriptor,bool>
81cdf0e10cSrcweir {
82cdf0e10cSrcweir public:
IsShell(const SfxShell * pShell)83cdf0e10cSrcweir IsShell (const SfxShell* pShell) : mpShell(pShell) {}
operator ()(const ShellDescriptor & rDescriptor)84cdf0e10cSrcweir bool operator() (const ShellDescriptor& rDescriptor)
85cdf0e10cSrcweir { return rDescriptor.mpShell == mpShell; }
86cdf0e10cSrcweir private:
87cdf0e10cSrcweir const SfxShell* mpShell;
88cdf0e10cSrcweir };
89cdf0e10cSrcweir
90cdf0e10cSrcweir
91cdf0e10cSrcweir
92cdf0e10cSrcweir
93cdf0e10cSrcweir /** This functor can be used to search for a shell in an STL container when the
94cdf0e10cSrcweir id of the shell is given.
95cdf0e10cSrcweir */
96cdf0e10cSrcweir class IsId : public ::std::unary_function<ShellDescriptor,bool>
97cdf0e10cSrcweir {
98cdf0e10cSrcweir public:
IsId(ShellId nId)99cdf0e10cSrcweir IsId (ShellId nId) : mnId(nId) {}
operator ()(const ShellDescriptor & rDescriptor)100cdf0e10cSrcweir bool operator() (const ShellDescriptor& rDescriptor)
101cdf0e10cSrcweir { return rDescriptor.mnId == mnId; }
102cdf0e10cSrcweir private:
103cdf0e10cSrcweir ShellId mnId;
104cdf0e10cSrcweir };
105cdf0e10cSrcweir
106cdf0e10cSrcweir } // end of anonymous namespace
107cdf0e10cSrcweir
108cdf0e10cSrcweir
109cdf0e10cSrcweir
110cdf0e10cSrcweir
111cdf0e10cSrcweir class ViewShellManager::Implementation
112cdf0e10cSrcweir {
113cdf0e10cSrcweir public:
114cdf0e10cSrcweir Implementation (
115cdf0e10cSrcweir ViewShellManager& rManager,
116cdf0e10cSrcweir ViewShellBase& rBase);
117cdf0e10cSrcweir ~Implementation (void);
118cdf0e10cSrcweir
119cdf0e10cSrcweir void AddShellFactory (
120cdf0e10cSrcweir const SfxShell* pViewShell,
121cdf0e10cSrcweir const SharedShellFactory& rpFactory);
122cdf0e10cSrcweir void RemoveShellFactory (
123cdf0e10cSrcweir const SfxShell* pViewShell,
124cdf0e10cSrcweir const SharedShellFactory& rpFactory);
125cdf0e10cSrcweir void ActivateViewShell (
126cdf0e10cSrcweir ViewShell* pViewShell);
127cdf0e10cSrcweir void DeactivateViewShell (const ViewShell& rShell);
128cdf0e10cSrcweir void ActivateShell (SfxShell& rShell);
129cdf0e10cSrcweir void DeactivateShell (const SfxShell& rShell);
130cdf0e10cSrcweir void ActivateShell (const ShellDescriptor& rDescriptor);
131cdf0e10cSrcweir void SetFormShell (const ViewShell* pViewShell, FmFormShell* pFormShell, bool bAbove);
132cdf0e10cSrcweir void ActivateSubShell (const SfxShell& rParentShell, ShellId nId);
133cdf0e10cSrcweir void DeactivateSubShell (const SfxShell& rParentShell, ShellId nId);
134cdf0e10cSrcweir void MoveSubShellToTop (const SfxShell& rParentShell, ShellId nId);
135cdf0e10cSrcweir void MoveToTop (const SfxShell& rParentShell);
136cdf0e10cSrcweir SfxShell* GetShell (ShellId nId) const;
137cdf0e10cSrcweir SfxShell* GetTopShell (void) const;
138cdf0e10cSrcweir void Shutdown (void);
139cdf0e10cSrcweir void InvalidateAllSubShells (const SfxShell* pParentShell);
140cdf0e10cSrcweir
141cdf0e10cSrcweir /** Remove all shells from the SFX stack above and including the given
142cdf0e10cSrcweir shell.
143cdf0e10cSrcweir */
144cdf0e10cSrcweir void TakeShellsFromStack (const SfxShell* pShell);
145cdf0e10cSrcweir
146cdf0e10cSrcweir class UpdateLock
147cdf0e10cSrcweir {
148cdf0e10cSrcweir public:
UpdateLock(Implementation & rImpl)149cdf0e10cSrcweir UpdateLock (Implementation& rImpl) : mrImpl(rImpl) {mrImpl.LockUpdate();}
~UpdateLock(void)150cdf0e10cSrcweir ~UpdateLock (void) {mrImpl.UnlockUpdate();};
151cdf0e10cSrcweir private:
152cdf0e10cSrcweir Implementation& mrImpl;
153cdf0e10cSrcweir };
154cdf0e10cSrcweir
155cdf0e10cSrcweir
156cdf0e10cSrcweir
157cdf0e10cSrcweir /** Prevent updates of the shell stack. While the sub shell manager is
158cdf0e10cSrcweir locked it will update its internal data structures but not alter the
159cdf0e10cSrcweir shell stack. Use this method when there are several modifications
160cdf0e10cSrcweir to the shell stack to prevent multiple rebuilds of the shell stack
161cdf0e10cSrcweir and resulting broadcasts.
162cdf0e10cSrcweir */
163cdf0e10cSrcweir void LockUpdate (void);
164cdf0e10cSrcweir
165cdf0e10cSrcweir /** Allow updates of the shell stack. This method has to be called the
166cdf0e10cSrcweir same number of times as LockUpdate() to really allow a rebuild of
167cdf0e10cSrcweir the shell stack.
168cdf0e10cSrcweir */
169cdf0e10cSrcweir void UnlockUpdate (void);
170cdf0e10cSrcweir
171cdf0e10cSrcweir private:
172cdf0e10cSrcweir ViewShellBase& mrBase;
173cdf0e10cSrcweir mutable ::osl::Mutex maMutex;
174cdf0e10cSrcweir
operator ()(const SfxShell * p) const175cdf0e10cSrcweir class ShellHash{public: size_t operator()(const SfxShell* p) const { return (size_t)p;} };
176cdf0e10cSrcweir typedef ::std::hash_multimap<const SfxShell*,SharedShellFactory,ShellHash>
177cdf0e10cSrcweir FactoryList;
178cdf0e10cSrcweir FactoryList maShellFactories;
179cdf0e10cSrcweir
180cdf0e10cSrcweir /** List of the active view shells. In order to create gather all shells
181cdf0e10cSrcweir to put on the shell stack each view shell in this list is asked for
182cdf0e10cSrcweir its sub-shells (typically toolbars).
183cdf0e10cSrcweir */
184cdf0e10cSrcweir typedef ::std::list<ShellDescriptor> ActiveShellList;
185cdf0e10cSrcweir ActiveShellList maActiveViewShells;
186cdf0e10cSrcweir
187cdf0e10cSrcweir typedef ::std::list<ShellDescriptor> SubShellSubList;
188cdf0e10cSrcweir typedef ::std::hash_map<const SfxShell*,SubShellSubList,ShellHash> SubShellList;
189cdf0e10cSrcweir SubShellList maActiveSubShells;
190cdf0e10cSrcweir
191cdf0e10cSrcweir /** In this member we remember what shells we have pushed on the shell
192cdf0e10cSrcweir stack.
193cdf0e10cSrcweir */
194cdf0e10cSrcweir typedef ::std::vector<SfxShell*> ShellStack;
195cdf0e10cSrcweir
196cdf0e10cSrcweir int mnUpdateLockCount;
197cdf0e10cSrcweir
198cdf0e10cSrcweir /** When this flag is set then the main view shell is always kept at the
199cdf0e10cSrcweir top of the shell stack.
200cdf0e10cSrcweir */
201cdf0e10cSrcweir bool mbKeepMainViewShellOnTop;
202cdf0e10cSrcweir
203cdf0e10cSrcweir /** The UpdateShellStack() method can be called recursively. This flag
204cdf0e10cSrcweir is used to communicate between different levels of invocation: if
205cdf0e10cSrcweir the stack has been updated in an inner call the outer call can (has
206cdf0e10cSrcweir to) stop and return immediately.
207cdf0e10cSrcweir */
208cdf0e10cSrcweir bool mbShellStackIsUpToDate;
209cdf0e10cSrcweir
210cdf0e10cSrcweir SfxShell* mpFormShell;
211cdf0e10cSrcweir const ViewShell* mpFormShellParent;
212cdf0e10cSrcweir bool mbFormShellAboveParent;
213cdf0e10cSrcweir
214cdf0e10cSrcweir SfxShell* mpTopShell;
215cdf0e10cSrcweir
216cdf0e10cSrcweir void GatherActiveShells (ShellStack& rShellList);
217cdf0e10cSrcweir
218cdf0e10cSrcweir void UpdateShellStack (void);
219cdf0e10cSrcweir
220cdf0e10cSrcweir void CreateShells (void);
221cdf0e10cSrcweir
222cdf0e10cSrcweir /** This method rebuilds the stack of shells that are stacked upon the
223cdf0e10cSrcweir view shell base.
224cdf0e10cSrcweir */
225cdf0e10cSrcweir void CreateTargetStack (ShellStack& rStack) const;
226cdf0e10cSrcweir
227cdf0e10cSrcweir DECL_LINK(WindowEventHandler, VclWindowEvent*);
228cdf0e10cSrcweir
229cdf0e10cSrcweir #ifdef VERBOSE
230cdf0e10cSrcweir void DumpShellStack (const ShellStack& rStack);
231cdf0e10cSrcweir void DumpSfxShellStack (void);
232cdf0e10cSrcweir #endif
233cdf0e10cSrcweir
234cdf0e10cSrcweir /** To be called before a shell is taken fom the SFX shell stack. This
235cdf0e10cSrcweir method deactivates an active text editing to avoid problems with
236cdf0e10cSrcweir undo managers.
237cdf0e10cSrcweir Afterwards the Deactivate() of the shell is called.
238cdf0e10cSrcweir */
239cdf0e10cSrcweir void Deactivate (SfxShell* pShell);
240cdf0e10cSrcweir
241cdf0e10cSrcweir ShellDescriptor CreateSubShell (
242cdf0e10cSrcweir SfxShell* pShell,
243cdf0e10cSrcweir ShellId nShellId,
244cdf0e10cSrcweir ::Window* pParentWindow,
245cdf0e10cSrcweir FrameView* pFrameView);
2467a32b0c8SAndre Fischer void DestroyViewShell (ShellDescriptor& rDescriptor);
247cdf0e10cSrcweir void DestroySubShell (
248cdf0e10cSrcweir const SfxShell& rViewShell,
249cdf0e10cSrcweir const ShellDescriptor& rDescriptor);
250cdf0e10cSrcweir };
251cdf0e10cSrcweir
252cdf0e10cSrcweir
253cdf0e10cSrcweir
254cdf0e10cSrcweir
255cdf0e10cSrcweir //===== ViewShellManager ======================================================
256cdf0e10cSrcweir
ViewShellManager(ViewShellBase & rBase)257cdf0e10cSrcweir ViewShellManager::ViewShellManager (ViewShellBase& rBase)
258cdf0e10cSrcweir : mpImpl(new Implementation(*this,rBase)),
259cdf0e10cSrcweir mbValid(true)
260cdf0e10cSrcweir {
261cdf0e10cSrcweir }
262cdf0e10cSrcweir
263cdf0e10cSrcweir
264cdf0e10cSrcweir
265cdf0e10cSrcweir
~ViewShellManager(void)266cdf0e10cSrcweir ViewShellManager::~ViewShellManager (void)
267cdf0e10cSrcweir {
268cdf0e10cSrcweir }
269cdf0e10cSrcweir
270cdf0e10cSrcweir
271cdf0e10cSrcweir
272cdf0e10cSrcweir
AddSubShellFactory(ViewShell * pViewShell,const SharedShellFactory & rpFactory)273cdf0e10cSrcweir void ViewShellManager::AddSubShellFactory (
274cdf0e10cSrcweir ViewShell* pViewShell,
275cdf0e10cSrcweir const SharedShellFactory& rpFactory)
276cdf0e10cSrcweir {
277cdf0e10cSrcweir if (mbValid)
278cdf0e10cSrcweir mpImpl->AddShellFactory(pViewShell, rpFactory);
279cdf0e10cSrcweir }
280cdf0e10cSrcweir
281cdf0e10cSrcweir
282cdf0e10cSrcweir
283cdf0e10cSrcweir
RemoveSubShellFactory(ViewShell * pViewShell,const SharedShellFactory & rpFactory)284cdf0e10cSrcweir void ViewShellManager::RemoveSubShellFactory (
285cdf0e10cSrcweir ViewShell* pViewShell,
286cdf0e10cSrcweir const SharedShellFactory& rpFactory)
287cdf0e10cSrcweir {
288cdf0e10cSrcweir if (mbValid)
289cdf0e10cSrcweir mpImpl->RemoveShellFactory(pViewShell, rpFactory);
290cdf0e10cSrcweir }
291cdf0e10cSrcweir
292cdf0e10cSrcweir
293cdf0e10cSrcweir
294cdf0e10cSrcweir
ActivateViewShell(ViewShell * pViewShell)295cdf0e10cSrcweir void ViewShellManager::ActivateViewShell (ViewShell* pViewShell)
296cdf0e10cSrcweir {
297cdf0e10cSrcweir if (mbValid)
298cdf0e10cSrcweir return mpImpl->ActivateViewShell(pViewShell);
299cdf0e10cSrcweir }
300cdf0e10cSrcweir
301cdf0e10cSrcweir
302cdf0e10cSrcweir
303cdf0e10cSrcweir
DeactivateViewShell(const ViewShell * pShell)304cdf0e10cSrcweir void ViewShellManager::DeactivateViewShell (const ViewShell* pShell)
305cdf0e10cSrcweir {
306cdf0e10cSrcweir if (mbValid && pShell!=NULL)
307cdf0e10cSrcweir mpImpl->DeactivateViewShell(*pShell);
308cdf0e10cSrcweir }
309cdf0e10cSrcweir
310cdf0e10cSrcweir
311cdf0e10cSrcweir
312cdf0e10cSrcweir
MoveSubShellToTop(const ViewShell & rParentShell,ShellId nId)313cdf0e10cSrcweir void ViewShellManager::MoveSubShellToTop (
314cdf0e10cSrcweir const ViewShell& rParentShell,
315cdf0e10cSrcweir ShellId nId)
316cdf0e10cSrcweir {
317cdf0e10cSrcweir if (mbValid)
318cdf0e10cSrcweir mpImpl->MoveSubShellToTop(rParentShell, nId);
319cdf0e10cSrcweir }
320cdf0e10cSrcweir
321cdf0e10cSrcweir
322cdf0e10cSrcweir
323cdf0e10cSrcweir
SetFormShell(const ViewShell * pParentShell,FmFormShell * pFormShell,bool bAbove)324cdf0e10cSrcweir void ViewShellManager::SetFormShell (
325cdf0e10cSrcweir const ViewShell* pParentShell,
326cdf0e10cSrcweir FmFormShell* pFormShell,
327cdf0e10cSrcweir bool bAbove)
328cdf0e10cSrcweir {
329cdf0e10cSrcweir if (mbValid)
330cdf0e10cSrcweir mpImpl->SetFormShell(pParentShell,pFormShell,bAbove);
331cdf0e10cSrcweir }
332cdf0e10cSrcweir
333cdf0e10cSrcweir
334cdf0e10cSrcweir
335cdf0e10cSrcweir
ActivateSubShell(const ViewShell & rViewShell,ShellId nId)336cdf0e10cSrcweir void ViewShellManager::ActivateSubShell (const ViewShell& rViewShell, ShellId nId)
337cdf0e10cSrcweir {
338cdf0e10cSrcweir if (mbValid)
339cdf0e10cSrcweir mpImpl->ActivateSubShell(rViewShell,nId);
340cdf0e10cSrcweir }
341cdf0e10cSrcweir
342cdf0e10cSrcweir
343cdf0e10cSrcweir
344cdf0e10cSrcweir
DeactivateSubShell(const ViewShell & rViewShell,ShellId nId)345cdf0e10cSrcweir void ViewShellManager::DeactivateSubShell (const ViewShell& rViewShell, ShellId nId)
346cdf0e10cSrcweir {
347cdf0e10cSrcweir if (mbValid)
348cdf0e10cSrcweir mpImpl->DeactivateSubShell(rViewShell,nId);
349cdf0e10cSrcweir }
350cdf0e10cSrcweir
351cdf0e10cSrcweir
352cdf0e10cSrcweir
353cdf0e10cSrcweir
InvalidateAllSubShells(ViewShell * pViewShell)354cdf0e10cSrcweir void ViewShellManager::InvalidateAllSubShells (ViewShell* pViewShell)
355cdf0e10cSrcweir {
356cdf0e10cSrcweir if (mbValid)
357cdf0e10cSrcweir mpImpl->InvalidateAllSubShells(pViewShell);
358cdf0e10cSrcweir }
359cdf0e10cSrcweir
360cdf0e10cSrcweir
361cdf0e10cSrcweir
362cdf0e10cSrcweir
ActivateShell(SfxShell * pShell)363cdf0e10cSrcweir void ViewShellManager::ActivateShell (SfxShell* pShell)
364cdf0e10cSrcweir {
365cdf0e10cSrcweir if (mbValid && pShell!=NULL)
366cdf0e10cSrcweir mpImpl->ActivateShell(*pShell);
367cdf0e10cSrcweir }
368cdf0e10cSrcweir
369cdf0e10cSrcweir
370cdf0e10cSrcweir
371cdf0e10cSrcweir
DeactivateShell(const SfxShell * pShell)372cdf0e10cSrcweir void ViewShellManager::DeactivateShell (const SfxShell* pShell)
373cdf0e10cSrcweir {
374cdf0e10cSrcweir if (mbValid && pShell!=NULL)
375cdf0e10cSrcweir mpImpl->DeactivateShell(*pShell);
376cdf0e10cSrcweir }
377cdf0e10cSrcweir
378cdf0e10cSrcweir
379cdf0e10cSrcweir
380cdf0e10cSrcweir
MoveToTop(const ViewShell & rParentShell)381cdf0e10cSrcweir void ViewShellManager::MoveToTop (const ViewShell& rParentShell)
382cdf0e10cSrcweir {
383cdf0e10cSrcweir if (mbValid)
384cdf0e10cSrcweir mpImpl->MoveToTop(rParentShell);
385cdf0e10cSrcweir }
386cdf0e10cSrcweir
387cdf0e10cSrcweir
388cdf0e10cSrcweir
389cdf0e10cSrcweir
GetShell(ShellId nId) const390cdf0e10cSrcweir SfxShell* ViewShellManager::GetShell (ShellId nId) const
391cdf0e10cSrcweir {
392cdf0e10cSrcweir if (mbValid)
393cdf0e10cSrcweir return mpImpl->GetShell(nId);
394cdf0e10cSrcweir else
395cdf0e10cSrcweir return NULL;
396cdf0e10cSrcweir }
397cdf0e10cSrcweir
398cdf0e10cSrcweir
399cdf0e10cSrcweir
400cdf0e10cSrcweir
GetTopShell(void) const401cdf0e10cSrcweir SfxShell* ViewShellManager::GetTopShell (void) const
402cdf0e10cSrcweir {
403cdf0e10cSrcweir if (mbValid)
404cdf0e10cSrcweir return mpImpl->GetTopShell();
405cdf0e10cSrcweir else
406cdf0e10cSrcweir return NULL;
407cdf0e10cSrcweir }
408cdf0e10cSrcweir
409cdf0e10cSrcweir
410cdf0e10cSrcweir
411cdf0e10cSrcweir
Shutdown(void)412cdf0e10cSrcweir void ViewShellManager::Shutdown (void)
413cdf0e10cSrcweir {
414cdf0e10cSrcweir if (mbValid)
415cdf0e10cSrcweir {
416cdf0e10cSrcweir mpImpl->Shutdown();
417cdf0e10cSrcweir mbValid = false;
418cdf0e10cSrcweir }
419cdf0e10cSrcweir }
420cdf0e10cSrcweir
421cdf0e10cSrcweir
422cdf0e10cSrcweir
LockUpdate(void)423cdf0e10cSrcweir void ViewShellManager::LockUpdate (void)
424cdf0e10cSrcweir {
425cdf0e10cSrcweir mpImpl->LockUpdate();
426cdf0e10cSrcweir }
427cdf0e10cSrcweir
428cdf0e10cSrcweir
429cdf0e10cSrcweir
430cdf0e10cSrcweir
UnlockUpdate(void)431cdf0e10cSrcweir void ViewShellManager::UnlockUpdate (void)
432cdf0e10cSrcweir {
433cdf0e10cSrcweir mpImpl->UnlockUpdate();
434cdf0e10cSrcweir }
435cdf0e10cSrcweir
436cdf0e10cSrcweir
437cdf0e10cSrcweir
438cdf0e10cSrcweir
439cdf0e10cSrcweir //===== ViewShellManager::Implementation ======================================
440cdf0e10cSrcweir
Implementation(ViewShellManager & rManager,ViewShellBase & rBase)441cdf0e10cSrcweir ViewShellManager::Implementation::Implementation (
442cdf0e10cSrcweir ViewShellManager& rManager,
443cdf0e10cSrcweir ViewShellBase& rBase)
444cdf0e10cSrcweir : mrBase(rBase),
445cdf0e10cSrcweir maMutex(),
446cdf0e10cSrcweir maShellFactories(),
447cdf0e10cSrcweir maActiveViewShells(),
448cdf0e10cSrcweir mnUpdateLockCount(0),
449cdf0e10cSrcweir mbKeepMainViewShellOnTop(false),
450cdf0e10cSrcweir mbShellStackIsUpToDate(true),
451cdf0e10cSrcweir mpFormShell(NULL),
452cdf0e10cSrcweir mpFormShellParent(NULL),
453cdf0e10cSrcweir mbFormShellAboveParent(true),
454cdf0e10cSrcweir mpTopShell(NULL)
455cdf0e10cSrcweir {
456cdf0e10cSrcweir (void)rManager;
457cdf0e10cSrcweir }
458cdf0e10cSrcweir
459cdf0e10cSrcweir
460cdf0e10cSrcweir
461cdf0e10cSrcweir
~Implementation(void)462cdf0e10cSrcweir ViewShellManager::Implementation::~Implementation (void)
463cdf0e10cSrcweir {
464cdf0e10cSrcweir Shutdown();
465cdf0e10cSrcweir }
466cdf0e10cSrcweir
467cdf0e10cSrcweir
468cdf0e10cSrcweir
469cdf0e10cSrcweir
AddShellFactory(const SfxShell * pViewShell,const SharedShellFactory & rpFactory)470cdf0e10cSrcweir void ViewShellManager::Implementation::AddShellFactory (
471cdf0e10cSrcweir const SfxShell* pViewShell,
472cdf0e10cSrcweir const SharedShellFactory& rpFactory)
473cdf0e10cSrcweir {
474cdf0e10cSrcweir bool bAlreadyAdded (false);
475cdf0e10cSrcweir
476cdf0e10cSrcweir // Check that the given factory has not already been added.
477cdf0e10cSrcweir ::std::pair<FactoryList::iterator,FactoryList::iterator> aRange(
478cdf0e10cSrcweir maShellFactories.equal_range(pViewShell));
479cdf0e10cSrcweir for (FactoryList::const_iterator iFactory=aRange.first; iFactory!=aRange.second; ++iFactory)
480cdf0e10cSrcweir if (iFactory->second == rpFactory)
481cdf0e10cSrcweir {
482cdf0e10cSrcweir bAlreadyAdded = true;
483cdf0e10cSrcweir break;
484cdf0e10cSrcweir }
485cdf0e10cSrcweir
486cdf0e10cSrcweir // Add the factory if it is not already present.
487cdf0e10cSrcweir if ( ! bAlreadyAdded)
488cdf0e10cSrcweir maShellFactories.insert(FactoryList::value_type(pViewShell, rpFactory));
489cdf0e10cSrcweir }
490cdf0e10cSrcweir
491cdf0e10cSrcweir
492cdf0e10cSrcweir
493cdf0e10cSrcweir
RemoveShellFactory(const SfxShell * pViewShell,const SharedShellFactory & rpFactory)494cdf0e10cSrcweir void ViewShellManager::Implementation::RemoveShellFactory (
495cdf0e10cSrcweir const SfxShell* pViewShell,
496cdf0e10cSrcweir const SharedShellFactory& rpFactory)
497cdf0e10cSrcweir {
498cdf0e10cSrcweir ::std::pair<FactoryList::iterator,FactoryList::iterator> aRange(
499cdf0e10cSrcweir maShellFactories.equal_range(pViewShell));
500cdf0e10cSrcweir for (FactoryList::iterator iFactory=aRange.first; iFactory!=aRange.second; ++iFactory)
501cdf0e10cSrcweir if (iFactory->second == rpFactory)
502cdf0e10cSrcweir {
503cdf0e10cSrcweir maShellFactories.erase(iFactory);
504cdf0e10cSrcweir break;
505cdf0e10cSrcweir }
506cdf0e10cSrcweir }
507cdf0e10cSrcweir
508cdf0e10cSrcweir
509cdf0e10cSrcweir
510cdf0e10cSrcweir
ActivateViewShell(ViewShell * pViewShell)511cdf0e10cSrcweir void ViewShellManager::Implementation::ActivateViewShell (ViewShell* pViewShell)
512cdf0e10cSrcweir {
513cdf0e10cSrcweir ::osl::MutexGuard aGuard (maMutex);
514cdf0e10cSrcweir
515cdf0e10cSrcweir ShellDescriptor aResult;
516cdf0e10cSrcweir aResult.mpShell = pViewShell;
517cdf0e10cSrcweir
518cdf0e10cSrcweir // Register as window listener so that the shells of the current
519cdf0e10cSrcweir // window can be moved to the top of the shell stack.
520cdf0e10cSrcweir if (aResult.mpShell != NULL)
521cdf0e10cSrcweir {
522cdf0e10cSrcweir ::Window* pWindow = aResult.GetWindow();
523cdf0e10cSrcweir if (pWindow != NULL)
5247a32b0c8SAndre Fischer {
525cdf0e10cSrcweir pWindow->AddEventListener(
526cdf0e10cSrcweir LINK(this, ViewShellManager::Implementation, WindowEventHandler));
5277a32b0c8SAndre Fischer aResult.mbIsListenerAddedToWindow = true;
5287a32b0c8SAndre Fischer }
529cdf0e10cSrcweir else
530cdf0e10cSrcweir {
531cdf0e10cSrcweir DBG_ASSERT(false,
532cdf0e10cSrcweir "ViewShellManager::ActivateViewShell: "
533cdf0e10cSrcweir "new view shell has no active window");
534cdf0e10cSrcweir }
535cdf0e10cSrcweir }
536cdf0e10cSrcweir
537cdf0e10cSrcweir ActivateShell(aResult);
538cdf0e10cSrcweir }
539cdf0e10cSrcweir
540cdf0e10cSrcweir
541cdf0e10cSrcweir
542cdf0e10cSrcweir
DeactivateViewShell(const ViewShell & rShell)543cdf0e10cSrcweir void ViewShellManager::Implementation::DeactivateViewShell (const ViewShell& rShell)
544cdf0e10cSrcweir {
545cdf0e10cSrcweir ::osl::MutexGuard aGuard (maMutex);
546cdf0e10cSrcweir
547cdf0e10cSrcweir ActiveShellList::iterator iShell (::std::find_if (
548cdf0e10cSrcweir maActiveViewShells.begin(),
549cdf0e10cSrcweir maActiveViewShells.end(),
550cdf0e10cSrcweir IsShell(&rShell)));
551cdf0e10cSrcweir if (iShell != maActiveViewShells.end())
552cdf0e10cSrcweir {
553cdf0e10cSrcweir UpdateLock aLocker (*this);
554cdf0e10cSrcweir
555cdf0e10cSrcweir ShellDescriptor aDescriptor(*iShell);
556cdf0e10cSrcweir mrBase.GetDocShell()->Disconnect(dynamic_cast<ViewShell*>(aDescriptor.mpShell));
557cdf0e10cSrcweir maActiveViewShells.erase(iShell);
558cdf0e10cSrcweir TakeShellsFromStack(aDescriptor.mpShell);
559cdf0e10cSrcweir
560cdf0e10cSrcweir // Deactivate sub shells.
561cdf0e10cSrcweir SubShellList::iterator iList (maActiveSubShells.find(&rShell));
562cdf0e10cSrcweir if (iList != maActiveSubShells.end())
563cdf0e10cSrcweir {
564cdf0e10cSrcweir SubShellSubList& rList (iList->second);
565cdf0e10cSrcweir while ( ! rList.empty())
566cdf0e10cSrcweir DeactivateSubShell(rShell, rList.front().mnId);
567cdf0e10cSrcweir }
568cdf0e10cSrcweir
569cdf0e10cSrcweir DestroyViewShell(aDescriptor);
570cdf0e10cSrcweir }
571cdf0e10cSrcweir }
572cdf0e10cSrcweir
573cdf0e10cSrcweir
574cdf0e10cSrcweir
575cdf0e10cSrcweir
ActivateShell(SfxShell & rShell)576cdf0e10cSrcweir void ViewShellManager::Implementation::ActivateShell (SfxShell& rShell)
577cdf0e10cSrcweir {
578cdf0e10cSrcweir ::osl::MutexGuard aGuard (maMutex);
579cdf0e10cSrcweir
580cdf0e10cSrcweir // Create a new shell or recycle on in the cache.
581cdf0e10cSrcweir ShellDescriptor aDescriptor;
582cdf0e10cSrcweir aDescriptor.mpShell = &rShell;
583cdf0e10cSrcweir
584cdf0e10cSrcweir ActivateShell(aDescriptor);
585cdf0e10cSrcweir }
586cdf0e10cSrcweir
587cdf0e10cSrcweir
588cdf0e10cSrcweir
589cdf0e10cSrcweir
ActivateShell(const ShellDescriptor & rDescriptor)590cdf0e10cSrcweir void ViewShellManager::Implementation::ActivateShell (const ShellDescriptor& rDescriptor)
591cdf0e10cSrcweir {
592cdf0e10cSrcweir // Put shell on top of the active view shells.
593cdf0e10cSrcweir if (rDescriptor.mpShell != NULL)
594cdf0e10cSrcweir {
595cdf0e10cSrcweir // Determine where to put the view shell on the stack. By default
596cdf0e10cSrcweir // it is put on top of the stack. When the view shell of the center
597cdf0e10cSrcweir // pane is to be kept top most and the new view shell is not
598cdf0e10cSrcweir // displayed in the center pane then it is inserted at the position
599cdf0e10cSrcweir // one below the top.
600cdf0e10cSrcweir ActiveShellList::iterator iInsertPosition (maActiveViewShells.begin());
601cdf0e10cSrcweir if (iInsertPosition != maActiveViewShells.end()
602cdf0e10cSrcweir && mbKeepMainViewShellOnTop
603cdf0e10cSrcweir && ! rDescriptor.IsMainViewShell()
604cdf0e10cSrcweir && iInsertPosition->IsMainViewShell())
605cdf0e10cSrcweir {
606cdf0e10cSrcweir ++iInsertPosition;
607cdf0e10cSrcweir }
608cdf0e10cSrcweir maActiveViewShells.insert(
609cdf0e10cSrcweir iInsertPosition,
610cdf0e10cSrcweir rDescriptor);
611cdf0e10cSrcweir }
612cdf0e10cSrcweir }
613cdf0e10cSrcweir
614cdf0e10cSrcweir
615cdf0e10cSrcweir
616cdf0e10cSrcweir
DeactivateShell(const SfxShell & rShell)617cdf0e10cSrcweir void ViewShellManager::Implementation::DeactivateShell (const SfxShell& rShell)
618cdf0e10cSrcweir {
619cdf0e10cSrcweir ::osl::MutexGuard aGuard (maMutex);
620cdf0e10cSrcweir
621cdf0e10cSrcweir ActiveShellList::iterator iShell (::std::find_if (
622cdf0e10cSrcweir maActiveViewShells.begin(),
623cdf0e10cSrcweir maActiveViewShells.end(),
624cdf0e10cSrcweir IsShell(&rShell)));
625cdf0e10cSrcweir if (iShell != maActiveViewShells.end())
626cdf0e10cSrcweir {
627cdf0e10cSrcweir UpdateLock aLocker (*this);
628cdf0e10cSrcweir
629cdf0e10cSrcweir ShellDescriptor aDescriptor(*iShell);
630cdf0e10cSrcweir mrBase.GetDocShell()->Disconnect(dynamic_cast<ViewShell*>(aDescriptor.mpShell));
631cdf0e10cSrcweir maActiveViewShells.erase(iShell);
632cdf0e10cSrcweir TakeShellsFromStack(aDescriptor.mpShell);
633cdf0e10cSrcweir
634cdf0e10cSrcweir // Deactivate sub shells.
635cdf0e10cSrcweir SubShellList::iterator iList (maActiveSubShells.find(&rShell));
636cdf0e10cSrcweir if (iList != maActiveSubShells.end())
637cdf0e10cSrcweir {
638cdf0e10cSrcweir SubShellSubList& rList (iList->second);
639cdf0e10cSrcweir while ( ! rList.empty())
640cdf0e10cSrcweir DeactivateSubShell(rShell, rList.front().mnId);
641cdf0e10cSrcweir }
642cdf0e10cSrcweir
643cdf0e10cSrcweir DestroyViewShell(aDescriptor);
644cdf0e10cSrcweir }
645cdf0e10cSrcweir }
646cdf0e10cSrcweir
647cdf0e10cSrcweir
648cdf0e10cSrcweir
649cdf0e10cSrcweir
ActivateSubShell(const SfxShell & rParentShell,ShellId nId)650cdf0e10cSrcweir void ViewShellManager::Implementation::ActivateSubShell (
651cdf0e10cSrcweir const SfxShell& rParentShell,
652cdf0e10cSrcweir ShellId nId)
653cdf0e10cSrcweir {
654cdf0e10cSrcweir ::osl::MutexGuard aGuard (maMutex);
655cdf0e10cSrcweir
656cdf0e10cSrcweir do
657cdf0e10cSrcweir {
658cdf0e10cSrcweir // Check that the given view shell is active.
659cdf0e10cSrcweir ActiveShellList::iterator iShell (::std::find_if (
660cdf0e10cSrcweir maActiveViewShells.begin(),
661cdf0e10cSrcweir maActiveViewShells.end(),
662cdf0e10cSrcweir IsShell(&rParentShell)));
663cdf0e10cSrcweir if (iShell == maActiveViewShells.end())
664cdf0e10cSrcweir break;
665cdf0e10cSrcweir
666cdf0e10cSrcweir // Create the sub shell list if it does not yet exist.
667cdf0e10cSrcweir SubShellList::iterator iList (maActiveSubShells.find(&rParentShell));
668cdf0e10cSrcweir if (iList == maActiveSubShells.end())
669cdf0e10cSrcweir iList = maActiveSubShells.insert(
670cdf0e10cSrcweir SubShellList::value_type(&rParentShell,SubShellSubList())).first;
671cdf0e10cSrcweir
672cdf0e10cSrcweir // Do not activate an object bar that is already active. Requesting
673cdf0e10cSrcweir // this is not exactly an error but may be an indication of one.
674cdf0e10cSrcweir SubShellSubList& rList (iList->second);
675cdf0e10cSrcweir if (::std::find_if(rList.begin(),rList.end(), IsId(nId)) != rList.end())
676cdf0e10cSrcweir break;
677cdf0e10cSrcweir
678cdf0e10cSrcweir // Add just the id of the sub shell. The actual shell is created
679cdf0e10cSrcweir // later in CreateShells().
680cdf0e10cSrcweir UpdateLock aLock (*this);
681cdf0e10cSrcweir rList.push_back(ShellDescriptor(NULL, nId));
682cdf0e10cSrcweir }
683cdf0e10cSrcweir while (false);
684cdf0e10cSrcweir }
685cdf0e10cSrcweir
686cdf0e10cSrcweir
687cdf0e10cSrcweir
688cdf0e10cSrcweir
DeactivateSubShell(const SfxShell & rParentShell,ShellId nId)689cdf0e10cSrcweir void ViewShellManager::Implementation::DeactivateSubShell (
690cdf0e10cSrcweir const SfxShell& rParentShell,
691cdf0e10cSrcweir ShellId nId)
692cdf0e10cSrcweir {
693cdf0e10cSrcweir ::osl::MutexGuard aGuard (maMutex);
694cdf0e10cSrcweir
695cdf0e10cSrcweir do
696cdf0e10cSrcweir {
697cdf0e10cSrcweir // Check that the given view shell is active.
698cdf0e10cSrcweir SubShellList::iterator iList (maActiveSubShells.find(&rParentShell));
699cdf0e10cSrcweir if (iList == maActiveSubShells.end())
700cdf0e10cSrcweir break;
701cdf0e10cSrcweir
702cdf0e10cSrcweir // Look up the sub shell.
703cdf0e10cSrcweir SubShellSubList& rList (iList->second);
704cdf0e10cSrcweir SubShellSubList::iterator iShell (
705cdf0e10cSrcweir ::std::find_if(rList.begin(),rList.end(), IsId(nId)));
706cdf0e10cSrcweir if (iShell == rList.end())
707cdf0e10cSrcweir break;
708cdf0e10cSrcweir SfxShell* pShell = iShell->mpShell;
709cdf0e10cSrcweir if (pShell == NULL)
710cdf0e10cSrcweir break;
711cdf0e10cSrcweir
712cdf0e10cSrcweir UpdateLock aLock (*this);
713cdf0e10cSrcweir
714cdf0e10cSrcweir ShellDescriptor aDescriptor(*iShell);
715cdf0e10cSrcweir // Remove the sub shell from both the internal structure as well as the
716cdf0e10cSrcweir // SFX shell stack above and including the sub shell.
717cdf0e10cSrcweir rList.erase(iShell);
718cdf0e10cSrcweir TakeShellsFromStack(pShell);
719cdf0e10cSrcweir
720cdf0e10cSrcweir DestroySubShell(rParentShell, aDescriptor);
721cdf0e10cSrcweir }
722cdf0e10cSrcweir while (false);
723cdf0e10cSrcweir }
724cdf0e10cSrcweir
725cdf0e10cSrcweir
726cdf0e10cSrcweir
727cdf0e10cSrcweir
MoveSubShellToTop(const SfxShell & rParentShell,ShellId nId)728cdf0e10cSrcweir void ViewShellManager::Implementation::MoveSubShellToTop (
729cdf0e10cSrcweir const SfxShell& rParentShell,
730cdf0e10cSrcweir ShellId nId)
731cdf0e10cSrcweir {
732cdf0e10cSrcweir SubShellList::iterator iList (maActiveSubShells.find(&rParentShell));
733cdf0e10cSrcweir if (iList != maActiveSubShells.end())
734cdf0e10cSrcweir {
735cdf0e10cSrcweir // Look up the sub shell.
736cdf0e10cSrcweir SubShellSubList& rList (iList->second);
737cdf0e10cSrcweir SubShellSubList::iterator iShell (
738cdf0e10cSrcweir ::std::find_if(rList.begin(),rList.end(), IsId(nId)));
739cdf0e10cSrcweir if (iShell!=rList.end() && iShell!=rList.begin())
740cdf0e10cSrcweir {
741cdf0e10cSrcweir SubShellSubList::value_type aEntry (*iShell);
742cdf0e10cSrcweir rList.erase(iShell);
743cdf0e10cSrcweir rList.push_front(aEntry);
744cdf0e10cSrcweir }
745cdf0e10cSrcweir }
746cdf0e10cSrcweir else
747cdf0e10cSrcweir {
748cdf0e10cSrcweir // Ignore this call when there are no sub shells for the given
749cdf0e10cSrcweir // parent shell. We could remember the sub shell to move to the top
750cdf0e10cSrcweir // but we do not. Do call this method at a later time instead.
751cdf0e10cSrcweir }
752cdf0e10cSrcweir }
753cdf0e10cSrcweir
754cdf0e10cSrcweir
755cdf0e10cSrcweir
MoveToTop(const SfxShell & rShell)756cdf0e10cSrcweir void ViewShellManager::Implementation::MoveToTop (const SfxShell& rShell)
757cdf0e10cSrcweir {
758cdf0e10cSrcweir ::osl::MutexGuard aGuard (maMutex);
759cdf0e10cSrcweir
760cdf0e10cSrcweir // Check that we have access to a dispatcher. If not, then we are
761cdf0e10cSrcweir // (probably) called while the view shell is still being created or
762cdf0e10cSrcweir // initialized. Without dispatcher we can not rebuild the shell stack
763cdf0e10cSrcweir // to move the requested shell to the top. So return right away instead
764cdf0e10cSrcweir // of making a mess without being able to clean up afterwards.
765cdf0e10cSrcweir if (mrBase.GetDispatcher() == NULL)
766cdf0e10cSrcweir return;
767cdf0e10cSrcweir
768cdf0e10cSrcweir ActiveShellList::iterator iShell (::std::find_if (
769cdf0e10cSrcweir maActiveViewShells.begin(),
770cdf0e10cSrcweir maActiveViewShells.end(),
771cdf0e10cSrcweir IsShell(&rShell)));
772cdf0e10cSrcweir bool bMove = true;
773cdf0e10cSrcweir if (iShell != maActiveViewShells.end())
774cdf0e10cSrcweir {
775cdf0e10cSrcweir // Is the shell already at the top of the stack? We have to keep
776cdf0e10cSrcweir // the case in mind that mbKeepMainViewShellOnTop is true. Shells
777cdf0e10cSrcweir // that are not the main view shell are placed on the second-to-top
778cdf0e10cSrcweir // position in this case.
779cdf0e10cSrcweir if (iShell == maActiveViewShells.begin()
780cdf0e10cSrcweir && (iShell->IsMainViewShell() || ! mbKeepMainViewShellOnTop))
781cdf0e10cSrcweir {
782cdf0e10cSrcweir // The shell is at the top position and is either a) the main
783cdf0e10cSrcweir // view shell or b) another shell but the main view shell is not
784cdf0e10cSrcweir // kept at the top position. We do not have to move the shell.
785cdf0e10cSrcweir bMove = false;
786cdf0e10cSrcweir }
787cdf0e10cSrcweir else if (iShell == ++maActiveViewShells.begin()
788cdf0e10cSrcweir && ! iShell->IsMainViewShell()
789cdf0e10cSrcweir && mbKeepMainViewShellOnTop)
790cdf0e10cSrcweir {
791cdf0e10cSrcweir // The shell is a the second-to-top position, not the main view
792cdf0e10cSrcweir // shell and the main view shell is kept at the top position.
793cdf0e10cSrcweir // Therefore we do not have to move the shell.
794cdf0e10cSrcweir bMove = false;
795cdf0e10cSrcweir }
796cdf0e10cSrcweir }
797cdf0e10cSrcweir else
798cdf0e10cSrcweir {
799cdf0e10cSrcweir // The shell is not on the stack. Therefore it can not be moved.
800cdf0e10cSrcweir // We could insert it but we don't. Use ActivateViewShell() for
801cdf0e10cSrcweir // that.
802cdf0e10cSrcweir bMove = false;
803cdf0e10cSrcweir }
804cdf0e10cSrcweir
805cdf0e10cSrcweir // When the shell is not at the right position it is removed from the
806cdf0e10cSrcweir // internal list of shells and inserted at the correct position.
807cdf0e10cSrcweir if (bMove)
808cdf0e10cSrcweir {
809cdf0e10cSrcweir UpdateLock aLock (*this);
810cdf0e10cSrcweir
811cdf0e10cSrcweir ShellDescriptor aDescriptor(*iShell);
812cdf0e10cSrcweir
813cdf0e10cSrcweir TakeShellsFromStack(&rShell);
814cdf0e10cSrcweir maActiveViewShells.erase(iShell);
815cdf0e10cSrcweir
816cdf0e10cSrcweir // Find out whether to insert at the top or one below.
817cdf0e10cSrcweir ActiveShellList::iterator aInsertPosition (maActiveViewShells.begin());
818cdf0e10cSrcweir if (mbKeepMainViewShellOnTop && ! aDescriptor.IsMainViewShell())
819cdf0e10cSrcweir {
820cdf0e10cSrcweir if (maActiveViewShells.back().IsMainViewShell())
821cdf0e10cSrcweir aInsertPosition++;
822cdf0e10cSrcweir }
823cdf0e10cSrcweir
824cdf0e10cSrcweir maActiveViewShells.insert(aInsertPosition, aDescriptor);
825cdf0e10cSrcweir }
826cdf0e10cSrcweir }
827cdf0e10cSrcweir
828cdf0e10cSrcweir
829cdf0e10cSrcweir
830cdf0e10cSrcweir
GetShell(ShellId nId) const831cdf0e10cSrcweir SfxShell* ViewShellManager::Implementation::GetShell (ShellId nId) const
832cdf0e10cSrcweir {
833cdf0e10cSrcweir ::osl::MutexGuard aGuard (maMutex);
834cdf0e10cSrcweir
835cdf0e10cSrcweir SfxShell* pShell = NULL;
836cdf0e10cSrcweir
837cdf0e10cSrcweir // First search the active view shells.
838cdf0e10cSrcweir ActiveShellList::const_iterator iShell (
839cdf0e10cSrcweir ::std::find_if (
840cdf0e10cSrcweir maActiveViewShells.begin(),
841cdf0e10cSrcweir maActiveViewShells.end(),
842cdf0e10cSrcweir IsId(nId)));
843cdf0e10cSrcweir if (iShell != maActiveViewShells.end())
844cdf0e10cSrcweir pShell = iShell->mpShell;
845cdf0e10cSrcweir else
846cdf0e10cSrcweir {
847cdf0e10cSrcweir // Now search the active sub shells of every active view shell.
848cdf0e10cSrcweir SubShellList::const_iterator iList;
849cdf0e10cSrcweir for (iList=maActiveSubShells.begin(); iList!=maActiveSubShells.end(); ++iList)
850cdf0e10cSrcweir {
851cdf0e10cSrcweir const SubShellSubList& rList (iList->second);
852cdf0e10cSrcweir SubShellSubList::const_iterator iSubShell(
853cdf0e10cSrcweir ::std::find_if(rList.begin(),rList.end(), IsId(nId)));
854cdf0e10cSrcweir if (iSubShell != rList.end())
855cdf0e10cSrcweir {
856cdf0e10cSrcweir pShell = iSubShell->mpShell;
857cdf0e10cSrcweir break;
858cdf0e10cSrcweir }
859cdf0e10cSrcweir }
860cdf0e10cSrcweir }
861cdf0e10cSrcweir
862cdf0e10cSrcweir return pShell;
863cdf0e10cSrcweir }
864cdf0e10cSrcweir
865cdf0e10cSrcweir
866cdf0e10cSrcweir
867cdf0e10cSrcweir
GetTopShell(void) const868cdf0e10cSrcweir SfxShell* ViewShellManager::Implementation::GetTopShell (void) const
869cdf0e10cSrcweir {
870cdf0e10cSrcweir OSL_ASSERT(mpTopShell == mrBase.GetSubShell(0));
871cdf0e10cSrcweir return mpTopShell;
872cdf0e10cSrcweir }
873cdf0e10cSrcweir
874cdf0e10cSrcweir
875cdf0e10cSrcweir
876cdf0e10cSrcweir
LockUpdate(void)877cdf0e10cSrcweir void ViewShellManager::Implementation::LockUpdate (void)
878cdf0e10cSrcweir {
879cdf0e10cSrcweir mnUpdateLockCount++;
880cdf0e10cSrcweir }
881cdf0e10cSrcweir
882cdf0e10cSrcweir
883cdf0e10cSrcweir
884cdf0e10cSrcweir
UnlockUpdate(void)885cdf0e10cSrcweir void ViewShellManager::Implementation::UnlockUpdate (void)
886cdf0e10cSrcweir {
887cdf0e10cSrcweir ::osl::MutexGuard aGuard (maMutex);
888cdf0e10cSrcweir
889cdf0e10cSrcweir mnUpdateLockCount--;
890cdf0e10cSrcweir if (mnUpdateLockCount < 0)
891cdf0e10cSrcweir {
892cdf0e10cSrcweir // This should not happen.
893cdf0e10cSrcweir OSL_ASSERT (mnUpdateLockCount>=0);
894cdf0e10cSrcweir mnUpdateLockCount = 0;
895cdf0e10cSrcweir }
896cdf0e10cSrcweir if (mnUpdateLockCount == 0)
897cdf0e10cSrcweir UpdateShellStack();
898cdf0e10cSrcweir }
899cdf0e10cSrcweir
900cdf0e10cSrcweir
901cdf0e10cSrcweir
902cdf0e10cSrcweir
903cdf0e10cSrcweir /** Update the SFX shell stack (the portion that is visible to us) so that
904cdf0e10cSrcweir it matches the internal shell stack. This is done in six steps:
905cdf0e10cSrcweir 1. Create the missing view shells and sub shells.
906cdf0e10cSrcweir 2. Set up the internal shell stack.
907cdf0e10cSrcweir 3. Get the SFX shell stack.
908cdf0e10cSrcweir 4. Find the lowest shell in which the two stacks differ.
909cdf0e10cSrcweir 5. Remove all shells above and including that shell from the SFX stack.
910cdf0e10cSrcweir 6. Push all shells of the internal stack on the SFX shell stack that are
911cdf0e10cSrcweir not already present on the later.
912cdf0e10cSrcweir */
UpdateShellStack(void)913cdf0e10cSrcweir void ViewShellManager::Implementation::UpdateShellStack (void)
914cdf0e10cSrcweir {
915cdf0e10cSrcweir ::osl::MutexGuard aGuard (maMutex);
916cdf0e10cSrcweir
917cdf0e10cSrcweir // Remember the undo manager from the top-most shell on the stack.
918cdf0e10cSrcweir SfxShell* pTopMostShell = mrBase.GetSubShell(0);
919cdf0e10cSrcweir ::svl::IUndoManager* pUndoManager = (pTopMostShell!=NULL)
920cdf0e10cSrcweir ? pTopMostShell->GetUndoManager()
921cdf0e10cSrcweir : NULL;
922cdf0e10cSrcweir
923cdf0e10cSrcweir // 1. Create the missing shells.
924cdf0e10cSrcweir CreateShells();
925cdf0e10cSrcweir
926cdf0e10cSrcweir
927cdf0e10cSrcweir // 2. Create the internal target stack.
928cdf0e10cSrcweir ShellStack aTargetStack;
929cdf0e10cSrcweir CreateTargetStack(aTargetStack);
930cdf0e10cSrcweir
931cdf0e10cSrcweir
932cdf0e10cSrcweir // 3. Get SFX shell stack.
933cdf0e10cSrcweir ShellStack aSfxShellStack;
934cdf0e10cSrcweir sal_uInt16 nIndex (0);
935cdf0e10cSrcweir while (mrBase.GetSubShell(nIndex)!=NULL)
936cdf0e10cSrcweir ++nIndex;
937cdf0e10cSrcweir aSfxShellStack.reserve(nIndex);
938cdf0e10cSrcweir while (nIndex-- > 0)
939cdf0e10cSrcweir aSfxShellStack.push_back(mrBase.GetSubShell(nIndex));
940cdf0e10cSrcweir
941cdf0e10cSrcweir
942cdf0e10cSrcweir #ifdef VERBOSE
943cdf0e10cSrcweir OSL_TRACE("Current SFX Stack\r");
944cdf0e10cSrcweir DumpShellStack(aSfxShellStack);
945cdf0e10cSrcweir OSL_TRACE("Target Stack\r");
946cdf0e10cSrcweir DumpShellStack(aTargetStack);
947cdf0e10cSrcweir #endif
948cdf0e10cSrcweir
949cdf0e10cSrcweir
950cdf0e10cSrcweir // 4. Find the lowest shell in which the two stacks differ.
951cdf0e10cSrcweir ShellStack::const_iterator iSfxShell (aSfxShellStack.begin());
952cdf0e10cSrcweir ShellStack::iterator iTargetShell (aTargetStack.begin());
953cdf0e10cSrcweir while (iSfxShell != aSfxShellStack.end()
954cdf0e10cSrcweir && iTargetShell!=aTargetStack.end()
955cdf0e10cSrcweir && (*iSfxShell)==(*iTargetShell))
956cdf0e10cSrcweir {
957cdf0e10cSrcweir ++iSfxShell;
958cdf0e10cSrcweir ++iTargetShell;
959cdf0e10cSrcweir }
960cdf0e10cSrcweir
961cdf0e10cSrcweir
962cdf0e10cSrcweir // 5. Remove all shells above and including the differing shell from the
963cdf0e10cSrcweir // SFX stack starting with the shell on top of the stack.
964cdf0e10cSrcweir while (iSfxShell != aSfxShellStack.end())
965cdf0e10cSrcweir {
966cdf0e10cSrcweir SfxShell* pShell = aSfxShellStack.back();
967cdf0e10cSrcweir aSfxShellStack.pop_back();
968cdf0e10cSrcweir #ifdef VERBOSE
969cdf0e10cSrcweir OSL_TRACE("removing shell %p from stack\r", pShell);
970cdf0e10cSrcweir #endif
971cdf0e10cSrcweir mrBase.RemoveSubShell(pShell);
972cdf0e10cSrcweir }
973cdf0e10cSrcweir
974cdf0e10cSrcweir
975cdf0e10cSrcweir // 6. Push shells from the given stack onto the SFX stack.
976cdf0e10cSrcweir mbShellStackIsUpToDate = false;
977cdf0e10cSrcweir while (iTargetShell != aTargetStack.end())
978cdf0e10cSrcweir {
979cdf0e10cSrcweir #ifdef VERBOSE
980cdf0e10cSrcweir OSL_TRACE("pushing shell %p on stack\r", *iTargetShell);
981cdf0e10cSrcweir #endif
982cdf0e10cSrcweir mrBase.AddSubShell(**iTargetShell);
983cdf0e10cSrcweir ++iTargetShell;
984cdf0e10cSrcweir
985cdf0e10cSrcweir // The pushing of the shell on to the shell stack may have lead to
986cdf0e10cSrcweir // another invocation of this method. In this case we have to abort
987cdf0e10cSrcweir // pushing shells on the stack and return immediately.
988cdf0e10cSrcweir if (mbShellStackIsUpToDate)
989cdf0e10cSrcweir break;
990cdf0e10cSrcweir }
991cdf0e10cSrcweir if (mrBase.GetDispatcher() != NULL)
992cdf0e10cSrcweir mrBase.GetDispatcher()->Flush();
993cdf0e10cSrcweir
994cdf0e10cSrcweir // Update the pointer to the top-most shell and set its undo manager
995cdf0e10cSrcweir // to the one of the previous top-most shell.
996cdf0e10cSrcweir mpTopShell = mrBase.GetSubShell(0);
997cdf0e10cSrcweir if (mpTopShell!=NULL && pUndoManager!=NULL && mpTopShell->GetUndoManager()==NULL)
998cdf0e10cSrcweir mpTopShell->SetUndoManager(pUndoManager);
999cdf0e10cSrcweir
1000cdf0e10cSrcweir // Finally tell an invocation of this method on a higher level that it can (has
1001cdf0e10cSrcweir // to) abort and return immediately.
1002cdf0e10cSrcweir mbShellStackIsUpToDate = true;
1003cdf0e10cSrcweir
1004cdf0e10cSrcweir #ifdef VERBOSE
1005cdf0e10cSrcweir OSL_TRACE("New current stack\r");
1006cdf0e10cSrcweir DumpSfxShellStack();
1007cdf0e10cSrcweir #endif
1008cdf0e10cSrcweir }
1009cdf0e10cSrcweir
1010cdf0e10cSrcweir
1011cdf0e10cSrcweir
1012cdf0e10cSrcweir
TakeShellsFromStack(const SfxShell * pShell)1013cdf0e10cSrcweir void ViewShellManager::Implementation::TakeShellsFromStack (const SfxShell* pShell)
1014cdf0e10cSrcweir {
1015cdf0e10cSrcweir ::osl::MutexGuard aGuard (maMutex);
1016cdf0e10cSrcweir
1017cdf0e10cSrcweir // Remember the undo manager from the top-most shell on the stack.
1018cdf0e10cSrcweir SfxShell* pTopMostShell = mrBase.GetSubShell(0);
1019cdf0e10cSrcweir ::svl::IUndoManager* pUndoManager = (pTopMostShell!=NULL)
1020cdf0e10cSrcweir ? pTopMostShell->GetUndoManager()
1021cdf0e10cSrcweir : NULL;
1022cdf0e10cSrcweir
1023cdf0e10cSrcweir #ifdef VERBOSE
1024cdf0e10cSrcweir OSL_TRACE("TakeShellsFromStack(%p)\r", pShell);
1025cdf0e10cSrcweir DumpSfxShellStack();
1026cdf0e10cSrcweir #endif
1027cdf0e10cSrcweir
1028cdf0e10cSrcweir // 0.Make sure that the given shell is on the stack. This is a
1029cdf0e10cSrcweir // preparation for the following assertion.
1030cdf0e10cSrcweir for (sal_uInt16 nIndex=0; true; nIndex++)
1031cdf0e10cSrcweir {
1032cdf0e10cSrcweir SfxShell* pShellOnStack = mrBase.GetSubShell(nIndex);
1033cdf0e10cSrcweir if (pShellOnStack == NULL)
1034cdf0e10cSrcweir {
1035cdf0e10cSrcweir // Set pShell to NULL to indicate the following code that the
1036cdf0e10cSrcweir // shell is not on the stack.
1037cdf0e10cSrcweir pShell = NULL;
1038cdf0e10cSrcweir break;
1039cdf0e10cSrcweir }
1040cdf0e10cSrcweir else if (pShellOnStack == pShell)
1041cdf0e10cSrcweir break;
1042cdf0e10cSrcweir }
1043cdf0e10cSrcweir
1044cdf0e10cSrcweir if (pShell != NULL)
1045cdf0e10cSrcweir {
1046cdf0e10cSrcweir // 1. Deactivate our shells on the stack before they are removed so
1047cdf0e10cSrcweir // that during the Deactivation() calls the stack is still intact.
1048cdf0e10cSrcweir for (sal_uInt16 nIndex=0; true; nIndex++)
1049cdf0e10cSrcweir {
1050cdf0e10cSrcweir SfxShell* pShellOnStack = mrBase.GetSubShell(nIndex);
1051cdf0e10cSrcweir Deactivate(pShellOnStack);
1052cdf0e10cSrcweir if (pShellOnStack == pShell)
1053cdf0e10cSrcweir break;
1054cdf0e10cSrcweir }
1055cdf0e10cSrcweir
1056cdf0e10cSrcweir // 2. Remove the shells from the stack.
1057cdf0e10cSrcweir while (true)
1058cdf0e10cSrcweir {
1059cdf0e10cSrcweir SfxShell* pShellOnStack = mrBase.GetSubShell(0);
1060cdf0e10cSrcweir #ifdef VERBOSE
1061cdf0e10cSrcweir OSL_TRACE("removing shell %p from stack\r", pShellOnStack);
1062cdf0e10cSrcweir #endif
1063cdf0e10cSrcweir mrBase.RemoveSubShell(pShellOnStack);
1064cdf0e10cSrcweir if (pShellOnStack == pShell)
1065cdf0e10cSrcweir break;
1066cdf0e10cSrcweir }
1067cdf0e10cSrcweir
1068cdf0e10cSrcweir // 3. Update the stack.
1069cdf0e10cSrcweir if (mrBase.GetDispatcher() != NULL)
1070cdf0e10cSrcweir mrBase.GetDispatcher()->Flush();
1071cdf0e10cSrcweir
1072cdf0e10cSrcweir // Update the pointer to the top-most shell and set its undo manager
1073cdf0e10cSrcweir // to the one of the previous top-most shell.
1074cdf0e10cSrcweir mpTopShell = mrBase.GetSubShell(0);
1075cdf0e10cSrcweir if (mpTopShell!=NULL && pUndoManager!=NULL && mpTopShell->GetUndoManager()==NULL)
1076cdf0e10cSrcweir mpTopShell->SetUndoManager(pUndoManager);
1077cdf0e10cSrcweir }
1078cdf0e10cSrcweir
1079cdf0e10cSrcweir #ifdef VERBOSE
1080cdf0e10cSrcweir OSL_TRACE("Sfx shell stack is:\r");
1081cdf0e10cSrcweir DumpSfxShellStack();
1082cdf0e10cSrcweir #endif
1083cdf0e10cSrcweir }
1084cdf0e10cSrcweir
1085cdf0e10cSrcweir
1086cdf0e10cSrcweir
1087cdf0e10cSrcweir
CreateShells(void)1088cdf0e10cSrcweir void ViewShellManager::Implementation::CreateShells (void)
1089cdf0e10cSrcweir {
1090cdf0e10cSrcweir ::osl::MutexGuard aGuard (maMutex);
1091cdf0e10cSrcweir
1092cdf0e10cSrcweir // Iterate over all view shells.
1093cdf0e10cSrcweir ShellStack aShellStack;
1094cdf0e10cSrcweir ActiveShellList::reverse_iterator iShell;
1095cdf0e10cSrcweir for (iShell=maActiveViewShells.rbegin(); iShell!=maActiveViewShells.rend(); ++iShell)
1096cdf0e10cSrcweir {
1097cdf0e10cSrcweir // Get the list of associated sub shells.
1098cdf0e10cSrcweir SubShellList::iterator iList (maActiveSubShells.find(iShell->mpShell));
1099cdf0e10cSrcweir if (iList != maActiveSubShells.end())
1100cdf0e10cSrcweir {
1101cdf0e10cSrcweir SubShellSubList& rList (iList->second);
1102cdf0e10cSrcweir
1103cdf0e10cSrcweir // Iterate over all sub shells of the current view shell.
1104cdf0e10cSrcweir SubShellSubList::iterator iSubShell;
1105cdf0e10cSrcweir for (iSubShell=rList.begin(); iSubShell!=rList.end(); ++iSubShell)
1106cdf0e10cSrcweir {
1107cdf0e10cSrcweir if (iSubShell->mpShell == NULL)
1108cdf0e10cSrcweir {
1109cdf0e10cSrcweir *iSubShell = CreateSubShell(iShell->mpShell,iSubShell->mnId,NULL,NULL);
1110cdf0e10cSrcweir }
1111cdf0e10cSrcweir }
1112cdf0e10cSrcweir }
1113cdf0e10cSrcweir }
1114cdf0e10cSrcweir }
1115cdf0e10cSrcweir
1116cdf0e10cSrcweir
1117cdf0e10cSrcweir
1118cdf0e10cSrcweir
CreateTargetStack(ShellStack & rStack) const1119cdf0e10cSrcweir void ViewShellManager::Implementation::CreateTargetStack (ShellStack& rStack) const
1120cdf0e10cSrcweir {
1121cdf0e10cSrcweir // Create a local stack of the shells that are to push on the shell
1122cdf0e10cSrcweir // stack. We can thus safly create the required shells wile still
1123cdf0e10cSrcweir // having a valid shell stack.
1124cdf0e10cSrcweir for (ActiveShellList::const_reverse_iterator iViewShell (maActiveViewShells.rbegin());
1125cdf0e10cSrcweir iViewShell != maActiveViewShells.rend();
1126cdf0e10cSrcweir ++iViewShell)
1127cdf0e10cSrcweir {
1128cdf0e10cSrcweir // Possibly place the form shell below the current view shell.
1129cdf0e10cSrcweir if ( ! mbFormShellAboveParent
1130cdf0e10cSrcweir && mpFormShell!=NULL
1131cdf0e10cSrcweir && iViewShell->mpShell==mpFormShellParent)
1132cdf0e10cSrcweir {
1133cdf0e10cSrcweir rStack.push_back(mpFormShell);
1134cdf0e10cSrcweir }
1135cdf0e10cSrcweir
1136cdf0e10cSrcweir // Put the view shell itself on the local stack.
1137cdf0e10cSrcweir rStack.push_back (iViewShell->mpShell);
1138cdf0e10cSrcweir
1139cdf0e10cSrcweir // Possibly place the form shell above the current view shell.
1140cdf0e10cSrcweir if (mbFormShellAboveParent
1141cdf0e10cSrcweir && mpFormShell!=NULL
1142cdf0e10cSrcweir && iViewShell->mpShell==mpFormShellParent)
1143cdf0e10cSrcweir {
1144cdf0e10cSrcweir rStack.push_back(mpFormShell);
1145cdf0e10cSrcweir }
1146cdf0e10cSrcweir
1147cdf0e10cSrcweir // Add all other sub shells.
1148cdf0e10cSrcweir SubShellList::const_iterator iList (maActiveSubShells.find(iViewShell->mpShell));
1149cdf0e10cSrcweir if (iList != maActiveSubShells.end())
1150cdf0e10cSrcweir {
1151cdf0e10cSrcweir const SubShellSubList& rList (iList->second);
1152cdf0e10cSrcweir SubShellSubList::const_reverse_iterator iSubShell;
1153cdf0e10cSrcweir for (iSubShell=rList.rbegin(); iSubShell!=rList.rend(); ++iSubShell)
1154cdf0e10cSrcweir if (iSubShell->mpShell != mpFormShell)
1155cdf0e10cSrcweir rStack.push_back(iSubShell->mpShell);
1156cdf0e10cSrcweir }
1157cdf0e10cSrcweir }
1158cdf0e10cSrcweir }
1159cdf0e10cSrcweir
1160cdf0e10cSrcweir
1161cdf0e10cSrcweir
1162cdf0e10cSrcweir
IMPL_LINK(ViewShellManager::Implementation,WindowEventHandler,VclWindowEvent *,pEvent)1163cdf0e10cSrcweir IMPL_LINK(ViewShellManager::Implementation, WindowEventHandler, VclWindowEvent*, pEvent)
1164cdf0e10cSrcweir {
1165cdf0e10cSrcweir if (pEvent != NULL)
1166cdf0e10cSrcweir {
1167cdf0e10cSrcweir ::Window* pEventWindow
1168cdf0e10cSrcweir = static_cast<VclWindowEvent*>(pEvent)->GetWindow();
1169cdf0e10cSrcweir
1170cdf0e10cSrcweir switch (pEvent->GetId())
1171cdf0e10cSrcweir {
1172cdf0e10cSrcweir case VCLEVENT_WINDOW_GETFOCUS:
1173cdf0e10cSrcweir {
1174cdf0e10cSrcweir for (ActiveShellList::iterator aI(maActiveViewShells.begin());
1175cdf0e10cSrcweir aI!=maActiveViewShells.end();
1176cdf0e10cSrcweir aI++)
1177cdf0e10cSrcweir {
1178cdf0e10cSrcweir if (pEventWindow == static_cast< ::Window*>(aI->GetWindow()))
1179cdf0e10cSrcweir {
1180cdf0e10cSrcweir MoveToTop(*aI->mpShell);
1181cdf0e10cSrcweir break;
1182cdf0e10cSrcweir }
1183cdf0e10cSrcweir }
1184cdf0e10cSrcweir }
1185cdf0e10cSrcweir break;
1186cdf0e10cSrcweir
1187cdf0e10cSrcweir case VCLEVENT_WINDOW_LOSEFOCUS:
1188cdf0e10cSrcweir break;
11897a32b0c8SAndre Fischer
11907a32b0c8SAndre Fischer case VCLEVENT_OBJECT_DYING:
11917a32b0c8SAndre Fischer // Remember that we do not have to remove the window
11927a32b0c8SAndre Fischer // listener for this window.
11937a32b0c8SAndre Fischer for (ActiveShellList::iterator
11947a32b0c8SAndre Fischer iShell(maActiveViewShells.begin()),
11957a32b0c8SAndre Fischer iEnd(maActiveViewShells.end());
11967a32b0c8SAndre Fischer iShell!=iEnd;
11977a32b0c8SAndre Fischer ++iShell)
11987a32b0c8SAndre Fischer {
11997a32b0c8SAndre Fischer if (iShell->GetWindow() == pEventWindow)
12007a32b0c8SAndre Fischer {
12017a32b0c8SAndre Fischer iShell->mbIsListenerAddedToWindow = false;
12027a32b0c8SAndre Fischer break;
12037a32b0c8SAndre Fischer }
12047a32b0c8SAndre Fischer }
12057a32b0c8SAndre Fischer break;
1206cdf0e10cSrcweir }
1207cdf0e10cSrcweir }
1208cdf0e10cSrcweir return sal_True;
1209cdf0e10cSrcweir }
1210cdf0e10cSrcweir
1211cdf0e10cSrcweir
1212cdf0e10cSrcweir
1213cdf0e10cSrcweir
CreateSubShell(SfxShell * pParentShell,ShellId nShellId,::Window * pParentWindow,FrameView * pFrameView)1214cdf0e10cSrcweir ShellDescriptor ViewShellManager::Implementation::CreateSubShell (
1215cdf0e10cSrcweir SfxShell* pParentShell,
1216cdf0e10cSrcweir ShellId nShellId,
1217cdf0e10cSrcweir ::Window* pParentWindow,
1218cdf0e10cSrcweir FrameView* pFrameView)
1219cdf0e10cSrcweir {
1220cdf0e10cSrcweir ::osl::MutexGuard aGuard (maMutex);
1221cdf0e10cSrcweir ShellDescriptor aResult;
1222cdf0e10cSrcweir
1223cdf0e10cSrcweir // Look up the factories for the parent shell.
1224cdf0e10cSrcweir ::std::pair<FactoryList::iterator,FactoryList::iterator> aRange(
1225cdf0e10cSrcweir maShellFactories.equal_range(pParentShell));
1226cdf0e10cSrcweir
1227cdf0e10cSrcweir // Try all factories to create the shell.
1228cdf0e10cSrcweir for (FactoryList::const_iterator iFactory=aRange.first; iFactory!=aRange.second; ++iFactory)
1229cdf0e10cSrcweir {
1230cdf0e10cSrcweir SharedShellFactory pFactory = iFactory->second;
1231*b862c97cSHerbert Dürr if( bool(pFactory))
1232cdf0e10cSrcweir aResult.mpShell = pFactory->CreateShell(nShellId, pParentWindow, pFrameView);
1233cdf0e10cSrcweir
1234cdf0e10cSrcweir // Exit the loop when the shell has been successfully created.
1235cdf0e10cSrcweir if (aResult.mpShell != NULL)
1236cdf0e10cSrcweir {
1237cdf0e10cSrcweir aResult.mpFactory = pFactory;
1238cdf0e10cSrcweir aResult.mnId = nShellId;
1239cdf0e10cSrcweir break;
1240cdf0e10cSrcweir }
1241cdf0e10cSrcweir }
1242cdf0e10cSrcweir
1243cdf0e10cSrcweir return aResult;
1244cdf0e10cSrcweir }
1245cdf0e10cSrcweir
1246cdf0e10cSrcweir
1247cdf0e10cSrcweir
1248cdf0e10cSrcweir
DestroyViewShell(ShellDescriptor & rDescriptor)1249cdf0e10cSrcweir void ViewShellManager::Implementation::DestroyViewShell (
12507a32b0c8SAndre Fischer ShellDescriptor& rDescriptor)
1251cdf0e10cSrcweir {
1252cdf0e10cSrcweir OSL_ASSERT(rDescriptor.mpShell != NULL);
12537a32b0c8SAndre Fischer
12547a32b0c8SAndre Fischer if (rDescriptor.mbIsListenerAddedToWindow)
1255cdf0e10cSrcweir {
12567a32b0c8SAndre Fischer rDescriptor.mbIsListenerAddedToWindow = false;
12577a32b0c8SAndre Fischer ::Window* pWindow = rDescriptor.GetWindow();
12587a32b0c8SAndre Fischer if (pWindow != NULL)
12597a32b0c8SAndre Fischer {
12607a32b0c8SAndre Fischer pWindow->RemoveEventListener(
12617a32b0c8SAndre Fischer LINK(this, ViewShellManager::Implementation, WindowEventHandler));
12627a32b0c8SAndre Fischer }
1263cdf0e10cSrcweir }
1264cdf0e10cSrcweir
1265cdf0e10cSrcweir // Destroy the sub shell factories.
1266cdf0e10cSrcweir ::std::pair<FactoryList::iterator,FactoryList::iterator> aRange(
1267cdf0e10cSrcweir maShellFactories.equal_range(rDescriptor.mpShell));
1268cdf0e10cSrcweir if (aRange.first != maShellFactories.end())
1269cdf0e10cSrcweir maShellFactories.erase(aRange.first, aRange.second);
1270cdf0e10cSrcweir
1271cdf0e10cSrcweir // Release the shell.
1272cdf0e10cSrcweir if (rDescriptor.mpFactory.get() != NULL)
1273cdf0e10cSrcweir rDescriptor.mpFactory->ReleaseShell(rDescriptor.mpShell);
1274cdf0e10cSrcweir }
1275cdf0e10cSrcweir
1276cdf0e10cSrcweir
1277cdf0e10cSrcweir
1278cdf0e10cSrcweir
DestroySubShell(const SfxShell & rParentShell,const ShellDescriptor & rDescriptor)1279cdf0e10cSrcweir void ViewShellManager::Implementation::DestroySubShell (
1280cdf0e10cSrcweir const SfxShell& rParentShell,
1281cdf0e10cSrcweir const ShellDescriptor& rDescriptor)
1282cdf0e10cSrcweir {
1283cdf0e10cSrcweir (void)rParentShell;
1284cdf0e10cSrcweir OSL_ASSERT(rDescriptor.mpFactory.get() != NULL);
1285cdf0e10cSrcweir rDescriptor.mpFactory->ReleaseShell(rDescriptor.mpShell);
1286cdf0e10cSrcweir }
1287cdf0e10cSrcweir
1288cdf0e10cSrcweir
1289cdf0e10cSrcweir
1290cdf0e10cSrcweir
InvalidateAllSubShells(const SfxShell * pParentShell)1291cdf0e10cSrcweir void ViewShellManager::Implementation::InvalidateAllSubShells (const SfxShell* pParentShell)
1292cdf0e10cSrcweir {
1293cdf0e10cSrcweir ::osl::MutexGuard aGuard (maMutex);
1294cdf0e10cSrcweir
1295cdf0e10cSrcweir SubShellList::iterator iList (maActiveSubShells.find(pParentShell));
1296cdf0e10cSrcweir if (iList != maActiveSubShells.end())
1297cdf0e10cSrcweir {
1298cdf0e10cSrcweir SubShellSubList& rList (iList->second);
1299cdf0e10cSrcweir SubShellSubList::iterator iShell;
1300cdf0e10cSrcweir for (iShell=rList.begin(); iShell!=rList.end(); ++iShell)
1301cdf0e10cSrcweir if (iShell->mpShell != NULL)
1302cdf0e10cSrcweir iShell->mpShell->Invalidate();
1303cdf0e10cSrcweir }
1304cdf0e10cSrcweir }
1305cdf0e10cSrcweir
1306cdf0e10cSrcweir
1307cdf0e10cSrcweir
1308cdf0e10cSrcweir
Shutdown(void)1309cdf0e10cSrcweir void ViewShellManager::Implementation::Shutdown (void)
1310cdf0e10cSrcweir {
1311cdf0e10cSrcweir ::osl::MutexGuard aGuard (maMutex);
1312cdf0e10cSrcweir
1313cdf0e10cSrcweir // Take stacked shells from stack.
1314cdf0e10cSrcweir if ( ! maActiveViewShells.empty())
1315cdf0e10cSrcweir {
1316cdf0e10cSrcweir UpdateLock aLock (*this);
1317cdf0e10cSrcweir
1318cdf0e10cSrcweir
1319cdf0e10cSrcweir while ( ! maActiveViewShells.empty())
1320cdf0e10cSrcweir {
1321cdf0e10cSrcweir SfxShell* pShell = maActiveViewShells.front().mpShell;
1322cdf0e10cSrcweir if (pShell != NULL)
1323cdf0e10cSrcweir {
1324cdf0e10cSrcweir ViewShell* pViewShell = dynamic_cast<ViewShell*>(pShell);
1325cdf0e10cSrcweir if (pViewShell != NULL)
1326cdf0e10cSrcweir DeactivateViewShell(*pViewShell);
1327cdf0e10cSrcweir else
1328cdf0e10cSrcweir DeactivateShell(*pShell);
1329cdf0e10cSrcweir }
1330cdf0e10cSrcweir else
1331cdf0e10cSrcweir {
1332cdf0e10cSrcweir DBG_ASSERT(false,
1333cdf0e10cSrcweir "ViewShellManager::Implementation::Shutdown(): empty active shell descriptor");
1334cdf0e10cSrcweir maActiveViewShells.pop_front();
1335cdf0e10cSrcweir }
1336cdf0e10cSrcweir }
1337cdf0e10cSrcweir }
1338cdf0e10cSrcweir mrBase.RemoveSubShell (NULL);
1339cdf0e10cSrcweir
1340cdf0e10cSrcweir maShellFactories.clear();
1341cdf0e10cSrcweir }
1342cdf0e10cSrcweir
1343cdf0e10cSrcweir
1344cdf0e10cSrcweir
1345cdf0e10cSrcweir
1346cdf0e10cSrcweir #ifdef VERBOSE
DumpShellStack(const ShellStack & rStack)1347cdf0e10cSrcweir void ViewShellManager::Implementation::DumpShellStack (const ShellStack& rStack)
1348cdf0e10cSrcweir {
1349cdf0e10cSrcweir ShellStack::const_reverse_iterator iEntry;
1350cdf0e10cSrcweir for (iEntry=rStack.rbegin(); iEntry!=rStack.rend(); ++iEntry)
1351cdf0e10cSrcweir if (*iEntry != NULL)
1352cdf0e10cSrcweir OSL_TRACE (" %p : %s\r",
1353cdf0e10cSrcweir *iEntry,
1354cdf0e10cSrcweir ::rtl::OUStringToOString((*iEntry)->GetName(),RTL_TEXTENCODING_UTF8).getStr());
1355cdf0e10cSrcweir else
1356cdf0e10cSrcweir OSL_TRACE(" null\r");
1357cdf0e10cSrcweir }
1358cdf0e10cSrcweir
1359cdf0e10cSrcweir
1360cdf0e10cSrcweir
1361cdf0e10cSrcweir
DumpSfxShellStack(void)1362cdf0e10cSrcweir void ViewShellManager::Implementation::DumpSfxShellStack (void)
1363cdf0e10cSrcweir {
1364cdf0e10cSrcweir ShellStack aSfxShellStack;
1365cdf0e10cSrcweir sal_uInt16 nIndex (0);
1366cdf0e10cSrcweir while (mrBase.GetSubShell(nIndex)!=NULL)
1367cdf0e10cSrcweir ++nIndex;
1368cdf0e10cSrcweir aSfxShellStack.reserve(nIndex);
1369cdf0e10cSrcweir while (nIndex-- > 0)
1370cdf0e10cSrcweir aSfxShellStack.push_back(mrBase.GetSubShell(nIndex));
1371cdf0e10cSrcweir DumpShellStack(aSfxShellStack);
1372cdf0e10cSrcweir }
1373cdf0e10cSrcweir #endif
1374cdf0e10cSrcweir
1375cdf0e10cSrcweir
1376cdf0e10cSrcweir
Deactivate(SfxShell * pShell)1377cdf0e10cSrcweir void ViewShellManager::Implementation::Deactivate (SfxShell* pShell)
1378cdf0e10cSrcweir {
1379cdf0e10cSrcweir OSL_ASSERT(pShell!=NULL);
1380cdf0e10cSrcweir
1381cdf0e10cSrcweir // We have to end a text edit for view shells that are to be taken from
1382cdf0e10cSrcweir // the shell stack.
1383cdf0e10cSrcweir ViewShell* pViewShell = dynamic_cast<ViewShell*>(pShell);
1384cdf0e10cSrcweir if (pViewShell != NULL)
1385cdf0e10cSrcweir {
1386cdf0e10cSrcweir sd::View* pView = pViewShell->GetView();
1387cdf0e10cSrcweir if (pView!=NULL && pView->IsTextEdit())
1388cdf0e10cSrcweir {
1389cdf0e10cSrcweir pView->SdrEndTextEdit();
1390cdf0e10cSrcweir pView->UnmarkAll();
1391cdf0e10cSrcweir pViewShell->GetViewFrame()->GetDispatcher()->Execute(
1392cdf0e10cSrcweir SID_OBJECT_SELECT,
1393cdf0e10cSrcweir SFX_CALLMODE_ASYNCHRON);
1394cdf0e10cSrcweir }
1395cdf0e10cSrcweir }
1396cdf0e10cSrcweir
1397cdf0e10cSrcweir // Now we can deactivate the shell.
1398cdf0e10cSrcweir pShell->Deactivate(sal_True);
1399cdf0e10cSrcweir }
1400cdf0e10cSrcweir
1401cdf0e10cSrcweir
1402cdf0e10cSrcweir
1403cdf0e10cSrcweir
SetFormShell(const ViewShell * pFormShellParent,FmFormShell * pFormShell,bool bFormShellAboveParent)1404cdf0e10cSrcweir void ViewShellManager::Implementation::SetFormShell (
1405cdf0e10cSrcweir const ViewShell* pFormShellParent,
1406cdf0e10cSrcweir FmFormShell* pFormShell,
1407cdf0e10cSrcweir bool bFormShellAboveParent)
1408cdf0e10cSrcweir {
1409cdf0e10cSrcweir ::osl::MutexGuard aGuard (maMutex);
1410cdf0e10cSrcweir
1411cdf0e10cSrcweir mpFormShellParent = pFormShellParent;
1412cdf0e10cSrcweir mpFormShell = pFormShell;
1413cdf0e10cSrcweir mbFormShellAboveParent = bFormShellAboveParent;
1414cdf0e10cSrcweir }
1415cdf0e10cSrcweir
1416cdf0e10cSrcweir
1417cdf0e10cSrcweir
1418cdf0e10cSrcweir
1419cdf0e10cSrcweir namespace {
1420cdf0e10cSrcweir
ShellDescriptor(void)1421cdf0e10cSrcweir ShellDescriptor::ShellDescriptor (void)
1422cdf0e10cSrcweir : mpShell(NULL),
1423cdf0e10cSrcweir mnId(0),
14247a32b0c8SAndre Fischer mpFactory(),
14257a32b0c8SAndre Fischer mbIsListenerAddedToWindow(false)
1426cdf0e10cSrcweir {
1427cdf0e10cSrcweir }
1428cdf0e10cSrcweir
1429cdf0e10cSrcweir
1430cdf0e10cSrcweir
1431cdf0e10cSrcweir
ShellDescriptor(SfxShell * pShell,ShellId nId)1432cdf0e10cSrcweir ShellDescriptor::ShellDescriptor (
1433cdf0e10cSrcweir SfxShell* pShell,
1434cdf0e10cSrcweir ShellId nId)
1435cdf0e10cSrcweir : mpShell(pShell),
1436cdf0e10cSrcweir mnId(nId),
14377a32b0c8SAndre Fischer mpFactory(),
14387a32b0c8SAndre Fischer mbIsListenerAddedToWindow(false)
1439cdf0e10cSrcweir {
1440cdf0e10cSrcweir }
1441cdf0e10cSrcweir
1442cdf0e10cSrcweir
1443cdf0e10cSrcweir
1444cdf0e10cSrcweir
ShellDescriptor(const ShellDescriptor & rDescriptor)1445cdf0e10cSrcweir ShellDescriptor::ShellDescriptor (const ShellDescriptor& rDescriptor)
14467a32b0c8SAndre Fischer : mpShell(rDescriptor.mpShell),
14477a32b0c8SAndre Fischer mnId(rDescriptor.mnId),
14487a32b0c8SAndre Fischer mpFactory(rDescriptor.mpFactory),
14497a32b0c8SAndre Fischer mbIsListenerAddedToWindow(rDescriptor.mbIsListenerAddedToWindow)
1450cdf0e10cSrcweir {
1451cdf0e10cSrcweir }
1452cdf0e10cSrcweir
1453cdf0e10cSrcweir
1454cdf0e10cSrcweir
1455cdf0e10cSrcweir
operator =(const ShellDescriptor & rDescriptor)1456cdf0e10cSrcweir ShellDescriptor& ShellDescriptor::operator= (const ShellDescriptor& rDescriptor)
1457cdf0e10cSrcweir {
14587a32b0c8SAndre Fischer if (this != &rDescriptor)
14597a32b0c8SAndre Fischer {
14607a32b0c8SAndre Fischer mpShell = rDescriptor.mpShell;
14617a32b0c8SAndre Fischer mnId = rDescriptor.mnId;
14627a32b0c8SAndre Fischer mpFactory = rDescriptor.mpFactory;
14637a32b0c8SAndre Fischer mbIsListenerAddedToWindow = rDescriptor.mbIsListenerAddedToWindow;
14647a32b0c8SAndre Fischer }
1465cdf0e10cSrcweir return *this;
1466cdf0e10cSrcweir }
1467cdf0e10cSrcweir
1468cdf0e10cSrcweir
1469cdf0e10cSrcweir
1470cdf0e10cSrcweir
IsMainViewShell(void) const1471cdf0e10cSrcweir bool ShellDescriptor::IsMainViewShell (void) const
1472cdf0e10cSrcweir {
1473cdf0e10cSrcweir ViewShell* pViewShell = dynamic_cast<ViewShell*>(mpShell);
1474cdf0e10cSrcweir if (pViewShell != NULL)
1475cdf0e10cSrcweir return pViewShell->IsMainViewShell();
1476cdf0e10cSrcweir else
1477cdf0e10cSrcweir return false;
1478cdf0e10cSrcweir }
1479cdf0e10cSrcweir
1480cdf0e10cSrcweir
1481cdf0e10cSrcweir
1482cdf0e10cSrcweir
GetWindow(void) const1483cdf0e10cSrcweir ::Window* ShellDescriptor::GetWindow (void) const
1484cdf0e10cSrcweir {
1485cdf0e10cSrcweir ViewShell* pViewShell = dynamic_cast<ViewShell*>(mpShell);
1486cdf0e10cSrcweir if (pViewShell != NULL)
1487cdf0e10cSrcweir return pViewShell->GetActiveWindow();
1488cdf0e10cSrcweir else
1489cdf0e10cSrcweir return NULL;
1490cdf0e10cSrcweir }
1491cdf0e10cSrcweir
1492cdf0e10cSrcweir
1493cdf0e10cSrcweir
1494cdf0e10cSrcweir } // end of anonymous namespace
1495cdf0e10cSrcweir
1496cdf0e10cSrcweir } // end of namespace sd
1497