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 : : #include <com/sun/star/awt/WindowEvent.hpp>
30 : : #include <comphelper/processfactory.hxx>
31 : :
32 : : #include <toolkit/helper/unowrapper.hxx>
33 : : #include <toolkit/helper/vclunohelper.hxx>
34 : : #include <toolkit/helper/convert.hxx>
35 : : #include <toolkit/awt/vclxwindow.hxx>
36 : : #include <toolkit/awt/vclxwindows.hxx>
37 : : #include <toolkit/awt/vclxcontainer.hxx>
38 : : #include <toolkit/awt/vclxtopwindow.hxx>
39 : : #include <toolkit/awt/vclxgraphics.hxx>
40 : :
41 : : #include "toolkit/dllapi.h"
42 : : #include <vcl/svapp.hxx>
43 : : #include <vcl/syswin.hxx>
44 : : #include <vcl/menu.hxx>
45 : :
46 : : #include <tools/debug.hxx>
47 : :
48 : : using namespace ::com::sun::star;
49 : :
50 : 37176 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > CreateXWindow( Window* pWindow )
51 : : {
52 [ + - + + : 37176 : switch ( pWindow->GetType() )
- + - - -
- + - - -
- + - + +
+ - + ]
53 : : {
54 : : case WINDOW_IMAGERADIOBUTTON:
55 : : case WINDOW_IMAGEBUTTON:
56 : : case WINDOW_SPINBUTTON:
57 : : case WINDOW_MENUBUTTON:
58 : : case WINDOW_MOREBUTTON:
59 : : case WINDOW_PUSHBUTTON:
60 : : case WINDOW_HELPBUTTON:
61 : : case WINDOW_OKBUTTON:
62 [ + - ][ + - ]: 36 : case WINDOW_CANCELBUTTON: return new VCLXButton;
63 [ # # ][ # # ]: 0 : case WINDOW_CHECKBOX: return new VCLXCheckBox;
64 : : // #i95042#
65 : : // A Window of type <MetricBox> is inherited from type <ComboBox>.
66 : : // Thus, it does make more sense to return a <VCLXComboBox> instance
67 : : // instead of only a <VCLXWindow> instance, especially regarding its
68 : : // corresponding accessibility API.
69 : : case WINDOW_METRICBOX:
70 [ + - ][ + - ]: 2889 : case WINDOW_COMBOBOX: return new VCLXComboBox;
71 : : case WINDOW_SPINFIELD:
72 : : case WINDOW_NUMERICFIELD:
73 [ + - ][ + - ]: 129 : case WINDOW_CURRENCYFIELD: return new VCLXNumericField;
74 [ # # ][ # # ]: 0 : case WINDOW_DATEFIELD: return new VCLXDateField;
75 : : case WINDOW_MULTILINEEDIT:
76 [ + - ][ + - ]: 10 : case WINDOW_EDIT: return new VCLXEdit;
77 [ # # ][ # # ]: 0 : case WINDOW_METRICFIELD: return new VCLXSpinField;
78 : : case WINDOW_MESSBOX:
79 : : case WINDOW_INFOBOX:
80 : : case WINDOW_WARNINGBOX:
81 : : case WINDOW_QUERYBOX:
82 [ # # ][ # # ]: 0 : case WINDOW_ERRORBOX: return new VCLXMessageBox;
83 [ # # ][ # # ]: 0 : case WINDOW_FIXEDIMAGE: return new VCLXImageControl;
84 [ # # ][ # # ]: 0 : case WINDOW_FIXEDTEXT: return new VCLXFixedText;
85 : : case WINDOW_MULTILISTBOX:
86 [ + - ][ + - ]: 298 : case WINDOW_LISTBOX: return new VCLXListBox;
87 [ # # ][ # # ]: 0 : case WINDOW_LONGCURRENCYFIELD: return new VCLXCurrencyField;
88 : : case WINDOW_DIALOG:
89 : : case WINDOW_MODALDIALOG:
90 : : case WINDOW_TABDIALOG:
91 : : case WINDOW_BUTTONDIALOG:
92 [ # # ][ # # ]: 0 : case WINDOW_MODELESSDIALOG: return new VCLXDialog;
93 [ # # ][ # # ]: 0 : case WINDOW_PATTERNFIELD: return new VCLXPatternField;
94 [ # # ][ # # ]: 0 : case WINDOW_RADIOBUTTON: return new VCLXRadioButton;
95 [ + - ][ + - ]: 37 : case WINDOW_SCROLLBAR: return new VCLXScrollBar;
96 [ # # ][ # # ]: 0 : case WINDOW_TIMEFIELD: return new VCLXTimeField;
97 : :
98 : : case WINDOW_SYSWINDOW:
99 : : case WINDOW_WORKWINDOW:
100 : : case WINDOW_DOCKINGWINDOW:
101 : : case WINDOW_FLOATINGWINDOW:
102 [ + - ][ + - ]: 3878 : case WINDOW_HELPTEXTWINDOW: return new VCLXTopWindow;
103 : :
104 : : case WINDOW_WINDOW:
105 [ + - ][ + - ]: 2889 : case WINDOW_TABPAGE: return new VCLXContainer;
106 : :
107 [ + - ][ + - ]: 3723 : case WINDOW_TOOLBOX: return new VCLXToolBox;
108 [ # # ][ # # ]: 0 : case WINDOW_TABCONTROL: return new VCLXMultiPage;
109 : :
110 : : // case WINDOW_FIXEDLINE:
111 : : // case WINDOW_FIXEDBITMAP:
112 : : // case WINDOW_DATEBOX:
113 : : // case WINDOW_GROUPBOX:
114 : : // case WINDOW_LONGCURRENCYBOX:
115 : : // case WINDOW_SPLITTER:
116 : : // case WINDOW_STATUSBAR:
117 : : // case WINDOW_TABCONTROL:
118 : : // case WINDOW_NUMERICBOX:
119 : : // case WINDOW_TRISTATEBOX:
120 : : // case WINDOW_TIMEBOX:
121 : : // case WINDOW_SPLITWINDOW:
122 : : // case WINDOW_SCROLLBARBOX:
123 : : // case WINDOW_PATTERNBOX:
124 : : // case WINDOW_CURRENCYBOX:
125 [ + - ][ + - ]: 37176 : default: return new VCLXWindow( true );
126 : : }
127 : : }
128 : :
129 : : // ----------------------------------------------------
130 : : // class UnoWrapper
131 : : // ----------------------------------------------------
132 : :
133 : : extern "C" {
134 : :
135 : 124 : TOOLKIT_DLLPUBLIC UnoWrapperBase* CreateUnoWrapper()
136 : : {
137 [ + - ][ + - ]: 124 : return new UnoWrapper( NULL );
138 : : }
139 : :
140 : : } // extern "C"
141 : :
142 : :
143 [ + - ]: 124 : UnoWrapper::UnoWrapper( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit>& rxToolkit )
144 : : {
145 [ + - ]: 124 : mxToolkit = rxToolkit;
146 : 124 : }
147 : :
148 : 64 : void UnoWrapper::Destroy()
149 : : {
150 [ + - ]: 64 : delete this;
151 : 64 : }
152 : :
153 [ + - ]: 64 : UnoWrapper::~UnoWrapper()
154 : : {
155 [ - + ]: 128 : }
156 : :
157 : 678 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit> UnoWrapper::GetVCLToolkit()
158 : : {
159 [ + + ]: 678 : if ( !mxToolkit.is() )
160 [ + - ]: 25 : mxToolkit = VCLUnoHelper::CreateToolkit();
161 : 678 : return mxToolkit.get();
162 : : }
163 : :
164 : 37176 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> UnoWrapper::GetWindowInterface( Window* pWindow, sal_Bool bCreate )
165 : : {
166 [ - + ]: 37176 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xPeer = pWindow->GetWindowPeer();
167 [ + - ][ + - ]: 37176 : if ( !xPeer.is() && bCreate )
[ + - ]
168 : : {
169 [ + - ][ + - ]: 37176 : xPeer = CreateXWindow( pWindow );
170 [ + - ]: 37176 : SetWindowInterface( pWindow, xPeer );
171 : : }
172 : 37176 : return xPeer;
173 : : }
174 : :
175 : 39606 : void UnoWrapper::SetWindowInterface( Window* pWindow, ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xIFace )
176 : : {
177 : 39606 : VCLXWindow* pVCLXWindow = VCLXWindow::GetImplementation( xIFace );
178 : :
179 : : DBG_ASSERT( pVCLXWindow, "SetComponentInterface - unsupported type" );
180 [ + - ]: 39606 : if ( pVCLXWindow )
181 : : {
182 [ + - ][ - + ]: 39606 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xPeer = pWindow->GetWindowPeer();
[ + - ]
183 [ - + ]: 39606 : if( xPeer.is() )
184 : : {
185 [ # # ][ # # ]: 0 : bool bSameInstance( pVCLXWindow == dynamic_cast< VCLXWindow* >( xPeer.get() ));
186 : : DBG_ASSERT( bSameInstance, "UnoWrapper::SetWindowInterface: there already *is* a WindowInterface for this window!" );
187 [ # # ]: 0 : if ( bSameInstance )
188 : 39606 : return;
189 : : }
190 [ + - ]: 39606 : pVCLXWindow->SetWindow( pWindow );
191 [ + - ][ + - ]: 39606 : pWindow->SetWindowPeer( xIFace, pVCLXWindow );
192 : : }
193 : : }
194 : :
195 : 20511 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics> UnoWrapper::CreateGraphics( OutputDevice* pOutDev )
196 : : {
197 : 20511 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics> xGrf;
198 [ + - ]: 20511 : VCLXGraphics* pGrf = new VCLXGraphics;
199 [ + - ]: 20511 : xGrf = pGrf;
200 [ + - ]: 20511 : pGrf->Init( pOutDev );
201 : 20511 : return xGrf;
202 : : }
203 : :
204 : 2201 : void UnoWrapper::ReleaseAllGraphics( OutputDevice* pOutDev )
205 : : {
206 : 2201 : VCLXGraphicsList_impl* pLst = pOutDev->GetUnoGraphicsList();
207 [ + - ]: 2201 : if ( pLst )
208 : : {
209 [ + + ]: 2229 : for ( size_t n = 0; n < pLst->size(); n++ )
210 : : {
211 : 28 : VCLXGraphics* pGrf = (*pLst)[ n ];
212 : 28 : pGrf->SetOutputDevice( NULL );
213 : : }
214 : : }
215 : :
216 : 2201 : }
217 : :
218 : : // It was once called in the Window-CTOR to make listeners of the Container
219 : : // to react. This didn't really work, as the interface within the Window-CTOR
220 : : // was not ready.
221 : : // => Call only the listener, when created through ::com::sun::star::awt::Toolkit
222 : :
223 : : /*
224 : : void ImplSmartWindowCreated( Window* pNewWindow )
225 : : {
226 : : UNOWindowData* pParentUNOData = pNewWindow->GetParent() ?
227 : : pNewWindow->GetParent()->GetUNOData() : NULL;
228 : :
229 : : if ( pParentUNOData && pParentUNOData->GetListeners( EL_CONTAINER ) )
230 : : {
231 : : UNOWindowData* pUNOData = pNewWindow->GetUNOData();
232 : : if ( !pUNOData )
233 : : pUNOData = ImplSmartCreateUNOData( pNewWindow );
234 : :
235 : : ::com::sun::star::awt::VclContainerEvent aEvent;
236 : : aEvent.Source = (UsrObject*)pParentUNOData->GetWindowPeer();
237 : : aEvent.Id = VCLCOMPONENT_ADDED;
238 : : aEvent.Child = (UsrObject*)pUNOData->GetWindowPeer();
239 : :
240 : : EventList* pLst = pParentUNOData->GetListeners( EL_CONTAINER );
241 : : for ( sal_uInt32 n = 0; n < pLst->Count(); n++ )
242 : : {
243 : : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > * pRef = pLst->GetObject( n );
244 : : ((::com::sun::star::awt::XVclContainerListener*)(::com::sun::star::lang::XEventListener*)*pRef)->windowAdded( aEvent );
245 : : }
246 : : }
247 : : }
248 : : */
249 : :
250 : 0 : sal_Bool lcl_ImplIsParent( Window* pParentWindow, Window* pPossibleChild )
251 : : {
252 [ # # ]: 0 : Window* pWindow = ( pPossibleChild != pParentWindow ) ? pPossibleChild : NULL;
253 [ # # ][ # # ]: 0 : while ( pWindow && ( pWindow != pParentWindow ) )
[ # # ]
254 : 0 : pWindow = pWindow->GetParent();
255 : :
256 [ # # ]: 0 : return pWindow ? sal_True : sal_False;
257 : : }
258 : :
259 : 120305 : void UnoWrapper::WindowDestroyed( Window* pWindow )
260 : : {
261 : : // their still might be some children created with ::com::sun::star::loader::Java
262 : : // that would otherwise not be destroyed until the garbage collector cleans up
263 [ + - ]: 120305 : Window* pChild = pWindow->GetWindow( WINDOW_FIRSTCHILD );
264 [ + + ]: 137038 : while ( pChild )
265 : : {
266 [ + - ]: 16733 : Window* pNextChild = pChild->GetWindow( WINDOW_NEXT );
267 : :
268 [ + - ]: 16733 : Window* pClient = pChild->GetWindow( WINDOW_CLIENT );
269 [ + - ][ + - ]: 16733 : if ( pClient->GetWindowPeer() )
270 : : {
271 [ + - ][ + - ]: 16733 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xComp( pClient->GetComponentInterface( sal_False ), ::com::sun::star::uno::UNO_QUERY );
272 [ + - ][ + - ]: 16733 : xComp->dispose();
273 : : }
274 : :
275 : 16733 : pChild = pNextChild;
276 : : }
277 : :
278 : : // ::com::sun::star::chaos::System-Windows suchen...
279 [ + - ]: 120305 : Window* pOverlap = pWindow->GetWindow( WINDOW_OVERLAP );
280 [ + - ]: 120305 : pOverlap = pOverlap->GetWindow( WINDOW_FIRSTOVERLAP );
281 [ - + ]: 120305 : while ( pOverlap )
282 : : {
283 [ # # ]: 0 : Window* pNextOverlap = pOverlap->GetWindow( WINDOW_NEXT );
284 [ # # ]: 0 : Window* pClient = pOverlap->GetWindow( WINDOW_CLIENT );
285 : :
286 [ # # ][ # # ]: 0 : if ( pClient->GetWindowPeer() && lcl_ImplIsParent( pWindow, pClient ) )
[ # # ][ # # ]
[ # # ]
287 : : {
288 [ # # ][ # # ]: 0 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xComp( pClient->GetComponentInterface( sal_False ), ::com::sun::star::uno::UNO_QUERY );
289 [ # # ][ # # ]: 0 : xComp->dispose();
290 : : }
291 : :
292 : 0 : pOverlap = pNextOverlap;
293 : : }
294 : :
295 [ + - ]: 120305 : Window* pParent = pWindow->GetParent();
296 [ + + ][ + - ]: 120305 : if ( pParent && pParent->GetWindowPeer() )
[ + + ][ + + ]
297 [ + - ][ + - ]: 72996 : pParent->GetWindowPeer()->notifyWindowRemoved( *pWindow );
298 : :
299 [ + - ]: 120305 : VCLXWindow* pWindowPeer = pWindow->GetWindowPeer();
300 [ + - ][ + - ]: 120305 : uno::Reference< lang::XComponent > xWindowPeerComp( pWindow->GetComponentInterface( sal_False ), uno::UNO_QUERY );
301 : : OSL_ENSURE( ( pWindowPeer != NULL ) == ( xWindowPeerComp.is() == sal_True ),
302 : : "UnoWrapper::WindowDestroyed: inconsistency in the window's peers!" );
303 [ + + ]: 120305 : if ( pWindowPeer )
304 : : {
305 [ + - ]: 38244 : pWindowPeer->SetWindow( NULL );
306 [ + - ][ + - ]: 38244 : pWindow->SetWindowPeer( NULL, NULL );
307 : : }
308 [ + + ]: 120305 : if ( xWindowPeerComp.is() )
309 [ + - ][ + - ]: 38244 : xWindowPeerComp->dispose();
310 : :
311 : : // #102132# Iterate over frames after setting Window peer to NULL,
312 : : // because while destroying other frames, we get get into the method again and try
313 : : // to destroy this window again...
314 : : // #i42462#/#116855# no, don't loop: Instead, just ensure that all our top-window-children
315 : : // are disposed, too (which should also be a valid fix for #102132#, but doesn't have the extreme
316 : : // performance penalties)
317 [ + - ]: 120305 : if ( pWindow )
318 : : {
319 [ + - ]: 120305 : Window* pTopWindowChild = pWindow->GetWindow( WINDOW_FIRSTTOPWINDOWCHILD );
320 [ - + ]: 120305 : while ( pTopWindowChild )
321 : : {
322 : : OSL_ENSURE( pTopWindowChild->GetParent() == pWindow,
323 : : "UnoWrapper::WindowDestroyed: inconsistency in the SystemWindow relationship!" );
324 : :
325 [ # # ]: 0 : Window* pNextTopChild = pTopWindowChild->GetWindow( WINDOW_NEXTTOPWINDOWSIBLING );
326 : :
327 : : //the window still could be on the stack, so we have to
328 : : // use lazy delete ( it will automatically
329 : : // disconnect from the currently destroyed parent window )
330 [ # # ]: 0 : pTopWindowChild->doLazyDelete();
331 : :
332 : 0 : pTopWindowChild = pNextTopChild;
333 : : }
334 : 120305 : }
335 : 120305 : }
336 : :
337 : : // ----------------------------------------------------------------------------
338 : 49 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > UnoWrapper::CreateAccessible( Menu* pMenu, sal_Bool bIsMenuBar )
339 : : {
340 : 49 : return maAccessibleFactoryAccess.getFactory().createAccessible( pMenu, bIsMenuBar );
341 : : }
342 : :
343 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|