bump product version to 6.3.0.0.beta1
[LibreOffice.git] / toolkit / source / awt / vclxtoolkit.cxx
blob69567b33c17b3489737daecb094a8ddfae431a61
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <stdio.h>
21 #ifdef _WIN32
22 #include <prewin.h>
23 #include <postwin.h>
24 #endif
25 #include <config_features.h>
26 #include <com/sun/star/awt/WindowAttribute.hpp>
27 #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
28 #include <com/sun/star/awt/WindowClass.hpp>
29 #include <com/sun/star/awt/MessageBoxButtons.hpp>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <com/sun/star/lang/SystemDependent.hpp>
32 #include <com/sun/star/awt/FocusEvent.hpp>
33 #include <com/sun/star/awt/KeyEvent.hpp>
34 #include <com/sun/star/awt/KeyModifier.hpp>
35 #include <com/sun/star/lang/EventObject.hpp>
36 #include <com/sun/star/uno/Reference.hxx>
37 #include <com/sun/star/uno/Sequence.hxx>
38 #include <com/sun/star/uno/XComponentContext.hpp>
39 #include <com/sun/star/uno/XInterface.hpp>
40 #include <com/sun/star/beans/NamedValue.hpp>
41 #include <com/sun/star/datatransfer/clipboard/SystemClipboard.hpp>
42 #include <com/sun/star/lang/XServiceInfo.hpp>
43 #include <com/sun/star/awt/XToolkitExperimental.hpp>
44 #include <com/sun/star/awt/XToolkitRobot.hpp>
45 #include <com/sun/star/awt/XMessageBoxFactory.hpp>
47 #include <cppuhelper/bootstrap.hxx>
48 #include <cppuhelper/compbase.hxx>
49 #include <cppuhelper/interfacecontainer.hxx>
50 #include <cppuhelper/supportsservice.hxx>
51 #include <cppuhelper/typeprovider.hxx>
52 #include <osl/conditn.hxx>
53 #include <osl/module.h>
54 #include <osl/thread.hxx>
55 #include <osl/mutex.hxx>
56 #include <rtl/uuid.h>
57 #include <rtl/process.h>
58 #include <sal/log.hxx>
59 #include <tools/link.hxx>
60 #include <tools/fract.hxx>
61 #include <tools/wintypes.hxx>
63 #ifdef MACOSX
64 #include <premac.h>
65 #include <Cocoa/Cocoa.h>
66 #include <postmac.h>
67 #endif
69 #include <vcl/sysdata.hxx>
70 #include <vcl/textrectinfo.hxx>
71 #include <vcl/vclmedit.hxx>
73 #include <toolkit/awt/vclxwindows.hxx>
74 #include <toolkit/awt/vclxsystemdependentwindow.hxx>
75 #include <toolkit/awt/vclxregion.hxx>
76 #include <toolkit/awt/vclxtabpagecontainer.hxx>
78 #include <toolkit/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/servicenames.hxx>
84 #include <toolkit/helper/macros.hxx>
85 #include <toolkit/helper/convert.hxx>
86 #include <vcl/unohelp.hxx>
87 #include <vcl/button.hxx>
88 #include <vcl/combobox.hxx>
89 #include <vcl/ctrl.hxx>
90 #include <vcl/dialog.hxx>
91 #include <vcl/dockingarea.hxx>
92 #include <vcl/dockwin.hxx>
93 #include <vcl/edit.hxx>
94 #include <vcl/event.hxx>
95 #include <vcl/field.hxx>
96 #include <vcl/fixed.hxx>
97 #include <vcl/floatwin.hxx>
98 #include <vcl/toolkit/group.hxx>
99 #include <vcl/scheduler.hxx>
100 #include <vcl/imgctrl.hxx>
101 #include <vcl/longcurr.hxx>
102 #include <vcl/lstbox.hxx>
103 #include <vcl/menubtn.hxx>
104 #include <vcl/toolkit/morebtn.hxx>
105 #include <vcl/msgbox.hxx>
106 #include <vcl/scrbar.hxx>
107 #include <vcl/spin.hxx>
108 #include <vcl/split.hxx>
109 #include <vcl/splitwin.hxx>
110 #include <vcl/status.hxx>
111 #include <vcl/svapp.hxx>
112 #include <vcl/syschild.hxx>
113 #include <vcl/tabctrl.hxx>
114 #include <vcl/tabdlg.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/throbber.hxx>
121 #if HAVE_FEATURE_OPENGL
122 #include <vcl/opengl/OpenGLWrapper.hxx>
123 #endif
124 #include <toolkit/awt/vclxspinbutton.hxx>
125 #include <tools/debug.hxx>
126 #include <tools/diagnose_ex.h>
127 #include <comphelper/processfactory.hxx>
128 #include <comphelper/profilezone.hxx>
130 #include <helper/msgbox.hxx>
131 #include <helper/scrollabledialog.hxx>
132 #include <helper/unowrapper.hxx>
134 #if defined(_WIN32)
135 #define SYSTEM_DEPENDENT_TYPE css::lang::SystemDependent::SYSTEM_WIN32
136 #elif defined(MACOSX)
137 #define SYSTEM_DEPENDENT_TYPE css::lang::SystemDependent::SYSTEM_MAC
138 #elif defined(UNX)
139 #define SYSTEM_DEPENDENT_TYPE css::lang::SystemDependent::SYSTEM_XWINDOW
140 #endif
142 void MessBox::ImplInitButtons()
144 ButtonDialogFlags nOKFlags = ButtonDialogFlags::OK;
145 ButtonDialogFlags nCancelFlags = ButtonDialogFlags::Cancel;
146 ButtonDialogFlags nRetryFlags = ButtonDialogFlags::NONE;
147 ButtonDialogFlags nYesFlags = ButtonDialogFlags::NONE;
148 ButtonDialogFlags nNoFlags = ButtonDialogFlags::NONE;
150 if ( mnMessBoxStyle & MessBoxStyle::OkCancel )
152 if ( mnMessBoxStyle & MessBoxStyle::DefaultCancel )
153 nCancelFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
154 else // MessBoxStyle::DefaultOk
155 nOKFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
157 AddButton( StandardButtonType::OK, RET_OK, nOKFlags );
158 AddButton( StandardButtonType::Cancel, RET_CANCEL, nCancelFlags );
160 else if ( mnMessBoxStyle & MessBoxStyle::YesNo )
162 if ( mnMessBoxStyle & MessBoxStyle::DefaultYes )
163 nYesFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
164 else // MessBoxStyle::DefaultNo
165 nNoFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
166 nNoFlags |= ButtonDialogFlags::Cancel;
168 AddButton( StandardButtonType::Yes, RET_YES, nYesFlags );
169 AddButton( StandardButtonType::No, RET_NO, nNoFlags );
171 else if ( mnMessBoxStyle & MessBoxStyle::YesNoCancel )
173 if ( mnMessBoxStyle & MessBoxStyle::DefaultYes )
174 nYesFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
175 else if ( mnMessBoxStyle & MessBoxStyle::DefaultNo )
176 nNoFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
177 else
178 nCancelFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
180 AddButton( StandardButtonType::Yes, RET_YES, nYesFlags );
181 AddButton( StandardButtonType::No, RET_NO, nNoFlags );
182 AddButton( StandardButtonType::Cancel, RET_CANCEL, nCancelFlags );
184 else if ( mnMessBoxStyle & MessBoxStyle::RetryCancel )
186 if ( mnMessBoxStyle & MessBoxStyle::DefaultCancel )
187 nCancelFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
188 else // MessBoxStyle::DefaultRetry
189 nRetryFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
191 AddButton( StandardButtonType::Retry, RET_RETRY, nRetryFlags );
192 AddButton( StandardButtonType::Cancel, RET_CANCEL, nCancelFlags );
194 else if ( mnMessBoxStyle & MessBoxStyle::AbortRetryIgnore )
196 ButtonDialogFlags nAbortFlags = ButtonDialogFlags::NONE;
197 ButtonDialogFlags nIgnoreFlags = ButtonDialogFlags::NONE;
199 if ( mnMessBoxStyle & MessBoxStyle::DefaultCancel )
200 nAbortFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
201 else if ( mnMessBoxStyle & MessBoxStyle::DefaultRetry )
202 nRetryFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
203 else if ( mnMessBoxStyle & MessBoxStyle::DefaultIgnore )
204 nIgnoreFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
206 AddButton( StandardButtonType::Abort, RET_CANCEL, nAbortFlags );
207 AddButton( StandardButtonType::Retry, RET_RETRY, nRetryFlags );
208 AddButton( StandardButtonType::Ignore, RET_IGNORE, nIgnoreFlags );
210 else if ( mnMessBoxStyle & MessBoxStyle::Ok )
212 nOKFlags |= ButtonDialogFlags::Default | ButtonDialogFlags::Focus;
214 AddButton( StandardButtonType::OK, RET_OK, nOKFlags );
218 MessBox::MessBox(vcl::Window* pParent, MessBoxStyle nMessBoxStyle, WinBits nWinBits,
219 const OUString& rTitle, const OUString& rMessage) :
220 ButtonDialog( WindowType::MESSBOX ),
221 mbHelpBtn( false ),
222 mnMessBoxStyle( nMessBoxStyle ),
223 maMessText( rMessage )
225 ImplLOKNotifier(pParent);
226 ImplInit(pParent, nWinBits | WB_MOVEABLE | WB_HORZ | WB_CENTER);
227 ImplInitButtons();
229 if ( !rTitle.isEmpty() )
230 SetText( rTitle );
233 MessBox::~MessBox()
235 disposeOnce();
238 void MessBox::dispose()
240 mpVCLMultiLineEdit.disposeAndClear();
241 mpFixedImage.disposeAndClear();
242 ButtonDialog::dispose();
245 void MessBox::ImplPosControls()
247 if ( !GetHelpId().isEmpty() )
249 if ( !mbHelpBtn )
251 AddButton( StandardButtonType::Help, RET_HELP, ButtonDialogFlags::Help, 3 );
252 mbHelpBtn = true;
255 else
257 if ( mbHelpBtn )
259 RemoveButton( RET_HELP );
260 mbHelpBtn = false;
264 TextRectInfo aTextInfo;
265 tools::Rectangle aRect( 0, 0, 30000, 30000 );
266 tools::Rectangle aFormatRect;
267 Point aTextPos( IMPL_DIALOG_OFFSET, IMPL_DIALOG_OFFSET+IMPL_MSGBOX_OFFSET_EXTRA_Y );
268 Size aImageSize;
269 Size aPageSize;
270 Size aMEditSize;
271 long nTitleWidth;
272 long nButtonSize = ImplGetButtonSize();
273 long nMaxWidth = GetDesktopRectPixel().GetWidth()-8;
274 long nMaxLineWidth;
275 long nWidth;
276 WinBits nWinStyle = WB_LEFT | WB_NOLABEL;
277 DrawTextFlags nTextStyle = DrawTextFlags::MultiLine | DrawTextFlags::Top | DrawTextFlags::Left;
279 mpVCLMultiLineEdit.disposeAndClear();
280 mpFixedImage.disposeAndClear();
282 // Clean up message text with tabs
283 OUString aMessText(maMessText.replaceAll("\t", " "));
285 //If window too small, we make dialog box be wider
286 nMaxWidth = 630 * GetDPIScaleFactor();
288 // MessagBox should be at least as wide as to see the title
289 // Extra-Width for Close button, because Close button is set after this call
290 nTitleWidth = CalcTitleWidth();
292 nMaxWidth -= (IMPL_DIALOG_OFFSET*2)+(IMPL_MSGBOX_OFFSET_EXTRA_X*2);
294 // for an image, get its size, create a suitable control and position it
295 aImageSize = maImage.GetSizePixel();
296 if ( aImageSize.Width() )
298 aImageSize.AdjustWidth(4 );
299 aImageSize.AdjustHeight(4 );
300 aTextPos.AdjustX(aImageSize.Width()+IMPL_SEP_MSGBOX_IMAGE );
301 mpFixedImage = VclPtr<FixedImage>::Create( this );
302 mpFixedImage->SetPosSizePixel( Point( IMPL_DIALOG_OFFSET-2+IMPL_MSGBOX_OFFSET_EXTRA_X,
303 IMPL_DIALOG_OFFSET-2+IMPL_MSGBOX_OFFSET_EXTRA_Y ),
304 aImageSize );
305 mpFixedImage->SetImage( maImage );
306 mpFixedImage->Show();
307 nMaxWidth -= aImageSize.Width()+IMPL_SEP_MSGBOX_IMAGE;
309 else
310 aTextPos.AdjustX(IMPL_MSGBOX_OFFSET_EXTRA_X );
312 // Determine maximum line length without wordbreak
313 aFormatRect = GetTextRect( aRect, aMessText, nTextStyle, &aTextInfo );
314 nMaxLineWidth = aFormatRect.GetWidth();
315 nTextStyle |= DrawTextFlags::WordBreak;
317 // Determine the width for text formatting
318 if ( nMaxLineWidth > 450 )
319 nWidth = 450;
320 else if ( nMaxLineWidth > 300 )
321 nWidth = nMaxLineWidth+5;
322 else
323 nWidth = 300;
325 nWidth *= GetDPIScaleFactor();
327 if ( nButtonSize > nWidth )
328 nWidth = nButtonSize-(aTextPos.X()-IMPL_DIALOG_OFFSET);
329 if ( nWidth > nMaxWidth )
330 nWidth = nMaxWidth;
332 aRect.SetRight( nWidth );
333 aFormatRect = GetTextRect( aRect, aMessText, nTextStyle, &aTextInfo );
334 if ( aTextInfo.GetMaxLineWidth() > nWidth )
336 nWidth = aTextInfo.GetMaxLineWidth()+8;
337 aRect.SetRight( nWidth );
338 aFormatRect = GetTextRect( aRect, aMessText, nTextStyle, &aTextInfo );
341 // get Style for VCLMultiLineEdit
342 aMEditSize.setWidth( aTextInfo.GetMaxLineWidth()+1 );
343 aMEditSize.setHeight( aFormatRect.GetHeight() );
344 aPageSize.setWidth( aImageSize.Width() );
345 if ( aMEditSize.Height() < aImageSize.Height() )
347 nWinStyle |= WB_VCENTER;
348 aPageSize.setHeight( aImageSize.Height() );
349 aMEditSize.setHeight( aImageSize.Height() );
351 else
353 nWinStyle |= WB_TOP;
354 aPageSize.setHeight( aMEditSize.Height() );
356 if ( aImageSize.Width() )
357 aPageSize.AdjustWidth(IMPL_SEP_MSGBOX_IMAGE );
358 aPageSize.AdjustWidth((IMPL_DIALOG_OFFSET*2)+(IMPL_MSGBOX_OFFSET_EXTRA_X*2) );
359 aPageSize.AdjustWidth(aMEditSize.Width()+1 );
360 aPageSize.AdjustHeight((IMPL_DIALOG_OFFSET*2)+(IMPL_MSGBOX_OFFSET_EXTRA_Y*2) );
362 if ( aPageSize.Width() < IMPL_MINSIZE_MSGBOX_WIDTH )
363 aPageSize.setWidth( IMPL_MINSIZE_MSGBOX_WIDTH );
364 if ( aPageSize.Width() < nTitleWidth )
365 aPageSize.setWidth( nTitleWidth );
367 mpVCLMultiLineEdit = VclPtr<VclMultiLineEdit>::Create( this, nWinStyle );
368 mpVCLMultiLineEdit->SetText( aMessText );
369 mpVCLMultiLineEdit->SetPosSizePixel( aTextPos, aMEditSize );
370 mpVCLMultiLineEdit->Show();
371 mpVCLMultiLineEdit->SetPaintTransparent(true);
372 mpVCLMultiLineEdit->EnableCursor(false);
373 SetPageSizePixel( aPageSize );
376 void MessBox::StateChanged( StateChangedType nType )
378 if ( nType == StateChangedType::InitShow )
380 ImplPosControls();
382 ButtonDialog::StateChanged( nType );
385 Size MessBox::GetOptimalSize() const
387 // FIXME: base me on the font size ?
388 return Size( 250, 100 );
392 namespace {
394 extern "C" typedef vcl::Window* (*FN_SvtCreateWindow)(
395 VCLXWindow** ppNewComp,
396 const css::awt::WindowDescriptor* pDescriptor,
397 vcl::Window* pParent,
398 WinBits nWinBits );
400 class Pause : public Idle
402 public:
403 explicit Pause(sal_Int32 nPauseMilliseconds) :
404 Idle("pause"),
405 m_nPauseMilliseconds(nPauseMilliseconds)
407 SetPriority(TaskPriority::HIGHEST);
408 Start();
411 virtual void Invoke() override
413 SolarMutexGuard aSolarGuard;
414 osl::Thread::wait(std::chrono::milliseconds(m_nPauseMilliseconds));
415 Stop();
416 delete this;
419 sal_Int32 const m_nPauseMilliseconds;
422 class VCLXToolkitMutexHelper
424 protected:
425 ::osl::Mutex maMutex;
428 class VCLXToolkit : public VCLXToolkitMutexHelper,
429 public cppu::WeakComponentImplHelper<
430 css::awt::XToolkitExperimental,
431 css::awt::XToolkitRobot,
432 css::lang::XServiceInfo >
434 css::uno::Reference< css::datatransfer::clipboard::XClipboard > mxClipboard;
435 css::uno::Reference< css::datatransfer::clipboard::XClipboard > mxSelection;
437 oslModule hSvToolsLib;
438 FN_SvtCreateWindow fnSvtCreateWindow;
440 ::comphelper::OInterfaceContainerHelper2 m_aTopWindowListeners;
441 ::comphelper::OInterfaceContainerHelper2 m_aKeyHandlers;
442 ::comphelper::OInterfaceContainerHelper2 m_aFocusListeners;
443 ::Link<VclSimpleEvent&,void> const m_aEventListenerLink;
444 ::Link<VclWindowEvent&,bool> const m_aKeyListenerLink;
445 bool m_bEventListener;
446 bool m_bKeyListener;
448 DECL_LINK(eventListenerHandler, ::VclSimpleEvent&, void);
450 DECL_LINK(keyListenerHandler, ::VclWindowEvent&, bool);
452 void callTopWindowListeners(
453 ::VclSimpleEvent const * pEvent,
454 void (SAL_CALL css::awt::XTopWindowListener::* pFn)(
455 css::lang::EventObject const &));
457 bool callKeyHandlers(::VclSimpleEvent const * pEvent, bool bPressed);
459 void callFocusListeners(::VclSimpleEvent const * pEvent, bool bGained);
461 protected:
462 ::osl::Mutex& GetMutex() { return maMutex; }
464 virtual void SAL_CALL disposing() override;
466 static vcl::Window* ImplCreateWindow( VCLXWindow** ppNewComp, const css::awt::WindowDescriptor& rDescriptor, vcl::Window* pParent,
467 WinBits nWinBits, MessBoxStyle nMessBoxStyle );
468 css::uno::Reference< css::awt::XWindowPeer > ImplCreateWindow( const css::awt::WindowDescriptor& Descriptor,
469 MessBoxStyle nForceMessBoxStyle );
471 public:
473 VCLXToolkit();
475 // css::awt::XToolkitExperimental
476 virtual void SAL_CALL processEventsToIdle() override;
478 virtual sal_Int64 SAL_CALL getOpenGLBufferSwapCounter() override;
480 virtual void SAL_CALL setDeterministicScheduling(sal_Bool bDeterministicMode) override;
482 virtual void SAL_CALL pause(sal_Int32 nMilliseconds) override;
484 virtual void SAL_CALL startRecording() override;
486 virtual void SAL_CALL stopRecording() override;
488 css::uno::Sequence< OUString > SAL_CALL getRecordingAndClear() override;
490 // css::awt::XToolkit
491 css::uno::Reference< css::awt::XWindowPeer > SAL_CALL getDesktopWindow( ) override;
492 css::awt::Rectangle SAL_CALL getWorkArea( ) override;
493 css::uno::Reference< css::awt::XWindowPeer > SAL_CALL createWindow( const css::awt::WindowDescriptor& Descriptor ) override;
494 css::uno::Sequence< css::uno::Reference< css::awt::XWindowPeer > > SAL_CALL createWindows( const css::uno::Sequence< css::awt::WindowDescriptor >& Descriptors ) override;
495 css::uno::Reference< css::awt::XDevice > SAL_CALL createScreenCompatibleDevice( sal_Int32 Width, sal_Int32 Height ) override;
496 css::uno::Reference< css::awt::XRegion > SAL_CALL createRegion( ) override;
498 // css::awt::XSystemChildFactory
499 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;
501 // css::awt::XMessageBoxFactory
502 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;
504 // css::awt::XDataTransfer
505 css::uno::Reference< css::datatransfer::dnd::XDragGestureRecognizer > SAL_CALL getDragGestureRecognizer( const css::uno::Reference< css::awt::XWindow >& window ) override;
506 css::uno::Reference< css::datatransfer::dnd::XDragSource > SAL_CALL getDragSource( const css::uno::Reference< css::awt::XWindow >& window ) override;
507 css::uno::Reference< css::datatransfer::dnd::XDropTarget > SAL_CALL getDropTarget( const css::uno::Reference< css::awt::XWindow >& window ) override;
508 css::uno::Reference< css::datatransfer::clipboard::XClipboard > SAL_CALL getClipboard( const OUString& clipboardName ) override;
510 // css::lang::XServiceInfo
511 OUString SAL_CALL getImplementationName( ) override;
512 sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
513 css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
515 // css::awt::XExtendedToolkit:
517 virtual ::sal_Int32 SAL_CALL getTopWindowCount() override;
519 virtual css::uno::Reference< css::awt::XTopWindow >
520 SAL_CALL getTopWindow(::sal_Int32 nIndex) override;
522 virtual css::uno::Reference< css::awt::XTopWindow >
523 SAL_CALL getActiveTopWindow() override;
525 virtual void SAL_CALL addTopWindowListener(
526 css::uno::Reference<
527 css::awt::XTopWindowListener > const & rListener) override;
529 virtual void SAL_CALL removeTopWindowListener(
530 css::uno::Reference<
531 css::awt::XTopWindowListener > const & rListener) override;
533 virtual void SAL_CALL addKeyHandler(
534 css::uno::Reference<
535 css::awt::XKeyHandler > const & rHandler) override;
537 virtual void SAL_CALL removeKeyHandler(
538 css::uno::Reference<
539 css::awt::XKeyHandler > const & rHandler) override;
541 virtual void SAL_CALL addFocusListener(
542 css::uno::Reference<
543 css::awt::XFocusListener > const & rListener) override;
545 virtual void SAL_CALL removeFocusListener(
546 css::uno::Reference<
547 css::awt::XFocusListener > const & rListener) override;
549 virtual void SAL_CALL fireFocusGained(
550 css::uno::Reference<
551 css::uno::XInterface > const & source) override;
553 virtual void SAL_CALL fireFocusLost(
554 css::uno::Reference<
555 css::uno::XInterface > const & source) override;
557 // css::awt::XReschedule:
558 virtual void SAL_CALL reschedule() override;
560 // css:awt:XToolkitRobot
561 virtual void SAL_CALL keyPress( const css::awt::KeyEvent & aKeyEvent ) override;
563 virtual void SAL_CALL keyRelease( const css::awt::KeyEvent & aKeyEvent ) override;
565 virtual void SAL_CALL mousePress( const css::awt::MouseEvent & aMouseEvent ) override;
567 virtual void SAL_CALL mouseRelease( const css::awt::MouseEvent & aMouseEvent ) override;
569 virtual void SAL_CALL mouseMove( const css::awt::MouseEvent & aMouseEvent ) override;
573 std::pair<WinBits,MessBoxStyle> ImplGetWinBits( sal_uInt32 nComponentAttribs, WindowType nCompType )
575 WinBits nWinBits = 0;
576 MessBoxStyle nStyle = MessBoxStyle::NONE;
578 bool bMessBox = false;
579 if ( ( nCompType == WindowType::INFOBOX ) ||
580 ( nCompType == WindowType::MESSBOX ) ||
581 ( nCompType == WindowType::QUERYBOX ) ||
582 ( nCompType == WindowType::WARNINGBOX ) ||
583 ( nCompType == WindowType::ERRORBOX ) )
585 bMessBox = true;
588 bool bDecoratedWindow = false;
589 if ( bMessBox
590 || ( nCompType == WindowType::DIALOG )
591 || ( nCompType == WindowType::MODELESSDIALOG )
592 || ( nCompType == WindowType::MODALDIALOG )
593 || ( nCompType == WindowType::DOCKINGWINDOW )
594 || ( nCompType == WindowType::TABDIALOG )
595 || ( nCompType == WindowType::BUTTONDIALOG )
596 || ( nCompType == WindowType::SYSTEMCHILDWINDOW )
599 bDecoratedWindow = true;
602 if( nComponentAttribs & css::awt::WindowAttribute::BORDER )
603 nWinBits |= WB_BORDER;
604 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::NOBORDER )
605 nWinBits |= WB_NOBORDER;
606 if( nComponentAttribs & css::awt::WindowAttribute::SIZEABLE )
607 nWinBits |= WB_SIZEABLE;
608 if( nComponentAttribs & css::awt::WindowAttribute::MOVEABLE )
609 nWinBits |= WB_MOVEABLE;
610 if( nComponentAttribs & css::awt::WindowAttribute::CLOSEABLE )
611 nWinBits |= WB_CLOSEABLE;
612 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::HSCROLL )
613 nWinBits |= WB_HSCROLL;
614 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::VSCROLL )
615 nWinBits |= WB_VSCROLL;
616 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::LEFT )
617 nWinBits |= WB_LEFT;
618 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::CENTER )
619 nWinBits |= WB_CENTER;
620 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::RIGHT )
621 nWinBits |= WB_RIGHT;
622 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::SPIN )
623 nWinBits |= WB_SPIN;
624 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::SORT )
625 nWinBits |= WB_SORT;
626 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DROPDOWN )
627 nWinBits |= WB_DROPDOWN;
628 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEFBUTTON )
629 nWinBits |= WB_DEFBUTTON;
630 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::READONLY )
631 nWinBits |= WB_READONLY;
632 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::CLIPCHILDREN )
633 nWinBits |= WB_CLIPCHILDREN;
634 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::GROUP )
635 nWinBits |= WB_GROUP;
636 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::NOLABEL ) //added for issue79712
637 nWinBits |= WB_NOLABEL;
639 // These bits are not unique
640 if ( bMessBox )
642 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::OK )
643 nStyle |= MessBoxStyle::Ok;
644 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::OK_CANCEL )
645 nStyle |= MessBoxStyle::OkCancel;
646 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::YES_NO )
647 nStyle |= MessBoxStyle::YesNo;
648 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::YES_NO_CANCEL )
649 nStyle |= MessBoxStyle::YesNoCancel;
650 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::RETRY_CANCEL )
651 nStyle |= MessBoxStyle::RetryCancel;
652 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEF_OK )
653 nStyle |= MessBoxStyle::DefaultOk;
654 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEF_CANCEL )
655 nStyle |= MessBoxStyle::DefaultCancel;
656 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEF_RETRY )
657 nStyle |= MessBoxStyle::DefaultRetry;
658 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEF_YES )
659 nStyle |= MessBoxStyle::DefaultYes;
660 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEF_NO )
661 nStyle |= MessBoxStyle::DefaultNo;
663 if ( nCompType == WindowType::MULTILINEEDIT || nCompType == WindowType::DIALOG || nCompType == WindowType::GROUPBOX )
665 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::AUTOHSCROLL )
666 nWinBits |= WB_AUTOHSCROLL;
667 if( nComponentAttribs & css::awt::VclWindowPeerAttribute::AUTOVSCROLL )
668 nWinBits |= WB_AUTOVSCROLL;
672 if ( bDecoratedWindow )
674 if( nComponentAttribs & css::awt::WindowAttribute::NODECORATION )
676 // No decoration removes several window attributes and must
677 // set WB_NOBORDER!
678 nWinBits &= ~WB_BORDER;
679 nWinBits &= ~WB_SIZEABLE;
680 nWinBits &= ~WB_MOVEABLE;
681 nWinBits &= ~WB_CLOSEABLE;
682 nWinBits |= WB_NOBORDER;
686 return { nWinBits, nStyle };
689 struct ComponentInfo
691 OUStringLiteral sName;
692 WindowType nWinType;
695 static ComponentInfo const aComponentInfos [] =
697 { OUStringLiteral("animatedimages"), WindowType::CONTROL },
698 { OUStringLiteral("buttondialog"), WindowType::BUTTONDIALOG },
699 { OUStringLiteral("cancelbutton"), WindowType::CANCELBUTTON },
700 { OUStringLiteral("checkbox"), WindowType::CHECKBOX },
701 { OUStringLiteral("combobox"), WindowType::COMBOBOX },
702 { OUStringLiteral("control"), WindowType::CONTROL },
703 { OUStringLiteral("currencybox"), WindowType::CURRENCYBOX },
704 { OUStringLiteral("currencyfield"), WindowType::CURRENCYFIELD },
705 { OUStringLiteral("datebox"), WindowType::DATEBOX },
706 { OUStringLiteral("datefield"), WindowType::DATEFIELD },
707 { OUStringLiteral("dialog"), WindowType::DIALOG },
708 { OUStringLiteral("dockingarea"), WindowType::DOCKINGAREA },
709 { OUStringLiteral("dockingwindow"), WindowType::DOCKINGWINDOW },
710 { OUStringLiteral("edit"), WindowType::EDIT },
711 { OUStringLiteral("errorbox"), WindowType::ERRORBOX },
712 { OUStringLiteral("fixedbitmap"), WindowType::FIXEDBITMAP },
713 { OUStringLiteral("fixedimage"), WindowType::FIXEDIMAGE },
714 { OUStringLiteral("fixedline"), WindowType::FIXEDLINE },
715 { OUStringLiteral("fixedtext"), WindowType::FIXEDTEXT },
716 { OUStringLiteral("floatingwindow"), WindowType::FLOATINGWINDOW },
717 { OUStringLiteral("frame"), WindowType::GROUPBOX },
718 { OUStringLiteral("framewindow"), WindowType::TOOLKIT_FRAMEWINDOW },
719 { OUStringLiteral("groupbox"), WindowType::GROUPBOX },
720 { OUStringLiteral("helpbutton"), WindowType::HELPBUTTON },
721 { OUStringLiteral("imagebutton"), WindowType::IMAGEBUTTON },
722 { OUStringLiteral("infobox"), WindowType::INFOBOX },
723 { OUStringLiteral("listbox"), WindowType::LISTBOX },
724 { OUStringLiteral("longcurrencybox"), WindowType::LONGCURRENCYBOX },
725 { OUStringLiteral("longcurrencyfield"), WindowType::LONGCURRENCYFIELD },
726 { OUStringLiteral("menubutton"), WindowType::MENUBUTTON },
727 { OUStringLiteral("messbox"), WindowType::MESSBOX },
728 { OUStringLiteral("metricbox"), WindowType::METRICBOX },
729 { OUStringLiteral("metricfield"), WindowType::METRICFIELD },
730 { OUStringLiteral("modaldialog"), WindowType::MODALDIALOG },
731 { OUStringLiteral("modelessdialog"), WindowType::MODELESSDIALOG },
732 { OUStringLiteral("morebutton"), WindowType::MOREBUTTON },
733 { OUStringLiteral("multilineedit"), WindowType::MULTILINEEDIT },
734 { OUStringLiteral("multilistbox"), WindowType::MULTILISTBOX },
735 { OUStringLiteral("numericbox"), WindowType::NUMERICBOX },
736 { OUStringLiteral("numericfield"), WindowType::NUMERICFIELD },
737 { OUStringLiteral("okbutton"), WindowType::OKBUTTON },
738 { OUStringLiteral("patternbox"), WindowType::PATTERNBOX },
739 { OUStringLiteral("patternfield"), WindowType::PATTERNFIELD },
740 { OUStringLiteral("pushbutton"), WindowType::PUSHBUTTON },
741 { OUStringLiteral("querybox"), WindowType::QUERYBOX },
742 { OUStringLiteral("radiobutton"), WindowType::RADIOBUTTON },
743 { OUStringLiteral("scrollbar"), WindowType::SCROLLBAR },
744 { OUStringLiteral("scrollbarbox"), WindowType::SCROLLBARBOX },
745 { OUStringLiteral("spinbutton"), WindowType::SPINBUTTON },
746 { OUStringLiteral("spinfield"), WindowType::SPINFIELD },
747 { OUStringLiteral("splitter"), WindowType::SPLITTER },
748 { OUStringLiteral("splitwindow"), WindowType::SPLITWINDOW },
749 { OUStringLiteral("statusbar"), WindowType::STATUSBAR },
750 { OUStringLiteral("systemchildwindow"), WindowType::TOOLKIT_SYSTEMCHILDWINDOW },
751 { OUStringLiteral("tabcontrol"), WindowType::TABCONTROL },
752 { OUStringLiteral("tabdialog"), WindowType::TABDIALOG },
753 { OUStringLiteral("tabpage"), WindowType::TABPAGE },
754 { OUStringLiteral("tabpagecontainer"), WindowType::CONTROL },
755 { OUStringLiteral("tabpagemodel"), WindowType::TABPAGE },
756 { OUStringLiteral("timebox"), WindowType::TIMEBOX },
757 { OUStringLiteral("timefield"), WindowType::TIMEFIELD },
758 { OUStringLiteral("toolbox"), WindowType::TOOLBOX },
759 { OUStringLiteral("tristatebox"), WindowType::TRISTATEBOX },
760 { OUStringLiteral("warningbox"), WindowType::WARNINGBOX },
761 { OUStringLiteral("window"), WindowType::WINDOW },
762 { OUStringLiteral("workwindow"), WindowType::WORKWINDOW }
765 bool ComponentInfoFindCompare( const ComponentInfo & lhs, const OUString & s)
767 return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(s.pData->buffer, s.pData->length,
768 lhs.sName.data, lhs.sName.size) > 0;
771 WindowType ImplGetComponentType( const OUString& rServiceName )
773 static bool bSorted = false;
774 if( !bSorted )
776 assert( std::is_sorted( std::begin(aComponentInfos), std::end(aComponentInfos),
777 [](const ComponentInfo & lhs, const ComponentInfo & rhs) {
778 return
779 rtl_str_compare_WithLength(
780 lhs.sName.data, lhs.sName.size, rhs.sName.data, rhs.sName.size)
781 < 0;
782 } ) );
783 bSorted = true;
786 OUString sSearch;
787 if ( !rServiceName.isEmpty() )
788 sSearch = rServiceName;
789 else
790 sSearch = "window";
792 auto it = std::lower_bound( std::begin(aComponentInfos), std::end(aComponentInfos), sSearch,
793 ComponentInfoFindCompare );
794 if (it != std::end(aComponentInfos) &&
795 rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(sSearch.pData->buffer, sSearch.pData->length, it->sName.data, it->sName.size) == 0)
796 return it->nWinType;
797 return WindowType::NONE;
800 struct MessageBoxTypeInfo
802 css::awt::MessageBoxType const eType;
803 const sal_Char *pName;
804 sal_Int32 const nLen;
807 static const MessageBoxTypeInfo aMessageBoxTypeInfo[] =
809 { css::awt::MessageBoxType_MESSAGEBOX, RTL_CONSTASCII_STRINGPARAM("messbox") },
810 { css::awt::MessageBoxType_INFOBOX, RTL_CONSTASCII_STRINGPARAM("infobox") },
811 { css::awt::MessageBoxType_WARNINGBOX, RTL_CONSTASCII_STRINGPARAM("warningbox") },
812 { css::awt::MessageBoxType_ERRORBOX, RTL_CONSTASCII_STRINGPARAM("errorbox") },
813 { css::awt::MessageBoxType_QUERYBOX, RTL_CONSTASCII_STRINGPARAM("querybox") },
814 { css::awt::MessageBoxType::MessageBoxType_MAKE_FIXED_SIZE, nullptr, 0 }
817 bool lcl_convertMessageBoxType(
818 OUString &sType,
819 css::awt::MessageBoxType eType )
821 const MessageBoxTypeInfo *pMap = aMessageBoxTypeInfo;
822 css::awt::MessageBoxType eVal = css::awt::MessageBoxType::MessageBoxType_MAKE_FIXED_SIZE;
824 while ( pMap->pName )
826 if ( pMap->eType == eType )
828 eVal = eType;
829 sType = OUString( pMap->pName, pMap->nLen, RTL_TEXTENCODING_ASCII_US );
830 break;
832 pMap++;
835 return ( eVal != css::awt::MessageBoxType::MessageBoxType_MAKE_FIXED_SIZE );
838 #ifndef IOS
840 static sal_Int32 nVCLToolkitInstanceCount = 0;
841 static bool bInitedByVCLToolkit = false;
843 osl::Mutex & getInitMutex()
845 static osl::Mutex aMutex;
846 return aMutex;
849 osl::Condition & getInitCondition()
851 static osl::Condition aCondition;
852 return aCondition;
855 extern "C"
857 static void ToolkitWorkerFunction( void* pArgs )
859 osl_setThreadName("VCLXToolkit VCL main thread");
861 css::uno::Reference<css::lang::XMultiServiceFactory> xServiceManager;
864 xServiceManager = ::comphelper::getProcessServiceFactory();
866 catch (const css::uno::DeploymentException&)
869 if (!xServiceManager.is())
871 css::uno::Reference<css::uno::XComponentContext> xContext =
872 ::cppu::defaultBootstrap_InitialComponentContext();
874 xServiceManager.set( xContext->getServiceManager(), css::uno::UNO_QUERY_THROW );
875 // set global process service factory used by unotools config helpers
876 ::comphelper::setProcessServiceFactory( xServiceManager );
879 VCLXToolkit * pTk = static_cast<VCLXToolkit *>(pArgs);
880 bInitedByVCLToolkit = InitVCL();
881 if( bInitedByVCLToolkit )
883 UnoWrapper* pUnoWrapper = new UnoWrapper( pTk );
884 UnoWrapperBase::SetUnoWrapper( pUnoWrapper );
886 getInitCondition().set();
887 if( bInitedByVCLToolkit )
890 SolarMutexGuard aGuard;
891 Application::Execute();
895 pTk->dispose();
897 catch( css::uno::Exception & )
900 DeInitVCL();
902 else
904 // having the thread join itself is pretty stupid.
905 // but we can't get the osl_Thread to destroy here so just leak it.
910 #endif
912 // constructor, which might initialize VCL
913 VCLXToolkit::VCLXToolkit():
914 cppu::WeakComponentImplHelper<
915 css::awt::XToolkitExperimental,
916 css::awt::XToolkitRobot,
917 css::lang::XServiceInfo>( GetMutex() ),
918 m_aTopWindowListeners(rBHelper.rMutex),
919 m_aKeyHandlers(rBHelper.rMutex),
920 m_aFocusListeners(rBHelper.rMutex),
921 m_aEventListenerLink(LINK(this, VCLXToolkit, eventListenerHandler)),
922 m_aKeyListenerLink(LINK(this, VCLXToolkit, keyListenerHandler)),
923 m_bEventListener(false),
924 m_bKeyListener(false)
926 hSvToolsLib = nullptr;
927 fnSvtCreateWindow = nullptr;
929 #ifndef IOS
930 osl::Guard< osl::Mutex > aGuard( getInitMutex() );
931 nVCLToolkitInstanceCount++;
932 if( ( nVCLToolkitInstanceCount == 1 ) && ( !Application::IsInMain() ) )
934 // setup execute thread
935 CreateMainLoopThread( ToolkitWorkerFunction, this );
936 getInitCondition().wait();
938 #endif
941 void SAL_CALL VCLXToolkit::disposing()
943 #ifndef DISABLE_DYNLOADING
944 if ( hSvToolsLib )
946 osl_unloadModule( hSvToolsLib );
947 hSvToolsLib = nullptr;
948 fnSvtCreateWindow = nullptr;
950 #endif
952 #ifndef IOS
954 osl::Guard< osl::Mutex > aGuard( getInitMutex() );
955 if( --nVCLToolkitInstanceCount == 0 )
957 if( bInitedByVCLToolkit )
959 Application::Quit();
960 JoinMainLoopThread();
961 bInitedByVCLToolkit = false;
965 #endif
966 if (m_bEventListener)
968 ::Application::RemoveEventListener(m_aEventListenerLink);
969 m_bEventListener = false;
971 if (m_bKeyListener)
973 ::Application::RemoveKeyListener(m_aKeyListenerLink);
974 m_bKeyListener = false;
976 css::lang::EventObject aEvent(
977 static_cast< ::cppu::OWeakObject * >(this));
978 m_aTopWindowListeners.disposeAndClear(aEvent);
979 m_aKeyHandlers.disposeAndClear(aEvent);
980 m_aFocusListeners.disposeAndClear(aEvent);
984 css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::getDesktopWindow( )
986 css::uno::Reference< css::awt::XWindowPeer > xRef;
987 // 07/00: AppWindow doesn't exist anymore...
988 return xRef;
991 css::awt::Rectangle VCLXToolkit::getWorkArea( )
993 sal_Int32 nDisplay = Application::GetDisplayBuiltInScreen();
994 tools::Rectangle aWorkRect = Application::GetScreenPosSizePixel( nDisplay );
995 css::awt::Rectangle aNotherRect;
996 aNotherRect.X = aWorkRect.getX();
997 aNotherRect.Y = aWorkRect.getY();
998 aNotherRect.Width = aWorkRect.getWidth();
999 aNotherRect.Height = aWorkRect.getHeight();
1000 return aNotherRect;
1003 css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::createWindow( const css::awt::WindowDescriptor& rDescriptor )
1005 return ImplCreateWindow( rDescriptor, MessBoxStyle::NONE );
1008 css::uno::Reference< css::awt::XDevice > VCLXToolkit::createScreenCompatibleDevice( sal_Int32 Width, sal_Int32 Height )
1010 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1012 css::uno::Reference< css::awt::XDevice > xRef;
1013 VCLXVirtualDevice* pVDev = new VCLXVirtualDevice;
1015 SolarMutexGuard aSolarGuard;
1017 VclPtrInstance<VirtualDevice> pV;
1018 pV->SetOutputSizePixel( Size( Width, Height ) );
1019 pVDev->SetVirtualDevice( pV );
1021 xRef = pVDev;
1022 return xRef;
1025 css::uno::Reference< css::awt::XRegion > VCLXToolkit::createRegion( )
1027 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1029 css::uno::Reference< css::awt::XRegion > xRef = new VCLXRegion;
1030 return xRef;
1033 class InfoBox : public MessBox
1035 public:
1036 InfoBox(vcl::Window* pParent, const OUString& rMessage)
1037 : MessBox(pParent, MessBoxStyle::Ok | MessBoxStyle::DefaultOk, 0, OUString(), rMessage)
1039 // Default Text is the display title from the application
1040 if (GetText().isEmpty())
1041 SetText(GetStandardInfoBoxText());
1042 SetImage(GetStandardInfoBoxImage());
1046 class ErrorBox : public MessBox
1048 public:
1049 ErrorBox(vcl::Window* pParent, MessBoxStyle nStyle, WinBits nWinBits, const OUString& rMessage)
1050 : MessBox(pParent, nStyle, nWinBits, OUString(), rMessage)
1052 // Default Text is the display title from the application
1053 if (GetText().isEmpty())
1054 SetText(GetStandardErrorBoxText());
1055 SetImage(GetStandardErrorBoxImage());
1059 class QueryBox : public MessBox
1061 public:
1062 QueryBox(vcl::Window* pParent, MessBoxStyle nStyle, WinBits nWinBits, const OUString& rMessage)
1063 : MessBox(pParent, nStyle, nWinBits, OUString(), rMessage)
1065 // Default Text is the display title from the application
1066 if (GetText().isEmpty())
1067 SetText(GetStandardQueryBoxText());
1068 SetImage(GetStandardQueryBoxImage());
1072 class WarningBox : public MessBox
1074 public:
1075 WarningBox(vcl::Window* pParent, MessBoxStyle nStyle, WinBits nWinBits, const OUString& rMessage)
1076 : MessBox(pParent, nStyle, nWinBits, OUString(), rMessage)
1078 // Default Text is the display title from the application
1079 if (GetText().isEmpty())
1080 SetText(GetStandardWarningBoxText());
1081 SetImage(GetStandardWarningBoxImage());
1085 vcl::Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp,
1086 const css::awt::WindowDescriptor& rDescriptor,
1087 vcl::Window* pParent, WinBits nWinBits, MessBoxStyle nMessBoxStyle )
1089 OUString aServiceName = rDescriptor.WindowServiceName.toAsciiLowerCase();
1091 VclPtr<vcl::Window> pNewWindow;
1092 WindowType nType = ImplGetComponentType( aServiceName );
1093 bool bFrameControl = false;
1094 if ( aServiceName == "frame" )
1095 bFrameControl = true;
1096 if ( aServiceName == "tabcontrolnotabs" )
1098 nWinBits |= WB_NOBORDER;
1099 nType = ImplGetComponentType( "tabcontrol" );
1101 if ( !pParent )
1103 // If the component needs a parent, then return NULL,
1104 // some time later css::uno::Exception...
1105 bool bException = true;
1106 if ( ( nType == WindowType::DIALOG )
1107 || ( nType == WindowType::MODALDIALOG )
1108 || ( nType == WindowType::MODELESSDIALOG )
1109 || ( nType == WindowType::MESSBOX )
1110 || ( nType == WindowType::INFOBOX )
1111 || ( nType == WindowType::WARNINGBOX )
1112 || ( nType == WindowType::ERRORBOX )
1113 || ( nType == WindowType::QUERYBOX )
1115 bException = false;
1116 else if ( ( nType == WindowType::WINDOW ) ||
1117 ( nType == WindowType::WORKWINDOW ) ||
1118 ( nType == WindowType::TOOLKIT_FRAMEWINDOW ) )
1120 if ( rDescriptor.Type == css::awt::WindowClass_TOP )
1121 bException = false;
1124 if ( bException )
1126 *ppNewComp = nullptr;
1127 return nullptr;
1131 if ( nType != WindowType::NONE )
1133 SolarMutexGuard aVclGuard;
1134 switch ( nType )
1136 case WindowType::CANCELBUTTON:
1137 pNewWindow = VclPtr<CancelButton>::Create( pParent, nWinBits );
1138 *ppNewComp = new VCLXButton;
1139 break;
1140 case WindowType::CHECKBOX:
1141 pNewWindow = VclPtr<CheckBox>::Create( pParent, nWinBits );
1142 *ppNewComp = new VCLXCheckBox;
1143 break;
1144 case WindowType::COMBOBOX:
1145 pNewWindow = VclPtr<ComboBox>::Create( pParent, nWinBits|WB_AUTOHSCROLL );
1146 static_cast<ComboBox*>(pNewWindow.get())->EnableAutoSize( false );
1147 *ppNewComp = new VCLXComboBox;
1148 break;
1149 case WindowType::CURRENCYBOX:
1150 pNewWindow = VclPtr<CurrencyBox>::Create( pParent, nWinBits );
1151 break;
1152 case WindowType::CURRENCYFIELD:
1153 pNewWindow = VclPtr<CurrencyField>::Create( pParent, nWinBits );
1154 static_cast<CurrencyField*>(pNewWindow.get())->EnableEmptyFieldValue( true );
1155 *ppNewComp = new VCLXNumericField;
1156 static_cast<VCLXFormattedSpinField*>(*ppNewComp)->SetFormatter( static_cast<FormatterBase*>(static_cast<CurrencyField*>(pNewWindow.get())) );
1157 break;
1158 case WindowType::DATEBOX:
1159 pNewWindow = VclPtr<DateBox>::Create( pParent, nWinBits );
1160 break;
1161 case WindowType::DATEFIELD:
1162 pNewWindow = VclPtr<DateField>::Create( pParent, nWinBits );
1163 static_cast<DateField*>(pNewWindow.get())->EnableEmptyFieldValue( true );
1164 *ppNewComp = new VCLXDateField;
1165 static_cast<VCLXFormattedSpinField*>(*ppNewComp)->SetFormatter( static_cast<FormatterBase*>(static_cast<DateField*>(pNewWindow.get())) );
1166 break;
1167 case WindowType::DOCKINGAREA:
1168 pNewWindow = VclPtr<DockingAreaWindow>::Create( pParent );
1169 break;
1170 case WindowType::MULTILINEEDIT:
1171 case WindowType::EDIT:
1172 pNewWindow = VclPtr<Edit>::Create( pParent, nWinBits );
1173 *ppNewComp = new VCLXEdit;
1174 break;
1175 case WindowType::ERRORBOX:
1176 pNewWindow = VclPtr<ErrorBox>::Create( pParent, nMessBoxStyle, nWinBits, OUString() );
1177 *ppNewComp = new VCLXMessageBox;
1178 break;
1179 case WindowType::FIXEDBITMAP:
1180 pNewWindow = VclPtr<FixedBitmap>::Create( pParent, nWinBits );
1181 break;
1182 case WindowType::FIXEDIMAGE:
1183 pNewWindow = VclPtr<ImageControl>::Create( pParent, nWinBits );
1184 *ppNewComp = new VCLXImageControl;
1185 break;
1186 case WindowType::FIXEDLINE:
1187 pNewWindow = VclPtr<FixedLine>::Create( pParent, nWinBits );
1188 break;
1189 case WindowType::FIXEDTEXT:
1190 pNewWindow = VclPtr<FixedText>::Create( pParent, nWinBits );
1191 *ppNewComp = new VCLXFixedText;
1192 break;
1193 case WindowType::FLOATINGWINDOW:
1194 pNewWindow = VclPtr<FloatingWindow>::Create( pParent, nWinBits );
1195 break;
1196 case WindowType::GROUPBOX:
1197 pNewWindow = VclPtr<GroupBox>::Create( pParent, nWinBits );
1198 if ( bFrameControl )
1200 GroupBox* pGroupBox = static_cast< GroupBox* >( pNewWindow.get() );
1201 *ppNewComp = new VCLXFrame;
1202 // Frame control needs to receive
1203 // Mouse events
1204 pGroupBox->SetMouseTransparent( false );
1206 break;
1207 case WindowType::HELPBUTTON:
1208 pNewWindow = VclPtr<HelpButton>::Create( pParent, nWinBits );
1209 *ppNewComp = new VCLXButton;
1210 break;
1211 case WindowType::IMAGEBUTTON:
1212 pNewWindow = VclPtr<ImageButton>::Create( pParent, nWinBits );
1213 *ppNewComp = new VCLXButton;
1214 break;
1215 case WindowType::INFOBOX:
1216 pNewWindow = VclPtr<InfoBox>::Create( pParent, OUString() );
1217 *ppNewComp = new VCLXMessageBox;
1218 break;
1219 case WindowType::LISTBOX:
1220 pNewWindow = VclPtr<ListBox>::Create( pParent, nWinBits|WB_SIMPLEMODE|WB_AUTOHSCROLL );
1221 static_cast<ListBox*>(pNewWindow.get())->EnableAutoSize( false );
1222 *ppNewComp = new VCLXListBox;
1223 break;
1224 case WindowType::LONGCURRENCYBOX:
1225 pNewWindow = VclPtr<LongCurrencyBox>::Create( pParent, nWinBits );
1226 break;
1227 case WindowType::LONGCURRENCYFIELD:
1228 pNewWindow = VclPtr<LongCurrencyField>::Create( pParent, nWinBits );
1229 *ppNewComp = new VCLXCurrencyField;
1230 static_cast<VCLXFormattedSpinField*>(*ppNewComp)->SetFormatter( static_cast<FormatterBase*>(static_cast<LongCurrencyField*>(pNewWindow.get())) );
1231 break;
1232 case WindowType::MENUBUTTON:
1233 pNewWindow = VclPtr<MenuButton>::Create( pParent, nWinBits );
1234 *ppNewComp = new VCLXButton;
1235 break;
1236 case WindowType::MESSBOX:
1237 pNewWindow = VclPtr<MessBox>::Create( pParent, nMessBoxStyle, nWinBits, OUString(), OUString() );
1238 *ppNewComp = new VCLXMessageBox;
1239 break;
1240 case WindowType::METRICBOX:
1241 pNewWindow = VclPtr<MetricBox>::Create( pParent, nWinBits );
1242 break;
1243 case WindowType::METRICFIELD:
1244 pNewWindow = VclPtr<MetricField>::Create( pParent, nWinBits );
1245 *ppNewComp = new VCLXMetricField;
1246 static_cast<VCLXFormattedSpinField*>(*ppNewComp)->SetFormatter( static_cast<FormatterBase*>(static_cast<MetricField*>(pNewWindow.get())) );
1247 break;
1248 case WindowType::DIALOG:
1249 case WindowType::MODALDIALOG:
1250 case WindowType::MODELESSDIALOG:
1252 // Modal/Modeless only via Show/Execute
1253 if ( (pParent == nullptr ) && ( rDescriptor.ParentIndex == -1 ) )
1254 pNewWindow = VclPtr<toolkit::ScrollableDialog>::Create( nullptr, nWinBits, Dialog::InitFlag::NoParent );
1255 else
1256 pNewWindow = VclPtr<toolkit::ScrollableDialog>::Create( pParent, nWinBits );
1257 // #i70217# Don't always create a new component object. It's possible that VCL has called
1258 // GetComponentInterface( sal_True ) in the Dialog ctor itself (see Window::IsTopWindow() )
1259 // which creates a component object.
1260 css::uno::Reference< css::awt::XWindowPeer > xWinPeer = pNewWindow->GetComponentInterface( false );
1261 if ( xWinPeer.is() )
1262 *ppNewComp = dynamic_cast< VCLXDialog* >( xWinPeer.get() );
1263 else
1264 *ppNewComp = new VCLXDialog;
1266 break;
1267 case WindowType::MOREBUTTON:
1268 pNewWindow = VclPtr<MoreButton>::Create( pParent, nWinBits );
1269 *ppNewComp = new VCLXButton;
1270 break;
1271 case WindowType::MULTILISTBOX:
1272 pNewWindow = VclPtr<MultiListBox>::Create( pParent, nWinBits );
1273 *ppNewComp = new VCLXListBox;
1274 break;
1275 case WindowType::NUMERICBOX:
1276 pNewWindow = VclPtr<NumericBox>::Create( pParent, nWinBits );
1277 break;
1278 case WindowType::NUMERICFIELD:
1279 pNewWindow = VclPtr<NumericField>::Create( pParent, nWinBits );
1280 static_cast<NumericField*>(pNewWindow.get())->EnableEmptyFieldValue( true );
1281 *ppNewComp = new VCLXNumericField;
1282 static_cast<VCLXFormattedSpinField*>(*ppNewComp)->SetFormatter( static_cast<FormatterBase*>(static_cast<NumericField*>(pNewWindow.get())) );
1283 break;
1284 case WindowType::OKBUTTON:
1285 pNewWindow = VclPtr<OKButton>::Create( pParent, nWinBits );
1286 *ppNewComp = new VCLXButton;
1287 break;
1288 case WindowType::PATTERNBOX:
1289 pNewWindow = VclPtr<PatternBox>::Create( pParent, nWinBits );
1290 break;
1291 case WindowType::PATTERNFIELD:
1292 pNewWindow = VclPtr<PatternField>::Create( pParent, nWinBits );
1293 *ppNewComp = new VCLXPatternField;
1294 static_cast<VCLXFormattedSpinField*>(*ppNewComp)->SetFormatter( static_cast<FormatterBase*>(static_cast<PatternField*>(pNewWindow.get())) );
1295 break;
1296 case WindowType::PUSHBUTTON:
1297 pNewWindow = VclPtr<PushButton>::Create( pParent, nWinBits );
1298 *ppNewComp = new VCLXButton;
1299 break;
1300 case WindowType::QUERYBOX:
1301 pNewWindow = VclPtr<QueryBox>::Create( pParent, nMessBoxStyle, nWinBits, OUString() );
1302 *ppNewComp = new VCLXMessageBox;
1303 break;
1304 case WindowType::RADIOBUTTON:
1305 pNewWindow = VclPtr<RadioButton>::Create( pParent, nWinBits );
1306 *ppNewComp = new VCLXRadioButton;
1308 // by default, disable RadioCheck
1309 // Since the VCLXRadioButton really cares for its RadioCheck settings, this is important:
1310 // if we enable it, the VCLXRadioButton will use RadioButton::Check instead of RadioButton::SetState
1311 // This leads to a strange behaviour if the control is newly created: when settings the initial
1312 // state to "checked", the RadioButton::Check (called because RadioCheck=sal_True) will uncheck
1313 // _all_other_ radio buttons in the same group. However, at this moment the grouping of the controls
1314 // is not really valid: the controls are grouped after they have been created, but we're still in
1315 // the creation process, so the RadioButton::Check relies on invalid grouping information.
1316 // 07.08.2001 - #87254# - frank.schoenheit@sun.com
1317 static_cast<RadioButton*>(pNewWindow.get())->EnableRadioCheck( false );
1318 break;
1319 case WindowType::SCROLLBAR:
1320 pNewWindow = VclPtr<ScrollBar>::Create( pParent, nWinBits );
1321 *ppNewComp = new VCLXScrollBar;
1322 break;
1323 case WindowType::SCROLLBARBOX:
1324 pNewWindow = VclPtr<ScrollBarBox>::Create( pParent, nWinBits );
1325 break;
1326 case WindowType::SPINBUTTON:
1327 pNewWindow = VclPtr<SpinButton>::Create( pParent, nWinBits );
1328 *ppNewComp = new ::toolkit::VCLXSpinButton;
1329 break;
1330 case WindowType::SPINFIELD:
1331 pNewWindow = VclPtr<SpinField>::Create( pParent, nWinBits );
1332 *ppNewComp = new VCLXNumericField;
1333 break;
1334 case WindowType::SPLITTER:
1335 pNewWindow = VclPtr<Splitter>::Create( pParent, nWinBits );
1336 break;
1337 case WindowType::SPLITWINDOW:
1338 pNewWindow = VclPtr<SplitWindow>::Create( pParent, nWinBits );
1339 break;
1340 case WindowType::STATUSBAR:
1341 pNewWindow = VclPtr<StatusBar>::Create( pParent, nWinBits );
1342 break;
1343 case WindowType::TOOLKIT_SYSTEMCHILDWINDOW:
1344 pNewWindow = VclPtr<SystemChildWindow>::Create( pParent, nWinBits );
1345 *ppNewComp = new VCLXSystemDependentWindow();
1346 break;
1347 case WindowType::TABCONTROL:
1348 pNewWindow = VclPtr<TabControl>::Create( pParent, nWinBits );
1349 *ppNewComp = new VCLXMultiPage;
1350 break;
1351 case WindowType::TABDIALOG:
1352 pNewWindow = VclPtr<TabDialog>::Create( pParent, nWinBits );
1353 break;
1354 case WindowType::TABPAGE:
1356 pNewWindow = VclPtr<TabPage>::Create( pParent, nWinBits );
1357 *ppNewComp = new VCLXTabPage;
1359 break;
1360 case WindowType::TIMEBOX:
1361 pNewWindow = VclPtr<TimeBox>::Create( pParent, nWinBits );
1362 break;
1363 case WindowType::TIMEFIELD:
1364 pNewWindow = VclPtr<TimeField>::Create( pParent, nWinBits );
1365 static_cast<TimeField*>(pNewWindow.get())->EnableEmptyFieldValue( true );
1366 *ppNewComp = new VCLXTimeField;
1367 static_cast<VCLXFormattedSpinField*>(*ppNewComp)->SetFormatter( static_cast<FormatterBase*>(static_cast<TimeField*>(pNewWindow.get())) );
1368 break;
1369 case WindowType::TOOLBOX:
1370 pNewWindow = VclPtr<ToolBox>::Create( pParent, nWinBits );
1371 *ppNewComp = new VCLXToolBox;
1372 break;
1373 case WindowType::TRISTATEBOX:
1374 pNewWindow = VclPtr<TriStateBox>::Create( pParent, nWinBits );
1375 break;
1376 case WindowType::WARNINGBOX:
1377 pNewWindow = VclPtr<WarningBox>::Create( pParent, nMessBoxStyle, nWinBits, OUString() );
1378 *ppNewComp = new VCLXMessageBox;
1379 break;
1380 case WindowType::WORKWINDOW:
1381 case WindowType::WINDOW:
1382 case WindowType::TOOLKIT_FRAMEWINDOW:
1383 case WindowType::DOCKINGWINDOW:
1384 if ( rDescriptor.Type == css::awt::WindowClass_TOP )
1386 if (nType == WindowType::DOCKINGWINDOW )
1387 pNewWindow = VclPtr<DockingWindow>::Create( pParent, nWinBits );
1388 else
1390 if ((pParent == nullptr) && rDescriptor.Parent.is())
1392 // try to get a system dependent window handle
1393 css::uno::Reference< css::awt::XSystemDependentWindowPeer > xSystemDepParent(rDescriptor.Parent, css::uno::UNO_QUERY);
1395 if (xSystemDepParent.is())
1397 sal_Int8 processID[16];
1399 rtl_getGlobalProcessId( reinterpret_cast<sal_uInt8*>(processID) );
1401 css::uno::Sequence<sal_Int8> processIdSeq(processID, 16);
1403 css::uno::Any anyHandle = xSystemDepParent->getWindowHandle(processIdSeq, SYSTEM_DEPENDENT_TYPE);
1405 // use sal_Int64 here to accommodate all int types
1406 // uno::Any shift operator whill upcast if necessary
1407 sal_Int64 nWindowHandle = 0;
1408 bool bXEmbed = false;
1410 bool bUseParentData = true;
1411 if( ! (anyHandle >>= nWindowHandle) )
1413 css::uno::Sequence< css::beans::NamedValue > aProps;
1414 if( anyHandle >>= aProps )
1416 const int nProps = aProps.getLength();
1417 const css::beans::NamedValue* pProps = aProps.getConstArray();
1418 for( int i = 0; i < nProps; i++ )
1420 if ( pProps[i].Name == "WINDOW" )
1421 pProps[i].Value >>= nWindowHandle;
1422 else if ( pProps[i].Name == "XEMBED" )
1423 pProps[i].Value >>= bXEmbed;
1426 else
1427 bUseParentData = false;
1430 if( bUseParentData )
1432 SystemParentData aParentData;
1433 aParentData.nSize = sizeof( aParentData );
1434 #if defined MACOSX
1435 aParentData.pView = reinterpret_cast<NSView*>(nWindowHandle);
1436 #elif defined ANDROID
1437 // Nothing
1438 #elif defined IOS
1439 // Nothing
1440 #elif defined UNX
1441 aParentData.aWindow = nWindowHandle;
1442 aParentData.bXEmbedSupport = bXEmbed;
1443 #elif defined WNT
1444 aParentData.hWnd = reinterpret_cast<HWND>(nWindowHandle);
1445 #endif
1446 pNewWindow = VclPtr<WorkWindow>::Create( &aParentData );
1451 if (!pNewWindow)
1452 pNewWindow = VclPtr<WorkWindow>::Create( pParent, nWinBits );
1455 *ppNewComp = new VCLXTopWindow();
1457 else if ( rDescriptor.Type == css::awt::WindowClass_CONTAINER )
1459 if (nType == WindowType::DOCKINGWINDOW )
1460 pNewWindow = VclPtr<DockingWindow>::Create( pParent, nWinBits );
1461 else
1462 pNewWindow = VclPtr<vcl::Window>::Create( pParent, nWinBits );
1463 *ppNewComp = new VCLXContainer;
1465 else
1467 if (nType == WindowType::DOCKINGWINDOW )
1468 pNewWindow = VclPtr<DockingWindow>::Create( pParent, nWinBits );
1469 else
1470 pNewWindow = VclPtr<vcl::Window>::Create( pParent, nWinBits );
1471 *ppNewComp = new VCLXWindow;
1473 break;
1474 case WindowType::CONTROL:
1475 if ( rDescriptor.WindowServiceName.equalsIgnoreAsciiCase(
1476 "tabpagecontainer" ) )
1478 // TabControl has a special case for tabs without border: they are displayed
1479 // in a different way, so we need to ensure that this style is not set, so
1480 // we can guarantee normal tab behavior
1481 pNewWindow = VclPtr<TabControl>::Create( pParent, nWinBits & (~WB_NOBORDER));
1482 *ppNewComp = new VCLXTabPageContainer;
1484 else if ( aServiceName == "animatedimages" )
1486 pNewWindow = VclPtr<Throbber>::Create( pParent, nWinBits );
1487 *ppNewComp = new ::toolkit::AnimatedImagesPeer;
1489 break;
1490 default:
1491 OSL_ENSURE( false, "VCLXToolkit::ImplCreateWindow: unknown window type!" );
1492 break;
1496 return pNewWindow;
1499 #ifndef DISABLE_DYNLOADING
1501 extern "C" { static void thisModule() {} }
1503 #else
1505 extern "C" vcl::Window* SAL_CALL CreateWindow( VCLXWindow** ppNewComp, const css::awt::WindowDescriptor* pDescriptor, vcl::Window* pParent, WinBits nWinBits );
1507 #endif
1509 css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::ImplCreateWindow(
1510 const css::awt::WindowDescriptor& rDescriptor,
1511 MessBoxStyle nForceMessBoxStyle )
1513 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1515 SolarMutexGuard aSolarGuard;
1517 css::uno::Reference< css::awt::XWindowPeer > xRef;
1519 VclPtr<vcl::Window> pParent;
1520 if ( rDescriptor.Parent.is() )
1522 VCLXWindow* pParentComponent = VCLXWindow::GetImplementation( rDescriptor.Parent );
1524 // #103939# Don't throw assertion, may be it's a system dependent window, used in ImplCreateWindow.
1525 // DBG_ASSERT( pParentComponent, "ParentComponent not valid" );
1527 if ( pParentComponent )
1528 pParent = pParentComponent->GetWindow();
1530 std::pair<WinBits, MessBoxStyle> aPair = ImplGetWinBits( rDescriptor.WindowAttributes,
1531 ImplGetComponentType( rDescriptor.WindowServiceName ) );
1532 WinBits nWinBits = aPair.first;
1533 aPair.second |= nForceMessBoxStyle;
1535 VCLXWindow* pNewComp = nullptr;
1537 vcl::Window* pNewWindow = nullptr;
1538 // Try to create the window with SvTools
1539 // (do this _before_ creating it on our own: The old mechanism (extended toolkit in SvTools) did it this way,
1540 // and we need to stay compatible)
1541 // try to load the lib
1542 if ( !fnSvtCreateWindow
1543 #ifndef DISABLE_DYNLOADING
1544 && !hSvToolsLib
1545 #endif
1548 #ifndef DISABLE_DYNLOADING
1549 OUString aLibName(SVT_DLL_NAME);
1550 hSvToolsLib = osl_loadModuleRelative(
1551 &thisModule, aLibName.pData, SAL_LOADMODULE_DEFAULT );
1552 if ( hSvToolsLib )
1554 OUString aFunctionName( "CreateWindow" );
1555 fnSvtCreateWindow = reinterpret_cast<FN_SvtCreateWindow>(osl_getFunctionSymbol( hSvToolsLib, aFunctionName.pData ));
1557 #else
1558 fnSvtCreateWindow = CreateWindow;
1559 #endif
1561 // ask the SvTool creation function
1562 if ( fnSvtCreateWindow )
1563 pNewWindow = fnSvtCreateWindow( &pNewComp, &rDescriptor, pParent, nWinBits );
1565 // if SvTools could not provide a window, create it ourself
1566 if ( !pNewWindow )
1567 pNewWindow = ImplCreateWindow( &pNewComp, rDescriptor, pParent, nWinBits, aPair.second );
1569 DBG_ASSERT( pNewWindow, "createWindow: Unknown Component!" );
1570 SAL_INFO_IF( !pNewComp, "toolkit", "createWindow: No special Interface!" );
1572 if ( pNewWindow )
1574 pNewWindow->SetCreatedWithToolkit( true );
1575 //pNewWindow->SetPosPixel( Point() ); // do not force (0,0) position, keep default pos instead
1577 if ( rDescriptor.WindowAttributes & css::awt::WindowAttribute::MINSIZE )
1579 pNewWindow->SetSizePixel( Size() );
1581 else if ( rDescriptor.WindowAttributes & css::awt::WindowAttribute::FULLSIZE )
1583 if ( pParent )
1584 pNewWindow->SetSizePixel( pParent->GetOutputSizePixel() );
1586 else if ( !VCLUnoHelper::IsZero( rDescriptor.Bounds ) )
1588 tools::Rectangle aRect = VCLRectangle( rDescriptor.Bounds );
1589 pNewWindow->SetPosSizePixel( aRect.TopLeft(), aRect.GetSize() );
1592 if ( !pNewComp )
1594 // Default-Interface
1595 xRef = pNewWindow->GetComponentInterface();
1597 else
1599 xRef = pNewComp;
1600 pNewWindow->SetComponentInterface( xRef );
1602 DBG_ASSERT( pNewWindow->GetComponentInterface( false ) == xRef,
1603 "VCLXToolkit::createWindow: did #133706# resurge?" );
1605 if ( rDescriptor.WindowAttributes & css::awt::WindowAttribute::SHOW )
1606 pNewWindow->Show();
1609 return xRef;
1612 css::uno::Sequence< css::uno::Reference< css::awt::XWindowPeer > > VCLXToolkit::createWindows( const css::uno::Sequence< css::awt::WindowDescriptor >& rDescriptors )
1614 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1616 sal_uInt32 nComponents = rDescriptors.getLength();
1617 css::uno::Sequence< css::uno::Reference< css::awt::XWindowPeer > > aSeq( nComponents );
1618 for ( sal_uInt32 n = 0; n < nComponents; n++ )
1620 css::awt::WindowDescriptor aDescr = rDescriptors.getConstArray()[n];
1622 if ( aDescr.ParentIndex == -1 )
1623 aDescr.Parent = nullptr;
1624 else if ( ( aDescr.ParentIndex >= 0 ) && ( aDescr.ParentIndex < static_cast<short>(n) ) )
1625 aDescr.Parent = aSeq.getConstArray()[aDescr.ParentIndex];
1626 aSeq.getArray()[n] = createWindow( aDescr );
1628 return aSeq;
1631 // css::awt::XSystemChildFactory
1632 css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::createSystemChild( const css::uno::Any& Parent, const css::uno::Sequence< sal_Int8 >& /*ProcessId*/, sal_Int16 nSystemType )
1634 VclPtr<vcl::Window> pChildWindow;
1635 if ( nSystemType == SYSTEM_DEPENDENT_TYPE )
1637 // use sal_Int64 here to accommodate all int types
1638 // uno::Any shift operator whill upcast if necessary
1639 sal_Int64 nWindowHandle = 0;
1640 bool bXEmbed = false;
1642 bool bUseParentData = true;
1643 if( ! (Parent >>= nWindowHandle) )
1645 css::uno::Sequence< css::beans::NamedValue > aProps;
1646 if( Parent >>= aProps )
1648 const int nProps = aProps.getLength();
1649 const css::beans::NamedValue* pProps = aProps.getConstArray();
1650 for( int i = 0; i < nProps; i++ )
1652 if ( pProps[i].Name == "WINDOW" )
1653 pProps[i].Value >>= nWindowHandle;
1654 else if ( pProps[i].Name == "XEMBED" )
1655 pProps[i].Value >>= bXEmbed;
1658 else
1659 bUseParentData = false;
1662 if( bUseParentData )
1664 SystemParentData aParentData;
1665 aParentData.nSize = sizeof( aParentData );
1666 #if defined MACOSX
1667 aParentData.pView = reinterpret_cast<NSView*>(nWindowHandle);
1668 #elif defined ANDROID
1669 // Nothing
1670 #elif defined IOS
1671 // Nothing
1672 #elif defined UNX
1673 aParentData.aWindow = nWindowHandle;
1674 aParentData.bXEmbedSupport = bXEmbed;
1675 #elif defined WNT
1676 aParentData.hWnd = reinterpret_cast<HWND>(nWindowHandle);
1677 #endif
1678 SolarMutexGuard aGuard;
1681 pChildWindow.reset( VclPtr<WorkWindow>::Create( &aParentData ) );
1683 catch ( const css::uno::RuntimeException & )
1685 // system child window could not be created
1686 DBG_UNHANDLED_EXCEPTION("toolkit");
1687 pChildWindow.clear();
1691 else if (nSystemType == css::lang::SystemDependent::SYSTEM_JAVA)
1693 SolarMutexGuard aGuard;
1694 pChildWindow.reset(VclPtr<WorkWindow>::Create(nullptr, Parent));
1697 css::uno::Reference< css::awt::XWindowPeer > xPeer;
1698 if ( pChildWindow )
1700 VCLXTopWindow* pPeer = new VCLXTopWindow;
1701 SolarMutexGuard aGuard;
1702 pPeer->SetWindow( pChildWindow );
1703 xPeer = pPeer;
1706 return xPeer;
1709 // css::awt::XMessageBoxFactory
1710 css::uno::Reference< css::awt::XMessageBox > SAL_CALL VCLXToolkit::createMessageBox(
1711 const css::uno::Reference< css::awt::XWindowPeer >& aParent,
1712 css::awt::MessageBoxType eType,
1713 ::sal_Int32 aButtons,
1714 const OUString& aTitle,
1715 const OUString& aMessage )
1717 css::awt::WindowDescriptor aDescriptor;
1719 sal_Int32 nWindowAttributes = css::awt::WindowAttribute::BORDER|css::awt::WindowAttribute::MOVEABLE|css::awt::WindowAttribute::CLOSEABLE;
1721 // Map button definitions to window attributes
1722 if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK )
1723 nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK;
1724 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_OK_CANCEL )
1725 nWindowAttributes |= css::awt::VclWindowPeerAttribute::OK_CANCEL;
1726 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO )
1727 nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO;
1728 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_YES_NO_CANCEL )
1729 nWindowAttributes |= css::awt::VclWindowPeerAttribute::YES_NO_CANCEL;
1730 else if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_RETRY_CANCEL )
1731 nWindowAttributes |= css::awt::VclWindowPeerAttribute::RETRY_CANCEL;
1733 // Map default button definitions to window attributes
1734 if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_OK )
1735 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_OK;
1736 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_CANCEL )
1737 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_CANCEL;
1738 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_YES )
1739 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_YES;
1740 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_NO )
1741 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_NO;
1742 else if (sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_RETRY )
1743 nWindowAttributes |= css::awt::VclWindowPeerAttribute::DEF_RETRY;
1745 // No more bits for VclWindowPeerAttribute possible. Mapping must be
1746 // done explicitly using VCL methods
1747 MessBoxStyle nAddWinBits = MessBoxStyle::NONE;
1748 if (( aButtons & 0x0000ffffL ) == css::awt::MessageBoxButtons::BUTTONS_ABORT_IGNORE_RETRY )
1749 nAddWinBits |= MessBoxStyle::AbortRetryIgnore;
1750 if ( sal_Int32( aButtons & 0xffff0000L ) == css::awt::MessageBoxButtons::DEFAULT_BUTTON_IGNORE )
1751 nAddWinBits |= MessBoxStyle::DefaultIgnore;
1753 OUString aType;
1754 lcl_convertMessageBoxType( aType, eType );
1756 aDescriptor.Type = css::awt::WindowClass_MODALTOP;
1757 aDescriptor.WindowServiceName = aType;
1758 aDescriptor.ParentIndex = -1;
1759 aDescriptor.Parent = aParent;
1760 aDescriptor.WindowAttributes = nWindowAttributes;
1761 css::uno::Reference< css::awt::XMessageBox > xMsgBox(
1762 ImplCreateWindow( aDescriptor, nAddWinBits ), css::uno::UNO_QUERY );
1763 css::uno::Reference< css::awt::XWindow > xWindow( xMsgBox, css::uno::UNO_QUERY );
1764 if ( xMsgBox.is() && xWindow.is() )
1766 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
1767 if ( pWindow )
1769 SolarMutexGuard aGuard;
1770 xMsgBox->setCaptionText( aTitle );
1771 xMsgBox->setMessageText( aMessage );
1775 return xMsgBox;
1778 css::uno::Reference< css::datatransfer::dnd::XDragGestureRecognizer > SAL_CALL VCLXToolkit::getDragGestureRecognizer( const css::uno::Reference< css::awt::XWindow >& window )
1780 SolarMutexGuard g;
1782 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( window );
1784 if( pWindow )
1785 return pWindow->GetDragGestureRecognizer();
1787 return css::uno::Reference< css::datatransfer::dnd::XDragGestureRecognizer >();
1790 css::uno::Reference< css::datatransfer::dnd::XDragSource > SAL_CALL VCLXToolkit::getDragSource( const css::uno::Reference< css::awt::XWindow >& window )
1792 SolarMutexGuard g;
1794 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( window );
1796 if( pWindow )
1797 return pWindow->GetDragSource();
1799 return css::uno::Reference< css::datatransfer::dnd::XDragSource >();
1802 css::uno::Reference< css::datatransfer::dnd::XDropTarget > SAL_CALL VCLXToolkit::getDropTarget( const css::uno::Reference< css::awt::XWindow >& window )
1804 SolarMutexGuard g;
1806 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( window );
1808 if( pWindow )
1809 return pWindow->GetDropTarget();
1811 return css::uno::Reference< css::datatransfer::dnd::XDropTarget >();
1814 css::uno::Reference< css::datatransfer::clipboard::XClipboard > SAL_CALL VCLXToolkit::getClipboard( const OUString& clipboardName )
1816 if( clipboardName.isEmpty() )
1818 if( !mxClipboard.is() )
1820 // remember clipboard here
1821 mxClipboard = css::datatransfer::clipboard::SystemClipboard::create(
1822 comphelper::getProcessComponentContext());
1825 return mxClipboard;
1828 else if( clipboardName == "Selection" )
1830 return mxSelection;
1833 return css::uno::Reference< css::datatransfer::clipboard::XClipboard >();
1836 // XServiceInfo
1837 OUString VCLXToolkit::getImplementationName()
1839 return OUString("stardiv.Toolkit.VCLXToolkit");
1842 sal_Bool VCLXToolkit::supportsService( const OUString& rServiceName )
1844 return cppu::supportsService(this, rServiceName);
1847 css::uno::Sequence< OUString > VCLXToolkit::getSupportedServiceNames()
1849 return css::uno::Sequence<OUString>{
1850 "com.sun.star.awt.Toolkit", "stardiv.vcl.VclToolkit"};
1853 // css::awt::XExtendedToolkit:
1855 // virtual
1856 ::sal_Int32 SAL_CALL VCLXToolkit::getTopWindowCount()
1858 return static_cast< ::sal_Int32 >(::Application::GetTopWindowCount());
1859 // XXX numeric overflow
1862 // virtual
1863 css::uno::Reference< css::awt::XTopWindow > SAL_CALL
1864 VCLXToolkit::getTopWindow(::sal_Int32 nIndex)
1866 vcl::Window * p = ::Application::GetTopWindow(static_cast< long >(nIndex));
1867 // XXX numeric overflow
1868 return css::uno::Reference< css::awt::XTopWindow >(
1869 p == nullptr ? nullptr : static_cast< css::awt::XWindow * >(p->GetWindowPeer()),
1870 css::uno::UNO_QUERY);
1873 // virtual
1874 css::uno::Reference< css::awt::XTopWindow > SAL_CALL
1875 VCLXToolkit::getActiveTopWindow()
1877 vcl::Window * p = ::Application::GetActiveTopWindow();
1878 return css::uno::Reference< css::awt::XTopWindow >(
1879 p == nullptr ? nullptr : static_cast< css::awt::XWindow * >(p->GetWindowPeer()),
1880 css::uno::UNO_QUERY);
1883 // virtual
1884 void SAL_CALL VCLXToolkit::addTopWindowListener(
1885 css::uno::Reference< css::awt::XTopWindowListener > const & rListener)
1887 OSL_ENSURE(rListener.is(), "Null rListener");
1888 ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
1889 if (rBHelper.bDisposed || rBHelper.bInDispose)
1891 aGuard.clear();
1892 rListener->disposing(
1893 css::lang::EventObject(
1894 static_cast< ::cppu::OWeakObject * >(this)));
1896 else if (m_aTopWindowListeners.addInterface(rListener) == 1
1897 && !m_bEventListener)
1899 m_bEventListener = true;
1900 ::Application::AddEventListener(m_aEventListenerLink);
1904 // virtual
1905 void SAL_CALL VCLXToolkit::removeTopWindowListener(
1906 css::uno::Reference< css::awt::XTopWindowListener > const & rListener)
1908 ::osl::MutexGuard aGuard(rBHelper.rMutex);
1909 if (!(rBHelper.bDisposed || rBHelper.bInDispose)
1910 && m_aTopWindowListeners.removeInterface(rListener) == 0
1911 && m_aFocusListeners.getLength() == 0 && m_bEventListener)
1913 ::Application::RemoveEventListener(m_aEventListenerLink);
1914 m_bEventListener = false;
1918 // virtual
1919 void SAL_CALL VCLXToolkit::addKeyHandler(
1920 css::uno::Reference< css::awt::XKeyHandler > const & rHandler)
1922 OSL_ENSURE(rHandler.is(), "Null rHandler");
1923 ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
1924 if (rBHelper.bDisposed || rBHelper.bInDispose)
1926 aGuard.clear();
1927 rHandler->disposing(
1928 css::lang::EventObject(
1929 static_cast< ::cppu::OWeakObject * >(this)));
1931 else if (m_aKeyHandlers.addInterface(rHandler) == 1 && !m_bKeyListener)
1933 m_bKeyListener = true;
1934 ::Application::AddKeyListener(m_aKeyListenerLink);
1938 // virtual
1939 void SAL_CALL VCLXToolkit::removeKeyHandler(
1940 css::uno::Reference< css::awt::XKeyHandler > const & rHandler)
1942 ::osl::MutexGuard aGuard(rBHelper.rMutex);
1943 if (!(rBHelper.bDisposed || rBHelper.bInDispose)
1944 && m_aKeyHandlers.removeInterface(rHandler) == 0 && m_bKeyListener)
1946 ::Application::RemoveKeyListener(m_aKeyListenerLink);
1947 m_bKeyListener = false;
1951 // virtual
1952 void SAL_CALL VCLXToolkit::addFocusListener(
1953 css::uno::Reference< css::awt::XFocusListener > const & rListener)
1955 OSL_ENSURE(rListener.is(), "Null rListener");
1956 ::osl::ClearableMutexGuard aGuard(rBHelper.rMutex);
1957 if (rBHelper.bDisposed || rBHelper.bInDispose)
1959 aGuard.clear();
1960 rListener->disposing(
1961 css::lang::EventObject(
1962 static_cast< ::cppu::OWeakObject * >(this)));
1964 else if (m_aFocusListeners.addInterface(rListener) == 1
1965 && !m_bEventListener)
1967 m_bEventListener = true;
1968 ::Application::AddEventListener(m_aEventListenerLink);
1972 // virtual
1973 void SAL_CALL VCLXToolkit::removeFocusListener(
1974 css::uno::Reference< css::awt::XFocusListener > const & rListener)
1976 ::osl::MutexGuard aGuard(rBHelper.rMutex);
1977 if (!(rBHelper.bDisposed || rBHelper.bInDispose)
1978 && m_aFocusListeners.removeInterface(rListener) == 0
1979 && m_aTopWindowListeners.getLength() == 0 && m_bEventListener)
1981 ::Application::RemoveEventListener(m_aEventListenerLink);
1982 m_bEventListener = false;
1986 // virtual
1987 void SAL_CALL VCLXToolkit::fireFocusGained(
1988 css::uno::Reference<
1989 css::uno::XInterface > const &)
1993 // virtual
1994 void SAL_CALL VCLXToolkit::fireFocusLost(
1995 css::uno::Reference<
1996 css::uno::XInterface > const &)
2001 IMPL_LINK(VCLXToolkit, eventListenerHandler, ::VclSimpleEvent&, rEvent, void)
2003 switch (rEvent.GetId())
2005 case VclEventId::WindowShow:
2006 callTopWindowListeners(
2007 &rEvent, &css::awt::XTopWindowListener::windowOpened);
2008 break;
2009 case VclEventId::WindowHide:
2010 callTopWindowListeners(
2011 &rEvent, &css::awt::XTopWindowListener::windowClosed);
2012 break;
2013 case VclEventId::WindowActivate:
2014 callTopWindowListeners(
2015 &rEvent, &css::awt::XTopWindowListener::windowActivated);
2016 break;
2017 case VclEventId::WindowDeactivate:
2018 callTopWindowListeners(
2019 &rEvent, &css::awt::XTopWindowListener::windowDeactivated);
2020 break;
2021 case VclEventId::WindowClose:
2022 callTopWindowListeners(
2023 &rEvent, &css::awt::XTopWindowListener::windowClosing);
2024 break;
2025 case VclEventId::WindowGetFocus:
2026 callFocusListeners(&rEvent, true);
2027 break;
2028 case VclEventId::WindowLoseFocus:
2029 callFocusListeners(&rEvent, false);
2030 break;
2031 case VclEventId::WindowMinimize:
2032 callTopWindowListeners(
2033 &rEvent, &css::awt::XTopWindowListener::windowMinimized);
2034 break;
2035 case VclEventId::WindowNormalize:
2036 callTopWindowListeners(
2037 &rEvent, &css::awt::XTopWindowListener::windowNormalized);
2038 break;
2039 default: break;
2043 IMPL_LINK(VCLXToolkit, keyListenerHandler, ::VclWindowEvent&, rEvent, bool)
2045 switch (rEvent.GetId())
2047 case VclEventId::WindowKeyInput:
2048 return callKeyHandlers(&rEvent, true);
2049 case VclEventId::WindowKeyUp:
2050 return callKeyHandlers(&rEvent, false);
2051 default: break;
2053 return false;
2056 void VCLXToolkit::callTopWindowListeners(
2057 ::VclSimpleEvent const * pEvent,
2058 void (SAL_CALL css::awt::XTopWindowListener::* pFn)(
2059 css::lang::EventObject const &))
2061 vcl::Window * pWindow
2062 = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
2063 if (pWindow->IsTopWindow())
2065 std::vector< css::uno::Reference< css::uno::XInterface > >
2066 aListeners(m_aTopWindowListeners.getElements());
2067 if (!aListeners.empty())
2069 css::lang::EventObject aAwtEvent(
2070 static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer()));
2071 for (css::uno::Reference<XInterface> & i : aListeners)
2073 css::uno::Reference< css::awt::XTopWindowListener >
2074 xListener(i, css::uno::UNO_QUERY);
2077 (xListener.get()->*pFn)(aAwtEvent);
2079 catch (const css::uno::RuntimeException &)
2081 DBG_UNHANDLED_EXCEPTION("toolkit");
2088 bool VCLXToolkit::callKeyHandlers(::VclSimpleEvent const * pEvent,
2089 bool bPressed)
2091 std::vector< css::uno::Reference< css::uno::XInterface > >
2092 aHandlers(m_aKeyHandlers.getElements());
2094 if (!aHandlers.empty())
2096 vcl::Window * pWindow = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
2098 // See implementation in vclxwindow.cxx for mapping between VCL and UNO AWT event
2099 ::KeyEvent * pKeyEvent = static_cast< ::KeyEvent * >(
2100 static_cast< ::VclWindowEvent const * >(pEvent)->GetData());
2101 css::awt::KeyEvent aAwtEvent(
2102 static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer()),
2103 (pKeyEvent->GetKeyCode().IsShift()
2104 ? css::awt::KeyModifier::SHIFT : 0)
2105 | (pKeyEvent->GetKeyCode().IsMod1()
2106 ? css::awt::KeyModifier::MOD1 : 0)
2107 | (pKeyEvent->GetKeyCode().IsMod2()
2108 ? css::awt::KeyModifier::MOD2 : 0)
2109 | (pKeyEvent->GetKeyCode().IsMod3()
2110 ? css::awt::KeyModifier::MOD3 : 0),
2111 pKeyEvent->GetKeyCode().GetCode(), pKeyEvent->GetCharCode(),
2112 sal::static_int_cast< sal_Int16 >(
2113 pKeyEvent->GetKeyCode().GetFunction()));
2114 for (css::uno::Reference<XInterface> & i : aHandlers)
2116 css::uno::Reference< css::awt::XKeyHandler > xHandler(
2117 i, css::uno::UNO_QUERY);
2120 if (bPressed ? xHandler->keyPressed(aAwtEvent)
2121 : xHandler->keyReleased(aAwtEvent))
2122 return true;
2124 catch (const css::uno::RuntimeException &)
2126 DBG_UNHANDLED_EXCEPTION("toolkit");
2130 return false;
2133 void VCLXToolkit::callFocusListeners(::VclSimpleEvent const * pEvent,
2134 bool bGained)
2136 vcl::Window * pWindow
2137 = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
2138 if (pWindow->IsTopWindow())
2140 std::vector< css::uno::Reference< css::uno::XInterface > >
2141 aListeners(m_aFocusListeners.getElements());
2142 if (!aListeners.empty())
2144 // Ignore the interior of compound controls when determining the
2145 // window that gets the focus next (see implementation in
2146 // vclxwindow.cxx for mapping between VCL and UNO AWT event):
2147 css::uno::Reference< css::uno::XInterface > xNext;
2148 vcl::Window * pFocus = ::Application::GetFocusWindow();
2149 for (vcl::Window * p = pFocus; p != nullptr; p = p->GetParent())
2150 if (!p->IsCompoundControl())
2152 pFocus = p;
2153 break;
2155 if (pFocus != nullptr)
2156 xNext = pFocus->GetComponentInterface();
2157 css::awt::FocusEvent aAwtEvent(
2158 static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer()),
2159 static_cast<sal_Int16>(pWindow->GetGetFocusFlags()),
2160 xNext, false);
2161 for (css::uno::Reference<XInterface> & i : aListeners)
2163 css::uno::Reference< css::awt::XFocusListener > xListener(
2164 i, css::uno::UNO_QUERY);
2167 bGained ? xListener->focusGained(aAwtEvent)
2168 : xListener->focusLost(aAwtEvent);
2170 catch (const css::uno::RuntimeException &)
2172 DBG_UNHANDLED_EXCEPTION("toolkit");
2179 // css::awt::XReschedule:
2181 void SAL_CALL VCLXToolkit::reschedule()
2183 SolarMutexGuard aSolarGuard;
2184 Application::Reschedule(true);
2187 // css::awt::XToolkitExperimental
2189 void SAL_CALL VCLXToolkit::processEventsToIdle()
2191 SolarMutexGuard aSolarGuard;
2192 comphelper::ProfileZone aZone("processEvents");
2193 Scheduler::ProcessEventsToIdle();
2196 sal_Int64 SAL_CALL VCLXToolkit::getOpenGLBufferSwapCounter()
2198 #if HAVE_FEATURE_OPENGL
2199 return OpenGLWrapper::getBufferSwapCounter();
2200 #else
2201 return 0;
2202 #endif
2205 void SAL_CALL VCLXToolkit::setDeterministicScheduling(sal_Bool bDeterministicMode)
2207 SolarMutexGuard aSolarGuard;
2208 Scheduler::SetDeterministicMode(bDeterministicMode);
2211 void SAL_CALL VCLXToolkit::pause(sal_Int32 nMilliseconds)
2213 new Pause(nMilliseconds);
2216 void SAL_CALL VCLXToolkit::startRecording()
2218 ::comphelper::ProfileRecording::startRecording(true);
2221 void SAL_CALL VCLXToolkit::stopRecording()
2223 ::comphelper::ProfileRecording::startRecording( false );
2226 css::uno::Sequence< OUString > VCLXToolkit::getRecordingAndClear()
2228 return ::comphelper::ProfileRecording::getRecordingAndClear();
2231 // css:awt:XToolkitRobot
2233 void SAL_CALL VCLXToolkit::keyPress( const css::awt::KeyEvent & aKeyEvent )
2235 css::uno::Reference<css::awt::XWindow> xWindow ( aKeyEvent.Source, css::uno::UNO_QUERY_THROW );
2236 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2237 if( !pWindow )
2238 throw css::uno::RuntimeException( "invalid event source" );
2240 ::KeyEvent aVCLKeyEvent = VCLUnoHelper::createVCLKeyEvent( aKeyEvent );
2241 ::Application::PostKeyEvent( VclEventId::WindowKeyInput, pWindow, &aVCLKeyEvent );
2244 void SAL_CALL VCLXToolkit::keyRelease( const css::awt::KeyEvent & aKeyEvent )
2246 css::uno::Reference<css::awt::XWindow> xWindow ( aKeyEvent.Source, css::uno::UNO_QUERY_THROW );
2247 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2248 if( !pWindow )
2249 throw css::uno::RuntimeException( "invalid event source" );
2251 ::KeyEvent aVCLKeyEvent = VCLUnoHelper::createVCLKeyEvent( aKeyEvent );
2252 ::Application::PostKeyEvent( VclEventId::WindowKeyUp, pWindow, &aVCLKeyEvent );
2256 void SAL_CALL VCLXToolkit::mousePress( const css::awt::MouseEvent & aMouseEvent )
2258 css::uno::Reference<css::awt::XWindow> xWindow ( aMouseEvent.Source, css::uno::UNO_QUERY_THROW );
2259 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2260 if( !pWindow )
2261 throw css::uno::RuntimeException( "invalid event source" );
2263 ::MouseEvent aVCLMouseEvent = VCLUnoHelper::createVCLMouseEvent( aMouseEvent );
2264 ::Application::PostMouseEvent( VclEventId::WindowMouseButtonDown, pWindow, &aVCLMouseEvent );
2267 void SAL_CALL VCLXToolkit::mouseRelease( const css::awt::MouseEvent & aMouseEvent )
2269 css::uno::Reference<css::awt::XWindow> xWindow ( aMouseEvent.Source, css::uno::UNO_QUERY_THROW );
2270 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2271 if( !pWindow )
2272 throw css::uno::RuntimeException( "invalid event source" );
2274 ::MouseEvent aVCLMouseEvent = VCLUnoHelper::createVCLMouseEvent( aMouseEvent );
2275 ::Application::PostMouseEvent( VclEventId::WindowMouseButtonUp, pWindow, &aVCLMouseEvent );
2278 void SAL_CALL VCLXToolkit::mouseMove( const css::awt::MouseEvent & aMouseEvent )
2280 css::uno::Reference<css::awt::XWindow> xWindow ( aMouseEvent.Source, css::uno::UNO_QUERY_THROW );
2281 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
2282 if( !pWindow )
2283 throw css::uno::RuntimeException( "invalid event source" );
2285 ::MouseEvent aVCLMouseEvent = VCLUnoHelper::createVCLMouseEvent( aMouseEvent );
2286 ::Application::PostMouseEvent( VclEventId::WindowMouseMove, pWindow, &aVCLMouseEvent );
2292 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
2293 stardiv_Toolkit_VCLXToolkit_get_implementation(
2294 css::uno::XComponentContext *,
2295 css::uno::Sequence<css::uno::Any> const &)
2297 return cppu::acquire(new VCLXToolkit());
2300 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */