Update ooo320-m1
[ooovba.git] / sd / source / ui / framework / factories / ChildWindowPane.cxx
blob9c8ed4a3311931cd31b11ec479752edc13317cb4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ChildWindowPane.cxx,v $
11 * $Revision: 1.3 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "precompiled_sd.hxx"
34 #include "ChildWindowPane.hxx"
36 #include "PaneDockingWindow.hxx"
37 #include "ViewShellBase.hxx"
38 #include "ViewShellManager.hxx"
39 #include "framework/FrameworkHelper.hxx"
40 #include <toolkit/helper/vclunohelper.hxx>
41 #include <vcl/svapp.hxx>
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::drawing::framework;
47 namespace sd { namespace framework {
50 ChildWindowPane::ChildWindowPane (
51 const Reference<XResourceId>& rxPaneId,
52 USHORT nChildWindowId,
53 ViewShellBase& rViewShellBase,
54 ::std::auto_ptr<SfxShell> pShell)
55 : ChildWindowPaneInterfaceBase(rxPaneId,(::Window*)NULL),
56 mnChildWindowId(nChildWindowId),
57 mrViewShellBase(rViewShellBase),
58 mpShell(pShell),
59 mbHasBeenActivated(false)
61 mrViewShellBase.GetViewShellManager()->ActivateShell(mpShell.get());
63 SfxViewFrame* pViewFrame = mrViewShellBase.GetViewFrame();
64 if (pViewFrame != NULL)
66 if (mrViewShellBase.IsActive())
68 if (pViewFrame->KnowsChildWindow(mnChildWindowId))
70 if (pViewFrame->HasChildWindow(mnChildWindowId))
72 // The ViewShellBase has already been activated. Make
73 // the child window visible as soon as possible.
74 pViewFrame->SetChildWindow(mnChildWindowId, TRUE);
75 OSL_TRACE("ChildWindowPane:activating now");
77 else
79 // The window is created asynchronously. Rely on the
80 // ConfigurationUpdater to try another update, and with
81 // that another request for this window, in a short
82 // time.
83 OSL_TRACE("ChildWindowPane:activated asynchronously");
86 else
88 OSL_TRACE("ChildWindowPane:not known");
91 else
93 // The ViewShellBase has not yet been activated. Hide the
94 // window and wait a little before it is made visible. See
95 // comments in the GetWindow() method for an explanation.
96 pViewFrame->SetChildWindow(mnChildWindowId, FALSE);
97 OSL_TRACE("ChildWindowPane:base not active");
105 ChildWindowPane::~ChildWindowPane (void) throw()
112 void ChildWindowPane::Hide (void)
114 SfxViewFrame* pViewFrame = mrViewShellBase.GetViewFrame();
115 if (pViewFrame != NULL)
116 if (pViewFrame->KnowsChildWindow(mnChildWindowId))
117 if (pViewFrame->HasChildWindow(mnChildWindowId))
118 pViewFrame->SetChildWindow(mnChildWindowId, FALSE);
120 // Release the window because when the child window is shown again it
121 // may use a different window.
122 mxWindow = NULL;
128 void SAL_CALL ChildWindowPane::disposing (void)
130 ::osl::MutexGuard aGuard (maMutex);
132 mrViewShellBase.GetViewShellManager()->DeactivateShell(mpShell.get());
133 mpShell.reset();
135 if (mxWindow.is())
137 mxWindow->removeEventListener(this);
140 Pane::disposing();
146 ::Window* ChildWindowPane::GetWindow (void)
150 if (mxWindow.is())
151 // Window already exists => nothing to do.
152 break;
154 // When the window is not yet present then obtain it only when the
155 // shell has already been activated. The activation is not
156 // necessary for the code to work properly but is used to optimize
157 // the layouting and displaying of the window. When it is made
158 // visible to early then some layouting seems to be made twice or at
159 // an inconvenient time and the overall process of initializing the
160 // Impress takes longer.
161 if ( ! mbHasBeenActivated && mpShell.get()!=NULL && ! mpShell->IsActive())
162 break;
164 mbHasBeenActivated = true;
165 SfxViewFrame* pViewFrame = mrViewShellBase.GetViewFrame();
166 if (pViewFrame == NULL)
167 break;
168 // The view frame has to know the child window. This can be the
169 // case, when for example the document is in read-only mode: the
170 // task pane is then not available.
171 if ( ! pViewFrame->KnowsChildWindow(mnChildWindowId))
172 break;
174 pViewFrame->SetChildWindow(mnChildWindowId, TRUE);
175 SfxChildWindow* pChildWindow = pViewFrame->GetChildWindow(mnChildWindowId);
176 if (pChildWindow == NULL)
177 if (pViewFrame->HasChildWindow(mnChildWindowId))
179 // The child window is not yet visible. Ask the view frame
180 // to show it and try again to get access to the child
181 // window.
182 pViewFrame->ShowChildWindow(mnChildWindowId, TRUE);
183 pChildWindow = pViewFrame->GetChildWindow(mnChildWindowId);
186 // When the child window is still not visible then we have to try later.
187 if (pChildWindow == NULL)
188 break;
190 // From the child window get the docking window and from that the
191 // content window that is the container for the actual content.
192 PaneDockingWindow* pDockingWindow = dynamic_cast<PaneDockingWindow*>(
193 pChildWindow->GetWindow());
194 if (pDockingWindow == NULL)
195 break;
197 // At last, we have access to the window and its UNO wrapper.
198 mpWindow = pDockingWindow->GetContentWindow();
199 mxWindow = VCLUnoHelper::GetInterface(mpWindow);
201 // Register as window listener to be informed when the child window
202 // is hidden.
203 if (mxWindow.is())
204 mxWindow->addEventListener(this);
206 while (false);
208 return mpWindow;
214 Reference<awt::XWindow> SAL_CALL ChildWindowPane::getWindow (void)
215 throw (RuntimeException)
217 if (mpWindow == NULL || ! mxWindow.is())
218 GetWindow();
219 return Pane::getWindow();
224 IMPLEMENT_FORWARD_XINTERFACE2(
225 ChildWindowPane,
226 ChildWindowPaneInterfaceBase,
227 Pane);
228 IMPLEMENT_FORWARD_XTYPEPROVIDER2(
229 ChildWindowPane,
230 ChildWindowPaneInterfaceBase,
231 Pane);
236 //----- XEventListener --------------------------------------------------------
238 void SAL_CALL ChildWindowPane::disposing (const lang::EventObject& rEvent)
239 throw (RuntimeException)
241 ThrowIfDisposed();
243 if (rEvent.Source == mxWindow)
245 // The window is gone but the pane remains alive. The next call to
246 // GetWindow() may create the window anew.
247 mxWindow = NULL;
248 mpWindow = NULL;
255 } } // end of namespace sd::framework