Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "ChildWindowPane.hxx"
22 :
23 : #include "PaneDockingWindow.hxx"
24 : #include "ViewShellBase.hxx"
25 : #include "ViewShellManager.hxx"
26 : #include "framework/FrameworkHelper.hxx"
27 : #include <toolkit/helper/vclunohelper.hxx>
28 : #include <vcl/svapp.hxx>
29 :
30 : using namespace ::com::sun::star;
31 : using namespace ::com::sun::star::uno;
32 : using namespace ::com::sun::star::drawing::framework;
33 :
34 : namespace sd { namespace framework {
35 :
36 :
37 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
38 0 : ChildWindowPane::ChildWindowPane (
39 : const Reference<XResourceId>& rxPaneId,
40 : sal_uInt16 nChildWindowId,
41 : ViewShellBase& rViewShellBase,
42 : ::std::auto_ptr<SfxShell> pShell)
43 : : ChildWindowPaneInterfaceBase(rxPaneId,(::Window*)NULL),
44 : mnChildWindowId(nChildWindowId),
45 : mrViewShellBase(rViewShellBase),
46 : mpShell(pShell),
47 0 : mbHasBeenActivated(false)
48 : {
49 0 : mrViewShellBase.GetViewShellManager()->ActivateShell(mpShell.get());
50 :
51 0 : SfxViewFrame* pViewFrame = mrViewShellBase.GetViewFrame();
52 0 : if (pViewFrame != NULL)
53 : {
54 0 : if (mrViewShellBase.IsActive())
55 : {
56 0 : if (pViewFrame->KnowsChildWindow(mnChildWindowId))
57 : {
58 0 : if (pViewFrame->HasChildWindow(mnChildWindowId))
59 : {
60 : // The ViewShellBase has already been activated. Make
61 : // the child window visible as soon as possible.
62 0 : pViewFrame->SetChildWindow(mnChildWindowId, true);
63 : OSL_TRACE("ChildWindowPane:activating now");
64 : }
65 : else
66 : {
67 : // The window is created asynchronously. Rely on the
68 : // ConfigurationUpdater to try another update, and with
69 : // that another request for this window, in a short
70 : // time.
71 : OSL_TRACE("ChildWindowPane:activated asynchronously");
72 : }
73 : }
74 : else
75 : {
76 : OSL_TRACE("ChildWindowPane:not known");
77 : }
78 : }
79 : else
80 : {
81 : // The ViewShellBase has not yet been activated. Hide the
82 : // window and wait a little before it is made visible. See
83 : // comments in the GetWindow() method for an explanation.
84 0 : pViewFrame->SetChildWindow(mnChildWindowId, false);
85 : OSL_TRACE("ChildWindowPane:base not active");
86 : }
87 : }
88 0 : }
89 : SAL_WNODEPRECATED_DECLARATIONS_POP
90 :
91 :
92 :
93 0 : ChildWindowPane::~ChildWindowPane (void)
94 : {
95 0 : }
96 :
97 :
98 :
99 :
100 0 : void ChildWindowPane::Hide (void)
101 : {
102 0 : SfxViewFrame* pViewFrame = mrViewShellBase.GetViewFrame();
103 0 : if (pViewFrame != NULL)
104 0 : if (pViewFrame->KnowsChildWindow(mnChildWindowId))
105 0 : if (pViewFrame->HasChildWindow(mnChildWindowId))
106 0 : pViewFrame->SetChildWindow(mnChildWindowId, false);
107 :
108 : // Release the window because when the child window is shown again it
109 : // may use a different window.
110 0 : mxWindow = NULL;
111 0 : }
112 :
113 :
114 :
115 :
116 0 : void SAL_CALL ChildWindowPane::disposing (void)
117 : {
118 0 : ::osl::MutexGuard aGuard (maMutex);
119 :
120 0 : mrViewShellBase.GetViewShellManager()->DeactivateShell(mpShell.get());
121 0 : mpShell.reset();
122 :
123 0 : if (mxWindow.is())
124 : {
125 0 : mxWindow->removeEventListener(this);
126 : }
127 :
128 0 : Pane::disposing();
129 0 : }
130 :
131 :
132 :
133 :
134 0 : ::Window* ChildWindowPane::GetWindow (void)
135 : {
136 : do
137 : {
138 0 : if (mxWindow.is())
139 : // Window already exists => nothing to do.
140 0 : break;
141 :
142 : // When the window is not yet present then obtain it only when the
143 : // shell has already been activated. The activation is not
144 : // necessary for the code to work properly but is used to optimize
145 : // the layouting and displaying of the window. When it is made
146 : // visible to early then some layouting seems to be made twice or at
147 : // an inconvenient time and the overall process of initializing the
148 : // Impress takes longer.
149 0 : if ( ! mbHasBeenActivated && mpShell.get()!=NULL && ! mpShell->IsActive())
150 0 : break;
151 :
152 0 : mbHasBeenActivated = true;
153 0 : SfxViewFrame* pViewFrame = mrViewShellBase.GetViewFrame();
154 0 : if (pViewFrame == NULL)
155 0 : break;
156 : // The view frame has to know the child window. This can be the
157 : // case, when for example the document is in read-only mode: the
158 : // task pane is then not available.
159 0 : if ( ! pViewFrame->KnowsChildWindow(mnChildWindowId))
160 0 : break;
161 :
162 0 : pViewFrame->SetChildWindow(mnChildWindowId, true);
163 0 : SfxChildWindow* pChildWindow = pViewFrame->GetChildWindow(mnChildWindowId);
164 0 : if (pChildWindow == NULL)
165 0 : if (pViewFrame->HasChildWindow(mnChildWindowId))
166 : {
167 : // The child window is not yet visible. Ask the view frame
168 : // to show it and try again to get access to the child
169 : // window.
170 0 : pViewFrame->ShowChildWindow(mnChildWindowId, true);
171 0 : pChildWindow = pViewFrame->GetChildWindow(mnChildWindowId);
172 : }
173 :
174 : // When the child window is still not visible then we have to try later.
175 0 : if (pChildWindow == NULL)
176 0 : break;
177 :
178 : // From the child window get the docking window and from that the
179 : // content window that is the container for the actual content.
180 : PaneDockingWindow* pDockingWindow = dynamic_cast<PaneDockingWindow*>(
181 0 : pChildWindow->GetWindow());
182 0 : if (pDockingWindow == NULL)
183 0 : break;
184 :
185 : // At last, we have access to the window and its UNO wrapper.
186 0 : mpWindow = &pDockingWindow->GetContentWindow();
187 0 : mxWindow = VCLUnoHelper::GetInterface(mpWindow);
188 :
189 : // Register as window listener to be informed when the child window
190 : // is hidden.
191 0 : if (mxWindow.is())
192 0 : mxWindow->addEventListener(this);
193 : }
194 : while (false);
195 :
196 0 : return mpWindow;
197 : }
198 :
199 :
200 :
201 :
202 0 : Reference<awt::XWindow> SAL_CALL ChildWindowPane::getWindow (void)
203 : throw (RuntimeException, std::exception)
204 : {
205 0 : if (mpWindow == NULL || ! mxWindow.is())
206 0 : GetWindow();
207 0 : return Pane::getWindow();
208 : }
209 :
210 :
211 :
212 0 : IMPLEMENT_FORWARD_XINTERFACE2(
213 : ChildWindowPane,
214 : ChildWindowPaneInterfaceBase,
215 : Pane);
216 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2(
217 : ChildWindowPane,
218 : ChildWindowPaneInterfaceBase,
219 : Pane);
220 :
221 :
222 :
223 :
224 : //----- XEventListener --------------------------------------------------------
225 :
226 0 : void SAL_CALL ChildWindowPane::disposing (const lang::EventObject& rEvent)
227 : throw (RuntimeException, std::exception)
228 : {
229 0 : ThrowIfDisposed();
230 :
231 0 : if (rEvent.Source == mxWindow)
232 : {
233 : // The window is gone but the pane remains alive. The next call to
234 : // GetWindow() may create the window anew.
235 0 : mxWindow = NULL;
236 0 : mpWindow = NULL;
237 : }
238 0 : }
239 :
240 :
241 :
242 :
243 : } } // end of namespace sd::framework
244 :
245 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|