1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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");
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
72 OSL_TRACE("ChildWindowPane:activated asynchronously");
77 OSL_TRACE("ChildWindowPane:not known");
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.
108 void SAL_CALL
ChildWindowPane::disposing()
110 ::osl::MutexGuard
aGuard (maMutex
);
112 mrViewShellBase
.GetViewShellManager()->DeactivateShell(mpShell
.get());
117 mxWindow
->removeEventListener(this);
123 vcl::Window
* ChildWindowPane::GetWindow()
128 // Window already exists => nothing to do.
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())
141 mbHasBeenActivated
= true;
142 SfxViewFrame
* pViewFrame
= mrViewShellBase
.GetViewFrame();
143 if (pViewFrame
== NULL
)
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
))
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
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
)
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
)
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
181 mxWindow
->addEventListener(this);
188 Reference
<awt::XWindow
> SAL_CALL
ChildWindowPane::getWindow()
189 throw (RuntimeException
, std::exception
)
191 if (mpWindow
== nullptr || ! mxWindow
.is())
193 return Pane::getWindow();
196 IMPLEMENT_FORWARD_XINTERFACE2(
198 ChildWindowPaneInterfaceBase
,
200 IMPLEMENT_FORWARD_XTYPEPROVIDER2(
202 ChildWindowPaneInterfaceBase
,
205 //----- XEventListener --------------------------------------------------------
207 void SAL_CALL
ChildWindowPane::disposing (const lang::EventObject
& rEvent
)
208 throw (RuntimeException
, std::exception
)
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.
221 } } // end of namespace sd::framework
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */