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/vclunohelper.hxx>
24 : #include <toolkit/helper/convert.hxx>
25 : #include <toolkit/awt/vclxwindow.hxx>
26 : #include <toolkit/awt/vclxwindows.hxx>
27 : #include <toolkit/awt/vclxcontainer.hxx>
28 : #include <toolkit/awt/vclxtopwindow.hxx>
29 : #include <toolkit/awt/vclxgraphics.hxx>
30 :
31 : #include "toolkit/dllapi.h"
32 : #include <vcl/svapp.hxx>
33 : #include <vcl/syswin.hxx>
34 : #include <vcl/menu.hxx>
35 :
36 : #include <tools/debug.hxx>
37 :
38 : #include "helper/unowrapper.hxx"
39 :
40 : using namespace ::com::sun::star;
41 :
42 75224 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > CreateXWindow( vcl::Window* pWindow )
43 : {
44 75224 : switch ( pWindow->GetType() )
45 : {
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 3 : 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 2470 : case WINDOW_COMBOBOX: return new VCLXComboBox;
62 : case WINDOW_SPINFIELD:
63 : case WINDOW_NUMERICFIELD:
64 3 : case WINDOW_CURRENCYFIELD: return new VCLXNumericField;
65 0 : case WINDOW_DATEFIELD: return new VCLXDateField;
66 : case WINDOW_MULTILINEEDIT:
67 5 : 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 3 : case WINDOW_FIXEDIMAGE: return new VCLXImageControl;
75 0 : case WINDOW_FIXEDTEXT: return new VCLXFixedText;
76 : case WINDOW_MULTILISTBOX:
77 22 : 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 9 : case WINDOW_MODELESSDIALOG: return new VCLXDialog;
84 0 : case WINDOW_PATTERNFIELD: return new VCLXPatternField;
85 15 : case WINDOW_RADIOBUTTON: return new VCLXRadioButton;
86 19 : 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 3258 : case WINDOW_HELPTEXTWINDOW: return new VCLXTopWindow;
94 :
95 : case WINDOW_WINDOW:
96 9240 : case WINDOW_TABPAGE: return new VCLXContainer;
97 :
98 19209 : 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 40968 : default: return new VCLXWindow( true );
117 : }
118 : }
119 :
120 :
121 : // class UnoWrapper
122 :
123 :
124 : extern "C" {
125 :
126 121 : TOOLKIT_DLLPUBLIC UnoWrapperBase* CreateUnoWrapper()
127 : {
128 121 : return new UnoWrapper( NULL );
129 : }
130 :
131 : } // extern "C"
132 :
133 :
134 121 : UnoWrapper::UnoWrapper( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit>& rxToolkit )
135 : {
136 121 : mxToolkit = rxToolkit;
137 121 : }
138 :
139 117 : void UnoWrapper::Destroy()
140 : {
141 117 : delete this;
142 117 : }
143 :
144 234 : UnoWrapper::~UnoWrapper()
145 : {
146 234 : }
147 :
148 376 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit> UnoWrapper::GetVCLToolkit()
149 : {
150 376 : if ( !mxToolkit.is() )
151 25 : mxToolkit = VCLUnoHelper::CreateToolkit();
152 376 : return mxToolkit.get();
153 : }
154 :
155 75224 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> UnoWrapper::GetWindowInterface( vcl::Window* pWindow, bool bCreate )
156 : {
157 75224 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xPeer = pWindow->GetWindowPeer();
158 75224 : if ( !xPeer.is() && bCreate )
159 : {
160 75224 : xPeer = CreateXWindow( pWindow );
161 75224 : SetWindowInterface( pWindow, xPeer );
162 : }
163 75224 : return xPeer;
164 : }
165 :
166 78892 : void UnoWrapper::SetWindowInterface( vcl::Window* pWindow, ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xIFace )
167 : {
168 78892 : VCLXWindow* pVCLXWindow = VCLXWindow::GetImplementation( xIFace );
169 :
170 : DBG_ASSERT( pVCLXWindow, "SetComponentInterface - unsupported type" );
171 78892 : if ( pVCLXWindow )
172 : {
173 78892 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xPeer = pWindow->GetWindowPeer();
174 78892 : if( xPeer.is() )
175 : {
176 7 : bool bSameInstance( pVCLXWindow == dynamic_cast< VCLXWindow* >( xPeer.get() ));
177 : DBG_ASSERT( bSameInstance, "UnoWrapper::SetWindowInterface: there already *is* a WindowInterface for this window!" );
178 7 : if ( bSameInstance )
179 78899 : return;
180 : }
181 78885 : pVCLXWindow->SetWindow( pWindow );
182 78885 : pWindow->SetWindowPeer( xIFace, pVCLXWindow );
183 : }
184 : }
185 :
186 28505 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics> UnoWrapper::CreateGraphics( OutputDevice* pOutDev )
187 : {
188 28505 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics> xGrf;
189 28505 : VCLXGraphics* pGrf = new VCLXGraphics;
190 28505 : xGrf = pGrf;
191 28505 : pGrf->Init( pOutDev );
192 28505 : return xGrf;
193 : }
194 :
195 760 : void UnoWrapper::ReleaseAllGraphics( OutputDevice* pOutDev )
196 : {
197 760 : std::vector< VCLXGraphics* > *pLst = pOutDev->GetUnoGraphicsList();
198 760 : if ( pLst )
199 : {
200 787 : for ( size_t n = 0; n < pLst->size(); n++ )
201 : {
202 27 : VCLXGraphics* pGrf = (*pLst)[ n ];
203 27 : pGrf->SetOutputDevice( NULL );
204 : }
205 : }
206 :
207 760 : }
208 :
209 0 : static bool lcl_ImplIsParent( vcl::Window* pParentWindow, vcl::Window* pPossibleChild )
210 : {
211 0 : vcl::Window* pWindow = ( pPossibleChild != pParentWindow ) ? pPossibleChild : NULL;
212 0 : while ( pWindow && ( pWindow != pParentWindow ) )
213 0 : pWindow = pWindow->GetParent();
214 :
215 0 : return pWindow != nullptr;
216 : }
217 :
218 267227 : void UnoWrapper::WindowDestroyed( vcl::Window* pWindow )
219 : {
220 : // their still might be some children created with ::com::sun::star::loader::Java
221 : // that would otherwise not be destroyed until the garbage collector cleans up
222 267227 : VclPtr< vcl::Window > pChild = pWindow->GetWindow( GetWindowType::FirstChild );
223 570148 : while ( pChild )
224 : {
225 35694 : VclPtr< vcl::Window > pNextChild = pChild->GetWindow( GetWindowType::Next );
226 :
227 71388 : VclPtr< vcl::Window > pClient = pChild->GetWindow( GetWindowType::Client );
228 35694 : if ( pClient && pClient->GetWindowPeer() )
229 : {
230 35694 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xComp( pClient->GetComponentInterface( false ), ::com::sun::star::uno::UNO_QUERY );
231 35694 : xComp->dispose();
232 : }
233 :
234 35694 : pChild = pNextChild;
235 35694 : }
236 :
237 : // System-Windows suchen...
238 534454 : VclPtr< vcl::Window > pOverlap = pWindow->GetWindow( GetWindowType::Overlap );
239 267227 : if ( pOverlap )
240 : {
241 267224 : pOverlap = pOverlap->GetWindow( GetWindowType::FirstOverlap );
242 534448 : while ( pOverlap )
243 : {
244 0 : VclPtr< vcl::Window > pNextOverlap = pOverlap->GetWindow( GetWindowType::Next );
245 0 : VclPtr< vcl::Window > pClient = pOverlap->GetWindow( GetWindowType::Client );
246 :
247 0 : if ( pClient && pClient->GetWindowPeer() && lcl_ImplIsParent( pWindow, pClient ) )
248 : {
249 0 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xComp( pClient->GetComponentInterface( false ), ::com::sun::star::uno::UNO_QUERY );
250 0 : xComp->dispose();
251 : }
252 :
253 0 : pOverlap = pNextOverlap;
254 0 : }
255 : }
256 :
257 : {
258 267227 : VclPtr< vcl::Window > pParent = pWindow->GetParent();
259 267227 : if ( pParent && pParent->GetWindowPeer() )
260 126858 : pParent->GetWindowPeer()->notifyWindowRemoved( *pWindow );
261 : }
262 :
263 267227 : VCLXWindow* pWindowPeer = pWindow->GetWindowPeer();
264 534454 : uno::Reference< lang::XComponent > xWindowPeerComp( pWindow->GetComponentInterface( false ), uno::UNO_QUERY );
265 : OSL_ENSURE( ( pWindowPeer != NULL ) == xWindowPeerComp.is(),
266 : "UnoWrapper::WindowDestroyed: inconsistency in the window's peers!" );
267 267227 : if ( pWindowPeer )
268 : {
269 78758 : pWindowPeer->SetWindow( NULL );
270 78758 : pWindow->SetWindowPeer( NULL, NULL );
271 : }
272 267227 : if ( xWindowPeerComp.is() )
273 78758 : xWindowPeerComp->dispose();
274 :
275 : // #102132# Iterate over frames after setting Window peer to NULL,
276 : // because while destroying other frames, we get get into the method again and try
277 : // to destroy this window again...
278 : // #i42462#/#116855# no, don't loop: Instead, just ensure that all our top-window-children
279 : // are disposed, too (which should also be a valid fix for #102132#, but doesn't have the extreme
280 : // performance penalties)
281 534454 : VclPtr< vcl::Window > pTopWindowChild = pWindow->GetWindow( GetWindowType::FirstTopWindowChild );
282 534456 : while ( pTopWindowChild )
283 : {
284 : OSL_ENSURE( pTopWindowChild->GetParent() == pWindow,
285 : "UnoWrapper::WindowDestroyed: inconsistency in the SystemWindow relationship!" );
286 :
287 2 : VclPtr< vcl::Window > pNextTopChild = pTopWindowChild->GetWindow( GetWindowType::NextTopWindowSibling );
288 :
289 : //the window still could be on the stack, so we have to
290 : // use lazy delete ( it will automatically
291 : // disconnect from the currently destroyed parent window )
292 2 : pTopWindowChild->doLazyDelete();
293 :
294 2 : pTopWindowChild = pNextTopChild;
295 267229 : }
296 267227 : }
297 :
298 :
299 25 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > UnoWrapper::CreateAccessible( Menu* pMenu, bool bIsMenuBar )
300 : {
301 25 : return maAccessibleFactoryAccess.getFactory().createAccessible( pMenu, bIsMenuBar );
302 : }
303 :
304 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|