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