1*02c50d82SAndre Fischer /**************************************************************
2*02c50d82SAndre Fischer *
3*02c50d82SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one
4*02c50d82SAndre Fischer * or more contributor license agreements. See the NOTICE file
5*02c50d82SAndre Fischer * distributed with this work for additional information
6*02c50d82SAndre Fischer * regarding copyright ownership. The ASF licenses this file
7*02c50d82SAndre Fischer * to you under the Apache License, Version 2.0 (the
8*02c50d82SAndre Fischer * "License"); you may not use this file except in compliance
9*02c50d82SAndre Fischer * with the License. You may obtain a copy of the License at
10*02c50d82SAndre Fischer *
11*02c50d82SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0
12*02c50d82SAndre Fischer *
13*02c50d82SAndre Fischer * Unless required by applicable law or agreed to in writing,
14*02c50d82SAndre Fischer * software distributed under the License is distributed on an
15*02c50d82SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*02c50d82SAndre Fischer * KIND, either express or implied. See the License for the
17*02c50d82SAndre Fischer * specific language governing permissions and limitations
18*02c50d82SAndre Fischer * under the License.
19*02c50d82SAndre Fischer *
20*02c50d82SAndre Fischer *************************************************************/
21*02c50d82SAndre Fischer
22*02c50d82SAndre Fischer #include "precompiled_sd.hxx"
23*02c50d82SAndre Fischer
24*02c50d82SAndre Fischer #include "SidebarShellManager.hxx"
25*02c50d82SAndre Fischer
26*02c50d82SAndre Fischer #include "ViewShellManager.hxx"
27*02c50d82SAndre Fischer #include <tools/diagnose_ex.h>
28*02c50d82SAndre Fischer #include <vcl/window.hxx>
29*02c50d82SAndre Fischer
30*02c50d82SAndre Fischer #include <algorithm>
31*02c50d82SAndre Fischer
32*02c50d82SAndre Fischer namespace sd { namespace sidebar {
33*02c50d82SAndre Fischer
SidebarShellManager(const::boost::shared_ptr<ViewShellManager> & rpViewShellManager,const ViewShell & rViewShell)34*02c50d82SAndre Fischer SidebarShellManager::SidebarShellManager (
35*02c50d82SAndre Fischer const ::boost::shared_ptr<ViewShellManager>& rpViewShellManager,
36*02c50d82SAndre Fischer const ViewShell& rViewShell)
37*02c50d82SAndre Fischer : mpViewShellManager(rpViewShellManager),
38*02c50d82SAndre Fischer mrViewShell(rViewShell),
39*02c50d82SAndre Fischer maSubShells()
40*02c50d82SAndre Fischer {
41*02c50d82SAndre Fischer }
42*02c50d82SAndre Fischer
43*02c50d82SAndre Fischer
44*02c50d82SAndre Fischer
45*02c50d82SAndre Fischer
~SidebarShellManager(void)46*02c50d82SAndre Fischer SidebarShellManager::~SidebarShellManager (void)
47*02c50d82SAndre Fischer {
48*02c50d82SAndre Fischer while ( ! maSubShells.empty())
49*02c50d82SAndre Fischer RemoveSubShell(maSubShells.begin()->second.mpShell);
50*02c50d82SAndre Fischer }
51*02c50d82SAndre Fischer
52*02c50d82SAndre Fischer
53*02c50d82SAndre Fischer
54*02c50d82SAndre Fischer
CreateShell(ShellId nId,::Window *,FrameView *)55*02c50d82SAndre Fischer SfxShell* SidebarShellManager::CreateShell( ShellId nId, ::Window* , FrameView* )
56*02c50d82SAndre Fischer {
57*02c50d82SAndre Fischer SubShells::const_iterator iShell (maSubShells.find(nId));
58*02c50d82SAndre Fischer if (iShell != maSubShells.end())
59*02c50d82SAndre Fischer return iShell->second.mpShell;
60*02c50d82SAndre Fischer else
61*02c50d82SAndre Fischer return NULL;
62*02c50d82SAndre Fischer }
63*02c50d82SAndre Fischer
64*02c50d82SAndre Fischer
65*02c50d82SAndre Fischer
66*02c50d82SAndre Fischer
ReleaseShell(SfxShell *)67*02c50d82SAndre Fischer void SidebarShellManager::ReleaseShell (SfxShell* )
68*02c50d82SAndre Fischer {
69*02c50d82SAndre Fischer // Nothing to do.
70*02c50d82SAndre Fischer }
71*02c50d82SAndre Fischer
AddSubShell(ShellId nId,SfxShell * pShell,::Window * pWindow)72*02c50d82SAndre Fischer void SidebarShellManager::AddSubShell (
73*02c50d82SAndre Fischer ShellId nId,
74*02c50d82SAndre Fischer SfxShell* pShell,
75*02c50d82SAndre Fischer ::Window* pWindow)
76*02c50d82SAndre Fischer {
77*02c50d82SAndre Fischer if (pShell != NULL)
78*02c50d82SAndre Fischer {
79*02c50d82SAndre Fischer maSubShells[nId] = ShellDescriptor(pShell,pWindow);
80*02c50d82SAndre Fischer if (pWindow != NULL)
81*02c50d82SAndre Fischer {
82*02c50d82SAndre Fischer pWindow->AddEventListener(LINK(this,SidebarShellManager,WindowCallback));
83*02c50d82SAndre Fischer if (pWindow->IsReallyVisible())
84*02c50d82SAndre Fischer mpViewShellManager->ActivateSubShell(mrViewShell, nId);
85*02c50d82SAndre Fischer }
86*02c50d82SAndre Fischer else
87*02c50d82SAndre Fischer mpViewShellManager->ActivateSubShell(mrViewShell, nId);
88*02c50d82SAndre Fischer }
89*02c50d82SAndre Fischer }
90*02c50d82SAndre Fischer
91*02c50d82SAndre Fischer
92*02c50d82SAndre Fischer
93*02c50d82SAndre Fischer
RemoveSubShell(const ShellId i_nShellId)94*02c50d82SAndre Fischer void SidebarShellManager::RemoveSubShell (const ShellId i_nShellId)
95*02c50d82SAndre Fischer {
96*02c50d82SAndre Fischer SubShells::iterator pos = maSubShells.find( i_nShellId );
97*02c50d82SAndre Fischer ENSURE_OR_RETURN_VOID( pos != maSubShells.end(), "no shell for this ID" );
98*02c50d82SAndre Fischer if ( pos->second.mpWindow != NULL )
99*02c50d82SAndre Fischer {
100*02c50d82SAndre Fischer pos->second.mpWindow->RemoveEventListener( LINK( this, SidebarShellManager, WindowCallback ) );
101*02c50d82SAndre Fischer }
102*02c50d82SAndre Fischer mpViewShellManager->DeactivateSubShell( mrViewShell, pos->first );
103*02c50d82SAndre Fischer maSubShells.erase( pos );
104*02c50d82SAndre Fischer }
105*02c50d82SAndre Fischer
106*02c50d82SAndre Fischer
107*02c50d82SAndre Fischer
108*02c50d82SAndre Fischer
RemoveSubShell(const SfxShell * pShell)109*02c50d82SAndre Fischer void SidebarShellManager::RemoveSubShell (const SfxShell* pShell)
110*02c50d82SAndre Fischer {
111*02c50d82SAndre Fischer if (pShell != NULL)
112*02c50d82SAndre Fischer {
113*02c50d82SAndre Fischer SubShells::iterator iShell;
114*02c50d82SAndre Fischer for (iShell=maSubShells.begin(); iShell!=maSubShells.end(); ++iShell)
115*02c50d82SAndre Fischer if (iShell->second.mpShell == pShell)
116*02c50d82SAndre Fischer {
117*02c50d82SAndre Fischer if (iShell->second.mpWindow != NULL)
118*02c50d82SAndre Fischer iShell->second.mpWindow->RemoveEventListener(
119*02c50d82SAndre Fischer LINK(this,SidebarShellManager,WindowCallback));
120*02c50d82SAndre Fischer mpViewShellManager->DeactivateSubShell(mrViewShell,iShell->first);
121*02c50d82SAndre Fischer maSubShells.erase(iShell);
122*02c50d82SAndre Fischer break;
123*02c50d82SAndre Fischer }
124*02c50d82SAndre Fischer }
125*02c50d82SAndre Fischer }
126*02c50d82SAndre Fischer
127*02c50d82SAndre Fischer
128*02c50d82SAndre Fischer
129*02c50d82SAndre Fischer
MoveToTop(SfxShell * pShell)130*02c50d82SAndre Fischer void SidebarShellManager::MoveToTop (SfxShell* pShell)
131*02c50d82SAndre Fischer {
132*02c50d82SAndre Fischer SubShells::const_iterator iShell;
133*02c50d82SAndre Fischer for (iShell=maSubShells.begin(); iShell!=maSubShells.end(); ++iShell)
134*02c50d82SAndre Fischer if (iShell->second.mpShell == pShell)
135*02c50d82SAndre Fischer {
136*02c50d82SAndre Fischer ViewShellManager::UpdateLock aLocker (mpViewShellManager);
137*02c50d82SAndre Fischer mpViewShellManager->MoveSubShellToTop(mrViewShell,iShell->first);
138*02c50d82SAndre Fischer mpViewShellManager->MoveToTop(mrViewShell);
139*02c50d82SAndre Fischer break;
140*02c50d82SAndre Fischer }
141*02c50d82SAndre Fischer }
142*02c50d82SAndre Fischer
143*02c50d82SAndre Fischer
144*02c50d82SAndre Fischer
145*02c50d82SAndre Fischer
IMPL_LINK(SidebarShellManager,WindowCallback,VclWindowEvent *,pEvent)146*02c50d82SAndre Fischer IMPL_LINK(SidebarShellManager, WindowCallback, VclWindowEvent*, pEvent)
147*02c50d82SAndre Fischer {
148*02c50d82SAndre Fischer if (pEvent != NULL)
149*02c50d82SAndre Fischer {
150*02c50d82SAndre Fischer SubShells::const_iterator iShell;
151*02c50d82SAndre Fischer ::Window* pWindow = pEvent->GetWindow();
152*02c50d82SAndre Fischer for (iShell=maSubShells.begin(); iShell!=maSubShells.end(); ++iShell)
153*02c50d82SAndre Fischer if (iShell->second.mpWindow == pWindow)
154*02c50d82SAndre Fischer break;
155*02c50d82SAndre Fischer if (iShell != maSubShells.end())
156*02c50d82SAndre Fischer switch (pEvent->GetId())
157*02c50d82SAndre Fischer {
158*02c50d82SAndre Fischer case VCLEVENT_WINDOW_SHOW:
159*02c50d82SAndre Fischer mpViewShellManager->ActivateSubShell(mrViewShell,iShell->first);
160*02c50d82SAndre Fischer break;
161*02c50d82SAndre Fischer
162*02c50d82SAndre Fischer case VCLEVENT_WINDOW_HIDE:
163*02c50d82SAndre Fischer // Do not activate the sub shell. This leads to
164*02c50d82SAndre Fischer // problems with shapes currently being in text edit
165*02c50d82SAndre Fischer // mode: Deactivating the shell leads to leaving the
166*02c50d82SAndre Fischer // text editing mode.
167*02c50d82SAndre Fischer // mpViewShellManager->DeactivateSubShell(mrViewShell,iShell->first);
168*02c50d82SAndre Fischer break;
169*02c50d82SAndre Fischer }
170*02c50d82SAndre Fischer }
171*02c50d82SAndre Fischer
172*02c50d82SAndre Fischer return 0;
173*02c50d82SAndre Fischer }
174*02c50d82SAndre Fischer
175*02c50d82SAndre Fischer
176*02c50d82SAndre Fischer } } // end of namespace ::sd::sidebar
177