Bug Summary

File:home/maarten/src/libreoffice/core/include/rtl/ref.hxx
Warning:line 192, column 9
Use of memory after it is freed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name vclxtoolkit.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D TOOLKIT_DLLIMPLEMENTATION -D SVT_DLL_NAME="libsvtlo.so" -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/epoxy/include -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/toolkit/inc -I /home/maarten/src/libreoffice/core/toolkit/source -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx

/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx

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 <sal/config.h>
21
22#include <string_view>
23
24#ifdef _WIN32
25#include <prewin.h>
26#include <postwin.h>
27#endif
28#include <config_features.h>
29#include <com/sun/star/awt/WindowAttribute.hpp>
30#include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
31#include <com/sun/star/awt/WindowClass.hpp>
32#include <com/sun/star/awt/MessageBoxButtons.hpp>
33#include <com/sun/star/lang/XMultiServiceFactory.hpp>
34#include <com/sun/star/lang/SystemDependent.hpp>
35#include <com/sun/star/awt/FocusEvent.hpp>
36#include <com/sun/star/awt/KeyEvent.hpp>
37#include <com/sun/star/awt/KeyModifier.hpp>
38#include <com/sun/star/lang/EventObject.hpp>
39#include <com/sun/star/uno/Reference.hxx>
40#include <com/sun/star/uno/Sequence.hxx>
41#include <com/sun/star/uno/XComponentContext.hpp>
42#include <com/sun/star/uno/XInterface.hpp>
43#include <com/sun/star/beans/NamedValue.hpp>
44#include <com/sun/star/beans/XPropertyChangeListener.hpp>
45#include <com/sun/star/beans/XPropertySet.hpp>
46#include <com/sun/star/datatransfer/clipboard/SystemClipboard.hpp>
47#include <com/sun/star/lang/XServiceInfo.hpp>
48#include <com/sun/star/awt/XToolkitExperimental.hpp>
49#include <com/sun/star/awt/XToolkitRobot.hpp>
50
51#include <cppuhelper/bootstrap.hxx>
52#include <cppuhelper/compbase.hxx>
53#include <cppuhelper/supportsservice.hxx>
54#include <osl/conditn.hxx>
55#include <osl/module.h>
56#include <osl/thread.hxx>
57#include <osl/mutex.hxx>
58#include <rtl/process.h>
59#include <sal/log.hxx>
60#include <tools/link.hxx>
61#include <tools/wintypes.hxx>
62
63#ifdef MACOSX
64#include <premac.h>
65#include <Cocoa/Cocoa.h>
66#include <postmac.h>
67#endif
68
69#include <vcl/sysdata.hxx>
70#include <vcl/textrectinfo.hxx>
71#include <vcl/toolkit/vclmedit.hxx>
72
73#include <toolkit/awt/vclxwindows.hxx>
74#include <awt/vclxsystemdependentwindow.hxx>
75#include <awt/vclxregion.hxx>
76#include <awt/vclxtabpagecontainer.hxx>
77
78#include <awt/animatedimagespeer.hxx>
79#include <toolkit/awt/vclxtopwindow.hxx>
80#include <toolkit/awt/vclxwindow.hxx>
81#include <toolkit/helper/vclunohelper.hxx>
82#include <toolkit/helper/property.hxx>
83
84#include <toolkit/helper/convert.hxx>
85#include <controls/filectrl.hxx>
86#include <controls/svmedit.hxx>
87#include <controls/treecontrolpeer.hxx>
88#include <vcl/toolkit/button.hxx>
89#include <vcl/toolkit/calendar.hxx>
90#include <vcl/toolkit/combobox.hxx>
91#include <vcl/ctrl.hxx>
92#include <vcl/toolkit/dialog.hxx>
93#include <vcl/dockingarea.hxx>
94#include <vcl/dockwin.hxx>
95#include <vcl/toolkit/edit.hxx>
96#include <vcl/event.hxx>
97#include <vcl/toolkit/field.hxx>
98#include <vcl/toolkit/fixed.hxx>
99#include <vcl/toolkit/fixedhyper.hxx>
100#include <vcl/floatwin.hxx>
101#include <vcl/toolkit/fmtfield.hxx>
102#include <vcl/toolkit/prgsbar.hxx>
103#include <vcl/scheduler.hxx>
104#include <vcl/toolkit/lstbox.hxx>
105#include <vcl/toolkit/longcurr.hxx>
106#include <vcl/menubtn.hxx>
107#include <vcl/stdtext.hxx>
108#include <vcl/scrbar.hxx>
109#include <vcl/split.hxx>
110#include <vcl/splitwin.hxx>
111#include <vcl/status.hxx>
112#include <vcl/svapp.hxx>
113#include <vcl/syschild.hxx>
114#include <vcl/tabctrl.hxx>
115#include <vcl/tabpage.hxx>
116#include <vcl/toolbox.hxx>
117#include <vcl/virdev.hxx>
118#include <vcl/window.hxx>
119#include <vcl/wrkwin.hxx>
120#include <vcl/toolkit/group.hxx>
121#include <vcl/toolkit/imgctrl.hxx>
122#include <vcl/toolkit/morebtn.hxx>
123#include <vcl/toolkit/roadmap.hxx>
124#include <vcl/toolkit/spin.hxx>
125#include <vcl/toolkit/tabdlg.hxx>
126#include <vcl/toolkit/throbber.hxx>
127#if HAVE_FEATURE_OPENGL1
128#include <vcl/opengl/OpenGLWrapper.hxx>
129#endif
130#include <awt/vclxspinbutton.hxx>
131#include <tools/debug.hxx>
132#include <tools/diagnose_ex.h>
133#include <comphelper/processfactory.hxx>
134#include <comphelper/profilezone.hxx>
135
136#include <helper/msgbox.hxx>
137#include <helper/scrollabledialog.hxx>
138#include <helper/unowrapper.hxx>
139
140#if defined(_WIN32)
141#define SYSTEM_DEPENDENT_TYPEcss::lang::SystemDependent::SYSTEM_XWINDOW css::lang::SystemDependent::SYSTEM_WIN32
142#elif defined(MACOSX)
143#define SYSTEM_DEPENDENT_TYPEcss::lang::SystemDependent::SYSTEM_XWINDOW css::lang::SystemDependent::SYSTEM_MAC
144#elif defined(UNX1)
145#define SYSTEM_DEPENDENT_TYPEcss::lang::SystemDependent::SYSTEM_XWINDOW css::lang::SystemDependent::SYSTEM_XWINDOW
146#endif
147
148void MessBox::ImplInitButtons()
149{
150 ButtonDialogFlags nOKFlags = ButtonDialogFlags::OK;
151 ButtonDialogFlags nCancelFlags = ButtonDialogFlags::Cancel;
152 ButtonDialogFlags nRetryFlags = ButtonDialogFlags::NONE;
153 ButtonDialogFlags nYesFlags = ButtonDialogFlags::NONE;
154 ButtonDialogFlags nNoFlags = ButtonDialogFlags::NONE;
155
156 if ( mnMessBoxStyle & MessBoxStyle::OkCancel )
157 {
158 if ( mnMessBoxStyle & MessBoxStyle::DefaultCancel )
159 nCancelFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
160 else // MessBoxStyle::DefaultOk
161 nOKFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
162
163 AddButton( StandardButtonType::OK, RET_OK, nOKFlags );
164 AddButton( StandardButtonType::Cancel, RET_CANCEL, nCancelFlags );
165 }
166 else if ( mnMessBoxStyle & MessBoxStyle::YesNo )
167 {
168 if ( mnMessBoxStyle & MessBoxStyle::DefaultYes )
169 nYesFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
170 else // MessBoxStyle::DefaultNo
171 nNoFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
172 nNoFlags |= ButtonDialogFlags::Cancel;
173
174 AddButton( StandardButtonType::Yes, RET_YES, nYesFlags );
175 AddButton( StandardButtonType::No, RET_NO, nNoFlags );
176 }
177 else if ( mnMessBoxStyle & MessBoxStyle::YesNoCancel )
178 {
179 if ( mnMessBoxStyle & MessBoxStyle::DefaultYes )
180 nYesFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
181 else if ( mnMessBoxStyle & MessBoxStyle::DefaultNo )
182 nNoFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
183 else
184 nCancelFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
185
186 AddButton( StandardButtonType::Yes, RET_YES, nYesFlags );
187 AddButton( StandardButtonType::No, RET_NO, nNoFlags );
188 AddButton( StandardButtonType::Cancel, RET_CANCEL, nCancelFlags );
189 }
190 else if ( mnMessBoxStyle & MessBoxStyle::RetryCancel )
191 {
192 if ( mnMessBoxStyle & MessBoxStyle::DefaultCancel )
193 nCancelFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
194 else // MessBoxStyle::DefaultRetry
195 nRetryFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
196
197 AddButton( StandardButtonType::Retry, RET_RETRY, nRetryFlags );
198 AddButton( StandardButtonType::Cancel, RET_CANCEL, nCancelFlags );
199 }
200 else if ( mnMessBoxStyle & MessBoxStyle::AbortRetryIgnore )
201 {
202 ButtonDialogFlags nAbortFlags = ButtonDialogFlags::NONE;
203 ButtonDialogFlags nIgnoreFlags = ButtonDialogFlags::NONE;
204
205 if ( mnMessBoxStyle & MessBoxStyle::DefaultCancel )
206 nAbortFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
207 else if ( mnMessBoxStyle & MessBoxStyle::DefaultRetry )
208 nRetryFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
209 else if ( mnMessBoxStyle & MessBoxStyle::DefaultIgnore )
210 nIgnoreFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
211
212 AddButton( StandardButtonType::Abort, RET_CANCEL, nAbortFlags );
213 AddButton( StandardButtonType::Retry, RET_RETRY, nRetryFlags );
214 AddButton( StandardButtonType::Ignore, RET_IGNORE, nIgnoreFlags );
215 }
216 else if ( mnMessBoxStyle & MessBoxStyle::Ok )
217 {
218 nOKFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
219
220 AddButton( StandardButtonType::OK, RET_OK, nOKFlags );
221 }
222}
223
224MessBox::MessBox(vcl::Window* pParent, MessBoxStyle nMessBoxStyle, WinBits nWinBits,
225 const OUString& rTitle, const OUString& rMessage) :
226 ButtonDialog( WindowType::MESSBOX ),
227 mbHelpBtn( false ),
228 mnMessBoxStyle( nMessBoxStyle ),
229 maMessText( rMessage )
230{
231 ImplLOKNotifier(pParent);
232 ImplInitDialog(pParent, nWinBits | WB_MOVEABLE | WB_HORZ | WB_CENTER);
233 ImplInitButtons();
234
235 if ( !rTitle.isEmpty() )
236 SetText( rTitle );
237}
238
239MessBox::~MessBox()
240{
241 disposeOnce();
242}
243
244void MessBox::dispose()
245{
246 mpVCLMultiLineEdit.disposeAndClear();
247 mpFixedImage.disposeAndClear();
1
Calling 'VclPtr::disposeAndClear'
248 ButtonDialog::dispose();
249}
250
251void MessBox::ImplPosControls()
252{
253 if ( !GetHelpId().isEmpty() )
254 {
255 if ( !mbHelpBtn )
256 {
257 AddButton( StandardButtonType::Help, RET_HELP, ButtonDialogFlags::Help, 3 );
258 mbHelpBtn = true;
259 }
260 }
261 else
262 {
263 if ( mbHelpBtn )
264 {
265 RemoveButton( RET_HELP );
266 mbHelpBtn = false;
267 }
268 }
269
270 TextRectInfo aTextInfo;
271 tools::Rectangle aRect( 0, 0, 30000, 30000 );
272 tools::Rectangle aFormatRect;
273 Point aTextPos( IMPL_DIALOG_OFFSET5, IMPL_DIALOG_OFFSET5+IMPL_MSGBOX_OFFSET_EXTRA_Y2 );
274 Size aImageSize;
275 Size aPageSize;
276 Size aMEditSize;
277 long nTitleWidth;
278 long nButtonSize = ImplGetButtonSize();
279 long nMaxLineWidth;
280 long nWidth;
281 WinBits nWinStyle = WB_LEFT | WB_NOLABEL;
282 DrawTextFlags nTextStyle = DrawTextFlags::MultiLine | DrawTextFlags::Top | DrawTextFlags::Left;
283
284 mpVCLMultiLineEdit.disposeAndClear();
285 mpFixedImage.disposeAndClear();
286
287 // Clean up message text with tabs
288 OUString aMessText(maMessText.replaceAll("\t", " "));
289
290 //If window too small, we make dialog box be wider
291 long nMaxWidth = 630 * GetDPIScaleFactor();
292
293 // MessagBox should be at least as wide as to see the title
294 // Extra-Width for Close button, because Close button is set after this call
295 nTitleWidth = CalcTitleWidth();
296
297 nMaxWidth -= (IMPL_DIALOG_OFFSET5*2)+(IMPL_MSGBOX_OFFSET_EXTRA_X0*2);
298
299 // for an image, get its size, create a suitable control and position it
300 aImageSize = maImage.GetSizePixel();
301 if ( aImageSize.Width() )
302 {
303 aImageSize.AdjustWidth(4 );
304 aImageSize.AdjustHeight(4 );
305 aTextPos.AdjustX(aImageSize.Width()+IMPL_SEP_MSGBOX_IMAGE8 );
306 mpFixedImage = VclPtr<FixedImage>::Create( this );
307 mpFixedImage->SetPosSizePixel( Point( IMPL_DIALOG_OFFSET5-2+IMPL_MSGBOX_OFFSET_EXTRA_X0,
308 IMPL_DIALOG_OFFSET5-2+IMPL_MSGBOX_OFFSET_EXTRA_Y2 ),
309 aImageSize );
310 mpFixedImage->SetImage( maImage );
311 mpFixedImage->Show();
312 nMaxWidth -= aImageSize.Width()+IMPL_SEP_MSGBOX_IMAGE8;
313 }
314 else
315 aTextPos.AdjustX(IMPL_MSGBOX_OFFSET_EXTRA_X0 );
316
317 // Determine maximum line length without wordbreak
318 aFormatRect = GetTextRect( aRect, aMessText, nTextStyle, &aTextInfo );
319 nMaxLineWidth = aFormatRect.GetWidth();
320 nTextStyle |= DrawTextFlags::WordBreak;
321
322 // Determine the width for text formatting
323 if ( nMaxLineWidth > 450 )
324 nWidth = 450;
325 else if ( nMaxLineWidth > 300 )
326 nWidth = nMaxLineWidth+5;
327 else
328 nWidth = 300;
329
330 nWidth *= GetDPIScaleFactor();
331
332 if ( nButtonSize > nWidth )
333 nWidth = nButtonSize-(aTextPos.X()-IMPL_DIALOG_OFFSET5);
334 if ( nWidth > nMaxWidth )
335 nWidth = nMaxWidth;
336
337 aRect.SetRight( nWidth );
338 aFormatRect = GetTextRect( aRect, aMessText, nTextStyle, &aTextInfo );
339 if ( aTextInfo.GetMaxLineWidth() > nWidth )
340 {
341 nWidth = aTextInfo.GetMaxLineWidth()+8;
342 aRect.SetRight( nWidth );
343 aFormatRect = GetTextRect( aRect, aMessText, nTextStyle, &aTextInfo );
344 }
345
346 // get Style for VCLMultiLineEdit
347 aMEditSize.setWidth( aTextInfo.GetMaxLineWidth()+1 );
348 aMEditSize.setHeight( aFormatRect.GetHeight() );
349 aPageSize.setWidth( aImageSize.Width() );
350 if ( aMEditSize.Height() < aImageSize.Height() )
351 {
352 nWinStyle |= WB_VCENTER;
353 aPageSize.setHeight( aImageSize.Height() );
354 aMEditSize.setHeight( aImageSize.Height() );
355 }
356 else
357 {
358 nWinStyle |= WB_TOP;
359 aPageSize.setHeight( aMEditSize.Height() );
360 }
361 if ( aImageSize.Width() )
362 aPageSize.AdjustWidth(IMPL_SEP_MSGBOX_IMAGE8 );
363 aPageSize.AdjustWidth((IMPL_DIALOG_OFFSET5*2)+(IMPL_MSGBOX_OFFSET_EXTRA_X0*2) );
364 aPageSize.AdjustWidth(aMEditSize.Width()+1 );
365 aPageSize.AdjustHeight((IMPL_DIALOG_OFFSET5*2)+(IMPL_MSGBOX_OFFSET_EXTRA_Y2*2) );
366
367 if ( aPageSize.Width() < IMPL_MINSIZE_MSGBOX_WIDTH150 )
368 aPageSize.setWidth( IMPL_MINSIZE_MSGBOX_WIDTH150 );
369 if ( aPageSize.Width() < nTitleWidth )
370 aPageSize.setWidth( nTitleWidth );
371
372 mpVCLMultiLineEdit = VclPtr<VclMultiLineEdit>::Create( this, nWinStyle );
373 mpVCLMultiLineEdit->SetText( aMessText );
374 mpVCLMultiLineEdit->SetPosSizePixel( aTextPos, aMEditSize );
375 mpVCLMultiLineEdit->Show();
376 mpVCLMultiLineEdit->SetPaintTransparent(true);
377 mpVCLMultiLineEdit->EnableCursor(false);
378 SetPageSizePixel( aPageSize );
379}
380
381void MessBox::StateChanged( StateChangedType nType )
382{
383 if ( nType == StateChangedType::InitShow )
384 {
385 ImplPosControls();
386 }
387 ButtonDialog::StateChanged( nType );
388}
389
390Size MessBox::GetOptimalSize() const
391{
392 // FIXME: base me on the font size ?
393 return Size( 250, 100 );
394}
395
396
397namespace {
398
399extern "C" typedef vcl::Window* (*FN_SvtCreateWindow)(
400 VCLXWindow** ppNewComp,
401 const css::awt::WindowDescriptor* pDescriptor,
402 vcl::Window* pParent,
403 WinBits nWinBits );
404
405class Pause : public Idle
406{
407public:
408 explicit Pause(sal_Int32 nPauseMilliseconds) :
409 Idle("pause"),
410 m_nPauseMilliseconds(nPauseMilliseconds)
411 {
412 SetPriority(TaskPriority::HIGHEST);
413 Start();
414 }
415
416 virtual void Invoke() override
417 {
418 SolarMutexGuard aSolarGuard;
419 osl::Thread::wait(std::chrono::milliseconds(m_nPauseMilliseconds));
420 Stop();
421 delete this;
422 }
423
424 sal_Int32 m_nPauseMilliseconds;
425};
426
427class VCLXToolkitMutexHelper
428{
429protected:
430 ::osl::Mutex maMutex;
431};
432
433class VCLXToolkit : public VCLXToolkitMutexHelper,
434 public cppu::WeakComponentImplHelper<
435 css::awt::XToolkitExperimental,
436 css::awt::XToolkitRobot,
437 css::lang::XServiceInfo >
438{
439 css::uno::Reference< css::datatransfer::clipboard::XClipboard > mxClipboard;
440 css::uno::Reference< css::datatransfer::clipboard::XClipboard > mxSelection;
441
442 oslModule hSvToolsLib;
443 FN_SvtCreateWindow fnSvtCreateWindow;
444
445 ::comphelper::OInterfaceContainerHelper2 m_aTopWindowListeners;
446 ::comphelper::OInterfaceContainerHelper2 m_aKeyHandlers;
447 ::comphelper::OInterfaceContainerHelper2 m_aFocusListeners;
448 ::Link<VclSimpleEvent&,void> m_aEventListenerLink;
449 ::Link<VclWindowEvent&,bool> m_aKeyListenerLink;
450 bool m_bEventListener;
451 bool m_bKeyListener;
452
453 DECL_LINK(eventListenerHandler, ::VclSimpleEvent&, void)static void LinkStubeventListenerHandler(void *, ::VclSimpleEvent
&); void eventListenerHandler(::VclSimpleEvent&)
;
454
455 DECL_LINK(keyListenerHandler, ::VclWindowEvent&, bool)static bool LinkStubkeyListenerHandler(void *, ::VclWindowEvent
&); bool keyListenerHandler(::VclWindowEvent&)
;
456
457 void callTopWindowListeners(
458 ::VclSimpleEvent const * pEvent,
459 void (SAL_CALL css::awt::XTopWindowListener::* pFn)(
460 css::lang::EventObject const &));
461
462 bool callKeyHandlers(::VclSimpleEvent const * pEvent, bool bPressed);
463
464 void callFocusListeners(::VclSimpleEvent const * pEvent, bool bGained);
465
466protected:
467 ::osl::Mutex& GetMutex() { return maMutex; }
468
469 virtual void SAL_CALL disposing() override;
470
471 static vcl::Window* ImplCreateWindow( VCLXWindow** ppNewComp, const css::awt::WindowDescriptor& rDescriptor, vcl::Window* pParent,
472 WinBits nWinBits, MessBoxStyle nMessBoxStyle );
473 css::uno::Reference< css::awt::XWindowPeer > ImplCreateWindow( const css::awt::WindowDescriptor& Descriptor,
474 MessBoxStyle nForceMessBoxStyle );
475
476public:
477
478 VCLXToolkit();
479
480 // css::awt::XToolkitExperimental
481 virtual void SAL_CALL processEventsToIdle() override;
482
483 virtual sal_Int64 SAL_CALL getOpenGLBufferSwapCounter() override;
484
485 virtual void SAL_CALL setDeterministicScheduling(sal_Bool bDeterministicMode) override;
486
487 virtual void SAL_CALL pause(sal_Int32 nMilliseconds) override;
488
489 virtual void SAL_CALL startRecording() override;
490
491 virtual void SAL_CALL stopRecording() override;
492
493 css::uno::Sequence< OUString > SAL_CALL getRecordingAndClear() override;
494
495 // css::awt::XToolkit
496 css::uno::Reference< css::awt::XWindowPeer > SAL_CALL getDesktopWindow( ) override;
497 css::awt::Rectangle SAL_CALL getWorkArea( ) override;
498 css::uno::Reference< css::awt::XWindowPeer > SAL_CALL createWindow( const css::awt::WindowDescriptor& Descriptor ) override;
499 css::uno::Sequence< css::uno::Reference< css::awt::XWindowPeer > > SAL_CALL createWindows( const css::uno::Sequence< css::awt::WindowDescriptor >& Descriptors ) override;
500 css::uno::Reference< css::awt::XDevice > SAL_CALL createScreenCompatibleDevice( sal_Int32 Width, sal_Int32 Height ) override;
501 css::uno::Reference< css::awt::XRegion > SAL_CALL createRegion( ) override;
502
503 // css::awt::XSystemChildFactory
504 css::uno::Reference< css::awt::XWindowPeer > SAL_CALL createSystemChild( const css::uno::Any& Parent, const css::uno::Sequence< sal_Int8 >& ProcessId, sal_Int16 SystemType ) override;
505
506 // css::awt::XMessageBoxFactory
507 virtual css::uno::Reference< css::awt::XMessageBox > SAL_CALL createMessageBox( const css::uno::Reference< css::awt::XWindowPeer >& aParent, css::awt::MessageBoxType eType, ::sal_Int32 aButtons, const OUString& aTitle, const OUString& aMessage ) override;
508
509 // css::awt::XDataTransfer
510 css::uno::Reference< css::datatransfer::dnd::XDragGestureRecognizer > SAL_CALL getDragGestureRecognizer( const css::uno::Reference< css::awt::XWindow >& window ) override;
511 css::uno::Reference< css::datatransfer::dnd::XDragSource > SAL_CALL getDragSource( const css::uno::Reference< css::awt::XWindow >& window ) override;
512 css::uno::Reference< css::datatransfer::dnd::XDropTarget > SAL_CALL getDropTarget( const css::uno::Reference< css::awt::XWindow >& window ) override;
513 css::uno::Reference< css::datatransfer::clipboard::XClipboard > SAL_CALL getClipboard( const OUString& clipboardName ) override;
514
515 // css::lang::XServiceInfo
516 OUString SAL_CALL getImplementationName( ) override;
517 sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
518 css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
519
520 // css::awt::XExtendedToolkit:
521
522 virtual ::sal_Int32 SAL_CALL getTopWindowCount() override;
523
524 virtual css::uno::Reference< css::awt::XTopWindow >
525 SAL_CALL getTopWindow(::sal_Int32 nIndex) override;
526
527 virtual css::uno::Reference< css::awt::XTopWindow >
528 SAL_CALL getActiveTopWindow() override;
529
530 virtual void SAL_CALL addTopWindowListener(
531 css::uno::Reference<
532 css::awt::XTopWindowListener > const & rListener) override;
533
534 virtual void SAL_CALL removeTopWindowListener(
535 css::uno::Reference<
536 css::awt::XTopWindowListener > const & rListener) override;
537
538 virtual void SAL_CALL addKeyHandler(
539 css::uno::Reference<
540 css::awt::XKeyHandler > const & rHandler) override;
541
542 virtual void SAL_CALL removeKeyHandler(
543 css::uno::Reference<
544 css::awt::XKeyHandler > const & rHandler) override;
545
546 virtual void SAL_CALL addFocusListener(
547 css::uno::Reference<
548 css::awt::XFocusListener > const & rListener) override;
549
550 virtual void SAL_CALL removeFocusListener(
551 css::uno::Reference<
552 css::awt::XFocusListener > const & rListener) override;
553
554 virtual void SAL_CALL fireFocusGained(
555 css::uno::Reference<
556 css::uno::XInterface > const & source) override;
557
558 virtual void SAL_CALL fireFocusLost(
559 css::uno::Reference<
560 css::uno::XInterface > const & source) override;
561
562 // css::awt::XReschedule:
563 virtual void SAL_CALL reschedule() override;
564
565 // css:awt:XToolkitRobot
566 virtual void SAL_CALL keyPress( const css::awt::KeyEvent & aKeyEvent ) override;
567
568 virtual void SAL_CALL keyRelease( const css::awt::KeyEvent & aKeyEvent ) override;
569
570 virtual void SAL_CALL mousePress( const css::awt::MouseEvent & aMouseEvent ) override;
571
572 virtual void SAL_CALL mouseRelease( const css::awt::MouseEvent & aMouseEvent ) override;
573
574 virtual void SAL_CALL mouseMove( const css::awt::MouseEvent & aMouseEvent ) override;
575
576};
577
578std::pair<WinBits,MessBoxStyle> ImplGetWinBits( sal_uInt32 nComponentAttribs, WindowType nCompType )
579{
580 WinBits nWinBits = 0;
581 MessBoxStyle nStyle = MessBoxStyle::NONE;
582
583 bool bMessBox = false;
584 if ( ( nCompType == WindowType::INFOBOX ) ||
585 ( nCompType == WindowType::MESSBOX ) ||
586 ( nCompType == WindowType::QUERYBOX ) ||
587 ( nCompType == WindowType::WARNINGBOX ) ||
588 ( nCompType == WindowType::ERRORBOX ) )
589 {
590 bMessBox = true;
591 }
592
593 bool bDecoratedWindow = false;
594 if ( bMessBox
595 || ( nCompType == WindowType::DIALOG )
596 || ( nCompType == WindowType::MODELESSDIALOG )
597 || ( nCompType == WindowType::DOCKINGWINDOW )
598 || ( nCompType == WindowType::TABDIALOG )
599 || ( nCompType == WindowType::BUTTONDIALOG )
600 || ( nCompType == WindowType::SYSTEMCHILDWINDOW )
601 )
602 {
603 bDecoratedWindow = true;
604 }
605
606 if( nComponentAttribs & css::awt::WindowAttribute::BORDER )
607 nWinBits |= WB_BORDER;
608 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::NOBORDER )
609 nWinBits |= WB_NOBORDER;
610 if( nComponentAttribs & css::awt::WindowAttribute::SIZEABLE )
611 nWinBits |= WB_SIZEABLE;
612 if( nComponentAttribs & css::awt::WindowAttribute::MOVEABLE )
613 nWinBits |= WB_MOVEABLE;
614 if( nComponentAttribs & css::awt::WindowAttribute::CLOSEABLE )
615 nWinBits |= WB_CLOSEABLE;
616 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::HSCROLL )
617 nWinBits |= WB_HSCROLL;
618 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::VSCROLL )
619 nWinBits |= WB_VSCROLL;
620 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::LEFT )
621 nWinBits |= WB_LEFT;
622 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::CENTER )
623 nWinBits |= WB_CENTER;
624 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::RIGHT )
625 nWinBits |= WB_RIGHT;
626 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::SPIN )
627 nWinBits |= WB_SPIN;
628 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::SORT )
629 nWinBits |= WB_SORT;
630 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DROPDOWN )
631 nWinBits |= WB_DROPDOWN;
632 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEFBUTTON )
633 nWinBits |= WB_DEFBUTTON;
634 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::READONLY )
635 nWinBits |= WB_READONLY;
636 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::CLIPCHILDREN )
637 nWinBits |= WB_CLIPCHILDREN;
638 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::GROUP )
639 nWinBits |= WB_GROUP;
640 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::NOLABEL ) //added for issue79712
641 nWinBits |= WB_NOLABEL;
642
643 // These bits are not unique
644 if ( bMessBox )
645 {
646 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::OK )
647 nStyle |= MessBoxStyle::Ok;
648 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::OK_CANCEL )
649 nStyle |= MessBoxStyle::OkCancel;
650 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::YES_NO )
651 nStyle |= MessBoxStyle::YesNo;
652 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::YES_NO_CANCEL )
653 nStyle |= MessBoxStyle::YesNoCancel;
654 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::RETRY_CANCEL )
655 nStyle |= MessBoxStyle::RetryCancel;
656 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEF_OK )
657 nStyle |= MessBoxStyle::DefaultOk;
658 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEF_CANCEL )
659 nStyle |= MessBoxStyle::DefaultCancel;
660 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEF_RETRY )
661 nStyle |= MessBoxStyle::DefaultRetry;
662 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEF_YES )
663 nStyle |= MessBoxStyle::DefaultYes;
664 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEF_NO )
665 nStyle |= MessBoxStyle::DefaultNo;
666 }
667 if ( nCompType == WindowType::MULTILINEEDIT || nCompType == WindowType::DIALOG || nCompType == WindowType::GROUPBOX )
668 {
669 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::AUTOHSCROLL )
670 nWinBits |= WB_AUTOHSCROLL;
671 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::AUTOVSCROLL )
672 nWinBits |= WB_AUTOVSCROLL;
673 }
674
675
676 if ( bDecoratedWindow )
677 {
678 if( nComponentAttribs & css::awt::WindowAttribute::NODECORATION )
679 {
680 // No decoration removes several window attributes and must
681 // set WB_NOBORDER!
682 nWinBits &= ~WB_BORDER;
683 nWinBits &= ~WB_SIZEABLE;
684 nWinBits &= ~WB_MOVEABLE;
685 nWinBits &= ~WB_CLOSEABLE;
686 nWinBits |= WB_NOBORDER;
687 }
688 }
689
690 return { nWinBits, nStyle };
691}
692
693struct ComponentInfo
694{
695 std::u16string_view sName;
696 WindowType nWinType;
697};
698
699ComponentInfo const aComponentInfos [] =
700{
701 { std::u16string_view(u"animatedimages"), WindowType::CONTROL },
702 { std::u16string_view(u"buttondialog"), WindowType::BUTTONDIALOG },
703 { std::u16string_view(u"cancelbutton"), WindowType::CANCELBUTTON },
704 { std::u16string_view(u"checkbox"), WindowType::CHECKBOX },
705 { std::u16string_view(u"combobox"), WindowType::COMBOBOX },
706 { std::u16string_view(u"control"), WindowType::CONTROL },
707 { std::u16string_view(u"currencybox"), WindowType::CURRENCYBOX },
708 { std::u16string_view(u"currencyfield"), WindowType::CURRENCYFIELD },
709 { std::u16string_view(u"datebox"), WindowType::DATEBOX },
710 { std::u16string_view(u"datefield"), WindowType::CONTROL },
711 { std::u16string_view(u"dialog"), WindowType::DIALOG },
712 { std::u16string_view(u"dockingarea"), WindowType::DOCKINGAREA },
713 { std::u16string_view(u"dockingwindow"), WindowType::DOCKINGWINDOW },
714 { std::u16string_view(u"edit"), WindowType::EDIT },
715 { std::u16string_view(u"errorbox"), WindowType::ERRORBOX },
716 { std::u16string_view(u"filecontrol"), WindowType::CONTROL },
717 { std::u16string_view(u"fixedbitmap"), WindowType::FIXEDBITMAP },
718 { std::u16string_view(u"fixedhyperlink"), WindowType::CONTROL },
719 { std::u16string_view(u"fixedimage"), WindowType::FIXEDIMAGE },
720 { std::u16string_view(u"fixedline"), WindowType::FIXEDLINE },
721 { std::u16string_view(u"fixedtext"), WindowType::FIXEDTEXT },
722 { std::u16string_view(u"floatingwindow"), WindowType::FLOATINGWINDOW },
723 { std::u16string_view(u"formattedfield"), WindowType::CONTROL },
724 { std::u16string_view(u"frame"), WindowType::GROUPBOX },
725 { std::u16string_view(u"framewindow"), WindowType::TOOLKIT_FRAMEWINDOW },
726 { std::u16string_view(u"groupbox"), WindowType::GROUPBOX },
727 { std::u16string_view(u"helpbutton"), WindowType::HELPBUTTON },
728 { std::u16string_view(u"imagebutton"), WindowType::IMAGEBUTTON },
729 { std::u16string_view(u"infobox"), WindowType::INFOBOX },
730 { std::u16string_view(u"listbox"), WindowType::LISTBOX },
731 { std::u16string_view(u"longcurrencybox"), WindowType::LONGCURRENCYBOX },
732 { std::u16string_view(u"longcurrencyfield"), WindowType::CONTROL },
733 { std::u16string_view(u"menubutton"), WindowType::MENUBUTTON },
734 { std::u16string_view(u"messbox"), WindowType::MESSBOX },
735 { std::u16string_view(u"metricbox"), WindowType::METRICBOX },
736 { std::u16string_view(u"metricfield"), WindowType::METRICFIELD },
737 { std::u16string_view(u"modelessdialog"), WindowType::MODELESSDIALOG },
738 { std::u16string_view(u"morebutton"), WindowType::MOREBUTTON },
739 { std::u16string_view(u"multilineedit"), WindowType::MULTILINEEDIT },
740 { std::u16string_view(u"multilistbox"), WindowType::MULTILISTBOX },
741 { std::u16string_view(u"numericbox"), WindowType::NUMERICBOX },
742 { std::u16string_view(u"numericfield"), WindowType::CONTROL },
743 { std::u16string_view(u"okbutton"), WindowType::OKBUTTON },
744 { std::u16string_view(u"patternbox"), WindowType::PATTERNBOX },
745 { std::u16string_view(u"patternfield"), WindowType::PATTERNFIELD },
746 { std::u16string_view(u"progressbar"), WindowType::CONTROL },
747 { std::u16string_view(u"pushbutton"), WindowType::PUSHBUTTON },
748 { std::u16string_view(u"querybox"), WindowType::QUERYBOX },
749 { std::u16string_view(u"radiobutton"), WindowType::RADIOBUTTON },
750 { std::u16string_view(u"roadmap"), WindowType::CONTROL },
751 { std::u16string_view(u"scrollbar"), WindowType::SCROLLBAR },
752 { std::u16string_view(u"scrollbarbox"), WindowType::SCROLLBARBOX },
753 { std::u16string_view(u"spinbutton"), WindowType::SPINBUTTON },
754 { std::u16string_view(u"spinfield"), WindowType::SPINFIELD },
755 { std::u16string_view(u"splitter"), WindowType::SPLITTER },
756 { std::u16string_view(u"splitwindow"), WindowType::SPLITWINDOW },
757 { std::u16string_view(u"statusbar"), WindowType::STATUSBAR },
758 { std::u16string_view(u"systemchildwindow"), WindowType::TOOLKIT_SYSTEMCHILDWINDOW },
759 { std::u16string_view(u"tabcontrol"), WindowType::TABCONTROL },
760 { std::u16string_view(u"tabdialog"), WindowType::TABDIALOG },
761 { std::u16string_view(u"tabpage"), WindowType::TABPAGE },
762 { std::u16string_view(u"tabpagecontainer"), WindowType::CONTROL },
763 { std::u16string_view(u"tabpagemodel"), WindowType::TABPAGE },
764 { std::u16string_view(u"timebox"), WindowType::TIMEBOX },
765 { std::u16string_view(u"timefield"), WindowType::TIMEFIELD },
766 { std::u16string_view(u"toolbox"), WindowType::TOOLBOX },
767 { std::u16string_view(u"tree"), WindowType::CONTROL },
768 { std::u16string_view(u"tristatebox"), WindowType::TRISTATEBOX },
769 { std::u16string_view(u"warningbox"), WindowType::WARNINGBOX },
770 { std::u16string_view(u"window"), WindowType::WINDOW },
771 { std::u16string_view(u"workwindow"), WindowType::WORKWINDOW }
772};
773
774bool ComponentInfoFindCompare( const ComponentInfo & lhs, const OUString & s)
775{
776 return rtl_ustr_compareIgnoreAsciiCase_WithLength(s.pData->buffer, s.pData->length,
777 lhs.sName.data(), lhs.sName.size()) > 0;
778}
779
780WindowType ImplGetComponentType( const OUString& rServiceName )
781{
782 static bool bSorted = false;
783 if( !bSorted )
784 {
785 assert( std::is_sorted( std::begin(aComponentInfos), std::end(aComponentInfos),(static_cast <bool> (std::is_sorted( std::begin(aComponentInfos
), std::end(aComponentInfos), [](const ComponentInfo & lhs
, const ComponentInfo & rhs) { return rtl_ustr_compare_WithLength
( lhs.sName.data(), lhs.sName.size(), rhs.sName.data(), rhs.sName
.size()) < 0; } )) ? void (0) : __assert_fail ("std::is_sorted( std::begin(aComponentInfos), std::end(aComponentInfos), [](const ComponentInfo & lhs, const ComponentInfo & rhs) { return rtl_ustr_compare_WithLength( lhs.sName.data(), lhs.sName.size(), rhs.sName.data(), rhs.sName.size()) < 0; } )"
, "/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
, 792, __extension__ __PRETTY_FUNCTION__))
786 [](const ComponentInfo & lhs, const ComponentInfo & rhs) {(static_cast <bool> (std::is_sorted( std::begin(aComponentInfos
), std::end(aComponentInfos), [](const ComponentInfo & lhs
, const ComponentInfo & rhs) { return rtl_ustr_compare_WithLength
( lhs.sName.data(), lhs.sName.size(), rhs.sName.data(), rhs.sName
.size()) < 0; } )) ? void (0) : __assert_fail ("std::is_sorted( std::begin(aComponentInfos), std::end(aComponentInfos), [](const ComponentInfo & lhs, const ComponentInfo & rhs) { return rtl_ustr_compare_WithLength( lhs.sName.data(), lhs.sName.size(), rhs.sName.data(), rhs.sName.size()) < 0; } )"
, "/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
, 792, __extension__ __PRETTY_FUNCTION__))
787 return(static_cast <bool> (std::is_sorted( std::begin(aComponentInfos
), std::end(aComponentInfos), [](const ComponentInfo & lhs
, const ComponentInfo & rhs) { return rtl_ustr_compare_WithLength
( lhs.sName.data(), lhs.sName.size(), rhs.sName.data(), rhs.sName
.size()) < 0; } )) ? void (0) : __assert_fail ("std::is_sorted( std::begin(aComponentInfos), std::end(aComponentInfos), [](const ComponentInfo & lhs, const ComponentInfo & rhs) { return rtl_ustr_compare_WithLength( lhs.sName.data(), lhs.sName.size(), rhs.sName.data(), rhs.sName.size()) < 0; } )"
, "/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
, 792, __extension__ __PRETTY_FUNCTION__))
788 rtl_ustr_compare_WithLength((static_cast <bool> (std::is_sorted( std::begin(aComponentInfos
), std::end(aComponentInfos), [](const ComponentInfo & lhs
, const ComponentInfo & rhs) { return rtl_ustr_compare_WithLength
( lhs.sName.data(), lhs.sName.size(), rhs.sName.data(), rhs.sName
.size()) < 0; } )) ? void (0) : __assert_fail ("std::is_sorted( std::begin(aComponentInfos), std::end(aComponentInfos), [](const ComponentInfo & lhs, const ComponentInfo & rhs) { return rtl_ustr_compare_WithLength( lhs.sName.data(), lhs.sName.size(), rhs.sName.data(), rhs.sName.size()) < 0; } )"
, "/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
, 792, __extension__ __PRETTY_FUNCTION__))
789 lhs.sName.data(), lhs.sName.size(), rhs.sName.data(),(static_cast <bool> (std::is_sorted( std::begin(aComponentInfos
), std::end(aComponentInfos), [](const ComponentInfo & lhs
, const ComponentInfo & rhs) { return rtl_ustr_compare_WithLength
( lhs.sName.data(), lhs.sName.size(), rhs.sName.data(), rhs.sName
.size()) < 0; } )) ? void (0) : __assert_fail ("std::is_sorted( std::begin(aComponentInfos), std::end(aComponentInfos), [](const ComponentInfo & lhs, const ComponentInfo & rhs) { return rtl_ustr_compare_WithLength( lhs.sName.data(), lhs.sName.size(), rhs.sName.data(), rhs.sName.size()) < 0; } )"
, "/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
, 792, __extension__ __PRETTY_FUNCTION__))
790 rhs.sName.size())(static_cast <bool> (std::is_sorted( std::begin(aComponentInfos
), std::end(aComponentInfos), [](const ComponentInfo & lhs
, const ComponentInfo & rhs) { return rtl_ustr_compare_WithLength
( lhs.sName.data(), lhs.sName.size(), rhs.sName.data(), rhs.sName
.size()) < 0; } )) ? void (0) : __assert_fail ("std::is_sorted( std::begin(aComponentInfos), std::end(aComponentInfos), [](const ComponentInfo & lhs, const ComponentInfo & rhs) { return rtl_ustr_compare_WithLength( lhs.sName.data(), lhs.sName.size(), rhs.sName.data(), rhs.sName.size()) < 0; } )"
, "/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
, 792, __extension__ __PRETTY_FUNCTION__))
791 < 0;(static_cast <bool> (std::is_sorted( std::begin(aComponentInfos
), std::end(aComponentInfos), [](const ComponentInfo & lhs
, const ComponentInfo & rhs) { return rtl_ustr_compare_WithLength
( lhs.sName.data(), lhs.sName.size(), rhs.sName.data(), rhs.sName
.size()) < 0; } )) ? void (0) : __assert_fail ("std::is_sorted( std::begin(aComponentInfos), std::end(aComponentInfos), [](const ComponentInfo & lhs, const ComponentInfo & rhs) { return rtl_ustr_compare_WithLength( lhs.sName.data(), lhs.sName.size(), rhs.sName.data(), rhs.sName.size()) < 0; } )"
, "/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
, 792, __extension__ __PRETTY_FUNCTION__))
792 } ) )(static_cast <bool> (std::is_sorted( std::begin(aComponentInfos
), std::end(aComponentInfos), [](const ComponentInfo & lhs
, const ComponentInfo & rhs) { return rtl_ustr_compare_WithLength
( lhs.sName.data(), lhs.sName.size(), rhs.sName.data(), rhs.sName
.size()) < 0; } )) ? void (0) : __assert_fail ("std::is_sorted( std::begin(aComponentInfos), std::end(aComponentInfos), [](const ComponentInfo & lhs, const ComponentInfo & rhs) { return rtl_ustr_compare_WithLength( lhs.sName.data(), lhs.sName.size(), rhs.sName.data(), rhs.sName.size()) < 0; } )"
, "/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
, 792, __extension__ __PRETTY_FUNCTION__))
;
793 bSorted = true;
794 }
795
796 OUString sSearch;
797 if ( !rServiceName.isEmpty() )
798 sSearch = rServiceName;
799 else
800 sSearch = "window";
801
802 auto it = std::lower_bound( std::begin(aComponentInfos), std::end(aComponentInfos), sSearch,
803 ComponentInfoFindCompare );
804 if (it != std::end(aComponentInfos) &&
805 rtl_ustr_compareIgnoreAsciiCase_WithLength(sSearch.pData->buffer, sSearch.pData->length, it->sName.data(), it->sName.size()) == 0)
806 return it->nWinType;
807 return WindowType::NONE;
808}
809
810struct MessageBoxTypeInfo
811{
812 css::awt::MessageBoxType eType;
813 const char *pName;
814 sal_Int32 nLen;
815};
816
817const MessageBoxTypeInfo aMessageBoxTypeInfo[] =
818{
819 { css::awt::MessageBoxType_MESSAGEBOX, RTL_CONSTASCII_STRINGPARAM("messbox")(&("messbox")[0]), ((sal_Int32)(sizeof(sal_n_array_size("messbox"
)))-1)
},
820 { css::awt::MessageBoxType_INFOBOX, RTL_CONSTASCII_STRINGPARAM("infobox")(&("infobox")[0]), ((sal_Int32)(sizeof(sal_n_array_size("infobox"
)))-1)
},
821 { css::awt::MessageBoxType_WARNINGBOX, RTL_CONSTASCII_STRINGPARAM("warningbox")(&("warningbox")[0]), ((sal_Int32)(sizeof(sal_n_array_size
("warningbox")))-1)
},
822 { css::awt::MessageBoxType_ERRORBOX, RTL_CONSTASCII_STRINGPARAM("errorbox")(&("errorbox")[0]), ((sal_Int32)(sizeof(sal_n_array_size(
"errorbox")))-1)
},
823 { css::awt::MessageBoxType_QUERYBOX, RTL_CONSTASCII_STRINGPARAM("querybox")(&("querybox")[0]), ((sal_Int32)(sizeof(sal_n_array_size(
"querybox")))-1)
},
824 { css::awt::MessageBoxType::MessageBoxType_MAKE_FIXED_SIZE, nullptr, 0 }
825};
826
827bool lcl_convertMessageBoxType(
828 OUString &sType,
829 css::awt::MessageBoxType eType )
830{
831 const MessageBoxTypeInfo *pMap = aMessageBoxTypeInfo;
832 css::awt::MessageBoxType eVal = css::awt::MessageBoxType::MessageBoxType_MAKE_FIXED_SIZE;
833
834 while ( pMap->pName )
835 {
836 if ( pMap->eType == eType )
837 {
838 eVal = eType;
839 sType = OUString( pMap->pName, pMap->nLen, RTL_TEXTENCODING_ASCII_US(((rtl_TextEncoding) 11)) );
840 break;
841 }
842 pMap++;
843 }
844
845 return ( eVal != css::awt::MessageBoxType::MessageBoxType_MAKE_FIXED_SIZE );
846}
847
848#ifndef IOS
849
850sal_Int32 nVCLToolkitInstanceCount = 0;
851bool bInitedByVCLToolkit = false;
852
853osl::Mutex & getInitMutex()
854{
855 static osl::Mutex aMutex;
856 return aMutex;
857}
858
859osl::Condition & getInitCondition()
860{
861 static osl::Condition aCondition;
862 return aCondition;
863}
864
865extern "C"
866{
867static void ToolkitWorkerFunction( void* pArgs )
868{
869 osl_setThreadName("VCLXToolkit VCL main thread");
870
871 css::uno::Reference<css::lang::XMultiServiceFactory> xServiceManager;
872 try
873 {
874 xServiceManager = ::comphelper::getProcessServiceFactory();
875 }
876 catch (const css::uno::DeploymentException&)
877 {
878 }
879 if (!xServiceManager.is())
880 {
881 css::uno::Reference<css::uno::XComponentContext> xContext =
882 ::cppu::defaultBootstrap_InitialComponentContext();
883
884 xServiceManager.set( xContext->getServiceManager(), css::uno::UNO_QUERY_THROW );
885 // set global process service factory used by unotools config helpers
886 ::comphelper::setProcessServiceFactory( xServiceManager );
887 }
888
889 VCLXToolkit * pTk = static_cast<VCLXToolkit *>(pArgs);
890 bInitedByVCLToolkit = !IsVCLInit() && InitVCL();
891 if( bInitedByVCLToolkit )
892 {
893 UnoWrapper* pUnoWrapper = new UnoWrapper( pTk );
894 UnoWrapperBase::SetUnoWrapper( pUnoWrapper );
895 }
896 getInitCondition().set();
897 if( bInitedByVCLToolkit )
898 {
899 {
900 SolarMutexGuard aGuard;
901 Application::Execute();
902 }
903 try
904 {
905 pTk->dispose();
906 }
907 catch( css::uno::Exception & )
908 {
909 }
910 DeInitVCL();
911 }
912 else
913 {
914 // having the thread join itself is pretty stupid.
915 // but we can't get the osl_Thread to destroy here so just leak it.
916 }
917}
918}
919
920#endif
921
922// constructor, which might initialize VCL
923VCLXToolkit::VCLXToolkit():
924 cppu::WeakComponentImplHelper<
925 css::awt::XToolkitExperimental,
926 css::awt::XToolkitRobot,
927 css::lang::XServiceInfo>( GetMutex() ),
928 m_aTopWindowListeners(rBHelper.rMutex),
929 m_aKeyHandlers(rBHelper.rMutex),
930 m_aFocusListeners(rBHelper.rMutex),
931 m_aEventListenerLink(LINK(this, VCLXToolkit, eventListenerHandler)::tools::detail::makeLink( ::tools::detail::castTo<VCLXToolkit
*>(this), &VCLXToolkit::LinkStubeventListenerHandler)
),
932 m_aKeyListenerLink(LINK(this, VCLXToolkit, keyListenerHandler)::tools::detail::makeLink( ::tools::detail::castTo<VCLXToolkit
*>(this), &VCLXToolkit::LinkStubkeyListenerHandler)
),
933 m_bEventListener(false),
934 m_bKeyListener(false)
935{
936 hSvToolsLib = nullptr;
937 fnSvtCreateWindow = nullptr;
938
939#ifndef IOS
940 osl::Guard< osl::Mutex > aGuard( getInitMutex() );
941 nVCLToolkitInstanceCount++;
942 if( ( nVCLToolkitInstanceCount == 1 ) && ( !Application::IsInMain() ) )
943 {
944 // setup execute thread
945 CreateMainLoopThread( ToolkitWorkerFunction, this );
946 getInitCondition().wait();
947 }
948#endif
949}
950
951void SAL_CALL VCLXToolkit::disposing()
952{
953#ifndef DISABLE_DYNLOADING
954 if ( hSvToolsLib )
955 {
956 osl_unloadModule( hSvToolsLib );
957 hSvToolsLib = nullptr;
958 fnSvtCreateWindow = nullptr;
959 }
960#endif
961
962#ifndef IOS
963 {
964 osl::Guard< osl::Mutex > aGuard( getInitMutex() );
965 if( --nVCLToolkitInstanceCount == 0 )
966 {
967 if( bInitedByVCLToolkit )
968 {
969 Application::Quit();
970 JoinMainLoopThread();
971 bInitedByVCLToolkit = false;
972 }
973 }
974 }
975#endif
976 if (m_bEventListener)
977 {
978 ::Application::RemoveEventListener(m_aEventListenerLink);
979 m_bEventListener = false;
980 }
981 if (m_bKeyListener)
982 {
983 ::Application::RemoveKeyListener(m_aKeyListenerLink);
984 m_bKeyListener = false;
985 }
986 css::lang::EventObject aEvent(
987 static_cast< ::cppu::OWeakObject * >(this));
988 m_aTopWindowListeners.disposeAndClear(aEvent);
989 m_aKeyHandlers.disposeAndClear(aEvent);
990 m_aFocusListeners.disposeAndClear(aEvent);
991}
992
993
994css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::getDesktopWindow( )
995{
996 css::uno::Reference< css::awt::XWindowPeer > xRef;
997 // 07/00: AppWindow doesn't exist anymore...
998 return xRef;
999}
1000
1001css::awt::Rectangle VCLXToolkit::getWorkArea( )
1002{
1003 sal_Int32 nDisplay = Application::GetDisplayBuiltInScreen();
1004 tools::Rectangle aWorkRect = Application::GetScreenPosSizePixel( nDisplay );
1005 css::awt::Rectangle aNotherRect;
1006 aNotherRect.X = aWorkRect.getX();
1007 aNotherRect.Y = aWorkRect.getY();
1008 aNotherRect.Width = aWorkRect.getWidth();
1009 aNotherRect.Height = aWorkRect.getHeight();
1010 return aNotherRect;
1011}
1012
1013css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::createWindow( const css::awt::WindowDescriptor& rDescriptor )
1014{
1015 return ImplCreateWindow( rDescriptor, MessBoxStyle::NONE );
1016}
1017
1018css::uno::Reference< css::awt::XDevice > VCLXToolkit::createScreenCompatibleDevice( sal_Int32 Width, sal_Int32 Height )
1019{
1020 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1021
1022 css::uno::Reference< css::awt::XDevice > xRef;
1023 VCLXVirtualDevice* pVDev = new VCLXVirtualDevice;
1024
1025 SolarMutexGuard aSolarGuard;
1026
1027 VclPtrInstance<VirtualDevice> pV;
1028 pV->SetOutputSizePixel( Size( Width, Height ) );
1029 pVDev->SetVirtualDevice( pV );
1030
1031 xRef = pVDev;
1032 return xRef;
1033}
1034
1035css::uno::Reference< css::awt::XRegion > VCLXToolkit::createRegion( )
1036{
1037 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1038
1039 css::uno::Reference< css::awt::XRegion > xRef = new VCLXRegion;
1040 return xRef;
1041}
1042
1043class InfoBox : public MessBox
1044{
1045public:
1046 InfoBox(vcl::Window* pParent, const OUString& rMessage)
1047 : MessBox(pParent, MessBoxStyle::Ok | MessBoxStyle::DefaultOk, 0, OUString(), rMessage)
1048 {
1049 // Default Text is the display title from the application
1050 if (GetText().isEmpty())
1051 SetText(GetStandardInfoBoxText());
1052 SetImage(GetStandardInfoBoxImage());
1053 }
1054};
1055
1056class ErrorBox : public MessBox
1057{
1058public:
1059 ErrorBox(vcl::Window* pParent, MessBoxStyle nStyle, WinBits nWinBits, const OUString& rMessage)
1060 : MessBox(pParent, nStyle, nWinBits, OUString(), rMessage)
1061 {
1062 // Default Text is the display title from the application
1063 if (GetText().isEmpty())
1064 SetText(GetStandardErrorBoxText());
1065 SetImage(GetStandardErrorBoxImage());
1066 }
1067};
1068
1069class QueryBox : public MessBox
1070{
1071public:
1072 QueryBox(vcl::Window* pParent, MessBoxStyle nStyle, WinBits nWinBits, const OUString& rMessage)
1073 : MessBox(pParent, nStyle, nWinBits, OUString(), rMessage)
1074 {
1075 // Default Text is the display title from the application
1076 if (GetText().isEmpty())
1077 SetText(GetStandardQueryBoxText());
1078 SetImage(GetStandardQueryBoxImage());
1079 }
1080};
1081
1082class WarningBox : public MessBox
1083{
1084public:
1085 WarningBox(vcl::Window* pParent, MessBoxStyle nStyle, WinBits nWinBits, const OUString& rMessage)
1086 : MessBox(pParent, nStyle, nWinBits, OUString(), rMessage)
1087 {
1088 // Default Text is the display title from the application
1089 if (GetText().isEmpty())
1090 SetText(GetStandardWarningBoxText());
1091 SetImage(GetStandardWarningBoxImage());
1092 }
1093};
1094
1095
1096struct RMItemData
1097{
1098 bool b_Enabled;
1099 sal_Int32 n_ID;
1100 OUString Label;
1101};
1102
1103typedef ::cppu::ImplInheritanceHelper < VCLXGraphicControl
1104 , css::container::XContainerListener
1105 , css::beans::XPropertyChangeListener
1106 , css::awt::XItemEventBroadcaster
1107 > SVTXRoadmap_Base;
1108class SVTXRoadmap final : public SVTXRoadmap_Base
1109{
1110public:
1111 SVTXRoadmap();
1112
1113 void SAL_CALL disposing( const css::lang::EventObject& Source ) override { VCLXWindow::disposing( Source ); }
1114
1115 // css::awt::XVclWindowPeer
1116 void SAL_CALL setProperty( const OUString& PropertyName, const css::uno::Any& Value ) override;
1117
1118 css::uno::Any SAL_CALL getProperty( const OUString& PropertyName ) override;
1119
1120 // XContainerListener
1121 void SAL_CALL elementInserted( const css::container::ContainerEvent& rEvent ) override;
1122 void SAL_CALL elementRemoved( const css::container::ContainerEvent& rEvent ) override;
1123 void SAL_CALL elementReplaced( const css::container::ContainerEvent& rEvent ) override;
1124
1125 // XItemEventBroadcaster
1126 virtual void SAL_CALL addItemListener( const css::uno::Reference< css::awt::XItemListener >& l ) override;
1127 virtual void SAL_CALL removeItemListener( const css::uno::Reference< css::awt::XItemListener >& l ) override;
1128
1129 // XPropertyChangeListener
1130 virtual void SAL_CALL propertyChange( const css::beans::PropertyChangeEvent& evt ) override;
1131
1132private:
1133
1134 // VCLXGraphicControl overridables
1135 virtual void ImplSetNewImage() override;
1136
1137 static void ImplGetPropertyIds( std::vector< sal_uInt16 > &aIds );
1138 virtual void GetPropertyIds( std::vector< sal_uInt16 > &aIds ) override { return ImplGetPropertyIds( aIds ); }
1139
1140 static RMItemData GetRMItemData( const css::container::ContainerEvent& _rEvent );
1141
1142 virtual void ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) override;
1143
1144 virtual ~SVTXRoadmap() override;
1145
1146 ItemListenerMultiplexer maItemListeners;
1147};
1148
1149
1150
1151
1152SVTXRoadmap::SVTXRoadmap() : maItemListeners( *this )
1153{
1154}
1155
1156SVTXRoadmap::~SVTXRoadmap()
1157{
1158}
1159
1160void SVTXRoadmap::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
1161{
1162 switch ( rVclWindowEvent.GetId() )
1163 {
1164 case VclEventId::RoadmapItemSelected:
1165 {
1166 SolarMutexGuard aGuard;
1167 VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >();
1168 if ( pField )
1169 {
1170 sal_Int16 CurItemID = pField->GetCurrentRoadmapItemID();
1171 css::awt::ItemEvent aEvent;
1172 aEvent.Selected = CurItemID;
1173 aEvent.Highlighted = CurItemID;
1174 aEvent.ItemId = CurItemID;
1175 maItemListeners.itemStateChanged( aEvent );
1176 }
1177 }
1178 break;
1179 default:
1180 SVTXRoadmap_Base::ProcessWindowEvent( rVclWindowEvent );
1181 break;
1182 }
1183}
1184
1185void SVTXRoadmap::propertyChange( const css::beans::PropertyChangeEvent& evt )
1186{
1187 SolarMutexGuard aGuard;
1188 VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >();
1189 if ( !pField )
1190 return;
1191
1192 css::uno::Reference< css::uno::XInterface > xRoadmapItem = evt.Source;
1193 sal_Int32 nID = 0;
1194 css::uno::Reference< css::beans::XPropertySet > xPropertySet( xRoadmapItem, css::uno::UNO_QUERY );
1195 css::uno::Any aValue = xPropertySet->getPropertyValue("ID");
1196 aValue >>= nID;
1197
1198 OUString sPropertyName = evt.PropertyName;
1199 if ( sPropertyName == "Enabled" )
1200 {
1201 bool bEnable = false;
1202 evt.NewValue >>= bEnable;
1203 pField->EnableRoadmapItem( static_cast<vcl::RoadmapTypes::ItemId>(nID) , bEnable );
1204 }
1205 else if ( sPropertyName == "Label" )
1206 {
1207 OUString sLabel;
1208 evt.NewValue >>= sLabel;
1209 pField->ChangeRoadmapItemLabel( static_cast<vcl::RoadmapTypes::ItemId>(nID) , sLabel );
1210 }
1211 else if ( sPropertyName == "ID" )
1212 {
1213 sal_Int32 nNewID = 0;
1214 evt.NewValue >>= nNewID;
1215 evt.OldValue >>= nID;
1216 pField->ChangeRoadmapItemID( static_cast<vcl::RoadmapTypes::ItemId>(nID), static_cast<vcl::RoadmapTypes::ItemId>(nNewID) );
1217 }
1218// else
1219 // TODO handle Interactive appropriately
1220}
1221
1222void SVTXRoadmap::addItemListener( const css::uno::Reference< css::awt::XItemListener >& l )
1223{
1224 maItemListeners.addInterface( l );
1225}
1226
1227void SVTXRoadmap::removeItemListener( const css::uno::Reference< css::awt::XItemListener >& l )
1228{
1229 maItemListeners.removeInterface( l );
1230}
1231
1232RMItemData SVTXRoadmap::GetRMItemData( const css::container::ContainerEvent& _rEvent )
1233{
1234 RMItemData aCurRMItemData;
1235 css::uno::Reference< css::uno::XInterface > xRoadmapItem;
1236 _rEvent.Element >>= xRoadmapItem;
1237 css::uno::Reference< css::beans::XPropertySet > xPropertySet( xRoadmapItem, css::uno::UNO_QUERY );
1238 if ( xPropertySet.is() )
1239 {
1240 css::uno::Any aValue = xPropertySet->getPropertyValue("Label");
1241 aValue >>= aCurRMItemData.Label;
1242 aValue = xPropertySet->getPropertyValue("ID");
1243 aValue >>= aCurRMItemData.n_ID;
1244 aValue = xPropertySet->getPropertyValue("Enabled");
1245 aValue >>= aCurRMItemData.b_Enabled;
1246 }
1247 else
1248 {
1249 aCurRMItemData.b_Enabled = false;
1250 aCurRMItemData.n_ID = 0;
1251 }
1252 return aCurRMItemData;
1253}
1254
1255void SVTXRoadmap::elementInserted( const css::container::ContainerEvent& _rEvent )
1256{
1257 SolarMutexGuard aGuard;
1258 VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >();
1259 if ( pField )
1260 {
1261 RMItemData CurItemData = GetRMItemData( _rEvent );
1262 sal_Int32 InsertIndex = 0;
1263 _rEvent.Accessor >>= InsertIndex;
1264 pField->InsertRoadmapItem( InsertIndex, CurItemData.Label, static_cast<vcl::RoadmapTypes::ItemId>(CurItemData.n_ID), CurItemData.b_Enabled );
1265 }
1266}
1267
1268void SVTXRoadmap::elementRemoved( const css::container::ContainerEvent& _rEvent )
1269{
1270 SolarMutexGuard aGuard;
1271 VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >();
1272 if ( pField )
1273 {
1274 sal_Int32 DelIndex = 0;
1275 _rEvent.Accessor >>= DelIndex;
1276 pField->DeleteRoadmapItem(DelIndex);
1277 }
1278}
1279
1280void SVTXRoadmap::elementReplaced( const css::container::ContainerEvent& _rEvent )
1281{
1282 SolarMutexGuard aGuard;
1283 VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >();
1284 if ( pField )
1285 {
1286 RMItemData CurItemData = GetRMItemData( _rEvent );
1287 sal_Int32 ReplaceIndex = 0;
1288 _rEvent.Accessor >>= ReplaceIndex;
1289 pField->ReplaceRoadmapItem( ReplaceIndex, CurItemData.Label, static_cast<vcl::RoadmapTypes::ItemId>(CurItemData.n_ID), CurItemData.b_Enabled );
1290 }
1291}
1292
1293void SVTXRoadmap::setProperty( const OUString& PropertyName, const css::uno::Any& Value)
1294{
1295 SolarMutexGuard aGuard;
1296
1297 VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >();
1298 if ( pField )
1299 {
1300 sal_uInt16 nPropType = GetPropertyId( PropertyName );
1301 switch (nPropType)
1302 {
1303 case BASEPROPERTY_COMPLETE106:
1304 {
1305 bool b = false;
1306 Value >>= b;
1307 pField->SetRoadmapComplete( b);
1308 }
1309 break;
1310
1311 case BASEPROPERTY_ACTIVATED105:
1312 {
1313 bool b = false;
1314 Value >>= b;
1315 pField->SetRoadmapInteractive( b);
1316 }
1317 break;
1318
1319 case BASEPROPERTY_CURRENTITEMID107:
1320 {
1321 sal_Int32 nId = 0;
1322 Value >>= nId;
1323 pField->SelectRoadmapItemByID( static_cast<vcl::RoadmapTypes::ItemId>(nId) );
1324 }
1325 break;
1326
1327 case BASEPROPERTY_TEXT1:
1328 {
1329 OUString aStr;
1330 Value >>= aStr;
1331 pField->SetText( aStr );
1332 pField->Invalidate();
1333 }
1334 break;
1335
1336 default:
1337 SVTXRoadmap_Base::setProperty( PropertyName, Value );
1338 break;
1339 }
1340
1341 }
1342 else
1343 SVTXRoadmap_Base::setProperty( PropertyName, Value );
1344}
1345
1346
1347css::uno::Any SVTXRoadmap::getProperty( const OUString& PropertyName )
1348{
1349 SolarMutexGuard aGuard;
1350
1351 css::uno::Any aReturn;
1352
1353 VclPtr<::vcl::ORoadmap> pField = GetAs< vcl::ORoadmap >();
1354 if ( pField )
1355 {
1356 sal_uInt16 nPropType = GetPropertyId( PropertyName );
1357 switch (nPropType)
1358 {
1359 case BASEPROPERTY_COMPLETE106:
1360 aReturn <<= pField->IsRoadmapComplete();
1361 break;
1362 case BASEPROPERTY_ACTIVATED105:
1363 aReturn <<= pField->IsRoadmapInteractive();
1364 break;
1365 case BASEPROPERTY_CURRENTITEMID107:
1366 aReturn <<= pField->GetCurrentRoadmapItemID();
1367 break;
1368 default:
1369 aReturn = SVTXRoadmap_Base::getProperty(PropertyName);
1370 break;
1371 }
1372 }
1373 return aReturn;
1374}
1375
1376void SVTXRoadmap::ImplSetNewImage()
1377{
1378 OSL_PRECOND( GetWindow(), "SVTXRoadmap::ImplSetNewImage: window is required to be not-NULL!" )do { if (true && (!(GetWindow()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
":" "1378" ": "), "%s", "SVTXRoadmap::ImplSetNewImage: window is required to be not-NULL!"
); } } while (false)
;
1379 VclPtr< ::vcl::ORoadmap > pButton = GetAs< ::vcl::ORoadmap >();
1380 pButton->SetRoadmapBitmap( GetImage().GetBitmapEx() );
1381}
1382
1383void SVTXRoadmap::ImplGetPropertyIds( std::vector< sal_uInt16 > &rIds )
1384{
1385 PushPropertyIds( rIds,
1386 BASEPROPERTY_COMPLETE106,
1387 BASEPROPERTY_ACTIVATED105,
1388 BASEPROPERTY_CURRENTITEMID107,
1389 BASEPROPERTY_TEXT1,
1390 0);
1391 VCLXWindow::ImplGetPropertyIds( rIds, true );
1392 VCLXGraphicControl::ImplGetPropertyIds( rIds );
1393}
1394
1395vcl::Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp,
1396 const css::awt::WindowDescriptor& rDescriptor,
1397 vcl::Window* pParent, WinBits nWinBits, MessBoxStyle nMessBoxStyle )
1398{
1399 OUString aServiceName = rDescriptor.WindowServiceName.toAsciiLowerCase();
1400
1401 VclPtr<vcl::Window> pNewWindow;
1402 WindowType nType = ImplGetComponentType( aServiceName );
1403 bool bFrameControl = false;
1404 if ( aServiceName == "frame" )
1405 bFrameControl = true;
1406 if ( aServiceName == "tabcontrolnotabs" )
1407 {
1408 nWinBits |= WB_NOBORDER;
1409 nType = ImplGetComponentType( "tabcontrol" );
1410 }
1411 if ( !pParent )
1412 {
1413 // If the component needs a parent, then return NULL,
1414 // some time later css::uno::Exception...
1415 bool bException = true;
1416 if ( ( nType == WindowType::DIALOG )
1417 || ( nType == WindowType::MODELESSDIALOG )
1418 || ( nType == WindowType::MESSBOX )
1419 || ( nType == WindowType::INFOBOX )
1420 || ( nType == WindowType::WARNINGBOX )
1421 || ( nType == WindowType::ERRORBOX )
1422 || ( nType == WindowType::QUERYBOX )
1423 )
1424 bException = false;
1425 else if ( ( nType == WindowType::WINDOW ) ||
1426 ( nType == WindowType::WORKWINDOW ) ||
1427 ( nType == WindowType::TOOLKIT_FRAMEWINDOW ) )
1428 {
1429 if ( rDescriptor.Type == css::awt::WindowClass_TOP )
1430 bException = false;
1431 }
1432
1433 if ( bException )
1434 {
1435 *ppNewComp = nullptr;
1436 return nullptr;
1437 }
1438 }
1439
1440 if ( nType != WindowType::NONE )
1441 {
1442 SolarMutexGuard aVclGuard;
1443 switch ( nType )
1444 {
1445 case WindowType::CANCELBUTTON:
1446 pNewWindow = VclPtr<CancelButton>::Create( pParent, nWinBits );
1447 *ppNewComp = new VCLXButton;
1448 break;
1449 case WindowType::CHECKBOX:
1450 pNewWindow = VclPtr<CheckBox>::Create( pParent, nWinBits );
1451 *ppNewComp = new VCLXCheckBox;
1452 break;
1453 case WindowType::COMBOBOX:
1454 pNewWindow = VclPtr<ComboBox>::Create( pParent, nWinBits|WB_AUTOHSCROLL );
1455 static_cast<ComboBox*>(pNewWindow.get())->EnableAutoSize( false );
1456 *ppNewComp = new VCLXComboBox;
1457 break;
1458 case WindowType::CURRENCYBOX:
1459 pNewWindow = VclPtr<CurrencyBox>::Create( pParent, nWinBits );
1460 break;
1461 case WindowType::CURRENCYFIELD:
1462 pNewWindow = VclPtr<CurrencyField>::Create( pParent, nWinBits );
1463 static_cast<CurrencyField*>(pNewWindow.get())->EnableEmptyFieldValue( true );
1464 *ppNewComp = new VCLXNumericField;
1465 static_cast<VCLXFormattedSpinField*>(*ppNewComp)->SetFormatter( static_cast<FormatterBase*>(static_cast<CurrencyField*>(pNewWindow.get())) );
1466 break;
1467 case WindowType::DATEBOX:
1468 pNewWindow = VclPtr<DateBox>::Create( pParent, nWinBits );
1469 break;
1470 case WindowType::DOCKINGAREA:
1471 pNewWindow = VclPtr<DockingAreaWindow>::Create( pParent );
1472 break;
1473 case WindowType::MULTILINEEDIT:
1474 pNewWindow = VclPtr<MultiLineEdit>::Create(pParent, nWinBits|WB_IGNORETAB);
1475 static_cast<MultiLineEdit*>(pNewWindow.get())->DisableSelectionOnFocus();
1476 *ppNewComp = new VCLXMultiLineEdit;
1477 break;
1478 case WindowType::EDIT:
1479 pNewWindow = VclPtr<Edit>::Create( pParent, nWinBits );
1480 *ppNewComp = new VCLXEdit;
1481 break;
1482 case WindowType::ERRORBOX:
1483 pNewWindow = VclPtr<ErrorBox>::Create( pParent, nMessBoxStyle, nWinBits, OUString() );
1484 *ppNewComp = new VCLXMessageBox;
1485 break;
1486 case WindowType::FIXEDBITMAP:
1487 pNewWindow = VclPtr<FixedBitmap>::Create( pParent, nWinBits );
1488 break;
1489 case WindowType::FIXEDIMAGE:
1490 pNewWindow = VclPtr<ImageControl>::Create( pParent, nWinBits );
1491 *ppNewComp = new VCLXImageControl;
1492 break;
1493 case WindowType::FIXEDLINE:
1494 pNewWindow = VclPtr<FixedLine>::Create( pParent, nWinBits );
1495 break;
1496 case WindowType::FIXEDTEXT:
1497 pNewWindow = VclPtr<FixedText>::Create( pParent, nWinBits );
1498 *ppNewComp = new VCLXFixedText;
1499 break;
1500 case WindowType::FLOATINGWINDOW:
1501 pNewWindow = VclPtr<FloatingWindow>::Create( pParent, nWinBits );
1502 break;
1503 case WindowType::GROUPBOX:
1504 pNewWindow = VclPtr<GroupBox>::Create( pParent, nWinBits );
1505 if ( bFrameControl )
1506 {
1507 GroupBox* pGroupBox = static_cast< GroupBox* >( pNewWindow.get() );
1508 *ppNewComp = new VCLXFrame;
1509 // Frame control needs to receive
1510 // Mouse events
1511 pGroupBox->SetMouseTransparent( false );
1512 }
1513 break;
1514 case WindowType::HELPBUTTON:
1515 pNewWindow = VclPtr<HelpButton>::Create( pParent, nWinBits );
1516 *ppNewComp = new VCLXButton;
1517 break;
1518 case WindowType::IMAGEBUTTON:
1519 pNewWindow = VclPtr<ImageButton>::Create( pParent, nWinBits );
1520 *ppNewComp = new VCLXButton;
1521 break;
1522 case WindowType::INFOBOX:
1523 pNewWindow = VclPtr<InfoBox>::Create( pParent, OUString() );
1524 *ppNewComp = new VCLXMessageBox;
1525 break;
1526 case WindowType::LISTBOX:
1527 pNewWindow = VclPtr<ListBox>::Create( pParent, nWinBits|WB_SIMPLEMODE|WB_AUTOHSCROLL );
1528 static_cast<ListBox*>(pNewWindow.get())->EnableAutoSize( false );
1529 *ppNewComp = new VCLXListBox;
1530 break;
1531 case WindowType::LONGCURRENCYBOX:
1532 pNewWindow = VclPtr<LongCurrencyBox>::Create( pParent, nWinBits );
1533 break;
1534 case WindowType::MENUBUTTON:
1535 pNewWindow = VclPtr<MenuButton>::Create( pParent, nWinBits );
1536 *ppNewComp = new VCLXButton;
1537 break;
1538 case WindowType::MESSBOX:
1539 pNewWindow = VclPtr<MessBox>::Create( pParent, nMessBoxStyle, nWinBits, OUString(), OUString() );
1540 *ppNewComp = new VCLXMessageBox;
1541 break;
1542 case WindowType::METRICBOX:
1543 pNewWindow = VclPtr<MetricBox>::Create( pParent, nWinBits );
1544 break;
1545 case WindowType::METRICFIELD:
1546 pNewWindow = VclPtr<MetricField>::Create( pParent, nWinBits );
1547 *ppNewComp = new VCLXMetricField;
1548 static_cast<VCLXFormattedSpinField*>(*ppNewComp)->SetFormatter( static_cast<FormatterBase*>(static_cast<MetricField*>(pNewWindow.get())) );
1549 break;
1550 case WindowType::DIALOG:
1551 case WindowType::MODELESSDIALOG:
1552 {
1553 // Modal/Modeless only via Show/Execute
1554 if ( (pParent == nullptr ) && ( rDescriptor.ParentIndex == -1 ) )
1555 pNewWindow = VclPtr<toolkit::ScrollableDialog>::Create( nullptr, nWinBits, Dialog::InitFlag::NoParent );
1556 else
1557 pNewWindow = VclPtr<toolkit::ScrollableDialog>::Create( pParent, nWinBits );
1558 // #i70217# Don't always create a new component object. It's possible that VCL has called
1559 // GetComponentInterface( sal_True ) in the Dialog ctor itself (see Window::IsTopWindow() )
1560 // which creates a component object.
1561 css::uno::Reference< css::awt::XWindowPeer > xWinPeer = pNewWindow->GetComponentInterface( false );
1562 if ( xWinPeer.is() )
1563 *ppNewComp = dynamic_cast< VCLXDialog* >( xWinPeer.get() );
1564 else
1565 *ppNewComp = new VCLXDialog;
1566 }
1567 break;
1568 case WindowType::MOREBUTTON:
1569 pNewWindow = VclPtr<MoreButton>::Create( pParent, nWinBits );
1570 *ppNewComp = new VCLXButton;
1571 break;
1572 case WindowType::MULTILISTBOX:
1573 pNewWindow = VclPtr<MultiListBox>::Create( pParent, nWinBits );
1574 *ppNewComp = new VCLXListBox;
1575 break;
1576 case WindowType::NUMERICBOX:
1577 pNewWindow = VclPtr<NumericBox>::Create( pParent, nWinBits );
1578 break;
1579 case WindowType::OKBUTTON:
1580 pNewWindow = VclPtr<OKButton>::Create( pParent, nWinBits );
1581 *ppNewComp = new VCLXButton;
1582 break;
1583 case WindowType::PATTERNBOX:
1584 pNewWindow = VclPtr<PatternBox>::Create( pParent, nWinBits );
1585 break;
1586 case WindowType::PATTERNFIELD:
1587 pNewWindow = VclPtr<PatternField>::Create( pParent, nWinBits );
1588 *ppNewComp = new VCLXPatternField;
1589 static_cast<VCLXFormattedSpinField*>(*ppNewComp)->SetFormatter( static_cast<FormatterBase*>(static_cast<PatternField*>(pNewWindow.get())) );
1590 break;
1591 case WindowType::PUSHBUTTON:
1592 pNewWindow = VclPtr<PushButton>::Create( pParent, nWinBits );
1593 *ppNewComp = new VCLXButton;
1594 break;
1595 case WindowType::QUERYBOX:
1596 pNewWindow = VclPtr<QueryBox>::Create( pParent, nMessBoxStyle, nWinBits, OUString() );
1597 *ppNewComp = new VCLXMessageBox;
1598 break;
1599 case WindowType::RADIOBUTTON:
1600 pNewWindow = VclPtr<RadioButton>::Create(pParent, false, nWinBits);
1601 *ppNewComp = new VCLXRadioButton;
1602
1603 // by default, disable RadioCheck
1604 // Since the VCLXRadioButton really cares for its RadioCheck settings, this is important:
1605 // if we enable it, the VCLXRadioButton will use RadioButton::Check instead of RadioButton::SetState
1606 // This leads to a strange behaviour if the control is newly created: when settings the initial
1607 // state to "checked", the RadioButton::Check (called because RadioCheck=sal_True) will uncheck
1608 // _all_other_ radio buttons in the same group. However, at this moment the grouping of the controls
1609 // is not really valid: the controls are grouped after they have been created, but we're still in
1610 // the creation process, so the RadioButton::Check relies on invalid grouping information.
1611 // 07.08.2001 - #87254# - frank.schoenheit@sun.com
1612 static_cast<RadioButton*>(pNewWindow.get())->EnableRadioCheck( false );
1613 break;
1614 case WindowType::SCROLLBAR:
1615 pNewWindow = VclPtr<ScrollBar>::Create( pParent, nWinBits );
1616 *ppNewComp = new VCLXScrollBar;
1617 break;
1618 case WindowType::SCROLLBARBOX:
1619 pNewWindow = VclPtr<ScrollBarBox>::Create( pParent, nWinBits );
1620 break;
1621 case WindowType::SPINBUTTON:
1622 pNewWindow = VclPtr<SpinButton>::Create( pParent, nWinBits );
1623 *ppNewComp = new ::toolkit::VCLXSpinButton;
1624 break;
1625 case WindowType::SPINFIELD:
1626 pNewWindow = VclPtr<SpinField>::Create( pParent, nWinBits );
1627 *ppNewComp = new VCLXNumericField;
1628 break;
1629 case WindowType::SPLITTER:
1630 pNewWindow = VclPtr<Splitter>::Create( pParent, nWinBits );
1631 break;
1632 case WindowType::SPLITWINDOW:
1633 pNewWindow = VclPtr<SplitWindow>::Create( pParent, nWinBits );
1634 break;
1635 case WindowType::STATUSBAR:
1636 pNewWindow = VclPtr<StatusBar>::Create( pParent, nWinBits );
1637 break;
1638 case WindowType::TOOLKIT_SYSTEMCHILDWINDOW:
1639 pNewWindow = VclPtr<SystemChildWindow>::Create( pParent, nWinBits );
1640 *ppNewComp = new VCLXSystemDependentWindow();
1641 break;
1642 case WindowType::TABCONTROL:
1643 pNewWindow = VclPtr<TabControl>::Create( pParent, nWinBits );
1644 *ppNewComp = new VCLXMultiPage;
1645 break;
1646 case WindowType::TABDIALOG:
1647 pNewWindow = VclPtr<TabDialog>::Create( pParent, nWinBits );
1648 break;
1649 case WindowType::TABPAGE:
1650 {
1651 pNewWindow = VclPtr<TabPage>::Create( pParent, nWinBits );
1652 *ppNewComp = new VCLXTabPage;
1653 }
1654 break;
1655 case WindowType::TIMEBOX:
1656 pNewWindow = VclPtr<TimeBox>::Create( pParent, nWinBits );
1657 break;
1658 case WindowType::TIMEFIELD:
1659 pNewWindow = VclPtr<TimeField>::Create( pParent, nWinBits );
1660 static_cast<TimeField*>(pNewWindow.get())->EnableEmptyFieldValue( true );
1661 *ppNewComp = new VCLXTimeField;
1662 static_cast<VCLXFormattedSpinField*>(*ppNewComp)->SetFormatter( static_cast<FormatterBase*>(static_cast<TimeField*>(pNewWindow.get())) );
1663 break;
1664 case WindowType::TOOLBOX:
1665 pNewWindow = VclPtr<ToolBox>::Create( pParent, nWinBits );
1666 *ppNewComp = new VCLXToolBox;
1667 break;
1668 case WindowType::TRISTATEBOX:
1669 pNewWindow = VclPtr<CheckBox>::Create( pParent, nWinBits );
1670 static_cast<CheckBox*>(pNewWindow.get())->EnableTriState(true);
1671 break;
1672 case WindowType::WARNINGBOX:
1673 pNewWindow = VclPtr<WarningBox>::Create( pParent, nMessBoxStyle, nWinBits, OUString() );
1674 *ppNewComp = new VCLXMessageBox;
1675 break;
1676 case WindowType::WORKWINDOW:
1677 case WindowType::WINDOW:
1678 case WindowType::TOOLKIT_FRAMEWINDOW:
1679 case WindowType::DOCKINGWINDOW:
1680 if ( rDescriptor.Type == css::awt::WindowClass_TOP )
1681 {
1682 if (nType == WindowType::DOCKINGWINDOW )
1683 pNewWindow = VclPtr<DockingWindow>::Create( pParent, nWinBits );
1684 else
1685 {
1686 if ((pParent == nullptr) && rDescriptor.Parent.is())
1687 {
1688 // try to get a system dependent window handle
1689 css::uno::Reference< css::awt::XSystemDependentWindowPeer > xSystemDepParent(rDescriptor.Parent, css::uno::UNO_QUERY);
1690
1691 if (xSystemDepParent.is())
1692 {
1693 sal_Int8 processID[16];
1694
1695 rtl_getGlobalProcessId( reinterpret_cast<sal_uInt8*>(processID) );
1696
1697 // coverity[overrun-buffer-arg : FALSE] - coverity has difficulty with css::uno::Sequence
1698 css::uno::Sequence<sal_Int8> processIdSeq(processID, 16);
1699
1700 css::uno::Any anyHandle = xSystemDepParent->getWindowHandle(processIdSeq, SYSTEM_DEPENDENT_TYPEcss::lang::SystemDependent::SYSTEM_XWINDOW);
1701
1702 // use sal_Int64 here to accommodate all int types
1703 // uno::Any shift operator whill upcast if necessary
1704 sal_Int64 nWindowHandle = 0;
1705 bool bXEmbed = false;
1706
1707 bool bUseParentData = true;
1708 if( ! (anyHandle >>= nWindowHandle) )
1709 {
1710 css::uno::Sequence< css::beans::NamedValue > aProps;
1711 if( anyHandle >>= aProps )
1712 {
1713 for( const css::beans::NamedValue& rProp : std::as_const(aProps) )
1714 {
1715 if ( rProp.Name == "WINDOW" )
1716 rProp.Value >>= nWindowHandle;
1717 else if ( rProp.Name == "XEMBED" )
1718 rProp.Value >>= bXEmbed;
1719 }
1720 }
1721 else
1722 bUseParentData = false;
1723 }
1724
1725 if( bUseParentData )
1726 {
1727 SystemParentData aParentData;
1728 aParentData.nSize = sizeof( aParentData );
1729 #if defined MACOSX
1730 aParentData.pView = reinterpret_cast<NSView*>(nWindowHandle);
1731 #elif defined ANDROID
1732 // Nothing
1733 #elif defined IOS
1734 // Nothing
1735 #elif defined UNX1
1736 aParentData.aWindow = nWindowHandle;
1737 aParentData.bXEmbedSupport = bXEmbed;
1738 #elif defined _WIN32
1739 aParentData.hWnd = reinterpret_cast<HWND>(nWindowHandle);
1740 #endif
1741 pNewWindow = VclPtr<WorkWindow>::Create( &aParentData );
1742 }
1743 }
1744 }
1745
1746 if (!pNewWindow)
1747 pNewWindow = VclPtr<WorkWindow>::Create( pParent, nWinBits );
1748 }
1749
1750 *ppNewComp = new VCLXTopWindow();
1751 }
1752 else if ( rDescriptor.Type == css::awt::WindowClass_CONTAINER )
1753 {
1754 if (nType == WindowType::DOCKINGWINDOW )
1755 pNewWindow = VclPtr<DockingWindow>::Create( pParent, nWinBits );
1756 else
1757 pNewWindow = VclPtr<vcl::Window>::Create( pParent, nWinBits );
1758 *ppNewComp = new VCLXContainer;
1759 }
1760 else
1761 {
1762 if (nType == WindowType::DOCKINGWINDOW )
1763 pNewWindow = VclPtr<DockingWindow>::Create( pParent, nWinBits );
1764 else
1765 pNewWindow = VclPtr<vcl::Window>::Create( pParent, nWinBits );
1766 *ppNewComp = new VCLXWindow;
1767 }
1768 break;
1769 case WindowType::CONTROL:
1770 if ( aServiceName == "tabpagecontainer" )
1771 {
1772 // TabControl has a special case for tabs without border: they are displayed
1773 // in a different way, so we need to ensure that this style is not set, so
1774 // we can guarantee normal tab behavior
1775 pNewWindow = VclPtr<TabControl>::Create( pParent, nWinBits & (~WB_NOBORDER));
1776 *ppNewComp = new VCLXTabPageContainer;
1777 }
1778 else if ( aServiceName == "animatedimages" )
1779 {
1780 pNewWindow = VclPtr<Throbber>::Create( pParent, nWinBits );
1781 *ppNewComp = new ::toolkit::AnimatedImagesPeer;
1782 }
1783 else if (aServiceName == "roadmap")
1784 {
1785 pNewWindow = VclPtr<::vcl::ORoadmap>::Create( pParent, WB_TABSTOP );
1786 *ppNewComp = new SVTXRoadmap;
1787 }
1788 else if (aServiceName == "fixedhyperlink")
1789 {
1790 pNewWindow = VclPtr<FixedHyperlink>::Create( pParent, nWinBits );
1791 *ppNewComp = new VCLXFixedHyperlink;
1792 }
1793 else if (aServiceName == "progressbar")
1794 {
1795 pNewWindow = VclPtr<ProgressBar>::Create( pParent, nWinBits );
1796 *ppNewComp = new VCLXProgressBar;
1797 }
1798 else if (aServiceName == "filecontrol")
1799 {
1800 pNewWindow = VclPtr<FileControl>::Create( pParent, nWinBits );
1801 *ppNewComp = new VCLXFileControl;
1802 }
1803 else if (aServiceName == "tree")
1804 {
1805 TreeControlPeer* pPeer = new TreeControlPeer;
1806 *ppNewComp = pPeer;
1807 pNewWindow = pPeer->createVclControl( pParent, nWinBits );
1808 }
1809 else if (aServiceName == "formattedfield")
1810 {
1811 pNewWindow = VclPtr<FormattedField>::Create( pParent, nWinBits );
1812 *ppNewComp = new SVTXFormattedField;
1813 }
1814 else if (aServiceName == "numericfield")
1815 {
1816 pNewWindow = VclPtr<DoubleNumericField>::Create( pParent, nWinBits );
1817 *ppNewComp = new SVTXNumericField;
1818 }
1819 else if (aServiceName == "longcurrencyfield")
1820 {
1821 pNewWindow = VclPtr<DoubleCurrencyField>::Create( pParent, nWinBits );
1822 *ppNewComp = new SVTXCurrencyField;
1823 }
1824 else if (aServiceName == "datefield")
1825 {
1826 pNewWindow = VclPtr<CalendarField>::Create(pParent, nWinBits);
1827 static_cast<CalendarField*>(pNewWindow.get())->EnableToday();
1828 static_cast<CalendarField*>(pNewWindow.get())->EnableNone();
1829 static_cast<CalendarField*>(pNewWindow.get())->EnableEmptyFieldValue( true );
1830 SVTXDateField * newComp = new SVTXDateField;
1831 *ppNewComp = newComp;
1832 newComp->SetFormatter( static_cast<FormatterBase*>(static_cast<DateField*>(pNewWindow.get())) );
1833 }
1834 break;
1835 default:
1836 OSL_ENSURE( false, "VCLXToolkit::ImplCreateWindow: unknown window type!" )do { if (true && (!(false))) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
":" "1836" ": "), "%s", "VCLXToolkit::ImplCreateWindow: unknown window type!"
); } } while (false)
;
1837 break;
1838 }
1839 }
1840
1841 // tdf#126717 default that formcontrols show accelerators
1842 if (Control* pControl = dynamic_cast<Control*>(pNewWindow.get()))
1843 pControl->SetShowAccelerator(true);
1844 return pNewWindow;
1845}
1846
1847#ifndef DISABLE_DYNLOADING
1848
1849extern "C" { static void thisModule() {} }
1850
1851#else
1852
1853extern "C" vcl::Window* SAL_CALL CreateWindow( VCLXWindow** ppNewComp, const css::awt::WindowDescriptor* pDescriptor, vcl::Window* pParent, WinBits nWinBits );
1854
1855#endif
1856
1857css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::ImplCreateWindow(
1858 const css::awt::WindowDescriptor& rDescriptor,
1859 MessBoxStyle nForceMessBoxStyle )
1860{
1861 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1862
1863 SolarMutexGuard aSolarGuard;
1864
1865 css::uno::Reference< css::awt::XWindowPeer > xRef;
1866
1867 VclPtr<vcl::Window> pParent;
1868 if ( rDescriptor.Parent.is() )
1869 {
1870 VCLXWindow* pParentComponent = comphelper::getUnoTunnelImplementation<VCLXWindow>( rDescriptor.Parent );
1871
1872 // #103939# Don't throw assertion, may be it's a system dependent window, used in ImplCreateWindow.
1873 // DBG_ASSERT( pParentComponent, "ParentComponent not valid" );
1874
1875 if ( pParentComponent )
1876 pParent = pParentComponent->GetWindow();
1877 }
1878 std::pair<WinBits, MessBoxStyle> aPair = ImplGetWinBits( rDescriptor.WindowAttributes,
1879 ImplGetComponentType( rDescriptor.WindowServiceName ) );
1880 WinBits nWinBits = aPair.first;
1881 aPair.second |= nForceMessBoxStyle;
1882
1883 VCLXWindow* pNewComp = nullptr;
1884
1885 vcl::Window* pNewWindow = nullptr;
1886 // Try to create the window with SvTools
1887 // (do this _before_ creating it on our own: The old mechanism (extended toolkit in SvTools) did it this way,
1888 // and we need to stay compatible)
1889 // try to load the lib
1890 if ( !fnSvtCreateWindow
1891#ifndef DISABLE_DYNLOADING
1892 && !hSvToolsLib
1893#endif
1894 )
1895 {
1896#ifndef DISABLE_DYNLOADING
1897 OUString aLibName(SVT_DLL_NAME"libsvtlo.so");
1898 hSvToolsLib = osl_loadModuleRelative(
1899 &thisModule, aLibName.pData, SAL_LOADMODULE_DEFAULT0x00000 );
1900 if ( hSvToolsLib )
1901 {
1902 OUString aFunctionName( "CreateWindow" );
1903 fnSvtCreateWindow = reinterpret_cast<FN_SvtCreateWindow>(osl_getFunctionSymbol( hSvToolsLib, aFunctionName.pData ));
1904 }
1905#else
1906 fnSvtCreateWindow = CreateWindow;
1907#endif
1908 }
1909 // ask the SvTool creation function
1910 if ( fnSvtCreateWindow )
1911 pNewWindow = fnSvtCreateWindow( &pNewComp, &rDescriptor, pParent, nWinBits );
1912
1913 // if SvTools could not provide a window, create it ourself
1914 if ( !pNewWindow )
1915 pNewWindow = ImplCreateWindow( &pNewComp, rDescriptor, pParent, nWinBits, aPair.second );
1916
1917 DBG_ASSERT( pNewWindow, "createWindow: Unknown Component!" )do { if (true && (!(pNewWindow))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
":" "1917" ": "), "%s", "createWindow: Unknown Component!");
} } while (false)
;
1918 SAL_INFO_IF( !pNewComp, "toolkit", "createWindow: No special Interface!" )do { if (true && (!pNewComp)) { switch (sal_detail_log_report
(::SAL_DETAIL_LOG_LEVEL_INFO, "toolkit")) { case SAL_DETAIL_LOG_ACTION_IGNORE
: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "createWindow: No special Interface!"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("toolkit"
), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
":" "1918" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "createWindow: No special Interface!"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "createWindow: No special Interface!"; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("toolkit"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
":" "1918" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "createWindow: No special Interface!") == 1) { ::
sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("toolkit"), (
"/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
":" "1918" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "createWindow: No special Interface!"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "createWindow: No special Interface!"; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("toolkit"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
":" "1918" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1919
1920 if ( pNewWindow )
1921 {
1922 pNewWindow->SetCreatedWithToolkit( true );
1923 //pNewWindow->SetPosPixel( Point() ); // do not force (0,0) position, keep default pos instead
1924
1925 if ( rDescriptor.WindowAttributes & css::awt::WindowAttribute::MINSIZE )
1926 {
1927 pNewWindow->SetSizePixel( Size() );
1928 }
1929 else if ( rDescriptor.WindowAttributes & css::awt::WindowAttribute::FULLSIZE )
1930 {
1931 if ( pParent )
1932 pNewWindow->SetSizePixel( pParent->GetOutputSizePixel() );
1933 }
1934 else if ( !VCLUnoHelper::IsZero( rDescriptor.Bounds ) )
1935 {
1936 tools::Rectangle aRect = VCLRectangle( rDescriptor.Bounds );
1937 pNewWindow->SetPosSizePixel( aRect.TopLeft(), aRect.GetSize() );
1938 }
1939
1940 if ( !pNewComp )
1941 {
1942 // Default-Interface
1943 xRef = pNewWindow->GetComponentInterface();
1944 }
1945 else
1946 {
1947 xRef = pNewComp;
1948 pNewWindow->SetComponentInterface( xRef );
1949 }
1950 DBG_ASSERT( pNewWindow->GetComponentInterface( false ) == xRef,do { if (true && (!(pNewWindow->GetComponentInterface
( false ) == xRef))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
":" "1951" ": "), "%s", "VCLXToolkit::createWindow: did #133706# resurge?"
); } } while (false)
1951 "VCLXToolkit::createWindow: did #133706# resurge?" )do { if (true && (!(pNewWindow->GetComponentInterface
( false ) == xRef))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
":" "1951" ": "), "%s", "VCLXToolkit::createWindow: did #133706# resurge?"
); } } while (false)
;
1952
1953 if ( rDescriptor.WindowAttributes & css::awt::WindowAttribute::SHOW )
1954 pNewWindow->Show();
1955 }
1956
1957 return xRef;
1958}
1959
1960css::uno::Sequence< css::uno::Reference< css::awt::XWindowPeer > > VCLXToolkit::createWindows( const css::uno::Sequence< css::awt::WindowDescriptor >& rDescriptors )
1961{
1962 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1963
1964 sal_uInt32 nComponents = rDescriptors.getLength();
1965 css::uno::Sequence< css::uno::Reference< css::awt::XWindowPeer > > aSeq( nComponents );
1966 for ( sal_uInt32 n = 0; n < nComponents; n++ )
1967 {
1968 css::awt::WindowDescriptor aDescr = rDescriptors.getConstArray()[n];
1969
1970 if ( aDescr.ParentIndex == -1 )
1971 aDescr.Parent = nullptr;
1972 else if ( ( aDescr.ParentIndex >= 0 ) && ( aDescr.ParentIndex < static_cast<short>(n) ) )
1973 aDescr.Parent = aSeq.getConstArray()[aDescr.ParentIndex];
1974 aSeq.getArray()[n] = createWindow( aDescr );
1975 }
1976 return aSeq;
1977}
1978
1979// css::awt::XSystemChildFactory
1980css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::createSystemChild( const css::uno::Any& Parent, const css::uno::Sequence< sal_Int8 >& /*ProcessId*/, sal_Int16 nSystemType )
1981{
1982 VclPtr<vcl::Window> pChildWindow;
1983 if ( nSystemType == SYSTEM_DEPENDENT_TYPEcss::lang::SystemDependent::SYSTEM_XWINDOW )
1984 {
1985 // use sal_Int64 here to accommodate all int types
1986 // uno::Any shift operator whill upcast if necessary
1987 sal_Int64 nWindowHandle = 0;
1988 bool bXEmbed = false;
1989
1990 bool bUseParentData = true;
1991 if( ! (Parent >>= nWindowHandle) )
1992 {
1993 css::uno::Sequence< css::beans::NamedValue > aProps;
1994 if( Parent >>= aProps )
1995 {
1996 for( const css::beans::NamedValue& rProp : std::as_const(aProps) )
1997 {
1998 if ( rProp.Name == "WINDOW" )
1999 rProp.Value >>= nWindowHandle;
2000 else if ( rProp.Name == "XEMBED" )
2001 rProp.Value >>= bXEmbed;
2002 }
2003 }
2004 else
2005 bUseParentData = false;
2006 }
2007
2008 if( bUseParentData )
2009 {
2010 SystemParentData aParentData;
2011 aParentData.nSize = sizeof( aParentData );
2012 #if defined MACOSX
2013 aParentData.pView = reinterpret_cast<NSView*>(nWindowHandle);
2014 #elif defined ANDROID
2015 // Nothing
2016 #elif defined IOS
2017 // Nothing
2018 #elif defined UNX1
2019 aParentData.aWindow = nWindowHandle;
2020 aParentData.bXEmbedSupport = bXEmbed;
2021 #elif defined _WIN32
2022 aParentData.hWnd = reinterpret_cast<HWND>(nWindowHandle);
2023 #endif
2024 SolarMutexGuard aGuard;
2025 try
2026 {
2027 pChildWindow.reset( VclPtr<WorkWindow>::Create( &aParentData ) );
2028 }
2029 catch ( const css::uno::RuntimeException & )
2030 {
2031 // system child window could not be created
2032 DBG_UNHANDLED_EXCEPTION("toolkit")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
":" "2032" ": ", "toolkit" );
;
2033 pChildWindow.clear();
2034 }
2035 }
2036 }
2037 else if (nSystemType == css::lang::SystemDependent::SYSTEM_JAVA)
2038 {
2039 SolarMutexGuard aGuard;
2040 pChildWindow.reset(VclPtr<WorkWindow>::Create(nullptr, Parent));
2041 }
2042
2043 css::uno::Reference< css::awt::XWindowPeer > xPeer;
2044 if ( pChildWindow )
2045 {
2046 VCLXTopWindow* pPeer = new VCLXTopWindow;
2047 SolarMutexGuard aGuard;
2048 pPeer->SetWindow( pChildWindow );
2049 xPeer = pPeer;
2050 }
2051
2052 return xPeer;
2053}
2054
2055// css::awt::XMessageBoxFactory
2056css::uno::Reference< css::awt::XMessageBox > SAL_CALL VCLXToolkit::createMessageBox(
2057 const css::uno::Reference< css::awt::XWindowPeer >& aParent,
2058 css::awt::MessageBoxType eType,
2059 ::sal_Int32 aButtons,
2060 const OUString& aTitle,
2061 const OUString& aMessage )
2062{
2063 css::awt::WindowDescriptor aDescriptor;
2064
2065 sal_Int32 nWindowAttributes = css::awt::WindowAttribute::BORDER|css::awt::WindowAttribute::MOVEABLE|css::awt::WindowAttribute::CLOSEABLE;
2066
2067 // Map button definitions to window attributes
2068 if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK )
2069 nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK;
2070 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK_CANCEL )
2071 nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK_CANCEL;
2072 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO )
2073 nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO;
2074 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO_CANCEL )
2075 nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO_CANCEL;
2076 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_RETRY_CANCEL )
2077 nWindowAttributes |= css::awt::VclWindowPeerAttribute::RETRY_CANCEL;
2078
2079 // Map default button definitions to window attributes
2080 if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_OK )
2081 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_OK;
2082 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_CANCEL )
2083 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_CANCEL;
2084 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_YES )
2085 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_YES;
2086 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_NO )
2087 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_NO;
2088 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_RETRY )
2089 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_RETRY;
2090
2091 // No more bits for VclWindowPeerAttribute possible. Mapping must be
2092 // done explicitly using VCL methods
2093 MessBoxStyle nAddWinBits = MessBoxStyle::NONE;
2094 if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_ABORT_IGNORE_RETRY )
2095 nAddWinBits |= MessBoxStyle::AbortRetryIgnore;
2096 if ( sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_IGNORE )
2097 nAddWinBits |= MessBoxStyle::DefaultIgnore;
2098
2099 OUString aType;
2100 lcl_convertMessageBoxType( aType, eType );
2101
2102 aDescriptor.Type = css::awt::WindowClass_MODALTOP;
2103 aDescriptor.WindowServiceName = aType;
2104 aDescriptor.ParentIndex = -1;
2105 aDescriptor.Parent = aParent;
2106 aDescriptor.WindowAttributes = nWindowAttributes;
2107 css::uno::Reference< css::awt::XMessageBox > xMsgBox(
2108 ImplCreateWindow( aDescriptor, nAddWinBits ), css::uno::UNO_QUERY );
2109 css::uno::Reference< css::awt::XWindow > xWindow( xMsgBox, css::uno::UNO_QUERY );
2110 if ( xMsgBox.is() && xWindow.is() )
2111 {
2112 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2113 if ( pWindow )
2114 {
2115 SolarMutexGuard aGuard;
2116 xMsgBox->setCaptionText( aTitle );
2117 xMsgBox->setMessageText( aMessage );
2118 }
2119 }
2120
2121 return xMsgBox;
2122}
2123
2124css::uno::Reference< css::datatransfer::dnd::XDragGestureRecognizer > SAL_CALL VCLXToolkit::getDragGestureRecognizer( const css::uno::Reference< css::awt::XWindow >& window )
2125{
2126 SolarMutexGuard g;
2127
2128 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( window );
2129
2130 if( pWindow )
2131 return pWindow->GetDragGestureRecognizer();
2132
2133 return css::uno::Reference< css::datatransfer::dnd::XDragGestureRecognizer >();
2134}
2135
2136css::uno::Reference< css::datatransfer::dnd::XDragSource > SAL_CALL VCLXToolkit::getDragSource( const css::uno::Reference< css::awt::XWindow >& window )
2137{
2138 SolarMutexGuard g;
2139
2140 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( window );
2141
2142 if( pWindow )
2143 return pWindow->GetDragSource();
2144
2145 return css::uno::Reference< css::datatransfer::dnd::XDragSource >();
2146}
2147
2148css::uno::Reference< css::datatransfer::dnd::XDropTarget > SAL_CALL VCLXToolkit::getDropTarget( const css::uno::Reference< css::awt::XWindow >& window )
2149{
2150 SolarMutexGuard g;
2151
2152 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( window );
2153
2154 if( pWindow )
2155 return pWindow->GetDropTarget();
2156
2157 return css::uno::Reference< css::datatransfer::dnd::XDropTarget >();
2158}
2159
2160css::uno::Reference< css::datatransfer::clipboard::XClipboard > SAL_CALL VCLXToolkit::getClipboard( const OUString& clipboardName )
2161{
2162 if( clipboardName.isEmpty() )
2163 {
2164 if( !mxClipboard.is() )
2165 {
2166 // remember clipboard here
2167 mxClipboard = css::datatransfer::clipboard::SystemClipboard::create(
2168 comphelper::getProcessComponentContext());
2169 }
2170
2171 return mxClipboard;
2172 }
2173
2174 else if( clipboardName == "Selection" )
2175 {
2176 return mxSelection;
2177 }
2178
2179 return css::uno::Reference< css::datatransfer::clipboard::XClipboard >();
2180}
2181
2182// XServiceInfo
2183OUString VCLXToolkit::getImplementationName()
2184{
2185 return "stardiv.Toolkit.VCLXToolkit";
2186}
2187
2188sal_Bool VCLXToolkit::supportsService( const OUString& rServiceName )
2189{
2190 return cppu::supportsService(this, rServiceName);
2191}
2192
2193css::uno::Sequence< OUString > VCLXToolkit::getSupportedServiceNames()
2194{
2195 return css::uno::Sequence<OUString>{
2196 "com.sun.star.awt.Toolkit", "stardiv.vcl.VclToolkit"};
2197}
2198
2199// css::awt::XExtendedToolkit:
2200
2201// virtual
2202::sal_Int32 SAL_CALL VCLXToolkit::getTopWindowCount()
2203{
2204 return static_cast< ::sal_Int32 >(::Application::GetTopWindowCount());
2205 // XXX numeric overflow
2206}
2207
2208// virtual
2209css::uno::Reference< css::awt::XTopWindow > SAL_CALL
2210VCLXToolkit::getTopWindow(::sal_Int32 nIndex)
2211{
2212 vcl::Window * p = ::Application::GetTopWindow(static_cast< long >(nIndex));
2213 // XXX numeric overflow
2214 return css::uno::Reference< css::awt::XTopWindow >(
2215 p == nullptr ? nullptr : static_cast< css::awt::XWindow * >(p->GetWindowPeer()),
2216 css::uno::UNO_QUERY);
2217}
2218
2219// virtual
2220css::uno::Reference< css::awt::XTopWindow > SAL_CALL
2221VCLXToolkit::getActiveTopWindow()
2222{
2223 vcl::Window * p = ::Application::GetActiveTopWindow();
2224 return css::uno::Reference< css::awt::XTopWindow >(
2225 p == nullptr ? nullptr : static_cast< css::awt::XWindow * >(p->GetWindowPeer()),
2226 css::uno::UNO_QUERY);
2227}
2228
2229// virtual
2230void SAL_CALL VCLXToolkit::addTopWindowListener(
2231 css::uno::Reference< css::awt::XTopWindowListener > const & rListener)
2232{
2233 OSL_ENSURE(rListener.is(), "Null rListener")do { if (true && (!(rListener.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
":" "2233" ": "), "%s", "Null rListener"); } } while (false)
;
2234 ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
2235 if (rBHelper.bDisposed || rBHelper.bInDispose)
2236 {
2237 aGuard.clear();
2238 rListener->disposing(
2239 css::lang::EventObject(
2240 static_cast< ::cppu::OWeakObject * >(this)));
2241 }
2242 else if (m_aTopWindowListeners.addInterface(rListener) == 1
2243 && !m_bEventListener)
2244 {
2245 m_bEventListener = true;
2246 ::Application::AddEventListener(m_aEventListenerLink);
2247 }
2248}
2249
2250// virtual
2251void SAL_CALL VCLXToolkit::removeTopWindowListener(
2252 css::uno::Reference< css::awt::XTopWindowListener > const & rListener)
2253{
2254 ::osl::MutexGuard aGuard(rBHelper.rMutex);
2255 if (!(rBHelper.bDisposed || rBHelper.bInDispose)
2256 && m_aTopWindowListeners.removeInterface(rListener) == 0
2257 && m_aFocusListeners.getLength() == 0 && m_bEventListener)
2258 {
2259 ::Application::RemoveEventListener(m_aEventListenerLink);
2260 m_bEventListener = false;
2261 }
2262}
2263
2264// virtual
2265void SAL_CALL VCLXToolkit::addKeyHandler(
2266 css::uno::Reference< css::awt::XKeyHandler > const & rHandler)
2267{
2268 OSL_ENSURE(rHandler.is(), "Null rHandler")do { if (true && (!(rHandler.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
":" "2268" ": "), "%s", "Null rHandler"); } } while (false)
;
2269 ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
2270 if (rBHelper.bDisposed || rBHelper.bInDispose)
2271 {
2272 aGuard.clear();
2273 rHandler->disposing(
2274 css::lang::EventObject(
2275 static_cast< ::cppu::OWeakObject * >(this)));
2276 }
2277 else if (m_aKeyHandlers.addInterface(rHandler) == 1 && !m_bKeyListener)
2278 {
2279 m_bKeyListener = true;
2280 ::Application::AddKeyListener(m_aKeyListenerLink);
2281 }
2282}
2283
2284// virtual
2285void SAL_CALL VCLXToolkit::removeKeyHandler(
2286 css::uno::Reference< css::awt::XKeyHandler > const & rHandler)
2287{
2288 ::osl::MutexGuard aGuard(rBHelper.rMutex);
2289 if (!(rBHelper.bDisposed || rBHelper.bInDispose)
2290 && m_aKeyHandlers.removeInterface(rHandler) == 0 && m_bKeyListener)
2291 {
2292 ::Application::RemoveKeyListener(m_aKeyListenerLink);
2293 m_bKeyListener = false;
2294 }
2295}
2296
2297// virtual
2298void SAL_CALL VCLXToolkit::addFocusListener(
2299 css::uno::Reference< css::awt::XFocusListener > const & rListener)
2300{
2301 OSL_ENSURE(rListener.is(), "Null rListener")do { if (true && (!(rListener.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
":" "2301" ": "), "%s", "Null rListener"); } } while (false)
;
2302 ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
2303 if (rBHelper.bDisposed || rBHelper.bInDispose)
2304 {
2305 aGuard.clear();
2306 rListener->disposing(
2307 css::lang::EventObject(
2308 static_cast< ::cppu::OWeakObject * >(this)));
2309 }
2310 else if (m_aFocusListeners.addInterface(rListener) == 1
2311 && !m_bEventListener)
2312 {
2313 m_bEventListener = true;
2314 ::Application::AddEventListener(m_aEventListenerLink);
2315 }
2316}
2317
2318// virtual
2319void SAL_CALL VCLXToolkit::removeFocusListener(
2320 css::uno::Reference< css::awt::XFocusListener > const & rListener)
2321{
2322 ::osl::MutexGuard aGuard(rBHelper.rMutex);
2323 if (!(rBHelper.bDisposed || rBHelper.bInDispose)
2324 && m_aFocusListeners.removeInterface(rListener) == 0
2325 && m_aTopWindowListeners.getLength() == 0 && m_bEventListener)
2326 {
2327 ::Application::RemoveEventListener(m_aEventListenerLink);
2328 m_bEventListener = false;
2329 }
2330}
2331
2332// virtual
2333void SAL_CALL VCLXToolkit::fireFocusGained(
2334 css::uno::Reference<
2335 css::uno::XInterface > const &)
2336{
2337}
2338
2339// virtual
2340void SAL_CALL VCLXToolkit::fireFocusLost(
2341 css::uno::Reference<
2342 css::uno::XInterface > const &)
2343{
2344}
2345
2346
2347IMPL_LINK(VCLXToolkit, eventListenerHandler, ::VclSimpleEvent&, rEvent, void)void VCLXToolkit::LinkStubeventListenerHandler(void * instance
, ::VclSimpleEvent& data) { return static_cast<VCLXToolkit
*>(instance)->eventListenerHandler(data); } void VCLXToolkit
::eventListenerHandler(::VclSimpleEvent& rEvent)
2348{
2349 switch (rEvent.GetId())
2350 {
2351 case VclEventId::WindowShow:
2352 callTopWindowListeners(
2353 &rEvent, &css::awt::XTopWindowListener::windowOpened);
2354 break;
2355 case VclEventId::WindowHide:
2356 callTopWindowListeners(
2357 &rEvent, &css::awt::XTopWindowListener::windowClosed);
2358 break;
2359 case VclEventId::WindowActivate:
2360 callTopWindowListeners(
2361 &rEvent, &css::awt::XTopWindowListener::windowActivated);
2362 break;
2363 case VclEventId::WindowDeactivate:
2364 callTopWindowListeners(
2365 &rEvent, &css::awt::XTopWindowListener::windowDeactivated);
2366 break;
2367 case VclEventId::WindowClose:
2368 callTopWindowListeners(
2369 &rEvent, &css::awt::XTopWindowListener::windowClosing);
2370 break;
2371 case VclEventId::WindowGetFocus:
2372 callFocusListeners(&rEvent, true);
2373 break;
2374 case VclEventId::WindowLoseFocus:
2375 callFocusListeners(&rEvent, false);
2376 break;
2377 case VclEventId::WindowMinimize:
2378 callTopWindowListeners(
2379 &rEvent, &css::awt::XTopWindowListener::windowMinimized);
2380 break;
2381 case VclEventId::WindowNormalize:
2382 callTopWindowListeners(
2383 &rEvent, &css::awt::XTopWindowListener::windowNormalized);
2384 break;
2385 default: break;
2386 }
2387}
2388
2389IMPL_LINK(VCLXToolkit, keyListenerHandler, ::VclWindowEvent&, rEvent, bool)bool VCLXToolkit::LinkStubkeyListenerHandler(void * instance,
::VclWindowEvent& data) { return static_cast<VCLXToolkit
*>(instance)->keyListenerHandler(data); } bool VCLXToolkit
::keyListenerHandler(::VclWindowEvent& rEvent)
2390{
2391 switch (rEvent.GetId())
2392 {
2393 case VclEventId::WindowKeyInput:
2394 return callKeyHandlers(&rEvent, true);
2395 case VclEventId::WindowKeyUp:
2396 return callKeyHandlers(&rEvent, false);
2397 default: break;
2398 }
2399 return false;
2400}
2401
2402void VCLXToolkit::callTopWindowListeners(
2403 ::VclSimpleEvent const * pEvent,
2404 void (SAL_CALL css::awt::XTopWindowListener::* pFn)(
2405 css::lang::EventObject const &))
2406{
2407 vcl::Window * pWindow
2408 = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
2409 if (!pWindow->IsTopWindow())
2410 return;
2411
2412 std::vector< css::uno::Reference< css::uno::XInterface > >
2413 aListeners(m_aTopWindowListeners.getElements());
2414 if (aListeners.empty())
2415 return;
2416
2417 css::lang::EventObject aAwtEvent(
2418 static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer()));
2419 for (const css::uno::Reference<XInterface> & i : aListeners)
2420 {
2421 css::uno::Reference< css::awt::XTopWindowListener >
2422 xListener(i, css::uno::UNO_QUERY);
2423 try
2424 {
2425 (xListener.get()->*pFn)(aAwtEvent);
2426 }
2427 catch (const css::uno::RuntimeException &)
2428 {
2429 DBG_UNHANDLED_EXCEPTION("toolkit")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
":" "2429" ": ", "toolkit" );
;
2430 }
2431 }
2432}
2433
2434bool VCLXToolkit::callKeyHandlers(::VclSimpleEvent const * pEvent,
2435 bool bPressed)
2436{
2437 std::vector< css::uno::Reference< css::uno::XInterface > >
2438 aHandlers(m_aKeyHandlers.getElements());
2439
2440 if (!aHandlers.empty())
2441 {
2442 vcl::Window * pWindow = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
2443
2444 // See implementation in vclxwindow.cxx for mapping between VCL and UNO AWT event
2445 ::KeyEvent * pKeyEvent = static_cast< ::KeyEvent * >(
2446 static_cast< ::VclWindowEvent const * >(pEvent)->GetData());
2447 css::awt::KeyEvent aAwtEvent(
2448 static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer()),
2449 (pKeyEvent->GetKeyCode().IsShift()
2450 ? css::awt::KeyModifier::SHIFT : 0)
2451 | (pKeyEvent->GetKeyCode().IsMod1()
2452 ? css::awt::KeyModifier::MOD1 : 0)
2453 | (pKeyEvent->GetKeyCode().IsMod2()
2454 ? css::awt::KeyModifier::MOD2 : 0)
2455 | (pKeyEvent->GetKeyCode().IsMod3()
2456 ? css::awt::KeyModifier::MOD3 : 0),
2457 pKeyEvent->GetKeyCode().GetCode(), pKeyEvent->GetCharCode(),
2458 sal::static_int_cast< sal_Int16 >(
2459 pKeyEvent->GetKeyCode().GetFunction()));
2460 for (const css::uno::Reference<XInterface> & i : aHandlers)
2461 {
2462 css::uno::Reference< css::awt::XKeyHandler > xHandler(
2463 i, css::uno::UNO_QUERY);
2464 try
2465 {
2466 if (bPressed ? xHandler->keyPressed(aAwtEvent)
2467 : xHandler->keyReleased(aAwtEvent))
2468 return true;
2469 }
2470 catch (const css::uno::RuntimeException &)
2471 {
2472 DBG_UNHANDLED_EXCEPTION("toolkit")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
":" "2472" ": ", "toolkit" );
;
2473 }
2474 }
2475 }
2476 return false;
2477}
2478
2479void VCLXToolkit::callFocusListeners(::VclSimpleEvent const * pEvent,
2480 bool bGained)
2481{
2482 vcl::Window * pWindow
2483 = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
2484 if (!pWindow->IsTopWindow())
2485 return;
2486
2487 std::vector< css::uno::Reference< css::uno::XInterface > >
2488 aListeners(m_aFocusListeners.getElements());
2489 if (aListeners.empty())
2490 return;
2491
2492 // Ignore the interior of compound controls when determining the
2493 // window that gets the focus next (see implementation in
2494 // vclxwindow.cxx for mapping between VCL and UNO AWT event):
2495 css::uno::Reference< css::uno::XInterface > xNext;
2496 vcl::Window * pFocus = ::Application::GetFocusWindow();
2497 for (vcl::Window * p = pFocus; p != nullptr; p = p->GetParent())
2498 if (!p->IsCompoundControl())
2499 {
2500 pFocus = p;
2501 break;
2502 }
2503 if (pFocus != nullptr)
2504 xNext = pFocus->GetComponentInterface();
2505 css::awt::FocusEvent aAwtEvent(
2506 static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer()),
2507 static_cast<sal_Int16>(pWindow->GetGetFocusFlags()),
2508 xNext, false);
2509 for (const css::uno::Reference<XInterface> & i : aListeners)
2510 {
2511 css::uno::Reference< css::awt::XFocusListener > xListener(
2512 i, css::uno::UNO_QUERY);
2513 try
2514 {
2515 bGained ? xListener->focusGained(aAwtEvent)
2516 : xListener->focusLost(aAwtEvent);
2517 }
2518 catch (const css::uno::RuntimeException &)
2519 {
2520 DBG_UNHANDLED_EXCEPTION("toolkit")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/toolkit/source/awt/vclxtoolkit.cxx"
":" "2520" ": ", "toolkit" );
;
2521 }
2522 }
2523}
2524
2525// css::awt::XReschedule:
2526
2527void SAL_CALL VCLXToolkit::reschedule()
2528{
2529 SolarMutexGuard aSolarGuard;
2530 Application::Reschedule(true);
2531}
2532
2533// css::awt::XToolkitExperimental
2534
2535void SAL_CALL VCLXToolkit::processEventsToIdle()
2536{
2537 SolarMutexGuard aSolarGuard;
2538 comphelper::ProfileZone aZone("processEvents");
2539 Scheduler::ProcessEventsToIdle();
2540}
2541
2542sal_Int64 SAL_CALL VCLXToolkit::getOpenGLBufferSwapCounter()
2543{
2544#if HAVE_FEATURE_OPENGL1
2545 return OpenGLWrapper::getBufferSwapCounter();
2546#else
2547 return 0;
2548#endif
2549}
2550
2551void SAL_CALL VCLXToolkit::setDeterministicScheduling(sal_Bool bDeterministicMode)
2552{
2553 SolarMutexGuard aSolarGuard;
2554 Scheduler::SetDeterministicMode(bDeterministicMode);
2555}
2556
2557void SAL_CALL VCLXToolkit::pause(sal_Int32 nMilliseconds)
2558{
2559 new Pause(nMilliseconds);
2560}
2561
2562void SAL_CALL VCLXToolkit::startRecording()
2563{
2564 ::comphelper::ProfileRecording::startRecording(true);
2565}
2566
2567void SAL_CALL VCLXToolkit::stopRecording()
2568{
2569 ::comphelper::ProfileRecording::startRecording( false );
2570}
2571
2572css::uno::Sequence< OUString > VCLXToolkit::getRecordingAndClear()
2573{
2574 return ::comphelper::ProfileRecording::getRecordingAndClear();
2575}
2576
2577// css:awt:XToolkitRobot
2578
2579void SAL_CALL VCLXToolkit::keyPress( const css::awt::KeyEvent & aKeyEvent )
2580{
2581 css::uno::Reference<css::awt::XWindow> xWindow ( aKeyEvent.Source, css::uno::UNO_QUERY_THROW );
2582 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2583 if( !pWindow )
2584 throw css::uno::RuntimeException( "invalid event source" );
2585
2586 ::KeyEvent aVCLKeyEvent = VCLUnoHelper::createVCLKeyEvent( aKeyEvent );
2587 ::Application::PostKeyEvent( VclEventId::WindowKeyInput, pWindow, &aVCLKeyEvent );
2588}
2589
2590void SAL_CALL VCLXToolkit::keyRelease( const css::awt::KeyEvent & aKeyEvent )
2591{
2592 css::uno::Reference<css::awt::XWindow> xWindow ( aKeyEvent.Source, css::uno::UNO_QUERY_THROW );
2593 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2594 if( !pWindow )
2595 throw css::uno::RuntimeException( "invalid event source" );
2596
2597 ::KeyEvent aVCLKeyEvent = VCLUnoHelper::createVCLKeyEvent( aKeyEvent );
2598 ::Application::PostKeyEvent( VclEventId::WindowKeyUp, pWindow, &aVCLKeyEvent );
2599}
2600
2601
2602void SAL_CALL VCLXToolkit::mousePress( const css::awt::MouseEvent & aMouseEvent )
2603{
2604 css::uno::Reference<css::awt::XWindow> xWindow ( aMouseEvent.Source, css::uno::UNO_QUERY_THROW );
2605 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2606 if( !pWindow )
2607 throw css::uno::RuntimeException( "invalid event source" );
2608
2609 ::MouseEvent aVCLMouseEvent = VCLUnoHelper::createVCLMouseEvent( aMouseEvent );
2610 ::Application::PostMouseEvent( VclEventId::WindowMouseButtonDown, pWindow, &aVCLMouseEvent );
2611}
2612
2613void SAL_CALL VCLXToolkit::mouseRelease( const css::awt::MouseEvent & aMouseEvent )
2614{
2615 css::uno::Reference<css::awt::XWindow> xWindow ( aMouseEvent.Source, css::uno::UNO_QUERY_THROW );
2616 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2617 if( !pWindow )
2618 throw css::uno::RuntimeException( "invalid event source" );
2619
2620 ::MouseEvent aVCLMouseEvent = VCLUnoHelper::createVCLMouseEvent( aMouseEvent );
2621 ::Application::PostMouseEvent( VclEventId::WindowMouseButtonUp, pWindow, &aVCLMouseEvent );
2622}
2623
2624void SAL_CALL VCLXToolkit::mouseMove( const css::awt::MouseEvent & aMouseEvent )
2625{
2626 css::uno::Reference<css::awt::XWindow> xWindow ( aMouseEvent.Source, css::uno::UNO_QUERY_THROW );
2627 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2628 if( !pWindow )
2629 throw css::uno::RuntimeException( "invalid event source" );
2630
2631 ::MouseEvent aVCLMouseEvent = VCLUnoHelper::createVCLMouseEvent( aMouseEvent );
2632 ::Application::PostMouseEvent( VclEventId::WindowMouseMove, pWindow, &aVCLMouseEvent );
2633}
2634
2635
2636}
2637
2638extern "C" SAL_DLLPUBLIC_EXPORT__attribute__ ((visibility("default"))) css::uno::XInterface *
2639stardiv_Toolkit_VCLXToolkit_get_implementation(
2640 css::uno::XComponentContext *,
2641 css::uno::Sequence<css::uno::Any> const &)
2642{
2643 return cppu::acquire(new VCLXToolkit());
2644}
2645
2646/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx

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#ifndef INCLUDED_VCL_PTR_HXX
21#define INCLUDED_VCL_PTR_HXX
22
23#include <sal/config.h>
24
25#include <rtl/ref.hxx>
26
27#include <utility>
28#include <type_traits>
29
30#ifdef DBG_UTIL
31#ifndef _WIN32
32#include <vcl/vclmain.hxx>
33#endif
34#endif
35
36class VclReferenceBase;
37
38namespace vcl::detail {
39
40template<typename>
41constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; }
42
43template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase(
44 int (*)[sizeof(T)])
45{ return std::is_base_of<VclReferenceBase, T>::value; }
46
47} // namespace vcl::detail
48
49/**
50 * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses.
51 *
52 * For more details on the design please see vcl/README.lifecycle
53 *
54 * @param reference_type must be a subclass of vcl::Window
55 */
56template <class reference_type>
57class VclPtr
58{
59 static_assert(
60 vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>(
61 nullptr),
62 "template argument type must be derived from VclReferenceBase");
63
64 ::rtl::Reference<reference_type> m_rInnerRef;
65
66public:
67 /** Constructor...
68 */
69 VclPtr()
70 : m_rInnerRef()
71 {}
72
73 /** Constructor...
74 */
75 VclPtr (reference_type * pBody)
76 : m_rInnerRef(pBody)
77 {}
78
79 /** Constructor... that doesn't take a ref.
80 */
81 VclPtr (reference_type * pBody, __sal_NoAcquire)
82 : m_rInnerRef(pBody, SAL_NO_ACQUIRE)
83 {}
84
85 /** Up-casting conversion constructor: Copies interface reference.
86
87 Does not work for up-casts to ambiguous bases. For the special case of
88 up-casting to Reference< XInterface >, see the corresponding conversion
89 operator.
90
91 @param rRef another reference
92 */
93 template< class derived_type >
94 VclPtr(
95 const VclPtr< derived_type > & rRef,
96 typename std::enable_if<
97 std::is_base_of<reference_type, derived_type>::value, int>::type
98 = 0 )
99 : m_rInnerRef( static_cast<reference_type*>(rRef) )
100 {
101 }
102
103#if defined(DBG_UTIL) && !defined(_WIN32)
104 virtual ~VclPtr()
105 {
106 assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain
::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 106, __extension__ __PRETTY_FUNCTION__))
;
107 // We can be one of the intermediate counts, but if we are the last
108 // VclPtr keeping this object alive, then something forgot to call dispose().
109 assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
110 && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
;
111 }
112 VclPtr(VclPtr const &) = default;
113 VclPtr(VclPtr &&) = default;
114 VclPtr & operator =(VclPtr const &) = default;
115 VclPtr & operator =(VclPtr &&) = default;
116#endif
117
118 /**
119 * A construction helper for VclPtr. Since VclPtr types are created
120 * with a reference-count of one - to help fit into the existing
121 * code-flow; this helps us to construct them easily.
122 *
123 * For more details on the design please see vcl/README.lifecycle
124 *
125 * @tparam reference_type must be a subclass of vcl::Window
126 */
127 template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg)
128 {
129 return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE );
130 }
131
132 /** Probably most common used: handle->someBodyOp().
133 */
134 reference_type * operator->() const
135 {
136 return m_rInnerRef.get();
137 }
138
139 /** Get the body. Can be used instead of operator->().
140 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
141 are the same.
142 */
143 reference_type * get() const
144 {
145 return m_rInnerRef.get();
146 }
147
148 void set(reference_type *pBody)
149 {
150 m_rInnerRef.set(pBody);
151 }
152
153 void reset(reference_type *pBody)
154 {
155 m_rInnerRef.set(pBody);
156 }
157
158 /** Up-casting copy assignment operator.
159
160 Does not work for up-casts to ambiguous bases.
161
162 @param rRef another reference
163 */
164 template<typename derived_type>
165 typename std::enable_if<
166 std::is_base_of<reference_type, derived_type>::value,
167 VclPtr &>::type
168 operator =(VclPtr<derived_type> const & rRef)
169 {
170 m_rInnerRef.set(rRef.get());
171 return *this;
172 }
173
174 VclPtr & operator =(reference_type * pBody)
175 {
176 m_rInnerRef.set(pBody);
177 return *this;
178 }
179
180 operator reference_type * () const
181 {
182 return m_rInnerRef.get();
183 }
184
185 explicit operator bool () const
186 {
187 return m_rInnerRef.get() != nullptr;
188 }
189
190 void clear()
191 {
192 m_rInnerRef.clear();
193 }
194
195 void reset()
196 {
197 m_rInnerRef.clear();
198 }
199
200 void disposeAndClear()
201 {
202 // hold it alive for the lifetime of this method
203 ::rtl::Reference<reference_type> aTmp(m_rInnerRef);
2
Calling copy constructor for 'Reference<FixedImage>'
5
Returning from copy constructor for 'Reference<FixedImage>'
204 m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-)
6
Calling 'Reference::clear'
13
Returning; memory was released
205 if (aTmp.get()) {
14
Calling 'Reference::get'
206 aTmp->disposeOnce();
207 }
208 }
209
210 /** Needed to place VclPtr's into STL collection.
211 */
212 bool operator< (const VclPtr<reference_type> & handle) const
213 {
214 return (m_rInnerRef < handle.m_rInnerRef);
215 }
216}; // class VclPtr
217
218template<typename T1, typename T2>
219inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
220 return p1.get() == p2.get();
221}
222
223template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2)
224{
225 return p1.get() == p2;
226}
227
228template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) {
229 return p1.get() == p2;
230}
231
232template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2)
233{
234 return p1 == p2.get();
235}
236
237template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) {
238 return p1 == p2.get();
239}
240
241template<typename T1, typename T2>
242inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
243 return !(p1 == p2);
244}
245
246template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2)
247{
248 return !(p1 == p2);
249}
250
251template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) {
252 return !(p1 == p2);
253}
254
255template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2)
256{
257 return !(p1 == p2);
258}
259
260template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) {
261 return !(p1 == p2);
262}
263
264/**
265 * A construction helper for a temporary VclPtr. Since VclPtr types
266 * are created with a reference-count of one - to help fit into
267 * the existing code-flow; this helps us to construct them easily.
268 * see also VclPtr::Create and ScopedVclPtr
269 *
270 * For more details on the design please see vcl/README.lifecycle
271 *
272 * @param reference_type must be a subclass of vcl::Window
273 */
274template <class reference_type>
275class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type>
276{
277public:
278 template<typename... Arg> VclPtrInstance(Arg &&... arg)
279 : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
280 {
281 }
282
283 /**
284 * Override and disallow this, to prevent people accidentally calling it and actually
285 * getting VclPtr::Create and getting a naked VclPtr<> instance
286 */
287 template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete;
288};
289
290template <class reference_type>
291class ScopedVclPtr : public VclPtr<reference_type>
292{
293public:
294 /** Constructor...
295 */
296 ScopedVclPtr()
297 : VclPtr<reference_type>()
298 {}
299
300 /** Constructor
301 */
302 ScopedVclPtr (reference_type * pBody)
303 : VclPtr<reference_type>(pBody)
304 {}
305
306 /** Copy constructor...
307 */
308 ScopedVclPtr (const VclPtr<reference_type> & handle)
309 : VclPtr<reference_type>(handle)
310 {}
311
312 /**
313 Assignment that releases the last reference.
314 */
315 void disposeAndReset(reference_type *pBody)
316 {
317 if (pBody != this->get()) {
318 VclPtr<reference_type>::disposeAndClear();
319 VclPtr<reference_type>::set(pBody);
320 }
321 }
322
323 /**
324 Assignment that releases the last reference.
325 */
326 ScopedVclPtr<reference_type>& operator = (reference_type * pBody)
327 {
328 disposeAndReset(pBody);
329 return *this;
330 }
331
332 /** Up-casting conversion constructor: Copies interface reference.
333
334 Does not work for up-casts to ambiguous bases. For the special case of
335 up-casting to Reference< XInterface >, see the corresponding conversion
336 operator.
337
338 @param rRef another reference
339 */
340 template< class derived_type >
341 ScopedVclPtr(
342 const VclPtr< derived_type > & rRef,
343 typename std::enable_if<
344 std::is_base_of<reference_type, derived_type>::value, int>::type
345 = 0 )
346 : VclPtr<reference_type>( rRef )
347 {
348 }
349
350 /** Up-casting assignment operator.
351
352 Does not work for up-casts to ambiguous bases.
353
354 @param rRef another VclPtr
355 */
356 template<typename derived_type>
357 typename std::enable_if<
358 std::is_base_of<reference_type, derived_type>::value,
359 ScopedVclPtr &>::type
360 operator =(VclPtr<derived_type> const & rRef)
361 {
362 disposeAndReset(rRef.get());
363 return *this;
364 }
365
366 /**
367 * Override and disallow this, to prevent people accidentally calling it and actually
368 * getting VclPtr::Create and getting a naked VclPtr<> instance
369 */
370 template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete;
371
372 ~ScopedVclPtr()
373 {
374 VclPtr<reference_type>::disposeAndClear();
375 assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get(
) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 375, __extension__ __PRETTY_FUNCTION__))
; // make sure there are no lingering references
376 }
377
378private:
379 // Most likely we don't want this default copy-constructor.
380 ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete;
381 // And certainly we don't want a default assignment operator.
382 ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete;
383 // And disallow reset as that doesn't call disposeAndClear on the original reference
384 void reset() = delete;
385 void reset(reference_type *pBody) = delete;
386
387protected:
388 ScopedVclPtr (reference_type * pBody, __sal_NoAcquire)
389 : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE)
390 {}
391};
392
393/**
394 * A construction helper for ScopedVclPtr. Since VclPtr types are created
395 * with a reference-count of one - to help fit into the existing
396 * code-flow; this helps us to construct them easily.
397 *
398 * For more details on the design please see vcl/README.lifecycle
399 *
400 * @param reference_type must be a subclass of vcl::Window
401 */
402#if defined _MSC_VER
403#pragma warning(push)
404#pragma warning(disable: 4521) // " multiple copy constructors specified"
405#endif
406template <class reference_type>
407class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type>
408{
409public:
410 template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg)
411 : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
412 {
413 }
414
415 /**
416 * Override and disallow this, to prevent people accidentally calling it and actually
417 * getting VclPtr::Create and getting a naked VclPtr<> instance
418 */
419 template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete;
420
421private:
422 // Prevent the above perfect forwarding ctor from hijacking (accidental)
423 // attempts at ScopedVclPtrInstance copy construction (where the hijacking
424 // would typically lead to somewhat obscure error messages); both non-const
425 // and const variants are needed here, as the ScopedVclPtr base class has a
426 // const--variant copy ctor, so the implicitly declared copy ctor for
427 // ScopedVclPtrInstance would also be the const variant, so non-const copy
428 // construction attempts would be hijacked by the perfect forwarding ctor;
429 // but if we only declared a non-const variant here, the const variant would
430 // no longer be implicitly declared (as there would already be an explicitly
431 // declared copy ctor), so const copy construction attempts would then be
432 // hijacked by the perfect forwarding ctor:
433 ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete;
434 ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete;
435};
436#if defined _MSC_VER
437#pragma warning(pop)
438#endif
439
440#endif // INCLUDED_VCL_PTR_HXX
441
442/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/rtl/ref.hxx

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#ifndef INCLUDED_RTL_REF_HXX
21#define INCLUDED_RTL_REF_HXX
22
23#include "sal/config.h"
24
25#include <cassert>
26#include <cstddef>
27#include <functional>
28#ifdef LIBO_INTERNAL_ONLY1
29#include <type_traits>
30#endif
31
32#include "sal/types.h"
33
34namespace rtl
35{
36
37/** Template reference class for reference type.
38*/
39template <class reference_type>
40class Reference
41{
42 /** The <b>reference_type</b> body pointer.
43 */
44 reference_type * m_pBody;
45
46
47public:
48 /** Constructor...
49 */
50 Reference()
51 : m_pBody (NULL__null)
52 {}
53
54
55 /** Constructor...
56 */
57 Reference (reference_type * pBody, __sal_NoAcquire)
58 : m_pBody (pBody)
59 {
60 }
61
62 /** Constructor...
63 */
64 Reference (reference_type * pBody)
65 : m_pBody (pBody)
66 {
67 if (m_pBody)
68 m_pBody->acquire();
69 }
70
71 /** Copy constructor...
72 */
73 Reference (const Reference<reference_type> & handle)
74 : m_pBody (handle.m_pBody)
75 {
76 if (m_pBody)
3
Assuming field 'm_pBody' is non-null
4
Taking true branch
77 m_pBody->acquire();
78 }
79
80#ifdef LIBO_INTERNAL_ONLY1
81 /** Move constructor...
82 */
83 Reference (Reference<reference_type> && handle) noexcept
84 : m_pBody (handle.m_pBody)
85 {
86 handle.m_pBody = nullptr;
87 }
88#endif
89
90#if defined LIBO_INTERNAL_ONLY1
91 /** Up-casting conversion constructor: Copies interface reference.
92
93 Does not work for up-casts to ambiguous bases.
94
95 @param rRef another reference
96 */
97 template< class derived_type >
98 inline Reference(
99 const Reference< derived_type > & rRef,
100 std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 )
101 : m_pBody (rRef.get())
102 {
103 if (m_pBody)
104 m_pBody->acquire();
105 }
106#endif
107
108 /** Destructor...
109 */
110 ~Reference() COVERITY_NOEXCEPT_FALSE
111 {
112 if (m_pBody)
113 m_pBody->release();
114 }
115
116 /** Set...
117 Similar to assignment.
118 */
119 Reference<reference_type> &
120 SAL_CALL set (reference_type * pBody)
121 {
122 if (pBody)
123 pBody->acquire();
124 reference_type * const pOld = m_pBody;
125 m_pBody = pBody;
126 if (pOld)
127 pOld->release();
128 return *this;
129 }
130
131 /** Assignment.
132 Unbinds this instance from its body (if bound) and
133 bind it to the body represented by the handle.
134 */
135 Reference<reference_type> &
136 SAL_CALL operator= (const Reference<reference_type> & handle)
137 {
138 return set( handle.m_pBody );
139 }
140
141#ifdef LIBO_INTERNAL_ONLY1
142 /** Assignment.
143 * Unbinds this instance from its body (if bound),
144 * bind it to the body represented by the handle, and
145 * set the body represented by the handle to nullptr.
146 */
147 Reference<reference_type> &
148 operator= (Reference<reference_type> && handle)
149 {
150 // self-movement guts ourself
151 if (m_pBody)
152 m_pBody->release();
153 m_pBody = handle.m_pBody;
154 handle.m_pBody = nullptr;
155 return *this;
156 }
157#endif
158
159 /** Assignment...
160 */
161 Reference<reference_type> &
162 SAL_CALL operator= (reference_type * pBody)
163 {
164 return set( pBody );
165 }
166
167 /** Unbind the body from this handle.
168 Note that for a handle representing a large body,
169 "handle.clear().set(new body());" _might_
170 perform a little bit better than "handle.set(new body());",
171 since in the second case two large objects exist in memory
172 (the old body and the new body).
173 */
174 Reference<reference_type> & SAL_CALL clear()
175 {
176 if (m_pBody
6.1
Field 'm_pBody' is non-null
6.1
Field 'm_pBody' is non-null
6.1
Field 'm_pBody' is non-null
6.1
Field 'm_pBody' is non-null
)
7
Taking true branch
177 {
178 reference_type * const pOld = m_pBody;
179 m_pBody = NULL__null;
180 pOld->release();
8
Calling 'VclReferenceBase::release'
12
Returning; memory was released
181 }
182 return *this;
183 }
184
185
186 /** Get the body. Can be used instead of operator->().
187 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
188 are the same.
189 */
190 reference_type * SAL_CALL get() const
191 {
192 return m_pBody;
15
Use of memory after it is freed
193 }
194
195
196 /** Probably most common used: handle->someBodyOp().
197 */
198 reference_type * SAL_CALL operator->() const
199 {
200 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 200, __extension__ __PRETTY_FUNCTION__))
;
201 return m_pBody;
202 }
203
204
205 /** Allows (*handle).someBodyOp().
206 */
207 reference_type & SAL_CALL operator*() const
208 {
209 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 209, __extension__ __PRETTY_FUNCTION__))
;
210 return *m_pBody;
211 }
212
213
214 /** Returns True if the handle does point to a valid body.
215 */
216 bool SAL_CALL is() const
217 {
218 return (m_pBody != NULL__null);
219 }
220
221#if defined LIBO_INTERNAL_ONLY1
222 /** Returns True if the handle does point to a valid body.
223 */
224 explicit operator bool() const
225 {
226 return is();
227 }
228#endif
229
230 /** Returns True if this points to pBody.
231 */
232 bool SAL_CALL operator== (const reference_type * pBody) const
233 {
234 return (m_pBody == pBody);
235 }
236
237
238 /** Returns True if handle points to the same body.
239 */
240 bool
241 SAL_CALL operator== (const Reference<reference_type> & handle) const
242 {
243 return (m_pBody == handle.m_pBody);
244 }
245
246
247 /** Needed to place References into STL collection.
248 */
249 bool
250 SAL_CALL operator!= (const Reference<reference_type> & handle) const
251 {
252 return (m_pBody != handle.m_pBody);
253 }
254
255
256 /** Needed to place References into STL collection.
257 */
258 bool
259 SAL_CALL operator< (const Reference<reference_type> & handle) const
260 {
261 return (m_pBody < handle.m_pBody);
262 }
263
264
265 /** Needed to place References into STL collection.
266 */
267 bool
268 SAL_CALL operator> (const Reference<reference_type> & handle) const
269 {
270 return (m_pBody > handle.m_pBody);
271 }
272};
273
274} // namespace rtl
275
276#if defined LIBO_INTERNAL_ONLY1
277namespace std
278{
279
280/// @cond INTERNAL
281/**
282 Make rtl::Reference hashable by default for use in STL containers.
283
284 @since LibreOffice 6.3
285*/
286template<typename T>
287struct hash<::rtl::Reference<T>>
288{
289 std::size_t operator()(::rtl::Reference<T> const & s) const
290 { return std::size_t(s.get()); }
291};
292/// @endcond
293
294}
295
296#endif
297
298#endif /* ! INCLUDED_RTL_REF_HXX */
299
300/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclreferencebase.hxx

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#ifndef INCLUDED_VCL_Reference_HXX
20#define INCLUDED_VCL_Reference_HXX
21
22#include <vcl/dllapi.h>
23#include <osl/interlck.h>
24
25class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase
26{
27 mutable oslInterlockedCount mnRefCnt;
28
29 template<typename T> friend class VclPtr;
30
31public:
32 void acquire() const
33 {
34 osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1);
35 }
36
37 void release() const
38 {
39 if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0)
9
Assuming the condition is true
10
Taking true branch
40 delete this;
11
Memory is released
41 }
42#ifdef DBG_UTIL
43#ifndef _WIN32
44 sal_Int32 getRefCount() const { return mnRefCnt; }
45#endif
46#endif
47
48
49private:
50 VclReferenceBase(const VclReferenceBase&) = delete;
51 VclReferenceBase& operator=(const VclReferenceBase&) = delete;
52
53 bool mbDisposed : 1;
54
55protected:
56 VclReferenceBase();
57protected:
58 virtual ~VclReferenceBase();
59
60protected:
61 virtual void dispose();
62
63public:
64 void disposeOnce();
65 bool isDisposed() const { return mbDisposed; }
66
67};
68#endif