bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / framework / factories / ChildWindowPane.cxx
blob9692d6b65b1c052d1059b8537931a0e216d04fc2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <utility>
24 #include "ChildWindowPane.hxx"
26 #include "PaneDockingWindow.hxx"
27 #include "ViewShellBase.hxx"
28 #include "ViewShellManager.hxx"
29 #include "framework/FrameworkHelper.hxx"
30 #include <toolkit/helper/vclunohelper.hxx>
31 #include <vcl/svapp.hxx>
33 using namespace ::com::sun::star;
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::drawing::framework;
37 namespace sd { namespace framework {
39 ChildWindowPane::ChildWindowPane (
40 const Reference<XResourceId>& rxPaneId,
41 sal_uInt16 nChildWindowId,
42 ViewShellBase& rViewShellBase,
43 ::std::unique_ptr<SfxShell> && pShell)
44 : ChildWindowPaneInterfaceBase(rxPaneId,(vcl::Window*)NULL),
45 mnChildWindowId(nChildWindowId),
46 mrViewShellBase(rViewShellBase),
47 mpShell(std::move(pShell)),
48 mbHasBeenActivated(false)
50 mrViewShellBase.GetViewShellManager()->ActivateShell(mpShell.get());
52 SfxViewFrame* pViewFrame = mrViewShellBase.GetViewFrame();
53 if (pViewFrame != NULL)
55 if (mrViewShellBase.IsActive())
57 if (pViewFrame->KnowsChildWindow(mnChildWindowId))
59 if (pViewFrame->HasChildWindow(mnChildWindowId))
61 // The ViewShellBase has already been activated. Make
62 // the child window visible as soon as possible.
63 pViewFrame->SetChildWindow(mnChildWindowId, true);
64 OSL_TRACE("ChildWindowPane:activating now");
66 else
68 // The window is created asynchronously. Rely on the
69 // ConfigurationUpdater to try another update, and with
70 // that another request for this window, in a short
71 // time.
72 OSL_TRACE("ChildWindowPane:activated asynchronously");
75 else
77 OSL_TRACE("ChildWindowPane:not known");
80 else
82 // The ViewShellBase has not yet been activated. Hide the
83 // window and wait a little before it is made visible. See
84 // comments in the GetWindow() method for an explanation.
85 pViewFrame->SetChildWindow(mnChildWindowId, false);
86 OSL_TRACE("ChildWindowPane:base not active");
91 ChildWindowPane::~ChildWindowPane()
95 void ChildWindowPane::Hide()
97 SfxViewFrame* pViewFrame = mrViewShellBase.GetViewFrame();
98 if (pViewFrame != NULL)
99 if (pViewFrame->KnowsChildWindow(mnChildWindowId))
100 if (pViewFrame->HasChildWindow(mnChildWindowId))
101 pViewFrame->SetChildWindow(mnChildWindowId, false);
103 // Release the window because when the child window is shown again it
104 // may use a different window.
105 mxWindow = NULL;
108 void SAL_CALL ChildWindowPane::disposing()
110 ::osl::MutexGuard aGuard (maMutex);
112 mrViewShellBase.GetViewShellManager()->DeactivateShell(mpShell.get());
113 mpShell.reset();
115 if (mxWindow.is())
117 mxWindow->removeEventListener(this);
120 Pane::disposing();
123 vcl::Window* ChildWindowPane::GetWindow()
127 if (mxWindow.is())
128 // Window already exists => nothing to do.
129 break;
131 // When the window is not yet present then obtain it only when the
132 // shell has already been activated. The activation is not
133 // necessary for the code to work properly but is used to optimize
134 // the layouting and displaying of the window. When it is made
135 // visible to early then some layouting seems to be made twice or at
136 // an inconvenient time and the overall process of initializing the
137 // Impress takes longer.
138 if ( ! mbHasBeenActivated && mpShell.get()!=NULL && ! mpShell->IsActive())
139 break;
141 mbHasBeenActivated = true;
142 SfxViewFrame* pViewFrame = mrViewShellBase.GetViewFrame();
143 if (pViewFrame == NULL)
144 break;
145 // The view frame has to know the child window. This can be the
146 // case, when for example the document is in read-only mode: the
147 // task pane is then not available.
148 if ( ! pViewFrame->KnowsChildWindow(mnChildWindowId))
149 break;
151 pViewFrame->SetChildWindow(mnChildWindowId, true);
152 SfxChildWindow* pChildWindow = pViewFrame->GetChildWindow(mnChildWindowId);
153 if (pChildWindow == NULL)
154 if (pViewFrame->HasChildWindow(mnChildWindowId))
156 // The child window is not yet visible. Ask the view frame
157 // to show it and try again to get access to the child
158 // window.
159 pViewFrame->ShowChildWindow(mnChildWindowId, true);
160 pChildWindow = pViewFrame->GetChildWindow(mnChildWindowId);
163 // When the child window is still not visible then we have to try later.
164 if (pChildWindow == NULL)
165 break;
167 // From the child window get the docking window and from that the
168 // content window that is the container for the actual content.
169 PaneDockingWindow* pDockingWindow = dynamic_cast<PaneDockingWindow*>(
170 pChildWindow->GetWindow());
171 if (pDockingWindow == NULL)
172 break;
174 // At last, we have access to the window and its UNO wrapper.
175 mpWindow = &pDockingWindow->GetContentWindow();
176 mxWindow = VCLUnoHelper::GetInterface(mpWindow);
178 // Register as window listener to be informed when the child window
179 // is hidden.
180 if (mxWindow.is())
181 mxWindow->addEventListener(this);
183 while (false);
185 return mpWindow;
188 Reference<awt::XWindow> SAL_CALL ChildWindowPane::getWindow()
189 throw (RuntimeException, std::exception)
191 if (mpWindow == nullptr || ! mxWindow.is())
192 GetWindow();
193 return Pane::getWindow();
196 IMPLEMENT_FORWARD_XINTERFACE2(
197 ChildWindowPane,
198 ChildWindowPaneInterfaceBase,
199 Pane);
200 IMPLEMENT_FORWARD_XTYPEPROVIDER2(
201 ChildWindowPane,
202 ChildWindowPaneInterfaceBase,
203 Pane);
205 //----- XEventListener --------------------------------------------------------
207 void SAL_CALL ChildWindowPane::disposing (const lang::EventObject& rEvent)
208 throw (RuntimeException, std::exception)
210 ThrowIfDisposed();
212 if (rEvent.Source == mxWindow)
214 // The window is gone but the pane remains alive. The next call to
215 // GetWindow() may create the window anew.
216 mxWindow = NULL;
217 mpWindow = NULL;
221 } } // end of namespace sd::framework
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */