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