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 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > CreateXWindow( Window* pWindow )
42 : {
43 0 : 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 0 : case WINDOW_COMBOBOX: return new VCLXComboBox;
61 : case WINDOW_SPINFIELD:
62 : case WINDOW_NUMERICFIELD:
63 0 : case WINDOW_CURRENCYFIELD: return new VCLXNumericField;
64 0 : case WINDOW_DATEFIELD: return new VCLXDateField;
65 : case WINDOW_MULTILINEEDIT:
66 0 : 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 0 : 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 0 : case WINDOW_MODELESSDIALOG: return new VCLXDialog;
83 0 : case WINDOW_PATTERNFIELD: return new VCLXPatternField;
84 0 : case WINDOW_RADIOBUTTON: return new VCLXRadioButton;
85 0 : 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 0 : case WINDOW_HELPTEXTWINDOW: return new VCLXTopWindow;
93 :
94 : case WINDOW_WINDOW:
95 0 : case WINDOW_TABPAGE: return new VCLXContainer;
96 :
97 0 : 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 0 : default: return new VCLXWindow( true );
116 : }
117 : }
118 :
119 :
120 : // class UnoWrapper
121 :
122 :
123 : extern "C" {
124 :
125 0 : TOOLKIT_DLLPUBLIC UnoWrapperBase* CreateUnoWrapper()
126 : {
127 0 : return new UnoWrapper( NULL );
128 : }
129 :
130 : } // extern "C"
131 :
132 :
133 0 : UnoWrapper::UnoWrapper( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit>& rxToolkit )
134 : {
135 0 : mxToolkit = rxToolkit;
136 0 : }
137 :
138 0 : void UnoWrapper::Destroy()
139 : {
140 0 : delete this;
141 0 : }
142 :
143 0 : UnoWrapper::~UnoWrapper()
144 : {
145 0 : }
146 :
147 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit> UnoWrapper::GetVCLToolkit()
148 : {
149 0 : if ( !mxToolkit.is() )
150 0 : mxToolkit = VCLUnoHelper::CreateToolkit();
151 0 : return mxToolkit.get();
152 : }
153 :
154 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> UnoWrapper::GetWindowInterface( Window* pWindow, sal_Bool bCreate )
155 : {
156 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xPeer = pWindow->GetWindowPeer();
157 0 : if ( !xPeer.is() && bCreate )
158 : {
159 0 : xPeer = CreateXWindow( pWindow );
160 0 : SetWindowInterface( pWindow, xPeer );
161 : }
162 0 : return xPeer;
163 : }
164 :
165 0 : void UnoWrapper::SetWindowInterface( Window* pWindow, ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xIFace )
166 : {
167 0 : VCLXWindow* pVCLXWindow = VCLXWindow::GetImplementation( xIFace );
168 :
169 : DBG_ASSERT( pVCLXWindow, "SetComponentInterface - unsupported type" );
170 0 : if ( pVCLXWindow )
171 : {
172 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer> xPeer = pWindow->GetWindowPeer();
173 0 : if( xPeer.is() )
174 : {
175 0 : bool bSameInstance( pVCLXWindow == dynamic_cast< VCLXWindow* >( xPeer.get() ));
176 : DBG_ASSERT( bSameInstance, "UnoWrapper::SetWindowInterface: there already *is* a WindowInterface for this window!" );
177 0 : if ( bSameInstance )
178 0 : return;
179 : }
180 0 : pVCLXWindow->SetWindow( pWindow );
181 0 : pWindow->SetWindowPeer( xIFace, pVCLXWindow );
182 : }
183 : }
184 :
185 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics> UnoWrapper::CreateGraphics( OutputDevice* pOutDev )
186 : {
187 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics> xGrf;
188 0 : VCLXGraphics* pGrf = new VCLXGraphics;
189 0 : xGrf = pGrf;
190 0 : pGrf->Init( pOutDev );
191 0 : return xGrf;
192 : }
193 :
194 0 : void UnoWrapper::ReleaseAllGraphics( OutputDevice* pOutDev )
195 : {
196 0 : VCLXGraphicsList_impl* pLst = pOutDev->GetUnoGraphicsList();
197 0 : if ( pLst )
198 : {
199 0 : for ( size_t n = 0; n < pLst->size(); n++ )
200 : {
201 0 : VCLXGraphics* pGrf = (*pLst)[ n ];
202 0 : pGrf->SetOutputDevice( NULL );
203 : }
204 : }
205 :
206 0 : }
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 0 : 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 0 : Window* pChild = pWindow->GetWindow( WINDOW_FIRSTCHILD );
222 0 : while ( pChild )
223 : {
224 0 : Window* pNextChild = pChild->GetWindow( WINDOW_NEXT );
225 :
226 0 : Window* pClient = pChild->GetWindow( WINDOW_CLIENT );
227 0 : if ( pClient->GetWindowPeer() )
228 : {
229 0 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xComp( pClient->GetComponentInterface( sal_False ), ::com::sun::star::uno::UNO_QUERY );
230 0 : xComp->dispose();
231 : }
232 :
233 0 : pChild = pNextChild;
234 : }
235 :
236 : // ::com::sun::star::chaos::System-Windows suchen...
237 0 : Window* pOverlap = pWindow->GetWindow( WINDOW_OVERLAP );
238 0 : if ( pOverlap )
239 : {
240 0 : pOverlap = pOverlap->GetWindow( WINDOW_FIRSTOVERLAP );
241 0 : 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 0 : Window* pParent = pWindow->GetParent();
257 0 : if ( pParent && pParent->GetWindowPeer() )
258 0 : pParent->GetWindowPeer()->notifyWindowRemoved( *pWindow );
259 :
260 0 : VCLXWindow* pWindowPeer = pWindow->GetWindowPeer();
261 0 : 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 0 : if ( pWindowPeer )
265 : {
266 0 : pWindowPeer->SetWindow( NULL );
267 0 : pWindow->SetWindowPeer( NULL, NULL );
268 : }
269 0 : if ( xWindowPeerComp.is() )
270 0 : 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 0 : Window* pTopWindowChild = pWindow->GetWindow( WINDOW_FIRSTTOPWINDOWCHILD );
279 0 : while ( pTopWindowChild )
280 : {
281 : OSL_ENSURE( pTopWindowChild->GetParent() == pWindow,
282 : "UnoWrapper::WindowDestroyed: inconsistency in the SystemWindow relationship!" );
283 :
284 0 : 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 0 : pTopWindowChild->doLazyDelete();
290 :
291 0 : pTopWindowChild = pNextTopChild;
292 0 : }
293 0 : }
294 :
295 :
296 0 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > UnoWrapper::CreateAccessible( Menu* pMenu, sal_Bool bIsMenuBar )
297 : {
298 0 : return maAccessibleFactoryAccess.getFactory().createAccessible( pMenu, bIsMenuBar );
299 : }
300 :
301 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|