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 126577 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > CreateXWindow( vcl::Window* pWindow )
43 : {
44 126577 : 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 6 : 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 5120 : case WINDOW_COMBOBOX: return new VCLXComboBox;
62 : case WINDOW_SPINFIELD:
63 : case WINDOW_NUMERICFIELD:
64 142 : case WINDOW_CURRENCYFIELD: return new VCLXNumericField;
65 0 : case WINDOW_DATEFIELD: return new VCLXDateField;
66 : case WINDOW_MULTILINEEDIT:
67 14 : 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 10 : case WINDOW_FIXEDIMAGE: return new VCLXImageControl;
75 4 : case WINDOW_FIXEDTEXT: return new VCLXFixedText;
76 : case WINDOW_MULTILISTBOX:
77 170 : 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 14 : case WINDOW_MODELESSDIALOG: return new VCLXDialog;
84 0 : case WINDOW_PATTERNFIELD: return new VCLXPatternField;
85 24 : case WINDOW_RADIOBUTTON: return new VCLXRadioButton;
86 38 : 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 6304 : case WINDOW_HELPTEXTWINDOW: return new VCLXTopWindow;
94 :
95 : case WINDOW_WINDOW:
96 14320 : case WINDOW_TABPAGE: return new VCLXContainer;
97 :
98 27364 : 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 73047 : default: return new VCLXWindow( true );
117 : }
118 : }
119 :
120 :
121 : // class UnoWrapper
122 :
123 :
124 : extern "C" {
125 :
126 182 : TOOLKIT_DLLPUBLIC UnoWrapperBase* CreateUnoWrapper()
127 : {
128 182 : return new UnoWrapper( NULL );
129 : }
130 :
131 : } // extern "C"
132 :
133 :
134 182 : UnoWrapper::UnoWrapper( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit>& rxToolkit )
135 : {
136 182 : mxToolkit = rxToolkit;
137 182 : }
138 :
139 174 : void UnoWrapper::Destroy()
140 : {
141 174 : delete this;
142 174 : }
143 :
144 348 : UnoWrapper::~UnoWrapper()
145 : {
146 348 : }
147 :
148 727 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit> UnoWrapper::GetVCLToolkit()
149 : {
150 727 : if ( !mxToolkit.is() )
151 32 : mxToolkit = VCLUnoHelper::CreateToolkit();
152 727 : return mxToolkit.get();
153 : }
154 :
155 126577 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> UnoWrapper::GetWindowInterface( vcl::Window* pWindow, bool bCreate )
156 : {
157 126577 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xPeer = pWindow->GetWindowPeer();
158 126577 : if ( !xPeer.is() && bCreate )
159 : {
160 126577 : xPeer = CreateXWindow( pWindow );
161 126577 : SetWindowInterface( pWindow, xPeer );
162 : }
163 126577 : return xPeer;
164 : }
165 :
166 132889 : void UnoWrapper::SetWindowInterface( vcl::Window* pWindow, ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xIFace )
167 : {
168 132889 : VCLXWindow* pVCLXWindow = VCLXWindow::GetImplementation( xIFace );
169 :
170 : DBG_ASSERT( pVCLXWindow, "SetComponentInterface - unsupported type" );
171 132889 : if ( pVCLXWindow )
172 : {
173 132889 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xPeer = pWindow->GetWindowPeer();
174 132889 : if( xPeer.is() )
175 : {
176 14 : bool bSameInstance( pVCLXWindow == dynamic_cast< VCLXWindow* >( xPeer.get() ));
177 : DBG_ASSERT( bSameInstance, "UnoWrapper::SetWindowInterface: there already *is* a WindowInterface for this window!" );
178 14 : if ( bSameInstance )
179 132903 : return;
180 : }
181 132875 : pVCLXWindow->SetWindow( pWindow );
182 132875 : pWindow->SetWindowPeer( xIFace, pVCLXWindow );
183 : }
184 : }
185 :
186 15058 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics> UnoWrapper::CreateGraphics( OutputDevice* pOutDev )
187 : {
188 15058 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics> xGrf;
189 15058 : VCLXGraphics* pGrf = new VCLXGraphics;
190 15058 : xGrf = pGrf;
191 15058 : pGrf->Init( pOutDev );
192 15058 : return xGrf;
193 : }
194 :
195 1737 : void UnoWrapper::ReleaseAllGraphics( OutputDevice* pOutDev )
196 : {
197 1737 : VCLXGraphicsList_impl* pLst = pOutDev->GetUnoGraphicsList();
198 1737 : if ( pLst )
199 : {
200 1765 : for ( size_t n = 0; n < pLst->size(); n++ )
201 : {
202 28 : VCLXGraphics* pGrf = (*pLst)[ n ];
203 28 : pGrf->SetOutputDevice( NULL );
204 : }
205 : }
206 :
207 1737 : }
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 ? sal_True : sal_False;
216 : }
217 :
218 442562 : 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 442562 : vcl::Window* pChild = pWindow->GetWindow( WINDOW_FIRSTCHILD );
223 945885 : while ( pChild )
224 : {
225 60761 : vcl::Window* pNextChild = pChild->GetWindow( WINDOW_NEXT );
226 :
227 60761 : vcl::Window* pClient = pChild->GetWindow( WINDOW_CLIENT );
228 60761 : if ( pClient->GetWindowPeer() )
229 : {
230 60761 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xComp( pClient->GetComponentInterface( false ), ::com::sun::star::uno::UNO_QUERY );
231 60761 : xComp->dispose();
232 : }
233 :
234 60761 : pChild = pNextChild;
235 : }
236 :
237 : // System-Windows suchen...
238 442562 : vcl::Window* pOverlap = pWindow->GetWindow( WINDOW_OVERLAP );
239 442562 : if ( pOverlap )
240 : {
241 442562 : pOverlap = pOverlap->GetWindow( WINDOW_FIRSTOVERLAP );
242 885124 : while ( pOverlap )
243 : {
244 0 : vcl::Window* pNextOverlap = pOverlap->GetWindow( WINDOW_NEXT );
245 0 : vcl::Window* pClient = pOverlap->GetWindow( WINDOW_CLIENT );
246 :
247 0 : if ( 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 : }
255 : }
256 :
257 442562 : vcl::Window* pParent = pWindow->GetParent();
258 442562 : if ( pParent && pParent->GetWindowPeer() )
259 222611 : pParent->GetWindowPeer()->notifyWindowRemoved( *pWindow );
260 :
261 442562 : VCLXWindow* pWindowPeer = pWindow->GetWindowPeer();
262 442562 : uno::Reference< lang::XComponent > xWindowPeerComp( pWindow->GetComponentInterface( false ), uno::UNO_QUERY );
263 : OSL_ENSURE( ( pWindowPeer != NULL ) == xWindowPeerComp.is(),
264 : "UnoWrapper::WindowDestroyed: inconsistency in the window's peers!" );
265 442562 : if ( pWindowPeer )
266 : {
267 132779 : pWindowPeer->SetWindow( NULL );
268 132779 : pWindow->SetWindowPeer( NULL, NULL );
269 : }
270 442562 : if ( xWindowPeerComp.is() )
271 132779 : xWindowPeerComp->dispose();
272 :
273 : // #102132# Iterate over frames after setting Window peer to NULL,
274 : // because while destroying other frames, we get get into the method again and try
275 : // to destroy this window again...
276 : // #i42462#/#116855# no, don't loop: Instead, just ensure that all our top-window-children
277 : // are disposed, too (which should also be a valid fix for #102132#, but doesn't have the extreme
278 : // performance penalties)
279 442562 : vcl::Window* pTopWindowChild = pWindow->GetWindow( WINDOW_FIRSTTOPWINDOWCHILD );
280 885128 : while ( pTopWindowChild )
281 : {
282 : OSL_ENSURE( pTopWindowChild->GetParent() == pWindow,
283 : "UnoWrapper::WindowDestroyed: inconsistency in the SystemWindow relationship!" );
284 :
285 4 : vcl::Window* pNextTopChild = pTopWindowChild->GetWindow( WINDOW_NEXTTOPWINDOWSIBLING );
286 :
287 : //the window still could be on the stack, so we have to
288 : // use lazy delete ( it will automatically
289 : // disconnect from the currently destroyed parent window )
290 4 : pTopWindowChild->doLazyDelete();
291 :
292 4 : pTopWindowChild = pNextTopChild;
293 442562 : }
294 442562 : }
295 :
296 :
297 50 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > UnoWrapper::CreateAccessible( Menu* pMenu, bool bIsMenuBar )
298 : {
299 50 : return maAccessibleFactoryAccess.getFactory().createAccessible( pMenu, bIsMenuBar );
300 1227 : }
301 :
302 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|