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 38402 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > CreateXWindow( Window* pWindow )
42 : {
43 38402 : switch ( pWindow->GetType() )
44 : {
45 : case WINDOW_IMAGEBUTTON:
46 : case WINDOW_SPINBUTTON:
47 : case WINDOW_MENUBUTTON:
48 : case WINDOW_MOREBUTTON:
49 : case WINDOW_PUSHBUTTON:
50 : case WINDOW_HELPBUTTON:
51 : case WINDOW_OKBUTTON:
52 0 : case WINDOW_CANCELBUTTON: return new VCLXButton;
53 0 : case WINDOW_CHECKBOX: return new VCLXCheckBox;
54 : // #i95042#
55 : // A Window of type <MetricBox> is inherited from type <ComboBox>.
56 : // Thus, it does make more sense to return a <VCLXComboBox> instance
57 : // instead of only a <VCLXWindow> instance, especially regarding its
58 : // corresponding accessibility API.
59 : case WINDOW_METRICBOX:
60 1692 : case WINDOW_COMBOBOX: return new VCLXComboBox;
61 : case WINDOW_SPINFIELD:
62 : case WINDOW_NUMERICFIELD:
63 63 : case WINDOW_CURRENCYFIELD: return new VCLXNumericField;
64 0 : case WINDOW_DATEFIELD: return new VCLXDateField;
65 : case WINDOW_MULTILINEEDIT:
66 5 : case WINDOW_EDIT: return new VCLXEdit;
67 0 : case WINDOW_METRICFIELD: return new VCLXSpinField;
68 : case WINDOW_MESSBOX:
69 : case WINDOW_INFOBOX:
70 : case WINDOW_WARNINGBOX:
71 : case WINDOW_QUERYBOX:
72 0 : case WINDOW_ERRORBOX: return new VCLXMessageBox;
73 0 : case WINDOW_FIXEDIMAGE: return new VCLXImageControl;
74 0 : case WINDOW_FIXEDTEXT: return new VCLXFixedText;
75 : case WINDOW_MULTILISTBOX:
76 148 : case WINDOW_LISTBOX: return new VCLXListBox;
77 0 : case WINDOW_LONGCURRENCYFIELD: return new VCLXCurrencyField;
78 : case WINDOW_DIALOG:
79 : case WINDOW_MODALDIALOG:
80 : case WINDOW_TABDIALOG:
81 : case WINDOW_BUTTONDIALOG:
82 7 : case WINDOW_MODELESSDIALOG: return new VCLXDialog;
83 0 : case WINDOW_PATTERNFIELD: return new VCLXPatternField;
84 0 : case WINDOW_RADIOBUTTON: return new VCLXRadioButton;
85 18 : case WINDOW_SCROLLBAR: return new VCLXScrollBar;
86 0 : case WINDOW_TIMEFIELD: return new VCLXTimeField;
87 :
88 : case WINDOW_SYSWINDOW:
89 : case WINDOW_WORKWINDOW:
90 : case WINDOW_DOCKINGWINDOW:
91 : case WINDOW_FLOATINGWINDOW:
92 2297 : case WINDOW_HELPTEXTWINDOW: return new VCLXTopWindow;
93 :
94 : case WINDOW_WINDOW:
95 2805 : case WINDOW_TABPAGE: return new VCLXContainer;
96 :
97 6110 : case WINDOW_TOOLBOX: return new VCLXToolBox;
98 0 : case WINDOW_TABCONTROL: return new VCLXMultiPage;
99 :
100 : // case WINDOW_FIXEDLINE:
101 : // case WINDOW_FIXEDBITMAP:
102 : // case WINDOW_DATEBOX:
103 : // case WINDOW_GROUPBOX:
104 : // case WINDOW_LONGCURRENCYBOX:
105 : // case WINDOW_SPLITTER:
106 : // case WINDOW_STATUSBAR:
107 : // case WINDOW_TABCONTROL:
108 : // case WINDOW_NUMERICBOX:
109 : // case WINDOW_TRISTATEBOX:
110 : // case WINDOW_TIMEBOX:
111 : // case WINDOW_SPLITWINDOW:
112 : // case WINDOW_SCROLLBARBOX:
113 : // case WINDOW_PATTERNBOX:
114 : // case WINDOW_CURRENCYBOX:
115 25257 : default: return new VCLXWindow( true );
116 : }
117 : }
118 :
119 :
120 : // class UnoWrapper
121 :
122 :
123 : extern "C" {
124 :
125 79 : TOOLKIT_DLLPUBLIC UnoWrapperBase* CreateUnoWrapper()
126 : {
127 79 : return new UnoWrapper( NULL );
128 : }
129 :
130 : } // extern "C"
131 :
132 :
133 79 : UnoWrapper::UnoWrapper( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit>& rxToolkit )
134 : {
135 79 : mxToolkit = rxToolkit;
136 79 : }
137 :
138 32 : void UnoWrapper::Destroy()
139 : {
140 32 : delete this;
141 32 : }
142 :
143 64 : UnoWrapper::~UnoWrapper()
144 : {
145 64 : }
146 :
147 365 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit> UnoWrapper::GetVCLToolkit()
148 : {
149 365 : if ( !mxToolkit.is() )
150 15 : mxToolkit = VCLUnoHelper::CreateToolkit();
151 365 : return mxToolkit.get();
152 : }
153 :
154 38402 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> UnoWrapper::GetWindowInterface( Window* pWindow, sal_Bool bCreate )
155 : {
156 38402 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xPeer = pWindow->GetWindowPeer();
157 38402 : if ( !xPeer.is() && bCreate )
158 : {
159 38402 : xPeer = CreateXWindow( pWindow );
160 38402 : SetWindowInterface( pWindow, xPeer );
161 : }
162 38402 : return xPeer;
163 : }
164 :
165 40850 : void UnoWrapper::SetWindowInterface( Window* pWindow, ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xIFace )
166 : {
167 40850 : VCLXWindow* pVCLXWindow = VCLXWindow::GetImplementation( xIFace );
168 :
169 : DBG_ASSERT( pVCLXWindow, "SetComponentInterface - unsupported type" );
170 40850 : if ( pVCLXWindow )
171 : {
172 40850 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xPeer = pWindow->GetWindowPeer();
173 40850 : if( xPeer.is() )
174 : {
175 7 : bool bSameInstance( pVCLXWindow == dynamic_cast< VCLXWindow* >( xPeer.get() ));
176 : DBG_ASSERT( bSameInstance, "UnoWrapper::SetWindowInterface: there already *is* a WindowInterface for this window!" );
177 7 : if ( bSameInstance )
178 40857 : return;
179 : }
180 40843 : pVCLXWindow->SetWindow( pWindow );
181 40843 : pWindow->SetWindowPeer( xIFace, pVCLXWindow );
182 : }
183 : }
184 :
185 12524 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics> UnoWrapper::CreateGraphics( OutputDevice* pOutDev )
186 : {
187 12524 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics> xGrf;
188 12524 : VCLXGraphics* pGrf = new VCLXGraphics;
189 12524 : xGrf = pGrf;
190 12524 : pGrf->Init( pOutDev );
191 12524 : return xGrf;
192 : }
193 :
194 1193 : void UnoWrapper::ReleaseAllGraphics( OutputDevice* pOutDev )
195 : {
196 1193 : VCLXGraphicsList_impl* pLst = pOutDev->GetUnoGraphicsList();
197 1193 : if ( pLst )
198 : {
199 1211 : for ( size_t n = 0; n < pLst->size(); n++ )
200 : {
201 18 : VCLXGraphics* pGrf = (*pLst)[ n ];
202 18 : pGrf->SetOutputDevice( NULL );
203 : }
204 : }
205 :
206 1193 : }
207 :
208 0 : static bool lcl_ImplIsParent( Window* pParentWindow, Window* pPossibleChild )
209 : {
210 0 : Window* pWindow = ( pPossibleChild != pParentWindow ) ? pPossibleChild : NULL;
211 0 : while ( pWindow && ( pWindow != pParentWindow ) )
212 0 : pWindow = pWindow->GetParent();
213 :
214 0 : return pWindow ? sal_True : sal_False;
215 : }
216 :
217 116079 : void UnoWrapper::WindowDestroyed( Window* pWindow )
218 : {
219 : // their still might be some children created with ::com::sun::star::loader::Java
220 : // that would otherwise not be destroyed until the garbage collector cleans up
221 116079 : Window* pChild = pWindow->GetWindow( WINDOW_FIRSTCHILD );
222 254724 : while ( pChild )
223 : {
224 22566 : Window* pNextChild = pChild->GetWindow( WINDOW_NEXT );
225 :
226 22566 : Window* pClient = pChild->GetWindow( WINDOW_CLIENT );
227 22566 : if ( pClient->GetWindowPeer() )
228 : {
229 22566 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xComp( pClient->GetComponentInterface( sal_False ), ::com::sun::star::uno::UNO_QUERY );
230 22566 : xComp->dispose();
231 : }
232 :
233 22566 : pChild = pNextChild;
234 : }
235 :
236 : // ::com::sun::star::chaos::System-Windows suchen...
237 116079 : Window* pOverlap = pWindow->GetWindow( WINDOW_OVERLAP );
238 116079 : if ( pOverlap )
239 : {
240 116079 : pOverlap = pOverlap->GetWindow( WINDOW_FIRSTOVERLAP );
241 232158 : while ( pOverlap )
242 : {
243 0 : Window* pNextOverlap = pOverlap->GetWindow( WINDOW_NEXT );
244 0 : Window* pClient = pOverlap->GetWindow( WINDOW_CLIENT );
245 :
246 0 : if ( pClient->GetWindowPeer() && lcl_ImplIsParent( pWindow, pClient ) )
247 : {
248 0 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xComp( pClient->GetComponentInterface( sal_False ), ::com::sun::star::uno::UNO_QUERY );
249 0 : xComp->dispose();
250 : }
251 :
252 0 : pOverlap = pNextOverlap;
253 : }
254 : }
255 :
256 116079 : Window* pParent = pWindow->GetParent();
257 116079 : if ( pParent && pParent->GetWindowPeer() )
258 75905 : pParent->GetWindowPeer()->notifyWindowRemoved( *pWindow );
259 :
260 116079 : VCLXWindow* pWindowPeer = pWindow->GetWindowPeer();
261 116079 : uno::Reference< lang::XComponent > xWindowPeerComp( pWindow->GetComponentInterface( sal_False ), uno::UNO_QUERY );
262 : OSL_ENSURE( ( pWindowPeer != NULL ) == xWindowPeerComp.is(),
263 : "UnoWrapper::WindowDestroyed: inconsistency in the window's peers!" );
264 116079 : if ( pWindowPeer )
265 : {
266 40612 : pWindowPeer->SetWindow( NULL );
267 40612 : pWindow->SetWindowPeer( NULL, NULL );
268 : }
269 116079 : if ( xWindowPeerComp.is() )
270 40612 : xWindowPeerComp->dispose();
271 :
272 : // #102132# Iterate over frames after setting Window peer to NULL,
273 : // because while destroying other frames, we get get into the method again and try
274 : // to destroy this window again...
275 : // #i42462#/#116855# no, don't loop: Instead, just ensure that all our top-window-children
276 : // are disposed, too (which should also be a valid fix for #102132#, but doesn't have the extreme
277 : // performance penalties)
278 116079 : Window* pTopWindowChild = pWindow->GetWindow( WINDOW_FIRSTTOPWINDOWCHILD );
279 232160 : while ( pTopWindowChild )
280 : {
281 : OSL_ENSURE( pTopWindowChild->GetParent() == pWindow,
282 : "UnoWrapper::WindowDestroyed: inconsistency in the SystemWindow relationship!" );
283 :
284 2 : Window* pNextTopChild = pTopWindowChild->GetWindow( WINDOW_NEXTTOPWINDOWSIBLING );
285 :
286 : //the window still could be on the stack, so we have to
287 : // use lazy delete ( it will automatically
288 : // disconnect from the currently destroyed parent window )
289 2 : pTopWindowChild->doLazyDelete();
290 :
291 2 : pTopWindowChild = pNextTopChild;
292 116079 : }
293 116079 : }
294 :
295 :
296 25 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > UnoWrapper::CreateAccessible( Menu* pMenu, sal_Bool bIsMenuBar )
297 : {
298 25 : return maAccessibleFactoryAccess.getFactory().createAccessible( pMenu, bIsMenuBar );
299 : }
300 :
301 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|