LibreOffice Module toolkit (master) 1
unowrapper.cxx
Go to the documentation of this file.
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
24#include <awt/vclxcontainer.hxx>
25#include <awt/vclxgraphics.hxx>
26#include <awt/vclxtopwindow.hxx>
27#include <awt/vclxwindows.hxx>
28
29#include <toolkit/dllapi.h>
30#include <vcl/menu.hxx>
31
32#include <helper/unowrapper.hxx>
33
34using namespace ::com::sun::star;
35
37{
38 switch ( pWindow->GetType() )
39 {
40 case WindowType::IMAGEBUTTON:
41 case WindowType::SPINBUTTON:
42 case WindowType::MENUBUTTON:
43 case WindowType::MOREBUTTON:
44 case WindowType::PUSHBUTTON:
45 case WindowType::HELPBUTTON:
46 case WindowType::OKBUTTON:
47 case WindowType::CANCELBUTTON: return new VCLXButton;
48 case WindowType::CHECKBOX: return new VCLXCheckBox;
49 // #i95042#
50 // A Window of type <MetricBox> is inherited from type <ComboBox>.
51 // Thus, it does make more sense to return a <VCLXComboBox> instance
52 // instead of only a <VCLXWindow> instance, especially regarding its
53 // corresponding accessibility API.
54 case WindowType::METRICBOX:
55 case WindowType::COMBOBOX: return new VCLXComboBox;
56 case WindowType::FORMATTEDFIELD: return new SVTXNumericField;
57 case WindowType::SPINFIELD:
58 case WindowType::CURRENCYFIELD: return new VCLXNumericField;
59 case WindowType::DATEFIELD: return new VCLXDateField;
60 case WindowType::MULTILINEEDIT:
61 case WindowType::EDIT: return new VCLXEdit;
62 case WindowType::METRICFIELD: return new VCLXSpinField;
63 case WindowType::MESSBOX:
64 case WindowType::INFOBOX:
65 case WindowType::WARNINGBOX:
66 case WindowType::QUERYBOX:
67 case WindowType::ERRORBOX: return new VCLXMessageBox;
68 case WindowType::FIXEDIMAGE: return new VCLXImageControl;
69 case WindowType::FIXEDTEXT: return new VCLXFixedText;
70 case WindowType::MULTILISTBOX:
71 case WindowType::LISTBOX: return new VCLXListBox;
72 case WindowType::DIALOG:
73 case WindowType::TABDIALOG:
74 case WindowType::BUTTONDIALOG:
75 case WindowType::MODELESSDIALOG: return new VCLXDialog;
76 case WindowType::PATTERNFIELD: return new VCLXPatternField;
77 case WindowType::RADIOBUTTON: return new VCLXRadioButton;
78 case WindowType::SCROLLBAR: return new VCLXScrollBar;
79 case WindowType::TIMEFIELD: return new VCLXTimeField;
80
81 case WindowType::WORKWINDOW:
82 case WindowType::DOCKINGWINDOW:
83 case WindowType::FLOATINGWINDOW:
84 case WindowType::HELPTEXTWINDOW: return new VCLXTopWindow;
85
86 case WindowType::WINDOW:
87 case WindowType::TABPAGE: return new VCLXContainer;
88
89 case WindowType::TOOLBOX: return new VCLXToolBox;
90 case WindowType::TABCONTROL: return new VCLXMultiPage;
91
92 case WindowType::HEADERBAR: return new VCLXHeaderBar;
93
94 // case WindowType::FIXEDLINE:
95 // case WindowType::FIXEDBITMAP:
96 // case WindowType::DATEBOX:
97 // case WindowType::GROUPBOX:
98 // case WindowType::LONGCURRENCYBOX:
99 // case WindowType::SPLITTER:
100 // case WindowType::STATUSBAR:
101 // case WindowType::TABCONTROL:
102 // case WindowType::NUMERICBOX:
103 // case WindowType::TRISTATEBOX:
104 // case WindowType::TIMEBOX:
105 // case WindowType::SPLITWINDOW:
106 // case WindowType::SCROLLBARBOX:
107 // case WindowType::PATTERNBOX:
108 // case WindowType::CURRENCYBOX:
109 default: return new VCLXWindow( true );
110 }
111}
112
113
114
115
116extern "C" {
117
119{
120 return new UnoWrapper( nullptr );
121}
122
123} // extern "C"
124
125
126UnoWrapper::UnoWrapper( const css::uno::Reference< css::awt::XToolkit>& rxToolkit )
127{
128 mxToolkit = rxToolkit;
129}
130
132{
133 delete this;
134}
135
137{
138}
139
140css::uno::Reference< css::awt::XToolkit> UnoWrapper::GetVCLToolkit()
141{
142 if ( !mxToolkit.is() )
144 return mxToolkit;
145}
146
147css::uno::Reference< css::awt::XVclWindowPeer> UnoWrapper::GetWindowInterface( vcl::Window* pWindow )
148{
149 css::uno::Reference< css::awt::XVclWindowPeer> xPeer = pWindow->GetWindowPeer();
150 if ( xPeer )
151 return xPeer;
152
153 rtl::Reference<VCLXWindow> xVCLXWindow = CreateXWindow( pWindow );
154 xVCLXWindow->SetWindow( pWindow );
155 pWindow->SetWindowPeer( xVCLXWindow, xVCLXWindow.get() );
156 return xVCLXWindow;
157}
158
159VclPtr<vcl::Window> UnoWrapper::GetWindow(const css::uno::Reference<css::awt::XWindow>& rWindow)
160{
161 return VCLUnoHelper::GetWindow(rWindow);
162}
163
164void UnoWrapper::SetWindowInterface( vcl::Window* pWindow, const css::uno::Reference< css::awt::XVclWindowPeer> & xIFace )
165{
166 VCLXWindow* pVCLXWindow = dynamic_cast<VCLXWindow*>( xIFace.get() );
167
168 assert( pVCLXWindow && "must be a VCLXWindow subclass" );
169 if ( !pVCLXWindow )
170 return;
171
172 if (!pWindow)
173 {
174 // we are disconnecting a peer from a window
175 pVCLXWindow->SetWindow( nullptr );
176 }
177 else
178 {
179 css::uno::Reference< css::awt::XVclWindowPeer> xPeer = pWindow->GetWindowPeer();
180 if( xPeer.is() )
181 {
182 bool bSameInstance( pVCLXWindow == dynamic_cast< VCLXWindow* >( xPeer.get() ));
183 SAL_WARN_IF( !bSameInstance, "toolkit.helper", "UnoWrapper::SetWindowInterface: there is already a WindowPeer/ComponentInterface for this VCL window" );
184 if ( bSameInstance )
185 return;
186 }
187 pVCLXWindow->SetWindow( pWindow );
188 pWindow->SetWindowPeer( xIFace, pVCLXWindow );
189 }
190}
191
192css::uno::Reference<css::awt::XPopupMenu> UnoWrapper::CreateMenuInterface( PopupMenu* pPopupMenu )
193{
194 return new VCLXPopupMenu(pPopupMenu);
195}
196
197css::uno::Reference< css::awt::XGraphics> UnoWrapper::CreateGraphics( OutputDevice* pOutDev )
198{
200 pGrf->Init( pOutDev );
201 return pGrf;
202}
203
205{
206 std::vector< VCLXGraphics* > *pLst = pOutDev->GetUnoGraphicsList();
207 if ( pLst )
208 {
209 for (VCLXGraphics* pGrf : *pLst)
210 {
211 pGrf->SetOutputDevice( nullptr );
212 }
213 }
214
215}
216
217static bool lcl_ImplIsParent( vcl::Window const * pParentWindow, vcl::Window* pPossibleChild )
218{
219 vcl::Window* pWindow = ( pPossibleChild != pParentWindow ) ? pPossibleChild : nullptr;
220 while ( pWindow && ( pWindow != pParentWindow ) )
221 pWindow = pWindow->GetParent();
222
223 return pWindow != nullptr;
224}
225
227{
228 // their still might be some children created with css::loader::Java
229 // that would otherwise not be destroyed until the garbage collector cleans up
230 VclPtr< vcl::Window > pChild = pWindow->GetWindow( GetWindowType::FirstChild );
231 while ( pChild )
232 {
233 VclPtr< vcl::Window > pNextChild = pChild->GetWindow( GetWindowType::Next );
234
235 VclPtr< vcl::Window > pClient = pChild->GetWindow( GetWindowType::Client );
236 if ( pClient && pClient->GetWindowPeer() )
237 {
238 css::uno::Reference< css::lang::XComponent > xComp = pClient->GetComponentInterface( false );
239 xComp->dispose();
240 }
241 else
242 {
243 // We need it to dispose the child windows properly (even without window peer),
244 // otherwise the vcl::Window will be leaked.
245 pClient.disposeAndClear();
246 }
247
248 pChild = pNextChild;
249 }
250
251 // find system windows...
252 VclPtr< vcl::Window > pOverlap = pWindow->GetWindow( GetWindowType::Overlap );
253 if ( pOverlap )
254 {
255 pOverlap = pOverlap->GetWindow( GetWindowType::FirstOverlap );
256 while ( pOverlap )
257 {
258 VclPtr< vcl::Window > pNextOverlap = pOverlap->GetWindow( GetWindowType::Next );
259 VclPtr< vcl::Window > pClient = pOverlap->GetWindow( GetWindowType::Client );
260
261 if ( pClient && pClient->GetWindowPeer() && lcl_ImplIsParent( pWindow, pClient ) )
262 {
263 css::uno::Reference< css::lang::XComponent > xComp = pClient->GetComponentInterface( false );
264 xComp->dispose();
265 }
266
267 pOverlap = pNextOverlap;
268 }
269 }
270
271 {
272 VclPtr< vcl::Window > pParent = pWindow->GetParent();
273 if ( pParent && pParent->GetWindowPeer() )
274 pParent->GetWindowPeer()->notifyWindowRemoved( *pWindow );
275 }
276
277 VCLXWindow* pWindowPeer = pWindow->GetWindowPeer();
278 uno::Reference< lang::XComponent > xWindowPeerComp = pWindow->GetComponentInterface( false );
279 OSL_ENSURE( ( pWindowPeer != nullptr ) == xWindowPeerComp.is(),
280 "UnoWrapper::WindowDestroyed: inconsistency in the window's peers!" );
281 if ( pWindowPeer )
282 {
283 pWindowPeer->SetWindow( nullptr );
284 pWindow->SetWindowPeer( nullptr, nullptr );
285 }
286 if ( xWindowPeerComp.is() )
287 xWindowPeerComp->dispose();
288
289 // #102132# Iterate over frames after setting Window peer to NULL,
290 // because while destroying other frames, we get into the method again and try
291 // to destroy this window again...
292 // #i42462#/#116855# no, don't loop: Instead, just ensure that all our top-window-children
293 // are disposed, too (which should also be a valid fix for #102132#, but doesn't have the extreme
294 // performance penalties)
295 VclPtr< vcl::Window > pTopWindowChild = pWindow->GetWindow( GetWindowType::FirstTopWindowChild );
296 while ( pTopWindowChild )
297 {
298 OSL_ENSURE( pTopWindowChild->GetParent() == pWindow,
299 "UnoWrapper::WindowDestroyed: inconsistency in the SystemWindow relationship!" );
300
301 VclPtr< vcl::Window > pNextTopChild = pTopWindowChild->GetWindow( GetWindowType::NextTopWindowSibling );
302
303 pTopWindowChild.disposeAndClear();
304 pTopWindowChild = pNextTopChild;
305 }
306}
307
308
309css::uno::Reference< css::accessibility::XAccessible > UnoWrapper::CreateAccessible( Menu* pMenu, bool bIsMenuBar )
310{
311 return maAccessibleFactoryAccess.getFactory().createAccessible( pMenu, bIsMenuBar );
312}
313
314/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< VCLXGraphics * > * GetUnoGraphicsList() const
void WindowDestroyed(vcl::Window *pWindow) override
Definition: unowrapper.cxx:226
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible(Menu *pMenu, bool bIsMenuBar) override
Definition: unowrapper.cxx:309
css::uno::Reference< css::awt::XToolkit > mxToolkit
Definition: unowrapper.hxx:38
virtual void SetWindowInterface(vcl::Window *pWindow, const css::uno::Reference< css::awt::XVclWindowPeer > &xIFace) override
Definition: unowrapper.cxx:164
UnoWrapper(const css::uno::Reference< css::awt::XToolkit > &rxToolkit)
Definition: unowrapper.cxx:126
virtual VclPtr< vcl::Window > GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow) override
Definition: unowrapper.cxx:159
virtual css::uno::Reference< css::awt::XGraphics > CreateGraphics(OutputDevice *pOutDev) override
Definition: unowrapper.cxx:197
virtual css::uno::Reference< css::awt::XVclWindowPeer > GetWindowInterface(vcl::Window *pWindow) override
Definition: unowrapper.cxx:147
virtual void Destroy() override
Definition: unowrapper.cxx:131
virtual css::uno::Reference< css::awt::XToolkit > GetVCLToolkit() override
Definition: unowrapper.cxx:140
virtual ~UnoWrapper()
Definition: unowrapper.cxx:136
::toolkit::AccessibilityClient maAccessibleFactoryAccess
Definition: unowrapper.hxx:39
virtual void ReleaseAllGraphics(OutputDevice *pOutDev) override
Definition: unowrapper.cxx:204
virtual css::uno::Reference< css::awt::XPopupMenu > CreateMenuInterface(PopupMenu *pPopupMenu) override
Definition: unowrapper.cxx:192
static css::uno::Reference< css::awt::XToolkit > CreateToolkit()
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
virtual void SetWindow(const VclPtr< vcl::Window > &pWindow)
Definition: vclxwindow.cxx:353
void disposeAndClear()
IAccessibleFactory & getFactory()
virtual css::uno::Reference< css::accessibility::XAccessible > createAccessible(Menu *_pMenu, bool _bIsMenuBar)=0
creates an accessible component for the given menu
vcl::Window * GetParent() const
WindowType GetType() const
VCLXWindow * GetWindowPeer() const
vcl::Window * GetWindow(GetWindowType nType) const
virtual css::uno::Reference< css::awt::XVclWindowPeer > GetComponentInterface(bool bCreate=true)
void SetWindowPeer(css::uno::Reference< css::awt::XVclWindowPeer > const &xPeer, VCLXWindow *pVCLXWindow)
#define TOOLKIT_DLLPUBLIC
Definition: dllapi.h:29
#define SAL_WARN_IF(condition, area, stream)
static rtl::Reference< VCLXWindow > CreateXWindow(vcl::Window const *pWindow)
Definition: unowrapper.cxx:36
static bool lcl_ImplIsParent(vcl::Window const *pParentWindow, vcl::Window *pPossibleChild)
Definition: unowrapper.cxx:217
TOOLKIT_DLLPUBLIC UnoWrapperBase * CreateUnoWrapper()
Definition: unowrapper.cxx:118