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